pidgin.next.minor: 38c3a105: This modifies Jaywalker's patch to use a...

rekkanoryo at pidgin.im rekkanoryo at pidgin.im
Wed Apr 30 01:45:49 EDT 2008


-----------------------------------------------------------------
Revision: 38c3a1050aefc66e1c541e3d91ae6f7fe6930559
Ancestor: 8086f2cffaab6ed17431381836b9227a64a53270
Author: rekkanoryo at pidgin.im
Date: 2008-04-30T05:37:19
Branch: im.pidgin.pidgin.next.minor
URL: http://d.pidgin.im/viewmtn/revision/info/38c3a1050aefc66e1c541e3d91ae6f7fe6930559

Modified files:
        libpurple/protocols/msn/msn.c
        libpurple/protocols/msnp9/msn.c
        libpurple/protocols/myspace/myspace.c libpurple/prpl.h
        pidgin/gtkaccount.c

ChangeLog: 

This modifies Jaywalker's patch to use a GHashTable, per Stu's suggestion in
the XMPP conference.  After some thought and discussion, I decided to have the
prpls create the hash table on each call.  This allows some dynamic key
creation in case we would need it in the future.

-------------- next part --------------
============================================================
--- libpurple/protocols/msn/msn.c	bbeeed30805a3fcac1562d5cb4c6f6df5aeb873f
+++ libpurple/protocols/msn/msn.c	77948ae5dc09e31ba75f6e45a762de36e7802460
@@ -132,8 +132,16 @@ msn_attention_types(PurpleAccount *accou
 	return list;
 }
 
-const char *msn_get_login_label() {
-	return _("E-mail Address...");
+static GHashTable *
+msn_get_account_text_table()
+{
+	GHashTable *table;
+	
+	table = g_hash_table_new(g_str_hash, g_str_equal);
+	
+	g_hash_table_insert(table, "login_label", (gpointer)_("E-mail Address..."));
+
+	return table;
 }
 
 static PurpleCmdRet
@@ -2309,7 +2317,7 @@ static PurplePluginProtocolInfo prpl_inf
 	NULL,					/* unregister_user */
 	msn_send_attention,                     /* send_attention */
 	msn_attention_types,                    /* attention_types */
-	msn_get_login_label			/* account_login_label */
+	msn_get_account_text_table			/* get_account_text_table */
 };
 
 static PurplePluginInfo info =
============================================================
--- libpurple/protocols/msnp9/msn.c	81c303657f22b0c165b34a1c8ec1ee7aca476670
+++ libpurple/protocols/msnp9/msn.c	ecc8cc5b4348a9e68fe64fadf1fb8b9339c97851
@@ -133,9 +133,16 @@ msn_attention_types(PurpleAccount *accou
 	return list;
 }
 
+static GHashTable *
+msn_get_account_text_table()
+{
+	GHashTable *table;
 
-const char *msn_get_login_label() {
-	return _("E-mail Address...");
+	table = g_hash_table_new(g_str_hash, g_str_equal);
+
+	g_hash_table_insert(table, "login_label", (gpointer)_("E-mail Address..."));
+
+	return table;
 }
 
 static PurpleCmdRet
@@ -2151,7 +2158,7 @@ static PurplePluginProtocolInfo prpl_inf
 	NULL,					/* unregister_user */
 	msn_send_attention,                     /* send_attention */
 	msn_attention_types,                    /* attention_types */
-	msn_get_login_label			/* account_login_label */
+	msn_get_account_text_table			/* get_account_text_table */
 };
 
 static PurplePluginInfo info =
============================================================
--- libpurple/protocols/myspace/myspace.c	2b9a44b140569fdd1d658d122e4216f5abaaf72d
+++ libpurple/protocols/myspace/myspace.c	915380f6fc68b07efb1905ecbf3d53eaa282395e
@@ -2449,8 +2449,16 @@ const char *msim_normalize(const PurpleA
 	return normalized;
 }
 
-const char *msim_get_login_label() {
-	return _("E-mail Address...");
+static GHashTable *
+msim_get_account_text_table()
+{
+	GHashTable *table;
+
+	table = g_hash_table_new(g_str_hash, g_str_equal);
+
+	g_hash_table_insert(table, "login_label", (gpointer)_("E-mail Address..."));
+
+	return table;
 }
 
 /** Return whether the buddy can be messaged while offline.
@@ -3135,7 +3143,7 @@ static PurplePluginProtocolInfo prpl_inf
 	NULL,                  /* unregister_user */
 	msim_send_attention,   /* send_attention */
 	msim_attention_types,  /* attention_types */
-	msim_get_login_label /* get screen name field title */
+	msim_get_account_text_table /* get_account_text_table */
 };
 
 
============================================================
--- libpurple/prpl.h	b58e091cb58e9cfb723b022a482f413d24e5be38
+++ libpurple/prpl.h	c8318416867d20db6de42b21260df18c99d088c3
@@ -398,11 +398,15 @@ struct _PurplePluginProtocolInfo
 	gboolean (*send_attention)(PurpleConnection *gc, const char *username, guint type);
 	GList *(*get_attention_types)(PurpleAccount *acct);
 
-	/* This allows protocols to specify a more specific term for the "ScreenName" field
-	 * in the add account window. This helps avoid confusion for users using protocols
-	 * such as MySpace or MSN
+	/** This allows protocols to specify additional strings to be used for
+	 * various purposes.  The idea is to stuff a bunch of strings in this hash
+	 * table instead of expanding the struct for every addition.  This hash
+	 * table is allocated every call and MUST be unrefed by the caller.
+	 *
+	 * @param account The account to specify.  This can be NULL.
+	 * @return The protocol's string hash table.
 	 */
-	const char *(*account_login_label)(void);
+	GHashTable *(*get_account_text_table)(PurpleAccount *account);
 };
 
 #define PURPLE_IS_PROTOCOL_PLUGIN(plugin) \
============================================================
--- pidgin/gtkaccount.c	b6ee355b36da4f62e58dad1dabc863c2d30051d2
+++ pidgin/gtkaccount.c	789167b0c49f0802c1f2d61815844eba9c9635d8
@@ -258,10 +258,19 @@ screenname_focus_cb(GtkWidget *widget, G
 static gboolean
 screenname_focus_cb(GtkWidget *widget, GdkEventFocus *event, AccountPrefsDialog *dialog)
 {
-	if (!strcmp(gtk_entry_get_text(GTK_ENTRY(widget)),dialog->prpl_info->account_login_label())) {
-		gtk_entry_set_text(GTK_ENTRY(widget),"");
-		gtk_widget_modify_text(widget,GTK_STATE_NORMAL,NULL);
+	GHashTable *table;
+	const char *label;
+	
+	table = dialog->prpl_info->get_account_text_table(NULL);
+	label = g_hash_table_lookup(table, "login_label");
+
+	if(!strcmp(gtk_entry_get_text(GTK_ENTRY(widget)), label)) {
+		gtk_entry_set_text(GTK_ENTRY(widget), "");
+		gtk_widget_modify_text(widget, GTK_STATE_NORMAL,NULL);
 	}
+
+	g_hash_table_unref(table);
+
 	return FALSE;
 }
 
@@ -284,16 +293,25 @@ screenname_nofocus_cb(GtkWidget *widget,
 screenname_nofocus_cb(GtkWidget *widget, GdkEventFocus *event, AccountPrefsDialog *dialog)
 {
 	GdkColor color = {0, 34952, 35466, 34181};
+	GHashTable *table;
+	const char *label;
+
+	table = dialog->prpl_info->get_account_text_table(NULL);
+	label = g_hash_table_lookup(table, "login_label");
+
 	if (*gtk_entry_get_text(GTK_ENTRY(widget)) == '\0') {
 		/* We have to avoid hitting the screenname_changed_cb function 
 		 * because it enables buttons we don't want enabled yet ;)
 		 */
 		g_signal_handlers_block_by_func(widget, G_CALLBACK(screenname_changed_cb), dialog);
-		gtk_entry_set_text(GTK_ENTRY(widget),dialog->prpl_info->account_login_label());
+		gtk_entry_set_text(GTK_ENTRY(widget), label);
 		/* Make sure we can hit it again */
 		g_signal_handlers_unblock_by_func(widget, G_CALLBACK(screenname_changed_cb), dialog);
-		gtk_widget_modify_text(widget,GTK_STATE_NORMAL,&color);
+		gtk_widget_modify_text(widget, GTK_STATE_NORMAL, &color);
 	}
+
+	g_hash_table_unref(table);
+
 	return FALSE;
 }
 
@@ -392,6 +410,8 @@ add_login_options(AccountPrefsDialog *di
 	GList *l, *l2;
 	char *username = NULL;
 	GdkColor color = {0, 34952, 35466, 34181};
+	GHashTable *table;
+	const char *label;
 
 	if (dialog->protocol_menu != NULL)
 	{
@@ -438,13 +458,18 @@ add_login_options(AccountPrefsDialog *di
 
 	add_pref_box(dialog, vbox, _("Screen _name:"), dialog->screenname_entry);
 
-	if (dialog->prpl_info->account_login_label) {
-		gtk_entry_set_text(dialog->screenname_entry,dialog->prpl_info->account_login_label());
+	if (dialog->prpl_info->get_account_text_table) {
+		table = dialog->prpl_info->get_account_text_table(NULL);
+		label = g_hash_table_lookup(table, "login_label");
+
+		gtk_entry_set_text(GTK_ENTRY(dialog->screenname_entry), label);
 		g_signal_connect(G_OBJECT(dialog->screenname_entry), "focus-in-event",
 						G_CALLBACK(screenname_focus_cb), dialog);
 		g_signal_connect(G_OBJECT(dialog->screenname_entry), "focus-out-event",
 						G_CALLBACK(screenname_nofocus_cb), dialog);
-		gtk_widget_modify_text(dialog->screenname_entry,GTK_STATE_NORMAL,&color);
+		gtk_widget_modify_text(dialog->screenname_entry, GTK_STATE_NORMAL, &color);
+
+		g_hash_table_unref(table);
 	}
 
 	g_signal_connect(G_OBJECT(dialog->screenname_entry), "changed",


More information about the Commits mailing list