source: trunk/third/evolution/e-util/e-request.c @ 18142

Revision 18142, 2.8 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18141, which included commits to RCS files with non-trunk default branches.
Line 
1/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2/* e-request.c
3 *
4 * Copyright (C) 2000, 2001 Ximian, Inc.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
19 *
20 * Author: Ettore Perazzoli
21 */
22
23#ifdef HAVE_CONFIG_H
24#include <config.h>
25#endif
26
27#include "e-request.h"
28
29#include <libgnomeui/gnome-dialog.h>
30#include <libgnomeui/gnome-stock.h>
31#include <gal/widgets/e-unicode.h>
32
33#include <gtk/gtklabel.h>
34#include <gtk/gtkentry.h>
35
36
37/**
38 * e_request_string:
39 * @parent: parent window, or %NULL
40 * @title: the dialog title (in the locale character set)
41 * @prompt: the prompt (in the locale character set)
42 * @default: default value (in UTF8)
43 *
44 * Request a string from the user.
45 *
46 * Return value: %NULL if the user cancelled the dialog, the inserted
47 * string (in UTF8) otherwise. The string must be freed by the caller.
48 **/
49char *
50e_request_string (GtkWindow *parent,
51                  const char *title,
52                  const char *prompt,
53                  const char *default_string)
54{
55        GtkWidget *dialog;
56        GtkWidget *prompt_label;
57        GtkWidget *entry;
58        GtkWidget *vbox;
59        char *retval;
60
61        g_return_val_if_fail (title != NULL, NULL);
62        g_return_val_if_fail (prompt != NULL, NULL);
63
64        dialog = gnome_dialog_new (title, GNOME_STOCK_BUTTON_OK, GNOME_STOCK_BUTTON_CANCEL, NULL);
65        gnome_dialog_set_parent (GNOME_DIALOG (dialog), parent);
66        gnome_dialog_set_default (GNOME_DIALOG (dialog), 0);
67        gnome_dialog_close_hides (GNOME_DIALOG (dialog), TRUE);
68
69        vbox = GNOME_DIALOG (dialog)->vbox;
70
71        prompt_label = gtk_label_new (prompt);
72        gtk_box_pack_start (GTK_BOX (vbox), prompt_label, TRUE, TRUE, 0);
73
74        entry = gtk_entry_new ();
75        e_utf8_gtk_entry_set_text (GTK_ENTRY (entry), default_string);
76        gtk_entry_select_region (GTK_ENTRY (entry), 0, -1);
77        gtk_box_pack_start (GTK_BOX (vbox), entry, TRUE, TRUE, 0);
78
79        gtk_widget_grab_focus (entry);
80        gnome_dialog_editable_enters (GNOME_DIALOG (dialog), GTK_EDITABLE (entry));
81
82        gtk_widget_show (prompt_label);
83        gtk_widget_show (entry);
84        gtk_widget_show (dialog);
85
86        switch (gnome_dialog_run (GNOME_DIALOG (dialog))) {
87        case 0:
88                /* OK.  */
89                retval = e_utf8_gtk_entry_get_text (GTK_ENTRY (entry));
90                break;
91        case -1:
92        case 1:
93                /* Cancel.  */
94                retval = NULL;
95                break;
96        default:
97                g_assert_not_reached ();
98                retval = NULL;
99        }
100
101        gtk_widget_destroy (dialog);
102
103        return retval;
104}
Note: See TracBrowser for help on using the repository browser.