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