* try /etc/hostname for the local device name as initial guess
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Sat, 21 Apr 2007 09:56:21 +0000 (09:56 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Sat, 21 Apr 2007 09:56:21 +0000 (09:56 +0000)
if there's a bluetooth name (used as the n800 device name), that one
  will replace the initial guess later during startup, but e.g.
  in scratchbox, the initial guess remains

pmo-trunk-r1624

src/maemo/modest-maemo-utils.c
src/maemo/modest-maemo-utils.h
src/modest-init.c

index 5b7e477..f63b9bc 100644 (file)
@@ -82,10 +82,6 @@ modest_maemo_utils_menubar_to_menu (GtkUIManager *ui_manager)
 }
 
 
-
-
-
-
 static void
 update_device_name_from_msg (DBusMessage *message)
 {
@@ -95,19 +91,14 @@ update_device_name_from_msg (DBusMessage *message)
        dbus_error_init (&error);
 
        if (dbus_set_error_from_message (&error, message)) {
-               g_printerr ("modest: failed to get bt name: %s\n", error.message);
+               g_printerr ("modest: failed to get bluetooth name: %s\n", error.message);
                dbus_error_free (&error);
-               modest_conf_set_string (modest_runtime_get_conf(),
-                                       MODEST_CONF_DEVICE_NAME,
-                                       MODEST_LOCAL_FOLDERS_DEFAULT_DISPLAY_NAME,
-                                       NULL);                                  
        } else {
                const gchar *device_name;
                if (!dbus_message_iter_init (message, &iter)) {
                        g_printerr ("modest: message did not have argument\n");
                        return;
                }
-
                dbus_message_iter_get_basic (&iter, &device_name);
                g_warning ("update device name: %s", device_name);
                modest_conf_set_string (modest_runtime_get_conf(),
index beb9cad..aa23b4f 100644 (file)
@@ -49,7 +49,7 @@ GtkWidget*    modest_maemo_utils_menubar_to_menu (GtkUIManager *ui_manager);
  *
  * get the name for this device. Note: this queries the bluetooth
  * name over DBUS, and may block. The result will be available in
- * MODEST_DEVICE_NAME in ModestConf; it will be updated when it
+ * MODEST_CONF_DEVICE_NAME in ModestConf; it will be updated when it
  * changes
  * 
  */
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);
+}