* Added the proper icon to each window
[modest] / src / modest-runtime.c
1 /* Copyright (c) 2006, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
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.
16  *
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.
28  */
29
30 #include <config.h>
31 #include <glib.h>
32 #include <glib-object.h>
33 #include <glib/gstdio.h>
34 #include <modest-runtime.h>
35 #include <modest-defs.h>
36 #include <modest-singletons.h>
37 #include <widgets/modest-header-view.h>
38 #include <widgets/modest-folder-view.h>
39 #include <modest-tny-platform-factory.h>
40 #include <modest-platform.h>
41 #include <modest-widget-memory.h>
42 #include <modest-widget-memory-priv.h>
43 #include <modest-local-folder-info.h>
44 #include <modest-account-mgr.h>
45 #include <modest-account-mgr-helpers.h>
46 #include <modest-icon-names.h>
47
48 static gboolean init_header_columns (ModestConf *conf, gboolean overwrite);
49 static gboolean init_local_folders  (void);
50 static gboolean init_default_account_maybe  (ModestAccountMgr *acc_mgr);
51 static void     init_i18n (void);
52 static void     init_stock_icons (void);
53 static void     init_debug_g_type (void);
54 static void     init_debug_logging (void);
55 static void     init_test_accounts (ModestAccountMgr *acc_mgr);
56 static void     init_default_settings (ModestConf *conf);
57
58
59 static ModestSingletons *_singletons = NULL;
60
61
62 /*
63  * defaults for the column headers
64  */
65 typedef struct {
66         ModestHeaderViewColumn col;
67         guint                  width;
68 } FolderCols;
69
70 static const FolderCols INBOX_COLUMNS_DETAILS[] = {
71         {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 40},
72         {MODEST_HEADER_VIEW_COLUMN_ATTACH,  40},
73         {MODEST_HEADER_VIEW_COLUMN_FROM,    80},
74         {MODEST_HEADER_VIEW_COLUMN_SUBJECT, 80},
75         {MODEST_HEADER_VIEW_COLUMN_RECEIVED_DATE, 60},
76         {MODEST_HEADER_VIEW_COLUMN_SIZE, 50}
77 };
78 static const FolderCols INBOX_COLUMNS_TWOLINES[] = {
79         {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 40},
80         {MODEST_HEADER_VIEW_COLUMN_ATTACH,  40},
81         {MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_IN, 200}
82 };
83
84 static const FolderCols OUTBOX_COLUMNS_DETAILS[] = {
85          {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 40},
86          {MODEST_HEADER_VIEW_COLUMN_ATTACH,  40},
87          {MODEST_HEADER_VIEW_COLUMN_TO,    80},
88          {MODEST_HEADER_VIEW_COLUMN_SUBJECT, 80},
89          {MODEST_HEADER_VIEW_COLUMN_SENT_DATE, 80},
90          {MODEST_HEADER_VIEW_COLUMN_SIZE, 50}
91 };
92 static const FolderCols OUTBOX_COLUMNS_TWOLINES[] = {
93          {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 40},
94          {MODEST_HEADER_VIEW_COLUMN_ATTACH,  40},
95          {MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_OUT,200},
96 };
97
98 #ifdef MODEST_PLATFORM_MAEMO
99 static const TnyFolderType LOCAL_FOLDERS[] = {
100         TNY_FOLDER_TYPE_OUTBOX,
101         TNY_FOLDER_TYPE_DRAFTS,
102         TNY_FOLDER_TYPE_SENT
103 };
104 #else
105 static const TnyFolderType LOCAL_FOLDERS[] = {
106         TNY_FOLDER_TYPE_OUTBOX,
107         TNY_FOLDER_TYPE_DRAFTS,
108         TNY_FOLDER_TYPE_SENT,
109         TNY_FOLDER_TYPE_TRASH,
110         TNY_FOLDER_TYPE_ARCHIVE 
111 };
112 #endif /* MODEST_PLATFORM_MAEMO */
113
114
115
116 gboolean
117 modest_runtime_init (void)
118 {
119         ModestSingletons *my_singletons;
120         gboolean reset;
121         
122         if (_singletons) {
123                 g_printerr ("modest: modest_runtime_init can only be called once\n");
124                 return FALSE;
125         }
126         
127         init_i18n();
128         init_debug_g_type();
129         init_debug_logging();
130
131         g_thread_init(NULL);
132         gdk_threads_init ();
133
134         /* Set application name */
135         g_set_application_name (_("FIXME Modest"));
136
137         my_singletons = modest_singletons_new ();
138         if (!my_singletons) {
139                 g_printerr ("modest: failed to initialize singletons\n");
140                 return FALSE;
141         }
142         
143         if (!modest_platform_init()) {
144                 modest_runtime_uninit ();
145                 g_printerr ("modest: failed to run platform-specific initialization\n");
146                 return FALSE;
147         }
148
149         /* based on the debug settings, we decide whether to overwrite old settings */
150         reset = modest_runtime_get_debug_flags () & MODEST_RUNTIME_DEBUG_FACTORY_SETTINGS;
151         if (!init_header_columns(modest_singletons_get_conf (my_singletons), reset)) {
152                 modest_runtime_uninit ();
153                 g_printerr ("modest: failed to init header columns\n");
154                 return FALSE;
155         }
156
157         init_default_settings (modest_singletons_get_conf (my_singletons));
158         
159         if (!init_local_folders()) {
160                 modest_runtime_uninit ();
161                 g_printerr ("modest: failed to init local folders\n");
162                 return FALSE;
163         }
164         
165         if (!init_default_account_maybe(modest_singletons_get_account_mgr (my_singletons))) {
166                 modest_runtime_uninit ();
167                 g_printerr ("modest: failed to init default account\n");
168                 return FALSE;
169         }
170
171         /* create the test accounts if the debug flag for that is set */
172         if (modest_runtime_get_debug_flags () & MODEST_RUNTIME_DEBUG_TINY_TEST_ACCOUNTS)
173                 init_test_accounts (modest_singletons_get_account_mgr (my_singletons)); 
174         
175         /* don't initialize _singletons before all the other init stuff
176          * is done; thus, using any of the singleton stuff before
177          * runtime is fully init'ed  is avoided
178          */
179         _singletons = my_singletons;
180         
181         return TRUE;
182 }
183
184
185 gboolean
186 modest_runtime_init_ui (gint argc, gchar** argv)
187 {
188         if (!gtk_init_check(&argc, &argv)) {
189                 g_printerr ("modest: failed to initialize graphical ui\n");
190                 return FALSE;
191         }
192
193         init_stock_icons ();
194         return TRUE;
195 }
196
197
198 gboolean
199 modest_runtime_uninit (void)
200 {
201         if (_singletons) {
202                 g_object_unref (G_OBJECT(_singletons));
203                 _singletons = NULL;
204         }
205         modest_runtime_verify_object_death (_singletons, "_singletons");
206         
207         return TRUE;
208 }
209
210
211 ModestAccountMgr*
212 modest_runtime_get_account_mgr   (void)
213 {
214         g_return_val_if_fail (_singletons, NULL);
215         return modest_singletons_get_account_mgr (_singletons);
216 }
217
218 ModestTnyAccountStore*
219 modest_runtime_get_account_store   (void)
220 {
221         g_return_val_if_fail (_singletons, NULL);
222         return modest_singletons_get_account_store (_singletons);
223
224 }
225
226 ModestConf*
227 modest_runtime_get_conf (void)
228 {
229         g_return_val_if_fail (_singletons, NULL);
230         return modest_singletons_get_conf (_singletons);
231 }
232
233
234 ModestCacheMgr*
235 modest_runtime_get_cache_mgr (void)
236 {
237         g_return_val_if_fail (_singletons, NULL);
238         return modest_singletons_get_cache_mgr (_singletons);
239 }
240
241
242 ModestMailOperationQueue*
243 modest_runtime_get_mail_operation_queue (void)
244 {
245         g_return_val_if_fail (_singletons, NULL);
246         return modest_singletons_get_mail_operation_queue (_singletons);
247 }
248
249
250
251 TnyDevice*
252 modest_runtime_get_device (void)
253 {
254         g_return_val_if_fail (_singletons, NULL);
255         return modest_singletons_get_device (_singletons);
256 }
257
258
259 TnyPlatformFactory*
260 modest_runtime_get_platform_factory  (void)
261 {
262         g_return_val_if_fail (_singletons, NULL);
263         return modest_singletons_get_platform_factory (_singletons);
264 }
265
266 ModestTnySendQueue*
267 modest_runtime_get_send_queue  (TnyTransportAccount *account)
268 {
269         ModestCacheMgr *cache_mgr;
270         GHashTable     *send_queue_cache;
271         gpointer       orig_key, send_queue;
272         
273         g_return_val_if_fail (_singletons, NULL);
274         g_return_val_if_fail (TNY_IS_TRANSPORT_ACCOUNT(account), NULL);
275
276         cache_mgr = modest_singletons_get_cache_mgr (_singletons);
277         send_queue_cache = modest_cache_mgr_get_cache (cache_mgr,
278                                                        MODEST_CACHE_MGR_CACHE_TYPE_SEND_QUEUE);
279
280         if (!g_hash_table_lookup_extended (send_queue_cache, account, &orig_key, &send_queue)) {
281                 send_queue = (gpointer)modest_tny_send_queue_new (TNY_CAMEL_TRANSPORT_ACCOUNT(account));
282                 g_hash_table_insert (send_queue_cache, account, send_queue);
283         }
284
285         return MODEST_TNY_SEND_QUEUE(send_queue);
286 }
287
288 ModestWindowMgr *
289 modest_runtime_get_window_mgr (void)
290 {
291         g_return_val_if_fail (_singletons, NULL);
292         return modest_singletons_get_window_mgr (_singletons);
293 }
294
295 /* http://primates.ximian.com/~federico/news-2006-04.html#memory-debugging-infrastructure*/
296 ModestRuntimeDebugFlags
297 modest_runtime_get_debug_flags ()
298 {
299         static const GDebugKey debug_keys[] = {
300                 { "abort-on-warning",   MODEST_RUNTIME_DEBUG_ABORT_ON_WARNING },
301                 { "log-actions",        MODEST_RUNTIME_DEBUG_LOG_ACTIONS },
302                 { "debug-objects",      MODEST_RUNTIME_DEBUG_DEBUG_OBJECTS },
303                 { "debug-signals",      MODEST_RUNTIME_DEBUG_DEBUG_SIGNALS },
304                 { "factory-settings",   MODEST_RUNTIME_DEBUG_FACTORY_SETTINGS},
305                 { "tiny-test-accounts", MODEST_RUNTIME_DEBUG_TINY_TEST_ACCOUNTS}
306         };
307         const gchar *str;
308         static ModestRuntimeDebugFlags debug_flags = -1;
309
310         if (debug_flags != -1)
311                 return debug_flags;
312         
313         str = g_getenv (MODEST_DEBUG);
314         
315         if (str != NULL)
316                 debug_flags = g_parse_debug_string (str, debug_keys, G_N_ELEMENTS (debug_keys));
317         else
318                 debug_flags = 0;
319         
320         return debug_flags;
321 }
322
323
324
325
326
327 /* NOTE: the exact details of this format are important, as they
328  * are also used in modest-widget-memory. FIXME: make a shared function
329  * for this with widget-memory
330  */
331 static gboolean
332 save_header_settings (ModestConf *conf, TnyFolderType type,
333                       ModestHeaderViewStyle style,  const FolderCols* cols,
334                       guint col_num, gboolean overwrite)
335 {
336         int i;
337         gchar *key;
338         GString *str;
339
340         g_return_val_if_fail (cols, FALSE);
341
342         key = _modest_widget_memory_get_keyname_with_double_type ("header-view",
343                                                                   type, style,
344                                                                   MODEST_WIDGET_MEMORY_PARAM_COLUMN_WIDTH);
345         /* if we're not in overwrite mode, only write stuff it
346          * there was nothing before */
347         if (!overwrite &&  modest_conf_key_exists(conf, key, NULL)) {
348                 g_free (key);
349                 return TRUE;
350         }
351
352         /* the format is necessarily the same as the one in modest-widget-memory */
353         str = g_string_new (NULL);
354         for (i = 0; i != col_num; ++i) 
355                 g_string_append_printf (str, "%d:%d ",
356                                         cols[i].col, cols[i].width); 
357
358         modest_conf_set_string (conf, key, str->str, NULL);
359         g_free (key);
360         g_string_free (str, TRUE);
361         
362         return TRUE;
363 }
364
365 /**
366  * modest_init_header_columns:
367  * @overwrite: write the setting, even if it already exists
368  * 
369  * will set defaults for the columns to show for folder,
370  * if there are no such settings yet (in ModestWidgetMemory)
371  * 
372  * Returns: TRUE if succeeded, FALSE in case of error
373  */
374 static gboolean
375 init_header_columns (ModestConf *conf, gboolean overwrite)
376 {
377         int folder_type;
378         
379         for (folder_type = TNY_FOLDER_TYPE_UNKNOWN;
380              folder_type <= TNY_FOLDER_TYPE_CALENDAR; ++folder_type) {          
381                 
382                 switch (folder_type) {
383                 case TNY_FOLDER_TYPE_OUTBOX:
384                 case TNY_FOLDER_TYPE_SENT:
385                 case TNY_FOLDER_TYPE_DRAFTS:
386                 save_header_settings (conf, folder_type,
387                                       MODEST_HEADER_VIEW_STYLE_DETAILS,
388                                       OUTBOX_COLUMNS_DETAILS,
389                                       G_N_ELEMENTS(OUTBOX_COLUMNS_DETAILS),
390                                       overwrite);
391                 save_header_settings (conf, folder_type,
392                                       MODEST_HEADER_VIEW_STYLE_TWOLINES,
393                                       OUTBOX_COLUMNS_TWOLINES,
394                                       G_N_ELEMENTS(OUTBOX_COLUMNS_TWOLINES),
395                                       overwrite);
396                 break;
397
398                 default:
399                 save_header_settings (conf, folder_type,
400                                       MODEST_HEADER_VIEW_STYLE_DETAILS,
401                                       INBOX_COLUMNS_DETAILS,
402                                       G_N_ELEMENTS(INBOX_COLUMNS_DETAILS),
403                                       overwrite);
404                 save_header_settings (conf, folder_type,
405                                       MODEST_HEADER_VIEW_STYLE_TWOLINES,
406                                       INBOX_COLUMNS_TWOLINES,
407                                       G_N_ELEMENTS(INBOX_COLUMNS_TWOLINES),
408                                       overwrite);
409                 };
410         }
411         return TRUE;
412 }
413
414 /**
415  * init_local_folders:
416  * 
417  * create the Local Folders folder under cache, if they
418  * do not exist yet.
419  * 
420  * Returns: TRUE if the folder were already there, or
421  * they were created, FALSE otherwise
422  */
423 static gboolean
424 init_local_folders  (void)
425 {
426         int i;
427         gchar *maildir_path;
428         static const gchar* maildirs[] = {
429                 "cur", "new", "tmp"
430         };
431         
432         maildir_path = modest_local_folder_info_get_maildir_path ();
433
434         for (i = 0; i != G_N_ELEMENTS(LOCAL_FOLDERS); ++i) {
435                 int j;
436                 for (j = 0; j != G_N_ELEMENTS(maildirs); ++j) {
437                         gchar *dir;
438                         dir = g_build_filename (maildir_path,
439                                                 modest_local_folder_info_get_type_name(LOCAL_FOLDERS[i]),
440                                                 maildirs[j],
441                                                 NULL);
442                         if (g_mkdir_with_parents (dir, 0755) < 0) {
443                                 g_printerr ("modest: failed to create %s\n", dir);
444                                 g_free (dir);
445                                 g_free (maildir_path);
446                                 return FALSE;
447                         }
448                         g_free(dir);
449                 }
450         }
451         
452         g_free (maildir_path);
453         return TRUE;
454 }
455
456
457
458 static void
459 free_element (gpointer data, gpointer user_data)
460 {
461         g_free (data);
462 }
463
464
465
466 /**
467  * init_default_account_maybe:
468  *
469  * if there are accounts defined, but there is no default account,
470  * it will be defined.
471  * 
472  * Returns: TRUE if there was a default account already,
473  *  or one has been created or there are no accounts yet,
474  *  returns FALSE in case of error
475  */
476 static gboolean
477 init_default_account_maybe  (ModestAccountMgr *acc_mgr)
478 {
479         GSList *all_accounts = NULL;
480         gchar *default_account;
481         gboolean retval = TRUE;
482         
483         all_accounts = modest_account_mgr_account_names (acc_mgr);
484         if (all_accounts) { /* if there are any accounts, there should be a default one */
485                 default_account = 
486                         modest_account_mgr_get_default_account (acc_mgr);
487                 if (!default_account) {
488                         gchar *first_account;
489                         g_printerr ("modest: no default account defined\n");
490                         first_account = (gchar*)all_accounts->data;
491                         if ((retval = modest_account_mgr_set_default_account (acc_mgr, first_account)))
492                                 g_printerr ("modest: set '%s' as the default account\n",
493                                             first_account);
494                         else
495                                 g_printerr ("modest: failed to set '%s' as the default account\n",
496                                             first_account);
497                         g_free (default_account);
498                 }
499                 g_slist_foreach (all_accounts, free_element, NULL);
500                 g_slist_free    (all_accounts);
501         }
502         return retval;
503 }
504
505
506
507 static void
508 init_debug_g_type (void)
509 {
510         GTypeDebugFlags gflags;
511         ModestRuntimeDebugFlags mflags;
512         
513         gflags = 0;
514         mflags = modest_runtime_get_debug_flags ();
515
516         if (mflags & MODEST_RUNTIME_DEBUG_DEBUG_OBJECTS)
517                 gflags |= G_TYPE_DEBUG_OBJECTS;
518         if (mflags & MODEST_RUNTIME_DEBUG_DEBUG_SIGNALS)
519                 gflags |= G_TYPE_DEBUG_SIGNALS;
520
521         g_type_init_with_debug_flags (gflags);
522 }
523
524 static void
525 init_debug_logging (void)
526 {
527         ModestRuntimeDebugFlags mflags;
528         mflags = modest_runtime_get_debug_flags ();
529         
530         if (mflags & MODEST_RUNTIME_DEBUG_ABORT_ON_WARNING)
531                 g_log_set_always_fatal (G_LOG_LEVEL_ERROR |
532                                         G_LOG_LEVEL_CRITICAL |
533                                         G_LOG_LEVEL_WARNING);
534 }
535
536
537 static void
538 init_i18n (void)
539 {
540         /* Setup gettext, to use our .po files: */
541         /* GETTEXT_PACKAGE and MODEST_LOCALE_DIR are defined in config.h */
542         bindtextdomain (GETTEXT_PACKAGE, MODEST_LOCALE_DIR);
543         bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
544         textdomain (GETTEXT_PACKAGE);
545 }
546
547
548 /* 
549  *  This function registers our custom toolbar icons, so they can be
550  *  themed. The idea of this function was taken from the gtk-demo
551  */
552 static void
553 init_stock_icons (void)
554 {
555         static gboolean registered = FALSE;
556   
557         if (!registered) {
558                 GtkIconTheme *current_theme;
559                 GdkPixbuf *pixbuf;
560                 GtkIconFactory *factory;
561                 gint i;
562
563                 static GtkStockItem items[] = {
564 #ifdef MODEST_PLATFORM_MAEMO
565                         { MODEST_STOCK_SPLIT_VIEW, "split view", 0, 0, NULL },
566                         { MODEST_STOCK_SORT, "sort mail", 0, 0, NULL },
567                         { MODEST_STOCK_REFRESH, "refresh mail", 0, 0, NULL },
568 #endif /*MODEST_PLATFORM_MAEMO*/
569                         { MODEST_STOCK_MAIL_SEND, "send mail", 0, 0, NULL },
570                         { MODEST_STOCK_NEW_MAIL, "new mail", 0, 0, NULL },
571 /*                      { MODEST_STOCK_SEND_RECEIVE, "send receive", 0, 0, NULL },  */
572                         { MODEST_STOCK_REPLY, "reply", 0, 0, NULL },
573                         { MODEST_STOCK_REPLY_ALL, "reply all", 0, 0, NULL },
574                         { MODEST_STOCK_FORWARD, "forward", 0, 0, NULL },
575                         { MODEST_STOCK_DELETE, "delete", 0, 0, NULL }, 
576 /*                      { MODEST_STOCK_NEXT, "next", 0, 0, NULL }, */
577 /*                      { MODEST_STOCK_PREV, "prev", 0, 0, NULL }, */
578 /*                      { MODEST_STOCK_STOP, "stop", 0, 0, NULL } */
579                 };
580       
581                 static gchar *items_names [] = {
582 #ifdef MODEST_PLATFORM_MAEMO
583                         MODEST_TOOLBAR_ICON_SPLIT_VIEW,
584                         MODEST_TOOLBAR_ICON_SORT,
585                         MODEST_TOOLBAR_ICON_REFRESH,
586 #endif /*MODEST_PLATFORM_MAEMO*/
587                         MODEST_TOOLBAR_ICON_MAIL_SEND,
588                         MODEST_TOOLBAR_ICON_NEW_MAIL,
589 /*                      MODEST_TOOLBAR_ICON_SEND_RECEIVE,  */
590                         MODEST_TOOLBAR_ICON_REPLY,      
591                         MODEST_TOOLBAR_ICON_REPLY_ALL,
592                         MODEST_TOOLBAR_ICON_FORWARD,
593                         MODEST_TOOLBAR_ICON_DELETE, 
594 /*                      MODEST_TOOLBAR_ICON_NEXT, */
595 /*                      MODEST_TOOLBAR_ICON_PREV, */
596 /*                      MODEST_TOOLBAR_ICON_STOP */
597                         MODEST_TOOLBAR_ICON_FORMAT_BULLETS,
598                 };
599
600                 registered = TRUE;
601
602                 /* Register our stock items */
603                 gtk_stock_add (items, G_N_ELEMENTS (items));
604       
605                 /* Add our custom icon factory to the list of defaults */
606                 factory = gtk_icon_factory_new ();
607                 gtk_icon_factory_add_default (factory);
608
609                 current_theme = gtk_icon_theme_get_default ();
610
611                 /* Register icons to accompany stock items */
612                 for (i = 0; i < G_N_ELEMENTS (items); i++) {
613
614 #ifdef MODEST_PLATFORM_MAEMO  /* MODES_PLATFORM_ID: 1 ==> gnome, 2==> maemo */ 
615                         pixbuf = gtk_icon_theme_load_icon (current_theme,
616                                                            items_names[i],
617                                                            26,
618                                                            GTK_ICON_LOOKUP_NO_SVG,
619                                                            NULL);
620 #else
621                         pixbuf = gdk_pixbuf_new_from_file (items_names[i], NULL);
622 #endif
623
624                         if (pixbuf != NULL) {
625                                 GtkIconSet *icon_set;
626                                 GdkPixbuf *transparent;
627
628                                 transparent = gdk_pixbuf_add_alpha (pixbuf, TRUE, 0xff, 0xff, 0xff);
629                                 icon_set = gtk_icon_set_new_from_pixbuf (transparent);
630                                 gtk_icon_factory_add (factory, items[i].stock_id, icon_set);
631                                 gtk_icon_set_unref (icon_set);
632                                 g_object_unref (pixbuf);
633                                 g_object_unref (transparent);
634                         }
635                         else
636                                 g_warning ("failed to load %s icon", items_names[i]);
637                 }
638                 /* Drop our reference to the factory, GTK will hold a reference. */
639                 g_object_unref (factory);
640         }
641 }
642
643
644 static void
645 init_test_accounts (ModestAccountMgr *acc_mgr)
646 {
647         const gchar *imap_test = "TnyImapTest";
648         const gchar *pop_test  = "TnyPopTest";
649         const gchar *smtp_test = "TnySmtpTest";
650
651         if (!modest_account_mgr_account_exists (acc_mgr, imap_test, FALSE)) 
652                 modest_account_mgr_add_server_account (acc_mgr,
653                                                        imap_test,
654                                                        "imap2.tinymail.org",
655                                                        "tnytest", "tnytest",
656                                                        MODEST_PROTOCOL_STORE_IMAP,
657                                                        MODEST_PROTOCOL_SECURITY_NONE,
658                                                        MODEST_PROTOCOL_AUTH_NONE);
659         if (!modest_account_mgr_account_exists (acc_mgr, pop_test, FALSE)) 
660                 modest_account_mgr_add_server_account (acc_mgr,
661                                                        pop_test,
662                                                        "imap2.tinymail.org",
663                                                        "tnytest", "tnytest",
664                                                        MODEST_PROTOCOL_STORE_POP,
665                                                        MODEST_PROTOCOL_SECURITY_NONE,
666                                                        MODEST_PROTOCOL_AUTH_NONE);
667         if (!modest_account_mgr_account_exists (acc_mgr, smtp_test, FALSE)) 
668                 modest_account_mgr_add_server_account (acc_mgr,
669                                                        smtp_test,
670                                                        "127.0.0.1",
671                                                        NULL,NULL,
672                                                        MODEST_PROTOCOL_TRANSPORT_SMTP,
673                                                        MODEST_PROTOCOL_SECURITY_NONE,
674                                                        MODEST_PROTOCOL_AUTH_NONE);
675         
676         modest_account_mgr_add_account (acc_mgr, imap_test, imap_test, smtp_test);
677         modest_account_mgr_add_account (acc_mgr,  pop_test, pop_test,  smtp_test);
678 }
679
680
681 static void
682 init_default_settings (ModestConf *conf)
683 {
684         if (!modest_conf_key_exists (conf, MODEST_CONF_SHOW_TOOLBAR, NULL))
685                 modest_conf_set_bool (conf, MODEST_CONF_SHOW_TOOLBAR, TRUE, NULL);
686         
687         if (!modest_conf_key_exists (conf, MODEST_CONF_SHOW_CC, NULL))
688                 modest_conf_set_bool (conf, MODEST_CONF_SHOW_CC, TRUE, NULL);
689
690         if (!modest_conf_key_exists (conf, MODEST_CONF_SHOW_BCC, NULL))
691                 modest_conf_set_bool (conf, MODEST_CONF_SHOW_BCC, FALSE, NULL);
692
693         if (!modest_conf_key_exists (conf, MODEST_CONF_CONNECT_AT_STARTUP, NULL))
694                 modest_conf_set_bool (conf, MODEST_CONF_CONNECT_AT_STARTUP, TRUE, NULL);
695
696 }