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

libempathy-gtk/empathy-contact-dialogs.c
libempathy-gtk/empathy-contact-widget.c
libempathy-gtk/empathy-new-message-dialog.c
libempathy/empathy-contact-manager.c
libempathy/empathy-contact-manager.h
megaphone/src/megaphone-applet.c
src/empathy-event-manager.c
src/empathy-main-window.c
tests/contact-manager.c
tests/contact-run-until-ready-2.c

index f7b6cb635794b54012b0011614c847017dec2509..0b02cead740c336a31a3620948ef5f80f2302a73 100644 (file)
@@ -68,7 +68,7 @@ subscription_dialog_response_cb (GtkDialog *dialog,
        EmpathyContactManager *manager;
        EmpathyContact        *contact;
 
-       manager = empathy_contact_manager_new ();
+       manager = empathy_contact_manager_dup_singleton ();
        contact = empathy_contact_widget_get_contact (contact_widget);
 
        if (response == GTK_RESPONSE_YES) {
@@ -242,7 +242,7 @@ can_add_contact_to_account (McAccount *account,
        EmpathyContactManager *mgr;
        gboolean               result;
 
-       mgr = empathy_contact_manager_new ();
+       mgr = empathy_contact_manager_dup_singleton ();
        result = empathy_contact_manager_can_add (mgr, account);
        g_object_unref (mgr);
 
@@ -257,7 +257,7 @@ new_contact_response_cb (GtkDialog *dialog,
        EmpathyContactManager *manager;
        EmpathyContact         *contact;
 
-       manager = empathy_contact_manager_new ();
+       manager = empathy_contact_manager_dup_singleton ();
        contact = empathy_contact_widget_get_contact (contact_widget);
 
        if (contact && response == GTK_RESPONSE_OK) {
index c8a21e85825b51e2793500102a8b8cd27be1e92e..b3fbe334b604b0ed7c15f4ff704259c0e3bb777f 100644 (file)
@@ -828,7 +828,7 @@ contact_widget_groups_setup (EmpathyContactWidget *information)
 {
   if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS)
     {
-      information->manager = empathy_contact_manager_new ();
+      information->manager = empathy_contact_manager_dup_singleton ();
       contact_widget_model_setup (information);
     }
 }
index 44e3a6d05905882af2e5df1b51b78694e946b4cc..ab1c6530acad84e09b685a56216cbfc2dc5d498d 100644 (file)
@@ -233,7 +233,7 @@ empathy_new_message_dialog_show (GtkWindow *parent)
        dialog = g_new0 (EmpathyNewMessageDialog, 1);
 
        /* create a contact manager */
-       dialog->contact_manager = empathy_contact_manager_new ();
+       dialog->contact_manager = empathy_contact_manager_dup_singleton ();
 
        filename = empathy_file_lookup ("empathy-new-message-dialog.glade",
                                        "libempathy-gtk");
index a69d6d9705faf46bf6521cedb96cea6499228645..533da2aaf2a3c0601019f38189d78259f6ed62af 100644 (file)
@@ -47,6 +47,8 @@ G_DEFINE_TYPE_WITH_CODE (EmpathyContactManager, empathy_contact_manager, G_TYPE_
                         G_IMPLEMENT_INTERFACE (EMPATHY_TYPE_CONTACT_LIST,
                                                contact_manager_iface_init));
 
+static EmpathyContactManager *manager_singleton = NULL;
+
 static void
 contact_manager_members_changed_cb (EmpathyTpContactList  *list,
                                    EmpathyContact        *contact,
@@ -196,12 +198,33 @@ contact_manager_finalize (GObject *object)
        }
 }
 
+static GObject *
+contact_manager_constructor (GType type,
+                            guint n_props,
+                            GObjectConstructParam *props)
+{
+       GObject *retval;
+
+       if (manager_singleton) {
+               retval = g_object_ref (manager_singleton);
+       } else {
+               retval = G_OBJECT_CLASS (empathy_contact_manager_parent_class)->constructor
+                       (type, n_props, props);
+
+               manager_singleton = EMPATHY_CONTACT_MANAGER (retval);
+               g_object_add_weak_pointer (retval, (gpointer *) &manager_singleton);
+       }
+
+       return retval;
+}
+
 static void
 empathy_contact_manager_class_init (EmpathyContactManagerClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
        object_class->finalize = contact_manager_finalize;
+       object_class->constructor = contact_manager_constructor;
 
        g_type_class_add_private (object_class, sizeof (EmpathyContactManagerPriv));
 }
@@ -240,18 +263,9 @@ empathy_contact_manager_init (EmpathyContactManager *manager)
 }
 
 EmpathyContactManager *
-empathy_contact_manager_new (void)
+empathy_contact_manager_dup_singleton (void)
 {
-       static EmpathyContactManager *manager = NULL;
-
-       if (!manager) {
-               manager = g_object_new (EMPATHY_TYPE_CONTACT_MANAGER, NULL);
-               g_object_add_weak_pointer (G_OBJECT (manager), (gpointer) &manager);
-       } else {
-               g_object_ref (manager);
-       }
-
-       return manager;
+       return g_object_new (EMPATHY_TYPE_CONTACT_MANAGER, NULL);
 }
 
 EmpathyTpContactList *
index c2e0b67a28c85a1fa3e7849860828dd1555dcb95..57e8764e4a3d6d56671e410a84e6d3db56234b82 100644 (file)
@@ -52,7 +52,7 @@ struct _EmpathyContactManagerClass {
 };
 
 GType                  empathy_contact_manager_get_type (void) G_GNUC_CONST;
-EmpathyContactManager *empathy_contact_manager_new      (void);
+EmpathyContactManager *empathy_contact_manager_dup_singleton  (void);
 EmpathyTpContactList * empathy_contact_manager_get_list (EmpathyContactManager *manager,
                                                         McAccount             *account);
 gboolean               empathy_contact_manager_can_add  (EmpathyContactManager *manager,
index 1d63a2cbb61fcd882364508c71a85a31212e8c6c..413e34276abfcc252230d4a2de39c2a8906de94e 100644 (file)
@@ -354,7 +354,7 @@ megaphone_applet_show_preferences (MegaphoneApplet *applet)
                                              NULL);
 
        /* Show all contacts, even offline and sort alphabetically */
-       contact_manager = empathy_contact_manager_new ();
+       contact_manager = empathy_contact_manager_dup_singleton ();
        contact_store = empathy_contact_list_store_new (EMPATHY_CONTACT_LIST (contact_manager));
        g_object_set (contact_store,
                      "is-compact", TRUE,
index efcea9ec8d8a0047614ef62b86b9471c6e77dc9a..398d8d9ffe53e220a67a0e08bc8ac512ff64b801 100644 (file)
@@ -460,7 +460,7 @@ empathy_event_manager_init (EmpathyEventManager *manager)
        manager->priv = priv;
 
        priv->dispatcher = empathy_dispatcher_new ();
-       priv->contact_manager = empathy_contact_manager_new ();
+       priv->contact_manager = empathy_contact_manager_dup_singleton ();
        g_signal_connect (priv->dispatcher, "filter-channel",
                          G_CALLBACK (event_manager_filter_channel_cb),
                          manager);
index 3d552492335304b39b6498765eea24667b68123e..4a6c862120b1730b5f3d0241c35105db54536861 100644 (file)
@@ -599,7 +599,7 @@ empathy_main_window_show (void)
        /* Set up contact list. */
        empathy_status_presets_get_all ();
 
-       list_iface = EMPATHY_CONTACT_LIST (empathy_contact_manager_new ());
+       list_iface = EMPATHY_CONTACT_LIST (empathy_contact_manager_dup_singleton ());
        monitor = empathy_contact_list_get_monitor (list_iface);
        window->list_store = empathy_contact_list_store_new (list_iface);
        window->list_view = empathy_contact_list_view_new (window->list_store,
index 81c1a9ba4770c27659e08a66e092994a1b1d7115..7793b44d9832430abdb74ede6584766a3aa93336 100644 (file)
@@ -23,7 +23,7 @@ main (int argc, char **argv)
 
        empathy_debug_set_flags (g_getenv ("EMPATHY_DEBUG"));
        main_loop = g_main_loop_new (NULL, FALSE);
-       manager = empathy_contact_manager_new ();
+       manager = empathy_contact_manager_dup_singleton ();
        store = empathy_contact_list_store_new (EMPATHY_CONTACT_LIST (manager));
        empathy_contact_list_store_set_is_compact (store, TRUE);
        empathy_contact_list_store_set_show_groups (store, FALSE);
index 03c7e8a64d367ea91331a5b43b733d4403550ab3..42653411602fb0a1929c1017fac1aa436dad7cf1 100644 (file)
@@ -41,7 +41,7 @@ callback (gpointer data)
 {
        EmpathyContactManager *manager;
 
-       manager = empathy_contact_manager_new ();
+       manager = empathy_contact_manager_dup_singleton ();
        g_signal_connect (manager, "pendings-changed",
                          G_CALLBACK (pending_cb),
                          NULL);