From: Sergio Villar Senin Date: Wed, 25 Feb 2009 12:56:04 +0000 (+0000) Subject: * Get the device name from the system instead of from bluetooth. Seems that could... X-Git-Tag: git_migration_finished~476 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=1046188c1febcdf1a34637a7400de3d3162e0302 * Get the device name from the system instead of from bluetooth. Seems that could fix some Dbus crashes * Show the device name in the new folder dialog instead of "Local folders" string pmo-trunk-r7683 --- diff --git a/src/hildon2/modest-maemo-utils.c b/src/hildon2/modest-maemo-utils.c index 02999f2..0dcdf0b 100644 --- a/src/hildon2/modest-maemo-utils.c +++ b/src/hildon2/modest-maemo-utils.c @@ -31,6 +31,7 @@ #define DBUS_API_SUBJECT_TO_CHANGE #endif /*DBUS_API_SUBJECT_TO_CHANGE*/ +#include #include #include #include @@ -80,7 +81,7 @@ modest_maemo_utils_get_osso_context (void) { if (!__osso_context) g_warning ("%s: __osso_context == NULL", __FUNCTION__); - + return __osso_context; } @@ -91,111 +92,18 @@ modest_maemo_utils_set_osso_context (osso_context_t *osso_context) __osso_context = osso_context; } -static void -update_device_name_from_msg (DBusMessage *message) +void +modest_maemo_utils_get_device_name (void) { - DBusError error; - DBusMessageIter iter; - - dbus_error_init (&error); + struct utsname name; - if (dbus_set_error_from_message (&error, message)) { - g_printerr ("modest: failed to get bluetooth name: %s\n", error.message); - dbus_error_free (&error); - } 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); + if (uname (&name) == 0) { modest_conf_set_string (modest_runtime_get_conf(), - MODEST_CONF_DEVICE_NAME, device_name, + MODEST_CONF_DEVICE_NAME, name.nodename, NULL); } } - -static void -on_device_name_received (DBusPendingCall *call, void *user_data) -{ - DBusMessage *message; - - g_return_if_fail (dbus_pending_call_get_completed (call)); - - message = dbus_pending_call_steal_reply (call); - if (!message) { - g_printerr ("modest: no reply on device name query\n"); - return; - } - - update_device_name_from_msg (message); - dbus_message_unref (message); -} - - -static DBusHandlerResult -handle_dbus_signal (DBusConnection *conn, DBusMessage *msg, gpointer data) -{ - if (dbus_message_is_signal(msg, BTNAME_SIGNAL_IF, BTNAME_SIG_CHANGED)) - update_device_name_from_msg (msg); - - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; -} - - -static void -get_device_name_from_dbus () -{ - static DBusConnection *conn = NULL; - DBusMessage *request; - DBusError error; - DBusPendingCall *call = NULL; - - dbus_error_init (&error); - if (!conn) { - conn = dbus_bus_get (DBUS_BUS_SYSTEM, &error); - if (!conn) { - g_printerr ("modest: cannot get on the dbus: %s: %s\n", - error.name, error.message); - dbus_error_free (&error); - return; - } - } - - request = dbus_message_new_method_call (BTNAME_SERVICE, BTNAME_REQUEST_PATH, - BTNAME_REQUEST_IF, BTNAME_REQ_GET); - if (!request) { - /* should we free the connection? */ - g_printerr ("modest: dbus_message_new_method_call failed\n"); - return; - } - dbus_message_set_auto_start (request, TRUE); - if (dbus_connection_send_with_reply (conn, request, &call, -1)) { - dbus_pending_call_set_notify (call, on_device_name_received, - NULL, NULL); - dbus_pending_call_unref (call); - } - dbus_message_unref (request); - - dbus_connection_setup_with_g_main (conn, NULL); - dbus_bus_add_match (conn, BTNAME_MATCH_RULE, &error); - if (dbus_error_is_set(&error)) { - g_printerr ("modest: dbus_bus_add_match failed: %s\n", error.message); - dbus_error_free (&error); - } - - if (!dbus_connection_add_filter(conn, handle_dbus_signal, NULL, NULL)) - g_printerr ("modest: dbus_connection_add_filter failed\n"); -} - - -void -modest_maemo_utils_get_device_name (void) -{ - get_device_name_from_dbus (); -} - void modest_maemo_utils_setup_images_filechooser (GtkFileChooser *chooser) { diff --git a/src/hildon2/modest-platform.c b/src/hildon2/modest-platform.c index bfdd3fe..264f209 100644 --- a/src/hildon2/modest-platform.c +++ b/src/hildon2/modest-platform.c @@ -724,7 +724,11 @@ static gchar * folder_store_get_display_name (TnyFolderStore *store) { if (TNY_IS_ACCOUNT (store)) { - return g_strdup (tny_account_get_name (TNY_ACCOUNT (store))); + if (modest_tny_account_is_virtual_local_folders (TNY_ACCOUNT (store))) + return modest_conf_get_string (modest_runtime_get_conf(), + MODEST_CONF_DEVICE_NAME, NULL); + else + return g_strdup (tny_account_get_name (TNY_ACCOUNT (store))); } else { gchar *fname; TnyFolderType type = TNY_FOLDER_TYPE_UNKNOWN; diff --git a/src/modest-init.c b/src/modest-init.c index 40c1454..09f3e4f 100644 --- a/src/modest-init.c +++ b/src/modest-init.c @@ -27,6 +27,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include @@ -773,28 +774,16 @@ init_default_settings (ModestConf *conf) static void init_device_name (ModestConf *conf) { - gsize len = 255; /* max len */ - gchar *devname = NULL; - - if (!g_file_get_contents("/etc/hostname", &devname, &len, NULL) || len < 2 || len > 254) { - g_warning ("%s: failed to read hostname\n", __FUNCTION__); - modest_conf_set_string (conf, MODEST_CONF_DEVICE_NAME, - MODEST_LOCAL_FOLDERS_DEFAULT_DISPLAY_NAME, + struct utsname name; + + if (uname (&name) == 0) { + modest_conf_set_string (modest_runtime_get_conf(), + MODEST_CONF_DEVICE_NAME, name.nodename, NULL); } else { - /* remove the \n at the end */ - if (devname[len-1] == '\n') - devname[len-1] = '\0'; - else - devname[len] = '\0'; - - GError *err = NULL; - if (!modest_conf_set_string (conf, MODEST_CONF_DEVICE_NAME,devname, &err)) { - g_printerr ("modest: error setting device name '%s': %s", - devname, err ? err->message: "?"); - g_error_free (err); - } + modest_conf_set_string (modest_runtime_get_conf(), + MODEST_CONF_DEVICE_NAME, + MODEST_LOCAL_FOLDERS_DEFAULT_DISPLAY_NAME, + NULL); } - - g_free (devname); }