+static void
+get_default_adapter_cb (DBusPendingCall *call,
+ void *user_data)
+{
+ DBusMessage *message;
+ DBusMessageIter iter;
+ gchar* path = NULL;
+
+ message = dbus_pending_call_steal_reply(call);
+
+ // Todo extract msg info from here
+ dbus_message_iter_init ( message, &iter );
+
+ dbus_message_iter_get_basic (&iter, &path);
+ if (path != NULL) {
+ DBusConnection *conn;
+ DBusMessage *adapterMsg = dbus_message_new_method_call(BTNAME_SERVICE, path,
+ BTNAME_REQUEST_IF,
+ BTNAME_REQ_GET_PROPERTIES);
+ DBusPendingCall *call = NULL;
+
+ conn = dbus_bus_get (DBUS_BUS_SYSTEM, NULL);
+
+ if (conn && dbus_connection_send_with_reply(conn, adapterMsg, &call, -1) ) {
+ dbus_pending_call_set_notify(call, get_properties_cb, NULL, NULL);
+ dbus_pending_call_block(call);
+ dbus_pending_call_unref(call);
+ }
+ } else {
+ g_warning ("Failed to get the default bluetooth adapter");
+ }
+}
+
+void
+modest_maemo_utils_get_device_name (void)
+{
+ 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;
+ }
+ }
+
+ /* Get the default adapter */
+ request = dbus_message_new_method_call(BTNAME_SERVICE, "/" ,
+ BTNAME_REQUEST_IF,
+ BTNAME_REQ_DEFAULT_ADAPTER);
+
+ if (dbus_connection_send_with_reply(conn, request, &call, -1)) {
+ dbus_pending_call_set_notify(call, get_default_adapter_cb, NULL, NULL);
+ dbus_pending_call_block(call);
+ dbus_pending_call_unref(call);
+ }
+
+/* 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"); */
+}
+