2005-07-17 [colin] 1.9.12cvs74
[claws.git] / src / alertpanel.c
index 081073a9ed3185cc3a73e8f2d8420d2e58a2eff6..1dfea5501fbf691adf2c6e3d4715b5440731ad0e 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2001 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2005 Hiroyuki Yamamoto
  *
  * 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
 #endif
 
 #include <stddef.h>
+
+#include <glib.h>
+#include <glib/gi18n.h>
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
 
-#include "intl.h"
 #include "mainwindow.h"
 #include "alertpanel.h"
 #include "manage_window.h"
@@ -39,8 +41,6 @@
 #define TITLE_HEIGHT           72
 #define MESSAGE_HEIGHT         62
 
-#define DEFAULT_TITLE_FONT     "Sans Bold 12"
-
 static gboolean alertpanel_is_open = FALSE;
 static AlertValue value;
 
@@ -73,17 +73,9 @@ AlertValue alertpanel(const gchar *title,
                      const gchar *button2_label,
                      const gchar *button3_label)
 {
-       if (alertpanel_is_open)
-               return -1;
-       else
-               alertpanel_is_open = TRUE;
-
-       alertpanel_create(title, message, button1_label, button2_label,
-                         button3_label, FALSE, NULL, ALERT_QUESTION);
-       alertpanel_show();
-
-       debug_print("return value = %d\n", value);
-       return value;
+       return alertpanel_with_type(title, message, button1_label,
+                                   button2_label, button3_label,
+                                   NULL, ALERT_QUESTION);
 }
 
 AlertValue alertpanel_with_widget(const gchar *title,
@@ -92,13 +84,27 @@ AlertValue alertpanel_with_widget(const gchar *title,
                                  const gchar *button2_label,
                                  const gchar *button3_label,
                                  GtkWidget *widget)
+{
+       return alertpanel_with_type(title, message, button1_label,
+                                   button2_label, button3_label,
+                                   widget, ALERT_QUESTION);
+}
+
+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)
 {
        if (alertpanel_is_open)
                return -1;
        else
                alertpanel_is_open = TRUE;
-       alertpanel_create(title, message, button1_label, button2_label, 
-                         button3_label, FALSE, widget, ALERT_QUESTION);
+       
+       alertpanel_create(title, message, button1_label, button2_label,
+                         button3_label, FALSE, widget, alert_type);
        alertpanel_show();
 
        debug_print("return value = %d\n", value);
@@ -118,6 +124,9 @@ static void alertpanel_message(const gchar *title, const gchar *message, gint ty
 
 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)
 {
        if (alertpanel_is_open)
@@ -125,8 +134,8 @@ AlertValue alertpanel_message_with_disable(const gchar *title,
        else
                alertpanel_is_open = TRUE;
 
-       alertpanel_create(title, message, NULL, NULL, NULL, TRUE, NULL,
-                         alert_type);
+       alertpanel_create(title, message, button1_label, button2_label, 
+                         button3_label, TRUE, NULL, alert_type);
        alertpanel_show();
 
        return value;
@@ -190,7 +199,7 @@ void alertpanel_error_log(const gchar *format, ...)
        mainwin = mainwindow_get_mainwindow();
        
        if (mainwin && mainwin->logwin) {
-               val = alertpanel(_("Error"), buf, _("OK"), _("View log"), NULL);
+               val = alertpanel_with_type(_("Error"), buf, _("OK"), _("View log"), NULL, NULL, ALERT_ERROR);
                if (val == G_ALERTALTERNATE)
                        log_window_show(mainwin->logwin);
        } else
@@ -230,8 +239,6 @@ static void alertpanel_create(const gchar *title,
        GtkWidget *w_hbox;
        GtkWidget *hbox;
        GtkWidget *vbox;
-       GtkWidget *spc_vbox;
-       GtkWidget *msg_vbox;
        GtkWidget *disable_chkbtn;
        GtkWidget *confirm_area;
        GtkWidget *button1;
@@ -240,6 +247,11 @@ static void alertpanel_create(const gchar *title,
        GtkWidget *icon;
        const gchar *label2;
        const gchar *label3;
+       
+       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,
@@ -249,9 +261,11 @@ static void alertpanel_create(const gchar *title,
 
        dialog = gtk_dialog_new();
        gtk_window_set_title(GTK_WINDOW(dialog), title);
-       gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, FALSE, FALSE);
-       gtk_container_set_border_width
-               (GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), 5);
+       gtk_window_set_resizable(GTK_WINDOW(dialog), TRUE);
+
+       gtk_window_set_default_size(GTK_WINDOW(dialog), 300, 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),
@@ -259,99 +273,96 @@ static void alertpanel_create(const gchar *title,
        g_signal_connect(G_OBJECT(dialog), "key_press_event",
                         G_CALLBACK(alertpanel_close),
                         (gpointer)G_ALERTOTHER);
-       gtk_widget_realize(dialog);
+
+       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);
 
        /* 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_box_pack_start(GTK_BOX(w_hbox), icon, FALSE, FALSE, 16);
-       hbox = gtk_hbox_new(FALSE, 0);
-       gtk_box_pack_start(GTK_BOX(w_hbox), hbox, FALSE, FALSE, 2);
-       gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
-                          w_hbox, TRUE, TRUE, 16);
-
-
-       label = gtk_label_new(title);
+       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);
+       
+       label = gtk_label_new(title_full);
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
        gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
+       gtk_label_set_use_markup(GTK_LABEL (label), TRUE);
+       gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
+       gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
        if (!font_desc) {
-               gchar *fontstr = prefs_common.titlefont
-                                       ? prefs_common.titlefont
-                                       : DEFAULT_TITLE_FONT;
-               font_desc = pango_font_description_from_string (fontstr);
+               gint size;
+
+               size = pango_font_description_get_size
+                       (label->style->font_desc);
+               font_desc = pango_font_description_new();
+               pango_font_description_set_weight
+                       (font_desc, PANGO_WEIGHT_BOLD);
+               pango_font_description_set_size
+                       (font_desc, size * PANGO_SCALE_LARGE);
        }
-       if (font_desc) {
-               gtk_widget_modify_font (label, font_desc);
-       }
-       gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 16);
-
-       /* for message and button(s) */
-       vbox = gtk_vbox_new(FALSE, 0);
-       gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area),
-                         vbox);
-
-       spc_vbox = gtk_vbox_new(FALSE, 0);
-       gtk_box_pack_start(GTK_BOX(vbox), spc_vbox, FALSE, FALSE, 0);
-       gtk_widget_set_size_request(spc_vbox, -1, 16);
-
-       msg_vbox = gtk_vbox_new(FALSE, 0);
-       gtk_box_pack_start(GTK_BOX(vbox), msg_vbox, FALSE, FALSE, 0);
-
-       /* for message label */
-       hbox = gtk_hbox_new(FALSE, 0);
-       gtk_box_pack_start(GTK_BOX(msg_vbox), hbox, FALSE, FALSE, 0);
-
-       /* message label */
+       if (font_desc)
+               gtk_widget_modify_font(label, font_desc);
+       g_free(title_full);
+       
        label = gtk_label_new(message);
-       gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 24);
+       gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
        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_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
+       gtk_widget_show(label);
+               
        /* Claws: custom widget */
        if (custom_widget) {
-               GtkWidget *custom_hbox = gtk_hbox_new(FALSE, 0);
-               gtk_box_pack_start(GTK_BOX(msg_vbox), custom_hbox, FALSE,
+               gtk_box_pack_start(GTK_BOX(vbox), custom_widget, FALSE,
                                   FALSE, 0);
-               gtk_box_pack_start(GTK_BOX(custom_hbox), custom_widget, FALSE,
-                                  FALSE, 24);
        }
+       
        if (can_disable) {
                hbox = gtk_hbox_new(FALSE, 0);
-               gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
-               gtk_container_set_border_width(GTK_CONTAINER(hbox), 8);
+               gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox,
+                                  FALSE, FALSE, 0);
 
                disable_chkbtn = gtk_check_button_new_with_label
                        (_("Show this message next time"));
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(disable_chkbtn),
                                             TRUE);
                gtk_box_pack_start(GTK_BOX(hbox), disable_chkbtn,
-                                  FALSE, FALSE, 0);
+                                  FALSE, FALSE, 12);
                g_signal_connect(G_OBJECT(disable_chkbtn), "toggled",
                                 G_CALLBACK(alertpanel_button_toggled),
                                 GUINT_TO_POINTER(G_ALERTDISABLE));
-       } else {
-               spc_vbox = gtk_vbox_new(FALSE, 0);
-               gtk_box_pack_start(GTK_BOX(vbox), spc_vbox, FALSE, FALSE, 0);
-               gtk_widget_set_size_request(spc_vbox, -1, 20);
        }
 
        /* for button(s) */
        if (!button1_label)
-               button1_label = _("OK");
+               button1_label = GTK_STOCK_OK;
        label2 = button2_label;
        label3 = button3_label;
        if (label2 && *label2 == '+') label2++;
        if (label3 && *label3 == '+') label3++;
 
-       gtkut_button_set_create(&confirm_area,
-                               &button1, button1_label,
-                               button2_label ? &button2 : NULL, label2,
-                               button3_label ? &button3 : NULL, label3);
+       gtkut_stock_button_set_create(&confirm_area,
+                                     &button1, button1_label,
+                                     button2_label ? &button2 : NULL, label2,
+                                     button3_label ? &button3 : NULL, label3);
 
-       gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
+       gtk_box_pack_end(GTK_BOX(GTK_DIALOG(dialog)->action_area),
+                        confirm_area, FALSE, FALSE, 0);
+       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 == '+') {
@@ -400,7 +411,7 @@ static gint alertpanel_deleted(GtkWidget *widget, GdkEventAny *event,
 }
 
 static gboolean alertpanel_close(GtkWidget *widget, GdkEventAny *event,
-                            gpointer data)
+                                gpointer data)
 {
        if (event->type == GDK_KEY_PRESS)
                if (((GdkEventKey *)event)->keyval != GDK_Escape)