gobjectification: 703edd0e: Split PurpleAccountManager into its own…

sadrul at pidgin.im sadrul at pidgin.im
Sat Mar 1 05:06:46 EST 2008


-----------------------------------------------------------------
Revision: 703edd0e7ce2eccf9f52b94b8d03783f32e75de2
Ancestor: 760fcafe15614b682f788c4d95abe462277ed964
Author: sadrul at pidgin.im
Date: 2008-03-01T10:05:42
Branch: im.pidgin.gobjectification
URL: http://d.pidgin.im/viewmtn/revision/info/703edd0e7ce2eccf9f52b94b8d03783f32e75de2

Added files:
        libpurple/accountmanager.c libpurple/accountmanager.h
Modified files:
        libpurple/Makefile.am libpurple/account.c
        libpurple/account.h po/POTFILES.in

ChangeLog: 

Split PurpleAccountManager into its own file. Account saving and loading needs to be moved from account.c to accountmanager.c now.

-------------- next part --------------
============================================================
--- libpurple/accountmanager.c	23ccacf84f58a751de9d27ac1ee2d56b01889fa8
+++ libpurple/accountmanager.c	23ccacf84f58a751de9d27ac1ee2d56b01889fa8
@@ -0,0 +1,168 @@
+/**
+ * @file accountmanager.c Account Manager API
+ * @ingroup core
+ */
+
+/* purple
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ */
+#include "purple.h"
+#include "marshallers.h"
+
+/******************************************************************************
+ * PurpleAccountManager API
+ *****************************************************************************/
+enum
+{
+	ACCOUNT_ADDED,
+	ACCOUNT_REMOVED,
+	ACCOUNT_MANAGER_LAST_SIGNAL
+};
+static int account_manager_signals[ACCOUNT_MANAGER_LAST_SIGNAL];
+
+struct _PurpleAccountManagerPrivate
+{
+	GList *accounts;
+};
+
+#define PURPLE_ACCOUNT_MANAGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_ACCOUNT_MANAGER, PurpleAccountManagerPrivate))
+
+static void
+purple_account_manager_class_init(PurpleAccountManagerClass *klass)
+{
+	account_manager_signals[ACCOUNT_ADDED] =
+		g_signal_new("account-added",
+				G_OBJECT_CLASS_TYPE(klass),
+				G_SIGNAL_RUN_LAST,
+				0, NULL, NULL,
+#warning FIXME: Change this to __OBJECT when PurpleAccount is a GObject
+				purple_smarshal_VOID__POINTER,
+				G_TYPE_NONE,
+				1, G_TYPE_POINTER);//PURPLE_TYPE_ACCOUNT);
+
+	account_manager_signals[ACCOUNT_REMOVED] =
+		g_signal_new("account-removed",
+				G_OBJECT_CLASS_TYPE(klass),
+				G_SIGNAL_RUN_LAST,
+				0, NULL, NULL,
+#warning FIXME: Change this to __OBJECT when PurpleAccount is a GObject
+				purple_smarshal_VOID__POINTER,
+				G_TYPE_NONE,
+				1, G_TYPE_POINTER);//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;
+}
+
+GType purple_account_manager_get_gtype(void)
+{
+	static GType type = 0;
+
+	if(type == 0) {
+		static const GTypeInfo info = {
+			sizeof(PurpleAccountManagerClass),
+			NULL,
+			NULL,
+			(GClassInitFunc)purple_account_manager_class_init,
+			NULL,
+			NULL,
+			sizeof(PurpleAccountManager),
+			0,
+			(GInstanceInitFunc)purple_account_manager_init,
+			NULL,
+		};
+
+		type = g_type_register_static(G_TYPE_OBJECT,
+				"PurpleAccountManager",
+				&info, 0);
+	}
+
+	return type;
+}
+
+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 (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);
+}
+
+void purple_account_manager_remove_account(PurpleAccountManager *manager, PurpleAccount *account)
+{
+	if (!g_list_find(manager->priv->accounts, account))
+		return;
+
+	manager->priv->accounts = g_list_remove(manager->priv->accounts, account);
+	g_signal_emit(manager, account_manager_signals[ACCOUNT_REMOVED], 0, account);
+}
+
+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;
+}
+
+GList *purple_account_manager_get_all_accounts(PurpleAccountManager *manager)
+{
+	return manager->priv->accounts;
+}
+
+
============================================================
--- libpurple/accountmanager.h	4cd9855dc94dced2e1fffc519ca01bf0286af188
+++ libpurple/accountmanager.h	4cd9855dc94dced2e1fffc519ca01bf0286af188
@@ -0,0 +1,77 @@
+/**
+ * @file accountmanager.h Account Manager API
+ * @ingroup core
+ */
+
+/* purple
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * 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_
+
+#include <glib.h>
+#include <glib-object.h>
+#include "account.h"
+
+#define PURPLE_TYPE_ACCOUNT_MANAGER				(purple_account_manager_get_gtype())
+#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))
+
+typedef struct _PurpleAccountManager          PurpleAccountManager;
+typedef struct _PurpleAccountManagerPrivate   PurpleAccountManagerPrivate;
+typedef struct _PurpleAccountManagerClass     PurpleAccountManagerClass;
+
+struct _PurpleAccountManager
+{
+	GObject gparent;
+
+	PurpleAccountManagerPrivate *priv;
+
+	void (*_purple_reserved[4])(void);
+};
+
+struct _PurpleAccountManagerClass
+{
+	GObjectClass gparent;
+	void (*_purple_reserved[4])(void);
+};
+
+G_BEGIN_DECLS
+
+/**************************************************************************/
+/** @name Account Manager */
+/**************************************************************************/
+/*@{*/
+
+GType purple_account_manager_get_gtype(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);
+/*@}*/
+
+G_END_DECLS
+
+#endif
============================================================
--- libpurple/Makefile.am	12c086077429279032d3808fba1baa0d29472bf1
+++ libpurple/Makefile.am	c056fb4f0773ea2581850f57d471c1115290e3bc
@@ -35,6 +35,7 @@ purple_coresources = \
 
 purple_coresources = \
 	account.c \
+	accountmanager.c \
 	accountopt.c \
 	blist.c \
 	buddyicon.c \
@@ -92,6 +93,7 @@ purple_coreheaders = \
 
 purple_coreheaders = \
 	account.h \
+	accountmanager.h \
 	accountopt.h \
 	blist.h \
 	buddyicon.h \
============================================================
--- libpurple/account.c	325a356790afaa87ce2c6d45da91f0ba3f796d2b
+++ libpurple/account.c	b9871fe0e42d35ce0132be84e5affe86b4cfd8fd
@@ -25,6 +25,7 @@
  */
 #include "internal.h"
 #include "account.h"
+#include "accountmanager.h"
 #include "core.h"
 #include "dbus-maybe.h"
 #include "debug.h"
@@ -469,6 +470,7 @@ schedule_accounts_save(void)
 static void
 schedule_accounts_save(void)
 {
+#warning Loading and saving should really be moved to the account manager
 	if (save_timer == 0)
 		save_timer = purple_timeout_add_seconds(5, save_cb, NULL);
 }
@@ -2568,6 +2570,8 @@ purple_accounts_reorder(PurpleAccount *a
 {
 	purple_account_manager_reorder_account(purple_account_manager_get(),
 			account, new_index);
+
+	schedule_accounts_save();
 }
 
 GList *
@@ -2708,7 +2712,7 @@ purple_accounts_init(void)
 	purple_signal_register(handle, "account-alias-changed",
 						 purple_marshal_VOID__POINTER_POINTER, NULL, 2,
 						 purple_value_new(PURPLE_TYPE_SUBTYPE,
-							 			PURPLE_SUBTYPE_ACCOUNT),
+										PURPLE_SUBTYPE_ACCOUNT),
 						 purple_value_new(PURPLE_TYPE_STRING));
 
 	purple_signal_register(handle, "account-authorization-requested",
@@ -2762,144 +2766,3 @@ purple_accounts_uninit(void)
 	purple_signals_unregister_by_instance(handle);
 }
 
-/******************************************************************************
- * PurpleAccountManager API
- *****************************************************************************/
-enum
-{
-	ACCOUNT_ADDED,
-	ACCOUNT_REMOVED,
-	ACCOUNT_MANAGER_LAST_SIGNAL
-};
-static int account_manager_signals[ACCOUNT_MANAGER_LAST_SIGNAL];
-
-struct _PurpleAccountManagerPrivate
-{
-	GList *accounts;
-};
-
-#define PURPLE_ACCOUNT_MANAGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_ACCOUNT_MANAGER, PurpleAccountManagerPrivate))
-
-static void
-purple_account_manager_class_init(PurpleAccountManagerClass *klass)
-{
-	account_manager_signals[ACCOUNT_ADDED] =
-		g_signal_new("account-added",
-				G_OBJECT_CLASS_TYPE(klass),
-				G_SIGNAL_RUN_LAST,
-				0, NULL, NULL,
-#warning FIXME: Change this to __OBJECT when PurpleAccount is a GObject
-				purple_smarshal_VOID__POINTER,
-				G_TYPE_NONE,
-				1, G_TYPE_POINTER);//PURPLE_TYPE_ACCOUNT);
-
-	account_manager_signals[ACCOUNT_REMOVED] =
-		g_signal_new("account-removed",
-				G_OBJECT_CLASS_TYPE(klass),
-				G_SIGNAL_RUN_LAST,
-				0, NULL, NULL,
-#warning FIXME: Change this to __OBJECT when PurpleAccount is a GObject
-				purple_smarshal_VOID__POINTER,
-				G_TYPE_NONE,
-				1, G_TYPE_POINTER);//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;
-}
-
-GType purple_account_manager_get_gtype(void)
-{
-	static GType type = 0;
-
-	if(type == 0) {
-		static const GTypeInfo info = {
-			sizeof(PurpleAccountManagerClass),
-			NULL,
-			NULL,
-			(GClassInitFunc)purple_account_manager_class_init,
-			NULL,
-			NULL,
-			sizeof(PurpleAccountManager),
-			0,
-			(GInstanceInitFunc)purple_account_manager_init,
-			NULL,
-		};
-
-		type = g_type_register_static(G_TYPE_OBJECT,
-				"PurpleAccountManager",
-				&info, 0);
-	}
-
-	return type;
-}
-
-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 (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);
-}
-
-void purple_account_manager_remove_account(PurpleAccountManager *manager, PurpleAccount *account)
-{
-	if (!g_list_find(manager->priv->accounts, account))
-		return;
-
-	manager->priv->accounts = g_list_remove(manager->priv->accounts, account);
-	g_signal_emit(manager, account_manager_signals[ACCOUNT_REMOVED], 0, account);
-}
-
-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();
-}
-
-GList *purple_account_manager_get_all_accounts(PurpleAccountManager *manager)
-{
-	return manager->priv->accounts;
-}
-
============================================================
--- libpurple/account.h	c88f0da9d8663714a5a5aa5f4d41320667dbf607
+++ libpurple/account.h	e259b8b44f7e9d017395110eeef8821261a5aade
@@ -1051,46 +1051,6 @@ void purple_accounts_uninit(void);
 
 /*@}*/
 
-/**************************************************************************/
-/** @name Account Manager */
-/**************************************************************************/
-/*@{*/
-
-#define PURPLE_TYPE_ACCOUNT_MANAGER				(purple_account_manager_get_gtype())
-#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))
-
-typedef struct _PurpleAccountManager          PurpleAccountManager;
-typedef struct _PurpleAccountManagerPrivate   PurpleAccountManagerPrivate;
-typedef struct _PurpleAccountManagerClass     PurpleAccountManagerClass;
-
-struct _PurpleAccountManager
-{
-	GObject gparent;
-
-	PurpleAccountManagerPrivate *priv;
-
-	void (*_purple_reserved[4])(void);
-};
-
-struct _PurpleAccountManagerClass
-{
-	GObjectClass gparent;
-	void (*_purple_reserved[4])(void);
-};
-
-GType purple_account_manager_get_gtype(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);
-/*@}*/
-
 #ifdef __cplusplus
 }
 #endif
============================================================
--- po/POTFILES.in	9a220ae97806133d70da22a0c3fe23fc4b188360
+++ po/POTFILES.in	b5c8381abe66410f0f5b9f32d45881355fd54c24
@@ -37,6 +37,7 @@ libpurple/account.c
 finch/plugins/grouping.c
 finch/plugins/lastlog.c
 libpurple/account.c
+libpurple/accountmanager.c
 libpurple/blist.c
 libpurple/certificate.c
 libpurple/connection.c


More information about the Commits mailing list