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

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