2007-06-17 [paul] 2.9.2cvs66
[claws.git] / src / alertpanel.c
index ca1475a1c3bd682297dc8890e7a9f7ea2ed0b02c..975ad203c0fd172ccda6a536acc9d3515ff78899 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * 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
@@ -28,6 +28,7 @@
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
 
+#include "hooks.h"
 #include "mainwindow.h"
 #include "alertpanel.h"
 #include "manage_window.h"
@@ -41,9 +42,8 @@
 #define TITLE_HEIGHT           72
 #define MESSAGE_HEIGHT         62
 
-static gboolean alertpanel_is_open = FALSE;
 static AlertValue value;
-
+static gboolean alertpanel_is_open = FALSE;
 static GtkWidget *dialog;
 
 static void alertpanel_show            (void);
@@ -73,12 +73,14 @@ AlertValue alertpanel_with_widget(const gchar *title,
                                  const gchar *button1_label,
                                  const gchar *button2_label,
                                  const gchar *button3_label,
-                                 GtkWidget *widget)
+                                 gboolean     can_disable,
+                                 AlertValue   default_value,
+                                 GtkWidget   *widget)
 {
        return alertpanel_full(title, message, button1_label,
                                    button2_label, button3_label,
-                                   FALSE, widget, ALERT_QUESTION,
-                                   G_ALERTDEFAULT);
+                                   can_disable, widget, ALERT_QUESTION,
+                                   default_value);
 }
 
 AlertValue alertpanel_full(const gchar *title, const gchar *message,
@@ -92,9 +94,10 @@ AlertValue alertpanel_full(const gchar *title, const gchar *message,
 {
        if (alertpanel_is_open)
                return -1;
-       else
+       else {
                alertpanel_is_open = TRUE;
-       
+               hooks_invoke(ALERTPANEL_OPENED_HOOKLIST, &alertpanel_is_open);
+       }
        alertpanel_create(title, message, button1_label, button2_label,
                          button3_label, can_disable, widget, alert_type,
                          default_value);
@@ -119,8 +122,10 @@ static void alertpanel_message(const gchar *title, const gchar *message, gint ty
 {
        if (alertpanel_is_open)
                return;
-       else
+       else {
                alertpanel_is_open = TRUE;
+               hooks_invoke(ALERTPANEL_OPENED_HOOKLIST, &alertpanel_is_open);
+       }
 
        alertpanel_create(title, message, GTK_STOCK_CLOSE, NULL, NULL,
                          FALSE, NULL, type, G_ALERTDEFAULT);
@@ -156,7 +161,7 @@ void alertpanel_warning(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);
@@ -185,8 +190,9 @@ void alertpanel_error_log(const gchar *format, ...)
        mainwin = mainwindow_get_mainwindow();
        
        if (mainwin && mainwin->logwin) {
-               val = alertpanel_full(_("Error"), buf, GTK_STOCK_OK,
-                                     _("View log"), NULL, FALSE, NULL,
+               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);
@@ -210,6 +216,8 @@ static void alertpanel_show(void)
        GTK_EVENTS_FLUSH();
 
        alertpanel_is_open = FALSE;
+       hooks_invoke(ALERTPANEL_OPENED_HOOKLIST, &alertpanel_is_open);
+
        inc_unlock();
 }
 
@@ -228,25 +236,26 @@ static void alertpanel_create(const gchar *title,
        GtkWidget *label;
        GtkWidget *hbox;
        GtkWidget *vbox;
-       GtkWidget *disable_chkbtn;
+       GtkWidget *disable_checkbtn;
        GtkWidget *confirm_area;
        GtkWidget *button1;
        GtkWidget *button2;
        GtkWidget *button3;
        const gchar *label2;
        const gchar *label3;
-       
+       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:"");
-
+                               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), TRUE);
 
-       gtk_window_set_default_size(GTK_WINDOW(dialog), 300, 100);
+       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);
@@ -316,6 +325,7 @@ static void alertpanel_create(const gchar *title,
        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);
@@ -331,13 +341,13 @@ static void alertpanel_create(const gchar *title,
                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));
        }