changeset 14405:8375ecb6152b

[gaim-migrate @ 17113] Pressing Alt+a will bring up a list of available 'actions', which you can use show the buddylist/accounts/debug etc. windows. Pressing ctrl+o in the buddylist will toggle showing online/offline users. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Fri, 01 Sep 2006 12:06:51 +0000
parents 8ff8f1c897b5
children c72f33e14f98
files console/gntblist.c console/gntui.c console/libgnt/gnt.h console/libgnt/gntmain.c
diffstat 4 files changed, 142 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/console/gntblist.c	Fri Sep 01 11:03:18 2006 +0000
+++ b/console/gntblist.c	Fri Sep 01 12:06:51 2006 +0000
@@ -1130,6 +1130,13 @@
 			ret = TRUE;
 		}
 	}
+	else if (strcmp(text, GNT_KEY_CTRL_O) == 0)
+	{
+		gaim_prefs_set_bool(PREF_ROOT "/showoffline",
+				!gaim_prefs_get_bool(PREF_ROOT "/showoffline"));
+		ret = TRUE;
+		stop = TRUE;
+	}
 
 	if (stop)
 		g_signal_stop_emission_by_name(G_OBJECT(widget), "key_pressed");
--- a/console/gntui.c	Fri Sep 01 11:03:18 2006 +0000
+++ b/console/gntui.c	Fri Sep 01 12:06:51 2006 +0000
@@ -4,9 +4,14 @@
 #include "gntblist.h"
 #include "gntconn.h"
 #include "gntconv.h"
+#include "gntdebug.h"
 #include "gntnotify.h"
 #include "gntplugin.h"
+#include "gntprefs.h"
 #include "gntrequest.h"
+#include "gntstatus.h"
+
+#include "internal.h"
 
 #include <prefs.h>
 
@@ -41,7 +46,12 @@
 	gg_request_init();
 	gaim_request_set_ui_ops(gg_request_get_ui_ops());
 
-	gg_plugins_show_all();
+	gnt_register_action(_("Accounts"), gg_accounts_show_all);
+	gnt_register_action(_("Buddy List"), gg_blist_show);
+	gnt_register_action(_("Debug Window"), gg_debug_window_show);
+	gnt_register_action(_("Plugins"), gg_plugins_show_all);
+	gnt_register_action(_("Preferences"), gg_prefs_show_all);
+	gnt_register_action(_("Statuses"), gg_savedstatus_show_all);
 
 #ifdef STANDALONE
 
--- a/console/libgnt/gnt.h	Fri Sep 01 11:03:18 2006 +0000
+++ b/console/libgnt/gnt.h	Fri Sep 01 12:06:51 2006 +0000
@@ -27,5 +27,7 @@
 
 void gnt_widget_set_urgent(GntWidget *widget);
 
+void gnt_register_action(const char *label, void (*callback)());
+
 void gnt_quit();
 
--- a/console/libgnt/gntmain.c	Fri Sep 01 11:03:18 2006 +0000
+++ b/console/libgnt/gntmain.c	Fri Sep 01 12:06:51 2006 +0000
@@ -46,11 +46,12 @@
 static gboolean mouse_enabled;
 
 static GMainLoop *loop;
+
 static struct
 {
 	GntWidget *window;
 	GntWidget *tree;
-} window_list;
+} _list, *window_list, *action_list;
 
 typedef struct
 {
@@ -77,6 +78,8 @@
 static gboolean refresh_screen();
 static const GList *list_all_windows();
 
+static void show_actions_list();
+
 static GntWM wm = 
 {
 	NULL,   /* new_window */
@@ -174,9 +177,9 @@
 	gnt_widget_draw(widget);
 	top_panel(node->panel);
 
-	if (window_list.window)
+	if (_list.window)
 	{
-		GntNode *nd = g_hash_table_lookup(nodes, window_list.window);
+		GntNode *nd = g_hash_table_lookup(nodes, _list.window);
 		top_panel(nd->panel);
 	}
 	update_screen(NULL);
@@ -188,7 +191,7 @@
 {
 	GntTextFormatFlags flag = 0;
 
-	if (window_list.window == NULL)
+	if (window_list == NULL)
 		return;
 
 	if (wid == ordered->data)
@@ -196,7 +199,7 @@
 	else if (GNT_WIDGET_IS_FLAG_SET(wid, GNT_WIDGET_URGENT))
 		flag |= GNT_TEXT_FLAG_BOLD;
 
-	gnt_tree_set_row_flags(GNT_TREE(window_list.tree), wid, flag);
+	gnt_tree_set_row_flags(GNT_TREE(window_list->tree), wid, flag);
 }
 
 static void
@@ -327,20 +330,34 @@
 }
 
 static void
+setup__list()
+{
+	GntWidget *tree, *win;
+	win = _list.window = gnt_box_new(FALSE, FALSE);
+	gnt_box_set_toplevel(GNT_BOX(win), TRUE);
+	gnt_box_set_pad(GNT_BOX(win), 0);
+
+	tree = _list.tree = gnt_tree_new();
+	gnt_box_add_widget(GNT_BOX(win), tree);
+}
+
+static void
 show_window_list()
 {
 	GntWidget *tree, *win;
 	GList *iter;
 
-	if (window_list.window)
+	if (window_list)
 		return;
+	
+	setup__list();
 
-	win = window_list.window = gnt_box_new(FALSE, FALSE);
-	gnt_box_set_toplevel(GNT_BOX(win), TRUE);
+	window_list = &_list;
+
+	win = window_list->window;
+	tree = window_list->tree;
+
 	gnt_box_set_title(GNT_BOX(win), "Window List");
-	gnt_box_set_pad(GNT_BOX(win), 0);
-
-	tree = window_list.tree = gnt_tree_new();
 
 	for (iter = focus_list; iter; iter = iter->next)
 	{
@@ -352,7 +369,7 @@
 	}
 
 	gnt_tree_set_selected(GNT_TREE(tree), ordered->data);
-	gnt_box_add_widget(GNT_BOX(win), tree);
+	g_signal_connect(G_OBJECT(tree), "activate", G_CALLBACK(window_list_activate), NULL);
 
 	gnt_tree_set_col_width(GNT_TREE(tree), 0, getmaxx(stdscr) / 3);
 	gnt_widget_set_size(tree, 0, getmaxy(stdscr) / 2);
@@ -361,8 +378,6 @@
 	lock_focus_list = 1;
 	gnt_widget_show(win);
 	lock_focus_list = 0;
-
-	g_signal_connect(G_OBJECT(tree), "activate", G_CALLBACK(window_list_activate), NULL);
 }
 
 static void
@@ -720,6 +735,11 @@
 					mode = GNT_KP_MODE_WINDOW_LIST;
 					show_window_list();
 				}
+				else if (strcmp(buffer + 1, "a") == 0)
+				{
+					mode = GNT_KP_MODE_WINDOW_LIST;
+					show_actions_list();
+				}
 				else if (strcmp(buffer + 1, "r") == 0 && focus_list)
 				{
 					/* Resize window */
@@ -810,18 +830,20 @@
 			mode = GNT_KP_MODE_NORMAL;
 		}
 	}
-	else if (mode == GNT_KP_MODE_WINDOW_LIST && window_list.window)
+	else if (mode == GNT_KP_MODE_WINDOW_LIST && _list.window)
 	{
-		gnt_widget_key_pressed(window_list.window, buffer);
+		gnt_widget_key_pressed(_list.window, buffer);
 
 		if (buffer[0] == '\r' || (buffer[0] == 27 && buffer[1] == 0))
 		{
 			mode = GNT_KP_MODE_NORMAL;
 			lock_focus_list = 1;
-			gnt_widget_destroy(window_list.window);
-			window_list.window = NULL;
-			window_list.tree = NULL;
+			gnt_widget_destroy(_list.window);
+			_list.window = NULL;
+			_list.tree = NULL;
 			lock_focus_list = 0;
+			window_list = NULL;
+			action_list = NULL;
 		}
 	}
 	else if (mode == GNT_KP_MODE_RESIZE)
@@ -1054,13 +1076,13 @@
 
 	refresh_node(widget, node, NULL);
 
-	if (window_list.window)
+	if (window_list)
 	{
-		if ((GNT_IS_BOX(widget) && GNT_BOX(widget)->title) && window_list.window != widget
+		if ((GNT_IS_BOX(widget) && GNT_BOX(widget)->title) && window_list->window != widget
 				&& GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_CAN_TAKE_FOCUS))
 		{
-			gnt_tree_add_row_last(GNT_TREE(window_list.tree), widget,
-					gnt_tree_create_row(GNT_TREE(window_list.tree), GNT_BOX(widget)->title),
+			gnt_tree_add_row_last(GNT_TREE(window_list->tree), widget,
+					gnt_tree_create_row(GNT_TREE(window_list->tree), GNT_BOX(widget)->title),
 					NULL);
 			update_window_in_list(widget);
 		}
@@ -1081,9 +1103,9 @@
 
 	g_hash_table_remove(nodes, widget);
 
-	if (window_list.window)
+	if (window_list)
 	{
-		gnt_tree_remove(GNT_TREE(window_list.tree), widget);
+		gnt_tree_remove(GNT_TREE(window_list->tree), widget);
 	}
 
 	update_screen(NULL);
@@ -1100,7 +1122,7 @@
 	node = g_hash_table_lookup(nodes, widget);
 	if (node && !node->panel)
 	{
-		if (wm.new_window)
+		if (wm.new_window && node->me != _list.window)
 			node->panel = wm.new_window(node->me);
 		else
 			node->panel = new_panel(node->me->window);
@@ -1111,9 +1133,9 @@
 		}
 	}
 
-	if (window_list.window)
+	if (_list.window)
 	{
-		GntNode *nd = g_hash_table_lookup(nodes, window_list.window);
+		GntNode *nd = g_hash_table_lookup(nodes, _list.window);
 		top_panel(nd->panel);
 	}
 
@@ -1131,7 +1153,7 @@
 	while (widget->parent)
 		widget = widget->parent;
 
-	if (widget == window_list.window)
+	if (widget == _list.window)
 		return TRUE;
 
 	if (ordered && ordered->data == widget)
@@ -1226,3 +1248,74 @@
 	draw_taskbar(FALSE);
 }
 
+/**
+ * An application can register actions which will show up in a 'start-menu' like popup
+ */
+typedef struct _GnAction
+{
+	const char *label;
+	void (*callback)();
+} GntAction;
+
+static GList *actions;
+
+void gnt_register_action(const char *label, void (*callback)())
+{
+	GntAction *action = g_new0(GntAction, 1);
+	action->label = g_strdup(label);
+	action->callback = callback;
+
+	actions = g_list_append(actions, action);
+}
+
+static void
+action_list_activate(GntTree *tree, gpointer null)
+{
+	GntAction *action = gnt_tree_get_selection_data(tree);
+	action->callback();
+}
+
+static int
+compare_action(gconstpointer p1, gconstpointer p2)
+{
+	const GntAction *a1 = p1;
+	const GntAction *a2 = p2;
+
+	return g_utf8_collate(a1->label, a2->label);
+}
+
+static void
+show_actions_list()
+{
+	GntWidget *tree, *win;
+	GList *iter;
+	int h;
+
+	if (action_list)
+		return;
+	
+	setup__list();
+	action_list = &_list;
+	win = action_list->window;
+	tree = action_list->tree;
+
+	gnt_box_set_title(GNT_BOX(win), "Available Actions");
+	GNT_WIDGET_SET_FLAGS(tree, GNT_WIDGET_NO_BORDER);
+	/* XXX: Do we really want this? */
+	gnt_tree_set_compare_func(GNT_TREE(tree), compare_action);
+
+	for (iter = actions; iter; iter = iter->next) {
+		GntAction *action = iter->data;
+		gnt_tree_add_row_last(GNT_TREE(tree), action,
+				gnt_tree_create_row(GNT_TREE(tree), action->label), NULL);
+	}
+	g_signal_connect(G_OBJECT(tree), "activate", G_CALLBACK(action_list_activate), NULL);
+	gnt_widget_set_size(tree, 0, g_list_length(actions));
+	gnt_widget_get_size(win, NULL, &h);
+	gnt_widget_set_position(win, 0, getmaxy(stdscr) - 1 - h);
+
+	lock_focus_list = 1;
+	gnt_widget_show(win);
+	lock_focus_list = 0;
+}
+