aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@src.gnome.org>2009-01-09 18:05:54 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2009-01-09 18:05:54 +0800
commit4100a5f538bf8f2c22658a579a80c909162dc46c (patch)
treeb401ae53129b4dd1c2847fcac86cc01565dc2006 /libempathy
parent2f6103a3cf15d278fc95929e72ed5652a103c058 (diff)
downloadgsoc2013-empathy-4100a5f538bf8f2c22658a579a80c909162dc46c.tar
gsoc2013-empathy-4100a5f538bf8f2c22658a579a80c909162dc46c.tar.gz
gsoc2013-empathy-4100a5f538bf8f2c22658a579a80c909162dc46c.tar.bz2
gsoc2013-empathy-4100a5f538bf8f2c22658a579a80c909162dc46c.tar.lz
gsoc2013-empathy-4100a5f538bf8f2c22658a579a80c909162dc46c.tar.xz
gsoc2013-empathy-4100a5f538bf8f2c22658a579a80c909162dc46c.tar.zst
gsoc2013-empathy-4100a5f538bf8f2c22658a579a80c909162dc46c.zip
Port EmpathyContactFactory to the new singleton policy.
svn path=/trunk/; revision=2113
Diffstat (limited to 'libempathy')
-rw-r--r--libempathy/empathy-contact-factory.c36
-rw-r--r--libempathy/empathy-contact-factory.h2
-rw-r--r--libempathy/empathy-dispatcher.c8
-rw-r--r--libempathy/empathy-tp-chat.c2
-rw-r--r--libempathy/empathy-tp-file.c2
-rw-r--r--libempathy/empathy-tp-group.c2
-rw-r--r--libempathy/empathy-tp-tube.c2
7 files changed, 34 insertions, 20 deletions
diff --git a/libempathy/empathy-contact-factory.c b/libempathy/empathy-contact-factory.c
index e35bc350d..f7f701bea 100644
--- a/libempathy/empathy-contact-factory.c
+++ b/libempathy/empathy-contact-factory.c
@@ -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);
}
diff --git a/libempathy/empathy-contact-factory.h b/libempathy/empathy-contact-factory.h
index 24fec0e03..16df02bcd 100644
--- a/libempathy/empathy-contact-factory.h
+++ b/libempathy/empathy-contact-factory.h
@@ -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,
diff --git a/libempathy/empathy-dispatcher.c b/libempathy/empathy-dispatcher.c
index 29345e0a3..aaac433c9 100644
--- a/libempathy/empathy-dispatcher.c
+++ b/libempathy/empathy-dispatcher.c
@@ -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);
diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c
index 8517c1c0d..690fa6d3f 100644
--- a/libempathy/empathy-tp-chat.c
+++ b/libempathy/empathy-tp-chat.c
@@ -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",
diff --git a/libempathy/empathy-tp-file.c b/libempathy/empathy-tp-file.c
index c21d780f9..ada0a4354 100644
--- a/libempathy/empathy-tp-file.c
+++ b/libempathy/empathy-tp-file.c
@@ -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",
diff --git a/libempathy/empathy-tp-group.c b/libempathy/empathy-tp-group.c
index c9220382a..c3471c157 100644
--- a/libempathy/empathy-tp-group.c
+++ b/libempathy/empathy-tp-group.c
@@ -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",
diff --git a/libempathy/empathy-tp-tube.c b/libempathy/empathy-tp-tube.c
index 5f421ac78..9d4c66038 100644
--- a/libempathy/empathy-tp-tube.c
+++ b/libempathy/empathy-tp-tube.c
@@ -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 *