215 lines
4.8 KiB
C
215 lines
4.8 KiB
C
#include "e.h"
|
|
|
|
/***************************************************************************/
|
|
typedef struct _Instance Instance;
|
|
|
|
struct _Instance
|
|
{
|
|
E_Gadcon_Client *gcc;
|
|
Evas_Object *obj;
|
|
Ecore_Poller *poller;
|
|
int on;
|
|
};
|
|
|
|
/***************************************************************************/
|
|
/**/
|
|
/* gadcon requirements */
|
|
static E_Gadcon_Client *_gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style);
|
|
static void _gc_shutdown(E_Gadcon_Client *gcc);
|
|
static void _gc_orient(E_Gadcon_Client *gcc, E_Gadcon_Orient orient);
|
|
static char *_gc_label(E_Gadcon_Client_Class *client_class);
|
|
static Evas_Object *_gc_icon(E_Gadcon_Client_Class *client_class, Evas *evas);
|
|
static const char *_gc_id_new(E_Gadcon_Client_Class *client_class);
|
|
/* and actually define the gadcon class that this module provides (just 1) */
|
|
static const E_Gadcon_Client_Class _gadcon_class =
|
|
{
|
|
GADCON_CLIENT_CLASS_VERSION,
|
|
"illume-bluetooth",
|
|
{
|
|
_gc_init, _gc_shutdown, _gc_orient, _gc_label, _gc_icon, _gc_id_new, NULL
|
|
},
|
|
E_GADCON_CLIENT_STYLE_PLAIN
|
|
};
|
|
static E_Module *mod = NULL;
|
|
/**/
|
|
/***************************************************************************/
|
|
|
|
static int _cb_poll(void *data);
|
|
|
|
/* called from the module core */
|
|
void
|
|
_e_mod_gad_bluetooth_init(E_Module *m)
|
|
{
|
|
mod = m;
|
|
e_gadcon_provider_register(&_gadcon_class);
|
|
}
|
|
|
|
void
|
|
_e_mod_gad_bluetooth_shutdown(void)
|
|
{
|
|
e_gadcon_provider_unregister(&_gadcon_class);
|
|
mod = NULL;
|
|
}
|
|
|
|
/* internal calls */
|
|
static Evas_Object *
|
|
_theme_obj_new(Evas *e, const char *custom_dir, const char *group)
|
|
{
|
|
Evas_Object *o;
|
|
|
|
o = edje_object_add(e);
|
|
if (!e_theme_edje_object_set(o, "base/theme/modules/illume", group))
|
|
{
|
|
if (custom_dir)
|
|
{
|
|
char buf[PATH_MAX];
|
|
|
|
snprintf(buf, sizeof(buf), "%s/illume.edj", custom_dir);
|
|
if (edje_object_file_set(o, buf, group))
|
|
{
|
|
printf("OK FALLBACK %s\n", buf);
|
|
}
|
|
}
|
|
}
|
|
return o;
|
|
}
|
|
|
|
static E_Gadcon_Client *
|
|
_gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style)
|
|
{
|
|
Evas_Object *o;
|
|
E_Gadcon_Client *gcc;
|
|
Instance *inst;
|
|
|
|
inst = E_NEW(Instance, 1);
|
|
o = _theme_obj_new(gc->evas, e_module_dir_get(mod),
|
|
"e/modules/illume/gadget/bluetooth");
|
|
evas_object_show(o);
|
|
gcc = e_gadcon_client_new(gc, name, id, style, o);
|
|
gcc->data = inst;
|
|
inst->gcc = gcc;
|
|
inst->obj = o;
|
|
e_gadcon_client_util_menu_attach(gcc);
|
|
|
|
inst->on = -1;
|
|
inst->poller = ecore_poller_add(ECORE_POLLER_CORE, 16, _cb_poll, inst);
|
|
|
|
return gcc;
|
|
}
|
|
|
|
static void
|
|
_gc_shutdown(E_Gadcon_Client *gcc)
|
|
{
|
|
Instance *inst;
|
|
|
|
inst = gcc->data;
|
|
ecore_poller_del(inst->poller);
|
|
evas_object_del(inst->obj);
|
|
free(inst);
|
|
}
|
|
|
|
static void
|
|
_gc_orient(E_Gadcon_Client *gcc, E_Gadcon_Orient orient)
|
|
{
|
|
Instance *inst;
|
|
Evas_Coord mw, mh, mxw, mxh;
|
|
|
|
inst = gcc->data;
|
|
mw = 0, mh = 0;
|
|
edje_object_size_min_get(inst->obj, &mw, &mh);
|
|
edje_object_size_max_get(inst->obj, &mxw, &mxh);
|
|
if ((mw < 1) || (mh < 1))
|
|
edje_object_size_min_calc(inst->obj, &mw, &mh);
|
|
if (mw < 4) mw = 4;
|
|
if (mh < 4) mh = 4;
|
|
if ((mxw > 0) && (mxh > 0))
|
|
e_gadcon_client_aspect_set(gcc, mxw, mxh);
|
|
e_gadcon_client_min_size_set(gcc, mw, mh);
|
|
}
|
|
|
|
static char *
|
|
_gc_label(E_Gadcon_Client_Class *client_class)
|
|
{
|
|
return "Bluetooth (Illume)";
|
|
}
|
|
|
|
static Evas_Object *
|
|
_gc_icon(E_Gadcon_Client_Class *client_class, Evas *evas)
|
|
{
|
|
/* FIXME: need icon
|
|
Evas_Object *o;
|
|
char buf[4096];
|
|
|
|
o = edje_object_add(evas);
|
|
snprintf(buf, sizeof(buf), "%s/e-module-clock.edj",
|
|
e_module_dir_get(clock_module));
|
|
edje_object_file_set(o, buf, "icon");
|
|
return o;
|
|
*/
|
|
return NULL;
|
|
}
|
|
|
|
static const char *
|
|
_gc_id_new(E_Gadcon_Client_Class *client_class)
|
|
{
|
|
return _gadcon_class.name;
|
|
}
|
|
|
|
static int
|
|
_find_interface_class(int iclass)
|
|
{
|
|
Eina_List *devs;
|
|
char *name;
|
|
|
|
devs = ecore_file_ls("/sys/bus/usb/devices");
|
|
EINA_LIST_FREE(devs, name)
|
|
{
|
|
char buf[PATH_MAX];
|
|
FILE *f;
|
|
|
|
snprintf(buf, sizeof(buf), "%s/%s/%s",
|
|
"/sys/bus/usb/devices", name, "bInterfaceClass");
|
|
f = fopen(buf, "r");
|
|
if (f)
|
|
{
|
|
if (fgets(buf, sizeof(buf), f))
|
|
{
|
|
int id = -1;
|
|
|
|
sscanf(buf, "%x", &id);
|
|
if (iclass == id)
|
|
{
|
|
EINA_LIST_FREE(devs, name)
|
|
free(name);
|
|
fclose(f);
|
|
return 1;
|
|
}
|
|
}
|
|
fclose(f);
|
|
}
|
|
|
|
free(name);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static int
|
|
_cb_poll(void *data)
|
|
{
|
|
Instance *inst;
|
|
int pon;
|
|
|
|
inst = data;
|
|
/* FIXME: get bt status and emit signal */
|
|
pon = inst->on;
|
|
inst->on = _find_interface_class(0xe0);
|
|
if (inst->on != pon)
|
|
{
|
|
if (inst->on)
|
|
edje_object_signal_emit(inst->obj, "e,state,active", "e");
|
|
else
|
|
edje_object_signal_emit(inst->obj, "e,state,passive", "e");
|
|
}
|
|
return 1;
|
|
}
|