2007-04-24 Murray Cumming <murrayc@murrayc.com>
[modest] / src / modest-init.c
index 6fc3f80..f4eb930 100644 (file)
@@ -55,6 +55,7 @@ static void     init_stock_icons (void);
 static void     init_debug_g_type (void);
 static void     init_debug_logging (void);
 static void     init_default_settings (ModestConf *conf);
+static void     init_device_name (ModestConf *conf);
 
 /*
  * defaults for the column headers
@@ -143,6 +144,10 @@ modest_init_init_core (void)
                return FALSE;
        }
 
+
+       /* do an initial guess for the device name */
+       init_device_name (modest_runtime_get_conf());
+
        if (!modest_platform_init()) {
                modest_init_uninit ();
                g_printerr ("modest: failed to run platform-specific initialization\n");
@@ -546,3 +551,32 @@ init_default_settings (ModestConf *conf)
                modest_conf_set_bool (conf, MODEST_CONF_CONNECT_AT_STARTUP, TRUE, NULL);
 
 }
+
+
+/* set the device name -- note this is an initial guess from /etc/hostname
+ * on maemo-device it will most probably be replaced with the Bluetooth device
+ * name later during starting (see maemo/modest-maemo-utils.[ch])
+ */
+static void
+init_device_name (ModestConf *conf)
+{
+       int len = 255; /* max len */
+       gchar *devname = NULL;
+       
+       if (!g_file_get_contents("/etc/hostname", &devname, &len, NULL) || len < 2 || len > 254) {
+               g_printerr ("modest: failed to read hostname\n");
+               modest_conf_set_string (conf, MODEST_CONF_DEVICE_NAME,
+                                       MODEST_LOCAL_FOLDERS_DEFAULT_DISPLAY_NAME,
+                                       NULL);
+       } else {
+               /* remove the \n at the end */
+               if (devname[len-1] == '\n')
+                       devname[len-1] = '\0';
+               else
+                       devname[len] = '\0';
+
+               modest_conf_set_string (conf, MODEST_CONF_DEVICE_NAME,devname, NULL);
+       }
+
+       g_free (devname);
+}