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

14 files changed:
libempathy-gtk/empathy-avatar-chooser.c
libempathy-gtk/empathy-contact-list-view.c
libempathy-gtk/empathy-contact-widget.c
libempathy/empathy-contact-factory.c
libempathy/empathy-contact-factory.h
libempathy/empathy-dispatcher.c
libempathy/empathy-tp-chat.c
libempathy/empathy-tp-file.c
libempathy/empathy-tp-group.c
libempathy/empathy-tp-tube.c
megaphone/src/megaphone-applet.c
src/empathy-event-manager.c
src/empathy-main-window.c
tests/contact-run-until-ready.c

index 86df44953cacd45c81664026c797b4812f564e65..5da81b936f3a84fefa5a83e1b71eebc52599d9e5 100644 (file)
@@ -213,7 +213,7 @@ empathy_avatar_chooser_init (EmpathyAvatarChooser *chooser)
                          G_CALLBACK (avatar_chooser_clicked_cb),
                          chooser);
 
-       priv->contact_factory = empathy_contact_factory_new ();
+       priv->contact_factory = empathy_contact_factory_dup_singleton ();
 
        empathy_avatar_chooser_set (chooser, NULL);
 }
index 839a0df363318f49db5ff85e06b2ddf066401dd8..f9fbce92f99bc4cfd6bd30a79a44cc2cbc90ae2d 100644 (file)
@@ -213,7 +213,7 @@ contact_list_view_drag_data_received (GtkWidget         *widget,
                id);
 
        strv = g_strsplit (id, "/", 2);
-       factory = empathy_contact_factory_new ();
+       factory = empathy_contact_factory_dup_singleton ();
        account = mc_account_lookup (strv[0]);
        if (account) {
                contact = empathy_contact_factory_get_from_id (factory,
index 4100a6872227e2e647b21b3d86470242a480315d..c8a21e85825b51e2793500102a8b8cd27be1e92e 100644 (file)
@@ -162,7 +162,7 @@ empathy_contact_widget_new (EmpathyContact *contact,
 
   information = g_slice_new0 (EmpathyContactWidget);
   information->flags = flags;
-  information->factory = empathy_contact_factory_new ();
+  information->factory = empathy_contact_factory_dup_singleton ();
 
   filename = empathy_file_lookup ("empathy-contact-widget.glade",
       "libempathy-gtk");
index e35bc350da3fb71b8c6100572bf67773a37dfc96..f7f701bea823c7db3de0c4b9b3b6eb45cf475295 100644 (file)
@@ -31,6 +31,8 @@ typedef struct {
 
 G_DEFINE_TYPE (EmpathyContactFactory, empathy_contact_factory, G_TYPE_OBJECT);
 
+static EmpathyContactFactory * factory_singleton = NULL;
+
 EmpathyTpContactFactory *
 empathy_contact_factory_get_tp_factory (EmpathyContactFactory *factory,
                                        McAccount             *account)
@@ -133,12 +135,33 @@ contact_factory_finalize (GObject *object)
        G_OBJECT_CLASS (empathy_contact_factory_parent_class)->finalize (object);
 }
 
+static GObject *
+contact_factory_constructor (GType type,
+                            guint n_props,
+                            GObjectConstructParam *props)
+{
+       GObject *retval;
+
+       if (factory_singleton) {
+               retval = g_object_ref (factory_singleton);
+       } else {
+               retval = G_OBJECT_CLASS (empathy_contact_factory_parent_class)->constructor
+                       (type, n_props, props);
+               g_object_add_weak_pointer (retval, (gpointer *) &retval);
+
+               factory_singleton = EMPATHY_CONTACT_FACTORY (retval);
+       }
+
+       return retval;
+}
+
 static void
 empathy_contact_factory_class_init (EmpathyContactFactoryClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
        object_class->finalize = contact_factory_finalize;
+       object_class->constructor = contact_factory_constructor;
 
        g_type_class_add_private (object_class, sizeof (EmpathyContactFactoryPriv));
 }
@@ -157,17 +180,8 @@ empathy_contact_factory_init (EmpathyContactFactory *factory)
 }
 
 EmpathyContactFactory *
-empathy_contact_factory_new (void)
+empathy_contact_factory_dup_singleton (void)
 {
-       static EmpathyContactFactory *factory = NULL;
-
-       if (!factory) {
-               factory = g_object_new (EMPATHY_TYPE_CONTACT_FACTORY, NULL);
-               g_object_add_weak_pointer (G_OBJECT (factory), (gpointer) &factory);
-       } else {
-               g_object_ref (factory);
-       }
-
-       return factory;
+       return g_object_new (EMPATHY_TYPE_CONTACT_FACTORY, NULL);
 }
 
index 24fec0e03082b283181e70c88a8642ec03a9240f..16df02bcdd012c0b6ceb291da3aea4d94e18bf52 100644 (file)
@@ -51,7 +51,7 @@ struct _EmpathyContactFactoryClass {
 };
 
 GType                  empathy_contact_factory_get_type         (void) G_GNUC_CONST;
-EmpathyContactFactory *empathy_contact_factory_new              (void);
+EmpathyContactFactory *empathy_contact_factory_dup_singleton    (void);
 EmpathyTpContactFactory *empathy_contact_factory_get_tp_factory (EmpathyContactFactory *factory,
                                                                 McAccount             *account);
 EmpathyContact *       empathy_contact_factory_get_user         (EmpathyContactFactory *factory,
index 29345e0a39c38acbedac752289f3ccb1f9695862..aaac433c978a779206226136bce23fb259ce7b4d 100644 (file)
@@ -235,7 +235,7 @@ dispatcher_tubes_new_tube_cb (TpChannel   *channel,
        tube = g_slice_new (DispatcherTube);
        tube->ref_count = 1;
        tube->handled = FALSE;
-       tube->factory = empathy_contact_factory_new ();
+       tube->factory = empathy_contact_factory_dup_singleton ();
        tube->bus_name = empathy_tube_handler_build_bus_name (type, service);
        tube->object_path = empathy_tube_handler_build_object_path (type, service);
        tube->public.activatable = FALSE;
@@ -850,7 +850,7 @@ empathy_dispatcher_call_with_contact (EmpathyContact *contact)
        group = empathy_tp_group_new (channel);
        empathy_run_until_ready (group);
 
-       factory = empathy_contact_factory_new ();
+       factory = empathy_contact_factory_dup_singleton ();
        self_contact = empathy_contact_factory_get_user (factory, account);
        empathy_contact_run_until_ready (self_contact,
                                         EMPATHY_CONTACT_READY_HANDLE,
@@ -873,7 +873,7 @@ empathy_dispatcher_call_with_contact_id (McAccount *account, const gchar *contac
        EmpathyContactFactory *factory;
        EmpathyContact        *contact;
 
-       factory = empathy_contact_factory_new ();
+       factory = empathy_contact_factory_dup_singleton ();
        contact = empathy_contact_factory_get_from_id (factory, account, contact_id);
        empathy_contact_run_until_ready (contact, EMPATHY_CONTACT_READY_HANDLE, NULL);
 
@@ -922,7 +922,7 @@ empathy_dispatcher_chat_with_contact_id (McAccount   *account,
        EmpathyContactFactory *factory;
        EmpathyContact        *contact;
 
-       factory = empathy_contact_factory_new ();
+       factory = empathy_contact_factory_dup_singleton ();
        contact = empathy_contact_factory_get_from_id (factory, account, contact_id);
        empathy_contact_run_until_ready (contact, EMPATHY_CONTACT_READY_HANDLE, NULL);
 
index 8517c1c0d43b50af8dec34508573ea0757955a10..690fa6d3f30a7b2efc6518016bcf78d5360304a3 100644 (file)
@@ -950,7 +950,7 @@ tp_chat_constructor (GType                  type,
 
        priv = GET_PRIV (chat);
        priv->account = empathy_channel_get_account (priv->channel);
-       priv->factory = empathy_contact_factory_new ();
+       priv->factory = empathy_contact_factory_dup_singleton ();
        priv->user = empathy_contact_factory_get_user (priv->factory, priv->account);
 
        g_signal_connect (priv->channel, "invalidated",
index c21d780f967a95d6afd88974bdb06a785f61f2c3..ada0a435475426350a7f86ca6b78c93e59e43e9b 100644 (file)
@@ -507,7 +507,7 @@ tp_file_constructor (GType type,
 
   tp_file = EMPATHY_TP_FILE (file_obj);
 
-  tp_file->priv->factory = empathy_contact_factory_new ();
+  tp_file->priv->factory = empathy_contact_factory_dup_singleton ();
   tp_file->priv->mc = empathy_mission_control_new ();
 
   g_signal_connect (tp_file->priv->channel, "invalidated",
index c9220382a30eb986dd834cac90d7c41de04bee25..c3471c1578c432c721667ba7929a7fd4cbfd336b 100644 (file)
@@ -570,7 +570,7 @@ tp_group_constructed (GObject *group)
        EmpathyTpGroupPriv *priv = GET_PRIV (group);
        gboolean            channel_ready;
 
-       priv->factory = empathy_contact_factory_new ();
+       priv->factory = empathy_contact_factory_dup_singleton ();
        priv->account = empathy_channel_get_account (priv->channel);
 
        g_signal_connect (priv->channel, "invalidated",
index 5f421ac7883da998c45619bed5f5046159fe0167..9d4c66038065f11046def07b64a1895c037f5d69 100644 (file)
@@ -351,7 +351,7 @@ empathy_tp_tube_init (EmpathyTpTube *tube)
 
   tube->priv = priv;
 
-  priv->factory = empathy_contact_factory_new ();
+  priv->factory = empathy_contact_factory_dup_singleton ();
 }
 
 EmpathyTpTube *
index 4be4443b853e02354c6e0e06413c36c8490824f4..1d63a2cbb61fcd882364508c71a85a31212e8c6c 100644 (file)
@@ -112,7 +112,7 @@ megaphone_applet_init (MegaphoneApplet *applet)
                MEGAPHONE_TYPE_APPLET, MegaphoneAppletPriv);
 
        applet->priv = priv;
-       priv->factory = empathy_contact_factory_new ();
+       priv->factory = empathy_contact_factory_dup_singleton ();
        priv->gconf = gconf_client_get_default ();
 
        /* Image holds the contact avatar */
index 4b5cfc5051f2d610f8f6a6a1bd722c99ad60871d..f192b9731cb40461684220190ea85f15e0b4f8ae 100644 (file)
@@ -223,7 +223,7 @@ event_manager_filter_channel_cb (EmpathyDispatcher   *dispatcher,
                McAccount             *account;
                EmpathyContactFactory *factory;
 
-               factory = empathy_contact_factory_new ();
+               factory = empathy_contact_factory_dup_singleton ();
                handle = tp_channel_get_handle (channel, NULL);
                account = empathy_channel_get_account (channel);
 
index f034638e3abac698a6c86a6170d342704f0b36b1..07c236f969dec6e301dd25a13d9c6f5dacd8a129 100644 (file)
@@ -1009,7 +1009,7 @@ main_window_edit_personal_information_cb (GtkWidget         *widget,
                McAccount             *account;
 
                account = accounts->data;
-               factory = empathy_contact_factory_new ();
+               factory = empathy_contact_factory_dup_singleton ();
                contact = empathy_contact_factory_get_user (factory, account);
                empathy_contact_run_until_ready (contact,
                                                 EMPATHY_CONTACT_READY_HANDLE |
index 1d263dd05228bba6f67fad66bafd1852440413ad..13fad63a72442a0a25d58f42a6a6ee74a8a7bbe9 100644 (file)
@@ -13,7 +13,7 @@ callback (gpointer data)
        EmpathyContact        *contact;
        EmpathyContactReady    ready_flags;
 
-       factory = empathy_contact_factory_new ();
+       factory = empathy_contact_factory_dup_singleton ();
        account = mc_account_lookup ("jabber0");
        contact = empathy_contact_factory_get_from_handle (factory, account, 2);