diff options
author | Xavier Claessens <xclaesse@src.gnome.org> | 2009-01-09 18:06:00 +0800 |
---|---|---|
committer | Xavier Claessens <xclaesse@src.gnome.org> | 2009-01-09 18:06:00 +0800 |
commit | c2a1dec002eb9a8c0372bc6fc920a54e36b7e991 (patch) | |
tree | eab79909cfb1550b494c5a81056301bbf2698204 /libempathy | |
parent | 4100a5f538bf8f2c22658a579a80c909162dc46c (diff) | |
download | gsoc2013-empathy-c2a1dec002eb9a8c0372bc6fc920a54e36b7e991.tar gsoc2013-empathy-c2a1dec002eb9a8c0372bc6fc920a54e36b7e991.tar.gz gsoc2013-empathy-c2a1dec002eb9a8c0372bc6fc920a54e36b7e991.tar.bz2 gsoc2013-empathy-c2a1dec002eb9a8c0372bc6fc920a54e36b7e991.tar.lz gsoc2013-empathy-c2a1dec002eb9a8c0372bc6fc920a54e36b7e991.tar.xz gsoc2013-empathy-c2a1dec002eb9a8c0372bc6fc920a54e36b7e991.tar.zst gsoc2013-empathy-c2a1dec002eb9a8c0372bc6fc920a54e36b7e991.zip |
Port EmpathyIdle to the new singleton policy.
svn path=/trunk/; revision=2114
Diffstat (limited to 'libempathy')
-rw-r--r-- | libempathy/empathy-idle.c | 38 | ||||
-rw-r--r-- | libempathy/empathy-idle.h | 2 |
2 files changed, 27 insertions, 13 deletions
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); |