changeset 8952:e3f4657fa555

[gaim-migrate @ 9724] " This patch enables plugins to have the ability to provide a list of named call-backs for a GaimGroup in the buddy list. Most of the credit for this should go to Christopher (siege) O'Brien who did the same for the buddy menu (patch 907267). See his excellent description on that patch :)" --Stu Tomlinson committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Sun, 16 May 2004 17:43:00 +0000
parents 3e69753b555b
children 0277908e367d
files src/blist.c src/blist.h src/gtkblist.c src/multi.h
diffstat 4 files changed, 61 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/blist.c	Sun May 16 15:46:46 2004 +0000
+++ b/src/blist.c	Sun May 16 17:43:00 2004 +0000
@@ -2723,6 +2723,13 @@
 	return menu;
 }
 
+GList *gaim_group_get_extended_menu(GaimGroup *g) {
+	GList *menu = NULL;
+	gaim_signal_emit(gaim_blist_get_handle(), "group-extended-menu",
+		g, &menu);
+	return menu;
+}
+
 
 int gaim_blist_get_group_size(GaimGroup *group, gboolean offline) {
 	if(!group)
@@ -2799,6 +2806,11 @@
 			     gaim_value_new(GAIM_TYPE_SUBTYPE,
 					    GAIM_SUBTYPE_BLIST_BUDDY),
 			     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,
+					    GAIM_SUBTYPE_BLIST_GROUP),
+			     gaim_value_new(GAIM_TYPE_BOXED, "GList **"));
 }
 
 void
--- a/src/blist.h	Sun May 16 15:46:46 2004 +0000
+++ b/src/blist.h	Sun May 16 17:43:00 2004 +0000
@@ -861,6 +861,12 @@
 */
 GList *gaim_buddy_get_extended_menu(GaimBuddy *b);
 
+/**
+ * Retrieves the extended menu items for a group.
+ * @param g      The group to obtain the extended menu items for
+*/
+GList *gaim_group_get_extended_menu(GaimGroup *g);
+
 
 /**************************************************************************/
 /** @name UI Registration Functions                                       */
--- a/src/gtkblist.c	Sun May 16 15:46:46 2004 +0000
+++ b/src/gtkblist.c	Sun May 16 17:43:00 2004 +0000
@@ -1065,6 +1065,13 @@
 		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;
@@ -1186,9 +1193,12 @@
 }
 
 static GtkWidget *
-create_group_menu (GaimBlistNode *node)
+create_group_menu (GaimBlistNode *node, GaimGroup *g)
 {
 	GtkWidget *menu;
+	GList *list = NULL, *l = NULL;
+	gboolean dup_separator = FALSE;
+	GtkWidget *menuitem;
 
 	menu = gtk_menu_new();
 	gaim_new_item_from_stock(menu, _("Add a _Buddy"), GTK_STOCK_ADD,
@@ -1199,6 +1209,31 @@
 				 G_CALLBACK(gaim_gtk_blist_remove_cb), node, 0, 0, NULL);
 	gaim_new_item_from_stock(menu, _("_Rename"), NULL,
 				 G_CALLBACK(show_rename_group), node, 0, 0, NULL);
+
+	list = gaim_group_get_extended_menu(g);
+	for(l = list; l; l = l->next) {
+		struct proto_group_menu *pgm = l->data;
+
+		/* draw "-" titled menu items as a separator.  see previous,
+		   identical-looking code. (in make_buddy_menu)*/
+		if(pgm == NULL) {
+			if(! dup_separator) {
+				gaim_separator(menu);
+				dup_separator = TRUE;
+			}
+			continue;
+		} else {
+			dup_separator = FALSE;
+		}
+
+		menuitem = gtk_menu_item_new_with_mnemonic(pgm->label);
+		g_object_set_data(G_OBJECT(menuitem), "gaimcallback", pgm);
+		g_signal_connect(G_OBJECT(menuitem), "activate",
+			G_CALLBACK(gaim_proto_group_menu_cb), g);
+		gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
+	}
+	g_list_free(list);
+
 	return menu;
 }
 
@@ -1351,7 +1386,8 @@
 
 	/* Create a menu based on the thing we right-clicked on */
 	if (GAIM_BLIST_NODE_IS_GROUP(node)) {
-		menu = create_group_menu(node);
+		GaimGroup *g = (GaimGroup *)node;
+		menu = create_group_menu(node, g);
 	} else if (GAIM_BLIST_NODE_IS_CHAT(node)) {
 		GaimChat *c = (GaimChat *)node;
 		GaimPlugin *prpl = NULL;
--- a/src/multi.h	Sun May 16 15:46:46 2004 +0000
+++ b/src/multi.h	Sun May 16 17:43:00 2004 +0000
@@ -45,6 +45,11 @@
 	GaimConnection *gc;
 };
 
+struct proto_group_menu {
+	char *label;
+	void (*callback)(GaimGroup *);
+};
+
 struct proto_chat_entry {
 	char *label;
 	char *identifier;