# HG changeset patch
# Node ID ac7d12637b24
# Parent  95c0077fe6bb
diff --git a/ChangeLog.API b/ChangeLog.API
--- a/ChangeLog.API
+++ b/ChangeLog.API
@@ -944,6 +944,7 @@ version 3.0.0 (??/??/????):
 		* pidgin_cell_renderer_expander_new
 		* pidgin_check_if_dir
 		* pidgin_clear_cursor
+		* pidgin_connection_get_handle
 		* PidginConversation.sg
 		* PidginConvPlacementFunc
 		* pidgin_conv_get_tab_at_xy
diff --git a/finch/gntaccount.c b/finch/gntaccount.c
--- a/finch/gntaccount.c
+++ b/finch/gntaccount.c
@@ -255,9 +255,9 @@ save_account_cb(AccountEditDialog *dialo
 		}
 	}
 
-	/* In case of a new account, the 'Accounts' window is updated from the account-added
-	 * callback. In case of changes in an existing account, we need to explicitly do it
-	 * here.
+	/* In case of a new account, the 'Accounts' window is updated from the
+	 * 'added' callback. In case of changes in an existing account, we need to
+	 * explicitly do it here.
 	 */
 	if (dialog->account != NULL && accounts.window) {
 		gnt_tree_change_text(GNT_TREE(accounts.tree), dialog->account,
@@ -861,7 +861,8 @@ finch_accounts_get_handle(void)
 }
 
 static void
-account_added_callback(PurpleAccount *account)
+account_added_callback(G_GNUC_UNUSED PurpleAccountManager *manager,
+                       PurpleAccount *account, G_GNUC_UNUSED gpointer data)
 {
 	if (accounts.window == NULL)
 		return;
@@ -870,7 +871,8 @@ account_added_callback(PurpleAccount *ac
 }
 
 static void
-account_removed_callback(PurpleAccount *account)
+account_removed_callback(G_GNUC_UNUSED PurpleAccountManager *manager,
+                         PurpleAccount *account, G_GNUC_UNUSED gpointer data)
 {
 	if (accounts.window == NULL)
 		return;
@@ -890,22 +892,23 @@ account_abled_cb(PurpleAccount *account,
 void finch_accounts_init()
 {
 	PurpleAccountManager *manager = NULL;
+	gpointer account_handle = NULL;
 	GList *iter;
 
-	purple_signal_connect(purple_accounts_get_handle(), "account-added",
-			finch_accounts_get_handle(), G_CALLBACK(account_added_callback),
-			NULL);
-	purple_signal_connect(purple_accounts_get_handle(), "account-removed",
-			finch_accounts_get_handle(), G_CALLBACK(account_removed_callback),
-			NULL);
-	purple_signal_connect(purple_accounts_get_handle(), "account-disabled",
+	manager = purple_account_manager_get_default();
+	account_handle = purple_accounts_get_handle();
+
+	g_signal_connect(manager, "added", G_CALLBACK(account_added_callback),
+	                 NULL);
+	g_signal_connect(manager, "removed", G_CALLBACK(account_removed_callback),
+	                 NULL);
+	purple_signal_connect(account_handle, "account-disabled",
 			finch_accounts_get_handle(),
 			G_CALLBACK(account_abled_cb), GINT_TO_POINTER(FALSE));
-	purple_signal_connect(purple_accounts_get_handle(), "account-enabled",
+	purple_signal_connect(account_handle, "account-enabled",
 			finch_accounts_get_handle(),
 			G_CALLBACK(account_abled_cb), GINT_TO_POINTER(TRUE));
 
-	manager = purple_account_manager_get_default();
 	iter = purple_account_manager_get_all(manager);
 	if (iter) {
 		for (; iter; iter = iter->next) {
diff --git a/finch/gntconn.c b/finch/gntconn.c
--- a/finch/gntconn.c
+++ b/finch/gntconn.c
@@ -108,19 +108,12 @@ finch_connection_report_disconnect(Purpl
 }
 
 static void
-account_removed_cb(PurpleAccount *account, gpointer user_data)
+account_removed_cb(G_GNUC_UNUSED PurpleAccountManager *manager,
+                   PurpleAccount *account, G_GNUC_UNUSED gpointer data)
 {
 	g_hash_table_remove(hash, account);
 }
 
-static void *
-finch_connection_get_handle(void)
-{
-	static int handle;
-
-	return &handle;
-}
-
 static PurpleConnectionUiOps ops = {
 	.report_disconnect = finch_connection_report_disconnect,
 };
@@ -132,17 +125,21 @@ PurpleConnectionUiOps *finch_connections
 
 void finch_connections_init()
 {
+	PurpleAccountManager *manager = purple_account_manager_get_default();
+
 	hash = g_hash_table_new_full(
 							g_direct_hash, g_direct_equal,
 							NULL, free_auto_recon);
 
-	purple_signal_connect(purple_accounts_get_handle(), "account-removed",
-						finch_connection_get_handle(),
-						G_CALLBACK(account_removed_cb), NULL);
+	g_signal_connect(manager, "removed", G_CALLBACK(account_removed_cb), NULL);
 }
 
 void finch_connections_uninit()
 {
-	purple_signals_disconnect_by_handle(finch_connection_get_handle());
+	PurpleAccountManager *manager = purple_account_manager_get_default();
+
+	g_signal_handlers_disconnect_by_func(manager,
+	                                     G_CALLBACK(account_removed_cb), NULL);
+
 	g_hash_table_destroy(hash);
 }
diff --git a/libpurple/savedstatuses.c b/libpurple/savedstatuses.c
--- a/libpurple/savedstatuses.c
+++ b/libpurple/savedstatuses.c
@@ -683,8 +683,9 @@ purple_savedstatus_unset_substatus(Purpl
  * exist for this account.
  */
 static void
-purple_savedstatus_unset_all_substatuses(PurpleAccount *account,
-                                         gpointer user_data)
+purple_savedstatus_unset_all_substatuses(G_GNUC_UNUSED PurpleAccountManager *manager,
+                                         PurpleAccount *account,
+                                         G_GNUC_UNUSED gpointer data)
 {
 	g_return_if_fail(account != NULL);
 
@@ -1204,6 +1205,7 @@ purple_savedstatuses_get_handle(void)
 void
 purple_savedstatuses_init(void)
 {
+	PurpleAccountManager *manager = purple_account_manager_get_default();
 	void *handle = purple_savedstatuses_get_handle();
 
 	creation_times = g_hash_table_new(g_direct_hash, g_direct_equal);
@@ -1240,15 +1242,15 @@ purple_savedstatuses_init(void)
 		purple_marshal_VOID__POINTER, G_TYPE_NONE, 1,
 		PURPLE_TYPE_SAVEDSTATUS);
 
-	purple_signal_connect(purple_accounts_get_handle(), "account-removed",
-			handle,
-			G_CALLBACK(purple_savedstatus_unset_all_substatuses),
-			NULL);
+	g_signal_connect(manager, "removed",
+	                 G_CALLBACK(purple_savedstatus_unset_all_substatuses),
+	                 NULL);
 }
 
 void
 purple_savedstatuses_uninit(void)
 {
+	PurpleAccountManager *manager = purple_account_manager_get_default();
 	gpointer handle = purple_savedstatuses_get_handle();
 
 	remove_old_transient_statuses();
@@ -1266,6 +1268,9 @@ purple_savedstatuses_uninit(void)
 	g_hash_table_destroy(creation_times);
 	creation_times = NULL;
 
+	g_signal_handlers_disconnect_by_func(manager,
+	                                     G_CALLBACK(purple_savedstatus_unset_all_substatuses),
+	                                     NULL);
 	purple_signals_unregister_by_instance(handle);
 	purple_signals_disconnect_by_handle(handle);
 }
diff --git a/pidgin/gtkconn.h b/pidgin/gtkconn.h
--- a/pidgin/gtkconn.h
+++ b/pidgin/gtkconn.h
@@ -42,15 +42,6 @@ G_BEGIN_DECLS
 PurpleConnectionUiOps *pidgin_connections_get_ui_ops(void);
 
 /**
- * pidgin_connection_get_handle:
- *
- * Returns the GTK connection handle.
- *
- * Returns: The handle to the GTK connection system.
- */
-void *pidgin_connection_get_handle(void);
-
-/**
  * pidgin_connection_init:
  *
  * Initializes the GTK connection system.
diff --git a/pidgin/gtkconn.c b/pidgin/gtkconn.c
--- a/pidgin/gtkconn.c
+++ b/pidgin/gtkconn.c
@@ -179,7 +179,8 @@ pidgin_connections_get_ui_ops(void)
 }
 
 static void
-account_removed_cb(PurpleAccount *account, gpointer user_data)
+account_removed_cb(G_GNUC_UNUSED PurpleAccountManager *manager,
+                   PurpleAccount *account, G_GNUC_UNUSED gpointer data)
 {
 	g_hash_table_remove(auto_reconns, account);
 }
@@ -189,30 +190,25 @@ account_removed_cb(PurpleAccount *accoun
 * GTK connection glue
 **************************************************************************/
 
-void *
-pidgin_connection_get_handle(void)
-{
-	static int handle;
-
-	return &handle;
-}
-
 void
 pidgin_connection_init(void)
 {
+	PurpleAccountManager *manager = purple_account_manager_get_default();
+
 	auto_reconns = g_hash_table_new_full(
 							g_direct_hash, g_direct_equal,
 							NULL, free_auto_recon);
 
-	purple_signal_connect(purple_accounts_get_handle(), "account-removed",
-						pidgin_connection_get_handle(),
-						G_CALLBACK(account_removed_cb), NULL);
+	g_signal_connect(manager, "removed", G_CALLBACK(account_removed_cb), NULL);
 }
 
 void
 pidgin_connection_uninit(void)
 {
-	purple_signals_disconnect_by_handle(pidgin_connection_get_handle());
+	PurpleAccountManager *manager = purple_account_manager_get_default();
+
+	g_signal_handlers_disconnect_by_func(manager,
+	                                     G_CALLBACK(account_removed_cb), NULL);
 
 	g_hash_table_destroy(auto_reconns);
 }
diff --git a/pidgin/gtkutils.c b/pidgin/gtkutils.c
--- a/pidgin/gtkutils.c
+++ b/pidgin/gtkutils.c
@@ -364,24 +364,47 @@ add_completion_list(PidginCompletionData
 }
 
 static void
-buddyname_autocomplete_destroyed_cb(GtkWidget *widget, gpointer data)
+repopulate_autocomplete(gpointer something, gpointer data)
 {
-	g_free(data);
-	purple_signals_disconnect_by_handle(widget);
+	add_completion_list(data);
+}
+
+static void
+autocomplete_account_added_cb(G_GNUC_UNUSED PurpleAccountManager *manager,
+                              G_GNUC_UNUSED PurpleAccount *account,
+                              gpointer data)
+{
+	add_completion_list(data);
 }
 
 static void
-repopulate_autocomplete(gpointer something, gpointer data)
+autocomplete_account_removed_cb(G_GNUC_UNUSED PurpleAccountManager *manager,
+                                G_GNUC_UNUSED PurpleAccount *account,
+                                gpointer data)
 {
 	add_completion_list(data);
 }
 
+static void
+buddyname_autocomplete_destroyed_cb(GtkWidget *widget, gpointer data)
+{
+	PurpleAccountManager *manager = NULL;
+	g_free(data);
+	purple_signals_disconnect_by_handle(widget);
+	manager = purple_account_manager_get_default();
+	g_signal_handlers_disconnect_by_func(manager,
+	                 G_CALLBACK(autocomplete_account_added_cb), data);
+	g_signal_handlers_disconnect_by_func(manager,
+	                 G_CALLBACK(autocomplete_account_removed_cb), data);
+}
+
 void
 pidgin_setup_screenname_autocomplete(
         GtkWidget *entry, GtkWidget *chooser,
         PidginFilterBuddyCompletionEntryFunc filter_func, gpointer user_data)
 {
 	PidginCompletionData *data;
+	PurpleAccountManager *manager = NULL;
 
 	/*
 	 * Store the displayed completion value, the buddy name, the UTF-8
@@ -434,10 +457,11 @@ pidgin_setup_screenname_autocomplete(
 	purple_signal_connect(purple_connections_get_handle(), "signed-off", entry,
 						G_CALLBACK(repopulate_autocomplete), data);
 
-	purple_signal_connect(purple_accounts_get_handle(), "account-added", entry,
-						G_CALLBACK(repopulate_autocomplete), data);
-	purple_signal_connect(purple_accounts_get_handle(), "account-removed", entry,
-						G_CALLBACK(repopulate_autocomplete), data);
+	manager = purple_account_manager_get_default();
+	g_signal_connect(manager, "added",
+	                 G_CALLBACK(autocomplete_account_added_cb), data);
+	g_signal_connect(manager, "removed",
+	                 G_CALLBACK(autocomplete_account_removed_cb), data);
 
 	g_signal_connect(G_OBJECT(entry), "destroy", G_CALLBACK(buddyname_autocomplete_destroyed_cb), data);
 }
diff --git a/pidgin/pidginaccountstore.c b/pidgin/pidginaccountstore.c
--- a/pidgin/pidginaccountstore.c
+++ b/pidgin/pidginaccountstore.c
@@ -79,16 +79,6 @@ pidgin_account_store_add_account_helper(
 }
 
 static void
-pidgin_account_store_add_accounts(PidginAccountStore *store) {
-	PurpleAccountManager *manager = NULL;
-
-	manager = purple_account_manager_get_default();
-	purple_account_manager_foreach(manager,
-	                               pidgin_account_store_add_account_helper,
-	                               store);
-}
-
-static void
 pidgin_account_store_remove_account(PidginAccountStore *store,
                                     PurpleAccount *account)
 {
@@ -126,14 +116,16 @@ pidgin_account_store_remove_account(Pidg
  * Callbacks
  *****************************************************************************/
 static void
-pidgin_account_store_account_added_cb(PurpleAccount *account,
+pidgin_account_store_account_added_cb(G_GNUC_UNUSED PurpleAccountManager *manager,
+                                      PurpleAccount *account,
                                       gpointer data)
 {
 	pidgin_account_store_add_account(PIDGIN_ACCOUNT_STORE(data), account);
 }
 
 static void
-pidgin_account_store_account_removed_cb(PurpleAccount *account,
+pidgin_account_store_account_removed_cb(G_GNUC_UNUSED PurpleAccountManager *manager,
+                                        PurpleAccount *account,
                                         gpointer data)
 {
 	pidgin_account_store_remove_account(PIDGIN_ACCOUNT_STORE(data), account);
@@ -146,7 +138,7 @@ G_DEFINE_TYPE(PidginAccountStore, pidgin
 
 static void
 pidgin_account_store_init(PidginAccountStore *store) {
-	gpointer accounts_handle = NULL;
+	PurpleAccountManager *manager = NULL;
 	GType types[PIDGIN_ACCOUNT_STORE_N_COLUMNS] = {
 		PURPLE_TYPE_ACCOUNT,
 		G_TYPE_STRING,
@@ -160,16 +152,18 @@ pidgin_account_store_init(PidginAccountS
 	);
 
 	/* add the known accounts */
-	pidgin_account_store_add_accounts(store);
+	manager = purple_account_manager_get_default();
+	purple_account_manager_foreach(manager,
+	                               pidgin_account_store_add_account_helper,
+	                               store);
 
 	/* add the signal handlers to dynamically add/remove accounts */
-	accounts_handle = purple_accounts_get_handle();
-	purple_signal_connect(accounts_handle, "account-added", store,
-	                      G_CALLBACK(pidgin_account_store_account_added_cb),
-	                      store);
-	purple_signal_connect(accounts_handle, "account-removed", store,
-	                      G_CALLBACK(pidgin_account_store_account_removed_cb),
-	                      store);
+	g_signal_connect_object(manager, "added",
+	                        G_CALLBACK(pidgin_account_store_account_added_cb),
+	                        store, 0);
+	g_signal_connect_object(manager, "removed",
+	                        G_CALLBACK(pidgin_account_store_account_removed_cb),
+	                        store, 0);
 }
 
 static void
