]> git.0d.be Git - empathy.git/commitdiff
Port EmpathyIdle to the new singleton policy.
authorXavier Claessens <xclaesse@src.gnome.org>
Fri, 9 Jan 2009 10:06:00 +0000 (10:06 +0000)
committerXavier Claessens <xclaesse@src.gnome.org>
Fri, 9 Jan 2009 10:06:00 +0000 (10:06 +0000)
svn path=/trunk/; revision=2114

libempathy-gtk/empathy-presence-chooser.c
libempathy/empathy-idle.c
libempathy/empathy-idle.h
src/empathy-status-icon.c
src/empathy.c

index c86baade01bbaad32c8df4b4f1f0686d74bf5473..ff735e52096b11380be15ab3e539e87073ee4428 100644 (file)
@@ -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);
 }
index 9eea49771235fa6889ccda86648d3f5f215099ae..2751f7cfafc0d5729392febc8ced689bd589a68c 100644 (file)
@@ -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
index fbaab36a95ed9afd657661bf56a42ffea18b467c..7296f7cd43105acd5aae19be5c8608f3d079b160 100644 (file)
@@ -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);
index 07fc3aa02a2e76b7ee4bbe8f2783912f40f33ad2..86fe27a4faaccd3cdfad6b3059736d490c52e765 100644 (file)
@@ -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",
index 815b2b487afe2562b69e10ab39765646148a32dd..e449247acd147544e28a3abca4f27f9d9a984cea 100644 (file)
@@ -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,