changeset 18511:7ee0e0597a26

Add utility function to trigger some button when some key is pressed with some other widget in focus. So now, pressing Insert in the accounts, status, pounce dialog will activate the 'Add' button, pressing Delete will activate the 'Delete' button. This can probably be used in some other places.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Fri, 13 Jul 2007 01:42:29 +0000
parents f104e1d45d85
children 0cb139b20d65 602e8264266a
files ChangeLog.API finch/gntaccount.c finch/gntpounce.c finch/gntstatus.c finch/libgnt/gntutils.c finch/libgnt/gntutils.h
diffstat 6 files changed, 59 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog.API	Fri Jul 13 01:30:08 2007 +0000
+++ b/ChangeLog.API	Fri Jul 13 01:42:29 2007 +0000
@@ -107,6 +107,8 @@
 			* gnt_tree_set_column_resizable
 			* gnt_tree_set_column_is_right_aligned
 			* 'file-selected' signal is emited for GntFileSel
+			* gnt_style_parse_bool
+			* gnt_util_set_trigger_widget
 
 			Changed:
 			* gnt_tree_get_rows() now returns a GList* instead of a const
--- a/finch/gntaccount.c	Fri Jul 13 01:30:08 2007 +0000
+++ b/finch/gntaccount.c	Fri Jul 13 01:42:29 2007 +0000
@@ -31,6 +31,7 @@
 #include <gntlabel.h>
 #include <gntline.h>
 #include <gnttree.h>
+#include <gntutils.h>
 #include <gntwindow.h>
 
 #include "finch.h"
@@ -690,6 +691,7 @@
 
 	button = gnt_button_new(_("Add"));
 	gnt_box_add_widget(GNT_BOX(box), button);
+	gnt_util_set_trigger_widget(GNT_WIDGET(accounts.tree), GNT_KEY_INS, button);
 	g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(add_account_cb), NULL);
 
 	button = gnt_button_new(_("Modify"));
@@ -698,6 +700,7 @@
 
 	button = gnt_button_new(_("Delete"));
 	gnt_box_add_widget(GNT_BOX(box), button);
+	gnt_util_set_trigger_widget(GNT_WIDGET(accounts.tree), GNT_KEY_DEL, button);
 	g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(delete_account_cb), accounts.tree);
 	
 	gnt_box_add_widget(GNT_BOX(accounts.window), box);
@@ -921,7 +924,7 @@
 	if (message != NULL && *message == '\0')
 		message = NULL;
 
-	buffer = g_strdup_printf(_("%s%s%s%s wants to add %s to his or her buddy list%s%s"),
+	buffer = g_strdup_printf(_("%s%s%s%s wants to add %s%s%s%s to his or her buddy list%s%s"),
 				remote_user,
 	 	                (alias != NULL ? " ("  : ""),
 		                (alias != NULL ? alias : ""),
@@ -931,7 +934,10 @@
 		                : (purple_connection_get_display_name(gc) != NULL
 		                ? purple_connection_get_display_name(gc)
 		                : purple_account_get_username(account))),
-		                (message != NULL ? ": " : "."),
+						id ? " (" : "",
+						id ? purple_account_get_username(account) : "",
+						id ? ")" : "",
+		                (message != NULL ? ":\n" : "."),
 		                (message != NULL ? message  : ""));
 	if (!on_list) {
 		GntWidget *widget;
--- a/finch/gntpounce.c	Fri Jul 13 01:30:08 2007 +0000
+++ b/finch/gntpounce.c	Fri Jul 13 01:42:29 2007 +0000
@@ -32,6 +32,8 @@
 #include <gntlabel.h>
 #include <gntline.h>
 #include <gnttree.h>
+#include <gntutils.h>
+
 #include "internal.h"
 #include "finch.h"
 
@@ -699,6 +701,7 @@
 	/* Add button */
 	button = gnt_button_new(_("Add"));
 	gnt_box_add_widget(GNT_BOX(bbox), button);
+	gnt_util_set_trigger_widget(tree, GNT_KEY_INS, button);
 
 	g_signal_connect(G_OBJECT(button), "activate",
 					 G_CALLBACK(pounces_manager_add_cb), dialog);
@@ -715,6 +718,7 @@
 	button = gnt_button_new(_("Delete"));
 	dialog->delete_button = button;
 	gnt_box_add_widget(GNT_BOX(bbox), button);
+	gnt_util_set_trigger_widget(tree, GNT_KEY_DEL, button);
 
 	g_signal_connect(G_OBJECT(button), "activate",
 					 G_CALLBACK(pounces_manager_delete_cb), dialog);
--- a/finch/gntstatus.c	Fri Jul 13 01:30:08 2007 +0000
+++ b/finch/gntstatus.c	Fri Jul 13 01:42:29 2007 +0000
@@ -30,6 +30,7 @@
 #include <gntlabel.h>
 #include <gntline.h>
 #include <gnttree.h>
+#include <gntutils.h>
 
 #include "finch.h"
 
@@ -196,6 +197,7 @@
 
 	button = gnt_button_new(_("Add"));
 	gnt_box_add_widget(GNT_BOX(box), button);
+	gnt_util_set_trigger_widget(tree, GNT_KEY_INS, button);
 	g_signal_connect_swapped(G_OBJECT(button), "activate",
 			G_CALLBACK(finch_savedstatus_edit), NULL);
 
@@ -206,6 +208,7 @@
 
 	button = gnt_button_new(_("Delete"));
 	gnt_box_add_widget(GNT_BOX(box), button);
+	gnt_util_set_trigger_widget(tree, GNT_KEY_DEL, button);
 	g_signal_connect(G_OBJECT(button), "activate",
 			G_CALLBACK(ask_before_delete), NULL);
 
--- a/finch/libgnt/gntutils.c	Fri Jul 13 01:30:08 2007 +0000
+++ b/finch/libgnt/gntutils.c	Fri Jul 13 01:42:29 2007 +0000
@@ -375,3 +375,36 @@
 #endif
 }
 
+/* Setup trigger widget */
+typedef struct {
+	char *text;
+	GntWidget *button;
+} TriggerButton;
+
+static void
+free_trigger_button(TriggerButton *b)
+{
+	g_free(b->text);
+	g_free(b);
+}
+
+static gboolean
+key_pressed(GntWidget *widget, const char *text, TriggerButton *trig)
+{
+	if (text && trig->text &&
+			strcmp(text, trig->text) == 0) {
+		gnt_widget_activate(trig->button);
+		return TRUE;
+	}
+	return FALSE;
+}
+
+void gnt_util_set_trigger_widget(GntWidget *wid, const char *text, GntWidget *button)
+{
+	TriggerButton *tb = g_new0(TriggerButton, 1);
+	tb->text = g_strdup(text);
+	tb->button = button;
+	g_signal_connect(G_OBJECT(wid), "key_pressed", G_CALLBACK(key_pressed), tb);
+	g_signal_connect_swapped(G_OBJECT(button), "destroy", G_CALLBACK(free_trigger_button), tb);
+}
+
--- a/finch/libgnt/gntutils.h	Fri Jul 13 01:30:08 2007 +0000
+++ b/finch/libgnt/gntutils.h	Fri Jul 13 01:42:29 2007 +0000
@@ -130,3 +130,12 @@
  */
 void gnt_util_parse_widgets(const char *string, int num, ...);
 
+/**
+ * Make some keypress activate a button when some key is pressed with 'wid' in focus.
+ *
+ * @param widget  The widget
+ * @param key     The key to trigger the button
+ * @param button  The button to trigger
+ */
+void gnt_util_set_trigger_widget(GntWidget *wid, const char *text, GntWidget *button);
+