Enlightenment CVS committal Author : devilhorns Project : e_modules Module : wlan
Dir : e_modules/wlan Modified Files: e_mod_main.h e_mod_main.c e_mod_config.h e_mod_config.c wlan.edc Log Message: Fixed WLan module :). Should work well now for everyone. Updated to handle faces too :) =================================================================== RCS file: /cvsroot/enlightenment/e_modules/wlan/e_mod_main.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- e_mod_main.h 20 Feb 2006 15:15:32 -0000 1.1 +++ e_mod_main.h 21 Feb 2006 12:12:51 -0000 1.2 @@ -5,25 +5,31 @@ typedef struct _Config_Face Config_Face; typedef struct _Wlan Wlan; typedef struct _Wlan_Face Wlan_Face; +typedef enum _Display_Mode +{ + NET_DISPLAY_BYTES, + NET_DISPLAY_KBYTES, + NET_DISPLAY_MBYTES +} Display_Mode; struct _Config { - char *device; - int check_interval; + Evas_List *faces; }; struct _Config_Face { unsigned char enabled; + char *device; + int check_interval; + int display_mode; }; struct _Wlan { E_Menu *config_menu; - Wlan_Face *face; + Evas_List *faces; Config *conf; - - E_Config_DD *conf_edd; E_Config_Dialog *cfd; }; @@ -35,7 +41,6 @@ Wlan *wlan; Config_Face *conf; - E_Config_DD *conf_face_edd; Evas_Object *wlan_obj; Evas_Object *event_obj; =================================================================== RCS file: /cvsroot/enlightenment/e_modules/wlan/e_mod_main.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -3 -r1.4 -r1.5 --- e_mod_main.c 20 Feb 2006 19:58:01 -0000 1.4 +++ e_mod_main.c 21 Feb 2006 12:12:51 -0000 1.5 @@ -3,22 +3,24 @@ #include "e_mod_config.h" #include "config.h" -static Wlan *_wlan_init(E_Module *m); -static void _wlan_shutdown(Wlan *n); -static void _wlan_config_menu_new(Wlan *n); - -static int _wlan_face_init(Wlan_Face *nf); -static void _wlan_face_menu_new(Wlan_Face *nf); -static void _wlan_face_enable(Wlan_Face *nf); -static void _wlan_face_disable(Wlan_Face *nf); -static void _wlan_face_free(Wlan_Face *nf); -static void _wlan_face_cb_gmc_change(void *data, E_Gadman_Client *gmc, E_Gadman_Change change); -static void _wlan_face_cb_mouse_down(void *data, Evas *evas, Evas_Object *obj, void *event_info); -static void _wlan_face_cb_menu_edit(void *data, E_Menu *mn, E_Menu_Item *mi); -static void _wlan_face_cb_menu_configure(void *data, E_Menu *mn, E_Menu_Item *mi); -static int _wlan_face_update_values(void *data); +static Wlan *_wlan_init(E_Module *m); +static void _wlan_shutdown(Wlan *n); +static void _wlan_config_menu_new(Wlan *n); + +static Wlan_Face *_wlan_face_init(Wlan *n, E_Container *con); +static void _wlan_face_menu_new(Wlan_Face *nf); +static void _wlan_face_enable(Wlan_Face *nf); +static void _wlan_face_disable(Wlan_Face *nf); +static void _wlan_face_free(Wlan_Face *nf); +static void _wlan_face_cb_gmc_change(void *data, E_Gadman_Client *gmc, E_Gadman_Change change); +static void _wlan_face_cb_mouse_down(void *data, Evas *evas, Evas_Object *obj, void *event_info); +static void _wlan_face_cb_menu_edit(void *data, E_Menu *mn, E_Menu_Item *mi); +static void _wlan_face_cb_menu_configure(void *data, E_Menu *mn, E_Menu_Item *mi); +static int _wlan_face_update_values(void *data); static int wlan_count; +static E_Config_DD *conf_edd; +static E_Config_DD *conf_face_edd; EAPI E_Module_Api e_modapi = { @@ -71,7 +73,7 @@ n = m->data; if (!n) return 0; - e_config_domain_save("module.wlan", n->conf_edd, n->conf); + e_config_domain_save("module.wlan", conf_edd, n->conf); return 1; } @@ -85,7 +87,7 @@ EAPI int e_modapi_about(E_Module *m) { - e_module_dialog_show(_("Enlightenment WLan Monitor Module"), + e_module_dialog_show(_("Enlightenment Wlan Monitor Module"), _("This module is used to monitor a wlan device.")); return 1; } @@ -94,18 +96,30 @@ e_modapi_config(E_Module *m) { Wlan *n; + Evas_List *l; E_Container *con; n = m->data; if (!n) return 0; - if (!n->face) + if (!n->faces) return 0; - con = e_container_current_get(e_manager_current_get()); - if (n->face->con == con) - _configure_wlan_module(con, n); - + for (l = n->faces; l; l = l->next) + { + Wlan_Face *nf; + + nf = l->data; + if (!nf) + continue; + + con = e_container_current_get(e_manager_current_get()); + if (nf->con == con) + { + _configure_wlan_module(nf); + break; + } + } return 1; } @@ -114,32 +128,37 @@ { Wlan *n; E_Menu_Item *mi; - Evas_List *mans, *l, *l2; + Evas_List *mans, *l, *l2, *fl; n = E_NEW(Wlan, 1); if (!n) return NULL; - n->conf_edd = E_CONFIG_DD_NEW("Wlan_Config", Config); + conf_face_edd = E_CONFIG_DD_NEW("Wlan_Config_Face", Config_Face); #undef T #undef D - #define T Config - #define D n->conf_edd + #define T Config_Face + #define D conf_face_edd + 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); - n->conf = e_config_domain_load("module.wlan", n->conf_edd); + conf_edd = E_CONFIG_DD_NEW("Wlan_Config", Config); + #undef T + #undef D + #define T Config + #define D conf_edd + E_CONFIG_LIST(D, T, faces, conf_face_edd); + + n->conf = e_config_domain_load("module.wlan", conf_edd); if (!n->conf) - { - n->conf = E_NEW(Config, 1); - n->conf->device = (char *)evas_stringshare_add("wlan0"); - n->conf->check_interval = 30; - } - E_CONFIG_LIMIT(n->conf->check_interval, 0, 60); + n->conf = E_NEW(Config, 1); _wlan_config_menu_new(n); mans = e_manager_list(); + fl = n->conf->faces; for (l = mans; l; l = l->next) { E_Manager *man; @@ -151,26 +170,27 @@ Wlan_Face *nf; con = l2->data; - nf = E_NEW(Wlan_Face, 1); + nf = _wlan_face_init(n, con); if (nf) { - nf->conf_face_edd = E_CONFIG_DD_NEW("Wlan_Face_Config", Config_Face); - #undef T - #undef D - #define T Config_Face - #define D nf->conf_face_edd - E_CONFIG_VAL(D, T, enabled, UCHAR); - - n->face = nf; - nf->wlan = n; - nf->con = con; - nf->evas = con->bg_evas; - - nf->conf = E_NEW(Config_Face, 1); - nf->conf->enabled = 1; + if (!fl) + { + nf->conf = E_NEW(Config_Face, 1); + nf->conf->enabled = 1; + nf->conf->device = (char *)evas_stringshare_add("wlan0"); + nf->conf->check_interval = 30; + nf->conf->display_mode = NET_DISPLAY_MBYTES; + n->conf->faces = evas_list_append(n->conf->faces, nf->conf); + } + else + { + nf->conf = fl->data; + 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); - if (!_wlan_face_init(nf)) - return NULL; + nf->monitor = ecore_timer_add((double)nf->conf->check_interval, _wlan_face_update_values, nf); _wlan_face_menu_new(nf); @@ -184,8 +204,6 @@ if (!nf->conf->enabled) _wlan_face_disable(nf); - else - _wlan_face_enable(nf); } } } @@ -195,13 +213,16 @@ static void _wlan_shutdown(Wlan *n) { - _wlan_face_free(n->face); + E_CONFIG_DD_FREE(conf_edd); + E_CONFIG_DD_FREE(conf_face_edd); - if (n->conf->device) - evas_stringshare_del(n->conf->device); + while (n->faces) + _wlan_face_free(n->faces->data); + + e_object_del(E_OBJECT(n->config_menu)); + evas_list_free(n->conf->faces); E_FREE(n->conf); - E_CONFIG_DD_FREE(n->conf_edd); E_FREE(n); } @@ -214,11 +235,22 @@ n->config_menu = mn; } -static int -_wlan_face_init(Wlan_Face *nf) +static Wlan_Face * +_wlan_face_init(Wlan *n, E_Container *con) { + Wlan_Face *nf; Evas_Object *o; char buf[4096]; + + nf = E_NEW(Wlan_Face, 1); + if (!nf) + return NULL; + nf->wlan = n; + n->faces = evas_list_append(n->faces, nf); + + nf->con = con; + e_object_ref(E_OBJECT(con)); + nf->evas = con->bg_evas; evas_event_freeze(nf->evas); @@ -232,13 +264,14 @@ } evas_object_show(o); - + o = evas_object_rectangle_add(nf->evas); nf->event_obj = o; evas_object_layer_set(o, 2); evas_object_repeat_events_set(o, 1); evas_object_color_set(o, 0, 0, 0, 0); - evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _wlan_face_cb_mouse_down, nf); + evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, + _wlan_face_cb_mouse_down, nf); evas_object_show(o); nf->gmc = e_gadman_client_new(nf->con->gadman); @@ -258,9 +291,8 @@ e_gadman_client_change_func_set(nf->gmc, _wlan_face_cb_gmc_change, nf); e_gadman_client_load(nf->gmc); evas_event_thaw(nf->evas); - - nf->monitor = ecore_timer_add((double)nf->wlan->conf->check_interval, _wlan_face_update_values, nf); - return 1; + + return nf; } static void @@ -274,12 +306,12 @@ mi = e_menu_item_new(mn); e_menu_item_label_set(mi, _("Configuration")); - e_util_menu_item_edje_icon_set(mi, "enlightenment/configuration"); + e_util_menu_item_edje_icon_set(mi, "enlightenment/configuration"); e_menu_item_callback_set(mi, _wlan_face_cb_menu_configure, nf); mi = e_menu_item_new(mn); e_menu_item_label_set(mi, _("Edit Mode")); - e_util_menu_item_edje_icon_set(mi, "enlightenment/gadgets"); + e_util_menu_item_edje_icon_set(mi, "enlightenment/gadgets"); e_menu_item_callback_set(mi, _wlan_face_cb_menu_edit, nf); } @@ -306,6 +338,9 @@ static void _wlan_face_free(Wlan_Face *nf) { + e_object_unref(E_OBJECT(nf->con)); + e_object_del(E_OBJECT(nf->menu)); + if (nf->monitor) ecore_timer_del(nf->monitor); if (nf->menu) @@ -326,6 +361,8 @@ e_object_del(E_OBJECT(nf->gmc)); } + nf->wlan->faces = evas_list_remove(nf->wlan->faces, nf); + E_FREE(nf->conf); E_FREE(nf); wlan_count--; @@ -343,20 +380,17 @@ case E_GADMAN_CHANGE_MOVE_RESIZE: e_gadman_client_geometry_get(nf->gmc, &x, &y, &w, &h); evas_object_move(nf->wlan_obj, x, y); - /* evas_object_move(nf->chart_obj, x, y); */ evas_object_move(nf->event_obj, x, y); evas_object_resize(nf->wlan_obj, w, h); - /* evas_object_resize(nf->chart_obj, w, h); */ evas_object_resize(nf->event_obj, w, h); break; case E_GADMAN_CHANGE_RAISE: evas_object_raise(nf->wlan_obj); - /* evas_object_raise(nf->chart_obj); */ evas_object_raise(nf->event_obj); break; default: break; - } + } } static void @@ -391,7 +425,10 @@ Wlan_Face *nf; nf = data; - _configure_wlan_module(nf->con, nf->wlan); + if (!nf) + return; + + _configure_wlan_module(nf); } static int @@ -408,6 +445,10 @@ int wlan_link = 0; int wlan_level = 0; int wlan_noise = 0; + Edje_Message_String_Set *msg; + char in_str[100]; + + nf = data; stat = fopen("/proc/net/wireless", "r"); if (!stat) @@ -426,23 +467,25 @@ iface, &wlan_status, &wlan_link, &wlan_level, &wlan_noise, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy) < 11) - continue; - - if (!strcmp(iface, strdup(nf->wlan->conf->device))) + continue; + if (!strcmp(iface, strdup(nf->conf->device))) { found_dev = 1; break; } } fclose(stat); + + if (!found_dev) + return 1; - /* Update the modules text */ - Edje_Message_Int_Set *msg; + /* Update the modules text */ + snprintf(in_str, sizeof(in_str), "LNK: %d", wlan_link); - msg = malloc(sizeof(Edje_Message_Int_Set) + 1 * sizeof(int)); + msg = malloc(sizeof(Edje_Message_String_Set) - sizeof(char *) + (1 + sizeof(char *))); msg->count = 1; - msg->val[0] = wlan_link; - edje_object_message_send(nf->wlan_obj, EDJE_MESSAGE_INT_SET, 1, msg); + msg->str[0] = in_str; + edje_object_message_send(nf->wlan_obj, EDJE_MESSAGE_STRING_SET, 1, msg); free(msg); return 1; =================================================================== RCS file: /cvsroot/enlightenment/e_modules/wlan/e_mod_config.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- e_mod_config.h 20 Feb 2006 15:15:32 -0000 1.1 +++ e_mod_config.h 21 Feb 2006 12:12:51 -0000 1.2 @@ -5,7 +5,7 @@ #include "e_mod_main.h" -void _configure_wlan_module(E_Container *con, Wlan *n); +void _configure_wlan_module(Wlan_Face *nf); #endif #endif =================================================================== RCS file: /cvsroot/enlightenment/e_modules/wlan/e_mod_config.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- e_mod_config.c 20 Feb 2006 15:15:32 -0000 1.1 +++ e_mod_config.c 21 Feb 2006 12:12:51 -0000 1.2 @@ -7,22 +7,23 @@ { char *device; int check_interval; + int display_mode; Ecore_List *devs; int dev_num; }; /* Protos */ -static void *_create_data (E_Config_Dialog *cfd); -static void _free_data (E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata); -static Evas_Object *_basic_create_widgets (E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata); -static int _basic_apply_data (E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata); -static void _fill_data (Wlan *n, E_Config_Dialog_Data *cfdata); +static void *_create_data (E_Config_Dialog *cfd); +static void _free_data (E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata); +static Evas_Object *_basic_create_widgets (E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata); +static int _basic_apply_data (E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata); +static void _fill_data (Wlan_Face *nf, E_Config_Dialog_Data *cfdata); static void _wlan_config_get_devices (Ecore_List *devs); /* Config Calls */ void -_configure_wlan_module(E_Container *con, Wlan *n) +_configure_wlan_module(Wlan_Face *nf) { E_Config_Dialog *cfd; E_Config_Dialog_View *v; @@ -34,26 +35,28 @@ v->basic.apply_cfdata = _basic_apply_data; v->basic.create_widgets = _basic_create_widgets; - cfd = e_config_dialog_new(con, _("Wlan Configuration"), NULL, 0, v, n); - n->cfd = cfd; + cfd = e_config_dialog_new(nf->con, _("Wlan Configuration"), NULL, 0, v, nf); + nf->wlan->cfd = cfd; } static void -_fill_data(Wlan *n, E_Config_Dialog_Data *cfdata) +_fill_data(Wlan_Face *nf, E_Config_Dialog_Data *cfdata) { char *tmp; int i; - cfdata->check_interval = n->conf->check_interval; + cfdata->check_interval = nf->conf->check_interval; - if (n->conf->device != NULL) - cfdata->device = strdup(n->conf->device); + if (nf->conf->device != NULL) + 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(); _wlan_config_get_devices(cfdata->devs); @@ -77,21 +80,21 @@ _create_data(E_Config_Dialog *cfd) { E_Config_Dialog_Data *cfdata; - Wlan *n; + Wlan_Face *nf; - n = cfd->data; + nf = cfd->data; cfdata = E_NEW(E_Config_Dialog_Data, 1); - _fill_data(n, cfdata); + _fill_data(nf, cfdata); return cfdata; } static void _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata) { - Wlan *n; + Wlan_Face *nf; - n = cfd->data; - n->cfd = NULL; + nf = cfd->data; + nf->wlan->cfd = NULL; free(cfdata); } @@ -100,17 +103,25 @@ { Evas_Object *o, *of, *ob, *ot; E_Radio_Group *rg; - Wlan *n; char *tmp; int i; - n = cfd->data; - 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) @@ -135,18 +146,19 @@ _basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata) { char *tmp; - Wlan *n; + Wlan_Face *nf; - n = cfd->data; + nf = cfd->data; tmp = ecore_list_goto_index(cfdata->devs, cfdata->dev_num); if (tmp != NULL) - n->conf->device = (char *)evas_stringshare_add(strdup(tmp)); - n->conf->check_interval = cfdata->check_interval; + 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 (n->face->monitor) - ecore_timer_interval_set(n->face->monitor, (double)cfdata->check_interval); - + if (nf->monitor) + ecore_timer_interval_set(nf->monitor, (double)cfdata->check_interval); + return 1; } @@ -154,9 +166,13 @@ _wlan_config_get_devices(Ecore_List *devs) { FILE *stat; - char dev[64]; + char iface[64]; char buf[256]; unsigned long dummy; + int wlan_status = 0; + int wlan_link = 0; + int wlan_level = 0; + int wlan_noise = 0; stat = fopen("/proc/net/wireless", "r"); if (!stat) @@ -165,17 +181,16 @@ while (fgets(buf, 256, stat)) { int i = 0; - for (; buf[i] != 0; i++) - { - if (buf[i] == ':' || buf[i] == '.') - buf[i] = ' '; - } - if (sscanf(buf, - "%s %*u %lu %lu %lu %lu %lu %lu %lu %lu %lu\n", - dev, &dummy, &dummy, &dummy, &dummy, &dummy, - &dummy, &dummy, &dummy, &dummy, &dummy) < 10) + for (; buf[i] != 0; i++) + if (buf[i] == ':' || buf[i] == '.') + buf[i] = ' '; + + if (sscanf(buf, "%s %u %u %u %u %u %u %u %u %u %u", + iface, &wlan_status, &wlan_link, &wlan_level, + &wlan_noise, &dummy, &dummy, &dummy, &dummy, + &dummy, &dummy) < 11) continue; - ecore_list_append(devs, strdup(dev)); + ecore_list_append(devs, strdup(iface)); } fclose(stat); } =================================================================== RCS file: /cvsroot/enlightenment/e_modules/wlan/wlan.edc,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- wlan.edc 20 Feb 2006 17:07:57 -0000 1.2 +++ wlan.edc 21 Feb 2006 12:12:51 -0000 1.3 @@ -15,22 +15,9 @@ name: "modules/wlan/main"; script { public message(Msg_Type:type, id, ...) { - if (type == MSG_INT_SET) { - new tmp; + if (type == MSG_STRING_SET) { new in_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)); set_text(PART:"link-text", in_str); } } ------------------------------------------------------- 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