talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit 8ff369242618f254d36e7985e372c66c97fc7746
parent e200f88614b2ad794fd3370690f3bbe044b34ce1
Author: Holger Berndt <hb@claws-mail.org>
Date:   Sat, 19 Dec 2009 22:50:46 +0000

2009-12-19 [holger]	3.7.3cvs41

	* src/prefs_toolbar.c
	* src/prefs_toolbar.h
	* src/toolbar.c
		Allow plugins to choose to which toolbar they want
		to add actions (main window, compose window, or message view)

Diffstat:
MChangeLog | 8++++++++
MPATCHSETS | 1+
Mconfigure.ac | 2+-
Msrc/prefs_toolbar.c | 150+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
Msrc/prefs_toolbar.h | 6+++---
Msrc/toolbar.c | 2+-
6 files changed, 103 insertions(+), 66 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,11 @@ +2009-12-19 [holger] 3.7.3cvs41 + + * src/prefs_toolbar.c + * src/prefs_toolbar.h + * src/toolbar.c + Allow plugins to choose to which toolbar they want + to add actions (main window, compose window, or message view) + 2009-12-19 [paul] 3.7.3cvs40 * src/statusbar.c diff --git a/PATCHSETS b/PATCHSETS @@ -3914,3 +3914,4 @@ ( cvs diff -u -r 1.382.2.535 -r 1.382.2.536 src/compose.c; ) > 3.7.3cvs38.patchset ( cvs diff -u -r 1.382.2.536 -r 1.382.2.537 src/compose.c; ) > 3.7.3cvs39.patchset ( cvs diff -u -r 1.5.2.25 -r 1.5.2.26 src/statusbar.c; ) > 3.7.3cvs40.patchset +( cvs diff -u -r 1.30.2.58 -r 1.30.2.59 src/prefs_toolbar.c; cvs diff -u -r 1.5.2.7 -r 1.5.2.8 src/prefs_toolbar.h; cvs diff -u -r 1.43.2.111 -r 1.43.2.112 src/toolbar.c; ) > 3.7.3cvs41.patchset diff --git a/configure.ac b/configure.ac @@ -12,7 +12,7 @@ MINOR_VERSION=7 MICRO_VERSION=3 INTERFACE_AGE=0 BINARY_AGE=0 -EXTRA_VERSION=40 +EXTRA_VERSION=41 EXTRA_RELEASE= EXTRA_GTK2_VERSION= diff --git a/src/prefs_toolbar.c b/src/prefs_toolbar.c @@ -183,7 +183,9 @@ struct _ToolbarPluginItem { }; /* items registered by plugins */ -static GHashTable *plugin_items = NULL; +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); @@ -228,6 +230,19 @@ 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; @@ -362,6 +377,7 @@ 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); combobox_set_popdown_strings(GTK_COMBO_BOX(prefs_toolbar->item_func_combo), @@ -383,8 +399,9 @@ static void prefs_toolbar_populate(ToolbarPage *prefs_toolbar) } /* items registered by plugins */ - if(plugin_items) - g_hash_table_foreach(plugin_items, add_item_to_plugin_combo, prefs_toolbar->item_plugin_combo); + 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); 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); @@ -1058,52 +1075,68 @@ ToolbarPage *prefs_toolbar_mainwindow; ToolbarPage *prefs_toolbar_composewindow; ToolbarPage *prefs_toolbar_messageview; -void prefs_toolbar_unregister_plugin_item(const gchar *plugin_name, const gchar *item_name) +static void toolbar_unregister_plugin_item_real(GHashTable *hash, const gchar *plugin_name, const gchar *item_name) { gchar *key; - if(!plugin_items) + if(!hash) return; key = g_strdup_printf(plugin_name, "/", item_name, NULL); - g_hash_table_remove(plugin_items, key); + g_hash_table_remove(hash, key); g_free(key); } -void prefs_toolbar_execute_plugin_item(const gchar *id) +void prefs_toolbar_unregister_plugin_item(ToolbarType toolbar_type, const gchar *plugin_name, const gchar *item_name) { - ToolbarPluginItem *value; - GSList *walk; - gboolean found; + 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(GHashTable *hash, const gchar *id) +{ + ToolbarPluginItem *value; + GSList *walk; + gboolean found; - if(!plugin_items) { + if(!hash) { debug_print("No plugin registered toolbar items yet\n"); return; - } + } - value = g_hash_table_lookup(plugin_items, id); - if(!value) { - debug_print("Could not find plugin toolbar item with id %s\n", id); - 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) { + /* 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(value->item_name, value->cb_data); + value->cb(value->item_name, value->cb_data); +} + +void prefs_toolbar_execute_plugin_item(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(*hash, id); } static void destroy_plugin_item_hash_value(ToolbarPluginItem *item) @@ -1113,26 +1146,34 @@ static void destroy_plugin_item_hash_value(ToolbarPluginItem *item) g_free(item); } -void prefs_toolbar_register_plugin_item(const gchar *plugin_name, const gchar *item_name, ToolbarPluginCallback cb, gpointer cb_data) +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; + gchar *key; + ToolbarPluginItem *value; - cm_return_if_fail(plugin_name && item_name); + cm_return_if_fail(plugin_name && item_name); - if(!plugin_items) { - plugin_items = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)destroy_plugin_item_hash_value); - if(!plugin_items) - return; - } + 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(plugin_items, key, value); + 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) @@ -1374,22 +1415,9 @@ static gboolean set_list_selected(GtkTreeSelection *selector, } if (g_utf8_collate(toolbar_ret_descr_from_val(A_CLAWS_PLUGINS), descr) == 0) { - gint num_items, ii; - gchar *txt; - gtk_combo_box_set_active(GTK_COMBO_BOX(prefs_toolbar->item_type_combo), ITEM_PLUGIN); - /* set combo box correctly */ - num_items = g_hash_table_size(plugin_items); - for(ii = 0; ii < num_items; ii++) { - gtk_combo_box_set_active(GTK_COMBO_BOX(prefs_toolbar->item_plugin_combo), ii); - txt = gtk_combo_box_get_active_text(GTK_COMBO_BOX(prefs_toolbar->item_plugin_combo)); - if(!g_utf8_collate(txt, icon_text)) { - break; - } - } - if(ii == num_items) - gtk_combo_box_set_active(GTK_COMBO_BOX(prefs_toolbar->item_plugin_combo), -1); + 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); diff --git a/src/prefs_toolbar.h b/src/prefs_toolbar.h @@ -25,8 +25,8 @@ void prefs_toolbar_done (void); typedef void (*ToolbarPluginCallback)(const gchar *item_name, gpointer data); -void prefs_toolbar_register_plugin_item(const gchar *plugin_name, const gchar *item_name, ToolbarPluginCallback cb, gpointer cb_data); -void prefs_toolbar_unregister_plugin_item(const gchar *plugin_name, const gchar *item_name); -void prefs_toolbar_execute_plugin_item(const gchar *id); +void prefs_toolbar_register_plugin_item(ToolbarType toolbar_type, const gchar *plugin_name, const gchar *item_name, ToolbarPluginCallback cb, gpointer cb_data); +void prefs_toolbar_unregister_plugin_item(ToolbarType toolbar_type, const gchar *plugin_name, const gchar *item_name); +void prefs_toolbar_execute_plugin_item(ToolbarType toolbar_type, const gchar *id); #endif /* __PREFS_CUSTOM_TOOLBAR_H__ */ diff --git a/src/toolbar.c b/src/toolbar.c @@ -1624,7 +1624,7 @@ static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data) static void toolbar_plugins_execute_cb(GtkWidget *widget, gpointer data) { ToolbarItem *toolbar_item = data; - prefs_toolbar_execute_plugin_item(toolbar_item->text); + prefs_toolbar_execute_plugin_item(toolbar_item->type, toolbar_item->text); } static MainWindow *get_mainwin(gpointer data)