From b7c6cb4be567ebaf391065f04f5acd923720002d Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 28 Aug 2012 16:50:12 +0100 Subject: [PATCH 1/8] McdAccountManager: move initialization from init to constructed This lets us use the construct properties, and in particular the TpDBusDaemon, which means we can make it a construct-time property on McdStorage. --- src/mcd-account-manager.c | 32 +++++++++++++------------------- src/mcd-storage.c | 15 ++------------- src/mcd-storage.h | 4 +--- 3 files changed, 16 insertions(+), 35 deletions(-) diff --git a/src/mcd-account-manager.c b/src/mcd-account-manager.c index e0e2350..e752406 100644 --- a/src/mcd-account-manager.c +++ b/src/mcd-account-manager.c @@ -1622,6 +1622,18 @@ static void mcd_account_manager_init (McdAccountManager *account_manager) { McdAccountManagerPrivate *priv; + + priv = G_TYPE_INSTANCE_GET_PRIVATE ((account_manager), + MCD_TYPE_ACCOUNT_MANAGER, + McdAccountManagerPrivate); + account_manager->priv = priv; +} + +static void +_mcd_account_manager_constructed (GObject *obj) +{ + McdAccountManager *account_manager = MCD_ACCOUNT_MANAGER (obj); + McdAccountManagerPrivate *priv = account_manager->priv; guint i = 0; static struct { const gchar *name; GCallback handler; } sig[] = { { "created", G_CALLBACK (created_cb) }, @@ -1634,12 +1646,7 @@ mcd_account_manager_init (McdAccountManager *account_manager) DEBUG (""); - priv = G_TYPE_INSTANCE_GET_PRIVATE ((account_manager), - MCD_TYPE_ACCOUNT_MANAGER, - McdAccountManagerPrivate); - account_manager->priv = priv; - - priv->storage = mcd_storage_new (); + priv->storage = mcd_storage_new (priv->dbus_daemon); priv->accounts = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, unref_account); @@ -1662,19 +1669,6 @@ mcd_account_manager_init (McdAccountManager *account_manager) mcd_dbus_init_interfaces_instances (account_manager); } -static void -_mcd_account_manager_constructed (GObject *obj) -{ - McdAccountManager *manager = MCD_ACCOUNT_MANAGER (obj); - McdAccountManagerPrivate *priv = MCD_ACCOUNT_MANAGER_PRIV (manager); - - /* FIXME: I'm pretty sure we should just move most of the above code out of - * _init() to here and then mcd_plugin_account_manager_new() could take the - * TpDBusDaemon * as it should and everyone wins. - */ - mcd_storage_set_dbus_daemon (priv->storage, priv->dbus_daemon); -} - McdAccountManager * mcd_account_manager_new (TpDBusDaemon *dbus_daemon) { diff --git a/src/mcd-storage.c b/src/mcd-storage.c index e786eed..814474c 100644 --- a/src/mcd-storage.c +++ b/src/mcd-storage.c @@ -153,24 +153,13 @@ mcd_storage_class_init (McdStorageClass *cls) } McdStorage * -mcd_storage_new () +mcd_storage_new (TpDBusDaemon *dbus_daemon) { return g_object_new (MCD_TYPE_STORAGE, + "dbus-daemon", dbus_daemon, NULL); } -void -mcd_storage_set_dbus_daemon (McdStorage *self, - TpDBusDaemon *dbusd) -{ - GValue value = { 0 }; - - g_value_init (&value, G_TYPE_OBJECT); - g_value_take_object (&value, dbusd); - - g_object_set_property (G_OBJECT (self), "dbus-daemon", &value); -} - static gchar * get_value (const McpAccountManager *ma, const gchar *account, diff --git a/src/mcd-storage.h b/src/mcd-storage.h index 5a09155..c8c031b 100644 --- a/src/mcd-storage.h +++ b/src/mcd-storage.h @@ -56,9 +56,7 @@ typedef struct _McdStoragePrivate McdStoragePrivate; GType mcd_storage_get_type (void); -McdStorage *mcd_storage_new (void); -void mcd_storage_set_dbus_daemon (McdStorage *self, - TpDBusDaemon *dbusd); +McdStorage *mcd_storage_new (TpDBusDaemon *dbus_daemon); void mcd_storage_ready (McdStorage *self); void mcd_storage_connect_signal (const gchar *signal, GCallback func, -- 1.7.10.4