X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-singletons.c;h=045ff090bc835d135fdffa1d3cdd012f9070af65;hp=3084cbd6667215bf6314ae7fb2085c6daf963f5c;hb=c62c3e27d371549d19265e01bd78194a2926dc21;hpb=0e1d967636205d5317d8cff2f8de52f22fe0647a diff --git a/src/modest-singletons.c b/src/modest-singletons.c index 3084cbd..045ff09 100644 --- a/src/modest-singletons.c +++ b/src/modest-singletons.c @@ -29,7 +29,14 @@ #include "modest-singletons.h" #include "modest-runtime.h" +#include "modest-defs.h" #include "modest-debug.h" +#ifdef MODEST_TOOLKIT_HILDON2 +#include "hildon2/modest-hildon2-window-mgr.h" +#else +#include "widgets/modest-hildon1-window-mgr.h" +#endif +#include /* 'private'/'protected' functions */ static void modest_singletons_class_init (ModestSingletonsClass *klass); @@ -46,6 +53,10 @@ struct _ModestSingletonsPrivate { TnyPlatformFactory *platform_fact; TnyDevice *device; ModestWindowMgr *window_mgr; + ModestProtocolRegistry *protocol_registry; + ModestPluginFactory *plugin_factory; + ModestToolkitFactory *toolkit_factory; + TnyStreamCache *images_cache; }; #define MODEST_SINGLETONS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ MODEST_TYPE_SINGLETONS, \ @@ -93,6 +104,7 @@ static void modest_singletons_init (ModestSingletons *obj) { ModestSingletonsPrivate *priv; + gchar *images_cache_path; priv = MODEST_SINGLETONS_GET_PRIVATE(obj); priv->conf = NULL; @@ -103,6 +115,17 @@ modest_singletons_init (ModestSingletons *obj) priv->platform_fact = NULL; priv->device = NULL; priv->window_mgr = NULL; + priv->protocol_registry = NULL; + priv->plugin_factory = NULL; + priv->toolkit_factory = NULL; + + priv->protocol_registry = modest_protocol_registry_new (); + if (!priv->protocol_registry) { + g_printerr ("modest:cannot create protocol registry instance\n"); + return; + } + modest_protocol_registry_set_to_default (priv->protocol_registry); + priv->images_cache = NULL; priv->conf = modest_conf_new (); if (!priv->conf) { @@ -128,6 +151,12 @@ modest_singletons_init (ModestSingletons *obj) return; } + priv->toolkit_factory = modest_toolkit_factory_get_instance (); + if (!priv->toolkit_factory) { + g_printerr ("modest: cannot create toolkit 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"); @@ -146,11 +175,30 @@ modest_singletons_init (ModestSingletons *obj) return; } - priv->window_mgr = modest_window_mgr_new (); +#if MODEST_TOOLKIT_HILDON2 + priv->window_mgr = modest_hildon2_window_mgr_new (); +#else + priv->window_mgr = modest_hildon1_window_mgr_new (); +#endif if (!priv->window_mgr) { g_printerr ("modest: cannot create modest window manager instance\n"); return; } + + priv->plugin_factory = modest_plugin_factory_new (); + if (!priv->plugin_factory) { + g_printerr ("modest: cannot create modest mail plugin factory instance\n"); + return; + } + + images_cache_path = g_build_filename (g_get_home_dir (), MODEST_DIR, MODEST_IMAGES_CACHE_DIR, NULL); + priv->images_cache = tny_fs_stream_cache_new (images_cache_path, MODEST_IMAGES_CACHE_SIZE); + g_free (images_cache_path); + if (!priv->images_cache) { + g_printerr ("modest: cannot create images cache instance\n"); + return; + } + } static void @@ -159,6 +207,12 @@ modest_singletons_finalize (GObject *obj) ModestSingletonsPrivate *priv; priv = MODEST_SINGLETONS_GET_PRIVATE(obj); + + if (priv->images_cache) { + MODEST_DEBUG_VERIFY_OBJECT_LAST_REF (priv->images_cache, ""); + g_object_unref (G_OBJECT (priv->images_cache)); + priv->images_cache = NULL; + } if (priv->window_mgr) { MODEST_DEBUG_VERIFY_OBJECT_LAST_REF(priv->window_mgr,""); @@ -196,6 +250,18 @@ modest_singletons_finalize (GObject *obj) priv->email_clipboard = NULL; } + if (priv->protocol_registry) { + MODEST_DEBUG_VERIFY_OBJECT_LAST_REF(priv->protocol_registry,""); + g_object_unref (G_OBJECT(priv->protocol_registry)); + priv->protocol_registry = NULL; + } + + if (priv->plugin_factory) { + MODEST_DEBUG_VERIFY_OBJECT_LAST_REF(priv->plugin_factory,""); + g_object_unref (G_OBJECT(priv->plugin_factory)); + priv->plugin_factory = NULL; + } + /* It is important that the account manager is uninitialized after * the mail op queue is uninitialized because the mail op queue * cancells any mail operations which in turn access the account @@ -234,7 +300,8 @@ modest_singletons_new (void) /* widget_factory will still be NULL, as it is initialized lazily */ if (!(priv->conf && priv->account_mgr && priv->email_clipboard && - priv->cache_mgr && priv->mail_op_queue && priv->device && priv->platform_fact)) { + priv->cache_mgr && priv->mail_op_queue && priv->device && + priv->platform_fact && priv->plugin_factory)) { g_printerr ("modest: failed to create singletons object\n"); g_object_unref (G_OBJECT(self)); self = NULL; @@ -295,9 +362,38 @@ modest_singletons_get_platform_factory (ModestSingletons *self) return MODEST_SINGLETONS_GET_PRIVATE(self)->platform_fact; } +ModestToolkitFactory* +modest_singletons_get_toolkit_factory (ModestSingletons *self) +{ + g_return_val_if_fail (self, NULL); + return MODEST_SINGLETONS_GET_PRIVATE(self)->toolkit_factory; +} + ModestWindowMgr* modest_singletons_get_window_mgr (ModestSingletons *self) { g_return_val_if_fail (self, NULL); return MODEST_SINGLETONS_GET_PRIVATE(self)->window_mgr; } + +ModestProtocolRegistry* +modest_singletons_get_protocol_registry (ModestSingletons *self) +{ + g_return_val_if_fail (self, NULL); + return MODEST_SINGLETONS_GET_PRIVATE(self)->protocol_registry; +} + +TnyStreamCache* +modest_singletons_get_images_cache (ModestSingletons *self) +{ + g_return_val_if_fail (self, NULL); + return MODEST_SINGLETONS_GET_PRIVATE(self)->images_cache; +} + +ModestPluginFactory * +modest_singletons_get_plugin_factory (ModestSingletons *self) +{ + g_return_val_if_fail (self, NULL); + + return MODEST_SINGLETONS_GET_PRIVATE (self)->plugin_factory; +}