[16769] | 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 |
---|
[16786] | 7 | * modify it under the terms of version 2 of the GNU General Public |
---|
| 8 | * License as published by the Free Software Foundation. |
---|
[16769] | 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 | |
---|
[19540] | 29 | #include <gtk/gtkbox.h> |
---|
| 30 | #include <gtk/gtkdialog.h> |
---|
[16769] | 31 | #include <gtk/gtkentry.h> |
---|
[19540] | 32 | #include <gtk/gtklabel.h> |
---|
| 33 | #include <gtk/gtkstock.h> |
---|
[16769] | 34 | |
---|
| 35 | |
---|
| 36 | /** |
---|
| 37 | * e_request_string: |
---|
[18141] | 38 | * @parent: parent window, or %NULL |
---|
| 39 | * @title: the dialog title (in the locale character set) |
---|
| 40 | * @prompt: the prompt (in the locale character set) |
---|
| 41 | * @default: default value (in UTF8) |
---|
[16769] | 42 | * |
---|
[18141] | 43 | * Request a string from the user. |
---|
[16769] | 44 | * |
---|
[18141] | 45 | * Return value: %NULL if the user cancelled the dialog, the inserted |
---|
| 46 | * string (in UTF8) otherwise. The string must be freed by the caller. |
---|
[16769] | 47 | **/ |
---|
| 48 | char * |
---|
| 49 | e_request_string (GtkWindow *parent, |
---|
| 50 | const char *title, |
---|
| 51 | const char *prompt, |
---|
| 52 | const char *default_string) |
---|
| 53 | { |
---|
| 54 | GtkWidget *prompt_label; |
---|
[19540] | 55 | char *text; |
---|
| 56 | GtkWidget *dialog; |
---|
[16769] | 57 | GtkWidget *entry; |
---|
| 58 | GtkWidget *vbox; |
---|
[19540] | 59 | |
---|
[16769] | 60 | g_return_val_if_fail (title != NULL, NULL); |
---|
| 61 | g_return_val_if_fail (prompt != NULL, NULL); |
---|
[19540] | 62 | |
---|
| 63 | dialog = gtk_dialog_new_with_buttons (title, parent, |
---|
| 64 | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL, |
---|
| 65 | GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
---|
| 66 | GTK_STOCK_OK, GTK_RESPONSE_OK, |
---|
| 67 | NULL); |
---|
| 68 | gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); |
---|
| 69 | gtk_window_set_default_size (GTK_WINDOW (dialog), 275, -1); |
---|
| 70 | gtk_container_set_border_width (GTK_CONTAINER (dialog), 6); |
---|
[16769] | 71 | |
---|
[19540] | 72 | vbox = GTK_DIALOG (dialog)->vbox; |
---|
| 73 | |
---|
[16769] | 74 | prompt_label = gtk_label_new (prompt); |
---|
[19540] | 75 | gtk_box_pack_start (GTK_BOX (vbox), prompt_label, TRUE, TRUE, 6); |
---|
| 76 | gtk_box_set_spacing (GTK_BOX (vbox), 6); |
---|
[16769] | 77 | |
---|
| 78 | entry = gtk_entry_new (); |
---|
[19540] | 79 | gtk_entry_set_text (GTK_ENTRY (entry), default_string); |
---|
| 80 | gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1); |
---|
| 81 | gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE); |
---|
| 82 | gtk_box_pack_start (GTK_BOX (vbox), entry, TRUE, TRUE, 3); |
---|
| 83 | |
---|
[16769] | 84 | gtk_widget_grab_focus (entry); |
---|
[19540] | 85 | |
---|
[16769] | 86 | gtk_widget_show (prompt_label); |
---|
| 87 | gtk_widget_show (entry); |
---|
| 88 | gtk_widget_show (dialog); |
---|
[19540] | 89 | |
---|
| 90 | switch (gtk_dialog_run (GTK_DIALOG (dialog))) { |
---|
| 91 | case GTK_RESPONSE_OK: |
---|
| 92 | text = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry))); |
---|
[16769] | 93 | break; |
---|
| 94 | default: |
---|
[19540] | 95 | text = NULL; |
---|
| 96 | break; |
---|
[16769] | 97 | } |
---|
| 98 | |
---|
| 99 | gtk_widget_destroy (dialog); |
---|
[19540] | 100 | |
---|
| 101 | return text; |
---|
[16769] | 102 | } |
---|