forked from enlightenment/enlightenment
Enlightenment: - Sysinfo gadget - Calculate net percentages correctly.
This commit is contained in:
parent
0caaf5fabe
commit
638d5d502f
|
@ -206,6 +206,9 @@ _netstatus_created_cb(void *data, Evas_Object *obj, void *event_data EINA_UNUSED
|
|||
|
||||
e_gadget_configure_cb_set(inst->o_main, _netstatus_configure_cb);
|
||||
|
||||
inst->cfg->netstatus.inmax = 0;
|
||||
inst->cfg->netstatus.outmax = 0;
|
||||
|
||||
inst->cfg->netstatus.o_gadget = elm_layout_add(inst->o_main);
|
||||
e_theme_edje_object_set(inst->cfg->netstatus.o_gadget, "base/theme/modules/netstatus",
|
||||
"e/modules/netstatus/main");
|
||||
|
@ -221,6 +224,9 @@ _netstatus_created_cb(void *data, Evas_Object *obj, void *event_data EINA_UNUSED
|
|||
Evas_Object *
|
||||
sysinfo_netstatus_create(Evas_Object *parent, Instance *inst)
|
||||
{
|
||||
inst->cfg->netstatus.inmax = 0;
|
||||
inst->cfg->netstatus.outmax = 0;
|
||||
|
||||
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");
|
||||
|
|
|
@ -24,9 +24,20 @@ _netstatus_proc_getrstatus(Instance *inst)
|
|||
fclose(f);
|
||||
}
|
||||
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 (!inst->cfg->netstatus.in)
|
||||
inst->cfg->netstatus.in = tot_in;
|
||||
else
|
||||
{
|
||||
inst->cfg->netstatus.in = tot_in;
|
||||
if (diffin > inst->cfg->netstatus.inmax)
|
||||
inst->cfg->netstatus.inmax = diffin;
|
||||
inst->cfg->netstatus.incurrent = diffin;
|
||||
if (inst->cfg->netstatus.inmax > 0)
|
||||
percent = 100 * ((float)inst->cfg->netstatus.incurrent / (float)inst->cfg->netstatus.inmax);
|
||||
if (percent > 100) percent = 100;
|
||||
else if (percent < 0) percent = 0;
|
||||
inst->cfg->netstatus.inpercent = percent;
|
||||
}
|
||||
if (!diffin)
|
||||
{
|
||||
snprintf(rin, sizeof(rin), "%s: 0 B/s", _("Receiving"));
|
||||
|
@ -41,13 +52,6 @@ _netstatus_proc_getrstatus(Instance *inst)
|
|||
else
|
||||
snprintf(rin, sizeof(rin), "%s: %lu B/s", _("Receiving"), diffin);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -75,9 +79,20 @@ _netstatus_proc_gettstatus(Instance *inst)
|
|||
fclose(f);
|
||||
}
|
||||
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 (!inst->cfg->netstatus.out)
|
||||
inst->cfg->netstatus.out = tot_out;
|
||||
else
|
||||
{
|
||||
inst->cfg->netstatus.out = tot_out;
|
||||
if (diffout > inst->cfg->netstatus.outmax)
|
||||
inst->cfg->netstatus.outmax = diffout;
|
||||
inst->cfg->netstatus.outcurrent = diffout;
|
||||
if (inst->cfg->netstatus.outcurrent > 0)
|
||||
percent = 100 * ((float)inst->cfg->netstatus.outcurrent / (float)inst->cfg->netstatus.outmax);
|
||||
if (percent > 100) percent = 100;
|
||||
else if (percent < 0) percent = 0;
|
||||
inst->cfg->netstatus.outpercent = percent;
|
||||
}
|
||||
if (!diffout)
|
||||
{
|
||||
snprintf(rout, sizeof(rout), "%s: 0 B/s", _("Sending"));
|
||||
|
@ -92,13 +107,6 @@ _netstatus_proc_gettstatus(Instance *inst)
|
|||
else
|
||||
snprintf(rout, sizeof(rout), "%s: %lu B/s", _("Sending"), diffout);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue