aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libempathy-gtk/empathy-contact-dialogs.c6
-rw-r--r--libempathy-gtk/empathy-contact-widget.c2
-rw-r--r--libempathy-gtk/empathy-new-message-dialog.c2
-rw-r--r--libempathy/empathy-contact-manager.c36
-rw-r--r--libempathy/empathy-contact-manager.h2
-rw-r--r--megaphone/src/megaphone-applet.c2
-rw-r--r--src/empathy-event-manager.c2
-rw-r--r--src/empathy-main-window.c2
-rw-r--r--tests/contact-manager.c2
-rw-r--r--tests/contact-run-until-ready-2.c2
10 files changed, 36 insertions, 22 deletions
diff --git a/libempathy-gtk/empathy-contact-dialogs.c b/libempathy-gtk/empathy-contact-dialogs.c
index f7b6cb635..0b02cead7 100644
--- a/libempathy-gtk/empathy-contact-dialogs.c
+++ b/libempathy-gtk/empathy-contact-dialogs.c
@@ -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) {
diff --git a/libempathy-gtk/empathy-contact-widget.c b/libempathy-gtk/empathy-contact-widget.c
index c8a21e858..b3fbe334b 100644
--- a/libempathy-gtk/empathy-contact-widget.c
+++ b/libempathy-gtk/empathy-contact-widget.c
@@ -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);
}
}
diff --git a/libempathy-gtk/empathy-new-message-dialog.c b/libempathy-gtk/empathy-new-message-dialog.c
index 44e3a6d05..ab1c6530a 100644
--- a/libempathy-gtk/empathy-new-message-dialog.c
+++ b/libempathy-gtk/empathy-new-message-dialog.c
@@ -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");
diff --git a/libempathy/empathy-contact-manager.c b/libempathy/empathy-contact-manager.c
index a69d6d970..533da2aaf 100644
--- a/libempathy/empathy-contact-manager.c
+++ b/libempathy/empathy-contact-manager.c
@@ -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 *
diff --git a/libempathy/empathy-contact-manager.h b/libempathy/empathy-contact-manager.h
index c2e0b67a2..57e8764e4 100644
--- a/libempathy/empathy-contact-manager.h
+++ b/libempathy/empathy-contact-manager.h
@@ -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,
diff --git a/megaphone/src/megaphone-applet.c b/megaphone/src/megaphone-applet.c
index 1d63a2cbb..413e34276 100644
--- a/megaphone/src/megaphone-applet.c
+++ b/megaphone/src/megaphone-applet.c
@@ -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,
diff --git a/src/empathy-event-manager.c b/src/empathy-event-manager.c
index efcea9ec8..398d8d9ff 100644
--- a/src/empathy-event-manager.c
+++ b/src/empathy-event-manager.c
@@ -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);
diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c
index 3d5524923..4a6c86212 100644
--- a/src/empathy-main-window.c
+++ b/src/empathy-main-window.c
@@ -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,
diff --git a/tests/contact-manager.c b/tests/contact-manager.c
index 81c1a9ba4..7793b44d9 100644
--- a/tests/contact-manager.c
+++ b/tests/contact-manager.c
@@ -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);
diff --git a/tests/contact-run-until-ready-2.c b/tests/contact-run-until-ready-2.c
index 03c7e8a64..426534116 100644
--- a/tests/contact-run-until-ready-2.c
+++ b/tests/contact-run-until-ready-2.c
@@ -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);