diff --git a/client/main.c b/client/main.c
index 6514be8..be785c5 100644
--- a/client/main.c
+++ b/client/main.c
return FALSE;
}
+static void set_default_device(GDBusProxy *proxy, const char *attribute)
+{
+ char *desc = NULL;
+ DBusMessageIter iter;
+ const char *path;
+
+ default_dev = proxy;
+
+ if (proxy == NULL) {
+ default_attr = NULL;
+ goto done;
+ }
+
+ if (!g_dbus_proxy_get_property(proxy, "Alias", &iter)) {
+ if (!g_dbus_proxy_get_property(proxy, "Address", &iter))
+ goto done;
+ }
+
+ path = g_dbus_proxy_get_path(proxy);
+
+ dbus_message_iter_get_basic(&iter, &desc);
+ desc = g_strdup_printf(COLOR_BLUE "[%s%s%s]" COLOR_OFF "# ", desc,
+ attribute ? ":" : "",
+ attribute ? attribute + strlen(path) : "");
+
+done:
+ rl_set_prompt(desc ? desc : PROMPT_ON);
+ printf("\r");
+ rl_on_new_line();
+ rl_redisplay();
+ g_free(desc);
+}
+
+static void device_added(GDBusProxy *proxy)
+{
+ DBusMessageIter iter;
+
+ dev_list = g_list_append(dev_list, proxy);
+
+ print_device(proxy, COLORED_NEW);
+
+ if (default_dev)
+ return;
+
+ if (g_dbus_proxy_get_property(proxy, "Connected", &iter)) {
+ dbus_bool_t connected;
+
+ dbus_message_iter_get_basic(&iter, &connected);
+
+ if (connected)
+ set_default_device(proxy, NULL);
+ }
+}
+
static void proxy_added(GDBusProxy *proxy, void *user_data)
{
const char *interface;
interface = g_dbus_proxy_get_interface(proxy);
if (!strcmp(interface, "org.bluez.Device1")) {
- if (device_is_child(proxy, default_ctrl) == TRUE) {
- dev_list = g_list_append(dev_list, proxy);
+ if (device_is_child(proxy, default_ctrl) == TRUE)
+ device_added(proxy);
- print_device(proxy, COLORED_NEW);
- }
} else if (!strcmp(interface, "org.bluez.Adapter1")) {
ctrl_list = g_list_append(ctrl_list, proxy);
}
}
-static void set_default_device(GDBusProxy *proxy, const char *attribute)
-{
- char *desc = NULL;
- DBusMessageIter iter;
- const char *path;
-
- default_dev = proxy;
-
- if (proxy == NULL) {
- default_attr = NULL;
- goto done;
- }
-
- if (!g_dbus_proxy_get_property(proxy, "Alias", &iter)) {
- if (!g_dbus_proxy_get_property(proxy, "Address", &iter))
- goto done;
- }
-
- path = g_dbus_proxy_get_path(proxy);
-
- dbus_message_iter_get_basic(&iter, &desc);
- desc = g_strdup_printf(COLOR_BLUE "[%s%s%s]" COLOR_OFF "# ", desc,
- attribute ? ":" : "",
- attribute ? attribute + strlen(path) : "");
-
-done:
- rl_set_prompt(desc ? desc : PROMPT_ON);
- printf("\r");
- rl_on_new_line();
- rl_redisplay();
- g_free(desc);
-}
-
static void set_default_attribute(GDBusProxy *proxy)
{
const char *path;