pidgin: c93f17d8: Press - or = in the accounts list to reo...

sadrul at pidgin.im sadrul at pidgin.im
Sun Aug 31 03:45:42 EDT 2008


-----------------------------------------------------------------
Revision: c93f17d85d0fe07aed434fceeca41166266e5ecf
Ancestor: ecfa0167d6248cd8fc41c067417f0bb055971dca
Author: sadrul at pidgin.im
Date: 2008-08-31T07:50:49
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/c93f17d85d0fe07aed434fceeca41166266e5ecf

Modified files:
        finch/gntaccount.c

ChangeLog: 

Press - or = in the accounts list to reorder accounts.

-------------- next part --------------
============================================================
--- finch/gntaccount.c	ca651f89af911d02c06bdce4ca60a749bea40954
+++ finch/gntaccount.c	29307a99f6e1ca850b5482c1156b3c483757e7a6
@@ -673,6 +673,45 @@ account_toggled(GntWidget *widget, void 
 	purple_account_set_enabled(account, FINCH_UI, gnt_tree_get_choice(GNT_TREE(widget), key));
 }
 
+static gboolean
+account_list_key_pressed_cb(GntWidget *widget, const char *text, gpointer null)
+{
+	GntTree *tree = GNT_TREE(widget);
+	PurpleAccount *account = gnt_tree_get_selection_data(tree);
+	int move, pos, count;
+	GList *accounts;
+
+	if (!account)
+		return FALSE;
+
+	switch (text[0]) {
+		case '-':
+			move = -1;
+			break;
+		case '=':
+			move = 2;  /* XXX: This seems to be a bug in libpurple */
+			break;
+		default:
+			return FALSE;
+	}
+
+	accounts = purple_accounts_get_all();
+	count = g_list_length(accounts);
+	pos = g_list_index(accounts, account);
+	pos = (move + pos + count + 1) % (count + 1);
+	purple_accounts_reorder(account, pos);
+
+	/* I don't like this, but recreating the entire list seems to be
+	 * the easiest way of doing it */
+	gnt_tree_remove_all(tree);
+	accounts = purple_accounts_get_all();
+	for (; accounts; accounts = accounts->next)
+		account_add(accounts->data);
+	gnt_tree_set_selected(tree, account);
+
+	return TRUE;
+}
+
 static void
 reset_accounts_win(GntWidget *widget, gpointer null)
 {
@@ -712,6 +751,7 @@ void finch_accounts_show_all()
 	}
 
 	g_signal_connect(G_OBJECT(accounts.tree), "toggled", G_CALLBACK(account_toggled), NULL);
+	g_signal_connect(G_OBJECT(accounts.tree), "key_pressed", G_CALLBACK(account_list_key_pressed_cb), NULL);
 
 	gnt_tree_set_col_width(GNT_TREE(accounts.tree), 0, 40);
 	gnt_tree_set_col_width(GNT_TREE(accounts.tree), 1, 10);


More information about the Commits mailing list