diff options
author | Pierre-Luc Beaudoin <pierre-luc.beaudoin@collabora.co.uk> | 2009-05-31 23:53:18 +0800 |
---|---|---|
committer | Pierre-Luc Beaudoin <pierre-luc.beaudoin@collabora.co.uk> | 2009-06-01 23:35:33 +0800 |
commit | f24134c23869a0a1749a7b8f8bc2347011050a4f (patch) | |
tree | 64b92fd13224623c0711fa70647a63249fad7c31 /libempathy-gtk | |
parent | 2b4b8cafc87d72a3f93ddab1a2058a64460e54c3 (diff) | |
download | gsoc2013-empathy-f24134c23869a0a1749a7b8f8bc2347011050a4f.tar gsoc2013-empathy-f24134c23869a0a1749a7b8f8bc2347011050a4f.tar.gz gsoc2013-empathy-f24134c23869a0a1749a7b8f8bc2347011050a4f.tar.bz2 gsoc2013-empathy-f24134c23869a0a1749a7b8f8bc2347011050a4f.tar.lz gsoc2013-empathy-f24134c23869a0a1749a7b8f8bc2347011050a4f.tar.xz gsoc2013-empathy-f24134c23869a0a1749a7b8f8bc2347011050a4f.tar.zst gsoc2013-empathy-f24134c23869a0a1749a7b8f8bc2347011050a4f.zip |
Reimplement the singleton in the constructor
Diffstat (limited to 'libempathy-gtk')
-rw-r--r-- | libempathy-gtk/empathy-location-manager.c | 37 | ||||
-rw-r--r-- | libempathy-gtk/empathy-location-manager.h | 2 |
2 files changed, 29 insertions, 10 deletions
diff --git a/libempathy-gtk/empathy-location-manager.c b/libempathy-gtk/empathy-location-manager.c index aab598bc9..3da7f7590 100644 --- a/libempathy-gtk/empathy-location-manager.c +++ b/libempathy-gtk/empathy-location-manager.c @@ -46,6 +46,7 @@ /* Seconds before updating the location */ #define TIMEOUT 10 +static EmpathyLocationManager *location_manager = NULL; #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyLocationManager) typedef struct { @@ -100,6 +101,29 @@ static gboolean publish_on_idle (gpointer user_data); G_DEFINE_TYPE (EmpathyLocationManager, empathy_location_manager, G_TYPE_OBJECT); +static GObject * +location_manager_constructor (GType type, + guint n_construct_params, + GObjectConstructParam *construct_params) +{ + GObject *retval; + + if (location_manager == NULL) + { + retval = G_OBJECT_CLASS (empathy_location_manager_parent_class)->constructor + (type, n_construct_params, construct_params); + + location_manager = EMPATHY_LOCATION_MANAGER (retval); + g_object_add_weak_pointer (retval, (gpointer) &location_manager); + } + else + { + retval = g_object_ref (location_manager); + } + + return retval; +} + static void empathy_location_manager_class_init (EmpathyLocationManagerClass *class) { @@ -107,6 +131,7 @@ empathy_location_manager_class_init (EmpathyLocationManagerClass *class) object_class = G_OBJECT_CLASS (class); + object_class->constructor = location_manager_constructor; object_class->dispose = location_manager_dispose; object_class->get_property = location_manager_get_property; object_class->set_property = location_manager_set_property; @@ -314,16 +339,10 @@ location_manager_set_property (GObject *object, } EmpathyLocationManager * -empathy_location_manager_dup_default (void) +empathy_location_manager_dup_singleton (void) { - static EmpathyLocationManager *singleton = NULL; - if (singleton == NULL) - { - singleton = g_object_new (EMPATHY_TYPE_LOCATION_MANAGER, NULL); - g_object_add_weak_pointer (G_OBJECT (singleton), (gpointer *)&singleton); - } - - return g_object_ref (singleton); + return EMPATHY_LOCATION_MANAGER (g_object_new (EMPATHY_TYPE_LOCATION_MANAGER, + NULL)); } static void diff --git a/libempathy-gtk/empathy-location-manager.h b/libempathy-gtk/empathy-location-manager.h index cb12791dc..092ef0809 100644 --- a/libempathy-gtk/empathy-location-manager.h +++ b/libempathy-gtk/empathy-location-manager.h @@ -50,7 +50,7 @@ struct _EmpathyLocationManagerClass }; GType empathy_location_manager_get_type (void) G_GNUC_CONST; -EmpathyLocationManager * empathy_location_manager_dup_default (void); +EmpathyLocationManager * empathy_location_manager_dup_singleton (void); G_END_DECLS |