pidgin: ecfa0167: Add 'Nested Grouping' option in the grou...

sadrul at pidgin.im sadrul at pidgin.im
Sun Aug 31 02:25:37 EDT 2008


-----------------------------------------------------------------
Revision: ecfa0167d6248cd8fc41c067417f0bb055971dca
Ancestor: b1ef699822316afbf61b80020078d92a5fd3ba8b
Author: sadrul at pidgin.im
Date: 2008-08-31T06:31:17
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/ecfa0167d6248cd8fc41c067417f0bb055971dca

Modified files:
        ChangeLog finch/plugins/grouping.c

ChangeLog: 

Add 'Nested Grouping' option in the grouping plugin

Nested groups are detected by the '/' character in the group name. For
example, groups 'Work/Accounting' and 'Work/Lab' will both be nested
under a 'Work' parent group. It would probably make more sense to
actually name the subgroups 'Accounting' and 'Lab' in this case, and a
patch to make that happen will be gladly accepted.

I think some other client uses similar behaviour for group nestedness.

-------------- next part --------------
============================================================
--- ChangeLog	bf7e8dfff923c2b497c3f01a410891a90a05f089
+++ ChangeLog	197ff3db55dd19e2bde58aa0fd88d28bf70f978a
@@ -1,6 +1,9 @@ version 2.5.2 (??/??/????):
 Pidgin and Finch: The Pimpin' Penguin IM Clients That're Good for the Soul
 
 version 2.5.2 (??/??/????):
+	Finch:
+	* A new 'Nested Grouping' option in the 'Grouping' plugin. Group
+	  hierarchies are defined by the '/' character in the group names
 
 version 2.5.1 (08/30/2008):
 	libpurple:
============================================================
--- finch/plugins/grouping.c	43b8dc64d2d8984578ab0630a6f9cce0b7ac21ee
+++ finch/plugins/grouping.c	f5828a65dcdb3bfb713f9d2694d9c0ca3dfed6e9
@@ -28,6 +28,8 @@
 
 #include "gnttree.h"
 
+static FinchBlistManager *default_manager;
+
 /**
  * Online/Offline
  */
@@ -103,12 +105,8 @@ static gboolean on_offline_create_toolti
 
 static gboolean on_offline_create_tooltip(gpointer selected_row, GString **body, char **tool_title)
 {
-	static FinchBlistManager *def = NULL;
 	PurpleBlistNode *node = selected_row;
 
-	if (def == NULL)
-		def = finch_blist_manager_find("default");
-
 	if (purple_blist_node_get_type(node) == PURPLE_BLIST_OTHER_NODE) {
 		/* There should be some easy way of getting the total online count,
 		 * or total number of chats. Doing a loop here will probably be pretty
@@ -117,7 +115,7 @@ static gboolean on_offline_create_toolti
 			*body = g_string_new(node == &online ? _("Online Buddies") : _("Offline Buddies"));
 		return TRUE;
 	} else {
-		return def ? def->create_tooltip(selected_row, body, tool_title) : FALSE;
+		return default_manager ? default_manager->create_tooltip(selected_row, body, tool_title) : FALSE;
 	}
 }
 
@@ -149,17 +147,13 @@ static gpointer meebo_find_parent(Purple
 
 static gpointer meebo_find_parent(PurpleBlistNode *node)
 {
-	static FinchBlistManager *def = NULL;
-	if (def == NULL)
-		def = finch_blist_manager_find("default");
-
 	if (PURPLE_BLIST_NODE_IS_CONTACT(node)) {
 		PurpleBuddy *buddy = purple_contact_get_priority_buddy((PurpleContact*)node);
 		if (buddy && !PURPLE_BUDDY_IS_ONLINE(buddy)) {
 			return &meebo;
 		}
 	}
-	return def->find_parent(node);
+	return default_manager->find_parent(node);
 }
 
 static FinchBlistManager meebo_group =
@@ -223,12 +217,127 @@ static FinchBlistManager no_group =
 	{NULL, NULL, NULL, NULL}
 };
 
+/**
+ * Nested Grouping
+ */
+static GHashTable *groups;
+
 static gboolean
+nested_group_init(void)
+{
+	groups = g_hash_table_new_full(g_str_hash, g_str_equal,
+			g_free, g_free);
+	return TRUE;
+}
+
+static gboolean
+nested_group_uninit(void)
+{
+	g_hash_table_destroy(groups);
+	groups = NULL;
+	return TRUE;
+}
+
+static gpointer
+nested_group_find_parent(PurpleBlistNode *node)
+{
+	char *name;
+	PurpleGroup *group;
+	char *sep;
+	PurpleBlistNode *ret, *parent;
+	GntTree *tree;
+
+	if (!PURPLE_BLIST_NODE_IS_GROUP(node))
+		return default_manager->find_parent(node);
+
+	group = (PurpleGroup *)node;
+	name = g_strdup(purple_group_get_name(group));
+	if (!(sep = strchr(name, '/'))) {
+		g_free(name);
+		return default_manager->find_parent(node);
+	}
+
+	tree = finch_blist_get_tree();
+	parent = NULL;
+
+	while (sep) {
+		*sep = 0;
+		if (*(sep + 1) && (ret = (PurpleBlistNode *)purple_find_group(name))) {
+			finch_blist_manager_add_node(ret);
+			parent = ret;
+		} else if (!(ret = g_hash_table_lookup(groups, name))) {
+			ret = g_new0(PurpleBlistNode, 1);
+			g_hash_table_insert(groups, g_strdup(name), ret);
+			ret->type = PURPLE_BLIST_OTHER_NODE;
+			gnt_tree_add_row_last(tree, ret,
+					gnt_tree_create_row(tree, name), parent);
+			parent = ret;
+		}
+		*sep = '/';
+		sep = strchr(sep + 1, '/');
+	}
+
+	g_free(name);
+	return ret;
+}
+
+static gboolean
+nested_group_create_tooltip(gpointer selected_row, GString **body, char **title)
+{
+	PurpleBlistNode *node = selected_row;
+	if (!node ||
+			purple_blist_node_get_type(node) != PURPLE_BLIST_OTHER_NODE)
+		return default_manager->create_tooltip(selected_row, body, title);
+	if (body)
+		*body = g_string_new(_("Nested Subgroup"));  /* Perhaps list the child groups/subgroups? */
+	return TRUE;
+}
+
+static gboolean
+nested_group_can_add_node(PurpleBlistNode *node)
+{
+	PurpleBlistNode *group;
+	int len;
+
+	if (!PURPLE_BLIST_NODE_IS_GROUP(node))
+		return default_manager->can_add_node(node);
+
+	if (default_manager->can_add_node(node))
+		return TRUE;
+
+	len = strlen(purple_group_get_name((PurpleGroup*)node));
+	group = purple_blist_get_root();
+	for (; group; group = purple_blist_node_get_sibling_next(group)) {
+		if (group == node)
+			continue;
+		if (strncmp(purple_group_get_name((PurpleGroup *)node),
+					purple_group_get_name((PurpleGroup *)group), len) == 0 &&
+				default_manager->can_add_node(group))
+			return TRUE;
+	}
+	return FALSE;
+}
+
+static FinchBlistManager nested_group =
+{
+	"nested",
+	N_("Nested Grouping (experimental)"),
+	.init = nested_group_init,
+	.uninit = nested_group_uninit,
+	.find_parent = nested_group_find_parent,
+	.create_tooltip = nested_group_create_tooltip,
+	.can_add_node = nested_group_can_add_node,
+};
+
+static gboolean
 plugin_load(PurplePlugin *plugin)
 {
+	default_manager = finch_blist_manager_find("default");
+
 	finch_blist_install_manager(&on_offline);
 	finch_blist_install_manager(&meebo_group);
 	finch_blist_install_manager(&no_group);
+	finch_blist_install_manager(&nested_group);
 	return TRUE;
 }
 
@@ -238,6 +347,7 @@ plugin_unload(PurplePlugin *plugin)
 	finch_blist_uninstall_manager(&on_offline);
 	finch_blist_uninstall_manager(&meebo_group);
 	finch_blist_uninstall_manager(&no_group);
+	finch_blist_uninstall_manager(&nested_group);
 	return TRUE;
 }
 


More information about the Commits mailing list