From 0d26bde204a0aca8d7ee5752b1fac62edfaac332 Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Mon, 3 Sep 2012 21:57:16 +0000 Subject: [PATCH] New code base for connman module ConnMan 1.0 is the first stable release and the one being packed by most distros. Completely remove the old code, together with the econnman-0.7x dependency. The relevant code is now maintained together with e17 module for easier maintenance. SVN revision: 76020 --- configure.ac | 3 +- src/modules/connman/E_Connman.h | 20 + src/modules/connman/Makefile.am | 5 +- src/modules/connman/e_connman.c | 162 +++ src/modules/connman/e_connman_private.h | 21 + src/modules/connman/e_mod_config.c | 665 +-------- src/modules/connman/e_mod_main.c | 1639 +---------------------- src/modules/connman/e_mod_main.h | 173 +-- src/modules/wizard/page_110.c | 78 +- 9 files changed, 380 insertions(+), 2386 deletions(-) create mode 100644 src/modules/connman/E_Connman.h create mode 100644 src/modules/connman/e_connman.c create mode 100644 src/modules/connman/e_connman_private.h diff --git a/configure.ac b/configure.ac index 0489347e7..23e493222 100644 --- a/configure.ac +++ b/configure.ac @@ -774,7 +774,8 @@ AC_SUBST(SOUND_LIBS) AM_CONDITIONAL(HAVE_ECONNMAN, false) define([CHECK_MODULE_CONNMAN], [ - AC_E_CHECK_PKG(ECONNMAN, [ edbus >= 1.2.0 econnman-0.7x >= 1.2.0 ], [], [CONNMAN=false]) + AC_E_CHECK_PKG(ECONNMAN, [ edbus >= 1.2.0 ], [], [CONNMAN=false]) + AC_E_CHECK_PKG(DUMMY, [ connman >= 1.0 ], [], [CONNMAN=false]) ]) AC_SUBST(ECONNMAN_CFLAGS) AC_SUBST(ECONNMAN_LIBS) diff --git a/src/modules/connman/E_Connman.h b/src/modules/connman/E_Connman.h new file mode 100644 index 000000000..e22034fa1 --- /dev/null +++ b/src/modules/connman/E_Connman.h @@ -0,0 +1,20 @@ +#ifndef E_CONNMAN_H +#define E_CONNMAN_H + +#include +#include + +#include +#include +#include + +/* Ecore Events */ +extern int E_CONNMAN_EVENT_MANAGER_IN; +extern int E_CONNMAN_EVENT_MANAGER_OUT; + +/* Daemon monitoring */ + +unsigned int e_connman_system_init(E_DBus_Connection *edbus_conn) EINA_ARG_NONNULL(1); +unsigned int e_connman_system_shutdown(void); + +#endif /* E_CONNMAN_H */ diff --git a/src/modules/connman/Makefile.am b/src/modules/connman/Makefile.am index 0012a1abc..431711468 100644 --- a/src/modules/connman/Makefile.am +++ b/src/modules/connman/Makefile.am @@ -23,7 +23,10 @@ pkg_LTLIBRARIES = module.la module_la_SOURCES = e_mod_main.h \ e_mod_main.c \ - e_mod_config.c + e_mod_config.c \ + e_connman.c \ + e_connman_private.h \ + E_Connman.h module_la_LIBADD = @e_libs@ @dlopen_libs@ @ECONNMAN_LIBS@ module_la_LDFLAGS = -module -avoid-version diff --git a/src/modules/connman/e_connman.c b/src/modules/connman/e_connman.c new file mode 100644 index 000000000..270cde18e --- /dev/null +++ b/src/modules/connman/e_connman.c @@ -0,0 +1,162 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "e_connman_private.h" +#include +#include + +static const char CONNMAN_BUS_NAME[] = "net.connman"; + +static E_DBus_Signal_Handler *cb_name_owner_changed; +static DBusPendingCall *pending_get_name_owner; +static unsigned int init_count; +static E_DBus_Connection *conn; + +EAPI int E_CONNMAN_EVENT_MANAGER_IN; +EAPI int E_CONNMAN_EVENT_MANAGER_OUT; + +int _e_dbus_connman_log_dom = -1; + +static inline void +_e_connman_system_name_owner_exit(void) +{ + ecore_event_add(E_CONNMAN_EVENT_MANAGER_OUT, NULL, NULL, NULL); +} + +static inline void +_e_connman_system_name_owner_enter(void) +{ + ecore_event_add(E_CONNMAN_EVENT_MANAGER_IN, NULL, NULL, NULL); +} + +static void +_e_connman_system_name_owner_changed(void *data __UNUSED__, DBusMessage *msg) +{ + const char *name, *from, *to; + DBusError err; + + dbus_error_init(&err); + if (!dbus_message_get_args(msg, &err, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_STRING, &from, + DBUS_TYPE_STRING, &to, + DBUS_TYPE_INVALID)) + { + ERR("could not get NameOwnerChanged arguments: %s: %s", + err.name, err.message); + dbus_error_free(&err); + return; + } + + if (strcmp(name, CONNMAN_BUS_NAME) != 0) + return; + + DBG("NameOwnerChanged %s from=[%s] to=[%s]", name, from, to); + + if (from[0] == '\0' && to[0] != '\0') + _e_connman_system_name_owner_enter(); + else if (from[0] != '\0' && to[0] == '\0') + _e_connman_system_name_owner_exit(); + else + ERR("unknow change from %s to %s", from, to); +} + +static void +_e_connman_get_name_owner(void *data __UNUSED__, DBusMessage *msg, DBusError *err) +{ + pending_get_name_owner = NULL; + DBG("get_name_owner msg=%p", msg); + + if (dbus_error_is_set(err)) + { + if (!strcmp(err->name, DBUS_ERROR_NAME_HAS_NO_OWNER)) + ERR("could not get bus name owner: %s %s", err->name, err->message); + return; + } + + _e_connman_system_name_owner_enter(); +} + +/** + * Initialize E Connection Manager (E_Connman) system. + * + * This will connect to ConnMan through DBus and watch for it going in and out. + * + * Interesting events are: + * - E_CONNMAN_EVENT_MANAGER_IN: issued when connman is avaiable. + * - E_CONNMAN_EVENT_MANAGER_OUT: issued when connman connection is lost. + */ +unsigned int +e_connman_system_init(E_DBus_Connection *edbus_conn) +{ + init_count++; + + if (init_count > 1) + return init_count; + + _e_dbus_connman_log_dom = eina_log_domain_register("e_dbus_connman", + EINA_LOG_DEFAULT_COLOR); + + if (_e_dbus_connman_log_dom < 0) + { + EINA_LOG_ERR("impossible to create a log domain for edbus_connman module"); + return -1; + } + + if (E_CONNMAN_EVENT_MANAGER_IN == 0) + E_CONNMAN_EVENT_MANAGER_IN = ecore_event_type_new(); + + if (E_CONNMAN_EVENT_MANAGER_OUT == 0) + E_CONNMAN_EVENT_MANAGER_OUT = ecore_event_type_new(); + + conn = edbus_conn; + cb_name_owner_changed = e_dbus_signal_handler_add(conn, + E_DBUS_FDO_BUS, E_DBUS_FDO_PATH, E_DBUS_FDO_INTERFACE, + "NameOwnerChanged", _e_connman_system_name_owner_changed, + NULL); + + pending_get_name_owner = e_dbus_get_name_owner(conn, + CONNMAN_BUS_NAME, _e_connman_get_name_owner, + NULL); + + return init_count; +} + +/** + * Shutdown ConnMan system + * + * When count drops to 0 resources will be released and no calls should be + * made anymore. + */ +unsigned int +e_connman_system_shutdown(void) +{ + if (init_count == 0) + { + ERR("connman system already shut down."); + return 0; + } + + init_count--; + if (init_count > 0) + return init_count; + + if (pending_get_name_owner) + { + dbus_pending_call_cancel(pending_get_name_owner); + pending_get_name_owner = NULL; + } + + if (cb_name_owner_changed) + { + e_dbus_signal_handler_del(conn, cb_name_owner_changed); + cb_name_owner_changed = NULL; + } + + eina_log_domain_unregister(_e_dbus_connman_log_dom); + conn = NULL; + + return init_count; +} + diff --git a/src/modules/connman/e_connman_private.h b/src/modules/connman/e_connman_private.h new file mode 100644 index 000000000..0e3261c49 --- /dev/null +++ b/src/modules/connman/e_connman_private.h @@ -0,0 +1,21 @@ +#include + +#include +#include +#include "E_Connman.h" + +extern int _e_dbus_connman_log_dom; + +#ifndef EINA_LOG_DEFAULT_COLOR +#define EINA_LOG_DEFAULT_COLOR EINA_COLOR_CYAN +#endif + +#undef DBG +#undef INF +#undef WRN +#undef ERR + +#define DBG(...) EINA_LOG_DOM_DBG(_e_dbus_connman_log_dom, __VA_ARGS__) +#define INF(...) EINA_LOG_DOM_INFO(_e_dbus_connman_log_dom, __VA_ARGS__) +#define WRN(...) EINA_LOG_DOM_WARN(_e_dbus_connman_log_dom, __VA_ARGS__) +#define ERR(...) EINA_LOG_DOM_ERR(_e_dbus_connman_log_dom, __VA_ARGS__) diff --git a/src/modules/connman/e_mod_config.c b/src/modules/connman/e_mod_config.c index 94cdb2918..1f4aa5fd9 100644 --- a/src/modules/connman/e_mod_config.c +++ b/src/modules/connman/e_mod_config.c @@ -2,216 +2,55 @@ extern const char _e_connman_Name[]; -extern const char *e_str_enabled; -extern const char *e_str_available; -extern const char *e_str_connected; -extern const char *e_str_offline; - -struct connman_config_technologies -{ - EINA_INLIST; - Evas_Object *obj; - E_Connman_Technology *technology; - int enabled; -}; - struct _E_Config_Dialog_Data { E_Connman_Module_Context *ctxt; - const char *selected_network; - struct connman_config_network_ui - { - Evas_Object *hlayout; - Evas_Object *netframe; - Evas_Object *netlist; -/* - Evas_Object *o_up; - Evas_Object *o_down; - Evas_Object *o_add; - Evas_Object *o_del; - */ - Evas_Object *setframe; - struct connman_config_network_settings_ui - { - Evas_Object *scr_general; - Evas_Object *list_general; - Evas_Object *lb_autoconn; - Evas_Object *lb_autoconn_val; - Evas_Object *lb_favorite; - Evas_Object *lb_favorite_val; - Evas_Object *lb_type; - Evas_Object *lb_type_val; - Evas_Object *lb_ipv4_method; - Evas_Object *lb_ipv4_method_val; - Evas_Object *lb_ipv4_address; - Evas_Object *lb_ipv4_address_val; - Evas_Object *lb_ipv4_netmask; - Evas_Object *lb_ipv4_netmask_val; - -#if 0 // need to do proxy stuff to enalbe the toolbook - Evas_Object *settings_otb; - Evas_Object *list_proxy; -#endif - } settings_otb; - } networks; - struct connman_config_switch_ui - { - Evas_Object *vlayout; - Evas_Object *type_frame; - Evas_Object *off_frame; - Eina_Inlist *technologies; - Evas_Object *o_off; - int offline_mode; - } switches; }; -/* Local Function Prototypes */ -static void *_create_data(E_Config_Dialog *dialog); -static void _free_data(E_Config_Dialog *dialog, - E_Config_Dialog_Data *cfdata); -static void _fill_data(E_Config_Dialog_Data *cfdata, - E_Connman_Module_Context *ctxt); -static Evas_Object *_basic_create(E_Config_Dialog *dialog, - Evas *evas, - E_Config_Dialog_Data *cfdata); -static int _basic_apply(E_Config_Dialog *dialog, - E_Config_Dialog_Data *cfdata); - -struct connman_service_move_data +static Evas_Object * +_basic_create(E_Config_Dialog *dialog __UNUSED__, Evas *evas, + E_Config_Dialog_Data *cfdata) { - const char *service_path; - const char *service_ref_path; - E_Connman_Module_Context *ctxt; -}; - -enum _Conmman_Move_Direction { - SERVICE_MOVE_DOWN, - SERVICE_MOVE_UP -}; - -#if 0 -static void -_connman_service_move_cb(void *data, - DBusMessage *msg __UNUSED__, - DBusError *error) -{ - struct connman_service_move_data *d = data; - if (error && dbus_error_is_set(error)) - { - ERR("%s method failed with message \'%s\'", - error->name, error->message); - dbus_error_free(error); - } - else - DBG("Changed service order"); - - eina_stringshare_del(d->service_ref_path); - eina_stringshare_del(d->service_path); - E_FREE(d); + return NULL; } -#endif -#if 0 -static void -_connman_service_move(E_Connman_Service *service, - const E_Connman_Service *service_ref, - enum _Conmman_Move_Direction direction) +static int +_basic_apply(E_Config_Dialog *dialog __UNUSED__, + E_Config_Dialog_Data *cfdata) { - struct connman_service_move_data *d; - int ret; - - d = E_NEW(struct connman_service_move_data, 1); - if (!d) - return; - - d->service_ref_path = eina_stringshare_ref(service_ref->path); - d->service_path = eina_stringshare_ref(service->path); - d->ctxt = service->ctxt; - - DBG("Try to move %s %s %s\n", d->service_path, - (direction == SERVICE_MOVE_UP) ? "before" : "after", - d->service_ref_path); - - if (direction == SERVICE_MOVE_UP) - ret = e_connman_service_move_before - (service->element, d->service_ref_path, _connman_service_move_cb, d); - else - ret = e_connman_service_move_after - (service->element, d->service_ref_path, _connman_service_move_cb, d); - - if (!ret) - { - eina_stringshare_del(d->service_ref_path); - eina_stringshare_del(d->service_path); - E_FREE(d); - _connman_operation_error_show(_("Re-order preferred services")); - } -} -#endif - -struct _connman_technology_onoff_data -{ - const char *type; - E_Connman_Module_Context *ctxt; - Eina_Bool on; -}; - -static void -_connman_technology_onoff_cb(void *data, - DBusMessage *msg __UNUSED__, - DBusError *error) -{ - struct _connman_technology_onoff_data *d = data; - if (error && dbus_error_is_set(error)) - { - ERR("%s method failed with message \'%s\'.", - error->name, error->message); - dbus_error_free(error); - } - else - DBG("Technology %s has been %s.", d->type, d->on ? "enabled" : "disabled"); - - eina_stringshare_del(d->type); - E_FREE(d); + return 1; } static void -_connman_technology_onoff(E_Connman_Module_Context *ctxt, - const char *type, - Eina_Bool on) +_free_data(E_Config_Dialog *dialog, + E_Config_Dialog_Data *cfdata) { - int ret; - struct _connman_technology_onoff_data *d; + E_Connman_Module_Context *ctxt = dialog->data; + ctxt->conf_dialog = NULL; + E_FREE(cfdata); +} - d = E_NEW(struct _connman_technology_onoff_data, 1); - if (!d) - { - _connman_operation_error_show("No memory available"); - return; - } +static inline void +_fill_data(E_Config_Dialog_Data *cfdata, + E_Connman_Module_Context *ctxt) +{ + cfdata->ctxt = ctxt; +} - d->type = eina_stringshare_add(type); - d->ctxt = ctxt; - d->on = on; +static void * +_create_data(E_Config_Dialog *dialog) +{ + E_Config_Dialog_Data *cfdata; - if(on) - ret = e_connman_manager_technology_enable - (type, _connman_technology_onoff_cb, d); - else - ret = e_connman_manager_technology_disable - (type, _connman_technology_onoff_cb, d); - - if(!ret) - { - eina_stringshare_del(type); - E_FREE(d); - } - - return; + cfdata = E_NEW(E_Config_Dialog_Data, 1); + if (!cfdata) + return NULL; + _fill_data(cfdata, dialog->data); + return cfdata; } E_Config_Dialog * -e_connman_config_dialog_new(E_Container *con, +e_connman_config_dialog_new(E_Container *con, E_Connman_Module_Context *ctxt) { E_Config_Dialog *dialog; @@ -236,447 +75,3 @@ e_connman_config_dialog_new(E_Container *con, return dialog; } - -static void * -_create_data(E_Config_Dialog *dialog) -{ - E_Config_Dialog_Data *cfdata; - - cfdata = E_NEW(E_Config_Dialog_Data, 1); - if (!cfdata) - return NULL; - _fill_data(cfdata, dialog->data); - return cfdata; -} - -static void -_free_data(E_Config_Dialog *dialog, - E_Config_Dialog_Data *cfdata) -{ - E_Connman_Module_Context *ctxt = dialog->data; - struct connman_config_switch_ui *ui = &cfdata->switches; - - while(ui->technologies) - { - struct connman_config_technologies *t; - - t = (struct connman_config_technologies *)ui->technologies; - ui->technologies = eina_inlist_remove - (ui->technologies, EINA_INLIST_GET(t)); - E_FREE(t); - } - - ctxt->conf_dialog = NULL; - E_FREE(cfdata); -} - -static inline void -_fill_data(E_Config_Dialog_Data *cfdata, - E_Connman_Module_Context *ctxt) -{ - cfdata->ctxt = ctxt; - cfdata->switches.technologies = NULL; -} - -void -_cb_scr_general_show(void *data, - Evas *evas __UNUSED__, - Evas_Object *obj, - void *event_info __UNUSED__) -{ - E_Config_Dialog_Data *cfdata = data; - struct connman_config_network_ui *ui; - ui = &cfdata->networks; - - if (e_widget_ilist_selected_get(ui->netlist) < 0) - evas_object_hide(obj); -} - -static void -_network_settings_general_page_create(Evas *evas, - E_Config_Dialog_Data *cfdata) -{ - struct connman_config_network_settings_ui *ui; - Evas_Coord mw, mh; - ui = &cfdata->networks.settings_otb; - - ui->list_general = e_widget_list_add(evas, 0, 0); -#define _APPEND_ITEM(item, label) \ - do \ - { \ - ui->lb_##item = e_widget_label_add(evas, _(label)); \ - ui->lb_##item ## _val = e_widget_entry_add \ - (evas, NULL, NULL, NULL, NULL); \ - e_widget_entry_readonly_set(ui->lb_##item ## _val, 1); \ - e_widget_list_object_append \ - (ui->list_general, ui->lb_##item, 1, 0, 0.0); \ - e_widget_list_object_append \ - (ui->list_general, ui->lb_##item ## _val, 1, 0, 0.0); \ - } while(0) - - _APPEND_ITEM(autoconn, _("Auto-connect:")); - _APPEND_ITEM(favorite, _("Favorite:")); - _APPEND_ITEM(type, _("Type:")); - _APPEND_ITEM(ipv4_method, _("IP method:")); - _APPEND_ITEM(ipv4_address, _("IP address:")); - _APPEND_ITEM(ipv4_netmask, _("Netmask:")); -#undef _APPEND_ITEM - - evas_object_show(ui->list_general); - e_widget_size_min_get(ui->list_general, &mw, &mh); - if (mw < 100 * e_scale) - mw = 100 * e_scale; - if (mh < 100 * e_scale) - mh = 100 * e_scale; - evas_object_resize(ui->list_general, mw, mh); - - ui->scr_general = e_widget_scrollframe_simple_add(evas, ui->list_general); - e_widget_size_min_set(ui->scr_general, 100 * e_scale, 100 * e_scale); - - evas_object_event_callback_add(ui->scr_general, EVAS_CALLBACK_SHOW, _cb_scr_general_show, cfdata); -} - -#if 0 // need to do proxy, until then hide the toolbook complexity -static void -_network_settings_proxy_page_create(Evas *evas, - E_Config_Dialog_Data *cfdata) -{ - struct connman_config_network_settings_ui *ui; - Evas_Object *label_todo; - ui = &cfdata->networks.settings_otb; - - ui->list_proxy = e_widget_list_add(evas, 0, 0); - - label_todo = e_widget_label_add(evas, "TODO"); - e_widget_list_object_append(ui->list_proxy, label_todo, 1, 1, 0.0); -} - -#endif - -static void -_network_settings_create(Evas *evas, - E_Config_Dialog_Data *cfdata) -{ - struct connman_config_network_ui *ui; - - ui = &cfdata->networks; - ui->setframe = e_widget_framelist_add(evas, _("Settings"), 0); - -#if 0 // need to do proxy, until then hide the toolbook complexity - ui->settings_otb.settings_otb = e_widget_toolbook_add(evas, 24 * e_scale, 24 * e_scale); - - _network_settings_general_page_create(evas, cfdata); - e_widget_toolbook_page_append - (ui->settings_otb.settings_otb, NULL, _("General"), - ui->settings_otb.scr_general, 1, 1, 1, 1, 0.5, 0.0); - - _network_settings_proxy_page_create(evas, cfdata); - e_widget_toolbook_page_append - (ui->settings_otb.settings_otb, NULL, _("Proxy"), - ui->settings_otb.list_proxy, 1, 0, 1, 0, 0.5, 0.0); - - e_widget_size_min_set(ui->settings_otb.settings_otb, 100, 100); - e_widget_toolbook_page_show(ui->settings_otb.settings_otb, 0); - e_widget_framelist_object_append(ui->setframe, ui->settings_otb.settings_otb); -#else - _network_settings_general_page_create(evas, cfdata); - e_widget_framelist_object_append(ui->setframe, ui->settings_otb.scr_general); -#endif -} - -static inline void -_networks_fill_details(E_Config_Dialog_Data *cfdata, - Evas_Object *list __UNUSED__, - int sel __UNUSED__) -{ - E_Connman_Service *service; - E_Connman_Module_Context *ctxt = cfdata->ctxt; - struct connman_config_network_settings_ui *ui = &cfdata->networks.settings_otb; - - service = _connman_ctxt_find_service_stringshare - (ctxt, cfdata->selected_network); - if (!service) - { - ERR("service not found: %s.", cfdata->selected_network); - return; - } - e_widget_entry_text_set(ui->lb_autoconn_val, - service->auto_connect ? _("True") : _("False")); - e_widget_entry_text_set(ui->lb_favorite_val, - service->favorite ? _("True") : _("False")); - e_widget_entry_text_set(ui->lb_type_val, service->type); - e_widget_entry_text_set(ui->lb_ipv4_method_val, service->ipv4_method); - e_widget_entry_text_set(ui->lb_ipv4_address_val, service->ipv4_address); - e_widget_entry_text_set(ui->lb_ipv4_netmask_val, service->ipv4_netmask); - - evas_object_show(ui->list_general); - evas_object_show(ui->scr_general); -} - -/* - static inline void - _networks_disable_buttons(E_Config_Dialog_Data *cfdata, Evas_Object *list, int sel) - { - Evas_Object *o_up = cfdata->networks.o_up; - Evas_Object *o_down = cfdata->networks.o_down; - - if (sel >= 0) - { - int index = e_widget_ilist_selected_get(list); - int count = e_widget_ilist_count(list); - e_widget_disabled_set(o_up, !index); - - e_widget_disabled_set(o_down, (count > index + 1)?0:1); - } - else - { - e_widget_disabled_set(o_up, 1); - e_widget_disabled_set(o_down, 1); - } - } - */ -void -_cb_service_selected(void *data) -{ - E_Config_Dialog_Data *cfdata = data; - Evas_Object *list = cfdata->networks.netlist; - int sel = e_widget_ilist_selected_get(list); -// _networks_disable_buttons(cfdata, list, sel); - _networks_fill_details(cfdata, list, sel); -} - -static unsigned int -_networks_list_fill(Evas *evas, - E_Config_Dialog_Data *cfdata) -{ - Evas_Object *list = cfdata->networks.netlist; - E_Connman_Module_Context *ctxt = cfdata->ctxt; - E_Connman_Service *service; - - EINA_INLIST_FOREACH(ctxt->services, service) - { - Evas_Object *icon = _connman_service_new_list_item(evas, service); - - e_widget_ilist_append - (list, icon, service->name, _cb_service_selected, - cfdata, service->path); - } - - return eina_inlist_count(ctxt->services); -} - -#if 0 -static void -_networks_button_up_cb(void *data, - void *data2 __UNUSED__) -{ - E_Config_Dialog_Data *cfdata = data; - Evas_Object *netlist = cfdata->networks.netlist; - E_Connman_Module_Context *ctxt = cfdata->ctxt; - E_Connman_Service *service, *service_ref; - int sel; - - sel = e_widget_ilist_selected_get(netlist); - if (sel <= 0) - return; - - service = _connman_ctxt_find_service_stringshare - (ctxt, cfdata->selected_network); - e_widget_ilist_selected_set(netlist, sel - 1); - - service_ref = _connman_ctxt_find_service_stringshare - (ctxt, cfdata->selected_network); - - e_widget_ilist_selected_set(netlist, sel); - - _connman_service_move(service, service_ref, SERVICE_MOVE_UP); -} - -static void -_networks_button_down_cb(void *data, - void *data2 __UNUSED__) -{ - E_Config_Dialog_Data *cfdata = data; - Evas_Object *netlist = cfdata->networks.netlist; - E_Connman_Module_Context *ctxt = cfdata->ctxt; - E_Connman_Service *service, *service_ref; - int sel; - int count; - - sel = e_widget_ilist_selected_get(netlist); - count = e_widget_ilist_count(netlist); - if (sel < 0 || (count == sel + 1)) - return; - - service = _connman_ctxt_find_service_stringshare - (ctxt, cfdata->selected_network); - e_widget_ilist_selected_set(netlist, sel + 1); - service_ref = _connman_ctxt_find_service_stringshare - (ctxt, cfdata->selected_network); - e_widget_ilist_selected_set(netlist, sel); - - _connman_service_move(service, service_ref, SERVICE_MOVE_DOWN); -} -#endif - -static void -_networks_list_create(Evas *evas, - E_Config_Dialog_Data *cfdata) -{ - struct connman_config_network_ui *ui; - - ui = &cfdata->networks; - ui->netframe = e_widget_framelist_add(evas, _("All networks"), 0); - ui->netlist = e_widget_ilist_add(evas, 24, 24, &cfdata->selected_network); - e_widget_ilist_multi_select_set(ui->netlist, 0); - e_widget_on_change_hook_set(ui->netlist, NULL, cfdata); - e_widget_size_min_set(ui->netlist, 100, 100); - e_widget_ilist_selected_set(ui->netlist, 0); - e_widget_framelist_object_append(ui->netframe, ui->netlist); - -#if 0 - Evas_Object *ot; - Evas_Coord mw, mh; - - /* Buttons */ - ot = e_widget_table_add(evas, 0); - ui->o_up = e_widget_button_add - (evas, _("Up"), "go-up", _networks_button_up_cb, cfdata, NULL); - e_widget_disabled_set(ui->o_up, 1); - e_widget_table_object_append(ot, ui->o_up, 0, 0, 1, 1, 1, 0, 1, 0); - ui->o_down = e_widget_button_add - (evas, _("Down"), "go-down", _networks_button_down_cb, cfdata, NULL); - e_widget_disabled_set(ui->o_down, 1); - e_widget_table_object_append(ot, ui->o_down, 1, 0, 1, 1, 1, 0, 1, 0); - ui->o_add = e_widget_button_add - (evas, _("Add"), "list-add", NULL, cfdata, NULL); - e_widget_disabled_set(ui->o_add, 1); - e_widget_table_object_append(ot, ui->o_add, 0, 1, 2, 1, 1, 0, 1, 0); - - e_widget_size_min_get(ot, &mw, &mh); - e_widget_framelist_object_append_full(ui->netframe, ot, - 1, 1, /* fill */ - 1, 0, /* expand */ - 0.5, 0.5, /* align */ - mw, mh, /* min */ - 99999, 99999 /* max */ - ); -#endif -} - -static void -_networks_page_create(Evas *evas, - E_Config_Dialog_Data *cfdata) -{ - struct connman_config_network_ui *ui; - - /* - * TODO: - * - * Add a elm_widget_pager similar to elm_pager and push pop the - * list and the associated element settings when the list - * element is selected (needs a view/edit/info/whatever button - * as the list elements may be reordered, thus we need th - * selection). - * - * This should reduce the width of this dialog. - */ - - ui = &cfdata->networks; - ui->hlayout = e_widget_list_add(evas, 0, 1); - _networks_list_create(evas, cfdata); - e_widget_list_object_append(ui->hlayout, ui->netframe, 1, 1, 0.0); - _network_settings_create(evas, cfdata); - e_widget_list_object_append(ui->hlayout, ui->setframe, 1, 1, 0.0); - evas_object_hide(ui->settings_otb.scr_general); -} - -static inline void -_switches_page_create_technologies(Evas *evas, - E_Connman_Module_Context *ctxt, - struct connman_config_switch_ui *ui) -{ - struct E_Connman_Technology *t; - EINA_INLIST_FOREACH(ctxt->technologies, t) - { - struct connman_config_technologies *t_list; - - t_list = E_NEW(struct connman_config_technologies, 1); - t_list->technology = t; - t_list->enabled = ((t->state == e_str_enabled) || - (t->state == e_str_connected)); - t_list->obj = e_widget_check_add(evas, _(t->name), &t_list->enabled); - - ui->technologies = eina_inlist_append - (ui->technologies, EINA_INLIST_GET(t_list)); - e_widget_framelist_object_append(ui->type_frame, t_list->obj); - } -} - -static void -_switches_page_create(Evas *evas, - E_Config_Dialog_Data *cfdata) -{ - struct connman_config_switch_ui *ui; - E_Connman_Module_Context *ctxt = cfdata->ctxt; - - ui = &cfdata->switches; - ui->vlayout = e_widget_list_add(evas, 0, 0); - ui->type_frame = e_widget_framelist_add(evas, _("Network types"), 0); - ui->offline_mode = ctxt->offline_mode; - - _switches_page_create_technologies(evas, ctxt, ui); - - e_widget_list_object_append(ui->vlayout, ui->type_frame, 1, 1, 0.0); - ui->off_frame = e_widget_framelist_add(evas, _("Disable networking"), 0); - ui->o_off = e_widget_check_add(evas, _("Offline mode"), &ui->offline_mode); - e_widget_framelist_object_append(ui->off_frame, ui->o_off); - e_widget_list_object_append(ui->vlayout, ui->off_frame, 1, 1, 0.0); -} - -static Evas_Object * -_basic_create(E_Config_Dialog *dialog __UNUSED__, - Evas *evas, - E_Config_Dialog_Data *cfdata) -{ - Evas_Object *otb; - - otb = e_widget_toolbook_add(evas, 48 * e_scale, 48 * e_scale); - - _networks_page_create(evas, cfdata); - e_widget_toolbook_page_append - (otb, NULL, _("Networks Settings"), - cfdata->networks.hlayout, 1, 1, 1, 1, 0.5, 0.0); - _switches_page_create(evas, cfdata); - e_widget_toolbook_page_append - (otb, NULL, _("Network Switches"), - cfdata->switches.vlayout, 1, 1, 0, 0, 0.5, 0.5); - - _networks_list_fill(evas, cfdata); - e_widget_toolbook_page_show(otb, 0); - e_widget_size_min_resize(otb); - - return otb; -} - -static int -_basic_apply(E_Config_Dialog *dialog __UNUSED__, - E_Config_Dialog_Data *cfdata) -{ - E_Connman_Module_Context *ctxt = cfdata->ctxt; - struct connman_config_switch_ui *sw = &cfdata->switches; - struct connman_config_technologies *t; - - EINA_INLIST_FOREACH(sw->technologies, t) - { - int was_enabled = ((t->technology->state == e_str_enabled) || - (t->technology->state == e_str_connected)); - if (t->enabled != was_enabled) - _connman_technology_onoff(ctxt, t->technology->type, t->enabled); - } - if (ctxt->offline_mode != sw->offline_mode) - _connman_toggle_offline_mode(ctxt); - - return 1; -} - diff --git a/src/modules/connman/e_mod_main.c b/src/modules/connman/e_mod_main.c index 3545dd36f..ceafe91b9 100644 --- a/src/modules/connman/e_mod_main.c +++ b/src/modules/connman/e_mod_main.c @@ -4,54 +4,17 @@ /* * STATUS: * - * displays current status, allows connecting and - * disconnecting. needs connman 0.48 or even better from git. - * - * TODO: - * - * MUST: - * 1. improve gadget ui - * - * GOOD: - * 1. imporve mouse over popup ui - * 2. nice popup using edje objects as rows, not simple lists (fancy) - * 3. "Controls" for detailed information, similar to Mixer app - * it would contain switches to toggle offline and choose - * technologies that are enabled. - * - * IDEAS: - * 1. create static connections - * 2. handle cellular: ask APN, Username and Password, use SetupRequired - * 3. handle vpn, bluetooth, wimax + * ConnMan in, ConnMan out * */ -static E_Module *connman_mod = NULL; +static E_Module *connman_mod; static char tmpbuf[4096]; /* general purpose buffer, just use immediately */ const char _e_connman_name[] = "connman"; const char _e_connman_Name[] = "Connection Manager"; int _e_connman_log_dom = -1; -static const char *e_str_idle = NULL; -static const char *e_str_association = NULL; -static const char *e_str_configuration = NULL; -static const char *e_str_ready = NULL; -static const char *e_str_login = NULL; -static const char *e_str_online = NULL; -static const char *e_str_disconnect = NULL; -static const char *e_str_failure = NULL; - -const char *e_str_enabled = NULL; -const char *e_str_available = NULL; -const char *e_str_connected = NULL; -const char *e_str_offline = NULL; - -static void _connman_service_ask_pass_and_connect(E_Connman_Service *service); -static void _connman_default_service_changed_delayed(E_Connman_Module_Context *ctxt); -static void _connman_gadget_update(E_Connman_Instance *inst); -static void _connman_tip_update(E_Connman_Instance *inst); - const char * e_connman_theme_path(void) { @@ -70,1344 +33,9 @@ e_connman_theme_path(void) } static void -_connman_toggle_offline_mode_cb(void *data, - DBusMessage *msg __UNUSED__, - DBusError *error) -{ - E_Connman_Module_Context *ctxt = data; - - if ((!error) || (!dbus_error_is_set(error))) - { - ctxt->offline_mode_pending = EINA_FALSE; - return; - } - - _connman_dbus_error_show(_("Cannot toggle system's offline mode."), error); - dbus_error_free(error); -} - -void -_connman_toggle_offline_mode(E_Connman_Module_Context *ctxt) -{ - Eina_Bool offline; - - if ((!ctxt) || (!ctxt->has_manager)) - { - _connman_operation_error_show(_("ConnMan Daemon is not running.")); - return; - } - - if (!e_connman_manager_offline_mode_get(&offline)) - { - _connman_operation_error_show - (_("Query system's offline mode.")); - return; - } - - offline = !offline; - if (!e_connman_manager_offline_mode_set - (offline, _connman_toggle_offline_mode_cb, ctxt)) - { - _connman_operation_error_show - (_("Cannot toggle system's offline mode.")); - return; - } -} - -static void -_connman_cb_toggle_offline_mode(E_Object *obj __UNUSED__, - const char *params __UNUSED__) -{ - E_Connman_Module_Context *ctxt; - - if (!connman_mod) - return; - - ctxt = connman_mod->data; - _connman_toggle_offline_mode(ctxt); -} - -struct connman_passphrase_data -{ - void (*cb)(void *data, - const char *password, - const char *service_path); - void *data; - const char *service_path; - char *passphrase; - E_Connman_Module_Context *ctxt; - E_Dialog *dia; - Evas_Object *entry; - Eina_Bool canceled; - int cleartext; -}; - -#if 0 // NOT WORKING, e_widget_entry_password_set() changes stops editing!!! -static void -_connman_passphrase_ask_cleartext_changed(void *data, - Evas_Object *obj, - void *event __UNUSED__) -{ - struct connman_passphrase_data *d = data; - e_widget_entry_password_set(d->entry, !e_widget_check_checked_get(obj)); - e_widget_entry_readonly_set(d->entry, 0); - e_widget_focus_set(d->entry, 1); -} - -#endif - -static void -_connman_passphrase_ask_ok(void *data, - E_Dialog *dia) -{ - struct connman_passphrase_data *d = data; - d->canceled = EINA_FALSE; - e_object_del(E_OBJECT(dia)); -} - -static void -_connman_passphrase_ask_cancel(void *data, - E_Dialog *dia) -{ - struct connman_passphrase_data *d = data; - d->canceled = EINA_TRUE; - e_object_del(E_OBJECT(dia)); -} - -static void -_connman_passphrase_ask_del(void *data) -{ - E_Dialog *dia = data; - struct connman_passphrase_data *d = e_object_data_get(E_OBJECT(dia)); - - if (d->canceled) - { - free(d->passphrase); - d->passphrase = NULL; - } - - d->cb(d->data, d->passphrase, d->service_path); - - eina_stringshare_del(d->service_path); - free(d->passphrase); - E_FREE(d); -} - -static void -_connman_passphrase_ask_key_down(void *data, - Evas *e __UNUSED__, - Evas_Object *o __UNUSED__, - void *event) -{ - Evas_Event_Key_Down *ev = event; - struct connman_passphrase_data *d = data; - - if (strcmp(ev->keyname, "Return") == 0) - _connman_passphrase_ask_ok(d, d->dia); - else if (strcmp(ev->keyname, "Escape") == 0) - _connman_passphrase_ask_cancel(d, d->dia); -} - -static void -_connman_passphrase_ask(E_Connman_Service *service, - void (*cb)(void *data, - const char *password, - const char *service_path), - const void *data) -{ - struct connman_passphrase_data *d; - Evas_Object *list, *o; - Evas *evas; - char buf[512]; - const char *passphrase; - int mw, mh; - - if (!cb) - return; - if (!service) - { - cb((void *)data, NULL, NULL); - return; - } - - d = E_NEW(struct connman_passphrase_data, 1); - if (!d) - { - cb((void *)data, NULL, NULL); - return; - } - d->cb = cb; - d->data = (void *)data; - d->service_path = eina_stringshare_add(service->path); - d->ctxt = service->ctxt; - d->canceled = EINA_TRUE; /* closing the dialog defaults to cancel */ - d->dia = e_dialog_new(NULL, "E", "connman_ask_passphrase"); - - e_dialog_title_set(d->dia, _("ConnMan needs your passphrase")); - e_dialog_icon_set(d->dia, "dialog-ask", 64); - e_dialog_border_icon_set(d->dia, "dialog-ask"); - - evas = d->dia->win->evas; - - list = e_widget_list_add(evas, 0, 0); - - o = edje_object_add(evas); - e_theme_edje_object_set(o, "base/theme/dialog", - "e/widgets/dialog/text"); - snprintf(buf, sizeof(buf), - _("Connection Manager needs your passphrase for
" - "the service %s"), - service->name); - edje_object_part_text_set(o, "e.textblock.message", buf); - edje_object_size_min_calc(o, &mw, &mh); - evas_object_size_hint_min_set(o, mw, mh); - evas_object_resize(o, mw, mh); - evas_object_show(o); - e_widget_list_object_append(list, o, 1, 1, 0.5); - - if (!e_connman_service_passphrase_get(service->element, &passphrase)) - passphrase = NULL; - if (passphrase && passphrase[0]) - d->passphrase = strdup(passphrase); - else - d->passphrase = NULL; - - d->entry = o = e_widget_entry_add(evas, &d->passphrase, NULL, NULL, NULL); - e_widget_entry_password_set(o, 0); - evas_object_show(o); - e_widget_list_object_append(list, o, 1, 0, 0.0); - -#if 0 // NOT WORKING, e_widget_entry_password_set() changes stops editing!!! - d->cleartext = 1; - o = e_widget_check_add(evas, _("Show passphrase as clear text"), - &d->cleartext); - evas_object_smart_callback_add - (o, "changed", _connman_passphrase_ask_cleartext_changed, d); - evas_object_show(o); - e_widget_list_object_append(list, o, 1, 0, 0.0); -#endif - - e_widget_size_min_get(list, &mw, &mh); - if (mw < 200) - mw = 200; - if (mh < 60) - mh = 60; - e_dialog_content_set(d->dia, list, mw, mh); - - e_dialog_button_add - (d->dia, _("Ok"), NULL, _connman_passphrase_ask_ok, d); - e_dialog_button_add - (d->dia, _("Cancel"), NULL, _connman_passphrase_ask_cancel, d); - - evas_object_event_callback_add - (d->dia->bg_object, EVAS_CALLBACK_KEY_DOWN, - _connman_passphrase_ask_key_down, d); - - e_object_del_attach_func_set - (E_OBJECT(d->dia), _connman_passphrase_ask_del); - e_object_data_set(E_OBJECT(d->dia), d); - - e_dialog_button_focus_num(d->dia, 0); - e_widget_focus_set(d->entry, 1); - - e_win_centered_set(d->dia->win, 1); - e_dialog_show(d->dia); -} - -static void -_connman_service_free(E_Connman_Service *service) -{ - eina_stringshare_del(service->path); - eina_stringshare_del(service->name); - eina_stringshare_del(service->type); - eina_stringshare_del(service->mode); - eina_stringshare_del(service->state); - eina_stringshare_del(service->error); - eina_stringshare_del(service->security); - eina_stringshare_del(service->ipv4_method); - eina_stringshare_del(service->ipv4_address); - eina_stringshare_del(service->ipv4_netmask); - - E_FREE(service); -} - -static const char * -_connman_service_security_find(const E_Connman_Element *element) -{ - const char **security; - unsigned int count; - - if (!e_connman_service_security_get(element, &count, &security)) - return NULL; - if ((!security) || (count < 1)) - return NULL; - return security[0]; -} - -static void -_connman_service_changed(void *data, - const E_Connman_Element *element) -{ - E_Connman_Service *service = data; - const char *str; - unsigned char u8; - Eina_Bool b; - -#define GSTR(name_, getter) \ - str = NULL; \ - if (!getter(element, &str)) \ - str = NULL; \ - eina_stringshare_replace(&service->name_, str) - - GSTR(name, e_connman_service_name_get); - GSTR(type, e_connman_service_type_get); - GSTR(state, e_connman_service_state_get); - GSTR(error, e_connman_service_error_get); - GSTR(ipv4_method, e_connman_service_ipv4_configuration_method_get); - - str = _connman_service_security_find(element); - eina_stringshare_replace(&service->security, str); - - if (service->ipv4_method && strcmp(service->ipv4_method, "dhcp") == 0) - { - GSTR(ipv4_address, e_connman_service_ipv4_address_get); - GSTR(ipv4_netmask, e_connman_service_ipv4_netmask_get); - } - else - { - GSTR(ipv4_address, - e_connman_service_ipv4_configuration_address_get); - GSTR(ipv4_netmask, - e_connman_service_ipv4_configuration_netmask_get); - } -#undef GSTR - - if ((service->state != e_str_failure) && (service->error)) - eina_stringshare_replace(&service->error, NULL); - - if (!e_connman_service_strength_get(element, &u8)) - u8 = 0; - service->strength = u8; - -#define GBOOL(name_, getter) \ - b = EINA_FALSE; \ - if (!getter(element, &b)) \ - b = EINA_FALSE; \ - service->name_ = b - - GBOOL(favorite, e_connman_service_favorite_get); - GBOOL(auto_connect, e_connman_service_auto_connect_get); - GBOOL(pass_required, e_connman_service_passphrase_required_get); -#undef GBOOL - - if ((service->ctxt->default_service == service) || - (!service->ctxt->default_service)) - _connman_default_service_changed_delayed(service->ctxt); - else - DBG("Do not request for delayed changed as this is not the default."); -} - -static void -_connman_service_freed(void *data) -{ - E_Connman_Service *service = data; - E_Connman_Module_Context *ctxt = service->ctxt; - - ctxt->services = eina_inlist_remove - (ctxt->services, EINA_INLIST_GET(service)); - - _connman_service_free(service); - - if (ctxt->default_service == service) - { - ctxt->default_service = NULL; - _connman_default_service_changed_delayed(ctxt); - } -} - -static E_Connman_Service * -_connman_service_new(E_Connman_Module_Context *ctxt, - E_Connman_Element *element) -{ - E_Connman_Service *service; - const char *str; - unsigned char u8; - Eina_Bool b; - - if (!element) - return NULL; - - service = E_NEW(E_Connman_Service, 1); - if (!service) - return NULL; - - service->ctxt = ctxt; - service->element = element; - service->path = eina_stringshare_add(element->path); - -#define GSTR(name_, getter) \ - str = NULL; \ - if (!getter(element, &str)) \ - str = NULL; \ - service->name_ = eina_stringshare_add(str) - - GSTR(name, e_connman_service_name_get); - GSTR(type, e_connman_service_type_get); - GSTR(state, e_connman_service_state_get); - GSTR(error, e_connman_service_error_get); - GSTR(ipv4_method, e_connman_service_ipv4_method_get); - GSTR(ipv4_address, e_connman_service_ipv4_address_get); - GSTR(ipv4_netmask, e_connman_service_ipv4_netmask_get); -#undef GSTR - - str = _connman_service_security_find(element); - eina_stringshare_replace(&service->security, str); - - if ((service->state != e_str_failure) && (service->error)) - eina_stringshare_replace(&service->error, NULL); - - if (!e_connman_service_strength_get(element, &u8)) - u8 = 0; - service->strength = u8; - -#define GBOOL(name_, getter) \ - b = EINA_FALSE; \ - if (!getter(element, &b)) \ - b = EINA_FALSE; \ - service->name_ = b - - GBOOL(favorite, e_connman_service_favorite_get); - GBOOL(auto_connect, e_connman_service_auto_connect_get); - GBOOL(pass_required, e_connman_service_passphrase_required_get); -#undef GBOOL - - e_connman_element_listener_add - (element, _connman_service_changed, service, - _connman_service_freed); - - return service; -} - -#define GSTR(name_, getter) \ - str = NULL; \ - if (!getter(element, &str)) \ - str = NULL; \ - eina_stringshare_replace(&t->name_, str) - -static void -_connman_technology_free(E_Connman_Technology *t) -{ - eina_stringshare_del(t->path); - eina_stringshare_del(t->name); - eina_stringshare_del(t->type); - eina_stringshare_del(t->state); - - E_FREE(t); -} - -static void -_connman_technology_changed(void *data, - const E_Connman_Element *element) -{ - E_Connman_Technology *t = data; - const char *str; - - GSTR(name, e_connman_technology_name_get); - GSTR(type, e_connman_technology_type_get); - GSTR(state, e_connman_technology_state_get); -} - -static void -_connman_technology_freed(void *data) -{ - E_Connman_Technology *t = data; - E_Connman_Module_Context *ctxt = t->ctxt; - - ctxt->technologies = eina_inlist_remove - (ctxt->technologies, EINA_INLIST_GET(t)); - - _connman_technology_free(t); -} - -static E_Connman_Technology * -_connman_technology_new(E_Connman_Module_Context *ctxt, - E_Connman_Element *element) -{ - E_Connman_Technology *t; - const char *str; - - if (!element) - return NULL; - - t = E_NEW(E_Connman_Technology, 1); - if (!t) - return NULL; - - t->ctxt = ctxt; - t->element = element; - t->path = eina_stringshare_add(element->path); - - GSTR(name, e_connman_technology_name_get); - GSTR(type, e_connman_technology_type_get); - GSTR(state, e_connman_technology_state_get); - - e_connman_element_listener_add - (element, _connman_technology_changed, t, - _connman_technology_freed); - - return t; -} - -#undef GSTR - -static void -_connman_service_disconnect_cb(void *data, - DBusMessage *msg __UNUSED__, - DBusError *error) -{ - E_Connman_Module_Context *ctxt = data; - - if (error && dbus_error_is_set(error)) - { - if ((strcmp(error->name, - "org.moblin.connman.Error.NotConnected") != 0) || - (strcmp(error->name, - "net.connman.Error.NotConnected") != 0)) - _connman_dbus_error_show(_("Disconnect from network service."), - error); - dbus_error_free(error); - } - - _connman_default_service_changed_delayed(ctxt); -} - -static void -_connman_service_disconnect(E_Connman_Service *service) -{ - if (!e_connman_service_disconnect - (service->element, _connman_service_disconnect_cb, service->ctxt)) - _connman_operation_error_show(_("Disconnect from network service.")); -} - -struct connman_service_connect_data -{ - const char *service_path; - E_Connman_Module_Context *ctxt; -}; - -static void -_connman_service_connect_cb(void *data, - DBusMessage *msg __UNUSED__, - DBusError *error) -{ - struct connman_service_connect_data *d = data; - - if (error && dbus_error_is_set(error)) - { - char *password_needed[] = { - "org.moblin.connman.Error.PassphraseRequired", - "org.moblin.connman.Error.Failed", - "net.connman.Error.PassphraseRequired", - "net.connman.Error.Failed", - NULL - }; - char *dont_display_error[] = { - "org.moblin.connman.Error.AlreadyConnected", - "net.connman.Error.AlreadyConnected", - "net.connman.Error.OperationAborted", - NULL - }; - int i; - - for (i = 0; password_needed[i]; ++i) - if (strcmp(error->name, password_needed[i]) == 0) - { - /* TODO: cellular might ask for SetupRequired to enter APN, - * username and password - */ - E_Connman_Service *service; - - service = _connman_ctxt_find_service_stringshare - (d->ctxt, d->service_path); - if (!service) - _connman_operation_error_show - (_("Service does not exist anymore")); - else if (strcmp(service->type, "wifi") == 0) - { - _connman_service_disconnect(service); - _connman_service_ask_pass_and_connect(service); - } - else - /* TODO: cellular might ask for user and pass */ - _connman_dbus_error_show(_("Connect to network service."), - error); - break; - } - - if (password_needed[i] == NULL) - { - for (i = 0; dont_display_error[i]; ++i) - if (strcmp(error->name, dont_display_error[i]) == 0) - break; - - if (dont_display_error[i] == NULL) - _connman_dbus_error_show(_("Connect to network service."), error); - } - - dbus_error_free(error); - } - - _connman_default_service_changed_delayed(d->ctxt); - eina_stringshare_del(d->service_path); - E_FREE(d); -} - -static void -_connman_service_connect(E_Connman_Service *service) -{ - struct connman_service_connect_data *d; - - d = E_NEW(struct connman_service_connect_data, 1); - if (!d) - return; - - d->service_path = eina_stringshare_ref(service->path); - d->ctxt = service->ctxt; - - if (!e_connman_service_connect - (service->element, _connman_service_connect_cb, d)) - { - eina_stringshare_del(d->service_path); - E_FREE(d); - _connman_operation_error_show(_("Connect to network service.")); - } -} - -struct connman_service_ask_pass_data -{ - const char *service_path; - E_Connman_Module_Context *ctxt; -}; - -static void -_connman_service_ask_pass_and_connect__set_cb(void *data, - DBusMessage *msg __UNUSED__, - DBusError *error) -{ - struct connman_service_ask_pass_data *d = data; - E_Connman_Service *service; - - service = _connman_ctxt_find_service_stringshare(d->ctxt, d->service_path); - if (!service) - { - _connman_operation_error_show(_("Service does not exist anymore")); - goto end; - } - - if ((!error) || (!dbus_error_is_set(error))) - _connman_service_connect(service); - -end: - if ((error) && (dbus_error_is_set(error))) - dbus_error_free(error); - eina_stringshare_del(d->service_path); - E_FREE(d); -} - -static void -_connman_service_ask_pass_and_connect__ask_cb(void *data, - const char *passphrase, - const char *service_path) -{ - E_Connman_Module_Context *ctxt = data; - E_Connman_Service *service; - struct connman_service_ask_pass_data *d; - - service = _connman_ctxt_find_service_stringshare(ctxt, service_path); - if (!service) - { - _connman_operation_error_show(_("Service does not exist anymore")); - return; - } - - if (!passphrase) - { - _connman_service_disconnect(service); - return; - } - - d = E_NEW(struct connman_service_ask_pass_data, 1); - if (!d) - return; - d->service_path = eina_stringshare_ref(service_path); - d->ctxt = ctxt; - - if (!e_connman_service_passphrase_set - (service->element, passphrase, - _connman_service_ask_pass_and_connect__set_cb, d)) - { - eina_stringshare_del(d->service_path); - E_FREE(d); - _connman_operation_error_show(_("Could not set service's passphrase")); - return; - } -} - -static void -_connman_service_ask_pass_and_connect(E_Connman_Service *service) -{ - _connman_passphrase_ask - (service, _connman_service_ask_pass_and_connect__ask_cb, service->ctxt); -} - -static void -_connman_services_free(E_Connman_Module_Context *ctxt) -{ - while (ctxt->services) - { - E_Connman_Service *service = (E_Connman_Service *)ctxt->services; - e_connman_element_listener_del - (service->element, _connman_service_changed, service); - /* no need for free or unlink, since listener_del() calls - * _connman_service_freed() - */ - //ctxt->services = eina_inlist_remove(ctxt->services, ctxt->services); - //_connman_service_free(service); - } -} - -static inline Eina_Bool -_connman_services_element_exists(const E_Connman_Module_Context *ctxt, - const E_Connman_Element *element) -{ - const E_Connman_Service *service; - - EINA_INLIST_FOREACH(ctxt->services, service) - if (service->path == element->path) - return EINA_TRUE; - - return EINA_FALSE; -} - -static inline Eina_Bool -_connman_technologies_element_exists(const E_Connman_Module_Context *ctxt, - const E_Connman_Element *element) -{ - const E_Connman_Technology *t; - - EINA_INLIST_FOREACH(ctxt->technologies, t) - { - if (t->path == element->path) - return EINA_TRUE; - } - - return EINA_FALSE; -} - -void -_connman_request_scan_cb(void *data __UNUSED__, - DBusMessage *msg __UNUSED__, - DBusError *error) -{ - static int perr = 0; - - if (error && dbus_error_is_set(error)) - { - if (perr != 1) - { - ERR("%s method failed with message \'%s\'", error->name, error->message); - } - perr = 1; - dbus_error_free(error); - } - else - perr = 0; - - return; -} - -static void -_connman_technologies_load(E_Connman_Module_Context *ctxt) -{ - unsigned int count, i; - E_Connman_Element **elements; - - if (!e_connman_manager_technologies_get(&count, &elements)) - return; - - DBG("Technologies = %d.", count); - for (i = 0; i < count; i++) - { - E_Connman_Element *e = elements[i]; - E_Connman_Technology *t; - - if ((!e) || _connman_technologies_element_exists(ctxt, e)) - continue; - - t = _connman_technology_new(ctxt, e); - if (!t) - continue; - - DBG("Added technology: %s.", t->name); - ctxt->technologies = eina_inlist_append - (ctxt->technologies, EINA_INLIST_GET(t)); - } - - if (!e_connman_manager_request_scan("", _connman_request_scan_cb, NULL)) - ERR("Request scan on all technologies failed."); - - free(elements); -} - -static void -_connman_services_load(E_Connman_Module_Context *ctxt) -{ - unsigned int i, count; - E_Connman_Element **elements; - - if (!e_connman_manager_services_get(&count, &elements)) - return; - - for (i = 0; i < count; i++) - { - E_Connman_Element *e = elements[i]; - E_Connman_Service *service; - - if ((!e) || (_connman_services_element_exists(ctxt, e))) - continue; - - service = _connman_service_new(ctxt, e); - if (!service) - continue; - - DBG("Added service: %s\n", service->name); - ctxt->services = eina_inlist_append - (ctxt->services, EINA_INLIST_GET(service)); - } - - /* no need to remove elements, as they remove themselves */ - free(elements); -} - -static void -_connman_default_service_changed(E_Connman_Module_Context *ctxt) -{ - E_Connman_Service *itr, *def = NULL; - E_Connman_Instance *inst; - const Eina_List *l; - const char *tech; - - EINA_INLIST_FOREACH(ctxt->services, itr) - { - if ((itr->state == e_str_ready) || - (itr->state == e_str_login) || - (itr->state == e_str_online)) - { - def = itr; - break; - } - else if ((itr->state == e_str_association) && - ((!def) || (def && def->state != e_str_configuration))) - def = itr; - else if (itr->state == e_str_configuration) - def = itr; - } - - DBG("Default service changed to %p (%s)", def, def ? def->name : ""); - - if (!e_connman_manager_technology_default_get(&tech)) - tech = NULL; - if (eina_stringshare_replace(&ctxt->technology, tech)) - DBG("Manager technology is '%s'", tech); - - if (!e_connman_manager_offline_mode_get(&ctxt->offline_mode)) - ctxt->offline_mode = EINA_FALSE; - - if ((e_config->mode.offline != ctxt->offline_mode) && - (!ctxt->offline_mode_pending)) - { - e_config->mode.offline = ctxt->offline_mode; - e_config_mode_changed(); - e_config_save_queue(); - } - - ctxt->default_service = def; - EINA_LIST_FOREACH(ctxt->instances, l, inst) - _connman_gadget_update(inst); -} - -static void -_connman_services_reload(E_Connman_Module_Context *ctxt) -{ - _connman_services_load(ctxt); - _connman_default_service_changed(ctxt); -} - -static Eina_Bool -_connman_default_service_changed_delayed_do(void *data) -{ - E_Connman_Module_Context *ctxt = data; - DBG("Do delayed change."); - - ctxt->poller.default_service_changed = NULL; - _connman_default_service_changed(ctxt); - return ECORE_CALLBACK_CANCEL; -} - -static void -_connman_default_service_changed_delayed(E_Connman_Module_Context *ctxt) -{ - if (!ctxt->has_manager) - return; - DBG("Request delayed change."); - if (ctxt->poller.default_service_changed) - ecore_poller_del(ctxt->poller.default_service_changed); - ctxt->poller.default_service_changed = ecore_poller_add - (ECORE_POLLER_CORE, 1, _connman_default_service_changed_delayed_do, ctxt); -} - -static void _connman_popup_del(E_Connman_Instance *inst); - -static Eina_Bool -_connman_popup_input_window_mouse_up_cb(void *data, - int type __UNUSED__, - void *event) -{ - Ecore_Event_Mouse_Button *ev = event; - E_Connman_Instance *inst = data; - - if (ev->window != inst->ui.input.win) - return ECORE_CALLBACK_PASS_ON; - - _connman_popup_del(inst); - - return ECORE_CALLBACK_PASS_ON; -} - -static Eina_Bool -_connman_popup_input_window_key_down_cb(void *data, - int type __UNUSED__, - void *event) -{ - Ecore_Event_Key *ev = event; - E_Connman_Instance *inst = data; - const char *keysym; - - if (ev->window != inst->ui.input.win) - return ECORE_CALLBACK_PASS_ON; - - keysym = ev->key; - if (strcmp(keysym, "Escape") == 0) - _connman_popup_del(inst); - - return ECORE_CALLBACK_PASS_ON; -} - -static void -_connman_popup_input_window_destroy(E_Connman_Instance *inst) -{ - ecore_x_window_free(inst->ui.input.win); - inst->ui.input.win = 0; - - ecore_event_handler_del(inst->ui.input.mouse_up); - inst->ui.input.mouse_up = NULL; - - ecore_event_handler_del(inst->ui.input.key_down); - inst->ui.input.key_down = NULL; -} - -static void -_connman_popup_input_window_create(E_Connman_Instance *inst) -{ - Ecore_X_Window_Configure_Mask mask; - Ecore_X_Window w, popup_w; - E_Manager *man; - - man = e_manager_current_get(); - - w = ecore_x_window_input_new(man->root, 0, 0, man->w, man->h); - mask = (ECORE_X_WINDOW_CONFIGURE_MASK_STACK_MODE | - ECORE_X_WINDOW_CONFIGURE_MASK_SIBLING); - popup_w = inst->popup->win->evas_win; - ecore_x_window_configure(w, mask, 0, 0, 0, 0, 0, popup_w, - ECORE_X_WINDOW_STACK_BELOW); - ecore_x_window_show(w); - - inst->ui.input.mouse_up = - ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_UP, - _connman_popup_input_window_mouse_up_cb, inst); - - inst->ui.input.key_down = - ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, - _connman_popup_input_window_key_down_cb, inst); - - inst->ui.input.win = w; -} - -static void -_connman_popup_cb_offline_mode_changed(void *data, - Evas_Object *obj) -{ - E_Connman_Instance *inst = data; - E_Connman_Module_Context *ctxt = inst->ctxt; - Eina_Bool offline = e_widget_check_checked_get(obj); - - if ((!ctxt) || (!ctxt->has_manager)) - { - _connman_operation_error_show(_("ConnMan Daemon is not running.")); - return; - } - - if (!e_connman_manager_offline_mode_set - (offline, _connman_toggle_offline_mode_cb, ctxt)) - { - _connman_operation_error_show - (_("Cannot toggle system's offline mode.")); - return; - } - ctxt->offline_mode_pending = EINA_TRUE; -} - -static void -_connman_popup_cb_controls(void *data, - void *data2 __UNUSED__) -{ - E_Connman_Instance *inst = data; - - if (!inst) - return; - if (inst->popup) - _connman_popup_del(inst); - if (inst->ctxt->conf_dialog) - return; - - inst->ctxt->conf_dialog = e_connman_config_dialog_new(NULL, inst->ctxt); -} - -static void -_connman_popup_service_selected(void *data) -{ - E_Connman_Instance *inst = data; - E_Connman_Module_Context *ctxt = inst->ctxt; - E_Connman_Service *service; - - if (inst->first_selection) - { - inst->first_selection = EINA_FALSE; - return; - } - - if (!inst->service_path) - return; - - service = _connman_ctxt_find_service_stringshare(ctxt, inst->service_path); - if (!service) - return; - - _connman_popup_del(inst); - - if ((service->state != e_str_idle) && - (service->state != e_str_disconnect) && - (service->state != e_str_failure)) - _connman_service_disconnect(service); - else if (service->pass_required) - _connman_service_ask_pass_and_connect(service); - else - _connman_service_connect(service); -} - -Evas_Object * -_connman_service_new_list_item(Evas *evas, - E_Connman_Service *service) -{ - Evas_Object *icon; - Edje_Message_Int msg; - char buf[128]; - - snprintf(buf, sizeof(buf), "e/modules/connman/icon/%s", service->type); - icon = edje_object_add(evas); - e_theme_edje_object_set(icon, "base/theme/modules/connman", buf); - - snprintf(buf, sizeof(buf), "e,state,%s", service->state); - edje_object_signal_emit(icon, buf, "e"); - - if (service->mode) - { - snprintf(buf, sizeof(buf), "e,mode,%s", service->mode); - edje_object_signal_emit(icon, buf, "e"); - } - - if (service->security) - { - snprintf(buf, sizeof(buf), "e,security,%s", service->security); - edje_object_signal_emit(icon, buf, "e"); - } - - if (service->favorite) - edje_object_signal_emit(icon, "e,favorite,yes", "e"); - else - edje_object_signal_emit(icon, "e,favorite,no", "e"); - - if (service->auto_connect) - edje_object_signal_emit(icon, "e,auto_connect,yes", "e"); - else - edje_object_signal_emit(icon, "e,auto_connect,no", "e"); - - if (service->pass_required) - edje_object_signal_emit(icon, "e,pass_required,yes", "e"); - else - edje_object_signal_emit(icon, "e,pass_required,no", "e"); - - msg.val = service->strength; - edje_object_message_send(icon, EDJE_MESSAGE_INT, 1, &msg); - - return icon; -} - -static void -_connman_popup_update(E_Connman_Instance *inst) -{ - Evas_Object *list = inst->ui.list; - E_Connman_Service *service; - const char *default_path; - Evas *evas = evas_object_evas_get(list); - int i, selected; - - default_path = inst->ctxt->default_service ? - inst->ctxt->default_service->path : NULL; - - /* TODO: replace this with a scroller + list of edje - * objects that are more full of features - */ - e_widget_ilist_freeze(list); - e_widget_ilist_clear(list); - i = 0; - selected = -1; - EINA_INLIST_FOREACH(inst->ctxt->services, service) - { - Evas_Object *icon; - - if (service->path == default_path) - selected = i; - i++; - - icon = _connman_service_new_list_item(evas, service); - - e_widget_ilist_append - (list, icon, service->name, _connman_popup_service_selected, - inst, service->path); - } - - if (selected >= 0) - { - inst->first_selection = EINA_TRUE; - e_widget_ilist_selected_set(list, selected); - } - else - inst->first_selection = EINA_FALSE; - - e_widget_ilist_thaw(list); - e_widget_ilist_go(list); - - e_widget_check_checked_set(inst->ui.offline_mode, inst->ctxt->offline_mode); -} - -static void -_connman_popup_del(E_Connman_Instance *inst) -{ - eina_stringshare_replace(&inst->service_path, NULL); - _connman_popup_input_window_destroy(inst); - e_object_del(E_OBJECT(inst->popup)); - inst->popup = NULL; -} - -static void -_connman_popup_new(E_Connman_Instance *inst) +_connman_edje_view_update(E_Connman_Instance *inst, Evas_Object *o) { E_Connman_Module_Context *ctxt = inst->ctxt; - Evas *evas; - Evas_Coord mw, mh; - - if (inst->popup) - { - e_gadcon_popup_show(inst->popup); - return; - } - - inst->popup = e_gadcon_popup_new(inst->gcc); - evas = inst->popup->win->evas; - - inst->ui.table = e_widget_table_add(evas, 0); - - if (ctxt->default_service) - eina_stringshare_replace(&inst->service_path, ctxt->default_service->path); - - // TODO: get this size from edj - inst->ui.list = e_widget_ilist_add(evas, 32, 32, &inst->service_path); - e_widget_size_min_set(inst->ui.list, 180, 100); - e_widget_table_object_append(inst->ui.table, inst->ui.list, - 0, 0, 1, 5, 1, 1, 1, 1); - - inst->offline_mode = ctxt->offline_mode; - inst->ui.offline_mode = e_widget_check_add - (evas, _("Offline mode"), &inst->offline_mode); - - evas_object_show(inst->ui.offline_mode); - e_widget_table_object_append(inst->ui.table, inst->ui.offline_mode, - 0, 5, 1, 1, 1, 1, 1, 0); - e_widget_on_change_hook_set - (inst->ui.offline_mode, _connman_popup_cb_offline_mode_changed, inst); - - inst->ui.button = e_widget_button_add - (evas, _("Controls"), NULL, - _connman_popup_cb_controls, inst, NULL); - e_widget_table_object_append(inst->ui.table, inst->ui.button, - 0, 6, 1, 1, 1, 1, 1, 0); - - _connman_popup_update(inst); - - e_widget_size_min_get(inst->ui.table, &mw, &mh); - if (mh < 200) mh = 200; - if (mw < 200) mw = 200; - e_widget_size_min_set(inst->ui.table, mw, mh); - - e_gadcon_popup_content_set(inst->popup, inst->ui.table); - e_gadcon_popup_show(inst->popup); - _connman_popup_input_window_create(inst); -} - -static void -_connman_menu_cb_cfg(void *data, - E_Menu *menu __UNUSED__, - E_Menu_Item *mi __UNUSED__) -{ - E_Connman_Instance *inst = data; - - if (!inst) - return; - if (inst->popup) - _connman_popup_del(inst); - if (inst->ctxt->conf_dialog) - return; - - inst->ctxt->conf_dialog = e_connman_config_dialog_new(NULL, inst->ctxt); -} - -static void -_connman_menu_new(E_Connman_Instance *inst, - Evas_Event_Mouse_Down *ev) -{ - E_Zone *zone; - E_Menu *m; - E_Menu_Item *mi; - int x, y; - - zone = e_util_zone_current_get(e_manager_current_get()); - - m = e_menu_new(); - mi = e_menu_item_new(m); - e_menu_item_label_set(mi, _("Settings")); - e_util_menu_item_theme_icon_set(mi, "configure"); - e_menu_item_callback_set(mi, _connman_menu_cb_cfg, inst); - - m = e_gadcon_client_util_menu_items_append(inst->gcc, m, 0); - e_gadcon_canvas_zone_geometry_get(inst->gcc->gadcon, &x, &y, NULL, NULL); - e_menu_activate_mouse(m, zone, x + ev->output.x, y + ev->output.y, - 1, 1, E_MENU_POP_DIRECTION_AUTO, ev->timestamp); - evas_event_feed_mouse_up(inst->gcc->gadcon->evas, ev->button, - EVAS_BUTTON_NONE, ev->timestamp, NULL); -} - -static void -_connman_tip_new(E_Connman_Instance *inst) -{ - Evas *e; - - inst->tip = e_gadcon_popup_new(inst->gcc); - if (!inst->tip) return; - - e = inst->tip->win->evas; - - inst->o_tip = edje_object_add(e); - e_theme_edje_object_set(inst->o_tip, "base/theme/modules/connman/tip", - "e/modules/connman/tip"); - - _connman_tip_update(inst); - - e_gadcon_popup_content_set(inst->tip, inst->o_tip); - e_gadcon_popup_show(inst->tip); -} - -static void -_connman_tip_del(E_Connman_Instance *inst) -{ - evas_object_del(inst->o_tip); - e_object_del(E_OBJECT(inst->tip)); - inst->tip = NULL; - inst->o_tip = NULL; -} - -static void -_connman_cb_mouse_down(void *data, - Evas *evas __UNUSED__, - Evas_Object *obj __UNUSED__, - void *event) -{ - E_Connman_Instance *inst; - Evas_Event_Mouse_Down *ev; - - inst = data; - if (!inst) - return; - - ev = event; - if (ev->button == 1) - { - if (!inst->popup) - _connman_popup_new(inst); - else - _connman_popup_del(inst); - } - else if (ev->button == 2) - _connman_toggle_offline_mode(inst->ctxt); - else if (ev->button == 3) - _connman_menu_new(inst, ev); -} - -static void -_connman_cb_mouse_in(void *data, - Evas *evas __UNUSED__, - Evas_Object *obj __UNUSED__, - void *event __UNUSED__) -{ - E_Connman_Instance *inst = data; - - if (inst->tip) - return; - - _connman_tip_new(inst); -} - -static void -_connman_cb_mouse_out(void *data, - Evas *evas __UNUSED__, - Evas_Object *obj __UNUSED__, - void *event __UNUSED__) -{ - E_Connman_Instance *inst = data; - - if (!inst->tip) - return; - - _connman_tip_del(inst); -} - -static void -_connman_edje_view_update(E_Connman_Instance *inst, - Evas_Object *o) -{ - E_Connman_Module_Context *ctxt = inst->ctxt; - const E_Connman_Service *service; Edje_Message_Int msg; char buf[128]; @@ -1437,22 +65,11 @@ _connman_edje_view_update(E_Connman_Instance *inst, edje_object_part_text_set(o, "e.text.offline_mode", ""); } - if (ctxt->technology && ctxt->technology[0]) - { - edje_object_part_text_set(o, "e.text.technology", - ctxt->technology); - snprintf(buf, sizeof(buf), "e,changed,technology,%s", - ctxt->technology); - edje_object_signal_emit(o, buf, "e"); - } - else if (!ctxt->default_service) - { edje_object_part_text_set(o, "e.text.technology", ""); edje_object_signal_emit(o, "e,changed,technology,none", "e"); - } - service = ctxt->default_service; - if (!service) + + if (1) // not connected { edje_object_part_text_set(o, "e.text.name", _("No Connection")); edje_object_signal_emit(o, "e,changed,service,none", "e"); @@ -1478,114 +95,42 @@ _connman_edje_view_update(E_Connman_Instance *inst, return; } - - edje_object_signal_emit(o, "e,changed,connected,yes", "e"); - - if (service->name) - edje_object_part_text_set(o, "e.text.name", service->name); - else - edje_object_part_text_set(o, "e.text.name", _("Unknown Name")); - - if (service->error) - { - edje_object_part_text_set(o, "e.text.error", service->error); - edje_object_signal_emit(o, "e,changed,error,yes", "e"); - } - else - { - edje_object_part_text_set(o, "e.text.error", _("No error")); - edje_object_signal_emit(o, "e,changed,error,no", "e"); - } - - snprintf(buf, sizeof(buf), "e,changed,service,%s", service->type); - edje_object_signal_emit(o, buf, "e"); - - if (!ctxt->technology) - { - edje_object_part_text_set(o, "e.text.technology", service->type); - snprintf(buf, sizeof(buf), "e,changed,technology,%s", service->type); - edje_object_signal_emit(o, buf, "e"); - } - - snprintf(buf, sizeof(buf), "e,changed,state,%s", service->state); - edje_object_signal_emit(o, buf, "e"); - edje_object_part_text_set(o, "e.text.state", _(service->state)); - - if (service->mode) - { - snprintf(buf, sizeof(buf), "e,changed,mode,%s", service->mode); - edje_object_signal_emit(o, buf, "e"); - } - else - edje_object_signal_emit(o, "e,changed,mode,none", "e"); - - if (service->security) - { - snprintf(buf, sizeof(buf), "e,changed,security,%s", service->security); - edje_object_signal_emit(o, buf, "e"); - } - else - edje_object_signal_emit(o, "e,changed,security,none", "e"); - - if (service->ipv4_address) - { - edje_object_part_text_set(o, "e.text.ipv4_address", service->ipv4_address); - edje_object_signal_emit(o, "e,changed,ipv4_address,yes", "e"); - } - else - { - edje_object_part_text_set(o, "e.text.ipv4_address", ""); - edje_object_signal_emit(o, "e,changed,ipv4_address,no", "e"); - } - - if (service->favorite) - edje_object_signal_emit(o, "e,changed,favorite,yes", "e"); - else - edje_object_signal_emit(o, "e,changed,favorite,no", "e"); - - if (service->auto_connect) - edje_object_signal_emit(o, "e,changed,auto_connect,yes", "e"); - else - edje_object_signal_emit(o, "e,changed,auto_connect,no", "e"); - - if (service->pass_required) - edje_object_signal_emit(o, "e,changed,pass_required,yes", "e"); - else - edje_object_signal_emit(o, "e,changed,pass_required,no", "e"); - - msg.val = service->strength; - edje_object_message_send(o, EDJE_MESSAGE_INT, 1, &msg); -} - -static void -_connman_tip_update(E_Connman_Instance *inst) -{ - _connman_edje_view_update(inst, inst->o_tip); } static void _connman_gadget_update(E_Connman_Instance *inst) { - E_Connman_Module_Context *ctxt = inst->ctxt; - - if (!ctxt->has_manager && inst->popup) - _connman_popup_del(inst); - - if (inst->popup) - _connman_popup_update(inst); - if (inst->tip) - _connman_tip_update(inst); - _connman_edje_view_update(inst, inst->ui.gadget); } +static void +_connman_cb_toggle_offline_mode(E_Object *obj __UNUSED__, + const char *params __UNUSED__) +{ +} + +static void +_connman_cb_mouse_down(void *data, Evas *evas __UNUSED__, + Evas_Object *obj __UNUSED__, void *event) +{ +} + +static void +_connman_cb_mouse_in(void *data, Evas *evas __UNUSED__, + Evas_Object *obj __UNUSED__, void *event __UNUSED__) +{ +} + +static void +_connman_cb_mouse_out(void *data, Evas *evas __UNUSED__, + Evas_Object *obj __UNUSED__, void *event __UNUSED__) +{ +} + /* Gadcon Api Functions */ static E_Gadcon_Client * -_gc_init(E_Gadcon *gc, - const char *name, - const char *id, - const char *style) +_gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style) { E_Connman_Instance *inst; E_Connman_Module_Context *ctxt; @@ -1643,8 +188,7 @@ _gc_shutdown(E_Gadcon_Client *gcc) } static void -_gc_orient(E_Gadcon_Client *gcc, - E_Gadcon_Orient orient __UNUSED__) +_gc_orient(E_Gadcon_Client *gcc, E_Gadcon_Orient orient __UNUSED__) { e_gadcon_client_aspect_set(gcc, 16, 16); e_gadcon_client_min_size_set(gcc, 16, 16); @@ -1657,8 +201,7 @@ _gc_label(const E_Gadcon_Client_Class *client_class __UNUSED__) } static Evas_Object * -_gc_icon(const E_Gadcon_Client_Class *client_class __UNUSED__, - Evas *evas) +_gc_icon(const E_Gadcon_Client_Class *client_class __UNUSED__, Evas *evas) { Evas_Object *o; @@ -1695,7 +238,7 @@ static const E_Gadcon_Client_Class _gc_class = E_GADCON_CLIENT_STYLE_PLAIN }; -EAPI E_Module_Api e_modapi = {E_MODULE_API_VERSION, _e_connman_Name}; +EAPI E_Module_Api e_modapi = { E_MODULE_API_VERSION, _e_connman_Name }; static const char _act_toggle_offline_mode[] = "toggle_offline_mode"; static const char _lbl_toggle_offline_mode[] = "Toggle Offline Mode"; @@ -1729,16 +272,12 @@ _connman_manager_changed_do(void *data) { E_Connman_Module_Context *ctxt = data; - _connman_technologies_load(ctxt); - _connman_services_reload(ctxt); - ctxt->poller.manager_changed = NULL; return ECORE_CALLBACK_CANCEL; } static void -_connman_manager_changed(void *data, - const E_Connman_Element *element __UNUSED__) +_connman_manager_changed(void *data) { E_Connman_Module_Context *ctxt = data; if (ctxt->poller.manager_changed) @@ -1748,64 +287,57 @@ _connman_manager_changed(void *data, } static Eina_Bool -_connman_event_manager_in(void *data, - int type __UNUSED__, +_connman_event_manager_in(void *data, int type __UNUSED__, void *event __UNUSED__) { + DBG("Manager in"); E_Connman_Module_Context *ctxt = data; - E_Connman_Element *element; + const Eina_List *l; + E_Connman_Instance *inst; ctxt->has_manager = EINA_TRUE; - element = e_connman_manager_get(); - e_connman_element_listener_add - (element, _connman_manager_changed, ctxt, NULL); - - _connman_services_reload(ctxt); + EINA_LIST_FOREACH(ctxt->instances, l, inst) + _connman_gadget_update(inst); +// Get manager +// Set poller when changed +// Load services return ECORE_CALLBACK_PASS_ON; } static Eina_Bool -_connman_event_manager_out(void *data, - int type __UNUSED__, +_connman_event_manager_out(void *data, int type __UNUSED__, void *event __UNUSED__) { + DBG("Manager out"); E_Connman_Module_Context *ctxt = data; + const Eina_List *l; + E_Connman_Instance *inst; ctxt->has_manager = EINA_FALSE; - eina_stringshare_replace(&ctxt->technology, NULL); - - _connman_services_free(ctxt); - _connman_default_service_changed(ctxt); + EINA_LIST_FOREACH(ctxt->instances, l, inst) + _connman_gadget_update(inst); return ECORE_CALLBACK_PASS_ON; } static Eina_Bool -_connman_event_mode_changed(void *data, - int type __UNUSED__, +_connman_event_mode_changed(void *data, int type __UNUSED__, void *event __UNUSED__) { E_Connman_Module_Context *ctxt = data; if ((ctxt->offline_mode == e_config->mode.offline) || (!ctxt->has_manager)) return ECORE_CALLBACK_PASS_ON; - if (!ctxt->offline_mode_pending) - { - if (!e_connman_manager_offline_mode_set(e_config->mode.offline, - _connman_toggle_offline_mode_cb, ctxt)) - _connman_operation_error_show(_("Cannot toggle system's offline mode.")); - } - else - ctxt->offline_mode_pending = EINA_FALSE; + +//TODO: set offline mode return ECORE_CALLBACK_PASS_ON; } static E_Config_Dialog * -_connman_config(E_Container *con, - const char *params __UNUSED__) +_connman_config(E_Container *con, const char *params __UNUSED__) { E_Connman_Module_Context *ctxt; @@ -1849,8 +381,8 @@ _connman_events_register(E_Connman_Module_Context *ctxt) (E_CONNMAN_EVENT_MANAGER_IN, _connman_event_manager_in, ctxt); ctxt->event.manager_out = ecore_event_handler_add (E_CONNMAN_EVENT_MANAGER_OUT, _connman_event_manager_out, ctxt); - ctxt->event.mode_changed = ecore_event_handler_add - (E_EVENT_CONFIG_MODE_CHANGED, _connman_event_mode_changed, ctxt); + +//TODO: register for state changed (offline-mode) } static void @@ -1860,42 +392,10 @@ _connman_events_unregister(E_Connman_Module_Context *ctxt) ecore_event_handler_del(ctxt->event.manager_in); if (ctxt->event.manager_out) ecore_event_handler_del(ctxt->event.manager_out); - if (ctxt->event.mode_changed) - ecore_event_handler_del(ctxt->event.mode_changed); -} -static inline void -_connman_status_stringshare_init(void) -{ - e_str_idle = eina_stringshare_add(N_("idle")); - e_str_association = eina_stringshare_add(N_("association")); - e_str_configuration = eina_stringshare_add(N_("configuration")); - e_str_ready = eina_stringshare_add(N_("ready")); - e_str_login = eina_stringshare_add(N_("login")); - e_str_online = eina_stringshare_add(N_("online")); - e_str_disconnect = eina_stringshare_add(N_("disconnect")); - e_str_failure = eina_stringshare_add(N_("failure")); - e_str_enabled = eina_stringshare_add(N_("enabled")); - e_str_available = eina_stringshare_add(N_("available")); - e_str_connected = eina_stringshare_add(N_("connected")); - e_str_offline = eina_stringshare_add(N_("offline")); -} - -static inline void -_connman_status_stringshare_del(void) -{ - eina_stringshare_replace(&e_str_idle, NULL); - eina_stringshare_replace(&e_str_association, NULL); - eina_stringshare_replace(&e_str_configuration, NULL); - eina_stringshare_replace(&e_str_ready, NULL); - eina_stringshare_replace(&e_str_login, NULL); - eina_stringshare_replace(&e_str_online, NULL); - eina_stringshare_replace(&e_str_disconnect, NULL); - eina_stringshare_replace(&e_str_failure, NULL); - eina_stringshare_replace(&e_str_enabled, NULL); - eina_stringshare_replace(&e_str_available, NULL); - eina_stringshare_replace(&e_str_connected, NULL); - eina_stringshare_replace(&e_str_offline, NULL); +// TODO: unregister for state changed (offline-mode) +// if (ctxt->event.mode_changed) +// ecore_event_handler_del(ctxt->event.mode_changed); } EAPI void * @@ -1904,8 +404,6 @@ e_modapi_init(E_Module *m) E_Connman_Module_Context *ctxt; E_DBus_Connection *c; - _connman_status_stringshare_init(); - c = e_dbus_bus_get(DBUS_BUS_SYSTEM); if (!c) goto error_dbus_bus_get; @@ -1916,8 +414,6 @@ e_modapi_init(E_Module *m) if (!ctxt) goto error_connman_context; - ctxt->services = NULL; - ctxt->technologies = NULL; ctxt->conf_dialog = NULL; connman_mod = m; @@ -1947,7 +443,6 @@ error_connman_context: e_connman_system_shutdown(); error_connman_system_init: error_dbus_bus_get: - _connman_status_stringshare_del(); return NULL; } @@ -1959,12 +454,13 @@ _connman_instances_free(E_Connman_Module_Context *ctxt) E_Connman_Instance *inst; inst = ctxt->instances->data; - +#if 0 +//TODO: enable this aprt if (inst->popup) _connman_popup_del(inst); if (inst->tip) _connman_tip_del(inst); - +#endif e_object_del(E_OBJECT(inst->gcc)); } } @@ -1973,27 +469,17 @@ EAPI int e_modapi_shutdown(E_Module *m) { E_Connman_Module_Context *ctxt; - E_Connman_Element *element; ctxt = m->data; if (!ctxt) return 0; - element = e_connman_manager_get(); - e_connman_element_listener_del - (element, _connman_manager_changed, ctxt); - _connman_events_unregister(ctxt); - _connman_instances_free(ctxt); - _connman_services_free(ctxt); - _connman_configure_registry_unregister(); _connman_actions_unregister(ctxt); e_gadcon_provider_unregister(&_gc_class); - if (ctxt->poller.default_service_changed) - ecore_poller_del(ctxt->poller.default_service_changed); if (ctxt->poller.manager_changed) ecore_poller_del(ctxt->poller.manager_changed); @@ -2001,8 +487,6 @@ e_modapi_shutdown(E_Module *m) connman_mod = NULL; e_connman_system_shutdown(); - - _connman_status_stringshare_del(); return 1; } @@ -2016,4 +500,3 @@ e_modapi_save(E_Module *m) return 0; return 1; } - diff --git a/src/modules/connman/e_mod_main.h b/src/modules/connman/e_mod_main.h index c99b692f7..0c77718fd 100644 --- a/src/modules/connman/e_mod_main.h +++ b/src/modules/connman/e_mod_main.h @@ -3,11 +3,11 @@ #include "config.h" #include -#define E_CONNMAN_I_KNOW_THIS_API_IS_SUBJECT_TO_CHANGE 1 -#include #include -#define MOD_CONF_VERSION 2 +#include "E_Connman.h" + +#define MOD_CONF_VERSION 3 extern int _e_connman_log_dom; #undef DBG @@ -17,90 +17,54 @@ extern int _e_connman_log_dom; #define WRN(...) EINA_LOG_DOM_WARN(_e_connman_log_dom, __VA_ARGS__) #define ERR(...) EINA_LOG_DOM_ERR(_e_connman_log_dom, __VA_ARGS__) -typedef struct E_Connman_Instance E_Connman_Instance; +typedef struct E_Connman_Instance E_Connman_Instance; typedef struct E_Connman_Module_Context E_Connman_Module_Context; -typedef struct E_Connman_Service E_Connman_Service; -typedef struct E_Connman_Technology E_Connman_Technology; struct E_Connman_Instance { E_Connman_Module_Context *ctxt; - E_Gadcon_Client *gcc; - E_Gadcon_Popup *popup; - E_Menu *menu; + E_Gadcon_Client *gcc; + E_Gadcon_Popup *popup; /* used by popup */ - int offline_mode; - const char *service_path; - Eina_Bool first_selection; + int offline_mode; + const char *service_path; struct - { - Evas_Object *gadget; - Evas_Object *list; - Evas_Object *offline_mode; - Evas_Object *button; - Evas_Object *table; - struct - { - Ecore_X_Window win; - Ecore_Event_Handler *mouse_up; - Ecore_Event_Handler *key_down; - } input; - } ui; + { + Evas_Object *gadget; + Evas_Object *list; + Evas_Object *offline_mode; + Evas_Object *button; + Evas_Object *table; + + struct + { + Ecore_X_Window win; + Ecore_Event_Handler *mouse_up; + Ecore_Event_Handler *key_down; + } input; + } ui; E_Gadcon_Popup *tip; Evas_Object *o_tip; }; -struct E_Connman_Service -{ - EINA_INLIST; - E_Connman_Module_Context *ctxt; - E_Connman_Element *element; - const char *path; - const char *name; - const char *type; - const char *mode; - const char *state; - const char *error; - const char *security; - const char *ipv4_method; - const char *ipv4_address; - const char *ipv4_netmask; - unsigned char strength; - Eina_Bool favorite : 1; - Eina_Bool auto_connect : 1; - Eina_Bool pass_required : 1; -}; - -struct E_Connman_Technology -{ - EINA_INLIST; - E_Connman_Module_Context *ctxt; - E_Connman_Element *element; - const char *path; - const char *name; - const char *type; - const char *state; -}; - struct E_Connman_Module_Context { - Eina_List *instances; + Eina_List *instances; E_Config_Dialog *conf_dialog; struct st_connman_actions - { - E_Action *toggle_offline_mode; - } actions; + { + E_Action *toggle_offline_mode; + } actions; struct - { - Ecore_Event_Handler *manager_in; - Ecore_Event_Handler *manager_out; - Ecore_Event_Handler *mode_changed; - } event; + { + Ecore_Event_Handler *manager_in; + Ecore_Event_Handler *manager_out; + } event; struct { @@ -108,81 +72,18 @@ struct E_Connman_Module_Context Ecore_Poller *manager_changed; } poller; - Eina_Bool has_manager : 1; - Eina_Bool offline_mode; - Eina_Bool offline_mode_pending; - const char *technology; - const E_Connman_Service *default_service; - Eina_Inlist *services; - Eina_Inlist *technologies; + Eina_Bool has_manager; + Eina_Bool offline_mode; }; 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 void *e_modapi_init(E_Module *m); +EAPI int e_modapi_shutdown(E_Module *m); +EAPI int e_modapi_save(E_Module *m); -const char *e_connman_theme_path(void); -E_Config_Dialog *e_connman_config_dialog_new(E_Container *con, +const char *e_connman_theme_path(void); +E_Config_Dialog *e_connman_config_dialog_new(E_Container *con, E_Connman_Module_Context *ctxt); -void _connman_toggle_offline_mode(E_Connman_Module_Context *ctxt); -Evas_Object *_connman_service_new_list_item(Evas *evas, - E_Connman_Service *service); - -static inline void -_connman_dbus_error_show(const char *msg, - const DBusError *error) -{ - const char *name; - - if ((!error) || (!dbus_error_is_set(error))) - return; - - name = error->name; - if (strncmp(name, "org.moblin.connman.Error.", - sizeof("org.moblin.connman.Error.") - 1) == 0) - name += sizeof("org.moblin.connman.Error.") - 1; - - e_util_dialog_show(_("Connman Server Operation Failed"), - _("Could not execute remote operation:
" - "%s
" - "Server Error %s: %s"), - msg, name, error->message); -} - -static inline void -_connman_operation_error_show(const char *msg) -{ - e_util_dialog_show(_("Connman Operation Failed"), - _("Could not execute local operation:
%s"), - msg); -} - -static inline E_Connman_Service * -_connman_ctxt_find_service_stringshare(const E_Connman_Module_Context *ctxt, - const char *service_path) -{ - E_Connman_Service *itr; - - EINA_INLIST_FOREACH(ctxt->services, itr) - if (itr->path == service_path) - return itr; - - return NULL; -} - -static inline E_Connman_Technology * -_connman_ctxt_technology_find_stringshare(const E_Connman_Module_Context *ctxt, - const char *path) -{ - E_Connman_Technology *t; - - EINA_INLIST_FOREACH(ctxt->technologies, t) - if (t->path == path) - return t; - - return NULL; -} /** * @addtogroup Optional_Devices diff --git a/src/modules/wizard/page_110.c b/src/modules/wizard/page_110.c index 1f614df2c..c3d063d84 100644 --- a/src/modules/wizard/page_110.c +++ b/src/modules/wizard/page_110.c @@ -2,13 +2,9 @@ #include "e.h" #include "e_mod_main.h" #ifdef HAVE_ECONNMAN -#define E_CONNMAN_I_KNOW_THIS_API_IS_SUBJECT_TO_CHANGE 1 -#include +#include #endif -static Ecore_Event_Handler *handler = NULL; -static Ecore_Timer *connman_timeout = NULL; - static void _recommend_connman(E_Wizard_Page *pg) { @@ -36,26 +32,11 @@ _recommend_connman(E_Wizard_Page *pg) } #ifdef HAVE_ECONNMAN -static Eina_Bool -_connman_in(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__) -{ - if (handler) - { - ecore_event_handler_del(handler); - handler = NULL; - } - if (connman_timeout) - { - ecore_timer_del(connman_timeout); - connman_timeout = NULL; - } - e_wizard_button_next_enable_set(1); - e_wizard_next(); - return EINA_TRUE; -} +static DBusPendingCall *pending_connman; +static Ecore_Timer *connman_timeout = NULL; static Eina_Bool -_connman_timeout(void *data) +_connman_fail(void *data) { E_Wizard_Page *pg = data; E_Config_Module *em; @@ -73,17 +54,38 @@ _connman_timeout(void *data) break; } } + e_config_save_queue(); - connman_timeout = NULL; - if (handler) + if (pending_connman) { - ecore_event_handler_del(handler); - handler = NULL; + dbus_pending_call_cancel(pending_connman); + pending_connman = NULL; } + connman_timeout = NULL; _recommend_connman(pg); return EINA_FALSE; } +static void +_check_connman_owner(void *data, DBusMessage *msg, DBusError *err) +{ + pending_connman = NULL; + + if (connman_timeout) + { + ecore_timer_del(connman_timeout); + connman_timeout = NULL; + } + + if (!msg) + { + _connman_fail(data); + return; + } + + e_wizard_button_next_enable_set(1); + e_wizard_next(); +} #endif EAPI int @@ -108,12 +110,16 @@ wizard_page_show(E_Wizard_Page *pg) if (c) { #ifdef HAVE_ECONNMAN - if (e_connman_system_init(c)) + if (pending_connman) + dbus_pending_call_cancel(pending_connman); + + pending_connman = e_dbus_name_has_owner(c, "net.connman", + _check_connman_owner, + pg); + if (pending_connman) { - handler = ecore_event_handler_add - (E_CONNMAN_EVENT_MANAGER_IN, _connman_in, NULL); if (connman_timeout) ecore_timer_del(connman_timeout); - connman_timeout = ecore_timer_add(2.0, _connman_timeout, pg); + connman_timeout = ecore_timer_add(2.0, _connman_fail, pg); have_connman = 1; e_wizard_button_next_enable_set(0); } @@ -146,17 +152,19 @@ wizard_page_show(E_Wizard_Page *pg) EAPI int wizard_page_hide(E_Wizard_Page *pg __UNUSED__) { - if (handler) +#ifdef HAVE_ECONNMAN + if (pending_connman) { - ecore_event_handler_del(handler); - handler = NULL; + dbus_pending_call_cancel(pending_connman); + pending_connman = NULL; } if (connman_timeout) { ecore_timer_del(connman_timeout); connman_timeout = NULL; } -// if (pg->data) evas_object_del(pg->data); +#endif + return 1; }