* all:
[modest] / src / modest-singletons.c
index 2915a0f..61d0b08 100644 (file)
@@ -28,6 +28,7 @@
  */
 
 #include "modest-singletons.h"
+#include "modest-runtime.h"
 
 /* 'private'/'protected' functions */
 static void modest_singletons_class_init (ModestSingletonsClass *klass);
@@ -41,7 +42,8 @@ struct _ModestSingletonsPrivate {
        ModestTnyAccountStore     *account_store;
        ModestCacheMgr            *cache_mgr;   
        ModestMailOperationQueue  *mail_op_queue;
-       ModestWidgetFactory       *widget_factory;
+       TnyPlatformFactory        *platform_fact;
+       TnyDevice                 *device;
 };
 #define MODEST_SINGLETONS_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
                                                MODEST_TYPE_SINGLETONS, \
@@ -96,7 +98,8 @@ modest_singletons_init (ModestSingletons *obj)
        priv->account_store  = NULL;
        priv->cache_mgr      = NULL;
        priv->mail_op_queue  = NULL;
-       priv->widget_factory = NULL;
+       priv->platform_fact  = NULL;
+       priv->device         = NULL;
        
        priv->conf           = modest_conf_new ();
        if (!priv->conf) {
@@ -110,12 +113,24 @@ modest_singletons_init (ModestSingletons *obj)
                return;
        }
 
-       priv->account_store  = modest_tny_account_store_new (priv->account_mgr);
+       priv->platform_fact  = modest_tny_platform_factory_get_instance ();
+       if (!priv->platform_fact) {
+               g_printerr ("modest: cannot create platform factory instance\n");
+               return;
+       }
+
+       priv->device  = tny_platform_factory_new_device (priv->platform_fact);
+       if (!priv->device) {
+               g_printerr ("modest: cannot create tny device instance\n");
+               return;
+       }
+       
+       priv->account_store  = modest_tny_account_store_new (priv->account_mgr, priv->device);
        if (!priv->account_store) {
                g_printerr ("modest: cannot create modest tny account store instance\n");
                return;
        }
-
+       
        priv->cache_mgr     = modest_cache_mgr_new ();
        if (!priv->cache_mgr) {
                g_printerr ("modest: cannot create modest cache mgr instance\n");
@@ -126,11 +141,7 @@ modest_singletons_init (ModestSingletons *obj)
        if (!priv->mail_op_queue) {
                g_printerr ("modest: cannot create modest mail operation queue instance\n");
                return;
-       }
-
-       /* don't initialize widget_factory here, but do it lazily, so we can
-        * instaniatie modest-singletons before gtk_init
-        */
+       }       
 }
 
 
@@ -138,49 +149,66 @@ static void
 check_object_is_dead (GObject *obj, gchar *name)
 {
        if (G_IS_OBJECT(obj))
-               g_printerr ("modest: %s is still alive\n", name);
+               g_warning ("BUG: %s still has %d ref(s)\n", name, obj->ref_count);
 }
 
 static void
 modest_singletons_finalize (GObject *obj)
 {
        ModestSingletonsPrivate *priv;
+       gboolean debug = modest_runtime_get_debug_flags() & MODEST_RUNTIME_DEBUG_DEBUG_OBJECTS;
+               
        priv = MODEST_SINGLETONS_GET_PRIVATE(obj);
 
-       if (priv->widget_factory) {
-               g_object_unref (G_OBJECT(priv->widget_factory));
-               check_object_is_dead ((GObject*)priv->widget_factory,
-                                     "priv->widget_factory");
-               priv->widget_factory = NULL;
-       }
-
        if (priv->account_store) {
                g_object_unref (G_OBJECT(priv->account_store));
-               check_object_is_dead ((GObject*)priv->account_store,
-                                     "priv->account_store");
+               if (debug)
+                       check_object_is_dead ((GObject*)priv->account_store,
+                                             "priv->account_store");
                priv->account_store = NULL;
        }
 
        if (priv->account_mgr) {
                g_object_unref (G_OBJECT(priv->account_mgr));
-               check_object_is_dead ((GObject*)priv->account_mgr,
-                                     "priv->account_mgr");
+               if (debug)
+                       check_object_is_dead ((GObject*)priv->account_mgr,
+                                             "priv->account_mgr");
                priv->account_mgr = NULL;
        }
 
        if (priv->conf) {
                g_object_unref (G_OBJECT(priv->conf));
-               check_object_is_dead ((GObject*)priv->conf,
-                                     "priv->conf");
+               if (debug)
+                       check_object_is_dead ((GObject*)priv->conf,
+                                             "priv->conf");
                priv->conf = NULL;
        }
 
        if (priv->cache_mgr) {
                g_object_unref (G_OBJECT(priv->cache_mgr));
-               check_object_is_dead ((GObject*)priv->cache_mgr,
-                                     "priv->cache_mgr");
+               if (debug)
+                       check_object_is_dead ((GObject*)priv->cache_mgr,
+                                             "priv->cache_mgr");
                priv->cache_mgr = NULL;
        }
+
+       if (priv->device) {
+               g_object_unref (G_OBJECT(priv->device));
+               if (debug)
+                       check_object_is_dead ((GObject*)priv->cache_mgr,
+                                             "priv->device");
+               priv->device = NULL;
+       }
+
+       if (priv->platform_fact) {
+               g_object_unref (G_OBJECT(priv->platform_fact));
+               if (debug)
+                       check_object_is_dead ((GObject*)priv->cache_mgr,
+                                             "priv->platform_fact");
+               priv->platform_fact = NULL;
+       }
+
+
        
        G_OBJECT_CLASS(parent_class)->finalize (obj);
 }
@@ -196,7 +224,7 @@ modest_singletons_new (void)
 
        /* widget_factory will still be NULL, as it is initialized lazily */
        if (!(priv->conf && priv->account_mgr && priv->account_store &&
-             priv->cache_mgr && priv->mail_op_queue)) {
+             priv->cache_mgr && priv->mail_op_queue && priv->device && priv->platform_fact)) {
                g_printerr ("modest: failed to create singletons instance\n");
                g_object_unref (G_OBJECT(self));
                self = NULL;
@@ -234,7 +262,6 @@ modest_singletons_get_cache_mgr (ModestSingletons *self)
        return MODEST_SINGLETONS_GET_PRIVATE(self)->cache_mgr;
 }
 
-
 ModestMailOperationQueue*
 modest_singletons_get_mail_operation_queue (ModestSingletons *self)
 {
@@ -243,20 +270,19 @@ modest_singletons_get_mail_operation_queue (ModestSingletons *self)
 }
 
 
-ModestWidgetFactory*
-modest_singletons_get_widget_factory (ModestSingletons *self)
-{
-       ModestSingletonsPrivate *priv;
 
+TnyDevice*
+modest_singletons_get_device (ModestSingletons *self)
+{
        g_return_val_if_fail (self, NULL);
+       return MODEST_SINGLETONS_GET_PRIVATE(self)->device;
+}
 
-       priv = MODEST_SINGLETONS_GET_PRIVATE(self);
 
-       if (G_UNLIKELY(!priv->widget_factory))  
-               priv->widget_factory = modest_widget_factory_new (priv->account_store);
-       if (G_UNLIKELY(!priv->widget_factory)) {
-               g_printerr ("modest: cannot create modest widget factory instance\n");
-               return NULL;
-       }
-       return priv->widget_factory;
+
+TnyPlatformFactory*
+modest_singletons_get_platform_factory (ModestSingletons *self)
+{
+       g_return_val_if_fail (self, NULL);
+       return MODEST_SINGLETONS_GET_PRIVATE(self)->platform_fact;
 }