2017-01-06 14:15:30 -08:00
|
|
|
#include "netstatus.h"
|
|
|
|
|
|
|
|
typedef struct _Thread_Config Thread_Config;
|
|
|
|
|
|
|
|
struct _Thread_Config
|
|
|
|
{
|
|
|
|
int interval;
|
|
|
|
Instance *inst;
|
2017-01-12 12:17:55 -08:00
|
|
|
int percent;
|
|
|
|
long current;
|
2017-01-06 14:15:30 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2017-01-12 12:17:55 -08:00
|
|
|
_netstatus_face_update(Instance *inst)
|
2017-01-06 14:15:30 -08:00
|
|
|
{
|
2017-01-12 12:17:55 -08:00
|
|
|
Edje_Message_Int_Set *msg;
|
|
|
|
|
|
|
|
msg = malloc(sizeof(Edje_Message_Int_Set) + 6 * sizeof(int));
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(msg);
|
|
|
|
msg->count = 6;
|
|
|
|
msg->val[0] = inst->cfg->netstatus.incurrent;
|
|
|
|
msg->val[1] = inst->cfg->netstatus.inpercent;
|
|
|
|
msg->val[2] = inst->cfg->netstatus.inmax;
|
2017-01-15 06:57:40 -08:00
|
|
|
msg->val[3] = inst->cfg->netstatus.outcurrent;
|
|
|
|
msg->val[4] = inst->cfg->netstatus.outpercent;
|
|
|
|
msg->val[5] = inst->cfg->netstatus.outmax;
|
|
|
|
edje_object_message_send(elm_layout_edje_get(inst->cfg->netstatus.o_gadget),
|
2017-01-12 12:17:55 -08:00
|
|
|
EDJE_MESSAGE_INT_SET, 1, msg);
|
|
|
|
free(msg);
|
2017-01-26 12:06:56 -08:00
|
|
|
|
|
|
|
if (inst->cfg->netstatus.popup)
|
|
|
|
{
|
|
|
|
char text[4096];
|
|
|
|
snprintf(text, sizeof(text), "%s<br>%s", inst->cfg->netstatus.instring, inst->cfg->netstatus.outstring);
|
|
|
|
elm_object_text_set(inst->cfg->netstatus.popup_label, text);
|
|
|
|
}
|
2017-01-11 19:21:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static Evas_Object *
|
|
|
|
_netstatus_configure_cb(Evas_Object *g)
|
|
|
|
{
|
|
|
|
Instance *inst = evas_object_data_get(g, "Instance");
|
|
|
|
|
|
|
|
if (!sysinfo_config) return NULL;
|
|
|
|
if (inst->cfg->netstatus.popup) return NULL;
|
|
|
|
return netstatus_configure(inst);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-01-11 20:06:38 -08:00
|
|
|
_netstatus_popup_dismissed(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
|
2017-01-11 19:21:34 -08:00
|
|
|
{
|
2017-01-11 20:06:38 -08:00
|
|
|
Instance *inst = data;
|
2017-01-11 19:21:34 -08:00
|
|
|
E_FREE_FUNC(obj, evas_object_del);
|
2017-01-11 20:06:38 -08:00
|
|
|
inst->cfg->netstatus.popup = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_netstatus_popup_deleted(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Instance *inst = data;
|
|
|
|
inst->cfg->netstatus.popup = NULL;
|
2017-01-11 19:21:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_netstatus_mouse_down_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_data)
|
|
|
|
{
|
|
|
|
Evas_Object *label, *popup;
|
|
|
|
Evas_Event_Mouse_Down *ev = event_data;
|
|
|
|
Instance *inst = data;
|
|
|
|
char text[4096];
|
|
|
|
|
|
|
|
if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
|
|
|
|
if (ev->button != 3)
|
|
|
|
{
|
|
|
|
if (inst->cfg->netstatus.popup)
|
|
|
|
{
|
|
|
|
elm_ctxpopup_dismiss(inst->cfg->netstatus.popup);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
popup = elm_ctxpopup_add(e_comp->elm);
|
|
|
|
elm_object_style_set(popup, "noblock");
|
2017-01-11 20:06:38 -08:00
|
|
|
evas_object_smart_callback_add(popup, "dismissed", _netstatus_popup_dismissed, inst);
|
|
|
|
evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL, _netstatus_popup_deleted, inst);
|
2017-01-11 19:21:34 -08:00
|
|
|
|
|
|
|
snprintf(text, sizeof(text), "%s<br>%s", inst->cfg->netstatus.instring, inst->cfg->netstatus.outstring);
|
|
|
|
label = elm_label_add(popup);
|
|
|
|
elm_object_style_set(label, "marker");
|
|
|
|
elm_object_text_set(label, text);
|
|
|
|
elm_object_content_set(popup, label);
|
|
|
|
evas_object_show(label);
|
2017-01-26 12:06:56 -08:00
|
|
|
inst->cfg->netstatus.popup_label = label;
|
2017-01-11 19:21:34 -08:00
|
|
|
|
2017-01-30 13:46:27 -08:00
|
|
|
e_gadget_util_ctxpopup_place(inst->o_main, popup,
|
|
|
|
inst->cfg->netstatus.o_gadget);
|
2017-01-11 19:21:34 -08:00
|
|
|
evas_object_show(popup);
|
|
|
|
inst->cfg->netstatus.popup = popup;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (inst->cfg->netstatus.popup)
|
2017-02-10 09:37:30 -08:00
|
|
|
elm_ctxpopup_dismiss(inst->cfg->netstatus.popup);
|
2017-01-11 19:21:34 -08:00
|
|
|
if (!sysinfo_config) return;
|
|
|
|
ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
|
|
|
|
if (inst->cfg->esm != E_SYSINFO_MODULE_NETSTATUS)
|
|
|
|
netstatus_configure(inst);
|
|
|
|
else
|
|
|
|
e_gadget_configure(inst->o_main);
|
2017-01-06 14:15:30 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-27 12:55:24 -08:00
|
|
|
static void
|
|
|
|
_netstatus_resize_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_data EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Evas_Coord w, h;
|
|
|
|
Instance *inst = data;
|
|
|
|
|
|
|
|
edje_object_parts_extends_calc(elm_layout_edje_get(inst->cfg->netstatus.o_gadget), 0, 0, &w, &h);
|
|
|
|
if (inst->cfg->esm == E_SYSINFO_MODULE_NETSTATUS)
|
|
|
|
evas_object_size_hint_aspect_set(inst->o_main, EVAS_ASPECT_CONTROL_BOTH, w, h);
|
|
|
|
else
|
|
|
|
evas_object_size_hint_aspect_set(inst->cfg->netstatus.o_gadget, EVAS_ASPECT_CONTROL_BOTH, w, h);
|
|
|
|
}
|
|
|
|
|
2017-01-06 14:15:30 -08:00
|
|
|
static void
|
|
|
|
_netstatus_cb_usage_check_main(void *data, Ecore_Thread *th)
|
|
|
|
{
|
|
|
|
Thread_Config *thc = data;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (ecore_thread_check(th)) break;
|
2017-01-12 12:17:55 -08:00
|
|
|
_netstatus_proc_getrstatus(thc->inst);
|
|
|
|
_netstatus_proc_gettstatus(thc->inst);
|
2017-01-06 14:15:30 -08:00
|
|
|
ecore_thread_feedback(th, NULL);
|
|
|
|
if (ecore_thread_check(th)) break;
|
|
|
|
usleep((1000000.0 / 8.0) * (double)thc->interval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_netstatus_cb_usage_check_notify(void *data,
|
|
|
|
Ecore_Thread *th EINA_UNUSED,
|
|
|
|
void *msg EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Thread_Config *thc = data;
|
|
|
|
Instance *inst = thc->inst;
|
|
|
|
|
|
|
|
if (!inst->cfg) return;
|
2017-01-09 07:39:58 -08:00
|
|
|
if (inst->cfg->esm != E_SYSINFO_MODULE_NETSTATUS && inst->cfg->esm != E_SYSINFO_MODULE_SYSINFO) return;
|
|
|
|
|
2017-01-12 12:17:55 -08:00
|
|
|
_netstatus_face_update(inst);
|
2017-01-06 14:15:30 -08:00
|
|
|
}
|
|
|
|
|
2017-01-28 14:50:52 -08:00
|
|
|
static void
|
|
|
|
_netstatus_cb_usage_check_end(void *data, Ecore_Thread *th EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Thread_Config *thc = data;
|
|
|
|
E_FREE_FUNC(thc, free);
|
|
|
|
}
|
|
|
|
|
2017-01-06 14:15:30 -08:00
|
|
|
void
|
|
|
|
_netstatus_config_updated(Instance *inst)
|
|
|
|
{
|
|
|
|
Thread_Config *thc;
|
|
|
|
|
|
|
|
if (inst->cfg->netstatus.usage_check_thread)
|
|
|
|
{
|
|
|
|
ecore_thread_cancel(inst->cfg->netstatus.usage_check_thread);
|
|
|
|
inst->cfg->netstatus.usage_check_thread = NULL;
|
|
|
|
}
|
|
|
|
thc = E_NEW(Thread_Config, 1);
|
|
|
|
if (thc)
|
|
|
|
{
|
|
|
|
thc->inst = inst;
|
|
|
|
thc->interval = inst->cfg->netstatus.poll_interval;
|
|
|
|
inst->cfg->netstatus.usage_check_thread =
|
|
|
|
ecore_thread_feedback_run(_netstatus_cb_usage_check_main,
|
|
|
|
_netstatus_cb_usage_check_notify,
|
2017-01-28 14:50:52 -08:00
|
|
|
_netstatus_cb_usage_check_end,
|
|
|
|
_netstatus_cb_usage_check_end, thc, EINA_TRUE);
|
2017-01-06 14:15:30 -08:00
|
|
|
}
|
|
|
|
e_config_save_queue();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_netstatus_removed_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_data)
|
|
|
|
{
|
|
|
|
Instance *inst = data;
|
|
|
|
|
|
|
|
if (inst->o_main != event_data) return;
|
|
|
|
|
2017-01-11 19:21:34 -08:00
|
|
|
if (inst->cfg->netstatus.popup)
|
|
|
|
E_FREE_FUNC(inst->cfg->netstatus.popup, evas_object_del);
|
|
|
|
if (inst->cfg->netstatus.configure)
|
|
|
|
E_FREE_FUNC(inst->cfg->netstatus.configure, evas_object_del);
|
2017-01-06 14:15:30 -08:00
|
|
|
if (inst->cfg->netstatus.usage_check_thread)
|
|
|
|
{
|
|
|
|
ecore_thread_cancel(inst->cfg->netstatus.usage_check_thread);
|
|
|
|
inst->cfg->netstatus.usage_check_thread = NULL;
|
|
|
|
}
|
2017-01-11 19:21:34 -08:00
|
|
|
E_FREE_FUNC(inst->cfg->netstatus.instring, eina_stringshare_del);
|
|
|
|
E_FREE_FUNC(inst->cfg->netstatus.outstring, eina_stringshare_del);
|
2017-01-11 07:27:43 -08:00
|
|
|
evas_object_event_callback_del_full(inst->o_main, EVAS_CALLBACK_DEL, sysinfo_netstatus_remove, data);
|
2017-01-06 14:15:30 -08:00
|
|
|
|
|
|
|
sysinfo_config->items = eina_list_remove(sysinfo_config->items, inst->cfg);
|
|
|
|
E_FREE(inst->cfg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-11 07:27:43 -08:00
|
|
|
sysinfo_netstatus_remove(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_data EINA_UNUSED)
|
2017-01-06 14:15:30 -08:00
|
|
|
{
|
2017-01-11 07:27:43 -08:00
|
|
|
Instance *inst = data;
|
|
|
|
|
2017-01-11 19:21:34 -08:00
|
|
|
if (inst->cfg->netstatus.popup)
|
|
|
|
E_FREE_FUNC(inst->cfg->netstatus.popup, evas_object_del);
|
|
|
|
if (inst->cfg->netstatus.configure)
|
|
|
|
E_FREE_FUNC(inst->cfg->netstatus.configure, evas_object_del);
|
2017-01-06 14:15:30 -08:00
|
|
|
if (inst->cfg->netstatus.usage_check_thread)
|
|
|
|
{
|
|
|
|
ecore_thread_cancel(inst->cfg->netstatus.usage_check_thread);
|
|
|
|
inst->cfg->netstatus.usage_check_thread = NULL;
|
|
|
|
}
|
2017-01-11 19:21:34 -08:00
|
|
|
E_FREE_FUNC(inst->cfg->netstatus.instring, eina_stringshare_del);
|
|
|
|
E_FREE_FUNC(inst->cfg->netstatus.outstring, eina_stringshare_del);
|
2017-01-06 14:15:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_netstatus_created_cb(void *data, Evas_Object *obj, void *event_data EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Instance *inst = data;
|
2017-02-10 09:59:47 -08:00
|
|
|
E_Gadget_Site_Orient orient = e_gadget_site_orient_get(e_gadget_site_get(inst->o_main));
|
2017-01-06 14:15:30 -08:00
|
|
|
|
2017-01-11 19:21:34 -08:00
|
|
|
e_gadget_configure_cb_set(inst->o_main, _netstatus_configure_cb);
|
|
|
|
|
2017-01-06 14:15:30 -08:00
|
|
|
inst->cfg->netstatus.o_gadget = elm_layout_add(inst->o_main);
|
2017-02-10 09:59:47 -08:00
|
|
|
if (orient == E_GADGET_SITE_ORIENT_VERTICAL)
|
|
|
|
e_theme_edje_object_set(inst->cfg->netstatus.o_gadget,
|
|
|
|
"base/theme/modules/netstatus",
|
|
|
|
"e/modules/netstatus/main_vert");
|
|
|
|
else
|
|
|
|
e_theme_edje_object_set(inst->cfg->netstatus.o_gadget, "base/theme/modules/netstatus",
|
|
|
|
"e/modules/netstatus/main");
|
2017-01-06 14:15:30 -08:00
|
|
|
E_EXPAND(inst->cfg->netstatus.o_gadget);
|
|
|
|
E_FILL(inst->cfg->netstatus.o_gadget);
|
|
|
|
elm_box_pack_end(inst->o_main, inst->cfg->netstatus.o_gadget);
|
2017-01-11 19:21:34 -08:00
|
|
|
evas_object_event_callback_add(inst->cfg->netstatus.o_gadget, EVAS_CALLBACK_MOUSE_DOWN, _netstatus_mouse_down_cb, inst);
|
2017-01-27 12:55:24 -08:00
|
|
|
evas_object_event_callback_add(inst->cfg->netstatus.o_gadget, EVAS_CALLBACK_RESIZE, _netstatus_resize_cb, inst);
|
2017-01-06 14:15:30 -08:00
|
|
|
evas_object_show(inst->cfg->netstatus.o_gadget);
|
|
|
|
evas_object_smart_callback_del_full(obj, "gadget_created", _netstatus_created_cb, data);
|
|
|
|
_netstatus_config_updated(inst);
|
|
|
|
}
|
|
|
|
|
|
|
|
Evas_Object *
|
|
|
|
sysinfo_netstatus_create(Evas_Object *parent, Instance *inst)
|
|
|
|
{
|
|
|
|
inst->cfg->netstatus.o_gadget = elm_layout_add(parent);
|
|
|
|
e_theme_edje_object_set(inst->cfg->netstatus.o_gadget, "base/theme/modules/netstatus",
|
|
|
|
"e/modules/netstatus/main");
|
|
|
|
E_EXPAND(inst->cfg->netstatus.o_gadget);
|
|
|
|
E_FILL(inst->cfg->netstatus.o_gadget);
|
2017-01-11 19:21:34 -08:00
|
|
|
evas_object_event_callback_add(inst->cfg->netstatus.o_gadget, EVAS_CALLBACK_MOUSE_DOWN, _netstatus_mouse_down_cb, inst);
|
2017-01-27 12:55:24 -08:00
|
|
|
evas_object_event_callback_add(inst->cfg->netstatus.o_gadget, EVAS_CALLBACK_RESIZE, _netstatus_resize_cb, inst);
|
2017-01-06 14:15:30 -08:00
|
|
|
evas_object_show(inst->cfg->netstatus.o_gadget);
|
|
|
|
_netstatus_config_updated(inst);
|
|
|
|
|
|
|
|
return inst->cfg->netstatus.o_gadget;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Config_Item *
|
|
|
|
_conf_item_get(int *id)
|
|
|
|
{
|
|
|
|
Config_Item *ci;
|
|
|
|
Eina_List *l;
|
|
|
|
|
|
|
|
if (*id > 0)
|
|
|
|
{
|
|
|
|
EINA_LIST_FOREACH(sysinfo_config->items, l, ci)
|
|
|
|
if (*id == ci->id && ci->esm == E_SYSINFO_MODULE_NETSTATUS) return ci;
|
|
|
|
}
|
|
|
|
|
|
|
|
ci = E_NEW(Config_Item, 1);
|
|
|
|
|
|
|
|
if (*id != -1)
|
|
|
|
ci->id = eina_list_count(sysinfo_config->items)+1;
|
|
|
|
else
|
|
|
|
ci->id = -1;
|
|
|
|
|
|
|
|
ci->esm = E_SYSINFO_MODULE_NETSTATUS;
|
|
|
|
ci->netstatus.poll_interval = 32;
|
2017-01-19 12:17:05 -08:00
|
|
|
ci->netstatus.automax = EINA_TRUE;
|
2017-01-12 12:17:55 -08:00
|
|
|
ci->netstatus.inmax = 0;
|
|
|
|
ci->netstatus.outmax = 0;
|
2017-01-19 12:17:05 -08:00
|
|
|
ci->netstatus.receive_units = NETSTATUS_UNIT_BYTES;
|
|
|
|
ci->netstatus.send_units = NETSTATUS_UNIT_BYTES;
|
|
|
|
ci->netstatus.in = 0;
|
|
|
|
ci->netstatus.out = 0;
|
2017-01-12 12:17:55 -08:00
|
|
|
ci->netstatus.incurrent = 0;
|
|
|
|
ci->netstatus.outcurrent = 0;
|
|
|
|
ci->netstatus.inpercent = 0;
|
|
|
|
ci->netstatus.outpercent = 0;
|
2017-01-11 19:21:34 -08:00
|
|
|
ci->netstatus.instring = NULL;
|
|
|
|
ci->netstatus.outstring = NULL;
|
|
|
|
ci->netstatus.popup = NULL;
|
|
|
|
ci->netstatus.configure = NULL;
|
2017-01-06 14:15:30 -08:00
|
|
|
sysinfo_config->items = eina_list_append(sysinfo_config->items, ci);
|
|
|
|
|
|
|
|
return ci;
|
|
|
|
}
|
|
|
|
|
|
|
|
Evas_Object *
|
|
|
|
netstatus_create(Evas_Object *parent, int *id, E_Gadget_Site_Orient orient EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Instance *inst;
|
|
|
|
|
|
|
|
inst = E_NEW(Instance, 1);
|
|
|
|
inst->cfg = _conf_item_get(id);
|
|
|
|
*id = inst->cfg->id;
|
|
|
|
inst->cfg->netstatus.in = 0;
|
|
|
|
inst->cfg->netstatus.out = 0;
|
2017-01-12 12:17:55 -08:00
|
|
|
inst->cfg->netstatus.incurrent = 0;
|
|
|
|
inst->cfg->netstatus.outcurrent = 0;
|
|
|
|
inst->cfg->netstatus.inpercent = 0;
|
|
|
|
inst->cfg->netstatus.outpercent = 0;
|
2017-01-11 19:21:34 -08:00
|
|
|
inst->cfg->netstatus.instring = NULL;
|
|
|
|
inst->cfg->netstatus.outstring = NULL;
|
|
|
|
inst->cfg->netstatus.popup = NULL;
|
2017-01-06 14:15:30 -08:00
|
|
|
inst->o_main = elm_box_add(parent);
|
|
|
|
E_EXPAND(inst->o_main);
|
2017-01-11 19:21:34 -08:00
|
|
|
evas_object_data_set(inst->o_main, "Instance", inst);
|
2017-01-06 14:15:30 -08:00
|
|
|
evas_object_smart_callback_add(parent, "gadget_created", _netstatus_created_cb, inst);
|
|
|
|
evas_object_smart_callback_add(parent, "gadget_removed", _netstatus_removed_cb, inst);
|
2017-01-11 07:27:43 -08:00
|
|
|
evas_object_event_callback_add(inst->o_main, EVAS_CALLBACK_DEL, sysinfo_netstatus_remove, inst);
|
2017-01-06 14:15:30 -08:00
|
|
|
evas_object_show(inst->o_main);
|
|
|
|
|
|
|
|
if (inst->cfg->id < 0) return inst->o_main;
|
|
|
|
|
|
|
|
sysinfo_instances =
|
|
|
|
eina_list_append(sysinfo_instances, inst);
|
|
|
|
|
|
|
|
return inst->o_main;
|
|
|
|
}
|
|
|
|
|