ace733ab6c59f9d8f6fad0014be9e08b70ba2f5e
[modest] / src / modest-init.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-runtime-priv.h>
36 #include <modest-init.h>
37 #include <modest-defs.h>
38 #include <modest-singletons.h>
39 #include <widgets/modest-header-view.h>
40 #include <widgets/modest-folder-view.h>
41 #include <modest-tny-platform-factory.h>
42 #include <modest-platform.h>
43 #include <modest-widget-memory.h>
44 #include <modest-widget-memory-priv.h>
45 #include <modest-local-folder-info.h>
46 #include <modest-account-mgr.h>
47 #include <modest-account-mgr-helpers.h>
48 #include <modest-icon-names.h>
49 #include "widgets/modest-global-settings-dialog.h"
50 #include "modest-tny-msg.h"
51
52 static gboolean init_header_columns (ModestConf *conf, gboolean overwrite);
53 static gboolean init_default_account_maybe  (ModestAccountMgr *acc_mgr);
54 static void     init_i18n (void);
55 static void     init_stock_icons (void);
56 static void     init_debug_g_type (void);
57 static void     init_debug_logging (void);
58 static void     init_default_settings (ModestConf *conf);
59 static void     init_device_name (ModestConf *conf);
60
61 /*
62  * defaults for the column headers
63  */
64 typedef struct {
65         ModestHeaderViewColumn col;
66         guint                  width;
67         gint                  sort;
68 } FolderCols;
69
70 static const FolderCols INBOX_COLUMNS_DETAILS[] = {
71         {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 40, 0},
72         {MODEST_HEADER_VIEW_COLUMN_ATTACH,  40, 0},
73         {MODEST_HEADER_VIEW_COLUMN_FROM,    80, 0},
74         {MODEST_HEADER_VIEW_COLUMN_SUBJECT, 80, 0},
75         {MODEST_HEADER_VIEW_COLUMN_RECEIVED_DATE, 60, 0},
76         {MODEST_HEADER_VIEW_COLUMN_SIZE, 50, 0}
77 };
78
79 static const FolderCols INBOX_COLUMNS_TWOLINES[] = {
80         {MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_IN, 180, 0},
81 };
82
83 static const FolderCols OUTBOX_COLUMNS_DETAILS[] = {
84         {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 40, 0},
85         {MODEST_HEADER_VIEW_COLUMN_ATTACH,  40, 0},
86         {MODEST_HEADER_VIEW_COLUMN_TO,    80, 0},
87         {MODEST_HEADER_VIEW_COLUMN_SUBJECT, 80, 0},
88         {MODEST_HEADER_VIEW_COLUMN_SENT_DATE, 80, 0},
89         {MODEST_HEADER_VIEW_COLUMN_SIZE, 50, 0}
90 };
91
92 static const FolderCols OUTBOX_COLUMNS_TWOLINES[] = {
93         {MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_OUT,180, 0},
94         {MODEST_HEADER_VIEW_COLUMN_STATUS, 240, 0}
95 };
96
97 static const FolderCols SENT_COLUMNS_TWOLINES[] = {
98         {MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_OUT,180, 0},
99 };
100
101 #ifdef MODEST_PLATFORM_MAEMO
102 static const TnyFolderType LOCAL_FOLDERS[] = {
103 /*      TNY_FOLDER_TYPE_OUTBOX, */
104         TNY_FOLDER_TYPE_DRAFTS,
105         TNY_FOLDER_TYPE_SENT
106 };
107 #else
108 static const TnyFolderType LOCAL_FOLDERS[] = {
109 /*      TNY_FOLDER_TYPE_OUTBOX, */
110         TNY_FOLDER_TYPE_DRAFTS,
111         TNY_FOLDER_TYPE_SENT,
112         TNY_FOLDER_TYPE_TRASH,
113         TNY_FOLDER_TYPE_ARCHIVE 
114 };
115 #endif /* MODEST_PLATFORM_MAEMO */
116
117
118 gboolean
119 modest_init_init_core (void)
120 {
121         gboolean reset;
122         static gboolean invoked = FALSE;
123
124         if (invoked) {
125                 g_printerr ("modest: modest_init_init_core may only be invoked once\n");
126                 g_assert (!invoked); /* abort */
127                 return FALSE;
128         } else
129                 invoked = TRUE;
130         
131         init_i18n();
132         init_debug_g_type();
133         init_debug_logging();
134
135         if (!g_thread_supported())
136                 g_thread_init(NULL);
137         
138         gdk_threads_init ();
139         
140         if (!modest_runtime_init()) {
141                 modest_init_uninit ();
142                 g_printerr ("modest: failed to initialize the modest runtime\n");
143                 return FALSE;
144         }
145
146
147         /* do an initial guess for the device name */
148         init_device_name (modest_runtime_get_conf());
149
150         if (!modest_platform_init()) {
151                 modest_init_uninit ();
152                 g_printerr ("modest: failed to run platform-specific initialization\n");
153                 return FALSE;
154         }
155
156         /* based on the debug settings, we decide whether to overwrite old settings */
157         reset = modest_runtime_get_debug_flags () & MODEST_RUNTIME_DEBUG_FACTORY_SETTINGS;
158         if (!init_header_columns(modest_runtime_get_conf(), reset)) {
159                 modest_init_uninit ();
160                 g_printerr ("modest: failed to init header columns\n");
161                 return FALSE;
162         }
163
164         init_default_settings (modest_runtime_get_conf ());
165         
166         if (!modest_init_local_folders(NULL /* means $HOME */)) {
167                 modest_init_uninit ();
168                 g_printerr ("modest: failed to init local folders\n");
169                 return FALSE;
170         }
171         
172         if (!init_default_account_maybe(modest_runtime_get_account_mgr ())) {
173                 modest_init_uninit ();
174                 g_printerr ("modest: failed to init default account\n");
175                 return FALSE;
176         }
177         
178         return TRUE;
179 }
180
181
182 gboolean
183 modest_init_init_ui (gint argc, gchar** argv)
184 {
185         if (!gtk_init_check(&argc, &argv)) {
186                 g_printerr ("modest: failed to initialize graphical ui\n");
187                 return FALSE;
188         }
189
190         /* Set application name */
191         g_set_application_name (modest_platform_get_app_name());
192         /* g_message (modest_platform_get_app_name()); */
193
194         init_stock_icons ();
195         return TRUE;
196 }
197
198
199 gboolean
200 modest_init_uninit (void)
201 {
202         if (!modest_runtime_uninit())
203                 g_printerr ("modest: failed to uninit runtime\n");
204                 
205         return TRUE;
206 }
207
208
209
210
211 /* NOTE: the exact details of this format are important, as they
212  * are also used in modest-widget-memory. FIXME: make a shared function
213  * for this with widget-memory
214  */
215 static gboolean
216 save_header_settings (ModestConf *conf, TnyFolderType type,
217                       ModestHeaderViewStyle style,  const FolderCols* cols,
218                       guint col_num, gboolean overwrite)
219 {
220         int i;
221         gchar *key;
222         GString *str;
223
224         g_return_val_if_fail (cols, FALSE);
225
226         key = _modest_widget_memory_get_keyname_with_double_type ("header-view",
227                                                                   type, style,
228                                                                   MODEST_WIDGET_MEMORY_PARAM_COLUMN_WIDTH);
229         /* if we're not in overwrite mode, only write stuff it
230          * there was nothing before */
231         if (!overwrite &&  modest_conf_key_exists(conf, key, NULL)) {
232                 g_free (key);
233                 return TRUE;
234         }
235
236         /* the format is necessarily the same as the one in modest-widget-memory */
237         str = g_string_new (NULL);
238         for (i = 0; i != col_num; ++i) 
239                 g_string_append_printf (str, "%d:%d:%d ",
240                                         cols[i].col, cols[i].width, cols[i].sort); 
241
242         modest_conf_set_string (conf, key, str->str, NULL);
243         g_free (key);
244         g_string_free (str, TRUE);
245         
246         return TRUE;
247 }
248
249 /**
250  * modest_init_header_columns:
251  * @overwrite: write the setting, even if it already exists
252  * 
253  * will set defaults for the columns to show for folder,
254  * if there are no such settings yet (in ModestWidgetMemory)
255  * 
256  * Returns: TRUE if succeeded, FALSE in case of error
257  */
258 static gboolean
259 init_header_columns (ModestConf *conf, gboolean overwrite)
260 {
261         int folder_type;
262         
263         for (folder_type = TNY_FOLDER_TYPE_UNKNOWN;
264              folder_type <= TNY_FOLDER_TYPE_CALENDAR; ++folder_type) {          
265                 
266                 switch (folder_type) {
267                 case TNY_FOLDER_TYPE_SENT:
268                 case TNY_FOLDER_TYPE_DRAFTS:
269                 save_header_settings (conf, folder_type,
270                                       MODEST_HEADER_VIEW_STYLE_DETAILS,
271                                       OUTBOX_COLUMNS_DETAILS,
272                                       G_N_ELEMENTS(OUTBOX_COLUMNS_DETAILS),
273                                       overwrite);
274                 save_header_settings (conf, folder_type,
275                                       MODEST_HEADER_VIEW_STYLE_TWOLINES,
276                                       SENT_COLUMNS_TWOLINES,
277                                       G_N_ELEMENTS(SENT_COLUMNS_TWOLINES),
278                                       overwrite);
279                 break;
280                 case TNY_FOLDER_TYPE_OUTBOX:
281                 save_header_settings (conf, folder_type,
282                                       MODEST_HEADER_VIEW_STYLE_TWOLINES,
283                                       OUTBOX_COLUMNS_TWOLINES,
284                                       G_N_ELEMENTS(OUTBOX_COLUMNS_TWOLINES),
285                                       overwrite);
286                 break;
287
288                 default:
289                 save_header_settings (conf, folder_type,
290                                       MODEST_HEADER_VIEW_STYLE_DETAILS,
291                                       INBOX_COLUMNS_DETAILS,
292                                       G_N_ELEMENTS(INBOX_COLUMNS_DETAILS),
293                                       overwrite);
294                 save_header_settings (conf, folder_type,
295                                       MODEST_HEADER_VIEW_STYLE_TWOLINES,
296                                       INBOX_COLUMNS_TWOLINES,
297                                       G_N_ELEMENTS(INBOX_COLUMNS_TWOLINES),
298                                       overwrite);
299                 };
300         }
301         return TRUE;
302 }
303
304 gboolean modest_init_one_local_folder (gchar *maildir_path)
305 {
306         static const gchar* maildirs[] = {
307                 "cur", "new", "tmp"
308         };
309         
310         int j;
311         for (j = 0; j != G_N_ELEMENTS(maildirs); ++j) {
312                 gchar *dir = g_build_filename (maildir_path,
313                                         maildirs[j],
314                                         NULL);
315                 if (g_mkdir_with_parents (dir, 0755) < 0) {
316                         g_printerr ("modest: failed to create %s\n", dir);
317                         g_free (dir);
318                         return FALSE;
319                 }
320                 
321                 g_free (dir);
322         }
323
324         return TRUE;
325 }
326
327 /**
328  * modest_init_local_folders:
329  * @location_filepath: The location at which the local-folders directory should be created, 
330  * or NULL to specify $HOME.
331  * 
332  * create the Local Folders folder under cache, if they
333  * do not exist yet.
334  * 
335  * Returns: TRUE if the folder were already there, or
336  * they were created, FALSE otherwise
337  */
338 gboolean
339 modest_init_local_folders  (const gchar* location_filepath)
340 {       
341         gchar *maildir_path = modest_local_folder_info_get_maildir_path (location_filepath);
342
343         /* Create each of the standard on-disk folders.
344          * Per-account outbox folders will be created when first needed. */
345         int i;
346         for (i = 0; i != G_N_ELEMENTS(LOCAL_FOLDERS); ++i) {
347                 gchar *dir = g_build_filename (maildir_path,
348                                                 modest_local_folder_info_get_type_name(LOCAL_FOLDERS[i]),
349                                                 NULL);                  
350                 const gboolean created = modest_init_one_local_folder (dir);
351                 g_free(dir);
352                 
353                 if (!created) {
354                         g_free (maildir_path);
355                         return FALSE;
356                 }
357         }
358         
359         g_free (maildir_path);
360         return TRUE;
361 }
362
363
364
365 static void
366 free_element (gpointer data, gpointer user_data)
367 {
368         g_free (data);
369 }
370
371
372 /* TODO: This is a duplicate of modest_account_mgr_set_first_account_as_default(). */
373 /**
374  * init_default_account_maybe:
375  *
376  * if there are accounts defined, but there is no default account,
377  * it will be defined.
378  * 
379  * Returns: TRUE if there was a default account already,
380  *  or one has been created or there are no accounts yet,
381  *  returns FALSE in case of error
382  */
383 static gboolean
384 init_default_account_maybe  (ModestAccountMgr *acc_mgr)
385 {
386         GSList *all_accounts = NULL;
387         gchar *default_account;
388         gboolean retval = TRUE;
389         
390         all_accounts = modest_account_mgr_account_names (acc_mgr, TRUE /* enabled accounts only */);
391         if (all_accounts) { /* if there are any accounts, there should be a default one */
392                 default_account = 
393                         modest_account_mgr_get_default_account (acc_mgr);
394                 if (!default_account) {
395                         gchar *first_account;
396                         g_printerr ("modest: no default account defined\n");
397                         first_account = (gchar*)all_accounts->data;
398                         if ((retval = modest_account_mgr_set_default_account (acc_mgr, first_account)))
399                                 g_printerr ("modest: set '%s' as the default account\n",
400                                             first_account);
401                         else
402                                 g_printerr ("modest: failed to set '%s' as the default account\n",
403                                             first_account);
404                         g_free (default_account);
405                 }
406                 g_slist_foreach (all_accounts, free_element, NULL);
407                 g_slist_free    (all_accounts);
408         }
409         return retval;
410 }
411
412
413
414 static void
415 init_debug_g_type (void)
416 {
417         GTypeDebugFlags gflags;
418         ModestRuntimeDebugFlags mflags;
419         
420         gflags = 0;
421         mflags = modest_runtime_get_debug_flags ();
422
423         if (mflags & MODEST_RUNTIME_DEBUG_DEBUG_OBJECTS)
424                 gflags |= G_TYPE_DEBUG_OBJECTS;
425         if (mflags & MODEST_RUNTIME_DEBUG_DEBUG_SIGNALS)
426                 gflags |= G_TYPE_DEBUG_SIGNALS;
427
428         g_type_init_with_debug_flags (gflags);
429 }
430
431 static void
432 init_debug_logging (void)
433 {
434         ModestRuntimeDebugFlags mflags;
435         mflags = modest_runtime_get_debug_flags ();
436         
437         if (mflags & MODEST_RUNTIME_DEBUG_ABORT_ON_WARNING)
438                 g_log_set_always_fatal (G_LOG_LEVEL_ERROR |
439                                         G_LOG_LEVEL_CRITICAL |
440                                         G_LOG_LEVEL_WARNING);
441 }
442
443
444 static void
445 init_i18n (void)
446 {
447         const gchar* gettext_package;
448         /* Setup gettext, to use our .po files: */
449         /* GETTEXT_PACKAGE and MODEST_LOCALE_DIR are defined in config.h */
450 #ifdef MODEST_HILDON_VERSION_0
451         gettext_package = GETTEXT_PACKAGE;
452         bindtextdomain (gettext_package, MODEST_LOCALE_DIR);
453 #else
454         gettext_package = "osso-email"; /* HACK to use the localizations */
455         bindtextdomain (gettext_package, "/usr/share/locale");
456 #endif /*MODEST_HILDON_VERSION_0*/
457         
458         bind_textdomain_codeset (gettext_package, "UTF-8");
459         textdomain (gettext_package);
460 }
461
462
463 /* 
464  *  This function registers our custom toolbar icons, so they can be
465  *  themed. The idea of this function was taken from the gtk-demo
466  */
467 static void
468 init_stock_icons (void)
469 {
470         static gboolean registered = FALSE;
471   
472         if (!registered) {
473                 GtkIconTheme *current_theme;
474                 GdkPixbuf *pixbuf;
475                 GtkIconFactory *factory;
476                 gint i;
477
478                 static GtkStockItem items[] = {
479 #ifdef MODEST_PLATFORM_MAEMO
480                         { MODEST_STOCK_SPLIT_VIEW, "split view", 0, 0, NULL },
481                         { MODEST_STOCK_SORT, "sort mail", 0, 0, NULL },
482                         { MODEST_STOCK_REFRESH, "refresh mail", 0, 0, NULL },
483 #endif /*MODEST_PLATFORM_MAEMO*/
484                         { MODEST_STOCK_MAIL_SEND, "send mail", 0, 0, NULL },
485                         { MODEST_STOCK_NEW_MAIL, "new mail", 0, 0, NULL },
486 /*                      { MODEST_STOCK_SEND_RECEIVE, "send receive", 0, 0, NULL },  */
487                         { MODEST_STOCK_REPLY, "reply", 0, 0, NULL },
488                         { MODEST_STOCK_REPLY_ALL, "reply all", 0, 0, NULL },
489                         { MODEST_STOCK_FORWARD, "forward", 0, 0, NULL },
490                         { MODEST_STOCK_DELETE, "delete", 0, 0, NULL }, 
491 /*                      { MODEST_STOCK_NEXT, "next", 0, 0, NULL }, */
492 /*                      { MODEST_STOCK_PREV, "prev", 0, 0, NULL }, */
493 /*                      { MODEST_STOCK_STOP, "stop", 0, 0, NULL } */
494                 };
495       
496                 static gchar *items_names [] = {
497 #ifdef MODEST_PLATFORM_MAEMO
498                         MODEST_TOOLBAR_ICON_SPLIT_VIEW,
499                         MODEST_TOOLBAR_ICON_SORT,
500                         MODEST_TOOLBAR_ICON_REFRESH,
501 #endif /*MODEST_PLATFORM_MAEMO*/
502                         MODEST_TOOLBAR_ICON_MAIL_SEND,
503                         MODEST_TOOLBAR_ICON_NEW_MAIL,
504 /*                      MODEST_TOOLBAR_ICON_SEND_RECEIVE,  */
505                         MODEST_TOOLBAR_ICON_REPLY,      
506                         MODEST_TOOLBAR_ICON_REPLY_ALL,
507                         MODEST_TOOLBAR_ICON_FORWARD,
508                         MODEST_TOOLBAR_ICON_DELETE, 
509 /*                      MODEST_TOOLBAR_ICON_NEXT, */
510 /*                      MODEST_TOOLBAR_ICON_PREV, */
511 /*                      MODEST_TOOLBAR_ICON_STOP */
512                         MODEST_TOOLBAR_ICON_FORMAT_BULLETS,
513                 };
514
515                 registered = TRUE;
516
517                 /* Register our stock items */
518                 gtk_stock_add (items, G_N_ELEMENTS (items));
519       
520                 /* Add our custom icon factory to the list of defaults */
521                 factory = gtk_icon_factory_new ();
522                 gtk_icon_factory_add_default (factory);
523
524                 current_theme = gtk_icon_theme_get_default ();
525
526                 /* Register icons to accompany stock items */
527                 for (i = 0; i < G_N_ELEMENTS (items); i++) {
528
529 #ifdef MODEST_PLATFORM_MAEMO  /* MODES_PLATFORM_ID: 1 ==> gnome, 2==> maemo */ 
530                         pixbuf = gtk_icon_theme_load_icon (current_theme,
531                                                            items_names[i],
532                                                            26,
533                                                            GTK_ICON_LOOKUP_NO_SVG,
534                                                            NULL);
535 #else
536                         pixbuf = gdk_pixbuf_new_from_file (items_names[i], NULL);
537 #endif
538
539                         if (pixbuf != NULL) {
540                                 GtkIconSet *icon_set;
541                                 GdkPixbuf *transparent;
542
543                                 transparent = gdk_pixbuf_add_alpha (pixbuf, TRUE, 0xff, 0xff, 0xff);
544                                 icon_set = gtk_icon_set_new_from_pixbuf (transparent);
545                                 gtk_icon_factory_add (factory, items[i].stock_id, icon_set);
546                                 gtk_icon_set_unref (icon_set);
547                                 g_object_unref (pixbuf);
548                                 g_object_unref (transparent);
549                         }
550                         else
551                                 g_warning ("failed to load %s icon", items_names[i]);
552                 }
553                 /* Drop our reference to the factory, GTK will hold a reference. */
554                 g_object_unref (factory);
555         }
556 }
557
558
559 static void
560 init_default_settings (ModestConf *conf)
561 {
562         if (!modest_conf_key_exists (conf, MODEST_CONF_SHOW_TOOLBAR, NULL))
563                 modest_conf_set_bool (conf, MODEST_CONF_SHOW_TOOLBAR, TRUE, NULL);
564
565         if (!modest_conf_key_exists (conf, MODEST_CONF_SHOW_TOOLBAR_FULLSCREEN, NULL))
566                 modest_conf_set_bool (conf, MODEST_CONF_SHOW_TOOLBAR_FULLSCREEN, TRUE, NULL);
567         
568         if (!modest_conf_key_exists (conf, MODEST_CONF_SHOW_CC, NULL))
569                 modest_conf_set_bool (conf, MODEST_CONF_SHOW_CC, TRUE, NULL);
570
571         if (!modest_conf_key_exists (conf, MODEST_CONF_SHOW_BCC, NULL))
572                 modest_conf_set_bool (conf, MODEST_CONF_SHOW_BCC, FALSE, NULL);
573
574         if (!modest_conf_key_exists (conf, MODEST_CONF_CONNECT_AT_STARTUP, NULL))
575                 modest_conf_set_bool (conf, MODEST_CONF_CONNECT_AT_STARTUP, TRUE, NULL);
576
577         /* Global settings */
578         if (!modest_conf_key_exists (conf, MODEST_CONF_AUTO_UPDATE, NULL))
579                 modest_conf_set_bool (conf, MODEST_CONF_AUTO_UPDATE, TRUE, NULL);
580
581         if (!modest_conf_key_exists (conf, MODEST_CONF_UPDATE_WHEN_CONNECTED_BY, NULL))
582                 modest_conf_set_int (conf, MODEST_CONF_UPDATE_WHEN_CONNECTED_BY, MODEST_CONNECTED_VIA_WLAN, NULL);
583
584         if (!modest_conf_key_exists (conf, MODEST_CONF_UPDATE_INTERVAL, NULL))
585                 modest_conf_set_int (conf, MODEST_CONF_UPDATE_INTERVAL, MODEST_UPDATE_INTERVAL_15_MIN, NULL);
586
587         if (!modest_conf_key_exists (conf, MODEST_CONF_MSG_SIZE_LIMIT, NULL))
588                 modest_conf_set_int (conf, MODEST_CONF_MSG_SIZE_LIMIT, 1000, NULL);
589
590         if (!modest_conf_key_exists (conf, MODEST_CONF_PLAY_SOUND_MSG_ARRIVE, NULL))
591                 modest_conf_set_bool (conf, MODEST_CONF_PLAY_SOUND_MSG_ARRIVE, FALSE, NULL);
592
593         if (!modest_conf_key_exists (conf, MODEST_CONF_PREFER_FORMATTED_TEXT, NULL))
594                 modest_conf_set_bool (conf, MODEST_CONF_PREFER_FORMATTED_TEXT, TRUE, NULL);
595
596         if (!modest_conf_key_exists (conf, MODEST_CONF_REPLY_TYPE, NULL))
597                 modest_conf_set_int (conf, MODEST_CONF_REPLY_TYPE, MODEST_TNY_MSG_REPLY_TYPE_QUOTE, NULL);
598 }
599
600
601 /* set the device name -- note this is an initial guess from /etc/hostname
602  * on maemo-device it will most probably be replaced with the Bluetooth device
603  * name later during starting (see maemo/modest-maemo-utils.[ch])
604  */
605 static void
606 init_device_name (ModestConf *conf)
607 {
608         int len = 255; /* max len */
609         gchar *devname = NULL;
610         
611         if (!g_file_get_contents("/etc/hostname", &devname, &len, NULL) || len < 2 || len > 254) {
612                 g_printerr ("modest: failed to read hostname\n");
613                 modest_conf_set_string (conf, MODEST_CONF_DEVICE_NAME,
614                                         MODEST_LOCAL_FOLDERS_DEFAULT_DISPLAY_NAME,
615                                         NULL);
616         } else {
617                 /* remove the \n at the end */
618                 if (devname[len-1] == '\n')
619                         devname[len-1] = '\0';
620                 else
621                         devname[len] = '\0';
622
623                 GError *err = NULL;
624                 if (!modest_conf_set_string (conf, MODEST_CONF_DEVICE_NAME,devname, &err)) {
625                         g_printerr ("modest: error setting device name '%s': %s",
626                                     devname, err ? err->message: "?");
627                         g_error_free (err);
628                 }
629         }
630         
631         g_free (devname);
632 }