diff options
author | Xavier Claessens <xclaesse@src.gnome.org> | 2009-01-07 00:48:25 +0800 |
---|---|---|
committer | Xavier Claessens <xclaesse@src.gnome.org> | 2009-01-07 00:48:25 +0800 |
commit | cea4cc62cdb35a1674ad8d3d418150e564b0cf33 (patch) | |
tree | 41e33b8bf9809b13cddec29a3f9ad5ceb896afea /libempathy | |
parent | 0ec769a38d77f1b76357ff626c4006e57cbf79e6 (diff) | |
download | gsoc2013-empathy-cea4cc62cdb35a1674ad8d3d418150e564b0cf33.tar gsoc2013-empathy-cea4cc62cdb35a1674ad8d3d418150e564b0cf33.tar.gz gsoc2013-empathy-cea4cc62cdb35a1674ad8d3d418150e564b0cf33.tar.bz2 gsoc2013-empathy-cea4cc62cdb35a1674ad8d3d418150e564b0cf33.tar.lz gsoc2013-empathy-cea4cc62cdb35a1674ad8d3d418150e564b0cf33.tar.xz gsoc2013-empathy-cea4cc62cdb35a1674ad8d3d418150e564b0cf33.tar.zst gsoc2013-empathy-cea4cc62cdb35a1674ad8d3d418150e564b0cf33.zip |
Use _constructor () override to implement singleton.
svn path=/trunk/; revision=2071
Diffstat (limited to 'libempathy')
-rw-r--r-- | libempathy/empathy-account-manager.c | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index dc5fa0fee..0d50cd9c7 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -59,7 +59,7 @@ enum { }; static guint signals[LAST_SIGNAL]; -static EmpathyAccountManager *manager = NULL; +static EmpathyAccountManager *manager_singleton = NULL; G_DEFINE_TYPE (EmpathyAccountManager, empathy_account_manager, G_TYPE_OBJECT); @@ -419,6 +419,25 @@ do_dispose (GObject *obj) G_OBJECT_CLASS (empathy_account_manager_parent_class)->dispose (obj); } +static GObject* +do_constructor (GType type, + guint n_construct_params, + GObjectConstructParam *construct_params) +{ + GObject *retval; + + if (!manager_singleton) { + retval = G_OBJECT_CLASS (empathy_account_manager_parent_class)->constructor (type, + n_construct_params, + construct_params); + manager_singleton = EMPATHY_ACCOUNT_MANAGER (retval); + } else { + retval = g_object_ref (manager_singleton); + } + + return retval; +} + static void empathy_account_manager_class_init (EmpathyAccountManagerClass *klass) { @@ -426,6 +445,7 @@ empathy_account_manager_class_init (EmpathyAccountManagerClass *klass) oclass->finalize = do_finalize; oclass->dispose = do_dispose; + oclass->constructor = do_constructor; signals[ACCOUNT_CREATED] = g_signal_new ("account-created", @@ -510,14 +530,7 @@ empathy_account_manager_class_init (EmpathyAccountManagerClass *klass) EmpathyAccountManager * empathy_account_manager_new (void) { - if (!manager) { - manager = g_object_new (EMPATHY_TYPE_ACCOUNT_MANAGER, NULL); - g_object_add_weak_pointer (G_OBJECT (manager), (gpointer) &manager); - } else { - g_object_ref (manager); - } - - return manager; + return g_object_new (EMPATHY_TYPE_ACCOUNT_MANAGER, NULL); } int |