X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-runtime.c;h=890b8db74ae31c8226ce05048881829638afbaea;hp=3d3843c4fc143cbe5739de8b82e754f79c293a33;hb=e374da56f67092cecb1572dd4bee2ca34e0bc04c;hpb=0fb332b6dc8b4e67b7f13ab60563a4205b2be743 diff --git a/src/modest-runtime.c b/src/modest-runtime.c index 3d3843c..890b8db 100644 --- a/src/modest-runtime.c +++ b/src/modest-runtime.c @@ -69,13 +69,13 @@ modest_runtime_init (void) g_printerr ("modest: modest_runtime_init can only be run once\n"); return FALSE; } - + _singletons = modest_singletons_new (); if (!_singletons) { g_printerr ("modest: failed to create singletons\n"); return FALSE; } - + return TRUE; } @@ -86,22 +86,33 @@ modest_runtime_uninit (void) return TRUE; /* uninit maybe called if runtime_init failed */ g_return_val_if_fail (MODEST_IS_SINGLETONS(_singletons), FALSE); - + + g_debug ("%s: cleaning up", __FUNCTION__); + + if (_sig_handlers) { + modest_signal_mgr_disconnect_all_and_destroy (_sig_handlers); + _sig_handlers = NULL; + } + + g_debug ("%s: cleaned up signal manager", __FUNCTION__); + + MODEST_DEBUG_VERIFY_OBJECT_LAST_REF(_singletons,""); + g_object_unref(_singletons); + _singletons = NULL; + + g_debug ("%s: cleaned up singletons", __FUNCTION__); + if (_account_store) { MODEST_DEBUG_VERIFY_OBJECT_LAST_REF(_account_store,""); g_object_unref(_account_store); _account_store = NULL; } - - MODEST_DEBUG_VERIFY_OBJECT_LAST_REF(_singletons,""); - g_object_unref(_singletons); - _singletons = NULL; + + g_debug ("%s: cleaned up the account store", __FUNCTION__); - if (_sig_handlers) { - modest_signal_mgr_disconnect_all_and_destroy (_sig_handlers); - _sig_handlers = NULL; - } + g_debug ("%s: all cleaned up", __FUNCTION__); + return TRUE; } @@ -115,6 +126,13 @@ modest_runtime_get_account_mgr (void) return modest_singletons_get_account_mgr (_singletons); } +TnyStreamCache* +modest_runtime_get_images_cache (void) +{ + g_return_val_if_fail (_singletons, NULL); + return modest_singletons_get_images_cache (_singletons); +} + ModestEmailClipboard* modest_runtime_get_email_clipboard (void) { @@ -125,9 +143,10 @@ modest_runtime_get_email_clipboard (void) ModestTnyAccountStore* modest_runtime_get_account_store (void) { - // we get the account store here instead of in Singletons - // as it leads to various chicken & problems with initialization - g_return_val_if_fail (_singletons, NULL); + g_return_val_if_fail (_singletons, NULL); + /* we get the account store here instead of in Singletons as + it leads to various chicken & egg problems with + initialization */ if (!_account_store) { _account_store = modest_tny_account_store_new (modest_runtime_get_account_mgr(), modest_runtime_get_device()); @@ -180,11 +199,12 @@ modest_runtime_get_platform_factory (void) } ModestTnySendQueue* -modest_runtime_get_send_queue (TnyTransportAccount *account) +modest_runtime_get_send_queue (TnyTransportAccount *account, + gboolean create) { ModestCacheMgr *cache_mgr; GHashTable *send_queue_cache; - gpointer orig_key, send_queue; + gpointer orig_key = NULL, send_queue = NULL; g_return_val_if_fail (_singletons, NULL); g_return_val_if_fail (TNY_IS_TRANSPORT_ACCOUNT(account), NULL); @@ -197,32 +217,34 @@ modest_runtime_get_send_queue (TnyTransportAccount *account) * Note that each modest account will have its own outbox folder, * returned by TnySendQueue::get_outbox_func(). */ - if (!g_hash_table_lookup_extended (send_queue_cache, account, &orig_key, &send_queue)) { + if (!g_hash_table_lookup_extended (send_queue_cache, account, &orig_key, &send_queue) && + create) { /* Note that this send queue will start sending messages from its outbox * as soon as it is instantiated: */ - send_queue = (gpointer)modest_tny_send_queue_new (TNY_CAMEL_TRANSPORT_ACCOUNT(account)); - - _sig_handlers = - modest_signal_mgr_connect (_sig_handlers, - send_queue, - "error_happened", - G_CALLBACK (modest_ui_actions_on_send_queue_error_happened), - NULL); - - _sig_handlers = - modest_signal_mgr_connect (_sig_handlers, - send_queue, - "status_changed", - G_CALLBACK (modest_ui_actions_on_send_queue_status_changed), - NULL); - - - g_hash_table_insert (send_queue_cache, - g_object_ref (account), - g_object_ref (send_queue)); + send_queue = modest_tny_send_queue_new (TNY_CAMEL_TRANSPORT_ACCOUNT(account)); + + if (send_queue) { + _sig_handlers = + modest_signal_mgr_connect (_sig_handlers, + send_queue, + "error_happened", + G_CALLBACK (modest_ui_actions_on_send_queue_error_happened), + NULL); + + _sig_handlers = + modest_signal_mgr_connect (_sig_handlers, + send_queue, + "status_changed", + G_CALLBACK (modest_ui_actions_on_send_queue_status_changed), + NULL); + + g_hash_table_insert (send_queue_cache, + g_object_ref (account), + send_queue); + } } - return MODEST_TNY_SEND_QUEUE(send_queue); + return (send_queue) ? MODEST_TNY_SEND_QUEUE(send_queue) : NULL; } void modest_runtime_remove_all_send_queues () @@ -232,6 +254,24 @@ void modest_runtime_remove_all_send_queues () modest_cache_mgr_flush (cache_mgr, MODEST_CACHE_MGR_CACHE_TYPE_SEND_QUEUE); } +void +modest_runtime_remove_send_queue (TnyTransportAccount *account) +{ + + ModestCacheMgr *cache_mgr; + GHashTable *send_queue_cache; + + g_return_if_fail (TNY_IS_TRANSPORT_ACCOUNT (account)); + g_return_if_fail (_singletons); + + cache_mgr = modest_singletons_get_cache_mgr (_singletons); + send_queue_cache = modest_cache_mgr_get_cache (cache_mgr, + MODEST_CACHE_MGR_CACHE_TYPE_SEND_QUEUE); + + if (g_hash_table_lookup (send_queue_cache, account)) + g_hash_table_remove (send_queue_cache, account); +} + ModestWindowMgr * modest_runtime_get_window_mgr (void) { @@ -239,6 +279,20 @@ modest_runtime_get_window_mgr (void) return modest_singletons_get_window_mgr (_singletons); } +ModestPluginFactory * +modest_runtime_get_plugin_factory (void) +{ + g_return_val_if_fail (_singletons, NULL); + return modest_singletons_get_plugin_factory (_singletons); +} + +ModestProtocolRegistry * +modest_runtime_get_protocol_registry (void) +{ + g_return_val_if_fail (_singletons, NULL); + return modest_singletons_get_protocol_registry (_singletons); +} + /* http://primates.ximian.com/~federico/news-2006-04.html#memory-debugging-infrastructure*/ ModestRuntimeDebugFlags modest_runtime_get_debug_flags ()