forked from enlightenment/enlightenment
bluez5 - remember pwr and pairable states and restore them on adapt add
bluez wont remember powered state for adapyters so for usability, do it for bluez so users get their last state as you might expect.
This commit is contained in:
parent
7c6702e2fd
commit
0c61b092bb
|
@ -4,6 +4,7 @@ static Eina_List *instances = NULL;
|
||||||
static E_Module *mod = NULL;
|
static E_Module *mod = NULL;
|
||||||
|
|
||||||
/* Local config */
|
/* Local config */
|
||||||
|
static E_Config_DD *conf_adapter_edd = NULL;
|
||||||
static E_Config_DD *conf_edd = NULL;
|
static E_Config_DD *conf_edd = NULL;
|
||||||
Config *ebluez5_config = NULL;
|
Config *ebluez5_config = NULL;
|
||||||
|
|
||||||
|
@ -232,6 +233,38 @@ static const E_Gadcon_Client_Class _gc_class = {
|
||||||
};
|
};
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void
|
||||||
|
ebluez5_conf_adapter_add(const char *addr, Eina_Bool powered, Eina_Bool pairable)
|
||||||
|
{
|
||||||
|
Eina_List *l;
|
||||||
|
Config_Adapter *ad;
|
||||||
|
|
||||||
|
if (!ebluez5_config) ebluez5_config = E_NEW(Config, 1);
|
||||||
|
if (!ebluez5_config) return;
|
||||||
|
EINA_LIST_FOREACH(ebluez5_config->adapters, l, ad)
|
||||||
|
{
|
||||||
|
if (!ad->addr) continue;
|
||||||
|
if (!strcmp(addr, ad->addr))
|
||||||
|
{
|
||||||
|
if ((ad->powered == powered) && (ad->pairable == pairable)) return;
|
||||||
|
ad->powered = powered;
|
||||||
|
ad->pairable = pairable;
|
||||||
|
e_config_save_queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ad = E_NEW(Config_Adapter, 1);
|
||||||
|
if (ad)
|
||||||
|
{
|
||||||
|
ad->addr = eina_stringshare_add(addr);
|
||||||
|
ad->powered = powered;
|
||||||
|
ad->pairable = pairable;
|
||||||
|
ebluez5_config->adapters = eina_list_append(ebluez5_config->adapters, ad);
|
||||||
|
}
|
||||||
|
e_config_save_queue();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ebluez5_popups_show(void)
|
ebluez5_popups_show(void)
|
||||||
{
|
{
|
||||||
|
@ -276,13 +309,21 @@ e_modapi_init(E_Module *m)
|
||||||
{
|
{
|
||||||
mod = m;
|
mod = m;
|
||||||
|
|
||||||
|
conf_adapter_edd = E_CONFIG_DD_NEW("Config_Adapter", Config_Adapter);
|
||||||
|
#undef T
|
||||||
|
#undef D
|
||||||
|
#define T Config_Adapter
|
||||||
|
#define D conf_adapter_edd
|
||||||
|
E_CONFIG_VAL(D, T, addr, STR);
|
||||||
|
E_CONFIG_VAL(D, T, powered, UCHAR);
|
||||||
|
E_CONFIG_VAL(D, T, pairable, UCHAR);
|
||||||
|
|
||||||
conf_edd = E_CONFIG_DD_NEW("Config", Config);
|
conf_edd = E_CONFIG_DD_NEW("Config", Config);
|
||||||
#undef T
|
#undef T
|
||||||
#undef D
|
#undef D
|
||||||
#define T Config
|
#define T Config
|
||||||
#define D conf_edd
|
#define D conf_edd
|
||||||
E_CONFIG_VAL(D, T, lock_dev_addr, STR);
|
E_CONFIG_LIST(D, T, adapters, conf_adapter_edd);
|
||||||
E_CONFIG_VAL(D, T, unlock_dev_addr, STR);
|
|
||||||
|
|
||||||
ebluez5_config = e_config_domain_load("module.ebluez5", conf_edd);
|
ebluez5_config = e_config_domain_load("module.ebluez5", conf_edd);
|
||||||
if (!ebluez5_config) ebluez5_config = E_NEW(Config, 1);
|
if (!ebluez5_config) ebluez5_config = E_NEW(Config, 1);
|
||||||
|
@ -299,10 +340,16 @@ e_modapi_init(E_Module *m)
|
||||||
E_API int
|
E_API int
|
||||||
e_modapi_shutdown(E_Module *m EINA_UNUSED)
|
e_modapi_shutdown(E_Module *m EINA_UNUSED)
|
||||||
{
|
{
|
||||||
E_CONFIG_DD_FREE(conf_edd);
|
Config_Adapter *ad;
|
||||||
|
|
||||||
eina_stringshare_del(ebluez5_config->lock_dev_addr);
|
E_CONFIG_DD_FREE(conf_edd);
|
||||||
eina_stringshare_del(ebluez5_config->unlock_dev_addr);
|
E_CONFIG_DD_FREE(conf_adapter_edd);
|
||||||
|
|
||||||
|
EINA_LIST_FREE(ebluez5_config->adapters, ad)
|
||||||
|
{
|
||||||
|
eina_stringshare_del(ad->addr);
|
||||||
|
free(ad);
|
||||||
|
}
|
||||||
free(ebluez5_config);
|
free(ebluez5_config);
|
||||||
ebluez5_config = NULL;
|
ebluez5_config = NULL;
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,14 @@ struct _Instance
|
||||||
typedef struct _Config Config;
|
typedef struct _Config Config;
|
||||||
struct _Config
|
struct _Config
|
||||||
{
|
{
|
||||||
const char *lock_dev_addr;
|
Eina_List *adapters;
|
||||||
const char *unlock_dev_addr;
|
};
|
||||||
|
typedef struct _Config_Adapter Config_Adapter;
|
||||||
|
struct _Config_Adapter
|
||||||
|
{
|
||||||
|
const char *addr;
|
||||||
|
Eina_Bool powered;
|
||||||
|
Eina_Bool pairable;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Config *ebluez5_config;
|
extern Config *ebluez5_config;
|
||||||
|
@ -34,6 +40,7 @@ E_API void *e_modapi_init(E_Module *m);
|
||||||
E_API int e_modapi_shutdown(E_Module *m);
|
E_API int e_modapi_shutdown(E_Module *m);
|
||||||
E_API int e_modapi_save(E_Module *m);
|
E_API int e_modapi_save(E_Module *m);
|
||||||
|
|
||||||
|
void ebluez5_conf_adapter_add(const char *addr, Eina_Bool powered, Eina_Bool pairable);
|
||||||
void ebluez5_popups_show(void);
|
void ebluez5_popups_show(void);
|
||||||
void ebluez5_rfkill_unblock(const char *name);
|
void ebluez5_rfkill_unblock(const char *name);
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,25 @@ static Eina_List *devices = NULL;
|
||||||
static void
|
static void
|
||||||
_adapter_add(Evas_Object *gl, Obj *o)
|
_adapter_add(Evas_Object *gl, Obj *o)
|
||||||
{
|
{
|
||||||
|
Eina_List *l;
|
||||||
|
Config_Adapter *ad;
|
||||||
Elm_Object_Item *it = evas_object_data_get(gl, "adapters_item");;
|
Elm_Object_Item *it = evas_object_data_get(gl, "adapters_item");;
|
||||||
elm_genlist_item_append(gl, adapt_itc, o, it, ELM_GENLIST_ITEM_NONE,
|
elm_genlist_item_append(gl, adapt_itc, o, it, ELM_GENLIST_ITEM_NONE,
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
|
if ((ebluez5_config) && (o->address))
|
||||||
|
{
|
||||||
|
EINA_LIST_FOREACH(ebluez5_config->adapters, l, ad)
|
||||||
|
{
|
||||||
|
if (!ad->addr) continue;
|
||||||
|
if (!strcmp(ad->addr, o->address))
|
||||||
|
{
|
||||||
|
if (ad->powered) bz_obj_power_on(o);
|
||||||
|
else bz_obj_power_off(o);
|
||||||
|
if (ad->pairable) bz_obj_pairable(o);
|
||||||
|
else bz_obj_unpairable(o);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -654,6 +670,9 @@ ebluez5_popup_adapter_change(Obj *o)
|
||||||
if (o == elm_object_item_data_get(it))
|
if (o == elm_object_item_data_get(it))
|
||||||
{
|
{
|
||||||
elm_genlist_item_update(it);
|
elm_genlist_item_update(it);
|
||||||
|
if (o->address)
|
||||||
|
ebluez5_conf_adapter_add(o->address, o->powered,
|
||||||
|
o->pairable);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue