]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-contact-factory.c
Fix type punned pointers warnings
[empathy.git] / libempathy / empathy-contact-factory.c
index 2169e7108a4501f4e9a19adc8f216d6a64b2c3c0..c3500577434f6e6ae42aca6c49d30db195b6c932 100644 (file)
@@ -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)
@@ -41,12 +43,10 @@ empathy_contact_factory_get_tp_factory (EmpathyContactFactory *factory,
        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 *
@@ -135,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);
+
+               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));
 }
@@ -159,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);
 }