changeset 22190:bcaf4a037704

Init and uninit the buddylist managers at appropriate times.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Wed, 23 Jan 2008 21:46:54 +0000
parents 4165bcd57486
children 3634d27ec6f1 1e103e1b845f 6d9757319bf6
files finch/gntblist.c finch/gntblist.h finch/plugins/grouping.c
diffstat 3 files changed, 53 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/finch/gntblist.c	Wed Jan 23 21:45:43 2008 +0000
+++ b/finch/gntblist.c	Wed Jan 23 21:46:54 2008 +0000
@@ -299,6 +299,8 @@
 {
 	"default",
 	N_("Default"),
+	NULL,
+	NULL,
 	default_can_add_node,
 	default_find_parent,
 	default_create_tooltip,
@@ -1827,6 +1829,9 @@
 	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 @@
 	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 @@
 
 	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);
--- a/finch/gntblist.h	Wed Jan 23 21:45:43 2008 +0000
+++ b/finch/gntblist.h	Wed Jan 23 21:46:54 2008 +0000
@@ -38,6 +38,8 @@
 {
 	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. */
--- a/finch/plugins/grouping.c	Wed Jan 23 21:45:43 2008 +0000
+++ b/finch/plugins/grouping.c	Wed Jan 23 21:46:54 2008 +0000
@@ -34,6 +34,18 @@
 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,18 +82,6 @@
 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:
@@ -125,6 +125,8 @@
 {
 	"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 @@
  * 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 @@
 	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,6 +166,8 @@
 {
 	"meebo",
 	N_("Meebo"),
+	meebo_init,
+	NULL,
 	NULL,
 	meebo_find_parent,
 	NULL,
@@ -168,6 +177,20 @@
 /**
  * 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 @@
 {
 	"no-group",
 	N_("No Grouping"),
+	no_group_init,
+	no_group_uninit,
 	no_group_can_add_node,
 	no_group_find_parent,
 	NULL,