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