From c2a1dec002eb9a8c0372bc6fc920a54e36b7e991 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Fri, 9 Jan 2009 10:06:00 +0000 Subject: Port EmpathyIdle to the new singleton policy. svn path=/trunk/; revision=2114 --- libempathy/empathy-idle.c | 38 ++++++++++++++++++++++++++------------ libempathy/empathy-idle.h | 2 +- 2 files changed, 27 insertions(+), 13 deletions(-) (limited to 'libempathy') diff --git a/libempathy/empathy-idle.c b/libempathy/empathy-idle.c index 9eea49771..2751f7cfa 100644 --- a/libempathy/empathy-idle.c +++ b/libempathy/empathy-idle.c @@ -76,7 +76,9 @@ enum { PROP_USE_NM }; -G_DEFINE_TYPE (EmpathyIdle, empathy_idle, G_TYPE_OBJECT) +G_DEFINE_TYPE (EmpathyIdle, empathy_idle, G_TYPE_OBJECT); + +static EmpathyIdle * idle_singleton = NULL; static void idle_presence_changed_cb (MissionControl *mc, @@ -271,6 +273,26 @@ idle_finalize (GObject *object) idle_ext_away_stop (EMPATHY_IDLE (object)); } +static GObject * +idle_constructor (GType type, + guint n_props, + GObjectConstructParam *props) +{ + GObject *retval; + + if (idle_singleton) { + retval = g_object_ref (idle_singleton); + } else { + retval = G_OBJECT_CLASS (empathy_idle_parent_class)->constructor + (type, n_props, props); + g_object_add_weak_pointer (retval, (gpointer *) &retval); + + idle_singleton = EMPATHY_IDLE (retval); + } + + return retval; +} + static void idle_get_property (GObject *object, guint param_id, @@ -345,6 +367,7 @@ empathy_idle_class_init (EmpathyIdleClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = idle_finalize; + object_class->constructor = idle_constructor; object_class->get_property = idle_get_property; object_class->set_property = idle_set_property; @@ -465,18 +488,9 @@ empathy_idle_init (EmpathyIdle *idle) } EmpathyIdle * -empathy_idle_new (void) +empathy_idle_dup_singleton (void) { - static EmpathyIdle *idle = NULL; - - if (!idle) { - idle = g_object_new (EMPATHY_TYPE_IDLE, NULL); - g_object_add_weak_pointer (G_OBJECT (idle), (gpointer) &idle); - } else { - g_object_ref (idle); - } - - return idle; + return g_object_new (EMPATHY_TYPE_IDLE, NULL); } McPresence diff --git a/libempathy/empathy-idle.h b/libempathy/empathy-idle.h index fbaab36a9..7296f7cd4 100644 --- a/libempathy/empathy-idle.h +++ b/libempathy/empathy-idle.h @@ -48,7 +48,7 @@ struct _EmpathyIdleClass { }; GType empathy_idle_get_type (void) G_GNUC_CONST; -EmpathyIdle *empathy_idle_new (void); +EmpathyIdle *empathy_idle_dup_singleton (void); McPresence empathy_idle_get_state (EmpathyIdle *idle); void empathy_idle_set_state (EmpathyIdle *idle, McPresence state); -- cgit v1.2.3