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