changeset 24150:95da3ec97c27

Show a manually added new empty group even if the preference is not set. The group is automatically hidden in the buddylist if it remains empty for a while (1 minute). This should make it easier to create new groups and moving/adding buddies to it.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Mon, 06 Oct 2008 02:13:53 +0000
parents f8ffea0d1c65
children bfe33e14f4b2
files finch/gntblist.c
diffstat 1 files changed, 58 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/finch/gntblist.c	Sat Oct 04 23:36:52 2008 +0000
+++ b/finch/gntblist.c	Mon Oct 06 02:13:53 2008 +0000
@@ -63,6 +63,8 @@
 #define PREF_ROOT "/finch/blist"
 #define TYPING_TIMEOUT 4000
 
+#define SHOW_EMPTY_GROUP_TIMEOUT  60
+
 typedef struct
 {
 	GntWidget *window;
@@ -86,6 +88,13 @@
 	GntMenuItem *plugins;
 	GntMenuItem *grouping;
 
+	/* When a new group is manually added, it is empty, but we still want to show it
+	 * for a while (SHOW_EMPTY_GROUP_TIMEOUT seconds) even if 'show empty groups' is
+	 * not selected.
+	 */
+	GList *new_group;
+	guint new_group_timeout;
+
 	FinchBlistManager *manager;
 } FinchBlist;
 
@@ -194,6 +203,9 @@
 			if (default_can_add_node(nd))
 				return TRUE;
 		}
+
+		if (ggblist && ggblist->new_group && g_list_find(ggblist->new_group, node))
+			return TRUE;
 	}
 
 	return FALSE;
@@ -489,9 +501,13 @@
 	FinchBlist *ggblist = FINCH_GET_DATA(list);
 	PurpleBlistNode *parent;
 
-	if (ggblist == NULL || FINCH_GET_DATA(node)== NULL)
+	if (ggblist == NULL || FINCH_GET_DATA(node) == NULL)
 		return;
 
+	if (PURPLE_BLIST_NODE_IS_GROUP(node) && ggblist->new_group) {
+		ggblist->new_group = g_list_remove(ggblist->new_group, node);
+	}
+
 	gnt_tree_remove(GNT_TREE(ggblist->tree), node);
 	reset_blist_node_ui_data(node);
 	if (ggblist->tagged)
@@ -572,6 +588,27 @@
 		ggblist->manager = &default_manager;
 }
 
+static gboolean
+remove_new_empty_group(gpointer data)
+{
+	PurpleBuddyList *list;
+
+	if (!ggblist)
+		return FALSE;
+
+	list = purple_get_blist();
+	g_return_val_if_fail(list, FALSE);
+
+	ggblist->new_group_timeout = 0;
+	while (ggblist->new_group) {
+		PurpleBlistNode *group = ggblist->new_group->data;
+		ggblist->new_group = g_list_delete_link(ggblist->new_group, ggblist->new_group);
+		node_update(list, group);
+	}
+
+	return FALSE;
+}
+
 static void
 add_buddy_cb(void *data, PurpleRequestFields *allfields)
 {
@@ -768,7 +805,21 @@
 	if (!grp)
 	{
 		grp = purple_group_new(group);
+		if (ggblist) {
+			ggblist->new_group = g_list_prepend(ggblist->new_group, grp);
+			if (!ggblist->new_group_timeout) {
+				ggblist->new_group_timeout = purple_timeout_add_seconds(SHOW_EMPTY_GROUP_TIMEOUT,
+						remove_new_empty_group, NULL);
+			}
+		}
 		purple_blist_add_group(grp, NULL);
+
+		/* Select the new group */
+		if (ggblist && ggblist->tree) {
+			FinchBlistNode *fnode = FINCH_GET_DATA((PurpleBlistNode*)grp);
+			if (fnode && fnode->row)
+				gnt_tree_set_selected(GNT_TREE(ggblist->tree), grp);
+		}
 	}
 	else
 	{
@@ -1955,6 +2006,12 @@
 	remove_peripherals(ggblist);
 	if (ggblist->tagged)
 		g_list_free(ggblist->tagged);
+
+	if (ggblist->new_group_timeout)
+		purple_timeout_remove(ggblist->new_group_timeout);
+	if (ggblist->new_group)
+		g_list_free(ggblist->new_group);
+
 	g_free(ggblist);
 	ggblist = NULL;
 }