e/bluez4: Allow user to remove devices

Patch by: Lucas Joia <lucasjoia@profusion.mobi>



SVN revision: 82192
This commit is contained in:
Lucas Joia 2013-01-04 16:12:32 +00:00 committed by Lucas De Marchi
parent 32ba9a1358
commit 896b8533c9
3 changed files with 64 additions and 5 deletions

View File

@ -87,10 +87,21 @@ _ebluez4_cb_connect(void *data, void *data2 __UNUSED__)
ebluez4_connect_to_device(addr);
}
static void
_ebluez4_cb_remove(void *data, void *data2 __UNUSED__)
{
Instance *inst = data;
const char *addr = e_widget_ilist_selected_value_get(inst->created_list);
if(!addr)
return;
ebluez4_remove_device(addr);
}
static void
_ebluez4_popup_new(Instance *inst)
{
Evas_Object *list, *tb, *conn_bt, *blank, *adap_bt, *search_bt;
Evas_Object *list, *tb, *conn_bt, *blank, *adap_bt, *search_bt, *rem_bt;
Evas_Coord mw, mh;
Evas *evas;
@ -106,6 +117,8 @@ _ebluez4_popup_new(Instance *inst)
conn_bt = e_widget_button_add(evas, "Connect", NULL, _ebluez4_cb_connect,
inst, NULL);
rem_bt = e_widget_button_add(evas, "Remove", NULL, _ebluez4_cb_remove, inst,
NULL);
search_bt = e_widget_button_add(evas, "Search New Devices", NULL,
_ebluez4_cb_search, inst, NULL);
adap_bt = e_widget_button_add(evas, "Adapters Settings", NULL, NULL, inst,
@ -115,11 +128,12 @@ _ebluez4_popup_new(Instance *inst)
e_widget_size_min_set(blank, 0, 10);
tb = e_widget_table_add(evas, 0);
e_widget_table_object_append(tb, search_bt, 0, 0, 1, 1, 1, 1, 1, 1);
e_widget_table_object_append(tb, adap_bt, 1, 0, 1, 1, 1, 1, 1, 1);
e_widget_list_object_append(list, conn_bt, 0, 0, 0.5);
e_widget_list_object_append(list, blank, 0, 0, 0.5);
e_widget_table_object_append(tb, conn_bt, 0, 0, 1, 1, 1, 1, 1, 1);
e_widget_table_object_append(tb, rem_bt, 1, 0, 1, 1, 1, 1, 1, 1);
e_widget_table_object_append(tb, blank, 0, 1, 1, 1, 1, 1, 1, 1);
e_widget_table_object_append(tb, search_bt, 0, 2, 1, 1, 1, 1, 1, 1);
e_widget_table_object_append(tb, adap_bt, 1, 2, 1, 1, 1, 1, 1, 1);
e_widget_list_object_append(list, tb, 1, 0, 0.5);
e_widget_size_min_get(list, &mw, &mh);

View File

@ -251,6 +251,19 @@ _on_dev_properties(void *data, const EDBus_Message *msg, EDBus_Pending *pending)
ebluez4_append_to_instances(dev, LIST_TYPE_CREATED_DEVICES);
}
static void
_unset_dev(const char *path)
{
Device *dev = eina_list_search_unsorted(ctxt->devices, ebluez4_path_cmp,
path);
if (!dev)
return;
ctxt->devices = eina_list_remove(ctxt->devices, dev);
ebluez4_update_instances(ctxt->devices, LIST_TYPE_CREATED_DEVICES);
_free_dev(dev);
}
static void
_set_dev(const char *path)
{
@ -265,6 +278,17 @@ _set_dev(const char *path)
ctxt->devices = eina_list_append(ctxt->devices, dev);
}
static void
_on_removed(void *context, const EDBus_Message *msg)
{
const char *path;
if (!edbus_message_arguments_get(msg, "o", &path))
return;
_unset_dev(path);
}
static void
_on_created(void *context, const EDBus_Message *msg)
{
@ -343,6 +367,8 @@ _set_adapter(const EDBus_Message *msg)
_on_device_found, NULL);
edbus_proxy_signal_handler_add(ctxt->adap_proxy, "DeviceCreated",
_on_created, NULL);
edbus_proxy_signal_handler_add(ctxt->adap_proxy, "DeviceRemoved",
_on_removed, NULL);
edbus_proxy_call(ctxt->adap_proxy, "ListDevices", _on_list, NULL, -1, "");
edbus_proxy_call(ctxt->adap_proxy, "RegisterAgent", NULL, NULL, -1, "os",
REMOTE_AGENT_PATH, "KeyboardDisplay");
@ -463,3 +489,20 @@ ebluez4_pair_with_device(const char *addr)
edbus_proxy_call(ctxt->adap_proxy, "CreatePairedDevice", _on_paired, NULL,
-1, "sos", addr, AGENT_PATH, "KeyboardDisplay");
}
void
ebluez4_remove_device(const char *addr)
{
Device *dev = eina_list_search_unsorted(ctxt->devices, _addr_cmp, addr);
edbus_proxy_call(ctxt->adap_proxy, "RemoveDevice", NULL, NULL, -1, "o",
edbus_object_path_get(dev->obj));
}
int
ebluez4_path_cmp(const void *d1, const void *d2)
{
const Device *dev = d1;
const char *path = d2;
return strcmp(edbus_object_path_get(dev->obj), path);
}

View File

@ -65,3 +65,5 @@ void ebluez4_start_discovery();
void ebluez4_stop_discovery();
void ebluez4_connect_to_device(const char *addr);
void ebluez4_pair_with_device(const char *addr);
void ebluez4_remove_device(const char *addr);
int ebluez4_path_cmp(const void *d1, const void *d2);