forked from enlightenment/enlightenment
Enlightenment: Sysinfo gadget - Calculate netstatus max automatically and send percentages to the theme.
This commit is contained in:
parent
7422e9102f
commit
de6ff6f48f
|
@ -104,6 +104,12 @@ sysinfo_init(void)
|
|||
ci->netstatus.poll_interval = 32;
|
||||
ci->netstatus.in = 0;
|
||||
ci->netstatus.out = 0;
|
||||
ci->netstatus.inmax = 0;
|
||||
ci->netstatus.outmax = 0;
|
||||
ci->netstatus.incurrent = 0;
|
||||
ci->netstatus.outcurrent = 0;
|
||||
ci->netstatus.inpercent = 0;
|
||||
ci->netstatus.outpercent = 0;
|
||||
ci->netstatus.instring = NULL;
|
||||
ci->netstatus.outstring = NULL;
|
||||
ci->netstatus.popup = NULL;
|
||||
|
|
|
@ -6,29 +6,43 @@ struct _Thread_Config
|
|||
{
|
||||
int interval;
|
||||
Instance *inst;
|
||||
const char *rstatus;
|
||||
const char *tstatus;
|
||||
int percent;
|
||||
long current;
|
||||
};
|
||||
|
||||
static void
|
||||
_netstatus_face_update(Instance *inst, Eina_Bool trans, const char *status)
|
||||
_netstatus_face_update(Instance *inst)
|
||||
{
|
||||
if (!trans && status)
|
||||
Edje_Message_Int_Set *msg;
|
||||
|
||||
if (inst->cfg->netstatus.incurrent > 0)
|
||||
{
|
||||
elm_layout_signal_emit(inst->cfg->netstatus.o_gadget, "e,state,received,active", "e");
|
||||
}
|
||||
else if (trans && status)
|
||||
{
|
||||
elm_layout_signal_emit(inst->cfg->netstatus.o_gadget, "e,state,transmitted,active", "e");
|
||||
}
|
||||
else if (!trans && !status)
|
||||
else
|
||||
{
|
||||
elm_layout_signal_emit(inst->cfg->netstatus.o_gadget, "e,state,received,idle", "e");
|
||||
}
|
||||
else if (trans && !status)
|
||||
if (inst->cfg->netstatus.outcurrent > 0)
|
||||
{
|
||||
elm_layout_signal_emit(inst->cfg->netstatus.o_gadget, "e,state,transmitted,active", "e");
|
||||
}
|
||||
else
|
||||
{
|
||||
elm_layout_signal_emit(inst->cfg->netstatus.o_gadget, "e,state,transmitted,idle", "e");
|
||||
}
|
||||
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;
|
||||
msg->val[0] = inst->cfg->netstatus.outcurrent;
|
||||
msg->val[1] = inst->cfg->netstatus.outpercent;
|
||||
msg->val[2] = inst->cfg->netstatus.outmax;
|
||||
edje_object_message_send(elm_layout_edje_get(inst->cfg->memusage.o_gadget),
|
||||
EDJE_MESSAGE_INT_SET, 1, msg);
|
||||
free(msg);
|
||||
}
|
||||
|
||||
static Evas_Object *
|
||||
|
@ -113,16 +127,12 @@ _netstatus_cb_usage_check_main(void *data, Ecore_Thread *th)
|
|||
for (;;)
|
||||
{
|
||||
if (ecore_thread_check(th)) break;
|
||||
E_FREE_FUNC(thc->rstatus, eina_stringshare_del);
|
||||
E_FREE_FUNC(thc->tstatus, eina_stringshare_del);
|
||||
thc->rstatus = _netstatus_proc_getrstatus(thc->inst);
|
||||
thc->tstatus = _netstatus_proc_gettstatus(thc->inst);
|
||||
_netstatus_proc_getrstatus(thc->inst);
|
||||
_netstatus_proc_gettstatus(thc->inst);
|
||||
ecore_thread_feedback(th, NULL);
|
||||
if (ecore_thread_check(th)) break;
|
||||
usleep((1000000.0 / 8.0) * (double)thc->interval);
|
||||
}
|
||||
E_FREE_FUNC(thc->rstatus, eina_stringshare_del);
|
||||
E_FREE_FUNC(thc->tstatus, eina_stringshare_del);
|
||||
E_FREE_FUNC(thc, free);
|
||||
}
|
||||
|
||||
|
@ -137,10 +147,7 @@ _netstatus_cb_usage_check_notify(void *data,
|
|||
if (!inst->cfg) return;
|
||||
if (inst->cfg->esm != E_SYSINFO_MODULE_NETSTATUS && inst->cfg->esm != E_SYSINFO_MODULE_SYSINFO) return;
|
||||
|
||||
eina_stringshare_replace(&inst->cfg->netstatus.instring, thc->rstatus);
|
||||
eina_stringshare_replace(&inst->cfg->netstatus.outstring, thc->tstatus);
|
||||
_netstatus_face_update(inst, EINA_FALSE, thc->rstatus);
|
||||
_netstatus_face_update(inst, EINA_TRUE, thc->tstatus);
|
||||
_netstatus_face_update(inst);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -265,6 +272,12 @@ _conf_item_get(int *id)
|
|||
ci->netstatus.poll_interval = 32;
|
||||
ci->netstatus.in = 0;
|
||||
ci->netstatus.out = 0;
|
||||
ci->netstatus.inmax = 0;
|
||||
ci->netstatus.outmax = 0;
|
||||
ci->netstatus.incurrent = 0;
|
||||
ci->netstatus.outcurrent = 0;
|
||||
ci->netstatus.inpercent = 0;
|
||||
ci->netstatus.outpercent = 0;
|
||||
ci->netstatus.instring = NULL;
|
||||
ci->netstatus.outstring = NULL;
|
||||
ci->netstatus.popup = NULL;
|
||||
|
@ -284,6 +297,12 @@ netstatus_create(Evas_Object *parent, int *id, E_Gadget_Site_Orient orient EINA_
|
|||
*id = inst->cfg->id;
|
||||
inst->cfg->netstatus.in = 0;
|
||||
inst->cfg->netstatus.out = 0;
|
||||
inst->cfg->netstatus.inmax = 0;
|
||||
inst->cfg->netstatus.outmax = 0;
|
||||
inst->cfg->netstatus.incurrent = 0;
|
||||
inst->cfg->netstatus.outcurrent = 0;
|
||||
inst->cfg->netstatus.inpercent = 0;
|
||||
inst->cfg->netstatus.outpercent = 0;
|
||||
inst->cfg->netstatus.instring = NULL;
|
||||
inst->cfg->netstatus.outstring = NULL;
|
||||
inst->cfg->netstatus.popup = NULL;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "../sysinfo.h"
|
||||
|
||||
void _netstatus_config_updated(Instance *inst);
|
||||
const char *_netstatus_proc_getrstatus(Instance *inst);
|
||||
const char *_netstatus_proc_gettstatus(Instance *inst);
|
||||
void _netstatus_proc_getrstatus(Instance *inst);
|
||||
void _netstatus_proc_gettstatus(Instance *inst);
|
||||
Evas_Object *netstatus_configure(Instance *inst);
|
||||
#endif
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
#include "netstatus.h"
|
||||
|
||||
const char *
|
||||
void
|
||||
_netstatus_proc_getrstatus(Instance *inst)
|
||||
{
|
||||
long in, dummy, tot_in = 0;
|
||||
long diffin;
|
||||
int percent = 0;
|
||||
char buf[4096], rin[4096], dummys[64];
|
||||
FILE *f;
|
||||
|
||||
|
@ -24,13 +25,14 @@ _netstatus_proc_getrstatus(Instance *inst)
|
|||
}
|
||||
diffin = tot_in - inst->cfg->netstatus.in;
|
||||
inst->cfg->netstatus.in = tot_in;
|
||||
if (tot_in > inst->cfg->netstatus.inmax)
|
||||
inst->cfg->netstatus.inmax = tot_in;
|
||||
if (!diffin)
|
||||
{
|
||||
snprintf(rin, sizeof(rin), "%s: 0 B/s", _("Receiving"));
|
||||
return eina_stringshare_add(rin);
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
diffin /= 0.5;
|
||||
if (diffin > 1048576)
|
||||
snprintf(rin, sizeof(rin), "%s: %.2f MB/s", _("Receiving"), ((float)diffin / 1048576));
|
||||
|
@ -39,14 +41,22 @@ _netstatus_proc_getrstatus(Instance *inst)
|
|||
else
|
||||
snprintf(rin, sizeof(rin), "%s: %lu B/s", _("Receiving"), diffin);
|
||||
}
|
||||
return eina_stringshare_add(rin);
|
||||
inst->cfg->netstatus.incurrent = diffin;
|
||||
if (inst->cfg->netstatus.inmax > 0)
|
||||
percent = 100 * ((float)diffin / (float)inst->cfg->netstatus.inmax);
|
||||
|
||||
if (percent > 100) percent = 100;
|
||||
else if (percent < 0) percent = 0;
|
||||
inst->cfg->netstatus.inpercent = percent;
|
||||
eina_stringshare_replace(&inst->cfg->netstatus.instring, rin);
|
||||
}
|
||||
|
||||
const char *
|
||||
_netstatus_proc_gettstatus(Instance *inst)
|
||||
void
|
||||
_netstatus_proc_gettstatus(Instance *inst)
|
||||
{
|
||||
long out, dummy, tot_out = 0;
|
||||
long diffout;
|
||||
int percent = 0;
|
||||
char buf[4096], rout[4096], dummys[64];
|
||||
FILE *f;
|
||||
|
||||
|
@ -66,10 +76,11 @@ const char *
|
|||
}
|
||||
diffout = tot_out - inst->cfg->netstatus.out;
|
||||
inst->cfg->netstatus.out = tot_out;
|
||||
if (tot_out > inst->cfg->netstatus.outmax)
|
||||
inst->cfg->netstatus.outmax = tot_out;
|
||||
if (!diffout)
|
||||
{
|
||||
snprintf(rout, sizeof(rout), "%s: 0 B/s", _("Sending"));
|
||||
return eina_stringshare_add(rout);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -81,6 +92,13 @@ const char *
|
|||
else
|
||||
snprintf(rout, sizeof(rout), "%s: %lu B/s", _("Sending"), diffout);
|
||||
}
|
||||
return eina_stringshare_add(rout);
|
||||
inst->cfg->netstatus.outcurrent = diffout;
|
||||
if (inst->cfg->netstatus.outcurrent > 0)
|
||||
percent = 100 * ((float)diffout / (float)inst->cfg->netstatus.outmax);
|
||||
|
||||
if (percent > 100) percent = 100;
|
||||
else if (percent < 0) percent = 0;
|
||||
inst->cfg->netstatus.outpercent = percent;
|
||||
eina_stringshare_replace(&inst->cfg->netstatus.outstring, rout);
|
||||
}
|
||||
|
||||
|
|
|
@ -125,6 +125,12 @@ _conf_item_get(int *id)
|
|||
ci->netstatus.poll_interval = 32;
|
||||
ci->netstatus.in = 0;
|
||||
ci->netstatus.out = 0;
|
||||
ci->netstatus.inmax = 0;
|
||||
ci->netstatus.outmax = 0;
|
||||
ci->netstatus.incurrent = 0;
|
||||
ci->netstatus.outcurrent = 0;
|
||||
ci->netstatus.inpercent = 0;
|
||||
ci->netstatus.outpercent = 0;
|
||||
ci->netstatus.instring = NULL;
|
||||
ci->netstatus.outstring = NULL;
|
||||
ci->netstatus.popup = NULL;
|
||||
|
|
|
@ -206,6 +206,12 @@ struct _Config_Item
|
|||
int poll_interval;
|
||||
long in;
|
||||
long out;
|
||||
long incurrent;
|
||||
long outcurrent;
|
||||
long inmax;
|
||||
long outmax;
|
||||
int inpercent;
|
||||
int outpercent;
|
||||
Eina_Stringshare *instring;
|
||||
Eina_Stringshare *outstring;
|
||||
Ecore_Thread *usage_check_thread;
|
||||
|
|
Loading…
Reference in New Issue