fix bug 4239, 'Preferences: Text Options Header Display modal is not modal' (sic)
[claws.git] / src / prefs_filtering_action.c
index 0d67298f29e57ca522d4611849101c1fcf1b0d78..9e7a04e01d479118d3be99531446260f215eefd9 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2003-2007 the Claws Mail team
+ * Copyright (C) 2003-2012 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
@@ -19,6 +19,7 @@
 
 #ifdef HAVE_CONFIG_H
 #  include "config.h"
+#include "claws-features.h"
 #endif
 
 #include "defs.h"
@@ -32,6 +33,7 @@
 #include <string.h>
 #include <errno.h>
 
+#include "gtkcmoptionmenu.h"
 #include "main.h"
 #include "prefs_gtk.h"
 #include "prefs_filtering_action.h"
 #include "matcher_parser.h"
 #include "colorlabel.h"
 #include "combobox.h"
+#include "account.h"
+#ifndef USE_ALT_ADDRBOOK
+       #include "addressbook.h"
+#endif
 
 enum {
        PFA_ACTION,
@@ -73,7 +79,9 @@ static gint prefs_filtering_action_deleted(GtkWidget *widget,
 static void prefs_filtering_action_type_selection_changed(GtkWidget *widget,
     gpointer user_data);
 static void prefs_filtering_action_select_dest(void);
+#ifndef USE_ALT_ADDRBOOK
 static void prefs_filtering_action_select_addressbook(void);
+#endif
 static void prefs_filtering_action_up(void);
 static void prefs_filtering_action_down(void);
 static void prefs_filtering_action_set_dialog(GSList *action_list);
@@ -115,7 +123,9 @@ static struct FilteringAction_ {
        GtkWidget *color_optmenu;
        GtkWidget *header_combo;
        GtkWidget *header_entry;
+#ifndef USE_ALT_ADDRBOOK
        GtkWidget *addressbook_btn;
+#endif
        GtkWidget *score_entry;
        GtkWidget *tags_combo;
 
@@ -270,7 +280,7 @@ void prefs_filtering_action_open(GSList *action_list,
                prefs_filtering_action_create();
        } else {
                /* update color label menu */
-               gtk_option_menu_set_menu(GTK_OPTION_MENU(filtering_action.color_optmenu),
+               gtk_cmoption_menu_set_menu(GTK_CMOPTION_MENU(filtering_action.color_optmenu),
                                colorlabel_create_color_menu());
        }
 
@@ -282,6 +292,7 @@ void prefs_filtering_action_open(GSList *action_list,
        prefs_filtering_action_set_dialog(action_list);
 
        gtk_widget_show(filtering_action.window);
+       gtk_window_set_modal(GTK_WINDOW(filtering_action.window), TRUE);
 }
 
 /*!
@@ -290,7 +301,7 @@ void prefs_filtering_action_open(GSList *action_list,
 static void prefs_filtering_action_size_allocate_cb(GtkWidget *widget,
                                         GtkAllocation *allocation)
 {
-       g_return_if_fail(allocation != NULL);
+       cm_return_if_fail(allocation != NULL);
 
        prefs_common.filteringactionwin_width = allocation->width;
        prefs_common.filteringactionwin_height = allocation->height;
@@ -331,7 +342,9 @@ static void prefs_filtering_action_create(void)
        GtkWidget *account_combo;
        GtkWidget *header_combo;
        GtkWidget *header_entry;
+#ifndef USE_ALT_ADDRBOOK
        GtkWidget *addressbook_btn;
+#endif
        GtkWidget *dest_entry;
        GtkWidget *dest_btn;
        GtkWidget *score_entry;
@@ -371,8 +384,8 @@ static void prefs_filtering_action_create(void)
        window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "prefs_filtering_action");
        gtk_container_set_border_width(GTK_CONTAINER(window), VBOX_BORDER);
        gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
-       gtk_window_set_modal(GTK_WINDOW(window), TRUE);
        gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
+       gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DIALOG);
 
        vbox = gtk_vbox_new(FALSE, 6);
        gtk_container_add(GTK_CONTAINER(window), vbox);
@@ -466,14 +479,14 @@ static void prefs_filtering_action_create(void)
        gtk_table_attach(GTK_TABLE(table), hbox1, 1, 2, 1, 2, 
                         GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
 
-       account_combo = gtk_combo_box_new_text ();
+       account_combo = gtk_combo_box_text_new ();
        gtk_size_group_add_widget(size_action, account_combo);
 
        for (accounts = account_get_list() ; accounts != NULL;
             accounts = accounts->next) {
                PrefsAccount *ac = (PrefsAccount *)accounts->data;
                gchar *name = g_strdup(ac->account_name);
-               gtk_combo_box_append_text(GTK_COMBO_BOX(account_combo), (gpointer) name);
+               gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(account_combo), (gpointer) name);
                g_free(name);
        }
 
@@ -488,7 +501,7 @@ static void prefs_filtering_action_create(void)
        gtk_size_group_add_widget(size_action, header_combo);
        gtk_box_pack_start (GTK_BOX (hbox1), header_combo,
                            FALSE, FALSE, 0);
-       header_entry = GTK_BIN(header_combo)->child;
+       header_entry = gtk_bin_get_child(GTK_BIN((header_combo)));
 
        /* destination */
 
@@ -502,23 +515,24 @@ static void prefs_filtering_action_create(void)
        score_entry = gtk_spin_button_new_with_range(-1000, 1000, 1);
        gtk_box_pack_start(GTK_BOX(hbox1), score_entry, FALSE, FALSE, 0);
        
-       color_optmenu = gtk_option_menu_new();
+       color_optmenu = gtk_cmoption_menu_new();
        gtk_size_group_add_widget(size_action, color_optmenu);
-       gtk_option_menu_set_menu(GTK_OPTION_MENU(color_optmenu),
+       gtk_cmoption_menu_set_menu(GTK_CMOPTION_MENU(color_optmenu),
                                 colorlabel_create_color_menu());
        prefs_filtering_action_check_widget_width(color_optmenu);
        gtk_box_pack_start(GTK_BOX(hbox1), color_optmenu, FALSE, FALSE, 0);
 
-       tags_combo = gtk_combo_box_new_text ();
+       tags_combo = gtk_combo_box_text_new ();
        gtk_size_group_add_widget(size_action, tags_combo);
 
        for (tmp = tags = tags_get_list() ; tmp != NULL;
             tmp = tmp->next) {
                gchar *name = g_strdup(tags_get_tag(GPOINTER_TO_INT(tmp->data)));
 
-               gtk_combo_box_append_text(GTK_COMBO_BOX(tags_combo), (gpointer) name);
+               gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(tags_combo), (gpointer) name);
                g_free(name);
        }
+       g_slist_free(tags);
 
        prefs_filtering_action_check_widget_width(tags_combo);
        gtk_combo_box_set_active(GTK_COMBO_BOX(tags_combo), 0);
@@ -529,23 +543,21 @@ static void prefs_filtering_action_create(void)
        gtk_table_attach(GTK_TABLE(table), hbox1, 2, 3, 2, 3, 
                        GTK_FILL, GTK_SHRINK, 0, 0);
 
-       dest_btn = gtk_button_new_with_label (_("Select ..."));
+       dest_btn = gtk_button_new_with_label (_("Select..."));
        gtk_box_pack_start (GTK_BOX (hbox1), dest_btn, FALSE, FALSE, 0);
        g_signal_connect (G_OBJECT (dest_btn), "clicked",
                          G_CALLBACK(prefs_filtering_action_select_dest),
                          NULL);
 
-       addressbook_btn = gtk_button_new_with_label (_("Select ..."));
+#ifndef USE_ALT_ADDRBOOK
+       addressbook_btn = gtk_button_new_with_label (_("Select..."));
        gtk_box_pack_start (GTK_BOX (hbox1), addressbook_btn, FALSE, FALSE, 0);
        g_signal_connect (G_OBJECT (addressbook_btn), "clicked",
                          G_CALLBACK(prefs_filtering_action_select_addressbook),
                          NULL);
+#endif
 
-#if GTK_CHECK_VERSION(2, 8, 0)
        exec_btn = gtk_button_new_from_stock(GTK_STOCK_INFO);
-#else
-       exec_btn = gtk_button_new_with_label (_("Info..."));
-#endif
        gtk_box_pack_start (GTK_BOX (hbox1), exec_btn, FALSE, FALSE, 0);
        g_signal_connect (G_OBJECT (exec_btn), "clicked",
                          G_CALLBACK(prefs_filtering_action_exec_info),
@@ -568,13 +580,15 @@ static void prefs_filtering_action_create(void)
        g_signal_connect(G_OBJECT(reg_btn), "clicked",
                         G_CALLBACK(prefs_filtering_action_register_cb), NULL);
 
-       subst_btn = gtkut_get_replace_btn(_("Replace"));
+       subst_btn = gtkut_get_replace_btn(_("_Replace"));
        gtk_box_pack_start(GTK_BOX(btn_hbox), subst_btn, FALSE, TRUE, 0);
        g_signal_connect(G_OBJECT(subst_btn), "clicked",
                         G_CALLBACK(prefs_filtering_action_substitute_cb),
                         NULL);
 
-       del_btn = gtk_button_new_from_stock(GTK_STOCK_DELETE);
+       del_btn = gtk_button_new_with_mnemonic (_("D_elete"));
+       gtk_button_set_image(GTK_BUTTON(del_btn),
+                       gtk_image_new_from_stock(GTK_STOCK_REMOVE,GTK_ICON_SIZE_BUTTON));
        gtk_box_pack_start(GTK_BOX(btn_hbox), del_btn, FALSE, TRUE, 0);
        g_signal_connect(G_OBJECT(del_btn), "clicked",
                         G_CALLBACK(prefs_filtering_action_delete_cb), NULL);
@@ -618,6 +632,9 @@ static void prefs_filtering_action_create(void)
        gtk_widget_set_size_request(window, prefs_common.filteringactionwin_width,
                                    prefs_common.filteringactionwin_height);
 
+       g_object_unref(G_OBJECT(size_group));
+       g_object_unref(G_OBJECT(size_action));
+
        gtk_widget_show_all(window);
 
        filtering_action.window    = window;
@@ -634,7 +651,9 @@ static void prefs_filtering_action_create(void)
        filtering_action.score_entry = score_entry;
        filtering_action.header_combo = header_combo;
        filtering_action.header_entry = header_entry;
+#ifndef USE_ALT_ADDRBOOK
        filtering_action.addressbook_btn = addressbook_btn;
+#endif
        filtering_action.ok_btn = ok_btn;
        filtering_action.action_list_view = action_list_view;
        
@@ -651,7 +670,7 @@ static void prefs_filtering_action_create(void)
 static void prefs_filtering_action_list_view_set_row(GtkTreeIter *row, 
                                                     FilteringAction *action)
 {
-        gchar buf[256];
+        gchar *buf;
 
        if (row == NULL && action == NULL) {
                prefs_filtering_action_list_view_insert_action
@@ -660,11 +679,12 @@ static void prefs_filtering_action_list_view_set_row(GtkTreeIter *row,
                return;
        }                        
 
-        filteringaction_to_string(buf, sizeof buf, action);
+        buf = filteringaction_to_string(action);
 
        prefs_filtering_action_list_view_insert_action
                        (filtering_action.action_list_view,
                         row, buf, TRUE);
+       g_free(buf);
 }
 
 /*!
@@ -884,7 +904,7 @@ static FilteringAction * prefs_filtering_action_dialog_to_action(gboolean alert)
                if (*destination == '\0') {
                        if (alert)
                                 alertpanel_error(action_id == ACTION_EXECUTE 
-                                                ? _("Command line not set")
+                                                ? _("Command-line not set")
                                                 : _("Destination is not set."));
                        g_free(destination);
                        return NULL;
@@ -903,7 +923,7 @@ static FilteringAction * prefs_filtering_action_dialog_to_action(gboolean alert)
                break;
        case ACTION_COLOR:
                labelcolor = colorlabel_get_color_menu_active_item(
-                       gtk_option_menu_get_menu(GTK_OPTION_MENU(filtering_action.color_optmenu)));
+                       gtk_cmoption_menu_get_menu(GTK_CMOPTION_MENU(filtering_action.color_optmenu)));
                destination = NULL;     
                break;
         case ACTION_CHANGE_SCORE:
@@ -934,7 +954,7 @@ static FilteringAction * prefs_filtering_action_dialog_to_action(gboolean alert)
                break;
        case ACTION_SET_TAG:
        case ACTION_UNSET_TAG:
-               destination = gtk_combo_box_get_active_text(GTK_COMBO_BOX(filtering_action.tags_combo));
+               destination = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(filtering_action.tags_combo));
                if (!destination || *destination == '\0') {
                        if (alert)
                                 alertpanel_error(_("Tag name is empty."));
@@ -1131,7 +1151,7 @@ static void prefs_filtering_action_down(void)
 static gboolean prefs_filtering_action_key_pressed(GtkWidget *widget,
     GdkEventKey *event, gpointer data)
 {
-       if (event && event->keyval == GDK_Escape) {
+       if (event && event->keyval == GDK_KEY_Escape) {
                prefs_filtering_action_cancel();
                return TRUE;            
        }
@@ -1215,7 +1235,8 @@ static gchar *exec_desc_strings[] = {
 
 static DescriptionWindow exec_desc_win = { 
        NULL,
-        NULL, 
+        NULL,
+       TRUE,
         2,
         N_("Filtering Action: 'Execute'"),
        N_("'Execute' allows you to send a message or message element "
@@ -1238,7 +1259,8 @@ static void prefs_filtering_action_select_dest(void)
        FolderItem *dest;
        gchar * path;
 
-       dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL, FALSE);
+       dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL, FALSE,
+                       _("Select destination folder"));
        if (!dest) return;
 
        path = folder_item_get_identifier(dest);
@@ -1247,6 +1269,7 @@ static void prefs_filtering_action_select_dest(void)
        g_free(path);
 }
 
+#ifndef USE_ALT_ADDRBOOK
 static void prefs_filtering_action_select_addressbook(void)
 {
        const gchar *folderpath = NULL;
@@ -1259,21 +1282,22 @@ static void prefs_filtering_action_select_addressbook(void)
                g_free(new_path);
        } 
 }
+#endif
 
 static void prefs_filtering_action_enable_widget(GtkWidget* widget, const gboolean enable)
 {
-       g_return_if_fail(widget != NULL);
+       cm_return_if_fail(widget != NULL);
 
        if(enable == TRUE)
        {
-               if(GTK_IS_COMBO_BOX(widget) || GTK_IS_COMBO_BOX_ENTRY(widget))
+               if(GTK_IS_COMBO_BOX(widget))
                        gtk_combo_box_set_active(GTK_COMBO_BOX(widget), 0);
                else if(GTK_IS_SPIN_BUTTON(widget))
                        gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), 0);
-               else if(GTK_IS_ENTRY(widget)) {
+               else if(GTK_IS_ENTRY(widget))
                        gtk_entry_set_text(GTK_ENTRY(widget), "");
-               } else if(GTK_IS_OPTION_MENU(widget))
-                       gtk_option_menu_set_history(GTK_OPTION_MENU(widget), 0);
+               else if(GTK_IS_CMOPTION_MENU(widget))
+                       gtk_cmoption_menu_set_history(GTK_CMOPTION_MENU(widget), 0);
                
                gtk_widget_set_sensitive(widget, TRUE);
                gtk_widget_show(widget);
@@ -1342,10 +1366,10 @@ static void prefs_filtering_action_type_selection_changed(GtkWidget *combo,
 
        prefs_filtering_action_enable_widget(filtering_action.header_combo,
                                        (value == ACTION_ADD_TO_ADDRESSBOOK));  
-
+#ifndef USE_ALT_ADDRBOOK
        prefs_filtering_action_enable_widget(filtering_action.addressbook_btn,
                                        (value == ACTION_ADD_TO_ADDRESSBOOK));
-
+#endif
        prefs_filtering_action_enable_widget(filtering_action.score_entry,
                                                ACTION_SCORE(value));
                
@@ -1430,6 +1454,7 @@ static GtkWidget *prefs_filtering_action_list_view_create(void)
        g_object_unref(model);  
        
        gtk_tree_view_set_rules_hint(list_view, prefs_common.use_stripes_everywhere);
+       gtk_tree_view_set_reorderable(list_view, TRUE);
 
        selector = gtk_tree_view_get_selection(list_view);
        gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
@@ -1469,6 +1494,7 @@ static gboolean prefs_filtering_actions_selected
        gint list_id;
        GtkTreeIter iter;
        gboolean is_valid;
+       GtkWidget *menu;
 
        if (currently_selected)
                return TRUE;
@@ -1571,8 +1597,11 @@ static gboolean prefs_filtering_actions_selected
        case MATCHACTION_COLOR:
                combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
                                     ACTION_COLOR);
-               gtk_option_menu_set_history(GTK_OPTION_MENU(filtering_action.color_optmenu),
-                                           action->labelcolor);     
+               gtk_cmoption_menu_set_history(GTK_CMOPTION_MENU(filtering_action.color_optmenu),
+                                           action->labelcolor + 1);
+               menu = gtk_cmoption_menu_get_menu(GTK_CMOPTION_MENU(
+                                               filtering_action.color_optmenu));
+               g_signal_emit_by_name(G_OBJECT(menu), "selection-done", menu);
                break;
        case MATCHACTION_CHANGE_SCORE:
                combobox_select_by_data(GTK_COMBO_BOX(filtering_action.action_combo),
@@ -1627,7 +1656,7 @@ static gboolean prefs_filtering_actions_selected
                                     ACTION_CLEAR_TAGS);
                break;
        default:
-               g_warning("unhandled case !\n");
+               g_warning("unhandled action type");
        }
        if (action->destination)
                gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), action->destination);