192 lines
4.9 KiB
C
192 lines
4.9 KiB
C
#include "e.h"
|
|
|
|
/* TODO
|
|
* o Grey if inUse property is false
|
|
* o Blue if the inUse property is true
|
|
* o Pulsing if an app requests access and the dialog shows?
|
|
* o Dialog with app name and option for Not yet, Never, Only once, Always
|
|
* o List of apps in settings window.
|
|
* o Display accuracy level? Per app?
|
|
*/
|
|
|
|
|
|
/* 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 const char *_gc_label(const E_Gadcon_Client_Class *client_class);
|
|
static Evas_Object *_gc_icon(const E_Gadcon_Client_Class *client_class, Evas *evas);
|
|
static const char *_gc_id_new(const 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,
|
|
"geolocation",
|
|
{
|
|
_gc_init, _gc_shutdown, _gc_orient, _gc_label, _gc_icon, _gc_id_new, NULL, NULL
|
|
},
|
|
E_GADCON_CLIENT_STYLE_PLAIN
|
|
};
|
|
|
|
/* actual module specifics */
|
|
typedef struct _Instance Instance;
|
|
|
|
struct _Instance
|
|
{
|
|
E_Gadcon_Client *gcc;
|
|
Evas_Object *o_geoclue2;
|
|
Eina_Bool in_use;
|
|
};
|
|
|
|
static Eina_List *geoclue2_instances = NULL;
|
|
static E_Module *geoclue2_module = NULL;
|
|
|
|
static void
|
|
_geoclue2_cb_mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event)
|
|
{
|
|
Instance *inst = data;
|
|
Evas_Event_Mouse_Down *ev = event;
|
|
|
|
if (ev->button == 3)
|
|
{
|
|
E_Zone *zone;
|
|
E_Menu *m;
|
|
E_Menu_Item *mi;
|
|
int x, y;
|
|
|
|
zone = e_util_zone_current_get(e_manager_current_get());
|
|
|
|
m = e_menu_new();
|
|
|
|
mi = e_menu_item_new(m);
|
|
e_menu_item_label_set(mi, _("Settings"));
|
|
e_util_menu_item_theme_icon_set(mi, "configure");
|
|
|
|
m = e_gadcon_client_util_menu_items_append(inst->gcc, m, 0);
|
|
|
|
e_gadcon_canvas_zone_geometry_get(inst->gcc->gadcon, &x, &y, NULL, NULL);
|
|
e_menu_activate_mouse(m, zone, x + ev->output.x, y + ev->output.y,
|
|
1, 1, E_MENU_POP_DIRECTION_AUTO, ev->timestamp);
|
|
evas_event_feed_mouse_up(inst->gcc->gadcon->evas, ev->button,
|
|
EVAS_BUTTON_NONE, ev->timestamp, NULL);
|
|
}
|
|
}
|
|
|
|
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 = edje_object_add(gc->evas);
|
|
e_theme_edje_object_set(o, "base/theme/modules/geolocation",
|
|
"e/modules/geolocation/main");
|
|
evas_object_show(o);
|
|
|
|
gcc = e_gadcon_client_new(gc, name, id, style, o);
|
|
gcc->data = inst;
|
|
|
|
inst->gcc = gcc;
|
|
inst->o_geoclue2 = o;
|
|
|
|
inst->in_use = EINA_FALSE;
|
|
edje_object_signal_emit(inst->o_geoclue2, "e,state,location_off", "e");
|
|
|
|
evas_object_event_callback_add(inst->o_geoclue2,
|
|
EVAS_CALLBACK_MOUSE_DOWN,
|
|
_geoclue2_cb_mouse_down,
|
|
inst);
|
|
|
|
geoclue2_instances = eina_list_append(geoclue2_instances, inst);
|
|
return gcc;
|
|
}
|
|
|
|
static void
|
|
_gc_shutdown(E_Gadcon_Client *gcc)
|
|
{
|
|
Instance *inst;
|
|
|
|
inst = gcc->data;
|
|
geoclue2_instances = eina_list_remove(geoclue2_instances, inst);
|
|
evas_object_del(inst->o_geoclue2);
|
|
free(inst);
|
|
}
|
|
|
|
static void
|
|
_gc_orient(E_Gadcon_Client *gcc, E_Gadcon_Orient orient __UNUSED__)
|
|
{
|
|
Instance *inst;
|
|
Evas_Coord mw, mh;
|
|
|
|
inst = gcc->data;
|
|
mw = 0, mh = 0;
|
|
edje_object_size_min_get(inst->o_geoclue2, &mw, &mh);
|
|
if ((mw < 1) || (mh < 1))
|
|
edje_object_size_min_calc(inst->o_geoclue2, &mw, &mh);
|
|
if (mw < 4) mw = 4;
|
|
if (mh < 4) mh = 4;
|
|
e_gadcon_client_aspect_set(gcc, mw, mh);
|
|
e_gadcon_client_min_size_set(gcc, mw, mh);
|
|
}
|
|
|
|
static const char *
|
|
_gc_label(const E_Gadcon_Client_Class *client_class __UNUSED__)
|
|
{
|
|
return _("Geolocation");
|
|
}
|
|
|
|
static Evas_Object *
|
|
_gc_icon(const E_Gadcon_Client_Class *client_class __UNUSED__, Evas *evas)
|
|
{
|
|
Evas_Object *o;
|
|
char buf[4096];
|
|
|
|
o = edje_object_add(evas);
|
|
snprintf(buf, sizeof(buf), "%s/e-module-geoclue2.edj",
|
|
e_module_dir_get(geoclue2_module));
|
|
edje_object_file_set(o, buf, "icon");
|
|
return o;
|
|
}
|
|
|
|
static const char *
|
|
_gc_id_new(const E_Gadcon_Client_Class *client_class)
|
|
{
|
|
static char buf[4096];
|
|
|
|
snprintf(buf, sizeof(buf), "%s.%d", client_class->name,
|
|
eina_list_count(geoclue2_instances) + 1);
|
|
return buf;
|
|
}
|
|
|
|
/* module setup */
|
|
EAPI E_Module_Api e_modapi =
|
|
{
|
|
E_MODULE_API_VERSION,
|
|
"Geolocation"
|
|
};
|
|
|
|
EAPI void *
|
|
e_modapi_init(E_Module *m)
|
|
{
|
|
geoclue2_module = m;
|
|
e_gadcon_provider_register(&_gadcon_class);
|
|
return m;
|
|
}
|
|
|
|
EAPI int
|
|
e_modapi_shutdown(E_Module *m __UNUSED__)
|
|
{
|
|
e_gadcon_provider_unregister(&_gadcon_class);
|
|
return 1;
|
|
}
|
|
|
|
EAPI int
|
|
e_modapi_save(E_Module *m __UNUSED__)
|
|
{
|
|
return 1;
|
|
}
|