im.pidgin.pidgin: 18ef4f37bd517422108a825df6d78ba063ef7c81

sadrul at pidgin.im sadrul at pidgin.im
Wed Jan 23 16:53:07 EST 2008


-----------------------------------------------------------------
Revision: 18ef4f37bd517422108a825df6d78ba063ef7c81
Ancestor: c7753033e7c91d45359e0532abb13afbcdda343e
Author: sadrul at pidgin.im
Date: 2008-01-23T21:46:54
Branch: im.pidgin.pidgin

Modified files:
        finch/gntblist.c finch/gntblist.h finch/plugins/grouping.c

ChangeLog: 

Init and uninit the buddylist managers at appropriate times.

-------------- next part --------------
============================================================
--- finch/gntblist.c	c642a0826955e3d0675faf81b2a6db7f60b24678
+++ finch/gntblist.c	abe8bb1de350b666729110fbc3f0175a608d0e4b
@@ -299,6 +299,8 @@ static FinchBlistManager default_manager
 {
 	"default",
 	N_("Default"),
+	NULL,
+	NULL,
 	default_can_add_node,
 	default_find_parent,
 	default_create_tooltip,
@@ -1827,6 +1829,9 @@ populate_buddylist(void)
 	PurpleBlistNode *node;
 	PurpleBuddyList *list;
 
+	if (ggblist->manager->init)
+		ggblist->manager->init();
+
 	if (strcmp(purple_prefs_get_string(PREF_ROOT "/sort_type"), "text") == 0) {
 		gnt_tree_set_compare_func(GNT_TREE(ggblist->tree),
 			(GCompareFunc)blist_node_compare_text);
@@ -1923,6 +1928,9 @@ redraw_blist(const char *name, PurplePre
 	if (manager == NULL)
 		manager = &default_manager;
 	if (ggblist->manager != manager) {
+		if (ggblist->manager->uninit)
+			ggblist->manager->uninit();
+
 		ggblist->manager = manager;
 		if (manager->can_add_node == NULL)
 			manager->can_add_node = default_can_add_node;
@@ -1937,6 +1945,7 @@ redraw_blist(const char *name, PurplePre
 
 	sel = gnt_tree_get_selection_data(GNT_TREE(ggblist->tree));
 	gnt_tree_remove_all(GNT_TREE(ggblist->tree));
+
 	node = purple_blist_get_root();
 	for (; node; node = purple_blist_node_next(node, TRUE))
 		reset_blist_node_ui_data(node);
============================================================
--- finch/gntblist.h	7ae1341485d973156378db136745bff269c5abf3
+++ finch/gntblist.h	21bc6b81b08070b83547ba8eac77989123046b00
@@ -38,6 +38,8 @@ typedef struct
 {
 	const char *id;                                    /**< An identifier for the manager. */
 	const char *name;                                  /**< Displayable name for the manager. */
+	gboolean (*init)(void);                            /**< Called right before it's being used. */
+	gboolean (*uninit)(void);                          /**< Called right after it's not being used any more. */
 	gboolean (*can_add_node)(PurpleBlistNode *node);   /**< Whether a node should be added to the view. */
 	gpointer (*find_parent)(PurpleBlistNode *node);    /**< Find the parent row for a node. */
 	gboolean (*create_tooltip)(gpointer selected_row, GString **body, char **title);  /**< Create tooltip for a selected row. */
============================================================
--- finch/plugins/grouping.c	cdbfdfbf9e0b7b6a137a41566f5ca4b4abb757f3
+++ finch/plugins/grouping.c	43b8dc64d2d8984578ab0630a6f9cce0b7ac21ee
@@ -34,6 +34,18 @@ static PurpleBlistNode online = {.type =
 static PurpleBlistNode online = {.type = PURPLE_BLIST_OTHER_NODE},
 					   offline = {.type = PURPLE_BLIST_OTHER_NODE};
 
+static gboolean on_offline_init()
+{
+	GntTree *tree = finch_blist_get_tree();
+
+	gnt_tree_add_row_after(tree, &online,
+			gnt_tree_create_row(tree, _("Online")), NULL, NULL);
+	gnt_tree_add_row_after(tree, &offline,
+			gnt_tree_create_row(tree, _("Offline")), NULL, &online);
+
+	return TRUE;
+}
+
 static gboolean on_offline_can_add_node(PurpleBlistNode *node)
 {
 	switch (purple_blist_node_get_type(node)) {
@@ -70,19 +82,7 @@ static gpointer on_offline_find_parent(P
 static gpointer on_offline_find_parent(PurpleBlistNode *node)
 {
 	gpointer ret = NULL;
-	GntTree *tree = finch_blist_get_tree();
 
-	if (!tree)
-		return NULL;
-
-	if (!g_list_find(gnt_tree_get_rows(tree), &online)) {
-		gnt_tree_remove_all(tree);
-		gnt_tree_add_row_after(tree, &online,
-				gnt_tree_create_row(tree, _("Online")), NULL, NULL);
-		gnt_tree_add_row_after(tree, &offline,
-				gnt_tree_create_row(tree, _("Offline")), NULL, &online);
-	}
-
 	switch (purple_blist_node_get_type(node)) {
 		case PURPLE_BLIST_CONTACT_NODE:
 			node = (PurpleBlistNode*)purple_contact_get_priority_buddy((PurpleContact*)node);
@@ -125,6 +125,8 @@ static FinchBlistManager on_offline =
 {
 	"on-offline",
 	N_("Online/Offline"),
+	on_offline_init,
+	NULL,
 	on_offline_can_add_node,
 	on_offline_find_parent,
 	on_offline_create_tooltip,
@@ -135,6 +137,16 @@ static PurpleBlistNode meebo = {.type = 
  * Meebo-like Grouping.
  */
 static PurpleBlistNode meebo = {.type = PURPLE_BLIST_OTHER_NODE};
+static gboolean meebo_init()
+{
+	GntTree *tree = finch_blist_get_tree();
+	if (!g_list_find(gnt_tree_get_rows(tree), &meebo)) {
+		gnt_tree_add_row_last(tree, &meebo,
+				gnt_tree_create_row(tree, _("Offline")), NULL);
+	}
+	return TRUE;
+}
+
 static gpointer meebo_find_parent(PurpleBlistNode *node)
 {
 	static FinchBlistManager *def = NULL;
@@ -144,11 +156,6 @@ static gpointer meebo_find_parent(Purple
 	if (PURPLE_BLIST_NODE_IS_CONTACT(node)) {
 		PurpleBuddy *buddy = purple_contact_get_priority_buddy((PurpleContact*)node);
 		if (buddy && !PURPLE_BUDDY_IS_ONLINE(buddy)) {
-			GntTree *tree = finch_blist_get_tree();
-			if (!g_list_find(gnt_tree_get_rows(tree), &meebo)) {
-				gnt_tree_add_row_last(tree, &meebo,
-						gnt_tree_create_row(tree, _("Offline")), NULL);
-			}
 			return &meebo;
 		}
 	}
@@ -159,7 +166,9 @@ static FinchBlistManager meebo_group =
 {
 	"meebo",
 	N_("Meebo"),
+	meebo_init,
 	NULL,
+	NULL,
 	meebo_find_parent,
 	NULL,
 	{NULL, NULL, NULL, NULL}
@@ -168,6 +177,20 @@ static FinchBlistManager meebo_group =
 /**
  * No Grouping.
  */
+static gboolean no_group_init()
+{
+	GntTree *tree = finch_blist_get_tree();
+	g_object_set(G_OBJECT(tree), "expander-level", 0, NULL);
+	return TRUE;
+}
+
+static gboolean no_group_uninit()
+{
+	GntTree *tree = finch_blist_get_tree();
+	g_object_set(G_OBJECT(tree), "expander-level", 1, NULL);
+	return TRUE;
+}
+
 static gboolean no_group_can_add_node(PurpleBlistNode *node)
 {
 	return on_offline_can_add_node(node);   /* These happen to be the same */
@@ -192,6 +215,8 @@ static FinchBlistManager no_group =
 {
 	"no-group",
 	N_("No Grouping"),
+	no_group_init,
+	no_group_uninit,
 	no_group_can_add_node,
 	no_group_find_parent,
 	NULL,


More information about the Commits mailing list