gobjectification: bb49fc89: Get rid of PurpleAccountManager.

sadrul at pidgin.im sadrul at pidgin.im
Tue Jul 13 18:04:05 EDT 2010


----------------------------------------------------------------------
Revision: bb49fc89e954766506275c1001248597d1cd213e
Parent:   0b1467237f63ad3dc679b37162c1b1901a4a542e
Author:   sadrul at pidgin.im
Date:     07/13/10 14:13:17
Branch:   im.pidgin.gobjectification
URL: http://d.pidgin.im/viewmtn/revision/info/bb49fc89e954766506275c1001248597d1cd213e

Changelog: 

Get rid of PurpleAccountManager.

The list of accounts is now maintained in accountlist.c, and we don't
need an account manager for that. The list automatically updates itself
when an account is added or removed. So a plugin/UI creating or removing
an account doesn't need to explicitly update the list of accounts
maintained by purple.

Changes against parent 0b1467237f63ad3dc679b37162c1b1901a4a542e

  renamed  libpurple/accountmanager.c
       to  libpurple/accountlist.c
  renamed  libpurple/accountmanager.h
       to  libpurple/accountlist.h
  patched  libpurple/Makefile.am
  patched  libpurple/account.c
  patched  libpurple/account.h
  patched  libpurple/accountlist.c
  patched  libpurple/accountlist.h
  patched  libpurple/blist.c
  patched  libpurple/buddy.c
  patched  libpurple/buddyicon.c
  patched  libpurple/chat.c
  patched  libpurple/core.c
  patched  libpurple/dbus-server.c
  patched  libpurple/dbus-useful.c
  patched  libpurple/log.c
  patched  libpurple/pounce.c
  patched  libpurple/purple-client-example.c
  patched  libpurple/purple.h.in
  patched  libpurple/savedstatuses.c
  patched  libpurple/util.c

-------------- next part --------------
============================================================
--- libpurple/util.c	29e3c18815ef7cf1a77c8175ee479dc2da07f5c6
+++ libpurple/util.c	8ce3ed9ff8cc35c79bea267992c15843d0057006
@@ -23,6 +23,8 @@
  */
 #include "internal.h"
 
+#include "account.h"
+#include "accountlist.h"
 #include "conversation.h"
 #include "core.h"
 #include "debug.h"
@@ -4966,7 +4968,7 @@ void purple_util_set_current_song(const 
 
 void purple_util_set_current_song(const char *title, const char *artist, const char *album)
 {
-	GList *list = purple_accounts_get_all();
+	GList *list = purple_accounts_all();
 	for (; list; list = list->next) {
 		PurplePresence *presence;
 		PurpleStatus *tune;
============================================================
--- libpurple/core.c	089d79bc72990c8d8c809e07a5f26e464a5f912d
+++ libpurple/core.c	a3794f934664d7c44e575533700f73e45e1a9333
@@ -24,7 +24,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
  */
 #include "internal.h"
-#include "accountmanager.h"
+#include "accountlist.h"
 #include "certificate.h"
 #include "cmds.h"
 #include "connection.h"
@@ -185,7 +185,7 @@ purple_core_init(const char *ui)
 	/* The UI may have registered some theme types, so refresh them */
 	purple_theme_manager_refresh();
 
-	purple_account_manager_load_accounts(purple_account_manager_get());
+	purple_accounts_load();
 
 	return TRUE;
 }
@@ -239,7 +239,6 @@ purple_core_quit(void)
 	purple_proxy_uninit();
 	purple_dnsquery_uninit();
 	purple_imgstore_uninit();
-	g_object_unref(G_OBJECT(purple_account_manager_get()));
 	purple_network_uninit();
 
 	/* Everything after unloading all plugins must not fail if prpls aren't
============================================================
--- libpurple/log.c	f5e905b035a4f0d41f3fc9dd9551e4a79b36dd9e
+++ libpurple/log.c	ce007711ac88f4eb775107bdfcb09bdc395a9209
@@ -26,6 +26,7 @@
 
 #include "internal.h"
 #include "account.h"
+#include "accountlist.h"
 #include "dbus-maybe.h"
 #include "debug.h"
 #include "internal.h"
@@ -1074,7 +1075,7 @@ static void log_get_log_sets_common(GHas
 		protocol_unescaped = g_strdup(purple_unescape_filename(protocol));
 
 		/* Find all the accounts for protocol. */
-		for (account_iter = purple_accounts_get_all() ; account_iter != NULL ; account_iter = account_iter->next) {
+		for (account_iter = purple_accounts_all() ; account_iter != NULL ; account_iter = account_iter->next) {
 			PurplePlugin *prpl;
 			PurplePluginProtocolInfo *prpl_info;
 
============================================================
--- libpurple/pounce.c	d70b90f90f270c4a01214a95f8e97b11cb9bbd2d
+++ libpurple/pounce.c	ecbbe113a0a7396521042fd52835a0fc6c988a80
@@ -24,6 +24,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
  */
 #include "internal.h"
+#include "accountlist.h"
 #include "conversation.h"
 #include "debug.h"
 #include "pounce.h"
============================================================
--- libpurple/blist.c	7fabe8b8e3d1081ff41cc08790e3dc7ef9989255
+++ libpurple/blist.c	2e6345a091f45a9c4a82887d5290001f9c84121f
@@ -24,6 +24,7 @@
 #define _BLIST_HELPERS_
 
 #include "internal.h"
+#include "accountlist.h"
 #include "dbus-maybe.h"
 #include "debug.h"
 #include "gsignal.h"
@@ -114,7 +115,7 @@ purple_blist_get_list()
 		list = g_object_new(PURPLE_BUDDY_LIST_TYPE, NULL);
 
 		purple_blist_load();
-		for (account = purple_accounts_get_all(); account != NULL; account = account->next)	{
+		for (account = purple_accounts_all(); account != NULL; account = account->next)	{
 			purple_blist_buddies_cache_add_account(account->data);
 		}
 
@@ -267,7 +268,7 @@ blist_to_xmlnode(void)
 
 	/* Write privacy settings */
 	child = xmlnode_new_child(node, "privacy");
-	for (cur = purple_accounts_get_all(); cur != NULL; cur = cur->next)
+	for (cur = purple_accounts_all(); cur != NULL; cur = cur->next)
 	{
 		grandchild = accountprivacy_to_xmlnode(cur->data);
 		xmlnode_insert_child(child, grandchild);
============================================================
--- libpurple/account.c	547b4157748f4739fbde54eedee06da5135997f2
+++ libpurple/account.c	794f06e8d2b9819d2fc890fc280d688685156aad
@@ -25,7 +25,7 @@
  */
 #include "internal.h"
 #include "account.h"
-#include "accountmanager.h"
+#include "accountlist.h"
 #include "core.h"
 #include "dbus-maybe.h"
 #include "debug.h"
@@ -2753,153 +2753,9 @@ xmlnode * purple_account_to_xmlnode(Purp
 	return node;
 }
 
-void
-purple_accounts_add(PurpleAccount *account)
-{
-	g_return_if_fail(PURPLE_IS_ACCOUNT(account));
+#warning Make sure all subsystems (e.g. conversation, blist etc.) update themselves when an account gets destroyed.
 
-	purple_account_manager_add_account(purple_account_manager_get(), account);
-}
-
 void
-purple_accounts_remove(PurpleAccount *account)
-{
-	g_return_if_fail(PURPLE_IS_ACCOUNT(account));
-
-	purple_account_manager_remove_account(purple_account_manager_get(), account);
-}
-
-void
-purple_accounts_delete(PurpleAccount *account)
-{
-	PurpleBlistNode *gnode, *cnode, *bnode;
-	GList *iter;
-
-	g_return_if_fail(PURPLE_IS_ACCOUNT(account));
-
-	/*
-	 * Disable the account before blowing it out of the water.
-	 * Conceptually it probably makes more sense to disable the
-	 * account for all UIs rather than the just the current UI,
-	 * but it doesn't really matter.
-	 */
-	purple_account_set_enabled(account, FALSE);
-
-	purple_notify_close_with_handle(account);
-	purple_request_close_with_handle(account);
-
-	purple_accounts_remove(account);
-
-	/* Remove this account's buddies */
-	for (gnode = purple_blist_get_root();
-	     gnode != NULL;
-		 gnode = purple_blist_node_next(gnode))
-	{
-		if (!PURPLE_IS_GROUP(gnode))
-			continue;
-
-		cnode = purple_blist_node_first_child(gnode);
-		while (cnode) {
-			PurpleBlistNode *cnode_next = purple_blist_node_next(cnode);
-
-			if(PURPLE_IS_CONTACT(cnode)) {
-				bnode = purple_blist_node_first_child(cnode);
-				while (bnode) {
-					PurpleBlistNode *bnode_next = purple_blist_node_next(bnode);
-
-					if (PURPLE_IS_BUDDY(bnode)) {
-						PurpleBuddy *b = (PurpleBuddy *)bnode;
-
-						if (purple_buddy_get_account(b) == account)
-							purple_blist_node_remove(PURPLE_BLIST_NODE(b));
-					}
-					bnode = bnode_next;
-				}
-			} else if (PURPLE_IS_CHAT(cnode)) {
-				PurpleChat *c = (PurpleChat *)cnode;
-
-				if (purple_chat_get_account(c) == account)
-					purple_blist_node_remove(PURPLE_BLIST_NODE(c));
-			}
-			cnode = cnode_next;
-		}
-	}
-
-	/* Remove any open conversation for this account */
-	for (iter = purple_get_conversations(); iter; ) {
-		PurpleConversation *conv = iter->data;
-		iter = iter->next;
-		if (purple_conversation_get_account(conv) == account)
-			purple_conversation_destroy(conv);
-	}
-
-	/* Remove this account's pounces */
-	purple_pounce_destroy_all_by_account(account);
-
-	/* This will cause the deletion of an old buddy icon. */
-	purple_buddy_icons_set_account_icon(account, NULL, 0);
-
-	purple_account_destroy(account);
-}
-
-void
-purple_accounts_reorder(PurpleAccount *account, gint new_index)
-{
-	purple_account_manager_reorder_account(purple_account_manager_get(),
-			account, new_index);
-}
-
-GList *
-purple_accounts_get_all(void)
-{
-	return purple_account_manager_get_all_accounts(purple_account_manager_get());
-}
-
-GList *
-purple_accounts_get_all_active(void)
-{
-	GList *list = NULL;
-	GList *all = purple_accounts_get_all();
-
-	while (all != NULL) {
-		PurpleAccount *account = all->data;
-
-		if (purple_account_get_enabled(account))
-			list = g_list_append(list, account);
-
-		all = all->next;
-	}
-
-	return list;
-}
-
-PurpleAccount *
-purple_accounts_find(const char *name, const char *protocol_id)
-{
-	PurpleAccount *account = NULL;
-	GList *l;
-	char *who;
-
-	g_return_val_if_fail(name != NULL, NULL);
-	g_return_val_if_fail(protocol_id != NULL, NULL);
-
-	for (l = purple_accounts_get_all(); l != NULL; l = l->next) {
-		account = (PurpleAccount *)l->data;
-		if (!purple_strequal(purple_account_get_protocol_id(account), protocol_id))
-			continue;
-
-		who = g_strdup(purple_normalize(account, name));
-		if (purple_strequal(purple_normalize(account, purple_account_get_username(account)), who)) {
-			g_free(who);
-			return account;
-		}
-		g_free(who);
-	}
-
-	return NULL;
-}
-
-void
 purple_accounts_restore_current_statuses()
 {
 	GList *l;
@@ -2912,7 +2768,7 @@ purple_accounts_restore_current_statuses
 		return;
 	}
 
-	for (l = purple_accounts_get_all(); l != NULL; l = l->next)
+	for (l = purple_accounts_all(); l != NULL; l = l->next)
 	{
 		account = (PurpleAccount *)l->data;
 		if (purple_account_get_enabled(account) &&
@@ -2943,100 +2799,3 @@ purple_accounts_get_handle(void)
 	return &handle;
 }
 
-void
-purple_accounts_init(void)
-{
-	void *handle = purple_accounts_get_handle();
-
-	purple_signal_register(handle, "account-connecting",
-						 purple_marshal_VOID__POINTER, NULL, 1,
-						 purple_value_new(PURPLE_TYPE_SUBTYPE,
-										PURPLE_SUBTYPE_ACCOUNT));
-
-	purple_signal_register(handle, "account-setting-info",
-						 purple_marshal_VOID__POINTER_POINTER, NULL, 2,
-						 purple_value_new(PURPLE_TYPE_SUBTYPE,
-										PURPLE_SUBTYPE_ACCOUNT),
-						 purple_value_new(PURPLE_TYPE_STRING));
-
-	purple_signal_register(handle, "account-set-info",
-						 purple_marshal_VOID__POINTER_POINTER, NULL, 2,
-						 purple_value_new(PURPLE_TYPE_SUBTYPE,
-										PURPLE_SUBTYPE_ACCOUNT),
-						 purple_value_new(PURPLE_TYPE_STRING));
-
-	purple_signal_register(handle, "account-status-changed",
-						 purple_marshal_VOID__POINTER_POINTER_POINTER, NULL, 3,
-						 purple_value_new(PURPLE_TYPE_SUBTYPE,
-										PURPLE_SUBTYPE_ACCOUNT),
-						 purple_value_new(PURPLE_TYPE_SUBTYPE,
-										PURPLE_SUBTYPE_STATUS),
-						 purple_value_new(PURPLE_TYPE_SUBTYPE,
-										PURPLE_SUBTYPE_STATUS));
-
-	purple_signal_register(handle, "account-actions-changed",
-						 purple_marshal_VOID__POINTER, NULL, 1,
-						 purple_value_new(PURPLE_TYPE_SUBTYPE, PURPLE_SUBTYPE_ACCOUNT));
-
-	purple_signal_register(handle, "account-authorization-requested",
-						purple_marshal_INT__POINTER_POINTER,
-						purple_value_new(PURPLE_TYPE_INT), 2,
-						purple_value_new(PURPLE_TYPE_SUBTYPE,
-										PURPLE_SUBTYPE_ACCOUNT),
-						purple_value_new(PURPLE_TYPE_STRING));
-
-	purple_signal_register(handle, "account-authorization-denied",
-						purple_marshal_VOID__POINTER_POINTER, NULL, 2,
-						purple_value_new(PURPLE_TYPE_SUBTYPE,
-										PURPLE_SUBTYPE_ACCOUNT),
-						purple_value_new(PURPLE_TYPE_STRING));
-
-	purple_signal_register(handle, "account-authorization-granted",
-						purple_marshal_VOID__POINTER_POINTER, NULL, 2,
-						purple_value_new(PURPLE_TYPE_SUBTYPE,
-										PURPLE_SUBTYPE_ACCOUNT),
-						purple_value_new(PURPLE_TYPE_STRING));
-
-	purple_signal_register(handle, "account-error-changed",
-	                       purple_marshal_VOID__POINTER_POINTER_POINTER,
-	                       NULL, 3,
-	                       purple_value_new(PURPLE_TYPE_SUBTYPE,
-	                                        PURPLE_SUBTYPE_ACCOUNT),
-	                       purple_value_new(PURPLE_TYPE_POINTER),
-	                       purple_value_new(PURPLE_TYPE_POINTER));
-
-	purple_signal_register(handle, "account-signed-on",
-	                       purple_marshal_VOID__POINTER, NULL, 1,
-	                       purple_value_new(PURPLE_TYPE_SUBTYPE,
-	                                        PURPLE_SUBTYPE_ACCOUNT));
-
-	purple_signal_register(handle, "account-signed-off",
-	                       purple_marshal_VOID__POINTER, NULL, 1,
-	                       purple_value_new(PURPLE_TYPE_SUBTYPE,
-	                                        PURPLE_SUBTYPE_ACCOUNT));
-
-	purple_signal_register(handle, "account-connection-error",
-	                       purple_marshal_VOID__POINTER_INT_POINTER, NULL, 3,
-	                       purple_value_new(PURPLE_TYPE_SUBTYPE,
-	                                        PURPLE_SUBTYPE_ACCOUNT),
-	                       purple_value_new(PURPLE_TYPE_ENUM),
-	                       purple_value_new(PURPLE_TYPE_STRING));
-
-#if 0
-	purple_signal_connect(conn_handle, "signed-on", handle,
-	                      PURPLE_CALLBACK(signed_on_cb), NULL);
-	purple_signal_connect(conn_handle, "signed-off", handle,
-	                      PURPLE_CALLBACK(signed_off_cb), NULL);
-	purple_signal_connect(conn_handle, "connection-error", handle,
-	                      PURPLE_CALLBACK(connection_error_cb), NULL);
-#endif
-}
-
-void
-purple_accounts_uninit(void)
-{
-	gpointer handle = purple_accounts_get_handle();
-
-	purple_signals_disconnect_by_handle(handle);
-	purple_signals_unregister_by_instance(handle);
-}
============================================================
--- libpurple/account.h	8da0c4cd2a3d63addc2fc22ec7a4188f6bc43253
+++ libpurple/account.h	3a6f6f968ef9cd254a205d5f203a4bf7d9193650
@@ -1020,65 +1020,6 @@ xmlnode * purple_account_to_xmlnode(Purp
 /*@{*/
 
 /**
- * Adds an account to the list of accounts.
- *
- * @param account The account.
- */
-void purple_accounts_add(PurpleAccount *account);
-
-/**
- * Removes an account from the list of accounts.
- *
- * @param account The account.
- */
-void purple_accounts_remove(PurpleAccount *account);
-
-/**
- * Deletes an account.
- *
- * This will remove any buddies from the buddy list that belong to this
- * account, buddy pounces that belong to this account, and will also
- * destroy @a account.
- *
- * @param account The account.
- */
-void purple_accounts_delete(PurpleAccount *account);
-
-/**
- * Reorders an account.
- *
- * @param account   The account to reorder.
- * @param new_index The new index for the account.
- */
-void purple_accounts_reorder(PurpleAccount *account, gint new_index);
-
-/**
- * Returns a list of all accounts.
- *
- * @constreturn A list of all accounts.
- */
-GList *purple_accounts_get_all(void);
-
-/**
- * Returns a list of all enabled accounts
- *
- * @return A list of all enabled accounts. The list is owned
- *         by the caller, and must be g_list_free()d to avoid
- *         leaking the nodes.
- */
-GList *purple_accounts_get_all_active(void);
-
-/**
- * Finds an account with the specified name and protocol id.
- *
- * @param name     The account username.
- * @param protocol The account protocol ID.
- *
- * @return The account, if found, or @c FALSE otherwise.
- */
-PurpleAccount *purple_accounts_find(const char *name, const char *protocol);
-
-/**
  * This is called by the core after all subsystems and what
  * not have been initialized.  It sets all enabled accounts
  * to their startup status by signing them on, setting them
@@ -1112,7 +1053,6 @@ PurpleAccountUiOps *purple_accounts_get_
 
 /*@}*/
 
-
 /**************************************************************************/
 /** @name Accounts Subsystem                                              */
 /**************************************************************************/
@@ -1125,16 +1065,7 @@ void *purple_accounts_get_handle(void);
  */
 void *purple_accounts_get_handle(void);
 
-/**
- * Initializes the accounts subsystem.
- */
-void purple_accounts_init(void);
 
-/**
- * Uninitializes the accounts subsystem.
- */
-void purple_accounts_uninit(void);
-
 /*@}*/
 
 #ifdef __cplusplus
============================================================
--- libpurple/buddyicon.c	f4e744c549bb3a5a39c88480bef6e021b4f046e0
+++ libpurple/buddyicon.c	3e6510efa5e0de81595786b28a6125343191fa6a
@@ -26,6 +26,7 @@
 #define _PURPLE_BUDDYICON_C_
 
 #include "internal.h"
+#include "accountlist.h"
 #include "buddyicon.h"
 #include "conversation.h"
 #include "dbus-maybe.h"
@@ -1128,7 +1129,7 @@ _purple_buddy_icons_account_loaded_cb()
 	const char *dirname = purple_buddy_icons_get_cache_dir();
 	GList *cur;
 
-	for (cur = purple_accounts_get_all(); cur != NULL; cur = cur->next)
+	for (cur = purple_accounts_all(); cur != NULL; cur = cur->next)
 	{
 		PurpleAccount *account = cur->data;
 		const char *account_icon_file = purple_account_get_string(account, "buddy_icon", NULL);
============================================================
--- libpurple/savedstatuses.c	73ae5411ae8d1c8f1140a03edced673fcd1eb476
+++ libpurple/savedstatuses.c	fa0c7cb251e76262441413052a567c338b0bdb7d
@@ -25,6 +25,7 @@
  */
 #include "internal.h"
 
+#include "accountlist.h"
 #include "debug.h"
 #include "idle.h"
 #include "notify.h"
@@ -883,7 +884,7 @@ purple_savedstatus_set_idleaway(gboolean
 		/* Our global status is already "away," so don't change anything */
 		return;
 
-	accounts = purple_accounts_get_all_active();
+	accounts = purple_accounts_actives();
 	for (node = accounts; node != NULL; node = node->next)
 	{
 		PurpleAccount *account;
@@ -1115,7 +1116,7 @@ purple_savedstatus_activate(PurpleSavedS
 	purple_prefs_set_int("/purple/savedstatus/default",
 					   purple_savedstatus_get_creation_time(saved_status));
 
-	accounts = purple_accounts_get_all_active();
+	accounts = purple_accounts_actives();
 	for (node = accounts; node != NULL; node = node->next)
 	{
 		PurpleAccount *account;
============================================================
--- libpurple/dbus-server.c	71e774dce7c36d2ff6b2aaea325e0145c1951c42
+++ libpurple/dbus-server.c	bf6d8e98682eb5f491a3f0f3dc580d94a6f9ec24
@@ -36,6 +36,7 @@
 #include <string.h>
 
 #include "account.h"
+#include "accountlist.h"
 #include "blist.h"
 #include "conversation.h"
 #include "dbus-purple.h"
============================================================
--- libpurple/dbus-useful.c	2cd34a439e5633c4623a1b7192babc24ed1d72e9
+++ libpurple/dbus-useful.c	b046f9f9061cf0808deb964afa295d0089b2b22c
@@ -3,6 +3,7 @@
 
 #include "dbus-useful.h"
 #include "account.h"
+#include "accountlist.h"
 #include "util.h"
 
 
@@ -19,7 +20,7 @@ purple_accounts_find_ext(const char *nam
 	else
 		who = NULL;
 
-	for (l = purple_accounts_get_all(); l != NULL; l = l->next) {
+	for (l = purple_accounts_all(); l != NULL; l = l->next) {
 		PurpleAccount *account = (PurpleAccount *)l->data;
 
 		if (who && strcmp(purple_normalize(NULL, purple_account_get_username(account)), who))
============================================================
--- libpurple/purple-client-example.c	9868f13b5b490b85d182d1b7b053e0f3ba5222a7
+++ libpurple/purple-client-example.c	cd2bf546e2a0ea4d954f807444484daa7013fca8
@@ -27,7 +27,7 @@ int main (int argc, char **argv)
 
 	purple_init();
 
-	alist = purple_accounts_get_all();
+	alist = purple_accounts_all();
 	for (node = alist; node != NULL; node = node->next)
 	{
 		PurpleAccount *account = (PurpleAccount*) node->data;
============================================================
--- libpurple/Makefile.am	86d6dbc82d762528cfa74512fe850a187528d712
+++ libpurple/Makefile.am	553a46c2b85dc706d4c98dbca191594082091583
@@ -36,7 +36,7 @@ purple_coresources = \
 
 purple_coresources = \
 	account.c \
-	accountmanager.c \
+	accountlist.c \
 	accountopt.c \
 	blist.c \
 	blist-node.c \
@@ -120,7 +120,7 @@ purple_coreheaders = \
 
 purple_coreheaders = \
 	account.h \
-	accountmanager.h \
+	accountlist.h \
 	accountopt.h \
 	blist.h \
 	blist-node.h \
@@ -232,7 +232,7 @@ dbus_headers  = dbus-bindings.h dbus-pur
 dbus_sources  = dbus-server.c dbus-useful.c
 dbus_headers  = dbus-bindings.h dbus-purple.h dbus-server.h dbus-useful.h dbus-define-api.h dbus-types.h
 
-dbus_exported = dbus-useful.h dbus-define-api.h account.h blist.h buddyicon.h \
+dbus_exported = dbus-useful.h dbus-define-api.h account.h accountlist.h blist.h buddyicon.h \
                 connection.h conversation.h core.h ft.h log.h notify.h prefs.h roomlist.h \
                 savedstatuses.h smiley.h status.h server.h util.h xmlnode.h prpl.h
 
============================================================
--- libpurple/purple.h.in	c4c483aaabd789760251fc02ad1c2136b72f42c8
+++ libpurple/purple.h.in	a1d0b8f27014159cde8c81f2a31e508def9a20bb
@@ -46,7 +46,7 @@
 @PLUGINS_DEFINE@
 
 #include <account.h>
-#include <accountmanager.h>
+#include <accountlist.h>
 #include <accountopt.h>
 #include <blist.h>
 #include <buddyicon.h>
============================================================
--- libpurple/accountmanager.c	e4d7eb707ede42f1f1edd85185e0b12bb3d971e8
+++ libpurple/accountlist.c	14ee885a53cce0d7d9bff7c97091565f4f2d9379
@@ -1,5 +1,5 @@
 /**
- * @file accountmanager.c Account Manager API
+ * @file accountlist.c API for dealing with the list of accounts.
  * @ingroup core
  */
 
@@ -25,168 +25,48 @@
  */
 #include "internal.h"
 #include "purple.h"
+#include "gsignal.h"
 #include "marshallers.h"
 
 #include <string.h>
 
-static void schedule_accounts_save(PurpleAccountManager *manager);
-static void sync_accounts(PurpleAccountManager *manager);
+static void schedule_accounts_save(void);
+static void sync_accounts(void);
 
-/******************************************************************************
- * PurpleAccountManager API
- *****************************************************************************/
-enum
-{
-	ACCOUNT_ADDED,
-	ACCOUNT_REMOVED,
-	ACCOUNT_MANAGER_LAST_SIGNAL
-};
-static int account_manager_signals[ACCOUNT_MANAGER_LAST_SIGNAL];
-
-struct _PurpleAccountManagerPrivate
-{
+static struct {
 	GList *accounts;
+	guint save_timer;
 	gboolean accounts_loaded;
-	int save_timer;
-};
 
-#define PURPLE_ACCOUNT_MANAGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_ACCOUNT_MANAGER, PurpleAccountManagerPrivate))
+	gpointer n_handler;
+	gpointer d_handler;
+} global;
 
-G_DEFINE_TYPE(PurpleAccountManager, purple_account_manager, G_TYPE_OBJECT)
-
-static GObject *
-purple_account_manager_constructor(GType type, guint n_cprops, GObjectConstructParam *cprops)
-{
-	static GObject *singleton = NULL;
-	if (singleton == NULL)
-		singleton = G_OBJECT_CLASS(purple_account_manager_parent_class)->constructor(type, n_cprops, cprops);
-	return singleton;
-}
-
 static void
-purple_account_manager_dispose(GObject *object)
+account_new_cb(PurpleAccount *account)
 {
-	PurpleAccountManager *manager = PURPLE_ACCOUNT_MANAGER(object);
-	sync_accounts(manager);
-}
+	g_return_if_fail(account);
+	g_return_if_fail(g_list_find(global.accounts, account) == NULL);
 
-static void
-purple_account_manager_finalize(GObject *object)
-{
-	PurpleAccountManagerPrivate *priv = PURPLE_ACCOUNT_MANAGER_GET_PRIVATE(object);
-	g_list_free(priv->accounts);
-}
+	global.accounts = g_list_append(global.accounts, account);
 
-static void
-purple_account_manager_class_init(PurpleAccountManagerClass *klass)
-{
-	GObjectClass *obj_class = G_OBJECT_CLASS(klass);
-
-	obj_class->constructor = purple_account_manager_constructor;
-	obj_class->dispose = purple_account_manager_dispose;
-	obj_class->finalize = purple_account_manager_finalize;
-
-	account_manager_signals[ACCOUNT_ADDED] =
-		g_signal_new("account-added",
-				G_OBJECT_CLASS_TYPE(klass),
-				G_SIGNAL_RUN_FIRST,
-				G_STRUCT_OFFSET(PurpleAccountManagerClass, account_added),
-				NULL, NULL,
-				purple_smarshal_VOID__OBJECT,
-				G_TYPE_NONE,
-				1, PURPLE_TYPE_ACCOUNT);
-
-	account_manager_signals[ACCOUNT_REMOVED] =
-		g_signal_new("account-removed",
-				G_OBJECT_CLASS_TYPE(klass),
-				G_SIGNAL_RUN_FIRST,
-				G_STRUCT_OFFSET(PurpleAccountManagerClass, account_removed),
-				NULL, NULL,
-				purple_smarshal_VOID__OBJECT,
-				G_TYPE_NONE,
-				1, PURPLE_TYPE_ACCOUNT);
-
-	g_type_class_add_private(klass, sizeof(PurpleAccountManagerPrivate));
-}
-
-static void
-purple_account_manager_init(PurpleAccountManager *manager)
-{
-	manager->priv = PURPLE_ACCOUNT_MANAGER_GET_PRIVATE(manager);
-	manager->priv->accounts = NULL;
-	manager->priv->accounts_loaded = FALSE;
-}
-
-PurpleAccountManager *purple_account_manager_get(void)
-{
-	static PurpleAccountManager *manager = NULL;
-	if (manager == NULL)
-		manager = g_object_new(PURPLE_TYPE_ACCOUNT_MANAGER, NULL);
-	return manager;
-}
-
-void purple_account_manager_add_account(PurpleAccountManager *manager, PurpleAccount *account)
-{
-	if (!account || g_list_find(manager->priv->accounts, account))
-		return;
-
-	manager->priv->accounts = g_list_append(manager->priv->accounts, account);
-	g_signal_emit(manager, account_manager_signals[ACCOUNT_ADDED], 0, account);
-
 	/* Make sure we save the accounts when something changes */
-	g_signal_connect_swapped(G_OBJECT(account), "notify", G_CALLBACK(schedule_accounts_save), manager);
-	g_signal_connect_swapped(G_OBJECT(account), "settings-changed", G_CALLBACK(schedule_accounts_save), manager);
+	g_signal_connect_swapped(G_OBJECT(account), "notify", G_CALLBACK(schedule_accounts_save), NULL);
+	g_signal_connect_swapped(G_OBJECT(account), "settings-changed", G_CALLBACK(schedule_accounts_save), NULL);
 }
 
-void purple_account_manager_remove_account(PurpleAccountManager *manager, PurpleAccount *account)
+static void
+account_destroyed_cb(PurpleAccount *account)
 {
-	if (!g_list_find(manager->priv->accounts, account))
+	if (!g_list_find(global.accounts, account))
 		return;
 
-	manager->priv->accounts = g_list_remove(manager->priv->accounts, account);
-	g_signal_emit(manager, account_manager_signals[ACCOUNT_REMOVED], 0, account);
+	global.accounts = g_list_remove(global.accounts, account);
 
 	g_signal_handlers_disconnect_by_func(G_OBJECT(account),
-			G_CALLBACK(schedule_accounts_save), manager);
+			G_CALLBACK(schedule_accounts_save), NULL);
 }
 
-void purple_account_manager_reorder_account(PurpleAccountManager *manager, PurpleAccount *account, int new_index)
-{
-	gint index;
-	GList *l;
-	GList *accounts = manager->priv->accounts;
-
-	g_return_if_fail(account != NULL);
-	g_return_if_fail(new_index <= g_list_length(accounts));
-
-	index = g_list_index(accounts, account);
-
-	if (index == -1) {
-		purple_debug_error("account",
-				   "Unregistered account (%s) discovered during reorder!\n",
-				   purple_account_get_username(account));
-		return;
-	}
-
-	l = g_list_nth(accounts, index);
-
-	if (new_index > index)
-		new_index--;
-
-	/* Remove the old one. */
-	accounts = g_list_delete_link(accounts, l);
-
-	/* Insert it where it should go. */
-	accounts = g_list_insert(accounts, account, new_index);
-	manager->priv->accounts = accounts;
-	schedule_accounts_save(manager);
-}
-
-GList *purple_account_manager_get_all_accounts(PurpleAccountManager *manager)
-{
-	return manager->priv->accounts;
-}
-
 /*********************************************************************
  * Reading from disk                                                 *
  *********************************************************************/
@@ -600,37 +480,12 @@ parse_account(xmlnode *node)
 	return ret;
 }
 
-void purple_account_manager_load_accounts(PurpleAccountManager *manager)
-{
-	xmlnode *node, *child;
-	PurpleAccountManagerPrivate *priv = PURPLE_ACCOUNT_MANAGER_GET_PRIVATE(manager);
-
-	priv->accounts_loaded = TRUE;
-
-	node = purple_util_read_xml_from_file("accounts.xml", _("accounts"));
-
-	if (node == NULL)
-		return;
-
-	for (child = xmlnode_get_child(node, "account"); child != NULL;
-			child = xmlnode_get_next_twin(child))
-	{
-		PurpleAccount *account;
-		account = parse_account(child);
-		purple_account_manager_add_account(manager, account);
-	}
-
-	xmlnode_free(node);
-
-	_purple_buddy_icons_account_loaded_cb();
-}
-
 /*********************************************************************
  * Writing to disk                                                   *
  *********************************************************************/
 
 static xmlnode *
-accounts_to_xmlnode(PurpleAccountManager *manager)
+accounts_to_xmlnode(void)
 {
 	xmlnode *node, *child;
 	GList *cur;
@@ -638,7 +493,7 @@ accounts_to_xmlnode(PurpleAccountManager
 	node = xmlnode_new("account");
 	xmlnode_set_attrib(node, "version", "1.0");
 
-	for (cur = purple_account_manager_get_all_accounts(manager);
+	for (cur = purple_accounts_all();
 			cur != NULL; cur = cur->next)
 	{
 		child = purple_account_to_xmlnode(PURPLE_ACCOUNT(cur->data));
@@ -649,43 +504,164 @@ static void
 }
 
 static void
-sync_accounts(PurpleAccountManager *manager)
+sync_accounts(void)
 {
 	xmlnode *node;
 	char *data;
-	PurpleAccountManagerPrivate *priv = PURPLE_ACCOUNT_MANAGER_GET_PRIVATE(manager);
 
-	if (priv->save_timer == 0)
+	if (global.save_timer == 0)
 		return;
 
-	if (!priv->accounts_loaded) {
+	if (!global.accounts_loaded) {
 		purple_debug_error("account", "Attempted to save accounts before "
 						 "they were read!\n");
 		return;
 	}
 
-	node = accounts_to_xmlnode(manager);
+	node = accounts_to_xmlnode();
 	data = xmlnode_to_formatted_str(node, NULL);
 	purple_util_write_data_to_file("accounts.xml", data, -1);
 	g_free(data);
 	xmlnode_free(node);
 
-	g_source_remove(priv->save_timer);
-	priv->save_timer = 0;
+	g_source_remove(global.save_timer);
+	global.save_timer = 0;
 }
 
 static gboolean
 save_cb(gpointer data)
 {
-	sync_accounts(PURPLE_ACCOUNT_MANAGER(data));
+	sync_accounts();
 	return FALSE;
 }
 
 static void
-schedule_accounts_save(PurpleAccountManager *manager)
+schedule_accounts_save(void)
 {
-	PurpleAccountManagerPrivate *priv = PURPLE_ACCOUNT_MANAGER_GET_PRIVATE(manager);
-	if (priv->save_timer == 0)
-		priv->save_timer = purple_timeout_add_seconds(5, save_cb, manager);
+	if (global.save_timer == 0)
+		global.save_timer = purple_timeout_add_seconds(5, save_cb, NULL);
 }
 
+
+
+void
+purple_accounts_init(void)
+{
+	global.n_handler = purple_g_signal_connect(PURPLE_TYPE_ACCOUNT, "new",
+			G_CALLBACK(account_new_cb), NULL);
+	global.d_handler = purple_g_signal_connect(PURPLE_TYPE_ACCOUNT, "destroying",
+			G_CALLBACK(account_destroyed_cb), NULL);
+}
+
+void
+purple_accounts_load()
+{
+	xmlnode *node, *child;
+
+	global.accounts_loaded = TRUE;
+
+	node = purple_util_read_xml_from_file("accounts.xml", _("accounts"));
+
+	if (node == NULL)
+		return;
+
+	for (child = xmlnode_get_child(node, "account"); child != NULL;
+			child = xmlnode_get_next_twin(child))
+		parse_account(child);
+
+	xmlnode_free(node);
+
+	_purple_buddy_icons_account_loaded_cb();
+}
+
+GList *
+purple_accounts_all(void)
+{
+	return global.accounts;
+}
+
+GList *
+purple_accounts_actives(void)
+{
+	GList *list = NULL;
+	GList *all = purple_accounts_all();
+
+	while (all != NULL) {
+		PurpleAccount *account = all->data;
+
+		if (purple_account_get_enabled(account))
+			list = g_list_append(list, account);
+
+		all = all->next;
+	}
+
+	return list;
+}
+
+PurpleAccount *
+purple_accounts_find(const char *name, const char *protocol_id)
+{
+	PurpleAccount *account = NULL;
+	GList *l;
+	char *who;
+
+	g_return_val_if_fail(name != NULL, NULL);
+	g_return_val_if_fail(protocol_id != NULL, NULL);
+
+	for (l = purple_accounts_all(); l != NULL; l = l->next) {
+		account = (PurpleAccount *)l->data;
+		if (!purple_strequal(purple_account_get_protocol_id(account), protocol_id))
+			continue;
+
+		who = g_strdup(purple_normalize(account, name));
+		if (purple_strequal(purple_normalize(account, purple_account_get_username(account)), who)) {
+			g_free(who);
+			return account;
+		}
+		g_free(who);
+	}
+
+	return NULL;
+}
+
+void
+purple_accounts_reorder(PurpleAccount *account, int new_index)
+{
+	gint index;
+	GList *l;
+
+	g_return_if_fail(account != NULL);
+	g_return_if_fail(new_index <= g_list_length(global.accounts));
+
+	index = g_list_index(global.accounts, account);
+
+	if (index == -1) {
+		purple_debug_error("account",
+				   "Unregistered account (%s) discovered during reorder!\n",
+				   purple_account_get_username(account));
+		return;
+	}
+
+	l = g_list_nth(global.accounts, index);
+
+	if (new_index > index)
+		new_index--;
+
+	/* Remove the old one. */
+	global.accounts = g_list_delete_link(global.accounts, l);
+
+	/* Insert it where it should go. */
+	global.accounts = g_list_insert(global.accounts, account, new_index);
+	schedule_accounts_save();
+}
+
+void
+purple_accounts_uninit(void)
+{
+	purple_g_signal_disconnect(global.n_handler);
+	purple_g_signal_disconnect(global.d_handler);
+
+	global.n_handler = NULL;
+	global.d_handler = NULL;
+}
+
============================================================
--- libpurple/accountmanager.h	1a182fae0515e7350897843d9ebaf20f7795e080
+++ libpurple/accountlist.h	d8a21627ffd59f76644de009353e09aca8a294a9
@@ -1,5 +1,5 @@
 /**
- * @file accountmanager.h Account Manager API
+ * @file accountlist.h API for dealing with list of accounts.
  * @ingroup core
  */
 
@@ -23,60 +23,63 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
  */
-#ifndef PURPLE_ACCOUNT_MANAGER_H_
-#define PURPLE_ACCOUNT_MANAGER_H_
+#ifndef PURPLE_ACCOUNT_LIST_H_
+#define PURPLE_ACCOUNT_LIST_H_
 
 #include <glib.h>
 #include <glib-object.h>
 #include "account.h"
 
-#define PURPLE_TYPE_ACCOUNT_MANAGER				(purple_account_manager_get_type())
-#define PURPLE_ACCOUNT_MANAGER(obj)				(G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_ACCOUNT_MANAGER, PurpleAccountManager))
-#define PURPLE_ACCOUNT_MANAGER_CLASS(klass)		(G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_ACCOUNT_MANAGER, PurpleAccountManagerClass))
-#define PURPLE_IS_ACCOUNT_MANAGER(obj)			(G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_ACCOUNT_MANAGER))
-#define PURPLE_IS_ACCOUNT_MANAGER_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE((klass), PURPLE_TYPE_ACCOUNT_MANAGER))
-#define PURPLE_ACCOUNT_MANAGER_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_ACCOUNT_MANAGER, PurpleAccountManagerClass))
+G_BEGIN_DECLS
 
-typedef struct _PurpleAccountManager          PurpleAccountManager;
-typedef struct _PurpleAccountManagerPrivate   PurpleAccountManagerPrivate;
-typedef struct _PurpleAccountManagerClass     PurpleAccountManagerClass;
+/*@{*/
 
-struct _PurpleAccountManager
-{
-	GObject gparent;
+/**
+ * Initializes the accounts subsystem.
+ */
+void purple_accounts_init(void);
 
-	PurpleAccountManagerPrivate *priv;
+/**
+ * Uninitializes the accounts subsystem.
+ */
+void purple_accounts_uninit(void);
 
-	void (*_purple_reserved[4])(void);
-};
+void purple_accounts_load(void);
 
-struct _PurpleAccountManagerClass
-{
-	GObjectClass gparent;
+/**
+ * Returns a list of all accounts.
+ *
+ * @constreturn A list of all accounts.
+ */
+GList * purple_accounts_all(void);
 
-	void (*account_added)(PurpleAccountManager *manager, PurpleAccount *);
-	void (*account_removed)(PurpleAccountManager *manager, PurpleAccount *);
+/**
+ * Returns a list of all enabled accounts
+ *
+ * @return A list of all enabled accounts. The list is owned
+ *         by the caller, and must be g_list_free()d to avoid
+ *         leaking the nodes.
+ */
+GList *purple_accounts_actives(void);
 
-	void (*_purple_reserved[4])(void);
-};
+/**
+ * Finds an account with the specified name and protocol id.
+ *
+ * @param name     The account username.
+ * @param protocol The account protocol ID.
+ *
+ * @return The account, if found, or @c FALSE otherwise.
+ */
+PurpleAccount *purple_accounts_find(const char *name, const char *protocol);
 
-G_BEGIN_DECLS
+/**
+ * Reorders an account.
+ *
+ * @param account   The account to reorder.
+ * @param new_index The new index for the account.
+ */
+void purple_accounts_reorder(PurpleAccount *account, int newindex);
 
-/**************************************************************************/
-/** @name Account Manager */
-/**************************************************************************/
-/*@{*/
-
-GType purple_account_manager_get_type(void);
-PurpleAccountManager *purple_account_manager_get(void);
-
-void purple_account_manager_add_account(PurpleAccountManager *manager, PurpleAccount *account);
-void purple_account_manager_remove_account(PurpleAccountManager *manager, PurpleAccount *account);
-void purple_account_manager_reorder_account(PurpleAccountManager *manager, PurpleAccount *account, int new_index);
-GList *purple_account_manager_get_all_accounts(PurpleAccountManager *manager);
-
-void purple_account_manager_load_accounts(PurpleAccountManager *manager);
-
 /*@}*/
 G_END_DECLS
 
============================================================
--- libpurple/buddy.c	c10d2501eff5ea285c081631250a1397fb80e151
+++ libpurple/buddy.c	63d7501a75d043f9660e0433fee19a8288fda567
@@ -23,6 +23,7 @@
 #define _PURPLE_BUDDY_C_
 
 #include "internal.h"
+#include "accountlist.h"
 #include "dbus-maybe.h"
 #include "debug.h"
 #include "server.h"
============================================================
--- libpurple/chat.c	a54c107940854fd211df35c73d58a7d924601c65
+++ libpurple/chat.c	29f6928b55e5784e1c8b2f763d741823408c3353
@@ -21,6 +21,7 @@
  *
  */
 #include "internal.h"
+#include "accountlist.h"
 #include "dbus-maybe.h"
 #include "debug.h"
 #include "server.h"


More information about the Commits mailing list