changeset 9013:d494fd1bd90b

[gaim-migrate @ 9789] " This patch allows plugins to extend the chat right-click menu in a UI-neutral way, just like they can already for the buddy and group right-click menus. Credit again to Christopher (siege) O'Brien for the initial implementation in the buddy menu which I continue to copy :)" --Stu Tomlinson committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Sat, 22 May 2004 16:46:07 +0000
parents c251e1d7925c
children 51b5b3a622ce
files ChangeLog src/blist.c src/blist.h src/gtkblist.c
diffstat 4 files changed, 72 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sat May 22 16:43:55 2004 +0000
+++ b/ChangeLog	Sat May 22 16:46:07 2004 +0000
@@ -17,7 +17,7 @@
 	  Stoddard of Novell)
 	* Find and Save buttons on the debug window (Stu Tomlinson)
 	* Plugin Actions menu (Christopher (siege) O'Brien)
-	* Plugins can now add entries to the rclick menu of a group (Stu
+	* Plugins can now add entries to the rclick menu of a group and a chat(Stu
 	  Tomlinson, Christopher (siege) O'Brien)
 	* Hyperlink colors are now themeable via your ~/.gtkrc-2.0 file
 
--- a/src/blist.c	Sat May 22 16:43:55 2004 +0000
+++ b/src/blist.c	Sat May 22 16:46:07 2004 +0000
@@ -2727,6 +2727,13 @@
 	return menu;
 }
 
+GList *gaim_chat_get_extended_menu(GaimChat *c) {
+	GList *menu = NULL;
+	gaim_signal_emit(gaim_blist_get_handle(), "chat-extended-menu",
+		c, &menu);
+	return menu;
+}
+
 GList *gaim_group_get_extended_menu(GaimGroup *g) {
 	GList *menu = NULL;
 	gaim_signal_emit(gaim_blist_get_handle(), "group-extended-menu",
@@ -2810,6 +2817,11 @@
 			     gaim_value_new(GAIM_TYPE_SUBTYPE,
 					    GAIM_SUBTYPE_BLIST_BUDDY),
 			     gaim_value_new(GAIM_TYPE_BOXED, "GList **"));
+	gaim_signal_register(handle, "chat-extended-menu",
+			     gaim_marshal_VOID__POINTER_POINTER, NULL, 2,
+			     gaim_value_new(GAIM_TYPE_SUBTYPE,
+					    GAIM_SUBTYPE_BLIST_CHAT),
+			     gaim_value_new(GAIM_TYPE_BOXED, "GList **"));
 	gaim_signal_register(handle, "group-extended-menu",
 			     gaim_marshal_VOID__POINTER_POINTER, NULL, 2,
 			     gaim_value_new(GAIM_TYPE_SUBTYPE,
--- a/src/blist.h	Sat May 22 16:43:55 2004 +0000
+++ b/src/blist.h	Sat May 22 16:46:07 2004 +0000
@@ -863,6 +863,12 @@
 GList *gaim_buddy_get_extended_menu(GaimBuddy *b);
 
 /**
+ * Retrieves the extended menu items for a chat.
+ * @param c      The chat to obtain the extended menu items for
+*/
+GList *gaim_chat_get_extended_menu(GaimChat *c);
+
+/**
  * Retrieves the extended menu items for a group.
  * @param g      The group to obtain the extended menu items for
 */
--- a/src/gtkblist.c	Sat May 22 16:43:55 2004 +0000
+++ b/src/gtkblist.c	Sat May 22 16:46:07 2004 +0000
@@ -1065,13 +1065,6 @@
 		pbm->callback(pbm->gc, b->name);
 }
 
-static void gaim_proto_group_menu_cb(GtkMenuItem *item, GaimGroup *g)
-{
-	struct proto_group_menu *pgm = g_object_get_data(G_OBJECT(item), "gaimcallback");
-	if (pgm->callback)
-		pgm->callback(g);
-}
-
 static void make_buddy_menu(GtkWidget *menu, GaimPluginProtocolInfo *prpl_info, GaimBuddy *b)
 {
 	GList *list = NULL, *l = NULL;
@@ -1095,9 +1088,8 @@
 		for(l = list; l; l = l->next) {
 			struct proto_buddy_menu *pbm = l->data;
 
-			/* draw NULL menu items as a separator. Since the
-			   pbm is not being used in a callback, it needs to be
-			   freed. Also, do some simple checking to prevent
+			/* draw NULL menu items as a separator.
+			   Also, do some simple checking to prevent
 			   doubled-up separators */
 			if(pbm == NULL) {
 				if(! dup_separator) {
@@ -1131,7 +1123,6 @@
 				gaim_separator(menu);
 				dup_separator = TRUE;
 			}
-			g_free(pbm);
 			continue;
 		} else {
 			dup_separator = FALSE;
@@ -1191,6 +1182,13 @@
 	return FALSE;
 }
 
+static void gaim_proto_group_menu_cb(GtkMenuItem *item, GaimGroup *g)
+{
+	struct proto_group_menu *pgm = g_object_get_data(G_OBJECT(item), "gaimcallback");
+	if (pgm->callback)
+		pgm->callback(g);
+}
+
 static GtkWidget *
 create_group_menu (GaimBlistNode *node, GaimGroup *g)
 {
@@ -1250,8 +1248,9 @@
 		  GaimPluginProtocolInfo *prpl_info)
 {
 	GtkWidget *menu;
-	GList *list;
+	GList *list, *l;
 	GtkWidget *menuitem;
+	gboolean dup_separator = FALSE;
 	gboolean autojoin = (gaim_blist_node_get_bool(node,
 						     "gtk-autojoin") || (gaim_blist_node_get_string(node,
 									 "gtk-autojoin") != NULL));
@@ -1267,6 +1266,20 @@
 		list = prpl_info->chat_menu(c->account->gc, c->components);
 		while (list) {
 			struct proto_chat_menu *pcm = list->data;
+
+			/* draw NULL menu items as a separator.
+			   Also, do some simple checking to prevent
+			   doubled-up separators */
+			if(pcm == NULL) {
+				if(! dup_separator) {
+					gaim_separator(menu);
+					dup_separator = TRUE;
+				}
+				continue;
+			} else {
+				dup_separator = FALSE;
+			}
+
 			menuitem = gtk_menu_item_new_with_mnemonic(pcm->label);
 			g_object_set_data(G_OBJECT(menuitem), "gaimcallback", pcm);
 			g_signal_connect(G_OBJECT(menuitem), "activate",
@@ -1275,6 +1288,34 @@
 			list = list->next;
 		}
 	}
+
+	/* check for additional menu items which may be added by other
+	   plugins. */
+	list = gaim_chat_get_extended_menu(c);
+	for(l = list; l; l = l->next) {
+		struct proto_chat_menu *pcm = l->data;
+
+		/* draw NULL menu items as a separator.  see previous,
+		   identical-looking code. */
+		if(pcm == NULL) {
+			if(! dup_separator) {
+				gaim_separator(menu);
+				dup_separator = TRUE;
+			}
+			continue;
+		} else {
+			dup_separator = FALSE;
+		}
+
+		menuitem = gtk_menu_item_new_with_mnemonic(pcm->label);
+		g_object_set_data(G_OBJECT(menuitem), "gaimcallback", pcm);
+		g_signal_connect(G_OBJECT(menuitem), "activate",
+			G_CALLBACK(gaim_proto_chat_menu_cb), c);
+		gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
+	}
+	g_list_free(list);
+
+	/* moving on to the old ui-specific plugin menus */
 	gaim_signal_emit(gaim_gtk_blist_get_handle(),
 			"drawing-menu", menu, c);