1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <glib-object.h>
33 #include <glib/gstdio.h>
34 #include <modest-runtime.h>
35 #include <modest-runtime-priv.h>
36 #include <modest-defs.h>
37 #include <modest-singletons.h>
38 #include <widgets/modest-header-view.h>
39 #include <widgets/modest-folder-view.h>
40 #include <modest-tny-platform-factory.h>
41 #include <modest-platform.h>
42 #include <modest-widget-memory.h>
43 #include <modest-widget-memory-priv.h>
44 #include <modest-local-folder-info.h>
45 #include <modest-account-mgr.h>
46 #include <modest-account-mgr-helpers.h>
47 #include <modest-icon-names.h>
49 static ModestSingletons *_singletons = NULL;
51 // we get the account store here instead of in Singletons
52 // as it leads to various chicken & problems with initialization
53 static ModestTnyAccountStore *_account_store = NULL;
57 * private functions declared in modest-runtime-priv.h -
58 * only to be called from modest-init.c
60 /*-----------------------------------------------------------------------------*/
62 modest_runtime_init (void)
65 g_printerr ("modest: modest_runtime_init can only be run once\n");
69 _singletons = modest_singletons_new ();
71 g_printerr ("modest: failed to create singletons\n");
79 modest_runtime_uninit (void)
82 return TRUE; /* uninit maybe called if runtime_init failed */
84 g_return_val_if_fail (MODEST_IS_SINGLETONS(_singletons), FALSE);
85 modest_runtime_verify_object_last_ref(_singletons,"");
86 g_object_unref(G_OBJECT(_singletons));
90 modest_runtime_verify_object_last_ref(_account_store,"");
91 g_object_unref(G_OBJECT(_account_store));
92 _account_store = NULL;
98 /*-----------------------------------------------------------------------------*/
102 modest_runtime_get_account_mgr (void)
104 g_return_val_if_fail (_singletons, NULL);
105 return modest_singletons_get_account_mgr (_singletons);
108 ModestEmailClipboard*
109 modest_runtime_get_email_clipboard (void)
111 g_return_val_if_fail (_singletons, NULL);
112 return modest_singletons_get_email_clipboard (_singletons);
115 ModestTnyAccountStore*
116 modest_runtime_get_account_store (void)
118 // we get the account store here instead of in Singletons
119 // as it leads to various chicken & problems with initialization
120 g_return_val_if_fail (_singletons, NULL);
121 if (!_account_store) {
122 _account_store = modest_tny_account_store_new (modest_runtime_get_account_mgr(),
123 modest_runtime_get_device());
124 if (!_account_store) {
125 g_printerr ("modest: cannot create modest tny account store instance\n");
129 return _account_store;
133 modest_runtime_get_conf (void)
135 g_return_val_if_fail (_singletons, NULL);
136 return modest_singletons_get_conf (_singletons);
141 modest_runtime_get_cache_mgr (void)
143 g_return_val_if_fail (_singletons, NULL);
144 return modest_singletons_get_cache_mgr (_singletons);
148 ModestMailOperationQueue*
149 modest_runtime_get_mail_operation_queue (void)
151 g_return_val_if_fail (_singletons, NULL);
152 return modest_singletons_get_mail_operation_queue (_singletons);
158 modest_runtime_get_device (void)
160 g_return_val_if_fail (_singletons, NULL);
161 return modest_singletons_get_device (_singletons);
166 modest_runtime_get_platform_factory (void)
168 g_return_val_if_fail (_singletons, NULL);
169 return modest_singletons_get_platform_factory (_singletons);
173 modest_runtime_get_send_queue (TnyTransportAccount *account)
175 ModestCacheMgr *cache_mgr;
176 GHashTable *send_queue_cache;
177 gpointer orig_key, send_queue;
179 g_return_val_if_fail (_singletons, NULL);
180 g_return_val_if_fail (TNY_IS_TRANSPORT_ACCOUNT(account), NULL);
182 cache_mgr = modest_singletons_get_cache_mgr (_singletons);
183 send_queue_cache = modest_cache_mgr_get_cache (cache_mgr,
184 MODEST_CACHE_MGR_CACHE_TYPE_SEND_QUEUE);
186 /* Each modest account has its own send queue.
187 * Note that each modest account will have its own outbox folder,
188 * returned by TnySendQueue::get_outbox_func().
190 if (!g_hash_table_lookup_extended (send_queue_cache, account, &orig_key, &send_queue)) {
191 /* Note that this send queue will start sending messages from its outbox
192 * as soon as it is instantiated: */
193 send_queue = (gpointer)modest_tny_send_queue_new (TNY_CAMEL_TRANSPORT_ACCOUNT(account));
195 g_hash_table_insert (send_queue_cache, account, send_queue);
196 g_object_ref (send_queue);
199 return MODEST_TNY_SEND_QUEUE(send_queue);
202 void modest_runtime_remove_all_send_queues ()
204 ModestCacheMgr *cache_mgr = modest_singletons_get_cache_mgr (_singletons);
206 modest_cache_mgr_flush (cache_mgr, MODEST_CACHE_MGR_CACHE_TYPE_SEND_QUEUE);
210 modest_runtime_get_window_mgr (void)
212 g_return_val_if_fail (_singletons, NULL);
213 return modest_singletons_get_window_mgr (_singletons);
216 /* http://primates.ximian.com/~federico/news-2006-04.html#memory-debugging-infrastructure*/
217 ModestRuntimeDebugFlags
218 modest_runtime_get_debug_flags ()
220 static const GDebugKey debug_keys[] = {
221 { "abort-on-warning", MODEST_RUNTIME_DEBUG_ABORT_ON_WARNING },
222 { "log-actions", MODEST_RUNTIME_DEBUG_LOG_ACTIONS },
223 { "debug-objects", MODEST_RUNTIME_DEBUG_DEBUG_OBJECTS },
224 { "debug-signals", MODEST_RUNTIME_DEBUG_DEBUG_SIGNALS },
225 { "factory-settings", MODEST_RUNTIME_DEBUG_FACTORY_SETTINGS}
228 static ModestRuntimeDebugFlags debug_flags = -1;
230 if (debug_flags != -1)
233 str = g_getenv (MODEST_DEBUG);
236 debug_flags = g_parse_debug_string (str, debug_keys, G_N_ELEMENTS (debug_keys));