/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2005 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#define TITLE_HEIGHT 72
#define MESSAGE_HEIGHT 62
-static gboolean alertpanel_is_open = FALSE;
+gboolean alertpanel_is_open = FALSE;
static AlertValue value;
static GtkWidget *dialog;
const gchar *button3_label,
gboolean can_disable,
GtkWidget *custom_widget,
- gint alert_type);
+ gint alert_type,
+ AlertValue default_value);
static void alertpanel_button_toggled (GtkToggleButton *button,
gpointer data);
GdkEventAny *event,
gpointer data);
-AlertValue alertpanel(const gchar *title,
- const gchar *message,
- const gchar *button1_label,
- const gchar *button2_label,
- const gchar *button3_label)
-{
- return alertpanel_with_type(title, message, button1_label,
- button2_label, button3_label,
- NULL, ALERT_QUESTION);
-}
-
AlertValue alertpanel_with_widget(const gchar *title,
const gchar *message,
const gchar *button1_label,
const gchar *button2_label,
const gchar *button3_label,
+ gboolean can_disable,
GtkWidget *widget)
{
- return alertpanel_with_type(title, message, button1_label,
+ return alertpanel_full(title, message, button1_label,
button2_label, button3_label,
- widget, ALERT_QUESTION);
+ can_disable, widget, ALERT_QUESTION,
+ G_ALERTDEFAULT);
}
-AlertValue alertpanel_with_type(const gchar *title,
- const gchar *message,
- const gchar *button1_label,
- const gchar *button2_label,
- const gchar *button3_label,
- GtkWidget *widget,
- gint alert_type)
+AlertValue alertpanel_full(const gchar *title, const gchar *message,
+ const gchar *button1_label,
+ const gchar *button2_label,
+ const gchar *button3_label,
+ gboolean can_disable,
+ GtkWidget *widget,
+ AlertType alert_type,
+ AlertValue default_value)
{
if (alertpanel_is_open)
return -1;
alertpanel_is_open = TRUE;
alertpanel_create(title, message, button1_label, button2_label,
- button3_label, FALSE, widget, alert_type);
+ button3_label, can_disable, widget, alert_type,
+ default_value);
alertpanel_show();
debug_print("return value = %d\n", value);
return value;
}
-static void alertpanel_message(const gchar *title, const gchar *message, gint type)
+AlertValue alertpanel(const gchar *title,
+ const gchar *message,
+ const gchar *button1_label,
+ const gchar *button2_label,
+ const gchar *button3_label)
{
- if (alertpanel_is_open)
- return;
- else
- alertpanel_is_open = TRUE;
-
- alertpanel_create(title, message, NULL, NULL, NULL, FALSE, NULL, type);
- alertpanel_show();
+ return alertpanel_full(title, message, button1_label, button2_label,
+ button3_label, FALSE, NULL, ALERT_QUESTION,
+ G_ALERTDEFAULT);
}
-AlertValue alertpanel_message_with_disable(const gchar *title,
- const gchar *message,
- const gchar *button1_label,
- const gchar *button2_label,
- const gchar *button3_label,
- gint alert_type)
+static void alertpanel_message(const gchar *title, const gchar *message, gint type)
{
if (alertpanel_is_open)
- return 0;
+ return;
else
alertpanel_is_open = TRUE;
- alertpanel_create(title, message, button1_label, button2_label,
- button3_label, TRUE, NULL, alert_type);
+ alertpanel_create(title, message, GTK_STOCK_CLOSE, NULL, NULL,
+ FALSE, NULL, type, G_ALERTDEFAULT);
alertpanel_show();
-
- return value;
}
void alertpanel_notice(const gchar *format, ...)
void alertpanel_error(const gchar *format, ...)
{
va_list args;
- gchar buf[256];
+ gchar buf[512];
va_start(args, format);
g_vsnprintf(buf, sizeof(buf), format, args);
mainwin = mainwindow_get_mainwindow();
if (mainwin && mainwin->logwin) {
- val = alertpanel_with_type(_("Error"), buf, _("OK"), _("View log"), NULL, NULL, ALERT_ERROR);
+ mainwindow_clear_error(mainwin);
+ val = alertpanel_full(_("Error"), buf, GTK_STOCK_CLOSE,
+ _("_View log"), NULL, FALSE, NULL,
+ ALERT_ERROR, G_ALERTDEFAULT);
if (val == G_ALERTALTERNATE)
log_window_show(mainwin->logwin);
} else
const gchar *button3_label,
gboolean can_disable,
GtkWidget *custom_widget,
- gint alert_type)
+ gint alert_type,
+ AlertValue default_value)
{
static PangoFontDescription *font_desc;
+ GtkWidget *image;
GtkWidget *label;
- GtkWidget *w_hbox;
GtkWidget *hbox;
GtkWidget *vbox;
- GtkWidget *disable_chkbtn;
+ GtkWidget *disable_checkbtn;
GtkWidget *confirm_area;
GtkWidget *button1;
GtkWidget *button2;
GtkWidget *button3;
- GtkWidget *icon;
const gchar *label2;
const gchar *label3;
- GdkGeometry geometry;
-
+ gchar *tmp = title?g_markup_printf_escaped("%s", title)
+ :g_strdup("");
gchar *title_full = g_strdup_printf("<span weight=\"bold\" "
"size=\"larger\">%s</span>",
- title?title:"");
-
- gchar *icon_desc[] = { GTK_STOCK_DIALOG_INFO,
- GTK_STOCK_DIALOG_QUESTION,
- GTK_STOCK_DIALOG_WARNING,
- GTK_STOCK_DIALOG_ERROR };
-
+ tmp);
+ g_free(tmp);
debug_print("Creating alert panel dialog...\n");
dialog = gtk_dialog_new();
gtk_window_set_title(GTK_WINDOW(dialog), title);
- gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE);
-
- geometry.min_width = 300;
- geometry.min_height = 100;
-
- gtk_window_set_geometry_hints(GTK_WINDOW(dialog), NULL, &geometry,
- GDK_HINT_MIN_SIZE);
+ gtk_window_set_resizable(GTK_WINDOW(dialog), TRUE);
+
+ gtk_window_set_default_size(GTK_WINDOW(dialog), 375, 100);
gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
g_signal_connect(G_OBJECT(dialog), "delete_event",
G_CALLBACK(alertpanel_deleted),
- (gpointer)G_ALERTOTHER);
+ (gpointer)G_ALERTCANCEL);
g_signal_connect(G_OBJECT(dialog), "key_press_event",
G_CALLBACK(alertpanel_close),
- (gpointer)G_ALERTOTHER);
-
- gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 14);
- hbox = gtk_hbox_new (FALSE, 12);
- gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
- gtk_widget_show (hbox);
- gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox,
- FALSE, FALSE, 0);
+ (gpointer)G_ALERTCANCEL);
+
+ /* for title icon, label and message */
+ hbox = gtk_hbox_new(FALSE, 12);
+ gtk_container_set_border_width(GTK_CONTAINER(hbox), 12);
+ gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
+ hbox, FALSE, FALSE, 0);
+
+ /* title icon */
+ switch (alert_type) {
+ case ALERT_QUESTION:
+ image = gtk_image_new_from_stock
+ (GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG);
+ break;
+ case ALERT_WARNING:
+ image = gtk_image_new_from_stock
+ (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_DIALOG);
+ break;
+ case ALERT_ERROR:
+ image = gtk_image_new_from_stock
+ (GTK_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_DIALOG);
+ break;
+ case ALERT_NOTICE:
+ default:
+ image = gtk_image_new_from_stock
+ (GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_DIALOG);
+ break;
+ }
+ gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.0);
+ gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0);
- /* for title label */
- w_hbox = gtk_hbox_new(FALSE, 0);
-
- if (alert_type < 0 || alert_type > 3)
- alert_type = 0;
-
- icon = gtk_image_new_from_stock(icon_desc[alert_type],
- GTK_ICON_SIZE_DIALOG);
- gtk_misc_set_alignment (GTK_MISC (icon), 0.5, 0.0);
- gtk_box_pack_start (GTK_BOX (hbox), icon, FALSE, FALSE, 0);
-
vbox = gtk_vbox_new (FALSE, 12);
gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
gtk_widget_show (vbox);
gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
gtk_label_set_selectable(GTK_LABEL(label), TRUE);
+ gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
+ GTK_WIDGET_UNSET_FLAGS(label, GTK_CAN_FOCUS);
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
gtk_widget_show(label);
gtk_box_pack_start(GTK_BOX(vbox), custom_widget, FALSE,
FALSE, 0);
}
-
+
if (can_disable) {
hbox = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox,
FALSE, FALSE, 0);
- disable_chkbtn = gtk_check_button_new_with_label
+ disable_checkbtn = gtk_check_button_new_with_label
(_("Show this message next time"));
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(disable_chkbtn),
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(disable_checkbtn),
TRUE);
- gtk_box_pack_start(GTK_BOX(hbox), disable_chkbtn,
+ gtk_box_pack_start(GTK_BOX(hbox), disable_checkbtn,
FALSE, FALSE, 12);
- g_signal_connect(G_OBJECT(disable_chkbtn), "toggled",
+ g_signal_connect(G_OBJECT(disable_checkbtn), "toggled",
G_CALLBACK(alertpanel_button_toggled),
GUINT_TO_POINTER(G_ALERTDISABLE));
}
gtk_container_set_border_width(GTK_CONTAINER(confirm_area), 5);
gtk_widget_grab_default(button1);
gtk_widget_grab_focus(button1);
- if (button2_label && *button2_label == '+') {
+ if (button2_label &&
+ (default_value == G_ALERTALTERNATE || *button2_label == '+')) {
gtk_widget_grab_default(button2);
gtk_widget_grab_focus(button2);
}
- if (button3_label && *button3_label == '+') {
+ if (button3_label &&
+ (default_value == G_ALERTOTHER || *button3_label == '+')) {
gtk_widget_grab_default(button3);
gtk_widget_grab_focus(button3);
}