fix bug 2986, 'Down and Delete buttons have same hotkey in filtering config' and...
[claws.git] / src / prefs_toolbar.c
index 06fc7509c4a3bf4c4affb79a6adf3bfcf5a41ceb..9969063c0de2a067132c7929901619c7327b6a5c 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2002-2007 Hiroyuki Yamamoto & the Claws Mail team
+ * Copyright (C) 2002-2013 Hiroyuki Yamamoto & 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
@@ -23,6 +23,7 @@
 
 #ifdef HAVE_CONFIG_H
 #  include "config.h"
+#include "claws-features.h"
 #endif
 
 #include "defs.h"
@@ -41,6 +42,7 @@
 #include "mainwindow.h"
 #include "alertpanel.h"
 #include "prefs_common.h"
+#include "prefs_actions.h"
 
 #include "utils.h"
 
@@ -48,6 +50,8 @@
 #include "prefs_toolbar.h"
 #include "prefswindow.h"
 #include "prefs_gtk.h"
+#include "plugin.h"
+#include "messageview.h"
 
 enum
 {
@@ -64,7 +68,8 @@ enum
 {
        ITEM_FUNCTION     = 0,
        ITEM_USER_ACTION  = 1,
-       ITEM_SEPARATOR    = 2
+       ITEM_PLUGIN       = 2,
+       ITEM_SEPARATOR    = 3,
 };
 
 static const gint ToolbarIcons[] =
@@ -158,6 +163,7 @@ typedef struct _ToolbarPage
        GtkWidget *item_type_combo;     /* item type selection widget    */
        GtkWidget *item_func_combo;     /* item internal function widget */
        GtkWidget *item_action_combo;   /* item user action widget       */
+       GtkWidget *item_plugin_combo;   /* items registered by plugins */
        GtkWidget *icon_button;         /* item icon chooser widget      */
        
        GtkWidget *icon_chooser_win;
@@ -171,6 +177,19 @@ typedef struct _ToolbarPage
 #define ERROR_MSG_NO_ICON _("Item has no icon defined.")
 #define ERROR_MSG_NO_TEXT _("Item has no text defined.")
 
+typedef struct _ToolbarPluginItem ToolbarPluginItem;
+struct _ToolbarPluginItem {
+       gchar *plugin;
+       gchar *item_name;
+       ToolbarPluginCallback cb;
+       gpointer cb_data;
+};
+
+/* items registered by plugins */
+static GHashTable *plugin_items_mainwin = NULL;
+static GHashTable *plugin_items_compose = NULL;
+static GHashTable *plugin_items_msgview = NULL;
+
 static void prefs_toolbar_populate               (ToolbarPage *prefs_toolbar);
 
 static void get_action_name                     (const gchar *entry, 
@@ -195,6 +214,8 @@ static void prefs_toolbar_down                   (GtkButton        *button,
 
 static void action_selection_changed            (GtkComboBox *action_combo,
                                                  ToolbarPage *prefs_toolbar);
+static void plugin_selection_changed            (GtkComboBox *action_combo,
+                                                 ToolbarPage *prefs_toolbar);
 
 static void func_selection_changed              (GtkComboBox *action_combo,
                                                  ToolbarPage *prefs_toolbar);
@@ -212,13 +233,22 @@ static gboolean set_list_selected          (GtkTreeSelection *selector,
 static void icon_chooser_create                         (GtkButton *button,
                                                  ToolbarPage *prefs_toolbar);
 
+
+static GHashTable** get_plugin_hash_from_toolbar_type(ToolbarType toolbar_type)
+{
+       if (toolbar_type == TOOLBAR_MAIN)
+               return &plugin_items_mainwin;
+       else if (toolbar_type == TOOLBAR_COMPOSE)
+               return &plugin_items_compose;
+       else if (toolbar_type == TOOLBAR_MSGVIEW)
+               return &plugin_items_msgview;
+       else
+               return NULL;
+}
+
 static void prefs_toolbar_create_widget(PrefsPage *_page, GtkWindow *window, gpointer data)
 {
        ToolbarPage *prefs_toolbar = (ToolbarPage *) _page;
-       gchar *win_titles[3];
-       win_titles[TOOLBAR_MAIN]    = _("Main toolbar configuration");
-       win_titles[TOOLBAR_COMPOSE] = _("Compose toolbar configuration");  
-       win_titles[TOOLBAR_MSGVIEW] = _("Message view toolbar configuration");  
 
        prefs_toolbar->window = GTK_WIDGET(window);
 
@@ -260,7 +290,6 @@ static void prefs_toolbar_save(PrefsPage *_page)
                        item->index = toolbar_ret_val_from_descr(event);
                        g_free(event);
 
-                       /* TODO: save A_CLAWS_ACTIONS only if they are still active */
                        toolbar_set_list_item(item, prefs_toolbar->source);
 
                        g_free(item->file);
@@ -272,7 +301,7 @@ static void prefs_toolbar_save(PrefsPage *_page)
        toolbar_save_config_file(prefs_toolbar->source);
 
        if (prefs_toolbar->source == TOOLBAR_MAIN) 
-               main_window_reflect_prefs_all_real(TRUE);
+               toolbar_update(TOOLBAR_MAIN, mainwindow_get_mainwindow());
        else if (prefs_toolbar->source == TOOLBAR_COMPOSE)
                compose_reflect_prefs_pixmap_theme();
        else if (prefs_toolbar->source == TOOLBAR_MSGVIEW)
@@ -337,14 +366,29 @@ static void prefs_toolbar_set_displayed(ToolbarPage *prefs_toolbar)
                                       &iter);  
 }
 
+static void add_item_to_plugin_combo(gpointer key, gpointer data, gpointer combo_box)
+{
+#if !GTK_CHECK_VERSION(2, 24, 0)
+       gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), (const gchar*)key);
+#else
+       gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo_box), (const gchar*)key);
+#endif
+}
+
 static void prefs_toolbar_populate(ToolbarPage *prefs_toolbar)
 {
        GSList *cur;
        gchar *act, *act_name;
+       GHashTable **hash;
 
        prefs_toolbar->combo_action_list = toolbar_get_action_items(prefs_toolbar->source);
+#if !GTK_CHECK_VERSION(2, 24, 0)
        combobox_set_popdown_strings(GTK_COMBO_BOX(prefs_toolbar->item_func_combo),
                                     prefs_toolbar->combo_action_list);
+#else
+       combobox_set_popdown_strings(GTK_COMBO_BOX_TEXT(prefs_toolbar->item_func_combo),
+                                    prefs_toolbar->combo_action_list);
+#endif
        
        /* get currently defined sylpheed actions */
        if (prefs_common.actions_list != NULL) {
@@ -352,17 +396,34 @@ static void prefs_toolbar_populate(ToolbarPage *prefs_toolbar)
                        act = (gchar *)cur->data;
                        get_action_name(act, &act_name);
                        
+#if !GTK_CHECK_VERSION(2, 24, 0)
                        gtk_combo_box_append_text(
                                GTK_COMBO_BOX(prefs_toolbar->item_action_combo),
+#else
+                       gtk_combo_box_text_append_text(
+                               GTK_COMBO_BOX_TEXT(prefs_toolbar->item_action_combo),
+#endif
                                act_name);
 
                        g_free(act_name);
                } 
 
-       }
+       } else
+               combobox_set_sensitive(GTK_COMBO_BOX(prefs_toolbar->item_type_combo),
+                                       ITEM_USER_ACTION, FALSE);
        
+       /* items registered by plugins */
+       hash = get_plugin_hash_from_toolbar_type(prefs_toolbar->source);
+       if (hash && *hash)
+               g_hash_table_foreach(*hash, add_item_to_plugin_combo, 
+                               prefs_toolbar->item_plugin_combo);
+       else
+               combobox_set_sensitive(GTK_COMBO_BOX(prefs_toolbar->item_type_combo),
+                                       ITEM_PLUGIN, FALSE);
+
        gtk_combo_box_set_active(GTK_COMBO_BOX(prefs_toolbar->item_func_combo), 0);
        gtk_combo_box_set_active(GTK_COMBO_BOX(prefs_toolbar->item_action_combo), 0);
+       gtk_combo_box_set_active(GTK_COMBO_BOX(prefs_toolbar->item_plugin_combo), 0);
        
        prefs_toolbar_set_displayed(prefs_toolbar);
 
@@ -378,7 +439,7 @@ static gboolean is_duplicate(ToolbarPage *prefs_toolbar, gchar *chosen_action)
        GtkTreeIter iter;
        gboolean result;
 
-       g_return_val_if_fail(chosen_action != NULL, TRUE);
+       cm_return_val_if_fail(chosen_action != NULL, TRUE);
 
        if (!gtk_tree_model_iter_n_children(model_set, NULL))
                return FALSE;
@@ -463,7 +524,11 @@ static void prefs_toolbar_register(GtkButton *button, ToolbarPage *prefs_toolbar
                }
                                
                if (item_type == ITEM_FUNCTION) {
+#if !GTK_CHECK_VERSION(2, 24, 0)
                        event = gtk_combo_box_get_active_text(GTK_COMBO_BOX(
+#else
+                       event = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(
+#endif
                                                prefs_toolbar->item_func_combo));
                                                
                        if (is_duplicate(prefs_toolbar, event)) {
@@ -471,7 +536,9 @@ static void prefs_toolbar_register(GtkButton *button, ToolbarPage *prefs_toolbar
                                g_free(event);
                                return;
                        }
-               } else
+               } else if(item_type == ITEM_PLUGIN)
+                 event = toolbar_ret_descr_from_val(A_CLAWS_PLUGINS);
+               else
                        event = toolbar_ret_descr_from_val(A_CLAWS_ACTIONS);
                
                text = gtk_editable_get_chars(
@@ -493,7 +560,7 @@ static void prefs_toolbar_register(GtkButton *button, ToolbarPage *prefs_toolbar
                }
                
                g_free(text);
-               if(item_type != ITEM_USER_ACTION)
+               if((item_type != ITEM_USER_ACTION) && (item_type != ITEM_PLUGIN))
                        g_free(event);
        }
        
@@ -547,7 +614,11 @@ static void prefs_toolbar_substitute(GtkButton *button, ToolbarPage *prefs_toolb
                                                  -1);
                
                if (item_type == ITEM_FUNCTION) {
+#if !GTK_CHECK_VERSION(2, 24, 0)
                        icon_event = gtk_combo_box_get_active_text(GTK_COMBO_BOX(
+#else
+                       icon_event = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(
+#endif
                                                prefs_toolbar->item_func_combo));
                                                
                        if (is_duplicate(prefs_toolbar, icon_event)
@@ -557,7 +628,9 @@ static void prefs_toolbar_substitute(GtkButton *button, ToolbarPage *prefs_toolb
                                g_free(set_event);
                                return;
                        }
-               } else
+               } else if(item_type == ITEM_PLUGIN)
+                       icon_event = toolbar_ret_descr_from_val(A_CLAWS_PLUGINS);
+               else
                        icon_event = toolbar_ret_descr_from_val(A_CLAWS_ACTIONS);
                
                text = gtk_editable_get_chars(
@@ -578,8 +651,8 @@ static void prefs_toolbar_substitute(GtkButton *button, ToolbarPage *prefs_toolb
                                
                g_free(text);
                g_free(set_event);
-               if(item_type != ITEM_USER_ACTION)
-                       g_free(icon_event);             
+               if((item_type != ITEM_USER_ACTION) && (item_type != ITEM_PLUGIN))
+                       g_free(icon_event);
        }
 }
 
@@ -678,6 +751,7 @@ static void item_type_changed(GtkComboBox *item_type_combo,
        case ITEM_FUNCTION:
                gtk_widget_show(prefs_toolbar->item_func_combo);
                gtk_widget_hide(prefs_toolbar->item_action_combo);
+               gtk_widget_hide(prefs_toolbar->item_plugin_combo);
                gtk_combo_box_set_active(
                        GTK_COMBO_BOX(prefs_toolbar->item_func_combo), 0);
                gtk_button_set_label(GTK_BUTTON(prefs_toolbar->icon_button), "");
@@ -691,6 +765,7 @@ static void item_type_changed(GtkComboBox *item_type_combo,
        case ITEM_USER_ACTION:
                gtk_widget_show(prefs_toolbar->item_action_combo);
                gtk_widget_hide(prefs_toolbar->item_func_combo);
+               gtk_widget_hide(prefs_toolbar->item_plugin_combo);
                gtk_combo_box_set_active(
                        GTK_COMBO_BOX(prefs_toolbar->item_action_combo), 0);
                gtk_button_set_label(GTK_BUTTON(prefs_toolbar->icon_button), "");
@@ -710,12 +785,26 @@ static void item_type_changed(GtkComboBox *item_type_combo,
                        GTK_COMBO_BOX(prefs_toolbar->item_func_combo), -1);
                gtk_combo_box_set_active(
                        GTK_COMBO_BOX(prefs_toolbar->item_action_combo), -1);
+               gtk_combo_box_set_active(
+                       GTK_COMBO_BOX(prefs_toolbar->item_plugin_combo), -1);
                gtk_entry_set_text(GTK_ENTRY(prefs_toolbar->item_text_entry), "");
                gtk_widget_set_sensitive(prefs_toolbar->item_action_combo, FALSE);
                gtk_widget_set_sensitive(prefs_toolbar->item_text_entry, FALSE);
+               gtk_widget_set_sensitive(prefs_toolbar->item_plugin_combo, FALSE);
                gtk_widget_set_sensitive(prefs_toolbar->item_func_combo, FALSE);
                gtk_widget_set_sensitive(prefs_toolbar->icon_button, FALSE);
                break;
+         case ITEM_PLUGIN:
+               gtk_widget_show(prefs_toolbar->item_plugin_combo);
+               gtk_widget_hide(prefs_toolbar->item_func_combo);
+               gtk_widget_hide(prefs_toolbar->item_action_combo);
+               gtk_combo_box_set_active(GTK_COMBO_BOX(prefs_toolbar->item_plugin_combo), 0);
+               gtk_button_set_label(GTK_BUTTON(prefs_toolbar->icon_button), "");
+               gtk_widget_set_sensitive(prefs_toolbar->item_text_entry, FALSE);
+               gtk_widget_set_sensitive(prefs_toolbar->item_plugin_combo, TRUE);
+               gtk_widget_set_sensitive(prefs_toolbar->icon_button, TRUE);
+               plugin_selection_changed(GTK_COMBO_BOX(prefs_toolbar->item_plugin_combo), prefs_toolbar);
+               break;
        }
 
 }
@@ -723,7 +812,11 @@ static void item_type_changed(GtkComboBox *item_type_combo,
 static void action_selection_changed(GtkComboBox *action_combo,
                                ToolbarPage *prefs_toolbar)
 {
+#if !GTK_CHECK_VERSION(2, 24, 0)
        gchar *text = gtk_combo_box_get_active_text(GTK_COMBO_BOX(
+#else
+       gchar *text = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(
+#endif
                           prefs_toolbar->item_action_combo));
 
        if(text != NULL) { /* action */
@@ -732,10 +825,29 @@ static void action_selection_changed(GtkComboBox *action_combo,
        } 
 }
 
+static void plugin_selection_changed(GtkComboBox *action_combo,
+                ToolbarPage *prefs_toolbar)
+{
+#if !GTK_CHECK_VERSION(2, 24, 0)
+       gchar *text = gtk_combo_box_get_active_text(GTK_COMBO_BOX(prefs_toolbar->item_plugin_combo));
+#else
+       gchar *text = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(prefs_toolbar->item_plugin_combo));
+#endif
+
+       if (text != NULL) { /* action */
+               gtk_entry_set_text(GTK_ENTRY(prefs_toolbar->item_text_entry), text);
+               g_free(text);
+       }
+}
+
 static void func_selection_changed(GtkComboBox *action_combo,
                                ToolbarPage *prefs_toolbar)
 {
+#if !GTK_CHECK_VERSION(2, 24, 0)
        gchar *text = gtk_combo_box_get_active_text(GTK_COMBO_BOX(
+#else
+       gchar *text = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(
+#endif
                           prefs_toolbar->item_func_combo));
 
        if(text != NULL) { /* action */
@@ -767,7 +879,10 @@ static void prefs_toolbar_create(ToolbarPage *prefs_toolbar)
        GtkWidget *icon_button;
        GtkWidget *icon_hbox;
        GtkWidget *item_type_combo;
+       GtkListStore *item_type_model;
+       GtkTreeIter iter;
        GtkWidget *item_action_combo;
+       GtkWidget *item_plugin_combo;
        GtkWidget *item_func_combo;
        GtkWidget *reg_hbox;
        GtkWidget *arrow;
@@ -821,8 +936,13 @@ static void prefs_toolbar_create(ToolbarPage *prefs_toolbar)
                         (GtkAttachOptions) (GTK_FILL),
                         (GtkAttachOptions) (0), 0, 0); 
        
-       item_type_combo = combobox_text_new(FALSE, _("Internal Function"),
-                               _("User Action"), _("Separator"), NULL);
+       item_type_combo = gtkut_sc_combobox_create(NULL, TRUE);
+       item_type_model = GTK_LIST_STORE(gtk_combo_box_get_model(
+                                        GTK_COMBO_BOX(item_type_combo)));
+       COMBOBOX_ADD(item_type_model, _("Internal Function"), ITEM_FUNCTION);
+       COMBOBOX_ADD(item_type_model, _("User Action"), ITEM_USER_ACTION);
+       COMBOBOX_ADD(item_type_model, _("Plugins"), ITEM_PLUGIN);
+       COMBOBOX_ADD(item_type_model, _("Separator"), ITEM_SEPARATOR);  
        gtk_widget_set_size_request(item_type_combo, 200, -1);
        gtk_table_attach(GTK_TABLE(table), item_type_combo, 1, 3, 0, 1,
                         (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
@@ -835,19 +955,38 @@ static void prefs_toolbar_create(ToolbarPage *prefs_toolbar)
                          (GtkAttachOptions) (GTK_FILL),
                          (GtkAttachOptions) (0), 0, 0);
 
+#if !GTK_CHECK_VERSION(2, 24, 0)
        item_action_combo = gtk_combo_box_new_text();
+#else
+       item_action_combo = gtk_combo_box_text_new();
+#endif
        gtk_widget_set_size_request(item_action_combo, 200, -1);
        gtk_table_attach (GTK_TABLE (table), item_action_combo, 1, 3, 1, 2,
                          (GtkAttachOptions) (GTK_FILL),
                          (GtkAttachOptions) (0), 0, 0);
                          
        /* available internal functions */
+#if !GTK_CHECK_VERSION(2, 24, 0)
        item_func_combo = gtk_combo_box_new_text();
+#else
+       item_func_combo = gtk_combo_box_text_new();
+#endif
        gtk_widget_set_size_request(item_func_combo, 200, -1);
        gtk_table_attach (GTK_TABLE (table), item_func_combo, 1, 3, 1, 2,
                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                          (GtkAttachOptions) (0), 0, 0);
        
+       /* plugin-registered items */
+#if !GTK_CHECK_VERSION(2, 24, 0)
+       item_plugin_combo = gtk_combo_box_new_text();
+#else
+       item_plugin_combo = gtk_combo_box_text_new();
+#endif
+       gtk_widget_set_size_request(item_plugin_combo, 200, -1);
+       gtk_table_attach(GTK_TABLE(table), item_plugin_combo, 1, 3, 1, 2,
+                        (GtkAttachOptions) (GTK_FILL),
+                        (GtkAttachOptions) (0), 0, 0);
+
        /* toolbar item description */
        label_icon_text = gtk_label_new(_("Toolbar text"));
        gtk_misc_set_alignment(GTK_MISC(label_icon_text), 0, 0.5);
@@ -900,19 +1039,23 @@ static void prefs_toolbar_create(ToolbarPage *prefs_toolbar)
        btn_hbox = gtk_hbox_new(TRUE, 4);
        gtk_box_pack_start(GTK_BOX(reg_hbox), btn_hbox, FALSE, FALSE, 0);
 
-       reg_btn = gtk_button_new_from_stock(GTK_STOCK_ADD);
+       reg_btn = gtk_button_new_with_mnemonic (_("A_dd"));
+       gtk_button_set_image(GTK_BUTTON(reg_btn),
+                       gtk_image_new_from_stock(GTK_STOCK_ADD,GTK_ICON_SIZE_BUTTON));
        gtk_box_pack_start(GTK_BOX(btn_hbox), reg_btn, FALSE, TRUE, 0);
        g_signal_connect(G_OBJECT(reg_btn), "clicked",
                         G_CALLBACK(prefs_toolbar_register), 
                         prefs_toolbar);
 
-       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_toolbar_substitute),
                         prefs_toolbar);
 
-       del_btn = gtk_button_new_from_stock(GTK_STOCK_DELETE);
+       del_btn = gtk_button_new_with_mnemonic (_("Re_move"));
+       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_toolbar_delete), 
@@ -966,6 +1109,8 @@ static void prefs_toolbar_create(ToolbarPage *prefs_toolbar)
                         G_CALLBACK(item_type_changed), prefs_toolbar);
        g_signal_connect(G_OBJECT(item_action_combo), "changed",
                         G_CALLBACK(action_selection_changed), prefs_toolbar);
+       g_signal_connect(G_OBJECT(item_plugin_combo), "changed",
+                        G_CALLBACK(plugin_selection_changed), prefs_toolbar);
        g_signal_connect(G_OBJECT(item_func_combo), "changed",
                         G_CALLBACK(func_selection_changed), prefs_toolbar);
        g_signal_connect(G_OBJECT(up_btn), "clicked",
@@ -980,6 +1125,7 @@ static void prefs_toolbar_create(ToolbarPage *prefs_toolbar)
        prefs_toolbar->item_type_combo  = item_type_combo;
        prefs_toolbar->item_func_combo  = item_func_combo;
        prefs_toolbar->item_action_combo= item_action_combo;
+       prefs_toolbar->item_plugin_combo= item_plugin_combo;
        prefs_toolbar->icon_button      = icon_button;
        prefs_toolbar->item_icon_file   = NULL;
        
@@ -990,6 +1136,123 @@ ToolbarPage *prefs_toolbar_mainwindow;
 ToolbarPage *prefs_toolbar_composewindow;
 ToolbarPage *prefs_toolbar_messageview;
 
+static void toolbar_unregister_plugin_item_real(GHashTable *hash, 
+                                       const gchar *plugin_name, 
+                                       const gchar *item_name)
+{
+       gchar *key;
+
+       if (!hash)
+               return;
+
+       key = g_strdup_printf(plugin_name, "/", item_name, NULL);
+       g_hash_table_remove(hash, key);
+       g_free(key);
+}
+
+void prefs_toolbar_unregister_plugin_item(ToolbarType toolbar_type, 
+                                       const gchar *plugin_name, 
+                                       const gchar *item_name)
+{
+       GHashTable **hash;
+       hash = get_plugin_hash_from_toolbar_type(toolbar_type);
+       if (hash)
+               toolbar_unregister_plugin_item_real(*hash, plugin_name, item_name);
+}
+
+static void prefs_toolbar_execute_plugin_item_real(gpointer parent, 
+                               GHashTable *hash, const gchar *id)
+{
+       ToolbarPluginItem *value;
+       GSList *walk;
+       gboolean found;
+
+       if (!hash) {
+               debug_print("No plugin registered toolbar items yet\n");
+               return;
+       }
+
+       value = g_hash_table_lookup(hash, id);
+       if (!value) {
+               debug_print("Could not find plugin toolbar item with id %s\n", id);
+               return;
+       }
+
+       /* check if corresponding plugin is currently loaded */
+       found = FALSE;
+       for (walk = plugin_get_list(); walk; walk = walk->next) {
+               const gchar *plugin_name;
+               Plugin *plugin = walk->data;
+               plugin_name = plugin_get_name(plugin);
+               if (!strcmp(plugin_name, value->plugin)) {
+                       found = TRUE;
+                       break;
+               }
+       }
+       if (!found) {
+               debug_print("Plugin '%s' is currently not loaded, cannot execute toolbar action\n", value->plugin);
+               return;
+       }
+
+       value->cb(parent, value->item_name, value->cb_data);
+}
+
+void prefs_toolbar_execute_plugin_item(gpointer parent, 
+                       ToolbarType toolbar_type, const gchar *id)
+{
+       GHashTable **hash;
+       hash = get_plugin_hash_from_toolbar_type(toolbar_type);
+       if (hash)
+               prefs_toolbar_execute_plugin_item_real(parent, *hash, id);
+}
+
+static void destroy_plugin_item_hash_value(ToolbarPluginItem *item)
+{
+       g_free(item->plugin);
+       g_free(item->item_name);
+       g_free(item);
+}
+
+static void prefs_toolbar_register_plugin_item_real(GHashTable **hash, 
+                                       const gchar *plugin_name, 
+                                       const gchar *item_name, 
+                                       ToolbarPluginCallback cb, 
+                                       gpointer cb_data)
+{
+       gchar *key;
+       ToolbarPluginItem *value;
+
+       cm_return_if_fail(plugin_name && item_name);
+
+       if (!*hash) {
+               *hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, 
+                               (GDestroyNotify) destroy_plugin_item_hash_value);
+               if (!*hash)
+                       return;
+       }
+
+       key = g_strconcat(plugin_name, "/", item_name, NULL);
+       value = g_new0(ToolbarPluginItem, 1);
+       value->plugin = g_strdup(plugin_name);
+       value->item_name = g_strdup(item_name);
+       value->cb = cb;
+       value->cb_data = cb_data;
+       g_hash_table_insert(*hash, key, value);
+}
+
+void prefs_toolbar_register_plugin_item(ToolbarType toolbar_type, 
+                                       const gchar *plugin_name, 
+                                       const gchar *item_name, 
+                                       ToolbarPluginCallback cb, 
+                                       gpointer cb_data)
+{
+       GHashTable **hash;
+       hash = get_plugin_hash_from_toolbar_type(toolbar_type);
+       if(hash)
+               prefs_toolbar_register_plugin_item_real(hash, plugin_name, 
+                                               item_name, cb, cb_data);
+}
+
 void prefs_toolbar_init(void)
 {
        ToolbarPage *page;
@@ -1051,6 +1314,24 @@ void prefs_toolbar_done(void)
        g_free(prefs_toolbar_messageview);
 }
 
+void prefs_toolbar_update_action_btns(void) 
+{
+       if (toolbar_check_action_btns(TOOLBAR_MAIN)) {
+               toolbar_save_config_file(TOOLBAR_MAIN);
+               toolbar_update(TOOLBAR_MAIN, mainwindow_get_mainwindow());
+       }
+
+       if (toolbar_check_action_btns(TOOLBAR_COMPOSE)) {
+               toolbar_save_config_file(TOOLBAR_COMPOSE);
+               compose_reflect_prefs_pixmap_theme();
+       }
+
+       if (toolbar_check_action_btns(TOOLBAR_MSGVIEW)) {
+               toolbar_save_config_file(TOOLBAR_MSGVIEW);
+               messageview_reflect_prefs_pixmap_theme();
+       }
+}
+
 static void set_visible_if_not_text(GtkTreeViewColumn *col,
                                    GtkCellRenderer   *renderer,
                                    GtkTreeModel      *model,
@@ -1217,15 +1498,30 @@ static gboolean set_list_selected(GtkTreeSelection *selector,
                                g_free(item_string);
                        }
                }
-               
+
                gtk_widget_show(prefs_toolbar->item_action_combo);
                gtk_widget_hide(prefs_toolbar->item_func_combo);
+               gtk_widget_hide(prefs_toolbar->item_plugin_combo);
                
                g_free(icon_text);
                g_free(descr);
 
                return TRUE;
        }
+
+       if (g_utf8_collate(toolbar_ret_descr_from_val(A_CLAWS_PLUGINS), descr) == 0) {
+               gtk_combo_box_set_active(GTK_COMBO_BOX(prefs_toolbar->item_type_combo), ITEM_PLUGIN);
+
+               gtk_combo_box_set_active(GTK_COMBO_BOX(prefs_toolbar->item_plugin_combo), 0);
+
+               gtk_widget_show(prefs_toolbar->item_plugin_combo);
+               gtk_widget_hide(prefs_toolbar->item_func_combo);
+               gtk_widget_hide(prefs_toolbar->item_action_combo);
+
+               g_free(descr);
+               g_free(icon_text);
+               return TRUE;
+       }
        
        /* scan combo list for selected description an set combo item accordingly */
        for (cur = prefs_toolbar->combo_action_list, item_num = 0; cur != NULL; 
@@ -1262,7 +1558,7 @@ static void icon_chooser_ok_clicked(GtkButton *button,
        GdkPixbuf *pix;
        gchar *icon_file;
        
-       g_return_if_fail(prefs_toolbar != NULL);
+       cm_return_if_fail(prefs_toolbar != NULL);
 
        model = gtk_icon_view_get_model(GTK_ICON_VIEW(prefs_toolbar->icon_chooser_view));
        list = gtk_icon_view_get_selected_items(GTK_ICON_VIEW(prefs_toolbar->icon_chooser_view));
@@ -1296,7 +1592,7 @@ static void icon_chooser_ok_clicked(GtkButton *button,
 static void icon_chooser_cancel_clicked(GtkButton *button,
                                        ToolbarPage *prefs_toolbar)
 {
-       g_return_if_fail(prefs_toolbar != NULL);
+       cm_return_if_fail(prefs_toolbar != NULL);
 
        gtk_widget_destroy(prefs_toolbar->icon_chooser_win);
        prefs_toolbar->icon_chooser_win = NULL;
@@ -1306,7 +1602,7 @@ static void icon_chooser_cancel_clicked(GtkButton *button,
 static gboolean icon_chooser_key_pressed(GtkWidget *widget, GdkEventKey *event,
                        ToolbarPage *prefs_toolbar)
 {
-       if (event && event->keyval == GDK_Escape) {
+       if (event && event->keyval == GDK_KEY_Escape) {
                icon_chooser_cancel_clicked(NULL, prefs_toolbar);
                return TRUE;
        }
@@ -1318,9 +1614,9 @@ static gboolean icon_list_key_pressed(GtkWidget *widget, GdkEventKey *event,
                        ToolbarPage *prefs_toolbar)
 {
        if (event) {
-               if (event->keyval == GDK_KP_Enter ||
-                   event->keyval == GDK_Return ||
-                   event->keyval == GDK_space) {
+               if (event->keyval == GDK_KEY_KP_Enter ||
+                   event->keyval == GDK_KEY_Return ||
+                   event->keyval == GDK_KEY_space) {
                        icon_chooser_ok_clicked(NULL, prefs_toolbar);
                        return TRUE;
                }
@@ -1352,11 +1648,9 @@ static gboolean icon_window_button_press(GtkWidget *widget,
                                               GdkEventButton *event,
                                               ToolbarPage *prefs_toolbar )
 {
-       GtkWidget *event_widget, *button;
+       GtkWidget *event_widget;
        gboolean restore = TRUE;
 
-       button = prefs_toolbar->icon_button;
-
        /* Test where mouse was clicked */
        event_widget = gtk_get_event_widget((GdkEvent *)event);
        if (event_widget != widget) {
@@ -1367,7 +1661,7 @@ static gboolean icon_window_button_press(GtkWidget *widget,
                                restore = FALSE;
                                break;
                        }
-                       event_widget = event_widget->parent;
+                       event_widget = gtk_widget_get_parent(event_widget);
                }
        }
 
@@ -1386,6 +1680,7 @@ static void icon_chooser_activated(GtkTreeView *treeview, GtkTreePath *path,
 
 static void icon_chooser_create(GtkButton *button, ToolbarPage *prefs_toolbar)
 {
+       GtkAllocation allocation;
        GtkWidget *icon_chooser_win;
        GtkWidget *scrollwin;
        GtkWidget *icon_view;
@@ -1413,13 +1708,13 @@ static void icon_chooser_create(GtkButton *button, ToolbarPage *prefs_toolbar)
        
        icon_chooser_win = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "prefs_toolbar");
        gtk_window_set_title(GTK_WINDOW(icon_chooser_win), _("Toolbar item icon"));
-#ifndef MAEMO
        gtk_window_set_decorated(GTK_WINDOW(icon_chooser_win), FALSE);
-#endif
-       gdk_window_get_origin(GTK_WIDGET(prefs_toolbar->icon_button)->window
+       gdk_window_get_origin(gtk_widget_get_window(
+                       GTK_WIDGET(prefs_toolbar->icon_button))
                        &x, &y);
-       x += GTK_WIDGET(prefs_toolbar->icon_button)->allocation.x;
-       y += GTK_WIDGET(prefs_toolbar->icon_button)->allocation.y;
+       gtk_widget_get_allocation(GTK_WIDGET(prefs_toolbar->icon_button), &allocation);
+       x += allocation.x;
+       y += allocation.y;
        y += 50;
        x -= 300-50;
        gtk_window_move(GTK_WINDOW(icon_chooser_win), x, y);