#include "empathy-contact-factory.h"
#include "empathy-utils.h"
-#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
- EMPATHY_TYPE_CONTACT_FACTORY, EmpathyContactFactoryPriv))
-
-struct _EmpathyContactFactoryPriv {
+#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyContactFactory)
+typedef struct {
GHashTable *accounts;
-};
-
-static void empathy_contact_factory_class_init (EmpathyContactFactoryClass *klass);
-static void empathy_contact_factory_init (EmpathyContactFactory *factory);
+} EmpathyContactFactoryPriv;
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)
tp_factory = g_hash_table_lookup (priv->accounts, account);
if (!tp_factory) {
tp_factory = empathy_tp_contact_factory_new (account);
- g_hash_table_insert (priv->accounts,
- g_object_ref (account),
- tp_factory);
+ g_hash_table_insert (priv->accounts, account, tp_factory);
}
- return tp_factory;
+ return g_object_ref (tp_factory);
}
EmpathyContact *
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);
+
+ factory_singleton = EMPATHY_CONTACT_FACTORY (retval);
+ g_object_add_weak_pointer (retval, (gpointer) &factory_singleton);
+ }
+
+ 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));
}
static void
empathy_contact_factory_init (EmpathyContactFactory *factory)
{
- EmpathyContactFactoryPriv *priv = GET_PRIV (factory);
+ EmpathyContactFactoryPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (factory,
+ EMPATHY_TYPE_CONTACT_FACTORY, EmpathyContactFactoryPriv);
+ factory->priv = priv;
priv->accounts = g_hash_table_new_full (empathy_account_hash,
empathy_account_equal,
g_object_unref,
}
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);
}