/soc/2013/ankitkv/gobjectification: 869de290ccfb: Disconnect all...

Ankit Vani a at nevitus.org
Tue Aug 6 19:41:08 EDT 2013


Changeset: 869de290ccfb31a4a7cd62ae04a22193534a9036
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-08-07 05:10 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/869de290ccfb

Description:

Disconnect all accounts of a protocol when the protocol is removed

diffstat:

 libpurple/prpl.c |  68 +++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 43 insertions(+), 25 deletions(-)

diffs (96 lines):

diff --git a/libpurple/prpl.c b/libpurple/prpl.c
--- a/libpurple/prpl.c
+++ b/libpurple/prpl.c
@@ -640,6 +640,45 @@ purple_protocol_add_action(PurplePluginP
 /**************************************************************************
  * Protocols API
  **************************************************************************/
+static void
+purple_protocol_destroy(PurplePluginProtocolInfo *prpl_info)
+{
+	GList *accounts, *l;
+
+	accounts = purple_accounts_get_all_active();
+	for (l = accounts; l != NULL; l = l->next) {
+		PurpleAccount *account = PURPLE_ACCOUNT(l->data);
+		if (purple_account_is_disconnected(account))
+			continue;
+
+		if (purple_strequal(prpl_info->id, purple_account_get_protocol_id(account)))
+			purple_account_disconnect(account);
+	}
+
+	g_list_free(accounts);
+
+	while (prpl_info->user_splits) {
+		PurpleAccountUserSplit *split = prpl_info->user_splits->data;
+		purple_account_user_split_destroy(split);
+		prpl_info->user_splits = g_list_delete_link(prpl_info->user_splits,
+				prpl_info->user_splits);
+	}
+
+	while (prpl_info->protocol_options) {
+		PurpleAccountOption *option = prpl_info->protocol_options->data;
+		purple_account_option_destroy(option);
+		prpl_info->protocol_options =
+				g_list_delete_link(prpl_info->protocol_options,
+				prpl_info->protocol_options);
+	}
+
+	while (prpl_info->actions) {
+		PurpleProtocolAction *action = prpl_info->actions->data;
+		g_free(action->label);
+		prpl_info->actions = g_list_delete_link(prpl_info->actions,
+				prpl_info->actions);
+	}
+}
 
 PurplePluginProtocolInfo *
 purple_find_protocol_info(const char *id)
@@ -662,29 +701,9 @@ gboolean purple_protocols_remove(PurpleP
 	if (purple_find_protocol_info(prpl_info->id) == NULL)
 		return FALSE;
 
-	while (prpl_info->user_splits) {
-		PurpleAccountUserSplit *split = prpl_info->user_splits->data;
-		purple_account_user_split_destroy(split);
-		prpl_info->user_splits = g_list_delete_link(prpl_info->user_splits,
-				prpl_info->user_splits);
-	}
+	g_hash_table_remove(protocols, prpl_info->id);
+	purple_protocol_destroy(prpl_info);
 
-	while (prpl_info->protocol_options) {
-		PurpleAccountOption *option = prpl_info->protocol_options->data;
-		purple_account_option_destroy(option);
-		prpl_info->protocol_options =
-				g_list_delete_link(prpl_info->protocol_options,
-				prpl_info->protocol_options);
-	}
-
-	while (prpl_info->actions) {
-		PurpleProtocolAction *action = prpl_info->actions->data;
-		g_free(action->label);
-		prpl_info->actions = g_list_delete_link(prpl_info->actions,
-				prpl_info->actions);
-	}
-
-	g_hash_table_remove(protocols, prpl_info->id);
 	return TRUE;
 }
 
@@ -705,12 +724,11 @@ purple_protocols_get_all(void)
 /**************************************************************************
  * Protocols Subsystem API
  **************************************************************************/
-
 void
 purple_protocols_init(void)
 {
-	/* TODO Use g_object_unref for value destroy when PurpleProtocol is a GObject */
-	protocols = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+	protocols = g_hash_table_new_full(g_str_hash, g_str_equal,
+			(GDestroyNotify)purple_protocol_destroy, NULL);
 }
 
 void *



More information about the Commits mailing list