changeset 13281:e629076386f1

[gaim-migrate @ 15647] SF Patch #1431225 from Sadrul "This emits a signal when the alias of an account is changed. This can be used by plugins which, for example, uses the account-statusboxes." committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Tue, 14 Feb 2006 07:28:58 +0000
parents 3de53fe8345f
children a651bfe0a922
files doc/account-signals.dox plugins/ChangeLog.API plugins/signals-test.c src/account.c
diffstat 4 files changed, 39 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/doc/account-signals.dox	Tue Feb 14 05:43:43 2006 +0000
+++ b/doc/account-signals.dox	Tue Feb 14 07:28:58 2006 +0000
@@ -90,5 +90,15 @@
   @param new     The status after change.
  @endsignaldef
 
+ @signaldef account-alias-changed
+  @signalproto
+void (*account_alias_changed)(GaimAccount *account, const char *old);
+  @endsignalproto
+  @signaldesc
+   Emitted when the alias of an account changes (after the change).
+  @param account The account for which the alias was changed.
+  @param old     The alias before change.
+ @endsignaldef
+
  */
 // vim: syntax=c tw=75 et
--- a/plugins/ChangeLog.API	Tue Feb 14 05:43:43 2006 +0000
+++ b/plugins/ChangeLog.API	Tue Feb 14 07:28:58 2006 +0000
@@ -303,6 +303,7 @@
 	Signals - Added:  (See the Doxygen docs for details on all signals.)
 	* "account-disabled"
 	* "account-status-changed"
+	* "account-alias-changed"
 	* "cipher-added"
 	* "cipher-removed"
 	* "conversation-dragging"
--- a/plugins/signals-test.c	Tue Feb 14 05:43:43 2006 +0000
+++ b/plugins/signals-test.c	Tue Feb 14 07:28:58 2006 +0000
@@ -68,6 +68,14 @@
 					gaim_status_get_name(new));
 }
 
+static void
+account_alias_changed(GaimAccount *account, const char *old, gpointer data)
+{
+	gaim_debug_misc("signals test", "account-alias-changed (%s, %s, %s)\n",
+					gaim_account_get_username(account),
+					old, gaim_account_get_alias(account));
+}
+
 /**************************************************************************
  * Buddy Icons signal callbacks
  **************************************************************************/
@@ -537,6 +545,8 @@
 						plugin, GAIM_CALLBACK(account_set_info_cb), NULL);
 	gaim_signal_connect(accounts_handle, "account-status-changed",
 						plugin, GAIM_CALLBACK(account_status_changed), NULL);
+	gaim_signal_connect(accounts_handle, "account-alias-changed",
+						plugin, GAIM_CALLBACK(account_alias_changed), NULL);
 
 	/* Buddy List subsystem signals */
 	gaim_signal_connect(blist_handle, "buddy-status-changed",
--- a/src/account.c	Tue Feb 14 05:43:43 2006 +0000
+++ b/src/account.c	Tue Feb 14 07:28:58 2006 +0000
@@ -1205,10 +1205,18 @@
 {
 	g_return_if_fail(account != NULL);
 
-	g_free(account->alias);
-	account->alias = (alias == NULL ? NULL : g_strdup(alias));
-
-	schedule_accounts_save();
+	if ((!alias && account->alias) || (alias && !account->alias) ||
+			g_utf8_collate(account->alias, alias))
+	{
+		char *old = account->alias;
+
+		account->alias = (alias == NULL ? NULL : g_strdup(alias));
+		gaim_signal_emit(gaim_accounts_get_handle(), "account-alias-changed",
+						 account, old);
+		g_free(old);
+
+		schedule_accounts_save();
+	}
 }
 
 void
@@ -2332,6 +2340,12 @@
 										GAIM_SUBTYPE_STATUS),
 						 gaim_value_new(GAIM_TYPE_SUBTYPE,
 										GAIM_SUBTYPE_STATUS));
+
+	gaim_signal_register(handle, "account-alias-changed",
+						 gaim_marshal_VOID__POINTER_POINTER, NULL, 2,
+						 gaim_value_new(GAIM_TYPE_SUBTYPE,
+							 			GAIM_SUBTYPE_ACCOUNT),
+						 gaim_value_new(GAIM_TYPE_STRING));
 	
 	load_accounts();