Allow setting of display mode for Bytes, KB, or MB. User configurable

SVN revision: 20659
This commit is contained in:
Christopher Michael 2006-02-21 02:39:54 +00:00
parent 724aa6d51c
commit 9f034d155c
4 changed files with 64 additions and 41 deletions

View File

@ -7,6 +7,7 @@ struct _E_Config_Dialog_Data
{
char *device;
int check_interval;
int display_mode;
Ecore_List *devs;
int dev_num;
@ -50,10 +51,12 @@ _fill_data(Net_Face *nf, E_Config_Dialog_Data *cfdata)
cfdata->device = strdup(nf->conf->device);
else
cfdata->device = NULL;
cfdata->display_mode = nf->conf->display_mode;
if (!cfdata->device)
return;
cfdata->devs = ecore_list_new();
_net_config_get_devices(cfdata->devs);
@ -104,10 +107,21 @@ _basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cf
int i;
o = e_widget_list_add(evas, 0, 0);
of = e_widget_framelist_add(evas, _("Display Settings"), 0);
ot = e_widget_table_add(evas, 0);
rg = e_widget_radio_group_new(&(cfdata->display_mode));
ob = e_widget_radio_add(evas, _("Show In Bytes"), NET_DISPLAY_BYTES, rg);
e_widget_table_object_append (ot, ob, 0, 0, 1, 1, 1, 0, 1, 0);
ob = e_widget_radio_add(evas, _("Show In KBytes"), NET_DISPLAY_KBYTES, rg);
e_widget_table_object_append (ot, ob, 0, 1, 1, 1, 1, 0, 1, 0);
ob = e_widget_radio_add(evas, _("Show In MBytes"), NET_DISPLAY_MBYTES, rg);
e_widget_table_object_append (ot, ob, 0, 2, 1, 1, 1, 0, 1, 0);
e_widget_framelist_object_append(of, ot);
e_widget_list_object_append(o, of, 1, 1, 0.5);
of = e_widget_framelist_add(evas, _("Device Settings"), 0);
ot = e_widget_table_add(evas, 0);
ot = e_widget_table_add(evas, 0);
rg = e_widget_radio_group_new(&(cfdata->dev_num));
i = 0;
ecore_list_goto_first(cfdata->devs);
while ((tmp = ecore_list_next(cfdata->devs)) != NULL)
@ -139,6 +153,7 @@ _basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
if (tmp != NULL)
nf->conf->device = (char *)evas_stringshare_add(strdup(tmp));
nf->conf->check_interval = cfdata->check_interval;
nf->conf->display_mode = cfdata->display_mode;
e_config_save_queue ();
if (nf->monitor)

View File

@ -143,6 +143,7 @@ _net_init(E_Module *m)
E_CONFIG_VAL(D, T, enabled, UCHAR);
E_CONFIG_VAL(D, T, device, STR);
E_CONFIG_VAL(D, T, check_interval, INT);
E_CONFIG_VAL(D, T, display_mode, INT);
conf_edd = E_CONFIG_DD_NEW("Net_Config", Config);
#undef T
@ -180,6 +181,7 @@ _net_init(E_Module *m)
nf->conf->enabled = 1;
nf->conf->device = (char *)evas_stringshare_add("eth0");
nf->conf->check_interval = 30;
nf->conf->display_mode = NET_DISPLAY_MBYTES;
n->conf->faces = evas_list_append(n->conf->faces, nf->conf);
}
else
@ -188,7 +190,8 @@ _net_init(E_Module *m)
fl = fl->next;
}
E_CONFIG_LIMIT(nf->conf->check_interval, 0, 60);
E_CONFIG_LIMIT(nf->conf->display_mode, NET_DISPLAY_BYTES, NET_DISPLAY_MBYTES);
nf->monitor = ecore_timer_add((double)nf->conf->check_interval, _net_face_update_values, nf);
_net_face_menu_new(nf);
@ -481,18 +484,41 @@ _net_face_update_values(void *data)
old_out = out;
else
out = 0;
/* Graph values */
/* _net_face_graph_values(nf, in, out); */
/* Update the modules text */
Edje_Message_Int_Set *msg;
Edje_Message_String_Set *msg;
char in_str[100];
char out_str[100];
msg = malloc(sizeof(Edje_Message_Int_Set) + 1 * sizeof(int));
switch (nf->conf->display_mode)
{
case NET_DISPLAY_BYTES:
snprintf(in_str, sizeof(in_str), "%d B", in);
snprintf(out_str, sizeof(out_str), "%d B", out);
break;
case NET_DISPLAY_KBYTES:
//if ((in > 1024) && (in < 1048576))
in = in / 1024;
//if ((out > 1024) && (out < 1048576))
out = out / 1024;
snprintf(in_str, sizeof(in_str), "%d KB", in);
snprintf(out_str, sizeof(out_str), "%d KB", out);
break;
case NET_DISPLAY_MBYTES:
//if (in > 1048576)
in = in / 1048576;
//if (out > 1048576)
out = out / 1048576;
snprintf(in_str, sizeof(in_str), "%d MB", in);
snprintf(out_str, sizeof(out_str), "%d MB", out);
break;
}
msg = malloc(sizeof(Edje_Message_String_Set) - sizeof(char *) + (1 + sizeof(char *)));
msg->count = 2;
msg->val[0] = in;
msg->val[1] = out;
edje_object_message_send(nf->net_obj, EDJE_MESSAGE_INT_SET, 1, msg);
msg->str[0] = in_str;
msg->str[1] = out_str;
edje_object_message_send(nf->net_obj, EDJE_MESSAGE_STRING_SET, 1, msg);
free(msg);
return 1;

View File

@ -5,6 +5,12 @@ typedef struct _Config Config;
typedef struct _Config_Face Config_Face;
typedef struct _Net Net;
typedef struct _Net_Face Net_Face;
typedef enum _Display_Mode
{
NET_DISPLAY_BYTES,
NET_DISPLAY_KBYTES,
NET_DISPLAY_MBYTES
} Display_Mode;
struct _Config
{
@ -16,6 +22,7 @@ struct _Config_Face
unsigned char enabled;
char *device;
int check_interval;
int display_mode;
};
struct _Net

33
net.edc
View File

@ -15,38 +15,13 @@ group
name: "modules/net/main";
script {
public message(Msg_Type:type, id, ...) {
if (type == MSG_INT_SET) {
new tmp;
if (type == MSG_STRING_SET) {
new in_str[64];
new out_str[64];
tmp = getarg(2);
if (tmp > 1048576) {
tmp = tmp / 1048576;
snprintf(in_str, sizeof(in_str), "%i MB", tmp);
}
else if (tmp > 1024 && tmp < 1048576) {
tmp = tmp / 1024;
snprintf(in_str, sizeof(in_str), "%i KB", tmp);
}
else {
snprintf(in_str, sizeof(in_str), "%i B", tmp);
}
getsarg(2, in_str, sizeof(in_str));
getsarg(3, out_str, sizeof(out_str));
set_text(PART:"in-text", in_str);
tmp = getarg(3);
if (tmp > 1048576) {
tmp = tmp / 1048576;
snprintf(out_str, sizeof(out_str), "%i MB", tmp);
}
else if (tmp > 1024 && tmp < 1048576) {
tmp = tmp / 1024;
snprintf(out_str, sizeof(out_str), "%i KB", tmp);
}
else {
snprintf(out_str, sizeof(out_str), "%i B", tmp);
}
set_text(PART:"out-text", out_str);
set_text(PART:"out-text", out_str);
}
}
}