Enlightenment CVS committal Author : chaos Project : e_modules Module : wlan
Dir : e_modules/wlan Modified Files: e_mod_main.c e_mod_main.h e_mod_config.c Log Message: * Shelf-ify wlan module =================================================================== RCS file: /cvs/e/e_modules/wlan/e_mod_main.c,v retrieving revision 1.27 retrieving revision 1.28 diff -u -3 -r1.27 -r1.28 --- e_mod_main.c 18 Jul 2006 00:03:04 -0000 1.27 +++ e_mod_main.c 2 Sep 2006 00:56:06 -0000 1.28 @@ -1,605 +1,496 @@ #include <e.h> #include "e_mod_main.h" -#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 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 void _wlan_face_graph_values (Wlan_Face * wf, int val); - -static int wlan_count; -static E_Config_DD *conf_edd; -static E_Config_DD *conf_face_edd; +typedef struct _Instance Instance; +typedef struct _Wlan Wlan; -EAPI E_Module_Api e_modapi = { - E_MODULE_API_VERSION, - "Wlan" +struct _Instance +{ + E_Gadcon_Client *gcc; + Evas_Object *wlan_obj; + Wlan *wlan; + Ecore_Timer *check_timer; }; -EAPI void * -e_modapi_init (E_Module * m) +struct _Wlan { - Wlan *n; + Instance *inst; + Evas_Object *wlan_obj; +}; - /* Set up module's message catalogue */ - bindtextdomain (PACKAGE, LOCALEDIR); - bind_textdomain_codeset (PACKAGE, "UTF-8"); +/* Func Protos for Gadcon */ +static E_Gadcon_Client *_gc_init (E_Gadcon * gc, const char *name, + const char *id, const char *style); +static void _gc_shutdown (E_Gadcon_Client * gcc); +static void _gc_orient (E_Gadcon_Client * gcc); +static char *_gc_label (void); +static Evas_Object *_gc_icon (Evas * evas); + +/* Func Protos for Module */ +static void _wlan_cb_mouse_down (void *data, Evas * e, Evas_Object * obj, + void *event_info); +static void _wlan_cb_mouse_in (void *data, Evas * e, Evas_Object * obj, + void *event_info); +static void _wlan_cb_mouse_out (void *data, Evas * e, Evas_Object * obj, + void *event_info); +static void _wlan_menu_cb_configure (void *data, E_Menu * m, E_Menu_Item * mi); +static void _wlan_menu_cb_post (void *data, E_Menu * m); +static Config_Item *_wlan_config_item_get (const char *id); +static Wlan *_wlan_new (Evas * evas); +static void _wlan_free (Wlan * wlan); +static int _wlan_cb_check (void *data); + +static E_Config_DD *conf_edd = NULL; +static E_Config_DD *conf_item_edd = NULL; + +Config *wlan_config = NULL; + +static const E_Gadcon_Client_Class _gc_class = { + GADCON_CLIENT_CLASS_VERSION, + "wlan", {_gc_init, _gc_shutdown, _gc_orient, _gc_label, _gc_icon}, + E_GADCON_CLIENT_STYLE_PLAIN +}; - n = _wlan_init (m); - if (!n) - return NULL; +static E_Gadcon_Client * +_gc_init (E_Gadcon * gc, const char *name, const char *id, const char *style) +{ + E_Gadcon_Client *gcc; + Evas_Object *o; + Instance *inst; + Config_Item *ci; + Wlan *wlan; + + inst = E_NEW (Instance, 1); + + ci = _wlan_config_item_get (id); + if (!ci->id) + ci->id = evas_stringshare_add (id); + + wlan = _wlan_new (gc->evas); + wlan->inst = inst; + inst->wlan = wlan; + + o = wlan->wlan_obj; + gcc = e_gadcon_client_new (gc, name, id, style, o); + gcc->data = inst; + inst->gcc = gcc; + inst->wlan_obj = o; - n->module = m; - return n; -} + evas_object_event_callback_add (o, EVAS_CALLBACK_MOUSE_DOWN, + _wlan_cb_mouse_down, inst); + evas_object_event_callback_add (o, EVAS_CALLBACK_MOUSE_IN, _wlan_cb_mouse_in, + inst); + evas_object_event_callback_add (o, EVAS_CALLBACK_MOUSE_OUT, + _wlan_cb_mouse_out, inst); -EAPI int -e_modapi_shutdown (E_Module * m) -{ - Wlan *n; + if (ci->always_text) + edje_object_signal_emit (inst->wlan_obj, "label_active", ""); - n = m->data; - if (!n) - return 0; + _wlan_cb_check (inst); - if (n->cfd) - { - e_object_del (E_OBJECT (n->cfd)); - n->cfd = NULL; - } - _wlan_shutdown (n); - return 1; + inst->check_timer = ecore_timer_add (ci->poll_time, _wlan_cb_check, inst); + wlan_config->instances = evas_list_append (wlan_config->instances, inst); + return gcc; } -EAPI int -e_modapi_save (E_Module * m) +static void +_gc_orient (E_Gadcon_Client * gcc) { - Wlan *n; - - n = m->data; - if (!n) - return 0; - e_config_domain_save ("module.wlan", conf_edd, n->conf); - return 1; + e_gadcon_client_aspect_set (gcc, 16, 16); + e_gadcon_client_min_size_set (gcc, 16, 16); } -EAPI int -e_modapi_about (E_Module * m) +static char * +_gc_label (void) { - e_module_dialog_show (m, D_ ("Enlightenment Wlan Monitor Module"), - D_ ("This module is used to monitor a wlan device.")); - return 1; + return D_ ("Wlan"); } -EAPI int -e_modapi_config (E_Module * m) +static Evas_Object * +_gc_icon (Evas * evas) { - Wlan *n; - Evas_List *l; - E_Container *con; - - n = m->data; - if (!n) - return 0; - if (!n->faces) - return 0; - - for (l = n->faces; l; l = l->next) - { - Wlan_Face *nf; - - nf = l->data; - if (!nf) - continue; + Evas_Object *o; + char buf[4096]; - con = e_container_current_get (e_manager_current_get ()); - if (nf->con == con) - { - _configure_wlan_module (nf); - break; - } - } - return 1; + o = edje_object_add (evas); + snprintf (buf, sizeof (buf), "%s/module.eap", + e_module_dir_get (wlan_config->module)); + edje_object_file_set (o, buf, "icon"); + return o; } -static Wlan * -_wlan_init (E_Module * m) +static void +_gc_shutdown (E_Gadcon_Client * gcc) { - Wlan *n; - E_Menu_Item *mi; - Evas_List *mans, *l, *l2, *fl; - - n = E_NEW (Wlan, 1); + Instance *inst; - if (!n) - return NULL; - - conf_face_edd = E_CONFIG_DD_NEW ("Wlan_Config_Face", Config_Face); -#undef T -#undef D -#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, show_text, INT); - E_CONFIG_VAL (D, T, show_graph, INT); - - 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); + inst = gcc->data; + if (inst->check_timer) + ecore_timer_del (inst->check_timer); + wlan_config->instances = evas_list_remove (wlan_config->instances, inst); + _wlan_free (inst->wlan); + free (inst); + inst = NULL; +} - _wlan_config_menu_new (n); +static void +_wlan_cb_mouse_down (void *data, Evas * e, Evas_Object * obj, void *event_info) +{ + Instance *inst; + Evas_Event_Mouse_Down *ev; - mans = e_manager_list (); - fl = n->conf->faces; - for (l = mans; l; l = l->next) + inst = data; + ev = event_info; + if ((ev->button == 3) && (!wlan_config->menu)) { - E_Manager *man; - - man = l->data; - for (l2 = man->containers; l2; l2 = l2->next) - { - E_Container *con; - Wlan_Face *nf; - - con = l2->data; - nf = _wlan_face_init (n, con); - if (nf) - { - if (!fl) - { - nf->conf = E_NEW (Config_Face, 1); - - nf->conf->enabled = 1; //wlan0 - nf->conf->device = (char *) evas_stringshare_add ("eth0"); - nf->conf->check_interval = 30; - nf->conf->show_text = 1; - nf->conf->show_graph = 1; - 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->show_text, 0, 1); - E_CONFIG_LIMIT (nf->conf->show_graph, 0, 1); - - nf->monitor = - ecore_timer_add ((double) nf->conf->check_interval, - _wlan_face_update_values, nf); - - _wlan_face_menu_new (nf); - - mi = e_menu_item_new (n->config_menu); - e_menu_item_label_set (mi, _("Configuration")); - e_menu_item_callback_set (mi, _wlan_face_cb_menu_configure, nf); - - mi = e_menu_item_new (n->config_menu); - e_menu_item_label_set (mi, con->name); - e_menu_item_submenu_set (mi, nf->menu); - - if (!nf->conf->enabled) - _wlan_face_disable (nf); - } - } + E_Menu *mn; + E_Menu_Item *mi; + int x, y, w, h; + + mn = e_menu_new (); + e_menu_post_deactivate_callback_set (mn, _wlan_menu_cb_post, inst); + wlan_config->menu = mn; + + mi = e_menu_item_new (mn); + e_menu_item_label_set (mi, D_ ("Configuration")); + e_util_menu_item_edje_icon_set (mi, "enlightenment/configuration"); + e_menu_item_callback_set (mi, _wlan_menu_cb_configure, inst); + + mi = e_menu_item_new (mn); + e_menu_item_separator_set (mi, 1); + + e_gadcon_client_util_menu_items_append (inst->gcc, mn, 0); + e_gadcon_canvas_zone_geometry_get (inst->gcc->gadcon, &x, &y, &w, &h); + e_menu_activate_mouse (mn, + e_util_zone_current_get (e_manager_current_get + ()), x + ev->output.x, + y + ev->output.y, 1, 1, + E_MENU_POP_DIRECTION_DOWN, ev->timestamp); + evas_event_feed_mouse_up (inst->gcc->gadcon->evas, ev->button, + EVAS_BUTTON_NONE, ev->timestamp, NULL); } - return n; } static void -_wlan_shutdown (Wlan * n) +_wlan_menu_cb_post (void *data, E_Menu * m) { - E_CONFIG_DD_FREE (conf_edd); - E_CONFIG_DD_FREE (conf_face_edd); - - while (n->faces) - _wlan_face_free (n->faces->data); - - e_object_del (E_OBJECT (n->config_menu)); - evas_list_free (n->conf->faces); - - n->module = NULL; - E_FREE (n->conf); - E_FREE (n); + if (!wlan_config->menu) + return; + e_object_del (E_OBJECT (wlan_config->menu)); + wlan_config->menu = NULL; } static void -_wlan_config_menu_new (Wlan * n) +_wlan_menu_cb_configure (void *data, E_Menu * m, E_Menu_Item * mi) { - E_Menu *mn; + Instance *inst; + Config_Item *ci; - mn = e_menu_new (); - n->config_menu = mn; + inst = data; + ci = _wlan_config_item_get (inst->gcc->id); + _config_wlan_module (ci); } -static Wlan_Face * -_wlan_face_init (Wlan * n, E_Container * con) +void +_wlan_config_updated (const char *id) { - 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); - - o = edje_object_add (nf->evas); - nf->wlan_obj = o; + Evas_List *l; + Config_Item *ci; - if (!e_theme_edje_object_set - (o, "base/theme/modules/wlan", "modules/wlan/main")) + if (!wlan_config) + return; + ci = _wlan_config_item_get (id); + for (l = wlan_config->instances; l; l = l->next) { - snprintf (buf, sizeof (buf), PACKAGE_DATA_DIR "/wlan.edj"); - edje_object_file_set (o, buf, "modules/wlan/main"); - } - evas_object_layer_set (o, 1); - evas_object_show (o); - - o = edje_object_add (nf->evas); - nf->chart_obj = o; - evas_object_layer_set (o, 2); - evas_object_repeat_events_set (o, 1); - evas_object_pass_events_set (o, 1); - evas_object_color_set (o, 255, 255, 255, 255); - evas_object_show (o); + Instance *inst; - o = edje_object_add (nf->evas); - nf->txt_obj = o; - if (!e_theme_edje_object_set - (o, "base/theme/modules/wlan", "modules/wlan/text")) - { - snprintf (buf, sizeof (buf), PACKAGE_DATA_DIR "/wlan.edj"); - edje_object_file_set (o, buf, "modules/wlan/text"); - } - evas_object_layer_set (o, 3); - evas_object_repeat_events_set (o, 1); - evas_object_pass_events_set (o, 1); - evas_object_color_set (o, 255, 255, 255, 255); - evas_object_show (o); - - o = evas_object_rectangle_add (nf->evas); - nf->event_obj = o; - evas_object_layer_set (o, 4); - 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_show (o); + inst = l->data; + if (!inst->gcc->id) + continue; - nf->gmc = e_gadman_client_new (nf->con->gadman); - e_gadman_client_domain_set (nf->gmc, "module.wlan", wlan_count++); - e_gadman_client_policy_set (nf->gmc, - E_GADMAN_POLICY_ANYWHERE | - E_GADMAN_POLICY_HMOVE | E_GADMAN_POLICY_HSIZE | - E_GADMAN_POLICY_VMOVE | E_GADMAN_POLICY_VSIZE); - e_gadman_client_auto_size_set (nf->gmc, 40, 40); - e_gadman_client_align_set (nf->gmc, 1.0, 1.0); - e_gadman_client_resize (nf->gmc, 40, 40); - 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); + if (!strcmp (inst->gcc->id, ci->id)) + { + if (inst->check_timer) + ecore_timer_del (inst->check_timer); + inst->check_timer = + ecore_timer_add ((double) ci->poll_time, _wlan_cb_check, inst); + if (ci->always_text) + edje_object_signal_emit (inst->wlan_obj, "label_active", ""); + else + edje_object_signal_emit (inst->wlan_obj, "label_passive", ""); - return nf; + break; + } + } } -static void -_wlan_face_menu_new (Wlan_Face * nf) +static Config_Item * +_wlan_config_item_get (const char *id) { - E_Menu *mn; - E_Menu_Item *mi; + Evas_List *l; + Config_Item *ci; - mn = e_menu_new (); - nf->menu = mn; + for (l = wlan_config->items; l; l = l->next) + { + ci = l->data; + if (!ci->id) + continue; + if (!strcmp (ci->id, id)) + return ci; + } + ci = E_NEW (Config_Item, 1); + ci->id = evas_stringshare_add (id); + ci->poll_time = 1.0; + ci->always_text = 0; + ci->show_percent = 1; +#ifdef __linux__ + ci->real_ignore_buffers = 0; + ci->real_ignore_cached = 0; +#endif - mi = e_menu_item_new (mn); - e_menu_item_label_set (mi, _("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_menu_item_callback_set (mi, _wlan_face_cb_menu_edit, nf); + wlan_config->items = evas_list_append (wlan_config->items, ci); + return ci; } -static void -_wlan_face_enable (Wlan_Face * nf) -{ - nf->conf->enabled = 1; - e_config_save_queue (); - evas_object_show (nf->wlan_obj); - evas_object_show (nf->chart_obj); - evas_object_show (nf->event_obj); - evas_object_show (nf->txt_obj); -} +EAPI E_Module_Api e_modapi = { + E_MODULE_API_VERSION, + "Wlan" +}; -static void -_wlan_face_disable (Wlan_Face * nf) +EAPI void * +e_modapi_init (E_Module * m) { - nf->conf->enabled = 0; - e_config_save_queue (); - evas_object_hide (nf->event_obj); - evas_object_hide (nf->chart_obj); - evas_object_hide (nf->wlan_obj); - evas_object_hide (nf->txt_obj); -} + bindtextdomain (PACKAGE, LOCALEDIR); + bind_textdomain_codeset (PACKAGE, "UTF-8"); -static void -_wlan_face_free (Wlan_Face * nf) -{ - e_object_unref (E_OBJECT (nf->con)); + conf_item_edd = E_CONFIG_DD_NEW ("Wlan_Config_Item", Config_Item); +#undef T +#undef D +#define T Config_Item +#define D conf_item_edd + E_CONFIG_VAL (D, T, id, STR); + E_CONFIG_VAL (D, T, poll_time, DOUBLE); + E_CONFIG_VAL (D, T, always_text, INT); + E_CONFIG_VAL (D, T, show_percent, INT); +#ifdef __linux__ + E_CONFIG_VAL (D, T, real_ignore_buffers, INT); + E_CONFIG_VAL (D, T, real_ignore_cached, INT); +#endif - if (nf->monitor) - ecore_timer_del (nf->monitor); - if (nf->menu) - e_object_del (E_OBJECT (nf->menu)); - if (nf->event_obj) - evas_object_del (nf->event_obj); - if (nf->wlan_obj) - evas_object_del (nf->wlan_obj); - if (nf->chart_obj) - evas_object_del (nf->chart_obj); - if (nf->txt_obj) - evas_object_del (nf->txt_obj); - if (nf->old_values) - _wlan_face_graph_clear (nf); + 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, items, conf_item_edd); - if (nf->gmc) + wlan_config = e_config_domain_load ("module.wlan", conf_edd); + if (!wlan_config) { - e_gadman_client_save (nf->gmc); - e_object_del (E_OBJECT (nf->gmc)); - } + Config_Item *ci; - nf->wlan->faces = evas_list_remove (nf->wlan->faces, nf); + wlan_config = E_NEW (Config, 1); - E_FREE (nf->conf); - E_FREE (nf); - wlan_count--; + ci = E_NEW (Config_Item, 1); + ci->id = evas_stringshare_add ("0"); + ci->poll_time = 1.0; + ci->always_text = 0; + ci->show_percent = 1; +#ifdef __linux__ + ci->real_ignore_buffers = 0; + ci->real_ignore_cached = 0; +#endif + wlan_config->items = evas_list_append (wlan_config->items, ci); + } + wlan_config->module = m; + e_gadcon_provider_register (&_gc_class); + return m; } -static void -_wlan_face_cb_gmc_change (void *data, E_Gadman_Client * gmc, - E_Gadman_Change change) +EAPI int +e_modapi_shutdown (E_Module * m) { - Wlan_Face *nf; - Evas_Coord x, y, w, h; + wlan_config->module = NULL; + e_gadcon_provider_unregister (&_gc_class); - nf = data; - switch (change) - { - 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->event_obj, x, y); - evas_object_move (nf->chart_obj, x, y); - evas_object_move (nf->txt_obj, x, y); - evas_object_resize (nf->wlan_obj, w, h); - evas_object_resize (nf->event_obj, w, h); - evas_object_resize (nf->chart_obj, w, h); - evas_object_resize (nf->txt_obj, w, h); - _wlan_face_graph_clear (nf); - break; - case E_GADMAN_CHANGE_RAISE: - evas_object_raise (nf->wlan_obj); - evas_object_raise (nf->event_obj); - evas_object_raise (nf->chart_obj); - evas_object_raise (nf->txt_obj); - break; - default: - break; - } + if (wlan_config->config_dialog) + e_object_del (E_OBJECT (wlan_config->config_dialog)); + if (wlan_config->menu) + { + e_menu_post_deactivate_callback_set (wlan_config->menu, NULL, NULL); + e_object_del (E_OBJECT (wlan_config->menu)); + wlan_config->menu = NULL; + } + while (wlan_config->items) + { + Config_Item *ci; + + ci = wlan_config->items->data; + wlan_config->items = + evas_list_remove_list (wlan_config->items, wlan_config->items); + if (ci->id) + evas_stringshare_del (ci->id); + free (ci); + ci = NULL; + } + free (wlan_config); + wlan_config = NULL; + E_CONFIG_DD_FREE (conf_item_edd); + E_CONFIG_DD_FREE (conf_edd); + return 1; } -static void -_wlan_face_cb_mouse_down (void *data, Evas * evas, Evas_Object * obj, - void *event_info) +EAPI int +e_modapi_save (E_Module * m) { - Wlan_Face *nf; - Evas_Event_Mouse_Down *ev; + Evas_List *l; - ev = event_info; - nf = data; - if (ev->button == 3) + for (l = wlan_config->instances; l; l = l->next) { - e_menu_activate_mouse (nf->menu, e_zone_current_get (nf->con), - ev->output.x, ev->output.y, 1, 1, - E_MENU_POP_DIRECTION_DOWN, ev->timestamp); - e_util_container_fake_mouse_up_all_later (nf->con); + Instance *inst; + Config_Item *ci; + + inst = l->data; + ci = _wlan_config_item_get (inst->gcc->id); + if (ci->id) + evas_stringshare_del (ci->id); + ci->id = evas_stringshare_add (inst->gcc->id); } + e_config_domain_save ("module.wlan", conf_edd, wlan_config); + return 1; } -static void -_wlan_face_cb_menu_edit (void *data, E_Menu * mn, E_Menu_Item * mi) +EAPI int +e_modapi_about (E_Module * m) { - Wlan_Face *nf; - - nf = data; - e_gadman_mode_set (nf->gmc->gadman, E_GADMAN_MODE_EDIT); + e_module_dialog_show (m, D_ ("Enlightenment Wlan Monitor Module"), + D_ ("This module is used to monitor wireless devices.")); + return 1; } -static void -_wlan_face_cb_menu_configure (void *data, E_Menu * mn, E_Menu_Item * mi) +static Wlan * +_wlan_new (Evas * evas) { - Wlan_Face *nf; + Wlan *wlan; + char buf[4096]; - nf = data; - if (!nf) - return; + wlan = E_NEW (Wlan, 1); - _configure_wlan_module (nf); + wlan->wlan_obj = edje_object_add (evas); + snprintf (buf, sizeof (buf), "%s/wlan.edj", + e_module_dir_get (wlan_config->module)); + if (!e_theme_edje_object_set + (wlan->wlan_obj, "base/theme/modules/wlan", "modules/wlan/main")) + edje_object_file_set (wlan->wlan_obj, buf, "modules/wlan/main"); + evas_object_show (wlan->wlan_obj); + + return wlan; } -static int -_wlan_face_update_values (void *data) +static void +_wlan_free (Wlan * m) { - Wlan_Face *nf; - unsigned int dummy; - char iface[64]; - char buf[256]; - FILE *stat; - int found_dev = 0; - int wlan_status = 0; - int wlan_link = 0; - int wlan_level = 0; - int wlan_noise = 0; - Edje_Message_Float msg; - - char in_str[100]; - - nf = data; - stat = fopen ("/proc/net/wireless", "r"); - if (!stat) - return 1; - - while (fgets (buf, 256, stat)) - { - int i = 0; - - /* remove : */ - 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; - if (!strcmp (iface, strdup (nf->conf->device))) - { - found_dev = 1; - break; - } - } - fclose (stat); - - if (!found_dev) - return 1; - - /* Update the modules text */ - if (nf->conf->show_text) - { - snprintf (in_str, sizeof (in_str), "LNK: %d%%", wlan_link); - edje_object_part_text_set (nf->txt_obj, "link-text", in_str); - } - else - edje_object_part_text_set (nf->txt_obj, "link-text", ""); - - msg.val = wlan_link; - edje_object_message_send (nf->wlan_obj, EDJE_MESSAGE_FLOAT, 1, &msg); - - if (nf->conf->show_graph) - _wlan_face_graph_values (nf, wlan_link); - else - _wlan_face_graph_clear (nf); - - return 1; + evas_object_del (m->wlan_obj); + free (m); + m = NULL; } static void -_wlan_face_graph_values (Wlan_Face * wf, int val) +_wlan_cb_mouse_in (void *data, Evas * e, Evas_Object * obj, void *event_info) { - int x, y, w, h; - Evas_Object *o; - Evas_Object *last = NULL; - Evas_List *l; - int i, j = 0; - int v; - - evas_event_freeze (wf->evas); - - evas_object_geometry_get (wf->chart_obj, &x, &y, &w, &h); + Instance *inst; - v = (int) ((double) val * ((double) h / (double) 100)); - o = evas_object_line_add (wf->evas); - edje_object_part_swallow (wf->chart_obj, "lines", o); - evas_object_layer_set (o, 1); - if (val == 0) - evas_object_hide (o); - else - { - evas_object_line_xy_set (o, (x + w), (y + h), (x + w), ((y + h) - v)); - evas_object_color_set (o, 255, 0, 0, 100); - evas_object_pass_events_set (o, 1); - evas_object_show (o); - } - - wf->old_values = evas_list_prepend (wf->old_values, o); - l = wf->old_values; - for (i = (x + w); l && (j - 2) < w; l = l->next, j++) - { - Evas_Coord oy; - Evas_Object *lo; - - lo = (Evas_Object *) evas_list_data (l); - evas_object_geometry_get (lo, NULL, &oy, NULL, NULL); - evas_object_move (lo, i--, oy); - last = lo; - } + inst = data; + edje_object_signal_emit (inst->wlan_obj, "label_active", ""); +} - if ((j - 2) >= w) - { - wf->old_values = evas_list_remove (wf->old_values, last); - edje_object_part_unswallow (wf->chart_obj, last); - evas_object_del (last); - } +static void +_wlan_cb_mouse_out (void *data, Evas * e, Evas_Object * obj, void *event_info) +{ + Instance *inst; + Config_Item *ci; - evas_event_thaw (wf->evas); + inst = data; + ci = _wlan_config_item_get (inst->gcc->id); + if (!ci->always_text) + edje_object_signal_emit (inst->wlan_obj, "label_passive", ""); } -void -_wlan_face_graph_clear (Wlan_Face * wf) +static int +_wlan_cb_check (void *data) { - Evas_List *l; + Instance *inst; + Config_Item *ci; + Edje_Message_Float msg; - evas_event_freeze (wf->evas); + int new_status, new_link, new_level, new_noise; + unsigned int dummy; + char iface[64]; + char buf[256]; + FILE *stat; + int found_dev = 0; + int wlan_status = 0; + int wlan_link = 0; + int wlan_level = 0; + int wlan_noise = 0; + + char omsg[100]; + char in_str[100]; + + stat = fopen("/proc/net/wireless", "r"); + if (!stat) + return 1; + + while (fgets(buf, 256, stat)) + { + int i = 0; + + /* remove : */ + 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; + if (!strcmp(iface, "wlan0")) + { + found_dev = 1; + break; + } + } + fclose(stat); + + if (!found_dev) + return 1; + + snprintf(in_str, sizeof(in_str), "LNK: %d%%", wlan_link); + + inst = data; + ci = _wlan_config_item_get (inst->gcc->id); + + + double link_send = ((double)wlan_link / (double)100.0); + double level_send = ((double)wlan_level / (double)100.0); + + Edje_Message_Float *val; + val = malloc(sizeof(Edje_Message_Float)); + val->val = link_send; + edje_object_message_send(inst->wlan_obj, EDJE_MESSAGE_FLOAT,1, val); + free(val); + + val = malloc(sizeof(Edje_Message_Float)); + val->val = level_send; + edje_object_message_send(inst->wlan_obj, EDJE_MESSAGE_FLOAT,2, val); + free(val); + + snprintf(omsg,sizeof(omsg),"Qual: %d%%", wlan_link); + edje_object_signal_emit(inst->wlan_obj, "label_active", ""); + edje_object_part_text_set(inst->wlan_obj, "qual_label", omsg); - for (l = wf->old_values; l; l = l->next) - { - Evas_Object *o; + snprintf(omsg,sizeof(omsg),"Lvl: %d%%", wlan_level); + edje_object_part_text_set(inst->wlan_obj, "level_label", omsg); - o = evas_list_data (l); - edje_object_part_unswallow (wf->chart_obj, o); - evas_object_del (o); - } - evas_list_free (wf->old_values); - wf->old_values = NULL; - evas_event_thaw (wf->evas); + return 1; } =================================================================== RCS file: /cvs/e/e_modules/wlan/e_mod_main.h,v retrieving revision 1.9 retrieving revision 1.10 diff -u -3 -r1.9 -r1.10 --- e_mod_main.h 3 Jul 2006 07:37:33 -0000 1.9 +++ e_mod_main.h 2 Sep 2006 00:56:06 -0000 1.10 @@ -4,61 +4,37 @@ #define E_MOD_MAIN_H typedef struct _Config Config; -typedef struct _Config_Face Config_Face; -typedef struct _Wlan Wlan; -typedef struct _Wlan_Face Wlan_Face; +typedef struct _Config_Item Config_Item; -struct _Config +struct _Config { - Evas_List *faces; -}; - -struct _Config_Face -{ - unsigned char enabled; - char *device; - int check_interval; - int show_text; - int show_graph; -}; - -struct _Wlan -{ - E_Menu *config_menu; - Evas_List *faces; - Config *conf; - E_Config_Dialog *cfd; E_Module *module; + E_Config_Dialog *config_dialog; + E_Menu *menu; + Evas_List *instances; + Evas_List *items; }; -struct _Wlan_Face +struct _Config_Item { - Evas *evas; - E_Container *con; - E_Menu *menu; - Wlan *wlan; - Evas_List *old_values; - - Config_Face *conf; - - Evas_Object *wlan_obj; - Evas_Object *event_obj; - Evas_Object *chart_obj; - Evas_Object *txt_obj; - - Ecore_Timer *monitor; - - E_Gadman_Client *gmc; + const char *id; + double poll_time; + int show_percent; + int always_text; + int real_ignore_buffers; + int real_ignore_cached; }; EAPI extern E_Module_Api e_modapi; EAPI void *e_modapi_init(E_Module *m); -EAPI int e_modapi_shutdown(E_Module *m); -EAPI int e_modapi_save(E_Module *m); -EAPI int e_modapi_about(E_Module *m); -EAPI int e_modapi_config(E_Module *m); - -void _wlan_face_graph_clear(Wlan_Face *wf); +EAPI int e_modapi_shutdown(E_Module *m); +EAPI int e_modapi_save(E_Module *m); +EAPI int e_modapi_about(E_Module *m); + +void _wlan_config_updated(const char *id); +void _config_wlan_module(Config_Item *ci); +void _wlan_get_values(Config_Item *ci, int *real, int *swap, int *total_real, int *total_swap); +extern Config *wlan_config; #endif =================================================================== RCS file: /cvs/e/e_modules/wlan/e_mod_config.c,v retrieving revision 1.13 retrieving revision 1.14 diff -u -3 -r1.13 -r1.14 --- e_mod_config.c 14 Aug 2006 21:18:41 -0000 1.13 +++ e_mod_config.c 2 Sep 2006 00:56:06 -0000 1.14 @@ -1,17 +1,15 @@ #include <e.h> #include "e_mod_main.h" -#include "e_mod_config.h" -#include "config.h" struct _E_Config_Dialog_Data { - char *device; - int check_interval; - int show_text; - int show_graph; - - Ecore_List *devs; - int dev_num; + double poll_time; + int always_text; + int show_percent; +#ifdef __linux__ + int real_ignore_buffers; + int real_ignore_cached; +#endif }; /* Protos */ @@ -21,15 +19,15 @@ 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); +static void _fill_data (Config_Item * ci, E_Config_Dialog_Data * cfdata); /* Config Calls */ void -_configure_wlan_module (Wlan_Face * nf) +_config_wlan_module (Config_Item * ci) { E_Config_Dialog *cfd; E_Config_Dialog_View *v; + E_Container *con; char buf[4096]; v = E_NEW (E_Config_Dialog_View, 1); @@ -40,72 +38,44 @@ v->basic.create_widgets = _basic_create_widgets; snprintf (buf, sizeof (buf), "%s/module.eap", - e_module_dir_get (nf->wlan->module)); - cfd = - e_config_dialog_new (nf->con, D_ ("Wlan Configuration"), "WLAN", "_e_modules_wlan_config_dialog", buf, 0, v, nf); - nf->wlan->cfd = cfd; + e_module_dir_get (wlan_config->module)); + con = e_container_current_get (e_manager_current_get ()); + cfd = e_config_dialog_new (con, D_ ("Wlan Configuration"), "Wlan", "_e_modules_wlan_config_dialog", buf, 0, v, ci); + wlan_config->config_dialog = cfd; } static void -_fill_data (Wlan_Face * nf, E_Config_Dialog_Data * cfdata) +_fill_data (Config_Item * ci, E_Config_Dialog_Data * cfdata) { - char *tmp; - int i; - - cfdata->check_interval = nf->conf->check_interval; - cfdata->show_text = nf->conf->show_text; - cfdata->show_graph = nf->conf->show_graph; - - if (nf->conf->device != NULL) - cfdata->device = strdup (nf->conf->device); - else - cfdata->device = NULL; - - if (!cfdata->device) - return; - - cfdata->devs = ecore_list_new (); - _wlan_config_get_devices (cfdata->devs); - - if (!cfdata->devs) - return; - - i = 0; - ecore_list_goto_first (cfdata->devs); - while ((tmp = ecore_list_next (cfdata->devs)) != NULL) - { - if (!strcmp (cfdata->device, tmp)) - { - cfdata->dev_num = i; - break; - } - i++; - } + cfdata->poll_time = ci->poll_time; +#ifdef __linux__ + cfdata->real_ignore_buffers = ci->real_ignore_buffers; + cfdata->real_ignore_cached = ci->real_ignore_cached; +#endif +// cfdata->show_text = c->conf->show_text; + cfdata->always_text = ci->always_text; + cfdata->show_percent = ci->show_percent; } static void * _create_data (E_Config_Dialog * cfd) { E_Config_Dialog_Data *cfdata; - Wlan_Face *nf; + Config_Item *ci; - nf = cfd->data; + ci = cfd->data; cfdata = E_NEW (E_Config_Dialog_Data, 1); - _fill_data (nf, cfdata); + _fill_data (ci, cfdata); return cfdata; } static void _free_data (E_Config_Dialog * cfd, E_Config_Dialog_Data * cfdata) { - Wlan_Face *nf; - - nf = cfd->data; - nf->wlan->cfd = NULL; - E_FREE (cfdata->device); - if (cfdata->devs) - ecore_list_destroy (cfdata->devs); + if (!wlan_config) + return; + wlan_config->config_dialog = NULL; free (cfdata); cfdata = NULL; } @@ -114,39 +84,36 @@ _basic_create_widgets (E_Config_Dialog * cfd, Evas * evas, E_Config_Dialog_Data * cfdata) { - Evas_Object *o, *of, *ob, *ot; + Evas_Object *o, *of, *ob; E_Radio_Group *rg; - char *tmp; - int i; o = e_widget_list_add (evas, 0, 0); of = e_widget_framelist_add (evas, D_ ("General Settings"), 0); - ob = e_widget_check_add (evas, D_ ("Show Text"), (&(cfdata->show_text))); + rg = e_widget_radio_group_new (&(cfdata->always_text)); + ob = e_widget_radio_add (evas, D_ ("Always Show Text"), 1, rg); e_widget_framelist_object_append (of, ob); - ob = e_widget_check_add (evas, D_ ("Show Graph"), (&(cfdata->show_graph))); + ob = e_widget_radio_add (evas, D_ ("Show Text On Mouse Over"), 0, rg); e_widget_framelist_object_append (of, ob); - e_widget_list_object_append (o, of, 1, 1, 0.5); - - of = e_widget_framelist_add (evas, D_ ("Device Settings"), 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) - { - ob = e_widget_radio_add (evas, tmp, i, rg); - e_widget_table_object_append (ot, ob, 0, i, 1, 1, 1, 0, 1, 0); - i++; - } - i++; + ob = + e_widget_check_add (evas, D_ ("Show Text As Percent"), + &(cfdata->show_percent)); + e_widget_framelist_object_append (of, ob); +#ifdef __linux__ + ob = + e_widget_check_add (evas, D_ ("Ignore Buffers"), + &(cfdata->real_ignore_buffers)); + e_widget_framelist_object_append (of, ob); + ob = + e_widget_check_add (evas, D_ ("Ignore Cached"), + &(cfdata->real_ignore_cached)); + e_widget_framelist_object_append (of, ob); +#endif ob = e_widget_label_add (evas, D_ ("Check Interval:")); - e_widget_table_object_append (ot, ob, 0, i, 1, 1, 0, 0, 1, 0); - i++; + e_widget_framelist_object_append (of, ob); ob = - e_widget_slider_add (evas, 1, 0, _("%1.0f seconds"), 1, 60, 1, 0, NULL, - &(cfdata->check_interval), 150); - e_widget_table_object_append (ot, ob, 0, i, 1, 1, 1, 0, 1, 0); - e_widget_framelist_object_append (of, ot); + e_widget_slider_add (evas, 1, 0, _("%1.0f seconds"), 1.0, 60.0, 1.0, 0, + &(cfdata->poll_time), NULL, 150); + e_widget_framelist_object_append (of, ob); e_widget_list_object_append (o, of, 1, 1, 0.5); return o; @@ -155,61 +122,18 @@ static int _basic_apply_data (E_Config_Dialog * cfd, E_Config_Dialog_Data * cfdata) { - char *tmp; - Wlan_Face *nf; - - nf = cfd->data; - tmp = ecore_list_goto_index (cfdata->devs, cfdata->dev_num); - if (tmp != NULL) - { - if (strcmp (tmp, nf->conf->device)) - { - _wlan_face_graph_clear (nf); - nf->conf->device = (char *) evas_stringshare_add (strdup (tmp)); - } - } - - nf->conf->check_interval = cfdata->check_interval; - nf->conf->show_text = cfdata->show_text; - nf->conf->show_graph = cfdata->show_graph; + Config_Item *ci; + ci = cfd->data; + ci->poll_time = cfdata->poll_time; +#ifdef __linux__ + ci->real_ignore_buffers = cfdata->real_ignore_buffers; + ci->real_ignore_cached = cfdata->real_ignore_cached; +#endif + ci->always_text = cfdata->always_text; + ci->show_percent = cfdata->show_percent; e_config_save_queue (); - - if (nf->monitor) - ecore_timer_interval_set (nf->monitor, (double) cfdata->check_interval); + _wlan_config_updated (ci->id); return 1; -} - -static void -_wlan_config_get_devices (Ecore_List * devs) -{ - FILE *stat; - 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) - return; - - 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 %u %u %u %lu %lu %lu %lu %lu %lu", - iface, &wlan_status, &wlan_link, &wlan_level, &wlan_noise, - &dummy, &dummy, &dummy, &dummy, &dummy, &dummy) < 11) - continue; - ecore_list_append (devs, strdup (iface)); - } - fclose (stat); } ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs