summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen 'Okra' Houston <smhouston88@gmail.com>2017-01-15 13:34:04 -0600
committerStephen 'Okra' Houston <smhouston88@gmail.com>2017-01-15 13:34:04 -0600
commit638d5d502fd02a47beb9ce5c33418dbb8965c0cd (patch)
tree2f7928a7a5d463b080b32be9eb0c371a49f1cce5
parent0caaf5fabe94f82ce372d98b92b4e6fe6528595c (diff)
Enlightenment: - Sysinfo gadget - Calculate net percentages correctly.
-rw-r--r--src/modules/sysinfo/netstatus/netstatus.c6
-rw-r--r--src/modules/sysinfo/netstatus/netstatus_proc.c48
2 files changed, 34 insertions, 20 deletions
diff --git a/src/modules/sysinfo/netstatus/netstatus.c b/src/modules/sysinfo/netstatus/netstatus.c
index 6f715fd17..4c2633fd8 100644
--- a/src/modules/sysinfo/netstatus/netstatus.c
+++ b/src/modules/sysinfo/netstatus/netstatus.c
@@ -206,6 +206,9 @@ _netstatus_created_cb(void *data, Evas_Object *obj, void *event_data EINA_UNUSED
206 206
207 e_gadget_configure_cb_set(inst->o_main, _netstatus_configure_cb); 207 e_gadget_configure_cb_set(inst->o_main, _netstatus_configure_cb);
208 208
209 inst->cfg->netstatus.inmax = 0;
210 inst->cfg->netstatus.outmax = 0;
211
209 inst->cfg->netstatus.o_gadget = elm_layout_add(inst->o_main); 212 inst->cfg->netstatus.o_gadget = elm_layout_add(inst->o_main);
210 e_theme_edje_object_set(inst->cfg->netstatus.o_gadget, "base/theme/modules/netstatus", 213 e_theme_edje_object_set(inst->cfg->netstatus.o_gadget, "base/theme/modules/netstatus",
211 "e/modules/netstatus/main"); 214 "e/modules/netstatus/main");
@@ -221,6 +224,9 @@ _netstatus_created_cb(void *data, Evas_Object *obj, void *event_data EINA_UNUSED
221Evas_Object * 224Evas_Object *
222sysinfo_netstatus_create(Evas_Object *parent, Instance *inst) 225sysinfo_netstatus_create(Evas_Object *parent, Instance *inst)
223{ 226{
227 inst->cfg->netstatus.inmax = 0;
228 inst->cfg->netstatus.outmax = 0;
229
224 inst->cfg->netstatus.o_gadget = elm_layout_add(parent); 230 inst->cfg->netstatus.o_gadget = elm_layout_add(parent);
225 e_theme_edje_object_set(inst->cfg->netstatus.o_gadget, "base/theme/modules/netstatus", 231 e_theme_edje_object_set(inst->cfg->netstatus.o_gadget, "base/theme/modules/netstatus",
226 "e/modules/netstatus/main"); 232 "e/modules/netstatus/main");
diff --git a/src/modules/sysinfo/netstatus/netstatus_proc.c b/src/modules/sysinfo/netstatus/netstatus_proc.c
index f7609e5db..86d6ae372 100644
--- a/src/modules/sysinfo/netstatus/netstatus_proc.c
+++ b/src/modules/sysinfo/netstatus/netstatus_proc.c
@@ -24,9 +24,20 @@ _netstatus_proc_getrstatus(Instance *inst)
24 fclose(f); 24 fclose(f);
25 } 25 }
26 diffin = tot_in - inst->cfg->netstatus.in; 26 diffin = tot_in - inst->cfg->netstatus.in;
27 inst->cfg->netstatus.in = tot_in; 27 if (!inst->cfg->netstatus.in)
28 if (tot_in > inst->cfg->netstatus.inmax) 28 inst->cfg->netstatus.in = tot_in;
29 inst->cfg->netstatus.inmax = tot_in; 29 else
30 {
31 inst->cfg->netstatus.in = tot_in;
32 if (diffin > inst->cfg->netstatus.inmax)
33 inst->cfg->netstatus.inmax = diffin;
34 inst->cfg->netstatus.incurrent = diffin;
35 if (inst->cfg->netstatus.inmax > 0)
36 percent = 100 * ((float)inst->cfg->netstatus.incurrent / (float)inst->cfg->netstatus.inmax);
37 if (percent > 100) percent = 100;
38 else if (percent < 0) percent = 0;
39 inst->cfg->netstatus.inpercent = percent;
40 }
30 if (!diffin) 41 if (!diffin)
31 { 42 {
32 snprintf(rin, sizeof(rin), "%s: 0 B/s", _("Receiving")); 43 snprintf(rin, sizeof(rin), "%s: 0 B/s", _("Receiving"));
@@ -41,13 +52,6 @@ _netstatus_proc_getrstatus(Instance *inst)
41 else 52 else
42 snprintf(rin, sizeof(rin), "%s: %lu B/s", _("Receiving"), diffin); 53 snprintf(rin, sizeof(rin), "%s: %lu B/s", _("Receiving"), diffin);
43 } 54 }
44 inst->cfg->netstatus.incurrent = diffin;
45 if (inst->cfg->netstatus.inmax > 0)
46 percent = 100 * ((float)diffin / (float)inst->cfg->netstatus.inmax);
47
48 if (percent > 100) percent = 100;
49 else if (percent < 0) percent = 0;
50 inst->cfg->netstatus.inpercent = percent;
51 eina_stringshare_replace(&inst->cfg->netstatus.instring, rin); 55 eina_stringshare_replace(&inst->cfg->netstatus.instring, rin);
52} 56}
53 57
@@ -75,9 +79,20 @@ _netstatus_proc_gettstatus(Instance *inst)
75 fclose(f); 79 fclose(f);
76 } 80 }
77 diffout = tot_out - inst->cfg->netstatus.out; 81 diffout = tot_out - inst->cfg->netstatus.out;
78 inst->cfg->netstatus.out = tot_out; 82 if (!inst->cfg->netstatus.out)
79 if (tot_out > inst->cfg->netstatus.outmax) 83 inst->cfg->netstatus.out = tot_out;
80 inst->cfg->netstatus.outmax = tot_out; 84 else
85 {
86 inst->cfg->netstatus.out = tot_out;
87 if (diffout > inst->cfg->netstatus.outmax)
88 inst->cfg->netstatus.outmax = diffout;
89 inst->cfg->netstatus.outcurrent = diffout;
90 if (inst->cfg->netstatus.outcurrent > 0)
91 percent = 100 * ((float)inst->cfg->netstatus.outcurrent / (float)inst->cfg->netstatus.outmax);
92 if (percent > 100) percent = 100;
93 else if (percent < 0) percent = 0;
94 inst->cfg->netstatus.outpercent = percent;
95 }
81 if (!diffout) 96 if (!diffout)
82 { 97 {
83 snprintf(rout, sizeof(rout), "%s: 0 B/s", _("Sending")); 98 snprintf(rout, sizeof(rout), "%s: 0 B/s", _("Sending"));
@@ -92,13 +107,6 @@ _netstatus_proc_gettstatus(Instance *inst)
92 else 107 else
93 snprintf(rout, sizeof(rout), "%s: %lu B/s", _("Sending"), diffout); 108 snprintf(rout, sizeof(rout), "%s: %lu B/s", _("Sending"), diffout);
94 } 109 }
95 inst->cfg->netstatus.outcurrent = diffout;
96 if (inst->cfg->netstatus.outcurrent > 0)
97 percent = 100 * ((float)diffout / (float)inst->cfg->netstatus.outmax);
98
99 if (percent > 100) percent = 100;
100 else if (percent < 0) percent = 0;
101 inst->cfg->netstatus.outpercent = percent;
102 eina_stringshare_replace(&inst->cfg->netstatus.outstring, rout); 110 eina_stringshare_replace(&inst->cfg->netstatus.outstring, rout);
103} 111}
104 112