Commit 4100a5f5 authored by Xavier Claessens's avatar Xavier Claessens

Port EmpathyContactFactory to the new singleton policy.

svn path=/trunk/; revision=2113
parent 2f6103a3
......@@ -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);
}
......
......@@ -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,
......
......@@ -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");
......
......@@ -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);
}
......@@ -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,
......
......@@ -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);
......
......@@ -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",
......
......@@ -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",
......
......@@ -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",
......
......@@ -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 *
......
......@@ -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 */
......
......@@ -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);
......
......@@ -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 |
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment