diff options
-rw-r--r-- | libempathy-gtk/empathy-presence-chooser.c | 4 | ||||
-rw-r--r-- | libempathy/empathy-idle.c | 38 | ||||
-rw-r--r-- | libempathy/empathy-idle.h | 2 | ||||
-rw-r--r-- | src/empathy-status-icon.c | 4 | ||||
-rw-r--r-- | src/empathy.c | 2 |
5 files changed, 32 insertions, 18 deletions
diff --git a/libempathy-gtk/empathy-presence-chooser.c b/libempathy-gtk/empathy-presence-chooser.c index c86baade0..ff735e520 100644 --- a/libempathy-gtk/empathy-presence-chooser.c +++ b/libempathy-gtk/empathy-presence-chooser.c @@ -203,7 +203,7 @@ empathy_presence_chooser_init (EmpathyPresenceChooser *chooser) G_CALLBACK (presence_chooser_scroll_event_cb), NULL); - priv->idle = empathy_idle_new (); + priv->idle = empathy_idle_dup_singleton (); presence_chooser_presence_changed_cb (chooser); g_signal_connect_swapped (priv->idle, "notify", G_CALLBACK (presence_chooser_presence_changed_cb), @@ -747,7 +747,7 @@ presence_chooser_set_state (McPresence state, { EmpathyIdle *idle; - idle = empathy_idle_new (); + idle = empathy_idle_dup_singleton (); empathy_idle_set_presence (idle, state, status); g_object_unref (idle); } 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); diff --git a/src/empathy-status-icon.c b/src/empathy-status-icon.c index 07fc3aa02..86fe27a4f 100644 --- a/src/empathy-status-icon.c +++ b/src/empathy-status-icon.c @@ -396,8 +396,8 @@ empathy_status_icon_init (EmpathyStatusIcon *icon) icon->priv = priv; priv->icon = gtk_status_icon_new (); priv->account_manager = empathy_account_manager_dup_singleton (); - priv->idle = empathy_idle_new (); - priv->event_manager = empathy_event_manager_new (); + priv->idle = empathy_idle_dup_singleton (); + priv->event_manager = empathy_event_manager_dup_singleton (); g_signal_connect (priv->account_manager, "account-connection-changed", diff --git a/src/empathy.c b/src/empathy.c index 815b2b487..e449247ac 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -473,7 +473,7 @@ main (int argc, char *argv[]) } /* Setting up Idle */ - idle = empathy_idle_new (); + idle = empathy_idle_dup_singleton (); empathy_idle_set_auto_away (idle, TRUE); use_nm_notify_cb (empathy_conf_get (), EMPATHY_PREFS_USE_NM, idle); empathy_conf_notify_add (empathy_conf_get (), EMPATHY_PREFS_USE_NM, |