Enlightenment CVS committal

Author  : devilhorns
Project : e_modules
Module  : net

Dir     : e_modules/net


Modified Files:
        net.edc e_mod_main.h e_mod_main.c e_mod_config.c 


Log Message:
Allow setting of display mode for Bytes, KB, or MB. User configurable
===================================================================
RCS file: /cvsroot/enlightenment/e_modules/net/net.edc,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -3 -r1.8 -r1.9
--- net.edc     19 Feb 2006 21:18:36 -0000      1.8
+++ net.edc     21 Feb 2006 02:39:54 -0000      1.9
@@ -15,38 +15,13 @@
       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);             
                                                
                      }
               }      
       }
===================================================================
RCS file: /cvsroot/enlightenment/e_modules/net/e_mod_main.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- e_mod_main.h        21 Feb 2006 02:09:49 -0000      1.2
+++ e_mod_main.h        21 Feb 2006 02:39:54 -0000      1.3
@@ -5,6 +5,12 @@
 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 @@
    unsigned char enabled;
    char *device;
    int check_interval;
+   int display_mode;
 };
 
 struct _Net 
===================================================================
RCS file: /cvsroot/enlightenment/e_modules/net/e_mod_main.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- e_mod_main.c        21 Feb 2006 02:09:49 -0000      1.3
+++ e_mod_main.c        21 Feb 2006 02:39:54 -0000      1.4
@@ -143,6 +143,7 @@
    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 @@
                       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 @@
                       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 @@
      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];
+   
+   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_Int_Set) + 1 * sizeof(int));
+   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;
===================================================================
RCS file: /cvsroot/enlightenment/e_modules/net/e_mod_config.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- e_mod_config.c      21 Feb 2006 02:09:49 -0000      1.3
+++ e_mod_config.c      21 Feb 2006 02:39:54 -0000      1.4
@@ -7,6 +7,7 @@
 {
    char *device;
    int check_interval;
+   int display_mode;
    
    Ecore_List *devs;
    int dev_num;
@@ -50,10 +51,12 @@
      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 @@
    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 @@
    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)




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to