2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2001 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.
26 #include <gdk/gdkkeysyms.h>
29 #include "mainwindow.h"
30 #include "alertpanel.h"
31 #include "manage_window.h"
35 #include "logwindow.h"
36 #include "prefs_common.h"
38 #define ALERT_PANEL_WIDTH 380
39 #define TITLE_HEIGHT 72
40 #define MESSAGE_HEIGHT 62
42 #define DEFAULT_TITLE_FONT "Helvetica 16"
44 static gboolean alertpanel_is_open = FALSE;
45 static AlertValue value;
47 static GtkWidget *dialog;
49 static void alertpanel_show (void);
50 static void alertpanel_create (const gchar *title,
52 const gchar *button1_label,
53 const gchar *button2_label,
54 const gchar *button3_label,
56 GtkWidget *custom_widget);
58 static void alertpanel_button_toggled (GtkToggleButton *button,
60 static void alertpanel_button_clicked (GtkWidget *widget,
62 static gint alertpanel_deleted (GtkWidget *widget,
65 static gboolean alertpanel_close (GtkWidget *widget,
69 AlertValue alertpanel(const gchar *title,
71 const gchar *button1_label,
72 const gchar *button2_label,
73 const gchar *button3_label)
75 if (alertpanel_is_open)
78 alertpanel_is_open = TRUE;
80 alertpanel_create(title, message, button1_label, button2_label,
81 button3_label, FALSE, NULL);
84 debug_print("return value = %d\n", value);
88 AlertValue alertpanel_with_widget(const gchar *title,
90 const gchar *button1_label,
91 const gchar *button2_label,
92 const gchar *button3_label,
95 if (alertpanel_is_open)
98 alertpanel_is_open = TRUE;
99 alertpanel_create(title, message, button1_label, button2_label,
100 button3_label, FALSE, widget);
103 debug_print("return value = %d\n", value);
106 void alertpanel_message(const gchar *title, const gchar *message)
108 if (alertpanel_is_open)
111 alertpanel_is_open = TRUE;
113 alertpanel_create(title, message, NULL, NULL, NULL, FALSE, NULL);
117 AlertValue alertpanel_message_with_disable(const gchar *title,
118 const gchar *message)
120 if (alertpanel_is_open)
123 alertpanel_is_open = TRUE;
125 alertpanel_create(title, message, NULL, NULL, NULL, TRUE, NULL);
131 void alertpanel_notice(const gchar *format, ...)
136 va_start(args, format);
137 g_vsnprintf(buf, sizeof(buf), format, args);
141 alertpanel_message(_("Notice"), buf);
144 void alertpanel_warning(const gchar *format, ...)
149 va_start(args, format);
150 g_vsnprintf(buf, sizeof(buf), format, args);
154 alertpanel_message(_("Warning"), buf);
157 void alertpanel_error(const gchar *format, ...)
162 va_start(args, format);
163 g_vsnprintf(buf, sizeof(buf), format, args);
167 alertpanel_message(_("Error"), buf);
171 *\brief display an error with a View Log button
174 void alertpanel_error_log(const gchar *format, ...)
181 va_start(args, format);
182 g_vsnprintf(buf, sizeof(buf), format, args);
186 mainwin = mainwindow_get_mainwindow();
188 if (mainwin && mainwin->logwin) {
189 val = alertpanel(_("Error"), buf, _("OK"), _("View log"), NULL);
190 if (val == G_ALERTALTERNATE)
191 log_window_show(mainwin->logwin);
193 alertpanel_error(buf);
196 static void alertpanel_show(void)
198 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
199 manage_window_set_transient(GTK_WINDOW(dialog));
202 if (gdk_pointer_is_grabbed())
203 gdk_pointer_ungrab(GDK_CURRENT_TIME);
205 while ((value & G_ALERT_VALUE_MASK) == G_ALERTWAIT)
206 gtk_main_iteration();
208 gtk_widget_destroy(dialog);
211 alertpanel_is_open = FALSE;
215 static void alertpanel_create(const gchar *title,
216 const gchar *message,
217 const gchar *button1_label,
218 const gchar *button2_label,
219 const gchar *button3_label,
220 gboolean can_disable,
221 GtkWidget *custom_widget)
223 static PangoFontDescription *font_desc;
229 GtkWidget *disable_chkbtn;
230 GtkWidget *confirm_area;
237 debug_print("Creating alert panel dialog...\n");
239 dialog = gtk_dialog_new();
240 gtk_window_set_title(GTK_WINDOW(dialog), title);
241 gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, FALSE, FALSE);
242 gtk_container_set_border_width
243 (GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), 5);
244 gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
245 g_signal_connect(G_OBJECT(dialog), "delete_event",
246 G_CALLBACK(alertpanel_deleted),
247 (gpointer)G_ALERTOTHER);
248 g_signal_connect(G_OBJECT(dialog), "key_press_event",
249 G_CALLBACK(alertpanel_close),
250 (gpointer)G_ALERTOTHER);
251 gtk_widget_realize(dialog);
253 /* for title label */
254 hbox = gtk_hbox_new(FALSE, 0);
255 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
256 hbox, TRUE, TRUE, 16);
259 /* pixmapwid = create_pixmapwid(dialog, GNUstep_xpm); */
260 /* gtk_box_pack_start(GTK_BOX(hbox), pixmapwid, FALSE, FALSE, 16); */
261 label = gtk_label_new(title);
262 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 16);
263 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
265 gchar *fontstr = prefs_common.titlefont
266 ? prefs_common.titlefont
267 : DEFAULT_TITLE_FONT;
268 font_desc = pango_font_description_from_string (fontstr);
271 gtk_widget_modify_font (label, font_desc);
274 /* for message and button(s) */
275 vbox = gtk_vbox_new(FALSE, 0);
276 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area),
279 spc_vbox = gtk_vbox_new(FALSE, 0);
280 gtk_box_pack_start(GTK_BOX(vbox), spc_vbox, FALSE, FALSE, 0);
281 gtk_widget_set_size_request(spc_vbox, -1, 16);
283 msg_vbox = gtk_vbox_new(FALSE, 0);
284 gtk_box_pack_start(GTK_BOX(vbox), msg_vbox, FALSE, FALSE, 0);
286 /* for message label */
287 hbox = gtk_hbox_new(FALSE, 0);
288 gtk_box_pack_start(GTK_BOX(msg_vbox), hbox, FALSE, FALSE, 0);
291 label = gtk_label_new(message);
292 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 24);
293 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
295 /* Claws: custom widget */
297 GtkWidget *custom_hbox = gtk_hbox_new(FALSE, 0);
298 gtk_box_pack_start(GTK_BOX(msg_vbox), custom_hbox, FALSE,
300 gtk_box_pack_start(GTK_BOX(custom_hbox), custom_widget, FALSE,
304 hbox = gtk_hbox_new(FALSE, 0);
305 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
306 gtk_container_set_border_width(GTK_CONTAINER(hbox), 8);
308 disable_chkbtn = gtk_check_button_new_with_label
309 (_("Show this message next time"));
310 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(disable_chkbtn),
312 gtk_box_pack_start(GTK_BOX(hbox), disable_chkbtn,
314 g_signal_connect(G_OBJECT(disable_chkbtn), "toggled",
315 G_CALLBACK(alertpanel_button_toggled),
316 GUINT_TO_POINTER(G_ALERTDISABLE));
318 spc_vbox = gtk_vbox_new(FALSE, 0);
319 gtk_box_pack_start(GTK_BOX(vbox), spc_vbox, FALSE, FALSE, 0);
320 gtk_widget_set_size_request(spc_vbox, -1, 20);
325 button1_label = _("OK");
326 label2 = button2_label;
327 label3 = button3_label;
328 if (label2 && *label2 == '+') label2++;
329 if (label3 && *label3 == '+') label3++;
331 gtkut_button_set_create(&confirm_area,
332 &button1, button1_label,
333 button2_label ? &button2 : NULL, label2,
334 button3_label ? &button3 : NULL, label3);
336 gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
337 gtk_widget_grab_default(button1);
338 gtk_widget_grab_focus(button1);
339 if (button2_label && *button2_label == '+') {
340 gtk_widget_grab_default(button2);
341 gtk_widget_grab_focus(button2);
343 if (button3_label && *button3_label == '+') {
344 gtk_widget_grab_default(button3);
345 gtk_widget_grab_focus(button3);
348 g_signal_connect(G_OBJECT(button1), "clicked",
349 G_CALLBACK(alertpanel_button_clicked),
350 GUINT_TO_POINTER(G_ALERTDEFAULT));
352 g_signal_connect(G_OBJECT(button2), "clicked",
353 G_CALLBACK(alertpanel_button_clicked),
354 GUINT_TO_POINTER(G_ALERTALTERNATE));
356 g_signal_connect(G_OBJECT(button3), "clicked",
357 G_CALLBACK(alertpanel_button_clicked),
358 GUINT_TO_POINTER(G_ALERTOTHER));
360 gtk_widget_show_all(dialog);
363 static void alertpanel_button_toggled(GtkToggleButton *button,
366 if (gtk_toggle_button_get_active(button))
367 value &= ~GPOINTER_TO_UINT(data);
369 value |= GPOINTER_TO_UINT(data);
372 static void alertpanel_button_clicked(GtkWidget *widget, gpointer data)
374 value = (value & ~G_ALERT_VALUE_MASK) | (AlertValue)data;
377 static gint alertpanel_deleted(GtkWidget *widget, GdkEventAny *event,
380 value = (value & ~G_ALERT_VALUE_MASK) | (AlertValue)data;
384 static gboolean alertpanel_close(GtkWidget *widget, GdkEventAny *event,
387 if (event->type == GDK_KEY_PRESS)
388 if (((GdkEventKey *)event)->keyval != GDK_Escape)
391 value = (value & ~G_ALERT_VALUE_MASK) | (AlertValue)data;