im.pidgin.pidgin: fa0e512d79dfe479bc36c2436089b51854ef3eb5

charkins at pidgin.im charkins at pidgin.im
Thu Oct 11 22:40:34 EDT 2007


-----------------------------------------------------------------
Revision: fa0e512d79dfe479bc36c2436089b51854ef3eb5
Ancestor: f33ba0034c79d8e37a70d664ec534356fa361608
Author: charkins at pidgin.im
Date: 2007-10-12T02:33:31
Branch: im.pidgin.pidgin

Modified files:
        pidgin/gtkdocklet.c

ChangeLog: 

Add plugin actions to the docklet context menu. These are the same actions
added to the Tools menu on the buddy list. This is the easiest path to
adding menu items to the docklet from plugins and fixes #1268.

-------------- next part --------------
============================================================
--- pidgin/gtkdocklet.c	c0fbf99c7ebe18814fa14bd3c151a2ee8929eafd
+++ pidgin/gtkdocklet.c	4c73333047f68075a24e54bdf50f53c632f17e6b
@@ -473,7 +473,88 @@ docklet_status_submenu()
 	return menuitem;
 }
 
+
 static void
+plugin_act(GtkObject *obj, PurplePluginAction *pam)
+{
+	if (pam && pam->callback)
+		pam->callback(pam);
+}
+
+static void
+build_plugin_actions(GtkWidget *menu, PurplePlugin *plugin,
+		gpointer context)
+{
+	GtkWidget *menuitem;
+	PurplePluginAction *action = NULL;
+	GList *actions, *l;
+
+	actions = PURPLE_PLUGIN_ACTIONS(plugin, context);
+
+	for (l = actions; l != NULL; l = l->next)
+	{
+		if (l->data)
+		{
+			action = (PurplePluginAction *) l->data;
+			action->plugin = plugin;
+			action->context = context;
+
+			menuitem = gtk_menu_item_new_with_label(action->label);
+			gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
+
+			g_signal_connect(G_OBJECT(menuitem), "activate",
+					G_CALLBACK(plugin_act), action);
+			g_object_set_data_full(G_OBJECT(menuitem), "plugin_action",
+								   action,
+								   (GDestroyNotify)purple_plugin_action_free);
+			gtk_widget_show(menuitem);
+		}
+		else
+			pidgin_separator(menu);
+	}
+
+	g_list_free(actions);
+}
+
+
+static void
+docklet_plugin_actions(GtkWidget *menu)
+{
+	GtkWidget *menuitem, *submenu;
+	PurplePlugin *plugin = NULL;
+	GList *l;
+	int c = 0;
+
+	g_return_if_fail(menu != NULL);
+
+	/* Add a submenu for each plugin with custom actions */
+	for (l = purple_plugins_get_loaded(); l; l = l->next) {
+		plugin = (PurplePlugin *) l->data;
+
+		if (PURPLE_IS_PROTOCOL_PLUGIN(plugin))
+			continue;
+
+		if (!PURPLE_PLUGIN_HAS_ACTIONS(plugin))
+			continue;
+
+		menuitem = gtk_image_menu_item_new_with_label(_(plugin->info->name));
+		gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
+		gtk_widget_show(menuitem);
+
+		submenu = gtk_menu_new();
+		gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu);
+		gtk_widget_show(submenu);
+
+		build_plugin_actions(submenu, plugin, NULL);
+
+		c++;
+	}
+	if(c>0)
+		pidgin_separator(menu);
+}
+
+
+static void
 docklet_menu() {
 	static GtkWidget *menu = NULL;
 	GtkWidget *menuitem;
@@ -539,6 +620,9 @@ docklet_menu() {
 
 	pidgin_separator(menu);
 
+	/* add plugin actions */
+	docklet_plugin_actions(menu);
+
 	pidgin_new_item_from_stock(menu, _("Quit"), GTK_STOCK_QUIT, G_CALLBACK(purple_core_quit), NULL, 0, 0, NULL);
 
 #ifdef _WIN32


More information about the Commits mailing list