diff options
author | Xavier Claessens <xclaesse@src.gnome.org> | 2009-01-09 18:06:32 +0800 |
---|---|---|
committer | Xavier Claessens <xclaesse@src.gnome.org> | 2009-01-09 18:06:32 +0800 |
commit | 5dadc0ac3a478376337e2d10dec4ade7d5b44998 (patch) | |
tree | e9c0587441515b0ef5c383aa2e8f78b8243f8987 /libempathy | |
parent | cdd2f65ff2d5b70b09b4ac57f28a94d38715c62d (diff) | |
download | gsoc2013-empathy-5dadc0ac3a478376337e2d10dec4ade7d5b44998.tar gsoc2013-empathy-5dadc0ac3a478376337e2d10dec4ade7d5b44998.tar.gz gsoc2013-empathy-5dadc0ac3a478376337e2d10dec4ade7d5b44998.tar.bz2 gsoc2013-empathy-5dadc0ac3a478376337e2d10dec4ade7d5b44998.tar.lz gsoc2013-empathy-5dadc0ac3a478376337e2d10dec4ade7d5b44998.tar.xz gsoc2013-empathy-5dadc0ac3a478376337e2d10dec4ade7d5b44998.tar.zst gsoc2013-empathy-5dadc0ac3a478376337e2d10dec4ade7d5b44998.zip |
Port EmpathyContactManager to the new singleton policy.
svn path=/trunk/; revision=2121
Diffstat (limited to 'libempathy')
-rw-r--r-- | libempathy/empathy-contact-manager.c | 36 | ||||
-rw-r--r-- | libempathy/empathy-contact-manager.h | 2 |
2 files changed, 26 insertions, 12 deletions
diff --git a/libempathy/empathy-contact-manager.c b/libempathy/empathy-contact-manager.c index a69d6d970..533da2aaf 100644 --- a/libempathy/empathy-contact-manager.c +++ b/libempathy/empathy-contact-manager.c @@ -47,6 +47,8 @@ G_DEFINE_TYPE_WITH_CODE (EmpathyContactManager, empathy_contact_manager, G_TYPE_ G_IMPLEMENT_INTERFACE (EMPATHY_TYPE_CONTACT_LIST, contact_manager_iface_init)); +static EmpathyContactManager *manager_singleton = NULL; + static void contact_manager_members_changed_cb (EmpathyTpContactList *list, EmpathyContact *contact, @@ -196,12 +198,33 @@ contact_manager_finalize (GObject *object) } } +static GObject * +contact_manager_constructor (GType type, + guint n_props, + GObjectConstructParam *props) +{ + GObject *retval; + + if (manager_singleton) { + retval = g_object_ref (manager_singleton); + } else { + retval = G_OBJECT_CLASS (empathy_contact_manager_parent_class)->constructor + (type, n_props, props); + + manager_singleton = EMPATHY_CONTACT_MANAGER (retval); + g_object_add_weak_pointer (retval, (gpointer *) &manager_singleton); + } + + return retval; +} + static void empathy_contact_manager_class_init (EmpathyContactManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = contact_manager_finalize; + object_class->constructor = contact_manager_constructor; g_type_class_add_private (object_class, sizeof (EmpathyContactManagerPriv)); } @@ -240,18 +263,9 @@ empathy_contact_manager_init (EmpathyContactManager *manager) } EmpathyContactManager * -empathy_contact_manager_new (void) +empathy_contact_manager_dup_singleton (void) { - static EmpathyContactManager *manager = NULL; - - if (!manager) { - manager = g_object_new (EMPATHY_TYPE_CONTACT_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_CONTACT_MANAGER, NULL); } EmpathyTpContactList * diff --git a/libempathy/empathy-contact-manager.h b/libempathy/empathy-contact-manager.h index c2e0b67a2..57e8764e4 100644 --- a/libempathy/empathy-contact-manager.h +++ b/libempathy/empathy-contact-manager.h @@ -52,7 +52,7 @@ struct _EmpathyContactManagerClass { }; GType empathy_contact_manager_get_type (void) G_GNUC_CONST; -EmpathyContactManager *empathy_contact_manager_new (void); +EmpathyContactManager *empathy_contact_manager_dup_singleton (void); EmpathyTpContactList * empathy_contact_manager_get_list (EmpathyContactManager *manager, McAccount *account); gboolean empathy_contact_manager_can_add (EmpathyContactManager *manager, |