2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2002 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include <gdk/gdkkeysyms.h>
26 #include <gtk/gtkmain.h>
27 #include <gtk/gtkwidget.h>
28 #include <gtk/gtkdialog.h>
29 #include <gtk/gtkwindow.h>
30 #include <gtk/gtksignal.h>
31 #include <gtk/gtkvbox.h>
32 #include <gtk/gtkhbox.h>
33 #include <gtk/gtklabel.h>
34 #include <gtk/gtkentry.h>
35 #include <gtk/gtkcombo.h>
36 #include <gtk/gtkbutton.h>
37 #include <gtk/gtkhbbox.h>
40 #include "inputdialog.h"
41 #include "manage_window.h"
45 #define INPUT_DIALOG_WIDTH 420
50 INPUT_DIALOG_INVISIBLE
,
56 static InputDialogType type
;
58 static GtkWidget
*dialog
;
59 static GtkWidget
*msg_label
;
60 static GtkWidget
*entry
;
61 static GtkWidget
*combo
;
62 static GtkWidget
*ok_button
;
64 static void input_dialog_create (void);
65 static gchar
*input_dialog_open (const gchar
*title
,
67 const gchar
*default_string
);
68 static void input_dialog_set (const gchar
*title
,
70 const gchar
*default_string
);
72 static void ok_clicked (GtkWidget
*widget
,
74 static void cancel_clicked (GtkWidget
*widget
,
76 static gint
delete_event (GtkWidget
*widget
,
79 static void key_pressed (GtkWidget
*widget
,
82 static void entry_activated (GtkEditable
*editable
);
83 static void combo_activated (GtkEditable
*editable
);
86 gchar
*input_dialog(const gchar
*title
, const gchar
*message
,
87 const gchar
*default_string
)
89 if (dialog
&& GTK_WIDGET_VISIBLE(dialog
)) return NULL
;
92 input_dialog_create();
94 type
= INPUT_DIALOG_NORMAL
;
95 gtk_widget_hide(combo
);
96 gtk_widget_show(entry
);
97 gtk_entry_set_visibility(GTK_ENTRY(entry
), TRUE
);
99 return input_dialog_open(title
, message
, default_string
);
102 gchar
*input_dialog_with_invisible(const gchar
*title
, const gchar
*message
,
103 const gchar
*default_string
)
105 if (dialog
&& GTK_WIDGET_VISIBLE(dialog
)) return NULL
;
108 input_dialog_create();
110 type
= INPUT_DIALOG_INVISIBLE
;
111 gtk_widget_hide(combo
);
112 gtk_widget_show(entry
);
113 gtk_entry_set_visibility(GTK_ENTRY(entry
), FALSE
);
115 return input_dialog_open(title
, message
, default_string
);
118 gchar
*input_dialog_combo(const gchar
*title
, const gchar
*message
,
119 const gchar
*default_string
, GList
*list
,
120 gboolean case_sensitive
)
122 if (dialog
&& GTK_WIDGET_VISIBLE(dialog
)) return NULL
;
125 input_dialog_create();
127 type
= INPUT_DIALOG_COMBO
;
128 gtk_widget_hide(entry
);
129 gtk_widget_show(combo
);
134 empty_list
.data
= (gpointer
)"";
135 empty_list
.next
= NULL
;
136 empty_list
.prev
= NULL
;
137 gtk_combo_set_popdown_strings(GTK_COMBO(combo
), &empty_list
);
139 gtk_combo_set_popdown_strings(GTK_COMBO(combo
), list
);
141 gtk_combo_set_case_sensitive(GTK_COMBO(combo
), case_sensitive
);
143 return input_dialog_open(title
, message
, default_string
);
146 gchar
*input_dialog_query_password(const gchar
*server
, const gchar
*user
)
151 message
= g_strdup_printf(_("Input password for %s on %s:"),
153 pass
= input_dialog_with_invisible(_("Input password"), message
, NULL
);
159 static void input_dialog_create(void)
163 GtkWidget
*confirm_area
;
164 GtkWidget
*cancel_button
;
166 dialog
= gtk_dialog_new();
167 gtk_window_set_policy(GTK_WINDOW(dialog
), FALSE
, FALSE
, FALSE
);
168 gtk_widget_set_usize(dialog
, INPUT_DIALOG_WIDTH
, -1);
169 gtk_container_set_border_width
170 (GTK_CONTAINER(GTK_DIALOG(dialog
)->action_area
), 5);
171 gtk_window_set_position(GTK_WINDOW(dialog
), GTK_WIN_POS_CENTER
);
172 gtk_signal_connect(GTK_OBJECT(dialog
), "delete_event",
173 GTK_SIGNAL_FUNC(delete_event
), NULL
);
174 gtk_signal_connect(GTK_OBJECT(dialog
), "key_press_event",
175 GTK_SIGNAL_FUNC(key_pressed
), NULL
);
176 MANAGE_WINDOW_SIGNALS_CONNECT(dialog
);
178 gtk_widget_realize(dialog
);
180 vbox
= gtk_vbox_new(FALSE
, 8);
181 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog
)->vbox
), vbox
);
182 gtk_container_set_border_width(GTK_CONTAINER(vbox
), 8);
184 hbox
= gtk_hbox_new(FALSE
, 0);
185 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 0);
187 msg_label
= gtk_label_new("");
188 gtk_box_pack_start(GTK_BOX(hbox
), msg_label
, FALSE
, FALSE
, 0);
189 gtk_label_set_justify(GTK_LABEL(msg_label
), GTK_JUSTIFY_LEFT
);
191 entry
= gtk_entry_new();
192 gtk_box_pack_start(GTK_BOX(vbox
), entry
, FALSE
, FALSE
, 0);
193 gtk_signal_connect(GTK_OBJECT(entry
), "activate",
194 GTK_SIGNAL_FUNC(entry_activated
), NULL
);
196 combo
= gtk_combo_new();
197 gtk_box_pack_start(GTK_BOX(vbox
), combo
, FALSE
, FALSE
, 0);
198 gtk_signal_connect(GTK_OBJECT(GTK_COMBO(combo
)->entry
), "activate",
199 GTK_SIGNAL_FUNC(combo_activated
), NULL
);
201 gtkut_button_set_create(&confirm_area
,
203 &cancel_button
, _("Cancel"),
205 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog
)->action_area
),
207 gtk_widget_grab_default(ok_button
);
209 gtk_signal_connect(GTK_OBJECT(ok_button
), "clicked",
210 GTK_SIGNAL_FUNC(ok_clicked
), NULL
);
211 gtk_signal_connect(GTK_OBJECT(cancel_button
), "clicked",
212 GTK_SIGNAL_FUNC(cancel_clicked
), NULL
);
215 gtk_widget_show_all(GTK_DIALOG(dialog
)->vbox
);
218 static gchar
*input_dialog_open(const gchar
*title
, const gchar
*message
,
219 const gchar
*default_string
)
223 if (dialog
&& GTK_WIDGET_VISIBLE(dialog
)) return NULL
;
226 input_dialog_create();
228 input_dialog_set(title
, message
, default_string
);
229 gtk_widget_show(dialog
);
230 gtk_window_set_modal(GTK_WINDOW(dialog
), TRUE
);
231 manage_window_set_transient(GTK_WINDOW(dialog
));
235 manage_window_focus_out(dialog
, NULL
, NULL
);
236 gtk_widget_hide(dialog
);
239 GtkEditable
*editable
;
241 if (type
== INPUT_DIALOG_COMBO
)
242 editable
= GTK_EDITABLE(GTK_COMBO(combo
)->entry
);
244 editable
= GTK_EDITABLE(entry
);
246 str
= gtk_editable_get_chars(editable
, 0, -1);
247 if (str
&& *str
== '\0') {
256 debug_print("return string = %s\n", str
? str
: "(none)");
260 static void input_dialog_set(const gchar
*title
, const gchar
*message
,
261 const gchar
*default_string
)
265 if (type
== INPUT_DIALOG_COMBO
)
266 entry_
= GTK_COMBO(combo
)->entry
;
270 gtk_window_set_title(GTK_WINDOW(dialog
), title
);
271 gtk_label_set_text(GTK_LABEL(msg_label
), message
);
272 if (default_string
&& *default_string
)
273 gtk_entry_set_text(GTK_ENTRY(entry_
), default_string
);
275 gtk_entry_set_text(GTK_ENTRY(entry_
), "");
276 gtk_entry_set_position(GTK_ENTRY(entry_
), 0);
277 gtk_entry_select_region(GTK_ENTRY(entry_
), 0, -1);
279 gtk_widget_grab_focus(ok_button
);
280 gtk_widget_grab_focus(entry_
);
283 static void ok_clicked(GtkWidget
*widget
, gpointer data
)
289 static void cancel_clicked(GtkWidget
*widget
, gpointer data
)
295 static gint
delete_event(GtkWidget
*widget
, GdkEventAny
*event
, gpointer data
)
303 static void key_pressed(GtkWidget
*widget
, GdkEventKey
*event
, gpointer data
)
305 if (event
&& event
->keyval
== GDK_Escape
) {
311 static void entry_activated(GtkEditable
*editable
)
317 static void combo_activated(GtkEditable
*editable
)