2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 #include <glib/gi18n.h>
29 #include <gdk/gdkkeysyms.h>
31 #include "mainwindow.h"
32 #include "alertpanel.h"
33 #include "manage_window.h"
37 #include "logwindow.h"
38 #include "prefs_common.h"
40 #define ALERT_PANEL_WIDTH 380
41 #define TITLE_HEIGHT 72
42 #define MESSAGE_HEIGHT 62
44 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 AlertValue default_value);
60 static void alertpanel_button_toggled (GtkToggleButton *button,
62 static void alertpanel_button_clicked (GtkWidget *widget,
64 static gint alertpanel_deleted (GtkWidget *widget,
67 static gboolean alertpanel_close (GtkWidget *widget,
71 AlertValue alertpanel_with_widget(const gchar *title,
73 const gchar *button1_label,
74 const gchar *button2_label,
75 const gchar *button3_label,
79 return alertpanel_full(title, message, button1_label,
80 button2_label, button3_label,
81 can_disable, widget, ALERT_QUESTION,
85 AlertValue alertpanel_full(const gchar *title, const gchar *message,
86 const gchar *button1_label,
87 const gchar *button2_label,
88 const gchar *button3_label,
92 AlertValue default_value)
94 if (alertpanel_is_open)
97 alertpanel_is_open = TRUE;
99 alertpanel_create(title, message, button1_label, button2_label,
100 button3_label, can_disable, widget, alert_type,
104 debug_print("return value = %d\n", value);
108 AlertValue alertpanel(const gchar *title,
109 const gchar *message,
110 const gchar *button1_label,
111 const gchar *button2_label,
112 const gchar *button3_label)
114 return alertpanel_full(title, message, button1_label, button2_label,
115 button3_label, FALSE, NULL, ALERT_QUESTION,
119 static void alertpanel_message(const gchar *title, const gchar *message, gint type)
121 if (alertpanel_is_open)
124 alertpanel_is_open = TRUE;
126 alertpanel_create(title, message, GTK_STOCK_CLOSE, NULL, NULL,
127 FALSE, NULL, type, G_ALERTDEFAULT);
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, ALERT_NOTICE);
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, ALERT_WARNING);
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, ALERT_ERROR);
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 mainwindow_clear_error(mainwin);
190 val = alertpanel_full(_("Error"), buf, GTK_STOCK_CLOSE,
191 _("_View log"), NULL, FALSE, NULL,
192 ALERT_ERROR, G_ALERTDEFAULT);
193 if (val == G_ALERTALTERNATE)
194 log_window_show(mainwin->logwin);
196 alertpanel_error(buf);
199 static void alertpanel_show(void)
201 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
202 manage_window_set_transient(GTK_WINDOW(dialog));
205 if (gdk_pointer_is_grabbed())
206 gdk_pointer_ungrab(GDK_CURRENT_TIME);
208 while ((value & G_ALERT_VALUE_MASK) == G_ALERTWAIT)
209 gtk_main_iteration();
211 gtk_widget_destroy(dialog);
214 alertpanel_is_open = FALSE;
218 static void alertpanel_create(const gchar *title,
219 const gchar *message,
220 const gchar *button1_label,
221 const gchar *button2_label,
222 const gchar *button3_label,
223 gboolean can_disable,
224 GtkWidget *custom_widget,
226 AlertValue default_value)
228 static PangoFontDescription *font_desc;
233 GtkWidget *disable_checkbtn;
234 GtkWidget *confirm_area;
240 gchar *tmp = title?g_markup_printf_escaped("%s", title)
242 gchar *title_full = g_strdup_printf("<span weight=\"bold\" "
243 "size=\"larger\">%s</span>",
246 debug_print("Creating alert panel dialog...\n");
248 dialog = gtk_dialog_new();
249 gtk_window_set_title(GTK_WINDOW(dialog), title);
250 gtk_window_set_resizable(GTK_WINDOW(dialog), TRUE);
252 gtk_window_set_default_size(GTK_WINDOW(dialog), 375, 100);
253 gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
255 gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
256 g_signal_connect(G_OBJECT(dialog), "delete_event",
257 G_CALLBACK(alertpanel_deleted),
258 (gpointer)G_ALERTCANCEL);
259 g_signal_connect(G_OBJECT(dialog), "key_press_event",
260 G_CALLBACK(alertpanel_close),
261 (gpointer)G_ALERTCANCEL);
263 /* for title icon, label and message */
264 hbox = gtk_hbox_new(FALSE, 12);
265 gtk_container_set_border_width(GTK_CONTAINER(hbox), 12);
266 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
267 hbox, FALSE, FALSE, 0);
270 switch (alert_type) {
272 image = gtk_image_new_from_stock
273 (GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG);
276 image = gtk_image_new_from_stock
277 (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_DIALOG);
280 image = gtk_image_new_from_stock
281 (GTK_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_DIALOG);
285 image = gtk_image_new_from_stock
286 (GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_DIALOG);
289 gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.0);
290 gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0);
292 vbox = gtk_vbox_new (FALSE, 12);
293 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
294 gtk_widget_show (vbox);
296 label = gtk_label_new(title_full);
297 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
298 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
299 gtk_label_set_use_markup(GTK_LABEL (label), TRUE);
300 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
301 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
305 size = pango_font_description_get_size
306 (label->style->font_desc);
307 font_desc = pango_font_description_new();
308 pango_font_description_set_weight
309 (font_desc, PANGO_WEIGHT_BOLD);
310 pango_font_description_set_size
311 (font_desc, size * PANGO_SCALE_LARGE);
314 gtk_widget_modify_font(label, font_desc);
317 label = gtk_label_new(message);
318 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
319 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
320 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
321 gtk_label_set_selectable(GTK_LABEL(label), TRUE);
322 gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
323 GTK_WIDGET_UNSET_FLAGS(label, GTK_CAN_FOCUS);
324 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
325 gtk_widget_show(label);
327 /* Claws: custom widget */
329 gtk_box_pack_start(GTK_BOX(vbox), custom_widget, FALSE,
334 hbox = gtk_hbox_new(FALSE, 0);
335 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox,
338 disable_checkbtn = gtk_check_button_new_with_label
339 (_("Show this message next time"));
340 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(disable_checkbtn),
342 gtk_box_pack_start(GTK_BOX(hbox), disable_checkbtn,
344 g_signal_connect(G_OBJECT(disable_checkbtn), "toggled",
345 G_CALLBACK(alertpanel_button_toggled),
346 GUINT_TO_POINTER(G_ALERTDISABLE));
351 button1_label = GTK_STOCK_OK;
352 label2 = button2_label;
353 label3 = button3_label;
354 if (label2 && *label2 == '+') label2++;
355 if (label3 && *label3 == '+') label3++;
357 gtkut_stock_button_set_create(&confirm_area,
358 &button1, button1_label,
359 button2_label ? &button2 : NULL, label2,
360 button3_label ? &button3 : NULL, label3);
362 gtk_box_pack_end(GTK_BOX(GTK_DIALOG(dialog)->action_area),
363 confirm_area, FALSE, FALSE, 0);
364 gtk_container_set_border_width(GTK_CONTAINER(confirm_area), 5);
365 gtk_widget_grab_default(button1);
366 gtk_widget_grab_focus(button1);
368 (default_value == G_ALERTALTERNATE || *button2_label == '+')) {
369 gtk_widget_grab_default(button2);
370 gtk_widget_grab_focus(button2);
373 (default_value == G_ALERTOTHER || *button3_label == '+')) {
374 gtk_widget_grab_default(button3);
375 gtk_widget_grab_focus(button3);
378 g_signal_connect(G_OBJECT(button1), "clicked",
379 G_CALLBACK(alertpanel_button_clicked),
380 GUINT_TO_POINTER(G_ALERTDEFAULT));
382 g_signal_connect(G_OBJECT(button2), "clicked",
383 G_CALLBACK(alertpanel_button_clicked),
384 GUINT_TO_POINTER(G_ALERTALTERNATE));
386 g_signal_connect(G_OBJECT(button3), "clicked",
387 G_CALLBACK(alertpanel_button_clicked),
388 GUINT_TO_POINTER(G_ALERTOTHER));
390 gtk_widget_show_all(dialog);
393 static void alertpanel_button_toggled(GtkToggleButton *button,
396 if (gtk_toggle_button_get_active(button))
397 value &= ~GPOINTER_TO_UINT(data);
399 value |= GPOINTER_TO_UINT(data);
402 static void alertpanel_button_clicked(GtkWidget *widget, gpointer data)
404 value = (value & ~G_ALERT_VALUE_MASK) | (AlertValue)data;
407 static gint alertpanel_deleted(GtkWidget *widget, GdkEventAny *event,
410 value = (value & ~G_ALERT_VALUE_MASK) | (AlertValue)data;
414 static gboolean alertpanel_close(GtkWidget *widget, GdkEventAny *event,
417 if (event->type == GDK_KEY_PRESS)
418 if (((GdkEventKey *)event)->keyval != GDK_Escape)
421 value = (value & ~G_ALERT_VALUE_MASK) | (AlertValue)data;