From aa7059eca40c02d8e4785f9b421162abe23a3dc2 Mon Sep 17 00:00:00 2001 From: JuWan Kim Date: Tue, 17 Mar 2015 11:56:16 +0900 Subject: [PATCH 01/16] Change c to cpp in ./ug/proxy/ Change-Id: Id26540561c151368479171e7b3f4802875ef0c7b Signed-off-by: JuWan Kim --- ug/proxy/CMakeLists.txt | 12 +++--- .../src/{connection_mgr.c => connection_mgr.cpp} | 2 +- ug/proxy/src/{main_view.c => main_view.cpp} | 50 +++++++++++----------- .../{ug_proxy_settings.c => ug_proxy_settings.cpp} | 18 +++++--- ug/proxy/src/{util.c => util.cpp} | 0 ug/proxy/src/{vconf_mgr.c => vconf_mgr.cpp} | 0 ug/proxy/src/{wifi_mgr.c => wifi_mgr.cpp} | 8 ++-- 7 files changed, 49 insertions(+), 41 deletions(-) rename ug/proxy/src/{connection_mgr.c => connection_mgr.cpp} (99%) rename ug/proxy/src/{main_view.c => main_view.cpp} (97%) rename ug/proxy/src/{ug_proxy_settings.c => ug_proxy_settings.cpp} (96%) rename ug/proxy/src/{util.c => util.cpp} (100%) rename ug/proxy/src/{vconf_mgr.c => vconf_mgr.cpp} (100%) rename ug/proxy/src/{wifi_mgr.c => wifi_mgr.cpp} (97%) diff --git a/ug/proxy/CMakeLists.txt b/ug/proxy/CMakeLists.txt index 33dd82d..333b6bc 100644 --- a/ug/proxy/CMakeLists.txt +++ b/ug/proxy/CMakeLists.txt @@ -47,12 +47,12 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fvisibility=hidden -Wall -W SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") SET(SRCS - src/ug_proxy_settings.c - src/main_view.c - src/vconf_mgr.c - src/connection_mgr.c - src/wifi_mgr.c - src/util.c + src/ug_proxy_settings.cpp + src/main_view.cpp + src/vconf_mgr.cpp + src/connection_mgr.cpp + src/wifi_mgr.cpp + src/util.cpp ) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) diff --git a/ug/proxy/src/connection_mgr.c b/ug/proxy/src/connection_mgr.cpp similarity index 99% rename from ug/proxy/src/connection_mgr.c rename to ug/proxy/src/connection_mgr.cpp index 3726c84..ca7d628 100644 --- a/ug/proxy/src/connection_mgr.c +++ b/ug/proxy/src/connection_mgr.cpp @@ -154,7 +154,7 @@ int connection_mgr_get_profile_info(connection_h connection, CONNECTION_ITERATOR_TYPE_REGISTERED, &iter); if (ret != CONNECTION_ERROR_NONE) { _ERR("Fail to get profile iterator: %s.\n", - _convert_error_to_string(ret)); + _convert_error_to_string((connection_error_e) ret)); return RET_FAILED; } diff --git a/ug/proxy/src/main_view.c b/ug/proxy/src/main_view.cpp similarity index 97% rename from ug/proxy/src/main_view.c rename to ug/proxy/src/main_view.cpp index 4a1e9ae..173e89d 100644 --- a/ug/proxy/src/main_view.c +++ b/ug/proxy/src/main_view.cpp @@ -176,7 +176,7 @@ static struct _priv *_init_priv() { struct _priv *priv; - priv = calloc(1, sizeof(*priv)); + priv = (struct _priv *) calloc(1, sizeof(*priv)); if (!priv) { _ERR("calloc priv failed."); return NULL; @@ -230,8 +230,8 @@ static void _base_key_pressed_cb(void *data, Evas *evas, return; } - ev = ei; - priv = data; + ev = (Evas_Event_Key_Down *) ei; + priv = (struct _priv *) data; if (!ev->keyname) { _ERR("ev->keyname is NULL."); @@ -505,7 +505,7 @@ static void _ctxpopup_unfocused_cb(void *data, return; } - priv = data; + priv = (struct _priv *) data; _unset_layout_dim(priv); @@ -589,8 +589,8 @@ static void _ctxpopup_key_pressed_cb(void *data, Evas *evas, return; } - priv = data; - ev = ei; + priv = (struct _priv *) data; + ev = (Evas_Event_Key_Down *) ei; if (!ev->keyname) { _ERR("ev->keyname is NULL."); @@ -668,7 +668,7 @@ static void _method_none_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) return; } - priv = data; + priv = (struct _priv *) data; _method_btn_click_proc(priv, METHOD_NONE); } @@ -691,7 +691,7 @@ static void _method_man_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) return; } - priv = data; + priv = (struct _priv *) data; _method_btn_click_proc(priv, METHOD_MAN); } @@ -714,7 +714,7 @@ static void _method_auto_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) return; } - priv = data; + priv = (struct _priv *) data; _method_btn_click_proc(priv, METHOD_AUTO); } @@ -748,7 +748,7 @@ static void _method_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) return; } - priv = data; + priv = (struct _priv *) data; base = priv->base; ctxpopup = util_add_layout(base, UG_PROXY_EDJ_FILE, @@ -901,7 +901,7 @@ static void _value_key_pressed_cb(void *data, Evas *evas, return; } - ev = ei; + ev = (Evas_Event_Key_Down *) ei; if (!ev->keyname) { _ERR("ev->keyname is NULL."); @@ -1027,22 +1027,22 @@ static void _set_the_value(struct _priv *priv) } value1 = NULL; - btn = evas_object_data_get(priv->ctxpopup, IP_VALUE1); + btn = (Evas_Object *) evas_object_data_get(priv->ctxpopup, IP_VALUE1); if (btn) value1 = elm_object_text_get(btn); value2 = NULL; - btn = evas_object_data_get(priv->ctxpopup, IP_VALUE2); + btn = (Evas_Object *) evas_object_data_get(priv->ctxpopup, IP_VALUE2); if (btn) value2 = elm_object_text_get(btn); value3 = NULL; - btn = evas_object_data_get(priv->ctxpopup, IP_VALUE3); + btn = (Evas_Object *) evas_object_data_get(priv->ctxpopup, IP_VALUE3); if (btn) value3 = elm_object_text_get(btn); value4 = NULL; - btn = evas_object_data_get(priv->ctxpopup, IP_VALUE4); + btn = (Evas_Object *) evas_object_data_get(priv->ctxpopup, IP_VALUE4); if (btn) value4 = elm_object_text_get(btn); @@ -1080,8 +1080,8 @@ static void _value_ctxpopup_key_pressed_cb(void *data, Evas *evas, return; } - ev = ei; - priv = data; + ev = (Evas_Event_Key_Down *) ei; + priv = (struct _priv *) data; if (!ev->keyname) { _ERR("ev->keyname is NULL."); @@ -1176,7 +1176,7 @@ static void _proxy_ip_btn_clicked_cb(void *data, return; } - priv = data; + priv = (struct _priv *) data; _keep_btn_dim_focused(priv->proxy_btn); @@ -1206,8 +1206,8 @@ static void _entry_key_pressed_cb(void *data, Evas *e, return; } - priv = data; - ev = ei; + priv = (struct _priv *) data; + ev = (Evas_Event_Key_Down *) ei; if (!ev->keyname) { _ERR("ev->keyname is NULL."); @@ -1303,7 +1303,7 @@ static void _url_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) return; } - priv = data; + priv = (struct _priv *) data; _create_input_entry(priv); } @@ -1580,7 +1580,7 @@ static void _ctxpopup_ok_btn_clicked_cb(void *data, return; } - priv = data; + priv = (struct _priv *) data; if (priv->ctxpopup) { evas_object_del(priv->ctxpopup); @@ -1857,7 +1857,7 @@ static void _ok_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) return; } - priv = data; + priv = (struct _priv *) data; ret = _set_proxy(priv); if (ret != RET_SUCCESS) { @@ -1895,7 +1895,7 @@ static void _cancel_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) return; } - priv = data; + priv = (struct _priv *) data; ug_destroy_me(priv->ug); } @@ -2058,7 +2058,7 @@ void destroy_main_view(Evas_Object *base) return; } - priv = evas_object_data_get(base, KEY_PRIV); + priv = (struct _priv *) evas_object_data_get(base, KEY_PRIV); if (!priv) return; diff --git a/ug/proxy/src/ug_proxy_settings.c b/ug/proxy/src/ug_proxy_settings.cpp similarity index 96% rename from ug/proxy/src/ug_proxy_settings.c rename to ug/proxy/src/ug_proxy_settings.cpp index 6ddb58c..b53faaa 100644 --- a/ug/proxy/src/ug_proxy_settings.c +++ b/ug/proxy/src/ug_proxy_settings.cpp @@ -25,6 +25,10 @@ #include "defs.h" #include "dbg.h" +#if defined (__cplusplus) +extern "C" { +#endif + struct _ug_data { Evas_Object *win; Evas_Object *base; @@ -62,12 +66,12 @@ static void *_on_create(ui_gadget_h ug, enum ug_mode mode, return NULL; } - ugd = priv; + ugd = (struct _ug_data *) priv; ugd->ug = ug; elm_theme_extension_add(NULL, UG_PROXY_EDJ_THEME); - win = ug_get_window(); + win = (Evas_Object *) ug_get_window(); if (!win) { _ERR("window get failed"); return NULL; @@ -158,7 +162,7 @@ static void _on_resume(ui_gadget_h ug, service_h service, void *priv) */ static void _on_destroy(ui_gadget_h ug, service_h service, void *priv) { - struct _ug_data *ugd = priv; + struct _ug_data *ugd = (struct _ug_data *) priv; if (!ug || !priv) { _ERR("Parameter error!"); @@ -245,7 +249,7 @@ UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops) if (!ops) return -1; - ugd = calloc(1, sizeof(*ugd)); + ugd = (struct _ug_data *) calloc(1, sizeof(*ugd)); if (!ugd) return -1; @@ -280,7 +284,11 @@ UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops) if (!ops) return; - ugd = ops->priv; + ugd = (struct _ug_data *) ops->priv; free(ugd); } + +#if defined (__cplusplus) +}; +#endif diff --git a/ug/proxy/src/util.c b/ug/proxy/src/util.cpp similarity index 100% rename from ug/proxy/src/util.c rename to ug/proxy/src/util.cpp diff --git a/ug/proxy/src/vconf_mgr.c b/ug/proxy/src/vconf_mgr.cpp similarity index 100% rename from ug/proxy/src/vconf_mgr.c rename to ug/proxy/src/vconf_mgr.cpp diff --git a/ug/proxy/src/wifi_mgr.c b/ug/proxy/src/wifi_mgr.cpp similarity index 97% rename from ug/proxy/src/wifi_mgr.c rename to ug/proxy/src/wifi_mgr.cpp index 88616a2..98eb1b1 100644 --- a/ug/proxy/src/wifi_mgr.c +++ b/ug/proxy/src/wifi_mgr.cpp @@ -150,7 +150,7 @@ int wifi_mgr_set_proxy_type(enum method_enum method) } ap = NULL; - ret = wifi_get_connected_ap(ap); + ret = wifi_get_connected_ap(&ap); if (ret != WIFI_ERROR_NONE) { _ERR("wifi_get_connected_ap() failed."); return ret; @@ -197,7 +197,7 @@ int wifi_mgr_get_proxy_type(enum method_enum *method) } ap = NULL; - ret = wifi_get_connected_ap(ap); + ret = wifi_get_connected_ap(&ap); if (ret != WIFI_ERROR_NONE) { _ERR("wifi_get_connected_ap() failed."); return ret; @@ -239,7 +239,7 @@ int wifi_mgr_set_proxy_address(const char *ip) int ret; ap = NULL; - ret = wifi_get_connected_ap(ap); + ret = wifi_get_connected_ap(&ap); if (ret != WIFI_ERROR_NONE) { _ERR("wifi_get_connected_ap() failed."); return ret; @@ -271,7 +271,7 @@ int wifi_mgr_get_proxy_address(char **ip) } ap = NULL; - ret = wifi_get_connected_ap(ap); + ret = wifi_get_connected_ap(&ap); if (ret != WIFI_ERROR_NONE) { _ERR("wifi_get_connected_ap() failed."); return ret; -- 2.7.4 From 8bdf69ca99c6494e317512d6fa0860888638c8a4 Mon Sep 17 00:00:00 2001 From: JuWan Kim Date: Tue, 17 Mar 2015 14:24:34 +0900 Subject: [PATCH 02/16] Change c to cpp in ./ug/system/ Change-Id: I01ae2cbf1b6dbc679cb13f03fd756d80464001a7 Signed-off-by: JuWan Kim --- ug/system/clock/CMakeLists.txt | 10 ++--- ug/system/clock/include/ug_clock.h | 8 ++++ ug/system/clock/src/{ug_clock.c => ug_clock.cpp} | 34 +++++++++------ ...ck_spin_control.c => ug_clock_spin_control.cpp} | 51 ++++++++++------------ .../{ug_clock_sublist.c => ug_clock_sublist.cpp} | 26 +++++------ ...in_control.c => ug_clock_time_spin_control.cpp} | 38 ++++++++-------- .../src/{ug_clock_utils.c => ug_clock_utils.cpp} | 0 7 files changed, 88 insertions(+), 79 deletions(-) rename ug/system/clock/src/{ug_clock.c => ug_clock.cpp} (97%) rename ug/system/clock/src/{ug_clock_spin_control.c => ug_clock_spin_control.cpp} (91%) rename ug/system/clock/src/{ug_clock_sublist.c => ug_clock_sublist.cpp} (93%) rename ug/system/clock/src/{ug_clock_time_spin_control.c => ug_clock_time_spin_control.cpp} (93%) rename ug/system/clock/src/{ug_clock_utils.c => ug_clock_utils.cpp} (100%) diff --git a/ug/system/clock/CMakeLists.txt b/ug/system/clock/CMakeLists.txt index 5884bf0..24e9640 100755 --- a/ug/system/clock/CMakeLists.txt +++ b/ug/system/clock/CMakeLists.txt @@ -41,11 +41,11 @@ ENDFOREACH(FLAG) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fvisibility=hidden -Wall") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") SET(SRCS - src/ug_clock.c - src/ug_clock_spin_control.c - src/ug_clock_sublist.c - src/ug_clock_utils.c - src/ug_clock_time_spin_control.c + src/ug_clock.cpp + src/ug_clock_spin_control.cpp + src/ug_clock_sublist.cpp + src/ug_clock_utils.cpp + src/ug_clock_time_spin_control.cpp ) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) diff --git a/ug/system/clock/include/ug_clock.h b/ug/system/clock/include/ug_clock.h index 4c4e6b4..11d8187 100755 --- a/ug/system/clock/include/ug_clock.h +++ b/ug/system/clock/include/ug_clock.h @@ -19,6 +19,14 @@ #include +#if defined (__cplusplus) +extern "C" { +#endif + void view_ug_clock_refresh(Evas_Object *base, unsigned int *date, int *time); +#if defined (__cplusplus) +}; +#endif + #endif /* __UG_CLOCK_H__ */ diff --git a/ug/system/clock/src/ug_clock.c b/ug/system/clock/src/ug_clock.cpp similarity index 97% rename from ug/system/clock/src/ug_clock.c rename to ug/system/clock/src/ug_clock.cpp index ce376f0..e35505d 100755 --- a/ug/system/clock/src/ug_clock.c +++ b/ug/system/clock/src/ug_clock.cpp @@ -32,6 +32,10 @@ #define CLOCK_SUBLIST_NULL_BTNS 2 #define UG_CLOCK_DATA_ID "ug_clock_data" +#if defined (__cplusplus) +extern "C" { +#endif + struct _ug_data { Evas_Object *win; Evas_Object *base; @@ -110,7 +114,7 @@ static void _close_btn_clicked_cb(void *priv, Evas_Object *obj, void *ei) return; } - data = priv; + data = (struct _ug_data *) priv; ug_destroy_me(data->ug); } @@ -139,13 +143,13 @@ static void _key_down_on_close_btn_cb(void *priv, Evas *e, return; } - event = ei; + event = (Evas_Event_Key_Down *) ei; keyname = event->keyname; if (!keyname) return; - data = priv; + data = (struct _ug_data *) priv; _key_down_cb(keyname, data); } @@ -175,12 +179,12 @@ static void _key_down_on_btns_cb(void *priv, Evas *e, return; } - event = ei; + event = (Evas_Event_Key_Down *) ei; keyname = event->keyname; if (!keyname) return; - data = priv; + data = (struct _ug_data *) priv; _key_down_cb(keyname, data); } @@ -291,7 +295,7 @@ static void _switch_btn_clicked_cb(void *priv, Evas_Object *obj, void *ei) if (!priv) return; - data = priv; + data = (struct _ug_data *) priv; data->cur_btn = obj; view_sublist_create(data->win, data->base); @@ -422,7 +426,7 @@ static void _date_btn_clicked_cb(void *priv, Evas_Object *obj, void *ei) return; } - data = priv; + data = (struct _ug_data *) priv; data->cur_btn = obj; view_spin_control_create(data->win, data->base); @@ -546,7 +550,7 @@ static void _time_btn_clicked_cb(void *priv, Evas_Object *obj, void *ei) if (!priv) return; - data = priv; + data = (struct _ug_data *) priv; data->cur_btn = obj; view_time_spin_ctrl_create(data->win, data->base); @@ -911,10 +915,10 @@ static void *_on_create(ui_gadget_h ug, elm_theme_overlay_add(NULL, UG_CLOCK_EDJTHEME); - data = priv; + data = (struct _ug_data *) priv; data->ug = ug; - win = ug_get_window(); + win = (Evas_Object *) ug_get_window(); if (!win) { _ERR("ug get window failed."); _free_ug_data(data); @@ -977,7 +981,7 @@ static void _on_destroy(ui_gadget_h ug, service_h service, void *priv) return; } - data = priv; + data = (struct _ug_data *) priv; _free_ug_data(data); } @@ -1116,7 +1120,7 @@ void view_ug_clock_refresh(Evas_Object *base, unsigned int *date, int *time) return; } - data = evas_object_data_get(base, UG_CLOCK_DATA_ID); + data = (struct _ug_data *) evas_object_data_get(base, UG_CLOCK_DATA_ID); if (!data) { _ERR("evas object data get failed. ID: %s", UG_CLOCK_DATA_ID); return; @@ -1155,7 +1159,7 @@ UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops) return -1; } - priv = calloc(1, sizeof(*priv)); + priv = (struct _ug_data *) calloc(1, sizeof(*priv)); if (!priv) { _ERR("calloc memory for ug private data failed."); return -1; @@ -1185,3 +1189,7 @@ UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops) return; } } + +#if defined (__cplusplus) +}; +#endif diff --git a/ug/system/clock/src/ug_clock_spin_control.c b/ug/system/clock/src/ug_clock_spin_control.cpp similarity index 91% rename from ug/system/clock/src/ug_clock_spin_control.c rename to ug/system/clock/src/ug_clock_spin_control.cpp index 3ea4a8d..d832330 100644 --- a/ug/system/clock/src/ug_clock_spin_control.c +++ b/ug/system/clock/src/ug_clock_spin_control.cpp @@ -104,8 +104,8 @@ void _arrow_btn_clicked_cb(void *priv, Evas_Object *obj, void *ev) if (!priv || !obj) return; - data = priv; - cur_btn = evas_object_data_get(obj, ARROW_BTN_DATA_ID); + data = (struct _date_spin_data *) priv; + cur_btn = (Evas_Object *) evas_object_data_get(obj, ARROW_BTN_DATA_ID); if (!cur_btn) { _ERR("evas object data get failed. ID: %s", ARROW_BTN_DATA_ID); return; @@ -124,7 +124,7 @@ void _arrow_btn_clicked_cb(void *priv, Evas_Object *obj, void *ev) idx = 0; for (i = DATE_DAY; i < DATE_MAX; i++) { - btn = eina_array_data_get(data->spin_array, i); + btn = (Evas_Object *) eina_array_data_get(data->spin_array, i); if (!btn) { _ERR("eina array data get failed. button index: %d", i); return; @@ -245,8 +245,7 @@ static int _add_date_spin(struct _date_spin_data *data) } } - elm_object_focus_set( - eina_array_data_get(array, 0), EINA_TRUE); + elm_object_focus_set((Evas_Object *) eina_array_data_get(array, 0), EINA_TRUE); data->spin_array = array; @@ -271,7 +270,7 @@ static void _date_spin_clicked_cb(void *priv, Evas_Object *obj, void *ei) return; } - data = priv; + data = (struct _date_spin_data *) priv; utils_set_date_value(data->date); @@ -337,7 +336,7 @@ static int _add_date_spin_click_event(struct _date_spin_data *data) array = data->spin_array; for (idx = DATE_MONTH; idx < DATE_MAX; idx++) { - spin = eina_array_data_get(array, idx); + spin = (Evas_Object *) eina_array_data_get(array, idx); if (!spin) { _ERR("eina array data get failed. spin index: %d", idx); return -1; @@ -372,7 +371,7 @@ static void _set_date_spin_direction(Eina_Array *array) } for (idx = DATE_MONTH; idx < DATE_MAX; idx++) { - spin = eina_array_data_get(array, idx); + spin = (Evas_Object *) eina_array_data_get(array, idx); if (!spin) { _ERR("there is no button. idx: %d", idx); return; @@ -382,29 +381,23 @@ static void _set_date_spin_direction(Eina_Array *array) elm_object_focus_next_object_set(spin, spin, ELM_FOCUS_DOWN); if (idx == DATE_MONTH) { - elm_object_focus_next_object_set(spin, - eina_array_data_get(array, idx+1), + elm_object_focus_next_object_set(spin, (Evas_Object *) eina_array_data_get(array, idx+1), ELM_FOCUS_NEXT); elm_object_focus_next_object_set(spin, spin, ELM_FOCUS_LEFT); - elm_object_focus_next_object_set(spin, - eina_array_data_get(array, idx + 1), + elm_object_focus_next_object_set(spin, (Evas_Object *) eina_array_data_get(array, idx + 1), ELM_FOCUS_RIGHT); } else if (idx == DATE_YEAR) { elm_object_focus_next_object_set(spin, spin, ELM_FOCUS_RIGHT); - elm_object_focus_next_object_set(spin, - eina_array_data_get(array, idx - 1), + elm_object_focus_next_object_set(spin, (Evas_Object *) eina_array_data_get(array, idx - 1), ELM_FOCUS_LEFT); } else { - elm_object_focus_next_object_set(spin, - eina_array_data_get(array, idx + 1), + elm_object_focus_next_object_set(spin, (Evas_Object *) eina_array_data_get(array, idx + 1), ELM_FOCUS_NEXT); - elm_object_focus_next_object_set(spin, - eina_array_data_get(array, idx + 1), + elm_object_focus_next_object_set(spin, (Evas_Object *) eina_array_data_get(array, idx + 1), ELM_FOCUS_RIGHT); - elm_object_focus_next_object_set(spin, - eina_array_data_get(array, idx - 1), + elm_object_focus_next_object_set(spin, (Evas_Object *) eina_array_data_get(array, idx - 1), ELM_FOCUS_LEFT); } } @@ -430,7 +423,7 @@ static void _init_date_spin(struct _date_spin_data *data) utils_get_date_value(data->date); - spin = eina_array_data_get(spin_array, 0); + spin = (Evas_Object *) eina_array_data_get(spin_array, 0); if (!spin) { _ERR("month button is null."); return; @@ -439,7 +432,7 @@ static void _init_date_spin(struct _date_spin_data *data) snprintf(buf, sizeof(buf), "%02d", data->date[DATE_MONTH]); elm_object_text_set(spin, buf); - spin = eina_array_data_get(spin_array, 1); + spin = (Evas_Object *) eina_array_data_get(spin_array, 1); if (!spin) { _ERR("month button is null."); return; @@ -448,7 +441,7 @@ static void _init_date_spin(struct _date_spin_data *data) snprintf(buf, sizeof(buf), "%02d", data->date[DATE_DAY]); elm_object_text_set(spin, buf); - spin = eina_array_data_get(spin_array, 2); + spin = (Evas_Object *) eina_array_data_get(spin_array, 2); if (!spin) { _ERR("month button is null."); return; @@ -531,12 +524,12 @@ static void _date_spin_keydown_cb(void *priv, Evas *e, return; } - event = ei; + event = (Evas_Event_Key_Down *) ei; keyname = event->keyname; if (!keyname) return; - data = priv; + data = (struct _date_spin_data *) priv; if (!data->spin_array) return; @@ -545,7 +538,7 @@ static void _date_spin_keydown_cb(void *priv, Evas *e, idx = -1; for (i = DATE_MONTH; i < DATE_MAX; i++) { - spin = eina_array_data_get(spin_array, i); + spin = (Evas_Object *) eina_array_data_get(spin_array, i); if (!spin) return; @@ -641,7 +634,7 @@ static int _add_date_spin_key_event(struct _date_spin_data *data) } for (idx = DATE_MONTH; idx < DATE_MAX; idx++) { - spin = eina_array_data_get(data->spin_array, idx); + spin = (Evas_Object *) eina_array_data_get(data->spin_array, idx); if (!spin) { _ERR("button is null."); return -1; @@ -750,7 +743,7 @@ static void _destroy(Evas_Object *base) return; } - data = evas_object_data_get(base, DATE_SPIN_DATA_ID); + data = (struct _date_spin_data *) evas_object_data_get(base, DATE_SPIN_DATA_ID); if (!data) { _ERR("evas object get data failed. ID: %s", DATE_SPIN_DATA_ID); return; @@ -778,7 +771,7 @@ void view_spin_control_create(Evas_Object *win, return; } - data = calloc(1, sizeof(*data)); + data = (struct _date_spin_data *) calloc(1, sizeof(*data)); if (!data) { _ERR("calloc spin control data memory failed."); return; diff --git a/ug/system/clock/src/ug_clock_sublist.c b/ug/system/clock/src/ug_clock_sublist.cpp similarity index 93% rename from ug/system/clock/src/ug_clock_sublist.c rename to ug/system/clock/src/ug_clock_sublist.cpp index 58f0700..c47b5e8 100644 --- a/ug/system/clock/src/ug_clock_sublist.c +++ b/ug/system/clock/src/ug_clock_sublist.cpp @@ -86,15 +86,15 @@ static void _sublist_btn_clicked_cb(void *priv, Evas_Object *obj, void *ei) return; } - data = priv; + data = (struct _sublist_data *) priv; if (!data->array) return; array = data->array; - on_btn = eina_array_data_get(array, 0); - off_btn = eina_array_data_get(array, 1); + on_btn = (Evas_Object *) eina_array_data_get(array, 0); + off_btn = (Evas_Object *) eina_array_data_get(array, 1); if (!on_btn || !off_btn) { _ERR("ON button or OFF button is null."); return; @@ -140,22 +140,22 @@ static void _key_down_on_sublist_btn_cb(void *priv, Evas *e, if (!priv || !ei || !obj) return; - data = priv; + data = (struct _sublist_data *) priv; if (!data->array || !data->base) return; array = data->array; - event = ei; + event = (Evas_Event_Key_Down *) ei; if (!event->keyname) return; keyname = event->keyname; - on_btn = eina_array_data_get(array, 0); - off_btn = eina_array_data_get(array, 1); + on_btn = (Evas_Object *) eina_array_data_get(array, 0); + off_btn = (Evas_Object *) eina_array_data_get(array, 1); if (!on_btn || !off_btn) { _ERR("ON button or OFF button is null."); return; @@ -322,8 +322,8 @@ static void _set_sublist_init_value(Eina_Array *array) return; } - on_btn = eina_array_data_get(array, 0); - off_btn = eina_array_data_get(array, 1); + on_btn = (Evas_Object *) eina_array_data_get(array, 0); + off_btn = (Evas_Object *) eina_array_data_get(array, 1); if (!on_btn || !off_btn) { _ERR("there is no button in sublist array."); return; @@ -361,8 +361,8 @@ static void _set_sublist_btn_directions(Eina_Array *array) if (!array) return; - on_btn = eina_array_data_get(array, 0); - off_btn = eina_array_data_get(array, 1); + on_btn = (Evas_Object *) eina_array_data_get(array, 0); + off_btn = (Evas_Object *) eina_array_data_get(array, 1); if (!on_btn || !off_btn) { _ERR("get sublist button from array failed."); return; @@ -432,7 +432,7 @@ static void _destroy(Evas_Object *base) if (!base) return; - data = evas_object_data_get(base, SUBLIST_DATA_ID); + data = (struct _sublist_data *) evas_object_data_get(base, SUBLIST_DATA_ID); if (!data) { _ERR("evas object get data failed. ID: %s", SUBLIST_DATA_ID); return; @@ -499,7 +499,7 @@ void view_sublist_create(Evas_Object *win, Evas_Object *ug_base) return; } - data = calloc(1, sizeof(*data)); + data = (struct _sublist_data *) calloc(1, sizeof(*data)); if (!data) { _ERR("calloc sublist data failed."); return; diff --git a/ug/system/clock/src/ug_clock_time_spin_control.c b/ug/system/clock/src/ug_clock_time_spin_control.cpp similarity index 93% rename from ug/system/clock/src/ug_clock_time_spin_control.c rename to ug/system/clock/src/ug_clock_time_spin_control.cpp index cd20936..0c100f9 100644 --- a/ug/system/clock/src/ug_clock_time_spin_control.c +++ b/ug/system/clock/src/ug_clock_time_spin_control.cpp @@ -148,21 +148,21 @@ static void _time_spin_keydown_cb(void *priv, return; } - data = priv; + data = (struct _time_spin_data *) priv; if (!data->spin_array) return; array = data->spin_array; - hour_btn = eina_array_data_get(array, TIME_HOUR); - minute_btn = eina_array_data_get(array, TIME_MINUTE); + hour_btn = (Evas_Object *) eina_array_data_get(array, TIME_HOUR); + minute_btn = (Evas_Object *) eina_array_data_get(array, TIME_MINUTE); if (!hour_btn || !minute_btn) { _ERR("eina array data get failed."); return; } - event = ei; + event = (Evas_Event_Key_Down *) ei; if (!event->keyname) return; @@ -274,7 +274,7 @@ static void _time_spin_click_cb(void *priv, if (!priv) return; - data = priv; + data = (struct _time_spin_data *)priv; utils_set_time_value(data->time); view_ug_clock_refresh(data->ug_base, NULL, data->time); @@ -338,8 +338,8 @@ static void _arrowbtn_clicked_cb(void *priv, Evas_Object *obj, void *ev) if (!priv || !obj) return; - data = priv; - cur_btn = evas_object_data_get(obj, ARROW_BTN_DATA_ID); + data = (struct _time_spin_data *)priv; + cur_btn = (Evas_Object *) evas_object_data_get(obj, ARROW_BTN_DATA_ID); if (!cur_btn) return; @@ -354,7 +354,7 @@ static void _arrowbtn_clicked_cb(void *priv, Evas_Object *obj, void *ev) idx = 0; for (i = TIME_HOUR; i < TIME_MAX; i++) { - btn = eina_array_data_get(data->spin_array, i); + btn = (Evas_Object *) eina_array_data_get(data->spin_array, i); if (cur_btn == btn) { idx = i; @@ -491,7 +491,7 @@ static int _add_time_spin_without_ampm(struct _time_spin_data *data) } } - elm_object_focus_set(eina_array_data_get(array, TIME_HOUR), EINA_TRUE); + elm_object_focus_set((Evas_Object *) eina_array_data_get(array, TIME_HOUR), EINA_TRUE); data->spin_array = array; @@ -580,7 +580,7 @@ static int _add_time_spin_with_ampm(struct _time_spin_data *data) } } - elm_object_focus_set(eina_array_data_get(array, TIME_HOUR), EINA_TRUE); + elm_object_focus_set((Evas_Object *) eina_array_data_get(array, TIME_HOUR), EINA_TRUE); data->spin_array = array; @@ -655,7 +655,7 @@ static void _set_time_spin_btn_directions(Eina_Array *btn_array) count = eina_array_count(btn_array); for (idx = TIME_HOUR; idx < count; idx++) { - btn = eina_array_data_get(btn_array, idx); + btn = (Evas_Object *) eina_array_data_get(btn_array, idx); if (!btn) { _ERR("there is no button. idx: %d", idx); return; @@ -668,26 +668,26 @@ static void _set_time_spin_btn_directions(Eina_Array *btn_array) elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_LEFT); elm_object_focus_next_object_set(btn, - eina_array_data_get(btn_array, idx + 1), + (Evas_Object *) eina_array_data_get(btn_array, idx + 1), ELM_FOCUS_RIGHT); elm_object_focus_next_object_set(btn, - eina_array_data_get(btn_array, idx + 1), + (Evas_Object *) eina_array_data_get(btn_array, idx + 1), ELM_FOCUS_NEXT); } else if (idx == count - 1) { elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_RIGHT); elm_object_focus_next_object_set(btn, - eina_array_data_get(btn_array, idx - 1), + (Evas_Object *) eina_array_data_get(btn_array, idx - 1), ELM_FOCUS_LEFT); } else { elm_object_focus_next_object_set(btn, - eina_array_data_get(btn_array, idx + 1), + (Evas_Object *) eina_array_data_get(btn_array, idx + 1), ELM_FOCUS_RIGHT); elm_object_focus_next_object_set(btn, - eina_array_data_get(btn_array, idx + 1), + (Evas_Object *) eina_array_data_get(btn_array, idx + 1), ELM_FOCUS_NEXT); elm_object_focus_next_object_set(btn, - eina_array_data_get(btn_array, idx - 1), + (Evas_Object *) eina_array_data_get(btn_array, idx - 1), ELM_FOCUS_LEFT); } } @@ -795,7 +795,7 @@ void _destroy(Evas_Object *base) return; } - data = evas_object_data_get(base, TIME_SPIN_DATA_ID); + data = (struct _time_spin_data *)evas_object_data_get(base, TIME_SPIN_DATA_ID); if (!data) { _ERR("evas object get data failed. ID: %s", TIME_SPIN_DATA_ID); return; @@ -823,7 +823,7 @@ void view_time_spin_ctrl_create(Evas_Object *win, return; } - data = calloc(1, sizeof(*data)); + data = (struct _time_spin_data *) calloc(1, sizeof(*data)); if (!data) { _ERR("calloc time spin control data memory failed."); return; diff --git a/ug/system/clock/src/ug_clock_utils.c b/ug/system/clock/src/ug_clock_utils.cpp similarity index 100% rename from ug/system/clock/src/ug_clock_utils.c rename to ug/system/clock/src/ug_clock_utils.cpp -- 2.7.4 From 38bd156d08c950cae401b93a8126b9b1ed9bbb03 Mon Sep 17 00:00:00 2001 From: JuWan Kim Date: Tue, 17 Mar 2015 15:11:26 +0900 Subject: [PATCH 03/16] Change c to cpp in ./ug/wifi-direct/ Change-Id: Ibbe71bbc023ef039e8c1404999ed0a2c682d850e Signed-off-by: JuWan Kim --- ug/wifi-direct/CMakeLists.txt | 8 +- .../src/{ug_wifi_direct.c => ug_wifi_direct.cpp} | 18 ++- ug/wifi-direct/src/{util.c => util.cpp} | 0 .../src/{wifi_direct_mgr.c => wifi_direct_mgr.cpp} | 0 .../{wifi_direct_view.c => wifi_direct_view.cpp} | 134 ++++++++++----------- 5 files changed, 84 insertions(+), 76 deletions(-) rename ug/wifi-direct/src/{ug_wifi_direct.c => ug_wifi_direct.cpp} (94%) rename ug/wifi-direct/src/{util.c => util.cpp} (100%) rename ug/wifi-direct/src/{wifi_direct_mgr.c => wifi_direct_mgr.cpp} (100%) rename ug/wifi-direct/src/{wifi_direct_view.c => wifi_direct_view.cpp} (94%) diff --git a/ug/wifi-direct/CMakeLists.txt b/ug/wifi-direct/CMakeLists.txt index fa2b100..70d7899 100644 --- a/ug/wifi-direct/CMakeLists.txt +++ b/ug/wifi-direct/CMakeLists.txt @@ -49,10 +49,10 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fvisibility=hidden -Wall -W SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") SET(SRCS - src/ug_wifi_direct.c - src/wifi_direct_mgr.c - src/wifi_direct_view.c - src/util.c + src/ug_wifi_direct.cpp + src/wifi_direct_mgr.cpp + src/wifi_direct_view.cpp + src/util.cpp ) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) diff --git a/ug/wifi-direct/src/ug_wifi_direct.c b/ug/wifi-direct/src/ug_wifi_direct.cpp similarity index 94% rename from ug/wifi-direct/src/ug_wifi_direct.c rename to ug/wifi-direct/src/ug_wifi_direct.cpp index 6a5d359..3553f50 100644 --- a/ug/wifi-direct/src/ug_wifi_direct.c +++ b/ug/wifi-direct/src/ug_wifi_direct.cpp @@ -24,6 +24,10 @@ #include "dbg.h" #include "wifi_direct_view.h" +#if defined (__cplusplus) +extern "C" { +#endif + struct _ug_data { Evas_Object *win; Evas_Object *base; @@ -55,12 +59,12 @@ static void *_on_create(ui_gadget_h ug, enum ug_mode mode, return NULL; } - ugd = priv; + ugd = (struct _ug_data *) priv; ugd->ug = ug; elm_theme_extension_add(NULL, UG_WIFI_DIRECT_EDJ_THEME); - win = ug_get_window(); + win = (Evas_Object *) ug_get_window(); if (!win) { _ERR("window get failed"); return NULL; @@ -70,7 +74,7 @@ static void *_on_create(ui_gadget_h ug, enum ug_mode mode, elm_win_focus_highlight_enabled_set(win, EINA_TRUE); elm_win_focus_highlight_style_set(win, "invisible"); - base = wifi_direct_view_create(win, ug); + base = (Evas_Object *) wifi_direct_view_create(win, ug); if (!base) { _ERR("add base layout failed."); return NULL; @@ -201,7 +205,7 @@ UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops) if (!ops) return -1; - ugd = calloc(1, sizeof(*ugd)); + ugd = (struct _ug_data *) calloc(1, sizeof(*ugd)); if (!ugd) return -1; @@ -236,6 +240,10 @@ UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops) if (!ops) return; - ugd = ops->priv; + ugd = (struct _ug_data *) ops->priv; free(ugd); } + +#if defined (__cplusplus) +}; +#endif diff --git a/ug/wifi-direct/src/util.c b/ug/wifi-direct/src/util.cpp similarity index 100% rename from ug/wifi-direct/src/util.c rename to ug/wifi-direct/src/util.cpp diff --git a/ug/wifi-direct/src/wifi_direct_mgr.c b/ug/wifi-direct/src/wifi_direct_mgr.cpp similarity index 100% rename from ug/wifi-direct/src/wifi_direct_mgr.c rename to ug/wifi-direct/src/wifi_direct_mgr.cpp diff --git a/ug/wifi-direct/src/wifi_direct_view.c b/ug/wifi-direct/src/wifi_direct_view.cpp similarity index 94% rename from ug/wifi-direct/src/wifi_direct_view.c rename to ug/wifi-direct/src/wifi_direct_view.cpp index db7a9c2..eddad62 100644 --- a/ug/wifi-direct/src/wifi_direct_view.c +++ b/ug/wifi-direct/src/wifi_direct_view.cpp @@ -63,31 +63,11 @@ enum direct_swith_enum { DIRECT_OFF }; -const char *action_button[] = { - [ACTION_BTN_REFRESH] = TXT_REFRESH_BTN, - [ACTION_BTN_CLOSE] = TXT_CLOSE_BTN, - [ACTION_BTN_STOP] = TXT_STOP_BTN -}; - -const char *popup_button_on[] = { - [DIRECT_OFF] = TXT_OFF_BTN, - [DIRECT_ON] = TXT_ON_BTN -}; - -static char *popup_button_conn[] = { - [DIRECT_ON] = TXT_CONNECT, - [DIRECT_OFF] = TXT_DISCONNECT -}; - -static char *popup_button_req[] = { - [DIRECT_ON] = TXT_YES, - [DIRECT_OFF] = TXT_NO -}; - -static char *part_req[] = { - [DIRECT_ON] = PART_YES, - [DIRECT_OFF] = PART_NO -}; +const char *action_button[] = { TXT_REFRESH_BTN, TXT_CLOSE_BTN, TXT_STOP_BTN }; +const char *popup_button_on[] = { TXT_ON_BTN, TXT_OFF_BTN }; +static char *popup_button_conn[] = { TXT_CONNECT, TXT_DISCONNECT }; +static char *popup_button_req[] = { TXT_YES, TXT_NO }; +static char *part_req[] = { PART_YES, PART_NO }; static void _device_state_changed_cb(int errcode, wifi_direct_device_state_e state, void *data); @@ -103,11 +83,11 @@ static bool _discoverd_peers_cb( void *data); static struct wifi_direct_cbs cbs = { - .device_state_cb = _device_state_changed_cb, - .discovery_state_cb = _discovery_state_changed_cb, - .connection_state_cb = _connection_state_changed_cb, - .connected_peer_cb = _connected_peer_cb, - .discovered_peer_cb = _discoverd_peers_cb + _device_state_changed_cb, + _discovery_state_changed_cb, + _connection_state_changed_cb, + _connected_peer_cb, + _discoverd_peers_cb }; static void _fill_content_part(struct _priv *priv, Evas_Object *obj); @@ -124,7 +104,7 @@ static struct _priv *_init_priv(void) { struct _priv *priv; - priv = calloc(1, sizeof(*priv)); + priv = (struct _priv *) calloc(1, sizeof(*priv)); if (!priv) { _ERR("calloc failed."); return NULL; @@ -143,6 +123,7 @@ static struct _priv *_init_priv(void) static void _fini_priv(struct _priv *priv) { struct device_info *info; + void *obj; if (!priv) { _ERR("priv is already NULL."); @@ -150,8 +131,11 @@ static void _fini_priv(struct _priv *priv) } if (!priv->item_list) - EINA_LIST_FREE(priv->item_list, info) + EINA_LIST_FREE(priv->item_list, obj) + { + info = (struct device_info *) obj; free(info); + } if (priv->dim_ly) evas_object_del(priv->dim_ly); @@ -205,13 +189,14 @@ static void _refresh_btn_clicked_cb(void *data, { struct _priv *priv; struct device_info *info; + void *temp_obj; if (!data || !obj) { _ERR("The param is invalid.\n"); return; } - priv = data; + priv = (struct _priv *) data; if (priv->scan_ly) evas_object_hide(priv->scan_ly); @@ -219,8 +204,11 @@ static void _refresh_btn_clicked_cb(void *data, elm_genlist_clear(priv->genlist); if (priv->item_list) - EINA_LIST_FREE(priv->item_list, info) + EINA_LIST_FREE(priv->item_list, temp_obj) + { + info = (struct device_info *) temp_obj; free(info); + } _create_device_list_view(priv); } @@ -241,7 +229,7 @@ static void _close_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) return; } - priv = data; + priv = (struct _priv *) data; if (!priv->ug) { _ERR("priv->ug is NULL."); @@ -346,7 +334,7 @@ static void _stop_btn_clicked_cb(void *data, return; } - priv = data; + priv = (struct _priv *) data; ret = wifi_direct_mgr_cancel_discovery(); if (ret != RET_SUCCESS) { @@ -497,8 +485,8 @@ static void _popup_back_pressed_cb(void *data, Evas *e, return; } - priv = data; - ev = ei; + priv = (struct _priv *) data; + ev = (Evas_Event_Key_Down *)ei; if (!ev->keyname) { _ERR("ev->keyname is NULL."); @@ -592,7 +580,7 @@ static void _item_conn_btn_clicked_cb(void *data, return; } - priv = data; + priv = (struct _priv *) data; gen_item = priv->popup_item; @@ -600,7 +588,7 @@ static void _item_conn_btn_clicked_cb(void *data, if (cur_idx < 0) return; - info = eina_list_nth(priv->item_list, cur_idx); + info = (struct device_info *) eina_list_nth(priv->item_list, cur_idx); if (!info) return; @@ -670,7 +658,7 @@ static void _genlist_item_select_cb(void *data, return; } - priv = data; + priv = (struct _priv *) data; if (!priv->dim_ly) { ret = _create_wifi_direct_dim(priv); @@ -682,7 +670,7 @@ static void _genlist_item_select_cb(void *data, evas_object_show(priv->dim_ly); - gen_item = event_info; + gen_item = (Elm_Object_Item *) event_info; priv->popup_item = gen_item; layout = util_add_layout(priv->base, UG_WIFI_DIRECT_EDJ_FILE, @@ -720,7 +708,7 @@ static void _genlist_item_select_cb(void *data, if (cur_idx < 0) return; - info = eina_list_nth(priv->item_list, cur_idx); + info = (struct device_info *) eina_list_nth(priv->item_list, cur_idx); if (!info) return; @@ -764,6 +752,7 @@ static Eina_Bool _is_peer_exist(struct _priv *priv, struct device_info *new_info) { struct device_info *cur_info; + void *obj; Eina_List *l; if (!priv || !new_info) { @@ -776,7 +765,8 @@ static Eina_Bool _is_peer_exist(struct _priv *priv, return EINA_FALSE; } - EINA_LIST_FOREACH(priv->item_list, l, cur_info) { + EINA_LIST_FOREACH(priv->item_list, l, obj) { + cur_info = (struct device_info *) obj; if (!strncmp(cur_info->mac_addr, new_info->mac_addr, WIFI_DIRECT_DEFAULT_BUF_LEN - 1)) return EINA_TRUE; @@ -796,9 +786,11 @@ static Eina_Bool _update_device_conn_state(struct _priv *priv, Eina_Bool conn) { struct device_info *cur_info; + void *obj; Eina_List *l; - EINA_LIST_FOREACH(priv->item_list, l, cur_info) { + EINA_LIST_FOREACH(priv->item_list, l, obj) { + cur_info = (struct device_info *) obj; if (!strncmp(cur_info->mac_addr, priv->req_addr, WIFI_DIRECT_DEFAULT_BUF_LEN - 1)) { cur_info->is_conn = conn; @@ -857,20 +849,24 @@ static void _process_discovery_start(struct wifi_direct_cbs cbs, int ret; struct _priv *priv; struct device_info *info; + void *obj; if (!data) { _ERR("Parameter error!"); return; } - priv = data; + priv = (struct _priv *) data; if (priv->genlist) elm_genlist_clear(priv->genlist); if (priv->item_list) - EINA_LIST_FREE(priv->item_list, info) + EINA_LIST_FREE(priv->item_list, obj) + { + info = (struct device_info *) obj; free(info); + } ret = wifi_direct_mgr_foreach_connected_peers( cbs.connected_peer_cb, data); @@ -920,7 +916,7 @@ static void _process_discovery_finished(void *data) return; } - priv = data; + priv = (struct _priv *) data; elm_object_part_content_unset(priv->base, PART_REFRESH_BTN); evas_object_hide(priv->btn_stop); @@ -948,7 +944,7 @@ static void _req_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) return; } - priv = data; + priv = (struct _priv *) data; value = elm_object_text_get(obj); if (!value) { @@ -1065,7 +1061,7 @@ static void _process_connection_req(const char *addr, void *data) return; } - priv = data; + priv = (struct _priv *) data; ret = wifi_direct_mgr_get_wps_type(&is_pbc); if (ret != WIFI_DIRECT_ERROR_NONE) { @@ -1108,7 +1104,7 @@ static void _process_connection_prog(void *data) return; } - priv = data; + priv = (struct _priv *) data; if (priv->dim_ly) evas_object_show(priv->dim_ly); @@ -1148,7 +1144,7 @@ static Eina_Bool _connection_ind_cb(void *data) return ECORE_CALLBACK_CANCEL; } - priv = data; + priv = (struct _priv *) data; ret = wifi_direct_mgr_start_discovery(); if (ret != RET_SUCCESS) @@ -1174,7 +1170,7 @@ static void _process_connection_ind(void *data) return; } - priv = data; + priv = (struct _priv *) data; timer = ecore_timer_add(HANDLER_INTERVAL, _connection_ind_cb, priv); if (!timer) { @@ -1201,10 +1197,10 @@ static void _process_connection_rsp(void *data) return; } - priv = data; + priv = (struct _priv *) data; cur_index = priv->conn_idx; - info = eina_list_nth(priv->item_list, cur_index); + info = (struct device_info *) eina_list_nth(priv->item_list, cur_index); if (!info) return; @@ -1245,7 +1241,7 @@ static void _device_state_changed_cb(int errcode, return; } - priv = data; + priv = (struct _priv *) data; if (state != WIFI_DIRECT_DEVICE_STATE_ACTIVATED) { elm_genlist_clear(priv->genlist); @@ -1358,9 +1354,9 @@ static bool _connected_peer_cb( return EINA_FALSE; } - priv = data; + priv = (struct _priv *) data; - info = calloc(1, sizeof(*info)); + info = (struct device_info *) calloc(1, sizeof(*info)); if (!info) { _ERR("calloc failed."); return EINA_FALSE; @@ -1402,8 +1398,8 @@ static bool _discoverd_peers_cb( return EINA_FALSE; } - priv = data; - info = calloc(1, sizeof(*info)); + priv = (struct _priv *) data; + info = (struct device_info *) calloc(1, sizeof(*info)); if (!info) { _ERR("calloc failed."); return EINA_FALSE; @@ -1556,6 +1552,7 @@ static void _wifi_direct_select_btn_cb(void *data, { struct _priv *priv; struct device_info *info; + void *temp_obj; const char *value; int ret; @@ -1564,9 +1561,9 @@ static void _wifi_direct_select_btn_cb(void *data, return; } - priv = data; + priv = (struct _priv *) data; - value = elm_object_text_get(obj); + value = (const char *) elm_object_text_get(obj); if (!value) { _ERR("get text from network type btn is NULL."); return; @@ -1579,8 +1576,11 @@ static void _wifi_direct_select_btn_cb(void *data, elm_genlist_clear(priv->genlist); if (priv->item_list) - EINA_LIST_FREE(priv->item_list, info) + EINA_LIST_FREE(priv->item_list, temp_obj) + { + info = (struct device_info *) temp_obj; free(info); + } _create_device_list_view(priv); @@ -1641,7 +1641,7 @@ static void _wifi_direct_btn_clicked_cb(void *data, return; } - priv = data; + priv = (struct _priv *) data; if (!priv->dim_ly) { ret = _create_wifi_direct_dim(priv); @@ -1783,7 +1783,7 @@ static char *_item_label_get(void *data, Evas_Object *obj, return NULL; } - info = data; + info = (struct device_info *) data; memset(&buf_name, 0x00, WIFI_DIRECT_DEFAULT_BUF_LEN); if (!strcmp(part, TXT_ELM_TEXT)) { @@ -1939,8 +1939,8 @@ static void _base_layout_key_down_cb(void *data, return; } - priv = data; - ei = event_info; + priv = (struct _priv *) data; + ei = (Evas_Event_Key_Down *) event_info; if (!ei->keyname) { _ERR("ei->keyname is NULL."); -- 2.7.4 From 6ccd0b39eb23d02b479b87327698a5fb130dc59b Mon Sep 17 00:00:00 2001 From: JuWan Kim Date: Tue, 17 Mar 2015 16:25:21 +0900 Subject: [PATCH 04/16] Change c to cpp in ./ug/network * Changing to cpp is done. Change-Id: I18227bae986d87b8e11e3598b2fbd342ecb96a81 Signed-off-by: JuWan Kim --- ug/network/CMakeLists.txt | 18 ++--- .../src/{connection_mgr.c => connection_mgr.cpp} | 14 ++-- .../src/{ip_setting_view.c => ip_setting_view.cpp} | 88 +++++++++++----------- ug/network/src/{main_view.c => main_view.cpp} | 81 ++++++++------------ .../src/{network_viewmgr.c => network_viewmgr.cpp} | 17 +++-- ..._network_settings.c => ug_network_settings.cpp} | 18 +++-- ug/network/src/{util.c => util.cpp} | 0 ug/network/src/{vconf_mgr.c => vconf_mgr.cpp} | 0 ug/network/src/{wifi_mgr.c => wifi_mgr.cpp} | 28 +++---- ...wifi_passcode_view.c => wifi_passcode_view.cpp} | 43 +++++------ 10 files changed, 152 insertions(+), 155 deletions(-) rename ug/network/src/{connection_mgr.c => connection_mgr.cpp} (97%) rename ug/network/src/{ip_setting_view.c => ip_setting_view.cpp} (97%) rename ug/network/src/{main_view.c => main_view.cpp} (97%) rename ug/network/src/{network_viewmgr.c => network_viewmgr.cpp} (92%) rename ug/network/src/{ug_network_settings.c => ug_network_settings.cpp} (96%) rename ug/network/src/{util.c => util.cpp} (100%) rename ug/network/src/{vconf_mgr.c => vconf_mgr.cpp} (100%) rename ug/network/src/{wifi_mgr.c => wifi_mgr.cpp} (95%) rename ug/network/src/{wifi_passcode_view.c => wifi_passcode_view.cpp} (96%) diff --git a/ug/network/CMakeLists.txt b/ug/network/CMakeLists.txt index 64d88b6..e0df379 100644 --- a/ug/network/CMakeLists.txt +++ b/ug/network/CMakeLists.txt @@ -47,15 +47,15 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fvisibility=hidden -Wall -W SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") SET(SRCS - src/ug_network_settings.c - src/main_view.c - src/network_viewmgr.c - src/ip_setting_view.c - src/vconf_mgr.c - src/wifi_mgr.c - src/connection_mgr.c - src/util.c - src/wifi_passcode_view.c + src/ug_network_settings.cpp + src/main_view.cpp + src/network_viewmgr.cpp + src/ip_setting_view.cpp + src/vconf_mgr.cpp + src/wifi_mgr.cpp + src/connection_mgr.cpp + src/util.cpp + src/wifi_passcode_view.cpp ) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) diff --git a/ug/network/src/connection_mgr.c b/ug/network/src/connection_mgr.cpp similarity index 97% rename from ug/network/src/connection_mgr.c rename to ug/network/src/connection_mgr.cpp index 0c54513..f9da7c2 100644 --- a/ug/network/src/connection_mgr.c +++ b/ug/network/src/connection_mgr.cpp @@ -419,7 +419,7 @@ int connection_mgr_ip_dynamic_config( ret = connection_update_profile(connection, profile); if (ret != CONNECTION_ERROR_NONE) { _ERR("connection_update_profile failed, ret: %s.\n", - _convert_error_to_string(ret)); + _convert_error_to_string((connection_error_e) ret)); return RET_FAILED; } @@ -428,14 +428,14 @@ int connection_mgr_ip_dynamic_config( CONNECTION_IP_CONFIG_TYPE_DYNAMIC); if (ret != CONNECTION_ERROR_NONE) { _ERR("Fail to set ip method type[%s]\n", - _convert_error_to_string(ret)); + _convert_error_to_string((connection_error_e) ret)); return RET_FAILED; } ret = connection_update_profile(connection, profile); if (ret != CONNECTION_ERROR_NONE) { _ERR("connection_update_profile failed, ret: %s.\n", - _convert_error_to_string(ret)); + _convert_error_to_string((connection_error_e) ret)); return RET_FAILED; } @@ -533,7 +533,7 @@ int connection_mgr_set_ip_config( info->ip_addr); if (ret != CONNECTION_ERROR_NONE) { _ERR("set ip address fail, ret: %s\n", - _convert_error_to_string(ret)); + _convert_error_to_string((connection_error_e) ret)); return RET_FAILED; } @@ -542,7 +542,7 @@ int connection_mgr_set_ip_config( info->submask); if (ret != CONNECTION_ERROR_NONE) { _ERR("set subnet mask fail. %s\n", - _convert_error_to_string(ret)); + _convert_error_to_string((connection_error_e) ret)); return RET_FAILED; } @@ -551,7 +551,7 @@ int connection_mgr_set_ip_config( info->gateway); if (ret != CONNECTION_ERROR_NONE) { _ERR("set gateway address fail %s\n", - _convert_error_to_string(ret)); + _convert_error_to_string((connection_error_e) ret)); return RET_FAILED; } @@ -581,7 +581,7 @@ int connection_mgr_set_dns_config( info->dns); if (ret != CONNECTION_ERROR_NONE) { _ERR("set dns address fail %d\n", - _convert_error_to_string(ret)); + _convert_error_to_string((connection_error_e) ret)); return RET_FAILED; } diff --git a/ug/network/src/ip_setting_view.c b/ug/network/src/ip_setting_view.cpp similarity index 97% rename from ug/network/src/ip_setting_view.c rename to ug/network/src/ip_setting_view.cpp index 19fed36..5051c37 100644 --- a/ug/network/src/ip_setting_view.c +++ b/ug/network/src/ip_setting_view.cpp @@ -111,7 +111,7 @@ static struct _priv *_init_priv() { struct _priv *priv; - priv = calloc(1, sizeof(*priv)); + priv = (struct _priv *) calloc(1, sizeof(*priv)); return priv; } @@ -428,7 +428,7 @@ static void _popup_ok_cancel_btn_clicked_cb(void *data, return; } - priv = data; + priv = (struct _priv *) data; _del_confirm_popup(priv); @@ -534,7 +534,7 @@ static void _popup_dismissed_cb(void *data, Evas_Object *obj, void *ev) return; } - priv = data; + priv = (struct _priv *) data; _unset_layout_dim(priv); @@ -561,7 +561,7 @@ static void _ip_auto_mode_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) return; } - priv = data; + priv = (struct _priv *) data; _disable_ip_btns(priv); @@ -595,7 +595,7 @@ static void _mode_sub_popup_dismissed_cb(void *data, return; } - priv = data; + priv = (struct _priv *) data; _unset_layout_dim(priv); @@ -629,8 +629,8 @@ static void _mode_sub_popup_key_pressed_cb(void *data, Evas *evas, return; } - priv = data; - ev = ei; + priv = (struct _priv *) data; + ev = (Evas_Event_Key_Down *) ei; if (!ev->keyname) { _ERR("ev->keyname is NULL."); @@ -670,7 +670,7 @@ static void _ip_manual_mode_btn_clicked_cb(void *data, return; } - priv = data; + priv = (struct _priv *) data; _enable_ip_btns(priv); @@ -705,8 +705,8 @@ static void _ip_ctxpopup_key_pressed_cb(void *data, Evas *evas, return; } - priv = data; - ev = ei; + priv = (struct _priv *) data; + ev = (Evas_Event_Key_Down *) ei; if (!ev->keyname) { _ERR("ev->keyname is NULL."); @@ -742,8 +742,8 @@ static void _ctxpopup_pressed_cb(void *data, Evas *e, return; } - priv = data; - ev = ei; + priv = (struct _priv *) data; + ev = (Evas_Event_Key_Down *) ei; if (!ev->keyname) { _ERR("ev->keyname is NULL."); @@ -776,7 +776,7 @@ static void _ctxpopup_unfocused_cb(void *data, return; } - priv = data; + priv = (struct _priv *) data; _unset_layout_dim(priv); evas_object_del(obj); @@ -846,7 +846,7 @@ static void _ip_setting_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) return; } - priv = data; + priv = (struct _priv *) data; priv->cur_type = SETTING_IP; base = priv->base; @@ -1007,7 +1007,7 @@ static void _ip_btn_key_pressed_cb(void *data, Evas *evas, return; } - ev = ei; + ev = (Evas_Event_Key_Down *) ei; if (!ev->keyname) { _ERR("ev->keyname is NULL."); @@ -1076,22 +1076,22 @@ static void _set_the_value(struct _priv *priv) } value1 = NULL; - btn = evas_object_data_get(priv->config_popup, IP_VALUE1); + btn = (Evas_Object *) evas_object_data_get(priv->config_popup, IP_VALUE1); if (btn) value1 = elm_object_text_get(btn); value2 = NULL; - btn = evas_object_data_get(priv->config_popup, IP_VALUE2); + btn = (Evas_Object *) evas_object_data_get(priv->config_popup, IP_VALUE2); if (btn) value2 = elm_object_text_get(btn); value3 = NULL; - btn = evas_object_data_get(priv->config_popup, IP_VALUE3); + btn = (Evas_Object *) evas_object_data_get(priv->config_popup, IP_VALUE3); if (btn) value3 = elm_object_text_get(btn); value4 = NULL; - btn = evas_object_data_get(priv->config_popup, IP_VALUE4); + btn = (Evas_Object *) evas_object_data_get(priv->config_popup, IP_VALUE4); if (btn) value4 = elm_object_text_get(btn); @@ -1151,8 +1151,8 @@ static void _value_ctxpopup_key_pressed_cb(void *data, Evas *evas, return; } - ev = ei; - priv = data; + ev = (Evas_Event_Key_Down *) ei; + priv = (struct _priv *) data; if (!ev->keyname) { _ERR("ev->keyname is NULL."); @@ -1341,7 +1341,7 @@ static void _ip_address_btn_clicked_cb(void *data, return; } - priv = data; + priv = (struct _priv *) data; priv->cur_type = SETTING_IP_ADDRESS; _create_value_popup(priv); @@ -1366,7 +1366,7 @@ static void _sub_mask_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) return; } - priv = data; + priv = (struct _priv *) data; priv->cur_type = SETTING_SUBNET_MASK; _create_value_popup(priv); @@ -1391,7 +1391,7 @@ static void _gateway_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) return; } - priv = data; + priv = (struct _priv *) data; priv->cur_type = SETTING_GATEWAY; _create_value_popup(priv); } @@ -1579,7 +1579,7 @@ static void _dns_auto_mode_btn_clicked_cb(void *data, return; } - priv = data; + priv = (struct _priv *) data; _disable_dns_btns(priv); @@ -1613,7 +1613,7 @@ static void _dns_manual_mode_btn_clicked_cb(void *data, return; } - priv = data; + priv = (struct _priv *) data; _enable_dns_btns(priv); @@ -1646,7 +1646,7 @@ static void _dns_ctxpopup_dismissed_cb(void *data, return; } - priv = data; + priv = (struct _priv *) data; _unset_layout_dim(priv); @@ -1676,8 +1676,8 @@ static void _dns_ctxpopup_key_pressed_cb(void *data, Evas *evas, return; } - priv = data; - ev = ei; + priv = (struct _priv *) data; + ev = (Evas_Event_Key_Down *) ei; if (!ev->keyname) { _ERR("ev->keyname is NULL."); @@ -1717,7 +1717,7 @@ static void _dns_setting_btn_clicked_cb(void *data, return; } - priv = data; + priv = (struct _priv *) data; priv->cur_type = SETTING_DNS; base = priv->base; @@ -1809,7 +1809,7 @@ static void _dns_server_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) return; } - priv = data; + priv = (struct _priv *) data; priv->cur_type = SETTING_DNS_SERVER; _create_value_popup(priv); @@ -2232,7 +2232,7 @@ static void _retry_btn_clicked_cb(void *data, return; } - priv = data; + priv = (struct _priv *) data; _del_confirm_popup(priv); @@ -2359,7 +2359,7 @@ static void _ok_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) return; } - priv = data; + priv = (struct _priv *) data; _config_network(priv); } @@ -2382,7 +2382,7 @@ static void _cancel_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) return; } - priv = data; + priv = (struct _priv *) data; if (priv && priv->vmgr) viewmgr_pop(priv->vmgr); @@ -2483,8 +2483,8 @@ static void _base_key_pressed_cb(void *data, Evas *evas, return; } - ev = ei; - priv = data; + ev = (Evas_Event_Key_Down *) ei; + priv = (struct _priv *) data; if (!ev->keyname) { _ERR("ev->keyname is NULL."); @@ -2528,7 +2528,7 @@ static Evas_Object *_create(struct viewmgr *vmgr, void *data) priv->ug = vmgr->ug; priv->vmgr = vmgr; - info = data; + info = (struct connection_info *) data; priv->connection = info->connection; priv->network_type = info->cur_type; priv->ap = info->ap; @@ -2599,7 +2599,7 @@ static void _destroy(Evas_Object *base) return; } - priv = evas_object_data_get(base, KEY_PRIV); + priv = (struct _priv *) evas_object_data_get(base, KEY_PRIV); if (!priv) return; @@ -2617,12 +2617,12 @@ static enum view_type _get_view_type(void) } static struct view_class _vclass = { - .create = _create, - .resume = NULL, - .pause = NULL, - .terminate = _destroy, - .message_handler = NULL, - .get_view_type = _get_view_type, + _create, + NULL, + NULL, + _destroy, + NULL, + _get_view_type, }; /** diff --git a/ug/network/src/main_view.c b/ug/network/src/main_view.cpp similarity index 97% rename from ug/network/src/main_view.c rename to ug/network/src/main_view.cpp index d795bc4..d2723c7 100644 --- a/ug/network/src/main_view.c +++ b/ug/network/src/main_view.cpp @@ -43,24 +43,9 @@ enum action_btn_enum { CLOSE }; -static char *action_button[] = { - [CONNECT] = TXT_CONNECT_BTN, - [REFRESH] = TXT_REFRESH_BTN, - [OTHER] = TXT_OTHER_BTN, - [CLOSE] = TXT_CLOSE_BTN -}; - -static char *button_swallow[] = { - [CONNECT] = PART_CONNECT_BTN, - [REFRESH] = PART_REFRESH_BTN, - [OTHER] = PART_OTHER_BTN, - [CLOSE] = PART_CLOSE_BTN -}; - -static char *popup_button[] = { - [TYPE_WIRELESS] = TXT_WIRELESS, - [TYPE_WIRED] = TXT_WIRED -}; +static char *action_button[4] = { TXT_CONNECT_BTN, TXT_REFRESH_BTN, TXT_OTHER_BTN, TXT_CLOSE_BTN }; +static char *button_swallow[4] = { PART_CONNECT_BTN, PART_REFRESH_BTN, PART_OTHER_BTN, PART_CLOSE_BTN }; +static char *popup_button[2] = { TXT_WIRELESS, TXT_WIRED }; struct _priv { ui_gadget_h ug; @@ -118,7 +103,7 @@ static struct _priv *_init_priv() { struct _priv *priv; - priv = calloc(1, sizeof(*priv)); + priv = (struct _priv *) calloc(1, sizeof(*priv)); if (!priv) { _ERR("calloc priv failed."); return NULL; @@ -283,8 +268,8 @@ static void _ctxpopup_pressed_cb(void *data, Evas *e, return; } - priv = data; - ev = ei; + priv = (struct _priv *) data; + ev = (Evas_Event_Key_Down *) ei; if (!ev->keyname) { _ERR("ev->keyname is NULL."); @@ -338,8 +323,8 @@ static void _main_ly_key_pressed_cb(void *data, Evas *e, return; } - priv = data; - ev = ei; + priv = (struct _priv *) data; + ev = (Evas_Event_Key_Down *) ei; if (!ev->keyname) { _ERR("ev->keyname is NULL."); @@ -667,7 +652,7 @@ static void _profie_btn_clicked_cb(void *data, return; } - priv = data; + priv = (struct _priv *) data; if (priv->wired_conn) { elm_object_signal_emit(obj, SIG_STATE_UNSELECTED, ELM); @@ -821,7 +806,7 @@ static char *_item_ap_name_get(void *data, Evas_Object *obj, const char *part) return NULL; } - ap_info = data; + ap_info = (struct wifi_ap_info *) data; if (!strcmp(part, PART_ELM_TEXT)) return strdup(ap_info->essid); @@ -943,8 +928,8 @@ static void _item_select_cb(void *data, Evas_Object *obj, void *ei) return; } - priv = data; - gen_item = ei; + priv = (struct _priv *) data; + gen_item = (Elm_Object_Item *) ei; if (priv->last_item == gen_item) { elm_object_item_signal_emit(gen_item, SIG_STATE_UNSELECTED, ELM); @@ -972,7 +957,7 @@ static void _item_select_cb(void *data, Evas_Object *obj, void *ei) return; } - ap_info = eina_list_nth(priv->ap_list, index); + ap_info = (struct wifi_ap_info *) eina_list_nth(priv->ap_list, index); if (!ap_info) { _ERR("ap info is NULL."); return; @@ -1023,7 +1008,7 @@ static Eina_Bool _select_connected_cb(void *data) return ECORE_CALLBACK_CANCEL; } - priv = data; + priv = (struct _priv *) data; elm_object_item_signal_emit(priv->last_item, SIG_STATE_SELECTED, ELM); _enable_connect_btn(priv); @@ -1056,7 +1041,7 @@ static bool _wifi_found_ap_cb(wifi_ap_h ap, void *data) return EINA_FALSE; } - priv = data; + priv = (struct _priv *) data; ret = wifi_mgr_is_activated(&state); if (ret != WIFI_ERROR_NONE || state == 0) { @@ -1064,7 +1049,7 @@ static bool _wifi_found_ap_cb(wifi_ap_h ap, void *data) return EINA_FALSE; } - ap_info = calloc(1, sizeof(*ap_info)); + ap_info = (struct wifi_ap_info *) calloc(1, sizeof(*ap_info)); if (!ap_info) { _ERR("calloc failed"); return EINA_FALSE; @@ -1155,7 +1140,7 @@ static void _wifi_activated_cb(wifi_error_e result, void *data) return; } - priv = data; + priv = (struct _priv *) data; ret = wifi_mgr_scan_request(_wifi_scan_request_cb, data); if (ret != RET_SUCCESS) { @@ -1322,7 +1307,7 @@ static void _type_select_btn_cb(void *data, return; } - priv = data; + priv = (struct _priv *) data; value = elm_object_text_get(obj); if (!value) { @@ -1373,8 +1358,8 @@ static void _type_key_pressed_cb(void *data, return; } - priv = data; - ev = ei; + priv = (struct _priv *) data; + ev = (Evas_Event_Key_Down *) ei; if (!ev->keyname) { _ERR("ev->keyname is NULL."); @@ -1418,7 +1403,7 @@ static void _network_type_btn_clicked_cb(void *data, return; } - priv = data; + priv = (struct _priv *) data; base = priv->base; _set_layout_dim(priv); @@ -1542,7 +1527,7 @@ static void _wifi_connected_cb(wifi_error_e error_code, void *user_data) return; } - priv = user_data; + priv = (struct _priv *) user_data; if (!priv->status_popup) return; @@ -1575,7 +1560,7 @@ static int _wifi_connect_ap(struct _priv *priv, int index) _show_progress_popup(priv); - ap_info = eina_list_nth(priv->ap_list, index); + ap_info = (struct wifi_ap_info *) eina_list_nth(priv->ap_list, index); if (!ap_info) { _ERR("ap info is NULL."); return RET_FAILED; @@ -1894,7 +1879,7 @@ static void _retry_btn_clicked_cb(void *data, return; } - priv = data; + priv = (struct _priv *) data; _del_status_popup(priv); @@ -1918,7 +1903,7 @@ static void _cancel_btn_clicked_cb(void *data, return; } - priv = data; + priv = (struct _priv *) data; _del_status_popup(priv); @@ -1942,7 +1927,7 @@ static void _ctxpopup_unfocused_cb(void *data, return; } - priv = data; + priv = (struct _priv *) data; _unset_layout_dim(priv); @@ -2161,7 +2146,7 @@ static void _connect_btn_clicked_cb(void *data, return; } - priv = data; + priv = (struct _priv *) data; _connect_network(priv); } @@ -2183,7 +2168,7 @@ static void _refresh_btn_clicked_cb(void *data, return; } - priv = data; + priv = (struct _priv *) data; _clear_genlist_item_list(priv); @@ -2209,7 +2194,7 @@ static void _other_btn_clicked_cb(void *data, return; } - priv = data; + priv = (struct _priv *) data; priv->cur_view = NETWORK_IP_SETTING_VIEW; @@ -2255,7 +2240,7 @@ static void _close_btn_clicked_cb(void *data, return; } - priv = data; + priv = (struct _priv *) data; if (!priv->ug) return; @@ -2434,7 +2419,7 @@ static void _resume(Evas_Object *base) return; } - priv = evas_object_data_get(base, KEY_PRIV); + priv = (struct _priv *) evas_object_data_get(base, KEY_PRIV); if (!priv) { _ERR("priv got from base is NULL."); return; @@ -2471,7 +2456,7 @@ static void _message_handler(Evas_Object *base, return; } - priv = evas_object_data_get(base, KEY_PRIV); + priv = (struct _priv *) evas_object_data_get(base, KEY_PRIV); if (!priv) { _ERR("priv got from base is NULL."); return; @@ -2513,7 +2498,7 @@ static void _destroy(Evas_Object *base) return; } - priv = evas_object_data_get(base, KEY_PRIV); + priv = (struct _priv *) evas_object_data_get(base, KEY_PRIV); _fini_priv(priv); } diff --git a/ug/network/src/network_viewmgr.c b/ug/network/src/network_viewmgr.cpp similarity index 92% rename from ug/network/src/network_viewmgr.c rename to ug/network/src/network_viewmgr.cpp index 4fe384c..6534a2a 100644 --- a/ug/network/src/network_viewmgr.c +++ b/ug/network/src/network_viewmgr.cpp @@ -38,7 +38,7 @@ struct viewmgr *viewmgr_init() { struct viewmgr *vmgr; - vmgr = calloc(1, sizeof(*vmgr)); + vmgr = (struct viewmgr *) calloc(1, sizeof(*vmgr)); if (!vmgr) { _ERR("calloc vmgr failed."); return NULL; @@ -84,7 +84,7 @@ static void _view_deleted(void *data, Evas *e, Evas_Object *obj, void *ev) if (!data || !obj) return; - vclass = data; + vclass = (struct view_class *) data; if (vclass->terminate) vclass->terminate(obj); } @@ -108,7 +108,7 @@ Evas_Object *viewmgr_push(struct viewmgr *vmgr, if (!vmgr || !vmgr->win || !vclass || !vclass->create) return NULL; - vinfo = calloc(1, sizeof(*vinfo)); + vinfo = (struct _viewinfo *) calloc(1, sizeof(*vinfo)); if (!vinfo) return NULL; @@ -124,7 +124,7 @@ Evas_Object *viewmgr_push(struct viewmgr *vmgr, vinfo->vclass = vclass; vinfo->view_type = vclass->get_view_type(); - vinfo_pre = eina_list_data_get(vmgr->vlist); + vinfo_pre = (struct _viewinfo *) eina_list_data_get(vmgr->vlist); if (vinfo_pre && vinfo_pre->base && vinfo_pre->vclass->pause) vinfo_pre->vclass->pause(vinfo_pre->base); @@ -150,6 +150,7 @@ int viewmgr_send_message(struct viewmgr *vmgr, enum message_id msg_id, void *data) { struct _viewinfo *vinfo; + void *obj; struct view_class *vclass; Eina_List *list, *list_next; @@ -158,7 +159,9 @@ int viewmgr_send_message(struct viewmgr *vmgr, return RET_FAILED; } - EINA_LIST_FOREACH_SAFE(vmgr->vlist, list, list_next, vinfo) { + EINA_LIST_FOREACH_SAFE(vmgr->vlist, list, list_next, obj) { + vinfo = (struct _viewinfo *) obj; + if (!vinfo) { _ERR("vinfo is NULL."); continue; @@ -196,7 +199,7 @@ int viewmgr_pop(struct viewmgr *vmgr) return RET_FAILED; } - vinfo = eina_list_data_get(vmgr->vlist); + vinfo = (struct _viewinfo *) eina_list_data_get(vmgr->vlist); if (!vinfo) { _ERR("eina_list_data_get() failed."); return RET_FAILED; @@ -231,7 +234,7 @@ int viewmgr_resume(struct viewmgr *vmgr) return RET_FAILED; } - vinfo = eina_list_data_get(vmgr->vlist); + vinfo = (struct _viewinfo *) eina_list_data_get(vmgr->vlist); if (!vinfo || !vinfo->vclass || !vinfo->base) { _ERR("vinfo, vinfo->vclass, or vinfo->base is NULL."); return RET_FAILED; diff --git a/ug/network/src/ug_network_settings.c b/ug/network/src/ug_network_settings.cpp similarity index 96% rename from ug/network/src/ug_network_settings.c rename to ug/network/src/ug_network_settings.cpp index f3f38dc..6d117d5 100644 --- a/ug/network/src/ug_network_settings.c +++ b/ug/network/src/ug_network_settings.cpp @@ -27,6 +27,10 @@ #include "main_view.h" #include "network_viewmgr.h" +#if defined (__cplusplus) +extern "C" { +#endif + struct _ug_data { Evas_Object *win; Evas_Object *base; @@ -66,12 +70,12 @@ static void *_on_create(ui_gadget_h ug, enum ug_mode mode, return NULL; } - ugd = priv; + ugd = (struct _ug_data *) priv; ugd->ug = ug; elm_theme_extension_add(NULL, UG_NETWORK_EDJ_THEME); - win = ug_get_window(); + win = (Evas_Object *) ug_get_window(); if (!win) { _ERR("window get failed"); return NULL; @@ -172,7 +176,7 @@ static void _on_resume(ui_gadget_h ug, service_h service, void *priv) */ static void _on_destroy(ui_gadget_h ug, service_h service, void *priv) { - struct _ug_data *ugd = priv; + struct _ug_data *ugd = (struct _ug_data *) priv; if (!ug || !priv) { _ERR("Parameter error!"); @@ -259,7 +263,7 @@ UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops) if (!ops) return -1; - ugd = calloc(1, sizeof(*ugd)); + ugd = (struct _ug_data *) calloc(1, sizeof(*ugd)); if (!ugd) return -1; @@ -294,7 +298,11 @@ UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops) if (!ops) return; - ugd = ops->priv; + ugd = (struct _ug_data *) ops->priv; free(ugd); } + +#if defined (__cplusplus) +}; +#endif diff --git a/ug/network/src/util.c b/ug/network/src/util.cpp similarity index 100% rename from ug/network/src/util.c rename to ug/network/src/util.cpp diff --git a/ug/network/src/vconf_mgr.c b/ug/network/src/vconf_mgr.cpp similarity index 100% rename from ug/network/src/vconf_mgr.c rename to ug/network/src/vconf_mgr.cpp diff --git a/ug/network/src/wifi_mgr.c b/ug/network/src/wifi_mgr.cpp similarity index 95% rename from ug/network/src/wifi_mgr.c rename to ug/network/src/wifi_mgr.cpp index 7555aeb..d7b6aaa 100644 --- a/ug/network/src/wifi_mgr.c +++ b/ug/network/src/wifi_mgr.cpp @@ -116,7 +116,7 @@ int wifi_mgr_is_activated(bool *activated) ret = wifi_is_activated(activated); if (ret != WIFI_ERROR_NONE) { _ERR("Fail to wifi_is_activated %s\n", - wifi_mgr_error_dbg(ret)); + wifi_mgr_error_dbg((wifi_error_e) ret)); return RET_FAILED; } @@ -144,7 +144,7 @@ int wifi_mgr_scan_request(wifi_scan_finished_cb cb, void *data) ret = wifi_scan(cb, data); if (ret != WIFI_ERROR_NONE) { _ERR("Scan request failed [%s]\n", - wifi_mgr_error_dbg(ret)); + wifi_mgr_error_dbg((wifi_error_e) ret)); return RET_FAILED; } @@ -171,7 +171,7 @@ int wifi_mgr_foreach_found_aps(wifi_found_ap_cb cb, void *data) ret = wifi_foreach_found_aps(cb, data); if (ret != WIFI_ERROR_NONE) { - _ERR("Fail to get AP list %s.\n", wifi_mgr_error_dbg(ret)); + _ERR("Fail to get AP list %s.\n", wifi_mgr_error_dbg((wifi_error_e) ret)); return RET_FAILED; } @@ -199,7 +199,7 @@ int wifi_mgr_activate(wifi_activated_cb cb, void *data) ret = wifi_activate(cb, data); if (ret != WIFI_ERROR_NONE) { _ERR("Fail to wifi_activate %s\n", - wifi_mgr_error_dbg(ret)); + wifi_mgr_error_dbg((wifi_error_e) ret)); return RET_FAILED; } @@ -346,14 +346,14 @@ int wifi_mgr_forget_last_ap(void) return RET_SUCCESS; } else if (ret != WIFI_ERROR_NONE) { _ERR("Fail to get connected AP [%s]\n", - wifi_mgr_error_dbg(ret)); + wifi_mgr_error_dbg((wifi_error_e) ret)); return RET_FAILED; } ret = wifi_ap_get_essid(ap, &name); if (ret != WIFI_ERROR_NONE) { _ERR("Fail to wifi_ap_get_essid AP [%s]\n", - wifi_mgr_error_dbg(ret)); + wifi_mgr_error_dbg((wifi_error_e) ret)); wifi_ap_destroy(ap); return RET_FAILED; } @@ -361,7 +361,7 @@ int wifi_mgr_forget_last_ap(void) ret = wifi_forget_ap(ap); if (ret != WIFI_ERROR_NONE) { _ERR("Fail to forget [%s],[%s].\n", name, - wifi_mgr_error_dbg(ret)); + wifi_mgr_error_dbg((wifi_error_e) ret)); wifi_ap_destroy(ap); free(name); return RET_FAILED; @@ -393,7 +393,7 @@ int wifi_mgr_set_passphrase(wifi_ap_h ap, const char *passcode) ret = wifi_ap_set_passphrase(ap, passcode); if (ret != WIFI_ERROR_NONE) { _ERR("failed to set passcode. ret: %s.", - wifi_mgr_error_dbg(ret)); + wifi_mgr_error_dbg((wifi_error_e) ret)); return RET_FAILED; } @@ -423,7 +423,7 @@ int wifi_mgr_connect(wifi_ap_h ap, wifi_connected_cb cb, void *data) ret = wifi_connect(ap, cb, data); if (ret != WIFI_ERROR_NONE) { _ERR("failed to connect ap. ret: %s.", - wifi_mgr_error_dbg(ret)); + wifi_mgr_error_dbg((wifi_error_e) ret)); return RET_FAILED; } @@ -452,7 +452,7 @@ int wifi_mgr_ap_set_ip_config_type(wifi_ap_h ap, ret = wifi_ap_set_ip_config_type(ap, WIFI_ADDRESS_FAMILY_IPV4, type); if (ret != WIFI_ERROR_NONE) { _ERR("failed to connect ap. ret: %s.", - wifi_mgr_error_dbg(ret)); + wifi_mgr_error_dbg((wifi_error_e) ret)); return RET_FAILED; } @@ -542,19 +542,19 @@ int wifi_mgr_set_ip_config(wifi_ap_h ap, struct network_info *info) info->ip_addr); if (ret != WIFI_ERROR_NONE) _ERR("Fail to set ip address[%s]\n", - wifi_mgr_error_dbg(ret)); + wifi_mgr_error_dbg((wifi_error_e) ret)); ret = wifi_ap_set_subnet_mask(ap, WIFI_ADDRESS_FAMILY_IPV4, info->submask); if (ret != WIFI_ERROR_NONE) _ERR("Fail to set subnet mask[%s]\n", - wifi_mgr_error_dbg(ret)); + wifi_mgr_error_dbg((wifi_error_e) ret)); ret = wifi_ap_set_gateway_address(ap, WIFI_ADDRESS_FAMILY_IPV4, info->gateway); if (ret != WIFI_ERROR_NONE) _ERR("Fail to set gateway address[%s]\n", - wifi_mgr_error_dbg(ret)); + wifi_mgr_error_dbg((wifi_error_e) ret)); return RET_SUCCESS; } @@ -579,7 +579,7 @@ int wifi_mgr_set_dns_config(wifi_ap_h ap, struct network_info *info) info->dns); if (ret != WIFI_ERROR_NONE) { _ERR("Fail to set dns address[%s]\n", - wifi_mgr_error_dbg(ret)); + wifi_mgr_error_dbg((wifi_error_e) ret)); return RET_FAILED; } diff --git a/ug/network/src/wifi_passcode_view.c b/ug/network/src/wifi_passcode_view.cpp similarity index 96% rename from ug/network/src/wifi_passcode_view.c rename to ug/network/src/wifi_passcode_view.cpp index 0890265..dc5c936 100644 --- a/ug/network/src/wifi_passcode_view.c +++ b/ug/network/src/wifi_passcode_view.cpp @@ -65,7 +65,7 @@ static struct _priv *_init_priv(void) { struct _priv *priv; - priv = calloc(1, sizeof(*priv)); + priv = (struct _priv *) calloc(1, sizeof(*priv)); return priv; } @@ -176,8 +176,8 @@ static void _base_key_press_cb(void *data, Evas *e, return; } - priv = data; - ev = ei; + priv = (struct _priv *) data; + ev = (Evas_Event_Key_Down *) ei; if (!ev->keyname) { _ERR("ev->keyname is NULL."); @@ -230,7 +230,7 @@ static void _popup_ok_btn_clicked_cb(void *data, return; } - priv = data; + priv = (struct _priv *) data; if (priv->ctxpopup) { evas_object_del(priv->ctxpopup); @@ -260,7 +260,7 @@ static void _ctxpopup_unfocused_cb(void *data, return; } - priv = data; + priv = (struct _priv *) data; _unset_layout_dim(priv); @@ -288,8 +288,8 @@ static void _ctxpopup_pressed_cb(void *data, Evas *e, return; } - priv = data; - ev = ei; + priv = (struct _priv *) data; + ev = (Evas_Event_Key_Down *) ei; if (!ev->keyname) { _ERR("ev->keyname is NULL."); @@ -401,7 +401,7 @@ static void _retry_btn_clicked_cb(void *data, return; } - priv = data; + priv = (struct _priv *) data; if (priv->ctxpopup) { evas_object_del(priv->ctxpopup); @@ -438,7 +438,7 @@ static void _cancel_btn_clicked_cb(void *data, return; } - priv = data; + priv = (struct _priv *) data; if (priv->ctxpopup) { evas_object_del(priv->ctxpopup); @@ -649,7 +649,7 @@ static void _wifi_connected_cb(wifi_error_e error_code, void *user_data) return; } - priv = user_data; + priv = (struct _priv *) user_data; if (!priv->ctxpopup) return; @@ -683,7 +683,7 @@ static bool _wifi_found_ap_cb(wifi_ap_h ap, void *data) return false; } - priv = data; + priv = (struct _priv *) data; wifi_mgr_get_ap_info(ap, &ap_info); @@ -728,7 +728,7 @@ static void _wifi_scan_request_cb(wifi_error_e error_code, void *data) ret = wifi_mgr_foreach_found_aps(_wifi_found_ap_cb, data); if (ret != RET_SUCCESS) { _ERR("wifi_mgr_foreach_found_aps() failed."); - _show_confirm_popup(data); + _show_confirm_popup((struct _priv *) data); return; } } @@ -787,8 +787,8 @@ static void _entry_key_press_cb(void *data, Evas *e, return; } - priv = data; - ev = ei; + priv = (struct _priv *) data; + ev = (Evas_Event_Key_Down *) ei; if (!ev->keyname) { _ERR("ev->keyname is NULL."); @@ -888,7 +888,7 @@ static Evas_Object *_create(struct viewmgr *vmgr, void *data) priv->ug = vmgr->ug; priv->vmgr = vmgr; - ap_info = data; + ap_info = (struct wifi_ap_info *) data; strncpy(priv->ap_name, ap_info->essid, AP_NAME_LENTH); base = util_add_layout(priv->win, UG_NETWORK_EDJ_FILE, @@ -931,7 +931,7 @@ static void _destroy(Evas_Object *base) return; } - priv = evas_object_data_get(base, KEY_PRIV); + priv = (struct _priv *) evas_object_data_get(base, KEY_PRIV); if (!priv) return; @@ -950,11 +950,12 @@ static enum view_type _get_view_type(void) static struct view_class _vclass = { - .create = _create, - .resume = NULL, - .terminate = _destroy, - .message_handler = NULL, - .get_view_type = _get_view_type, + _create, + NULL, + NULL, + _destroy, + NULL, + _get_view_type, }; /** -- 2.7.4 From 7a28c5cc70ec144b96e651331357fff66ee9d8a2 Mon Sep 17 00:00:00 2001 From: JuWan Kim Date: Thu, 19 Mar 2015 09:51:49 +0900 Subject: [PATCH 05/16] Add CWifiMgr for ug common. Change-Id: I1d14f6efdd955428e01c1316d85e75fc8fb6f412 Signed-off-by: JuWan Kim --- include/dbg.h | 5 +- packaging/org.tizen.settings-tv-ref.spec | 1 - ug/channel/CMakeLists.txt | 4 +- ug/channel/include/dbg.h | 36 -- ug/channel/include/util.h | 9 +- ug/include/UgCommon.h | 10 + ug/include/WifiMgr.h | 55 +++ ug/network/CMakeLists.txt | 7 +- ug/network/include/common.h | 24 ++ ug/network/include/dbg.h | 40 -- ug/network/include/main_view.h | 1 - ug/network/include/util.h | 15 +- ug/network/include/wifi_mgr.h | 69 ---- ug/network/include/wifi_passcode_view.h | 1 - ug/network/src/ip_setting_view.cpp | 63 +++- ug/network/src/main_view.cpp | 120 ++++-- ug/network/src/wifi_passcode_view.cpp | 56 ++- ug/proxy/CMakeLists.txt | 7 +- ug/proxy/include/common.h | 6 - ug/proxy/include/connection_mgr.h | 17 +- ug/proxy/include/dbg.h | 40 -- ug/proxy/include/util.h | 13 +- ug/proxy/include/wifi_mgr.h | 31 -- ug/proxy/src/connection_mgr.cpp | 16 +- ug/proxy/src/main_view.cpp | 188 ++++------ ug/proxy/src/wifi_mgr.cpp | 287 -------------- ug/src/WifiMgr.cpp | 626 +++++++++++++++++++++++++++++++ ug/system/clock/CMakeLists.txt | 3 +- ug/system/clock/include/dbg.h | 33 -- ug/wifi-direct/CMakeLists.txt | 4 +- ug/wifi-direct/include/dbg.h | 38 -- ug/wifi-direct/include/util.h | 9 +- 32 files changed, 1008 insertions(+), 826 deletions(-) delete mode 100644 ug/channel/include/dbg.h create mode 100644 ug/include/UgCommon.h create mode 100644 ug/include/WifiMgr.h delete mode 100644 ug/network/include/dbg.h delete mode 100644 ug/network/include/wifi_mgr.h delete mode 100644 ug/proxy/include/dbg.h delete mode 100644 ug/proxy/include/wifi_mgr.h delete mode 100644 ug/proxy/src/wifi_mgr.cpp create mode 100644 ug/src/WifiMgr.cpp delete mode 100755 ug/system/clock/include/dbg.h delete mode 100644 ug/wifi-direct/include/dbg.h diff --git a/include/dbg.h b/include/dbg.h index c331cc3..544a636 100644 --- a/include/dbg.h +++ b/include/dbg.h @@ -19,6 +19,8 @@ #include +#define ASSERT(exp) if (!(exp)) { _DBG(#exp); int* a = 0; *a = 5; } + #ifdef LOG_TAG #undef LOG_TAG #endif @@ -33,8 +35,7 @@ #endif #ifndef _INFO -#define _INFO(fmt, args...) \ - (LOGI("[%s:%d] "fmt"\n", __func__, __LINE__, ##args)) +#define _INFO(fmt, args...) (LOGI("[%s:%d] "fmt"\n", __func__, __LINE__, ##args)) #endif #endif /* __DBG_H__ */ diff --git a/packaging/org.tizen.settings-tv-ref.spec b/packaging/org.tizen.settings-tv-ref.spec index 5d41cad..13cce91 100644 --- a/packaging/org.tizen.settings-tv-ref.spec +++ b/packaging/org.tizen.settings-tv-ref.spec @@ -13,7 +13,6 @@ BuildRequires: pkgconfig(application-common) BuildRequires: pkgconfig(capi-appfw-application) BuildRequires: pkgconfig(elementary) BuildRequires: pkgconfig(ecore) -BuildRequires: pkgconfig(ecore-x) BuildRequires: pkgconfig(edje) BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(aul) diff --git a/ug/channel/CMakeLists.txt b/ug/channel/CMakeLists.txt index bc4297a..79f361e 100644 --- a/ug/channel/CMakeLists.txt +++ b/ug/channel/CMakeLists.txt @@ -25,10 +25,8 @@ SET(AUTO_PRGM_EDJ_THEME "ug_auto_program_theme.edj") INCLUDE(FindPkgConfig) pkg_check_modules(AUTO_PRGM_UG_PKGS REQUIRED - dlog eina edje - ecore-x evas elementary capi-appfw-application @@ -58,6 +56,8 @@ SET(SRCS ) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../include) + ADD_DEFINITIONS("-DPKGNAME=\"${PROJECT_NAME}\"") ADD_DEFINITIONS("-DAUTO_PRGM_EDJ_FILE=\"${AUTO_PRGM_EDJEDIR}/${AUTO_PRGM_EDJ_FILE}\"") diff --git a/ug/channel/include/dbg.h b/ug/channel/include/dbg.h deleted file mode 100644 index 6e6cd9d..0000000 --- a/ug/channel/include/dbg.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __DBG_H__ - - -#include - - -#ifndef _ERR -#define _ERR(fmt, args...) LOGE("[%s:%d] "fmt"\n", __func__, __LINE__, ##args) -#endif - -#ifndef _DBG -#define _DBG(fmt, args...) LOGD("[%s:%d] "fmt"\n", __func__, __LINE__, ##args) -#endif - -#ifndef _INFO -#define _INFO(fmt, args...) LOGI("[%s:%d] "fmt"\n", __func__, __LINE__, ##args) -#endif - - -#endif /* __DBG_H__ */ diff --git a/ug/channel/include/util.h b/ug/channel/include/util.h index 6630dcf..fe2bab9 100644 --- a/ug/channel/include/util.h +++ b/ug/channel/include/util.h @@ -17,13 +17,10 @@ #ifndef __UTIL_H__ #define __UTIL_H__ -Evas_Object *util_add_layout(Evas_Object *parent, const char *file, - const char *group); -Evas_Object *util_add_scroller(Evas_Object *parent, Eina_Bool h_bounce, - Eina_Bool v_bounce); +Evas_Object *util_add_layout(Evas_Object *parent, const char *file, const char *group); +Evas_Object *util_add_scroller(Evas_Object *parent, Eina_Bool h_bounce, Eina_Bool v_bounce); Evas_Object *util_add_box(Evas_Object *parent, double h, double v); -Evas_Object *util_add_button(Evas_Object *parent, const char *btnstyle, - const char *btnpart, const char *btntext, Eina_Bool flag); +Evas_Object *util_add_button(Evas_Object *parent, const char *btnstyle, const char *btnpart, const char *btntext, Eina_Bool flag); void util_focus_next_set(Evas_Object *obj); #endif /* __UTIL_H__ */ diff --git a/ug/include/UgCommon.h b/ug/include/UgCommon.h new file mode 100644 index 0000000..32a8b32 --- /dev/null +++ b/ug/include/UgCommon.h @@ -0,0 +1,10 @@ +#ifndef __UG_COMMON_H__ +#define __UG_COMMON_H__ + +enum EProxyMethod { + PROXY_METHOD_NONE = 0, + PROXY_METHOD_MANUAL, + PROXY_METHOD_AUTO +}; + +#endif /* __UG_COMMON_H__ */ diff --git a/ug/include/WifiMgr.h b/ug/include/WifiMgr.h new file mode 100644 index 0000000..6e710df --- /dev/null +++ b/ug/include/WifiMgr.h @@ -0,0 +1,55 @@ +#ifndef __WIFIMGR_H__ +#define __WIFIMGR_H__ + +#include "UgCommon.h" +#include "wifi.h" + +class CWifiMgr { +private: + static CWifiMgr* instance; + struct SWifiMgr *m; +public: + CWifiMgr(void) : m(0) {} + virtual ~CWifiMgr() {} + + static bool Initialize(void); + static void Finalize(void); + static CWifiMgr * GetInstance(void); + + bool Activate(void(*ActivatedCb)(wifi_error_e err, void *data), void *data); + + bool IsActivated(bool *activated); + bool GetConnectedAP(wifi_ap_h *ap); + + bool DestroyAP(wifi_ap_h ap); + bool CloneAP(wifi_ap_h *cloned_ap, wifi_ap_h origin); + + bool RegisterScanCallback(void(*ScanFinishedCb)(wifi_error_e err, void *data), void *data); + bool RegisterFoundAPCallback(bool(*FoundCb)(wifi_ap_h ap, void *data), void *data); + + bool SetProxyType(enum EProxyMethod pm); + bool GetProxyType(enum EProxyMethod *pm); + bool SetProxyAddr(const char *ip); + bool GetProxyAddr(char **ip); + bool GetESSID(wifi_ap_h ap, char *essid); + bool GetConnectionState(wifi_ap_h ap, wifi_connection_state_e *state); + bool GetSecurityType(wifi_ap_h ap, wifi_security_type_e *type); + bool ForgetAP(void); + bool SetPassPhrase(wifi_ap_h ap, const char *passcode); + + bool Connect(wifi_ap_h ap, void(*wifi_connected_cb)(wifi_error_e err, void *data), void *data); + bool SetIpType(wifi_ap_h ap, wifi_ip_config_type_e type); + + bool GetIp(wifi_ap_h ap, char *ip); + bool GetSubnetMask(wifi_ap_h ap, char *submask); + bool GetGateway(wifi_ap_h ap, char *gateway); + bool GetDNS(wifi_ap_h ap, char *dns); + + bool SetIp(wifi_ap_h ap, char *ip); + bool SetSubnetMask(wifi_ap_h ap, char *submask); + bool SetGateway(wifi_ap_h ap, char *gateway); + bool SetDNS(wifi_ap_h ap, char *dns); + const char * GetErrorMsg(wifi_error_e err); +}; + +#endif /* __WIFIMGR_H__ */ diff --git a/ug/network/CMakeLists.txt b/ug/network/CMakeLists.txt index e0df379..f53b0bc 100644 --- a/ug/network/CMakeLists.txt +++ b/ug/network/CMakeLists.txt @@ -24,10 +24,8 @@ SET(UG_NETWORK_EDJ_THEME "ug-network-settings-theme.edj") INCLUDE(FindPkgConfig) pkg_check_modules(UG_NETWORK_PKGS REQUIRED - dlog eina edje - ecore-x evas elementary aul @@ -52,13 +50,16 @@ SET(SRCS src/network_viewmgr.cpp src/ip_setting_view.cpp src/vconf_mgr.cpp - src/wifi_mgr.cpp src/connection_mgr.cpp src/util.cpp src/wifi_passcode_view.cpp + ../src/WifiMgr.cpp ) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../include) + ADD_DEFINITIONS("-DPKGNAME=\"${PROJECT_NAME}\"") ADD_DEFINITIONS("-DUG_NETWORK_EDJ_FILE=\"${UG_NETWORK_EDJE_DIR}/${UG_NETWORK_EDJ_FILE}\"") diff --git a/ug/network/include/common.h b/ug/network/include/common.h index 1f158ee..19f2c19 100644 --- a/ug/network/include/common.h +++ b/ug/network/include/common.h @@ -50,4 +50,28 @@ struct network_info { char dns[IP_STRING_MAX_SIZE + 1]; }; +#define SSID_MAX_LENTH 256 +#define PWD_MAX_LENTH 256 + +struct wifi_ap_info { + char essid[SSID_MAX_LENTH]; + char bssid[SSID_MAX_LENTH]; + int rssi; + int frequency; + int max_speed; + wifi_security_type_e secure_type; + wifi_encryption_type_e encryption_type; + bool passphrase_required; + int wps_supported; + wifi_connection_state_e state; + + wifi_ip_config_type_e ip_type; + wifi_proxy_type_e proxy_type; + wifi_encryption_type_e enc_type; + wifi_eap_type_e eap_type; + wifi_eap_auth_type_e eap_auth_type; + + wifi_ap_h ap; + void *user_data; +}; #endif /* __NETWORK_COMMON_H__ */ diff --git a/ug/network/include/dbg.h b/ug/network/include/dbg.h deleted file mode 100644 index faf282c..0000000 --- a/ug/network/include/dbg.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __DBG_H__ -#define __DBG_H__ - -#include - -#ifdef LOG_TAG -#undef LOG_TAG -#endif -#define LOG_TAG "ug-network-settings" - -#ifndef _ERR -#define _ERR(fmt, args...) (LOGE("[%s:%d] "fmt"\n", __func__, __LINE__, ##args)) -#endif - -#ifndef _DBG -#define _DBG(fmt, args...) (LOGD("[%s:%d] "fmt"\n", __func__, __LINE__, ##args)) -#endif - -#ifndef _INFO -#define _INFO(fmt, args...) \ - (LOGI("[%s:%d] "fmt"\n", __func__, __LINE__, ##args)) -#endif - -#endif /* __DBG_H__ */ diff --git a/ug/network/include/main_view.h b/ug/network/include/main_view.h index 018af4b..8b01e27 100644 --- a/ug/network/include/main_view.h +++ b/ug/network/include/main_view.h @@ -18,7 +18,6 @@ #define __MAIN_VIEW_H__ #include -#include #include #include #include "network_viewmgr.h" diff --git a/ug/network/include/util.h b/ug/network/include/util.h index 8e21037..80606d9 100644 --- a/ug/network/include/util.h +++ b/ug/network/include/util.h @@ -17,18 +17,13 @@ #ifndef __UTIL_H__ #define __UTIL_H__ -Evas_Object *util_add_layout(Evas_Object *parent, const char *file, - const char *group); -Evas_Object *util_add_button(Evas_Object *parent, const char *style, - const char *part, const char *text); -Evas_Object *util_add_key_value_button(Evas_Object *parent, - const char *part, const char *text_key, const char *text_value); +Evas_Object *util_add_layout(Evas_Object *parent, const char *file, const char *group); +Evas_Object *util_add_button(Evas_Object *parent, const char *style, const char *part, const char *text); +Evas_Object *util_add_key_value_button(Evas_Object *parent, const char *part, const char *text_key, const char *text_value); Evas_Object *util_add_scroll(Evas_Object *parent, const char *part); Evas_Object *util_add_box(Evas_Object *parent, const char *part); -Evas_Object *util_add_image(Evas_Object *parent, - const char *file, const char *part); -Evas_Object *util_add_entry(Evas_Object *parent, - const char *style, const char *part); +Evas_Object *util_add_image(Evas_Object *parent, const char *file, const char *part); +Evas_Object *util_add_entry(Evas_Object *parent, const char *style, const char *part); Evas_Object *util_add_genlist(Evas_Object *parent); void util_focus_next_set(Evas_Object *obj); diff --git a/ug/network/include/wifi_mgr.h b/ug/network/include/wifi_mgr.h deleted file mode 100644 index d9048cf..0000000 --- a/ug/network/include/wifi_mgr.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __WIFI_MGR_H__ -#define __WIFI_MGR_H__ - -#include -#include "common.h" - -#define SSID_MAX_LENTH 256 -#define PWD_MAX_LENTH 256 - -struct wifi_ap_info { - char essid[SSID_MAX_LENTH]; - char bssid[SSID_MAX_LENTH]; - int rssi; - int frequency; - int max_speed; - wifi_security_type_e secure_type; - wifi_encryption_type_e encryption_type; - bool passphrase_required; - int wps_supported; - wifi_connection_state_e state; - - wifi_ip_config_type_e ip_type; - wifi_proxy_type_e proxy_type; - wifi_encryption_type_e enc_type; - wifi_eap_type_e eap_type; - wifi_eap_auth_type_e eap_auth_type; - - wifi_ap_h ap; - void *user_data; -}; - -const char *wifi_mgr_error_dbg(wifi_error_e err_type); -int wifi_mgr_init(void); -int wifi_mgr_deinit(void); -int wifi_mgr_ap_destroy(wifi_ap_h ap); -int wifi_mgr_ap_clone(wifi_ap_h *cloned_ap, wifi_ap_h origin); -int wifi_mgr_is_activated(bool *activated); -int wifi_mgr_scan_request(wifi_scan_finished_cb cb, void *data); -int wifi_mgr_foreach_found_aps(wifi_found_ap_cb cb, void *data); -int wifi_mgr_activate(wifi_activated_cb cb, void *data); -int wifi_mgr_get_ap_info(wifi_ap_h ap, struct wifi_ap_info *ap_info); -int wifi_mgr_get_connected_ap(wifi_ap_h *ap); -int wifi_mgr_forget_last_ap(void); -int wifi_mgr_connect(wifi_ap_h ap, wifi_connected_cb cb, void *data); -int wifi_mgr_set_passphrase(wifi_ap_h ap, const char *passcode); -int wifi_mgr_get_ip_info(wifi_ap_h ap, struct network_info *info); -int wifi_mgr_ap_set_ip_config_type(wifi_ap_h ap, - wifi_ip_config_type_e type); -int wifi_mgr_set_ip_config(wifi_ap_h ap, struct network_info *info); -int wifi_mgr_set_dns_config(wifi_ap_h ap, struct network_info *info); -//int wifi_mgr_get_is_online_async(wifi_get_is_online_async_cb cb, void *data); - -#endif /* __WIFI_MGR_H__ */ diff --git a/ug/network/include/wifi_passcode_view.h b/ug/network/include/wifi_passcode_view.h index 5805235..0014947 100644 --- a/ug/network/include/wifi_passcode_view.h +++ b/ug/network/include/wifi_passcode_view.h @@ -18,7 +18,6 @@ #define __WIFI_PASSWORD_VIEW_H__ #include -#include #include #include #include "network_viewmgr.h" diff --git a/ug/network/src/ip_setting_view.cpp b/ug/network/src/ip_setting_view.cpp index 5051c37..458a88b 100644 --- a/ug/network/src/ip_setting_view.cpp +++ b/ug/network/src/ip_setting_view.cpp @@ -26,7 +26,8 @@ #include "util.h" #include "common.h" #include "util.h" -#include "wifi_mgr.h" + +#include "WifiMgr.h" #define KEY_PRIV "priv" @@ -95,6 +96,8 @@ struct _priv { wifi_ap_h ap; char name[MAX_NAME_SIZE]; + + CWifiMgr *pWifiMgr; }; static void _show_confirm_popup(struct _priv *priv); @@ -113,6 +116,10 @@ static struct _priv *_init_priv() priv = (struct _priv *) calloc(1, sizeof(*priv)); + priv->pWifiMgr = NULL; + priv->pWifiMgr = CWifiMgr::GetInstance(); + ASSERT(priv->pWifiMgr); + return priv; } @@ -297,6 +304,7 @@ static int _get_cur_ip_info(struct _priv *priv) { struct network_info info; int ret; + bool result = false; if (!priv) { _ERR("The param is invalid.\n"); @@ -328,10 +336,25 @@ static int _get_cur_ip_info(struct _priv *priv) } } else if (priv->network_type == TYPE_WIRELESS) { if (priv->ip_mode == MODE_AUTO) { - ret = wifi_mgr_get_ip_info(priv->ap, &info); - if (ret != RET_SUCCESS) { + result = priv->pWifiMgr->GetIp(priv->ap, priv->info.ip_addr); + if(result != true) { _ERR("wifi_mgr_get_ip_info() failed."); - return ret; + return RET_FAILED; + } + result = priv->pWifiMgr->GetSubnetMask(priv->ap, priv->info.submask); + if(result != true) { + _ERR("wifi_mgr_get_ip_info() failed."); + return RET_FAILED; + } + result = priv->pWifiMgr->GetGateway(priv->ap, priv->info.gateway); + if(result != true) { + _ERR("wifi_mgr_get_ip_info() failed."); + return RET_FAILED; + } + result = priv->pWifiMgr->GetDNS(priv->ap, priv->info.dns); + if(result != true) { + _ERR("wifi_mgr_get_ip_info() failed."); + return RET_FAILED; } } else if (priv->ip_mode == MODE_MAN) { ret = vconf_mgr_get_wireless_network_info(&info); @@ -2022,6 +2045,7 @@ static void _show_invalid_ip_popup(struct _priv *priv) static int _config_network_manually(struct _priv *priv) { int ret; + bool result = false; if (!priv) { _ERR("The param is NULL.\n"); @@ -2054,16 +2078,25 @@ static int _config_network_manually(struct _priv *priv) break; case TYPE_WIRELESS: - ret = wifi_mgr_set_ip_config(priv->ap, &priv->info); - if (ret != RET_SUCCESS) { - _ERR("set wifi ip config failed."); - return ret; + result = priv->pWifiMgr->SetIp(priv->ap, priv->info.ip_addr); + if(result != true) { + _ERR("set wifi dns config failed."); + return RET_FAILED; } - - ret = wifi_mgr_set_dns_config(priv->ap, &priv->info); - if (ret != RET_SUCCESS) { + result = priv->pWifiMgr->SetSubnetMask(priv->ap, priv->info.submask); + if(result != true) { _ERR("set wifi dns config failed."); - return ret; + return RET_FAILED; + } + result = priv->pWifiMgr->SetGateway(priv->ap, priv->info.gateway); + if(result != true) { + _ERR("set wifi dns config failed."); + return RET_FAILED; + } + result = priv->pWifiMgr->SetDNS(priv->ap, priv->info.dns); + if(result != true) { + _ERR("set wifi dns config failed."); + return RET_FAILED; } ret = vconf_mgr_save_wireless_config_info(&priv->info); @@ -2091,6 +2124,7 @@ static int _config_network_manually(struct _priv *priv) static int _config_network_dynamic(struct _priv *priv) { int ret; + bool result = false; if (!priv) { _ERR("The param is NULL.\n"); @@ -2110,9 +2144,8 @@ static int _config_network_dynamic(struct _priv *priv) break; case TYPE_WIRELESS: - ret = wifi_mgr_ap_set_ip_config_type(priv->ap, - WIFI_IP_CONFIG_TYPE_DYNAMIC); - if (ret != RET_SUCCESS) { + result = priv->pWifiMgr->SetIpType(priv->ap, WIFI_IP_CONFIG_TYPE_DYNAMIC); + if(result != false) { _ERR("connection_mgr_ip_dynamic_config() failed."); return RET_FAILED; } diff --git a/ug/network/src/main_view.cpp b/ug/network/src/main_view.cpp index d2723c7..f137381 100644 --- a/ug/network/src/main_view.cpp +++ b/ug/network/src/main_view.cpp @@ -23,11 +23,12 @@ #include "ip_setting_view.h" #include "connection_mgr.h" #include "i18n.h" -#include "wifi_mgr.h" #include "common.h" #include "wifi_passcode_view.h" #include "util.h" +#include "WifiMgr.h" + #define BTN_ACT 4 #define BTN_TYPE 2 #define TIMER_INTERNAL 0.1 @@ -87,6 +88,8 @@ struct _priv { wifi_ap_h ap; char *ap_name; char *ap_pwd; + + CWifiMgr *pWifiMgr; }; static void _show_confirm_popup(struct _priv *priv); @@ -145,12 +148,17 @@ static void _fini_priv(struct _priv *priv) connection_mgr_destroy(priv->connection); if (priv->ap) - wifi_mgr_ap_destroy(priv->ap); + { + priv->pWifiMgr->DestroyAP(priv->ap); + } free(priv->ap_name); free(priv->ap_pwd); - wifi_mgr_deinit(); + CWifiMgr::Finalize(); + + delete (priv->pWifiMgr); + priv->pWifiMgr = NULL; free(priv); } @@ -975,11 +983,11 @@ static void _item_select_cb(void *data, Evas_Object *obj, void *ei) } if (priv->ap) { - wifi_mgr_ap_destroy(priv->ap); + priv->pWifiMgr->DestroyAP(priv->ap); priv->ap = NULL; } - wifi_mgr_ap_clone(&priv->ap, ap_info->ap); + priv->pWifiMgr->CloneAP(&priv->ap, ap_info->ap); if (!priv->ap) { _ERR("ap clone failed."); return; @@ -1030,7 +1038,7 @@ static Eina_Bool _select_connected_cb(void *data) */ static bool _wifi_found_ap_cb(wifi_ap_h ap, void *data) { - int ret; + bool ret; bool state; struct _priv *priv; struct wifi_ap_info *ap_info; @@ -1043,8 +1051,8 @@ static bool _wifi_found_ap_cb(wifi_ap_h ap, void *data) priv = (struct _priv *) data; - ret = wifi_mgr_is_activated(&state); - if (ret != WIFI_ERROR_NONE || state == 0) { + ret = priv->pWifiMgr->IsActivated(&state); + if (ret != true || state == 0) { _ERR("failt to wifi_is_activated"); return EINA_FALSE; } @@ -1055,7 +1063,23 @@ static bool _wifi_found_ap_cb(wifi_ap_h ap, void *data) return EINA_FALSE; } - wifi_mgr_get_ap_info(ap, ap_info); + ret = priv->pWifiMgr->GetESSID(ap, ap_info->essid); + if(ret != true) { + _ERR("Fail to get info"); + return EINA_FALSE; + } + + ret = priv->pWifiMgr->GetConnectionState(ap, &ap_info->state); + if(ret != true) { + _ERR("Fail to get info"); + return EINA_FALSE; + } + + ret = priv->pWifiMgr->GetSecurityType(ap, &ap_info->secure_type); + if(ret != true) { + _ERR("Fail to get info"); + return EINA_FALSE; + } ap_info->ap = ap; ap_info->user_data = priv; @@ -1079,11 +1103,17 @@ static bool _wifi_found_ap_cb(wifi_ap_h ap, void *data) if (ap_info->state == WIFI_CONNECTION_STATE_CONNECTED) { priv->last_item = item; if (priv->ap) { - wifi_mgr_ap_destroy(priv->ap); + ret = priv->pWifiMgr->DestroyAP(priv->ap); + if(ret != true) { + _ERR("Fail to destroy AP"); + } priv->ap = NULL; } - wifi_mgr_ap_clone(&priv->ap, ap); + ret = priv->pWifiMgr->CloneAP(&priv->ap, ap); + if(ret != true) { + _ERR("Fail to clone AP"); + } priv->timer = ecore_timer_add(TIMER_INTERNAL, _select_connected_cb, priv); @@ -1104,15 +1134,18 @@ static bool _wifi_found_ap_cb(wifi_ap_h ap, void *data) */ static void _wifi_scan_request_cb(wifi_error_e error_code, void *data) { - int ret; + struct _priv *priv; + bool ret; if (!data) { _ERR("data is NULL."); return; } - ret = wifi_mgr_foreach_found_aps(_wifi_found_ap_cb, data); - if (ret != RET_SUCCESS) { + priv = (struct _priv *) data; + + ret = priv->pWifiMgr->RegisterFoundAPCallback(_wifi_found_ap_cb, data); + if (ret != true) { _ERR("wifi_mgr_foreach_found_aps() failed."); return; } @@ -1127,11 +1160,12 @@ static void _wifi_scan_request_cb(wifi_error_e error_code, void *data) static void _wifi_activated_cb(wifi_error_e result, void *data) { struct _priv *priv; - int ret; + bool ret; + + priv = (struct _priv *) data; if (result != WIFI_ERROR_NONE) { - _ERR("Wi-Fi Activation Failed! error ==%s.\n", - wifi_mgr_error_dbg(result)); + _ERR("Wi-Fi Activation Failed! error == %s", priv->pWifiMgr->GetErrorMsg(result)); return; } @@ -1140,10 +1174,8 @@ static void _wifi_activated_cb(wifi_error_e result, void *data) return; } - priv = (struct _priv *) data; - - ret = wifi_mgr_scan_request(_wifi_scan_request_cb, data); - if (ret != RET_SUCCESS) { + ret = priv->pWifiMgr->RegisterScanCallback(_wifi_scan_request_cb, data); + if (ret != true) { _ERR("wifi_mgr_scan_request() failed."); _fill_content_part(priv, priv->wireless_discon_ly); _set_action_btn_pos(priv); @@ -1192,7 +1224,7 @@ static int _display_wireless_setting(struct _priv *priv) { Evas_Object *obj; bool activated; - int ret; + bool ret = false; if (!priv) { _ERR("the param is invalid."); @@ -1208,9 +1240,14 @@ static int _display_wireless_setting(struct _priv *priv) return RET_FAILED; } - ret = wifi_mgr_init(); - if (ret != RET_SUCCESS) { - _ERR("fail to init wifi network"); + ret = CWifiMgr::Initialize(); + if(ret != true) { + _ERR("Fail to initialize WifiMgr"); + return RET_FAILED; + } + priv->pWifiMgr = CWifiMgr::GetInstance(); + if(!priv->pWifiMgr) { + _ERR("Fail to get instance"); return RET_FAILED; } @@ -1220,21 +1257,23 @@ static int _display_wireless_setting(struct _priv *priv) _clear_genlist_item_list(priv); activated = EINA_FALSE; - ret = wifi_mgr_is_activated(&activated); - if (ret != RET_SUCCESS) { + ret = priv->pWifiMgr->IsActivated(&activated); + if (ret != true) { _ERR("the wifi is not activated."); return RET_FAILED; } if (activated) { if (priv->ap) { - wifi_mgr_ap_destroy(priv->ap); + ret = priv->pWifiMgr->DestroyAP(priv->ap); + if(ret != true) { + _ERR("Fail to destroy AP"); + } priv->ap = NULL; } - ret = wifi_mgr_scan_request(_wifi_scan_request_cb, - (void *)priv); - if (ret != RET_SUCCESS) { + ret = priv->pWifiMgr->RegisterScanCallback(_wifi_scan_request_cb, (void *)priv); + if (ret != true) { _ERR("wifi_mgr_scan_request() failed."); goto _wireless_finish; } @@ -1243,8 +1282,8 @@ static int _display_wireless_setting(struct _priv *priv) } else { priv->wifi_conn = EINA_FALSE; - ret = wifi_mgr_activate(_wifi_activated_cb, (void *)priv); - if (ret != RET_SUCCESS) + ret = priv->pWifiMgr->Activate(_wifi_activated_cb, (void *)priv); + if (ret != true) _ERR("wifi_mgr_activate() failed."); } @@ -1551,7 +1590,7 @@ static void _wifi_connected_cb(wifi_error_e error_code, void *user_data) static int _wifi_connect_ap(struct _priv *priv, int index) { struct wifi_ap_info *ap_info; - int ret; + bool ret; if (!priv || index < 0) { _ERR("Parameter error!"); @@ -1591,23 +1630,22 @@ static int _wifi_connect_ap(struct _priv *priv, int index) return RET_SUCCESS; } - ret = wifi_mgr_forget_last_ap(); - if (ret != RET_SUCCESS) { + ret = priv->pWifiMgr->ForgetAP(); + if (ret != true) { _ERR("forget last ap failed."); return RET_FAILED; } if (priv->ap_pwd) { - ret = wifi_mgr_set_passphrase(priv->ap, - priv->ap_pwd); - if (ret != RET_SUCCESS) { + ret = priv->pWifiMgr->SetPassPhrase(priv->ap, priv->ap_pwd); + if (ret != true) { _ERR("wifi_mgr_set_passphrase() failed."); return RET_FAILED; } } - ret = wifi_mgr_connect(priv->ap, _wifi_connected_cb, priv); - if (ret != RET_SUCCESS) { + ret = priv->pWifiMgr->Connect(priv->ap, _wifi_connected_cb, priv); + if (ret != true) { _ERR("Fail to connection request.\n"); return RET_FAILED; } diff --git a/ug/network/src/wifi_passcode_view.cpp b/ug/network/src/wifi_passcode_view.cpp index dc5c936..db7f442 100644 --- a/ug/network/src/wifi_passcode_view.cpp +++ b/ug/network/src/wifi_passcode_view.cpp @@ -25,7 +25,8 @@ #include "common.h" #include "wifi_passcode_view.h" #include "util.h" -#include "wifi_mgr.h" + +#include "WifiMgr.h" #define KEY_PRIV "priv" #define KEY_NETWORK_ENTER "Select" @@ -48,6 +49,8 @@ struct _priv { Evas_Object *ctxpopup; char ap_name[AP_NAME_LENTH + 1]; char *ap_pwd; + + CWifiMgr *pWifiMgr; }; static int _wifi_connect_ap(struct _priv *priv); @@ -67,6 +70,10 @@ static struct _priv *_init_priv(void) priv = (struct _priv *) calloc(1, sizeof(*priv)); + priv->pWifiMgr = NULL; + priv->pWifiMgr = CWifiMgr::GetInstance(); + ASSERT(priv->pWifiMgr); + return priv; } @@ -656,7 +663,7 @@ static void _wifi_connected_cb(wifi_error_e error_code, void *user_data) if (error_code != WIFI_ERROR_NONE) { _ERR("connect AP failed, ret: %s.", - wifi_mgr_error_dbg(error_code)); + priv->pWifiMgr->GetErrorMsg(error_code)); _show_confirm_popup(priv); return; } @@ -674,7 +681,7 @@ static void _wifi_connected_cb(wifi_error_e error_code, void *user_data) */ static bool _wifi_found_ap_cb(wifi_ap_h ap, void *data) { - int ret; + bool ret; struct _priv *priv; struct wifi_ap_info ap_info; @@ -685,18 +692,32 @@ static bool _wifi_found_ap_cb(wifi_ap_h ap, void *data) priv = (struct _priv *) data; - wifi_mgr_get_ap_info(ap, &ap_info); + ret = priv->pWifiMgr->GetESSID(ap, ap_info.essid); + if(ret != true) { + _ERR("Fail to get info"); + return false; + } + ret = priv->pWifiMgr->GetConnectionState(ap, &ap_info.state); + if(ret != true) { + _ERR("Fail to get info"); + return false; + } + ret = priv->pWifiMgr->GetSecurityType(ap, &ap_info.secure_type); + if(ret != true) { + _ERR("Fail to get info"); + return false; + } if (!strncmp(priv->ap_name, ap_info.essid, AP_NAME_LENTH)) { - ret = wifi_mgr_set_passphrase(ap, priv->ap_pwd); - if (ret != RET_SUCCESS) { + ret = priv->pWifiMgr->SetPassPhrase(ap, priv->ap_pwd); + if (ret != true) { _ERR("wifi_mgr_set_passphrase() failed."); _show_confirm_popup(priv); return false; } - ret = wifi_mgr_connect(ap, _wifi_connected_cb, priv); - if (ret != RET_SUCCESS) { + ret = priv->pWifiMgr->Connect(ap, _wifi_connected_cb, priv); + if (ret != true) { _ERR("Fail to connection request.\n"); _show_confirm_popup(priv); return false; @@ -718,15 +739,18 @@ static bool _wifi_found_ap_cb(wifi_ap_h ap, void *data) */ static void _wifi_scan_request_cb(wifi_error_e error_code, void *data) { - int ret; + struct _priv *priv; + bool ret; if (!data) { _ERR("data is NULL."); return; } - ret = wifi_mgr_foreach_found_aps(_wifi_found_ap_cb, data); - if (ret != RET_SUCCESS) { + priv = (struct _priv *) data; + + ret = priv->pWifiMgr->RegisterFoundAPCallback(_wifi_found_ap_cb, data); + if (ret != true) { _ERR("wifi_mgr_foreach_found_aps() failed."); _show_confirm_popup((struct _priv *) data); return; @@ -741,7 +765,7 @@ static void _wifi_scan_request_cb(wifi_error_e error_code, void *data) */ static int _wifi_connect_ap(struct _priv *priv) { - int ret; + bool ret; if (!priv || !priv->ap_pwd) { _ERR("Parameter error!"); @@ -750,14 +774,14 @@ static int _wifi_connect_ap(struct _priv *priv) _show_progress_popup(priv); - ret = wifi_mgr_forget_last_ap(); - if (ret != RET_SUCCESS) { + ret = priv->pWifiMgr->ForgetAP(); + if (ret != true) { _ERR("forget last ap failed."); return false; } - ret = wifi_mgr_scan_request(_wifi_scan_request_cb, priv); - if (ret != RET_SUCCESS) { + ret = priv->pWifiMgr->RegisterScanCallback(_wifi_scan_request_cb, priv); + if (ret != true) { _ERR("wifi_mgr_scan_request() failed."); return RET_FAILED; } diff --git a/ug/proxy/CMakeLists.txt b/ug/proxy/CMakeLists.txt index 333b6bc..2158e83 100644 --- a/ug/proxy/CMakeLists.txt +++ b/ug/proxy/CMakeLists.txt @@ -24,10 +24,8 @@ SET(UG_PROXY_EDJ_THEME "ug-proxy-settings-theme.edj") INCLUDE(FindPkgConfig) pkg_check_modules(UG_PROXY_PKGS REQUIRED - dlog eina edje - ecore-x evas elementary aul @@ -51,11 +49,14 @@ SET(SRCS src/main_view.cpp src/vconf_mgr.cpp src/connection_mgr.cpp - src/wifi_mgr.cpp src/util.cpp + ../src/WifiMgr.cpp ) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../include) + ADD_DEFINITIONS("-DPKGNAME=\"${PROJECT_NAME}\"") ADD_DEFINITIONS("-DUG_PROXY_EDJ_FILE=\"${UG_PROXY_EDJE_DIR}/${UG_PROXY_EDJ_FILE}\"") diff --git a/ug/proxy/include/common.h b/ug/proxy/include/common.h index 3f18331..ceaf2dc 100644 --- a/ug/proxy/include/common.h +++ b/ug/proxy/include/common.h @@ -26,10 +26,4 @@ #define IP_ZERO "0.0.0.0" #define URL_BLANK "" -enum method_enum { - METHOD_NONE = 0, - METHOD_MAN, - METHOD_AUTO -}; - #endif /* __PROXY_COMMON_H__ */ diff --git a/ug/proxy/include/connection_mgr.h b/ug/proxy/include/connection_mgr.h index acd36a3..57dfc77 100644 --- a/ug/proxy/include/connection_mgr.h +++ b/ug/proxy/include/connection_mgr.h @@ -19,19 +19,14 @@ #include #include -#include "common.h" +#include "UgCommon.h" connection_h connection_mgr_create(void); int connection_mgr_destroy(connection_h connection); -int connection_mgr_get_profile_info(connection_h connection, - connection_profile_h *out_proflie); -int connection_mgr_set_proxy_type(connection_h connection, - enum method_enum method); -int connection_mgr_get_proxy_type(connection_h connection, - enum method_enum *method); -int connection_mgr_set_proxy_address(connection_h connection, - const char *ip); -int connection_mgr_get_proxy_address(connection_h connection, - char **ip); +int connection_mgr_get_profile_info(connection_h connection, connection_profile_h *out_proflie); +int connection_mgr_set_proxy_type(connection_h connection, enum EProxyMethod method); +int connection_mgr_get_proxy_type(connection_h connection, enum EProxyMethod *method); +int connection_mgr_set_proxy_address(connection_h connection, const char *ip); +int connection_mgr_get_proxy_address(connection_h connection, char **ip); #endif /* __CONNECTION_MGR_H__ */ diff --git a/ug/proxy/include/dbg.h b/ug/proxy/include/dbg.h deleted file mode 100644 index faf282c..0000000 --- a/ug/proxy/include/dbg.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __DBG_H__ -#define __DBG_H__ - -#include - -#ifdef LOG_TAG -#undef LOG_TAG -#endif -#define LOG_TAG "ug-network-settings" - -#ifndef _ERR -#define _ERR(fmt, args...) (LOGE("[%s:%d] "fmt"\n", __func__, __LINE__, ##args)) -#endif - -#ifndef _DBG -#define _DBG(fmt, args...) (LOGD("[%s:%d] "fmt"\n", __func__, __LINE__, ##args)) -#endif - -#ifndef _INFO -#define _INFO(fmt, args...) \ - (LOGI("[%s:%d] "fmt"\n", __func__, __LINE__, ##args)) -#endif - -#endif /* __DBG_H__ */ diff --git a/ug/proxy/include/util.h b/ug/proxy/include/util.h index 16b0647..5b0a0b0 100644 --- a/ug/proxy/include/util.h +++ b/ug/proxy/include/util.h @@ -17,16 +17,11 @@ #ifndef __UTIL_H__ #define __UTIL_H__ -Evas_Object *util_add_layout(Evas_Object *parent, const char *file, - const char *group); -Evas_Object *util_add_button(Evas_Object *parent, const char *style, - const char *part, const char *text); -Evas_Object *util_add_key_value_button(Evas_Object *parent, - const char *style, const char *part, - const char *text_key, const char *text_value); +Evas_Object *util_add_layout(Evas_Object *parent, const char *file, const char *group); +Evas_Object *util_add_button(Evas_Object *parent, const char *style, const char *part, const char *text); +Evas_Object *util_add_key_value_button(Evas_Object *parent, const char *style, const char *part, const char *text_key, const char *text_value); Evas_Object *util_add_box(Evas_Object *parent, const char *part); -Evas_Object *util_add_entry(Evas_Object *parent, - const char *style, const char *part); +Evas_Object *util_add_entry(Evas_Object *parent, const char *style, const char *part); void util_set_focus_next_self(Evas_Object *obj); #endif /* __UTIL_H__ */ diff --git a/ug/proxy/include/wifi_mgr.h b/ug/proxy/include/wifi_mgr.h deleted file mode 100644 index 43482a4..0000000 --- a/ug/proxy/include/wifi_mgr.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __WIFI_MGR_H__ -#define __WIFI_MGR_H__ - -#include -#include "common.h" - -int wifi_mgr_init(void); -int wifi_mgr_deinit(void); -int wifi_mgr_get_connected_ap(wifi_ap_h *ap); -int wifi_mgr_set_proxy_type(enum method_enum method); -int wifi_mgr_get_proxy_type(enum method_enum *method); -int wifi_mgr_set_proxy_address(const char *ip); -int wifi_mgr_get_proxy_address(char **ip); - -#endif /* __WIFI_MGR_H__ */ diff --git a/ug/proxy/src/connection_mgr.cpp b/ug/proxy/src/connection_mgr.cpp index ca7d628..f61cc22 100644 --- a/ug/proxy/src/connection_mgr.cpp +++ b/ug/proxy/src/connection_mgr.cpp @@ -209,7 +209,7 @@ int connection_mgr_get_profile_info(connection_h connection, * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; */ int connection_mgr_set_proxy_type(connection_h connection, - enum method_enum method) + enum EProxyMethod method) { connection_profile_h profile; connection_proxy_type_e type; @@ -228,13 +228,13 @@ int connection_mgr_set_proxy_type(connection_h connection, } switch (method) { - case METHOD_NONE: + case PROXY_METHOD_NONE: type = CONNECTION_PROXY_TYPE_DIRECT; break; - case METHOD_MAN: + case PROXY_METHOD_MANUAL: type = CONNECTION_PROXY_TYPE_MANUAL; break; - case METHOD_AUTO: + case PROXY_METHOD_AUTO: type = CONNECTION_PROXY_TYPE_AUTO; break; default: @@ -258,7 +258,7 @@ int connection_mgr_set_proxy_type(connection_h connection, * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; */ int connection_mgr_get_proxy_type(connection_h connection, - enum method_enum *method) + enum EProxyMethod *method) { connection_profile_h profile; connection_proxy_type_e type; @@ -284,13 +284,13 @@ int connection_mgr_get_proxy_type(connection_h connection, switch (type) { case CONNECTION_PROXY_TYPE_DIRECT: - *method = METHOD_NONE; + *method = PROXY_METHOD_NONE; break; case CONNECTION_PROXY_TYPE_MANUAL: - *method = METHOD_MAN; + *method = PROXY_METHOD_MANUAL; break; case CONNECTION_PROXY_TYPE_AUTO: - *method = METHOD_AUTO; + *method = PROXY_METHOD_AUTO; break; default: return RET_FAILED; diff --git a/ug/proxy/src/main_view.cpp b/ug/proxy/src/main_view.cpp index 173e89d..a69271f 100644 --- a/ug/proxy/src/main_view.cpp +++ b/ug/proxy/src/main_view.cpp @@ -20,12 +20,15 @@ #include "dbg.h" #include "main_view.h" #include "vconf_mgr.h" -#include "wifi_mgr.h" #include "connection_mgr.h" #include "i18n.h" #include "util.h" #include "common.h" +#include "UgCommon.h" +#include "WifiMgr.h" + + #define KEY_PRIV "priv" #define KEY_PROXY_ENTER "Select" #define IP_VALUE1 "value1" @@ -75,13 +78,15 @@ struct _priv { Evas_Object *ctxpopup; Evas_Object *vaule_btns[PROXY_CONFIG_MAX_NUM]; - enum method_enum method; enum network_type_enum net_type; connection_h connection; char ip[IP_STRING_LEN + 1]; char url[MOTHED_URL_LEN + 1]; + + CWifiMgr *pWifiMgr; + enum EProxyMethod eMethod; }; static int _create_method_none_btn(struct _priv *priv); @@ -89,24 +94,6 @@ static int _create_method_manual_btns(struct _priv *priv); static int _create_method_auto_btns(struct _priv *priv); /** - * Initializes WI-FI for wireless network. - * - * @param[in] priv The handler of the private data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -static int _init_wifi(struct _priv *priv) -{ - if (!priv) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - wifi_mgr_init(); - - return RET_SUCCESS; -} - -/** * Initializes connection for wired network. * * @param[in] priv The handler of the private data @@ -129,24 +116,6 @@ static int _init_connection(struct _priv *priv) } /** - * Deinitializes WI-FI for wireless network. - * - * @param[in] priv The handler of the private data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -static int _fini_wifi(struct _priv *priv) -{ - if (!priv) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - wifi_mgr_deinit(); - - return RET_SUCCESS; -} - -/** * Deinitializes connection for wired network. * * @param[in] priv The handler of the private data @@ -174,6 +143,7 @@ static int _fini_connection(struct _priv *priv) */ static struct _priv *_init_priv() { + bool ret = false; struct _priv *priv; priv = (struct _priv *) calloc(1, sizeof(*priv)); @@ -182,7 +152,18 @@ static struct _priv *_init_priv() return NULL; } - _init_wifi(priv); + ret = CWifiMgr::Initialize(); + if(ret != true) { + _ERR("Fail to initialize WifiMgr"); + return NULL; + } + priv->pWifiMgr = CWifiMgr::GetInstance(); + if(!priv->pWifiMgr) { + _ERR("Fail to get instance"); + free (priv); + return NULL; + } + _init_connection(priv); return priv; @@ -200,9 +181,14 @@ static void _fini_priv(struct _priv *priv) if (!priv) return; - _fini_wifi(priv); + //_fini_wifi(priv); _fini_connection(priv); + if(priv->pWifiMgr) { + CWifiMgr::Finalize(); + priv->pWifiMgr = NULL; + } + if (priv->base) evas_object_del(priv->base); @@ -447,13 +433,13 @@ static int _get_proxy_method(struct _priv *priv) switch (value) { case 0: - priv->method = METHOD_NONE; + priv->eMethod = PROXY_METHOD_NONE; break; case 1: - priv->method = METHOD_MAN; + priv->eMethod = PROXY_METHOD_MANUAL; break; case 2: - priv->method = METHOD_AUTO; + priv->eMethod = PROXY_METHOD_AUTO; break; default: return RET_FAILED; @@ -516,27 +502,6 @@ static void _ctxpopup_unfocused_cb(void *data, } /** - * Clears the buttons in the box. - * - * When the method is changed, clear the box firstly. - * - * @param[in] priv The handler of the private data - */ -static void _clear_method_btns(struct _priv *priv) -{ - if (!priv) { - _ERR("Parameter error!"); - return; - } - - elm_box_clear(priv->box); - - priv->method_btn = NULL; - priv->proxy_btn= NULL; - priv->url_btn = NULL; -} - -/** * Creates the method select button. * * Uses the style of 'method_select'. @@ -616,7 +581,7 @@ static void _ctxpopup_key_pressed_cb(void *data, Evas *evas, * @param[in] method The proxy method */ static void _method_btn_click_proc(struct _priv *priv, - enum method_enum method) + enum EProxyMethod method) { if (!priv) { _ERR("The param is invalid.\n"); @@ -628,18 +593,22 @@ static void _method_btn_click_proc(struct _priv *priv, priv->ctxpopup = NULL; } - priv->method = method; + priv->eMethod = method; - _clear_method_btns(priv); + elm_box_clear(priv->box); - switch (priv->method) { - case METHOD_NONE: + priv->method_btn = NULL; + priv->proxy_btn= NULL; + priv->url_btn = NULL; + + switch (priv->eMethod) { + case PROXY_METHOD_NONE: _create_method_none_btn(priv); break; - case METHOD_MAN: + case PROXY_METHOD_MANUAL: _create_method_manual_btns(priv); break; - case METHOD_AUTO: + case PROXY_METHOD_AUTO: _create_method_auto_btns(priv); break; default: @@ -670,7 +639,7 @@ static void _method_none_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) priv = (struct _priv *) data; - _method_btn_click_proc(priv, METHOD_NONE); + _method_btn_click_proc(priv, PROXY_METHOD_NONE); } /** @@ -693,7 +662,7 @@ static void _method_man_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) priv = (struct _priv *) data; - _method_btn_click_proc(priv, METHOD_MAN); + _method_btn_click_proc(priv, PROXY_METHOD_MANUAL); } /** @@ -716,7 +685,7 @@ static void _method_auto_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) priv = (struct _priv *) data; - _method_btn_click_proc(priv, METHOD_AUTO); + _method_btn_click_proc(priv, PROXY_METHOD_AUTO); } /** @@ -785,7 +754,7 @@ static void _method_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) elm_box_pack_end(box, none_btn); elm_object_focus_set(none_btn, EINA_TRUE); - btn[METHOD_NONE] = none_btn; + btn[PROXY_METHOD_NONE] = none_btn; man_btn = _create_method_select_btn(ctxpopup, _(TXT_MOTHED_MAN), _method_man_btn_clicked_cb, priv); @@ -796,7 +765,7 @@ static void _method_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) } elm_box_pack_end(box, man_btn); - btn[METHOD_MAN] = man_btn; + btn[PROXY_METHOD_MANUAL] = man_btn; auto_btn = _create_method_select_btn(ctxpopup, _(TXT_MOTHED_AUTO), _method_auto_btn_clicked_cb, priv); @@ -807,19 +776,19 @@ static void _method_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) } elm_box_pack_end(box, auto_btn); - btn[METHOD_AUTO] = auto_btn; + btn[PROXY_METHOD_AUTO] = auto_btn; _set_up_down_cycle_focus(btn, METHOD_NUM); _set_left_right_cycle_focus(btn, METHOD_NUM); - switch (priv->method) { - case METHOD_NONE: + switch (priv->eMethod) { + case PROXY_METHOD_NONE: elm_object_signal_emit(none_btn, SIG_BTN_SELECTED, PROG); break; - case METHOD_MAN: + case PROXY_METHOD_MANUAL: elm_object_signal_emit(man_btn, SIG_BTN_SELECTED, PROG); break; - case METHOD_AUTO: + case PROXY_METHOD_AUTO: elm_object_signal_emit(auto_btn, SIG_BTN_SELECTED, PROG); break; default: @@ -1499,8 +1468,8 @@ static int _create_proxy_ly(struct _priv *priv) priv->box = box; - switch (priv->method) { - case METHOD_NONE: + switch (priv->eMethod) { + case PROXY_METHOD_NONE: ret = _create_method_none_btn(priv); if (ret != RET_SUCCESS) { _ERR("add method none failed."); @@ -1508,7 +1477,7 @@ static int _create_proxy_ly(struct _priv *priv) } break; - case METHOD_MAN: + case PROXY_METHOD_MANUAL: ret = _create_method_manual_btns(priv); if (ret != RET_SUCCESS) { _ERR("add method manual failed."); @@ -1516,7 +1485,7 @@ static int _create_proxy_ly(struct _priv *priv) } break; - case METHOD_AUTO: + case PROXY_METHOD_AUTO: ret = _create_method_auto_btns(priv); if (ret != RET_SUCCESS) { _ERR("add method manual failed."); @@ -1625,12 +1594,12 @@ static void _show_invalid_info_ctxpopup(struct _priv *priv, int ret) return; } - switch (priv->method) { - case METHOD_MAN: + switch (priv->eMethod) { + case PROXY_METHOD_MANUAL: elm_object_part_text_set(layout, PART_TEXT_TITLE, _(TXT_MANUAL_TITLE)); break; - case METHOD_AUTO: + case PROXY_METHOD_AUTO: elm_object_part_text_set(layout, PART_TEXT_TITLE, _(TXT_AUTO_TITLE)); break; @@ -1700,18 +1669,18 @@ static int _save_to_vconf(struct _priv *priv) return RET_SUCCESS; } - vconf_mgr_set_int_value(VCONF_PROXY_METHOD, priv->method); + vconf_mgr_set_int_value(VCONF_PROXY_METHOD, priv->eMethod); - switch (priv->method) { - case METHOD_NONE: + switch (priv->eMethod) { + case PROXY_METHOD_NONE: break; - case METHOD_MAN: + case PROXY_METHOD_MANUAL: _check_ip_is_valid(priv); vconf_mgr_set_string_value(VCONF_PROXY_IP, priv->ip); break; - case METHOD_AUTO: + case PROXY_METHOD_AUTO: vconf_mgr_set_string_value(VCONF_PROXY_URL, priv->url); break; @@ -1737,23 +1706,23 @@ static int _set_connection_proxy(struct _priv *priv) return RET_FAILED; } - ret = connection_mgr_set_proxy_type(priv->connection, priv->method); + ret = connection_mgr_set_proxy_type(priv->connection, priv->eMethod); if (ret != RET_SUCCESS) { _ERR("wifi_mgr_get_proxy_type() failed."); return ret; } - switch (priv->method) { - case METHOD_NONE: + switch (priv->eMethod) { + case PROXY_METHOD_NONE: connection_mgr_set_proxy_address(priv->connection, NULL); break; - case METHOD_MAN: + case PROXY_METHOD_MANUAL: if (priv->ip) connection_mgr_set_proxy_address(priv->connection, priv->ip); break; - case METHOD_AUTO: + case PROXY_METHOD_AUTO: if (priv->url) connection_mgr_set_proxy_address(priv->connection, priv->url); @@ -1776,27 +1745,32 @@ static int _set_wifi_proxy(struct _priv *priv) int ret; if (!priv) { - _ERR("The param is invalid.\n"); + _ERR("The param is invalid."); + return RET_FAILED; + } + + if (!priv->pWifiMgr) { + _ERR("WifiMgr is not initialized."); return RET_FAILED; } - ret = wifi_mgr_set_proxy_type(priv->method); + ret = priv->pWifiMgr->SetProxyType(priv->eMethod); if (ret != RET_SUCCESS) { _ERR("wifi_mgr_get_proxy_type() failed."); return ret; } - switch (priv->method) { - case METHOD_NONE: - wifi_mgr_set_proxy_address(NULL); + switch (priv->eMethod) { + case PROXY_METHOD_NONE: + priv->pWifiMgr->SetProxyAddr(NULL); break; - case METHOD_MAN: + case PROXY_METHOD_MANUAL: if (priv->ip) - wifi_mgr_set_proxy_address(priv->ip); + priv->pWifiMgr->SetProxyAddr(priv->ip); break; - case METHOD_AUTO: + case PROXY_METHOD_AUTO: if (priv->url) - wifi_mgr_set_proxy_address(priv->url); + priv->pWifiMgr->SetProxyAddr(priv->url); break; default: return RET_FAILED; diff --git a/ug/proxy/src/wifi_mgr.cpp b/ug/proxy/src/wifi_mgr.cpp deleted file mode 100644 index 98eb1b1..0000000 --- a/ug/proxy/src/wifi_mgr.cpp +++ /dev/null @@ -1,287 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "defs.h" -#include "dbg.h" -#include "wifi_mgr.h" - -/** - * Converts the error type to string information. - * - * @param[in] err_type Error type - * @return error string information; - */ -const char *wifi_mgr_error_dbg(wifi_error_e err_type) -{ - switch (err_type) { - case WIFI_ERROR_NONE: - return "NONE"; - case WIFI_ERROR_INVALID_PARAMETER: - return "INVALID_PARAMETER"; - case WIFI_ERROR_OUT_OF_MEMORY: - return "OUT_OF_MEMORY"; - case WIFI_ERROR_INVALID_OPERATION: - return "INVALID_OPERATION"; - case WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED: - return "ADDRESS_FAMILY_NOT_SUPPORTED"; - case WIFI_ERROR_OPERATION_FAILED: - return "OPERATION_FAILED"; - case WIFI_ERROR_NO_CONNECTION: - return "NO_CONNECTION"; - case WIFI_ERROR_NOW_IN_PROGRESS: - return "NOW_IN_PROGRESS"; - case WIFI_ERROR_ALREADY_EXISTS: - return "ALREADY_EXISTS"; - case WIFI_ERROR_OPERATION_ABORTED: - return "OPERATION_ABORTED"; - case WIFI_ERROR_DHCP_FAILED: - return "DHCP_FAILED"; - case WIFI_ERROR_INVALID_KEY: - return "INVALID_KEY"; - case WIFI_ERROR_NO_REPLY: - return "NO_REPLY"; - case WIFI_ERROR_SECURITY_RESTRICTED: - return "SECURITY_RESTRICTED"; - default: - break; - } - - return "UNKNOWN"; -} - -/** - * Initializes Wi-Fi. - * - * Called before using wifi APIs. - * - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int wifi_mgr_init(void) -{ - int ret; - - ret = wifi_initialize(); - if (ret != WIFI_ERROR_NONE) { - _ERR("Fail to wifi_initialize.\n"); - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Deinitializes Wi-Fi. - * - * Called when network setting is destroyed. - * - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int wifi_mgr_deinit(void) -{ - int ret; - - ret = wifi_deinitialize(); - if (ret != WIFI_ERROR_NONE) { - _ERR("Fail to wifi_deinitialize.\n"); - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Gets the handle of connected access point. - * - * You can get the connected access point and its configuration. - * - * @param[out] ap The handle of access point - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int wifi_mgr_get_connected_ap(wifi_ap_h *ap) -{ - int ret; - - if (!ap) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - ret = wifi_get_connected_ap(ap); - if (ret != WIFI_ERROR_NONE) { - _ERR("wifi_get_connected_ap() failed."); - return ret; - } - - return RET_SUCCESS; -} - -/** - * Sets the Proxy type. - * - * If you set Proxy type to #WIFI_PROXY_TYPE_AUTO or - * #WIFI_PROXY_TYPE_MANUAL, then Proxy will be restored. - * - * @param[in] method The proxy method - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int wifi_mgr_set_proxy_type(enum method_enum method) -{ - wifi_proxy_type_e type; - wifi_ap_h ap; - int ret; - - if (method < 0 || method >= METHOD_NUM) { - _ERR("method is invalid."); - return RET_FAILED; - } - - ap = NULL; - ret = wifi_get_connected_ap(&ap); - if (ret != WIFI_ERROR_NONE) { - _ERR("wifi_get_connected_ap() failed."); - return ret; - } - - switch (method) { - case METHOD_NONE: - type = WIFI_PROXY_TYPE_DIRECT; - break; - case METHOD_MAN: - type = WIFI_PROXY_TYPE_MANUAL; - break; - case METHOD_AUTO: - type = WIFI_PROXY_TYPE_AUTO; - break; - default: - return RET_FAILED; - } - - ret = wifi_ap_set_proxy_type(ap, type); - if (ret != WIFI_ERROR_NONE) { - _ERR("wifi_ap_set_proxy_type() failed."); - return ret; - } - - return RET_SUCCESS; -} - -/** - * Gets the Proxy type. - * - * @param[out] method The proxy method - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int wifi_mgr_get_proxy_type(enum method_enum *method) -{ - wifi_proxy_type_e type; - wifi_ap_h ap; - int ret; - - if (!method) { - _ERR("method is invalid."); - return RET_FAILED; - } - - ap = NULL; - ret = wifi_get_connected_ap(&ap); - if (ret != WIFI_ERROR_NONE) { - _ERR("wifi_get_connected_ap() failed."); - return ret; - } - - ret = wifi_ap_get_proxy_type(ap, &type); - if (ret != WIFI_ERROR_NONE) { - _ERR("wifi_ap_get_proxy_type() failed."); - return ret; - } - - switch (type) { - case WIFI_PROXY_TYPE_DIRECT: - *method = METHOD_NONE; - break; - case WIFI_PROXY_TYPE_MANUAL: - *method = METHOD_MAN; - break; - case WIFI_PROXY_TYPE_AUTO: - *method = METHOD_AUTO; - break; - default: - return RET_FAILED; - } - - return RET_SUCCESS; - -} - -/** - * Sets the proxy address. - * - * @param[in] ip The IP address - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int wifi_mgr_set_proxy_address(const char *ip) -{ - wifi_ap_h ap; - int ret; - - ap = NULL; - ret = wifi_get_connected_ap(&ap); - if (ret != WIFI_ERROR_NONE) { - _ERR("wifi_get_connected_ap() failed."); - return ret; - } - - ret = wifi_ap_set_proxy_address(ap, WIFI_ADDRESS_FAMILY_IPV4, ip); - if (ret != WIFI_ERROR_NONE) { - _ERR("wifi_ap_set_proxy_address() failed."); - return ret; - } - - return RET_SUCCESS; -} - -/** - * Gets the proxy address. - * - * @param[out] ip The IP address - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int wifi_mgr_get_proxy_address(char **ip) -{ - wifi_ap_h ap; - int ret; - - if (!ip || !*ip) { - _ERR("ip is invalid."); - return RET_FAILED; - } - - ap = NULL; - ret = wifi_get_connected_ap(&ap); - if (ret != WIFI_ERROR_NONE) { - _ERR("wifi_get_connected_ap() failed."); - return ret; - } - - ret = wifi_ap_get_proxy_address(ap, WIFI_ADDRESS_FAMILY_IPV4, ip); - if (ret != WIFI_ERROR_NONE) { - _ERR("wifi_ap_get_proxy_address() failed."); - return ret; - } - - return RET_SUCCESS; -} diff --git a/ug/src/WifiMgr.cpp b/ug/src/WifiMgr.cpp new file mode 100644 index 0000000..7c993e3 --- /dev/null +++ b/ug/src/WifiMgr.cpp @@ -0,0 +1,626 @@ +#include +#include +#include "WifiMgr.h" + +#define IP_STRING_MAX_SIZE 20 +#define MAX_NAME_SIZE 256 +#define CONTENT_TXT_SIZE 500 +#define ZERO_IP "0.0.0.0" + +CWifiMgr *CWifiMgr::instance = NULL; + +struct SWifiMgr { + wifi_ap_h ap; +}; + + +bool CWifiMgr::Initialize(void) +{ + ASSERT(!instance); + + instance = new CWifiMgr; + if(!instance) + return false; + + int ret; + + instance->m = new SWifiMgr; + if(instance->m == NULL) return false; + + ret = wifi_initialize(); + if (ret != WIFI_ERROR_NONE) { + _ERR("Fail to wifi_initialize. error : %s", instance->GetErrorMsg((wifi_error_e) ret)); + return false; + } + + instance->m->ap = NULL; + + return true; +} + + +void CWifiMgr::Finalize(void) +{ + if(!instance) + return; + ASSERT(instance->m); + + if (wifi_deinitialize() != WIFI_ERROR_NONE) { + _ERR("Fail to wifi_deinitialize."); + } + + delete instance->m; + delete instance; + instance = NULL; +} + + +CWifiMgr *CWifiMgr::GetInstance(void) +{ + return instance; +} + + +bool CWifiMgr::Activate(void(*ActivatedCb)(wifi_error_e err, void *data), void *data) +{ + int ret; + + if (!ActivatedCb) { + _ERR("Parameter is invalid"); + return false; + } + + ret = wifi_activate(ActivatedCb, data); + if (ret != WIFI_ERROR_NONE) { + _ERR("Fail to wifi_activate %s", GetErrorMsg((wifi_error_e) ret)); + return false; + } + + return true; +} + + +bool CWifiMgr::IsActivated(bool *activated) +{ + int ret; + + ret = wifi_is_activated(activated); + if (ret != WIFI_ERROR_NONE) { + _ERR("Fail to wifi_is_activated %s",GetErrorMsg((wifi_error_e) ret)); + return false; + } + + return true; +} + + +bool CWifiMgr::GetConnectedAP(wifi_ap_h *ap) +{ + int ret; + + if (!ap) { + _ERR("the param is invalid."); + return false; + } + + ret = wifi_get_connected_ap(ap); + if (ret != WIFI_ERROR_NONE) { + _ERR("Fail to wifi_get_connected_ap %s",GetErrorMsg((wifi_error_e) ret)); + return false; + } + + return true; +} + +bool CWifiMgr::DestroyAP(wifi_ap_h ap) +{ + int ret; + + if (!ap) { + _ERR("the ap is already NULL."); + return true; + } + + ret = wifi_ap_destroy(ap); + if (ret != WIFI_ERROR_NONE) { + _ERR("Fail to wifi_ap_destroy %s",GetErrorMsg((wifi_error_e) ret)); + return false; + } + + return true; +} + + +bool CWifiMgr::CloneAP(wifi_ap_h *cloned_ap, wifi_ap_h origin) +{ + int ret; + + if (!cloned_ap || !origin) { + _ERR("the param is invalid."); + return false; + } + + ret = wifi_ap_clone(cloned_ap, origin); + if (ret != WIFI_ERROR_NONE) { + _ERR("Fail to wifi_ap_clone %s",GetErrorMsg((wifi_error_e) ret)); + return false; + } + + return true; +} + + +bool CWifiMgr::RegisterScanCallback(void(*ScanFinishedCb)(wifi_error_e err, void* data), void *data) +{ + int ret; + + if (!ScanFinishedCb) { + _ERR("Parameter is invalid"); + return false; + } + + ret = wifi_scan(ScanFinishedCb, data); + if (ret != WIFI_ERROR_NONE) { + _ERR("Scan request failed [%s]", GetErrorMsg((wifi_error_e) ret)); + return false; + } + + return true; +} + + +bool CWifiMgr::RegisterFoundAPCallback(bool(*FoundCb)(wifi_ap_h ap, void *data), void *data) +{ + int ret; + + if (!FoundCb) { + _ERR("Parameter is invalid"); + return false; + } + + ret = wifi_foreach_found_aps(FoundCb, data); + if (ret != WIFI_ERROR_NONE) { + _ERR("Fail to get AP list %s.", GetErrorMsg((wifi_error_e) ret)); + return false; + } + + return true; +} + + +bool CWifiMgr::SetProxyType(enum EProxyMethod pm) +{ + ASSERT(m); + + wifi_proxy_type_e type; + wifi_ap_h ap; + + if (wifi_get_connected_ap(&ap) != WIFI_ERROR_NONE) { + _ERR("wifi_get_connected_ap() failed."); + return false; + } + + switch (pm) { + case PROXY_METHOD_NONE: + type = WIFI_PROXY_TYPE_DIRECT; + break; + case PROXY_METHOD_MANUAL: + type = WIFI_PROXY_TYPE_MANUAL; + break; + case PROXY_METHOD_AUTO: + type = WIFI_PROXY_TYPE_AUTO; + break; + default: + return false; + } + + if (wifi_ap_set_proxy_type(ap, type) != WIFI_ERROR_NONE) { + _ERR("wifi_ap_set_proxy_type() failed."); + return false; + } + + return true; +} + + +bool CWifiMgr::GetProxyType(enum EProxyMethod *pm) +{ + ASSERT(m); + + wifi_proxy_type_e type; + wifi_ap_h ap; + + if (!pm) { + _ERR("parameter is invalid."); + return false; + } + + if (wifi_get_connected_ap(&ap) != WIFI_ERROR_NONE) { + _ERR("wifi_get_connected_ap() failed."); + return false; + } + + if (wifi_ap_get_proxy_type(ap, &type) != WIFI_ERROR_NONE) { + _ERR("wifi_ap_get_proxy_type() failed."); + return false; + } + + switch (type) { + case WIFI_PROXY_TYPE_DIRECT: + *pm = PROXY_METHOD_NONE; + break; + case WIFI_PROXY_TYPE_MANUAL: + *pm = PROXY_METHOD_MANUAL; + break; + case WIFI_PROXY_TYPE_AUTO: + *pm = PROXY_METHOD_AUTO; + break; + default: + return false; + } + + return true; +} + + +bool CWifiMgr::SetProxyAddr(const char *ip) +{ + ASSERT(m); + + wifi_ap_h ap; + + if (wifi_get_connected_ap(&ap) != WIFI_ERROR_NONE) { + _ERR("wifi_get_connected_ap() failed."); + return false; + } + + if (wifi_ap_set_proxy_address(ap, WIFI_ADDRESS_FAMILY_IPV4, ip) != WIFI_ERROR_NONE) { + _ERR("wifi_ap_set_proxy_address() failed."); + return false; + } + + return true; +} + + +bool CWifiMgr::GetProxyAddr(char **ip) +{ + ASSERT(m); + wifi_ap_h ap; + + if (!ip || !*ip) { + _ERR("parameter is invalid."); + return false; + } + + if (wifi_get_connected_ap(&ap) != WIFI_ERROR_NONE) { + _ERR("wifi_get_connected_ap() failed."); + return false; + } + + if (wifi_ap_get_proxy_address(ap, WIFI_ADDRESS_FAMILY_IPV4, ip) != WIFI_ERROR_NONE) { + _ERR("wifi_ap_get_proxy_address() failed."); + return false; + } + + return true; +} + + +bool CWifiMgr::GetESSID(wifi_ap_h ap, char *essid) +{ + ASSERT(m); + ASSERT(ap); + + char *str; + str = NULL; + if (wifi_ap_get_essid(ap, &str) == WIFI_ERROR_NONE) { + strncpy(essid, str, 255); + _DBG("str : %s , ESSID : %s", str, essid); + delete (str); + str = NULL; + } else { + _ERR("Fail to get ESSID"); + return false; + } + + return true; +} + + +bool CWifiMgr::GetConnectionState(wifi_ap_h ap, wifi_connection_state_e *state) +{ + ASSERT(m); + ASSERT(ap); + + if (wifi_ap_get_connection_state(ap, state) != WIFI_ERROR_NONE) { + _ERR("Fail to get Connection State"); + return false; + } + + return true; +} + + +bool CWifiMgr::GetSecurityType(wifi_ap_h ap, wifi_security_type_e *type) +{ + ASSERT(m); + ASSERT(ap); + + if (wifi_ap_get_security_type(ap, type) != WIFI_ERROR_NONE) { + _ERR("Fail to get Security type"); + return false; + } + + return true; +} + + +bool CWifiMgr::ForgetAP(void) +{ + int ret; + wifi_ap_h ap; + char *name; + + ret = wifi_get_connected_ap(&ap); + if (ret == WIFI_ERROR_NO_CONNECTION) { + return true; + } else if (ret != WIFI_ERROR_NONE) { + _ERR("Fail to get connected AP [%s]", GetErrorMsg((wifi_error_e) ret)); + return false; + } + + ret = wifi_ap_get_essid(ap, &name); + if (ret != WIFI_ERROR_NONE) { + _ERR("Fail to wifi_ap_get_essid AP [%s]", GetErrorMsg((wifi_error_e) ret)); + wifi_ap_destroy(ap); + return false; + } + + ret = wifi_forget_ap(ap); + if (ret != WIFI_ERROR_NONE) { + _ERR("Fail to forget [%s],[%s].", name, GetErrorMsg((wifi_error_e) ret)); + wifi_ap_destroy(ap); + delete (name); + return false; + } + + delete (name); + + return true; +} + + +bool CWifiMgr::SetPassPhrase(wifi_ap_h ap, const char *passcode) +{ + int ret; + + if (!ap || !passcode) { + _ERR("the param is invalid."); + return false; + } + + ret = wifi_ap_set_passphrase(ap, passcode); + if (ret != WIFI_ERROR_NONE) { + _ERR("failed to set passcode. ret: %s.", GetErrorMsg((wifi_error_e) ret)); + return false; + } + + return true; +} + + +bool CWifiMgr::Connect(wifi_ap_h ap, void(*wifi_connected_cb)(wifi_error_e err, void *data), void *data) +{ + int ret; + + if (!wifi_connected_cb || !ap) { + _ERR("the param is invalid."); + return false; + } + + ret = wifi_connect(ap, wifi_connected_cb, data); + if (ret != WIFI_ERROR_NONE) { + _ERR("failed to connect ap. ret: %s.", GetErrorMsg((wifi_error_e) ret)); + return false; + } + + return true; +} + + +bool CWifiMgr::SetIpType(wifi_ap_h ap, wifi_ip_config_type_e type) +{ + int ret; + + if (!ap) { + _ERR("the param is invalid."); + return false; + } + + ret = wifi_ap_set_ip_config_type(ap, WIFI_ADDRESS_FAMILY_IPV4, type); + if (ret != WIFI_ERROR_NONE) { + _ERR("failed to connect ap. ret: %s.", GetErrorMsg((wifi_error_e) ret)); + return false; + } + + return true; +} + + +bool CWifiMgr::GetIp(wifi_ap_h ap, char *ip) +{ + ASSERT(ap); + + char *str_value; + + str_value = NULL; + if (wifi_ap_get_ip_address(ap, WIFI_ADDRESS_FAMILY_IPV4, &str_value) == WIFI_ERROR_NONE) { + strncpy(ip, str_value, IP_STRING_MAX_SIZE); + delete (str_value); + return true; + } else { + strncpy(ip, ZERO_IP, IP_STRING_MAX_SIZE); + _ERR("Fail to get Gateway"); + return false; + } +} + + +bool CWifiMgr::GetSubnetMask(wifi_ap_h ap, char *submask) +{ + ASSERT(ap); + + char *str_value; + + str_value = NULL; + if (wifi_ap_get_subnet_mask(ap, WIFI_ADDRESS_FAMILY_IPV4, &str_value) == WIFI_ERROR_NONE) { + strncpy(submask, str_value, IP_STRING_MAX_SIZE); + delete (str_value); + return true; + } else { + strncpy(submask, ZERO_IP, IP_STRING_MAX_SIZE); + _ERR("Fail to get Gateway"); + return false; + } +} + + +bool CWifiMgr::GetGateway(wifi_ap_h ap, char *gateway) +{ + ASSERT(ap); + + char *str_value; + + str_value = NULL; + if (wifi_ap_get_gateway_address(ap, WIFI_ADDRESS_FAMILY_IPV4, &str_value) == WIFI_ERROR_NONE) { + strncpy(gateway, str_value, IP_STRING_MAX_SIZE); + delete (str_value); + return true; + } else { + strncpy(gateway, ZERO_IP, IP_STRING_MAX_SIZE); + _ERR("Fail to get Gateway"); + return false; + } +} + + +bool CWifiMgr::GetDNS(wifi_ap_h ap, char *dns) +{ + ASSERT(ap); + + char *str_value; + + str_value = NULL; + if (wifi_ap_get_dns_address(ap, 1, WIFI_ADDRESS_FAMILY_IPV4, &str_value) == WIFI_ERROR_NONE) { + strncpy(dns, str_value, IP_STRING_MAX_SIZE); + delete (str_value); + return true; + } else { + strncpy(dns, ZERO_IP, IP_STRING_MAX_SIZE); + _ERR("Fail to get DNS1"); + return false; + } +} + +bool CWifiMgr::SetIp(wifi_ap_h ap, char *ip) +{ + ASSERT(ap); + + int ret; + + ret = wifi_ap_set_ip_address(ap, WIFI_ADDRESS_FAMILY_IPV4, ip); + if (ret != WIFI_ERROR_NONE) { + _ERR("Fail to set ip address[%s]", GetErrorMsg((wifi_error_e) ret)); + return false; + } + + return true; +} + + +bool CWifiMgr::SetSubnetMask(wifi_ap_h ap, char *submask) +{ + ASSERT(ap); + + int ret; + + ret = wifi_ap_set_subnet_mask(ap, WIFI_ADDRESS_FAMILY_IPV4, submask); + if (ret != WIFI_ERROR_NONE) { + _ERR("Fail to set subnet mask[%s]", GetErrorMsg((wifi_error_e) ret)); + return false; + } + + return true; +} + + +bool CWifiMgr::SetGateway(wifi_ap_h ap, char *gateway) +{ + ASSERT(ap); + + int ret; + + ret = wifi_ap_set_gateway_address(ap, WIFI_ADDRESS_FAMILY_IPV4, gateway); + if (ret != WIFI_ERROR_NONE) { + _ERR("Fail to set gateway address[%s]", GetErrorMsg((wifi_error_e) ret)); + return false; + } + + return true; +} + + +bool CWifiMgr::SetDNS(wifi_ap_h ap, char *dns) +{ + ASSERT(ap); + + int ret; + + ret = wifi_ap_set_dns_address(ap, 1, WIFI_ADDRESS_FAMILY_IPV4, dns); + if (ret != WIFI_ERROR_NONE) { + _ERR("Fail to set dns address[%s]", GetErrorMsg((wifi_error_e) ret)); + return false; + } + + return true; +} + + +const char * CWifiMgr::GetErrorMsg(wifi_error_e err_type) +{ + switch (err_type) { + case WIFI_ERROR_NONE: + return "NONE"; + case WIFI_ERROR_INVALID_PARAMETER: + return "INVALID_PARAMETER"; + case WIFI_ERROR_OUT_OF_MEMORY: + return "OUT_OF_MEMORY"; + case WIFI_ERROR_INVALID_OPERATION: + return "INVALID_OPERATION"; + case WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED: + return "ADDRESS_FAMILY_NOT_SUPPORTED"; + case WIFI_ERROR_OPERATION_FAILED: + return "OPERATION_FAILED"; + case WIFI_ERROR_NO_CONNECTION: + return "NO_CONNECTION"; + case WIFI_ERROR_NOW_IN_PROGRESS: + return "NOW_IN_PROGRESS"; + case WIFI_ERROR_ALREADY_EXISTS: + return "ALREADY_EXISTS"; + case WIFI_ERROR_OPERATION_ABORTED: + return "OPERATION_ABORTED"; + case WIFI_ERROR_DHCP_FAILED: + return "DHCP_FAILED"; + case WIFI_ERROR_INVALID_KEY: + return "INVALID_KEY"; + case WIFI_ERROR_NO_REPLY: + return "NO_REPLY"; + case WIFI_ERROR_SECURITY_RESTRICTED: + return "SECURITY_RESTRICTED"; + default: + break; + } + + return "UNKNOWN"; +} diff --git a/ug/system/clock/CMakeLists.txt b/ug/system/clock/CMakeLists.txt index 24e9640..c83eebd 100755 --- a/ug/system/clock/CMakeLists.txt +++ b/ug/system/clock/CMakeLists.txt @@ -21,10 +21,8 @@ SET(UG_CLOCK_EDJ_THEME "ug_clock_theme.edj") INCLUDE(FindPkgConfig) pkg_check_modules(UG_CLOCK_PKGS REQUIRED - dlog eina edje - ecore-x evas elementary aul @@ -49,6 +47,7 @@ SET(SRCS ) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../include) ADD_DEFINITIONS("-DUG_CLOCK_EDJFILE=\"${UG_CLOCK_EDJE_DIR}/${UG_CLOCK_EDJ_FILE}\"") ADD_DEFINITIONS("-DUG_CLOCK_EDJTHEME=\"${UG_CLOCK_EDJE_DIR}/${UG_CLOCK_EDJ_THEME}\"") diff --git a/ug/system/clock/include/dbg.h b/ug/system/clock/include/dbg.h deleted file mode 100755 index a2ff87a..0000000 --- a/ug/system/clock/include/dbg.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __DBG_H__ - -#include - -#ifndef _ERR -#define _ERR(fmt, args...) LOGE("[%s:%d] "fmt"\n", __func__, __LINE__, ##args) -#endif - -#ifndef _DBG -#define _DBG(fmt, args...) LOGD("[%s:%d] "fmt"\n", __func__, __LINE__, ##args) -#endif - -#ifndef _INFO -#define _INFO(fmt, args...) LOGI("[%s:%d] "fmt"\n", __func__, __LINE__, ##args) -#endif - -#endif /* __DBG_H__ */ diff --git a/ug/wifi-direct/CMakeLists.txt b/ug/wifi-direct/CMakeLists.txt index 70d7899..c36b456 100644 --- a/ug/wifi-direct/CMakeLists.txt +++ b/ug/wifi-direct/CMakeLists.txt @@ -25,10 +25,8 @@ SET(UG_WIFI_DIRECT_EDJ_THEME "ug-wifi-direct-theme.edj") INCLUDE(FindPkgConfig) pkg_check_modules(UG_WIFI_DIRECT_PKGS REQUIRED - dlog eina edje - ecore-x evas elementary aul @@ -56,6 +54,8 @@ SET(SRCS ) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../include) + ADD_DEFINITIONS("-DPKGNAME=\"${PROJECT_NAME}\"") ADD_DEFINITIONS("-DUG_WIFI_DIRECT_EDJ_FILE=\"${UG_WIFI_DIRECT_EDJE_DIR}/${UG_WIFI_DIRECT_EDJ_FILE}\"") diff --git a/ug/wifi-direct/include/dbg.h b/ug/wifi-direct/include/dbg.h deleted file mode 100644 index 0e63b49..0000000 --- a/ug/wifi-direct/include/dbg.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __DBG_H__ - -#include - -#ifdef LOG_TAG -#undef LOG_TAG -#endif -#define LOG_TAG "ug-wifi-direct" - -#ifndef _ERR -#define _ERR(fmt, args...) LOGE("[%s:%d] "fmt"\n", __func__, __LINE__, ##args) -#endif - -#ifndef _DBG -#define _DBG(fmt, args...) LOGD("[%s:%d] "fmt"\n", __func__, __LINE__, ##args) -#endif - -#ifndef _INFO -#define _INFO(fmt, args...) LOGI("[%s:%d] "fmt"\n", __func__, __LINE__, ##args) -#endif - -#endif /* __DBG_H__ */ diff --git a/ug/wifi-direct/include/util.h b/ug/wifi-direct/include/util.h index 1de093a..871e775 100644 --- a/ug/wifi-direct/include/util.h +++ b/ug/wifi-direct/include/util.h @@ -17,13 +17,10 @@ #ifndef __UTIL_H__ #define __UTIL_H__ -Evas_Object *util_add_layout(Evas_Object *parent, const char *file, - const char *group); -Evas_Object *util_add_button(Evas_Object *parent, const char *style, - const char *part, const char *text); +Evas_Object *util_add_layout(Evas_Object *parent, const char *file, const char *group); +Evas_Object *util_add_button(Evas_Object *parent, const char *style, const char *part, const char *text); Evas_Object *util_add_box(Evas_Object *parent, const char *part); -Evas_Object *util_add_progressbar(Evas_Object *parent, - const char *style, const char *part); +Evas_Object *util_add_progressbar(Evas_Object *parent, const char *style, const char *part); void util_set_cycle_focus(Evas_Object **obj, int count); #endif /* __UTIL_H__ */ -- 2.7.4 From ecaaa655ef2cb800216c1f7d23493905862fe70a Mon Sep 17 00:00:00 2001 From: JuWan Kim Date: Thu, 19 Mar 2015 14:11:54 +0900 Subject: [PATCH 06/16] Add NetConMgr and remove connection_mgr.cpp and remove vconf_mgr.cpp Change-Id: Ied6f6520916e7b2720ac39ec5abbce26097044ee Signed-off-by: JuWan Kim --- ug/include/NetConMgr.h | 28 +++ ug/include/WifiMgr.h | 10 +- ug/network/include/connection_mgr.h | 14 +- ug/network/src/main_view.cpp | 8 +- ug/proxy/CMakeLists.txt | 3 +- ug/proxy/include/connection_mgr.h | 32 ---- ug/proxy/include/vconf_mgr.h | 28 --- ug/proxy/src/connection_mgr.cpp | 369 ------------------------------------ ug/proxy/src/main_view.cpp | 102 ++++------ ug/proxy/src/vconf_mgr.cpp | 111 ----------- ug/src/NetConMgr.cpp | 288 ++++++++++++++++++++++++++++ ug/src/WifiMgr.cpp | 4 +- 12 files changed, 368 insertions(+), 629 deletions(-) create mode 100644 ug/include/NetConMgr.h delete mode 100644 ug/proxy/include/connection_mgr.h delete mode 100644 ug/proxy/include/vconf_mgr.h delete mode 100644 ug/proxy/src/connection_mgr.cpp delete mode 100644 ug/proxy/src/vconf_mgr.cpp create mode 100644 ug/src/NetConMgr.cpp diff --git a/ug/include/NetConMgr.h b/ug/include/NetConMgr.h new file mode 100644 index 0000000..3a17e42 --- /dev/null +++ b/ug/include/NetConMgr.h @@ -0,0 +1,28 @@ +#ifndef __NETCONMGR_H__ +#define __NETCONMGR_H__ + +#include "UgCommon.h" +#include "net_connection.h" + +class CNetConMgr { +private: + static CNetConMgr *instance; + struct SNetConMgr *m; +private: + CNetConMgr(void) : m(0) {} + virtual ~CNetConMgr() {} + +public: + static bool Initialize(void); + static void Finalize(void); + static CNetConMgr *GetInstance(void); + + bool GetProfileInfo(connection_profile_h out_profile); + bool SetProxyType(EProxyMethod method); + bool GetProxyType(EProxyMethod *method); + bool SetProxyAddr(char *ip); + bool GetProxyAddr(char *ip); + const char *GetErrorMsg(connection_error_e err); +}; + +#endif /* __NETCONMGR_H__ */ diff --git a/ug/include/WifiMgr.h b/ug/include/WifiMgr.h index 6e710df..3a1fa1d 100644 --- a/ug/include/WifiMgr.h +++ b/ug/include/WifiMgr.h @@ -6,12 +6,14 @@ class CWifiMgr { private: - static CWifiMgr* instance; + static CWifiMgr *instance; struct SWifiMgr *m; -public: + +private: CWifiMgr(void) : m(0) {} virtual ~CWifiMgr() {} +public: static bool Initialize(void); static void Finalize(void); static CWifiMgr * GetInstance(void); @@ -27,8 +29,8 @@ public: bool RegisterScanCallback(void(*ScanFinishedCb)(wifi_error_e err, void *data), void *data); bool RegisterFoundAPCallback(bool(*FoundCb)(wifi_ap_h ap, void *data), void *data); - bool SetProxyType(enum EProxyMethod pm); - bool GetProxyType(enum EProxyMethod *pm); + bool SetProxyType(EProxyMethod pm); + bool GetProxyType(EProxyMethod *pm); bool SetProxyAddr(const char *ip); bool GetProxyAddr(char **ip); bool GetESSID(wifi_ap_h ap, char *essid); diff --git a/ug/network/include/connection_mgr.h b/ug/network/include/connection_mgr.h index 8967901..32a9751 100644 --- a/ug/network/include/connection_mgr.h +++ b/ug/network/include/connection_mgr.h @@ -28,17 +28,11 @@ int connection_mgr_set_profile( connection_h connection_mgr_create(void); int connection_mgr_destroy(connection_h connection); int connection_mgr_uninit(connection_h connection); -int connection_mgr_get_profile_info( - connection_h connection, struct connection_info *info); +int connection_mgr_get_profile_info(connection_h connection, struct connection_info *info); Eina_Bool connection_mgr_is_connected(connection_h connection); -int connection_mgr_ip_dynamic_config(connection_h connection, - connection_profile_h profile); -int connection_mgr_get_ethernet_state( - connection_h connection, - Eina_Bool *plugin); -int connection_mgr_get_ip_info( - connection_profile_h profile, - struct network_info *info); +int connection_mgr_ip_dynamic_config(connection_h connection,connection_profile_h profile); +int connection_mgr_get_ethernet_state(connection_h connection,Eina_Bool *plugin); +int connection_mgr_get_ip_info(connection_profile_h profile,struct network_info *info); #if 0 int connection_mgr_register_ethernet_state_cb( connection_h connection, diff --git a/ug/network/src/main_view.cpp b/ug/network/src/main_view.cpp index f137381..4effc56 100644 --- a/ug/network/src/main_view.cpp +++ b/ug/network/src/main_view.cpp @@ -155,10 +155,10 @@ static void _fini_priv(struct _priv *priv) free(priv->ap_name); free(priv->ap_pwd); - CWifiMgr::Finalize(); - - delete (priv->pWifiMgr); - priv->pWifiMgr = NULL; + if(priv->pWifiMgr) { + CWifiMgr::Finalize(); + priv->pWifiMgr = NULL; + } free(priv); } diff --git a/ug/proxy/CMakeLists.txt b/ug/proxy/CMakeLists.txt index 2158e83..a5cc8f9 100644 --- a/ug/proxy/CMakeLists.txt +++ b/ug/proxy/CMakeLists.txt @@ -47,10 +47,9 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") SET(SRCS src/ug_proxy_settings.cpp src/main_view.cpp - src/vconf_mgr.cpp - src/connection_mgr.cpp src/util.cpp ../src/WifiMgr.cpp + ../src/NetConMgr.cpp ) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) diff --git a/ug/proxy/include/connection_mgr.h b/ug/proxy/include/connection_mgr.h deleted file mode 100644 index 57dfc77..0000000 --- a/ug/proxy/include/connection_mgr.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __CONNECTION_MGR_H__ -#define __CONNECTION_MGR_H__ - -#include -#include -#include "UgCommon.h" - -connection_h connection_mgr_create(void); -int connection_mgr_destroy(connection_h connection); -int connection_mgr_get_profile_info(connection_h connection, connection_profile_h *out_proflie); -int connection_mgr_set_proxy_type(connection_h connection, enum EProxyMethod method); -int connection_mgr_get_proxy_type(connection_h connection, enum EProxyMethod *method); -int connection_mgr_set_proxy_address(connection_h connection, const char *ip); -int connection_mgr_get_proxy_address(connection_h connection, char **ip); - -#endif /* __CONNECTION_MGR_H__ */ diff --git a/ug/proxy/include/vconf_mgr.h b/ug/proxy/include/vconf_mgr.h deleted file mode 100644 index 363a73a..0000000 --- a/ug/proxy/include/vconf_mgr.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __VCONF_MGR_H__ -#define __VCONF_MGR_H__ - -#include -#include "common.h" - -char *vconf_mgr_get_string_value(const char *key); -int vconf_mgr_set_string_value(const char *key, const char *value); -int vconf_mgr_get_int_value(const char *key, int *value); -int vconf_mgr_set_int_value(const char *key, const int value); - -#endif /* __VCONF_MGR_H__ */ diff --git a/ug/proxy/src/connection_mgr.cpp b/ug/proxy/src/connection_mgr.cpp deleted file mode 100644 index f61cc22..0000000 --- a/ug/proxy/src/connection_mgr.cpp +++ /dev/null @@ -1,369 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "defs.h" -#include "dbg.h" -#include "connection_mgr.h" - -/** - * Converts the error type to string information. - * - * @param[in] err_type Error type - * @return error string information; - */ -static const char *_convert_error_to_string(connection_error_e err_type) -{ - _DBG("Not Yet"); -#if 0 - switch (err_type) { - case CONNECTION_ERROR_NONE: - return "NONE"; - case CONNECTION_ERROR_INVALID_PARAMETER: - return "INVALID_PARAMETER"; - case CONNECTION_ERROR_OUT_OF_MEMORY: - return "OUT_OF_MEMORY"; - case CONNECTION_ERROR_INVALID_OPERATION: - return "INVALID_OPERATION"; - case CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED: - return "ADDRESS_FAMILY_NOT_SUPPORTED"; - case CONNECTION_ERROR_OPERATION_FAILED: - return "OPERATION_FAILED"; - case CONNECTION_ERROR_ITERATOR_END: - return "ITERATOR_END"; - case CONNECTION_ERROR_NO_CONNECTION: - return "NO_CONNECTION"; - case CONNECTION_ERROR_NOW_IN_PROGRESS: - return "NOW_IN_PROGRESS"; - case CONNECTION_ERROR_ALREADY_EXISTS: - return "ALREADY_EXISTS"; - case CONNECTION_ERROR_OPERATION_ABORTED: - return "OPERATION_ABORTED"; - case CONNECTION_ERROR_DHCP_FAILED: - return "DHCP_FAILED"; - case CONNECTION_ERROR_INVALID_KEY: - return "INVALID_KEY"; - case CONNECTION_ERROR_NO_REPLY: - return "NO_REPLY"; - case CONNECTION_ERROR_NO_KEYWORD: - return "NO_KEYWORD"; - case CONNECTION_ERROR_TCP_RST: - return "RST_IN_TCP_RESPONSE"; - case CONNECTION_ERROR_TCP_SYN_TIMEOUT: - return "TCP_SYN_TIMEOUT"; - case CONNECTION_ERROR_OFFLINE: - return "CONNECTION_OFFLINE"; - case CONNECTION_ERROR_NETWORK_MONITOR_FAILURE: - return "monitor failer"; - case CONNECTION_ERROR_INVALID_GATEWAY: - return "invalid gateway"; - case CONNECTION_ERROR_INVALID_MACADDRESS: - return "invalid mac addr"; - default: - break; - } - -#endif - return "Unknown"; -} - -/** - * Creates a handle for managing data connections. - * - * The handle must be released with connection_destroy(). - * - * @return connetcion if the operation is successful; NULL if failed; - */ -connection_h connection_mgr_create(void) -{ - int ret; - connection_h connection; - - connection = NULL; - ret = connection_create(&connection); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("connection_create failed"); - connection = NULL; - } - - return connection; -} - -/** - * Destroys the connection handle. - * - * @param[in] connection The handle of the connection - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int connection_mgr_destroy(connection_h connection) -{ - int ret; - - if (!connection) { - _ERR("connection is NULL."); - return RET_FAILED; - } - - ret = connection_destroy(connection); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("connection_destroy() failed."); - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Gets the ethernet profile information. - * - * Iterates all the profile in the connection, and gets the ethernet one. - * - * @param[in] connection The handle of the connection - * @param[out] info The structure to store profile information - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int connection_mgr_get_profile_info(connection_h connection, - connection_profile_h *out_profile) -{ - connection_profile_iterator_h iter; - connection_profile_h profile; - connection_profile_type_e type; - char *name; - int ret; - - if (!connection || !out_profile) { - _ERR("param is NULL."); - return RET_FAILED; - } - - ret = connection_get_profile_iterator(connection, - CONNECTION_ITERATOR_TYPE_REGISTERED, &iter); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("Fail to get profile iterator: %s.\n", - _convert_error_to_string((connection_error_e) ret)); - return RET_FAILED; - } - - while (connection_profile_iterator_has_next(iter)) { - profile = NULL; - if (connection_profile_iterator_next(iter, - &profile) != CONNECTION_ERROR_NONE) { - _ERR("Fail to get profile handle\n"); - return RET_FAILED; - } - - if (!profile) { - _ERR("get profile failed."); - return RET_FAILED; - } - - if (connection_profile_get_type(profile, - &type) != CONNECTION_ERROR_NONE) { - _ERR("Fail to get profile type\n"); - return RET_FAILED; - } - - name = NULL; - if (connection_profile_get_name(profile, - &name) != CONNECTION_ERROR_NONE) { - _ERR("Fail to get profile name\n"); - return RET_FAILED; - } - - if (!name) { - _ERR("get name failed."); - return RET_FAILED; - } - - if (type == CONNECTION_PROFILE_TYPE_ETHERNET) - *out_profile = profile; - - free(name); - } - - return RET_SUCCESS; -} - -/** - * Sets the Proxy type. - * - * If you set Proxy type to #WIFI_PROXY_TYPE_AUTO or - * #WIFI_PROXY_TYPE_MANUAL, then Proxy will be restored. - * - * @param[in] connection The handle of the connection - * @param[in] method The proxy type - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int connection_mgr_set_proxy_type(connection_h connection, - enum EProxyMethod method) -{ - connection_profile_h profile; - connection_proxy_type_e type; - int ret; - - if (!connection) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - profile = NULL; - ret = connection_mgr_get_profile_info(connection, &profile); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("connection_mgr_get_profile_info() failed.\n"); - return RET_FAILED; - } - - switch (method) { - case PROXY_METHOD_NONE: - type = CONNECTION_PROXY_TYPE_DIRECT; - break; - case PROXY_METHOD_MANUAL: - type = CONNECTION_PROXY_TYPE_MANUAL; - break; - case PROXY_METHOD_AUTO: - type = CONNECTION_PROXY_TYPE_AUTO; - break; - default: - return RET_FAILED; - } - - ret = connection_profile_set_proxy_type(profile, type); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("connection_profile_set_proxy_type() failed.\n"); - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Gets the Proxy type. - * - * @param[in] connection The handle of the connection - * @param[out] method The proxy type - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int connection_mgr_get_proxy_type(connection_h connection, - enum EProxyMethod *method) -{ - connection_profile_h profile; - connection_proxy_type_e type; - int ret; - - if (!connection || !method) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - profile = NULL; - ret = connection_mgr_get_profile_info(connection, &profile); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("connection_mgr_get_profile_info() failed.\n"); - return RET_FAILED; - } - - ret = connection_profile_get_proxy_type(profile, &type); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("connection_profile_get_proxy_type() failed.\n"); - return RET_FAILED; - } - - switch (type) { - case CONNECTION_PROXY_TYPE_DIRECT: - *method = PROXY_METHOD_NONE; - break; - case CONNECTION_PROXY_TYPE_MANUAL: - *method = PROXY_METHOD_MANUAL; - break; - case CONNECTION_PROXY_TYPE_AUTO: - *method = PROXY_METHOD_AUTO; - break; - default: - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Sets the Proxy address. - * - * @param[in] connection The handle of the connection - * @param[in] ip IP address - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int connection_mgr_set_proxy_address(connection_h connection, - const char *ip) -{ - connection_profile_h profile; - int ret; - - if (!connection) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - profile = NULL; - ret = connection_mgr_get_profile_info(connection, &profile); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("connection_mgr_get_profile_info() failed.\n"); - return RET_FAILED; - } - - ret = connection_profile_set_proxy_address(profile, - CONNECTION_ADDRESS_FAMILY_IPV4, ip); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("connection_profile_set_proxy_address() failed.\n"); - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Gets the Proxy address. - * - * @param[in] connection The handle of the connection - * @param[out] ip IP address - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int connection_mgr_get_proxy_address(connection_h connection, char **ip) -{ - connection_profile_h profile; - int ret; - - if (!connection || !ip || !*ip) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - profile = NULL; - ret = connection_mgr_get_profile_info(connection, &profile); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("connection_mgr_get_profile_info() failed.\n"); - return RET_FAILED; - } - - ret = connection_profile_get_proxy_address(profile, - CONNECTION_ADDRESS_FAMILY_IPV4, ip); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("connection_profile_get_proxy_address() failed.\n"); - return RET_FAILED; - } - - return RET_SUCCESS; -} diff --git a/ug/proxy/src/main_view.cpp b/ug/proxy/src/main_view.cpp index a69271f..6db110d 100644 --- a/ug/proxy/src/main_view.cpp +++ b/ug/proxy/src/main_view.cpp @@ -16,18 +16,17 @@ #include #include +#include #include "defs.h" #include "dbg.h" #include "main_view.h" -#include "vconf_mgr.h" -#include "connection_mgr.h" #include "i18n.h" #include "util.h" #include "common.h" #include "UgCommon.h" #include "WifiMgr.h" - +#include "NetConMgr.h" #define KEY_PRIV "priv" #define KEY_PROXY_ENTER "Select" @@ -80,13 +79,13 @@ struct _priv { enum network_type_enum net_type; - connection_h connection; - char ip[IP_STRING_LEN + 1]; char url[MOTHED_URL_LEN + 1]; CWifiMgr *pWifiMgr; enum EProxyMethod eMethod; + + CNetConMgr *pNetConMgr; }; static int _create_method_none_btn(struct _priv *priv); @@ -94,47 +93,6 @@ static int _create_method_manual_btns(struct _priv *priv); static int _create_method_auto_btns(struct _priv *priv); /** - * Initializes connection for wired network. - * - * @param[in] priv The handler of the private data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -static int _init_connection(struct _priv *priv) -{ - if (!priv) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - priv->connection = connection_mgr_create(); - if (!priv->connection) { - _ERR("connection_mgr_create() failed."); - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Deinitializes connection for wired network. - * - * @param[in] priv The handler of the private data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -static int _fini_connection(struct _priv *priv) -{ - if (!priv) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - if (priv->connection) - connection_mgr_destroy(priv->connection); - - return RET_SUCCESS; -} - -/** * Initializes the private data. * * Called when the view is loaded. @@ -164,7 +122,19 @@ static struct _priv *_init_priv() return NULL; } - _init_connection(priv); + ret = CNetConMgr::Initialize(); + if(ret != true) { + _ERR("Fail to initialize NetConMgr"); + return NULL; + } + + priv->pNetConMgr = CNetConMgr::GetInstance(); + if(!priv->pNetConMgr) { + _ERR("Fail to get instance"); + CWifiMgr::Finalize(); + free (priv); + return NULL; + } return priv; } @@ -181,8 +151,10 @@ static void _fini_priv(struct _priv *priv) if (!priv) return; - //_fini_wifi(priv); - _fini_connection(priv); + if(priv->pNetConMgr) { + CNetConMgr::Finalize(); + priv->pNetConMgr = NULL; + } if(priv->pWifiMgr) { CWifiMgr::Finalize(); @@ -394,7 +366,7 @@ static void _get_man_saved_value(char *des_ip, return; } - ip = vconf_mgr_get_string_value(key_ip); + ip = vconf_get_str(key_ip); if (!ip) snprintf(des_ip, IP_STRING_LEN, "%s", IP_ZERO); else @@ -418,16 +390,16 @@ static int _get_proxy_method(struct _priv *priv) return RET_FAILED; } - str = vconf_mgr_get_string_value(VCONF_NETWORK_TYPE); + str = vconf_get_str(VCONF_NETWORK_TYPE); if (str && !strcmp(str, TXT_WIRED)) priv->net_type = TYPE_WIRED; else priv->net_type = TYPE_WIRELESS; value = 0; - ret = vconf_mgr_get_int_value(VCONF_PROXY_METHOD, &value); + ret = vconf_get_int(VCONF_PROXY_METHOD, &value); if (ret != RET_SUCCESS) { - _ERR("vconf_mgr_get_int_value() failed."); + _ERR("vconf_get_int() failed."); return RET_FAILED; } @@ -447,7 +419,7 @@ static int _get_proxy_method(struct _priv *priv) _get_man_saved_value(priv->ip, VCONF_PROXY_IP); - str = vconf_mgr_get_string_value(VCONF_PROXY_URL); + str = vconf_get_str(VCONF_PROXY_URL); if (!str) snprintf(priv->url, MOTHED_URL_LEN, "%s", URL_BLANK); else @@ -1669,7 +1641,7 @@ static int _save_to_vconf(struct _priv *priv) return RET_SUCCESS; } - vconf_mgr_set_int_value(VCONF_PROXY_METHOD, priv->eMethod); + vconf_set_int(VCONF_PROXY_METHOD, priv->eMethod); switch (priv->eMethod) { case PROXY_METHOD_NONE: @@ -1677,11 +1649,11 @@ static int _save_to_vconf(struct _priv *priv) case PROXY_METHOD_MANUAL: _check_ip_is_valid(priv); - vconf_mgr_set_string_value(VCONF_PROXY_IP, priv->ip); + vconf_set_str(VCONF_PROXY_IP, priv->ip); break; case PROXY_METHOD_AUTO: - vconf_mgr_set_string_value(VCONF_PROXY_URL, priv->url); + vconf_set_str(VCONF_PROXY_URL, priv->url); break; default: @@ -1699,33 +1671,29 @@ static int _save_to_vconf(struct _priv *priv) */ static int _set_connection_proxy(struct _priv *priv) { - int ret; + bool ret; if (!priv) { _ERR("The param is invalid.\n"); return RET_FAILED; } - ret = connection_mgr_set_proxy_type(priv->connection, priv->eMethod); - if (ret != RET_SUCCESS) { + ret = priv->pNetConMgr->SetProxyType(priv->eMethod); + if (ret != true) { _ERR("wifi_mgr_get_proxy_type() failed."); - return ret; + return RET_FAILED; } switch (priv->eMethod) { case PROXY_METHOD_NONE: - connection_mgr_set_proxy_address(priv->connection, - NULL); break; case PROXY_METHOD_MANUAL: if (priv->ip) - connection_mgr_set_proxy_address(priv->connection, - priv->ip); + priv->pNetConMgr->SetProxyAddr(priv->ip); break; case PROXY_METHOD_AUTO: if (priv->url) - connection_mgr_set_proxy_address(priv->connection, - priv->url); + priv->pNetConMgr->SetProxyAddr(priv->url); break; default: return RET_FAILED; diff --git a/ug/proxy/src/vconf_mgr.cpp b/ug/proxy/src/vconf_mgr.cpp deleted file mode 100644 index d018549..0000000 --- a/ug/proxy/src/vconf_mgr.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "defs.h" -#include "dbg.h" -#include "vconf_mgr.h" -#include "i18n.h" - -/** - * Gets the string value from vconf. - * - * @param[in] key Vconf key - * @return the value in vconf; - */ -char *vconf_mgr_get_string_value(const char *key) -{ - if (!key) { - _ERR("the param is invalid."); - return NULL; - } - - return vconf_get_str(key); -} - -/** - * Sets the string value to vconf. - * - * @param[in] key Vconf key - * @param[in] value The value - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int vconf_mgr_set_string_value(const char *key, const char *value) -{ - int ret; - - if (!key || !value) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - ret = vconf_set_str(key, value); - if (ret != 0) { - _ERR("vconf set str failed."); - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Gets the integer value from vconf. - * - * @param[in] key Vconf key - * @param[out] value The value - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int vconf_mgr_get_int_value(const char *key, int *value) -{ - int ret; - - if (!key || !value) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - ret = vconf_get_int(key, value); - if (ret != 0) { - _ERR("vconf get int failed"); - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Sets the integer value to vconf. - * - * @param[in] key Vconf key - * @param[in] value The value - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int vconf_mgr_set_int_value(const char *key, const int value) -{ - int ret; - - if (!key) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - ret = vconf_set_int(key, value); - if (ret != 0) { - _ERR("vconf set int failed."); - return RET_FAILED; - } - - return RET_SUCCESS; -} diff --git a/ug/src/NetConMgr.cpp b/ug/src/NetConMgr.cpp new file mode 100644 index 0000000..68e96a3 --- /dev/null +++ b/ug/src/NetConMgr.cpp @@ -0,0 +1,288 @@ +#include "dbg.h" +#include "NetConMgr.h" + +CNetConMgr *CNetConMgr::instance = NULL; + +struct SNetConMgr { + connection_h handle; +}; + +bool CNetConMgr::Initialize(void) +{ + ASSERT(!instance); + + instance = new CNetConMgr; + if(!instance) { + _ERR("Fail to allocate memory"); + return false; + } + + instance->m = new SNetConMgr; + if(!instance->m) { + _ERR("Fail to allocate memory"); + delete (instance); + instance = NULL; + return false; + } + + int ret = 0; + ret = connection_create(&instance->m->handle); + if( ret != CONNECTION_ERROR_NONE) { + _ERR("Fail to create connection : error = %s", instance->GetErrorMsg((connection_error_e) ret)); + delete (instance->m); + delete (instance); + instance = NULL; + return false; + } + + return true; +} + + +void CNetConMgr::Finalize(void) +{ + ASSERT(instance); + ASSERT(instance->m); + + int ret = 0; + ret = connection_destroy(instance->m->handle); + if( ret != CONNECTION_ERROR_NONE) { + _ERR("Fail to destroy connection : error = %s", instance->GetErrorMsg((connection_error_e) ret)); + } + + delete (instance->m); + delete (instance); + instance = NULL; +} + + +CNetConMgr *CNetConMgr::GetInstance(void) +{ + return instance; +} + + +bool CNetConMgr::GetProfileInfo(connection_profile_h out_profile) +{ + ASSERT(m); + + connection_profile_iterator_h iter = NULL; + connection_profile_h profile = NULL; + connection_profile_type_e type; + + char *name; + int ret; + + if (!out_profile) { + _ERR("param is NULL."); + return false; + } + + ret = connection_get_profile_iterator(m->handle, CONNECTION_ITERATOR_TYPE_REGISTERED, &iter); + if (ret != CONNECTION_ERROR_NONE) { + _ERR("Fail to get profile iterator: %s", GetErrorMsg((connection_error_e) ret)); + return false; + } + + while (connection_profile_iterator_has_next(iter)) { + if (connection_profile_iterator_next(iter, &profile) != CONNECTION_ERROR_NONE) { + _ERR("Fail to get profile handle"); + return false; + } + + ASSERT(profile); /* weird */ + + if (connection_profile_get_type(profile, &type) != CONNECTION_ERROR_NONE) { + _ERR("Fail to get profile type"); + return false; + } + + if (type == CONNECTION_PROFILE_TYPE_ETHERNET) + out_profile = profile; + } + + /* TODO : should check when tere are many same profiles. */ + + return true; +} + + +bool CNetConMgr::SetProxyType(EProxyMethod method) +{ + ASSERT(m); + + connection_profile_h profile = NULL; + connection_proxy_type_e type; + + int ret; + + ret = GetProfileInfo(profile); + if (ret != CONNECTION_ERROR_NONE) { + _ERR("GetProfileInfo() failed"); + return false; + } + + switch (method) { + case PROXY_METHOD_NONE: + type = CONNECTION_PROXY_TYPE_DIRECT; + break; + case PROXY_METHOD_MANUAL: + type = CONNECTION_PROXY_TYPE_MANUAL; + break; + case PROXY_METHOD_AUTO: + type = CONNECTION_PROXY_TYPE_AUTO; + break; + default: + return false; + } + + ret = connection_profile_set_proxy_type(profile, type); + if (ret != CONNECTION_ERROR_NONE) { + _ERR("connection_profile_set_proxy_type() failed"); + return false; + } + + return true; +} + + +bool CNetConMgr::GetProxyType(EProxyMethod *method) +{ + ASSERT(m); + + connection_profile_h profile = NULL; + connection_proxy_type_e type; + + int ret; + + if (!method) { + _ERR("the param is invalid."); + return false; + } + + ret = GetProfileInfo(profile); + if (ret != CONNECTION_ERROR_NONE) { + _ERR("GetProfileInfo() failed"); + return false; + } + + ret = connection_profile_get_proxy_type(profile, &type); + if (ret != CONNECTION_ERROR_NONE) { + _ERR("connection_profile_get_proxy_type() failed"); + return false; + } + + switch (type) { + case CONNECTION_PROXY_TYPE_DIRECT: + *method = PROXY_METHOD_NONE; + break; + case CONNECTION_PROXY_TYPE_MANUAL: + *method = PROXY_METHOD_MANUAL; + break; + case CONNECTION_PROXY_TYPE_AUTO: + *method = PROXY_METHOD_AUTO; + break; + default: + return false; + } + + return true; +} + + +bool CNetConMgr::SetProxyAddr(char *ip) +{ + ASSERT(m); + + connection_profile_h profile; + int ret; + + profile = NULL; + ret = GetProfileInfo(profile); + if (ret != CONNECTION_ERROR_NONE) { + _ERR("GetProfileInfo() failed"); + return false; + } + + ret = connection_profile_set_proxy_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, ip); + if (ret != CONNECTION_ERROR_NONE) { + _ERR("connection_profile_set_proxy_address() failed"); + return false; + } + + return true; +} + + +bool CNetConMgr::GetProxyAddr(char *ip) +{ + ASSERT(m); + + connection_profile_h profile; + int ret; + char *str; + + if (!ip) { + _ERR("the param is invalid."); + return false; + } + + profile = NULL; + ret = GetProfileInfo(profile); + if (ret != CONNECTION_ERROR_NONE) { + _ERR("GetProfileInfo() failed"); + return false; + } + + ret = connection_profile_get_proxy_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &str); + if (ret != CONNECTION_ERROR_NONE) { + _ERR("connection_profile_get_proxy_address() failed"); + return false; + } + + /* FIXME : hardcoding */ + strncpy(ip, str, 20); + delete (str); + + return true; +} + + +const char *CNetConMgr::GetErrorMsg(connection_error_e err) +{ + switch (err) { + case CONNECTION_ERROR_NONE: + return "NONE"; + case CONNECTION_ERROR_INVALID_PARAMETER: + return "INVALID_PARAMETER"; + case CONNECTION_ERROR_OUT_OF_MEMORY: + return "OUT_OF_MEMORY"; + case CONNECTION_ERROR_INVALID_OPERATION: + return "INVALID_OPERATION"; + case CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED: + return "ADDRESS_FAMILY_NOT_SUPPORTED"; + case CONNECTION_ERROR_OPERATION_FAILED: + return "OPERATION_FAILED"; + case CONNECTION_ERROR_ITERATOR_END: + return "ITERATOR_END"; + case CONNECTION_ERROR_NO_CONNECTION: + return "NO_CONNECTION"; + case CONNECTION_ERROR_NOW_IN_PROGRESS: + return "NOW_IN_PROGRESS"; + case CONNECTION_ERROR_ALREADY_EXISTS: + return "ALREADY_EXISTS"; + case CONNECTION_ERROR_OPERATION_ABORTED: + return "OPERATION_ABORTED"; + case CONNECTION_ERROR_DHCP_FAILED: + return "DHCP_FAILED"; + case CONNECTION_ERROR_INVALID_KEY: + return "INVALID_KEY"; + case CONNECTION_ERROR_NO_REPLY: + return "NO_REPLY"; + default: + break; + } + + return "Unknown"; +} + diff --git a/ug/src/WifiMgr.cpp b/ug/src/WifiMgr.cpp index 7c993e3..3ae6ad6 100644 --- a/ug/src/WifiMgr.cpp +++ b/ug/src/WifiMgr.cpp @@ -188,7 +188,7 @@ bool CWifiMgr::RegisterFoundAPCallback(bool(*FoundCb)(wifi_ap_h ap, void *data), } -bool CWifiMgr::SetProxyType(enum EProxyMethod pm) +bool CWifiMgr::SetProxyType(EProxyMethod pm) { ASSERT(m); @@ -223,7 +223,7 @@ bool CWifiMgr::SetProxyType(enum EProxyMethod pm) } -bool CWifiMgr::GetProxyType(enum EProxyMethod *pm) +bool CWifiMgr::GetProxyType(EProxyMethod *pm) { ASSERT(m); -- 2.7.4 From 0632b687331e3085826d2b8a3373f563a0548d79 Mon Sep 17 00:00:00 2001 From: JuWan Kim Date: Fri, 20 Mar 2015 13:57:59 +0900 Subject: [PATCH 07/16] Update CNetConMgr and code clean Change-Id: Ib8d0e03a674fc5acc787d7a0adda49807163eca5 Signed-off-by: JuWan Kim --- log.txt | 211 ------------ ug/include/NetConMgr.h | 31 +- ug/network/CMakeLists.txt | 2 +- ug/network/include/common.h | 3 - ug/network/include/connection_mgr.h | 51 --- ug/network/include/main_view.h | 5 - ug/network/include/vconf_mgr.h | 1 - ug/network/src/connection_mgr.cpp | 650 ------------------------------------ ug/network/src/ip_setting_view.cpp | 52 ++- ug/network/src/main_view.cpp | 149 +++------ ug/proxy/include/common.h | 29 -- ug/proxy/include/defs.h | 10 + ug/proxy/include/main_view.h | 2 - ug/proxy/src/main_view.cpp | 1 - ug/src/NetConMgr.cpp | 442 ++++++++++++++++++++---- 15 files changed, 507 insertions(+), 1132 deletions(-) delete mode 100644 log.txt delete mode 100644 ug/network/include/connection_mgr.h delete mode 100644 ug/network/src/connection_mgr.cpp delete mode 100644 ug/proxy/include/common.h diff --git a/log.txt b/log.txt deleted file mode 100644 index cc4d26d..0000000 --- a/log.txt +++ /dev/null @@ -1,211 +0,0 @@ -+ GBS_ROOT=/home/juwankim/GBS-ROOT/local/BUILD-ROOTS/scratch.armv7l.0/ -+ BUILD_DIR=home/abuild/rpmbuild/BUILD/ -+ cd /home/juwankim/GBS-ROOT/local/BUILD-ROOTS/scratch.armv7l.0/home/abuild/rpmbuild/BUILD/ -+ ls -1 -+ PROJECT=org.tizen.settings-tv-ref-0.1 -+ echo Source Copying.. -Source Copying.. -+ cp -rf src/data_wrapper.c src/main.c src/parser.c src/settings_provider.c src/timeout_handler.c src/utils.c src/view_bottomslider.c src/view_bottomsublist.c src/view_device_manager.c src/view_maincatalog.c src/view_need_pwd.c src/view_pwd_popup.c src/view_resetpopup.c src/view_sublist.c src/view_system_clock.c src/view_uigadget.c src/view_upgrade_popup.c src/viewmgr.c /home/juwankim/GBS-ROOT/local/BUILD-ROOTS/scratch.armv7l.0/home/abuild/rpmbuild/BUILD/org.tizen.settings-tv-ref-0.1/src/ -+ cp -rf ug/channel ug/network ug/proxy ug/system ug/wifi-direct /home/juwankim/GBS-ROOT/local/BUILD-ROOTS/scratch.armv7l.0/home/abuild/rpmbuild/BUILD/org.tizen.settings-tv-ref-0.1/ug/ -+ cp -rf include/data_wrapper.h include/dbg.h include/def.h include/json_marco.h include/parser.h include/settings_provider.h include/timeout_handler.h include/utils.h include/view_bottomslider.h include/view_bottomsublist.h include/view_device_manager.h include/view_maincatalog.h include/view_need_pwd.h include/view_pwd_popup.h include/view_resetpopup.h include/view_sublist.h include/view_system_clock.h include/view_uigadget.h include/view_upgrade_popup.h include/viewmgr.h /home/juwankim/GBS-ROOT/local/BUILD-ROOTS/scratch.armv7l.0/home/abuild/rpmbuild/BUILD/org.tizen.settings-tv-ref-0.1/include/ -+ echo Build Start -Build Start -+ sudo chroot /home/juwankim/GBS-ROOT/local/BUILD-ROOTS/scratch.armv7l.0/ /bin/bash -c cd /home/abuild/rpmbuild/BUILD/org.tizen.settings-tv-ref-0.1/ && make -j16 && exit --- Configuring done --- Generating done --- Build files have been written to: /home/abuild/rpmbuild/BUILD/org.tizen.settings-tv-ref-0.1 -qemu: Unsupported syscall: 350 -qemu: Unsupported syscall: 350 -qemu: Unsupported syscall: 350 -qemu: Unsupported syscall: 350 -qemu: Unsupported syscall: 350 -qemu: Unsupported syscall: 350 -qemu: Unsupported syscall: 350 -qemu: Unsupported syscall: 350 -qemu: Unsupported syscall: 350 -qemu: Unsupported syscall: 350 -qemu: Unsupported syscall: 350 -qemu: Unsupported syscall: 350 -qemu: Unsupported syscall: 350 -qemu: Unsupported syscall: 350 -qemu: Unsupported syscall: 350 -qemu: Unsupported syscall: 350 -qemu: Unsupported syscall: 350 -qemu: Unsupported syscall: 350 -qemu: Unsupported syscall: 350 -qemu: Unsupported syscall: 350 -qemu: Unsupported syscall: 350 -qemu: Unsupported syscall: 350 -qemu: Unsupported syscall: 350 -qemu: Unsupported syscall: 350 -edje_cc: Warning. Part 'elm.text' in group 'elm/progressbar/horizontal/scan_progress' contains description 'default:0' which has text.min: 1 X; but not text.ellipsis: -1; -edje_cc: Warning. This is almost certainly not what you want. -edje_cc: Warning. Part 'elm.text' in group 'elm/progressbar/horizontal/update_progressbar' contains description 'default:0' which has text.min: 1 X; but not text.ellipsis: -1; -edje_cc: Warning. This is almost certainly not what you want. -[ 0%] Built target ug-proxy-settings.edj -[ 0%] Built target ug_auto_program.edj -[ 0%] Built target ug_auto_program_theme.edj -[ 0%] Scanning dependencies of target ug-auto-program -Built target ug-proxy-settings-theme.edj -[ 2%] [ 4%] [ 6%] [ 8%] [ 10%] [ 12%] [ 12%] Building C object ug/channel/CMakeFiles/ug-auto-program.dir/src/ug_auto_program.c.o -Building C object ug/channel/CMakeFiles/ug-auto-program.dir/src/util.c.o -[ 14%] Building C object ug/channel/CMakeFiles/ug-auto-program.dir/src/viewmgr_auto_program.c.o -Building C object ug/channel/CMakeFiles/ug-auto-program.dir/src/view_scan_start.c.o -Built target ug_clock_theme.edj -Scanning dependencies of target ug-proxy-settings -[ 14%] Building C object ug/channel/CMakeFiles/ug-auto-program.dir/src/view_search_page.c.o -Building C object ug/channel/CMakeFiles/ug-auto-program.dir/src/view_result_page.c.o -Built target ug-network-settings.edj -[ 16%] Building C object ug/channel/CMakeFiles/ug-auto-program.dir/src/tv_scan.c.o -[ 18%] [ 18%] [ 18%] [ 20%] Building C object ug/proxy/CMakeFiles/ug-proxy-settings.dir/src/main_view.c.o -Built target ug-network-settings-theme.edj -Building C object ug/proxy/CMakeFiles/ug-proxy-settings.dir/src/ug_proxy_settings.c.o -Built target org.tizen.settings-tv-ref-theme.edj -[ 20%] [ 20%] Building C object ug/proxy/CMakeFiles/ug-proxy-settings.dir/src/vconf_mgr.c.o -[ 22%] Built target ug-wifi-direct.edj -Built target ug_clock.edj -[ 24%] Building C object ug/proxy/CMakeFiles/ug-proxy-settings.dir/src/connection_mgr.c.o -/home/abuild/rpmbuild/BUILD/org.tizen.settings-tv-ref-0.1/ug/channel/src/tv_scan.c: In function '_handle_signal': -/home/abuild/rpmbuild/BUILD/org.tizen.settings-tv-ref-0.1/ug/channel/src/tv_scan.c:300:1: warning: no return statement in function returning non-void [-Wreturn-type] - } - ^ -/home/abuild/rpmbuild/BUILD/org.tizen.settings-tv-ref-0.1/ug/channel/src/tv_scan.c: At top level: -/home/abuild/rpmbuild/BUILD/org.tizen.settings-tv-ref-0.1/ug/channel/src/tv_scan.c:103:13: warning: '_handle_begin_signal' defined but not used [-Wunused-function] - static void _handle_begin_signal(struct tv_scan *tvs, - ^ -/home/abuild/rpmbuild/BUILD/org.tizen.settings-tv-ref-0.1/ug/channel/src/tv_scan.c:136:13: warning: '_handle_progress_signal' defined but not used [-Wunused-function] - static void _handle_progress_signal(struct tv_scan *tvs, - ^ -/home/abuild/rpmbuild/BUILD/org.tizen.settings-tv-ref-0.1/ug/channel/src/tv_scan.c:161:13: warning: '_channel_count' defined but not used [-Wunused-function] - static void _channel_count(unsigned int *atv, unsigned int *dtv, - ^ -/home/abuild/rpmbuild/BUILD/org.tizen.settings-tv-ref-0.1/ug/channel/src/tv_scan.c:190:13: warning: '_handle_found_signal' defined but not used [-Wunused-function] - static void _handle_found_signal(struct tv_scan *tvs, - ^ -/home/abuild/rpmbuild/BUILD/org.tizen.settings-tv-ref-0.1/ug/channel/src/tv_scan.c:227:13: warning: '_handle_done_signal' defined but not used [-Wunused-function] - static void _handle_done_signal(struct tv_scan *tvs, - ^ -/home/abuild/rpmbuild/BUILD/org.tizen.settings-tv-ref-0.1/ug/channel/src/tv_scan.c:250:18: warning: '_handle_signal' defined but not used [-Wunused-function] - static Eina_Bool _handle_signal(void *data) - ^ -/home/abuild/rpmbuild/BUILD/org.tizen.settings-tv-ref-0.1/ug/channel/src/tv_scan.c: In function 'tv_scan_pause': -/home/abuild/rpmbuild/BUILD/org.tizen.settings-tv-ref-0.1/ug/channel/src/tv_scan.c:541:1: warning: control reaches end of non-void function [-Wreturn-type] - } - ^ -[ 26%] Building C object ug/proxy/CMakeFiles/ug-proxy-settings.dir/src/wifi_mgr.c.o -Scanning dependencies of target ug-network-settings -[ 28%] Scanning dependencies of target ug-clock -Building C object ug/proxy/CMakeFiles/ug-proxy-settings.dir/src/util.c.o -[ 30%] [ 32%] [ 34%] [ 36%] [ 38%] [ 40%] Building C object ug/network/CMakeFiles/ug-network-settings.dir/src/main_view.c.o -[ 42%] Building C object ug/network/CMakeFiles/ug-network-settings.dir/src/ug_network_settings.c.o -Building C object ug/network/CMakeFiles/ug-network-settings.dir/src/vconf_mgr.c.o -Building C object ug/network/CMakeFiles/ug-network-settings.dir/src/wifi_mgr.c.o -Building C object ug/network/CMakeFiles/ug-network-settings.dir/src/ip_setting_view.c.o -[ 44%] Building C object ug/network/CMakeFiles/ug-network-settings.dir/src/network_viewmgr.c.o -Building C object ug/system/clock/CMakeFiles/ug-clock.dir/src/ug_clock_spin_control.c.o -Building C object ug/system/clock/CMakeFiles/ug-clock.dir/src/ug_clock.c.o -[ 46%] [ 46%] Linking C shared library libug-auto-program.so -Building C object ug/system/clock/CMakeFiles/ug-clock.dir/src/ug_clock_sublist.c.o -Built target ug-wifi-direct-theme.edj -Building C object ug/system/clock/CMakeFiles/ug-clock.dir/src/ug_clock_utils.c.o -[ 48%] [ 51%] Building C object ug/network/CMakeFiles/ug-network-settings.dir/src/connection_mgr.c.o -Building C object ug/network/CMakeFiles/ug-network-settings.dir/src/util.c.o -[ 53%] [ 55%] Building C object ug/network/CMakeFiles/ug-network-settings.dir/src/wifi_passcode_view.c.o -Linking C shared library libug-proxy-settings.so -Building C object ug/system/clock/CMakeFiles/ug-clock.dir/src/ug_clock_time_spin_control.c.o -Scanning dependencies of target ug-wifi-direct -[ 55%] [ 57%] Built target ug-auto-program -[ 61%] [ 61%] [ 63%] Building C object ug/wifi-direct/CMakeFiles/ug-wifi-direct.dir/src/ug_wifi_direct.c.o -Building C object ug/wifi-direct/CMakeFiles/ug-wifi-direct.dir/src/wifi_direct_view.c.o -Building C object ug/wifi-direct/CMakeFiles/ug-wifi-direct.dir/src/util.c.o -Building C object ug/wifi-direct/CMakeFiles/ug-wifi-direct.dir/src/wifi_direct_mgr.c.o -[ 63%] Built target ug-proxy-settings -Linking C shared library libug-clock.so -Linking C shared library libug-network-settings.so -[ 63%] [ 63%] Built target ug-clock -Built target ug-network-settings -[ 63%] Built target org.tizen.settings-tv-ref.edj -Linking C shared library libug-wifi-direct.so -Scanning dependencies of target settings-tv-ref -[ 67%] [ 67%] [ 73%] [ 73%] [ 73%] [ 75%] [ 77%] [ 79%] [ 79%] [ 81%] Built target ug-wifi-direct -Building C object CMakeFiles/settings-tv-ref.dir/src/utils.c.o -Building C object CMakeFiles/settings-tv-ref.dir/src/main.c.o -[ 83%] Building C object CMakeFiles/settings-tv-ref.dir/src/viewmgr.c.o -Building C object CMakeFiles/settings-tv-ref.dir/src/parser.c.o -Building C object CMakeFiles/settings-tv-ref.dir/src/view_uigadget.c.o -Building C object CMakeFiles/settings-tv-ref.dir/src/data_wrapper.c.o -Building C object CMakeFiles/settings-tv-ref.dir/src/view_maincatalog.c.o -Building C object CMakeFiles/settings-tv-ref.dir/src/view_sublist.c.o -[ 87%] [ 87%] Building C object CMakeFiles/settings-tv-ref.dir/src/view_bottomsublist.c.o -[ 89%] Building C object CMakeFiles/settings-tv-ref.dir/src/view_bottomslider.c.o -Building C object CMakeFiles/settings-tv-ref.dir/src/settings_provider.c.o -Building C object CMakeFiles/settings-tv-ref.dir/src/view_pwd_popup.c.o -[ 91%] Building C object CMakeFiles/settings-tv-ref.dir/src/view_device_manager.c.o -[ 93%] [ 95%] Building C object CMakeFiles/settings-tv-ref.dir/src/view_upgrade_popup.c.o -Building C object CMakeFiles/settings-tv-ref.dir/src/view_system_clock.c.o -Building C object CMakeFiles/settings-tv-ref.dir/src/view_resetpopup.c.o -[ 97%] In file included from /home/abuild/rpmbuild/BUILD/org.tizen.settings-tv-ref-0.1/src/settings_provider.c:21:0: -/usr/include/media/sound_manager.h:220:1: warning: 'sound_session_notify_e' is deprecated (declared at /usr/include/media/sound_manager.h:193) [-Wdeprecated-declarations] - typedef void (*sound_session_notify_cb) (sound_session_notify_e notify, void *user_data) DEPRECATED; // will be deprecated - ^ -/usr/include/media/sound_manager.h:229:1: warning: 'sound_interrupted_code_e' is deprecated (declared at /usr/include/media/sound_manager.h:202) [-Wdeprecated-declarations] - typedef void(* sound_interrupted_cb)(sound_interrupted_code_e code, void *user_data) DEPRECATED; // will be deprecated - ^ -/usr/include/media/sound_manager.h:526:1: warning: 'volume_key_type_e' is deprecated (declared at /usr/include/media/sound_manager.h:84) [-Wdeprecated-declarations] - int sound_manager_set_volume_key_type(volume_key_type_e type) DEPRECATED;// will be deprecated - ^ -/usr/include/media/sound_manager.h:726:1: warning: 'sound_session_notify_cb' is deprecated [-Wdeprecated-declarations] - int sound_manager_set_session_notify_cb(sound_session_notify_cb callback, void *user_data) DEPRECATED;// will be deprecated - ^ -/usr/include/media/sound_manager.h:745:1: warning: 'sound_interrupted_cb' is deprecated [-Wdeprecated-declarations] - int sound_manager_set_interrupted_cb(sound_interrupted_cb callback, void *user_data) DEPRECATED;// will be deprecated; - ^ -/usr/include/media/sound_manager.h:991:1: warning: 'sound_route_e' is deprecated (declared at /usr/include/media/sound_manager.h:363) [-Wdeprecated-declarations] - typedef bool(* sound_available_route_cb)(sound_route_e route, void *user_data) DEPRECATED;// will be deprecated - ^ -/usr/include/media/sound_manager.h:1001:1: warning: 'sound_route_e' is deprecated (declared at /usr/include/media/sound_manager.h:363) [-Wdeprecated-declarations] - typedef void(* sound_available_route_changed_cb)(sound_route_e route, bool available, void *user_data) DEPRECATED;// will be deprecated - ^ -/usr/include/media/sound_manager.h:1010:1: warning: 'sound_device_in_e' is deprecated (declared at /usr/include/media/sound_manager.h:339) [-Wdeprecated-declarations] - typedef void(* sound_active_device_changed_cb)(sound_device_in_e in, sound_device_out_e out, void *user_data) DEPRECATED;// will be deprecated - ^ -/usr/include/media/sound_manager.h:1010:1: warning: 'sound_device_out_e' is deprecated (declared at /usr/include/media/sound_manager.h:348) [-Wdeprecated-declarations] -/usr/include/media/sound_manager.h:1022:1: warning: 'sound_available_route_cb' is deprecated [-Wdeprecated-declarations] - int sound_manager_foreach_available_route (sound_available_route_cb callback, void *user_data) DEPRECATED;// will be deprecated - ^ -/usr/include/media/sound_manager.h:1032:1: warning: 'sound_route_e' is deprecated (declared at /usr/include/media/sound_manager.h:363) [-Wdeprecated-declarations] - int sound_manager_set_active_route (sound_route_e route) DEPRECATED;// will be deprecated - ^ -/usr/include/media/sound_manager.h:1043:1: warning: 'sound_device_in_e' is deprecated (declared at /usr/include/media/sound_manager.h:339) [-Wdeprecated-declarations] - int sound_manager_get_active_device (sound_device_in_e *in, sound_device_out_e *out) DEPRECATED;// will be deprecated - ^ -/usr/include/media/sound_manager.h:1043:1: warning: 'sound_device_out_e' is deprecated (declared at /usr/include/media/sound_manager.h:348) [-Wdeprecated-declarations] -/usr/include/media/sound_manager.h:1052:1: warning: 'sound_route_e' is deprecated (declared at /usr/include/media/sound_manager.h:363) [-Wdeprecated-declarations] - bool sound_manager_is_route_available (sound_route_e route) DEPRECATED;// will be deprecated - ^ -/usr/include/media/sound_manager.h:1065:1: warning: 'sound_available_route_changed_cb' is deprecated [-Wdeprecated-declarations] - int sound_manager_set_available_route_changed_cb (sound_available_route_changed_cb callback, void *user_data) DEPRECATED;// will be deprecated - ^ -/usr/include/media/sound_manager.h:1084:1: warning: 'sound_active_device_changed_cb' is deprecated [-Wdeprecated-declarations] - int sound_manager_set_active_device_changed_cb (sound_active_device_changed_cb callback, void *user_data); - ^ -/home/abuild/rpmbuild/BUILD/org.tizen.settings-tv-ref-0.1/src/settings_provider.c: In function '_get_int': -/home/abuild/rpmbuild/BUILD/org.tizen.settings-tv-ref-0.1/src/settings_provider.c:403:20: warning: unused variable 'index' [-Wunused-variable] - int status, size, index; - ^ -/home/abuild/rpmbuild/BUILD/org.tizen.settings-tv-ref-0.1/src/settings_provider.c:403:14: warning: unused variable 'size' [-Wunused-variable] - int status, size, index; - ^ -/home/abuild/rpmbuild/BUILD/org.tizen.settings-tv-ref-0.1/src/settings_provider.c: At top level: -/home/abuild/rpmbuild/BUILD/org.tizen.settings-tv-ref-0.1/src/settings_provider.c:170:21: warning: 'sleeptimer_value' defined but not used [-Wunused-variable] - static unsigned int sleeptimer_value[] = { - ^ -/home/abuild/rpmbuild/BUILD/org.tizen.settings-tv-ref-0.1/src/settings_provider.c:313:12: warning: '_find_index' defined but not used [-Wunused-function] - static int _find_index(unsigned int *array, int size, int val, int *index) - ^ -[100%] Building C object CMakeFiles/settings-tv-ref.dir/src/view_need_pwd.c.o -Building C object CMakeFiles/settings-tv-ref.dir/src/timeout_handler.c.o -Linking C executable settings-tv-ref -[100%] Built target settings-tv-ref -+ echo Build Done -Build Done diff --git a/ug/include/NetConMgr.h b/ug/include/NetConMgr.h index 3a17e42..38c0498 100644 --- a/ug/include/NetConMgr.h +++ b/ug/include/NetConMgr.h @@ -8,6 +8,15 @@ class CNetConMgr { private: static CNetConMgr *instance; struct SNetConMgr *m; + +private: + static void sm_CbIpAddrChanged(const char *ipv4, const char *ipv6, void* data); + void m_OnIpAddrChanged(void *data); + + static void sm_CbProfileStateChanged(connection_profile_state_e state, void *data); + bool m_GetEthernetProfile(void); + bool m_UpdateProfile(void); + private: CNetConMgr(void) : m(0) {} virtual ~CNetConMgr() {} @@ -17,12 +26,32 @@ public: static void Finalize(void); static CNetConMgr *GetInstance(void); - bool GetProfileInfo(connection_profile_h out_profile); + void RefreshEthernetProfile(void); + bool GetEthernetState(bool *state); + + bool GetProfileName(char *out_name); + bool IsConnected(void); + + bool SetIpConfType(connection_ip_config_type_e); + bool SetIpAddr(char *ip); + bool SetSubnetMask(char *submask); + bool SetGateway(char *gateway); + bool SetDNS(char *dns); + + bool GetIpAddr(char *ip); + bool GetSubnetMask(char *submask); + bool GetGateway(char *gateway); + bool GetDNS(char *dns); + bool SetProxyType(EProxyMethod method); bool GetProxyType(EProxyMethod *method); bool SetProxyAddr(char *ip); bool GetProxyAddr(char *ip); + const char *GetErrorMsg(connection_error_e err); + + bool RegisterIpChangedCallback(void(*ip_changed_cb)(bool change_state, void *data), void *data); + }; #endif /* __NETCONMGR_H__ */ diff --git a/ug/network/CMakeLists.txt b/ug/network/CMakeLists.txt index f53b0bc..2357079 100644 --- a/ug/network/CMakeLists.txt +++ b/ug/network/CMakeLists.txt @@ -50,10 +50,10 @@ SET(SRCS src/network_viewmgr.cpp src/ip_setting_view.cpp src/vconf_mgr.cpp - src/connection_mgr.cpp src/util.cpp src/wifi_passcode_view.cpp ../src/WifiMgr.cpp + ../src/NetConMgr.cpp ) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) diff --git a/ug/network/include/common.h b/ug/network/include/common.h index 19f2c19..8f15b48 100644 --- a/ug/network/include/common.h +++ b/ug/network/include/common.h @@ -17,7 +17,6 @@ #ifndef __NETWORK_COMMON_H__ #define __NETWORK_COMMON_H__ -#include #include #define IP_STRING_MAX_SIZE 20 @@ -37,8 +36,6 @@ enum setting_mode { struct connection_info { enum network_type_enum cur_type; - connection_h connection; - connection_profile_h profile; char name[MAX_NAME_SIZE]; wifi_ap_h ap; }; diff --git a/ug/network/include/connection_mgr.h b/ug/network/include/connection_mgr.h deleted file mode 100644 index 32a9751..0000000 --- a/ug/network/include/connection_mgr.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __CONNECTION_MGR_H__ -#define __CONNECTION_MGR_H__ - -#include -#include -#include "common.h" - -int connection_mgr_set_profile( - connection_h connection, - connection_profile_h profile, - struct network_info *info); -connection_h connection_mgr_create(void); -int connection_mgr_destroy(connection_h connection); -int connection_mgr_uninit(connection_h connection); -int connection_mgr_get_profile_info(connection_h connection, struct connection_info *info); -Eina_Bool connection_mgr_is_connected(connection_h connection); -int connection_mgr_ip_dynamic_config(connection_h connection,connection_profile_h profile); -int connection_mgr_get_ethernet_state(connection_h connection,Eina_Bool *plugin); -int connection_mgr_get_ip_info(connection_profile_h profile,struct network_info *info); -#if 0 -int connection_mgr_register_ethernet_state_cb( - connection_h connection, - connection_ethernet_state_chaged_cb cb, void *data); -int connection_mgr_set_profile_state_changed_cb( - connection_profile_h profile, - connection_profile_state_changed_cb cb, void *data); -int connection_mgr_get_is_online_async( - connection_h connection, - connection_is_online_async_cb cb, void *data); -int connection_mgr_check_gateway_async( - connection_profile_h profile, - connection_profile_check_gateway_async_cb cb, void *data); -#endif - -#endif /* __CONNECTION_MGR_H__ */ diff --git a/ug/network/include/main_view.h b/ug/network/include/main_view.h index 8b01e27..199007d 100644 --- a/ug/network/include/main_view.h +++ b/ug/network/include/main_view.h @@ -17,11 +17,6 @@ #ifndef __MAIN_VIEW_H__ #define __MAIN_VIEW_H__ -#include -#include -#include -#include "network_viewmgr.h" - struct view_class *main_view_vclass_get(void); #endif /* __MAIN_VIEW_H__ */ diff --git a/ug/network/include/vconf_mgr.h b/ug/network/include/vconf_mgr.h index e3335c2..2d57b66 100644 --- a/ug/network/include/vconf_mgr.h +++ b/ug/network/include/vconf_mgr.h @@ -18,7 +18,6 @@ #define __VCONF_MGR_H__ #include -#include "connection_mgr.h" #include "common.h" int vconf_mgr_get_network_type(enum network_type_enum *network_type); diff --git a/ug/network/src/connection_mgr.cpp b/ug/network/src/connection_mgr.cpp deleted file mode 100644 index f9da7c2..0000000 --- a/ug/network/src/connection_mgr.cpp +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "defs.h" -#include "dbg.h" -#include "connection_mgr.h" - -/** - * Converts the error type to string information. - * - * @param[in] err_type Error type - * @return error string information; - */ -static const char *_convert_error_to_string(connection_error_e err_type) -{ - _DBG("Not Yet"); -#if 0 - switch (err_type) { - case CONNECTION_ERROR_NONE: - return "NONE"; - case CONNECTION_ERROR_INVALID_PARAMETER: - return "INVALID_PARAMETER"; - case CONNECTION_ERROR_OUT_OF_MEMORY: - return "OUT_OF_MEMORY"; - case CONNECTION_ERROR_INVALID_OPERATION: - return "INVALID_OPERATION"; - case CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED: - return "ADDRESS_FAMILY_NOT_SUPPORTED"; - case CONNECTION_ERROR_OPERATION_FAILED: - return "OPERATION_FAILED"; - case CONNECTION_ERROR_ITERATOR_END: - return "ITERATOR_END"; - case CONNECTION_ERROR_NO_CONNECTION: - return "NO_CONNECTION"; - case CONNECTION_ERROR_NOW_IN_PROGRESS: - return "NOW_IN_PROGRESS"; - case CONNECTION_ERROR_ALREADY_EXISTS: - return "ALREADY_EXISTS"; - case CONNECTION_ERROR_OPERATION_ABORTED: - return "OPERATION_ABORTED"; - case CONNECTION_ERROR_DHCP_FAILED: - return "DHCP_FAILED"; - case CONNECTION_ERROR_INVALID_KEY: - return "INVALID_KEY"; - case CONNECTION_ERROR_NO_REPLY: - return "NO_REPLY"; - case CONNECTION_ERROR_NO_KEYWORD: - return "NO_KEYWORD"; - case CONNECTION_ERROR_TCP_RST: - return "RST_IN_TCP_RESPONSE"; - case CONNECTION_ERROR_TCP_SYN_TIMEOUT: - return "TCP_SYN_TIMEOUT"; - case CONNECTION_ERROR_OFFLINE: - return "CONNECTION_OFFLINE"; - case CONNECTION_ERROR_NETWORK_MONITOR_FAILURE: - return "monitor failer"; - case CONNECTION_ERROR_INVALID_GATEWAY: - return "invalid gateway"; - case CONNECTION_ERROR_INVALID_MACADDRESS: - return "invalid mac addr"; - default: - break; - } -#endif - - return "Unknown"; -} - -/** - * Creates a handle for managing data connections. - * - * The handle must be released with connection_destroy(). - * - * @return connetcion if the operation is successful; NULL if failed; - */ -connection_h connection_mgr_create(void) -{ - int ret; - connection_h connection; - - connection = NULL; - ret = connection_create(&connection); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("connection_create failed"); - connection = NULL; - } - - return connection; -} - -/** - * Destroys the connection handle. - * - * @param[in] connection The handle of the connection - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int connection_mgr_destroy(connection_h connection) -{ - int ret; - - if (!connection) { - _ERR("connection is NULL."); - return RET_FAILED; - } - - ret = connection_destroy(connection); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("connection_destroy() failed."); - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Gets the ethernet profile information. - * - * Iterates all the profile in the connection, and gets the ethernet one. - * - * @param[in] connection The handle of the connection - * @param[out] info The structure to store profile information - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int connection_mgr_get_profile_info( - connection_h connection, struct connection_info *info) -{ - connection_profile_iterator_h iter; - connection_profile_h profile; - connection_profile_type_e type; - char *name; - int ret; - - if (!info || !connection) { - _ERR("param is NULL."); - return RET_FAILED; - } - - ret = connection_get_profile_iterator(connection, - CONNECTION_ITERATOR_TYPE_REGISTERED, &iter); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("Fail to get profile iterator [%d]\n", ret); - return RET_FAILED; - } - - while (connection_profile_iterator_has_next(iter)) { - profile = NULL; - if (connection_profile_iterator_next(iter, - &profile) != CONNECTION_ERROR_NONE) { - _ERR("Fail to get profile handle\n"); - return RET_FAILED; - } - - if (!profile) { - _ERR("get profile failed."); - return RET_FAILED; - } - - if (connection_profile_get_type(profile, - &type) != CONNECTION_ERROR_NONE) { - _ERR("Fail to get profile type\n"); - return RET_FAILED; - } - - name = NULL; - if (connection_profile_get_name(profile, - &name) != CONNECTION_ERROR_NONE) { - _ERR("Fail to get profile name\n"); - return RET_FAILED; - } - - if (!name) { - _ERR("get name failed."); - return RET_FAILED; - } - - if (type == CONNECTION_PROFILE_TYPE_ETHERNET) { - strncpy(info->name, name, MAX_NAME_SIZE - 1); - info->profile = profile; - } - - free(name); - } - - return RET_SUCCESS; -} - -/** - * Registers the callback called when the state of profile is changed. - * - * If the state of profile is changed, the registered callback will be called. - * - * @param[in] profile The handle of the profile - * @param[in] cb The callback function to be called - * @param[in] data User data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -#if 0 -int connection_mgr_set_profile_state_changed_cb( - connection_profile_h profile, - connection_profile_state_changed_cb cb, void *data) -{ - int ret; - - if (!profile || !cb || !data) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - ret = connection_profile_set_state_changed_cb(profile, - cb, data); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("connection_profile_set_state_changed_cb() failed."); - return RET_FAILED; - } - - return RET_SUCCESS; -} -#endif - -/** - * Gets the state of the connection. - * - * @param[in] connection The handle of the connection - * @return EINA_TRUE if the connection is OK; EINA_FALSE otherwise; - */ -Eina_Bool connection_mgr_is_connected(connection_h connection) -{ - int ret; - connection_ethernet_state_e state; - - if (!connection) { - _ERR("the connection is NULL."); - return EINA_FALSE; - } - - ret = connection_get_ethernet_state(connection, &state); - if (ret == CONNECTION_ERROR_NONE && - state == CONNECTION_ETHERNET_STATE_CONNECTED) - return EINA_TRUE; - - return EINA_FALSE; -} - -/** - * Sets the profile information. - * - * Sets the network information to profile. - * - * @param[in] connection The handle of the connection - * @param[in] profile The handle of the profile - * @param[in] info Network information - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int connection_mgr_set_profile(connection_h connection, - connection_profile_h profile, - struct network_info *info) -{ - int ret; - - if (!connection || !profile || !info) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - ret = connection_update_profile(connection, profile); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("connection_update_profile failed.\n"); - return RET_FAILED; - } - - ret = connection_profile_set_ip_config_type(profile, - CONNECTION_ADDRESS_FAMILY_IPV4, - CONNECTION_IP_CONFIG_TYPE_STATIC); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("connection_profile_set_ip_config_type() failed."); - return RET_FAILED; - } - - ret = connection_profile_set_ip_address(profile, - CONNECTION_ADDRESS_FAMILY_IPV4, - info->ip_addr); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("connection_profile_set_ip_address() failed."); - return RET_FAILED; - } - - ret = connection_profile_set_subnet_mask(profile, - CONNECTION_ADDRESS_FAMILY_IPV4, - info->submask); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("fail to set_subnet_mask %d\n" , ret); - return RET_FAILED; - } - - ret = connection_profile_set_gateway_address(profile, - CONNECTION_ADDRESS_FAMILY_IPV4, - info->gateway); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("fail to set_gateway_address %d\n" , ret); - return RET_FAILED; - } - - ret = connection_profile_set_dns_address(profile, 1, - CONNECTION_ADDRESS_FAMILY_IPV4, - info->dns); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("fail to set_dns_address %d\n" , ret); - return RET_FAILED; - } - - ret = connection_update_profile(connection, profile); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("connection_update_profile failed.\n"); - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Gets whether the profile can access to the internet asynchronously. - * - * The result will return in the registered callback. - * - * @param[in] connection The handle of the connection - * @param[in] cb The callback function to be called - * @param[in] data User data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -#if 0 -int connection_mgr_get_is_online_async( - connection_h connection, - connection_is_online_async_cb cb, void *data) -{ - int ret; - - if (!connection || !cb || !data) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - ret = connection_get_is_online_async(connection, cb, data); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("connection_get_is_online_async() failed."); - return RET_FAILED; - } - - return RET_SUCCESS; -} -#endif - -/** - * Validates gateway address set for Ethernet Asynchronusly. - * - * The result will return in the registered callback. - * - * @param[in] profile The handle of the profile - * @param[in] cb The callback function to be called - * @param[in] data User data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -#if 0 -int connection_mgr_check_gateway_async( - connection_profile_h profile, - connection_profile_check_gateway_async_cb cb, void *data) -{ - int ret; - - if (!profile || !cb || !data) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - ret = connection_profile_check_gateway_async(profile, cb, data); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("connection_get_is_online_async() failed."); - return RET_FAILED; - } - - return RET_SUCCESS; -} -#endif - -/** - * Sets the IP config type into dynamic. - * - * Called when the profile need getting IP dynamically. - * - * @param[in] connection The handle of the connection - * @param[in] profile The handle of the profile - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int connection_mgr_ip_dynamic_config( - connection_h connection, - connection_profile_h profile) -{ - int ret; - - if (!connection || !profile) { - _ERR("The param is invalid.\n"); - return RET_FAILED; - } - - ret = connection_update_profile(connection, profile); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("connection_update_profile failed, ret: %s.\n", - _convert_error_to_string((connection_error_e) ret)); - return RET_FAILED; - } - - ret = connection_profile_set_ip_config_type(profile, - CONNECTION_ADDRESS_FAMILY_IPV4, - CONNECTION_IP_CONFIG_TYPE_DYNAMIC); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("Fail to set ip method type[%s]\n", - _convert_error_to_string((connection_error_e) ret)); - return RET_FAILED; - } - - ret = connection_update_profile(connection, profile); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("connection_update_profile failed, ret: %s.\n", - _convert_error_to_string((connection_error_e) ret)); - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Registers callback for ethernet cable. - * - * Including cable plugged [in/out] event. - * - * @param[in] connection The handle of the connection - * @param[in] cb The callback function to be called - * @param[in] data User data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -#if 0 -int connection_mgr_register_ethernet_state_cb( - connection_h connection, - connection_ethernet_state_chaged_cb cb, void *data) -{ - int ret; - - if (!connection || !cb || !data) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - ret = connection_set_ethernet_state_chaged_cb(connection, cb, data); - if (ret != RET_SUCCESS) { - _ERR("connection_set_ethernet_state_chaged_cb() failed."); - return RET_FAILED; - } - - return RET_SUCCESS; -} -#endif - -/** - * Gets the state of ethernet. - * - * The returned state is for the ethernet connection state. - * - * @param[in] connection The handle of the connection - * @param[out] plugin The cable plugged state - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int connection_mgr_get_ethernet_state( - connection_h connection, Eina_Bool *plugin) -{ - int ret; - connection_ethernet_state_e state; - - if (!connection || !plugin) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - ret = connection_get_ethernet_state(connection, &state); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("connection_get_ethernet_state() failed."); - return RET_FAILED; - } - - if (state == CONNECTION_ETHERNET_STATE_DEACTIVATED) - *plugin = EINA_FALSE; - else - *plugin = EINA_TRUE; - - return RET_SUCCESS; -} - -/** - * Sets the network information. - * - * Including IP, submask and gateway. - * - * @param[in] profile The handle of the profile - * @param[in] info The structure of network - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int connection_mgr_set_ip_config( - connection_profile_h profile, - struct network_info *info) -{ - int ret; - - if (!profile || !info) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - ret = connection_profile_set_ip_address(profile, - CONNECTION_ADDRESS_FAMILY_IPV4, - info->ip_addr); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("set ip address fail, ret: %s\n", - _convert_error_to_string((connection_error_e) ret)); - return RET_FAILED; - } - - ret = connection_profile_set_subnet_mask(profile, - CONNECTION_ADDRESS_FAMILY_IPV4, - info->submask); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("set subnet mask fail. %s\n", - _convert_error_to_string((connection_error_e) ret)); - return RET_FAILED; - } - - ret = connection_profile_set_gateway_address(profile, - CONNECTION_ADDRESS_FAMILY_IPV4, - info->gateway); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("set gateway address fail %s\n", - _convert_error_to_string((connection_error_e) ret)); - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Sets the DNS. - * - * @param[in] profile The handle of the profile - * @param[in] info The structure of network - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int connection_mgr_set_dns_config( - connection_profile_h profile, - struct network_info *info) -{ - int ret; - - if (!profile || !info) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - ret = connection_profile_set_dns_address(profile, 1, - CONNECTION_ADDRESS_FAMILY_IPV4, - info->dns); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("set dns address fail %d\n", - _convert_error_to_string((connection_error_e) ret)); - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Gets the network information. - * - * @param[in] profile The handle of the profile - * @param[out] info The structure of network - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int connection_mgr_get_ip_info( - connection_profile_h profile, - struct network_info *info) -{ - char *str_value; - - if (!profile || !info) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - if (connection_profile_get_ip_address(profile, - CONNECTION_ADDRESS_FAMILY_IPV4, - &str_value) != CONNECTION_ERROR_NONE) { - _ERR("Fail to get IP address!\n"); - strncpy(info->ip_addr, ZERO_IP, IP_STRING_MAX_SIZE); - } else { - strncpy(info->ip_addr, str_value, IP_STRING_MAX_SIZE); - free(str_value); - } - - if (connection_profile_get_subnet_mask(profile, - CONNECTION_ADDRESS_FAMILY_IPV4, - &str_value) != CONNECTION_ERROR_NONE) { - _ERR("Fail to get subnet mask!\n"); - strncpy(info->submask, ZERO_IP, IP_STRING_MAX_SIZE); - } else { - strncpy(info->submask, str_value, IP_STRING_MAX_SIZE); - free(str_value); - } - - if (connection_profile_get_gateway_address(profile, - CONNECTION_ADDRESS_FAMILY_IPV4, - &str_value) != CONNECTION_ERROR_NONE) { - _ERR("Fail to get gateway!\n"); - strncpy(info->gateway, ZERO_IP, IP_STRING_MAX_SIZE); - } else { - strncpy(info->gateway, str_value, IP_STRING_MAX_SIZE); - free(str_value); - } - - if (connection_profile_get_dns_address(profile, 1, - CONNECTION_ADDRESS_FAMILY_IPV4, - &str_value) != CONNECTION_ERROR_NONE) { - _ERR("Fail to get DNS1!\n"); - strncpy(info->dns, ZERO_IP, IP_STRING_MAX_SIZE); - } else { - strncpy(info->dns, str_value, IP_STRING_MAX_SIZE); - free(str_value); - } - - return RET_SUCCESS; -} diff --git a/ug/network/src/ip_setting_view.cpp b/ug/network/src/ip_setting_view.cpp index 458a88b..481e90a 100644 --- a/ug/network/src/ip_setting_view.cpp +++ b/ug/network/src/ip_setting_view.cpp @@ -28,6 +28,7 @@ #include "util.h" #include "WifiMgr.h" +#include "NetConMgr.h" #define KEY_PRIV "priv" @@ -90,14 +91,12 @@ struct _priv { enum connection_setting_enum cur_type; enum network_type_enum network_type; - connection_h connection; - connection_profile_h profile; - wifi_ap_h ap; char name[MAX_NAME_SIZE]; CWifiMgr *pWifiMgr; + CNetConMgr *pNetConMgr; }; static void _show_confirm_popup(struct _priv *priv); @@ -274,21 +273,17 @@ static int _get_cur_mode(struct _priv *priv) static int _get_connection_profile_info(struct _priv *priv) { struct connection_info info; - int ret; if (!priv) { _ERR("the param is invalid."); return RET_FAILED; } - ret = connection_mgr_get_profile_info(priv->connection, &info); - if (ret != RET_SUCCESS) { + if(!priv->pNetConMgr->GetProfileName(info.name)) { _ERR("connection_mgr_get_profile_info() failed."); return RET_FAILED; } - priv->profile = info.profile; - return RET_SUCCESS; } @@ -319,10 +314,21 @@ static int _get_cur_ip_info(struct _priv *priv) if (priv->network_type == TYPE_WIRED) { if (priv->ip_mode == MODE_AUTO) { - ret = connection_mgr_get_ip_info(priv->profile, &info); - if (ret != RET_SUCCESS) { + if (!priv->pNetConMgr->GetIpAddr(info.ip_addr)) { _ERR("connection_mgr_get_ip_info() failed."); - return ret; + return RET_FAILED; + } + if (!priv->pNetConMgr->GetSubnetMask(info.submask)) { + _ERR("connection_mgr_get_ip_info() failed."); + return RET_FAILED; + } + if (!priv->pNetConMgr->GetGateway(info.gateway)) { + _ERR("connection_mgr_get_ip_info() failed."); + return RET_FAILED; + } + if (!priv->pNetConMgr->GetDNS(info.dns)) { + _ERR("connection_mgr_get_ip_info() failed."); + return RET_FAILED; } } else if (priv->ip_mode == MODE_MAN) { ret = vconf_mgr_get_wired_network_info(&info); @@ -2063,9 +2069,19 @@ static int _config_network_manually(struct _priv *priv) switch (priv->network_type) { case TYPE_WIRED: - ret = connection_mgr_set_profile(priv->connection, - priv->profile, &priv->info); - if (ret != RET_SUCCESS) { + if (!priv->pNetConMgr->SetIpAddr(priv->info.ip_addr)) { + _ERR("set profile failed."); + return ret; + } + if (!priv->pNetConMgr->SetSubnetMask(priv->info.submask)) { + _ERR("set profile failed."); + return ret; + } + if (!priv->pNetConMgr->SetGateway(priv->info.gateway)) { + _ERR("set profile failed."); + return ret; + } + if (!priv->pNetConMgr->SetDNS(priv->info.dns)) { _ERR("set profile failed."); return ret; } @@ -2135,9 +2151,7 @@ static int _config_network_dynamic(struct _priv *priv) switch (priv->network_type) { case TYPE_WIRED: - ret = connection_mgr_ip_dynamic_config(priv->connection, - priv->profile); - if (ret != RET_SUCCESS) { + if(!priv->pNetConMgr->SetIpConfType(CONNECTION_IP_CONFIG_TYPE_DYNAMIC)) { _ERR("connection_mgr_ip_dynamic_config() failed."); return RET_FAILED; } @@ -2561,8 +2575,10 @@ static Evas_Object *_create(struct viewmgr *vmgr, void *data) priv->ug = vmgr->ug; priv->vmgr = vmgr; + priv->pNetConMgr = CNetConMgr::GetInstance(); + ASSERT(priv->pNetConMgr); + info = (struct connection_info *) data; - priv->connection = info->connection; priv->network_type = info->cur_type; priv->ap = info->ap; strncpy(priv->name, info->name, MAX_NAME_SIZE - 1); diff --git a/ug/network/src/main_view.cpp b/ug/network/src/main_view.cpp index 4effc56..3837878 100644 --- a/ug/network/src/main_view.cpp +++ b/ug/network/src/main_view.cpp @@ -21,13 +21,13 @@ #include "main_view.h" #include "vconf_mgr.h" #include "ip_setting_view.h" -#include "connection_mgr.h" #include "i18n.h" #include "common.h" #include "wifi_passcode_view.h" #include "util.h" #include "WifiMgr.h" +#include "NetConMgr.h" #define BTN_ACT 4 #define BTN_TYPE 2 @@ -81,8 +81,6 @@ struct _priv { Eina_Bool wifi_conn; Eina_Bool wired_conn; - connection_h connection; - connection_profile_h profile; char profile_name[MAX_NAME_SIZE]; wifi_ap_h ap; @@ -90,6 +88,7 @@ struct _priv { char *ap_pwd; CWifiMgr *pWifiMgr; + CNetConMgr *pNetConMgr; }; static void _show_confirm_popup(struct _priv *priv); @@ -145,7 +144,10 @@ static void _fini_priv(struct _priv *priv) if (priv->timer) ecore_timer_del(priv->timer); - connection_mgr_destroy(priv->connection); + if(priv->pNetConMgr) { + CNetConMgr::Finalize(); + priv->pNetConMgr = NULL; + } if (priv->ap) { @@ -503,34 +505,6 @@ static void _set_action_btn_pos(struct _priv *priv) } /** -* Get the connection profile infomation -* -* @param[in] priv _priv object bypassed -* @return 0 on success,otherwise -1 -*/ -static int _get_connection_profile_info(struct _priv *priv) -{ - struct connection_info info; - int ret; - - if (!priv) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - ret = connection_mgr_get_profile_info(priv->connection, &info); - if (ret != RET_SUCCESS) { - _ERR("connection_mgr_get_profile_info() failed."); - return RET_FAILED; - } - - priv->profile = info.profile; - strncpy(priv->profile_name, info.name, MAX_NAME_SIZE - 1); - - return RET_SUCCESS; -} - -/** * Callback function to set content to list panel * * Depending on different ethernet, set corresponding connection state @@ -538,9 +512,7 @@ static int _get_connection_profile_info(struct _priv *priv) * * @param[in] priv _priv object bypassed */ -#if 0 -static void _connection_ethernet_state_callback( - connection_ethernet_cable_state_e state, void *data) +static void _connection_ethernet_state_callback(bool state, void *data) { struct _priv *priv; @@ -549,16 +521,16 @@ static void _connection_ethernet_state_callback( return; } - priv = data; + priv = (struct _priv *) data; if (priv->network_type != TYPE_WIRED) { _ERR("cur network type is wireless, return."); return; } - if (state == CONNECTION_ETHERNET_CABLE_ATTACHED) { + if (state == true) { // ethernet connected _fill_content_part(priv, priv->wired_con_box); - } else if (state == CONNECTION_ETHERNET_CABLE_DETACHED) { + } else { _fill_content_part(priv, priv->wired_discon_ly); priv->wired_conn = EINA_FALSE; @@ -566,7 +538,6 @@ static void _connection_ethernet_state_callback( _set_action_btn_pos(priv); } -#endif /** * Initialize the connection information @@ -576,33 +547,29 @@ static void _connection_ethernet_state_callback( */ static int _init_connection(struct _priv *priv) { - int ret = RET_FAILED; - if (!priv) { _ERR("the param is invalid."); return RET_FAILED; } - priv->connection = connection_mgr_create(); - if (!priv->connection) { - _ERR("connection_mgr_create() failed."); + if(!CNetConMgr::Initialize()) { + _ERR("the param is invalid."); return RET_FAILED; } -#if 0 - ret = connection_mgr_register_ethernet_state_cb - (priv->connection, - _connection_ethernet_state_callback, - priv); - if (ret != RET_SUCCESS) { - _ERR("register_ethernet_state_cb() failed."); + priv->pNetConMgr = CNetConMgr::GetInstance(); + if (!priv->pNetConMgr) { + _ERR("Fail to get instance"); return RET_FAILED; } -#endif - ret = _get_connection_profile_info(priv); - if (ret != RET_SUCCESS) { - _ERR("_get_connection_profile_info() failed."); + if(!priv->pNetConMgr->GetProfileName(priv->profile_name)) { + _ERR("Fail to get instance"); + return RET_FAILED; + } + + if(!priv->pNetConMgr->RegisterIpChangedCallback( _connection_ethernet_state_callback, priv)) { + _ERR("register_ethernet_state_cb() failed."); return RET_FAILED; } @@ -731,8 +698,7 @@ static int _create_wired_connect_part(struct _priv *priv) */ static int _display_wired_setting(struct _priv *priv) { - Eina_Bool plugin; - int ret; + bool plugin; if (!priv) { _ERR("the param is invalid."); @@ -743,11 +709,9 @@ static int _display_wired_setting(struct _priv *priv) _create_wired_disconnect_part(priv); - ret = connection_mgr_get_ethernet_state(priv->connection, - &plugin); - if (ret != RET_SUCCESS) { + if(!priv->pNetConMgr->GetEthernetState(&plugin)) { _ERR("connection_mgr_get_ethernet_state() failed."); - plugin = EINA_FALSE; + plugin = false; } if (plugin) { @@ -1721,9 +1685,7 @@ static const char *_convert_error_to_string(connection_error_e err_type) * @param[in] result the connection error type * @param[in] data the user data */ -#if 0 -static void _connection_get_is_online_async_cb( - connection_error_e result, void *data) +static void _connection_get_is_online_async_cb( bool state, void *data) { struct _priv *priv; @@ -1732,11 +1694,10 @@ static void _connection_get_is_online_async_cb( return; } - priv = data; + priv = (struct _priv *) data; - if (result != CONNECTION_ERROR_NONE) { - _ERR("connection result: %s.", - _convert_error_to_string(result)); + if (state != true) { + _ERR("connection result"); _show_confirm_popup(priv); } else { ug_destroy_me(priv->ug); @@ -1749,34 +1710,29 @@ static void _connection_get_is_online_async_cb( * @param[in] result the connection error type * @param[in] data the user data */ -static void _connection_check_gateway_async_cb( - connection_error_e result, void *data) +static void _connection_check_gateway_async_cb(bool state, void *data) { struct _priv *priv; - int ret; + bool ret; if (!data) { _ERR("the param is invalid."); return; } - priv = data; + priv = (struct _priv *) data; - if (result != CONNECTION_ERROR_NONE) { - _ERR("connection result: %s.", - _convert_error_to_string(result)); + if (state != true) { + _ERR("connection disconnected"); _show_confirm_popup(priv); } else { - ret = connection_mgr_get_is_online_async(priv->connection, - _connection_get_is_online_async_cb, - (void *)priv); - if (ret != RET_SUCCESS) { + ret = priv->pNetConMgr->RegisterIpChangedCallback( _connection_get_is_online_async_cb, (void *)priv); + if (ret != true) { _ERR("connection_mgr_get_is_online_async() failed."); return; } } } -#endif /** * Write the connection information saved last time to the profile @@ -1801,12 +1757,12 @@ static int _connection_set_last_network(struct _priv *priv) return ret; } + bool result = false; if (ip_mode == MODE_AUTO) { - ret = connection_mgr_ip_dynamic_config(priv->connection, - priv->profile); - if (ret != RET_SUCCESS) { + result = priv->pNetConMgr->SetIpConfType(CONNECTION_IP_CONFIG_TYPE_DYNAMIC); + if (result != true) { _ERR("connection_mgr_ip_dynamic_config() failed."); - return ret; + return RET_FAILED; } } else { ret = vconf_mgr_get_wired_network_info(&info); @@ -1814,13 +1770,6 @@ static int _connection_set_last_network(struct _priv *priv) _ERR("vconf_mgr_get_wired_network_info() failed."); return ret; } - - ret = connection_mgr_set_profile(priv->connection, - priv->profile, &info); - if (ret != RET_SUCCESS) { - _ERR("set profile failed."); - return ret; - } } return RET_SUCCESS; @@ -1843,7 +1792,11 @@ static int _wired_connect_proc(struct _priv *priv) _show_progress_popup(priv); - _get_connection_profile_info(priv); + priv->pNetConMgr->RefreshEthernetProfile(); + if(!priv->pNetConMgr->GetProfileName(priv->profile_name)) { + _ERR("Fail to get profile name"); + return RET_FAILED; + } ret = _connection_set_last_network(priv); if (ret != RET_SUCCESS) { @@ -1851,15 +1804,12 @@ static int _wired_connect_proc(struct _priv *priv) return ret; } - _DBG("Not Yet"); -#if 0 - ret = connection_mgr_check_gateway_async(priv->profile, - _connection_check_gateway_async_cb, (void *)priv); - if (ret != RET_SUCCESS) { + bool result = false; + result = priv->pNetConMgr->RegisterIpChangedCallback( _connection_check_gateway_async_cb, (void *)priv); + if (result != true) { _ERR("connection_mgr_get_is_online_async() failed."); - return ret; + return RET_FAILED; } -#endif return RET_SUCCESS; } @@ -2237,7 +2187,6 @@ static void _other_btn_clicked_cb(void *data, priv->cur_view = NETWORK_IP_SETTING_VIEW; info.cur_type = priv->network_type; - info.connection = priv->connection; if (priv->network_type == TYPE_WIRED) { strncpy(info.name, priv->profile_name, diff --git a/ug/proxy/include/common.h b/ug/proxy/include/common.h deleted file mode 100644 index ceaf2dc..0000000 --- a/ug/proxy/include/common.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __PROXY_COMMON_H__ -#define __PROXY_COMMON_H__ - -#define MOTHED_STRING_LEN 15 -#define IP_STRING_LEN 15 -#define MOTHED_URL_LEN 100 -#define STRING_MAX_LEN 100 -#define METHOD_NUM 3 - -#define IP_ZERO "0.0.0.0" -#define URL_BLANK "" - -#endif /* __PROXY_COMMON_H__ */ diff --git a/ug/proxy/include/defs.h b/ug/proxy/include/defs.h index abfcb00..576cebd 100644 --- a/ug/proxy/include/defs.h +++ b/ug/proxy/include/defs.h @@ -17,6 +17,16 @@ #ifndef __DEFS_H__ #define __DEFS_H__ +/* Common */ +#define MOTHED_STRING_LEN 15 +#define IP_STRING_LEN 15 +#define MOTHED_URL_LEN 100 +#define STRING_MAX_LEN 100 +#define METHOD_NUM 3 + +#define IP_ZERO "0.0.0.0" +#define URL_BLANK "" + #define ELM_SCALE elm_config_scale_get() #define RET_SUCCESS 0 diff --git a/ug/proxy/include/main_view.h b/ug/proxy/include/main_view.h index 8f7a1f4..c6e8170 100644 --- a/ug/proxy/include/main_view.h +++ b/ug/proxy/include/main_view.h @@ -17,8 +17,6 @@ #ifndef __MAIN_VIEW_H__ #define __MAIN_VIEW_H__ -#include - Evas_Object *create_main_view(Evas_Object *win, ui_gadget_h ug); void destroy_main_view(Evas_Object *base); diff --git a/ug/proxy/src/main_view.cpp b/ug/proxy/src/main_view.cpp index 6db110d..510f151 100644 --- a/ug/proxy/src/main_view.cpp +++ b/ug/proxy/src/main_view.cpp @@ -22,7 +22,6 @@ #include "main_view.h" #include "i18n.h" #include "util.h" -#include "common.h" #include "UgCommon.h" #include "WifiMgr.h" diff --git a/ug/src/NetConMgr.cpp b/ug/src/NetConMgr.cpp index 68e96a3..cefce3d 100644 --- a/ug/src/NetConMgr.cpp +++ b/ug/src/NetConMgr.cpp @@ -1,12 +1,118 @@ #include "dbg.h" #include "NetConMgr.h" +#define IP_STRING_MAX_SIZE 20 +#define MAX_NAME_SIZE 256 +#define CONTENT_TXT_SIZE 500 +#define ZERO_IP "0.0.0.0" + CNetConMgr *CNetConMgr::instance = NULL; struct SNetConMgr { connection_h handle; + connection_profile_h ethernet_profile_h; + void(*ip_changed_cb)(bool change_state, void *data); }; + +void CNetConMgr::sm_CbIpAddrChanged(const char *ipv4, const char *ipv6, void* data) +{ + _DBG("IP addr is changed!! [IPv4:%s] [IPv6:%s]", ipv4, ipv6); + + CNetConMgr::GetInstance()->m_OnIpAddrChanged(data); +} + + +void CNetConMgr::m_OnIpAddrChanged(void *data) +{ + if(m->ip_changed_cb) + m->ip_changed_cb(true, data); +} + + +void CNetConMgr::sm_CbProfileStateChanged(connection_profile_state_e state, void *data) +{ + + _DBG("Profile is changed!!!!!!!!!!!!!!!!!!!!!!!!!"); + + /* TODO : check the flow again */ + CNetConMgr::GetInstance()->RefreshEthernetProfile(); +} + + +bool CNetConMgr::m_GetEthernetProfile(void) +{ + ASSERT(m); + + connection_profile_iterator_h iter = NULL; + connection_profile_h profile = NULL; + connection_profile_type_e type; + + int ret; + char name[MAX_NAME_SIZE] = {0}; + + ret = connection_get_profile_iterator(m->handle, CONNECTION_ITERATOR_TYPE_REGISTERED, &iter); + if (ret != CONNECTION_ERROR_NONE) { + _ERR("Fail to get profile iterator: %s", GetErrorMsg((connection_error_e) ret)); + return false; + } + + /* TODO : check whether to use do ~ while */ + while (connection_profile_iterator_has_next(iter)) { + if (connection_profile_iterator_next(iter, &profile) != CONNECTION_ERROR_NONE) { + _ERR("Fail to get profile handle"); + return false; + } + + ASSERT(profile); /* weird, profile should be existed */ + + if (connection_profile_get_type(profile, &type) != CONNECTION_ERROR_NONE) { + _ERR("Fail to get profile type"); + return false; + } + + if (type == CONNECTION_PROFILE_TYPE_ETHERNET) + { + /* FIXME : should check when tere are many same profiles. */ + m->ethernet_profile_h = profile; + GetProfileName(name); + _DBG("GetProfileName = %s", name); + } + } + + ret = connection_destroy_profile_iterator(iter); + if (ret != CONNECTION_ERROR_NONE) { + _ERR("Fail to get profile iterator: %s", GetErrorMsg((connection_error_e) ret)); + return false; + } + + /* FIXME:API return wrong parameter */ + ret = connection_profile_set_state_changed_cb( m->ethernet_profile_h, sm_CbProfileStateChanged, (void *)instance); + if (ret != CONNECTION_ERROR_NONE) { + _ERR("connection_profile_set_state_changed_cb() failed."); + return false; + } + + return true; +} + + +bool CNetConMgr::m_UpdateProfile(void) +{ + ASSERT(m); + + int ret = -1; + + ret = connection_update_profile( m->handle, m->ethernet_profile_h); + if (ret != CONNECTION_ERROR_NONE) { + _ERR("connection_update_profile failed"); + return false; + } + + return true; +} + + bool CNetConMgr::Initialize(void) { ASSERT(!instance); @@ -21,7 +127,6 @@ bool CNetConMgr::Initialize(void) if(!instance->m) { _ERR("Fail to allocate memory"); delete (instance); - instance = NULL; return false; } @@ -35,13 +140,19 @@ bool CNetConMgr::Initialize(void) return false; } + if(!instance->m_GetEthernetProfile()) { + _ERR("Fail to get ethernet_profile"); + } + return true; } void CNetConMgr::Finalize(void) { - ASSERT(instance); + if(!instance) + return; + ASSERT(instance->m); int ret = 0; @@ -62,66 +173,275 @@ CNetConMgr *CNetConMgr::GetInstance(void) } -bool CNetConMgr::GetProfileInfo(connection_profile_h out_profile) +void CNetConMgr::RefreshEthernetProfile(void) { ASSERT(m); - connection_profile_iterator_h iter = NULL; - connection_profile_h profile = NULL; - connection_profile_type_e type; + if(!m_GetEthernetProfile()) { + _ERR("Fail to get ethernet_profile"); + } +} + + +bool CNetConMgr::GetEthernetState(bool *out_state) +{ + ASSERT(m); + + int ret = -1; + connection_ethernet_state_e state; + + if (!out_state) { + _ERR("the param is invalid."); + return false; + } + + ret = connection_get_ethernet_state(m->handle, &state); + if (ret != CONNECTION_ERROR_NONE) { + _ERR("connection_get_ethernet_state() failed."); + return false; + } + + if (state == CONNECTION_ETHERNET_STATE_DEACTIVATED) + *out_state = false; + else + *out_state = true; + + return true; +} + + +bool CNetConMgr::GetProfileName(char *out_name) +{ + ASSERT(m); char *name; - int ret; - if (!out_profile) { - _ERR("param is NULL."); + if(!m->ethernet_profile_h) { + _ERR("There is no ethernet profile Try to call RefreshEthernetProfile()"); return false; } - ret = connection_get_profile_iterator(m->handle, CONNECTION_ITERATOR_TYPE_REGISTERED, &iter); + if (connection_profile_get_name(m->ethernet_profile_h, &name) != CONNECTION_ERROR_NONE) { + _ERR("Fail to get profile name\n"); + return false; + } + + strncpy(out_name, name, MAX_NAME_SIZE - 1); + + delete (name); +} + + +bool CNetConMgr::IsConnected(void) +{ + ASSERT(m); + + int ret; + connection_ethernet_state_e state; + + ret = connection_get_ethernet_state(m->handle, &state); + if (ret == CONNECTION_ERROR_NONE && state == CONNECTION_ETHERNET_STATE_CONNECTED) + return true; + + return false; +} + + +bool CNetConMgr::SetIpConfType(connection_ip_config_type_e type) +{ + ASSERT(m); + + if(!m_UpdateProfile()) return false; + + int ret = -1; + + ret = connection_profile_set_ip_config_type( m->ethernet_profile_h, CONNECTION_ADDRESS_FAMILY_IPV4, type); if (ret != CONNECTION_ERROR_NONE) { - _ERR("Fail to get profile iterator: %s", GetErrorMsg((connection_error_e) ret)); + _ERR("connection_profile_set_ip_config_type() failed."); return false; } - while (connection_profile_iterator_has_next(iter)) { - if (connection_profile_iterator_next(iter, &profile) != CONNECTION_ERROR_NONE) { - _ERR("Fail to get profile handle"); - return false; - } + if(!m_UpdateProfile()) return false; - ASSERT(profile); /* weird */ + return true; +} - if (connection_profile_get_type(profile, &type) != CONNECTION_ERROR_NONE) { - _ERR("Fail to get profile type"); - return false; - } - if (type == CONNECTION_PROFILE_TYPE_ETHERNET) - out_profile = profile; +bool CNetConMgr::SetIpAddr(char *ip) +{ + ASSERT(m); + + if(!m_UpdateProfile()) return false; + if(!SetIpConfType(CONNECTION_IP_CONFIG_TYPE_STATIC)) return false; + + int ret = -1; + ret = connection_profile_set_ip_address( m->ethernet_profile_h, CONNECTION_ADDRESS_FAMILY_IPV4, ip); + if (ret != CONNECTION_ERROR_NONE) { + _ERR("connection_profile_set_ip_address() failed."); + return false; } - /* TODO : should check when tere are many same profiles. */ + if(!m_UpdateProfile()) return false; return true; } -bool CNetConMgr::SetProxyType(EProxyMethod method) +bool CNetConMgr::SetSubnetMask(char *submask) { ASSERT(m); - connection_profile_h profile = NULL; - connection_proxy_type_e type; + if(!m_UpdateProfile()) return false; + if(!SetIpConfType(CONNECTION_IP_CONFIG_TYPE_STATIC)) return false; - int ret; + int ret = -1; + ret = connection_profile_set_subnet_mask( m->ethernet_profile_h, CONNECTION_ADDRESS_FAMILY_IPV4, submask); + if (ret != CONNECTION_ERROR_NONE) { + _ERR("fail to set_subnet_mask"); + return false; + } + + if(!m_UpdateProfile()) return false; +} + + +bool CNetConMgr::SetGateway(char *gateway) +{ + ASSERT(m); + + if(!m_UpdateProfile()) return false; + if(!SetIpConfType(CONNECTION_IP_CONFIG_TYPE_STATIC)) return false; + + int ret = -1; + ret = connection_profile_set_gateway_address( m->ethernet_profile_h, CONNECTION_ADDRESS_FAMILY_IPV4, gateway); + if (ret != CONNECTION_ERROR_NONE) { + _ERR("fail to set_gateway_address"); + return false; + } + + if(!m_UpdateProfile()) return false; +} + + +bool CNetConMgr::SetDNS(char *dns) +{ + ASSERT(m); - ret = GetProfileInfo(profile); + if(!m_UpdateProfile()) return false; + if(!SetIpConfType(CONNECTION_IP_CONFIG_TYPE_STATIC)) return false; + + int ret = -1; + ret = connection_profile_set_dns_address( m->ethernet_profile_h, 1, CONNECTION_ADDRESS_FAMILY_IPV4, dns); if (ret != CONNECTION_ERROR_NONE) { - _ERR("GetProfileInfo() failed"); + _ERR("fail to set_dns_address"); return false; } + if(!m_UpdateProfile()) return false; +} + + +bool CNetConMgr::GetIpAddr(char *ip) +{ + ASSERT(m); + + if(!ip) { + _ERR("Invalid parameter"); + return false; + } + + char *str_value; + + if (connection_profile_get_ip_address( m->ethernet_profile_h, CONNECTION_ADDRESS_FAMILY_IPV4, &str_value) != CONNECTION_ERROR_NONE) { + _ERR("Fail to get IP address!"); + strncpy(ip, ZERO_IP, IP_STRING_MAX_SIZE); + } else { + strncpy(ip, str_value, IP_STRING_MAX_SIZE); + delete(str_value); + } + + return true; +} + + +bool CNetConMgr::GetSubnetMask(char *submask) +{ + ASSERT(m); + + if(!submask) { + _ERR("Invalid parameter"); + return false; + } + + char *str_value; + if (connection_profile_get_subnet_mask( m->ethernet_profile_h, CONNECTION_ADDRESS_FAMILY_IPV4, &str_value) != CONNECTION_ERROR_NONE) { + _ERR("Fail to get subnet mask!"); + strncpy(submask, ZERO_IP, IP_STRING_MAX_SIZE); + } else { + strncpy(submask, str_value, IP_STRING_MAX_SIZE); + delete(str_value); + } + + return true; +} + + +bool CNetConMgr::GetGateway(char *gateway) +{ + ASSERT(m); + + if(!gateway) { + _ERR("Invalid parameter"); + return false; + } + + char *str_value; + if (connection_profile_get_gateway_address( m->ethernet_profile_h, CONNECTION_ADDRESS_FAMILY_IPV4, &str_value) != CONNECTION_ERROR_NONE) { + _ERR("Fail to get gateway!"); + strncpy(gateway, ZERO_IP, IP_STRING_MAX_SIZE); + } else { + strncpy(gateway, str_value, IP_STRING_MAX_SIZE); + delete(str_value); + } + + return true; +} + + +bool CNetConMgr::GetDNS(char *dns) +{ + ASSERT(m); + + if(!dns) { + _ERR("Invalid parameter"); + return false; + } + + char *str_value; + if (connection_profile_get_dns_address( m->ethernet_profile_h, 1, CONNECTION_ADDRESS_FAMILY_IPV4, &str_value) != CONNECTION_ERROR_NONE) { + _ERR("Fail to get DNS1!"); + strncpy(dns, ZERO_IP, IP_STRING_MAX_SIZE); + } else { + strncpy(dns, str_value, IP_STRING_MAX_SIZE); + delete(str_value); + } + + return true; +} + + +bool CNetConMgr::SetProxyType(EProxyMethod method) +{ + ASSERT(m); + if(!m->ethernet_profile_h) { + _ERR("There is no ethernet profile Try to call RefreshEthernetProfile()"); + return false; + } + + connection_proxy_type_e type; + + int ret; + switch (method) { case PROXY_METHOD_NONE: type = CONNECTION_PROXY_TYPE_DIRECT; @@ -136,7 +456,7 @@ bool CNetConMgr::SetProxyType(EProxyMethod method) return false; } - ret = connection_profile_set_proxy_type(profile, type); + ret = connection_profile_set_proxy_type( m->ethernet_profile_h, type); if (ret != CONNECTION_ERROR_NONE) { _ERR("connection_profile_set_proxy_type() failed"); return false; @@ -149,8 +469,11 @@ bool CNetConMgr::SetProxyType(EProxyMethod method) bool CNetConMgr::GetProxyType(EProxyMethod *method) { ASSERT(m); + if(!m->ethernet_profile_h) { + _ERR("There is no ethernet profile Try to call RefreshEthernetProfile()"); + return false; + } - connection_profile_h profile = NULL; connection_proxy_type_e type; int ret; @@ -160,13 +483,7 @@ bool CNetConMgr::GetProxyType(EProxyMethod *method) return false; } - ret = GetProfileInfo(profile); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("GetProfileInfo() failed"); - return false; - } - - ret = connection_profile_get_proxy_type(profile, &type); + ret = connection_profile_get_proxy_type( m->ethernet_profile_h, &type); if (ret != CONNECTION_ERROR_NONE) { _ERR("connection_profile_get_proxy_type() failed"); return false; @@ -193,18 +510,14 @@ bool CNetConMgr::GetProxyType(EProxyMethod *method) bool CNetConMgr::SetProxyAddr(char *ip) { ASSERT(m); - - connection_profile_h profile; - int ret; - - profile = NULL; - ret = GetProfileInfo(profile); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("GetProfileInfo() failed"); + if(!m->ethernet_profile_h) { + _ERR("There is no ethernet profile Try to call RefreshEthernetProfile()"); return false; } - ret = connection_profile_set_proxy_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, ip); + int ret; + + ret = connection_profile_set_proxy_address( m->ethernet_profile_h, CONNECTION_ADDRESS_FAMILY_IPV4, ip); if (ret != CONNECTION_ERROR_NONE) { _ERR("connection_profile_set_proxy_address() failed"); return false; @@ -217,8 +530,11 @@ bool CNetConMgr::SetProxyAddr(char *ip) bool CNetConMgr::GetProxyAddr(char *ip) { ASSERT(m); + if(!m->ethernet_profile_h) { + _ERR("There is no ethernet profile Try to call RefreshEthernetProfile()"); + return false; + } - connection_profile_h profile; int ret; char *str; @@ -227,21 +543,13 @@ bool CNetConMgr::GetProxyAddr(char *ip) return false; } - profile = NULL; - ret = GetProfileInfo(profile); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("GetProfileInfo() failed"); - return false; - } - - ret = connection_profile_get_proxy_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &str); + ret = connection_profile_get_proxy_address( m->ethernet_profile_h, CONNECTION_ADDRESS_FAMILY_IPV4, &str); if (ret != CONNECTION_ERROR_NONE) { _ERR("connection_profile_get_proxy_address() failed"); return false; } - /* FIXME : hardcoding */ - strncpy(ip, str, 20); + strncpy(ip, str, IP_STRING_MAX_SIZE ); delete (str); return true; @@ -286,3 +594,19 @@ const char *CNetConMgr::GetErrorMsg(connection_error_e err) return "Unknown"; } + +bool CNetConMgr::RegisterIpChangedCallback(void(*ip_changed_cb)(bool connected, void *data), void *data) +{ + ASSERT(m); + + int ret = -1; + + ret = connection_set_ip_address_changed_cb( m->handle, sm_CbIpAddrChanged, data); + if (ret != CONNECTION_ERROR_NONE) { + _ERR("connection_set_ip_address_changed_cb() failed."); + return false; + } + m->ip_changed_cb = ip_changed_cb; + + return true; +} -- 2.7.4 From 9f994ff1cc44beb523cc34176876742f08a18ec6 Mon Sep 17 00:00:00 2001 From: JuWan Kim Date: Mon, 23 Mar 2015 11:47:47 +0900 Subject: [PATCH 08/16] Fix launch bug * Remove iter destroy code. Change-Id: Ie8c1fc4910b852c3d84f096b2887be7d806231dc --- ug/src/NetConMgr.cpp | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/ug/src/NetConMgr.cpp b/ug/src/NetConMgr.cpp index cefce3d..19641c1 100644 --- a/ug/src/NetConMgr.cpp +++ b/ug/src/NetConMgr.cpp @@ -45,7 +45,6 @@ bool CNetConMgr::m_GetEthernetProfile(void) ASSERT(m); connection_profile_iterator_h iter = NULL; - connection_profile_h profile = NULL; connection_profile_type_e type; int ret; @@ -57,36 +56,35 @@ bool CNetConMgr::m_GetEthernetProfile(void) return false; } - /* TODO : check whether to use do ~ while */ while (connection_profile_iterator_has_next(iter)) { - if (connection_profile_iterator_next(iter, &profile) != CONNECTION_ERROR_NONE) { + + m->ethernet_profile_h = NULL; + + if (connection_profile_iterator_next(iter, &m->ethernet_profile_h) != CONNECTION_ERROR_NONE) { _ERR("Fail to get profile handle"); - return false; + break; } - ASSERT(profile); /* weird, profile should be existed */ - - if (connection_profile_get_type(profile, &type) != CONNECTION_ERROR_NONE) { + if (connection_profile_get_type(m->ethernet_profile_h, &type) != CONNECTION_ERROR_NONE) { _ERR("Fail to get profile type"); - return false; + break; } if (type == CONNECTION_PROFILE_TYPE_ETHERNET) { - /* FIXME : should check when tere are many same profiles. */ - m->ethernet_profile_h = profile; - GetProfileName(name); - _DBG("GetProfileName = %s", name); + /* FIXME : should check when there are same ethernet profiles. */ + break; } } - ret = connection_destroy_profile_iterator(iter); - if (ret != CONNECTION_ERROR_NONE) { - _ERR("Fail to get profile iterator: %s", GetErrorMsg((connection_error_e) ret)); + if(!m->ethernet_profile_h) { + _ERR("ethernet_profile_h is NULL"); return false; } - /* FIXME:API return wrong parameter */ + GetProfileName(name); + _DBG("GetProfileName = %s", name); + ret = connection_profile_set_state_changed_cb( m->ethernet_profile_h, sm_CbProfileStateChanged, (void *)instance); if (ret != CONNECTION_ERROR_NONE) { _ERR("connection_profile_set_state_changed_cb() failed."); -- 2.7.4 From b9048ee9758337f74d14b7fe46e0b732f3a54b6a Mon Sep 17 00:00:00 2001 From: JuWan Kim Date: Mon, 23 Mar 2015 14:52:10 +0900 Subject: [PATCH 09/16] Remove vconf_mgr in /ug/network Change-Id: Ia54013cdd765573d120ce99ced29565fe2aeb7e7 Signed-off-by: JuWan Kim --- ug/network/CMakeLists.txt | 1 - ug/network/include/defs.h | 16 ++ ug/network/include/ip_setting_view.h | 3 - ug/network/include/vconf_mgr.h | 38 --- ug/network/include/wifi_passcode_view.h | 5 - ug/network/src/ip_setting_view.cpp | 129 ++++++---- ug/network/src/main_view.cpp | 111 +++------ ug/network/src/vconf_mgr.cpp | 404 -------------------------------- ug/network/src/wifi_passcode_view.cpp | 1 + 9 files changed, 137 insertions(+), 571 deletions(-) delete mode 100644 ug/network/include/vconf_mgr.h delete mode 100644 ug/network/src/vconf_mgr.cpp diff --git a/ug/network/CMakeLists.txt b/ug/network/CMakeLists.txt index 2357079..0095541 100644 --- a/ug/network/CMakeLists.txt +++ b/ug/network/CMakeLists.txt @@ -49,7 +49,6 @@ SET(SRCS src/main_view.cpp src/network_viewmgr.cpp src/ip_setting_view.cpp - src/vconf_mgr.cpp src/util.cpp src/wifi_passcode_view.cpp ../src/WifiMgr.cpp diff --git a/ug/network/include/defs.h b/ug/network/include/defs.h index ac78e4d..bf446db 100644 --- a/ug/network/include/defs.h +++ b/ug/network/include/defs.h @@ -163,4 +163,20 @@ #define DEFAULT_WIN_WIDTH 1920 #define DEFAULT_WIN_HEIGHT 1080 +/* vconf value */ +#define WIRED_DNS_LAST_MODE "db/menu/network/wired_dns_mode" +#define WIRED_IP_LAST_MODE "db/menu/network/wired_ip_mode" +#define WIRED_IP_KEY "db/menu/network/wired_ip" +#define WIRED_SUBMASK_KEY "db/menu/network/wired_subnet" +#define WIRED_GATEWAY_KEY "db/menu/network/wired_gateway" +#define WIRED_DNS_KEY "db/menu/network/wired_dns" + +#define WIRELESS_IP_LAST_MODE "db/menu/network/wireless_ip_mode" +#define WIRELESS_DNS_LAST_MODE "db/menu/network/wireless_dns_mode" +#define WIRELESS_IP_KEY "db/menu/network/wireless_ip" +#define WIRELESS_SUBMASK_KEY "db/menu/network/wireless_subnet" +#define WIRELESS_GATEWAY_KEY "db/menu/network/wireless_gateway" +#define WIRELESS_DNS_KEY "db/menu/network/wireless_dns" + +#define SELECTED_NETWORK_TYPE_KEY "db/menu/network/network_type" #endif /* __DEFS_H__ */ diff --git a/ug/network/include/ip_setting_view.h b/ug/network/include/ip_setting_view.h index 0e85c27..214c2f9 100644 --- a/ug/network/include/ip_setting_view.h +++ b/ug/network/include/ip_setting_view.h @@ -17,9 +17,6 @@ #ifndef __CONNECTION_VIEW_H__ #define __CONNECTION_VIEW_H__ -#include -#include "network_viewmgr.h" - struct view_class *ip_setting_view_vclass_get(void); #endif /* __CONNECTION_VIEW_H__ */ diff --git a/ug/network/include/vconf_mgr.h b/ug/network/include/vconf_mgr.h deleted file mode 100644 index 2d57b66..0000000 --- a/ug/network/include/vconf_mgr.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __VCONF_MGR_H__ -#define __VCONF_MGR_H__ - -#include -#include "common.h" - -int vconf_mgr_get_network_type(enum network_type_enum *network_type); -int vconf_mgr_set_network_type(enum network_type_enum network_type); -int vconf_mgr_get_wired_network_info(struct network_info *info); -int vconf_mgr_get_wireless_network_info(struct network_info *info); -int vconf_mgr_save_wired_config_info(struct network_info *info); -int vconf_mgr_save_wireless_config_info(struct network_info *info); -int vconf_mgr_get_wired_ip_mode(enum setting_mode *mode); -int vconf_mgr_set_wired_ip_mode(enum setting_mode mode); -int vconf_mgr_get_wired_dns_mode(enum setting_mode *mode); -int vconf_mgr_set_wired_dns_mode(enum setting_mode mode); -int vconf_mgr_get_wireless_ip_mode(enum setting_mode *mode); -int vconf_mgr_set_wireless_ip_mode(enum setting_mode mode); -int vconf_mgr_get_wireless_dns_mode(enum setting_mode *mode); -int vconf_mgr_set_wireless_dns_mode(enum setting_mode mode); - -#endif /* __VCONF_MGR_H__ */ diff --git a/ug/network/include/wifi_passcode_view.h b/ug/network/include/wifi_passcode_view.h index 0014947..525135c 100644 --- a/ug/network/include/wifi_passcode_view.h +++ b/ug/network/include/wifi_passcode_view.h @@ -17,11 +17,6 @@ #ifndef __WIFI_PASSWORD_VIEW_H__ #define __WIFI_PASSWORD_VIEW_H__ -#include -#include -#include -#include "network_viewmgr.h" - struct view_class *wifi_passcode_view_vclass_get(void); #endif /* __WIFI_PASSWORD_VIEW_H__ */ diff --git a/ug/network/src/ip_setting_view.cpp b/ug/network/src/ip_setting_view.cpp index 481e90a..7aea65a 100644 --- a/ug/network/src/ip_setting_view.cpp +++ b/ug/network/src/ip_setting_view.cpp @@ -21,7 +21,8 @@ #include "defs.h" #include "dbg.h" #include "ip_setting_view.h" -#include "vconf_mgr.h" +#include "network_viewmgr.h" +#include #include "i18n.h" #include "util.h" #include "common.h" @@ -102,6 +103,23 @@ struct _priv { static void _show_confirm_popup(struct _priv *priv); static void _popup_dismissed_cb(void *data, Evas_Object *obj, void *ev); +static void _get_ip_info(char *des, const char *key) +{ + const char *str; + + if (!des || !key) + return; + + str = vconf_get_str(key); + if (!str) + return; + + if (str == '\0' || !strncmp(str, NULL_STRING, IP_STRING_MAX_SIZE)) + strncpy(des, _(ZERO_IP), IP_STRING_MAX_SIZE); + else + strncpy(des, str, IP_STRING_MAX_SIZE); +} + /** * Initializes the private data. * @@ -238,22 +256,33 @@ static int _get_cur_mode(struct _priv *priv) return RET_FAILED; } + const char *str = NULL; if (priv->network_type == TYPE_WIRED) { - ret = vconf_mgr_get_wired_ip_mode(&priv->ip_mode); - if (ret != RET_SUCCESS) - _ERR("get wired ip mode from vconf failed."); + str = vconf_get_str(WIRED_IP_LAST_MODE); + if (str && !strcmp(str, _(TXT_OBTAIN_AUTO))) + priv->ip_mode = MODE_AUTO; + else + priv->ip_mode = MODE_MAN; - ret = vconf_mgr_get_wired_dns_mode(&priv->dns_mode); - if (ret != RET_SUCCESS) - _ERR("get wired dns mode from vconf failed."); + str = NULL; + str = vconf_get_str(WIRED_DNS_LAST_MODE); + if (str && !strcmp(str, _(TXT_OBTAIN_AUTO))) + priv->dns_mode = MODE_AUTO; + else + priv->dns_mode = MODE_MAN; } else if (priv->network_type == TYPE_WIRELESS) { - ret = vconf_mgr_get_wireless_ip_mode(&priv->ip_mode); - if (ret != RET_SUCCESS) - _ERR("get wireless ip mode from vconf failed."); + str = vconf_get_str(WIRELESS_IP_LAST_MODE); + if (str && !strcmp(str, _(TXT_OBTAIN_AUTO))) + priv->ip_mode = MODE_AUTO; + else + priv->ip_mode = MODE_MAN; - ret = vconf_mgr_get_wireless_dns_mode(&priv->dns_mode); - if (ret != RET_SUCCESS) - _ERR("get wireless dns mode from vconf failed."); + str = NULL; + str = vconf_get_str(WIRELESS_DNS_LAST_MODE); + if (str && !strcmp(str, _(TXT_OBTAIN_AUTO))) + priv->dns_mode = MODE_AUTO; + else + priv->dns_mode = MODE_MAN; } else { _ERR("the network type is invalid."); ret = RET_FAILED; @@ -331,11 +360,10 @@ static int _get_cur_ip_info(struct _priv *priv) return RET_FAILED; } } else if (priv->ip_mode == MODE_MAN) { - ret = vconf_mgr_get_wired_network_info(&info); - if (ret != RET_SUCCESS) { - _ERR("get wired network info failed."); - return ret; - } + _get_ip_info(info.ip_addr, WIRED_IP_KEY); + _get_ip_info(info.submask, WIRED_SUBMASK_KEY); + _get_ip_info(info.gateway, WIRED_GATEWAY_KEY); + _get_ip_info(info.dns, WIRED_DNS_KEY); } else { _ERR("ip mode is invalid."); return RET_FAILED; @@ -363,11 +391,10 @@ static int _get_cur_ip_info(struct _priv *priv) return RET_FAILED; } } else if (priv->ip_mode == MODE_MAN) { - ret = vconf_mgr_get_wireless_network_info(&info); - if (ret != RET_SUCCESS) { - _ERR("get wireless network info failed."); - return ret; - } + _get_ip_info(info.ip_addr, WIRELESS_IP_KEY); + _get_ip_info(info.submask, WIRELESS_SUBMASK_KEY); + _get_ip_info(info.gateway, WIRELESS_GATEWAY_KEY); + _get_ip_info(info.dns, WIRELESS_DNS_KEY); } else { _ERR("ip mode is invalid."); return RET_FAILED; @@ -2086,12 +2113,10 @@ static int _config_network_manually(struct _priv *priv) return ret; } - ret = vconf_mgr_save_wired_config_info(&priv->info); - if (ret != RET_SUCCESS) { - _ERR("saved wired ip info to vconf failed."); - return ret; - } - + vconf_set_str(WIRED_IP_KEY, priv->info.ip_addr); + vconf_set_str(WIRED_SUBMASK_KEY, priv->info.submask); + vconf_set_str(WIRED_GATEWAY_KEY, priv->info.gateway); + vconf_set_str(WIRED_DNS_KEY, priv->info.dns); break; case TYPE_WIRELESS: result = priv->pWifiMgr->SetIp(priv->ap, priv->info.ip_addr); @@ -2115,12 +2140,10 @@ static int _config_network_manually(struct _priv *priv) return RET_FAILED; } - ret = vconf_mgr_save_wireless_config_info(&priv->info); - if (ret != RET_SUCCESS) { - _ERR("saved wireless ip info to vconf failed."); - return ret; - } - + vconf_set_str(WIRELESS_IP_KEY, priv->info.ip_addr); + vconf_set_str(WIRELESS_SUBMASK_KEY, priv->info.submask); + vconf_set_str(WIRELESS_GATEWAY_KEY, priv->info.gateway); + vconf_set_str(WIRELESS_DNS_KEY, priv->info.dns); break; default: break; @@ -2188,23 +2211,35 @@ static void _save_mode(struct _priv *priv) switch (priv->network_type) { case TYPE_WIRED: - ret = vconf_mgr_set_wired_ip_mode(priv->ip_mode); - if (ret != RET_SUCCESS) - _ERR("vconf_mgr_set_wired_ip_mode() failed."); + if(priv->ip_mode == MODE_AUTO) { + vconf_set_str(WIRED_IP_LAST_MODE, _(TXT_OBTAIN_AUTO)); + } + else if(priv->ip_mode == MODE_MAN) { + vconf_set_str(WIRED_IP_LAST_MODE, _(TXT_ENTER_MAN)); + } - ret = vconf_mgr_set_wired_dns_mode(priv->dns_mode); - if (ret != RET_SUCCESS) - _ERR("vconf_mgr_set_wired_dns_mode() failed."); + if(priv->dns_mode == MODE_AUTO) { + vconf_set_str(WIRED_DNS_LAST_MODE, _(TXT_OBTAIN_AUTO)); + } + else if(priv->dns_mode == MODE_MAN) { + vconf_set_str(WIRED_DNS_LAST_MODE, _(TXT_ENTER_MAN)); + } break; case TYPE_WIRELESS: - ret = vconf_mgr_set_wireless_ip_mode(priv->ip_mode); - if (ret != RET_SUCCESS) - _ERR("vconf_mgr_set_wireless_ip_mode() failed."); + if(priv->ip_mode == MODE_AUTO) { + vconf_set_str(WIRELESS_IP_LAST_MODE, _(TXT_OBTAIN_AUTO)); + } + else if(priv->ip_mode == MODE_MAN) { + vconf_set_str(WIRELESS_IP_LAST_MODE, _(TXT_ENTER_MAN)); + } - ret = vconf_mgr_set_wireless_dns_mode(priv->dns_mode); - if (ret != RET_SUCCESS) - _ERR("vconf_mgr_set_wireless_dns_mode() failed."); + if(priv->dns_mode == MODE_AUTO) { + vconf_set_str(WIRELESS_DNS_LAST_MODE, _(TXT_OBTAIN_AUTO)); + } + else if(priv->dns_mode == MODE_MAN) { + vconf_set_str(WIRELESS_DNS_LAST_MODE, _(TXT_ENTER_MAN)); + } break; default: diff --git a/ug/network/src/main_view.cpp b/ug/network/src/main_view.cpp index 3837878..a83f300 100644 --- a/ug/network/src/main_view.cpp +++ b/ug/network/src/main_view.cpp @@ -19,12 +19,14 @@ #include "defs.h" #include "dbg.h" #include "main_view.h" -#include "vconf_mgr.h" #include "ip_setting_view.h" #include "i18n.h" #include "common.h" #include "wifi_passcode_view.h" #include "util.h" +#include +#include +#include "network_viewmgr.h" #include "WifiMgr.h" #include "NetConMgr.h" @@ -1323,13 +1325,13 @@ static void _type_select_btn_cb(void *data, priv->network_type = TYPE_WIRELESS; _display_wireless_setting(priv); - vconf_mgr_set_network_type(TYPE_WIRELESS); + vconf_set_str(SELECTED_NETWORK_TYPE_KEY, TXT_WIRELESS); } else if ((!strcmp(value, _(popup_button[TYPE_WIRED]))) && priv->network_type == TYPE_WIRELESS) { priv->network_type = TYPE_WIRED; _display_wired_setting(priv); - vconf_mgr_set_network_type(TYPE_WIRED); + vconf_set_str(SELECTED_NETWORK_TYPE_KEY, TXT_WIRED); } _refresh_network_type_text(priv); @@ -1617,65 +1619,6 @@ static int _wifi_connect_ap(struct _priv *priv, int index) return RET_SUCCESS; } -/** -* Convert connection error type code to the corresponding string -* -* @param[in] err_code the connection error type -* @return the error description string -*/ -#if 0 -static const char *_convert_error_to_string(connection_error_e err_type) -{ - switch (err_type) { - case CONNECTION_ERROR_NONE: - return "NONE"; - case CONNECTION_ERROR_INVALID_PARAMETER: - return "INVALID_PARAMETER"; - case CONNECTION_ERROR_OUT_OF_MEMORY: - return "OUT_OF_MEMORY"; - case CONNECTION_ERROR_INVALID_OPERATION: - return "INVALID_OPERATION"; - case CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED: - return "ADDRESS_FAMILY_NOT_SUPPORTED"; - case CONNECTION_ERROR_OPERATION_FAILED: - return "OPERATION_FAILED"; - case CONNECTION_ERROR_ITERATOR_END: - return "ITERATOR_END"; - case CONNECTION_ERROR_NO_CONNECTION: - return "NO_CONNECTION"; - case CONNECTION_ERROR_NOW_IN_PROGRESS: - return "NOW_IN_PROGRESS"; - case CONNECTION_ERROR_ALREADY_EXISTS: - return "ALREADY_EXISTS"; - case CONNECTION_ERROR_OPERATION_ABORTED: - return "OPERATION_ABORTED"; - case CONNECTION_ERROR_DHCP_FAILED: - return "DHCP_FAILED"; - case CONNECTION_ERROR_INVALID_KEY: - return "INVALID_KEY"; - case CONNECTION_ERROR_NO_REPLY: - return "NO_REPLY"; - case CONNECTION_ERROR_NO_KEYWORD: - return "NO_KEYWORD"; - case CONNECTION_ERROR_TCP_RST: - return "RST_IN_TCP_RESPONSE"; - case CONNECTION_ERROR_TCP_SYN_TIMEOUT: - return "TCP_SYN_TIMEOUT"; - case CONNECTION_ERROR_OFFLINE: - return "CONNECTION_OFFLINE"; - case CONNECTION_ERROR_NETWORK_MONITOR_FAILURE: - return "monitor failer"; - case CONNECTION_ERROR_INVALID_GATEWAY: - return "invalid gateway"; - case CONNECTION_ERROR_INVALID_MACADDRESS: - return "invalid mac addr"; - default: - break; - } - - return "Unknown"; -} -#endif /** * Callback function called by _connection_check_gateway_async_cb() @@ -1734,6 +1677,23 @@ static void _connection_check_gateway_async_cb(bool state, void *data) } } +static void _get_ip_info(char *des, const char *key) +{ + const char *str; + + if (!des || !key) + return; + + str = vconf_get_str(key); + if (!str) + return; + + if (str == '\0' || !strncmp(str, NULL_STRING, IP_STRING_MAX_SIZE)) + strncpy(des, _(ZERO_IP), IP_STRING_MAX_SIZE); + else + strncpy(des, str, IP_STRING_MAX_SIZE); +} + /** * Write the connection information saved last time to the profile * @@ -1751,11 +1711,12 @@ static int _connection_set_last_network(struct _priv *priv) return RET_FAILED; } - ret = vconf_mgr_get_wired_ip_mode(&ip_mode); - if (ret != RET_SUCCESS) { - _ERR("get wired ip mode from vconf failed."); - return ret; - } + const char *str = NULL; + str = vconf_get_str(WIRED_IP_LAST_MODE); + if (str && !strcmp(str, _(TXT_OBTAIN_AUTO))) + ip_mode = MODE_AUTO; + else + ip_mode = MODE_MAN; bool result = false; if (ip_mode == MODE_AUTO) { @@ -1765,11 +1726,10 @@ static int _connection_set_last_network(struct _priv *priv) return RET_FAILED; } } else { - ret = vconf_mgr_get_wired_network_info(&info); - if (ret != RET_SUCCESS) { - _ERR("vconf_mgr_get_wired_network_info() failed."); - return ret; - } + _get_ip_info(info.ip_addr, WIRED_IP_KEY); + _get_ip_info(info.submask, WIRED_SUBMASK_KEY); + _get_ip_info(info.gateway, WIRED_GATEWAY_KEY); + _get_ip_info(info.dns, WIRED_DNS_KEY); } return RET_SUCCESS; @@ -2358,7 +2318,12 @@ static Evas_Object *_create(struct viewmgr *vmgr, void *data) evas_object_data_set(base, KEY_PRIV, priv); - vconf_mgr_get_network_type(&priv->network_type); + const char *str = NULL; + str = vconf_get_str(SELECTED_NETWORK_TYPE_KEY); + if (str && !strcmp(str, TXT_WIRED)) + priv->network_type = TYPE_WIRED; + else + priv->network_type = TYPE_WIRELESS; ret = _create_upper_layout(priv); if (ret != RET_SUCCESS) { diff --git a/ug/network/src/vconf_mgr.cpp b/ug/network/src/vconf_mgr.cpp deleted file mode 100644 index b4c72c8..0000000 --- a/ug/network/src/vconf_mgr.cpp +++ /dev/null @@ -1,404 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "defs.h" -#include "dbg.h" -#include "vconf_mgr.h" -#include "i18n.h" - -static const char *WIRED_DNS_LAST_MODE = "db/menu/network/wired_dns_mode"; -static const char *WIRED_IP_LAST_MODE = "db/menu/network/wired_ip_mode"; -static const char *WIRED_IP_KEY = "db/menu/network/wired_ip"; -static const char *WIRED_SUBMASK_KEY = "db/menu/network/wired_subnet"; -static const char *WIRED_GATEWAY_KEY = "db/menu/network/wired_gateway"; -static const char *WIRED_DNS_KEY = "db/menu/network/wired_dns"; - -static const char *WIRELESS_IP_LAST_MODE = "db/menu/network/wireless_ip_mode"; -static const char *WIRELESS_DNS_LAST_MODE = "db/menu/network/wireless_dns_mode"; -static const char *WIRELESS_IP_KEY = "db/menu/network/wireless_ip"; -static const char *WIRELESS_SUBMASK_KEY = "db/menu/network/wireless_subnet"; -static const char *WIRELESS_GATEWAY_KEY = "db/menu/network/wireless_gateway"; -static const char *WIRELESS_DNS_KEY = "db/menu/network/wireless_dns"; - -static const char *SELECTED_NETWORK_TYPE_KEY = "db/menu/network/network_type"; - -/** - * Gets the network type. - * - * Gets the last network type from vconf. - * - * @param[out] network_type Network type - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int vconf_mgr_get_network_type(enum network_type_enum *network_type) -{ - const char *str; - - if (!network_type) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - str = vconf_get_str(SELECTED_NETWORK_TYPE_KEY); - if (str && !strcmp(str, TXT_WIRED)) - *network_type = TYPE_WIRED; - else - *network_type = TYPE_WIRELESS; - - return RET_SUCCESS; -} - -/** - * Sets the network type. - * - * Sets the network type into vconf, so it can be used - * next time by calling vconf_mgr_get_network_type. - * - * @param[in] network_type Network type - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int vconf_mgr_set_network_type(enum network_type_enum network_type) -{ - switch (network_type) { - case TYPE_WIRED: - vconf_set_str(SELECTED_NETWORK_TYPE_KEY, TXT_WIRED); - break; - case TYPE_WIRELESS: - vconf_set_str(SELECTED_NETWORK_TYPE_KEY, TXT_WIRELESS); - break; - default: - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Gets the string value from the vconf. - * - * @param[out] des The string value - * @param[in] key Vconf key - */ -static void _get_info(char *des, const char *key) -{ - const char *str; - - if (!des || !key) - return; - - str = vconf_get_str(key); - if (!str) - return; - - if (str == '\0' || !strncmp(str, NULL_STRING, IP_STRING_MAX_SIZE)) - strncpy(des, _(ZERO_IP), IP_STRING_MAX_SIZE); - else - strncpy(des, str, IP_STRING_MAX_SIZE); -} - -/** - * Gets wired network information. - * - * Including IP, submask, gateway and DNS. - * - * @param[out] info The structure of network information - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int vconf_mgr_get_wired_network_info(struct network_info *info) -{ - if (!info) { - _ERR("the param is NULL."); - return RET_FAILED; - } - - _get_info(info->ip_addr, WIRED_IP_KEY); - _get_info(info->submask, WIRED_SUBMASK_KEY); - _get_info(info->gateway, WIRED_GATEWAY_KEY); - _get_info(info->dns, WIRED_DNS_KEY); - - return RET_SUCCESS; -} - -/** - * Gets wireless network information. - * - * Including IP, submask, gateway and DNS. - * - * @param[out] info The structure of network information - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int vconf_mgr_get_wireless_network_info(struct network_info *info) -{ - if (!info) { - _ERR("the param is NULL."); - return RET_FAILED; - } - - _get_info(info->ip_addr, WIRELESS_IP_KEY); - _get_info(info->submask, WIRELESS_SUBMASK_KEY); - _get_info(info->gateway, WIRELESS_GATEWAY_KEY); - _get_info(info->dns, WIRELESS_DNS_KEY); - - return RET_SUCCESS; -} - -/** - * Saves wired network information into vconf. - * - * Including IP, submask, gateway and DNS. - * - * @param[in] info The structure of network information - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int vconf_mgr_save_wired_config_info(struct network_info *info) -{ - if (!info) { - _ERR("the param is NULL."); - return RET_FAILED; - } - - vconf_set_str(WIRED_IP_KEY, info->ip_addr); - vconf_set_str(WIRED_SUBMASK_KEY, info->submask); - vconf_set_str(WIRED_GATEWAY_KEY, info->gateway); - vconf_set_str(WIRED_DNS_KEY, info->dns); - - return RET_SUCCESS; -} - -/** - * Saves wireless network information into vconf. - * - * Including IP, submask, gateway and DNS. - * - * @param[in] info The structure of network information - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int vconf_mgr_save_wireless_config_info(struct network_info *info) -{ - if (!info) { - _ERR("the param is NULL."); - return RET_FAILED; - } - - vconf_set_str(WIRELESS_IP_KEY, info->ip_addr); - vconf_set_str(WIRELESS_SUBMASK_KEY, info->submask); - vconf_set_str(WIRELESS_GATEWAY_KEY, info->gateway); - vconf_set_str(WIRELESS_DNS_KEY, info->dns); - - return RET_SUCCESS; -} - -/** - * Gets the wired IP mode from vconf. - * - * The mode includes automatical and manual. - * - * @param[out] mode The enum of setting mode - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int vconf_mgr_get_wired_ip_mode(enum setting_mode *mode) -{ - const char *str; - - if (!mode) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - str = vconf_get_str(WIRED_IP_LAST_MODE); - if (str && !strcmp(str, _(TXT_OBTAIN_AUTO))) - *mode = MODE_AUTO; - else - *mode = MODE_MAN; - - return RET_SUCCESS; -} - -/** - * Sets the wired IP mode into vconf. - * - * The mode includes automatical and manual. - * - * @param[in] mode The enum of setting mode - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int vconf_mgr_set_wired_ip_mode(enum setting_mode mode) -{ - switch (mode) { - case MODE_AUTO: - vconf_set_str(WIRED_IP_LAST_MODE, _(TXT_OBTAIN_AUTO)); - break; - case MODE_MAN: - vconf_set_str(WIRED_IP_LAST_MODE, _(TXT_ENTER_MAN)); - break; - default: - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Gets the wired DNS mode from vconf. - * - * The mode includes automatical and manual. - * - * @param[out] mode The enum of setting mode - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int vconf_mgr_get_wired_dns_mode(enum setting_mode *mode) -{ - char *str; - - if (!mode) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - str = vconf_get_str(WIRED_DNS_LAST_MODE); - if (str && !strcmp(str, _(TXT_OBTAIN_AUTO))) - *mode = MODE_AUTO; - else - *mode = MODE_MAN; - - return RET_SUCCESS; -} - -/** - * Sets the wired DNS mode into vconf. - * - * The mode includes automatical and manual. - * - * @param[in] mode The enum of setting mode - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int vconf_mgr_set_wired_dns_mode(enum setting_mode mode) -{ - switch (mode) { - case MODE_AUTO: - vconf_set_str(WIRED_DNS_LAST_MODE, _(TXT_OBTAIN_AUTO)); - break; - case MODE_MAN: - vconf_set_str(WIRED_DNS_LAST_MODE, _(TXT_ENTER_MAN)); - break; - default: - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Gets the wireless IP mode from vconf. - * - * The mode includes automatical and manual. - * - * @param[out] mode The enum of setting mode - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int vconf_mgr_get_wireless_ip_mode(enum setting_mode *mode) -{ - char *str; - - if (!mode) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - str = vconf_get_str(WIRELESS_IP_LAST_MODE); - if (str && !strcmp(str, _(TXT_OBTAIN_AUTO))) - *mode = MODE_AUTO; - else - *mode = MODE_MAN; - - return RET_SUCCESS; -} - -/** - * Sets the wireless IP mode into vconf. - * - * The mode includes automatical and manual. - * - * @param[in] mode The enum of setting mode - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int vconf_mgr_set_wireless_ip_mode(enum setting_mode mode) -{ - switch (mode) { - case MODE_AUTO: - vconf_set_str(WIRELESS_IP_LAST_MODE, _(TXT_OBTAIN_AUTO)); - break; - case MODE_MAN: - vconf_set_str(WIRELESS_IP_LAST_MODE, _(TXT_ENTER_MAN)); - break; - default: - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Gets the wireless DNS mode from vconf. - * - * The mode includes automatical and manual. - * - * @param[out] mode The enum of setting mode - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int vconf_mgr_get_wireless_dns_mode(enum setting_mode *mode) -{ - char *str; - - if (!mode) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - str = vconf_get_str(WIRELESS_DNS_LAST_MODE); - if (str && !strcmp(str, _(TXT_OBTAIN_AUTO))) - *mode = MODE_AUTO; - else - *mode = MODE_MAN; - - return RET_SUCCESS; -} - -/** - * Sets the wireless DNS mode into vconf. - * - * The mode includes automatical and manual. - * - * @param[in] mode The enum of setting mode - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int vconf_mgr_set_wireless_dns_mode(enum setting_mode mode) -{ - switch (mode) { - case MODE_AUTO: - vconf_set_str(WIRELESS_DNS_LAST_MODE, - _(TXT_OBTAIN_AUTO)); - break; - case MODE_MAN: - vconf_set_str(WIRELESS_DNS_LAST_MODE, - _(TXT_ENTER_MAN)); - break; - default: - return RET_FAILED; - } - - return RET_SUCCESS; -} diff --git a/ug/network/src/wifi_passcode_view.cpp b/ug/network/src/wifi_passcode_view.cpp index db7f442..27be997 100644 --- a/ug/network/src/wifi_passcode_view.cpp +++ b/ug/network/src/wifi_passcode_view.cpp @@ -25,6 +25,7 @@ #include "common.h" #include "wifi_passcode_view.h" #include "util.h" +#include "network_viewmgr.h" #include "WifiMgr.h" -- 2.7.4 From 6e53be846c182d4e931aa8a611ca0380257e151e Mon Sep 17 00:00:00 2001 From: JuWan Kim Date: Wed, 25 Mar 2015 16:59:41 +0900 Subject: [PATCH 10/16] Change main_view to NetworkMainView class in ./ug/network/ * It has UI problem because of using application-common (elm_win_resize_object_add) * But, when main code will be refactored, I am looking forward to solve the bug. Change-Id: Ia55d0a41a4cd4d8903071218cdae78c5245a5c7f Signed-off-by: JuWan Kim --- ug/network/CMakeLists.txt | 5 +- ug/network/include/NetworkMainView.h | 96 ++ ug/network/include/common.h | 19 + ug/network/include/defs.h | 3 + ug/network/include/main_view.h | 22 - ug/network/include/network_viewmgr.h | 6 +- ug/network/src/NetworkMainView.cpp | 1708 ++++++++++++++++++++++ ug/network/src/main_view.cpp | 2485 -------------------------------- ug/network/src/ug_network_settings.cpp | 46 +- ug/src/NetConMgr.cpp | 4 + 10 files changed, 1858 insertions(+), 2536 deletions(-) create mode 100644 ug/network/include/NetworkMainView.h delete mode 100644 ug/network/include/main_view.h create mode 100644 ug/network/src/NetworkMainView.cpp delete mode 100644 ug/network/src/main_view.cpp diff --git a/ug/network/CMakeLists.txt b/ug/network/CMakeLists.txt index 0095541..cad0340 100644 --- a/ug/network/CMakeLists.txt +++ b/ug/network/CMakeLists.txt @@ -35,6 +35,7 @@ pkg_check_modules(UG_NETWORK_PKGS REQUIRED capi-appfw-application capi-network-wifi capi-network-connection + application-common ) SET(PKGS_LDFLAGS "${PKGS_LDFLAGS} ${UG_NETWORK_PKGS_LDFLAGS}") @@ -46,11 +47,11 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") SET(SRCS src/ug_network_settings.cpp - src/main_view.cpp + src/NetworkMainView.cpp src/network_viewmgr.cpp src/ip_setting_view.cpp - src/util.cpp src/wifi_passcode_view.cpp + src/util.cpp ../src/WifiMgr.cpp ../src/NetConMgr.cpp ) diff --git a/ug/network/include/NetworkMainView.h b/ug/network/include/NetworkMainView.h new file mode 100644 index 0000000..6b3a01e --- /dev/null +++ b/ug/network/include/NetworkMainView.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __NETWORK_MAIN_VIEW_H__ +#define __NETWORK_MAIN_VIEW_H__ + +class CNetworkMainView : public CBaseView { +private : + struct SNetworkMainView *m; + + static void sm_CbGenlistItemSelected(void *data, Evas_Object *obj, void *ei); + static Eina_Bool sm_CbSelectConnected(void *data); + + static bool sm_CbWifiFoundAP(wifi_ap_h ap, void *data); + void m_OnWifiFoundAP(wifi_ap_h ap); + + static void sm_CbWifiScanRequest(wifi_error_e err, void *data); + void m_OnWifiScanRequest(wifi_error_e err, void *data); + + static void sm_CbConnectionOnlineAsync(bool state, void *data); + void m_OnConnectionOnlineAync(bool state); + + static void sm_CbCheckGatewayAsync(bool state, void *data); + void m_OnCheckGatewayAsync(bool state); + + static void sm_CbWifiActivated(wifi_error_e err, void *data); + void m_OnWifiActivated(wifi_error_e err); + + static char* sm_GetApName(void *data, Evas_Object *obj, const char *part); + static void sm_CbEthernetStateChanged(bool state, void *data); + void m_OnEthernetStateChanged(bool state); + + bool m_InitConnectionMgr(void); + void m_FinalizeConnectionMgr(); + + Evas_Object *m_CreateMainLayout(void); + bool m_CreateUpperLayout(void); + + bool m_CreateActionBtns(void); + void m_DestroyActionBtns(); + + bool m_CreateDimLayout(void); + void m_SetNetTypeBtnText(void); + + bool m_SetWireless(void); + bool m_SetWired(void); + + void m_FillContentPart(Evas_Object *obj); + void m_SetActionBtnPos(void); + + void m_CreateWirelessDisconnectPart(void); + bool m_CreateWiredConnectPart(void); + bool m_CreateWiredDisconnectPart(void); + Evas_Object* m_CreateGenlistView(void); + void m_ClearGenlist(void); + + static void sm_CbWifiConnected(wifi_error_e err, void *data); + void m_OnWifiConnected(wifi_error_e err); + void m_ConnectNetwork(void); + bool m_WifiConnectAP(int index); + bool m_WiredConnectAP(); + bool m_ConnectionSetLastNetwork(void); + void m_GetIpInfo(char *des, const char *key); + + void m_ShowConfirmPopup(void); + void m_ShowProgressPopup(void); +public : + +protected : + virtual void t_OnShow(void); + virtual void t_OnUpdate(void *data); + virtual void t_OnHide(void); + +public : + CNetworkMainView(const char *szViewId) : CBaseView(szViewId), m(0) {} + virtual ~CNetworkMainView() {} + + virtual bool Create(void *data); + virtual void Destroy(void); + virtual Evas_Object* Base(void); +}; + +#endif /* __NETWORK_MAIN_VIEW_H__ */ diff --git a/ug/network/include/common.h b/ug/network/include/common.h index 8f15b48..6653826 100644 --- a/ug/network/include/common.h +++ b/ug/network/include/common.h @@ -34,6 +34,19 @@ enum setting_mode { MODE_MAN }; +enum action_btn_enum { + CONNECT, + REFRESH, + OTHER, + CLOSE +}; + +enum view_type { + NETWORK_MAIN_VIEW = 0, + NETWORK_WIFI_PASSCODE_VIEW, + NETWORK_IP_SETTING_VIEW +}; + struct connection_info { enum network_type_enum cur_type; char name[MAX_NAME_SIZE]; @@ -50,6 +63,12 @@ struct network_info { #define SSID_MAX_LENTH 256 #define PWD_MAX_LENTH 256 +#define BTN_ACT 4 +#define BTN_TYPE 2 +#define TIMER_INTERNAL 0.1 +#define KEY_PRIV "priv" +#define TYPE_POPUP_X_OFFSET 190 + struct wifi_ap_info { char essid[SSID_MAX_LENTH]; char bssid[SSID_MAX_LENTH]; diff --git a/ug/network/include/defs.h b/ug/network/include/defs.h index bf446db..3fe2aa3 100644 --- a/ug/network/include/defs.h +++ b/ug/network/include/defs.h @@ -23,6 +23,9 @@ #define RET_FAILED -1 #define RET_IP_INVALID -2 +/* VIEW */ +#define NETWORK_MAINVIEW "NETWORK_MAIN_VIEW" + /*GROUP*/ #define GRP_MAIN "main" #define GRP_NETWORK_TYPE_SELECT "popup_select" diff --git a/ug/network/include/main_view.h b/ug/network/include/main_view.h deleted file mode 100644 index 199007d..0000000 --- a/ug/network/include/main_view.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __MAIN_VIEW_H__ -#define __MAIN_VIEW_H__ - -struct view_class *main_view_vclass_get(void); - -#endif /* __MAIN_VIEW_H__ */ diff --git a/ug/network/include/network_viewmgr.h b/ug/network/include/network_viewmgr.h index fd5d0f4..a39ed47 100644 --- a/ug/network/include/network_viewmgr.h +++ b/ug/network/include/network_viewmgr.h @@ -17,14 +17,10 @@ #ifndef __NETVIEWMGR_H__ #define __NETVIEWMGR_H__ +#include "common.h" #include #include -enum view_type { - NETWORK_MAIN_VIEW = 0, - NETWORK_WIFI_PASSCODE_VIEW, - NETWORK_IP_SETTING_VIEW -}; enum message_id { PASSCODE_DEVIVER = 0 diff --git a/ug/network/src/NetworkMainView.cpp b/ug/network/src/NetworkMainView.cpp new file mode 100644 index 0000000..b231edc --- /dev/null +++ b/ug/network/src/NetworkMainView.cpp @@ -0,0 +1,1708 @@ +#include +#include "AppCommon.h" +#include "dbg.h" +#include "util.h" +#include "defs.h" +#include "ip_setting_view.h" +#include "i18n.h" +#include "common.h" +#include "wifi_passcode_view.h" +#include +#include +#include "WifiMgr.h" +#include "NetConMgr.h" + +#include "BaseView.h" +#include "ViewMgr.h" +#include "NetworkMainView.h" + +static char *action_button[4] = { TXT_CONNECT_BTN, TXT_REFRESH_BTN, TXT_OTHER_BTN, TXT_CLOSE_BTN }; +static char *button_swallow[4] = { PART_CONNECT_BTN, PART_REFRESH_BTN, PART_OTHER_BTN, PART_CLOSE_BTN }; +static char *popup_button[2] = { TXT_WIRELESS, TXT_WIRED }; + +struct SNetworkMainView { + ui_gadget_h ug; + + Evas_Object *win; + Evas_Object *base; + Evas_Object *type_btn; + Evas_Object *network_ctxpopup; + Evas_Object *dim_ly; + Evas_Object *connect_btn; + Evas_Object *refresh_btn; + Evas_Object *other_btn; + Evas_Object *close_btn; + Evas_Object *genlist; + Evas_Object *wired_con_box; + Evas_Object *wireless_discon_ly; + Evas_Object *wired_discon_ly; + Evas_Object *status_popup; + + Elm_Genlist_Item_Class *lock_ic; + Elm_Genlist_Item_Class *nolock_ic; + Elm_Object_Item *last_item; + + Eina_List *ap_list; + Ecore_Timer *timer; + + enum network_type_enum network_type; + enum view_type cur_view; + + int wifi_init; + Eina_Bool wifi_conn; + Eina_Bool wired_conn; + + char profile_name[MAX_NAME_SIZE]; + + wifi_ap_h ap; + char *ap_name; + char *ap_pwd; + + CWifiMgr *pWifiMgr; + CNetConMgr *pNetConMgr; + CViewMgr *pViewMgr; + + SNetworkMainView() { + pHandlerBase = new CHandlerBase(this); + pHandlerTypeButton= new CHandlerTypeButton(this); + pHandlerPopupButton = new CHandlerPopupButton(this); + pHandlerWiredConBox = new CHandlerWiredConBox(this); + pHandlerActionBtns = new CHandlerActionBtns(this); + pHandlerConfirmPopup = new CHandlerConfirmPopup(this); + } + virtual ~SNetworkMainView() { + delete pHandlerConfirmPopup; + delete pHandlerActionBtns; + delete pHandlerWiredConBox; + delete pHandlerPopupButton; + delete pHandlerTypeButton; + delete pHandlerBase; + } + + class CHandlerBase : public CListenerMgr, public IKeyDownListener { + private: + SNetworkMainView *m; + + public: + CHandlerBase(SNetworkMainView *ins) : IKeyDownListener(this) { m = ins; } + + virtual void OnKeyDown(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev) { + _DBG(); + switch (id) { + case 0: + if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) { + ug_destroy_me(m->ug); + } + break; + case 1: + if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) { + //_unset_layout_dim(priv); + evas_object_hide(m->dim_ly); + if (m->network_ctxpopup) { + evas_object_del(m->network_ctxpopup); + m->network_ctxpopup = NULL; + } + } + break; + default: + break; + } + } + } *pHandlerBase; + + class CHandlerTypeButton : public CListenerMgr, IMouseClickedListener { + private: + SNetworkMainView *m; + + public: + CHandlerTypeButton(SNetworkMainView *ins) : IMouseClickedListener(this) { m = ins; } + + virtual void OnMouseClicked(int id, Evas_Object *obj) { + _DBG(); + Evas_Object *base; + Evas_Object *layout, *box; + Evas_Object *btn[BTN_TYPE]; + Evas_Coord x; + Evas_Coord y; + Evas_Coord w; + Evas_Coord h; + int i; + + evas_object_show(m->dim_ly); + + layout = util_add_layout(base, UG_NETWORK_EDJ_FILE, GRP_NETWORK_TYPE_SELECT); + if (!layout) { + _ERR("util_add_layout() failed."); + return; + } + + box = util_add_box(layout, PART_SWALLOW_CONTENT); + if (!box) { + evas_object_del(layout); + return; + } + + evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, 0); + + for (i = 0; i < BTN_TYPE; i++) { + btn[i] = util_add_button(box, STYLE_POPUP_BTN, NULL, _(popup_button[i])); + if (!btn[i]) { + evas_object_del(layout); + return; + } + + elm_box_pack_end(box, btn[i]); + + //evas_object_smart_callback_add(btn[i], SIG_CLICKED, _type_select_btn_cb, priv); + m->pHandlerPopupButton->Connect(btn[i],i); + } + + if (m->network_type == TYPE_WIRELESS) + elm_object_signal_emit(btn[TYPE_WIRELESS], SIG_BTN_SELECTED, PROG); + else + elm_object_signal_emit(btn[TYPE_WIRED], SIG_BTN_SELECTED, PROG); + + elm_object_part_content_set(layout, PART_SWALLOW_CONTENT, box); + + elm_object_focus_next_object_set(btn[1], btn[0], ELM_FOCUS_DOWN); + elm_object_focus_next_object_set(btn[0], btn[1], ELM_FOCUS_UP); + elm_object_focus_next_object_set(btn[1], btn[0], ELM_FOCUS_UP); + elm_object_focus_next_object_set(btn[0], btn[1], ELM_FOCUS_DOWN); + elm_object_focus_next_object_set(btn[0], btn[0], ELM_FOCUS_LEFT); + elm_object_focus_next_object_set(btn[0], btn[0], ELM_FOCUS_RIGHT); + elm_object_focus_next_object_set(btn[1], btn[1], ELM_FOCUS_LEFT); + elm_object_focus_next_object_set(btn[1], btn[1], ELM_FOCUS_RIGHT); + + x = 0; y = 0; w = 0; h = 0; + + evas_object_geometry_get(m->type_btn, &x, &y, &w, &h); + evas_object_move(layout, (x + w - TYPE_POPUP_X_OFFSET) * ELM_SCALE, (y + h) * ELM_SCALE); + + m->network_ctxpopup = layout; + + //evas_object_event_callback_add(layout, EVAS_CALLBACK_KEY_DOWN, _type_key_pressed_cb, priv); + m->pHandlerBase->Connect(layout, 1); + + elm_object_focus_set(btn[0], EINA_TRUE); + evas_object_show(layout); + } + } *pHandlerTypeButton; + + class CHandlerPopupButton : public CListenerMgr, IMouseClickedListener { + private: + SNetworkMainView *m; + public: + CHandlerPopupButton(SNetworkMainView *ins) : IMouseClickedListener(this) { m = ins; } + + virtual void OnMouseClicked(int id, Evas_Object *obj) { + _DBG(); + const char *value; + + value = elm_object_text_get(obj); + if (!value) { + _ERR("get text from network type btn is NULL."); + return; + } + + if ((!strcmp(value, _(popup_button[TYPE_WIRELESS]))) && m->network_type == TYPE_WIRED) { + m->network_type = TYPE_WIRELESS; + //m_SetWireless(); + vconf_set_str(SELECTED_NETWORK_TYPE_KEY, TXT_WIRELESS); + } else if ((!strcmp(value, _(popup_button[TYPE_WIRED]))) && m->network_type == TYPE_WIRELESS) { + m->network_type = TYPE_WIRED; + //m_SetWired(); + vconf_set_str(SELECTED_NETWORK_TYPE_KEY, TXT_WIRED); + } + + //m_SetNetTypeBtnText(); + + if (m->network_ctxpopup) { + evas_object_del(m->network_ctxpopup); + m->network_ctxpopup = NULL; + } + + evas_object_hide(m->dim_ly); + } + } *pHandlerPopupButton; + + class CHandlerWiredConBox : public CListenerMgr, IMouseClickedListener { + private: + SNetworkMainView *m; + public: + CHandlerWiredConBox(SNetworkMainView *ins) : IMouseClickedListener(this) { m = ins; } + + virtual void OnMouseClicked(int id, Evas_Object *obj) { + _DBG(); + if (m->wired_conn) { + elm_object_signal_emit(obj, SIG_STATE_UNSELECTED, ELM); + m->wired_conn = EINA_FALSE; + elm_object_disabled_set(m->connect_btn, EINA_TRUE); + elm_object_disabled_set(m->other_btn, EINA_TRUE); + } else { + elm_object_signal_emit(obj, SIG_STATE_SELECTED, ELM); + m->wired_conn = EINA_TRUE; + elm_object_disabled_set(m->connect_btn, EINA_FALSE); + elm_object_disabled_set(m->other_btn, EINA_FALSE); + } + } + } *pHandlerWiredConBox; + + class CHandlerActionBtns : public CListenerMgr, IMouseClickedListener { + private: + SNetworkMainView *m; + public: + CHandlerActionBtns(SNetworkMainView *ins) : IMouseClickedListener(this) { m = ins; } + + virtual void OnMouseClicked(int id, Evas_Object *obj) { + _DBG(); + switch (id) { + case 0: /* CONNECT */ + //m_ConnectNetwork(); + break; + case 1: /* REFRESH */ + //m_ClearGenlist(); + //m_SetWireless(); + break; + case 2: /* OTHER */ + struct connection_info info; + + m->cur_view = NETWORK_IP_SETTING_VIEW; + + info.cur_type = m->network_type; + + if (m->network_type == TYPE_WIRED) { + strncpy(info.name, m->profile_name, + MAX_NAME_SIZE - 1); + } else { + if (!m->ap) { + _ERR("selected ap is NULL."); + return; + } + + info.ap = m->ap; + + if (m->ap_name) + strncpy(info.name, m->ap_name, + MAX_NAME_SIZE - 1); + } + +#if 0 + base = viewmgr_push(m->vmgr, ip_setting_view_vclass_get(), &info); + if (!base) + _ERR("add connection layout failed."); +#endif + break; + case 3: /* CLOSE */ + if (m->ug) + ug_destroy_me(m->ug); + break; + default: + break; + } + } + } *pHandlerActionBtns; + + class CHandlerConfirmPopup : public CListenerMgr, IKeyDownListener, IMouseClickedListener, IUnfocusedListener { + private: + SNetworkMainView *m; + public: + CHandlerConfirmPopup(SNetworkMainView *ins) : IKeyDownListener(this), IMouseClickedListener(this), IUnfocusedListener(this) { m = ins; } + + virtual void OnKeyDown(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev) { + _DBG(); + switch(id) { + case 0: /* retry_btn */ + break; + case 1: /* cancel_btn */ + break; + case 2: /* layout */ + case 5: /* layout of progress popup */ + if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) { + evas_object_hide(m->dim_ly); + evas_object_del(obj); + } + break; + default: + break; + } + } + virtual void OnMouseClicked(int id, Evas_Object *obj) { + _DBG(); + switch(id) { + case 0: + evas_object_hide(m->dim_ly); + if (m->status_popup) + evas_object_del(m->status_popup); + m->status_popup = NULL; + //m_ConnectNetwork(); + break; + case 1: + case 4: /* cancel_btn of progress popup */ + evas_object_hide(m->dim_ly); + if (m->status_popup) + evas_object_del(m->status_popup); + m->status_popup = NULL; + elm_object_focus_set(m->connect_btn, EINA_TRUE); + break; + case 2: + break; + default: + break; + } + } + virtual void OnUnfocused(int id, Evas_Object *obj, Elm_Object_Item *item){ + _DBG(); + switch(id) { + case 0: + break; + case 1: + break; + case 2: + case 5: /* layout of progress popup */ + evas_object_hide(m->dim_ly); + evas_object_del(obj); + break; + default: + break; + } + } + } *pHandlerConfirmPopup; +}; + + +void CNetworkMainView::sm_CbGenlistItemSelected(void *data, Evas_Object *obj, void *ei) +{ + _DBG(); + struct SNetworkMainView *priv; + Elm_Object_Item *gen_item; + struct wifi_ap_info *ap_info; + int index; + + if (!data || !ei) { + _ERR("Parameter error!"); + return; + } + + priv = (struct SNetworkMainView *) data; + gen_item = (Elm_Object_Item *) ei; + + if (priv->last_item == gen_item) { + elm_object_item_signal_emit(gen_item, SIG_STATE_UNSELECTED, ELM); + + elm_object_disabled_set(priv->connect_btn, EINA_TRUE); + elm_object_disabled_set(priv->other_btn, EINA_TRUE); + + priv->last_item = NULL; + + return; + } + + elm_object_item_signal_emit(gen_item, SIG_STATE_SELECTED, ELM); + if (priv->last_item) + elm_object_item_signal_emit(priv->last_item, SIG_STATE_UNSELECTED, ELM); + priv->last_item = gen_item; + + elm_object_disabled_set(priv->connect_btn, EINA_FALSE); + elm_object_disabled_set(priv->other_btn, EINA_FALSE); + + index = elm_genlist_item_index_get(priv->last_item); + if (index < 0) { + _ERR("the index of item is invalid."); + return; + } + + ap_info = (struct wifi_ap_info *) eina_list_nth(priv->ap_list, index); + if (!ap_info) { + _ERR("ap info is NULL."); + return; + } + + if (priv->ap_name) { + free(priv->ap_name); + priv->ap_name = NULL; + } + + priv->ap_name = strdup(ap_info->essid); + if (!priv->ap_name) { + _ERR("ap name gets failed."); + return; + } + + if (priv->ap) { + priv->pWifiMgr->DestroyAP(priv->ap); + priv->ap = NULL; + } + + priv->pWifiMgr->CloneAP(&priv->ap, ap_info->ap); + if (!priv->ap) { + _ERR("ap clone failed."); + return; + } + + if (ap_info->secure_type == WIFI_SECURITY_TYPE_NONE) { + if (priv->ap_pwd) { + free(priv->ap_pwd); + priv->ap_pwd = NULL; + } + } +} + + +Eina_Bool CNetworkMainView::sm_CbSelectConnected(void *data) +{ + _DBG(); + struct SNetworkMainView *priv; + + if (!data) { + _ERR("Parameter error!"); + return ECORE_CALLBACK_CANCEL; + } + + priv = (struct SNetworkMainView *) data; + + elm_object_item_signal_emit(priv->last_item, SIG_STATE_SELECTED, ELM); + elm_object_disabled_set(priv->connect_btn, EINA_FALSE); + elm_object_disabled_set(priv->other_btn, EINA_FALSE); + + priv->timer = NULL; + + return ECORE_CALLBACK_CANCEL; +} + + +bool CNetworkMainView::sm_CbWifiFoundAP(wifi_ap_h ap, void *data) +{ + _DBG(); + CNetworkMainView *instance = NULL; + instance = (CNetworkMainView *) data; + instance->m_OnWifiFoundAP(ap); +} + + +void CNetworkMainView::m_OnWifiFoundAP(wifi_ap_h ap) +{ + _DBG(); + bool ret; + bool state; + struct wifi_ap_info *ap_info; + Elm_Object_Item *item; + + ret = m->pWifiMgr->IsActivated(&state); + if (ret != true || state == 0) { + _ERR("failt to wifi_is_activated"); + return ; + } + + ap_info = (struct wifi_ap_info *) calloc(1, sizeof(*ap_info)); + if (!ap_info) { + _ERR("calloc failed"); + return ; + } + + ret = m->pWifiMgr->GetESSID(ap, ap_info->essid); + if(ret != true) { + _ERR("Fail to get info"); + return ; + } + + ret = m->pWifiMgr->GetConnectionState(ap, &ap_info->state); + if(ret != true) { + _ERR("Fail to get info"); + return ; + } + + ret = m->pWifiMgr->GetSecurityType(ap, &ap_info->secure_type); + if(ret != true) { + _ERR("Fail to get info"); + return ; + } + + ap_info->ap = ap; + ap_info->user_data = m; + m->ap_list = eina_list_append(m->ap_list, ap_info); + + m_FillContentPart(m->genlist); + + if (ap_info->secure_type == WIFI_SECURITY_TYPE_NONE) + item = elm_genlist_item_append(m->genlist, m->nolock_ic, ap_info, NULL, ELM_GENLIST_ITEM_NONE, sm_CbGenlistItemSelected, m); + else + item = elm_genlist_item_append(m->genlist, m->lock_ic, ap_info, NULL, ELM_GENLIST_ITEM_NONE, sm_CbGenlistItemSelected, m); + if (!item) { + _ERR("genlist append item failed."); + return ; + } + + if (ap_info->state == WIFI_CONNECTION_STATE_CONNECTED) { + m->last_item = item; + if (m->ap) { + ret = m->pWifiMgr->DestroyAP(m->ap); + if(ret != true) { + _ERR("Fail to destroy AP"); + } + m->ap = NULL; + } + + ret = m->pWifiMgr->CloneAP(&m->ap, ap); + if(ret != true) { + _ERR("Fail to clone AP"); + } + + m->timer = ecore_timer_add(TIMER_INTERNAL, sm_CbSelectConnected, m); + if (!m->timer) { + _ERR("add timer failed."); + return ; + } + } +} + + +void CNetworkMainView::sm_CbWifiScanRequest(wifi_error_e err, void *data) +{ + _DBG(); + CNetworkMainView *instance = NULL; + instance = (CNetworkMainView *) data; + instance->m_OnWifiScanRequest(err, data); +} + + +void CNetworkMainView::m_OnWifiScanRequest(wifi_error_e err, void *data) +{ + _DBG(); + bool ret = false; + ret = m->pWifiMgr->RegisterFoundAPCallback( sm_CbWifiFoundAP, data); + if (ret != true) { + _ERR("wifi_mgr_foreach_found_aps() failed."); + } +} + + +void CNetworkMainView::sm_CbConnectionOnlineAsync(bool state, void *data) +{ + _DBG(); + CNetworkMainView *instance = NULL; + instance = (CNetworkMainView *) data; + + instance->m_OnConnectionOnlineAync(state); +} + +void CNetworkMainView::m_OnConnectionOnlineAync(bool state) +{ + _DBG(); + if (state != true) { + _ERR("connection result"); + m_ShowConfirmPopup(); + } else { + ug_destroy_me(m->ug); + } +} + +void CNetworkMainView::sm_CbCheckGatewayAsync(bool state, void *data) +{ + _DBG(); + CNetworkMainView *instance = NULL; + instance = (CNetworkMainView *) data; + + instance->m_OnCheckGatewayAsync(state); +} + + +void CNetworkMainView::m_OnCheckGatewayAsync(bool state) +{ + _DBG(); + bool ret; + + if (state != true) { + _ERR("connection disconnected"); + m_ShowConfirmPopup(); + } else { + ret = m->pNetConMgr->RegisterIpChangedCallback( sm_CbConnectionOnlineAsync, this); + if (ret != true) { + _ERR("connection_mgr_get_is_online_async() failed."); + return; + } + } +} + + +void CNetworkMainView::sm_CbWifiActivated(wifi_error_e err, void *data) +{ + _DBG(); + CNetworkMainView *instance = NULL; + instance = (CNetworkMainView *) data; + + instance->m_OnWifiActivated(err); +} + + +void CNetworkMainView::m_OnWifiActivated(wifi_error_e err) +{ + _DBG(); + bool ret; + + if (err != WIFI_ERROR_NONE) { + _ERR("Wi-Fi Activation Failed! error == %s", m->pWifiMgr->GetErrorMsg(err)); + return; + } + + ret = m->pWifiMgr->RegisterScanCallback(sm_CbWifiScanRequest, this); + if (ret != true) { + _ERR("wifi_mgr_scan_request() failed."); + m_FillContentPart(m->wireless_discon_ly); + m_SetActionBtnPos(); + return; + } + + m->wifi_conn = EINA_TRUE; + + m_SetActionBtnPos(); + + m_FillContentPart(m->genlist); +} + + +char* CNetworkMainView::sm_GetApName(void *data, Evas_Object *obj, const char *part) +{ + _DBG(); + struct wifi_ap_info *ap_info; + + if (!data || !obj || !part) { + _ERR("Parameter error!"); + return NULL; + } + + ap_info = (struct wifi_ap_info *) data; + + if (!strcmp(part, PART_ELM_TEXT)) + return strdup(ap_info->essid); + + return NULL; +} + + +void CNetworkMainView::sm_CbEthernetStateChanged(bool state, void *data) +{ + _DBG(); + if (!data) { + _ERR("data is NULL."); + return; + } + + CNetworkMainView *priv = (CNetworkMainView *) data; + + priv->m_OnEthernetStateChanged(state); +} + + +void CNetworkMainView::m_OnEthernetStateChanged(bool state) +{ + _DBG(); + if (m->network_type != TYPE_WIRED) { + _ERR("cur network type is wireless, return."); + return; + } + + if (state == true) { // ethernet connected + m_FillContentPart(m->wired_con_box); + } else { + m_FillContentPart(m->wired_discon_ly); + + m->wired_conn = EINA_FALSE; + } + + m_SetActionBtnPos(); +} + + +bool CNetworkMainView::m_InitConnectionMgr() +{ + _DBG(); + if(!CNetConMgr::Initialize()) { + _ERR("the param is invalid."); + return false; + } + + m->pNetConMgr = CNetConMgr::GetInstance(); + if (!m->pNetConMgr) { + _ERR("Fail to get instance"); + return false; + } + + if(!m->pNetConMgr->GetProfileName(m->profile_name)) { + _ERR("Fail to get instance"); + return false; + } + + if(!m->pNetConMgr->RegisterIpChangedCallback( sm_CbEthernetStateChanged, this)) { + _ERR("register_ethernet_state_cb() failed."); + return false; + } + + return true; +} + + +void CNetworkMainView::m_FinalizeConnectionMgr() +{ + _DBG(); + CNetConMgr::Finalize(); + m->pNetConMgr = NULL; +} + + +Evas_Object* CNetworkMainView::m_CreateMainLayout() +{ + _DBG(); + Evas_Object *base; + + base = util_add_layout(m->win, UG_NETWORK_EDJ_FILE, GRP_MAIN); + if (!base) { + _ERR("Add pannel view failed."); + return NULL; + } + + //evas_object_event_callback_add(base, EVAS_CALLBACK_KEY_DOWN, _main_ly_key_pressed_cb, priv); + m->pHandlerBase->Connect(base, 0); + + evas_object_show(base); + + return base; +} + + +bool CNetworkMainView::m_CreateUpperLayout() +{ + _DBG(); + Evas_Object *type_btn; + + elm_object_part_text_set(m->base, PART_SELECT_TEXT, _(TXT_NETWORK_DISC)); + + type_btn = util_add_button(m->base, STYLE_TYPE_BTN, PART_NETWORK_TYPE, _(TXT_TYPE_BTN)); + if (!type_btn) + return false; + + m->pHandlerTypeButton->Connect(m->base); + + elm_object_focus_next_object_set(type_btn, type_btn, ELM_FOCUS_UP); + elm_object_focus_next_object_set(type_btn, type_btn, ELM_FOCUS_LEFT); + + m->type_btn = type_btn; + + elm_object_focus_set(type_btn, EINA_TRUE); + + m_SetNetTypeBtnText(); + + return true; +} + + +bool CNetworkMainView::m_CreateActionBtns() +{ + _DBG(); + Evas_Object *bt[BTN_ACT]; + int i; + + for (i = 0; i < BTN_ACT; i++) { + bt[i] = util_add_button(m->base, STYLE_ACTION_BTN, button_swallow[i], _(action_button[i])); + if (!bt[i]) + return false; + } + + m->connect_btn = bt[CONNECT]; + m->refresh_btn = bt[REFRESH]; + m->other_btn = bt[OTHER]; + m->close_btn = bt[CLOSE]; + + evas_object_hide(m->refresh_btn); + + //evas_object_smart_callback_add(bt[CONNECT], SIG_CLICKED, _connect_btn_clicked_cb, priv); + //evas_object_smart_callback_add(bt[REFRESH], SIG_CLICKED, _refresh_btn_clicked_cb, priv); + //evas_object_smart_callback_add(bt[OTHER], SIG_CLICKED, _other_btn_clicked_cb, priv); + //evas_object_smart_callback_add(bt[CLOSE], SIG_CLICKED, _close_btn_clicked_cb, priv); + m->pHandlerActionBtns->Connect(bt[CONNECT], 0); + m->pHandlerActionBtns->Connect(bt[REFRESH], 1); + m->pHandlerActionBtns->Connect(bt[OTHER], 2); + m->pHandlerActionBtns->Connect(bt[CLOSE], 3); + + m_SetActionBtnPos(); + + return true; +} + + +void CNetworkMainView::m_DestroyActionBtns() +{ + _DBG(); + if(m->close_btn) evas_object_del(m->close_btn); + if(m->other_btn) evas_object_del(m->other_btn); + if(m->refresh_btn) evas_object_del(m->refresh_btn); + if(m->connect_btn) evas_object_del(m->connect_btn); +} + + +bool CNetworkMainView::m_CreateDimLayout() +{ + _DBG(); + Evas_Object *dim_ly; + + dim_ly = util_add_layout(m->win, UG_NETWORK_EDJ_FILE, GRP_DIM_LY); + if (!dim_ly) { + _ERR("elm_layout_add() failed.\n"); + return false; + } + + m->dim_ly = dim_ly; + + evas_object_hide(m->dim_ly); + + return true; +} + + +void CNetworkMainView::m_SetNetTypeBtnText() +{ + _DBG(); + switch (m->network_type) { + case TYPE_WIRELESS: + elm_object_part_text_set(m->base, PART_CUR_TYPE_TEXT, _(TXT_WIRELESS_NETWORK)); + elm_object_part_text_set(m->type_btn, PART_NETWORK_TYPE_SELECTED, _(TXT_WIRELESS)); + break; + case TYPE_WIRED: + elm_object_part_text_set(m->base, PART_CUR_TYPE_TEXT, _(TXT_WIRED_NETWORK)); + elm_object_part_text_set(m->type_btn, PART_NETWORK_TYPE_SELECTED, _(TXT_WIRED)); + break; + default: + break; + } +} + + +bool CNetworkMainView::m_SetWireless() +{ + _DBG(); + Evas_Object *obj; + bool activated; + bool ret = false; + + m_CreateWirelessDisconnectPart(); + + if (!m->wifi_init) { + obj = m_CreateGenlistView(); + if (!obj) { + _ERR("fail to create genlist"); + return false; + } + + ret = CWifiMgr::Initialize(); + if(ret != true) { + _ERR("Fail to initialize WifiMgr"); + return false; + } + m->pWifiMgr = CWifiMgr::GetInstance(); + if(!m->pWifiMgr) { + _ERR("Fail to get instance"); + return false; + } + + m->wifi_init = 1; + } + + m_ClearGenlist(); + + activated = EINA_FALSE; + ret = m->pWifiMgr->IsActivated(&activated); + if (ret != true) { + _ERR("the wifi is not activated."); + return false; + } + + if (activated) { + if (m->ap) { + ret = m->pWifiMgr->DestroyAP(m->ap); + if(ret != true) { + _ERR("Fail to destroy AP"); + } + m->ap = NULL; + } + + ret = m->pWifiMgr->RegisterScanCallback(sm_CbWifiScanRequest, this); + if (ret != true) { + _ERR("wifi_mgr_scan_request() failed."); + goto _wireless_finish; + } + + m->wifi_conn = EINA_TRUE; + } else { + m->wifi_conn = EINA_FALSE; + + ret = m->pWifiMgr->Activate(sm_CbWifiActivated, this); + if (ret != true) + _ERR("wifi_mgr_activate() failed."); + } + +_wireless_finish: + m_FillContentPart(m->wireless_discon_ly); + m_SetActionBtnPos(); + + return true; +} + + +bool CNetworkMainView::m_SetWired() +{ + _DBG(); + bool plugin; + + m_CreateWiredConnectPart(); + + m_CreateWiredDisconnectPart(); + + if(!m->pNetConMgr->GetEthernetState(&plugin)) { + _ERR("connection_mgr_get_ethernet_state() failed."); + plugin = false; + } + + if (plugin) { + m_FillContentPart(m->wired_con_box); + } else { + m->wired_conn = EINA_FALSE; + m_FillContentPart(m->wired_discon_ly); + } + + m_SetActionBtnPos(); + + return true; +} + + +void CNetworkMainView::m_FillContentPart(Evas_Object *obj) +{ + _DBG(); + Evas_Object *old_obj; + + if (!obj) { + _ERR("The param is invalid."); + return; + } + + old_obj = elm_object_part_content_get(m->base, PART_NETLIST_PANNEL); + if (old_obj == obj) { + _ERR("PART_NETLIST_PANNEL already filled with this object."); + return; + } + + if (old_obj) { + elm_object_part_content_unset(m->base, PART_NETLIST_PANNEL); + evas_object_hide(old_obj); + } + + elm_object_part_content_set(m->base, PART_NETLIST_PANNEL, obj); + + evas_object_show(obj); +} + + +void CNetworkMainView::m_SetActionBtnPos() +{ + _DBG(); + Evas_Object *btn; + + btn = elm_object_part_content_get(m->base, button_swallow[CONNECT]); + if (!btn) { + elm_object_part_content_set(m->base, button_swallow[CONNECT], m->connect_btn); + evas_object_show(m->connect_btn); + } + + btn = elm_object_part_content_get(m->base, button_swallow[REFRESH]); + if (btn) { + elm_object_part_content_unset(m->base, button_swallow[REFRESH]); + evas_object_hide(btn); + } + + btn = elm_object_part_content_get(m->base, button_swallow[OTHER]); + if (btn) { + elm_object_part_content_unset(m->base, button_swallow[OTHER]); + evas_object_hide(btn); + } + + btn = elm_object_part_content_get(m->base, button_swallow[CLOSE]); + if (btn) { + elm_object_part_content_unset(m->base, button_swallow[CLOSE]); + evas_object_hide(btn); + } + + if (m->network_type == TYPE_WIRELESS) { + if (!m->wifi_conn) { + elm_object_part_content_set(m->base, button_swallow[REFRESH], m->other_btn); + evas_object_show(m->other_btn); + + elm_object_part_content_set(m->base, button_swallow[OTHER], m->close_btn); + evas_object_show(m->close_btn); + } else { + elm_object_part_content_set(m->base, button_swallow[REFRESH], m->refresh_btn); + evas_object_show(m->refresh_btn); + + elm_object_part_content_set(m->base, button_swallow[OTHER], m->other_btn); + evas_object_show(m->other_btn); + + elm_object_part_content_set(m->base, button_swallow[CLOSE], m->close_btn); + evas_object_show(m->close_btn); + } + + if (m->ap) { + elm_object_disabled_set(m->other_btn, EINA_FALSE); + elm_object_disabled_set(m->connect_btn, EINA_FALSE); + } else { + elm_object_disabled_set(m->connect_btn, EINA_TRUE); + elm_object_disabled_set(m->other_btn, EINA_TRUE); + } + } else if (m->network_type == TYPE_WIRED) { + if (!m->wired_conn) { + elm_object_disabled_set(m->connect_btn, EINA_TRUE); + elm_object_disabled_set(m->other_btn, EINA_TRUE); + } else { + elm_object_disabled_set(m->connect_btn, EINA_FALSE); + elm_object_disabled_set(m->other_btn, EINA_FALSE); + } + + elm_object_part_content_set(m->base, button_swallow[REFRESH], m->other_btn); + evas_object_show(m->other_btn); + + elm_object_part_content_set(m->base, button_swallow[OTHER], m->close_btn); + evas_object_show(m->close_btn); + } +} + + +void CNetworkMainView::m_CreateWirelessDisconnectPart(void) +{ + _DBG(); + Evas_Object *disconnect_ly; + + if (m->wireless_discon_ly) + return; + + disconnect_ly = util_add_layout(m->base, UG_NETWORK_EDJ_FILE, GRP_WIRELESS_DISCONNECT_LY); + if (!disconnect_ly) { + _ERR("call elm_layout_add() failed."); + return; + } + + elm_object_part_text_set(disconnect_ly, PART_DISCONNECT_TEXT, TXT_NO_NETWORK); + + evas_object_hide(disconnect_ly); + + m->wireless_discon_ly = disconnect_ly; +} + + +bool CNetworkMainView::m_CreateWiredConnectPart(void) +{ + _DBG(); + Evas_Object *box; + Evas_Object *btn; + + box = util_add_box(m->base, NULL); + if (!box) { + _ERR("add wired connect box failed."); + return false; + } + + elm_box_horizontal_set(box, EINA_FALSE); + + btn = util_add_button(box, STYLE_WIRED_LIST_BTN, NULL, _(m->profile_name)); + if (!btn) { + _ERR("elm_button_add failed."); + evas_object_del(box); + return false; + } + + evas_object_size_hint_align_set(btn, 0, 0); + m->pHandlerWiredConBox->Connect(btn); + if (m->wired_conn) + elm_object_signal_emit(btn, SIG_STATE_SELECTED, ELM); + elm_box_pack_end(box, btn); + elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_LEFT); + evas_object_hide(box); + + m->wired_con_box = box; + + return true; +} + + +bool CNetworkMainView::m_CreateWiredDisconnectPart(void) +{ + _DBG(); + Evas_Object *disconnect_ly; + + disconnect_ly = util_add_layout(m->base, UG_NETWORK_EDJ_FILE, GRP_WIRED_DISCONNECTED_LY); + if (!disconnect_ly) { + _ERR("call elm_layout_add() failed."); + return false; + } + + elm_object_part_text_set(disconnect_ly, PART_DISCONNECT_TEXT, _(TXT_PLUG_CABLE)); + + evas_object_hide(disconnect_ly); + + m->wired_discon_ly = disconnect_ly; + + return true; +} + + +Evas_Object* CNetworkMainView::m_CreateGenlistView(void) +{ + _DBG(); + Evas_Object *genlist; + + Elm_Genlist_Item_Class *ic; + + ic = elm_genlist_item_class_new(); + if (!ic) { + _ERR("elm_genlist_item_class_new() failed."); + return NULL; + } + + ic->item_style = STYLE_ITEM_LOCK; + ic->func.text_get = sm_GetApName; + ic->func.content_get = NULL; + ic->func.state_get = NULL; + ic->func.del = NULL; + + m->lock_ic = ic; + + ic = NULL; + ic = elm_genlist_item_class_new(); + if (!ic) { + _ERR("elm_genlist_item_class_new() failed."); + return NULL; + } + + ic->item_style = STYLE_ITEM_NOLOCK; + ic->func.text_get = sm_GetApName; + ic->func.content_get = NULL; + ic->func.state_get = NULL; + ic->func.del = NULL; + if (!ic) { + _ERR("get item class failed."); + return NULL; + } + + m->nolock_ic = ic; + + genlist = util_add_genlist(m->base); + if (!genlist) { + _ERR("util_add_genlist() failed."); + return NULL; + } + + m->genlist = genlist; + + elm_object_focus_next_object_set(genlist, genlist, ELM_FOCUS_LEFT); + elm_object_focus_next_object_set(genlist, m->close_btn, ELM_FOCUS_RIGHT); + + return genlist; +} + + +void CNetworkMainView::m_ClearGenlist(void) +{ + _DBG(); + void *temp; + + elm_genlist_clear(m->genlist); + + if (m->ap_list) + EINA_LIST_FREE(m->ap_list, temp) + free(temp); +} + + +void CNetworkMainView::sm_CbWifiConnected(wifi_error_e err, void *data) +{ + _DBG(); + CNetworkMainView *instance; + + if (!data) { + _ERR("Parameter error!"); + return; + } + + instance = (CNetworkMainView *) data; + instance->m_OnWifiConnected(err); +} + + +void CNetworkMainView::m_OnWifiConnected(wifi_error_e err) +{ + _DBG(); + if (!m->status_popup) + return; + + if (err != WIFI_ERROR_NONE) { + _ERR("connect AP failed."); + m_ShowConfirmPopup(); + return; + } + + ug_destroy_me(m->ug); +} + + +void CNetworkMainView::m_ConnectNetwork(void) +{ + _DBG(); + int index; + bool ret = false; + + if (m->network_type == TYPE_WIRELESS) { + if (m->last_item) { + index = elm_genlist_item_index_get(m->last_item); + + ret = m_WifiConnectAP(index); + if (ret != true) { + _ERR("connect ap"); + m_ShowConfirmPopup(); + return; + } + } + } else { + ret = m_WiredConnectAP(); + if (ret != true) { + _ERR("connect ap"); + m_ShowConfirmPopup(); + return; + } + } +} + + +bool CNetworkMainView::m_WifiConnectAP(int index) +{ + _DBG(); + struct wifi_ap_info *ap_info; + bool ret = false; + + if (index < 0) { + _ERR("Parameter error!"); + return false; + } + + m_ShowProgressPopup(); + + ap_info = (struct wifi_ap_info *) eina_list_nth(m->ap_list, index); + if (!ap_info) { + _ERR("ap info is NULL."); + return false; + } + + if (m->ap_name) { + free(m->ap_name); + m->ap_name = NULL; + } + + m->ap_name = strdup(ap_info->essid); + if (!m->ap_name) { + _ERR("ap name gets failed."); + return false; + } + + if (ap_info->secure_type == WIFI_SECURITY_TYPE_NONE) { + if (m->ap_pwd) { + free(m->ap_pwd); + m->ap_pwd = NULL; + } + } else { + m->cur_view = NETWORK_WIFI_PASSCODE_VIEW; +#if 0 + //m->pViewMgr->PushView(~~~) + //viewmgr_push(m->vmgr, wifi_passcode_view_vclass_get(), ap_info); +#endif + + return true; + } + + ret = m->pWifiMgr->ForgetAP(); + if (ret != true) { + _ERR("forget last ap failed."); + return false; + } + + if (m->ap_pwd) { + ret = m->pWifiMgr->SetPassPhrase(m->ap, m->ap_pwd); + if (ret != true) { + _ERR("wifi_mgr_set_passphrase() failed."); + return false; + } + } + + ret = m->pWifiMgr->Connect(m->ap, sm_CbWifiConnected, this); + if (ret != true) { + _ERR("Fail to connection request."); + return false; + } + return true; +} + + +bool CNetworkMainView::m_WiredConnectAP() +{ + _DBG(); + bool ret = false; + + m_ShowProgressPopup(); + + m->pNetConMgr->RefreshEthernetProfile(); + if(!m->pNetConMgr->GetProfileName(m->profile_name)) { + _ERR("Fail to get profile name"); + return false; + } + + ret = m_ConnectionSetLastNetwork(); + if (ret != true) { + _ERR("_connection_set_last_network() failed."); + return ret; + } + + ret = m->pNetConMgr->RegisterIpChangedCallback( sm_CbCheckGatewayAsync, this); + if (ret != true) { + _ERR("connection_mgr_get_is_online_async() failed."); + return false; + } + + return true; +} + + +bool CNetworkMainView::m_ConnectionSetLastNetwork(void) +{ + _DBG(); + enum setting_mode ip_mode; + struct network_info info; + + const char *str = NULL; + str = vconf_get_str(WIRED_IP_LAST_MODE); + if (str && !strcmp(str, _(TXT_OBTAIN_AUTO))) + ip_mode = MODE_AUTO; + else + ip_mode = MODE_MAN; + + bool result = false; + if (ip_mode == MODE_AUTO) { + result = m->pNetConMgr->SetIpConfType(CONNECTION_IP_CONFIG_TYPE_DYNAMIC); + if (result != true) { + _ERR("connection_mgr_ip_dynamic_config() failed."); + return false; + } + } else { + m_GetIpInfo(info.ip_addr, WIRED_IP_KEY); + m_GetIpInfo(info.submask, WIRED_SUBMASK_KEY); + m_GetIpInfo(info.gateway, WIRED_GATEWAY_KEY); + m_GetIpInfo(info.dns, WIRED_DNS_KEY); + } + + return true; +} + + +void CNetworkMainView::m_GetIpInfo(char *des, const char *key) +{ + _DBG(); + const char *str; + + if (!des || !key) + return; + + str = vconf_get_str(key); + if (!str) + return; + + if (str == '\0' || !strncmp(str, NULL_STRING, IP_STRING_MAX_SIZE)) + strncpy(des, _(ZERO_IP), IP_STRING_MAX_SIZE); + else + strncpy(des, str, IP_STRING_MAX_SIZE); +} + + +void CNetworkMainView::m_ShowConfirmPopup(void) +{ + _DBG(); + Evas_Object *layout; + Evas_Object *retry_btn; + Evas_Object *cancel_btn; + Evas_Coord w; + Evas_Coord h; + char content[CONTENT_TXT_SIZE]; + + if (m->status_popup) { + evas_object_hide(m->dim_ly); + evas_object_del(m->status_popup); + } + + evas_object_show(m->dim_ly); + + layout = util_add_layout(m->base, UG_NETWORK_EDJ_FILE, GRP_CONFIRM_LAYOUT); + if (!layout) { + _ERR("add layout failed."); + evas_object_hide(m->dim_ly); + return; + } + + evas_object_show(layout); + + memset(content, 0, CONTENT_TXT_SIZE); + if (m->network_type == TYPE_WIRED) { + elm_object_part_text_set(layout, PART_TEXT_TITLE, _(TXT_WIRED_LY)); + snprintf(content, CONTENT_TXT_SIZE - 1, "%s %s", _(TXT_FAILED_CONNECT), _(m->profile_name)); + } else { + elm_object_part_text_set(layout, PART_TEXT_TITLE, _(TXT_WIRELESS_LY)); + snprintf(content, CONTENT_TXT_SIZE - 1, "%s %s", _(TXT_FAILED_CONNECT), m->ap_name); + } + + elm_object_part_text_set(layout, PART_TEXT_CONTENT, content); + + retry_btn = util_add_button(layout, STYLE_SETTING_BTN, PART_RETRY_BTN, _(TXT_RETRY)); + if (!retry_btn) { + _ERR("util add button failed."); + evas_object_del(layout); + evas_object_hide(m->dim_ly); + return; + } + + cancel_btn = util_add_button(layout, STYLE_SETTING_BTN, PART_CANCEL_BTN, _(TXT_CANCEL)); + if (!cancel_btn) { + _ERR("util add button failed."); + evas_object_del(layout); + evas_object_hide(m->dim_ly); + return; + } + + elm_object_focus_next_object_set(retry_btn, cancel_btn, ELM_FOCUS_RIGHT); + elm_object_focus_next_object_set(cancel_btn, retry_btn, ELM_FOCUS_LEFT); + elm_object_focus_next_object_set(cancel_btn, cancel_btn, ELM_FOCUS_RIGHT); + elm_object_focus_next_object_set(retry_btn, retry_btn, ELM_FOCUS_LEFT); + elm_object_focus_next_object_set(cancel_btn, cancel_btn, ELM_FOCUS_UP); + elm_object_focus_next_object_set(retry_btn, retry_btn, ELM_FOCUS_UP); + elm_object_focus_next_object_set(cancel_btn, cancel_btn, ELM_FOCUS_DOWN); + elm_object_focus_next_object_set(retry_btn, retry_btn, ELM_FOCUS_DOWN); + + //evas_object_smart_callback_add(retry_btn, SIG_CLICKED, _retry_btn_clicked_cb, priv); + //evas_object_smart_callback_add(cancel_btn, SIG_CLICKED, _cancel_btn_clicked_cb, priv); + m->pHandlerConfirmPopup->Connect(retry_btn, 0); + m->pHandlerConfirmPopup->Connect(cancel_btn, 1); + + elm_object_focus_set(retry_btn, EINA_TRUE); + + elm_object_focus_allow_set(layout, EINA_TRUE); + //evas_object_smart_callback_add(layout, SIG_UNFOCUSED, _ctxpopup_unfocused_cb, priv); + //evas_object_event_callback_add(layout, EVAS_CALLBACK_KEY_DOWN, _ctxpopup_pressed_cb, priv); + m->pHandlerConfirmPopup->Connect(layout, 2); + + w = DEFAULT_WIN_WIDTH; + h = DEFAULT_WIN_HEIGHT; + + evas_object_move(layout, CENTER_ALIGN * (w - POPUP_WIDTH) * ELM_SCALE, CENTER_ALIGN * (h - POPUP_HEIGHT) * ELM_SCALE); + + m->status_popup = layout; +} + +void CNetworkMainView::m_ShowProgressPopup(void) +{ + _DBG(); + Evas_Object *layout; + Evas_Object *cancel_btn; + Evas_Coord w; + Evas_Coord h; + char content[CONTENT_TXT_SIZE]; + + if (m->status_popup) { + evas_object_hide(m->dim_ly); + evas_object_del(m->status_popup); + } + + evas_object_show(m->dim_ly); + + layout = util_add_layout(m->base, UG_NETWORK_EDJ_FILE, GRP_PROCESSING_LAYOUT); + if (!layout) { + _ERR("add layout failed."); + evas_object_hide(m->dim_ly); + return; + } + + evas_object_show(layout); + + m->status_popup = layout; + + memset(content, 0, CONTENT_TXT_SIZE); + if (m->network_type == TYPE_WIRED) { + elm_object_part_text_set(layout, PART_TEXT_TITLE, _(TXT_WIRED_LY)); + snprintf(content, CONTENT_TXT_SIZE - 1, "%s %s", _(TXT_CONNECTTING), _(m->profile_name)); + } else { + elm_object_part_text_set(layout, PART_TEXT_TITLE, _(TXT_WIRELESS_LY)); + snprintf(content, CONTENT_TXT_SIZE - 1, "%s %s", _(TXT_CONNECTTING), m->ap_name); + } + + elm_object_part_text_set(layout, PART_TEXT_CONTENT, content); + + cancel_btn = util_add_button(layout, STYLE_SETTING_BTN, PART_CANCEL_BTN, _(TXT_CANCEL)); + if (!cancel_btn) { + _ERR("util add button failed."); + evas_object_del(layout); + evas_object_hide(m->dim_ly); + return; + } + + evas_object_show(cancel_btn); + + elm_object_focus_next_object_set(cancel_btn, cancel_btn, ELM_FOCUS_LEFT); + elm_object_focus_next_object_set(cancel_btn, cancel_btn, ELM_FOCUS_RIGHT); + elm_object_focus_next_object_set(cancel_btn, cancel_btn, ELM_FOCUS_UP); + elm_object_focus_next_object_set(cancel_btn, cancel_btn, ELM_FOCUS_DOWN); + + //evas_object_smart_callback_add(cancel_btn, SIG_CLICKED, _cancel_btn_clicked_cb, priv); + m->pHandlerConfirmPopup->Connect(cancel_btn, 4); + elm_object_focus_set(cancel_btn, EINA_TRUE); + elm_object_focus_allow_set(layout, EINA_TRUE); + //evas_object_smart_callback_add(layout, SIG_UNFOCUSED, _ctxpopup_unfocused_cb, priv); + //evas_object_event_callback_add(layout, EVAS_CALLBACK_KEY_DOWN, _ctxpopup_pressed_cb, priv); + m->pHandlerConfirmPopup->Connect(layout, 5); + + w = DEFAULT_WIN_WIDTH; + h = DEFAULT_WIN_HEIGHT; + + evas_object_move(layout, CENTER_ALIGN * (w - POPUP_WIDTH) * ELM_SCALE, CENTER_ALIGN * (h - POPUP_HEIGHT) * ELM_SCALE); +} + + +void CNetworkMainView::t_OnShow() +{ + _DBG(); + + evas_object_show(m->base); + + CBaseView::t_OnShow(); +} + + +void CNetworkMainView::t_OnUpdate(void *data) +{ + _DBG(); + + evas_object_show(m->base); + + switch (m->cur_view) { + case NETWORK_IP_SETTING_VIEW: + elm_object_focus_set(m->other_btn, EINA_TRUE); + break; + case NETWORK_WIFI_PASSCODE_VIEW: + elm_object_focus_set(m->connect_btn, EINA_TRUE); + break; + default: + break; + } +} + + +void CNetworkMainView::t_OnHide() +{ + _DBG(); + + evas_object_hide(m->base); + + CBaseView::t_OnHide(); +} + + +bool CNetworkMainView::Create(void *data) +{ + _DBG(); + ASSERT(!m); + + bool ret = false; + + _CREATE_BEGIN{ + _CHECK(m = new SNetworkMainView) + _CHECK(m->win = CViewMgr::GetInstance()->Window()) + _CHECK(m_InitConnectionMgr()) + _CHECK(m->base = m_CreateMainLayout()) + _COMMAND{ + const char *str = NULL; + str = vconf_get_str(SELECTED_NETWORK_TYPE_KEY); + if (str && !strcmp(str, TXT_WIRED)) + m->network_type = TYPE_WIRED; + else + m->network_type = TYPE_WIRELESS; + } + _CHECK(m_CreateUpperLayout()) + _COMMAND{ + + if (m->network_type == TYPE_WIRELESS) + ret = m_SetWireless(); + else if (m->network_type == TYPE_WIRED) + ret = m_SetWired(); + else + ret = false; + } + _CHECK(ret) + _CHECK(m_CreateActionBtns()) + _CHECK(m_CreateDimLayout()) + + _WHEN_SUCCESS{ + m->pViewMgr = CViewMgr::GetInstance(); + } + + _CHECK_FAIL{ if(m->dim_ly) evas_object_del(m->dim_ly); } + _CHECK_FAIL{ m_DestroyActionBtns(); } + _CHECK_FAIL{ /* ret */ + if (m->lock_ic) + elm_genlist_item_class_free(m->lock_ic); + if (m->nolock_ic) + elm_genlist_item_class_free(m->nolock_ic); + if (m->ap_list) { + EINA_LIST_FREE(m->ap_list, data) + free(data); + } + if (m->timer) + ecore_timer_del(m->timer); + if (m->ap) + m->pWifiMgr->DestroyAP(m->ap); + + free(m->ap_name); + free(m->ap_pwd); + + if(m->pWifiMgr) { + CWifiMgr::Finalize(); + m->pWifiMgr = NULL; + } + } + _CHECK_FAIL{ /* m_CreateUpperLayout() */ } + _CHECK_FAIL{ evas_object_del(m->base); } + _CHECK_FAIL{ m_FinalizeConnectionMgr(); } + _CHECK_FAIL{ /* m->win = CViewMgr::GetInstance()->Window() */ } + _CHECK_FAIL{ delete m; m = NULL; } + } _CREATE_END_AND_CATCH{ return false; } + + _DBG("Done"); + return true; +} + + +void CNetworkMainView::Destroy() +{ + ASSERT(m); + _DBG(); + + CBaseView::Destroy(); + delete m; + m = NULL; +} + +Evas_Object* CNetworkMainView::Base() +{ + ASSERT(m); + _DBG(); + + return m->base; +} + diff --git a/ug/network/src/main_view.cpp b/ug/network/src/main_view.cpp deleted file mode 100644 index a83f300..0000000 --- a/ug/network/src/main_view.cpp +++ /dev/null @@ -1,2485 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "defs.h" -#include "dbg.h" -#include "main_view.h" -#include "ip_setting_view.h" -#include "i18n.h" -#include "common.h" -#include "wifi_passcode_view.h" -#include "util.h" -#include -#include -#include "network_viewmgr.h" - -#include "WifiMgr.h" -#include "NetConMgr.h" - -#define BTN_ACT 4 -#define BTN_TYPE 2 -#define TIMER_INTERNAL 0.1 - -#define KEY_PRIV "priv" - -#define TYPE_POPUP_X_OFFSET 190 - -enum action_btn_enum { - CONNECT, - REFRESH, - OTHER, - CLOSE -}; - -static char *action_button[4] = { TXT_CONNECT_BTN, TXT_REFRESH_BTN, TXT_OTHER_BTN, TXT_CLOSE_BTN }; -static char *button_swallow[4] = { PART_CONNECT_BTN, PART_REFRESH_BTN, PART_OTHER_BTN, PART_CLOSE_BTN }; -static char *popup_button[2] = { TXT_WIRELESS, TXT_WIRED }; - -struct _priv { - ui_gadget_h ug; - struct viewmgr *vmgr; - - Evas_Object *win; - Evas_Object *base; - Evas_Object *type_btn; - Evas_Object *network_ctxpopup; - Evas_Object *dim_ly; - Evas_Object *connect_btn; - Evas_Object *refresh_btn; - Evas_Object *other_btn; - Evas_Object *close_btn; - Evas_Object *genlist; - Evas_Object *wired_con_box; - Evas_Object *wireless_discon_ly; - Evas_Object *wired_discon_ly; - Evas_Object *status_popup; - - Elm_Genlist_Item_Class *lock_ic; - Elm_Genlist_Item_Class *nolock_ic; - Elm_Object_Item *last_item; - - Eina_List *ap_list; - Ecore_Timer *timer; - - enum network_type_enum network_type; - enum view_type cur_view; - - int wifi_init; - Eina_Bool wifi_conn; - Eina_Bool wired_conn; - - char profile_name[MAX_NAME_SIZE]; - - wifi_ap_h ap; - char *ap_name; - char *ap_pwd; - - CWifiMgr *pWifiMgr; - CNetConMgr *pNetConMgr; -}; - -static void _show_confirm_popup(struct _priv *priv); -static void _show_progress_popup(struct _priv *priv); - -/** -* Initialize the priv -* -* Called when initialize the network -* -* @return the _priv object initialized -*/ -static struct _priv *_init_priv() -{ - struct _priv *priv; - - priv = (struct _priv *) calloc(1, sizeof(*priv)); - if (!priv) { - _ERR("calloc priv failed."); - return NULL; - } - - return priv; -} - -/** -* Finalize the priv -* -* Called when app is destroyed -* -* @param[in] priv the _priv object -*/ -static void _fini_priv(struct _priv *priv) -{ - void *data; - - if (!priv) - return; - - if (priv->lock_ic) - elm_genlist_item_class_free(priv->lock_ic); - - if (priv->nolock_ic) - elm_genlist_item_class_free(priv->nolock_ic); - - if (priv->ap_list) - EINA_LIST_FREE(priv->ap_list, data) - free(data); - - if (priv->dim_ly) - evas_object_del(priv->dim_ly); - - if (priv->timer) - ecore_timer_del(priv->timer); - - if(priv->pNetConMgr) { - CNetConMgr::Finalize(); - priv->pNetConMgr = NULL; - } - - if (priv->ap) - { - priv->pWifiMgr->DestroyAP(priv->ap); - } - - free(priv->ap_name); - free(priv->ap_pwd); - - if(priv->pWifiMgr) { - CWifiMgr::Finalize(); - priv->pWifiMgr = NULL; - } - - free(priv); -} - -/** -* Eable the "Connect" button -* -* @param[in] priv _priv object bypassed -*/ -static void _enable_connect_btn(struct _priv *priv) -{ - if (!priv || !priv->connect_btn) { - _ERR("The param is invalid."); - return; - } - - elm_object_disabled_set(priv->connect_btn, EINA_FALSE); -} - -/** -* Disable the "Connect" button -* -* @param[in] priv _priv object bypassed -*/ -static void _disable_connect_btn(struct _priv *priv) -{ - if (!priv || !priv->connect_btn) { - _ERR("The param is invalid."); - return; - } - - elm_object_disabled_set(priv->connect_btn, EINA_TRUE); -} - -/** -* Enable the "Other" button -* -* @param[in] priv _priv object bypassed -*/ -static void _enable_other_btn(struct _priv *priv) -{ - if (!priv || !priv->other_btn) { - _ERR("The param is invalid."); - return; - } - - elm_object_disabled_set(priv->other_btn, EINA_FALSE); -} - -/** -* Disable the "Other" button -* -* @param[in] priv _priv object bypassed -*/ -static void _disable_other_btn(struct _priv *priv) -{ - if (!priv || !priv->other_btn) { - _ERR("The param is invalid."); - return; - } - - elm_object_disabled_set(priv->other_btn, EINA_TRUE); -} - -/** -* Enable the dim effect -* -* Called when popup is displayed -* -* @param[in] priv _priv object bypassed -*/ -static void _set_layout_dim(struct _priv *priv) -{ - if (!priv || !priv->dim_ly) { - _ERR("The param is invalid.\n"); - return; - } - - evas_object_show(priv->dim_ly); -} - -/** -* Disable the dim effect -* -* This function is the opposite action of the set_layout_dim -* -* @param[in] priv _priv object bypassed -*/ -static void _unset_layout_dim(struct _priv *priv) -{ - if (!priv || !priv->dim_ly) { - _ERR("The param is invalid.\n"); - return; - } - - evas_object_hide(priv->dim_ly); -} - -/** -* Evas_object_Event_Cb type callback for handling delection event -* -* @param[in] data the user data -* @param[in] e evas handler -* @param[in] obj the corresponding object which clicked event occurred -* @param[in] ei event information -*/ -static void _ctxpopup_pressed_cb(void *data, Evas *e, - Evas_Object *obj, void *ei) -{ - Evas_Event_Key_Down *ev; - struct _priv *priv; - - if (!data || !ei || !obj) { - _ERR("Parameter error!"); - return; - } - - priv = (struct _priv *) data; - ev = (Evas_Event_Key_Down *) ei; - - if (!ev->keyname) { - _ERR("ev->keyname is NULL."); - return; - } - - if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) { - _unset_layout_dim(priv); - evas_object_del(obj); - } -} - -/** -* Delete the connection progress popup when connection successed or failed -* -* @param[in] priv _priv object bypassed -*/ -static void _del_status_popup(struct _priv *priv) -{ - if (!priv) { - _ERR("priv is NULL."); - return; - } - - _unset_layout_dim(priv); - - if (priv->status_popup) - evas_object_del(priv->status_popup); - - priv->status_popup = NULL; -} - -/** -* Evas_Object_Event_Cb type callback for handling back event -* -* This function delete the ug when EVAS_CALLBACK_KEY_DOWN happens -* -* @param[in] data the user data -* @param[in] e evas handler -* @param[in] obj the corresponding object which clicked event occurred -* @param[in] ei event information -*/ -static void _main_ly_key_pressed_cb(void *data, Evas *e, - Evas_Object *obj, void *ei) -{ - Evas_Event_Key_Down *ev; - struct _priv *priv; - - if (!data || !ei) { - _ERR("Parameter error!"); - return; - } - - priv = (struct _priv *) data; - ev = (Evas_Event_Key_Down *) ei; - - if (!ev->keyname) { - _ERR("ev->keyname is NULL."); - return; - } - - if (!priv->ug) - return; - - if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) - ug_destroy_me(priv->ug); -} - -/** -* Create the base layout -* -* Called by _create when network is invoked -* -* @param[in] priv _priv object bypassed -*/ -static Evas_Object *_create_main_layout(struct _priv *priv) -{ - Evas_Object *base; - - if (!priv) { - _ERR("Parameter error!"); - return NULL; - } - - base = util_add_layout(priv->win, UG_NETWORK_EDJ_FILE, GRP_MAIN); - if (!base) { - _ERR("Add pannel view failed.\n"); - return NULL; - } - - evas_object_event_callback_add(base, EVAS_CALLBACK_KEY_DOWN, - _main_ly_key_pressed_cb, priv); - - evas_object_show(base); - - return base; -} - -/** -* Refresh the object of the defined part -* -* @param[in] priv _priv object bypassed -* @param[in] obj the Evas_Object to be setted to the part -*/ -static void _fill_content_part(struct _priv *priv, Evas_Object *obj) -{ - Evas_Object *old_obj; - - if (!priv || !obj || !priv->base) { - _ERR("The param is invalid.\n"); - return; - } - - old_obj = elm_object_part_content_get(priv->base, PART_NETLIST_PANNEL); - if (old_obj == obj) { - _ERR("PART_NETLIST_PANNEL already filled with this object."); - return; - } - - if (old_obj) { - elm_object_part_content_unset(priv->base, PART_NETLIST_PANNEL); - evas_object_hide(old_obj); - } - - elm_object_part_content_set(priv->base, PART_NETLIST_PANNEL, obj); - - evas_object_show(obj); -} - -/** -* Refresh the buttons of the correct position -* -* Called when the view type is changed -* -* @param[in] priv _priv object bypassed -*/ -static void _set_action_btn_pos(struct _priv *priv) -{ - Evas_Object *base; - Evas_Object *btn; - - if (!priv || !priv->base) { - _ERR("Parameter error!"); - return; - } - - base = priv->base; - - btn = elm_object_part_content_get(base, button_swallow[CONNECT]); - if (!btn) { - elm_object_part_content_set(base, button_swallow[CONNECT], - priv->connect_btn); - evas_object_show(priv->connect_btn); - } - - btn = elm_object_part_content_get(base, button_swallow[REFRESH]); - if (btn) { - elm_object_part_content_unset(base, button_swallow[REFRESH]); - evas_object_hide(btn); - } - - btn = elm_object_part_content_get(base, button_swallow[OTHER]); - if (btn) { - elm_object_part_content_unset(base, button_swallow[OTHER]); - evas_object_hide(btn); - } - - btn = elm_object_part_content_get(base, button_swallow[CLOSE]); - if (btn) { - elm_object_part_content_unset(base, button_swallow[CLOSE]); - evas_object_hide(btn); - } - - if (priv->network_type == TYPE_WIRELESS) { - if (!priv->wifi_conn) { - elm_object_part_content_set(base, - button_swallow[REFRESH], - priv->other_btn); - evas_object_show(priv->other_btn); - - elm_object_part_content_set(base, button_swallow[OTHER], - priv->close_btn); - evas_object_show(priv->close_btn); - } else { - elm_object_part_content_set(base, - button_swallow[REFRESH], - priv->refresh_btn); - evas_object_show(priv->refresh_btn); - - elm_object_part_content_set(base, button_swallow[OTHER], - priv->other_btn); - evas_object_show(priv->other_btn); - - elm_object_part_content_set(base, button_swallow[CLOSE], - priv->close_btn); - evas_object_show(priv->close_btn); - } - - if (priv->ap) { - elm_object_disabled_set(priv->other_btn, EINA_FALSE); - elm_object_disabled_set(priv->connect_btn, EINA_FALSE); - } else { - elm_object_disabled_set(priv->connect_btn, EINA_TRUE); - elm_object_disabled_set(priv->other_btn, EINA_TRUE); - } - } else if (priv->network_type == TYPE_WIRED) { - if (!priv->wired_conn) { - elm_object_disabled_set(priv->connect_btn, EINA_TRUE); - elm_object_disabled_set(priv->other_btn, EINA_TRUE); - } else { - elm_object_disabled_set(priv->connect_btn, EINA_FALSE); - elm_object_disabled_set(priv->other_btn, EINA_FALSE); - } - - elm_object_part_content_set(base, button_swallow[REFRESH], - priv->other_btn); - evas_object_show(priv->other_btn); - - elm_object_part_content_set(base, button_swallow[OTHER], - priv->close_btn); - evas_object_show(priv->close_btn); - } -} - -/** -* Callback function to set content to list panel -* -* Depending on different ethernet, set corresponding connection state -* view to the list panel -* -* @param[in] priv _priv object bypassed -*/ -static void _connection_ethernet_state_callback(bool state, void *data) -{ - struct _priv *priv; - - if (!data) { - _ERR("data is NULL."); - return; - } - - priv = (struct _priv *) data; - - if (priv->network_type != TYPE_WIRED) { - _ERR("cur network type is wireless, return."); - return; - } - - if (state == true) { // ethernet connected - _fill_content_part(priv, priv->wired_con_box); - } else { - _fill_content_part(priv, priv->wired_discon_ly); - - priv->wired_conn = EINA_FALSE; - } - - _set_action_btn_pos(priv); -} - -/** -* Initialize the connection information -* -* @param[in] priv _priv object bypassed -* @return 0 on success,otherwise -1 -*/ -static int _init_connection(struct _priv *priv) -{ - if (!priv) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - if(!CNetConMgr::Initialize()) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - priv->pNetConMgr = CNetConMgr::GetInstance(); - if (!priv->pNetConMgr) { - _ERR("Fail to get instance"); - return RET_FAILED; - } - - if(!priv->pNetConMgr->GetProfileName(priv->profile_name)) { - _ERR("Fail to get instance"); - return RET_FAILED; - } - - if(!priv->pNetConMgr->RegisterIpChangedCallback( _connection_ethernet_state_callback, priv)) { - _ERR("register_ethernet_state_cb() failed."); - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** -* Create the layout when no network cable plugin -* -* @param[in] priv _priv object bypassed -* @return 0 on success,otherwise -1 -*/ -static int _create_wired_disconnect_part(struct _priv *priv) -{ - Evas_Object *disconnect_ly; - - if (!priv || !priv->base) { - _ERR("the param is NULL.\n"); - return RET_FAILED; - } - - disconnect_ly = util_add_layout(priv->base, - UG_NETWORK_EDJ_FILE, GRP_WIRED_DISCONNECTED_LY); - if (!disconnect_ly) { - _ERR("call elm_layout_add() failed.\n"); - return RET_FAILED; - } - - elm_object_part_text_set(disconnect_ly, PART_DISCONNECT_TEXT, - _(TXT_PLUG_CABLE)); - - evas_object_hide(disconnect_ly); - - priv->wired_discon_ly = disconnect_ly; - - return RET_SUCCESS; -} - -/** -* Callback function when profile button is clicked -* -* This function disable/enable the relating buttons according to the connection state -* -* @param[in] data the user data -* @param[in] obj the corresponding object which clicked event occurred -* @param[in] event_inf event information -*/ -static void _profie_btn_clicked_cb(void *data, - Evas_Object *obj, void *event_inf) -{ - struct _priv *priv; - - if (!data) { - _ERR("Parameter error!"); - return; - } - - priv = (struct _priv *) data; - - if (priv->wired_conn) { - elm_object_signal_emit(obj, SIG_STATE_UNSELECTED, ELM); - priv->wired_conn = EINA_FALSE; - _disable_connect_btn(priv); - _disable_other_btn(priv); - } else { - elm_object_signal_emit(obj, SIG_STATE_SELECTED, ELM); - priv->wired_conn = EINA_TRUE; - _enable_connect_btn(priv); - _enable_other_btn(priv); - } -} - -/** -* Create the layout when wired connect successful -* -* @param[in] priv _priv object bypassed -* @return 0 on success,otherwise -1 -*/ -static int _create_wired_connect_part(struct _priv *priv) -{ - Evas_Object *box; - Evas_Object *btn; - - if (!priv || !priv->base) { - _ERR("the param is NULL.\n"); - return RET_FAILED; - } - - box = util_add_box(priv->base, NULL); - if (!box) { - _ERR("add wired connect box failed."); - return RET_FAILED; - } - - elm_box_horizontal_set(box, EINA_FALSE); - - btn = util_add_button(box, STYLE_WIRED_LIST_BTN, NULL, - _(priv->profile_name)); - if (!btn) { - _ERR("elm_button_add failed.\n"); - evas_object_del(box); - return RET_FAILED; - } - - evas_object_size_hint_align_set(btn, 0, 0); - evas_object_smart_callback_add(btn, SIG_CLICKED, - _profie_btn_clicked_cb, priv); - if (priv->wired_conn) - elm_object_signal_emit(btn, SIG_STATE_SELECTED, ELM); - elm_box_pack_end(box, btn); - elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_LEFT); - evas_object_hide(box); - - priv->wired_con_box = box; - - return RET_SUCCESS; -} - -/** -* Display the wired view when select the wired network type -* -* This fuction is called when the wired of the network type popup is clicked -* -* @param[in] priv _priv object bypassed -* @return 0 on success,otherwise -1 -*/ -static int _display_wired_setting(struct _priv *priv) -{ - bool plugin; - - if (!priv) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - _create_wired_connect_part(priv); - - _create_wired_disconnect_part(priv); - - if(!priv->pNetConMgr->GetEthernetState(&plugin)) { - _ERR("connection_mgr_get_ethernet_state() failed."); - plugin = false; - } - - if (plugin) { - _fill_content_part(priv, priv->wired_con_box); - } else { - priv->wired_conn = EINA_FALSE; - _fill_content_part(priv, priv->wired_discon_ly); - } - - _set_action_btn_pos(priv); - - return RET_SUCCESS; -} - -/** -* Create the layout when wireless connect successful -* -* @param[in] priv _priv object bypassed -* @return 0 on success,otherwise -1 -*/ -static void _create_wireless_disconnect_part(struct _priv *priv) -{ - Evas_Object *disconnect_ly; - - if (!priv) { - _ERR("the param is invalid."); - return; - } - - if (priv->wireless_discon_ly) - return; - - disconnect_ly = util_add_layout(priv->base, - UG_NETWORK_EDJ_FILE, GRP_WIRELESS_DISCONNECT_LY); - if (!disconnect_ly) { - _ERR("call elm_layout_add() failed.\n"); - return; - } - - elm_object_part_text_set(disconnect_ly, PART_DISCONNECT_TEXT, - TXT_NO_NETWORK); - - evas_object_hide(disconnect_ly); - - priv->wireless_discon_ly = disconnect_ly; -} - -/** -* Callback funcion called to get the text name of the added item -* -* This function return the strdup'()ed string of the added genlist item -* -* @param[in] data the user data -* @param[in] obj the genlist object -* @param[in] part the part text -* @return strdup'()ed string on success ,NULL otherwise -*/ -static char *_item_ap_name_get(void *data, Evas_Object *obj, const char *part) -{ - struct wifi_ap_info *ap_info; - - if (!data || !obj || !part) { - _ERR("Parameter error!"); - return NULL; - } - - ap_info = (struct wifi_ap_info *) data; - - if (!strcmp(part, PART_ELM_TEXT)) - return strdup(ap_info->essid); - - return NULL; -} - -/** -* Create a new genlist item class in a given genlist widget -* -* @param[in] style the genlist style set to the item -* @return new allocated genlist item class -*/ -static Elm_Genlist_Item_Class *_create_item_class(char *style) -{ - Elm_Genlist_Item_Class *ic; - - if (!style) { - _ERR("the param is invalid."); - return NULL; - } - - ic = elm_genlist_item_class_new(); - if (!ic) { - _ERR("elm_genlist_item_class_new() failed."); - return NULL; - } - - ic->item_style = style; - ic->func.text_get = _item_ap_name_get; - ic->func.content_get = NULL; - ic->func.state_get = NULL; - ic->func.del = NULL; - - return ic; -} - -/** -* Create the genlist item class for both locked and unlocked -* -* @param[in] priv the data _priv structure bypassed -*/ -static void _create_genlist_item_class(struct _priv *priv) -{ - Elm_Genlist_Item_Class *ic; - - if (!priv) { - _ERR("the param is invalid."); - return; - } - - ic = _create_item_class(STYLE_ITEM_LOCK); - if (!ic) { - _ERR("get item class failed."); - return; - } - - priv->lock_ic = ic; - - ic = _create_item_class(STYLE_ITEM_NOLOCK); - if (!ic) { - _ERR("get item class failed."); - return; - } - - priv->nolock_ic = ic; -} - -/** -* Create the genlist view -* -* This function create the genlist item class and genlist widget -* -* @param[in] priv _priv object bypassed -* @return the genlist object in success,NULL otherwise -*/ -static Evas_Object *_create_genlist_view(struct _priv *priv) -{ - Evas_Object *genlist; - - if (!priv) { - _ERR("Parameter error!"); - return NULL; - } - - _create_genlist_item_class(priv); - - genlist = util_add_genlist(priv->base); - if (!genlist) { - _ERR("util_add_genlist() failed.\n"); - return NULL; - } - - priv->genlist = genlist; - - elm_object_focus_next_object_set(genlist, genlist, ELM_FOCUS_LEFT); - elm_object_focus_next_object_set(genlist, priv->close_btn, - ELM_FOCUS_RIGHT); - - return genlist; -} - -/** -* Callback function called when a certain genlist item is clicked -* -* @param[in] data the user data -* @param[in] obj the corresponding item which clicked event occurred -* @param[in] event_inf event information -*/ -static void _item_select_cb(void *data, Evas_Object *obj, void *ei) -{ - struct _priv *priv; - Elm_Object_Item *gen_item; - struct wifi_ap_info *ap_info; - int index; - - if (!data || !ei) { - _ERR("Parameter error!"); - return; - } - - priv = (struct _priv *) data; - gen_item = (Elm_Object_Item *) ei; - - if (priv->last_item == gen_item) { - elm_object_item_signal_emit(gen_item, SIG_STATE_UNSELECTED, ELM); - - _disable_connect_btn(priv); - _disable_other_btn(priv); - - priv->last_item = NULL; - - return; - } - - elm_object_item_signal_emit(gen_item, SIG_STATE_SELECTED, ELM); - if (priv->last_item) - elm_object_item_signal_emit(priv->last_item, - SIG_STATE_UNSELECTED, ELM); - priv->last_item = gen_item; - - _enable_connect_btn(priv); - _enable_other_btn(priv); - - index = elm_genlist_item_index_get(priv->last_item); - if (index < 0) { - _ERR("the index of item is invalid."); - return; - } - - ap_info = (struct wifi_ap_info *) eina_list_nth(priv->ap_list, index); - if (!ap_info) { - _ERR("ap info is NULL."); - return; - } - - if (priv->ap_name) { - free(priv->ap_name); - priv->ap_name = NULL; - } - - priv->ap_name = strdup(ap_info->essid); - if (!priv->ap_name) { - _ERR("ap name gets failed."); - return; - } - - if (priv->ap) { - priv->pWifiMgr->DestroyAP(priv->ap); - priv->ap = NULL; - } - - priv->pWifiMgr->CloneAP(&priv->ap, ap_info->ap); - if (!priv->ap) { - _ERR("ap clone failed."); - return; - } - - if (ap_info->secure_type == WIFI_SECURITY_TYPE_NONE) { - if (priv->ap_pwd) { - free(priv->ap_pwd); - priv->ap_pwd = NULL; - } - } -} - -/** -* Effect the connected state when timer is empired -* -* @param[in]data the user data -* @return ECORE_CALLBACK_CANCEL returns to finish time -*/ -static Eina_Bool _select_connected_cb(void *data) -{ - struct _priv *priv; - - if (!data) { - _ERR("Parameter error!"); - return ECORE_CALLBACK_CANCEL; - } - - priv = (struct _priv *) data; - - elm_object_item_signal_emit(priv->last_item, SIG_STATE_SELECTED, ELM); - _enable_connect_btn(priv); - _enable_other_btn(priv); - - priv->timer = NULL; - - return ECORE_CALLBACK_CANCEL; -} - -/** -*This is a callback function called when you get the found access point repeatedly -* -* The ap valid only here. if use outside the function, must wifi_mgr_ap_clone() to clone it -* -* @param[in] ap the access point -* @param[in] data the user data -* @return 0 to continue with the next iterator of the loop,-1 to break -*/ -static bool _wifi_found_ap_cb(wifi_ap_h ap, void *data) -{ - bool ret; - bool state; - struct _priv *priv; - struct wifi_ap_info *ap_info; - Elm_Object_Item *item; - - if (!ap || !data) { - _ERR("Parameter error!"); - return EINA_FALSE; - } - - priv = (struct _priv *) data; - - ret = priv->pWifiMgr->IsActivated(&state); - if (ret != true || state == 0) { - _ERR("failt to wifi_is_activated"); - return EINA_FALSE; - } - - ap_info = (struct wifi_ap_info *) calloc(1, sizeof(*ap_info)); - if (!ap_info) { - _ERR("calloc failed"); - return EINA_FALSE; - } - - ret = priv->pWifiMgr->GetESSID(ap, ap_info->essid); - if(ret != true) { - _ERR("Fail to get info"); - return EINA_FALSE; - } - - ret = priv->pWifiMgr->GetConnectionState(ap, &ap_info->state); - if(ret != true) { - _ERR("Fail to get info"); - return EINA_FALSE; - } - - ret = priv->pWifiMgr->GetSecurityType(ap, &ap_info->secure_type); - if(ret != true) { - _ERR("Fail to get info"); - return EINA_FALSE; - } - - ap_info->ap = ap; - ap_info->user_data = priv; - priv->ap_list = eina_list_append(priv->ap_list, ap_info); - - _fill_content_part(priv, priv->genlist); - - if (ap_info->secure_type == WIFI_SECURITY_TYPE_NONE) - item = elm_genlist_item_append(priv->genlist, priv->nolock_ic, - ap_info, NULL, ELM_GENLIST_ITEM_NONE, - _item_select_cb, priv); - else - item = elm_genlist_item_append(priv->genlist, priv->lock_ic, - ap_info, NULL, ELM_GENLIST_ITEM_NONE, - _item_select_cb, priv); - if (!item) { - _ERR("genlist append item failed."); - return EINA_FALSE; - } - - if (ap_info->state == WIFI_CONNECTION_STATE_CONNECTED) { - priv->last_item = item; - if (priv->ap) { - ret = priv->pWifiMgr->DestroyAP(priv->ap); - if(ret != true) { - _ERR("Fail to destroy AP"); - } - priv->ap = NULL; - } - - ret = priv->pWifiMgr->CloneAP(&priv->ap, ap); - if(ret != true) { - _ERR("Fail to clone AP"); - } - - priv->timer = ecore_timer_add(TIMER_INTERNAL, - _select_connected_cb, priv); - if (!priv->timer) { - _ERR("add timer failed."); - return EINA_FALSE; - } - } - - return EINA_TRUE; -} - -/** -* Scan the wifi access point -* -* @param[in] error_code the wifi error type -* @param[in] data the user data -*/ -static void _wifi_scan_request_cb(wifi_error_e error_code, void *data) -{ - struct _priv *priv; - bool ret; - - if (!data) { - _ERR("data is NULL."); - return; - } - - priv = (struct _priv *) data; - - ret = priv->pWifiMgr->RegisterFoundAPCallback(_wifi_found_ap_cb, data); - if (ret != true) { - _ERR("wifi_mgr_foreach_found_aps() failed."); - return; - } -} - -/** -* Callback function briefly called after wifi activated successfully -* -* @param[in] error_code the wifi activation error type -* @param[in] data the user data -*/ -static void _wifi_activated_cb(wifi_error_e result, void *data) -{ - struct _priv *priv; - bool ret; - - priv = (struct _priv *) data; - - if (result != WIFI_ERROR_NONE) { - _ERR("Wi-Fi Activation Failed! error == %s", priv->pWifiMgr->GetErrorMsg(result)); - return; - } - - if (!data) { - _ERR("Parameter error!"); - return; - } - - ret = priv->pWifiMgr->RegisterScanCallback(_wifi_scan_request_cb, data); - if (ret != true) { - _ERR("wifi_mgr_scan_request() failed."); - _fill_content_part(priv, priv->wireless_discon_ly); - _set_action_btn_pos(priv); - return; - } - - priv->wifi_conn = EINA_TRUE; - - _set_action_btn_pos(priv); - - _fill_content_part(priv, priv->genlist); -} - -/** -* Clear the genlist item list. -* -* Called when need clear the ap list,eg.refrsh button is clicked -* -* @param[in] priv _priv object bypassed -*/ -static void _clear_genlist_item_list(struct _priv *priv) -{ - void *temp; - - if (!priv || !priv->genlist) { - _ERR("Parameter error!"); - return; - } - - elm_genlist_clear(priv->genlist); - - if (priv->ap_list) - EINA_LIST_FREE(priv->ap_list, temp) - free(temp); -} - -/** -* Display the wireless view when select the wireless network type -* -* Called when the wireless of the network type popup is clicked -* -* @param[in] priv _priv object bypassed -* @return 0 on success,otherwise -1 -*/ -static int _display_wireless_setting(struct _priv *priv) -{ - Evas_Object *obj; - bool activated; - bool ret = false; - - if (!priv) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - _create_wireless_disconnect_part(priv); - - if (!priv->wifi_init) { - obj = _create_genlist_view(priv); - if (!obj) { - _ERR("fail to create genlist"); - return RET_FAILED; - } - - ret = CWifiMgr::Initialize(); - if(ret != true) { - _ERR("Fail to initialize WifiMgr"); - return RET_FAILED; - } - priv->pWifiMgr = CWifiMgr::GetInstance(); - if(!priv->pWifiMgr) { - _ERR("Fail to get instance"); - return RET_FAILED; - } - - priv->wifi_init = 1; - } - - _clear_genlist_item_list(priv); - - activated = EINA_FALSE; - ret = priv->pWifiMgr->IsActivated(&activated); - if (ret != true) { - _ERR("the wifi is not activated."); - return RET_FAILED; - } - - if (activated) { - if (priv->ap) { - ret = priv->pWifiMgr->DestroyAP(priv->ap); - if(ret != true) { - _ERR("Fail to destroy AP"); - } - priv->ap = NULL; - } - - ret = priv->pWifiMgr->RegisterScanCallback(_wifi_scan_request_cb, (void *)priv); - if (ret != true) { - _ERR("wifi_mgr_scan_request() failed."); - goto _wireless_finish; - } - - priv->wifi_conn = EINA_TRUE; - } else { - priv->wifi_conn = EINA_FALSE; - - ret = priv->pWifiMgr->Activate(_wifi_activated_cb, (void *)priv); - if (ret != true) - _ERR("wifi_mgr_activate() failed."); - } - -_wireless_finish: - _fill_content_part(priv, priv->wireless_discon_ly); - _set_action_btn_pos(priv); - - return RET_SUCCESS; -} - -/** -* Refresh the text content below the network type button -* -* Called to set the network type name according to the network type currently -* -* @param[in] priv _priv object bypassed -*/ -static void _refresh_network_type_text(struct _priv *priv) -{ - if (!priv) { - _ERR("the param is invalid."); - return; - } - - switch (priv->network_type) { - case TYPE_WIRELESS: - elm_object_part_text_set(priv->base, - PART_CUR_TYPE_TEXT, - _(TXT_WIRELESS_NETWORK)); - elm_object_part_text_set(priv->type_btn, - PART_NETWORK_TYPE_SELECTED, - _(TXT_WIRELESS)); - break; - case TYPE_WIRED: - elm_object_part_text_set(priv->base, - PART_CUR_TYPE_TEXT, _(TXT_WIRED_NETWORK)); - elm_object_part_text_set(priv->type_btn, - PART_NETWORK_TYPE_SELECTED, _(TXT_WIRED)); - break; - default: - break; - } -} - -/** -* Callback function when popup type button is clicked -* -* This fuction set the current network type according to the clicked button text -* -* @param[in] priv _priv object bypassed -*/ -static void _type_select_btn_cb(void *data, - Evas_Object *obj, void *event_inf) -{ - struct _priv *priv; - const char *value; - - if (!data || !obj) { - _ERR("the param is invalid."); - return; - } - - priv = (struct _priv *) data; - - value = elm_object_text_get(obj); - if (!value) { - _ERR("get text from network type btn is NULL."); - return; - } - - if ((!strcmp(value, _(popup_button[TYPE_WIRELESS]))) - && priv->network_type == TYPE_WIRED) { - priv->network_type = TYPE_WIRELESS; - - _display_wireless_setting(priv); - vconf_set_str(SELECTED_NETWORK_TYPE_KEY, TXT_WIRELESS); - } else if ((!strcmp(value, _(popup_button[TYPE_WIRED]))) - && priv->network_type == TYPE_WIRELESS) { - priv->network_type = TYPE_WIRED; - - _display_wired_setting(priv); - vconf_set_str(SELECTED_NETWORK_TYPE_KEY, TXT_WIRED); - } - - _refresh_network_type_text(priv); - - if (priv->network_ctxpopup) { - evas_object_del(priv->network_ctxpopup); - priv->network_ctxpopup = NULL; - } - - _unset_layout_dim(priv); -} - -/** -* Evas_Object_Event_Cb type callback for handling back event -* -* @param[in] data the user data -* @param[in] e evas handler -* @param[in] o the corresponding object which clicked event occurred -* @param[in] ei event information -*/ -static void _type_key_pressed_cb(void *data, - Evas *evas, Evas_Object *o, void *ei) -{ - Evas_Event_Key_Down *ev; - struct _priv *priv; - - if (!ei || !data) { - _ERR("The param is invalid.\n"); - return; - } - - priv = (struct _priv *) data; - ev = (Evas_Event_Key_Down *) ei; - - if (!ev->keyname) { - _ERR("ev->keyname is NULL."); - return; - } - - if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) { - _unset_layout_dim(priv); - - if (priv->network_ctxpopup) { - evas_object_del(priv->network_ctxpopup); - priv->network_ctxpopup = NULL; - } - - return; - } -} - -/** -* Evas_Smart_Cb type callback for handling clicked event -* -* @param[in] data the user data -* @param[in] obj the corresponding object which clicked event occurred -* @param[in] event_inf event information -*/ -static void _network_type_btn_clicked_cb(void *data, - Evas_Object *obj, void *event_inf) -{ - struct _priv *priv; - Evas_Object *base; - Evas_Object *layout, *box; - Evas_Object *btn[BTN_TYPE]; - Evas_Coord x; - Evas_Coord y; - Evas_Coord w; - Evas_Coord h; - int i; - - if (!data) { - _ERR("Parameter error!"); - return; - } - - priv = (struct _priv *) data; - base = priv->base; - - _set_layout_dim(priv); - - layout = util_add_layout(base, UG_NETWORK_EDJ_FILE, - GRP_NETWORK_TYPE_SELECT); - if (!layout) { - _ERR("util_add_layout() failed.\n"); - return; - } - - box = util_add_box(layout, PART_SWALLOW_CONTENT); - if (!box) { - evas_object_del(layout); - return; - } - - evas_object_size_hint_weight_set(box, - EVAS_HINT_EXPAND, 0); - - for (i = 0; i < BTN_TYPE; i++) { - btn[i] = util_add_button(box, STYLE_POPUP_BTN, NULL, - _(popup_button[i])); - if (!btn[i]) { - evas_object_del(layout); - return; - } - - elm_box_pack_end(box, btn[i]); - - evas_object_smart_callback_add(btn[i], SIG_CLICKED, - _type_select_btn_cb, priv); - } - - if (priv->network_type == TYPE_WIRELESS) - elm_object_signal_emit(btn[TYPE_WIRELESS], - SIG_BTN_SELECTED, PROG); - else - elm_object_signal_emit(btn[TYPE_WIRED], - SIG_BTN_SELECTED, PROG); - - elm_object_part_content_set(layout, PART_SWALLOW_CONTENT, box); - - elm_object_focus_next_object_set(btn[1], btn[0], ELM_FOCUS_DOWN); - elm_object_focus_next_object_set(btn[0], btn[1], ELM_FOCUS_UP); - elm_object_focus_next_object_set(btn[1], btn[0], ELM_FOCUS_UP); - elm_object_focus_next_object_set(btn[0], btn[1], ELM_FOCUS_DOWN); - elm_object_focus_next_object_set(btn[0], btn[0], ELM_FOCUS_LEFT); - elm_object_focus_next_object_set(btn[0], btn[0], ELM_FOCUS_RIGHT); - elm_object_focus_next_object_set(btn[1], btn[1], ELM_FOCUS_LEFT); - elm_object_focus_next_object_set(btn[1], btn[1], ELM_FOCUS_RIGHT); - - x = 0; - y = 0; - w = 0; - h = 0; - evas_object_geometry_get(priv->type_btn, &x, &y, &w, &h); - evas_object_move(layout, (x + w - TYPE_POPUP_X_OFFSET) * ELM_SCALE, - (y + h) * ELM_SCALE); - - priv->network_ctxpopup = layout; - evas_object_event_callback_add(layout, EVAS_CALLBACK_KEY_DOWN, - _type_key_pressed_cb, priv); - - elm_object_focus_set(btn[0], EINA_TRUE); - evas_object_show(layout); -} - -/** -* Create the upper part for the base view -* -* @param[in] priv _priv object bypassed -* @return 0 on success,-1 otherwise -*/ -static int _create_upper_layout(struct _priv *priv) -{ - Evas_Object *type_btn; - Evas_Object *base; - - if (!priv || !priv->base) { - _ERR("Parameter error!"); - return RET_FAILED; - } - - base = priv->base; - - elm_object_part_text_set(base, PART_SELECT_TEXT, _(TXT_NETWORK_DISC)); - - type_btn = util_add_button(base, STYLE_TYPE_BTN, PART_NETWORK_TYPE, - _(TXT_TYPE_BTN)); - if (!type_btn) - return RET_FAILED; - - evas_object_smart_callback_add(type_btn, SIG_CLICKED, - _network_type_btn_clicked_cb, priv); - - elm_object_focus_next_object_set(type_btn, type_btn, ELM_FOCUS_UP); - elm_object_focus_next_object_set(type_btn, type_btn, ELM_FOCUS_LEFT); - - priv->type_btn = type_btn; - - elm_object_focus_set(type_btn, EINA_TRUE); - - _refresh_network_type_text(priv); - - return RET_SUCCESS; -} - -/** -* Callback function briefly called after wifi connected successfully -* -* @param[in] error_code the wifi activation error type -* @param[in] user_data the user data -*/ -static void _wifi_connected_cb(wifi_error_e error_code, void *user_data) -{ - struct _priv *priv; - - if (!user_data) { - _ERR("Parameter error!"); - return; - } - - priv = (struct _priv *) user_data; - - if (!priv->status_popup) - return; - - if (error_code != WIFI_ERROR_NONE) { - _ERR("connect AP failed."); - _show_confirm_popup(priv); - return; - } - - ug_destroy_me(priv->ug); -} - -/** -* Connect to the selected wifi access point -* -* @param[in] priv _priv object bypassed -* @param[in] index the index of the access point -* @return 0 on success, otherwise -1 -*/ -static int _wifi_connect_ap(struct _priv *priv, int index) -{ - struct wifi_ap_info *ap_info; - bool ret; - - if (!priv || index < 0) { - _ERR("Parameter error!"); - return RET_FAILED; - } - - _show_progress_popup(priv); - - ap_info = (struct wifi_ap_info *) eina_list_nth(priv->ap_list, index); - if (!ap_info) { - _ERR("ap info is NULL."); - return RET_FAILED; - } - - if (priv->ap_name) { - free(priv->ap_name); - priv->ap_name = NULL; - } - - priv->ap_name = strdup(ap_info->essid); - if (!priv->ap_name) { - _ERR("ap name gets failed."); - return RET_FAILED; - } - - if (ap_info->secure_type == WIFI_SECURITY_TYPE_NONE) { - if (priv->ap_pwd) { - free(priv->ap_pwd); - priv->ap_pwd = NULL; - } - } else { - priv->cur_view = NETWORK_WIFI_PASSCODE_VIEW; - viewmgr_push(priv->vmgr, - wifi_passcode_view_vclass_get(), - ap_info); - - return RET_SUCCESS; - } - - ret = priv->pWifiMgr->ForgetAP(); - if (ret != true) { - _ERR("forget last ap failed."); - return RET_FAILED; - } - - if (priv->ap_pwd) { - ret = priv->pWifiMgr->SetPassPhrase(priv->ap, priv->ap_pwd); - if (ret != true) { - _ERR("wifi_mgr_set_passphrase() failed."); - return RET_FAILED; - } - } - - ret = priv->pWifiMgr->Connect(priv->ap, _wifi_connected_cb, priv); - if (ret != true) { - _ERR("Fail to connection request.\n"); - return RET_FAILED; - } - - return RET_SUCCESS; -} - - -/** -* Callback function called by _connection_check_gateway_async_cb() -* -* Called after checking whether the profile can access to the internet asynchronously -* -* @param[in] result the connection error type -* @param[in] data the user data -*/ -static void _connection_get_is_online_async_cb( bool state, void *data) -{ - struct _priv *priv; - - if (!data) { - _ERR("the param is invalid."); - return; - } - - priv = (struct _priv *) data; - - if (state != true) { - _ERR("connection result"); - _show_confirm_popup(priv); - } else { - ug_destroy_me(priv->ug); - } -} - -/** -* Check whether the profile can access to the internet asynchronously -* -* @param[in] result the connection error type -* @param[in] data the user data -*/ -static void _connection_check_gateway_async_cb(bool state, void *data) -{ - struct _priv *priv; - bool ret; - - if (!data) { - _ERR("the param is invalid."); - return; - } - - priv = (struct _priv *) data; - - if (state != true) { - _ERR("connection disconnected"); - _show_confirm_popup(priv); - } else { - ret = priv->pNetConMgr->RegisterIpChangedCallback( _connection_get_is_online_async_cb, (void *)priv); - if (ret != true) { - _ERR("connection_mgr_get_is_online_async() failed."); - return; - } - } -} - -static void _get_ip_info(char *des, const char *key) -{ - const char *str; - - if (!des || !key) - return; - - str = vconf_get_str(key); - if (!str) - return; - - if (str == '\0' || !strncmp(str, NULL_STRING, IP_STRING_MAX_SIZE)) - strncpy(des, _(ZERO_IP), IP_STRING_MAX_SIZE); - else - strncpy(des, str, IP_STRING_MAX_SIZE); -} - -/** -* Write the connection information saved last time to the profile -* -* @param[in] priv _priv object bypassed -* @return 0 on success, otherwize -1 -*/ -static int _connection_set_last_network(struct _priv *priv) -{ - int ret; - enum setting_mode ip_mode; - struct network_info info; - - if (!priv) { - _ERR("the param is NULL."); - return RET_FAILED; - } - - const char *str = NULL; - str = vconf_get_str(WIRED_IP_LAST_MODE); - if (str && !strcmp(str, _(TXT_OBTAIN_AUTO))) - ip_mode = MODE_AUTO; - else - ip_mode = MODE_MAN; - - bool result = false; - if (ip_mode == MODE_AUTO) { - result = priv->pNetConMgr->SetIpConfType(CONNECTION_IP_CONFIG_TYPE_DYNAMIC); - if (result != true) { - _ERR("connection_mgr_ip_dynamic_config() failed."); - return RET_FAILED; - } - } else { - _get_ip_info(info.ip_addr, WIRED_IP_KEY); - _get_ip_info(info.submask, WIRED_SUBMASK_KEY); - _get_ip_info(info.gateway, WIRED_GATEWAY_KEY); - _get_ip_info(info.dns, WIRED_DNS_KEY); - } - - return RET_SUCCESS; -} - -/** -* Proccess the wired network connection -* -* @param[in] priv _priv object bypassed -* @return 0 on success, otherwise -1 -*/ -static int _wired_connect_proc(struct _priv *priv) -{ - int ret; - - if (!priv) { - _ERR("the param is NULL."); - return RET_FAILED; - } - - _show_progress_popup(priv); - - priv->pNetConMgr->RefreshEthernetProfile(); - if(!priv->pNetConMgr->GetProfileName(priv->profile_name)) { - _ERR("Fail to get profile name"); - return RET_FAILED; - } - - ret = _connection_set_last_network(priv); - if (ret != RET_SUCCESS) { - _ERR("_connection_set_last_network() failed."); - return ret; - } - - bool result = false; - result = priv->pNetConMgr->RegisterIpChangedCallback( _connection_check_gateway_async_cb, (void *)priv); - if (result != true) { - _ERR("connection_mgr_get_is_online_async() failed."); - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** -* Process the network connection -* -* @param[in] priv _priv object bypassed -*/ -static void _connect_network(struct _priv *priv) -{ - int index; - int ret; - - if (!priv) { - _ERR("the param is NULL."); - return; - } - - if (priv->network_type == TYPE_WIRELESS) { - if (priv->last_item) { - index = elm_genlist_item_index_get(priv->last_item); - - ret = _wifi_connect_ap(priv, index); - if (ret != RET_SUCCESS) { - _ERR("connect ap"); - _show_confirm_popup(priv); - return; - } - } - } else { - ret = _wired_connect_proc(priv); - if (ret != RET_SUCCESS) { - _ERR("connect ap"); - _show_confirm_popup(priv); - return; - } - } -} - -/** -* @Evas_Smart_Cb type callback for handling click event -* -* @param[in] data the user data -* @param[in] obj the corresponding object which the click event occurred -* @param[in] event event information -*/ -static void _retry_btn_clicked_cb(void *data, - Evas_Object *obj, void *event) -{ - struct _priv *priv; - - if (!data) { - _ERR("Parameter error!"); - return; - } - - priv = (struct _priv *) data; - - _del_status_popup(priv); - - _connect_network(priv); -} - -/** -* @Evas_Smart_Cb type callback for handling click event. -* -* @param[in] data the user data -* @param[in] obj the corresponding object which the click event occurred -* @param[in] event event information -*/ -static void _cancel_btn_clicked_cb(void *data, - Evas_Object *obj, void *event) -{ - struct _priv *priv; - - if (!data) { - _ERR("Parameter error!"); - return; - } - - priv = (struct _priv *) data; - - _del_status_popup(priv); - - elm_object_focus_set(priv->connect_btn, EINA_TRUE); -} - -/** -* @Evas_Smart_Cb type callback for handling unfocus event -* -* @param[in] data the user data -* @param[in] obj the corresponding object which the unfocus event occurred -* @param[in] source event information -*/ -static void _ctxpopup_unfocused_cb(void *data, - Evas_Object *obj, void *source) -{ - struct _priv *priv; - - if (!data || !obj) { - _ERR("data is NULL.\n"); - return; - } - - priv = (struct _priv *) data; - - _unset_layout_dim(priv); - - evas_object_del(obj); -} - -/** -* Called when confirm information popup is shown -* -* @param[in] priv _priv object bypassed -*/ -static void _show_confirm_popup(struct _priv *priv) -{ - Evas_Object *layout; - Evas_Object *retry_btn; - Evas_Object *cancel_btn; - Evas_Coord w; - Evas_Coord h; - char content[CONTENT_TXT_SIZE]; - - if (!priv) { - _ERR("the param is NULL."); - return; - } - - if (priv->status_popup) - _del_status_popup(priv); - - _set_layout_dim(priv); - - layout = util_add_layout(priv->base, UG_NETWORK_EDJ_FILE, - GRP_CONFIRM_LAYOUT); - if (!layout) { - _ERR("add layout failed."); - _unset_layout_dim(priv); - return; - } - - evas_object_show(layout); - - memset(content, 0, CONTENT_TXT_SIZE); - if (priv->network_type == TYPE_WIRED) { - elm_object_part_text_set(layout, - PART_TEXT_TITLE, _(TXT_WIRED_LY)); - snprintf(content, CONTENT_TXT_SIZE - 1, "%s %s", - _(TXT_FAILED_CONNECT), _(priv->profile_name)); - } else { - elm_object_part_text_set(layout, - PART_TEXT_TITLE, _(TXT_WIRELESS_LY)); - snprintf(content, CONTENT_TXT_SIZE - 1, "%s %s", - _(TXT_FAILED_CONNECT), priv->ap_name); - } - - elm_object_part_text_set(layout, - PART_TEXT_CONTENT, content); - - retry_btn = util_add_button(layout, STYLE_SETTING_BTN, - PART_RETRY_BTN, _(TXT_RETRY)); - if (!retry_btn) { - _ERR("util add button failed."); - evas_object_del(layout); - _unset_layout_dim(priv); - return; - } - - cancel_btn = util_add_button(layout, STYLE_SETTING_BTN, - PART_CANCEL_BTN, _(TXT_CANCEL)); - if (!cancel_btn) { - _ERR("util add button failed."); - evas_object_del(layout); - _unset_layout_dim(priv); - return; - } - - elm_object_focus_next_object_set(retry_btn, cancel_btn, - ELM_FOCUS_RIGHT); - elm_object_focus_next_object_set(cancel_btn, retry_btn, - ELM_FOCUS_LEFT); - elm_object_focus_next_object_set(cancel_btn, cancel_btn, - ELM_FOCUS_RIGHT); - elm_object_focus_next_object_set(retry_btn, retry_btn, - ELM_FOCUS_LEFT); - elm_object_focus_next_object_set(cancel_btn, cancel_btn, - ELM_FOCUS_UP); - elm_object_focus_next_object_set(retry_btn, retry_btn, - ELM_FOCUS_UP); - elm_object_focus_next_object_set(cancel_btn, cancel_btn, - ELM_FOCUS_DOWN); - elm_object_focus_next_object_set(retry_btn, retry_btn, - ELM_FOCUS_DOWN); - - evas_object_smart_callback_add(retry_btn, SIG_CLICKED, - _retry_btn_clicked_cb, priv); - evas_object_smart_callback_add(cancel_btn, SIG_CLICKED, - _cancel_btn_clicked_cb, priv); - - elm_object_focus_set(retry_btn, EINA_TRUE); - - elm_object_focus_allow_set(layout, EINA_TRUE); - evas_object_smart_callback_add(layout, SIG_UNFOCUSED, - _ctxpopup_unfocused_cb, priv); - evas_object_event_callback_add(layout, EVAS_CALLBACK_KEY_DOWN, - _ctxpopup_pressed_cb, priv); - - w = DEFAULT_WIN_WIDTH; - h = DEFAULT_WIN_HEIGHT; - - evas_object_move(layout, CENTER_ALIGN * (w - POPUP_WIDTH) * ELM_SCALE, - CENTER_ALIGN * (h - POPUP_HEIGHT) * ELM_SCALE); - - priv->status_popup = layout; -} - -/** -* Called when connect a wifi device and show connection progress -* -* @param[in] priv _priv object to be finalized -*/ -static void _show_progress_popup(struct _priv *priv) -{ - Evas_Object *layout; - Evas_Object *cancel_btn; - Evas_Coord w; - Evas_Coord h; - char content[CONTENT_TXT_SIZE]; - - if (!priv) { - _ERR("the param is NULL."); - return; - } - - if (priv->status_popup) - _del_status_popup(priv); - - _set_layout_dim(priv); - - layout = util_add_layout(priv->base, UG_NETWORK_EDJ_FILE, - GRP_PROCESSING_LAYOUT); - if (!layout) { - _ERR("add layout failed."); - _unset_layout_dim(priv); - return; - } - - evas_object_show(layout); - - priv->status_popup = layout; - - memset(content, 0, CONTENT_TXT_SIZE); - if (priv->network_type == TYPE_WIRED) { - elm_object_part_text_set(layout, - PART_TEXT_TITLE, _(TXT_WIRED_LY)); - snprintf(content, CONTENT_TXT_SIZE - 1, "%s %s", - _(TXT_CONNECTTING), _(priv->profile_name)); - } else { - elm_object_part_text_set(layout, - PART_TEXT_TITLE, _(TXT_WIRELESS_LY)); - snprintf(content, CONTENT_TXT_SIZE - 1, "%s %s", - _(TXT_CONNECTTING), priv->ap_name); - } - - elm_object_part_text_set(layout, PART_TEXT_CONTENT, content); - - cancel_btn = util_add_button(layout, STYLE_SETTING_BTN, - PART_CANCEL_BTN, _(TXT_CANCEL)); - if (!cancel_btn) { - _ERR("util add button failed."); - evas_object_del(layout); - _unset_layout_dim(priv); - return; - } - - evas_object_show(cancel_btn); - - elm_object_focus_next_object_set(cancel_btn, cancel_btn, - ELM_FOCUS_LEFT); - elm_object_focus_next_object_set(cancel_btn, cancel_btn, - ELM_FOCUS_RIGHT); - elm_object_focus_next_object_set(cancel_btn, cancel_btn, - ELM_FOCUS_UP); - elm_object_focus_next_object_set(cancel_btn, cancel_btn, - ELM_FOCUS_DOWN); - - evas_object_smart_callback_add(cancel_btn, SIG_CLICKED, - _cancel_btn_clicked_cb, priv); - - elm_object_focus_set(cancel_btn, EINA_TRUE); - - elm_object_focus_allow_set(layout, EINA_TRUE); - evas_object_smart_callback_add(layout, SIG_UNFOCUSED, - _ctxpopup_unfocused_cb, priv); - evas_object_event_callback_add(layout, EVAS_CALLBACK_KEY_DOWN, - _ctxpopup_pressed_cb, priv); - - w = DEFAULT_WIN_WIDTH; - h = DEFAULT_WIN_HEIGHT; - - evas_object_move(layout, CENTER_ALIGN * (w - POPUP_WIDTH) * ELM_SCALE, - CENTER_ALIGN * (h - POPUP_HEIGHT) * ELM_SCALE); -} - -/** -* @Evas_Smart_Cb type callback for handling click event -* -* @param[in] data the user data -* @param[in] obj the corresponding object which the click event occurred -* @param[in] event event information -*/ -static void _connect_btn_clicked_cb(void *data, - Evas_Object *obj, void *event) -{ - struct _priv *priv; - - if (!data) { - _ERR("Parameter error!"); - return; - } - - priv = (struct _priv *) data; - - _connect_network(priv); -} - -/** -* @Evas_Smart_Cb type callback for handling click event -* -* @param[in] data the user data -* @param[in] obj the corresponding object which the click event occurred -* @param[in] event event information -*/ -static void _refresh_btn_clicked_cb(void *data, - Evas_Object *obj, void *event) -{ - struct _priv *priv; - - if (!data) { - _ERR("Parameter error!"); - return; - } - - priv = (struct _priv *) data; - - _clear_genlist_item_list(priv); - - _display_wireless_setting(priv); -} - -/** -* @Evas_Smart_Cb type callback for handling click event -* -* @param[in] data the user data -* @param[in] obj the corresponding object which the click event occurred -* @param[in] event event information -*/ -static void _other_btn_clicked_cb(void *data, - Evas_Object *obj, void *event) -{ - struct _priv *priv; - Evas_Object *base; - struct connection_info info; - - if (!data) { - _ERR("Parameter error!"); - return; - } - - priv = (struct _priv *) data; - - priv->cur_view = NETWORK_IP_SETTING_VIEW; - - info.cur_type = priv->network_type; - - if (priv->network_type == TYPE_WIRED) { - strncpy(info.name, priv->profile_name, - MAX_NAME_SIZE - 1); - } else { - if (!priv->ap) { - _ERR("selected ap is NULL."); - return; - } - - info.ap = priv->ap; - - if (priv->ap_name) - strncpy(info.name, priv->ap_name, - MAX_NAME_SIZE - 1); - } - - base = viewmgr_push(priv->vmgr, - ip_setting_view_vclass_get(), &info); - if (!base) - _ERR("add connection layout failed."); -} - -/** -* @Evas_Smart_Cb type callback for handling click event -* -* @param[in] data the user data -* @param[in] obj the corresponding object which the click event occurred -* @param[in] event event information -*/ -static void _close_btn_clicked_cb(void *data, - Evas_Object *obj, void *event) -{ - struct _priv *priv; - - if (!data) { - _ERR("Parameter error!"); - return; - } - - priv = (struct _priv *) data; - - if (!priv->ug) - return; - - ug_destroy_me(priv->ug); -} - -/** -* Create the action buttons such as "Connect" button and set to defined part -* -* @param[in] priv _priv object bypassed -* @return 0 on success,otherwise -1 -*/ -static int _create_action_btns(struct _priv *priv) -{ - Evas_Object *bt[BTN_ACT]; - Evas_Object *base; - int i; - - if (!priv || !priv->base) { - _ERR("Parameter error!"); - return RET_FAILED; - } - - base = priv->base; - - for (i = 0; i < BTN_ACT; i++) { - bt[i] = util_add_button(base, STYLE_ACTION_BTN, - button_swallow[i], _(action_button[i])); - if (!bt[i]) - return RET_FAILED; - } - - priv->connect_btn = bt[CONNECT]; - priv->refresh_btn = bt[REFRESH]; - priv->other_btn = bt[OTHER]; - priv->close_btn = bt[CLOSE]; - - evas_object_hide(priv->refresh_btn); - - evas_object_smart_callback_add(bt[CONNECT], SIG_CLICKED, - _connect_btn_clicked_cb, priv); - evas_object_smart_callback_add(bt[REFRESH], SIG_CLICKED, - _refresh_btn_clicked_cb, priv); - evas_object_smart_callback_add(bt[OTHER], SIG_CLICKED, - _other_btn_clicked_cb, priv); - evas_object_smart_callback_add(bt[CLOSE], SIG_CLICKED, - _close_btn_clicked_cb, priv); - - _set_action_btn_pos(priv); - - return RET_SUCCESS; -} - -/** -* Create the dim layout but didn't show it -* -* @param[in] priv _priv object bypassed -* @return 0 on success,otherwise -1 -*/ -static int _create_dim_layout(struct _priv *priv) -{ - Evas_Object *dim_ly; - - if (!priv || !priv->win) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - dim_ly = util_add_layout(priv->win, UG_NETWORK_EDJ_FILE, GRP_DIM_LY); - if (!dim_ly) { - _ERR("elm_layout_add() failed.\n"); - return RET_FAILED; - } - - priv->dim_ly = dim_ly; - - _unset_layout_dim(priv); - - return RET_SUCCESS; -} - -/** -* Create the base layout and initialize the network -* -* Called at the start of the application for initializing before the main loop start up -* -* @param[in] vmgr view manager object -* @param[in] data the user data passed from the callback registration function -* @return the base layout of network setting -*/ -static Evas_Object *_create(struct viewmgr *vmgr, void *data) -{ - struct _priv *priv; - Evas_Object *base; - int ret; - - if (!vmgr || !vmgr->win || !vmgr->ug) { - _ERR("Parameter error!"); - return NULL; - } - - priv = _init_priv(); - if (!priv) { - _ERR("init priv failed."); - return NULL; - } - - priv->win = vmgr->win; - priv->ug = vmgr->ug; - priv->vmgr = vmgr; - - ret = _init_connection(priv); - if (ret != RET_SUCCESS) { - _ERR("create connection failed."); - _fini_priv(priv); - return NULL; - } - - base = _create_main_layout(priv); - if (!base) { - _ERR("Add main view failed.\n"); - _fini_priv(priv); - return NULL; - } - - priv->base = base; - - evas_object_data_set(base, KEY_PRIV, priv); - - const char *str = NULL; - str = vconf_get_str(SELECTED_NETWORK_TYPE_KEY); - if (str && !strcmp(str, TXT_WIRED)) - priv->network_type = TYPE_WIRED; - else - priv->network_type = TYPE_WIRELESS; - - ret = _create_upper_layout(priv); - if (ret != RET_SUCCESS) { - _ERR("create network type button failed."); - goto error; - } - - if (priv->network_type == TYPE_WIRELESS) - ret = _display_wireless_setting(priv); - else if (priv->network_type == TYPE_WIRED) - ret = _display_wired_setting(priv); - else - ret = RET_FAILED; - if (ret != RET_SUCCESS) - goto error; - - ret = _create_action_btns(priv); - if (ret != RET_SUCCESS) - goto error; - - ret = _create_dim_layout(priv); - if (ret != RET_SUCCESS) - goto error; - - return base; - -error: - evas_object_del(priv->base); - _fini_priv(priv); - - return NULL; -} - -/** -* Resume the network ug -* -* @param[in] base the base layout which was initilized in the _create() -*/ -static void _resume(Evas_Object *base) -{ - struct _priv *priv; - - if (!base) { - _ERR("Parameter error!"); - return; - } - - priv = (struct _priv *) evas_object_data_get(base, KEY_PRIV); - if (!priv) { - _ERR("priv got from base is NULL."); - return; - } - - evas_object_show(base); - - switch (priv->cur_view) { - case NETWORK_IP_SETTING_VIEW: - elm_object_focus_set(priv->other_btn, EINA_TRUE); - break; - case NETWORK_WIFI_PASSCODE_VIEW: - elm_object_focus_set(priv->connect_btn, EINA_TRUE); - break; - default: - break; - } -} - -/** -* Handle the message sended -* -* @param[in] base the base layout which was initilized in the _create() -* @param[in] message_id the id of the message sended -* @param[in] data the user data -*/ -static void _message_handler(Evas_Object *base, - enum message_id msg_id, void *data) -{ - struct _priv *priv; - - if (!base) { - _ERR("Parameter error!"); - return; - } - - priv = (struct _priv *) evas_object_data_get(base, KEY_PRIV); - if (!priv) { - _ERR("priv got from base is NULL."); - return; - } - - if (msg_id == PASSCODE_DEVIVER) { - if (priv->ap_pwd) - free(priv->ap_pwd); - priv->ap_pwd = strdup((char *)data); - } -} - -/** -* Pause the network ug -* -* @param[in] base the base layout which was initilized in the _create() -*/ -static void _pause(Evas_Object *base) -{ - if (!base) { - _ERR("Parameter error!"); - return; - } - - evas_object_hide(base); -} - -/** -* Destroy the network ug and release the resource -* -* @param[in] base the base layout which was initilized in the _create() -*/ -static void _destroy(Evas_Object *base) -{ - struct _priv *priv; - - if (!base) { - _ERR("Parameter error!"); - return; - } - - priv = (struct _priv *) evas_object_data_get(base, KEY_PRIV); - - _fini_priv(priv); -} - -/** -* Get the view type -* -* @return the view type -*/ -static enum view_type _get_view_type(void) -{ - return NETWORK_MAIN_VIEW; -} - -static struct view_class _vclass = { - .create = _create, - .pause = _pause, - .resume = _resume, - .terminate = _destroy, - .message_handler = _message_handler, - .get_view_type = _get_view_type, -}; - -/** -* Get the network view class -* -* @return the view class -*/ -struct view_class *main_view_vclass_get(void) -{ - return &_vclass; -} diff --git a/ug/network/src/ug_network_settings.cpp b/ug/network/src/ug_network_settings.cpp index 6d117d5..5fb6688 100644 --- a/ug/network/src/ug_network_settings.cpp +++ b/ug/network/src/ug_network_settings.cpp @@ -24,8 +24,11 @@ #include "i18n.h" #include "defs.h" #include "dbg.h" -#include "main_view.h" -#include "network_viewmgr.h" + +#include +#include "wifi.h" +#include "BaseView.h" +#include "NetworkMainView.h" #if defined (__cplusplus) extern "C" { @@ -35,7 +38,9 @@ struct _ug_data { Evas_Object *win; Evas_Object *base; ui_gadget_h ug; - struct viewmgr *vmgr; + CViewMgr *pViewMgr; + CNetworkMainView *pNetworkMainView; + //struct viewmgr *vmgr; }; /** @@ -61,9 +66,7 @@ static void *_on_create(ui_gadget_h ug, enum ug_mode mode, service_h service, void *priv) { struct _ug_data *ugd; - Evas_Object *base; Evas_Object *win; - struct viewmgr *vmgr; if (!ug || !priv) { _ERR("Parameter error!"); @@ -85,27 +88,25 @@ static void *_on_create(ui_gadget_h ug, enum ug_mode mode, elm_win_focus_highlight_enabled_set(win, EINA_TRUE); elm_win_focus_highlight_style_set(win, "invisible"); - vmgr = viewmgr_init(); - if (!vmgr) { - _ERR("init view mgr failed.\n"); + CViewMgr::Initialize(ugd->win, NULL); + ugd->pViewMgr = CViewMgr::GetInstance(); + if(!ugd->pViewMgr) { + CViewMgr::Finalize(); + _ERR("Fail to get CViewMgr instance"); return NULL; } - ugd->vmgr = vmgr; - - vmgr->ug = ug; - vmgr->win = win; - - base = viewmgr_push(vmgr, main_view_vclass_get(), NULL); - if (!base) { - _ERR("add base layout failed."); - viewmgr_fini(vmgr); - return NULL; + ugd->pNetworkMainView = new CNetworkMainView(NETWORK_MAINVIEW); + if(!ugd->pViewMgr->AddView(ugd->pNetworkMainView)) { + _ERR("Fail to add pFbBaseView"); + CViewMgr::Finalize(); + return false; } - ugd->base = base; - evas_object_raise(base); + ugd->pViewMgr->PushView(NETWORK_MAINVIEW, NULL); + ugd->base = ugd->pNetworkMainView->Base(); + evas_object_raise(ugd->base); - return base; + return ugd->base; } /** @@ -186,7 +187,8 @@ static void _on_destroy(ui_gadget_h ug, service_h service, void *priv) if (!ugd || !ugd->base) return; - viewmgr_fini(ugd->vmgr); + CViewMgr::Finalize(); + //viewmgr_fini(ugd->vmgr); } /** diff --git a/ug/src/NetConMgr.cpp b/ug/src/NetConMgr.cpp index 19641c1..9c6f95d 100644 --- a/ug/src/NetConMgr.cpp +++ b/ug/src/NetConMgr.cpp @@ -227,6 +227,7 @@ bool CNetConMgr::GetProfileName(char *out_name) strncpy(out_name, name, MAX_NAME_SIZE - 1); delete (name); + return true; } @@ -300,6 +301,7 @@ bool CNetConMgr::SetSubnetMask(char *submask) } if(!m_UpdateProfile()) return false; + return true; } @@ -318,6 +320,7 @@ bool CNetConMgr::SetGateway(char *gateway) } if(!m_UpdateProfile()) return false; + return true; } @@ -336,6 +339,7 @@ bool CNetConMgr::SetDNS(char *dns) } if(!m_UpdateProfile()) return false; + return true; } -- 2.7.4 From 27a7bfc700ba39649dbeed9257c433e1b4c214d1 Mon Sep 17 00:00:00 2001 From: JuWan Kim Date: Thu, 26 Mar 2015 17:01:49 +0900 Subject: [PATCH 11/16] Refactoring / Add IpSettingView.cpp / Fix Segfault bug. Change-Id: I33319b02134d4d6cdf068357a6d94a8e4d7ba9a6 Signed-off-by: JuWan Kim --- ug/network/CMakeLists.txt | 2 +- ug/network/include/IpSettingView.h | 71 + ug/network/include/WifiPasscodeView.h | 0 ug/network/include/ip_setting_view.h | 22 - ug/network/src/IpSettingView.cpp | 1697 ++++++++++++++++++++ ug/network/src/NetworkMainView.cpp | 16 +- ug/network/src/WifiPasscodeView.cpp | 0 ug/network/src/ip_setting_view.cpp | 2720 --------------------------------- 8 files changed, 1779 insertions(+), 2749 deletions(-) create mode 100644 ug/network/include/IpSettingView.h create mode 100644 ug/network/include/WifiPasscodeView.h delete mode 100644 ug/network/include/ip_setting_view.h create mode 100644 ug/network/src/IpSettingView.cpp create mode 100644 ug/network/src/WifiPasscodeView.cpp delete mode 100644 ug/network/src/ip_setting_view.cpp diff --git a/ug/network/CMakeLists.txt b/ug/network/CMakeLists.txt index cad0340..478d1fd 100644 --- a/ug/network/CMakeLists.txt +++ b/ug/network/CMakeLists.txt @@ -48,8 +48,8 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") SET(SRCS src/ug_network_settings.cpp src/NetworkMainView.cpp + src/IpSettingView.cpp src/network_viewmgr.cpp - src/ip_setting_view.cpp src/wifi_passcode_view.cpp src/util.cpp ../src/WifiMgr.cpp diff --git a/ug/network/include/IpSettingView.h b/ug/network/include/IpSettingView.h new file mode 100644 index 0000000..4e5828c --- /dev/null +++ b/ug/network/include/IpSettingView.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __IP_SETTING_VIEW_H__ +#define __IP_SETTING_VIEW_H__ + +class CIpSettingView : public CBaseView, public IMouseClickedListener, public IUnfocusedListener { +private : + struct SIpSettingView *m; + + bool m_InitConnectionMgr(); + void m_FinalizeConnectionMgr(); + Evas_Object* m_CreateMainLayout(); + + bool m_GetCurConnectionMode(void); + bool m_GetCurIpInfo(void); + + void m_GetIpInfo(char *des, const char *key); + bool m_CreateDNSSetting(void); + bool m_CreateBtns(void); + bool m_CreateIpSetting(void); + bool m_CreateDimLayout(void); + Evas_Object* m_CreateSettingBtn(char *key, char *txt, Evas_Smart_Cb cb, void *data); + void m_SetupDownCycleFocus(Evas_Object **obj, int count); + void m_KeepBtnFocused(void); + void m_CreateValuePopup(void); + Evas_Object* m_CreateValueBtn(Evas_Object *base, int num, char *txt, void *data); + void m_SetLeftRightCycleFocus(Evas_Object **obj, int count); + bool m_GetValuePopupPos(Evas_Coord *pos_x, Evas_Coord *pos_y); + void m_ConfigNetwork(void); + void m_ShowConfirmPopup(void); + bool m_ConfigNetworkDynamic(void); + bool m_ConfigNetworkManually(void); + bool m_CheckIpValid(void); + void m_ShowInvalidIpPopup(void); + void m_SaveMode(void); + void m_SetTheValue(void); + +protected : + virtual void t_OnShow(void); + virtual void t_OnUpdate(void *data); + virtual void t_OnHide(void); + +public : + CIpSettingView(const char *szViewId) : CBaseView(szViewId), IMouseClickedListener(this), IUnfocusedListener(this), m(0) {} + virtual ~CIpSettingView() {} + + virtual bool Create(void *data); + virtual void Destroy(void); + virtual Evas_Object* Base(void); + + virtual void OnKeyDown(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev); + virtual void OnMouseClicked(int id, Evas_Object *obj); + virtual void OnUnfocused(int id, Evas_Object *obj, Elm_Object_Item *item); +}; + +#endif /* __IP_SETTING_VIEW_H__ */ + diff --git a/ug/network/include/WifiPasscodeView.h b/ug/network/include/WifiPasscodeView.h new file mode 100644 index 0000000..e69de29 diff --git a/ug/network/include/ip_setting_view.h b/ug/network/include/ip_setting_view.h deleted file mode 100644 index 214c2f9..0000000 --- a/ug/network/include/ip_setting_view.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __CONNECTION_VIEW_H__ -#define __CONNECTION_VIEW_H__ - -struct view_class *ip_setting_view_vclass_get(void); - -#endif /* __CONNECTION_VIEW_H__ */ diff --git a/ug/network/src/IpSettingView.cpp b/ug/network/src/IpSettingView.cpp new file mode 100644 index 0000000..4ff7476 --- /dev/null +++ b/ug/network/src/IpSettingView.cpp @@ -0,0 +1,1697 @@ +#include +#include +#include "defs.h" +#include "dbg.h" +#include +#include "i18n.h" +#include "util.h" +#include "common.h" + +#include +#include + +#include "WifiMgr.h" +#include "NetConMgr.h" +#include "BaseView.h" +#include "ViewMgr.h" + +#include "IpSettingView.h" + +#define MODE_BTN_NUM 2 +#define MAX_IP_NUM 255 +#define IP_SET_MAX_NUM 4 +#define STRING_MAX_SIZE 50 +#define SETTING_MODE_OFFSET_X 448 +#define SETTING_MODE_OFFSET_Y 0 +#define SETTING_VALUE_OFFSET_X 162 +#define SETTING_VALUE_OFFSET_Y 20 +#define CENTER_ALIGN 0.5 +#define BOX_PAD_X 0 +#define BOX_PAD_Y 2 +#define RATIO 10 + +#define IP_VALUE1 "value1" +#define IP_VALUE2 "value2" +#define IP_VALUE3 "value3" +#define IP_VALUE4 "value4" + +#define TXT_MAKE_OTHER_NETWORK _("You can make other network"\ + "
Enter the IP address to use.") + +enum connection_setting_enum { + SETTING_INVALID, + SETTING_IP, + SETTING_IP_ADDRESS, + SETTING_SUBNET_MASK, + SETTING_GATEWAY, + SETTING_DNS, + SETTING_DNS_SERVER +}; + +struct SIpSettingView { + ui_gadget_h ug; + + Evas_Object *win; + Evas_Object *base; + Evas_Object *dim_ly; + Evas_Object *ip_mode_btn; + Evas_Object *ip_addr_btn; + Evas_Object *subnet_mask_btn; + Evas_Object *gateway_btn; + Evas_Object *dns_mode_btn; + Evas_Object *dns_server_btn; + Evas_Object *ip_mode_ly; + Evas_Object *dns_mode_ly; + Evas_Object *config_popup; + Evas_Object *cur_ip_btn[IP_SET_MAX_NUM]; + Evas_Object *confirm_popup; + Evas_Object *ok_btn; + Evas_Object *cancel_btn; + + struct network_info info; + enum setting_mode ip_mode; + enum setting_mode dns_mode; + + enum connection_setting_enum cur_type; + enum network_type_enum network_type; + + wifi_ap_h ap; + + char profile_name[MAX_NAME_SIZE]; + + CWifiMgr *pWifiMgr; + CNetConMgr *pNetConMgr; + CViewMgr *pViewMgr; +}; + + +bool CIpSettingView::m_InitConnectionMgr() +{ + _DBG(); + if(!CNetConMgr::Initialize()) { + _ERR("Fail to init CNetConMgr"); + } + + m->pNetConMgr = CNetConMgr::GetInstance(); + if (!m->pNetConMgr) { + _ERR("Fail to get instance"); + return false; + } + + if(!m->pNetConMgr->GetProfileName(m->profile_name)) { + _ERR("Fail to get profilename"); + return false; + } + + return true; +} + +void CIpSettingView::m_FinalizeConnectionMgr() +{ + _DBG(); + CNetConMgr::Finalize(); + m->pNetConMgr = NULL; +} + + +bool CIpSettingView::m_GetCurConnectionMode(void) +{ + const char *str = NULL; + if (m->network_type == TYPE_WIRED) { + str = vconf_get_str(WIRED_IP_LAST_MODE); + if (str && !strcmp(str, _(TXT_OBTAIN_AUTO))) + m->ip_mode = MODE_AUTO; + else + m->ip_mode = MODE_MAN; + + str = NULL; + str = vconf_get_str(WIRED_DNS_LAST_MODE); + if (str && !strcmp(str, _(TXT_OBTAIN_AUTO))) + m->dns_mode = MODE_AUTO; + else + m->dns_mode = MODE_MAN; + } else if (m->network_type == TYPE_WIRELESS) { + str = vconf_get_str(WIRELESS_IP_LAST_MODE); + if (str && !strcmp(str, _(TXT_OBTAIN_AUTO))) + m->ip_mode = MODE_AUTO; + else + m->ip_mode = MODE_MAN; + + str = NULL; + str = vconf_get_str(WIRELESS_DNS_LAST_MODE); + if (str && !strcmp(str, _(TXT_OBTAIN_AUTO))) + m->dns_mode = MODE_AUTO; + else + m->dns_mode = MODE_MAN; + } else { + _ERR("the network type is invalid."); + return false; + } + + return true; +} + + +bool CIpSettingView::m_GetCurIpInfo(void) +{ + struct network_info info; + bool result = false; + + if (m->network_type == TYPE_WIRED) { + if (m->ip_mode == MODE_AUTO) { + if (!m->pNetConMgr->GetIpAddr(info.ip_addr)) { + _ERR("connection_mgr_get_ip_info() failed."); + return false; + } + if (!m->pNetConMgr->GetSubnetMask(info.submask)) { + _ERR("connection_mgr_get_ip_info() failed."); + return false; + } + if (!m->pNetConMgr->GetGateway(info.gateway)) { + _ERR("connection_mgr_get_ip_info() failed."); + return false; + } + if (!m->pNetConMgr->GetDNS(info.dns)) { + _ERR("connection_mgr_get_ip_info() failed."); + return false; + } + } else if (m->ip_mode == MODE_MAN) { + m_GetIpInfo(info.ip_addr, WIRED_IP_KEY); + m_GetIpInfo(info.submask, WIRED_SUBMASK_KEY); + m_GetIpInfo(info.gateway, WIRED_GATEWAY_KEY); + m_GetIpInfo(info.dns, WIRED_DNS_KEY); + } else { + _ERR("ip mode is invalid."); + return false; + } + } else if (m->network_type == TYPE_WIRELESS) { + if (m->ip_mode == MODE_AUTO) { + result = m->pWifiMgr->GetIp(m->ap, m->info.ip_addr); + if(result != true) { + _ERR("wifi_mgr_get_ip_info() failed."); + return false; + } + result = m->pWifiMgr->GetSubnetMask(m->ap, m->info.submask); + if(result != true) { + _ERR("wifi_mgr_get_ip_info() failed."); + return false; + } + result = m->pWifiMgr->GetGateway(m->ap, m->info.gateway); + if(result != true) { + _ERR("wifi_mgr_get_ip_info() failed."); + return false; + } + result = m->pWifiMgr->GetDNS(m->ap, m->info.dns); + if(result != true) { + _ERR("wifi_mgr_get_ip_info() failed."); + return false; + } + } else if (m->ip_mode == MODE_MAN) { + m_GetIpInfo(info.ip_addr, WIRELESS_IP_KEY); + m_GetIpInfo(info.submask, WIRELESS_SUBMASK_KEY); + m_GetIpInfo(info.gateway, WIRELESS_GATEWAY_KEY); + m_GetIpInfo(info.dns, WIRELESS_DNS_KEY); + } else { + _ERR("ip mode is invalid."); + return false; + } + } else { + _ERR("network type is invalid."); + return false; + } + + strncpy(m->info.ip_addr, info.ip_addr, IP_STRING_MAX_SIZE); + strncpy(m->info.submask, info.submask, IP_STRING_MAX_SIZE); + strncpy(m->info.gateway, info.gateway, IP_STRING_MAX_SIZE); + strncpy(m->info.dns, info.dns, IP_STRING_MAX_SIZE); + + return true; +} + + +void CIpSettingView::m_GetIpInfo(char *des, const char *key) +{ + _DBG(); + const char *str; + + if (!des || !key) + return; + + str = vconf_get_str(key); + if (!str) + return; + + if (str == '\0' || !strncmp(str, NULL_STRING, IP_STRING_MAX_SIZE)) + strncpy(des, _(ZERO_IP), IP_STRING_MAX_SIZE); + else + strncpy(des, str, IP_STRING_MAX_SIZE); +} + + +bool CIpSettingView::m_CreateDNSSetting(void) +{ + Evas_Object *base; + Evas_Object *btn; + Evas_Object *box; + char mode[STRING_MAX_SIZE]; + + box = util_add_box(base, PART_CONNECTION_DNS_SETTING); + if (!box) { + _ERR("add box failed."); + return false; + } + + elm_box_horizontal_set(box, EINA_FALSE); + elm_box_padding_set(box, BOX_PAD_X, BOX_PAD_Y); + + memset(mode, 0, STRING_MAX_SIZE); + if (m->dns_mode == MODE_AUTO) + snprintf(mode, STRING_MAX_SIZE - 1, "%s", _(TXT_OBTAIN_AUTO)); + else + snprintf(mode, STRING_MAX_SIZE - 1, "%s", _(TXT_ENTER_MAN)); + + btn = util_add_key_value_button(base, NULL, _(TXT_DNS_SETING), mode); + if (!btn) { + _ERR("Add button failed."); + evas_object_del(box); + return false; + } + + //evas_object_smart_callback_add(btn, SIG_CLICKED, _dns_setting_btn_clicked_cb, priv); + Connect(btn, 1); + + elm_box_pack_end(box, btn); + elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_LEFT); + + m->dns_mode_btn = btn; + + btn = util_add_key_value_button(base, NULL, _(TXT_DNS_SERVER), m->info.dns); + if (!btn) { + _ERR("Add btn failed."); + evas_object_del(box); + return false; + } + + elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_LEFT); + + //evas_object_smart_callback_add(btn, SIG_CLICKED, _dns_server_btn_clicked_cb, priv); + Connect(btn, 2); + + elm_object_signal_emit(btn, SIG_HIDE_BOTTOME_LINE, PROG); + elm_box_pack_end(box, btn); + + m->dns_server_btn = btn; + + if (m->dns_mode == MODE_AUTO) + elm_object_disabled_set(m->dns_server_btn, EINA_TRUE); + + return true; +} + + +bool CIpSettingView::m_CreateBtns(void) +{ + Evas_Object *base; + Evas_Object *ok_btn; + Evas_Object *cancel_btn; + + ok_btn = util_add_button(base, STYLE_SETTING_BTN, NULL, _(TXT_OK)); + if (!ok_btn) { + _ERR("Add button failed."); + return false; + } + + elm_object_part_content_set(base, PART_CONNECTION_OK_BTN, ok_btn); + m->ok_btn = ok_btn; + + //evas_object_smart_callback_add(ok_btn, SIG_CLICKED, _ok_btn_clicked_cb, priv); + Connect(ok_btn, 3); + + cancel_btn = util_add_button(base, STYLE_SETTING_BTN, PART_CONNECTION_CANCEL_BTN, _(TXT_CANCEL)); + if (!cancel_btn) { + _ERR("Add button failed."); + evas_object_del(ok_btn); + return false; + } + + //evas_object_smart_callback_add(cancel_btn, SIG_CLICKED, _cancel_btn_clicked_cb, priv); + Connect(cancel_btn, 4); + + m->cancel_btn = cancel_btn; + + return true; +} + + +bool CIpSettingView::m_CreateIpSetting(void) +{ + Evas_Object *base; + Evas_Object *scroll; + Evas_Object *box; + Evas_Object *btn; + char mode[STRING_MAX_SIZE]; + + scroll = util_add_scroll(base, PART_CONNECTION_IP_SETTING); + if (!scroll) { + _ERR("add scroll failed."); + return false; + } + + box = util_add_box(scroll, NULL); + if (!box) { + _ERR("add box failed."); + evas_object_del(scroll); + return false; + } + + elm_box_horizontal_set(box, EINA_FALSE); + elm_box_padding_set(box, BOX_PAD_X, BOX_PAD_Y); + + memset(mode, 0, STRING_MAX_SIZE); + if (m->ip_mode == MODE_AUTO) + snprintf(mode, STRING_MAX_SIZE - 1, "%s", _(TXT_OBTAIN_AUTO)); + else + snprintf(mode, STRING_MAX_SIZE - 1, "%s", _(TXT_ENTER_MAN)); + + btn = util_add_key_value_button(base, NULL, _(TXT_IP_SETTING), mode); + if (!btn) { + _ERR("Add button failed."); + evas_object_del(scroll); + return false; + } + //evas_object_smart_callback_add(btn, SIG_CLICKED, cb, data); + Connect(btn, 5); + elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_LEFT); + + elm_box_pack_end(box, btn); + elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_UP); + elm_object_focus_set(btn, EINA_TRUE); + m->ip_mode_btn = btn; + + btn = util_add_key_value_button(base, NULL, _(TXT_IP_ADDR), m->info.ip_addr); + if (!btn) { + _ERR("Add btn failed."); + evas_object_del(scroll); + return false; + } + //evas_object_smart_callback_add(btn, SIG_CLICKED, _ip_address_btn_clicked_cb, data); + Connect(btn, 6); + elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_LEFT); + + elm_box_pack_end(box, btn); + m->ip_addr_btn = btn; + + btn = util_add_key_value_button(base, NULL, _(TXT_SUBNET_MASK), m->info.submask); + if (!btn) { + _ERR("Add btn failed."); + evas_object_del(scroll); + return false; + } + //evas_object_smart_callback_add(btn, SIG_CLICKED, _sub_mask_btn_clicked_cb, data); + Connect(btn, 7); + elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_LEFT); + + elm_box_pack_end(box, btn); + m->subnet_mask_btn = btn; + + btn = util_add_key_value_button(base, NULL, _(TXT_GATEWAY), m->info.gateway); + if (!btn) { + _ERR("Add btn failed."); + evas_object_del(scroll); + return false; + } + //evas_object_smart_callback_add(btn, SIG_CLICKED, _gateway_btn_clicked_cb, data); + Connect(btn, 8); + elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_LEFT); + + elm_object_signal_emit(btn, SIG_HIDE_BOTTOME_LINE, PROG); + + elm_box_pack_end(box, btn); + m->gateway_btn = btn; + + elm_object_content_set(scroll, box); + + if (m->ip_mode == MODE_AUTO){ + elm_object_disabled_set(m->ip_addr_btn, EINA_TRUE); + elm_object_disabled_set(m->subnet_mask_btn, EINA_TRUE); + elm_object_disabled_set(m->gateway_btn, EINA_TRUE); + } + + return true; +} + + +bool CIpSettingView::m_CreateDimLayout(void) +{ + Evas_Object *dim_ly; + + dim_ly = util_add_layout(m->win, UG_NETWORK_EDJ_FILE, + GRP_DIM_LY); + if (!dim_ly) { + _ERR("elm_layout_add() failed."); + return false; + } + + m->dim_ly = dim_ly; + evas_object_hide(m->dim_ly); + + return true; +} + +Evas_Object* CIpSettingView::m_CreateMainLayout() +{ + _DBG(); + Evas_Object *base; + + base = elm_layout_add(m->win); + if (!base) { + _ERR("elm_layout_add() failed."); + return NULL; + } + + elm_layout_file_set(base, UG_NETWORK_EDJ_FILE, GRP_CONNECTION_SETTING); + + evas_object_show(base); + + return base; +} + + +void CIpSettingView::t_OnShow() +{ + _DBG(); + + evas_object_show(m->base); + + CBaseView::t_OnShow(); +} + + +void CIpSettingView::t_OnUpdate(void *data) +{ + _DBG(); + + evas_object_show(m->base); + +#if 0 + switch (m->cur_view) { + case NETWORK_IP_SETTING_VIEW: + elm_object_focus_set(m->other_btn, EINA_TRUE); + break; + case NETWORK_WIFI_PASSCODE_VIEW: + elm_object_focus_set(m->connect_btn, EINA_TRUE); + break; + default: + break; + } +#endif +} + + +void CIpSettingView::t_OnHide() +{ + _DBG(); + + evas_object_hide(m->base); + + CBaseView::t_OnHide(); +} + + +bool CIpSettingView::Create(void *data) +{ + _DBG(); + ASSERT(!m); + + struct connection_info *info; + + _CREATE_BEGIN{ + _CHECK(m = new SIpSettingView) + _CHECK(m->win = CViewMgr::GetInstance()->Window()) + _CHECK(m_InitConnectionMgr()) + _COMMAND{ + if(data) { + info = (struct connection_info *) data; + m->network_type = info->cur_type; + m->ap = m->ap; + strncpy(m->profile_name, info->name, MAX_NAME_SIZE - 1); + } + } + _CHECK(m->base = m_CreateMainLayout()) + _COMMAND{ + //evas_object_event_callback_add(base, EVAS_CALLBACK_KEY_DOWN, _base_key_pressed_cb, priv); + Connect(m->base, 0); + elm_object_part_text_set(m->base, PART_CONNECTION_DESCRITION, TXT_MAKE_OTHER_NETWORK); + } + _CHECK(m_GetCurConnectionMode()) + _CHECK(m_GetCurIpInfo()) + _CHECK(m_CreateDNSSetting()) + _CHECK(m_CreateBtns()) + _CHECK(m_CreateIpSetting()) + _CHECK(m_CreateDimLayout()) + _WHEN_SUCCESS{ + m->pViewMgr = CViewMgr::GetInstance(); + } + _CHECK_FAIL{ /* m_CreateDimLayout() */ } + _CHECK_FAIL{ /* m_CreateIpSetting() */ } + _CHECK_FAIL{ /* m_CreateBtns() */ } + _CHECK_FAIL{ /* m_CreateDNSSetting() */ } + _CHECK_FAIL{ /* m_GetCurIpInfo() */ } + _CHECK_FAIL{ /* m_GetCurConnectionMode() */ } + _CHECK_FAIL{ evas_object_del(m->base); } + _CHECK_FAIL{ m_FinalizeConnectionMgr(); } + _CHECK_FAIL{ /* m->win = CViewMgr::GetInstance()->Window() */ } + _CHECK_FAIL{ delete m; m = NULL; } + } _CREATE_END_AND_CATCH{ return false; } + + _DBG("Done"); + return true; +} + + +void CIpSettingView::Destroy() +{ + ASSERT(m); + _DBG(); + + if (m->dim_ly) + evas_object_del(m->dim_ly); + + CBaseView::Destroy(); + delete m; + m = NULL; +} + +Evas_Object* CIpSettingView::Base() +{ + ASSERT(m); + _DBG(); + + return m->base; +} + + +void CIpSettingView::m_SetupDownCycleFocus(Evas_Object **obj, int count) +{ + int i; + + if (!*obj || !obj) + return; + + for (i = 0; i < count; i++) { + if (i == count - 1) + elm_object_focus_next_object_set(obj[i], obj[0], ELM_FOCUS_DOWN); + else + elm_object_focus_next_object_set(obj[i], obj[i + 1], ELM_FOCUS_DOWN); + + if (i == 0) + elm_object_focus_next_object_set(obj[i], obj[count - 1], ELM_FOCUS_UP); + else + elm_object_focus_next_object_set(obj[i], obj[i - 1], ELM_FOCUS_UP); + } +} + + +void CIpSettingView::m_KeepBtnFocused(void) +{ + Evas_Object *obj; + + switch (m->cur_type) { + case SETTING_IP: + obj = m->ip_mode_btn; + break; + case SETTING_IP_ADDRESS: + obj = m->ip_addr_btn; + break; + case SETTING_SUBNET_MASK: + obj = m->subnet_mask_btn; + break; + case SETTING_GATEWAY: + obj = m->gateway_btn; + break; + case SETTING_DNS: + obj = m->dns_mode_btn; + break; + case SETTING_DNS_SERVER: + obj = m->dns_server_btn; + break; + default: + return; + } + + elm_object_signal_emit(obj, SIG_BTN_SELECTED, PROG); +} + + +void CIpSettingView::m_CreateValuePopup(void) +{ + Evas_Object *base, *ctxpopup, *btn; + Evas_Coord pos_x, pos_y; + int i; + + ctxpopup = util_add_layout(base, UG_NETWORK_EDJ_FILE, + GRP_NETWORK_VALUE_SETTING); + if (!ctxpopup) { + _ERR("elm_ctxpopup_add() failed."); + return; + } + + elm_object_focus_allow_set(ctxpopup, EINA_TRUE); + //evas_object_smart_callback_add(ctxpopup, SIG_UNFOCUSED, _ctxpopup_unfocused_cb, priv); + Connect(ctxpopup, 15); + + m->config_popup = ctxpopup; + + evas_object_show(m->dim_ly); + + for (i = 0; i < IP_SET_MAX_NUM; i++) { + btn = m_CreateValueBtn(ctxpopup, i, _(TXT_ZERO), NULL); + if (!btn) { + _ERR("_create_value_btn() failed."); + evas_object_del(ctxpopup); + m->config_popup = NULL; + return; + } + + m->cur_ip_btn[i] = btn; + } + //evas_object_smart_callback_add(btn, SIG_CLICKED, _popup_dismissed_cb, data); + //evas_object_event_callback_add(btn, EVAS_CALLBACK_KEY_DOWN, _ip_btn_key_pressed_cb, data); + Connect(m->cur_ip_btn[0], 16); + Connect(m->cur_ip_btn[1], 17); + Connect(m->cur_ip_btn[2], 18); + Connect(m->cur_ip_btn[3], 19); + + //evas_object_event_callback_add(ctxpopup, EVAS_CALLBACK_KEY_DOWN, _value_ctxpopup_key_pressed_cb, priv); + m_SetLeftRightCycleFocus(m->cur_ip_btn, IP_SET_MAX_NUM); + + m_KeepBtnFocused(); + + pos_x = 0; + pos_y = 0; + m_GetValuePopupPos(&pos_x, &pos_y); + evas_object_move(ctxpopup, pos_x * ELM_SCALE, pos_y * ELM_SCALE); + +} + + +Evas_Object* CIpSettingView::m_CreateValueBtn(Evas_Object *base, int num, char *txt, void *data) +{ + Evas_Object *btn; + + if (!base || !txt || !data) { + _ERR("The param is invalid."); + return NULL; + } + + btn = util_add_button(base, STYLE_VALUE_BTN, NULL, txt); + if (!btn) { + _ERR("add button failed."); + return NULL; + } + + switch (num) { + case 0: + elm_object_part_content_set(base, PART_IP_FIRST, btn); + evas_object_data_set(base, IP_VALUE1, btn); + elm_object_focus_set(btn, EINA_TRUE); + break; + case 1: + elm_object_part_content_set(base, PART_IP_SECOND, btn); + evas_object_data_set(base, IP_VALUE2, btn); + break; + case 2: + elm_object_part_content_set(base, PART_IP_THIRD, btn); + evas_object_data_set(base, IP_VALUE3, btn); + break; + case 3: + elm_object_part_content_set(base, PART_IP_FORTH, btn); + evas_object_data_set(base, IP_VALUE4, btn); + break; + default: + break; + } + + elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_UP); + elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_DOWN); + + return btn; +} + + +void CIpSettingView::m_SetLeftRightCycleFocus(Evas_Object **obj, int count) +{ + int i; + + if (!obj || !*obj) { + _ERR("the param is invalid."); + return; + } + + for (i = 0; i < count; i++) { + if (i == count - 1) + elm_object_focus_next_object_set(obj[i], obj[0], ELM_FOCUS_RIGHT); + else + elm_object_focus_next_object_set(obj[i], obj[i + 1], ELM_FOCUS_RIGHT); + + if (i == 0) + elm_object_focus_next_object_set(obj[i], obj[count - 1], ELM_FOCUS_LEFT); + else + elm_object_focus_next_object_set(obj[i], obj[i - 1], ELM_FOCUS_LEFT); + } +} + + +bool CIpSettingView::m_GetValuePopupPos(Evas_Coord *pos_x, Evas_Coord *pos_y) +{ + Evas_Coord x; + Evas_Coord y; + Evas_Coord w; + Evas_Coord h; + + if (!pos_x || !pos_y) { + _ERR("the param is invalid."); + return false; + } + + switch (m->cur_type) { + case SETTING_IP_ADDRESS: + evas_object_geometry_get(m->ip_addr_btn, &x, &y, &w, &h); + *pos_x = x + SETTING_VALUE_OFFSET_X; + *pos_y = y - SETTING_VALUE_OFFSET_Y; + break; + case SETTING_SUBNET_MASK: + evas_object_geometry_get(m->subnet_mask_btn, &x, &y, &w, &h); + *pos_x = x + SETTING_VALUE_OFFSET_X; + *pos_y = y - SETTING_VALUE_OFFSET_Y; + break; + case SETTING_GATEWAY: + evas_object_geometry_get(m->gateway_btn, &x, &y, &w, &h); + *pos_x = x + SETTING_VALUE_OFFSET_X; + *pos_y = y - SETTING_VALUE_OFFSET_Y; + break; + case SETTING_DNS_SERVER: + evas_object_geometry_get(m->dns_server_btn, &x, &y, &w, &h); + *pos_x = x + SETTING_VALUE_OFFSET_X; + *pos_y = y - 2 * SETTING_VALUE_OFFSET_Y; + break; + default: + return false; + } + + return true; +} + + +void CIpSettingView::m_ConfigNetwork(void) +{ + bool ret; + + switch (m->ip_mode) { + case MODE_AUTO: + ret = m_ConfigNetworkDynamic(); + if (ret != true) { + _ERR("config network automatically failed."); + m_ShowConfirmPopup(); + return; + } + + break; + case MODE_MAN: + ret = m_ConfigNetworkManually(); + if (ret == false) { + _ERR("invalid IP."); + return; + } else if (ret != true) { + _ERR("config network manually failed."); + m_ShowConfirmPopup(); + return; + } + + break; + default: + m_ShowConfirmPopup(); + return; + } + + m_SaveMode(); + +#if 0 + viewmgr_pop(m->vmgr); +#endif +} + + +void CIpSettingView::m_ShowConfirmPopup(void) +{ + Evas_Object *layout; + Evas_Object *retry_btn, *cancel_btn; + Evas_Coord w; + Evas_Coord h; + char content[CONTENT_TXT_SIZE]; + + evas_object_show(m->dim_ly); + + layout = util_add_layout(m->base, UG_NETWORK_EDJ_FILE, + GRP_CONFIRM_LAYOUT); + if (!layout) { + _ERR("add layout failed."); + evas_object_hide(m->dim_ly); + return; + } + + m->confirm_popup = layout; + + if (m->network_type == TYPE_WIRED) + elm_object_part_text_set(layout, PART_TEXT_TITLE, _(TXT_WIRED_LY)); + else + elm_object_part_text_set(layout, PART_TEXT_TITLE, _(TXT_WIRELESS_LY)); + + memset(content, 0, CONTENT_TXT_SIZE); + snprintf(content, CONTENT_TXT_SIZE - 1, "%s %s", _(TXT_FAILED_CONNECT), m->profile_name); + elm_object_part_text_set(layout, PART_TEXT_CONTENT, content); + + retry_btn = util_add_button(layout, STYLE_SETTING_BTN, PART_RETRY_BTN, _(TXT_RETRY)); + if (!retry_btn) { + _ERR("util add button failed."); + evas_object_del(layout); + evas_object_hide(m->dim_ly); + return; + } + + cancel_btn = util_add_button(layout, STYLE_SETTING_BTN, PART_CANCEL_BTN, _(TXT_CANCEL)); + if (!cancel_btn) { + _ERR("util add button failed."); + evas_object_del(layout); + evas_object_hide(m->dim_ly); + return; + } + + elm_object_focus_next_object_set(retry_btn, cancel_btn, ELM_FOCUS_RIGHT); + elm_object_focus_next_object_set(cancel_btn, retry_btn, ELM_FOCUS_LEFT); + elm_object_focus_next_object_set(cancel_btn, cancel_btn, ELM_FOCUS_RIGHT); + elm_object_focus_next_object_set(retry_btn, retry_btn, ELM_FOCUS_LEFT); + elm_object_focus_next_object_set(cancel_btn, cancel_btn, ELM_FOCUS_UP); + elm_object_focus_next_object_set(retry_btn, retry_btn, ELM_FOCUS_UP); + elm_object_focus_next_object_set(cancel_btn, cancel_btn, ELM_FOCUS_DOWN); + elm_object_focus_next_object_set(retry_btn, retry_btn, ELM_FOCUS_DOWN); + + //evas_object_smart_callback_add(retry_btn, SIG_CLICKED, _retry_btn_clicked_cb, priv); + //evas_object_smart_callback_add(cancel_btn, SIG_CLICKED, _popup_ok_cancel_btn_clicked_cb, priv); + Connect(retry_btn, 20); + Connect(cancel_btn, 21); + + elm_object_focus_set(retry_btn, EINA_TRUE); + + elm_object_focus_allow_set(layout, EINA_TRUE); + //evas_object_smart_callback_add(layout, SIG_UNFOCUSED, _ctxpopup_unfocused_cb, priv); + //evas_object_event_callback_add(layout, EVAS_CALLBACK_KEY_DOWN, _ctxpopup_pressed_cb, priv); + Connect(layout, 22); + + w = DEFAULT_WIN_WIDTH; + h = DEFAULT_WIN_HEIGHT; + + evas_object_move(layout, CENTER_ALIGN * (w - POPUP_WIDTH) * ELM_SCALE, CENTER_ALIGN * (h - POPUP_HEIGHT) * ELM_SCALE); +} + + +bool CIpSettingView::m_ConfigNetworkDynamic(void) +{ + bool result = false; + + switch (m->network_type) { + case TYPE_WIRED: + if(!m->pNetConMgr->SetIpConfType(CONNECTION_IP_CONFIG_TYPE_DYNAMIC)) { + _ERR("connection_mgr_ip_dynamic_config() failed."); + return false; + } + + break; + case TYPE_WIRELESS: + result = m->pWifiMgr->SetIpType(m->ap, WIFI_IP_CONFIG_TYPE_DYNAMIC); + if(result != false) { + _ERR("connection_mgr_ip_dynamic_config() failed."); + return false; + } + + break; + default: + break; + } + + return true; +} + + +bool CIpSettingView::m_ConfigNetworkManually(void) +{ + bool result = false; + + result = m_CheckIpValid(); + if (result != true) { + _ERR("the ip is invalid."); + m_ShowInvalidIpPopup(); + return false; + } + + result = false; + switch (m->network_type) { + case TYPE_WIRED: + if (!m->pNetConMgr->SetIpAddr(m->info.ip_addr)) { + _ERR("set profile failed."); + return false; + } + if (!m->pNetConMgr->SetSubnetMask(m->info.submask)) { + _ERR("set profile failed."); + return false; + } + if (!m->pNetConMgr->SetGateway(m->info.gateway)) { + _ERR("set profile failed."); + return false; + } + if (!m->pNetConMgr->SetDNS(m->info.dns)) { + _ERR("set profile failed."); + return false; + } + + vconf_set_str(WIRED_IP_KEY, m->info.ip_addr); + vconf_set_str(WIRED_SUBMASK_KEY, m->info.submask); + vconf_set_str(WIRED_GATEWAY_KEY, m->info.gateway); + vconf_set_str(WIRED_DNS_KEY, m->info.dns); + break; + case TYPE_WIRELESS: + result = m->pWifiMgr->SetIp(m->ap, m->info.ip_addr); + if(result != true) { + _ERR("set wifi dns config failed."); + return false; + } + result = m->pWifiMgr->SetSubnetMask(m->ap, m->info.submask); + if(result != true) { + _ERR("set wifi dns config failed."); + return false; + } + result = m->pWifiMgr->SetGateway(m->ap, m->info.gateway); + if(result != true) { + _ERR("set wifi dns config failed."); + return false; + } + result = m->pWifiMgr->SetDNS(m->ap, m->info.dns); + if(result != true) { + _ERR("set wifi dns config failed."); + return false; + } + + vconf_set_str(WIRELESS_IP_KEY, m->info.ip_addr); + vconf_set_str(WIRELESS_SUBMASK_KEY, m->info.submask); + vconf_set_str(WIRELESS_GATEWAY_KEY, m->info.gateway); + vconf_set_str(WIRELESS_DNS_KEY, m->info.dns); + break; + default: + break; + } + + return true; +} + + +bool CIpSettingView::m_CheckIpValid(void) +{ + if (!strncmp(m->info.ip_addr, ZERO_IP, IP_STRING_MAX_SIZE)) { + _ERR("IP addr is invalid."); + return false; + } + + if (!strncmp(m->info.submask, ZERO_IP, IP_STRING_MAX_SIZE)) { + _ERR("submask addr is invalid."); + return false; + } + + if (!strncmp(m->info.gateway, ZERO_IP, IP_STRING_MAX_SIZE)) { + _ERR("gateway addr is invalid."); + return false; + } + + if (!strncmp(m->info.dns, ZERO_IP, IP_STRING_MAX_SIZE)) { + _ERR("dns addr is invalid."); + return false; + } + + return true; +} + + +void CIpSettingView::m_ShowInvalidIpPopup(void) +{ + Evas_Object *layout; + Evas_Object *ok_btn; + Evas_Coord w; + Evas_Coord h; + char content[CONTENT_TXT_SIZE]; + + if (m->confirm_popup) { + evas_object_del(m->confirm_popup); + m->confirm_popup = NULL; + } + + evas_object_show(m->dim_ly); + + layout = util_add_layout(m->base, UG_NETWORK_EDJ_FILE, GRP_CONFIRM_LAYOUT); + if (!layout) { + _ERR("add layout failed."); + evas_object_hide(m->dim_ly); + return; + } + + evas_object_show(layout); + + if (m->network_type == TYPE_WIRED) + elm_object_part_text_set(layout, PART_TEXT_TITLE, _(TXT_WIRED_LY)); + else + elm_object_part_text_set(layout, PART_TEXT_TITLE, _(TXT_WIRELESS_LY)); + + memset(content, 0, CONTENT_TXT_SIZE); + snprintf(content, CONTENT_TXT_SIZE - 1, "%s", _(TXT_INVALID_IP)); + elm_object_part_text_set(layout, PART_TEXT_CONTENT, content); + + ok_btn = util_add_button(layout, STYLE_SETTING_BTN, PART_OK_BTN, _(TXT_OK)); + if (!ok_btn) { + _ERR("util add button failed."); + evas_object_del(layout); + evas_object_hide(m->dim_ly); + return; + } + + elm_object_focus_next_object_set(ok_btn, ok_btn, ELM_FOCUS_RIGHT); + elm_object_focus_next_object_set(ok_btn, ok_btn, ELM_FOCUS_LEFT); + elm_object_focus_next_object_set(ok_btn, ok_btn, ELM_FOCUS_UP); + elm_object_focus_next_object_set(ok_btn, ok_btn, ELM_FOCUS_DOWN); + //evas_object_smart_callback_add(ok_btn, SIG_CLICKED, _popup_ok_cancel_btn_clicked_cb, priv); + Connect(ok_btn, 23); + + elm_object_focus_set(ok_btn, EINA_TRUE); + + elm_object_focus_allow_set(layout, EINA_TRUE); + //evas_object_smart_callback_add(layout, SIG_UNFOCUSED, _ctxpopup_unfocused_cb, priv); + //evas_object_event_callback_add(layout, EVAS_CALLBACK_KEY_DOWN, _ctxpopup_pressed_cb, priv); + Connect(layout, 24); + + w = DEFAULT_WIN_WIDTH; + h = DEFAULT_WIN_HEIGHT; + + evas_object_move(layout, CENTER_ALIGN * (w - POPUP_WIDTH) * ELM_SCALE, CENTER_ALIGN * (h - POPUP_HEIGHT) * ELM_SCALE); + + m->confirm_popup = layout; +} + + +void CIpSettingView::m_SaveMode(void) +{ + switch (m->network_type) { + case TYPE_WIRED: + if(m->ip_mode == MODE_AUTO) { + vconf_set_str(WIRED_IP_LAST_MODE, _(TXT_OBTAIN_AUTO)); + } + else if(m->ip_mode == MODE_MAN) { + vconf_set_str(WIRED_IP_LAST_MODE, _(TXT_ENTER_MAN)); + } + + if(m->dns_mode == MODE_AUTO) { + vconf_set_str(WIRED_DNS_LAST_MODE, _(TXT_OBTAIN_AUTO)); + } + else if(m->dns_mode == MODE_MAN) { + vconf_set_str(WIRED_DNS_LAST_MODE, _(TXT_ENTER_MAN)); + } + break; + case TYPE_WIRELESS: + if(m->ip_mode == MODE_AUTO) { + vconf_set_str(WIRELESS_IP_LAST_MODE, _(TXT_OBTAIN_AUTO)); + } + else if(m->ip_mode == MODE_MAN) { + vconf_set_str(WIRELESS_IP_LAST_MODE, _(TXT_ENTER_MAN)); + } + + if(m->dns_mode == MODE_AUTO) { + vconf_set_str(WIRELESS_DNS_LAST_MODE, _(TXT_OBTAIN_AUTO)); + } + else if(m->dns_mode == MODE_MAN) { + vconf_set_str(WIRELESS_DNS_LAST_MODE, _(TXT_ENTER_MAN)); + } + break; + default: + break; + } +} + + +void CIpSettingView::m_SetTheValue(void) +{ + Evas_Object *btn; + const char *value1; + const char *value2; + const char *value3; + const char *value4; + char value[IP_STRING_MAX_SIZE]; + + value1 = NULL; + btn = (Evas_Object *) evas_object_data_get(m->config_popup, IP_VALUE1); + if (btn) + value1 = elm_object_text_get(btn); + + value2 = NULL; + btn = (Evas_Object *) evas_object_data_get(m->config_popup, IP_VALUE2); + if (btn) + value2 = elm_object_text_get(btn); + + value3 = NULL; + btn = (Evas_Object *) evas_object_data_get(m->config_popup, IP_VALUE3); + if (btn) + value3 = elm_object_text_get(btn); + + value4 = NULL; + btn = (Evas_Object *) evas_object_data_get(m->config_popup, IP_VALUE4); + if (btn) + value4 = elm_object_text_get(btn); + + memset(value, 0, IP_STRING_MAX_SIZE); + snprintf(value, IP_STRING_MAX_SIZE, "%s.%s.%s.%s", + value1 ? value1 : "\\0", value2 ? value2 : "\\0", + value3 ? value3 : "\\0", value4 ? value4 : "\\0"); + + switch (m->cur_type) { + case SETTING_IP_ADDRESS: + elm_object_part_text_set(m->ip_addr_btn, PART_VALUE, value); + strncpy(m->info.ip_addr, value, IP_STRING_MAX_SIZE); + break; + case SETTING_SUBNET_MASK: + elm_object_part_text_set(m->subnet_mask_btn, PART_VALUE, value); + strncpy(m->info.submask, value, IP_STRING_MAX_SIZE); + break; + case SETTING_GATEWAY: + elm_object_part_text_set(m->gateway_btn, PART_VALUE, value); + strncpy(m->info.gateway, value, IP_STRING_MAX_SIZE); + break; + case SETTING_DNS_SERVER: + elm_object_part_text_set(m->dns_server_btn, PART_VALUE, value); + strncpy(m->info.dns, value, IP_STRING_MAX_SIZE); + break; + default: + return; + } + + evas_object_del(m->config_popup); + m->config_popup = NULL; +} + + +void CIpSettingView::OnKeyDown(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev) +{ + /* ID list */ + /* 0 m->base */ + /* 1 m->dns_mode_btn */ + /* 2 m->dns_setting_btn */ + /* 3 m->ok_btn */ + /* 4 m->cancel_btn */ + /* 5 m->ip_mode_btn */ + /* 6 m->ip_addr_btn */ + /* 7 m->subnet_mask_btn */ + /* 8 m->gateway_btn */ + /* 9 btn_auto */ + /* 10 btn_man */ + /* 11 m->dns_mode_ly */ + /* 12 ctxpopup auto_btn*/ + /* 13 ctxpopup man_btn*/ + /* 14 m->ip_mode_ly */ + /* 15 m->config_popup */ + /* 16 m->cur_ip_btn[0] */ + /* 17 m->cur_ip_btn[1] */ + /* 18 m->cur_ip_btn[2] */ + /* 19 m->cur_ip_btn[3] */ + /* 20 showpopup retry_btn */ + /* 21 showpopup cancel_btn */ + /* 22 showpopup */ + /* 23 showInvalidIpPopup ok_btn */ + /* 24 showInvalidIpPopup layout */ + + + if (!ev->keyname) { + _ERR("ev->keyname is NULL."); + return; + } + + switch(id) { + case 0: + if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) { +#if 0 + viewmgr_pop(m->vmgr); +#endif + return; + } + break; + case 9: + case 10: + case 12: + case 13: + if (!strcmp(ev->keyname, KEY_LEFT) || !strcmp(ev->keyname, KEY_RIGHT)) { + evas_object_hide(m->dim_ly); + if (m->cur_type == SETTING_IP) { + evas_object_del(m->ip_mode_ly); + m->ip_mode_ly = NULL; + } else if (m->cur_type == SETTING_DNS) { + evas_object_del(m->dns_mode_ly); + m->dns_mode_ly = NULL; + } + } + break; + case 11: + if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) { + evas_object_hide(m->dim_ly); + evas_object_del(m->dns_mode_ly); + m->dns_mode_ly = NULL; + } else if (!strcmp(ev->keyname, KEY_EXIT)) { + ug_destroy_me(m->ug); + } + break; + case 14: + if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) { + evas_object_hide(m->dim_ly); + evas_object_del(m->ip_mode_ly); + m->ip_mode_ly = NULL; + } + break; + case 15: + if (!strcmp(ev->keyname, KEY_ENTER) || !strcmp(ev->keyname, KEY_ENTER_REMOTE)) { + evas_object_hide(m->dim_ly); + m_SetTheValue(); + evas_object_del(obj); + } else if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) { + evas_object_hide(m->dim_ly); + evas_object_del(obj); + } + break; + case 16: + case 17: + case 18: + case 19: + const char *value; + int num, new_num; + + if (!strcmp(ev->keyname, KEY_UP)) { + value = elm_object_text_get(obj); + num = atoi(value); + num++; + if (num > MAX_IP_NUM) + num = 0; + } else if (!strcmp(ev->keyname, KEY_DOWN)) { + value = elm_object_text_get(obj); + num = atoi(value); + num--; + if (num < 0) + num = MAX_IP_NUM; + } else if (!strcmp(ev->keyname, KEY_0) || + !strcmp(ev->keyname, KEY_1) || + !strcmp(ev->keyname, KEY_2) || + !strcmp(ev->keyname, KEY_3) || + !strcmp(ev->keyname, KEY_4) || + !strcmp(ev->keyname, KEY_5) || + !strcmp(ev->keyname, KEY_6) || + !strcmp(ev->keyname, KEY_7) || + !strcmp(ev->keyname, KEY_8) || + !strcmp(ev->keyname, KEY_9)) { + value = elm_object_text_get(obj); + if (!value) + elm_object_text_set(obj, ev->keyname); + + new_num = atoi(ev->keyname); + + num = atoi(value); + if (!num || (num * RATIO + new_num) > MAX_IP_NUM) { + elm_object_text_set(obj, ev->keyname); + return; + } + + num = num * RATIO + new_num; + } else { + return; + } + + char temp_value[IP_STRING_MAX_SIZE]; + + memset(temp_value, 0, IP_STRING_MAX_SIZE); + snprintf(temp_value, IP_STRING_MAX_SIZE - 1, "%d", num); + elm_object_text_set(obj, temp_value); + break; + case 22: + case 24: + if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) { + evas_object_hide(m->dim_ly); + evas_object_del(obj); + } + break; + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + default: + break; + } +} + + +void CIpSettingView::OnMouseClicked(int id, Evas_Object *obj) +{ + /* ID list */ + /* 0 m->base */ + /* 1 m->dns_mode_btn */ + /* 2 m->dns_setting_btn */ + /* 3 m->ok_btn */ + /* 4 m->cancel_btn */ + /* 5 m->ip_mode_btn */ + /* 6 m->ip_addr_btn */ + /* 7 m->subnet_mask_btn */ + /* 8 m->gateway_btn */ + /* 9 btn_auto */ + /* 10 btn_man */ + /* 11 m->dns_mode_ly */ + /* 12 ctxpopup auto_btn*/ + /* 13 ctxpopup man_btn*/ + /* 14 m->ip_mode_ly */ + /* 15 m->config_popup */ + /* 16 m->cur_ip_btn[0] */ + /* 17 m->cur_ip_btn[1] */ + /* 18 m->cur_ip_btn[2] */ + /* 19 m->cur_ip_btn[3] */ + /* 20 showpopup retry_btn */ + /* 21 showpopup cancel_btn */ + /* 22 showpopup */ + /* 23 showInvalidIpPopup ok_btn */ + /* 24 showInvalidIpPopup layout */ + + switch(id) { + case 0: + break; + case 1: + { + Evas_Object *ctxpopup, *box, *btn_auto, *btn_man; + Evas_Coord x, y, w, h; + Evas_Object *btn[2]; + + m->cur_type = SETTING_DNS; + + if (m->dns_mode == MODE_INVALID) + m->dns_mode = MODE_MAN; + + ctxpopup = util_add_layout(m->base, UG_NETWORK_EDJ_FILE, GRP_NETWORK_MODE_SETTING); + if (!ctxpopup) { + _ERR("elm_layout_add() failed."); + return; + } + + box = util_add_box(ctxpopup, PART_SWALLOW_CONTENT); + if (!box) { + _ERR("add box failed."); + evas_object_del(ctxpopup); + return; + } + + elm_box_horizontal_set(box, EINA_FALSE); + + btn_auto = util_add_button(m->base, STYLE_MODE_SELECT_BTN, NULL, _(TXT_OBTAIN_AUTO)); + if (!btn_auto) { + _ERR("Add btn failed."); + evas_object_del(ctxpopup); + return; + } +#if 0 + evas_object_smart_callback_add(btn_auto, SIG_DISMISSED, _mode_sub_popup_dismissed_cb, data); +#endif + //evas_object_smart_callback_add(btn_auto, SIG_CLICKED, _dns_auto_mode_btn_clicked_cb, data); + //evas_object_event_callback_add(btn_auto, EVAS_CALLBACK_KEY_DOWN, _mode_sub_popup_key_pressed_cb, data); + Connect(btn_auto, 9); + + elm_box_pack_end(box, btn_auto); + elm_object_focus_set(btn_auto, EINA_TRUE); + btn[0] = btn_auto; + + btn_man = util_add_button(m->base, STYLE_MODE_SELECT_BTN, NULL, _(TXT_ENTER_MAN)); + if (!btn_man) { + _ERR("Add btn failed."); + evas_object_del(ctxpopup); + return; + } +#if 0 + evas_object_smart_callback_add(btn, SIG_DISMISSED, _mode_sub_popup_dismissed_cb, data); +#endif + //evas_object_smart_callback_add(btn, SIG_CLICKED, _dns_manual_mode_btn_clicked_cb, data); + //evas_object_event_callback_add(btn, EVAS_CALLBACK_KEY_DOWN, _mode_sub_popup_key_pressed_cb, data); + Connect(btn_man, 10); + + elm_box_pack_end(box, btn_man); + btn[1] = btn_man; + + m_SetupDownCycleFocus(btn, 2); +#if 0 + + evas_object_smart_callback_add(ctxpopup, SIG_DISMISSED, _dns_ctxpopup_dismissed_cb, priv); +#endif + //evas_object_event_callback_add(ctxpopup, EVAS_CALLBACK_KEY_DOWN, _dns_ctxpopup_key_pressed_cb, priv); + //evas_object_smart_callback_add(ctxpopup, SIG_UNFOCUSED, _ctxpopup_unfocused_cb, priv); + Connect(ctxpopup, 11); + + evas_object_geometry_get(m->dns_mode_btn, &x, &y, &w, &h); + m->dns_mode_ly = ctxpopup; + + evas_object_move(ctxpopup, (x + SETTING_MODE_OFFSET_X) * ELM_SCALE, + (y + h) * ELM_SCALE); + + if (m->dns_mode == MODE_AUTO) + elm_object_signal_emit(btn_auto, SIG_BTN_SELECTED, PROG); + else if (m->dns_mode == MODE_MAN) + elm_object_signal_emit(btn_man, SIG_BTN_SELECTED, PROG); + + evas_object_show(m->dim_ly); + + m_KeepBtnFocused(); + } + break; + case 2: + m->cur_type = SETTING_DNS_SERVER; + m_CreateValuePopup(); + break; + case 3: + m_ConfigNetwork(); + break; + case 4: +#if 0 + if (m->vmgr) + viewmgr_pop(m->vmgr); +#endif + break; + case 5: + { + Evas_Object *ctxpopup, *box, *auto_btn, *man_btn; + Evas_Coord x, y, w, h; + Evas_Object *btn[MODE_BTN_NUM]; + + m->cur_type = SETTING_IP; + + if (m->ip_mode == MODE_INVALID) + m->ip_mode = MODE_MAN; + + ctxpopup = util_add_layout(m->base, UG_NETWORK_EDJ_FILE, GRP_NETWORK_MODE_SETTING); + if (!ctxpopup) { + _ERR("elm_layout_add() failed."); + return; + } + + evas_object_show(m->dim_ly); + m_KeepBtnFocused(); + + box = util_add_box(ctxpopup, PART_SWALLOW_CONTENT); + if (!box) { + _ERR("create box failed."); + evas_object_del(ctxpopup); + return; + } + + elm_box_horizontal_set(box, EINA_FALSE); + + auto_btn = util_add_button(ctxpopup, STYLE_MODE_SELECT_BTN, NULL, _(TXT_OBTAIN_AUTO)); + if (!auto_btn) { + _ERR("Add btn failed."); + evas_object_del(ctxpopup); + return; + } +#if 0 + evas_object_smart_callback_add(auto_btn, SIG_DISMISSED, _mode_sub_popup_dismissed_cb, NULL); +#endif + //evas_object_smart_callback_add(auto_btn, SIG_CLICKED, _ip_auto_mode_btn_clicked_cb, NULL); + //evas_object_event_callback_add(auto_btn, EVAS_CALLBACK_KEY_DOWN, _mode_sub_popup_key_pressed_cb, NULL); + Connect(auto_btn, 12); + + elm_box_pack_end(box, auto_btn); + elm_object_focus_set(auto_btn, EINA_TRUE); + btn[0] = auto_btn; + + man_btn = util_add_button(ctxpopup, STYLE_MODE_SELECT_BTN, NULL, _(TXT_ENTER_MAN)); + if (!man_btn) { + _ERR("Add btn failed."); + evas_object_del(ctxpopup); + return; + } +#if 0 + evas_object_smart_callback_add(man_btn, SIG_DISMISSED, _mode_sub_popup_dismissed_cb, NULL); +#endif + //evas_object_smart_callback_add(man_btn, SIG_CLICKED, _ip_manual_mode_btn_clicked_cb, NULL); + //evas_object_event_callback_add(man_btn, EVAS_CALLBACK_KEY_DOWN, _mode_sub_popup_key_pressed_cb, NULL); + Connect(man_btn, 13); + + elm_box_pack_end(box, man_btn); + btn[1] = man_btn; + + m_SetupDownCycleFocus(btn, 2); + //evas_object_event_callback_add(ctxpopup, EVAS_CALLBACK_KEY_DOWN, _ip_ctxpopup_key_pressed_cb, priv); + //evas_object_smart_callback_add(ctxpopup, SIG_UNFOCUSED, _ctxpopup_unfocused_cb, priv); + Connect(man_btn, 14); + + m->ip_mode_ly = ctxpopup; + + if (m->ip_mode == MODE_AUTO) + elm_object_signal_emit(auto_btn, SIG_BTN_SELECTED, PROG); + else if (m->ip_mode == MODE_MAN) + elm_object_signal_emit(man_btn, SIG_BTN_SELECTED, PROG); + + evas_object_geometry_get(m->ip_mode_btn, &x, &y, &w, &h); + evas_object_move(ctxpopup, (x + SETTING_MODE_OFFSET_X) * ELM_SCALE, (y + h) * ELM_SCALE); + } + break; + case 6: + m->cur_type = SETTING_IP_ADDRESS; + m_CreateValuePopup(); + break; + case 7: + m->cur_type = SETTING_SUBNET_MASK; + m_CreateValuePopup(); + break; + case 8: + m->cur_type = SETTING_GATEWAY; + m_CreateValuePopup(); + break; + case 9: + elm_object_disabled_set(m->dns_server_btn, EINA_TRUE); + elm_object_part_text_set(m->dns_mode_btn, PART_VALUE, _(TXT_OBTAIN_AUTO)); + evas_object_del(m->dns_mode_ly); + m->dns_mode_ly = NULL; + m->dns_mode = MODE_AUTO; + evas_object_hide(m->dim_ly); + break; + case 10: + elm_object_disabled_set(m->dns_server_btn, EINA_FALSE); + elm_object_part_text_set(m->dns_mode_btn, PART_VALUE, _(TXT_ENTER_MAN)); + evas_object_del(m->dns_mode_ly); + m->dns_mode_ly = NULL; + m->dns_mode = MODE_MAN; + evas_object_hide(m->dim_ly); + break; + case 11: + break; + case 12: + elm_object_disabled_set(m->ip_addr_btn, EINA_TRUE); + elm_object_disabled_set(m->subnet_mask_btn, EINA_TRUE); + elm_object_disabled_set(m->gateway_btn, EINA_TRUE); + + if (m->ip_mode_btn) + elm_object_part_text_set(m->ip_mode_btn, PART_VALUE, _(TXT_OBTAIN_AUTO)); + + evas_object_del(m->ip_mode_ly); + m->ip_mode_ly = NULL; + m->ip_mode = MODE_AUTO; + + evas_object_hide(m->dim_ly); + break; + case 13: + elm_object_disabled_set(m->ip_addr_btn, EINA_FALSE); + elm_object_disabled_set(m->subnet_mask_btn, EINA_FALSE); + elm_object_disabled_set(m->gateway_btn, EINA_FALSE); + + elm_object_part_text_set(m->ip_mode_btn, + PART_VALUE, _(TXT_ENTER_MAN)); + + evas_object_del(m->ip_mode_ly); + m->ip_mode_ly = NULL; + m->ip_mode = MODE_MAN; + + evas_object_hide(m->dim_ly); + break; + case 16: + case 17: + case 18: + case 19: + evas_object_hide(m->dim_ly); + if (m->confirm_popup) + evas_object_del(m->confirm_popup); + break; + case 20: + if (m->confirm_popup) + evas_object_del(m->confirm_popup); + evas_object_hide(m->dim_ly); + elm_object_focus_set(m->ok_btn, EINA_TRUE); + m_ConfigNetwork(); + break; + case 21: + case 23: + if (m->confirm_popup) + evas_object_del(m->confirm_popup); + evas_object_hide(m->dim_ly); + elm_object_focus_set(m->ok_btn, EINA_TRUE); + break; + default: + break; + } +} + +void CIpSettingView::OnUnfocused(int id, Evas_Object *obj, Elm_Object_Item *item){ + /* ID list */ + /* 0 m->base */ + /* 1 m->dns_mode_btn */ + /* 2 m->dns_setting_btn */ + /* 3 m->ok_btn */ + /* 4 m->cancel_btn */ + /* 5 m->ip_mode_btn */ + /* 6 m->ip_addr_btn */ + /* 7 m->subnet_mask_btn */ + /* 8 m->gateway_btn */ + /* 9 btn_auto */ + /* 10 btn_man */ + /* 11 m->dns_mode_ly */ + /* 12 ctxpopup auto_btn*/ + /* 13 ctxpopup man_btn*/ + /* 14 m->ip_mode_ly */ + /* 15 m->config_popup */ + /* 16 m->cur_ip_btn[0] */ + /* 17 m->cur_ip_btn[1] */ + /* 18 m->cur_ip_btn[2] */ + /* 19 m->cur_ip_btn[3] */ + /* 20 showpopup retry_btn */ + /* 21 showpopup cancel_btn */ + /* 22 showpopup */ + /* 23 showInvalidIpPopup ok_btn */ + /* 24 showInvalidIpPopup layout */ + + switch(id) { + case 11: + case 14: + case 15: + case 22: + case 24: + evas_object_hide(m->dim_ly); + evas_object_del(obj); + break; + default: + break; + } +} + + diff --git a/ug/network/src/NetworkMainView.cpp b/ug/network/src/NetworkMainView.cpp index b231edc..d7f63b4 100644 --- a/ug/network/src/NetworkMainView.cpp +++ b/ug/network/src/NetworkMainView.cpp @@ -3,7 +3,6 @@ #include "dbg.h" #include "util.h" #include "defs.h" -#include "ip_setting_view.h" #include "i18n.h" #include "common.h" #include "wifi_passcode_view.h" @@ -476,6 +475,7 @@ bool CNetworkMainView::sm_CbWifiFoundAP(wifi_ap_h ap, void *data) CNetworkMainView *instance = NULL; instance = (CNetworkMainView *) data; instance->m_OnWifiFoundAP(ap); + return true; } @@ -717,8 +717,7 @@ bool CNetworkMainView::m_InitConnectionMgr() { _DBG(); if(!CNetConMgr::Initialize()) { - _ERR("the param is invalid."); - return false; + _ERR("Fail to init CNetConMgr"); } m->pNetConMgr = CNetConMgr::GetInstance(); @@ -728,7 +727,7 @@ bool CNetworkMainView::m_InitConnectionMgr() } if(!m->pNetConMgr->GetProfileName(m->profile_name)) { - _ERR("Fail to get instance"); + _ERR("Fail to get profilename"); return false; } @@ -991,10 +990,10 @@ void CNetworkMainView::m_FillContentPart(Evas_Object *obj) } if (old_obj) { - elm_object_part_content_unset(m->base, PART_NETLIST_PANNEL); evas_object_hide(old_obj); } + elm_object_part_content_unset(m->base, PART_NETLIST_PANNEL); elm_object_part_content_set(m->base, PART_NETLIST_PANNEL, obj); evas_object_show(obj); @@ -1209,13 +1208,17 @@ Evas_Object* CNetworkMainView::m_CreateGenlistView(void) void CNetworkMainView::m_ClearGenlist(void) { _DBG(); + struct wifi_ap_info *ap; void *temp; elm_genlist_clear(m->genlist); if (m->ap_list) EINA_LIST_FREE(m->ap_list, temp) - free(temp); + { + ap = (struct wifi_ap_info *) temp; + free(ap); + } } @@ -1627,6 +1630,7 @@ bool CNetworkMainView::Create(void *data) _CHECK(m_InitConnectionMgr()) _CHECK(m->base = m_CreateMainLayout()) _COMMAND{ + m->ap_list = NULL; const char *str = NULL; str = vconf_get_str(SELECTED_NETWORK_TYPE_KEY); if (str && !strcmp(str, TXT_WIRED)) diff --git a/ug/network/src/WifiPasscodeView.cpp b/ug/network/src/WifiPasscodeView.cpp new file mode 100644 index 0000000..e69de29 diff --git a/ug/network/src/ip_setting_view.cpp b/ug/network/src/ip_setting_view.cpp deleted file mode 100644 index 7aea65a..0000000 --- a/ug/network/src/ip_setting_view.cpp +++ /dev/null @@ -1,2720 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include "defs.h" -#include "dbg.h" -#include "ip_setting_view.h" -#include "network_viewmgr.h" -#include -#include "i18n.h" -#include "util.h" -#include "common.h" -#include "util.h" - -#include "WifiMgr.h" -#include "NetConMgr.h" - -#define KEY_PRIV "priv" - -#define MODE_BTN_NUM 2 -#define MAX_IP_NUM 255 -#define IP_SET_MAX_NUM 4 -#define STRING_MAX_SIZE 50 -#define SETTING_MODE_OFFSET_X 448 -#define SETTING_MODE_OFFSET_Y 0 -#define SETTING_VALUE_OFFSET_X 162 -#define SETTING_VALUE_OFFSET_Y 20 -#define CENTER_ALIGN 0.5 -#define BOX_PAD_X 0 -#define BOX_PAD_Y 2 -#define RATIO 10 - -#define IP_VALUE1 "value1" -#define IP_VALUE2 "value2" -#define IP_VALUE3 "value3" -#define IP_VALUE4 "value4" - -#define TXT_MAKE_OTHER_NETWORK _("You can make other network"\ - "
Enter the IP address to use.") - -enum connection_setting_enum { - SETTING_INVALID, - SETTING_IP, - SETTING_IP_ADDRESS, - SETTING_SUBNET_MASK, - SETTING_GATEWAY, - SETTING_DNS, - SETTING_DNS_SERVER -}; - -struct _priv { - Evas_Object *win; - ui_gadget_h ug; - struct viewmgr *vmgr; - - Evas_Object *base; - Evas_Object *dim_ly; - Evas_Object *ip_mode_btn; - Evas_Object *ip_addr_btn; - Evas_Object *subnet_mask_btn; - Evas_Object *gateway_btn; - Evas_Object *dns_mode_btn; - Evas_Object *dns_server_btn; - Evas_Object *ip_mode_ly; - Evas_Object *dns_mode_ly; - Evas_Object *config_popup; - Evas_Object *cur_ip_btn[IP_SET_MAX_NUM]; - Evas_Object *confirm_popup; - Evas_Object *ok_btn; - Evas_Object *cancel_btn; - - struct network_info info; - enum setting_mode ip_mode; - enum setting_mode dns_mode; - - enum connection_setting_enum cur_type; - enum network_type_enum network_type; - - wifi_ap_h ap; - - char name[MAX_NAME_SIZE]; - - CWifiMgr *pWifiMgr; - CNetConMgr *pNetConMgr; -}; - -static void _show_confirm_popup(struct _priv *priv); -static void _popup_dismissed_cb(void *data, Evas_Object *obj, void *ev); - -static void _get_ip_info(char *des, const char *key) -{ - const char *str; - - if (!des || !key) - return; - - str = vconf_get_str(key); - if (!str) - return; - - if (str == '\0' || !strncmp(str, NULL_STRING, IP_STRING_MAX_SIZE)) - strncpy(des, _(ZERO_IP), IP_STRING_MAX_SIZE); - else - strncpy(des, str, IP_STRING_MAX_SIZE); -} - -/** - * Initializes the private data. - * - * Called when the view is loaded. - * - * @return the handler of the private data; - */ -static struct _priv *_init_priv() -{ - struct _priv *priv; - - priv = (struct _priv *) calloc(1, sizeof(*priv)); - - priv->pWifiMgr = NULL; - priv->pWifiMgr = CWifiMgr::GetInstance(); - ASSERT(priv->pWifiMgr); - - return priv; -} - -/** - * Deinitializes the private data. - * - * Called when the view is deleted. - * - * @param[in] priv The handler of the private data - */ -static void _fini_priv(struct _priv *priv) -{ - if (!priv) - return; - - if (priv->dim_ly) - evas_object_del(priv->dim_ly); - - free(priv); -} - -/** - * Sets the cycle focus in the direction of up and down. - * - * Sets the cycle focus for an array of objects. - * - * @param[in] obj The handler of objects - * @param[in] count The count of objects - */ -static void _set_up_down_cycle_focus(Evas_Object **obj, - int count) -{ - int i; - - if (!*obj || !obj) - return; - - for (i = 0; i < count; i++) { - if (i == count - 1) - elm_object_focus_next_object_set(obj[i], obj[0], - ELM_FOCUS_DOWN); - else - elm_object_focus_next_object_set(obj[i], obj[i + 1], - ELM_FOCUS_DOWN); - - if (i == 0) - elm_object_focus_next_object_set(obj[i], obj[count - 1], - ELM_FOCUS_UP); - else - elm_object_focus_next_object_set(obj[i], obj[i - 1], - ELM_FOCUS_UP); - } -} - -/** - * Creates the basic layout of the view. - * - * @param[in] parent The parent object - * @return layout if the operation is successful; NULL if failed; - */ -static Evas_Object *_create_basic_layout(Evas_Object *parent) -{ - Evas_Object *base; - - if (!parent) { - _ERR("parent is NULL."); - return NULL; - } - - base = elm_layout_add(parent); - if (!base) { - _ERR("elm_layout_add() failed."); - return NULL; - } - - elm_layout_file_set(base, UG_NETWORK_EDJ_FILE, - GRP_CONNECTION_SETTING); - - evas_object_show(base); - - return base; -} - -/** - * Sets the description. - * - * Sets the description for the IP setting view. - * - * @param[in] priv The handler of the private data - */ -static void _set_description(struct _priv *priv) -{ - if (!priv || !priv->base) { - _ERR("priv is invalid."); - return; - } - - elm_object_part_text_set(priv->base, - PART_CONNECTION_DESCRITION, - TXT_MAKE_OTHER_NETWORK); -} - -/** - * Gets the network type. - * - * For either wired or wireless. - * - * @param[in] priv The handler of the private data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -static int _get_cur_mode(struct _priv *priv) -{ - int ret; - - if (!priv) { - _ERR("The param is invalid.\n"); - return RET_FAILED; - } - - const char *str = NULL; - if (priv->network_type == TYPE_WIRED) { - str = vconf_get_str(WIRED_IP_LAST_MODE); - if (str && !strcmp(str, _(TXT_OBTAIN_AUTO))) - priv->ip_mode = MODE_AUTO; - else - priv->ip_mode = MODE_MAN; - - str = NULL; - str = vconf_get_str(WIRED_DNS_LAST_MODE); - if (str && !strcmp(str, _(TXT_OBTAIN_AUTO))) - priv->dns_mode = MODE_AUTO; - else - priv->dns_mode = MODE_MAN; - } else if (priv->network_type == TYPE_WIRELESS) { - str = vconf_get_str(WIRELESS_IP_LAST_MODE); - if (str && !strcmp(str, _(TXT_OBTAIN_AUTO))) - priv->ip_mode = MODE_AUTO; - else - priv->ip_mode = MODE_MAN; - - str = NULL; - str = vconf_get_str(WIRELESS_DNS_LAST_MODE); - if (str && !strcmp(str, _(TXT_OBTAIN_AUTO))) - priv->dns_mode = MODE_AUTO; - else - priv->dns_mode = MODE_MAN; - } else { - _ERR("the network type is invalid."); - ret = RET_FAILED; - } - - return ret; -} - -/** - * Gets the network information for the profile. - * - * For wired network. - * - * @param[in] priv The handler of the private data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -static int _get_connection_profile_info(struct _priv *priv) -{ - struct connection_info info; - - if (!priv) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - if(!priv->pNetConMgr->GetProfileName(info.name)) { - _ERR("connection_mgr_get_profile_info() failed."); - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Gets the network information for the profile. - * - * For either wired network or wireless network. - * - * @param[in] priv The handler of the private data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -static int _get_cur_ip_info(struct _priv *priv) -{ - struct network_info info; - int ret; - bool result = false; - - if (!priv) { - _ERR("The param is invalid.\n"); - return RET_FAILED; - } - - ret = _get_connection_profile_info(priv); - if (ret != RET_SUCCESS) { - _ERR("get profile failed."); - return RET_FAILED; - } - - if (priv->network_type == TYPE_WIRED) { - if (priv->ip_mode == MODE_AUTO) { - if (!priv->pNetConMgr->GetIpAddr(info.ip_addr)) { - _ERR("connection_mgr_get_ip_info() failed."); - return RET_FAILED; - } - if (!priv->pNetConMgr->GetSubnetMask(info.submask)) { - _ERR("connection_mgr_get_ip_info() failed."); - return RET_FAILED; - } - if (!priv->pNetConMgr->GetGateway(info.gateway)) { - _ERR("connection_mgr_get_ip_info() failed."); - return RET_FAILED; - } - if (!priv->pNetConMgr->GetDNS(info.dns)) { - _ERR("connection_mgr_get_ip_info() failed."); - return RET_FAILED; - } - } else if (priv->ip_mode == MODE_MAN) { - _get_ip_info(info.ip_addr, WIRED_IP_KEY); - _get_ip_info(info.submask, WIRED_SUBMASK_KEY); - _get_ip_info(info.gateway, WIRED_GATEWAY_KEY); - _get_ip_info(info.dns, WIRED_DNS_KEY); - } else { - _ERR("ip mode is invalid."); - return RET_FAILED; - } - } else if (priv->network_type == TYPE_WIRELESS) { - if (priv->ip_mode == MODE_AUTO) { - result = priv->pWifiMgr->GetIp(priv->ap, priv->info.ip_addr); - if(result != true) { - _ERR("wifi_mgr_get_ip_info() failed."); - return RET_FAILED; - } - result = priv->pWifiMgr->GetSubnetMask(priv->ap, priv->info.submask); - if(result != true) { - _ERR("wifi_mgr_get_ip_info() failed."); - return RET_FAILED; - } - result = priv->pWifiMgr->GetGateway(priv->ap, priv->info.gateway); - if(result != true) { - _ERR("wifi_mgr_get_ip_info() failed."); - return RET_FAILED; - } - result = priv->pWifiMgr->GetDNS(priv->ap, priv->info.dns); - if(result != true) { - _ERR("wifi_mgr_get_ip_info() failed."); - return RET_FAILED; - } - } else if (priv->ip_mode == MODE_MAN) { - _get_ip_info(info.ip_addr, WIRELESS_IP_KEY); - _get_ip_info(info.submask, WIRELESS_SUBMASK_KEY); - _get_ip_info(info.gateway, WIRELESS_GATEWAY_KEY); - _get_ip_info(info.dns, WIRELESS_DNS_KEY); - } else { - _ERR("ip mode is invalid."); - return RET_FAILED; - } - } else { - _ERR("network type is invalid."); - return RET_FAILED; - } - - strncpy(priv->info.ip_addr, info.ip_addr, IP_STRING_MAX_SIZE); - strncpy(priv->info.submask, info.submask, IP_STRING_MAX_SIZE); - strncpy(priv->info.gateway, info.gateway, IP_STRING_MAX_SIZE); - strncpy(priv->info.dns, info.dns, IP_STRING_MAX_SIZE); - - return RET_SUCCESS; -} - -/** - * Shows the dim layout. - * - * Called when there is a ctxpopup. - * - * @param[in] priv The handler of the private data - */ -static void _set_layout_dim(struct _priv *priv) -{ - if (!priv || !priv->dim_ly) { - _ERR("The param is invalid.\n"); - return; - } - - evas_object_show(priv->dim_ly); -} - -/** - * Hides the dim layout. - * - * Called when the existing ctxpopup is deleted. - * - * @param[in] priv The handler of the private data - */ -static void _unset_layout_dim(struct _priv *priv) -{ - if (!priv || !priv->dim_ly) { - _ERR("The param is invalid.\n"); - return; - } - - evas_object_hide(priv->dim_ly); -} - -/** - * Deletes the confirm popup. - * - * @param[in] priv The handler of the private data - */ -static void _del_confirm_popup(struct _priv *priv) -{ - if (!priv || !priv->confirm_popup) { - _ERR("The param is invalid.\n"); - return; - } - - evas_object_del(priv->confirm_popup); - priv->confirm_popup = NULL; - - _unset_layout_dim(priv); -} - -/** -* @Evas_Smart_Cb type callback for handling clicked event. -* -* When the 'OK' or 'Cancel' button is clicked, delete the popup, -* and set the default focus. -* -* @param[in] data User data -* @param[in] obj The corresponding object which the focus event occurred -* @param[in] event Event information -*/ -static void _popup_ok_cancel_btn_clicked_cb(void *data, - Evas_Object *obj, void *event) -{ - struct _priv *priv; - - if (!data) { - _ERR("Parameter error!"); - return; - } - - priv = (struct _priv *) data; - - _del_confirm_popup(priv); - - elm_object_focus_set(priv->ok_btn, EINA_TRUE); -} - -/** - * Keeps the focused layout for the specific button. - * - * Emits a signal to edc to keep the focused state. - * - * @param[in] priv The handler of the private data - */ -static void _keep_button_focused(struct _priv *priv) -{ - Evas_Object *obj; - - if (!priv) { - _ERR("the param is invalid."); - return; - } - - switch (priv->cur_type) { - case SETTING_IP: - obj = priv->ip_mode_btn; - break; - case SETTING_IP_ADDRESS: - obj = priv->ip_addr_btn; - break; - case SETTING_SUBNET_MASK: - obj = priv->subnet_mask_btn; - break; - case SETTING_GATEWAY: - obj = priv->gateway_btn; - break; - case SETTING_DNS: - obj = priv->dns_mode_btn; - break; - case SETTING_DNS_SERVER: - obj = priv->dns_server_btn; - break; - default: - return; - } - - elm_object_signal_emit(obj, SIG_BTN_SELECTED, PROG); -} - -/** - * Disables the IP buttons. - * - * If the mode is automatic, the IP buttons will be disabled. - * - * @param[in] priv The handler of the private data - */ -static void _disable_ip_btns(struct _priv *priv) -{ - if (!priv) { - _ERR("the param is invalid."); - return; - } - - elm_object_disabled_set(priv->ip_addr_btn, EINA_TRUE); - elm_object_disabled_set(priv->subnet_mask_btn, EINA_TRUE); - elm_object_disabled_set(priv->gateway_btn, EINA_TRUE); -} - -/** - * Eables the IP buttons. - * - * If the mode is manual, the IP buttons will be eabled. - * - * @param[in] priv The handler of the private data - */ -static void _enable_ip_btns(struct _priv *priv) -{ - if (!priv) { - _ERR("the param is invalid."); - return; - } - - elm_object_disabled_set(priv->ip_addr_btn, EINA_FALSE); - elm_object_disabled_set(priv->subnet_mask_btn, EINA_FALSE); - elm_object_disabled_set(priv->gateway_btn, EINA_FALSE); -} - -/** -* @Evas_Smart_Cb type callback for handling dismissed event. -* -* When the ctxpopup is dismissed, delete the ctxpopup, -* and set the default focus. -* -* @param[in] data User data -* @param[in] obj The corresponding object which the focus event occurred -* @param[in] ev Event information -*/ -static void _popup_dismissed_cb(void *data, Evas_Object *obj, void *ev) -{ - struct _priv *priv; - - if (!data) { - _ERR("Parameter error!"); - return; - } - - priv = (struct _priv *) data; - - _unset_layout_dim(priv); - - if (priv->confirm_popup) - evas_object_del(priv->confirm_popup); -} - -/** -* @Evas_Smart_Cb type callback for handling clicked event. -* -* When the 'automatical' button is clicked, delete the popup, -* and disable the IP buttons. -* -* @param[in] data User data -* @param[in] obj The corresponding object which the focus event occurred -* @param[in] ev Event information -*/ -static void _ip_auto_mode_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) -{ - struct _priv *priv; - - if (!data || !obj) { - _ERR("The param is invalid.\n"); - return; - } - - priv = (struct _priv *) data; - - _disable_ip_btns(priv); - - if (priv->ip_mode_btn) - elm_object_part_text_set(priv->ip_mode_btn, - PART_VALUE, _(TXT_OBTAIN_AUTO)); - - evas_object_del(priv->ip_mode_ly); - priv->ip_mode_ly = NULL; - priv->ip_mode = MODE_AUTO; - - _unset_layout_dim(priv); -} - -/** -* @Evas_Smart_Cb type callback for handling dismissed event. -* -* When the ctxpopup is dismissed, delete the ctxpopup. -* -* @param[in] data User data -* @param[in] o The corresponding object which the focus event occurred -* @param[in] ei Event information -*/ -static void _mode_sub_popup_dismissed_cb(void *data, - Evas_Object *o, void *ei) -{ - struct _priv *priv; - - if (!data) { - _ERR("Parameter error!"); - return; - } - - priv = (struct _priv *) data; - - _unset_layout_dim(priv); - - if (priv->cur_type == SETTING_IP) { - evas_object_del(priv->ip_mode_ly); - priv->ip_mode_ly = NULL; - } else if (priv->cur_type == SETTING_DNS) { - evas_object_del(priv->dns_mode_ly); - priv->dns_mode_ly = NULL; - } -} - -/** - * Callback for key pressed event. - * - * If the key is KEY_BACK, delete the mode ctxpopup. - * - * @param[in] data User data - * @param[in] evas Evas handler - * @param[in] o The corresponding object which the deletion event occurred - * @param[in] ei Event information - */ -static void _mode_sub_popup_key_pressed_cb(void *data, Evas *evas, - Evas_Object *o, void *ei) -{ - Evas_Event_Key_Down *ev; - struct _priv *priv; - - if (!ei || !data) { - _ERR("The param is invalid.\n"); - return; - } - - priv = (struct _priv *) data; - ev = (Evas_Event_Key_Down *) ei; - - if (!ev->keyname) { - _ERR("ev->keyname is NULL."); - return; - } - - if (!strcmp(ev->keyname, KEY_LEFT) || !strcmp(ev->keyname, KEY_RIGHT)) { - _unset_layout_dim(priv); - - if (priv->cur_type == SETTING_IP) { - evas_object_del(priv->ip_mode_ly); - priv->ip_mode_ly = NULL; - } else if (priv->cur_type == SETTING_DNS) { - evas_object_del(priv->dns_mode_ly); - priv->dns_mode_ly = NULL; - } - } -} - -/** -* @Evas_Smart_Cb type callback for handling clicked event. -* -* When the manual mode button is clicked, delete the popup, -* and enable the IP buttons. -* -* @param[in] data User data -* @param[in] obj The corresponding object which the focus event occurred -* @param[in] ev Event information -*/ -static void _ip_manual_mode_btn_clicked_cb(void *data, - Evas_Object *obj, void *ev) -{ - struct _priv *priv; - - if (!data || !obj) { - _ERR("The param is invalid.\n"); - return; - } - - priv = (struct _priv *) data; - - _enable_ip_btns(priv); - - elm_object_part_text_set(priv->ip_mode_btn, - PART_VALUE, _(TXT_ENTER_MAN)); - - evas_object_del(priv->ip_mode_ly); - priv->ip_mode_ly = NULL; - priv->ip_mode = MODE_MAN; - - _unset_layout_dim(priv); -} - -/** - * Callback for key pressed event. - * - * If the key is KEY_BACK, delete the IP value ctxpopup. - * - * @param[in] data User data - * @param[in] evas Evas handler - * @param[in] o The corresponding object which the deletion event occurred - * @param[in] ei Event information - */ -static void _ip_ctxpopup_key_pressed_cb(void *data, Evas *evas, - Evas_Object *o, void *ei) -{ - Evas_Event_Key_Down *ev; - struct _priv *priv; - - if (!ei || !data) { - _ERR("The param is invalid.\n"); - return; - } - - priv = (struct _priv *) data; - ev = (Evas_Event_Key_Down *) ei; - - if (!ev->keyname) { - _ERR("ev->keyname is NULL."); - return; - } - - if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) { - _unset_layout_dim(priv); - - evas_object_del(priv->ip_mode_ly); - priv->ip_mode_ly = NULL; - } -} - -/** - * Callback for key pressed event. - * - * If the key is KEY_BACK, delete the ctxpopup. - * - * @param[in] data User data - * @param[in] e Evas handler - * @param[in] obj The corresponding object which the deletion event occurred - * @param[in] ei Event information - */ -static void _ctxpopup_pressed_cb(void *data, Evas *e, - Evas_Object *obj, void *ei) -{ - Evas_Event_Key_Down *ev; - struct _priv *priv; - - if (!data || !ei) { - _ERR("Parameter error!"); - return; - } - - priv = (struct _priv *) data; - ev = (Evas_Event_Key_Down *) ei; - - if (!ev->keyname) { - _ERR("ev->keyname is NULL."); - return; - } - - if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) { - _unset_layout_dim(priv); - evas_object_del(obj); - } -} - -/** -* @Evas_Smart_Cb type callback for handling unfocused event. -* -* When the ctxpopup is unfocused, hide the dim layout, -* and delete the ctxpopup. -* -* @param[in] data User data -* @param[in] obj The corresponding object which the focus event occurred -* @param[in] source Event information -*/ -static void _ctxpopup_unfocused_cb(void *data, - Evas_Object *obj, void *source) -{ - struct _priv *priv; - - if (!data || !obj) { - _ERR("data is NULL.\n"); - return; - } - - priv = (struct _priv *) data; - - _unset_layout_dim(priv); - evas_object_del(obj); -} - -/** - * Creates the mode button. - * - * Uses the style of 'mode_select'. - * - * @param[in] base The parent object - * @param[in] txt The text in button - * @param[in] cb The callback for clicked event - * @param[in] data User data - * @return button if the operation is successful; NULL if failed; - */ -static Evas_Object *_create_mode_setting_btn(Evas_Object *base, - char *txt, Evas_Smart_Cb cb, void *data) -{ - Evas_Object *btn; - - if (!base || !txt || !cb || !data) { - _ERR("The param is invalid.\n"); - return NULL; - } - - btn = util_add_button(base, STYLE_MODE_SELECT_BTN, NULL, txt); - if (!btn) { - _ERR("Add btn failed.\n"); - return NULL; - } - - evas_object_smart_callback_add(btn, SIG_DISMISSED, - _mode_sub_popup_dismissed_cb, data); - evas_object_smart_callback_add(btn, SIG_CLICKED, cb, data); - evas_object_event_callback_add(btn, EVAS_CALLBACK_KEY_DOWN, - _mode_sub_popup_key_pressed_cb, data); - - return btn; -} - -/** -* @Evas_Smart_Cb type callback for handling clicked event. -* -* Creates the IP value ctxpopup. -* -* @param[in] data User data -* @param[in] obj The corresponding object which the focus event occurred -* @param[in] ev Event information -*/ -static void _ip_setting_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) -{ - struct _priv *priv; - Evas_Object *base; - Evas_Object *ctxpopup; - Evas_Object *box; - Evas_Object *auto_btn; - Evas_Object *man_btn; - Evas_Coord x; - Evas_Coord y; - Evas_Coord w; - Evas_Coord h; - Evas_Object *btn[MODE_BTN_NUM]; - - if (!data || !obj) { - _ERR("The param is invalid.\n"); - return; - } - - priv = (struct _priv *) data; - priv->cur_type = SETTING_IP; - base = priv->base; - - if (priv->ip_mode == MODE_INVALID) - priv->ip_mode = MODE_MAN; - - ctxpopup = util_add_layout(base, UG_NETWORK_EDJ_FILE, - GRP_NETWORK_MODE_SETTING); - if (!ctxpopup) { - _ERR("elm_layout_add() failed.\n"); - return; - } - - _set_layout_dim(priv); - _keep_button_focused(priv); - - box = util_add_box(ctxpopup, PART_SWALLOW_CONTENT); - if (!box) { - _ERR("create box failed."); - evas_object_del(ctxpopup); - return; - } - - elm_box_horizontal_set(box, EINA_FALSE); - - auto_btn = _create_mode_setting_btn(ctxpopup, _(TXT_OBTAIN_AUTO), - _ip_auto_mode_btn_clicked_cb, (void *)priv); - if (!auto_btn) { - _ERR("Add btn failed.\n"); - evas_object_del(ctxpopup); - return; - } - - elm_box_pack_end(box, auto_btn); - elm_object_focus_set(auto_btn, EINA_TRUE); - btn[0] = auto_btn; - - man_btn = _create_mode_setting_btn(ctxpopup, _(TXT_ENTER_MAN), - _ip_manual_mode_btn_clicked_cb, (void *)priv); - if (!man_btn) { - _ERR("Add btn failed.\n"); - evas_object_del(ctxpopup); - return; - } - - elm_box_pack_end(box, man_btn); - btn[1] = man_btn; - - _set_up_down_cycle_focus(btn, 2); - - evas_object_event_callback_add(ctxpopup, EVAS_CALLBACK_KEY_DOWN, - _ip_ctxpopup_key_pressed_cb, priv); - evas_object_smart_callback_add(ctxpopup, SIG_UNFOCUSED, - _ctxpopup_unfocused_cb, priv); - - priv->ip_mode_ly = ctxpopup; - - if (priv->ip_mode == MODE_AUTO) - elm_object_signal_emit(auto_btn, SIG_BTN_SELECTED, PROG); - else if (priv->ip_mode == MODE_MAN) - elm_object_signal_emit(man_btn, SIG_BTN_SELECTED, PROG); - - evas_object_geometry_get(priv->ip_mode_btn, &x, &y, &w, &h); - evas_object_move(ctxpopup, (x + SETTING_MODE_OFFSET_X) * ELM_SCALE, - (y + h) * ELM_SCALE); -} - -/** - * Gets the position of IP value ctxpopup. - * - * Gets the specific position by the current type. - * - * @param[in] priv The handler of the private data - * @param[out] pos_x X position - * @param[out] pos_y Y position - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -static int _get_value_popup_pos(struct _priv *priv, - Evas_Coord *pos_x, Evas_Coord *pos_y) -{ - Evas_Coord x; - Evas_Coord y; - Evas_Coord w; - Evas_Coord h; - - if (!priv || !pos_x || !pos_y) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - switch (priv->cur_type) { - case SETTING_IP_ADDRESS: - evas_object_geometry_get(priv->ip_addr_btn, &x, &y, &w, &h); - *pos_x = x + SETTING_VALUE_OFFSET_X; - *pos_y = y - SETTING_VALUE_OFFSET_Y; - break; - case SETTING_SUBNET_MASK: - evas_object_geometry_get(priv->subnet_mask_btn, &x, &y, &w, &h); - *pos_x = x + SETTING_VALUE_OFFSET_X; - *pos_y = y - SETTING_VALUE_OFFSET_Y; - break; - case SETTING_GATEWAY: - evas_object_geometry_get(priv->gateway_btn, &x, &y, &w, &h); - *pos_x = x + SETTING_VALUE_OFFSET_X; - *pos_y = y - SETTING_VALUE_OFFSET_Y; - break; - case SETTING_DNS_SERVER: - evas_object_geometry_get(priv->dns_server_btn, &x, &y, &w, &h); - *pos_x = x + SETTING_VALUE_OFFSET_X; - *pos_y = y - 2 * SETTING_VALUE_OFFSET_Y; - break; - default: - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Sets the number to the object text. - * - * @param[in] obj The handler of the object - * @param[in] num The number - */ -static void _set_text_num(Evas_Object *obj, int num) -{ - char value[IP_STRING_MAX_SIZE]; - - if (!obj) { - _ERR("The param is invalid."); - return; - } - - memset(value, 0, IP_STRING_MAX_SIZE); - snprintf(value, IP_STRING_MAX_SIZE - 1, "%d", num); - elm_object_text_set(obj, value); -} - -/** - * Callback for key pressed event. - * - * The button responds the key, and sets the number for the button. - * - * @param[in] data User data - * @param[in] evas Evas handler - * @param[in] obj The corresponding object which the deletion event occurred - * @param[in] ei Event information - */ -static void _ip_btn_key_pressed_cb(void *data, Evas *evas, - Evas_Object *obj, void *ei) -{ - Evas_Event_Key_Down *ev; - const char *value; - int num, new_num; - - if (!ei || !data || !obj) { - _ERR("The param is invalid.\n"); - return; - } - - ev = (Evas_Event_Key_Down *) ei; - - if (!ev->keyname) { - _ERR("ev->keyname is NULL."); - return; - } - - if (!strcmp(ev->keyname, KEY_UP)) { - value = elm_object_text_get(obj); - num = atoi(value); - num++; - if (num > MAX_IP_NUM) - num = 0; - } else if (!strcmp(ev->keyname, KEY_DOWN)) { - value = elm_object_text_get(obj); - num = atoi(value); - num--; - if (num < 0) - num = MAX_IP_NUM; - } else if (!strcmp(ev->keyname, KEY_0) || - !strcmp(ev->keyname, KEY_1) || - !strcmp(ev->keyname, KEY_2) || - !strcmp(ev->keyname, KEY_3) || - !strcmp(ev->keyname, KEY_4) || - !strcmp(ev->keyname, KEY_5) || - !strcmp(ev->keyname, KEY_6) || - !strcmp(ev->keyname, KEY_7) || - !strcmp(ev->keyname, KEY_8) || - !strcmp(ev->keyname, KEY_9)) { - value = elm_object_text_get(obj); - if (!value) - elm_object_text_set(obj, ev->keyname); - - new_num = atoi(ev->keyname); - - num = atoi(value); - if (!num || (num * RATIO + new_num) > MAX_IP_NUM) { - elm_object_text_set(obj, ev->keyname); - return; - } - - num = num * RATIO + new_num; - } else { - return; - } - - _set_text_num(obj, num); -} - -/** - * Sets the value to the object text. - * - * @param[in] priv The handler of the private data - */ -static void _set_the_value(struct _priv *priv) -{ - Evas_Object *btn; - const char *value1; - const char *value2; - const char *value3; - const char *value4; - char value[IP_STRING_MAX_SIZE]; - - if (!priv || !priv->config_popup) { - _ERR("The param is invalid.\n"); - return; - } - - value1 = NULL; - btn = (Evas_Object *) evas_object_data_get(priv->config_popup, IP_VALUE1); - if (btn) - value1 = elm_object_text_get(btn); - - value2 = NULL; - btn = (Evas_Object *) evas_object_data_get(priv->config_popup, IP_VALUE2); - if (btn) - value2 = elm_object_text_get(btn); - - value3 = NULL; - btn = (Evas_Object *) evas_object_data_get(priv->config_popup, IP_VALUE3); - if (btn) - value3 = elm_object_text_get(btn); - - value4 = NULL; - btn = (Evas_Object *) evas_object_data_get(priv->config_popup, IP_VALUE4); - if (btn) - value4 = elm_object_text_get(btn); - - memset(value, 0, IP_STRING_MAX_SIZE); - snprintf(value, IP_STRING_MAX_SIZE, "%s.%s.%s.%s", - value1 ? value1 : "\\0", value2 ? value2 : "\\0", - value3 ? value3 : "\\0", value4 ? value4 : "\\0"); - - switch (priv->cur_type) { - case SETTING_IP_ADDRESS: - elm_object_part_text_set(priv->ip_addr_btn, - PART_VALUE, value); - strncpy(priv->info.ip_addr, value, IP_STRING_MAX_SIZE); - break; - case SETTING_SUBNET_MASK: - elm_object_part_text_set(priv->subnet_mask_btn, - PART_VALUE, value); - strncpy(priv->info.submask, value, IP_STRING_MAX_SIZE); - break; - case SETTING_GATEWAY: - elm_object_part_text_set(priv->gateway_btn, - PART_VALUE, value); - strncpy(priv->info.gateway, value, IP_STRING_MAX_SIZE); - break; - case SETTING_DNS_SERVER: - elm_object_part_text_set(priv->dns_server_btn, - PART_VALUE, value); - strncpy(priv->info.dns, value, IP_STRING_MAX_SIZE); - break; - default: - return; - } - - evas_object_del(priv->config_popup); - priv->config_popup = NULL; -} - -/** - * Callback for key pressed event. - * - * If the key is KEY_BACK, delete the IP value ctxpopup. - * If the key is KEY_ENTER, set the value into the button. - * - * @param[in] data User data - * @param[in] evas Evas handler - * @param[in] obj The corresponding object which the deletion event occurred - * @param[in] ei Event information - */ -static void _value_ctxpopup_key_pressed_cb(void *data, Evas *evas, - Evas_Object *obj, void *ei) -{ - Evas_Event_Key_Down *ev; - struct _priv *priv; - - if (!ei || !data) { - _ERR("The param is invalid.\n"); - return; - } - - ev = (Evas_Event_Key_Down *) ei; - priv = (struct _priv *) data; - - if (!ev->keyname) { - _ERR("ev->keyname is NULL."); - return; - } - - if (!strcmp(ev->keyname, KEY_ENTER) || !strcmp(ev->keyname, KEY_ENTER_REMOTE)) { - _unset_layout_dim(priv); - _set_the_value(priv); - evas_object_del(obj); - } else if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) { - _unset_layout_dim(priv); - evas_object_del(obj); - } -} - -/** - * Sets the cycle focus in the direction of left and right. - * - * Sets the cycle focus for an array of objects. - * - * @param[in] obj The handler of objects - * @param[in] count The count of objects - */ -static void _set_left_right_cycle_focus(Evas_Object **obj, int count) -{ - int i; - - if (!obj || !*obj) { - _ERR("the param is invalid."); - return; - } - - for (i = 0; i < count; i++) { - if (i == count - 1) - elm_object_focus_next_object_set(obj[i], - obj[0], ELM_FOCUS_RIGHT); - else - elm_object_focus_next_object_set(obj[i], - obj[i + 1], ELM_FOCUS_RIGHT); - - if (i == 0) - elm_object_focus_next_object_set(obj[i], - obj[count - 1], ELM_FOCUS_LEFT); - else - elm_object_focus_next_object_set(obj[i], - obj[i - 1], ELM_FOCUS_LEFT); - } -} - -/** - * Creates the value button for IP setting. - * - * @param[in] base The parent object - * @param[in] num The sequence number of the button - * @param[in] txt The text in the button - * @param[in] data User data - * @return button if the operation is successful; NULL if failed; - */ -static Evas_Object *_create_value_btn(Evas_Object *base, int num, - char *txt, void *data) -{ - Evas_Object *btn; - - if (!base || !txt || !data) { - _ERR("The param is invalid.\n"); - return NULL; - } - - btn = util_add_button(base, STYLE_VALUE_BTN, NULL, txt); - if (!btn) { - _ERR("add button failed.\n"); - return NULL; - } - - switch (num) { - case 0: - elm_object_part_content_set(base, PART_IP_FIRST, btn); - evas_object_data_set(base, IP_VALUE1, btn); - elm_object_focus_set(btn, EINA_TRUE); - break; - case 1: - elm_object_part_content_set(base, PART_IP_SECOND, btn); - evas_object_data_set(base, IP_VALUE2, btn); - break; - case 2: - elm_object_part_content_set(base, PART_IP_THIRD, btn); - evas_object_data_set(base, IP_VALUE3, btn); - break; - case 3: - elm_object_part_content_set(base, PART_IP_FORTH, btn); - evas_object_data_set(base, IP_VALUE4, btn); - break; - default: - break; - } - - evas_object_smart_callback_add(btn, SIG_CLICKED, - _popup_dismissed_cb, data); - evas_object_event_callback_add(btn, EVAS_CALLBACK_KEY_DOWN, - _ip_btn_key_pressed_cb, data); - elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_UP); - elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_DOWN); - - return btn; -} - -/** - * Creates value ctxpopup. - * - * User can set number in the ctxpopup. - * - * @param[in] priv The handler of the private data - */ -static void _create_value_popup(struct _priv *priv) -{ - Evas_Object *base; - Evas_Object *ctxpopup; - Evas_Object *btn; - Evas_Coord pos_x; - Evas_Coord pos_y; - int i; - - if (!priv || !priv->base) { - _ERR("The param is invalid.\n"); - return; - } - - base = priv->base; - - ctxpopup = util_add_layout(base, UG_NETWORK_EDJ_FILE, - GRP_NETWORK_VALUE_SETTING); - if (!ctxpopup) { - _ERR("elm_ctxpopup_add() failed.\n"); - return; - } - - elm_object_focus_allow_set(ctxpopup, EINA_TRUE); - evas_object_smart_callback_add(ctxpopup, SIG_UNFOCUSED, - _ctxpopup_unfocused_cb, priv); - priv->config_popup = ctxpopup; - - _set_layout_dim(priv); - - for (i = 0; i < IP_SET_MAX_NUM; i++) { - btn = _create_value_btn(ctxpopup, i, _(TXT_ZERO), (void *)priv); - if (!btn) { - _ERR("_create_value_btn() failed.\n"); - evas_object_del(ctxpopup); - priv->config_popup = NULL; - return; - } - - priv->cur_ip_btn[i] = btn; - } - - evas_object_event_callback_add(ctxpopup, EVAS_CALLBACK_KEY_DOWN, - _value_ctxpopup_key_pressed_cb, priv); - _set_left_right_cycle_focus(priv->cur_ip_btn, IP_SET_MAX_NUM); - - _keep_button_focused(priv); - - pos_x = 0; - pos_y = 0; - _get_value_popup_pos(priv, &pos_x, &pos_y); - evas_object_move(ctxpopup, pos_x * ELM_SCALE, pos_y * ELM_SCALE); -} - -/** -* @Evas_Smart_Cb type callback for handling clicked event. -* -* After the IP button is clicked, the value ctxpopup -* will be created to set the value. -* -* @param[in] data User data -* @param[in] obj The corresponding object which the focus event occurred -* @param[in] ev Event information -*/ -static void _ip_address_btn_clicked_cb(void *data, - Evas_Object *obj, void *ev) -{ - struct _priv *priv; - - if (!data || !obj) { - _ERR("The param is invalid.\n"); - return; - } - - priv = (struct _priv *) data; - - priv->cur_type = SETTING_IP_ADDRESS; - _create_value_popup(priv); -} - -/** -* @Evas_Smart_Cb type callback for handling clicked event. -* -* After the submask button is clicked, the value ctxpopup -* will be created to set the value. -* -* @param[in] data User data -* @param[in] obj The corresponding object which the focus event occurred -* @param[in] ev Event information -*/ -static void _sub_mask_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) -{ - struct _priv *priv; - - if (!data || !obj) { - _ERR("The param is invalid.\n"); - return; - } - - priv = (struct _priv *) data; - - priv->cur_type = SETTING_SUBNET_MASK; - _create_value_popup(priv); -} - -/** -* @Evas_Smart_Cb type callback for handling clicked event. -* -* After the gateway button is clicked, the value ctxpopup -* will be created to set the value. -* -* @param[in] data User data -* @param[in] obj The corresponding object which the focus event occurred -* @param[in] ev Event information -*/ -static void _gateway_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) -{ - struct _priv *priv; - - if (!data || !obj) { - _ERR("The param is invalid.\n"); - return; - } - - priv = (struct _priv *) data; - priv->cur_type = SETTING_GATEWAY; - _create_value_popup(priv); -} - -/** - * Creates setting button. - * - * @param[in] base The parent object - * @param[in] key The key value - * @param[in] txt The text in the button - * @param[in] cb The callback for clicked event - * @param[in] data User data - * @return button if the operation is successful; NULL if failed; - */ -static Evas_Object *_create_setting_btn(Evas_Object *base, - char *key, char *txt, Evas_Smart_Cb cb, void *data) -{ - Evas_Object *btn; - - if (!base || !key || !txt || !cb || !data) { - _ERR("The param is invalid.\n"); - return NULL; - } - - btn = util_add_key_value_button(base, NULL, key, txt); - if (!btn) { - _ERR("Add button failed.\n"); - return NULL; - } - - evas_object_smart_callback_add(btn, SIG_CLICKED, cb, data); - elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_LEFT); - - return btn; -} - -/** - * Creates IP setting layout. - * - * @param[in] priv The handler of the private data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -static int _create_ip_setting(struct _priv *priv) -{ - Evas_Object *base; - Evas_Object *scroll; - Evas_Object *box; - Evas_Object *btn; - char mode[STRING_MAX_SIZE]; - - if (!priv || !priv->base) { - _ERR("The param is invalid.\n"); - return RET_FAILED; - } - - base = priv->base; - - scroll = util_add_scroll(base, PART_CONNECTION_IP_SETTING); - if (!scroll) { - _ERR("add scroll failed."); - return RET_FAILED; - } - - box = util_add_box(scroll, NULL); - if (!box) { - _ERR("add box failed."); - evas_object_del(scroll); - return RET_FAILED; - } - - elm_box_horizontal_set(box, EINA_FALSE); - elm_box_padding_set(box, BOX_PAD_X, BOX_PAD_Y); - - memset(mode, 0, STRING_MAX_SIZE); - if (priv->ip_mode == MODE_AUTO) - snprintf(mode, STRING_MAX_SIZE - 1, - "%s", _(TXT_OBTAIN_AUTO)); - else - snprintf(mode, STRING_MAX_SIZE - 1, - "%s", _(TXT_ENTER_MAN)); - - btn = _create_setting_btn(base, _(TXT_IP_SETTING), mode, - _ip_setting_btn_clicked_cb, (void *)priv); - if (!btn) { - _ERR("Add button failed.\n"); - evas_object_del(scroll); - return RET_FAILED; - } - - elm_box_pack_end(box, btn); - elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_UP); - elm_object_focus_set(btn, EINA_TRUE); - priv->ip_mode_btn = btn; - - btn = _create_setting_btn(base, _(TXT_IP_ADDR), priv->info.ip_addr, - _ip_address_btn_clicked_cb, (void *)priv); - if (!btn) { - _ERR("Add btn failed.\n"); - evas_object_del(scroll); - return RET_FAILED; - } - - elm_box_pack_end(box, btn); - priv->ip_addr_btn = btn; - - btn = _create_setting_btn(base, _(TXT_SUBNET_MASK), priv->info.submask, - _sub_mask_btn_clicked_cb, (void *)priv); - if (!btn) { - _ERR("Add btn failed.\n"); - evas_object_del(scroll); - return RET_FAILED; - } - - elm_box_pack_end(box, btn); - priv->subnet_mask_btn = btn; - - btn = _create_setting_btn(base, _(TXT_GATEWAY), priv->info.gateway, - _gateway_btn_clicked_cb, (void *)priv); - if (!btn) { - _ERR("Add btn failed.\n"); - evas_object_del(scroll); - return RET_FAILED; - } - - elm_object_signal_emit(btn, SIG_HIDE_BOTTOME_LINE, PROG); - - elm_box_pack_end(box, btn); - priv->gateway_btn = btn; - - elm_object_content_set(scroll, box); - - if (priv->ip_mode == MODE_AUTO) - _disable_ip_btns(priv); - - return RET_SUCCESS; -} - -/** - * Disables DNS setting button. - * - * @param[in] priv The handler of the private data - */ -static void _disable_dns_btns(struct _priv *priv) -{ - if (!priv || !priv->dns_server_btn) { - _ERR("The param is invalid.\n"); - return; - } - - elm_object_disabled_set(priv->dns_server_btn, EINA_TRUE); -} - -/** - * Enables DNS setting button. - * - * @param[in] priv The handler of the private data - */ -static void _enable_dns_btns(struct _priv *priv) -{ - if (!priv || !priv->dns_server_btn) { - _ERR("The param is invalid.\n"); - return; - } - - elm_object_disabled_set(priv->dns_server_btn, EINA_FALSE); -} - -/** -* @Evas_Smart_Cb type callback for handling clicked event. -* -* When the 'automatical' button is clicked, delete the popup, -* and disable the DNS buttons. -* -* @param[in] data User data -* @param[in] obj The corresponding object which the focus event occurred -* @param[in] ev Event information -*/ -static void _dns_auto_mode_btn_clicked_cb(void *data, - Evas_Object *obj, void *ev) -{ - struct _priv *priv; - - if (!data || !obj) { - _ERR("The param is invalid.\n"); - return; - } - - priv = (struct _priv *) data; - - _disable_dns_btns(priv); - - elm_object_part_text_set(priv->dns_mode_btn, - PART_VALUE, _(TXT_OBTAIN_AUTO)); - - evas_object_del(priv->dns_mode_ly); - priv->dns_mode_ly = NULL; - priv->dns_mode = MODE_AUTO; - - _unset_layout_dim(priv); -} - -/** -* @Evas_Smart_Cb type callback for handling clicked event. -* -* When the manual mode button is clicked, delete the popup, -* and enable the DNS buttons. -* -* @param[in] data User data -* @param[in] obj The corresponding object which the focus event occurred -* @param[in] ev Event information -*/ -static void _dns_manual_mode_btn_clicked_cb(void *data, - Evas_Object *obj, void *ev) -{ - struct _priv *priv; - - if (!data || !obj) { - _ERR("The param is invalid.\n"); - return; - } - - priv = (struct _priv *) data; - - _enable_dns_btns(priv); - - elm_object_part_text_set(priv->dns_mode_btn, - PART_VALUE, _(TXT_ENTER_MAN)); - - evas_object_del(priv->dns_mode_ly); - priv->dns_mode_ly = NULL; - priv->dns_mode = MODE_MAN; - - _unset_layout_dim(priv); -} - -/** -* @Evas_Smart_Cb type callback for handling dismissed event. -* -* When the ctxpopup is dismissed, delete the ctxpopup. -* -* @param[in] data User data -* @param[in] obj The corresponding object which the focus event occurred -* @param[in] ev Event information -*/ -static void _dns_ctxpopup_dismissed_cb(void *data, - Evas_Object *obj, void *source) -{ - struct _priv *priv; - - if (!data) { - _ERR("Parameter error!"); - return; - } - - priv = (struct _priv *) data; - - _unset_layout_dim(priv); - - evas_object_del(priv->dns_mode_ly); - priv->dns_mode_ly = NULL; -} - -/** - * Callback for key pressed event. - * - * If the key is KEY_BACK, delete the DNS ctxpopup. - * If the key is KEY_EXIT, destroy the ug. - * - * @param[in] data User data - * @param[in] evas Evas handler - * @param[in] o The corresponding object which the deletion event occurred - * @param[in] ei Event information - */ -static void _dns_ctxpopup_key_pressed_cb(void *data, Evas *evas, - Evas_Object *o, void *ei) -{ - Evas_Event_Key_Down *ev; - struct _priv *priv; - - if (!ei || !data) { - _ERR("The param is invalid.\n"); - return; - } - - priv = (struct _priv *) data; - ev = (Evas_Event_Key_Down *) ei; - - if (!ev->keyname) { - _ERR("ev->keyname is NULL."); - return; - } - - if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) { - _unset_layout_dim(priv); - evas_object_del(priv->dns_mode_ly); - priv->dns_mode_ly = NULL; - } else if (!strcmp(ev->keyname, KEY_EXIT)) { - ug_destroy_me(priv->ug); - } -} - -/** -* @Evas_Smart_Cb type callback for handling clicked event. -* -* Creates the DNS mode ctxpopup. -* -* @param[in] data User data -* @param[in] obj The corresponding object which the focus event occurred -* @param[in] ev Event information -*/ -static void _dns_setting_btn_clicked_cb(void *data, - Evas_Object *obj, void *ev) -{ - struct _priv *priv; - Evas_Object *base; - Evas_Object *ctxpopup, *box; - Evas_Object *btn_auto, *btn_man; - Evas_Coord x, y, w, h; - Evas_Object *btn[2]; - - if (!data || !obj) { - _ERR("The param is invalid.\n"); - return; - } - - priv = (struct _priv *) data; - priv->cur_type = SETTING_DNS; - - base = priv->base; - - if (priv->dns_mode == MODE_INVALID) - priv->dns_mode = MODE_MAN; - - ctxpopup = util_add_layout(base, UG_NETWORK_EDJ_FILE, - GRP_NETWORK_MODE_SETTING); - if (!ctxpopup) { - _ERR("elm_layout_add() failed.\n"); - return; - } - - box = util_add_box(ctxpopup, PART_SWALLOW_CONTENT); - if (!box) { - _ERR("add box failed."); - evas_object_del(ctxpopup); - return; - } - - elm_box_horizontal_set(box, EINA_FALSE); - - btn_auto = _create_mode_setting_btn(ctxpopup, _(TXT_OBTAIN_AUTO), - _dns_auto_mode_btn_clicked_cb, priv); - if (!btn_auto) { - _ERR("Add btn failed.\n"); - evas_object_del(ctxpopup); - return; - } - - elm_box_pack_end(box, btn_auto); - elm_object_focus_set(btn_auto, EINA_TRUE); - btn[0] = btn_auto; - - btn_man = _create_mode_setting_btn(ctxpopup, _(TXT_ENTER_MAN), - _dns_manual_mode_btn_clicked_cb, priv); - if (!btn_man) { - _ERR("Add btn failed.\n"); - evas_object_del(ctxpopup); - return; - } - - elm_box_pack_end(box, btn_man); - btn[1] = btn_man; - - _set_up_down_cycle_focus(btn, 2); - - evas_object_event_callback_add(ctxpopup, - EVAS_CALLBACK_KEY_DOWN, - _dns_ctxpopup_key_pressed_cb, priv); - evas_object_smart_callback_add(ctxpopup, SIG_UNFOCUSED, - _ctxpopup_unfocused_cb, priv); - evas_object_smart_callback_add(ctxpopup, SIG_DISMISSED, - _dns_ctxpopup_dismissed_cb, priv); - - evas_object_geometry_get(priv->dns_mode_btn, &x, &y, &w, &h); - priv->dns_mode_ly = ctxpopup; - - evas_object_move(ctxpopup, (x + SETTING_MODE_OFFSET_X) * ELM_SCALE, - (y + h) * ELM_SCALE); - - if (priv->dns_mode == MODE_AUTO) - elm_object_signal_emit(btn_auto, SIG_BTN_SELECTED, PROG); - else if (priv->dns_mode == MODE_MAN) - elm_object_signal_emit(btn_man, SIG_BTN_SELECTED, PROG); - - _set_layout_dim(priv); - - _keep_button_focused(priv); -} - -/** -* @Evas_Smart_Cb type callback for handling clicked event. -* -* After the DNS button is clicked, the value ctxpopup -* will be created to set the value. -* -* @param[in] data User data -* @param[in] obj The corresponding object which the focus event occurred -* @param[in] ev Event information -*/ -static void _dns_server_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) -{ - struct _priv *priv; - - if (!data || !obj) { - _ERR("The param is invalid.\n"); - return; - } - - priv = (struct _priv *) data; - - priv->cur_type = SETTING_DNS_SERVER; - _create_value_popup(priv); -} - -/** - * Creates DNS setting layout. - * - * @param[in] priv The handler of the private data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -static int _create_dns_setting(struct _priv *priv) -{ - Evas_Object *base; - Evas_Object *btn; - Evas_Object *box; - char mode[STRING_MAX_SIZE]; - - if (!priv || !priv->base) { - _ERR("The param is invalid.\n"); - return RET_FAILED; - } - - base = priv->base; - - box = util_add_box(base, PART_CONNECTION_DNS_SETTING); - if (!box) { - _ERR("add box failed."); - return RET_FAILED; - } - - elm_box_horizontal_set(box, EINA_FALSE); - elm_box_padding_set(box, BOX_PAD_X, BOX_PAD_Y); - - memset(mode, 0, STRING_MAX_SIZE); - if (priv->dns_mode == MODE_AUTO) - snprintf(mode, STRING_MAX_SIZE - 1, - "%s", _(TXT_OBTAIN_AUTO)); - else - snprintf(mode, STRING_MAX_SIZE - 1, - "%s", _(TXT_ENTER_MAN)); - - btn = util_add_key_value_button(base, NULL, - _(TXT_DNS_SETING), mode); - if (!btn) { - _ERR("Add button failed.\n"); - evas_object_del(box); - return RET_FAILED; - } - - evas_object_smart_callback_add(btn, - SIG_CLICKED, _dns_setting_btn_clicked_cb, priv); - elm_box_pack_end(box, btn); - elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_LEFT); - - priv->dns_mode_btn = btn; - - btn = util_add_key_value_button(base, NULL, - _(TXT_DNS_SERVER), priv->info.dns); - if (!btn) { - _ERR("Add btn failed.\n"); - evas_object_del(box); - return RET_FAILED; - } - - elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_LEFT); - evas_object_smart_callback_add(btn, SIG_CLICKED, - _dns_server_btn_clicked_cb, priv); - elm_object_signal_emit(btn, SIG_HIDE_BOTTOME_LINE, PROG); - elm_box_pack_end(box, btn); - - priv->dns_server_btn = btn; - - if (priv->dns_mode == MODE_AUTO) - _disable_dns_btns(priv); - - return RET_SUCCESS; -} - -/** - * Checks if IP is valid. - * - * Now only check if IP is '0.0.0.0'. - * - * @param[in] priv The handler of the private data - * @return RET_SUCCESS if the operation is successful; - * RET_IP_INVALID if the IP is '0.0.0.0'; RET_FAILED if failed; - */ -static int _check_is_ip_valid(struct _priv *priv) -{ - if (!priv) { - _ERR("The param is NULL.\n"); - return RET_FAILED; - } - - if (!strncmp(priv->info.ip_addr, ZERO_IP, - IP_STRING_MAX_SIZE)) { - _ERR("IP addr is invalid."); - return RET_IP_INVALID; - } - - if (!strncmp(priv->info.submask, ZERO_IP, - IP_STRING_MAX_SIZE)) { - _ERR("submask addr is invalid."); - return RET_IP_INVALID; - } - - if (!strncmp(priv->info.gateway, ZERO_IP, - IP_STRING_MAX_SIZE)) { - _ERR("gateway addr is invalid."); - return RET_IP_INVALID; - } - - if (!strncmp(priv->info.dns, ZERO_IP, - IP_STRING_MAX_SIZE)) { - _ERR("dns addr is invalid."); - return RET_IP_INVALID; - } - - return RET_SUCCESS; -} - -/** - * Shows the invalid IP ctxpopup. - * - * @param[in] priv The handler of the private data - */ -static void _show_invalid_ip_popup(struct _priv *priv) -{ - Evas_Object *layout; - Evas_Object *ok_btn; - Evas_Coord w; - Evas_Coord h; - char content[CONTENT_TXT_SIZE]; - - if (!priv) { - _ERR("The param is NULL.\n"); - return; - } - - if (priv->confirm_popup) - _del_confirm_popup(priv); - - _set_layout_dim(priv); - - layout = util_add_layout(priv->base, UG_NETWORK_EDJ_FILE, - GRP_CONFIRM_LAYOUT); - if (!layout) { - _ERR("add layout failed."); - _unset_layout_dim(priv); - return; - } - - evas_object_show(layout); - - if (priv->network_type == TYPE_WIRED) - elm_object_part_text_set(layout, - PART_TEXT_TITLE, _(TXT_WIRED_LY)); - else - elm_object_part_text_set(layout, - PART_TEXT_TITLE, _(TXT_WIRELESS_LY)); - - memset(content, 0, CONTENT_TXT_SIZE); - snprintf(content, CONTENT_TXT_SIZE - 1, "%s", - _(TXT_INVALID_IP)); - elm_object_part_text_set(layout, - PART_TEXT_CONTENT, content); - - ok_btn = util_add_button(layout, - STYLE_SETTING_BTN, PART_OK_BTN, _(TXT_OK)); - if (!ok_btn) { - _ERR("util add button failed."); - evas_object_del(layout); - _unset_layout_dim(priv); - return; - } - - elm_object_focus_next_object_set(ok_btn, ok_btn, ELM_FOCUS_RIGHT); - elm_object_focus_next_object_set(ok_btn, ok_btn, ELM_FOCUS_LEFT); - elm_object_focus_next_object_set(ok_btn, ok_btn, ELM_FOCUS_UP); - elm_object_focus_next_object_set(ok_btn, ok_btn, ELM_FOCUS_DOWN); - evas_object_smart_callback_add(ok_btn, SIG_CLICKED, - _popup_ok_cancel_btn_clicked_cb, priv); - - elm_object_focus_set(ok_btn, EINA_TRUE); - - elm_object_focus_allow_set(layout, EINA_TRUE); - evas_object_smart_callback_add(layout, SIG_UNFOCUSED, - _ctxpopup_unfocused_cb, priv); - evas_object_event_callback_add(layout, EVAS_CALLBACK_KEY_DOWN, - _ctxpopup_pressed_cb, priv); - - w = DEFAULT_WIN_WIDTH; - h = DEFAULT_WIN_HEIGHT; - - evas_object_move(layout, CENTER_ALIGN * (w - POPUP_WIDTH) * ELM_SCALE, - CENTER_ALIGN * (h - POPUP_HEIGHT) * ELM_SCALE); - - priv->confirm_popup = layout; -} - -/** - * Sets the mode as 'manually'. - * - * Depends on the network type. - * - * @param[in] priv The handler of the private data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -static int _config_network_manually(struct _priv *priv) -{ - int ret; - bool result = false; - - if (!priv) { - _ERR("The param is NULL.\n"); - return RET_FAILED; - } - - ret = _check_is_ip_valid(priv); - if (ret != RET_SUCCESS) { - _ERR("the ip is invalid."); - _show_invalid_ip_popup(priv); - return ret; - } - - _get_connection_profile_info(priv); - - switch (priv->network_type) { - case TYPE_WIRED: - if (!priv->pNetConMgr->SetIpAddr(priv->info.ip_addr)) { - _ERR("set profile failed."); - return ret; - } - if (!priv->pNetConMgr->SetSubnetMask(priv->info.submask)) { - _ERR("set profile failed."); - return ret; - } - if (!priv->pNetConMgr->SetGateway(priv->info.gateway)) { - _ERR("set profile failed."); - return ret; - } - if (!priv->pNetConMgr->SetDNS(priv->info.dns)) { - _ERR("set profile failed."); - return ret; - } - - vconf_set_str(WIRED_IP_KEY, priv->info.ip_addr); - vconf_set_str(WIRED_SUBMASK_KEY, priv->info.submask); - vconf_set_str(WIRED_GATEWAY_KEY, priv->info.gateway); - vconf_set_str(WIRED_DNS_KEY, priv->info.dns); - break; - case TYPE_WIRELESS: - result = priv->pWifiMgr->SetIp(priv->ap, priv->info.ip_addr); - if(result != true) { - _ERR("set wifi dns config failed."); - return RET_FAILED; - } - result = priv->pWifiMgr->SetSubnetMask(priv->ap, priv->info.submask); - if(result != true) { - _ERR("set wifi dns config failed."); - return RET_FAILED; - } - result = priv->pWifiMgr->SetGateway(priv->ap, priv->info.gateway); - if(result != true) { - _ERR("set wifi dns config failed."); - return RET_FAILED; - } - result = priv->pWifiMgr->SetDNS(priv->ap, priv->info.dns); - if(result != true) { - _ERR("set wifi dns config failed."); - return RET_FAILED; - } - - vconf_set_str(WIRELESS_IP_KEY, priv->info.ip_addr); - vconf_set_str(WIRELESS_SUBMASK_KEY, priv->info.submask); - vconf_set_str(WIRELESS_GATEWAY_KEY, priv->info.gateway); - vconf_set_str(WIRELESS_DNS_KEY, priv->info.dns); - break; - default: - break; - } - - return RET_SUCCESS; -} - -/** - * Sets the mode as 'dynamic'. - * - * Depends on the network type. - * - * @param[in] priv The handler of the private data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -static int _config_network_dynamic(struct _priv *priv) -{ - int ret; - bool result = false; - - if (!priv) { - _ERR("The param is NULL.\n"); - return RET_FAILED; - } - - _get_connection_profile_info(priv); - - switch (priv->network_type) { - case TYPE_WIRED: - if(!priv->pNetConMgr->SetIpConfType(CONNECTION_IP_CONFIG_TYPE_DYNAMIC)) { - _ERR("connection_mgr_ip_dynamic_config() failed."); - return RET_FAILED; - } - - break; - case TYPE_WIRELESS: - result = priv->pWifiMgr->SetIpType(priv->ap, WIFI_IP_CONFIG_TYPE_DYNAMIC); - if(result != false) { - _ERR("connection_mgr_ip_dynamic_config() failed."); - return RET_FAILED; - } - - break; - default: - break; - } - - return RET_SUCCESS; -} - -/** - * Saves the mode to vconf. - * - * @param[in] priv The handler of the private data - */ -static void _save_mode(struct _priv *priv) -{ - int ret; - - if (!priv) { - _ERR("The param is NULL.\n"); - return; - } - - switch (priv->network_type) { - case TYPE_WIRED: - if(priv->ip_mode == MODE_AUTO) { - vconf_set_str(WIRED_IP_LAST_MODE, _(TXT_OBTAIN_AUTO)); - } - else if(priv->ip_mode == MODE_MAN) { - vconf_set_str(WIRED_IP_LAST_MODE, _(TXT_ENTER_MAN)); - } - - if(priv->dns_mode == MODE_AUTO) { - vconf_set_str(WIRED_DNS_LAST_MODE, _(TXT_OBTAIN_AUTO)); - } - else if(priv->dns_mode == MODE_MAN) { - vconf_set_str(WIRED_DNS_LAST_MODE, _(TXT_ENTER_MAN)); - } - - break; - case TYPE_WIRELESS: - if(priv->ip_mode == MODE_AUTO) { - vconf_set_str(WIRELESS_IP_LAST_MODE, _(TXT_OBTAIN_AUTO)); - } - else if(priv->ip_mode == MODE_MAN) { - vconf_set_str(WIRELESS_IP_LAST_MODE, _(TXT_ENTER_MAN)); - } - - if(priv->dns_mode == MODE_AUTO) { - vconf_set_str(WIRELESS_DNS_LAST_MODE, _(TXT_OBTAIN_AUTO)); - } - else if(priv->dns_mode == MODE_MAN) { - vconf_set_str(WIRELESS_DNS_LAST_MODE, _(TXT_ENTER_MAN)); - } - - break; - default: - break; - } -} - -/** - * Configs the network mode. - * - * @param[in] priv The handler of the private data - */ -static void _config_network(struct _priv *priv) -{ - int ret; - - if (!priv) { - _ERR("Parameter error!"); - return; - } - - switch (priv->ip_mode) { - case MODE_AUTO: - ret = _config_network_dynamic(priv); - if (ret != RET_SUCCESS) { - _ERR("config network automatically failed."); - goto error; - } - - break; - case MODE_MAN: - ret = _config_network_manually(priv); - if (ret == RET_IP_INVALID) { - _ERR("invalid IP."); - return; - } else if (ret != RET_SUCCESS) { - _ERR("config network manually failed."); - goto error; - } - - break; - default: - goto error; - } - - _save_mode(priv); - - viewmgr_pop(priv->vmgr); - - return; - -error: - _show_confirm_popup(priv); -} - -/** -* @Evas_Smart_Cb type callback for handling clicked event. -* -* When the 'Retry' button is clicked, retry to connect to the network. -* -* @param[in] data User data -* @param[in] obj The corresponding object which the focus event occurred -* @param[in] event Event information -*/ -static void _retry_btn_clicked_cb(void *data, - Evas_Object *obj, void *event) -{ - struct _priv *priv; - - if (!data) { - _ERR("Parameter error!"); - return; - } - - priv = (struct _priv *) data; - - _del_confirm_popup(priv); - - elm_object_focus_set(priv->ok_btn, EINA_TRUE); - - _config_network(priv); -} - -/** - * Shows the confirm ctxpopup. - * - * Decides to connect the network again or cancel it. - * - * @param[in] priv The handler of the private data - */ -static void _show_confirm_popup(struct _priv *priv) -{ - Evas_Object *layout; - Evas_Object *retry_btn, *cancel_btn; - Evas_Coord w; - Evas_Coord h; - char content[CONTENT_TXT_SIZE]; - - if (!priv) { - _ERR("the param is NULL."); - return; - } - - _set_layout_dim(priv); - - layout = util_add_layout(priv->base, UG_NETWORK_EDJ_FILE, - GRP_CONFIRM_LAYOUT); - if (!layout) { - _ERR("add layout failed."); - _unset_layout_dim(priv); - return; - } - - priv->confirm_popup = layout; - - if (priv->network_type == TYPE_WIRED) - elm_object_part_text_set(layout, - PART_TEXT_TITLE, _(TXT_WIRED_LY)); - else - elm_object_part_text_set(layout, - PART_TEXT_TITLE, _(TXT_WIRELESS_LY)); - - memset(content, 0, CONTENT_TXT_SIZE); - snprintf(content, CONTENT_TXT_SIZE - 1, "%s %s", - _(TXT_FAILED_CONNECT), priv->name); - elm_object_part_text_set(layout, - PART_TEXT_CONTENT, content); - - retry_btn = util_add_button(layout, - STYLE_SETTING_BTN, PART_RETRY_BTN, _(TXT_RETRY)); - if (!retry_btn) { - _ERR("util add button failed."); - evas_object_del(layout); - _unset_layout_dim(priv); - return; - } - - cancel_btn = util_add_button(layout, - STYLE_SETTING_BTN, PART_CANCEL_BTN, _(TXT_CANCEL)); - if (!cancel_btn) { - _ERR("util add button failed."); - evas_object_del(layout); - _unset_layout_dim(priv); - return; - } - - elm_object_focus_next_object_set(retry_btn, cancel_btn, - ELM_FOCUS_RIGHT); - elm_object_focus_next_object_set(cancel_btn, retry_btn, - ELM_FOCUS_LEFT); - elm_object_focus_next_object_set(cancel_btn, cancel_btn, - ELM_FOCUS_RIGHT); - elm_object_focus_next_object_set(retry_btn, retry_btn, - ELM_FOCUS_LEFT); - elm_object_focus_next_object_set(cancel_btn, cancel_btn, - ELM_FOCUS_UP); - elm_object_focus_next_object_set(retry_btn, retry_btn, - ELM_FOCUS_UP); - elm_object_focus_next_object_set(cancel_btn, cancel_btn, - ELM_FOCUS_DOWN); - elm_object_focus_next_object_set(retry_btn, retry_btn, - ELM_FOCUS_DOWN); - - evas_object_smart_callback_add(retry_btn, SIG_CLICKED, - _retry_btn_clicked_cb, priv); - evas_object_smart_callback_add(cancel_btn, SIG_CLICKED, - _popup_ok_cancel_btn_clicked_cb, priv); - - elm_object_focus_set(retry_btn, EINA_TRUE); - - elm_object_focus_allow_set(layout, EINA_TRUE); - evas_object_smart_callback_add(layout, SIG_UNFOCUSED, - _ctxpopup_unfocused_cb, priv); - evas_object_event_callback_add(layout, EVAS_CALLBACK_KEY_DOWN, - _ctxpopup_pressed_cb, priv); - - w = DEFAULT_WIN_WIDTH; - h = DEFAULT_WIN_HEIGHT; - - evas_object_move(layout, CENTER_ALIGN * (w - POPUP_WIDTH) * ELM_SCALE, - CENTER_ALIGN * (h - POPUP_HEIGHT) * ELM_SCALE); -} - -/** -* @Evas_Smart_Cb type callback for handling clicked event. -* -* Configs the network. -* -* @param[in] data User data -* @param[in] obj The corresponding object which the focus event occurred -* @param[in] ev Event information -*/ -static void _ok_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) -{ - struct _priv *priv; - - if (!data || !obj) { - _ERR("The param is invalid.\n"); - return; - } - - priv = (struct _priv *) data; - - _config_network(priv); -} - -/** -* @Evas_Smart_Cb type callback for handling clicked event. -* -* Cancels to config the network, and pops the view. -* -* @param[in] data User data -* @param[in] obj The corresponding object which the focus event occurred -* @param[in] ev Event information -*/ -static void _cancel_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) -{ - struct _priv *priv; - - if (!data || !obj) { - _ERR("The param is invalid.\n"); - return; - } - - priv = (struct _priv *) data; - - if (priv && priv->vmgr) - viewmgr_pop(priv->vmgr); -} - -/** - * Creates the action buttons. - * - * @param[in] priv The handler of the private data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -static int _create_btns(struct _priv *priv) -{ - Evas_Object *base; - Evas_Object *ok_btn; - Evas_Object *cancel_btn; - - if (!priv) { - _ERR("The param is invalid.\n"); - return RET_FAILED; - } - - base = priv->base; - - ok_btn = util_add_button(base, STYLE_SETTING_BTN, NULL, _(TXT_OK)); - if (!ok_btn) { - _ERR("Add button failed.\n"); - return RET_FAILED; - } - - elm_object_part_content_set(base, PART_CONNECTION_OK_BTN, ok_btn); - priv->ok_btn = ok_btn; - evas_object_smart_callback_add(ok_btn, SIG_CLICKED, - _ok_btn_clicked_cb, priv); - - cancel_btn = util_add_button(base, STYLE_SETTING_BTN, - PART_CONNECTION_CANCEL_BTN, _(TXT_CANCEL)); - if (!cancel_btn) { - _ERR("Add button failed.\n"); - evas_object_del(ok_btn); - return RET_FAILED; - } - - evas_object_smart_callback_add(cancel_btn, SIG_CLICKED, - _cancel_btn_clicked_cb, priv); - - priv->cancel_btn = cancel_btn; - - return RET_SUCCESS; -} - -/** - * Creates the dim layout. - * - * @param[in] priv The handler of the private data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -static int _create_dim_layout(struct _priv *priv) -{ - Evas_Object *dim_ly; - - if (!priv || !priv->win) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - dim_ly = util_add_layout(priv->win, UG_NETWORK_EDJ_FILE, - GRP_DIM_LY); - if (!dim_ly) { - _ERR("elm_layout_add() failed.\n"); - return RET_FAILED; - } - - priv->dim_ly = dim_ly; - _unset_layout_dim(priv); - - return RET_SUCCESS; -} - -/** - * Callback for key pressed event. - * - * If the key is KEY_BACK, pops the view. - * - * @param[in] data User data - * @param[in] evas Evas handler - * @param[in] obj The corresponding object which the deletion event occurred - * @param[in] ei Event information - */ -static void _base_key_pressed_cb(void *data, Evas *evas, - Evas_Object *obj, void *ei) -{ - Evas_Event_Key_Down *ev; - struct _priv *priv; - - if (!ei || !data) { - _ERR("The param is invalid.\n"); - return; - } - - ev = (Evas_Event_Key_Down *) ei; - priv = (struct _priv *) data; - - if (!ev->keyname) { - _ERR("ev->keyname is NULL."); - return; - } - - if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) { - viewmgr_pop(priv->vmgr); - return; - } -} - -/** - * Creates the layout of the view. - * - * Called when the view is pushed. - * - * @param[in] vmgr The handler of view manager - * @param[in] data The passed data from main view - * @return layout if the operation is successful; NULL if failed; - */ -static Evas_Object *_create(struct viewmgr *vmgr, void *data) -{ - struct _priv *priv; - Evas_Object *base; - struct connection_info *info; - int ret; - - if (!vmgr || !vmgr->win || !vmgr->ug || !data) { - _ERR("Parameter error!"); - return NULL; - } - - priv = _init_priv(); - if (!priv) { - _ERR("init priv failed."); - return NULL; - } - - priv->win = vmgr->win; - priv->ug = vmgr->ug; - priv->vmgr = vmgr; - - priv->pNetConMgr = CNetConMgr::GetInstance(); - ASSERT(priv->pNetConMgr); - - info = (struct connection_info *) data; - priv->network_type = info->cur_type; - priv->ap = info->ap; - strncpy(priv->name, info->name, MAX_NAME_SIZE - 1); - - base = _create_basic_layout(priv->win); - if (!base) { - _ERR("Add main view failed.\n"); - _fini_priv(priv); - return NULL; - } - - evas_object_event_callback_add(base, EVAS_CALLBACK_KEY_DOWN, - _base_key_pressed_cb, priv); - - priv->base = base; - - evas_object_data_set(base, KEY_PRIV, priv); - - _set_description(priv); - - ret = _get_cur_mode(priv); - if (ret != RET_SUCCESS) - goto error; - - ret = _get_cur_ip_info(priv); - if (ret != RET_SUCCESS) - goto error; - - ret = _create_dns_setting(priv); - if (ret != RET_SUCCESS) - goto error; - - ret = _create_btns(priv); - if (ret != RET_SUCCESS) - goto error; - - ret = _create_ip_setting(priv); - if (ret != RET_SUCCESS) - goto error; - - ret = _create_dim_layout(priv); - if (ret != RET_SUCCESS) - goto error; - - return base; - -error: - evas_object_del(base); - _fini_priv(priv); - - return NULL; -} - -/** - * Destroies the layout of the view. - * - * Called when the view is popped. - * - * @param[in] base The base layout - */ -static void _destroy(Evas_Object *base) -{ - struct _priv *priv; - - if (!base) { - _ERR("Parameter error!"); - return; - } - - priv = (struct _priv *) evas_object_data_get(base, KEY_PRIV); - if (!priv) - return; - - _fini_priv(priv); -} - -/** - * Gets the current view type. - * - * @return view type; - */ -static enum view_type _get_view_type(void) -{ - return NETWORK_IP_SETTING_VIEW; -} - -static struct view_class _vclass = { - _create, - NULL, - NULL, - _destroy, - NULL, - _get_view_type, -}; - -/** - * Gets the current view class. - * - * @return view class; - */ -struct view_class *ip_setting_view_vclass_get(void) -{ - return &_vclass; -} -- 2.7.4 From 26d0cb1c3c2192faffd0733c9781476d6921c751 Mon Sep 17 00:00:00 2001 From: JuWan Kim Date: Sat, 28 Mar 2015 07:58:56 +0900 Subject: [PATCH 12/16] UG Network refactoring DONE Change-Id: I71866a2443abc2e038bc33d1b488ab0ab99caaec Signed-off-by: JuWan Kim --- ug/network/CMakeLists.txt | 3 +- ug/network/include/WifiPasscodeView.h | 43 ++ ug/network/include/network_viewmgr.h | 57 -- ug/network/include/wifi_passcode_view.h | 22 - ug/network/src/IpSettingView.cpp | 3 +- ug/network/src/NetworkMainView.cpp | 9 +- ug/network/src/WifiPasscodeView.cpp | 611 ++++++++++++++++++++ ug/network/src/network_viewmgr.cpp | 262 --------- ug/network/src/wifi_mgr.cpp | 615 -------------------- ug/network/src/wifi_passcode_view.cpp | 994 -------------------------------- 10 files changed, 664 insertions(+), 1955 deletions(-) delete mode 100644 ug/network/include/network_viewmgr.h delete mode 100644 ug/network/include/wifi_passcode_view.h delete mode 100644 ug/network/src/network_viewmgr.cpp delete mode 100644 ug/network/src/wifi_mgr.cpp delete mode 100644 ug/network/src/wifi_passcode_view.cpp diff --git a/ug/network/CMakeLists.txt b/ug/network/CMakeLists.txt index 478d1fd..0fac965 100644 --- a/ug/network/CMakeLists.txt +++ b/ug/network/CMakeLists.txt @@ -49,8 +49,7 @@ SET(SRCS src/ug_network_settings.cpp src/NetworkMainView.cpp src/IpSettingView.cpp - src/network_viewmgr.cpp - src/wifi_passcode_view.cpp + src/WifiPasscodeView.cpp src/util.cpp ../src/WifiMgr.cpp ../src/NetConMgr.cpp diff --git a/ug/network/include/WifiPasscodeView.h b/ug/network/include/WifiPasscodeView.h index e69de29..b3746f2 100644 --- a/ug/network/include/WifiPasscodeView.h +++ b/ug/network/include/WifiPasscodeView.h @@ -0,0 +1,43 @@ +#ifndef __WIFI_PASSCODE_VIEW_H__ +#define __WIFI_PASSCODE_VIEW_H__ + +class CWifiPasscodeView : public CBaseView, public IMouseClickedListener, public IUnfocusedListener { +private : + struct SWifiPasscodeView *m; + + static void sm_CbWifiConnected(wifi_error_e err, void *data); + void m_OnWifiConnected(wifi_error_e err); + + static bool sm_CbWifiFoundAP(wifi_ap_h ap, void *data); + void m_OnWifiFoundAP(wifi_ap_h ap); + + static void sm_CbWifiScanRequest(wifi_error_e err, void *data); + void m_OnWifiScanRequest(wifi_error_e err, void *data); + + void m_AddEntry(void); + bool m_CreateDimLayout(void); + void m_ShowInvalidPwdPopup(void); + bool m_WifiConnectAP(void); + void m_ShowProgressPopup(void); + void m_ShowConfirmPopup(void); + +protected : + virtual void t_OnShow(void); + virtual void t_OnUpdate(void *data); + virtual void t_OnHide(void); + +public : + CWifiPasscodeView(const char *szViewId) : CBaseView(szViewId), IMouseClickedListener(this), IUnfocusedListener(this), m(0) {} + virtual ~CWifiPasscodeView() {} + + virtual bool Create(void *data); + virtual void Destroy(void); + virtual Evas_Object* Base(void); + + virtual void OnKeyDown(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev); + virtual void OnMouseClicked(int id, Evas_Object *obj); + virtual void OnUnfocused(int id, Evas_Object *obj, Elm_Object_Item *item); +}; + +#endif /* __WIFI_PASSCODE_VIEW_H__ */ + diff --git a/ug/network/include/network_viewmgr.h b/ug/network/include/network_viewmgr.h deleted file mode 100644 index a39ed47..0000000 --- a/ug/network/include/network_viewmgr.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __NETVIEWMGR_H__ -#define __NETVIEWMGR_H__ - -#include "common.h" -#include -#include - - -enum message_id { - PASSCODE_DEVIVER = 0 -}; - -struct viewmgr { - Eina_List *vlist; - Evas_Object *win; - ui_gadget_h ug; -}; - -struct view_class { - Evas_Object * (*create)(struct viewmgr *vmgr, void *data); - void (*pause)(Evas_Object *base); - void (*resume)(Evas_Object *base); - void (*terminate)(Evas_Object *base); - void (*message_handler)(Evas_Object *base, - enum message_id msg_id, void *data); - enum view_type (*get_view_type)(void); -}; - -struct viewmgr *viewmgr_init(); -void viewmgr_fini(struct viewmgr *vmgr); -Evas_Object *viewmgr_push(struct viewmgr *vmgr, - struct view_class *vclass, void *data); -int viewmgr_send_message(struct viewmgr *vmgr, - enum view_type view_type, - enum message_id msg_id, void *data); -int viewmgr_pop(struct viewmgr *vmgr); -int viewmgr_resume(struct viewmgr *vmgr); -Evas_Object *viewmgr_win_get(struct viewmgr *vmgr); - -#endif /* __VIEWMGR_H__ */ - diff --git a/ug/network/include/wifi_passcode_view.h b/ug/network/include/wifi_passcode_view.h deleted file mode 100644 index 525135c..0000000 --- a/ug/network/include/wifi_passcode_view.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __WIFI_PASSWORD_VIEW_H__ -#define __WIFI_PASSWORD_VIEW_H__ - -struct view_class *wifi_passcode_view_vclass_get(void); - -#endif /* __WIFI_PASSWORD_VIEW_H__ */ diff --git a/ug/network/src/IpSettingView.cpp b/ug/network/src/IpSettingView.cpp index 4ff7476..202fcd1 100644 --- a/ug/network/src/IpSettingView.cpp +++ b/ug/network/src/IpSettingView.cpp @@ -1652,7 +1652,8 @@ void CIpSettingView::OnMouseClicked(int id, Evas_Object *obj) } } -void CIpSettingView::OnUnfocused(int id, Evas_Object *obj, Elm_Object_Item *item){ +void CIpSettingView::OnUnfocused(int id, Evas_Object *obj, Elm_Object_Item *item) +{ /* ID list */ /* 0 m->base */ /* 1 m->dns_mode_btn */ diff --git a/ug/network/src/NetworkMainView.cpp b/ug/network/src/NetworkMainView.cpp index d7f63b4..6b5e9b0 100644 --- a/ug/network/src/NetworkMainView.cpp +++ b/ug/network/src/NetworkMainView.cpp @@ -5,7 +5,6 @@ #include "defs.h" #include "i18n.h" #include "common.h" -#include "wifi_passcode_view.h" #include #include #include "WifiMgr.h" @@ -63,7 +62,7 @@ struct SNetworkMainView { SNetworkMainView() { pHandlerBase = new CHandlerBase(this); - pHandlerTypeButton= new CHandlerTypeButton(this); + pHandlerTypeButton = new CHandlerTypeButton(this); pHandlerPopupButton = new CHandlerPopupButton(this); pHandlerWiredConBox = new CHandlerWiredConBox(this); pHandlerActionBtns = new CHandlerActionBtns(this); @@ -473,6 +472,12 @@ bool CNetworkMainView::sm_CbWifiFoundAP(wifi_ap_h ap, void *data) { _DBG(); CNetworkMainView *instance = NULL; + + if (!data) { + _ERR("data is NULL."); + return true; + } + instance = (CNetworkMainView *) data; instance->m_OnWifiFoundAP(ap); return true; diff --git a/ug/network/src/WifiPasscodeView.cpp b/ug/network/src/WifiPasscodeView.cpp index e69de29..bfeb80f 100644 --- a/ug/network/src/WifiPasscodeView.cpp +++ b/ug/network/src/WifiPasscodeView.cpp @@ -0,0 +1,611 @@ +#include +#include +#include +#include +#include "defs.h" +#include "dbg.h" +#include "i18n.h" +#include "util.h" +#include "common.h" +#include "util.h" + +#include +#include +#include "BaseView.h" +#include "ViewMgr.h" + +#include "WifiMgr.h" +#include "WifiPasscodeView.h" + +#define KEY_PRIV "priv" +#define KEY_NETWORK_ENTER "Select" + +#define AP_NAME_LENTH 256 + +#define TXT_PASSCODE "Network passcode" +#define TXT_ENTER_PASSCODE "Enter the network password" + +#define STYLE_ENTRY_FOCUS "focus" +#define STYLE_ENTRY_TXT "DEFAULT='font_size=30 linesize=40'" + +struct SWifiPasscodeView { + ui_gadget_h ug; + + Evas_Object *win; + Evas_Object *base; + Evas_Object *entry; + Evas_Object *dim_ly; + Evas_Object *ctxpopup; + char ap_name[AP_NAME_LENTH + 1]; + char *ap_pwd; + + CWifiMgr *pWifiMgr; + CViewMgr *pViewMgr; +}; + + +void CWifiPasscodeView::sm_CbWifiConnected(wifi_error_e err, void *data) +{ + _DBG(); + CWifiPasscodeView *instance; + + if (!data) { + _ERR("Parameter error!"); + return; + } + + instance = (CWifiPasscodeView *) data; + instance->m_OnWifiConnected(err); +} + + +void CWifiPasscodeView::m_OnWifiConnected(wifi_error_e err) +{ + if (!m->ctxpopup) + return; + + if (err!= WIFI_ERROR_NONE) { + _ERR("connect AP failed, ret: %s.", m->pWifiMgr->GetErrorMsg(err)); + m_ShowConfirmPopup(); + return; + } + + ug_destroy_me(m->ug); +} + + +bool CWifiPasscodeView::sm_CbWifiFoundAP(wifi_ap_h ap, void *data) +{ + _DBG(); + CWifiPasscodeView *instance = NULL; + + if (!data) { + _ERR("data is NULL."); + return false; + } + + instance = (CWifiPasscodeView *) data; + instance->m_OnWifiFoundAP(ap); + return true; +} + + +void CWifiPasscodeView::m_OnWifiFoundAP(wifi_ap_h ap) +{ + bool ret; + struct wifi_ap_info ap_info; + + if (!ap) { + _ERR("Parameter error!"); + return ; + } + + ret = m->pWifiMgr->GetESSID(ap, ap_info.essid); + if(ret != true) { + _ERR("Fail to get info"); + return ; + } + ret = m->pWifiMgr->GetConnectionState(ap, &ap_info.state); + if(ret != true) { + _ERR("Fail to get info"); + return ; + } + ret = m->pWifiMgr->GetSecurityType(ap, &ap_info.secure_type); + if(ret != true) { + _ERR("Fail to get info"); + return ; + } + + if (!strncmp(m->ap_name, ap_info.essid, AP_NAME_LENTH)) { + ret = m->pWifiMgr->SetPassPhrase(ap, m->ap_pwd); + if (ret != true) { + _ERR("wifi_mgr_set_passphrase() failed."); + m_ShowConfirmPopup(); + return ; + } + + ret = m->pWifiMgr->Connect(ap, sm_CbWifiConnected, this); + if (ret != true) { + _ERR("Fail to connection request."); + m_ShowConfirmPopup(); + return ; + } + } + return ; +} + + +void CWifiPasscodeView::sm_CbWifiScanRequest(wifi_error_e err, void *data) +{ + CWifiPasscodeView *instance; + + if (!data) { + _ERR("data is NULL."); + return; + } + + instance = (CWifiPasscodeView *) data; + instance->m_OnWifiScanRequest(err, data); +} + + +void CWifiPasscodeView::m_OnWifiScanRequest(wifi_error_e err, void *data) +{ + if(err != WIFI_ERROR_NONE) + _ERR("parameter error = %s", m->pWifiMgr->GetErrorMsg(err)); + + if(!m->pWifiMgr->RegisterFoundAPCallback(sm_CbWifiFoundAP, data)) { + _ERR("wifi_mgr_foreach_found_aps() failed."); + m_ShowConfirmPopup(); + return; + } +} + + +void CWifiPasscodeView::m_AddEntry(void) +{ + Evas_Object *entry; + + entry = util_add_entry(m->base, STYLE_ENTRY_FOCUS, PART_WIFI_PASSCODE_ENTRY); + if (!entry) { + _ERR("util_add_entry failed."); + evas_object_del(m->base); + return; + } + + elm_entry_password_set(entry, EINA_TRUE); + elm_entry_text_style_user_push(entry, STYLE_ENTRY_TXT); + + //evas_object_event_callback_add(entry, EVAS_CALLBACK_KEY_DOWN, _entry_key_press_cb, priv); + Connect(entry, 1); + + elm_entry_input_panel_enabled_set(entry, EINA_TRUE); + + elm_object_focus_next_object_set(entry, entry, ELM_FOCUS_UP); + elm_object_focus_next_object_set(entry, entry, ELM_FOCUS_LEFT); + + elm_object_focus_set(entry, EINA_TRUE); + + m->entry = entry; +} + + +bool CWifiPasscodeView::m_CreateDimLayout(void) +{ + Evas_Object *dim_ly; + + dim_ly = util_add_layout(m->win, UG_NETWORK_EDJ_FILE, GRP_DIM_LY); + if (!dim_ly) { + _ERR("elm_layout_add() failed."); + return false; + } + + m->dim_ly = dim_ly; + evas_object_hide(m->dim_ly); + + return true; +} + + +void CWifiPasscodeView::m_ShowInvalidPwdPopup(void) +{ + Evas_Object *layout; + Evas_Object *ok_btn; + Evas_Coord w; + Evas_Coord h; + char content[CONTENT_TXT_SIZE]; + + if (m->ctxpopup) { + evas_object_del(m->ctxpopup); + m->ctxpopup = NULL; + } + + evas_object_show(m->dim_ly); + + layout = util_add_layout(m->base, UG_NETWORK_EDJ_FILE, GRP_CONFIRM_LAYOUT); + if (!layout) { + _ERR("add layout failed."); + evas_object_hide(m->dim_ly); + return; + } + + elm_object_part_text_set(layout, PART_TEXT_TITLE, _(TXT_WIRELESS_LY)); + + memset(content, 0, CONTENT_TXT_SIZE); + snprintf(content, CONTENT_TXT_SIZE - 1, "%s", _(TXT_INVALID_PWD)); + elm_object_part_text_set(layout, PART_TEXT_CONTENT, content); + + ok_btn = util_add_button(layout, STYLE_SETTING_BTN, PART_OK_BTN, _(TXT_OK)); + if (!ok_btn) { + _ERR("util add button failed."); + evas_object_del(layout); + evas_object_hide(m->dim_ly); + return; + } + + elm_object_focus_next_object_set(ok_btn, ok_btn, ELM_FOCUS_RIGHT); + elm_object_focus_next_object_set(ok_btn, ok_btn, ELM_FOCUS_LEFT); + elm_object_focus_next_object_set(ok_btn, ok_btn, ELM_FOCUS_UP); + elm_object_focus_next_object_set(ok_btn, ok_btn, ELM_FOCUS_DOWN); + //evas_object_smart_callback_add(ok_btn, SIG_CLICKED, _popup_ok_btn_clicked_cb, priv); + Connect(ok_btn, 2); + + elm_object_focus_set(ok_btn, EINA_TRUE); + + elm_object_focus_allow_set(layout, EINA_TRUE); + //evas_object_smart_callback_add(layout, SIG_UNFOCUSED, _ctxpopup_unfocused_cb, priv); + //evas_object_event_callback_add(layout, EVAS_CALLBACK_KEY_DOWN, _ctxpopup_pressed_cb, priv); + Connect(layout, 3); + + + w = DEFAULT_WIN_WIDTH; + h = DEFAULT_WIN_HEIGHT; + + evas_object_move(layout, CENTER_ALIGN * (w - POPUP_WIDTH) * ELM_SCALE, CENTER_ALIGN * (h - POPUP_HEIGHT) * ELM_SCALE); + + m->ctxpopup = layout; +} + + +bool CWifiPasscodeView::m_WifiConnectAP(void) +{ + bool ret; + + m_ShowProgressPopup(); + + ret = m->pWifiMgr->ForgetAP(); + if (ret != true) { + _ERR("forget last ap failed."); + return false; + } + + ret = m->pWifiMgr->RegisterScanCallback(sm_CbWifiScanRequest, this); + if (ret != true) { + _ERR("wifi_mgr_scan_request() failed."); + return false; + } + + return true; +} + + +void CWifiPasscodeView::m_ShowProgressPopup(void) +{ + Evas_Object *layout; + Evas_Object *cancel_btn; + Evas_Coord w; + Evas_Coord h; + char content[CONTENT_TXT_SIZE]; + + if (m->ctxpopup) { + evas_object_del(m->ctxpopup); + m->ctxpopup = NULL; + } + + evas_object_show(m->dim_ly); + + layout = util_add_layout(m->base, UG_NETWORK_EDJ_FILE, GRP_PROCESSING_LAYOUT); + if (!layout) { + _ERR("add layout failed."); + evas_object_hide(m->dim_ly); + return; + } + + memset(content, 0, CONTENT_TXT_SIZE); + elm_object_part_text_set(layout, PART_TEXT_TITLE, _(TXT_WIRELESS_LY)); + snprintf(content, CONTENT_TXT_SIZE - 1, "%s %s", _(TXT_CONNECTTING), m->ap_name); + elm_object_part_text_set(layout, PART_TEXT_CONTENT, content); + + cancel_btn = util_add_button(layout, STYLE_SETTING_BTN, PART_CANCEL_BTN, _(TXT_CANCEL)); + if (!cancel_btn) { + _ERR("util add button failed."); + evas_object_del(layout); + evas_object_hide(m->dim_ly); + return; + } + + elm_object_focus_next_object_set(cancel_btn, cancel_btn, ELM_FOCUS_LEFT); + elm_object_focus_next_object_set(cancel_btn, cancel_btn, ELM_FOCUS_RIGHT); + elm_object_focus_next_object_set(cancel_btn, cancel_btn, ELM_FOCUS_UP); + elm_object_focus_next_object_set(cancel_btn, cancel_btn, ELM_FOCUS_DOWN); + + //evas_object_smart_callback_add(cancel_btn, SIG_CLICKED, _cancel_btn_clicked_cb, priv); + Connect(cancel_btn, 4); + + elm_object_focus_set(cancel_btn, EINA_TRUE); + + elm_object_focus_allow_set(layout, EINA_TRUE); + //evas_object_smart_callback_add(layout, SIG_UNFOCUSED, _ctxpopup_unfocused_cb, priv); + //evas_object_event_callback_add(layout, EVAS_CALLBACK_KEY_DOWN, _ctxpopup_pressed_cb, priv); + Connect(layout, 5); + + w = DEFAULT_WIN_WIDTH; + h = DEFAULT_WIN_HEIGHT; + + evas_object_move(layout, CENTER_ALIGN * (w - POPUP_WIDTH) * ELM_SCALE, CENTER_ALIGN * (h - POPUP_HEIGHT) * ELM_SCALE); + + m->ctxpopup = layout; +} + + +void CWifiPasscodeView::m_ShowConfirmPopup(void) +{ + Evas_Object *layout; + Evas_Object *retry_btn; + Evas_Object *cancel_btn; + Evas_Coord w; + Evas_Coord h; + char content[CONTENT_TXT_SIZE]; + + if (m->ctxpopup) { + evas_object_del(m->ctxpopup); + m->ctxpopup = NULL; + } + + evas_object_show(m->dim_ly); + + layout = util_add_layout(m->base, UG_NETWORK_EDJ_FILE, GRP_CONFIRM_LAYOUT); + if (!layout) { + _ERR("add layout failed."); + evas_object_hide(m->dim_ly); + return; + } + + memset(content, 0, CONTENT_TXT_SIZE); + elm_object_part_text_set(layout, PART_TEXT_TITLE, _(TXT_WIRELESS_LY)); + snprintf(content, CONTENT_TXT_SIZE - 1, "%s %s", _(TXT_FAILED_CONNECT), m->ap_name); + + elm_object_part_text_set(layout, PART_TEXT_CONTENT, content); + + retry_btn = util_add_button(layout, STYLE_SETTING_BTN, PART_RETRY_BTN, _(TXT_RETRY)); + if (!retry_btn) { + _ERR("util add button failed."); + evas_object_del(layout); + evas_object_hide(m->dim_ly); + return; + } + + cancel_btn = util_add_button(layout, STYLE_SETTING_BTN, PART_CANCEL_BTN, _(TXT_CANCEL)); + if (!cancel_btn) { + _ERR("util add button failed."); + evas_object_del(layout); + evas_object_hide(m->dim_ly); + return; + } + + elm_object_focus_next_object_set(retry_btn, cancel_btn, ELM_FOCUS_RIGHT); + elm_object_focus_next_object_set(cancel_btn, retry_btn, ELM_FOCUS_LEFT); + elm_object_focus_next_object_set(cancel_btn, cancel_btn, ELM_FOCUS_RIGHT); + elm_object_focus_next_object_set(retry_btn, retry_btn, ELM_FOCUS_LEFT); + elm_object_focus_next_object_set(cancel_btn, cancel_btn, ELM_FOCUS_UP); + elm_object_focus_next_object_set(retry_btn, retry_btn, ELM_FOCUS_UP); + elm_object_focus_next_object_set(cancel_btn, cancel_btn, ELM_FOCUS_DOWN); + elm_object_focus_next_object_set(retry_btn, retry_btn, ELM_FOCUS_DOWN); + + //evas_object_smart_callback_add(retry_btn, SIG_CLICKED, _retry_btn_clicked_cb, priv); + Connect(retry_btn, 6); + //evas_object_smart_callback_add(cancel_btn, SIG_CLICKED, _cancel_btn_clicked_cb, priv); + Connect(cancel_btn, 7); + + elm_object_focus_set(retry_btn, EINA_TRUE); + + elm_object_focus_allow_set(layout, EINA_TRUE); + //evas_object_smart_callback_add(layout, SIG_UNFOCUSED, _ctxpopup_unfocused_cb, priv); + //evas_object_event_callback_add(layout, EVAS_CALLBACK_KEY_DOWN, _ctxpopup_pressed_cb, priv); + Connect(layout, 8); + + w = DEFAULT_WIN_WIDTH; + h = DEFAULT_WIN_HEIGHT; + + evas_object_move(layout, CENTER_ALIGN * (w - POPUP_WIDTH) * ELM_SCALE, CENTER_ALIGN * (h - POPUP_HEIGHT) * ELM_SCALE); + + m->ctxpopup = layout; +} + + +bool CWifiPasscodeView::Create(void *data) +{ + _DBG(); + ASSERT(!m); + struct wifi_ap_info *ap_info = NULL; + + if(data) + ap_info = (struct wifi_ap_info *) data; + + _CREATE_BEGIN{ + _CHECK(m = new SWifiPasscodeView) + _CHECK(m->win = CViewMgr::GetInstance()->Window()) +// _CHECK(m->ug = (ui_gadget_h) data) + _CHECK(m->base = util_add_layout(m->win, UG_NETWORK_EDJ_FILE, GRP_WIFI_PASSCODE_BASE)) + _COMMAND { + CWifiMgr::Initialize(); + strncpy(m->ap_name, ap_info->essid, AP_NAME_LENTH); + } + _CHECK(m->pWifiMgr = CWifiMgr::GetInstance()) + + _WHEN_SUCCESS{ + //evas_object_event_callback_add(base, EVAS_CALLBACK_KEY_DOWN, _base_key_press_cb, priv); + Connect(m->base, 0); + + elm_object_part_text_set(m->base, PART_WIFI_PASSCODE_TITLE, _(TXT_PASSCODE)); + elm_object_part_text_set(m->base, PART_WIFI_PASSCODE_TEXT, _(TXT_ENTER_PASSCODE)); + elm_object_part_text_set(m->base, PART_WIFI_PASSCODE_AP_NAME, m->ap_name); + + m_AddEntry(); + m_CreateDimLayout(); + m->pViewMgr = CViewMgr::GetInstance(); + } + + _CHECK_FAIL{ /*m->pWifiMgr = CWifiMgr::GetInstance() */ } + _CHECK_FAIL{ evas_object_del(m->base); } +// _CHECK_FAIL{ /* m->ug = (ui_gadget_h) data */ } + _CHECK_FAIL{ /* m->win = CViewMgr::GetInstance()->Window() */ } + _CHECK_FAIL{ delete m; m = NULL; } + } _CREATE_END_AND_CATCH{ return false; } + + return true; +} + + +void CWifiPasscodeView::Destroy(void) +{ + ASSERT(m); + _DBG(); + + if (m->dim_ly) + evas_object_del(m->dim_ly); + + if(m->ap_pwd) + delete (m->ap_pwd); + + CBaseView::Destroy(); + delete m; + m = NULL; +} + + +Evas_Object* CWifiPasscodeView::Base(void) +{ + ASSERT(m); + _DBG(); + + return m->base; +} + + +void CWifiPasscodeView::OnKeyDown(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev) +{ + /* ID list */ + /* 0 m->base */ + /* 1 entry */ + /* 2 invalidpwdpopup ok_btn */ + /* 3 invalidpwdpopup layout */ + /* 4 showprogresspopup cancel_btn */ + /* 5 showprogresspopup layout */ + /* 6 showconfirmpopup retry_btn */ + /* 7 showconfirmpopup cancel_btn */ + /* 8 showconfirmpopup layout */ + + if (!ev->keyname) { + _ERR("ev->keyname is NULL."); + return; + } + + switch(id) { + case 0: +#if 0 + if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) + viewmgr_pop(m->vmgr); +#endif + break; + case 1: + if (!strcmp(ev->keyname, KEY_NETWORK_ENTER)) { + if (m->ap_pwd) { + free(m->ap_pwd); + m->ap_pwd = NULL; + } + + m->ap_pwd = strdup(elm_entry_entry_get(obj)); + if (!m->ap_pwd) { + _ERR("the passcode in entry is NULL."); + m_ShowInvalidPwdPopup(); + return; + } + + if(m_WifiConnectAP()) { + _ERR("connect ap"); + m_ShowConfirmPopup(); + return; + } + } + break; + case 3: + case 5: + case 8: + if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) { + evas_object_hide(m->dim_ly); + evas_object_del(obj); + elm_object_focus_set(m->entry, EINA_TRUE); + } + break; + default: + break; + } +} + + +void CWifiPasscodeView::OnMouseClicked(int id, Evas_Object *obj) +{ + switch(id) { + case 2: + if (m->ctxpopup) { + evas_object_del(m->ctxpopup); + m->ctxpopup = NULL; + } + elm_object_focus_set(m->entry, EINA_TRUE); + break; + case 4: + case 7: + if (m->ctxpopup) { + evas_object_del(m->ctxpopup); + m->ctxpopup = NULL; + } + + evas_object_hide(m->dim_ly); + + elm_object_focus_set(m->entry, EINA_TRUE); + break; + case 6: + if (m->ctxpopup) { + evas_object_del(m->ctxpopup); + m->ctxpopup = NULL; + } + + evas_object_hide(m->dim_ly); + + if(!m_WifiConnectAP()) { + _ERR("connect ap"); + m_ShowConfirmPopup(); + return; + } + break; + default: + break; + } +} + +void CWifiPasscodeView::OnUnfocused(int id, Evas_Object *obj, Elm_Object_Item *item) +{ + switch(id) { + case 3: + case 5: + case 8: + evas_object_hide(m->dim_ly); + evas_object_del(obj); + break; + default: + break; + } + + +} diff --git a/ug/network/src/network_viewmgr.cpp b/ug/network/src/network_viewmgr.cpp deleted file mode 100644 index 6534a2a..0000000 --- a/ug/network/src/network_viewmgr.cpp +++ /dev/null @@ -1,262 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include "network_viewmgr.h" -#include "defs.h" -#include "dbg.h" - -struct _viewinfo { - struct view_class *vclass; - Evas_Object *base; - enum view_type view_type; -}; - -/** - * Create and initialize the view manager. - * - * Called when app is created. - * - * @return View manager object - */ -struct viewmgr *viewmgr_init() -{ - struct viewmgr *vmgr; - - vmgr = (struct viewmgr *) calloc(1, sizeof(*vmgr)); - if (!vmgr) { - _ERR("calloc vmgr failed."); - return NULL; - } - - return vmgr; -} - -/** - * Finalize the view manager. - * - * Called when app is about to destroyed. - * - * @param[in] vmgr View manager object - */ -void viewmgr_fini(struct viewmgr *vmgr) -{ - int i; - - if (!vmgr) - return; - - for (i = eina_list_count(vmgr->vlist); i > 0; i--) - viewmgr_pop(vmgr); - - free(vmgr); -} - -/** - * Callback function for the view deleted event. - * - * Called when the view is deleted. - * - * @param[in] data The pointer to view class object - * @param[in] e The pointer of the evas canvas - * @param[in] obj The object that is deleted - * @param[in] ev The pointer of event info - */ -static void _view_deleted(void *data, Evas *e, Evas_Object *obj, void *ev) -{ - struct view_class *vclass; - - if (!data || !obj) - return; - - vclass = (struct view_class *) data; - if (vclass->terminate) - vclass->terminate(obj); -} - -/** - * Push a view to the view manager. - * - * Called when one new view is to be pushed. - * - * @param[in] vmgr View manager object - * @param[in] vclass The specific view class for the view to be pushed - * @param[in] data User data - * @return base if the view is created successfully; NULL if failed; - */ -Evas_Object *viewmgr_push(struct viewmgr *vmgr, - struct view_class *vclass, void *data) -{ - struct _viewinfo *vinfo, *vinfo_pre; - Evas_Object *base; - - if (!vmgr || !vmgr->win || !vclass || !vclass->create) - return NULL; - - vinfo = (struct _viewinfo *) calloc(1, sizeof(*vinfo)); - if (!vinfo) - return NULL; - - base = vclass->create(vmgr, data); - if (!base) { - free(vinfo); - return NULL; - } - evas_object_event_callback_add(base, EVAS_CALLBACK_DEL, - _view_deleted, vclass); - - vinfo->base = base; - vinfo->vclass = vclass; - vinfo->view_type = vclass->get_view_type(); - - vinfo_pre = (struct _viewinfo *) eina_list_data_get(vmgr->vlist); - if (vinfo_pre && vinfo_pre->base - && vinfo_pre->vclass->pause) - vinfo_pre->vclass->pause(vinfo_pre->base); - - vmgr->vlist = eina_list_prepend(vmgr->vlist, vinfo); - - return base; -} - -/** - * Send a message between the views. - * - * Called when there is the information to pass. - * - * @param[in] vmgr View manager object - * @param[in] view_type The view type - * @param[in] msg_id Message ID - * @param[in] data User data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int viewmgr_send_message(struct viewmgr *vmgr, - enum view_type view_type, - enum message_id msg_id, void *data) -{ - struct _viewinfo *vinfo; - void *obj; - struct view_class *vclass; - Eina_List *list, *list_next; - - if (!vmgr) { - _ERR("vmgr is NULL."); - return RET_FAILED; - } - - EINA_LIST_FOREACH_SAFE(vmgr->vlist, list, list_next, obj) { - vinfo = (struct _viewinfo *) obj; - - if (!vinfo) { - _ERR("vinfo is NULL."); - continue; - } - - vclass = vinfo->vclass; - - if (vinfo->view_type == view_type) { - if (vclass && vclass->message_handler) - vclass->message_handler(vinfo->base, - msg_id, data); - - /*only support single message now, so break.*/ - break; - } - } - - return RET_SUCCESS; -} - -/** - * Pop a view from the view manager. - * - * Called when the top view is to be poped. - * - * @param[in] vmgr View manager object - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int viewmgr_pop(struct viewmgr *vmgr) -{ - struct _viewinfo *vinfo; - - if (!vmgr || !vmgr->vlist) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - vinfo = (struct _viewinfo *) eina_list_data_get(vmgr->vlist); - if (!vinfo) { - _ERR("eina_list_data_get() failed."); - return RET_FAILED; - } - - vmgr->vlist = eina_list_remove_list(vmgr->vlist, vmgr->vlist); - viewmgr_resume(vmgr); - - evas_object_del(vinfo->base); - - free(vinfo); - - return RET_SUCCESS; -} - -/** - * Resume a view with the view manager. - * - * When the top view is poped, and the next view has some - * specific state to be show, the function is called. - * - * @param[in] vmgr View manager object - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int viewmgr_resume(struct viewmgr *vmgr) -{ - struct _viewinfo *vinfo; - struct view_class *vclass; - - if (!vmgr || !vmgr->vlist) { - _ERR("param is invalid."); - return RET_FAILED; - } - - vinfo = (struct _viewinfo *) eina_list_data_get(vmgr->vlist); - if (!vinfo || !vinfo->vclass || !vinfo->base) { - _ERR("vinfo, vinfo->vclass, or vinfo->base is NULL."); - return RET_FAILED; - } - - vclass = vinfo->vclass; - if (vclass->resume) - vclass->resume(vinfo->base); - - return RET_SUCCESS; -} - -/** - * Get the pointer of window. - * - * @param[in] vmgr View manager object - * @return win if the operation is successful; NULL if failed; - */ -Evas_Object *viewmgr_win_get(struct viewmgr *vmgr) -{ - if (!vmgr) - return NULL; - - return vmgr->win; -} diff --git a/ug/network/src/wifi_mgr.cpp b/ug/network/src/wifi_mgr.cpp deleted file mode 100644 index d7b6aaa..0000000 --- a/ug/network/src/wifi_mgr.cpp +++ /dev/null @@ -1,615 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "defs.h" -#include "dbg.h" -#include "wifi_mgr.h" - -/** - * Converts the error type to string information. - * - * @param[in] err_type Error type - * @return error string information; - */ -const char *wifi_mgr_error_dbg(wifi_error_e err_type) -{ - switch (err_type) { - case WIFI_ERROR_NONE: - return "NONE"; - case WIFI_ERROR_INVALID_PARAMETER: - return "INVALID_PARAMETER"; - case WIFI_ERROR_OUT_OF_MEMORY: - return "OUT_OF_MEMORY"; - case WIFI_ERROR_INVALID_OPERATION: - return "INVALID_OPERATION"; - case WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED: - return "ADDRESS_FAMILY_NOT_SUPPORTED"; - case WIFI_ERROR_OPERATION_FAILED: - return "OPERATION_FAILED"; - case WIFI_ERROR_NO_CONNECTION: - return "NO_CONNECTION"; - case WIFI_ERROR_NOW_IN_PROGRESS: - return "NOW_IN_PROGRESS"; - case WIFI_ERROR_ALREADY_EXISTS: - return "ALREADY_EXISTS"; - case WIFI_ERROR_OPERATION_ABORTED: - return "OPERATION_ABORTED"; - case WIFI_ERROR_DHCP_FAILED: - return "DHCP_FAILED"; - case WIFI_ERROR_INVALID_KEY: - return "INVALID_KEY"; - case WIFI_ERROR_NO_REPLY: - return "NO_REPLY"; - case WIFI_ERROR_SECURITY_RESTRICTED: - return "SECURITY_RESTRICTED"; - default: - break; - } - - return "UNKNOWN"; -} - -/** - * Initializes Wi-Fi. - * - * Called before using wifi APIs. - * - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int wifi_mgr_init(void) -{ - int ret; - - ret = wifi_initialize(); - if (ret != WIFI_ERROR_NONE) { - _ERR("Fail to wifi_initialize.\n"); - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Deinitializes Wi-Fi. - * - * Called when network setting is destroyed. - * - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int wifi_mgr_deinit(void) -{ - int ret; - - ret = wifi_deinitialize(); - if (ret != WIFI_ERROR_NONE) { - _ERR("Fail to wifi_deinitialize.\n"); - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Checks whether Wi-Fi is activated. - * - * @param[out] activated The activated value of wifi - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int wifi_mgr_is_activated(bool *activated) -{ - int ret; - - ret = wifi_is_activated(activated); - if (ret != WIFI_ERROR_NONE) { - _ERR("Fail to wifi_is_activated %s\n", - wifi_mgr_error_dbg((wifi_error_e) ret)); - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Starts scan, asynchronously. - * - * Called if you want to get the ap list. - * - * @param[in] cb The callback function to be called - * @param[in] data User data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int wifi_mgr_scan_request(wifi_scan_finished_cb cb, void *data) -{ - int ret; - - if (!cb || !data) { - _ERR("null pointer"); - return RET_FAILED; - } - - ret = wifi_scan(cb, data); - if (ret != WIFI_ERROR_NONE) { - _ERR("Scan request failed [%s]\n", - wifi_mgr_error_dbg((wifi_error_e) ret)); - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Gets the result of scan. - * - * Called in the callback of wifi_scan(). - * - * @param[in] cb The callback function to be called - * @param[in] data User data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int wifi_mgr_foreach_found_aps(wifi_found_ap_cb cb, void *data) -{ - int ret; - - if (!cb || !data) { - _ERR("null pointer"); - return RET_FAILED; - } - - ret = wifi_foreach_found_aps(cb, data); - if (ret != WIFI_ERROR_NONE) { - _ERR("Fail to get AP list %s.\n", wifi_mgr_error_dbg((wifi_error_e) ret)); - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Activates Wi-Fi, asynchronously. - * - * If the wireless adaptor is not activated, you should activate it first. - * - * @param[in] cb The callback function to be called - * @param[in] data User data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int wifi_mgr_activate(wifi_activated_cb cb, void *data) -{ - int ret; - - if (!cb || !data) { - _ERR("null pointer"); - return RET_FAILED; - } - - ret = wifi_activate(cb, data); - if (ret != WIFI_ERROR_NONE) { - _ERR("Fail to wifi_activate %s\n", - wifi_mgr_error_dbg((wifi_error_e) ret)); - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Gets the handle of connected access point. - * - * You can get the connected access point and its configuration. - * - * @param[out] ap The handle of access point - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int wifi_mgr_get_connected_ap(wifi_ap_h *ap) -{ - int ret; - - if (!ap) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - ret = wifi_get_connected_ap(ap); - if (ret != WIFI_ERROR_NONE) { - _ERR("wifi_get_connected_ap() failed."); - return ret; - } - - return RET_SUCCESS; -} - -/** - * Destroys the handle of access point. - * - * when you cloned an ap and don't use it later, you should destroy it. - * - * @param[in] ap The handle of access point - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int wifi_mgr_ap_destroy(wifi_ap_h ap) -{ - int ret; - - if (!ap) { - _ERR("the ap is already NULL."); - return RET_SUCCESS; - } - - ret = wifi_ap_destroy(ap); - if (ret != WIFI_ERROR_NONE) - ret = RET_FAILED; - else - ret = RET_SUCCESS; - - return ret; -} - -/** - * Clones the handle of access point. - * - * Copy the data of an ap. - * - * @param[out] cloned_ap The handle of access point to clone - * @param[in] origin The handle of access point to be cloned - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int wifi_mgr_ap_clone(wifi_ap_h *cloned_ap, wifi_ap_h origin) -{ - int ret; - - if (!cloned_ap || !origin) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - ret = wifi_ap_clone(cloned_ap, origin); - if (ret != WIFI_ERROR_NONE) - ret = RET_FAILED; - else - ret = RET_SUCCESS; - - return ret; -} - -/** - * Gets the data of access point. - * - * @param[in] ap The handle of access point - * @param[out] ap_info The structue to store the data of access point - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int wifi_mgr_get_ap_info(wifi_ap_h ap, struct wifi_ap_info *ap_info) -{ - char *str; - - if (!ap || !ap_info) { - _ERR("null pointer"); - return RET_FAILED; - } - - str = NULL; - if (wifi_ap_get_essid(ap, &str) == WIFI_ERROR_NONE) { - _ERR("ESSID : %s\n", str); - strncpy(ap_info->essid, str, SSID_MAX_LENTH - 1); - free(str); - } else { - _ERR("Fail to get ESSID\n"); - return RET_FAILED; - } - - if (wifi_ap_get_connection_state(ap, - &ap_info->state) != WIFI_ERROR_NONE) { - _ERR("Fail to get Connection State\n"); - return RET_FAILED; - } - - if (wifi_ap_get_security_type(ap, - &ap_info->secure_type) != WIFI_ERROR_NONE) { - _ERR("Fail to get Security type\n"); - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Deletes the information of stored access point and disconnects it when it is connected. - * - * If an AP is connected, then connection information will be stored. - * This information is used when a connection to that AP is established automatically. - * If you want to connect another access point, you should desconnect the connected one. - * - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int wifi_mgr_forget_last_ap(void) -{ - int ret; - wifi_ap_h ap; - char *name; - - ret = wifi_get_connected_ap(&ap); - if (ret == WIFI_ERROR_NO_CONNECTION) { - return RET_SUCCESS; - } else if (ret != WIFI_ERROR_NONE) { - _ERR("Fail to get connected AP [%s]\n", - wifi_mgr_error_dbg((wifi_error_e) ret)); - return RET_FAILED; - } - - ret = wifi_ap_get_essid(ap, &name); - if (ret != WIFI_ERROR_NONE) { - _ERR("Fail to wifi_ap_get_essid AP [%s]\n", - wifi_mgr_error_dbg((wifi_error_e) ret)); - wifi_ap_destroy(ap); - return RET_FAILED; - } - - ret = wifi_forget_ap(ap); - if (ret != WIFI_ERROR_NONE) { - _ERR("Fail to forget [%s],[%s].\n", name, - wifi_mgr_error_dbg((wifi_error_e) ret)); - wifi_ap_destroy(ap); - free(name); - return RET_FAILED; - } - - free(name); - - return RET_SUCCESS; -} - -/** - * Sets the passphrase. - * - * When the access point is locked, you should set passphrase first. - * - * @param[in] ap The handle of access point - * @param[in] passcode The passcode - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int wifi_mgr_set_passphrase(wifi_ap_h ap, const char *passcode) -{ - int ret; - - if (!ap || !passcode) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - ret = wifi_ap_set_passphrase(ap, passcode); - if (ret != WIFI_ERROR_NONE) { - _ERR("failed to set passcode. ret: %s.", - wifi_mgr_error_dbg((wifi_error_e) ret)); - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Connects the access point, asynchronously. - * - * After you make the preprarion, such as setting passphrase, - * forgetting the connected ap, then you can connect the ap. - * - * @param[in] ap The handle of access point - * @param[in] cb The callback function to be called - * @param[in] data User data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int wifi_mgr_connect(wifi_ap_h ap, wifi_connected_cb cb, void *data) -{ - int ret; - - if (!cb || !ap || !data) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - ret = wifi_connect(ap, cb, data); - if (ret != WIFI_ERROR_NONE) { - _ERR("failed to connect ap. ret: %s.", - wifi_mgr_error_dbg((wifi_error_e) ret)); - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Sets the config type of IP. - * - * Only support IPV4 now. - * - * @param[in] ap The handle of access point - * @param[in] type The type of IP config - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int wifi_mgr_ap_set_ip_config_type(wifi_ap_h ap, - wifi_ip_config_type_e type) -{ - int ret; - - if (!ap) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - ret = wifi_ap_set_ip_config_type(ap, WIFI_ADDRESS_FAMILY_IPV4, type); - if (ret != WIFI_ERROR_NONE) { - _ERR("failed to connect ap. ret: %s.", - wifi_mgr_error_dbg((wifi_error_e) ret)); - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Gets the data of access point. - * - * Get ip, dns, submask, and gateway info. - * - * @param[in] ap The handle of access point - * @param[out] info The structure to store ip info - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int wifi_mgr_get_ip_info(wifi_ap_h ap, struct network_info *info) -{ - char *str_value; - - if (!info || !ap) { - _ERR("null pointer"); - return RET_FAILED; - } - - str_value = NULL; - if (wifi_ap_get_ip_address(ap, WIFI_ADDRESS_FAMILY_IPV4, - &str_value) == WIFI_ERROR_NONE) { - strncpy(info->ip_addr, str_value, IP_STRING_MAX_SIZE); - free(str_value); - } else { - strncpy(info->ip_addr, ZERO_IP, IP_STRING_MAX_SIZE); - _ERR("Fail to get Gateway\n"); - } - - str_value = NULL; - if (wifi_ap_get_subnet_mask(ap, WIFI_ADDRESS_FAMILY_IPV4, - &str_value) == WIFI_ERROR_NONE) { - strncpy(info->submask, str_value, IP_STRING_MAX_SIZE); - free(str_value); - } else { - strncpy(info->submask, ZERO_IP, IP_STRING_MAX_SIZE); - _ERR("Fail to get Gateway\n"); - } - - str_value = NULL; - if (wifi_ap_get_gateway_address(ap, WIFI_ADDRESS_FAMILY_IPV4, - &str_value) == WIFI_ERROR_NONE) { - strncpy(info->gateway, str_value, IP_STRING_MAX_SIZE); - free(str_value); - } else { - strncpy(info->gateway, ZERO_IP, IP_STRING_MAX_SIZE); - _ERR("Fail to get Gateway\n"); - } - - str_value = NULL; - if (wifi_ap_get_dns_address(ap, 1, WIFI_ADDRESS_FAMILY_IPV4, - &str_value) == WIFI_ERROR_NONE) { - strncpy(info->dns, str_value, IP_STRING_MAX_SIZE); - free(str_value); - } else { - strncpy(info->dns, ZERO_IP, IP_STRING_MAX_SIZE); - _ERR("Fail to get DNS1\n"); - } - - return RET_SUCCESS; -} - -/** - * Sets the data of access point. - * - * Set ip, submask, and gateway info. - * - * @param[in] ap The handle of access point - * @param[in] info The structure of ip info - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int wifi_mgr_set_ip_config(wifi_ap_h ap, struct network_info *info) -{ - int ret; - - if (!info || !ap) { - _ERR("null pointer"); - return RET_FAILED; - } - - ret = wifi_ap_set_ip_address(ap, WIFI_ADDRESS_FAMILY_IPV4, - info->ip_addr); - if (ret != WIFI_ERROR_NONE) - _ERR("Fail to set ip address[%s]\n", - wifi_mgr_error_dbg((wifi_error_e) ret)); - - ret = wifi_ap_set_subnet_mask(ap, WIFI_ADDRESS_FAMILY_IPV4, - info->submask); - if (ret != WIFI_ERROR_NONE) - _ERR("Fail to set subnet mask[%s]\n", - wifi_mgr_error_dbg((wifi_error_e) ret)); - - ret = wifi_ap_set_gateway_address(ap, WIFI_ADDRESS_FAMILY_IPV4, - info->gateway); - if (ret != WIFI_ERROR_NONE) - _ERR("Fail to set gateway address[%s]\n", - wifi_mgr_error_dbg((wifi_error_e) ret)); - - return RET_SUCCESS; -} - -/** - * Sets dns of access point. - * - * @param[in] ap The handle of access point - * @param[in] info The structure of ip info - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -int wifi_mgr_set_dns_config(wifi_ap_h ap, struct network_info *info) -{ - int ret; - - if (!info || !ap) { - _ERR("null pointer"); - return RET_FAILED; - } - - ret = wifi_ap_set_dns_address(ap, 1, WIFI_ADDRESS_FAMILY_IPV4, - info->dns); - if (ret != WIFI_ERROR_NONE) { - _ERR("Fail to set dns address[%s]\n", - wifi_mgr_error_dbg((wifi_error_e) ret)); - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Gets whether Wi-Fi can access to the internet asynchronously. - * - * @param[in] cb The callback function to be called - * @param[in] data User data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -#if 0 -int wifi_mgr_get_is_online_async(wifi_get_is_online_async_cb cb, - void *data) -{ - int ret; - - if (!cb || !data) { - _ERR("the param is NULL."); - return RET_FAILED; - } - - ret = wifi_get_is_online_async(cb, data); - if (ret != WIFI_ERROR_NONE) { - _ERR("wifi_get_is_online_async() failed."); - return RET_FAILED; - } - - return RET_SUCCESS; -} -#endif diff --git a/ug/network/src/wifi_passcode_view.cpp b/ug/network/src/wifi_passcode_view.cpp deleted file mode 100644 index 27be997..0000000 --- a/ug/network/src/wifi_passcode_view.cpp +++ /dev/null @@ -1,994 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include "defs.h" -#include "dbg.h" -#include "i18n.h" -#include "util.h" -#include "common.h" -#include "wifi_passcode_view.h" -#include "util.h" -#include "network_viewmgr.h" - -#include "WifiMgr.h" - -#define KEY_PRIV "priv" -#define KEY_NETWORK_ENTER "Select" - -#define AP_NAME_LENTH 256 - -#define TXT_PASSCODE "Network passcode" -#define TXT_ENTER_PASSCODE "Enter the network password" - -#define STYLE_ENTRY_FOCUS "focus" -#define STYLE_ENTRY_TXT "DEFAULT='font_size=30 linesize=40'" - -struct _priv { - Evas_Object *win; - ui_gadget_h ug; - struct viewmgr *vmgr; - Evas_Object *base; - Evas_Object *entry; - Evas_Object *dim_ly; - Evas_Object *ctxpopup; - char ap_name[AP_NAME_LENTH + 1]; - char *ap_pwd; - - CWifiMgr *pWifiMgr; -}; - -static int _wifi_connect_ap(struct _priv *priv); -static void _show_confirm_popup(struct _priv *priv); -static void _show_progress_popup(struct _priv *priv); - -/** - * Initializes the private data. - * - * Called when the view is loaded. - * - * @return the handler of the private data; - */ -static struct _priv *_init_priv(void) -{ - struct _priv *priv; - - priv = (struct _priv *) calloc(1, sizeof(*priv)); - - priv->pWifiMgr = NULL; - priv->pWifiMgr = CWifiMgr::GetInstance(); - ASSERT(priv->pWifiMgr); - - return priv; -} - -/** - * Deinitializes the private data. - * - * Called when the view is deleted. - * - * @param[in] priv The handler of the private data - */ -static void _fini_priv(struct _priv *priv) -{ - if (!priv) { - _ERR("priv is already NULL."); - return; - } - - if (priv->dim_ly) - evas_object_del(priv->dim_ly); - - free(priv->ap_pwd); - free(priv); -} - -/** - * Shows the dim layout. - * - * Called when there is a ctxpopup. - * - * @param[in] priv The handler of the private data - */ -static void _set_layout_dim(struct _priv *priv) -{ - if (!priv || !priv->dim_ly) { - _ERR("The param is invalid.\n"); - return; - } - - evas_object_show(priv->dim_ly); -} - -/** - * Hides the dim layout. - * - * Called when the existing ctxpopup is deleted. - * - * @param[in] priv The handler of the private data - */ -static void _unset_layout_dim(struct _priv *priv) -{ - if (!priv || !priv->dim_ly) { - _ERR("The param is invalid.\n"); - return; - } - - evas_object_hide(priv->dim_ly); -} - -/** - * Creates the dim layout. - * - * Called when the view is created. - * - * @param[in] priv The handler of the private data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -static int _create_dim_layout(struct _priv *priv) -{ - Evas_Object *dim_ly; - - if (!priv || !priv->win) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - dim_ly = util_add_layout(priv->win, UG_NETWORK_EDJ_FILE, GRP_DIM_LY); - if (!dim_ly) { - _ERR("elm_layout_add() failed.\n"); - return RET_FAILED; - } - - priv->dim_ly = dim_ly; - - _unset_layout_dim(priv); - - return RET_SUCCESS; -} - -/** - * Callback for key pressed event. - * - * If the key is KEY_BACK, delete this view. - * - * @param[in] data User data - * @param[in] e Evas handler - * @param[in] obj The corresponding object which the deletion event occurred - * @param[in] ei Event information - */ -static void _base_key_press_cb(void *data, Evas *e, - Evas_Object *obj, void *ei) -{ - Evas_Event_Key_Down *ev; - struct _priv *priv; - - if (!ei || !data) { - _ERR("ei or data is NULL"); - return; - } - - priv = (struct _priv *) data; - ev = (Evas_Event_Key_Down *) ei; - - if (!ev->keyname) { - _ERR("ev->keyname is NULL."); - return; - } - - if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) - viewmgr_pop(priv->vmgr); -} - -/** - * Sets the description. - * - * Sets the description for the passcode view. - * - * @param[in] priv The handler of the private data - */ -static void _set_description(struct _priv *priv) -{ - if (!priv || !priv->base) { - _ERR("priv is invalid."); - return; - } - - elm_object_part_text_set(priv->base, PART_WIFI_PASSCODE_TITLE, - _(TXT_PASSCODE)); - elm_object_part_text_set(priv->base, PART_WIFI_PASSCODE_TEXT, - _(TXT_ENTER_PASSCODE)); - elm_object_part_text_set(priv->base, PART_WIFI_PASSCODE_AP_NAME, - priv->ap_name); -} - -/** -* @Evas_Smart_Cb type callback for handling click event. -* -* When the 'OK' button is clicked, delete the popup, -* and set the default focus. -* -* @param[in] data User data -* @param[in] obj The corresponding object which the focus event occurred -* @param[in] event Event information -*/ -static void _popup_ok_btn_clicked_cb(void *data, - Evas_Object *obj, void *event) -{ - struct _priv *priv; - - if (!data) { - _ERR("Parameter error!"); - return; - } - - priv = (struct _priv *) data; - - if (priv->ctxpopup) { - evas_object_del(priv->ctxpopup); - priv->ctxpopup = NULL; - } - - elm_object_focus_set(priv->entry, EINA_TRUE); -} - -/** -* @Evas_Smart_Cb type callback for handling unfocused event. -* -* When the ctxpopup is unfocused, hide the dim layout, -* and delete the ctxpopup. -* -* @param[in] data User data -* @param[in] obj The corresponding object which the focus event occurred -* @param[in] source Event information -*/ -static void _ctxpopup_unfocused_cb(void *data, - Evas_Object *obj, void *source) -{ - struct _priv *priv; - - if (!data || !obj) { - _ERR("data is NULL.\n"); - return; - } - - priv = (struct _priv *) data; - - _unset_layout_dim(priv); - - evas_object_del(obj); -} - -/** -* @Evas_Object_Event_Cb type callback for handling pressed event. -* -* When KEY_BACK is pressed in the ctxpopup, delete the ctxpopup. -* -* @param[in] data User data -* @param[in] e Evas handler -* @param[in] obj The corresponding object which the deletion event occurred -* @param[in] ei Event information -*/ -static void _ctxpopup_pressed_cb(void *data, Evas *e, - Evas_Object *obj, void *ei) -{ - Evas_Event_Key_Down *ev; - struct _priv *priv; - - if (!data || !ei || !obj) { - _ERR("Parameter error!"); - return; - } - - priv = (struct _priv *) data; - ev = (Evas_Event_Key_Down *) ei; - - if (!ev->keyname) { - _ERR("ev->keyname is NULL."); - return; - } - - if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) { - _unset_layout_dim(priv); - evas_object_del(obj); - - elm_object_focus_set(priv->entry, EINA_TRUE); - } -} - -/** - * Shows the invalid ctxpopup. - * - * The ctxpopup will show the invalid passcode information. - * - * @param[in] priv The handler of the private data - */ -static void _show_invalid_pwd_popup(struct _priv *priv) -{ - Evas_Object *layout; - Evas_Object *ok_btn; - Evas_Coord w; - Evas_Coord h; - char content[CONTENT_TXT_SIZE]; - - if (!priv) { - _ERR("The param is NULL.\n"); - return; - } - - if (priv->ctxpopup) { - evas_object_del(priv->ctxpopup); - priv->ctxpopup = NULL; - } - - _set_layout_dim(priv); - - layout = util_add_layout(priv->base, UG_NETWORK_EDJ_FILE, - GRP_CONFIRM_LAYOUT); - if (!layout) { - _ERR("add layout failed."); - _unset_layout_dim(priv); - return; - } - - elm_object_part_text_set(layout, - PART_TEXT_TITLE, _(TXT_WIRELESS_LY)); - - memset(content, 0, CONTENT_TXT_SIZE); - snprintf(content, CONTENT_TXT_SIZE - 1, "%s", - _(TXT_INVALID_PWD)); - elm_object_part_text_set(layout, - PART_TEXT_CONTENT, content); - - ok_btn = util_add_button(layout, STYLE_SETTING_BTN, - PART_OK_BTN, _(TXT_OK)); - if (!ok_btn) { - _ERR("util add button failed."); - evas_object_del(layout); - _unset_layout_dim(priv); - return; - } - - elm_object_focus_next_object_set(ok_btn, ok_btn, ELM_FOCUS_RIGHT); - elm_object_focus_next_object_set(ok_btn, ok_btn, ELM_FOCUS_LEFT); - elm_object_focus_next_object_set(ok_btn, ok_btn, ELM_FOCUS_UP); - elm_object_focus_next_object_set(ok_btn, ok_btn, ELM_FOCUS_DOWN); - evas_object_smart_callback_add(ok_btn, SIG_CLICKED, - _popup_ok_btn_clicked_cb, priv); - - elm_object_focus_set(ok_btn, EINA_TRUE); - - elm_object_focus_allow_set(layout, EINA_TRUE); - evas_object_smart_callback_add(layout, SIG_UNFOCUSED, - _ctxpopup_unfocused_cb, priv); - evas_object_event_callback_add(layout, EVAS_CALLBACK_KEY_DOWN, - _ctxpopup_pressed_cb, priv); - - w = DEFAULT_WIN_WIDTH; - h = DEFAULT_WIN_HEIGHT; - - evas_object_move(layout, CENTER_ALIGN * (w - POPUP_WIDTH) * ELM_SCALE, - CENTER_ALIGN * (h - POPUP_HEIGHT) * ELM_SCALE); - - priv->ctxpopup = layout; -} - -/** -* @Evas_Smart_Cb type callback for handling clicking event. -* -* When the 'Retry' button is clicked, retry to connect the ap. -* -* @param[in] data User data -* @param[in] obj The corresponding object which the focus event occurred -* @param[in] event Event information -*/ -static void _retry_btn_clicked_cb(void *data, - Evas_Object *obj, void *event) -{ - struct _priv *priv; - int ret; - - if (!data) { - _ERR("Parameter error!"); - return; - } - - priv = (struct _priv *) data; - - if (priv->ctxpopup) { - evas_object_del(priv->ctxpopup); - priv->ctxpopup = NULL; - } - - _unset_layout_dim(priv); - - ret = _wifi_connect_ap(priv); - if (ret != RET_SUCCESS) { - _ERR("connect ap"); - _show_confirm_popup(priv); - return; - } -} - -/** -* @Evas_Smart_Cb type callback for handling clicking event. -* -* When the 'Cancel' button is clicked, delete the ctxpopup -* where the button is located. -* -* @param[in] data User data -* @param[in] obj The corresponding object which the focus event occurred -* @param[in] event Event information -*/ -static void _cancel_btn_clicked_cb(void *data, - Evas_Object *obj, void *event) -{ - struct _priv *priv; - - if (!data) { - _ERR("Parameter error!"); - return; - } - - priv = (struct _priv *) data; - - if (priv->ctxpopup) { - evas_object_del(priv->ctxpopup); - priv->ctxpopup = NULL; - } - - _unset_layout_dim(priv); - - elm_object_focus_set(priv->entry, EINA_TRUE); -} - -/** - * Shows the confirm ctxpopup. - * - * The ctxpopup will show the result of connectting the ap. - * - * @param[in] priv The handler of the private data - */ -static void _show_confirm_popup(struct _priv *priv) -{ - Evas_Object *layout; - Evas_Object *retry_btn; - Evas_Object *cancel_btn; - Evas_Coord w; - Evas_Coord h; - char content[CONTENT_TXT_SIZE]; - - if (!priv) { - _ERR("the param is NULL."); - return; - } - - if (priv->ctxpopup) { - evas_object_del(priv->ctxpopup); - priv->ctxpopup = NULL; - } - - _set_layout_dim(priv); - - layout = util_add_layout(priv->base, UG_NETWORK_EDJ_FILE, - GRP_CONFIRM_LAYOUT); - if (!layout) { - _ERR("add layout failed."); - _unset_layout_dim(priv); - return; - } - - memset(content, 0, CONTENT_TXT_SIZE); - elm_object_part_text_set(layout, - PART_TEXT_TITLE, _(TXT_WIRELESS_LY)); - snprintf(content, CONTENT_TXT_SIZE - 1, "%s %s", - _(TXT_FAILED_CONNECT), priv->ap_name); - - elm_object_part_text_set(layout, - PART_TEXT_CONTENT, content); - - retry_btn = util_add_button(layout, STYLE_SETTING_BTN, - PART_RETRY_BTN, _(TXT_RETRY)); - if (!retry_btn) { - _ERR("util add button failed."); - evas_object_del(layout); - _unset_layout_dim(priv); - return; - } - - cancel_btn = util_add_button(layout, STYLE_SETTING_BTN, - PART_CANCEL_BTN, _(TXT_CANCEL)); - if (!cancel_btn) { - _ERR("util add button failed."); - evas_object_del(layout); - _unset_layout_dim(priv); - return; - } - - elm_object_focus_next_object_set(retry_btn, cancel_btn, - ELM_FOCUS_RIGHT); - elm_object_focus_next_object_set(cancel_btn, retry_btn, - ELM_FOCUS_LEFT); - elm_object_focus_next_object_set(cancel_btn, cancel_btn, - ELM_FOCUS_RIGHT); - elm_object_focus_next_object_set(retry_btn, retry_btn, - ELM_FOCUS_LEFT); - elm_object_focus_next_object_set(cancel_btn, cancel_btn, - ELM_FOCUS_UP); - elm_object_focus_next_object_set(retry_btn, retry_btn, - ELM_FOCUS_UP); - elm_object_focus_next_object_set(cancel_btn, cancel_btn, - ELM_FOCUS_DOWN); - elm_object_focus_next_object_set(retry_btn, retry_btn, - ELM_FOCUS_DOWN); - - evas_object_smart_callback_add(retry_btn, SIG_CLICKED, - _retry_btn_clicked_cb, priv); - evas_object_smart_callback_add(cancel_btn, SIG_CLICKED, - _cancel_btn_clicked_cb, priv); - - elm_object_focus_set(retry_btn, EINA_TRUE); - - elm_object_focus_allow_set(layout, EINA_TRUE); - evas_object_smart_callback_add(layout, SIG_UNFOCUSED, - _ctxpopup_unfocused_cb, priv); - evas_object_event_callback_add(layout, EVAS_CALLBACK_KEY_DOWN, - _ctxpopup_pressed_cb, priv); - - w = DEFAULT_WIN_WIDTH; - h = DEFAULT_WIN_HEIGHT; - - evas_object_move(layout, CENTER_ALIGN * (w - POPUP_WIDTH) * ELM_SCALE, - CENTER_ALIGN * (h - POPUP_HEIGHT) * ELM_SCALE); - - priv->ctxpopup = layout; -} - -/** - * Shows the progress ctxpopup. - * - * The ctxpopup will show the progress of connectting the ap. - * - * @param[in] priv The handler of the private data - */ -static void _show_progress_popup(struct _priv *priv) -{ - Evas_Object *layout; - Evas_Object *cancel_btn; - Evas_Coord w; - Evas_Coord h; - char content[CONTENT_TXT_SIZE]; - - if (!priv) { - _ERR("the param is NULL."); - return; - } - - if (priv->ctxpopup) { - evas_object_del(priv->ctxpopup); - priv->ctxpopup = NULL; - } - - _set_layout_dim(priv); - - layout = util_add_layout(priv->base, UG_NETWORK_EDJ_FILE, - GRP_PROCESSING_LAYOUT); - if (!layout) { - _ERR("add layout failed."); - _unset_layout_dim(priv); - return; - } - - memset(content, 0, CONTENT_TXT_SIZE); - elm_object_part_text_set(layout, - PART_TEXT_TITLE, _(TXT_WIRELESS_LY)); - snprintf(content, CONTENT_TXT_SIZE - 1, "%s %s", - _(TXT_CONNECTTING), priv->ap_name); - elm_object_part_text_set(layout, PART_TEXT_CONTENT, content); - - cancel_btn = util_add_button(layout, STYLE_SETTING_BTN, - PART_CANCEL_BTN, _(TXT_CANCEL)); - if (!cancel_btn) { - _ERR("util add button failed."); - evas_object_del(layout); - _unset_layout_dim(priv); - return; - } - - elm_object_focus_next_object_set(cancel_btn, cancel_btn, - ELM_FOCUS_LEFT); - elm_object_focus_next_object_set(cancel_btn, cancel_btn, - ELM_FOCUS_RIGHT); - elm_object_focus_next_object_set(cancel_btn, cancel_btn, - ELM_FOCUS_UP); - elm_object_focus_next_object_set(cancel_btn, cancel_btn, - ELM_FOCUS_DOWN); - - evas_object_smart_callback_add(cancel_btn, SIG_CLICKED, - _cancel_btn_clicked_cb, priv); - - elm_object_focus_set(cancel_btn, EINA_TRUE); - - elm_object_focus_allow_set(layout, EINA_TRUE); - evas_object_smart_callback_add(layout, SIG_UNFOCUSED, - _ctxpopup_unfocused_cb, priv); - evas_object_event_callback_add(layout, EVAS_CALLBACK_KEY_DOWN, - _ctxpopup_pressed_cb, priv); - - w = DEFAULT_WIN_WIDTH; - h = DEFAULT_WIN_HEIGHT; - - evas_object_move(layout, CENTER_ALIGN * (w - POPUP_WIDTH) * ELM_SCALE, - CENTER_ALIGN * (h - POPUP_HEIGHT) * ELM_SCALE); - - priv->ctxpopup = layout; -} - -/** - * The callback of wifi connection. - * - * The result is in the error code. - * - * @param[in] error_code Error code - * @param[in] user_data User data - */ -static void _wifi_connected_cb(wifi_error_e error_code, void *user_data) -{ - struct _priv *priv; - - if (!user_data) { - _ERR("Parameter error!"); - return; - } - - priv = (struct _priv *) user_data; - - if (!priv->ctxpopup) - return; - - if (error_code != WIFI_ERROR_NONE) { - _ERR("connect AP failed, ret: %s.", - priv->pWifiMgr->GetErrorMsg(error_code)); - _show_confirm_popup(priv); - return; - } - - ug_destroy_me(priv->ug); -} - -/** - * The callback of finding ap. - * - * The callback will be called the same times as the ap count. - * - * @param[in] ap The hander of ap - * @param[in] data User data - */ -static bool _wifi_found_ap_cb(wifi_ap_h ap, void *data) -{ - bool ret; - struct _priv *priv; - struct wifi_ap_info ap_info; - - if (!ap || !data) { - _ERR("Parameter error!"); - return false; - } - - priv = (struct _priv *) data; - - ret = priv->pWifiMgr->GetESSID(ap, ap_info.essid); - if(ret != true) { - _ERR("Fail to get info"); - return false; - } - ret = priv->pWifiMgr->GetConnectionState(ap, &ap_info.state); - if(ret != true) { - _ERR("Fail to get info"); - return false; - } - ret = priv->pWifiMgr->GetSecurityType(ap, &ap_info.secure_type); - if(ret != true) { - _ERR("Fail to get info"); - return false; - } - - if (!strncmp(priv->ap_name, ap_info.essid, AP_NAME_LENTH)) { - ret = priv->pWifiMgr->SetPassPhrase(ap, priv->ap_pwd); - if (ret != true) { - _ERR("wifi_mgr_set_passphrase() failed."); - _show_confirm_popup(priv); - return false; - } - - ret = priv->pWifiMgr->Connect(ap, _wifi_connected_cb, priv); - if (ret != true) { - _ERR("Fail to connection request.\n"); - _show_confirm_popup(priv); - return false; - } - - return false; - } - - return true; -} - -/** - * The callback of ap scanning request. - * - * The callback will be called the same times as the ap count. - * - * @param[in] error_code Error code - * @param[in] data User data - */ -static void _wifi_scan_request_cb(wifi_error_e error_code, void *data) -{ - struct _priv *priv; - bool ret; - - if (!data) { - _ERR("data is NULL."); - return; - } - - priv = (struct _priv *) data; - - ret = priv->pWifiMgr->RegisterFoundAPCallback(_wifi_found_ap_cb, data); - if (ret != true) { - _ERR("wifi_mgr_foreach_found_aps() failed."); - _show_confirm_popup((struct _priv *) data); - return; - } -} - -/** - * Connects the ap. - * - * @param[in] priv The handler of the private data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -static int _wifi_connect_ap(struct _priv *priv) -{ - bool ret; - - if (!priv || !priv->ap_pwd) { - _ERR("Parameter error!"); - return RET_FAILED; - } - - _show_progress_popup(priv); - - ret = priv->pWifiMgr->ForgetAP(); - if (ret != true) { - _ERR("forget last ap failed."); - return false; - } - - ret = priv->pWifiMgr->RegisterScanCallback(_wifi_scan_request_cb, priv); - if (ret != true) { - _ERR("wifi_mgr_scan_request() failed."); - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Callback for key pressed event. - * - * If the key is 'Select', connect the ap. - * - * @param[in] data User data - * @param[in] e Evas handler - * @param[in] obj The corresponding object which the deletion event occurred - * @param[in] ei Event information - */ -static void _entry_key_press_cb(void *data, Evas *e, - Evas_Object *obj, void *ei) -{ - Evas_Event_Key_Down *ev; - struct _priv *priv; - int ret; - - if (!ei || !data) { - _ERR("ei or data is NULL"); - return; - } - - priv = (struct _priv *) data; - ev = (Evas_Event_Key_Down *) ei; - - if (!ev->keyname) { - _ERR("ev->keyname is NULL."); - return; - } - - if (!strcmp(ev->keyname, KEY_NETWORK_ENTER)) { - if (priv->ap_pwd) { - free(priv->ap_pwd); - priv->ap_pwd = NULL; - } - - priv->ap_pwd = strdup(elm_entry_entry_get(obj)); - if (!priv->ap_pwd) { - _ERR("the passcode in entry is NULL."); - _show_invalid_pwd_popup(priv); - return; - } - - ret = _wifi_connect_ap(priv); - if (ret != RET_SUCCESS) { - _ERR("connect ap"); - _show_confirm_popup(priv); - return; - } - } -} - -/** - * Creates the entry. - * - * @param[in] priv The handler of the private data - */ -static void _add_entry(struct _priv *priv) -{ - Evas_Object *base; - Evas_Object *entry; - - if (!priv || !priv->base) { - _ERR("the param is invalid."); - return; - } - - base = priv->base; - - entry = util_add_entry(base, STYLE_ENTRY_FOCUS, - PART_WIFI_PASSCODE_ENTRY); - if (!entry) { - _ERR("util_add_entry failed."); - evas_object_del(base); - _fini_priv(priv); - return; - } - - elm_entry_password_set(entry, EINA_TRUE); - elm_entry_text_style_user_push(entry, STYLE_ENTRY_TXT); - evas_object_event_callback_add(entry, EVAS_CALLBACK_KEY_DOWN, - _entry_key_press_cb, priv); - - elm_entry_input_panel_enabled_set(entry, EINA_TRUE); - - elm_object_focus_next_object_set(entry, entry, ELM_FOCUS_UP); - elm_object_focus_next_object_set(entry, entry, ELM_FOCUS_LEFT); - - elm_object_focus_set(entry, EINA_TRUE); - - priv->entry = entry; -} - -/** - * Creates the layout of the view. - * - * Called when the view is pushed. - * - * @param[in] vmgr View manager - * @param[in] data User data - * @return layout if the operation is successful; NULL if failed; - */ -static Evas_Object *_create(struct viewmgr *vmgr, void *data) -{ - struct _priv *priv; - struct wifi_ap_info *ap_info; - Evas_Object *base; - - if (!vmgr || !vmgr->win || !vmgr->ug || !data) { - _ERR("Parameter error!"); - return NULL; - } - - priv = _init_priv(); - if (!priv) { - _ERR("init priv failed."); - return NULL; - } - - priv->win = vmgr->win; - priv->ug = vmgr->ug; - priv->vmgr = vmgr; - - ap_info = (struct wifi_ap_info *) data; - strncpy(priv->ap_name, ap_info->essid, AP_NAME_LENTH); - - base = util_add_layout(priv->win, UG_NETWORK_EDJ_FILE, - GRP_WIFI_PASSCODE_BASE); - if (!base) { - _ERR("util_add_layout failed."); - _fini_priv(priv); - return NULL; - } - - evas_object_data_set(base, KEY_PRIV, priv); - - evas_object_event_callback_add(base, EVAS_CALLBACK_KEY_DOWN, - _base_key_press_cb, priv); - - priv->base = base; - - _set_description(priv); - - _add_entry(priv); - - _create_dim_layout(priv); - - return base; -} - -/** - * Destroies the layout of the view. - * - * Called when the view is popped. - * - * @param[in] base The base layout - */ -static void _destroy(Evas_Object *base) -{ - struct _priv *priv; - - if (!base) { - _ERR("Parameter error!"); - return; - } - - priv = (struct _priv *) evas_object_data_get(base, KEY_PRIV); - if (!priv) - return; - - _fini_priv(priv); -} - -/** - * Gets the current view type. - * - * @return view type; - */ -static enum view_type _get_view_type(void) -{ - return NETWORK_WIFI_PASSCODE_VIEW; -} - - -static struct view_class _vclass = { - _create, - NULL, - NULL, - _destroy, - NULL, - _get_view_type, -}; - -/** - * Gets the current view class. - * - * @return view class; - */ -struct view_class *wifi_passcode_view_vclass_get(void) -{ - return &_vclass; -} -- 2.7.4 From f88267a386f0ece9ddbe09738ed0a408266cd80d Mon Sep 17 00:00:00 2001 From: JuWan Kim Date: Sat, 28 Mar 2015 14:13:28 +0900 Subject: [PATCH 13/16] UG Proxy refactoring Done Change-Id: I9bd9c3ae81916a63227a60155d2cc6aa694396d7 Signed-off-by: JuWan Kim --- ug/network/src/ug_network_settings.cpp | 1 - ug/proxy/CMakeLists.txt | 2 +- ug/proxy/include/ProxyMainView.h | 55 + ug/proxy/include/defs.h | 3 + ug/proxy/include/main_view.h | 23 - ug/proxy/src/ProxyMainView.cpp | 1171 +++++++++++++++++++ ug/proxy/src/main_view.cpp | 2007 -------------------------------- ug/proxy/src/ug_proxy_settings.cpp | 31 +- 8 files changed, 1252 insertions(+), 2041 deletions(-) create mode 100644 ug/proxy/include/ProxyMainView.h delete mode 100644 ug/proxy/include/main_view.h create mode 100644 ug/proxy/src/ProxyMainView.cpp delete mode 100644 ug/proxy/src/main_view.cpp diff --git a/ug/network/src/ug_network_settings.cpp b/ug/network/src/ug_network_settings.cpp index 5fb6688..04ff410 100644 --- a/ug/network/src/ug_network_settings.cpp +++ b/ug/network/src/ug_network_settings.cpp @@ -40,7 +40,6 @@ struct _ug_data { ui_gadget_h ug; CViewMgr *pViewMgr; CNetworkMainView *pNetworkMainView; - //struct viewmgr *vmgr; }; /** diff --git a/ug/proxy/CMakeLists.txt b/ug/proxy/CMakeLists.txt index a5cc8f9..20da480 100644 --- a/ug/proxy/CMakeLists.txt +++ b/ug/proxy/CMakeLists.txt @@ -46,7 +46,7 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") SET(SRCS src/ug_proxy_settings.cpp - src/main_view.cpp + src/ProxyMainView.cpp src/util.cpp ../src/WifiMgr.cpp ../src/NetConMgr.cpp diff --git a/ug/proxy/include/ProxyMainView.h b/ug/proxy/include/ProxyMainView.h new file mode 100644 index 0000000..7bd13dd --- /dev/null +++ b/ug/proxy/include/ProxyMainView.h @@ -0,0 +1,55 @@ +#ifndef __PROXY_MAIN_VIEW_H__ +#define __PROXY_MAIN_VIEW_H__ + +#include "UgCommon.h" + +class CProxyMainView : public CBaseView, public IMouseClickedListener, public IUnfocusedListener { +private : + struct SProxyMainView *m; + + bool m_InitConnection(void); + void m_FinalizeConnection(void); + Evas_Object* m_CreateMainLayout(void); + + Evas_Object *m_CreateValueBtn(Evas_Object *parent, int num, char *txt); + bool m_SetWifiProxy(void); + bool m_SetConnectionProxy(void); + bool m_SetProxy(void); + void m_MethodBtnClicked(EProxyMethod method); + void m_SetupDownCycleFocus(Evas_Object **obj, int count); + void m_SetTheValue(void); + void m_SetLeftRightCycleFocus(Evas_Object **obj, int count); + void m_CreateValuePopup(void); + void m_CreateInputEntry(void); + void m_ShowInvalidInfoPopup(int status); + bool m_CreateMethodBoxBtn(Evas_Object *btn, const char *key, char *value, int line); + + bool m_CreateMethodAutoBtn(void); + bool m_CreateMethodManualBtn(void); + bool m_CreateMethodNoneBtn(void); + + bool m_CreateDimLayout(void); + bool m_CreateActionBtns(void); + bool m_GetProxyMethod(void); + bool m_CreateProxyLayout(void); + +protected : + virtual void t_OnShow(void); + virtual void t_OnUpdate(void *data); + virtual void t_OnHide(void); + +public : + CProxyMainView(const char *szViewId) : CBaseView(szViewId), IMouseClickedListener(this), IUnfocusedListener(this), m(0) {} + virtual ~CProxyMainView() {} + + virtual bool Create(void *data); + virtual void Destroy(void); + virtual Evas_Object* Base(void); + + virtual void OnKeyDown(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev); + virtual void OnMouseClicked(int id, Evas_Object *obj); + virtual void OnUnfocused(int id, Evas_Object *obj, Elm_Object_Item *item); +}; + +#endif /* __PROXY_MAIN_VIEW_H__ */ + diff --git a/ug/proxy/include/defs.h b/ug/proxy/include/defs.h index 576cebd..1af98cc 100644 --- a/ug/proxy/include/defs.h +++ b/ug/proxy/include/defs.h @@ -17,6 +17,9 @@ #ifndef __DEFS_H__ #define __DEFS_H__ +/* View */ +#define PROXY_MAINVIEW "PROXY_MAINVIEW" + /* Common */ #define MOTHED_STRING_LEN 15 #define IP_STRING_LEN 15 diff --git a/ug/proxy/include/main_view.h b/ug/proxy/include/main_view.h deleted file mode 100644 index c6e8170..0000000 --- a/ug/proxy/include/main_view.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __MAIN_VIEW_H__ -#define __MAIN_VIEW_H__ - -Evas_Object *create_main_view(Evas_Object *win, ui_gadget_h ug); -void destroy_main_view(Evas_Object *base); - -#endif /* __MAIN_VIEW_H__ */ diff --git a/ug/proxy/src/ProxyMainView.cpp b/ug/proxy/src/ProxyMainView.cpp new file mode 100644 index 0000000..b16a2e7 --- /dev/null +++ b/ug/proxy/src/ProxyMainView.cpp @@ -0,0 +1,1171 @@ +#include +#include +#include +#include "defs.h" +#include "dbg.h" +#include "i18n.h" +#include "util.h" + +#include "UgCommon.h" +#include "WifiMgr.h" +#include "NetConMgr.h" + +#include +#include + +#include "BaseView.h" +#include "ViewMgr.h" +#include "ProxyMainView.h" + +#define KEY_PRIV "priv" +#define KEY_PROXY_ENTER "Select" +#define IP_VALUE1 "value1" +#define IP_VALUE2 "value2" +#define IP_VALUE3 "value3" +#define IP_VALUE4 "value4" + +static const char *VCONF_NETWORK_TYPE = "db/menu/network/network_type"; +static const char *VCONF_PROXY_METHOD = "db/menu/proxy/method"; +static const char *VCONF_PROXY_IP = "db/menu/proxy/ip"; +static const char *VCONF_PROXY_URL = "db/menu/proxy/url"; + +#define METHOD_CTXPOPUP_OFFSET_X 448 +#define VALUE_CTXPOPUP_OFFSET_X 162 +#define VALUE_CTXPOPUP_OFFSET_Y 20 +#define PROXY_CONFIG_MAX_NUM 4 +#define IP_MAX_NUM 255 +#define IP_RATIO 10 +#define PORT_MAX_NUM 65535 +#define PORT_INVALID_NUM 65536 +#define PORT_NO_NEED 65537 +#define CENTER_ALIGN 0.5 +#define CTXPOPUP_WIDTH 688 +#define CTXPOPUP_HEIGHT 411 +#define BTN_ONE_LINE 1 +#define BTN_TWO_LINE 2 +#define LINE_PAD 2 +#define ALIGH_RATIO 1.5 + +enum network_type_enum { + TYPE_WIRELESS = 0, + TYPE_WIRED +}; + +struct SProxyMainView { + ui_gadget_h ug; + + Evas_Object *win; + Evas_Object *base; + Evas_Object *dim_ly; + Evas_Object *box; + Evas_Object *method_btn; + Evas_Object *proxy_btn; + Evas_Object *url_btn; + Evas_Object *ok_btn; + Evas_Object *cancel_btn; + Evas_Object *ctxpopup; + Evas_Object *vaule_btns[PROXY_CONFIG_MAX_NUM]; + + enum network_type_enum net_type; + + char ip[IP_STRING_LEN + 1]; + char url[MOTHED_URL_LEN + 1]; + + enum EProxyMethod eMethod; + + CWifiMgr *pWifiMgr; + CNetConMgr *pNetConMgr; + CViewMgr *pViewMgr; +}; + +bool CProxyMainView::m_InitConnection(void) +{ + bool ret = false; + + if(!CWifiMgr::Initialize()) { + _ERR("Fail to initialize WifiMgr"); + return false; + } + + m->pWifiMgr = CWifiMgr::GetInstance(); + if(!m->pWifiMgr) { + _ERR("Fail to get instance"); + return false; + } + + ret = CNetConMgr::Initialize(); + if(ret != true) { + _ERR("Fail to initialize NetConMgr"); + return false; + } + + m->pNetConMgr = CNetConMgr::GetInstance(); + if(!m->pNetConMgr) { + _ERR("Fail to get instance"); + return false; + } + + return true; +} + + +void CProxyMainView::m_FinalizeConnection() +{ + CNetConMgr::Finalize(); + CWifiMgr::Finalize(); + m->pNetConMgr = NULL; + m->pWifiMgr = NULL; +} + + +Evas_Object* CProxyMainView::m_CreateMainLayout(void) +{ + Evas_Object *base; + + base = util_add_layout(m->win, UG_PROXY_EDJ_FILE, GRP_MAIN_VIEW); + if (!base) { + _ERR("elm_layout_add() failed."); + return NULL; + } + + //evas_object_event_callback_add(base, EVAS_CALLBACK_KEY_DOWN, _base_key_pressed_cb, priv); + Connect(base, 0); + + evas_object_show(base); + + return base; +} + + +Evas_Object * CProxyMainView::m_CreateValueBtn(Evas_Object *parent, int num, char *txt) +{ + Evas_Object *btn; + + btn = util_add_button(parent, STYLE_VALUE_BTN, NULL, txt); + if (!btn) { + _ERR("add button failed."); + return NULL; + } + + switch (num) { + case 0: + elm_object_part_content_set(parent, PART_IP_FIRST, btn); + evas_object_data_set(parent, IP_VALUE1, btn); + elm_object_focus_set(btn, EINA_TRUE); + break; + case 1: + elm_object_part_content_set(parent, PART_IP_SECOND, btn); + evas_object_data_set(parent, IP_VALUE2, btn); + break; + case 2: + elm_object_part_content_set(parent, PART_IP_THIRD, btn); + evas_object_data_set(parent, IP_VALUE3, btn); + break; + case 3: + elm_object_part_content_set(parent, PART_IP_FORTH, btn); + evas_object_data_set(parent, IP_VALUE4, btn); + break; + default: + break; + } + + //evas_object_event_callback_add(btn, EVAS_CALLBACK_KEY_DOWN, _value_key_pressed_cb, data); + Connect(btn, 14); + elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_UP); + elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_DOWN); + + return btn; + +} + + +bool CProxyMainView::m_SetWifiProxy(void) +{ + bool ret = false; + + if (!m->pWifiMgr) { + _ERR("WifiMgr is not initialized."); + return false; + } + + ret = m->pWifiMgr->SetProxyType(m->eMethod); + if (ret != true) { + _ERR("wifi_mgr_get_proxy_type() failed."); + return ret; + } + + switch (m->eMethod) { + case PROXY_METHOD_NONE: + m->pWifiMgr->SetProxyAddr(NULL); + break; + case PROXY_METHOD_MANUAL: + if (m->ip) + m->pWifiMgr->SetProxyAddr(m->ip); + break; + case PROXY_METHOD_AUTO: + if (m->url) + m->pWifiMgr->SetProxyAddr(m->url); + break; + default: + return false; + } + + return true; +} + + +bool CProxyMainView::m_SetConnectionProxy(void) +{ + bool ret; + ret = m->pNetConMgr->SetProxyType(m->eMethod); + if (ret != true) { + _ERR("wifi_mgr_get_proxy_type() failed."); + return false; + } + + switch (m->eMethod) { + case PROXY_METHOD_NONE: + break; + case PROXY_METHOD_MANUAL: + if (m->ip) + m->pNetConMgr->SetProxyAddr(m->ip); + break; + case PROXY_METHOD_AUTO: + if (m->url) + m->pNetConMgr->SetProxyAddr(m->url); + break; + default: + return false; + } + + return true; +} + + +bool CProxyMainView::m_SetProxy(void) +{ + bool ret = false; + + if (m->net_type == TYPE_WIRED) { + ret = m_SetConnectionProxy(); + if (ret != true) { + _ERR("the ip or port is invalid."); + return ret; + } + } else if (m->net_type == TYPE_WIRELESS) { + ret = m_SetWifiProxy(); + if (ret != true) { + _ERR("the ip or port is invalid."); + return ret; + } + } + + return true; + +} + + +void CProxyMainView::m_MethodBtnClicked(EProxyMethod method) +{ + if (m->ctxpopup) { + evas_object_del(m->ctxpopup); + m->ctxpopup = NULL; + } + + m->eMethod = method; + + elm_box_clear(m->box); + + m->method_btn = NULL; + m->proxy_btn= NULL; + m->url_btn = NULL; + + switch (m->eMethod) { + case PROXY_METHOD_NONE: + m_CreateMethodNoneBtn(); + break; + case PROXY_METHOD_MANUAL: + m_CreateMethodManualBtn(); + break; + case PROXY_METHOD_AUTO: + m_CreateMethodAutoBtn(); + break; + default: + break; + } + + elm_object_focus_set(m->method_btn, EINA_TRUE); +} + + +void CProxyMainView::m_SetupDownCycleFocus(Evas_Object **obj, int count) +{ + for (int i = 0; i < count; i++) { + if (i == count - 1) + elm_object_focus_next_object_set(obj[i], obj[0], ELM_FOCUS_DOWN); + else + elm_object_focus_next_object_set(obj[i], obj[i + 1], ELM_FOCUS_DOWN); + + if (i == 0) + elm_object_focus_next_object_set(obj[i], obj[count - 1], ELM_FOCUS_UP); + else + elm_object_focus_next_object_set(obj[i], obj[i - 1], ELM_FOCUS_UP); + } +} + + +void CProxyMainView::m_SetTheValue(void) +{ + Evas_Object *btn; + const char *value1; + const char *value2; + const char *value3; + const char *value4; + char ip[IP_STRING_LEN + 1]; + + value1 = NULL; + btn = (Evas_Object *) evas_object_data_get(m->ctxpopup, IP_VALUE1); + if (btn) + value1 = elm_object_text_get(btn); + + value2 = NULL; + btn = (Evas_Object *) evas_object_data_get(m->ctxpopup, IP_VALUE2); + if (btn) + value2 = elm_object_text_get(btn); + + value3 = NULL; + btn = (Evas_Object *) evas_object_data_get(m->ctxpopup, IP_VALUE3); + if (btn) + value3 = elm_object_text_get(btn); + + value4 = NULL; + btn = (Evas_Object *) evas_object_data_get(m->ctxpopup, IP_VALUE4); + if (btn) + value4 = elm_object_text_get(btn); + + memset(ip, 0, IP_STRING_LEN + 1); + snprintf(ip, IP_STRING_LEN, "%s.%s.%s.%s", + value1 ? value1 : "\\0", value2 ? value2 : "\\0", + value3 ? value3 : "\\0", value4 ? value4 : "\\0"); + + strncpy(m->ip, ip, IP_STRING_LEN); + elm_object_part_text_set(m->proxy_btn, PART_VALUE, ip); + + evas_object_del(m->ctxpopup); + m->ctxpopup = NULL; +} + + +void CProxyMainView::m_SetLeftRightCycleFocus(Evas_Object **obj, int count) +{ + int i; + + if (!obj || !*obj) { + _ERR("the param is invalid."); + return; + } + + for (i = 0; i < count; i++) { + if (i == count - 1) + elm_object_focus_next_object_set(obj[i], obj[0], ELM_FOCUS_RIGHT); + else + elm_object_focus_next_object_set(obj[i], obj[i + 1], ELM_FOCUS_RIGHT); + + if (i == 0) + elm_object_focus_next_object_set(obj[i], obj[count - 1], ELM_FOCUS_LEFT); + else + elm_object_focus_next_object_set(obj[i], obj[i - 1], ELM_FOCUS_LEFT); + } +} + + +void CProxyMainView::m_CreateValuePopup(void) +{ + Evas_Object *ctxpopup; + Evas_Object *btn; + Evas_Coord pos_x; + Evas_Coord pos_y; + int i; + + ctxpopup = util_add_layout(m->base, UG_PROXY_EDJ_FILE, GRP_PROXY_VALUE_SETTING); + if (!ctxpopup) { + _ERR("elm_ctxpopup_add() failed."); + return; + } + + m->ctxpopup = ctxpopup; + + evas_object_show(m->dim_ly); + + for (i = 0; i < PROXY_CONFIG_MAX_NUM; i++) { + btn = m_CreateValueBtn(ctxpopup, i, _(TXT_ZERO)); + if (!btn) { + _ERR("m_CreateValueBtn() failed."); + evas_object_del(ctxpopup); + return; + } + + m->vaule_btns[i] = btn; + } + + elm_object_part_text_set(ctxpopup, PART_TXT_SEPERATOR, _(TXT_COLON)); + //evas_object_smart_callback_add(ctxpopup, SIG_UNFOCUSED, _ctxpopup_unfocused_cb, priv); + //evas_object_event_callback_add(ctxpopup, EVAS_CALLBACK_KEY_DOWN, _value_ctxpopup_key_pressed_cb, priv); + Connect(ctxpopup, 10); + m_SetLeftRightCycleFocus(m->vaule_btns, PROXY_CONFIG_MAX_NUM); + + pos_x = 0; + pos_y = 0; + + Evas_Coord x; + Evas_Coord y; + evas_object_geometry_get(m->proxy_btn, &x, &y, NULL, NULL); + pos_x = x + VALUE_CTXPOPUP_OFFSET_X; + pos_y = y - VALUE_CTXPOPUP_OFFSET_Y; + + evas_object_move(ctxpopup, pos_x * ELM_SCALE, pos_y * ELM_SCALE); +} + + +void CProxyMainView::m_CreateInputEntry(void) +{ + Evas_Object *entry; + Evas_Object *layout; + + if (m->ctxpopup) { + evas_object_del(m->ctxpopup); + m->ctxpopup = NULL; + } + + layout = util_add_layout(m->base, UG_PROXY_EDJ_FILE, GRP_ENTRY_POPUP); + if (!layout) { + _ERR("create layout fail."); + return; + } + + entry = util_add_entry(layout, STYLE_ENTRY, PART_ENTRY); + if (!entry) { + _ERR("add entry failed."); + evas_object_del(layout); + return; + } + + util_set_focus_next_self(entry); + //evas_object_event_callback_add(entry, EVAS_CALLBACK_KEY_DOWN, _entry_key_pressed_cb, priv); + Connect(entry, 9); + elm_object_focus_set(entry, EINA_TRUE); + + evas_object_show(m->dim_ly); + + m->ctxpopup = layout; +} + + +void CProxyMainView::m_ShowInvalidInfoPopup(int status) +{ + Evas_Object *layout; + Evas_Object *btn; + Evas_Coord w; + Evas_Coord h; + + if (m->ctxpopup) { + evas_object_del(m->ctxpopup); + m->ctxpopup = NULL; + } + + evas_object_show(m->dim_ly); + + layout = util_add_layout(m->base, UG_PROXY_EDJ_FILE, GRP_CONFIRM_LAYOUT); + if (!layout) { + _ERR("add layout failed."); + evas_object_hide(m->dim_ly); + return; + } + + switch (m->eMethod) { + case PROXY_METHOD_MANUAL: + elm_object_part_text_set(layout, PART_TEXT_TITLE, _(TXT_MANUAL_TITLE)); + break; + case PROXY_METHOD_AUTO: + elm_object_part_text_set(layout, PART_TEXT_TITLE, _(TXT_AUTO_TITLE)); + break; + default: + evas_object_del(layout); + evas_object_hide(m->dim_ly); + return; + } + + elm_object_part_text_set(layout, PART_TEXT_TITLE, _(TXT_MANUAL_TITLE)); + + if (status == RET_IP_INVALID) + elm_object_part_text_set(layout, PART_TEXT_CONTENT, _(TXT_IP_INVALID)); + else if (status == RET_VCONF_FAILED) + elm_object_part_text_set(layout, PART_TEXT_CONTENT, _(TXT_VCONF_FAILED)); + else if (status == RET_WIRED_PROXY_FAILED) + elm_object_part_text_set(layout, PART_TEXT_CONTENT, _(TXT_WIRED_FAILED)); + else if (status == RET_WIRELESS_PROXY_FAILED) + elm_object_part_text_set(layout, PART_TEXT_CONTENT, _(TXT_WIRELESS_FAILED)); + + btn = util_add_button(layout, STYLE_ACTION_BTN, PART_OK_BTN, _(TXT_OK)); + if (!btn) { + _ERR("util add button failed."); + evas_object_del(layout); + evas_object_hide(m->dim_ly); + return; + } + + elm_object_focus_set(btn, EINA_TRUE); + elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_RIGHT); + elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_LEFT); + elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_UP); + elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_DOWN); + + //evas_object_smart_callback_add(btn, SIG_CLICKED, _ctxpopup_ok_btn_clicked_cb, priv); + //evas_object_smart_callback_add(layout, SIG_UNFOCUSED, _ctxpopup_unfocused_cb, priv); + //evas_object_event_callback_add(layout, EVAS_CALLBACK_KEY_DOWN, _ctxpopup_key_pressed_cb, priv); + Connect(btn, 7); + Connect(layout, 8); + + w = DEFAULT_WIN_WIDTH; + h = DEFAULT_WIN_HEIGHT; + + evas_object_move(layout, CENTER_ALIGN * (w - CTXPOPUP_WIDTH) * ELM_SCALE, CENTER_ALIGN * (h - CTXPOPUP_HEIGHT) * ELM_SCALE); + + m->ctxpopup = layout; +} + + +bool CProxyMainView::m_CreateMethodBoxBtn(Evas_Object *btn, const char *key, char *value, int line) +{ + if (btn) { + evas_object_show(btn); + elm_object_part_text_set(btn, PART_VALUE, value); + } else { + if (line == BTN_TWO_LINE) + btn = util_add_key_value_button(m->box, STYLE_KEY_VALUE_TWO_LINES, NULL, key, value); + else + btn = util_add_key_value_button(m->box, STYLE_KEY_VALUE_BTN, NULL, key, value); + + if (!btn) { + _ERR("add method btn failed."); + return false; + } + } + return true; +} + + +bool CProxyMainView::m_CreateMethodAutoBtn(void) +{ + Evas_Object *box; + box = m->box; + + if(!m_CreateMethodBoxBtn(m->method_btn, _(TXT_MOTHED), _(TXT_MOTHED_AUTO), BTN_ONE_LINE)) { + _ERR("add method btn failed."); + return false; + } + ASSERT(m->method_btn); + //evas_object_smart_callback_add(btn, SIG_CLICKED, _method_btn_clicked_cb, priv); + Connect(m->method_btn, 3); + elm_object_focus_next_object_set(m->method_btn, m->method_btn, ELM_FOCUS_LEFT); + elm_box_pack_end(box, m->method_btn); + + if(!m_CreateMethodBoxBtn(m->url_btn, _(TXT_CONFIG_URL), _(m->url), BTN_TWO_LINE)) { + _ERR("add url btn failed."); + return false; + } + ASSERT(m->url_btn); + //evas_object_smart_callback_add(btn, SIG_CLICKED, _url_btn_clicked_cb, priv); + Connect(m->url_btn, 4); + elm_object_focus_next_object_set(m->url_btn, m->url_btn, ELM_FOCUS_LEFT); + elm_box_pack_end(box, m->url_btn); + + return true; +} + + +bool CProxyMainView::m_CreateMethodManualBtn(void) +{ + Evas_Object *box; + box = m->box; + + if(!m_CreateMethodBoxBtn(m->method_btn, _(TXT_MOTHED), _(TXT_MOTHED_MAN), BTN_ONE_LINE)) { + _ERR("add method btn failed."); + return false; + } + ASSERT(m->method_btn); + //evas_object_smart_callback_add(btn, SIG_CLICKED, _method_btn_clicked_cb, priv); + Connect(m->method_btn, 3); + elm_object_focus_next_object_set(m->method_btn, m->method_btn, ELM_FOCUS_LEFT); + elm_box_pack_end(box, m->method_btn); + + if(!m_CreateMethodBoxBtn(m->proxy_btn, _(TXT_PROXY_IP), _(m->ip), BTN_ONE_LINE)) { + _ERR("add http btn failed."); + return false; + } + ASSERT(m->proxy_btn); + //evas_object_smart_callback_add(btn, SIG_CLICKED, _proxy_ip_btn_clicked_cb, priv); + Connect(m->proxy_btn, 5); + elm_object_focus_next_object_set(m->proxy_btn, m->proxy_btn, ELM_FOCUS_LEFT); + elm_box_pack_end(box, m->proxy_btn); + + return true; +} + + +bool CProxyMainView::m_CreateMethodNoneBtn(void) +{ + Evas_Object *box; + box = m->box; + + if(!m_CreateMethodBoxBtn(m->method_btn, _(TXT_MOTHED), _(TXT_MOTHED_NONE), BTN_ONE_LINE)) { + _ERR("add method btn failed."); + return false; + } + //evas_object_smart_callback_add(btn, SIG_CLICKED, _method_btn_clicked_cb, priv); + Connect(m->method_btn, 3); + elm_object_focus_next_object_set(m->method_btn, m->method_btn, ELM_FOCUS_LEFT); + elm_box_pack_end(m->box, m->method_btn); + + return true; +} + + +bool CProxyMainView::m_CreateDimLayout(void) +{ + Evas_Object *dim_ly; + + dim_ly = util_add_layout(m->base, UG_PROXY_EDJ_FILE, GRP_DIM_LY); + if (!dim_ly) { + _ERR("elm_layout_add() failed."); + return false; + } + + m->dim_ly = dim_ly; + evas_object_hide(m->dim_ly); + + return true; +} + + +bool CProxyMainView::m_CreateActionBtns(void) +{ + Evas_Object *btn; + + btn = util_add_button(m->base, STYLE_ACTION_BTN, PART_OK_BTN, _(TXT_OK)); + if (!btn) { + _ERR("add ok button failed."); + return false; + } + + //evas_object_smart_callback_add(btn, SIG_CLICKED, _ok_btn_clicked_cb, priv); + Connect(btn, 1); + + elm_object_focus_set(btn, EINA_TRUE); + + btn = util_add_button(m->base, STYLE_ACTION_BTN, PART_CANCEL_BTN, _(TXT_CANCEL)); + if (!btn) { + _ERR("add cancel button failed."); + return false; + } + + //evas_object_smart_callback_add(btn, SIG_CLICKED, _cancel_btn_clicked_cb, priv); + Connect(btn, 2); + + return true; +} + + +bool CProxyMainView::m_GetProxyMethod(void) +{ + int value; + int ret; + char *str; + + str = vconf_get_str(VCONF_NETWORK_TYPE); + if (str && !strcmp(str, TXT_WIRED)) + m->net_type = TYPE_WIRED; + else + m->net_type = TYPE_WIRELESS; + + value = 0; + ret = vconf_get_int(VCONF_PROXY_METHOD, &value); + if (ret != true) { + _ERR("vconf_get_int() failed."); + return false; + } + + switch (value) { + case 0: + m->eMethod = PROXY_METHOD_NONE; + break; + case 1: + m->eMethod = PROXY_METHOD_MANUAL; + break; + case 2: + m->eMethod = PROXY_METHOD_AUTO; + break; + default: + return false; + } + + char *ip = NULL; + ip = vconf_get_str(VCONF_PROXY_IP); + if (!ip) + snprintf(m->ip, IP_STRING_LEN, "%s", IP_ZERO); + else + snprintf(m->ip, IP_STRING_LEN, "%s", ip); + + str = vconf_get_str(VCONF_PROXY_URL); + if (!str) + snprintf(m->url, MOTHED_URL_LEN, "%s", URL_BLANK); + else + snprintf(m->url, MOTHED_URL_LEN, "%s", str); + + return true; +} + + +bool CProxyMainView::m_CreateProxyLayout(void) +{ + Evas_Object *box; + int ret; + + box = util_add_box(m->base, PART_PROXY_SETTING); + if (!box) { + _ERR("add box failed."); + return false; + } + + m->box = box; + + switch (m->eMethod) { + case PROXY_METHOD_NONE: + ret = m_CreateMethodNoneBtn(); + if (ret != true) { + _ERR("add method none failed."); + evas_object_del(box); + return false; + } + + break; + case PROXY_METHOD_MANUAL: + ret = m_CreateMethodManualBtn(); + if (ret != true) { + _ERR("add method manual failed."); + evas_object_del(box); + return false; + } + + break; + case PROXY_METHOD_AUTO: + ret = m_CreateMethodAutoBtn(); + if (ret != true) { + _ERR("add method manual failed."); + evas_object_del(box); + return false; + } + + break; + default: + break; + } + + return true; +} + + +void CProxyMainView::t_OnShow() +{ + _DBG(); + + evas_object_show(m->base); + + CBaseView::t_OnShow(); +} + + +void CProxyMainView::t_OnUpdate(void *data) +{ + _DBG(); + + evas_object_show(m->base); + +#if 0 + switch (m->cur_view) { + case NETWORK_IP_SETTING_VIEW: + elm_object_focus_set(m->other_btn, EINA_TRUE); + break; + case NETWORK_WIFI_PASSCODE_VIEW: + elm_object_focus_set(m->connect_btn, EINA_TRUE); + break; + default: + break; + } +#endif +} + + +void CProxyMainView::t_OnHide() +{ + _DBG(); + + evas_object_hide(m->base); + + CBaseView::t_OnHide(); +} + + +bool CProxyMainView::Create(void *data) +{ + _DBG(); + ASSERT(!m); + + _CREATE_BEGIN{ + _CHECK(m = new SProxyMainView) + _CHECK(m->win = CViewMgr::GetInstance()->Window()) + _CHECK(m_InitConnection()) + _CHECK(m->base = m_CreateMainLayout()) + _CHECK(m_GetProxyMethod()) + _CHECK(m_CreateProxyLayout()) + _CHECK(m_CreateActionBtns()) + _CHECK(m_CreateDimLayout()) + + _WHEN_SUCCESS { + elm_object_part_text_set(m->base, PART_PROXY_DESCRITION, _(TXT_PROXY_DESCRIPTION)); + elm_object_focus_set(m->method_btn, EINA_TRUE); + m->pViewMgr = CViewMgr::GetInstance(); + } + + _CHECK_FAIL{/* m_CreateDimLayout() */} + _CHECK_FAIL{/* m_CreateActionBtns() */} + _CHECK_FAIL{/* m_CreateProxyLayout() */} + _CHECK_FAIL{/* m_GetProxyMethod() */} + _CHECK_FAIL{evas_object_del(m->base);} + _CHECK_FAIL{m_FinalizeConnection();} + _CHECK_FAIL{/* m->win = CViewMgr::GetInstance()->Window() */} + _CHECK_FAIL{ delete m; m = NULL; } + } _CREATE_END_AND_CATCH{ return false; } + + return m->base; +} + +void CProxyMainView::Destroy() +{ + ASSERT(m); + _DBG(); + + CBaseView::Destroy(); + delete m; + m = NULL; +} + + +Evas_Object* CProxyMainView::Base() +{ + ASSERT(m); + _DBG(); + + return m->base; +} + + +void CProxyMainView::OnKeyDown(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev) +{ + /* ID list */ + /* 0 m->base */ + /* 1 action ok_btn */ + /* 2 action cancel_btn */ + /* 3 method_btn */ + /* 4 url_btn */ + /* 5 proxy_btn */ + /* 6 ctxpopup */ + /* 7 invalidinfo popup ok_btn */ + /* 8 invalidinfo popup layout */ + /* 9 input entry */ + /* 10 value popup */ + + if (!ev->keyname) { + _ERR("ev->keyname is NULL."); + return; + } + + switch(id) { + case 0: + if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) { + ug_destroy_me(m->ug); + return; + } + break; + case 6: + case 8: + if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) { + evas_object_hide(m->dim_ly); + if (m->ctxpopup) { + evas_object_del(m->ctxpopup); + m->ctxpopup = NULL; + } + } + break; + case 9: + elm_entry_input_panel_show(obj); + + if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) { + if (m->ctxpopup) { + evas_object_del(m->ctxpopup); + m->ctxpopup = NULL; + } + evas_object_hide(m->dim_ly); + } else if (!strcmp(ev->keyname, KEY_PROXY_ENTER)) { + const char *value; + value = elm_entry_entry_get(obj); + elm_object_part_text_set(m->url_btn, PART_VALUE, value); + memset(m->url, 0, MOTHED_URL_LEN + 1); + strncpy(m->url, value, MOTHED_URL_LEN); + + if (m->ctxpopup) { + evas_object_del(m->ctxpopup); + m->ctxpopup = NULL; + } + + elm_object_focus_set(m->url_btn, EINA_TRUE); + evas_object_hide(m->dim_ly); + } + break; + case 10: + if (!strcmp(ev->keyname, KEY_ENTER) || !strcmp(ev->keyname, KEY_ENTER_REMOTE)) { + evas_object_show(m->dim_ly); + m_SetTheValue(); + evas_object_del(obj); + } else if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) { + evas_object_hide(m->dim_ly); + evas_object_del(obj); + } + break; + case 14: + const char *value; + int num, new_num, max_num; + max_num = IP_MAX_NUM; + + if (!strcmp(ev->keyname, KEY_UP)) { + value = elm_object_text_get(obj); + num = atoi(value); + num++; + if (num > max_num) + num = 0; + } else if (!strcmp(ev->keyname, KEY_DOWN)) { + value = elm_object_text_get(obj); + num = atoi(value); + num--; + if (num < 0) + num = max_num; + } else if (!strcmp(ev->keyname, KEY_0) || + !strcmp(ev->keyname, KEY_1) || + !strcmp(ev->keyname, KEY_2) || + !strcmp(ev->keyname, KEY_3) || + !strcmp(ev->keyname, KEY_4) || + !strcmp(ev->keyname, KEY_5) || + !strcmp(ev->keyname, KEY_6) || + !strcmp(ev->keyname, KEY_7) || + !strcmp(ev->keyname, KEY_8) || + !strcmp(ev->keyname, KEY_9)) { + value = elm_object_text_get(obj); + if (!value) + elm_object_text_set(obj, ev->keyname); + + new_num = atoi(ev->keyname); + + num = atoi(value); + if (!num || (num * IP_RATIO + new_num) > max_num) { + elm_object_text_set(obj, ev->keyname); + return; + } + + num = num * IP_RATIO + new_num; + } else { + return; + } + + char temp_value[MOTHED_STRING_LEN]; + + if (!obj) { + _ERR("The param is invalid."); + return; + } + + memset(temp_value, 0, MOTHED_STRING_LEN); + snprintf(temp_value, MOTHED_STRING_LEN - 1, "%d", num); + elm_object_text_set(obj, temp_value); + break; + default: + break; + } +} + + +void CProxyMainView::OnMouseClicked(int id, Evas_Object *obj) +{ + bool ret = false; + + switch(id) { + case 1: + ret = m_SetProxy(); + if (ret != true) { + _ERR("the ip or port is invalid."); + m_ShowInvalidInfoPopup(ret); + return; + } + + vconf_set_int(VCONF_PROXY_METHOD, m->eMethod); + + if (m->eMethod == PROXY_METHOD_MANUAL) { + if (!strncmp(m->ip, IP_ZERO, IP_STRING_LEN)) { + _ERR("IP addr is invalid."); + } + vconf_set_str(VCONF_PROXY_IP, m->ip); + } + else if(m->eMethod == PROXY_METHOD_AUTO) { + vconf_set_str(VCONF_PROXY_URL, m->url); + } + ug_destroy_me(m->ug); + break; + case 2: + ug_destroy_me(m->ug); + break; + case 3: + Evas_Object *ctxpopup; + Evas_Object *box; + Evas_Object *none_btn; + Evas_Object *man_btn; + Evas_Object *auto_btn; + Evas_Object *btn[METHOD_NUM]; + Evas_Coord x; + Evas_Coord y; + Evas_Coord w; + Evas_Coord h; + + ctxpopup = util_add_layout(m->base, UG_PROXY_EDJ_FILE, GRP_METHOD_SETTING); + if (!ctxpopup) { + _ERR("add method ctxpopup failed."); + return; + } + + //evas_object_smart_callback_add(ctxpopup, SIG_UNFOCUSED, _ctxpopup_unfocused_cb, priv); + //evas_object_event_callback_add(ctxpopup, EVAS_CALLBACK_KEY_DOWN, _ctxpopup_key_pressed_cb, priv); + Connect(ctxpopup, 6); + + m->ctxpopup = ctxpopup; + + elm_object_signal_emit(m->method_btn, SIG_BTN_SELECTED, PROG); + evas_object_show(m->dim_ly); + + box = util_add_box(ctxpopup, PART_SWALLOW_CONTENT); + if (!box) { + _ERR("create box failed."); + evas_object_del(ctxpopup); + return; + } + + none_btn = util_add_button(ctxpopup, STYLE_METHOD_SET, NULL, _(TXT_MOTHED_NONE)); + if (!none_btn) { + _ERR("Add btn failed."); + evas_object_del(ctxpopup); + return; + } + //evas_object_smart_callback_add(none_btn, SIG_CLICKED, _method_none_btn_clicked_cb, NULL); + Connect(none_btn, 11); + + elm_box_pack_end(box, none_btn); + elm_object_focus_set(none_btn, EINA_TRUE); + btn[PROXY_METHOD_NONE] = none_btn; + + man_btn = util_add_button(ctxpopup, STYLE_METHOD_SET, NULL, _(TXT_MOTHED_MAN)); + if (!man_btn) { + _ERR("Add btn failed."); + evas_object_del(ctxpopup); + return; + } + //evas_object_smart_callback_add(man_btn, SIG_CLICKED, _method_man_btn_clicked_cb, NULL); + Connect(man_btn, 12); + + elm_box_pack_end(box, man_btn); + btn[PROXY_METHOD_MANUAL] = man_btn; + + auto_btn = util_add_button(ctxpopup, STYLE_METHOD_SET, NULL, _(TXT_MOTHED_AUTO)); + if (!auto_btn) { + _ERR("Add btn failed."); + evas_object_del(ctxpopup); + return; + } + //evas_object_smart_callback_add(auto_btn, SIG_CLICKED, _method_auto_btn_clicked_cb, NULL); + Connect(auto_btn, 13); + elm_box_pack_end(box, auto_btn); + btn[PROXY_METHOD_AUTO] = auto_btn; + m_SetupDownCycleFocus(btn, METHOD_NUM); + m_SetLeftRightCycleFocus(btn, METHOD_NUM); + + switch (m->eMethod) { + case PROXY_METHOD_NONE: + elm_object_signal_emit(none_btn, SIG_BTN_SELECTED, PROG); + break; + case PROXY_METHOD_MANUAL: + elm_object_signal_emit(man_btn, SIG_BTN_SELECTED, PROG); + break; + case PROXY_METHOD_AUTO: + elm_object_signal_emit(auto_btn, SIG_BTN_SELECTED, PROG); + break; + default: + break; + } + + evas_object_geometry_get(m->method_btn, &x, &y, &w, &h); + evas_object_move(ctxpopup, (x + METHOD_CTXPOPUP_OFFSET_X) * ELM_SCALE, (y + ALIGH_RATIO * h + LINE_PAD) * ELM_SCALE); + break; + case 4: + m_CreateInputEntry(); + break; + case 5: + elm_object_signal_emit(m->proxy_btn, SIG_BTN_SELECTED, PROG); + m_CreateValuePopup(); + break; + case 7: + if (m->ctxpopup) { + evas_object_del(m->ctxpopup); + m->ctxpopup = NULL; + } + evas_object_hide(m->dim_ly); + elm_object_focus_set(m->ok_btn, EINA_TRUE); + break; + case 11: + m_MethodBtnClicked(PROXY_METHOD_NONE); + break; + case 12: + m_MethodBtnClicked(PROXY_METHOD_MANUAL); + break; + case 13: + m_MethodBtnClicked(PROXY_METHOD_AUTO); + break; + default: + break; + } +} + + +void CProxyMainView::OnUnfocused(int id, Evas_Object *obj, Elm_Object_Item *item) +{ + switch(id) { + case 0: + break; + case 6: + case 8: + case 10: + evas_object_hide(m->dim_ly); + if (m->ctxpopup) { + evas_object_del(m->ctxpopup); + m->ctxpopup = NULL; + } + break; + default: + break; + } +} diff --git a/ug/proxy/src/main_view.cpp b/ug/proxy/src/main_view.cpp deleted file mode 100644 index 510f151..0000000 --- a/ug/proxy/src/main_view.cpp +++ /dev/null @@ -1,2007 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include "defs.h" -#include "dbg.h" -#include "main_view.h" -#include "i18n.h" -#include "util.h" - -#include "UgCommon.h" -#include "WifiMgr.h" -#include "NetConMgr.h" - -#define KEY_PRIV "priv" -#define KEY_PROXY_ENTER "Select" -#define IP_VALUE1 "value1" -#define IP_VALUE2 "value2" -#define IP_VALUE3 "value3" -#define IP_VALUE4 "value4" - -static const char *VCONF_NETWORK_TYPE = "db/menu/network/network_type"; -static const char *VCONF_PROXY_METHOD = "db/menu/proxy/method"; -static const char *VCONF_PROXY_IP = "db/menu/proxy/ip"; -static const char *VCONF_PROXY_URL = "db/menu/proxy/url"; - -#define METHOD_CTXPOPUP_OFFSET_X 448 -#define VALUE_CTXPOPUP_OFFSET_X 162 -#define VALUE_CTXPOPUP_OFFSET_Y 20 -#define PROXY_CONFIG_MAX_NUM 4 -#define IP_MAX_NUM 255 -#define IP_RATIO 10 -#define PORT_MAX_NUM 65535 -#define PORT_INVALID_NUM 65536 -#define PORT_NO_NEED 65537 -#define CENTER_ALIGN 0.5 -#define CTXPOPUP_WIDTH 688 -#define CTXPOPUP_HEIGHT 411 -#define BTN_ONE_LINE 1 -#define BTN_TWO_LINE 2 -#define LINE_PAD 2 -#define ALIGH_RATIO 1.5 - -enum network_type_enum { - TYPE_WIRELESS = 0, - TYPE_WIRED -}; - -struct _priv { - Evas_Object *win; - ui_gadget_h ug; - - Evas_Object *base; - Evas_Object *dim_ly; - Evas_Object *box; - Evas_Object *method_btn; - Evas_Object *proxy_btn; - Evas_Object *url_btn; - Evas_Object *ok_btn; - Evas_Object *cancel_btn; - Evas_Object *ctxpopup; - Evas_Object *vaule_btns[PROXY_CONFIG_MAX_NUM]; - - enum network_type_enum net_type; - - char ip[IP_STRING_LEN + 1]; - char url[MOTHED_URL_LEN + 1]; - - CWifiMgr *pWifiMgr; - enum EProxyMethod eMethod; - - CNetConMgr *pNetConMgr; -}; - -static int _create_method_none_btn(struct _priv *priv); -static int _create_method_manual_btns(struct _priv *priv); -static int _create_method_auto_btns(struct _priv *priv); - -/** - * Initializes the private data. - * - * Called when the view is loaded. - * - * @return the handler of the private data; - */ -static struct _priv *_init_priv() -{ - bool ret = false; - struct _priv *priv; - - priv = (struct _priv *) calloc(1, sizeof(*priv)); - if (!priv) { - _ERR("calloc priv failed."); - return NULL; - } - - ret = CWifiMgr::Initialize(); - if(ret != true) { - _ERR("Fail to initialize WifiMgr"); - return NULL; - } - priv->pWifiMgr = CWifiMgr::GetInstance(); - if(!priv->pWifiMgr) { - _ERR("Fail to get instance"); - free (priv); - return NULL; - } - - ret = CNetConMgr::Initialize(); - if(ret != true) { - _ERR("Fail to initialize NetConMgr"); - return NULL; - } - - priv->pNetConMgr = CNetConMgr::GetInstance(); - if(!priv->pNetConMgr) { - _ERR("Fail to get instance"); - CWifiMgr::Finalize(); - free (priv); - return NULL; - } - - return priv; -} - -/** - * Deinitializes the private data. - * - * Called when the view is deleted. - * - * @param[in] priv The handler of the private data - */ -static void _fini_priv(struct _priv *priv) -{ - if (!priv) - return; - - if(priv->pNetConMgr) { - CNetConMgr::Finalize(); - priv->pNetConMgr = NULL; - } - - if(priv->pWifiMgr) { - CWifiMgr::Finalize(); - priv->pWifiMgr = NULL; - } - - if (priv->base) - evas_object_del(priv->base); - - free(priv); -} - -/** - * Callback for key pressed event. - * - * If the key is KEY_BACK, destroies the ug. - * - * @param[in] data User data - * @param[in] evas Evas handler - * @param[in] obj The corresponding object which the deletion event occurred - * @param[in] ei Event information - */ -static void _base_key_pressed_cb(void *data, Evas *evas, - Evas_Object *obj, void *ei) -{ - Evas_Event_Key_Down *ev; - struct _priv *priv; - - if (!ei || !data) { - _ERR("The param is invalid.\n"); - return; - } - - ev = (Evas_Event_Key_Down *) ei; - priv = (struct _priv *) data; - - if (!ev->keyname) { - _ERR("ev->keyname is NULL."); - return; - } - - if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) { - ug_destroy_me(priv->ug); - return; - } -} - -/** - * Shows the dim layout. - * - * Called when there is a ctxpopup. - * - * @param[in] priv The handler of the private data - */ -static void _set_layout_dim(struct _priv *priv) -{ - if (!priv || !priv->dim_ly) { - _ERR("The param is invalid.\n"); - return; - } - - evas_object_show(priv->dim_ly); -} - -/** - * Hides the dim layout. - * - * Called when the existing ctxpopup is deleted. - * - * @param[in] priv The handler of the private data - */ -static void _unset_layout_dim(struct _priv *priv) -{ - if (!priv || !priv->dim_ly) { - _ERR("The param is invalid.\n"); - return; - } - - evas_object_hide(priv->dim_ly); -} - -/** - * Sets the cycle focus in the direction of up and down. - * - * Sets the cycle focus for an array of objects. - * - * @param[in] obj The handler of objects - * @param[in] count The count of objects - */ -static void _set_up_down_cycle_focus(Evas_Object **obj, - int count) -{ - int i; - - if (!*obj || !obj) - return; - - for (i = 0; i < count; i++) { - if (i == count - 1) - elm_object_focus_next_object_set(obj[i], obj[0], - ELM_FOCUS_DOWN); - else - elm_object_focus_next_object_set(obj[i], obj[i + 1], - ELM_FOCUS_DOWN); - - if (i == 0) - elm_object_focus_next_object_set(obj[i], obj[count - 1], - ELM_FOCUS_UP); - else - elm_object_focus_next_object_set(obj[i], obj[i - 1], - ELM_FOCUS_UP); - } -} - -/** - * Sets the cycle focus in the direction of left and right. - * - * Sets the cycle focus for an array of objects. - * - * @param[in] obj The handler of objects - * @param[in] count The count of objects - */ -static void _set_left_right_cycle_focus(Evas_Object **obj, int count) -{ - int i; - - if (!obj || !*obj) { - _ERR("the param is invalid."); - return; - } - - for (i = 0; i < count; i++) { - if (i == count - 1) - elm_object_focus_next_object_set(obj[i], - obj[0], ELM_FOCUS_RIGHT); - else - elm_object_focus_next_object_set(obj[i], - obj[i + 1], ELM_FOCUS_RIGHT); - - if (i == 0) - elm_object_focus_next_object_set(obj[i], - obj[count - 1], ELM_FOCUS_LEFT); - else - elm_object_focus_next_object_set(obj[i], - obj[i - 1], ELM_FOCUS_LEFT); - } -} - -/** - * Creates the basic layout of the view. - * - * @param[in] parent The parent object - * @return layout if the operation is successful; NULL if failed; - */ -static Evas_Object *_create_basic_layout(struct _priv *priv) -{ - Evas_Object *base; - - if (!priv || !priv->win) { - _ERR("priv is NULL."); - return NULL; - } - - base = util_add_layout(priv->win, UG_PROXY_EDJ_FILE, GRP_MAIN_VIEW); - if (!base) { - _ERR("elm_layout_add() failed."); - return NULL; - } - - evas_object_event_callback_add(base, EVAS_CALLBACK_KEY_DOWN, - _base_key_pressed_cb, priv); - - evas_object_show(base); - - return base; -} - -/** - * Sets the description. - * - * Sets the description for the proxy setting view. - * - * @param[in] priv The handler of the private data - */ -static void _set_description(struct _priv *priv) -{ - if (!priv || !priv->base) { - _ERR("Parameter error!"); - return; - } - - elm_object_part_text_set(priv->base, PART_PROXY_DESCRITION, - _(TXT_PROXY_DESCRIPTION)); -} - -/** - * Gets proxy IP from vconf. - * - * @param[out] des_ip Destination IP - * @param[in] key_ip The vconf key - */ -static void _get_man_saved_value(char *des_ip, - const char *key_ip) -{ - char *ip; - - if (!des_ip || !key_ip) { - _ERR("Parameter error!"); - return; - } - - ip = vconf_get_str(key_ip); - if (!ip) - snprintf(des_ip, IP_STRING_LEN, "%s", IP_ZERO); - else - snprintf(des_ip, IP_STRING_LEN, "%s", ip); -} - -/** - * Gets the proxy method from vconf. - * - * @param[in] priv The handler of the private data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -static int _get_proxy_method(struct _priv *priv) -{ - int value; - int ret; - char *str; - - if (!priv) { - _ERR("Parameter error!"); - return RET_FAILED; - } - - str = vconf_get_str(VCONF_NETWORK_TYPE); - if (str && !strcmp(str, TXT_WIRED)) - priv->net_type = TYPE_WIRED; - else - priv->net_type = TYPE_WIRELESS; - - value = 0; - ret = vconf_get_int(VCONF_PROXY_METHOD, &value); - if (ret != RET_SUCCESS) { - _ERR("vconf_get_int() failed."); - return RET_FAILED; - } - - switch (value) { - case 0: - priv->eMethod = PROXY_METHOD_NONE; - break; - case 1: - priv->eMethod = PROXY_METHOD_MANUAL; - break; - case 2: - priv->eMethod = PROXY_METHOD_AUTO; - break; - default: - return RET_FAILED; - } - - _get_man_saved_value(priv->ip, VCONF_PROXY_IP); - - str = vconf_get_str(VCONF_PROXY_URL); - if (!str) - snprintf(priv->url, MOTHED_URL_LEN, "%s", URL_BLANK); - else - snprintf(priv->url, MOTHED_URL_LEN, "%s", str); - - return RET_SUCCESS; -} - -/** - * Keeps the focused state for the button. - * - * @param[in] btn The object button - */ -static void _keep_btn_dim_focused(Evas_Object *btn) -{ - if (!btn) { - _ERR("the param is invalid."); - return; - } - - elm_object_signal_emit(btn, SIG_BTN_SELECTED, PROG); -} - -/** -* @Evas_Smart_Cb type callback for handling unfocused event. -* -* When the ctxpopup is unfocused, hide the dim layout, -* and delete the ctxpopup. -* -* @param[in] data User data -* @param[in] o The corresponding object which the focus event occurred -* @param[in] ei Event information -*/ -static void _ctxpopup_unfocused_cb(void *data, - Evas_Object *o, void *ei) -{ - struct _priv *priv; - - if (!data) { - _ERR("Parameter error!"); - return; - } - - priv = (struct _priv *) data; - - _unset_layout_dim(priv); - - if (priv->ctxpopup) { - evas_object_del(priv->ctxpopup); - priv->ctxpopup = NULL; - } -} - -/** - * Creates the method select button. - * - * Uses the style of 'method_select'. - * - * @param[in] base The parent object - * @param[in] txt The text in button - * @param[in] cb The callback for clicked event - * @param[in] data User data - * @return button if the operation is successful; NULL if failed; - */ -static Evas_Object *_create_method_select_btn(Evas_Object *base, - char *txt, Evas_Smart_Cb cb, void *data) -{ - Evas_Object *btn; - - if (!base || !txt || !cb || !data) { - _ERR("The param is invalid.\n"); - return NULL; - } - - btn = util_add_button(base, STYLE_METHOD_SET, NULL, txt); - if (!btn) { - _ERR("Add btn failed.\n"); - return NULL; - } - - evas_object_smart_callback_add(btn, SIG_CLICKED, cb, data); - - return btn; -} - -/** - * Callback for key pressed event. - * - * If the key is KEY_BACK, delete the ctxpopup. - * - * @param[in] data User data - * @param[in] evas Evas handler - * @param[in] o The corresponding object which the deletion event occurred - * @param[in] ei Event information - */ -static void _ctxpopup_key_pressed_cb(void *data, Evas *evas, - Evas_Object *o, void *ei) -{ - Evas_Event_Key_Down *ev; - struct _priv *priv; - - if (!ei || !data) { - _ERR("The param is invalid.\n"); - return; - } - - priv = (struct _priv *) data; - ev = (Evas_Event_Key_Down *) ei; - - if (!ev->keyname) { - _ERR("ev->keyname is NULL."); - return; - } - - if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) { - _unset_layout_dim(priv); - - if (priv->ctxpopup) { - evas_object_del(priv->ctxpopup); - priv->ctxpopup = NULL; - } - } -} - -/** - * Handles the process of clicked event. - * - * According to the method. - * - * @param[in] priv The handler of the private data - * @param[in] method The proxy method - */ -static void _method_btn_click_proc(struct _priv *priv, - enum EProxyMethod method) -{ - if (!priv) { - _ERR("The param is invalid.\n"); - return; - } - - if (priv->ctxpopup) { - evas_object_del(priv->ctxpopup); - priv->ctxpopup = NULL; - } - - priv->eMethod = method; - - elm_box_clear(priv->box); - - priv->method_btn = NULL; - priv->proxy_btn= NULL; - priv->url_btn = NULL; - - switch (priv->eMethod) { - case PROXY_METHOD_NONE: - _create_method_none_btn(priv); - break; - case PROXY_METHOD_MANUAL: - _create_method_manual_btns(priv); - break; - case PROXY_METHOD_AUTO: - _create_method_auto_btns(priv); - break; - default: - break; - } - - elm_object_focus_set(priv->method_btn, EINA_TRUE); - -} - -/** -* @Evas_Smart_Cb type callback for handling clicked event. -* -* For the 'METHOD_NONE' button. -* -* @param[in] data User data -* @param[in] obj The corresponding object which the focus event occurred -* @param[in] ev Event information -*/ -static void _method_none_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) -{ - struct _priv *priv; - - if (!data || !obj) { - _ERR("The param is invalid.\n"); - return; - } - - priv = (struct _priv *) data; - - _method_btn_click_proc(priv, PROXY_METHOD_NONE); -} - -/** -* @Evas_Smart_Cb type callback for handling clicked event. -* -* For the 'METHOD_MAN' button. -* -* @param[in] data User data -* @param[in] obj The corresponding object which the focus event occurred -* @param[in] ev Event information -*/ -static void _method_man_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) -{ - struct _priv *priv; - - if (!data || !obj) { - _ERR("The param is invalid.\n"); - return; - } - - priv = (struct _priv *) data; - - _method_btn_click_proc(priv, PROXY_METHOD_MANUAL); -} - -/** -* @Evas_Smart_Cb type callback for handling clicked event. -* -* For the 'METHOD_AUTO' button. -* -* @param[in] data User data -* @param[in] obj The corresponding object which the focus event occurred -* @param[in] ev Event information -*/ -static void _method_auto_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) -{ - struct _priv *priv; - - if (!data || !obj) { - _ERR("The param is invalid.\n"); - return; - } - - priv = (struct _priv *) data; - - _method_btn_click_proc(priv, PROXY_METHOD_AUTO); -} - -/** -* @Evas_Smart_Cb type callback for handling clicked event. -* -* For the method select button. -* -* @param[in] data User data -* @param[in] obj The corresponding object which the focus event occurred -* @param[in] ev Event information -*/ -static void _method_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) -{ - struct _priv *priv; - Evas_Object *base; - Evas_Object *ctxpopup; - Evas_Object *box; - Evas_Object *none_btn; - Evas_Object *man_btn; - Evas_Object *auto_btn; - Evas_Object *btn[METHOD_NUM]; - Evas_Coord x; - Evas_Coord y; - Evas_Coord w; - Evas_Coord h; - - if (!data || !obj) { - _ERR("The param is invalid.\n"); - return; - } - - priv = (struct _priv *) data; - base = priv->base; - - ctxpopup = util_add_layout(base, UG_PROXY_EDJ_FILE, - GRP_METHOD_SETTING); - if (!ctxpopup) { - _ERR("add method ctxpopup failed.\n"); - return; - } - - evas_object_smart_callback_add(ctxpopup, SIG_UNFOCUSED, - _ctxpopup_unfocused_cb, priv); - evas_object_event_callback_add(ctxpopup, EVAS_CALLBACK_KEY_DOWN, - _ctxpopup_key_pressed_cb, priv); - - priv->ctxpopup = ctxpopup; - - _keep_btn_dim_focused(priv->method_btn); - _set_layout_dim(priv); - - box = util_add_box(ctxpopup, PART_SWALLOW_CONTENT); - if (!box) { - _ERR("create box failed."); - evas_object_del(ctxpopup); - return; - } - - none_btn = _create_method_select_btn(ctxpopup, _(TXT_MOTHED_NONE), - _method_none_btn_clicked_cb, priv); - if (!none_btn) { - _ERR("Add btn failed.\n"); - evas_object_del(ctxpopup); - return; - } - - elm_box_pack_end(box, none_btn); - elm_object_focus_set(none_btn, EINA_TRUE); - btn[PROXY_METHOD_NONE] = none_btn; - - man_btn = _create_method_select_btn(ctxpopup, _(TXT_MOTHED_MAN), - _method_man_btn_clicked_cb, priv); - if (!man_btn) { - _ERR("Add btn failed.\n"); - evas_object_del(ctxpopup); - return; - } - - elm_box_pack_end(box, man_btn); - btn[PROXY_METHOD_MANUAL] = man_btn; - - auto_btn = _create_method_select_btn(ctxpopup, _(TXT_MOTHED_AUTO), - _method_auto_btn_clicked_cb, priv); - if (!auto_btn) { - _ERR("Add btn failed.\n"); - evas_object_del(ctxpopup); - return; - } - - elm_box_pack_end(box, auto_btn); - btn[PROXY_METHOD_AUTO] = auto_btn; - - _set_up_down_cycle_focus(btn, METHOD_NUM); - _set_left_right_cycle_focus(btn, METHOD_NUM); - - switch (priv->eMethod) { - case PROXY_METHOD_NONE: - elm_object_signal_emit(none_btn, SIG_BTN_SELECTED, PROG); - break; - case PROXY_METHOD_MANUAL: - elm_object_signal_emit(man_btn, SIG_BTN_SELECTED, PROG); - break; - case PROXY_METHOD_AUTO: - elm_object_signal_emit(auto_btn, SIG_BTN_SELECTED, PROG); - break; - default: - break; - } - - evas_object_geometry_get(priv->method_btn, &x, &y, &w, &h); - evas_object_move(ctxpopup, (x + METHOD_CTXPOPUP_OFFSET_X) * ELM_SCALE, - (y + ALIGH_RATIO * h + LINE_PAD) * ELM_SCALE); -} - -/** - * Gets the position of IP value ctxpopup. - * - * @param[in] priv The handler of the private data - * @param[out] pos_x X position - * @param[out] pos_y Y position - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -static int _get_value_popup_pos(struct _priv *priv, - Evas_Coord *pos_x, Evas_Coord *pos_y) -{ - Evas_Coord x; - Evas_Coord y; - - if (!priv || !pos_x || !pos_y) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - evas_object_geometry_get(priv->proxy_btn, &x, &y, NULL, NULL); - *pos_x = x + VALUE_CTXPOPUP_OFFSET_X; - *pos_y = y - VALUE_CTXPOPUP_OFFSET_Y; - - return RET_SUCCESS; -} - -/** - * Sets the number to the object text. - * - * @param[in] obj The handler of the object - * @param[in] num The number - */ -static void _set_btn_vaule(Evas_Object *obj, int num) -{ - char value[MOTHED_STRING_LEN]; - - if (!obj) { - _ERR("The param is invalid."); - return; - } - - memset(value, 0, MOTHED_STRING_LEN); - snprintf(value, MOTHED_STRING_LEN - 1, "%d", num); - elm_object_text_set(obj, value); -} - -/** - * Callback for key pressed event. - * - * If the key is KEY_UP, increase the value. - * If the key is KEY_DOWN, decrease the value. - * If the key is a number, append the number. - * - * @param[in] data User data - * @param[in] evas Evas handler - * @param[in] obj The corresponding object which the deletion event occurred - * @param[in] ei Event information - */ -static void _value_key_pressed_cb(void *data, Evas *evas, - Evas_Object *obj, void *ei) -{ - Evas_Event_Key_Down *ev; - const char *value; - int num, new_num, max_num; - - if (!ei || !data || !obj) { - _ERR("The param is invalid.\n"); - return; - } - - ev = (Evas_Event_Key_Down *) ei; - - if (!ev->keyname) { - _ERR("ev->keyname is NULL."); - return; - } - - max_num = IP_MAX_NUM; - - if (!strcmp(ev->keyname, KEY_UP)) { - value = elm_object_text_get(obj); - num = atoi(value); - num++; - if (num > max_num) - num = 0; - } else if (!strcmp(ev->keyname, KEY_DOWN)) { - value = elm_object_text_get(obj); - num = atoi(value); - num--; - if (num < 0) - num = max_num; - } else if (!strcmp(ev->keyname, KEY_0) || - !strcmp(ev->keyname, KEY_1) || - !strcmp(ev->keyname, KEY_2) || - !strcmp(ev->keyname, KEY_3) || - !strcmp(ev->keyname, KEY_4) || - !strcmp(ev->keyname, KEY_5) || - !strcmp(ev->keyname, KEY_6) || - !strcmp(ev->keyname, KEY_7) || - !strcmp(ev->keyname, KEY_8) || - !strcmp(ev->keyname, KEY_9)) { - value = elm_object_text_get(obj); - if (!value) - elm_object_text_set(obj, ev->keyname); - - new_num = atoi(ev->keyname); - - num = atoi(value); - if (!num || (num * IP_RATIO + new_num) > max_num) { - elm_object_text_set(obj, ev->keyname); - return; - } - - num = num * IP_RATIO + new_num; - } else { - return; - } - - _set_btn_vaule(obj, num); -} - -/** - * Creates the value button for IP setting. - * - * @param[in] parent The parent object - * @param[in] num The sequence number of the button - * @param[in] txt The text in the button - * @param[in] data User data - * @return button if the operation is successful; NULL if failed; - */ -static Evas_Object *_create_value_btn(Evas_Object *parent, int num, - char *txt, void *data) -{ - Evas_Object *btn; - - if (!parent || !txt || !data) { - _ERR("The param is invalid.\n"); - return NULL; - } - - btn = util_add_button(parent, STYLE_VALUE_BTN, NULL, txt); - if (!btn) { - _ERR("add button failed.\n"); - return NULL; - } - - switch (num) { - case 0: - elm_object_part_content_set(parent, PART_IP_FIRST, btn); - evas_object_data_set(parent, IP_VALUE1, btn); - elm_object_focus_set(btn, EINA_TRUE); - break; - case 1: - elm_object_part_content_set(parent, PART_IP_SECOND, btn); - evas_object_data_set(parent, IP_VALUE2, btn); - break; - case 2: - elm_object_part_content_set(parent, PART_IP_THIRD, btn); - evas_object_data_set(parent, IP_VALUE3, btn); - break; - case 3: - elm_object_part_content_set(parent, PART_IP_FORTH, btn); - evas_object_data_set(parent, IP_VALUE4, btn); - break; - default: - break; - } - - evas_object_event_callback_add(btn, EVAS_CALLBACK_KEY_DOWN, - _value_key_pressed_cb, data); - elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_UP); - elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_DOWN); - - return btn; -} - -/** - * Sets the value to the object text. - * - * @param[in] priv The handler of the private data - */ -static void _set_the_value(struct _priv *priv) -{ - Evas_Object *btn; - const char *value1; - const char *value2; - const char *value3; - const char *value4; - char ip[IP_STRING_LEN + 1]; - - if (!priv || !priv->ctxpopup) { - _ERR("The param is invalid.\n"); - return; - } - - value1 = NULL; - btn = (Evas_Object *) evas_object_data_get(priv->ctxpopup, IP_VALUE1); - if (btn) - value1 = elm_object_text_get(btn); - - value2 = NULL; - btn = (Evas_Object *) evas_object_data_get(priv->ctxpopup, IP_VALUE2); - if (btn) - value2 = elm_object_text_get(btn); - - value3 = NULL; - btn = (Evas_Object *) evas_object_data_get(priv->ctxpopup, IP_VALUE3); - if (btn) - value3 = elm_object_text_get(btn); - - value4 = NULL; - btn = (Evas_Object *) evas_object_data_get(priv->ctxpopup, IP_VALUE4); - if (btn) - value4 = elm_object_text_get(btn); - - memset(ip, 0, IP_STRING_LEN + 1); - snprintf(ip, IP_STRING_LEN, "%s.%s.%s.%s", - value1 ? value1 : "\\0", value2 ? value2 : "\\0", - value3 ? value3 : "\\0", value4 ? value4 : "\\0"); - - strncpy(priv->ip, ip, IP_STRING_LEN); - elm_object_part_text_set(priv->proxy_btn, PART_VALUE, ip); - - evas_object_del(priv->ctxpopup); - priv->ctxpopup = NULL; -} - -/** - * Callback for key pressed event. - * - * If the key is KEY_BACK, delete the IP value ctxpopup. - * If the key is KEY_ENTER, set the value into the button. - * - * @param[in] data User data - * @param[in] evas Evas handler - * @param[in] obj The corresponding object which the deletion event occurred - * @param[in] ei Event information - */ -static void _value_ctxpopup_key_pressed_cb(void *data, Evas *evas, - Evas_Object *obj, void *ei) -{ - Evas_Event_Key_Down *ev; - struct _priv *priv; - - if (!ei || !data) { - _ERR("The param is invalid.\n"); - return; - } - - ev = (Evas_Event_Key_Down *) ei; - priv = (struct _priv *) data; - - if (!ev->keyname) { - _ERR("ev->keyname is NULL."); - return; - } - - if (!strcmp(ev->keyname, KEY_ENTER) || !strcmp(ev->keyname, KEY_ENTER_REMOTE)) { - _unset_layout_dim(priv); - _set_the_value(priv); - evas_object_del(obj); - } else if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) { - _unset_layout_dim(priv); - evas_object_del(obj); - } -} - -/** - * Creates value ctxpopup. - * - * User can set number in the ctxpopup. - * - * @param[in] priv The handler of the private data - */ -static void _create_value_popup(struct _priv *priv) -{ - Evas_Object *base; - Evas_Object *ctxpopup; - Evas_Object *btn; - Evas_Coord pos_x; - Evas_Coord pos_y; - int i; - - if (!priv || !priv->base) { - _ERR("The param is invalid.\n"); - return; - } - - base = priv->base; - - ctxpopup = util_add_layout(base, UG_PROXY_EDJ_FILE, - GRP_PROXY_VALUE_SETTING); - if (!ctxpopup) { - _ERR("elm_ctxpopup_add() failed.\n"); - return; - } - - priv->ctxpopup = ctxpopup; - - _set_layout_dim(priv); - - for (i = 0; i < PROXY_CONFIG_MAX_NUM; i++) { - btn = _create_value_btn(ctxpopup, i, _(TXT_ZERO), priv); - if (!btn) { - _ERR("_create_value_btn() failed.\n"); - evas_object_del(ctxpopup); - return; - } - - priv->vaule_btns[i] = btn; - } - - elm_object_part_text_set(ctxpopup, PART_TXT_SEPERATOR, _(TXT_COLON)); - evas_object_smart_callback_add(ctxpopup, SIG_UNFOCUSED, - _ctxpopup_unfocused_cb, priv); - evas_object_event_callback_add(ctxpopup, EVAS_CALLBACK_KEY_DOWN, - _value_ctxpopup_key_pressed_cb, priv); - _set_left_right_cycle_focus(priv->vaule_btns, PROXY_CONFIG_MAX_NUM); - - pos_x = 0; - pos_y = 0; - _get_value_popup_pos(priv, &pos_x, &pos_y); - evas_object_move(ctxpopup, pos_x * ELM_SCALE, pos_y * ELM_SCALE); -} - -/** -* @Evas_Smart_Cb type callback for handling clicked event. -* -* After the proxy button is clicked, the value ctxpopup -* will be created to set the value. -* -* @param[in] data User data -* @param[in] obj The corresponding object which the focus event occurred -* @param[in] ev Event information -*/ -static void _proxy_ip_btn_clicked_cb(void *data, - Evas_Object *obj, void *ev) -{ - struct _priv *priv; - - if (!data || !obj) { - _ERR("The param is invalid.\n"); - return; - } - - priv = (struct _priv *) data; - - _keep_btn_dim_focused(priv->proxy_btn); - - _create_value_popup(priv); -} - -/** - * Callback for key pressed event. - * - * If the key is 'Select', save the passcode. - * If the key is KEY_BACK, delete the layout. - * - * @param[in] data User data - * @param[in] e Evas handler - * @param[in] obj The corresponding object which the deletion event occurred - * @param[in] ei Event information - */ -static void _entry_key_pressed_cb(void *data, Evas *e, - Evas_Object *obj, void *ei) -{ - Evas_Event_Key_Down *ev; - struct _priv *priv; - const char *value; - - if (!data || !ei) { - _ERR("Parameter error!"); - return; - } - - priv = (struct _priv *) data; - ev = (Evas_Event_Key_Down *) ei; - - if (!ev->keyname) { - _ERR("ev->keyname is NULL."); - return; - } - - elm_entry_input_panel_show(obj); - - if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) { - if (priv->ctxpopup) { - evas_object_del(priv->ctxpopup); - priv->ctxpopup = NULL; - } - - _unset_layout_dim(priv); - } else if (!strcmp(ev->keyname, KEY_PROXY_ENTER)) { - value = elm_entry_entry_get(obj); - elm_object_part_text_set(priv->url_btn, PART_VALUE, value); - memset(priv->url, 0, MOTHED_URL_LEN + 1); - strncpy(priv->url, value, MOTHED_URL_LEN); - - if (priv->ctxpopup) { - evas_object_del(priv->ctxpopup); - priv->ctxpopup = NULL; - } - - elm_object_focus_set(priv->url_btn, EINA_TRUE); - - _unset_layout_dim(priv); - } -} - -/** - * Creates the entry to input passcode. - * - * @param[in] priv The handler of the private data - */ -static void _create_input_entry(struct _priv *priv) -{ - Evas_Object *entry; - Evas_Object *layout; - - if (!priv || !priv->base) { - _ERR("the param is NULL."); - return; - } - - if (priv->ctxpopup) { - evas_object_del(priv->ctxpopup); - priv->ctxpopup = NULL; - } - - layout = util_add_layout(priv->base, UG_PROXY_EDJ_FILE, - GRP_ENTRY_POPUP); - if (!layout) { - _ERR("create layout fail.\n"); - return; - } - - entry = util_add_entry(layout, STYLE_ENTRY, PART_ENTRY); - if (!entry) { - _ERR("add entry failed."); - evas_object_del(layout); - return; - } - - util_set_focus_next_self(entry); - evas_object_event_callback_add(entry, EVAS_CALLBACK_KEY_DOWN, - _entry_key_pressed_cb, priv); - elm_object_focus_set(entry, EINA_TRUE); - - _set_layout_dim(priv); - - priv->ctxpopup = layout; -} - -/** -* @Evas_Smart_Cb type callback for handling clicked event. -* -* After the URL button is clicked, the layout will be - * created to input the passcode. -* -* @param[in] data User data -* @param[in] obj The corresponding object which the focus event occurred -* @param[in] ev Event information -*/ -static void _url_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) -{ - struct _priv *priv; - - if (!data || !obj) { - _ERR("The param is invalid.\n"); - return; - } - - priv = (struct _priv *) data; - - _create_input_entry(priv); -} - -/** - * Creates the method button. - * - * The common API for method button. - * - * @param[in] priv The handler of the private data - * @param[in] btn The handle of the button to be created - * @param[in] key The key value - * @param[in] value The value - * @param[in] line The number of lines - * @param[in] cb The callback for clicked event - * @return button if the operation is successful; NULL if failed; - */ -static Evas_Object *_create_method_box_btn(struct _priv *priv, Evas_Object *btn, - const char *key, char *value, int line, Evas_Smart_Cb cb) -{ - if (!priv || !priv->box || !key || !value || !cb) { - _ERR("Parameter error!"); - return NULL; - } - - if (btn) { - evas_object_show(btn); - elm_object_part_text_set(btn, PART_VALUE, value); - } else { - if (line == BTN_TWO_LINE) - btn = util_add_key_value_button(priv->box, - STYLE_KEY_VALUE_TWO_LINES, - NULL, key, value); - else - btn = util_add_key_value_button(priv->box, - STYLE_KEY_VALUE_BTN, NULL, key, value); - if (!btn) { - _ERR("add method btn failed."); - return NULL; - } - - evas_object_smart_callback_add(btn, SIG_CLICKED, cb, priv); - } - - elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_LEFT); - - return btn; -} - -/** - * Creates method none button. - * - * @param[in] priv The handler of the private data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -static int _create_method_none_btn(struct _priv *priv) -{ - Evas_Object *box; - Evas_Object *btn; - - if (!priv || !priv->box) { - _ERR("Parameter error!"); - return RET_FAILED; - } - - box = priv->box; - - btn = _create_method_box_btn(priv, priv->method_btn, - _(TXT_MOTHED), _(TXT_MOTHED_NONE), - BTN_ONE_LINE, _method_btn_clicked_cb); - if (!btn) { - _ERR("add method btn failed."); - return RET_FAILED; - } - - elm_box_pack_end(box, btn); - - priv->method_btn = btn; - - return RET_SUCCESS; -} - -/** - * Creates method manual button. - * - * @param[in] priv The handler of the private data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -static int _create_method_manual_btns(struct _priv *priv) -{ - Evas_Object *box; - Evas_Object *btn; - - if (!priv || !priv->box) { - _ERR("Parameter error!"); - return RET_FAILED; - } - - box = priv->box; - - btn = _create_method_box_btn(priv, priv->method_btn, - _(TXT_MOTHED), _(TXT_MOTHED_MAN), - BTN_ONE_LINE, _method_btn_clicked_cb); - if (!btn) { - _ERR("add method btn failed."); - return RET_FAILED; - } - - elm_box_pack_end(box, btn); - priv->method_btn = btn; - - btn = _create_method_box_btn(priv, priv->proxy_btn, - _(TXT_PROXY_IP), _(priv->ip), - BTN_ONE_LINE, _proxy_ip_btn_clicked_cb); - if (!btn) { - _ERR("add http btn failed."); - return RET_FAILED; - } - - elm_box_pack_end(box, btn); - priv->proxy_btn = btn; - - return RET_SUCCESS; -} - -/** - * Creates method auto button. - * - * @param[in] priv The handler of the private data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -static int _create_method_auto_btns(struct _priv *priv) -{ - Evas_Object *box; - Evas_Object *btn; - - if (!priv || !priv->box) { - _ERR("Parameter error!"); - return RET_FAILED; - } - - box = priv->box; - - btn = _create_method_box_btn(priv, priv->method_btn, - _(TXT_MOTHED), _(TXT_MOTHED_AUTO), - BTN_ONE_LINE, _method_btn_clicked_cb); - if (!btn) { - _ERR("add method btn failed."); - return RET_FAILED; - } - - elm_box_pack_end(box, btn); - priv->method_btn = btn; - - btn = _create_method_box_btn(priv, priv->url_btn, - _(TXT_CONFIG_URL), _(priv->url), - BTN_TWO_LINE, _url_btn_clicked_cb); - if (!btn) { - _ERR("add url btn failed."); - return RET_FAILED; - } - - elm_box_pack_end(box, btn); - priv->url_btn = btn; - - return RET_SUCCESS; -} - -/** - * Creates the proxy layout. - * - * @param[in] priv The handler of the private data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -static int _create_proxy_ly(struct _priv *priv) -{ - Evas_Object *base; - Evas_Object *box; - int ret; - - if (!priv || !priv->base) { - _ERR("Parameter error!"); - return RET_FAILED; - } - - base = priv->base; - - box = util_add_box(base, PART_PROXY_SETTING); - if (!box) { - _ERR("add box failed."); - return RET_FAILED; - } - - priv->box = box; - - switch (priv->eMethod) { - case PROXY_METHOD_NONE: - ret = _create_method_none_btn(priv); - if (ret != RET_SUCCESS) { - _ERR("add method none failed."); - goto error; - } - - break; - case PROXY_METHOD_MANUAL: - ret = _create_method_manual_btns(priv); - if (ret != RET_SUCCESS) { - _ERR("add method manual failed."); - goto error; - } - - break; - case PROXY_METHOD_AUTO: - ret = _create_method_auto_btns(priv); - if (ret != RET_SUCCESS) { - _ERR("add method manual failed."); - goto error; - } - - break; - default: - break; - } - - return RET_SUCCESS; - -error: - evas_object_del(box); - - return RET_FAILED; -} - -/** - * Checks if IP is valid. - * - * Now only check if IP is '0.0.0.0'. - * - * @param[in] priv The handler of the private data - * @return RET_SUCCESS if the operation is successful; - * RET_IP_INVALID if the IP is '0.0.0.0'; RET_FAILED if failed; - */ -static int _check_ip_is_valid(struct _priv *priv) -{ - if (!priv) { - _ERR("The param is NULL.\n"); - return RET_FAILED; - } - - if (!strncmp(priv->ip, IP_ZERO, IP_STRING_LEN)) { - _ERR("IP addr is invalid."); - return RET_IP_INVALID; - } - - return RET_SUCCESS; -} - -/** -* @Evas_Smart_Cb type callback for handling clicked event. -* -* When the 'OK' button is clicked, delete the popup, -* and set the default focus. -* -* @param[in] data User data -* @param[in] obj The corresponding object which the focus event occurred -* @param[in] event Event information -*/ -static void _ctxpopup_ok_btn_clicked_cb(void *data, - Evas_Object *obj, void *event) -{ - struct _priv *priv; - - if (!data) { - _ERR("Parameter error!"); - return; - } - - priv = (struct _priv *) data; - - if (priv->ctxpopup) { - evas_object_del(priv->ctxpopup); - priv->ctxpopup = NULL; - } - - _unset_layout_dim(priv); - - elm_object_focus_set(priv->ok_btn, EINA_TRUE); -} - -/** - * Shows the invalid IP ctxpopup according to return value. - * - * @param[in] priv The handler of the private data - * @param[in] ret The return value from - */ -static void _show_invalid_info_ctxpopup(struct _priv *priv, int ret) -{ - Evas_Object *layout; - Evas_Object *btn; - Evas_Coord w; - Evas_Coord h; - - if (!priv) { - _ERR("The param is NULL.\n"); - return; - } - - if (priv->ctxpopup) { - evas_object_del(priv->ctxpopup); - priv->ctxpopup = NULL; - } - - _set_layout_dim(priv); - - layout = util_add_layout(priv->base, UG_PROXY_EDJ_FILE, - GRP_CONFIRM_LAYOUT); - if (!layout) { - _ERR("add layout failed."); - _unset_layout_dim(priv); - return; - } - - switch (priv->eMethod) { - case PROXY_METHOD_MANUAL: - elm_object_part_text_set(layout, PART_TEXT_TITLE, - _(TXT_MANUAL_TITLE)); - break; - case PROXY_METHOD_AUTO: - elm_object_part_text_set(layout, PART_TEXT_TITLE, - _(TXT_AUTO_TITLE)); - break; - default: - evas_object_del(layout); - _unset_layout_dim(priv); - return; - } - - elm_object_part_text_set(layout, PART_TEXT_TITLE, _(TXT_MANUAL_TITLE)); - - if (ret == RET_IP_INVALID) - elm_object_part_text_set(layout, - PART_TEXT_CONTENT, _(TXT_IP_INVALID)); - else if (ret == RET_VCONF_FAILED) - elm_object_part_text_set(layout, - PART_TEXT_CONTENT, _(TXT_VCONF_FAILED)); - else if (ret == RET_WIRED_PROXY_FAILED) - elm_object_part_text_set(layout, - PART_TEXT_CONTENT, _(TXT_WIRED_FAILED)); - else if (ret == RET_WIRELESS_PROXY_FAILED) - elm_object_part_text_set(layout, - PART_TEXT_CONTENT, _(TXT_WIRELESS_FAILED)); - - btn = util_add_button(layout, - STYLE_ACTION_BTN, PART_OK_BTN, _(TXT_OK)); - if (!btn) { - _ERR("util add button failed."); - evas_object_del(layout); - _unset_layout_dim(priv); - return; - } - - elm_object_focus_set(btn, EINA_TRUE); - elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_RIGHT); - elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_LEFT); - elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_UP); - elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_DOWN); - evas_object_smart_callback_add(btn, SIG_CLICKED, - _ctxpopup_ok_btn_clicked_cb, priv); - - evas_object_smart_callback_add(layout, SIG_UNFOCUSED, - _ctxpopup_unfocused_cb, priv); - evas_object_event_callback_add(layout, EVAS_CALLBACK_KEY_DOWN, - _ctxpopup_key_pressed_cb, priv); - - w = DEFAULT_WIN_WIDTH; - h = DEFAULT_WIN_HEIGHT; - - evas_object_move(layout, - CENTER_ALIGN * (w - CTXPOPUP_WIDTH) * ELM_SCALE, - CENTER_ALIGN * (h - CTXPOPUP_HEIGHT) * ELM_SCALE); - - priv->ctxpopup = layout; -} - -/** - * Saves the proxy information to vconf. - * - * @param[in] priv The handler of the private data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -static int _save_to_vconf(struct _priv *priv) -{ - if (!priv) { - _ERR("The param is invalid.\n"); - return RET_SUCCESS; - } - - vconf_set_int(VCONF_PROXY_METHOD, priv->eMethod); - - switch (priv->eMethod) { - case PROXY_METHOD_NONE: - break; - case PROXY_METHOD_MANUAL: - _check_ip_is_valid(priv); - - vconf_set_str(VCONF_PROXY_IP, priv->ip); - - break; - case PROXY_METHOD_AUTO: - vconf_set_str(VCONF_PROXY_URL, priv->url); - - break; - default: - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Sets the proxy information with connection api. - * - * @param[in] priv The handler of the private data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -static int _set_connection_proxy(struct _priv *priv) -{ - bool ret; - - if (!priv) { - _ERR("The param is invalid.\n"); - return RET_FAILED; - } - - ret = priv->pNetConMgr->SetProxyType(priv->eMethod); - if (ret != true) { - _ERR("wifi_mgr_get_proxy_type() failed."); - return RET_FAILED; - } - - switch (priv->eMethod) { - case PROXY_METHOD_NONE: - break; - case PROXY_METHOD_MANUAL: - if (priv->ip) - priv->pNetConMgr->SetProxyAddr(priv->ip); - break; - case PROXY_METHOD_AUTO: - if (priv->url) - priv->pNetConMgr->SetProxyAddr(priv->url); - break; - default: - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Sets the proxy information with wifi api. - * - * @param[in] priv The handler of the private data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -static int _set_wifi_proxy(struct _priv *priv) -{ - int ret; - - if (!priv) { - _ERR("The param is invalid."); - return RET_FAILED; - } - - if (!priv->pWifiMgr) { - _ERR("WifiMgr is not initialized."); - return RET_FAILED; - } - - ret = priv->pWifiMgr->SetProxyType(priv->eMethod); - if (ret != RET_SUCCESS) { - _ERR("wifi_mgr_get_proxy_type() failed."); - return ret; - } - - switch (priv->eMethod) { - case PROXY_METHOD_NONE: - priv->pWifiMgr->SetProxyAddr(NULL); - break; - case PROXY_METHOD_MANUAL: - if (priv->ip) - priv->pWifiMgr->SetProxyAddr(priv->ip); - break; - case PROXY_METHOD_AUTO: - if (priv->url) - priv->pWifiMgr->SetProxyAddr(priv->url); - break; - default: - return RET_FAILED; - } - - return RET_SUCCESS; -} - -/** - * Sets the proxy information. - * - * @param[in] priv The handler of the private data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -static int _set_proxy(struct _priv *priv) -{ - int ret; - - if (!priv) { - _ERR("The param is invalid.\n"); - return RET_FAILED; - } - - if (priv->net_type == TYPE_WIRED) { - ret = _set_connection_proxy(priv); - if (ret != RET_SUCCESS) { - _ERR("the ip or port is invalid."); - return ret; - } - } else if (priv->net_type == TYPE_WIRELESS) { - ret = _set_wifi_proxy(priv); - if (ret != RET_SUCCESS) { - _ERR("the ip or port is invalid."); - return ret; - } - } - - return RET_SUCCESS; -} - -/** -* @Evas_Smart_Cb type callback for handling clicked event. -* -* When the 'OK' button is clicked, save the proxy information, -* and destroy the ug. -* -* @param[in] data User data -* @param[in] obj The corresponding object which the focus event occurred -* @param[in] ev Event information -*/ -static void _ok_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) -{ - struct _priv *priv; - int ret; - - if (!data || !obj) { - _ERR("The param is invalid.\n"); - return; - } - - priv = (struct _priv *) data; - - ret = _set_proxy(priv); - if (ret != RET_SUCCESS) { - _ERR("the ip or port is invalid."); - _show_invalid_info_ctxpopup(priv, ret); - return; - } - - ret = _save_to_vconf(priv); - if (ret != RET_SUCCESS) { - _ERR("the ip or port is invalid."); - _show_invalid_info_ctxpopup(priv, ret); - return; - } - - ug_destroy_me(priv->ug); -} - -/** -* @Evas_Smart_Cb type callback for handling clicked event. -* -* When the 'OK' button is clicked, don't save the proxy information, -* and destroy the ug. -* -* @param[in] data User data -* @param[in] obj The corresponding object which the focus event occurred -* @param[in] ev Event information -*/ -static void _cancel_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) -{ - struct _priv *priv; - - if (!data || !obj) { - _ERR("The param is invalid.\n"); - return; - } - - priv = (struct _priv *) data; - - ug_destroy_me(priv->ug); -} - -/** - * Creates the action buttons. - * - * @param[in] priv The handler of the private data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -static int _create_action_btns(struct _priv *priv) -{ - Evas_Object *base; - Evas_Object *btn; - - if (!priv || !priv->base) { - _ERR("Parameter error!"); - return RET_FAILED; - } - - base = priv->base; - - btn = util_add_button(base, STYLE_ACTION_BTN, PART_OK_BTN, _(TXT_OK)); - if (!btn) { - _ERR("add ok button failed."); - return RET_FAILED; - } - - evas_object_smart_callback_add(btn, SIG_CLICKED, - _ok_btn_clicked_cb, priv); - - elm_object_focus_set(btn, EINA_TRUE); - - btn = util_add_button(base, STYLE_ACTION_BTN, - PART_CANCEL_BTN, _(TXT_CANCEL)); - if (!btn) { - _ERR("add cancel button failed."); - return RET_FAILED; - } - - evas_object_smart_callback_add(btn, SIG_CLICKED, - _cancel_btn_clicked_cb, priv); - - return RET_SUCCESS; -} - -/** - * Creates the dim layout. - * - * @param[in] priv The handler of the private data - * @return RET_SUCCESS if the operation is successful; RET_FAILED if failed; - */ -static int _create_dim_layout(struct _priv *priv) -{ - Evas_Object *dim_ly; - - if (!priv || !priv->base) { - _ERR("the param is invalid."); - return RET_FAILED; - } - - dim_ly = util_add_layout(priv->base, UG_PROXY_EDJ_FILE, - GRP_DIM_LY); - if (!dim_ly) { - _ERR("elm_layout_add() failed.\n"); - return RET_FAILED; - } - - priv->dim_ly = dim_ly; - _unset_layout_dim(priv); - - return RET_SUCCESS; -} - -/** - * Creates the layout of the view. - * - * Called when the ug is launched. - * - * @param[in] win The handler of view manager - * @param[in] data The passed data from main view - * @return layout if the operation is successful; NULL if failed; - */ -Evas_Object *create_main_view(Evas_Object *win, ui_gadget_h ug) -{ - struct _priv *priv; - Evas_Object *base; - int ret; - - if (!win || !ug) { - _ERR("Parameter error!"); - return NULL; - } - - priv = _init_priv(); - if (!priv) { - _ERR("init priv failed."); - return NULL; - } - - priv->win = win; - priv->ug = ug; - - base = _create_basic_layout(priv); - if (!base) { - _ERR("Add main view failed.\n"); - _fini_priv(priv); - return NULL; - } - - priv->base = base; - - _set_description(priv); - - ret = _get_proxy_method(priv); - if (ret != RET_SUCCESS) { - _ERR("get proxy method failed.\n"); - goto error; - } - - ret = _create_proxy_ly(priv); - if (ret != RET_SUCCESS) { - _ERR("get proxy method failed.\n"); - goto error; - } - - ret = _create_action_btns(priv); - if (ret != RET_SUCCESS) { - _ERR("create action buttons failed.\n"); - goto error; - } - - ret = _create_dim_layout(priv); - if (ret != RET_SUCCESS) - goto error; - - elm_object_focus_set(priv->method_btn, EINA_TRUE); - evas_object_data_set(base, KEY_PRIV, priv); - - return base; - -error: - _fini_priv(priv); - return NULL; -} - -/** - * Destroies the layout of the view. - * - * Called when the ug is destroied. - * - * @param[in] base The base layout - */ -void destroy_main_view(Evas_Object *base) -{ - struct _priv *priv; - - if (!base) { - _ERR("Parameter error!"); - return; - } - - priv = (struct _priv *) evas_object_data_get(base, KEY_PRIV); - if (!priv) - return; - - _fini_priv(priv); -} diff --git a/ug/proxy/src/ug_proxy_settings.cpp b/ug/proxy/src/ug_proxy_settings.cpp index b53faaa..a76a562 100644 --- a/ug/proxy/src/ug_proxy_settings.cpp +++ b/ug/proxy/src/ug_proxy_settings.cpp @@ -20,11 +20,15 @@ #include #include -#include "main_view.h" #include "i18n.h" #include "defs.h" #include "dbg.h" +#include +#include "wifi.h" +#include "BaseView.h" +#include "ProxyMainView.h" + #if defined (__cplusplus) extern "C" { #endif @@ -33,6 +37,8 @@ struct _ug_data { Evas_Object *win; Evas_Object *base; ui_gadget_h ug; + CViewMgr *pViewMgr; + CProxyMainView *pProxyMainView; }; /** @@ -58,7 +64,6 @@ static void *_on_create(ui_gadget_h ug, enum ug_mode mode, service_h service, void *priv) { struct _ug_data *ugd; - Evas_Object *base; Evas_Object *win; if (!ug || !priv) { @@ -82,16 +87,24 @@ static void *_on_create(ui_gadget_h ug, enum ug_mode mode, elm_win_focus_highlight_enabled_set(win, EINA_TRUE); elm_win_focus_highlight_style_set(win, "invisible"); - base = create_main_view(win, ug); - if (!base) { - _ERR("add base layout failed."); + CViewMgr::Initialize(ugd->win, NULL); + ugd->pViewMgr = CViewMgr::GetInstance(); + if(!ugd->pViewMgr) { + CViewMgr::Finalize(); + _ERR("Fail to get CViewMgr instance"); return NULL; } + ugd->pProxyMainView = new CProxyMainView(PROXY_MAINVIEW); + if(!ugd->pViewMgr->AddView(ugd->pProxyMainView)) { + _ERR("Fail to add pFbBaseView"); + CViewMgr::Finalize(); + return false; + } - ugd->base = base; - evas_object_raise(base); + ugd->pViewMgr->PushView(PROXY_MAINVIEW, NULL); + ugd->base = ugd->pProxyMainView->Base(); - return base; + return ugd->base; } /** @@ -172,7 +185,7 @@ static void _on_destroy(ui_gadget_h ug, service_h service, void *priv) if (!ugd || !ugd->base) return; - destroy_main_view(ugd->base); + CViewMgr::Finalize(); } /** -- 2.7.4 From 454badf837e5d8c9b0035b55a1ef2b67035e54fe Mon Sep 17 00:00:00 2001 From: Kim Youngjin Date: Mon, 30 Mar 2015 15:12:28 +0900 Subject: [PATCH 14/16] viewmgr is changed to class module. Change-Id: I9bd106203acedb2160554202669f7e4cd470bd0e Signed-off-by: Kim Youngjin --- include/viewmgr.h | 69 +++++++----- src/main.cpp | 20 ++-- src/view_maincatalog.cpp | 57 ++++------ src/view_need_pwd.cpp | 16 +-- src/view_pwd_popup.cpp | 19 ++-- src/view_sublist.cpp | 9 +- src/view_system_clock.cpp | 14 ++- src/view_uigadget.cpp | 11 +- src/viewmgr.cpp | 281 +++++++++++++++++++++++----------------------- 9 files changed, 254 insertions(+), 242 deletions(-) diff --git a/include/viewmgr.h b/include/viewmgr.h index 40843aa..d0120e0 100644 --- a/include/viewmgr.h +++ b/include/viewmgr.h @@ -17,8 +17,11 @@ #ifndef __VIEWMGR_H__ #define __VIEWMGR_H__ + #include #include "data_wrapper.h" +#include "viewmgr.h" + #define SELECTED_ITEM_ID "bottomslider_selected_item" @@ -34,6 +37,7 @@ #define VCLASS_TITLE_UPGRADE "Upgrade Software" #define VCLASS_TITLE_NEED_PASSCODE "Need Passcode" + struct setting_mgr; struct evas_obj_data { @@ -50,9 +54,11 @@ struct obj_geometry_data { int y; }; +class CSettingMgr; + struct setting_class { const char *title; - Evas_Object * (*create)(struct setting_mgr *mgr, + Evas_Object * (*create)(CSettingMgr *mgr, struct settingview_data *view, void *prev); void (*show)(Evas_Object *base); void (*pause)(Evas_Object *base); @@ -67,29 +73,42 @@ struct setting_class { int hide_view; }; -struct setting_mgr *settingmgr_init(Evas_Object *win); -void settingmgr_fini(struct setting_mgr *mgr); -int settingmgr_view_push(struct setting_mgr *mgr, - const char *name, void *data); -void settingmgr_view_pop(struct setting_mgr *mgr); -Evas_Object *settingmgr_get_win(struct setting_mgr *mgr); -struct settingview_data *settingmgr_get_view(struct setting_mgr *mgr, - const char *name); -struct settingmgr_data *settingmgr_get_data(struct setting_mgr *mgr); -Eina_List *settingmgr_get_view_list(struct setting_mgr *mgr); -int settingmgr_launch_item(struct setting_mgr *mgr, - const char *name); -Eina_Array *settingmgr_get_item_path(struct setting_mgr *mgr); -void settingmgr_view_refresh(struct setting_mgr *mgr); -void settingmgr_set_refresh_flag(struct setting_mgr *mgr, - unsigned int val); -unsigned int settingmgr_get_refresh_flag(struct setting_mgr *mgr); -void settingmgr_set_relaunch_flag(struct setting_mgr *mgr, - unsigned int val); -unsigned int settingmgr_get_relaunch_flag(struct setting_mgr *mgr); -void settingmgr_freeze_timeout(struct setting_mgr *mgr); -void settingmgr_thaw_timeout(struct setting_mgr *mgr); -Eina_Bool settingmgr_get_timeout_freeze_state(struct setting_mgr *mgr); -void settingmgr_lang_changed(struct setting_mgr *mgr); + +class CSettingMgr { +private: + static CSettingMgr *instance; + struct setting_mgr *m; + +protected: + CSettingMgr() : m(0) {} + virtual ~CSettingMgr() {} + +public: + static bool Initialize(Evas_Object *win); + static void Finalize(void); + + static CSettingMgr *GetInstance(void); + + bool ViewPush(const char *name, void *data); + void ViewPop(void); + Evas_Object *Window(void); + + settingview_data *GetView(const char *name); + settingmgr_data *GetData(void); + Eina_List *GetViewList(void); + + bool LaunchItem(const char *name); + Eina_Array *GetItemPath(void); + void ViewRefresh(void); + void SetRefreshFlag(unsigned int val); + unsigned int GetRefreshFlag(void); + void SetRelaunchFlag(unsigned int val); + unsigned int GetRelaunchFlag(void); + void FreezeTimeout(void); + void ThawTimeout(void); + Eina_Bool GetTimeoutFreezeState(void); + void LangChanged(void); +}; + #endif /* __VIEWMGR_H__ */ diff --git a/src/main.cpp b/src/main.cpp index fda34a6..e043aad 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -55,7 +55,7 @@ class CApp : public CBaseApp { struct _appdata { Evas_Object *win; - struct setting_mgr *mgr; + CSettingMgr *mgr; const char *name; char *item; unsigned int app_control; @@ -135,7 +135,8 @@ protected: virtual void OnTerminate(void) { - settingmgr_fini(ad.mgr); + CSettingMgr::Finalize(); + ad.mgr = NULL; provider_fini(); @@ -148,7 +149,7 @@ protected: virtual void OnAppControl(app_control_h app_control) { _DBG(" ******************* OnAppControl *********************"); - struct setting_mgr *mgr; + CSettingMgr *mgr; int r; char *param; unsigned int relaunch, refresh; @@ -168,31 +169,30 @@ protected: } if (relaunch) { - settingmgr_fini(ad.mgr); + CSettingMgr::Finalize(); } else { if (refresh) { if (!ad.mgr) return; - settingmgr_view_refresh(ad.mgr); + ad.mgr->ViewRefresh(); } } } - mgr = settingmgr_init(ad.win); - if (!mgr) + if (!CSettingMgr::Initialize(ad.win)) app_efl_exit(); + mgr = CSettingMgr::GetInstance(); r = app_control_get_extra_data(app_control, PARAM_SETTINGS_ITEM, ¶m); if (r == APP_CONTROL_ERROR_NONE && param) { - r = settingmgr_launch_item(mgr, param); - if (r != 0) { + if (!mgr->LaunchItem(param)) { _ERR("the item is not exist."); app_efl_exit(); } } else { - settingmgr_view_push(mgr, MAIN_CATALOG, NULL); + mgr->ViewPush(MAIN_CATALOG, NULL); } ad.mgr = mgr; diff --git a/src/view_maincatalog.cpp b/src/view_maincatalog.cpp index 42d58a6..277740c 100644 --- a/src/view_maincatalog.cpp +++ b/src/view_maincatalog.cpp @@ -24,6 +24,7 @@ #include "view_maincatalog.h" #include "data_wrapper.h" #include "settings_provider.h" +#include "viewmgr.h" #define DATA_ID "main_setting_data" #define SUBITEM_DATA_ID "subitem_data_id" @@ -64,7 +65,7 @@ struct _view_data { int main_item_count; int sub_item_count; - struct setting_mgr *mgr; + CSettingMgr *mgr; struct settingview_data *main_setting_view; struct settingview_data *subsetting_view; }; @@ -203,7 +204,6 @@ static int _push_ug_view(struct _view_data *data, { const char *id; struct evas_obj_data param; - int r; if (!data || !item || !obj) { _ERR("Invalid argument"); @@ -220,8 +220,7 @@ static int _push_ug_view(struct _view_data *data, param.display_name = settingitem_get_display_name(item); param.cur_btn = obj; - r = settingmgr_view_push(data->mgr, id, (void *)¶m); - if (r != 0) { + if (!data->mgr->ViewPush(id, (void *)¶m)) { _ERR("Fail to push view"); return -1; } @@ -242,7 +241,6 @@ static int _push_sublist_view(struct _view_data *data, struct settingitem *item, Evas_Object *obj) { const char *id; - int r; struct obj_geometry_data ogd; if (!data || !item || !obj) { @@ -258,8 +256,7 @@ static int _push_sublist_view(struct _view_data *data, _get_geometry_data(obj, &ogd); - r = settingmgr_view_push(data->mgr, id, (void *)&ogd); - if (r != 0) { + if (!data->mgr->ViewPush(id, (void *)&ogd)) { _ERR("Fail to push view"); return -1; } @@ -282,7 +279,6 @@ static int _push_bottom_sublist_view(struct _view_data *data, struct settingitem *item) { const char *id; - int r; if (!data || !item) { _ERR("Invalid argument"); @@ -295,8 +291,7 @@ static int _push_bottom_sublist_view(struct _view_data *data, return -1; } - r = settingmgr_view_push(data->mgr, id, NULL); - if (r != 0) { + if (!data->mgr->ViewPush(id, NULL)) { _ERR("Fail to push view"); return -1; } @@ -317,7 +312,6 @@ static int _push_bottom_slider_view(struct _view_data *data, struct settingitem *item, Evas_Object *obj) { const char *id; - int r; Eina_List *list; Evas_Object *pb; @@ -339,10 +333,9 @@ static int _push_bottom_slider_view(struct _view_data *data, list = settingitem_get_slider_group_list( viewdata_get_parentitem(data->subsetting_view), - settingmgr_get_data(data->mgr), id); + data->mgr->GetData(), id); - r = settingmgr_view_push(data->mgr, id, list); - if (r != 0) { + if (!data->mgr->ViewPush(id, list)) { _ERR("Fail to push view"); return -1; } @@ -362,7 +355,6 @@ static int _push_passcode_popup_view(struct _view_data *data, struct settingitem *item) { const char *id; - int r; if (!data || !item) { _ERR("Invalid argument"); @@ -375,8 +367,7 @@ static int _push_passcode_popup_view(struct _view_data *data, return -1; } - r = settingmgr_view_push(data->mgr, id, NULL); - if (r != 0) { + if (!data->mgr->ViewPush(id, NULL)) { _ERR("Fail to push view"); return -1; } @@ -397,7 +388,6 @@ static int _push_device_manager_view(struct _view_data *data, { const char *id; struct evas_obj_data param; - int r; if (!data || !item) { _ERR("Invalid argument"); @@ -413,8 +403,7 @@ static int _push_device_manager_view(struct _view_data *data, param.display_name = settingitem_get_display_name(item); param.subitem_box = data->subitem_box; - r = settingmgr_view_push(data->mgr, id, ¶m); - if (r != 0) { + if (!data->mgr->ViewPush(id, ¶m)) { _ERR("Fail to push view"); return -1; } @@ -434,7 +423,6 @@ static int _push_reset_popup_view(struct _view_data *data, struct settingitem *item) { const char *id; - int r; if (!data || !item) { _ERR("Invalid argument"); @@ -447,8 +435,7 @@ static int _push_reset_popup_view(struct _view_data *data, return -1; } - r = settingmgr_view_push(data->mgr, id, NULL); - if (r != 0) { + if (!data->mgr->ViewPush(id, NULL)) { _ERR("Fail to push view"); return -1; } @@ -468,7 +455,6 @@ static int _push_upgrade_popup_view(struct _view_data *data, struct settingitem *item) { const char *id; - int r; if (!data || !item) { _ERR("Invalid argument"); @@ -481,8 +467,7 @@ static int _push_upgrade_popup_view(struct _view_data *data, return -1; } - r = settingmgr_view_push(data->mgr, id, NULL); - if (r != 0) { + if (!data->mgr->ViewPush(id, NULL)) { _ERR("Fail to push view"); return -1; } @@ -505,7 +490,6 @@ static int _push_clock_sublist_view(struct _view_data *data, const char *id; struct evas_obj_data param; struct obj_geometry_data ogd; - int r; if (!data || !item || !obj) { _ERR("Invalid argument"); @@ -526,8 +510,7 @@ static int _push_clock_sublist_view(struct _view_data *data, evas_object_data_set(obj, SYSTEM_CLOCK_DATA, (void *)&ogd); - r = settingmgr_view_push(data->mgr, id, ¶m); - if (r != 0) { + if (!data->mgr->ViewPush(id, ¶m)) { _ERR("Fail to push view"); return -1; } @@ -550,7 +533,6 @@ static int _push_need_passcode_view(struct _view_data *data, struct settingitem *item, Evas_Object *obj) { const char *id; - int r; struct obj_geometry_data ogd; if (!data || !item || !obj) { @@ -566,8 +548,7 @@ static int _push_need_passcode_view(struct _view_data *data, _get_geometry_data(obj, &ogd); - r = settingmgr_view_push(data->mgr, id, &ogd); - if (r != 0) { + if (!data->mgr->ViewPush(id, &ogd)) { _ERR("Fail to push view"); return -1; } @@ -1108,7 +1089,7 @@ static int _draw_subitems(struct _view_data *data, const char *name) return -1; } - view = settingmgr_get_view(data->mgr, name); + view = data->mgr->GetView(name); if (!view) { _ERR("get subview failed\n"); return -1; @@ -1775,7 +1756,7 @@ static void _change_buttons_name(Eina_List *list, * * @return: the base layout of settings or null if error occurred. */ -static Evas_Object *_create(struct setting_mgr *mgr, +static Evas_Object *_create(CSettingMgr *mgr, struct settingview_data *view, void *prev) { _DBG("START =================================================================="); @@ -1787,7 +1768,7 @@ static Evas_Object *_create(struct setting_mgr *mgr, return NULL; } - win = settingmgr_get_win(mgr); + win = mgr->Window(); if (!win) { _ERR("Fail to get win"); return NULL; @@ -1811,7 +1792,7 @@ static Evas_Object *_create(struct setting_mgr *mgr, data->base = base; data->main_setting_view = view; data->subsetting_view = NULL; - data->item_path = settingmgr_get_item_path(mgr); + data->item_path = mgr->GetItemPath(); evas_object_data_set(base, DATA_ID, data); @@ -1984,8 +1965,8 @@ static void _refresh(Evas_Object *base) SIG_UNCTRL_PB_FOCUSED, SRC_PB_PROG); } - if (settingmgr_get_timeout_freeze_state(data->mgr) == EINA_TRUE) - settingmgr_thaw_timeout(data->mgr); + if (data->mgr->GetTimeoutFreezeState() == EINA_TRUE) + data->mgr->ThawTimeout(); } /** diff --git a/src/view_need_pwd.cpp b/src/view_need_pwd.cpp index 042f151..d314894 100644 --- a/src/view_need_pwd.cpp +++ b/src/view_need_pwd.cpp @@ -62,7 +62,7 @@ struct _chnllock_data { char passcode[BUF_SIZE]; - struct setting_mgr *mgr; + CSettingMgr *mgr; struct settingview_data *view; struct obj_geometry_data gd; }; @@ -173,7 +173,7 @@ static void _cancel_btn_clicked_cb(void *priv, Evas_Object *obj, data = (struct _chnllock_data *) priv; - settingmgr_view_pop(data->mgr); + data->mgr->ViewPop(); } /** @@ -259,7 +259,7 @@ static void _push_next_view(struct _chnllock_data *data) if (!id) return; - settingmgr_view_push(data->mgr, id, &data->gd); + data->mgr->ViewPush(id, &data->gd); } /** @@ -308,7 +308,7 @@ static void _key_down_cb(void *priv, Evas *e, Evas_Object *obj, return; if (!strncmp(keyname, KEY_BACK, strlen(keyname)) || !strncmp(keyname, KEY_BACK_REMOTE, strlen(keyname))) { - settingmgr_view_pop(data->mgr); + data->mgr->ViewPop(); } else if (!strncmp(keyname, KEY_DOWN, strlen(keyname))) { elm_object_focus_set(data->cancel_btn, EINA_TRUE); } else if (!strncmp(keyname, KEY_0, strlen(keyname)) || @@ -532,7 +532,7 @@ static void _ctxpopup_dismissed(void *priv, Evas_Object *obj, _hide(data->base); - settingmgr_view_pop(data->mgr); + data->mgr->ViewPop(); } /** @@ -545,7 +545,7 @@ static void _ctxpopup_dismissed(void *priv, Evas_Object *obj, * @return: the base layout of channel lock view or null * if error occurred. */ -static Evas_Object *_create(struct setting_mgr *mgr, +static Evas_Object *_create(CSettingMgr *mgr, struct settingview_data *view, void *prev) { Evas_Object *win, *base, *bg; @@ -560,7 +560,7 @@ static Evas_Object *_create(struct setting_mgr *mgr, return NULL; } - win = settingmgr_get_win(mgr); + win = mgr->Window(); if (!win) { _ERR("settings manager get window failed."); return NULL; @@ -727,7 +727,7 @@ static void _refresh(Evas_Object *base) if (!data) return; - settingmgr_view_pop(data->mgr); + data->mgr->ViewPop(); } /** diff --git a/src/view_pwd_popup.cpp b/src/view_pwd_popup.cpp index 13a54b7..592614b 100644 --- a/src/view_pwd_popup.cpp +++ b/src/view_pwd_popup.cpp @@ -19,6 +19,7 @@ #include "view_pwd_popup.h" #include "utils.h" #include "settings_provider.h" +#include "viewmgr.h" #define PWD_DATA_ID "change_passcode_data" #define CTXPOPUP_WIDTH 688 @@ -68,7 +69,7 @@ struct _pwd_data { int renew_flag; int wrong_flag; - struct setting_mgr *mgr; + CSettingMgr *mgr; struct settingview_data *view; }; @@ -176,7 +177,7 @@ static void _cancelbtn_clicked_cb(void *priv, Evas_Object *obj, void *ev) data = (struct _pwd_data *) priv; - settingmgr_view_pop(data->mgr); + data->mgr->ViewPop(); } /** @@ -483,7 +484,7 @@ static void _entry_keypress_cb(void *priv, Evas *e, } if (!strncmp(keyname, KEY_BACK, strlen(keyname)) || !strncmp(keyname, KEY_BACK_REMOTE, strlen(keyname))) { - settingmgr_view_pop(data->mgr); + data->mgr->ViewPop(); } else if (!strncmp(keyname, KEY_DOWN, strlen(keyname))) { elm_object_focus_set(data->cancel_btn, EINA_TRUE); } else if (!strncmp(keyname, KEY_0, strlen(keyname)) || @@ -543,7 +544,7 @@ static void _entry_keypress_cb(void *priv, Evas *e, data->new_flag = 0; data->renew_flag = 0; - settingmgr_view_pop(data->mgr); + data->mgr->ViewPop(); } else { _update_pwd_ui(data, PART_UPTEXT, MSGID_DIFFER_PWD); @@ -697,7 +698,7 @@ static void _ctxpopup_dismissed(void *priv, Evas_Object *obj, _hide(data->base); - settingmgr_view_pop(data->mgr); + data->mgr->ViewPop(); } /** @@ -710,9 +711,11 @@ static void _ctxpopup_dismissed(void *priv, Evas_Object *obj, * @return: the base layout of change passcode view or null * if error occurred. */ -static Evas_Object *_create(struct setting_mgr *mgr, +static Evas_Object *_create(CSettingMgr *mgr, struct settingview_data *view, void *prev) { + ASSERT(mgr); + Evas_Object *base, *bg; Evas_Object *win; Evas_Object *cancel_btn; @@ -722,12 +725,12 @@ static Evas_Object *_create(struct setting_mgr *mgr, int width, height; int xpos, ypos; - if (!mgr || !view) { + if (!view) { _ERR("invalid argument."); return NULL; } - win = settingmgr_get_win(mgr); + win = mgr->Window(); if (!win) { _ERR("settingmgr get window failed."); return NULL; diff --git a/src/view_sublist.cpp b/src/view_sublist.cpp index 39399e5..9f538ab 100644 --- a/src/view_sublist.cpp +++ b/src/view_sublist.cpp @@ -22,6 +22,7 @@ #include "data_wrapper.h" #include "settings_provider.h" #include "view_sublist.h" +#include "viewmgr.h" #define DATA_ID "SUBLISTDATA" #define MAX_ITEMS 8 @@ -52,7 +53,7 @@ struct _sublist_data { int selected_index; struct obj_geometry_data *geometry_data; struct settingview_data *sublist_view; - struct setting_mgr *mgr; + CSettingMgr *mgr; }; static void _destroy(Evas_Object *base); @@ -70,7 +71,7 @@ static void _exit_view(struct _sublist_data *data) return; _hide(data->base); - settingmgr_view_pop(data->mgr); + data->mgr->ViewPop(); } /** @@ -616,7 +617,7 @@ static int _draw_sublist(struct _sublist_data *data) * @param prev [in] The parameter data which passed by prev view or NULL. * @return View layout evas object, NULL on error. */ -static Evas_Object *_create(struct setting_mgr *mgr, +static Evas_Object *_create(CSettingMgr *mgr, struct settingview_data *view, void *prev) { Evas_Object *base, *ctxpopup, *win; @@ -627,7 +628,7 @@ static Evas_Object *_create(struct setting_mgr *mgr, return NULL; } - win = settingmgr_get_win(mgr); + win = mgr->Window(); if (!win) { _ERR("Fail to get win"); return NULL; diff --git a/src/view_system_clock.cpp b/src/view_system_clock.cpp index eeb4cb5..e396d26 100644 --- a/src/view_system_clock.cpp +++ b/src/view_system_clock.cpp @@ -50,7 +50,7 @@ struct _sysclk_data { int count; int sel_idx; struct settingview_data *vdata; - struct setting_mgr *mgr; + CSettingMgr *mgr; struct evas_obj_data ugd; struct obj_geometry_data *ogd; @@ -73,7 +73,7 @@ static void _exit_view(struct _sysclk_data *data) _hide(data->base); - settingmgr_view_pop(data->mgr); + data->mgr->ViewPop(); } /** @@ -311,7 +311,7 @@ static void _subitem_clicked_cb(void *priv, Evas_Object *obj, void *ev) data->ugd.display_name = name; - settingmgr_view_push(data->mgr, id, (void *)&data->ugd); + data->mgr->ViewPush(id, (void *)&data->ugd); } else { _exit_view(data); } @@ -556,7 +556,7 @@ static void _ctxpopup_dismissed(void *priv, Evas_Object *obj, _hide(data->base); - settingmgr_view_pop(data->mgr); + data->mgr->ViewPop(); } /** @@ -569,7 +569,7 @@ static void _ctxpopup_dismissed(void *priv, Evas_Object *obj, * @return: the base layout of system clock view or null * if error occurred. */ -static Evas_Object *_create(struct setting_mgr *mgr, +static Evas_Object *_create(CSettingMgr *mgr, struct settingview_data *view, void *prev) { Evas_Object *base; @@ -587,7 +587,8 @@ static Evas_Object *_create(struct setting_mgr *mgr, ugd = (struct evas_obj_data *) prev; ogd = (struct obj_geometry_data *) evas_object_data_get(ugd->cur_btn, DATA_ID); - win = settingmgr_get_win(mgr); + win = mgr->Window(); + if (!win) { _ERR("settingmgr get window failed."); return NULL; @@ -781,3 +782,4 @@ struct setting_class *view_system_clock_get_vclass(void) { return &_vclass; } + diff --git a/src/view_uigadget.cpp b/src/view_uigadget.cpp index 92c0a8c..715d7f0 100644 --- a/src/view_uigadget.cpp +++ b/src/view_uigadget.cpp @@ -18,6 +18,7 @@ #include "view_uigadget.h" #include "dbg.h" #include "def.h" +#include "viewmgr.h" #define DATA_ID "ugdata" @@ -31,7 +32,7 @@ struct _data { const char *display_name; ui_gadget_h ug_handler; Eina_Bool ug_is_existed; - struct setting_mgr *mgr; + CSettingMgr *mgr; struct settingview_data *view; }; @@ -61,7 +62,7 @@ static void _back_to_mainview(struct _data *data) return; _hide(data->base); - settingmgr_view_pop(data->mgr); + data->mgr->ViewPop(); } /** @@ -187,7 +188,7 @@ static int _load_uigadget(struct _data *data) } else { data->ug_is_existed = EINA_TRUE; data->ug_handler = ug; - settingmgr_freeze_timeout(data->mgr); + data->mgr->FreezeTimeout(); } return 0; @@ -233,7 +234,7 @@ static void _hide_item_btns(Evas_Object *box) * @param prev [in] The parameter data which passed by prev view or NULL. * @return View layout evas object, NULL on error. */ -static Evas_Object *_create(struct setting_mgr *mgr, +static Evas_Object *_create(CSettingMgr *mgr, struct settingview_data *view, void *prev) { Evas_Object *win, *base; @@ -250,7 +251,7 @@ static Evas_Object *_create(struct setting_mgr *mgr, _hide_item_btns(param->subitem_box); - win = settingmgr_get_win(mgr); + win = mgr->Window(); if (!win) { _ERR("Invalid argument"); return NULL; diff --git a/src/viewmgr.cpp b/src/viewmgr.cpp index a103874..bc98edd 100644 --- a/src/viewmgr.cpp +++ b/src/viewmgr.cpp @@ -26,6 +26,7 @@ #include "view_pwd_popup.h" #include "view_system_clock.h" #include "view_need_pwd.h" +#include "viewmgr.h" #define MAINCATALOG "maincatalog" #define PATH_FACTOR 3 @@ -278,49 +279,66 @@ void _active_view_in_list(struct setting_mgr *mgr) } } + + +CSettingMgr *CSettingMgr::instance = NULL; + /** * This function is invoked to initialize setting manager. * * @param win [in] The window's evas object. * @return The setting_mgr data pointer. */ -struct setting_mgr *settingmgr_init(Evas_Object *win) +bool CSettingMgr::Initialize(Evas_Object *win) { - struct setting_mgr *mgr; + ASSERT(!instance); + + instance = new CSettingMgr; + if (!instance) { + return false; + } + instance->m = new setting_mgr; + if (!instance->m) { + delete instance; + return false; + } + struct settingmgr_data *data; struct timeout_handler *handler; if (!win) return NULL; - mgr = (struct setting_mgr *)calloc(1, sizeof(*mgr)); - if (!mgr) - return NULL; - data = viewmgr_data_init(); if (!data) { _ERR("viewmgr_data_init failed!"); - free(mgr); - return NULL; + delete instance->m; + delete instance; + instance = NULL; + return false; } handler = timeout_handler_init(TIMEOUT_SECS); if (!handler) { _ERR("Fail to init timeout handler"); viewmgr_data_fini(data); - free(mgr); - return NULL; + delete instance->m; + delete instance; + instance = NULL; + return false; } - mgr->win = win; - mgr->depth = 0; - mgr->data = data; - mgr->handler = handler; - mgr->is_freeze = EINA_FALSE; - return mgr; + instance->m->win = win; + instance->m->depth = 0; + instance->m->data = data; + instance->m->handler = handler; + instance->m->is_freeze = EINA_FALSE; + + return true; } + /** * This function is invoked to destroy all views stored in view list and release * setting_mgr data structure. @@ -328,34 +346,41 @@ struct setting_mgr *settingmgr_init(Evas_Object *win) * @param mgr [in] The setting_mgr data pointer. * @return void. */ -void settingmgr_fini(struct setting_mgr *mgr) +void CSettingMgr::Finalize(void) { + ASSERT(instance); + ASSERT(instance->m); + struct _settinginfo *sinfo; void* obj; - if (!mgr) { - _ERR("Parameter error!"); - return; - } + _hide_view_in_list(instance->m); + _destroy_views_in_list(instance->m); - _hide_view_in_list(mgr); - _destroy_views_in_list(mgr); - - EINA_LIST_FREE(mgr->view_list, obj) + EINA_LIST_FREE(instance->m->view_list, obj) { sinfo = (struct _settinginfo *)obj; free(sinfo); } - if (mgr->item_path) - eina_array_free(mgr->item_path); + if (instance->m->item_path) + eina_array_free(instance->m->item_path); + + viewmgr_data_fini(instance->m->data); + timeout_handler_fini(instance->m->handler); + + delete instance->m; + delete instance; + instance = NULL; +} - viewmgr_data_fini(mgr->data); - timeout_handler_fini(mgr->handler); - free(mgr); +CSettingMgr *CSettingMgr::GetInstance(void) +{ + return instance; } + /** * This function is invoked to push a view with specific name and data. * @@ -367,45 +392,44 @@ void settingmgr_fini(struct setting_mgr *mgr) * @param data [in] The function specific data passed by caller. * @return 0 if success, -1 if fail. */ -int settingmgr_view_push(struct setting_mgr *mgr, - const char *name, void *data) +bool CSettingMgr::ViewPush(const char *name, void *data) { + ASSERT(m); + ASSERT(name); + Evas_Object *base; struct _settinginfo *sinfo; struct setting_class *sclass; struct settingview_data *view; - if (!mgr || !name) - return -1; - - mgr->depth++; + m->depth++; - sinfo = (struct _settinginfo *)calloc(1, sizeof(*sinfo)); + sinfo = new _settinginfo; if (!sinfo) - return -1; + return false; - view = _build_setting_view(mgr, name); + view = _build_setting_view(m, name); if (!view) { _ERR("Build setting view data failed\n"); goto error; } - sclass = _get_view_class(mgr, view); + sclass = _get_view_class(m, view); if (!sclass) { _ERR("failed to get view class."); goto error; } - base = sclass->create(mgr, view, data); + base = sclass->create(this, view, data); if (!base) { _ERR("failed to create base layout."); goto error; } - _frozen_view_in_list(mgr); + _frozen_view_in_list(m); if (sclass->hide_view) - _hide_view_in_list(mgr); + _hide_view_in_list(m); if (sclass->show) sclass->show(base); @@ -414,12 +438,12 @@ int settingmgr_view_push(struct setting_mgr *mgr, sinfo->sclass = sclass; sinfo->sview = view; - mgr->view_list = eina_list_prepend(mgr->view_list, sinfo); + m->view_list = eina_list_prepend(m->view_list, sinfo); return 0; error: - mgr->depth--; + m->depth--; free(sinfo); viewdata_release(view); @@ -435,21 +459,18 @@ error: * @param mgr [in] The setting_mgr data pointer. * @return void. */ -void settingmgr_view_pop(struct setting_mgr *mgr) +void CSettingMgr::ViewPop(void) { + ASSERT(m); + struct _settinginfo *sinfo, *prev; struct setting_class *sclass; int hide; char *item; const char *title; - if (!mgr) { - _ERR("Invalid arguments\n"); - return; - } - - mgr->depth--; - sinfo = (struct _settinginfo *) eina_list_data_get(mgr->view_list); + m->depth--; + sinfo = (struct _settinginfo *) eina_list_data_get(m->view_list); if (!sinfo) { _DBG("get sinfo failed\n"); return; @@ -467,13 +488,13 @@ void settingmgr_view_pop(struct setting_mgr *mgr) if (sclass->destroy && sinfo->base) sclass->destroy(sinfo->base); - mgr->view_list = eina_list_remove_list(mgr->view_list, mgr->view_list); + m->view_list = eina_list_remove_list(m->view_list, m->view_list); free(sinfo); - if (!mgr->view_list) + if (!m->view_list) return; - prev = (struct _settinginfo *) eina_list_data_get(mgr->view_list); + prev = (struct _settinginfo *) eina_list_data_get(m->view_list); if (!prev || !prev->sclass) return; @@ -488,10 +509,10 @@ void settingmgr_view_pop(struct setting_mgr *mgr) if (sclass->update) sclass->update(prev->base); - _active_view_in_list(mgr); + _active_view_in_list(m); if (hide) - _show_view_in_list(mgr); + _show_view_in_list(m); } /** @@ -500,12 +521,11 @@ void settingmgr_view_pop(struct setting_mgr *mgr) * @param mgr [in] The setting_mgr data pointer. * @return The window's evas object, NULL on error. */ -Evas_Object *settingmgr_get_win(struct setting_mgr *mgr) +Evas_Object *CSettingMgr::Window(void) { - if (!mgr) - return NULL; + ASSERT(m); - return mgr->win; + return m->win; } /** @@ -515,10 +535,11 @@ Evas_Object *settingmgr_get_win(struct setting_mgr *mgr) * @param name [in] The view name to be got. * @return The settingview_data data pointer, NULL on error. */ -struct settingview_data *settingmgr_get_view(struct setting_mgr *mgr, - const char *name) +settingview_data *CSettingMgr::GetView(const char *name) { - return _build_setting_view(mgr, name); + ASSERT(m); + + return _build_setting_view(m, name); } /** @@ -527,14 +548,11 @@ struct settingview_data *settingmgr_get_view(struct setting_mgr *mgr, * @param mgr [in] The setting_mgr data pointer. * @return The settingmgr_data data pointer, NULL on error. */ -struct settingmgr_data *settingmgr_get_data(struct setting_mgr *mgr) +settingmgr_data *CSettingMgr::GetData(void) { - if (!mgr) { - _ERR("Parameter error!"); - return NULL; - } + ASSERT(m); - return mgr->data; + return m->data; } /** @@ -543,14 +561,12 @@ struct settingmgr_data *settingmgr_get_data(struct setting_mgr *mgr) * @param mgr [in] The setting_mgr data pointer. * @return The Eina_List data pointer, NULL on error. */ -Eina_List *settingmgr_get_view_list(struct setting_mgr *mgr) +Eina_List *CSettingMgr::GetViewList(void) { - if (!mgr) { - _ERR("Parameter error!"); - return NULL; - } + ASSERT(m); - return mgr->view_list; + + return m->view_list; } /** @@ -563,21 +579,20 @@ Eina_List *settingmgr_get_view_list(struct setting_mgr *mgr) * @param name [in] The item name. * @return 0 if success, -1 if fail. */ -int settingmgr_launch_item(struct setting_mgr *mgr, - const char *name) +bool CSettingMgr::LaunchItem(const char *name) { + ASSERT(m); + ASSERT(name); + const char *parent; struct settingitem *item; Eina_Array *path; int i, cnt; - if (!mgr || !name) - return -1; - path = eina_array_new(1); if (!path) { _ERR("new eina array failed."); - return -1; + return false; } eina_array_push(path, name); @@ -586,15 +601,15 @@ int settingmgr_launch_item(struct setting_mgr *mgr, if (!parent) { _ERR("get parent item name failed."); eina_array_free(path); - return -1; + return false; } eina_array_push(path, parent); do { - viewmgr_data_read_jsonfile_into_hash(mgr->data, parent); + viewmgr_data_read_jsonfile_into_hash(m->data, parent); - item = viewmgr_data_get_settingitem(mgr->data, parent); + item = viewmgr_data_get_settingitem(m->data, parent); if (!item) break; @@ -602,16 +617,18 @@ int settingmgr_launch_item(struct setting_mgr *mgr, eina_array_push(path, parent); } while (parent && strncmp(parent, MAINCATALOG, strlen(parent))); - mgr->item_path = path; + m->item_path = path; + + + ViewPush(MAINCATALOG, NULL); - settingmgr_view_push(mgr, MAINCATALOG, NULL); cnt = eina_array_count(path); for (i = cnt - PATH_FACTOR; i > 0; i--) - settingmgr_view_push(mgr,(const char *) eina_array_data_get(path, i), NULL); + ViewPush((const char *) eina_array_data_get(path, i), NULL); - return 0; + return true; } /** @@ -623,12 +640,11 @@ int settingmgr_launch_item(struct setting_mgr *mgr, * @param mgr [in] The setting_mgr data pointer. * @return The Eina_Array data pointer, NULL on error. */ -Eina_Array *settingmgr_get_item_path(struct setting_mgr *mgr) +Eina_Array *CSettingMgr::GetItemPath(void) { - if (!mgr || !mgr->item_path) - return NULL; + ASSERT(m); - return mgr->item_path; + return m->item_path; } /** @@ -637,15 +653,17 @@ Eina_Array *settingmgr_get_item_path(struct setting_mgr *mgr) * @param mgr [in] The setting_mgr data pointer. * @return void. */ -void settingmgr_view_refresh(struct setting_mgr *mgr) +void CSettingMgr::ViewRefresh(void) { + ASSERT(m); + struct _settinginfo *info; struct setting_class *vclass; - if (!mgr || !mgr->view_list) + if (!m->view_list) return; - info = (struct _settinginfo *) eina_list_data_get(mgr->view_list); + info = (struct _settinginfo *) eina_list_data_get(m->view_list); if (!info) return; @@ -665,13 +683,11 @@ void settingmgr_view_refresh(struct setting_mgr *mgr) * @param val [in] The value to be set. * @return void. */ -void settingmgr_set_refresh_flag(struct setting_mgr *mgr, - unsigned int val) +void CSettingMgr::SetRefreshFlag(unsigned int val) { - if (!mgr) - return; + ASSERT(m); - mgr->refresh = val; + m->refresh = val; } /** @@ -680,12 +696,11 @@ void settingmgr_set_refresh_flag(struct setting_mgr *mgr, * @param mgr [in] The setting_mgr data pointer. * @return The refresh flag value, -1 if fail. */ -unsigned int settingmgr_get_refresh_flag(struct setting_mgr *mgr) +unsigned int CSettingMgr::GetRefreshFlag(void) { - if (!mgr) - return -1; + ASSERT(m); - return mgr->refresh; + return m->refresh; } /** @@ -695,13 +710,11 @@ unsigned int settingmgr_get_refresh_flag(struct setting_mgr *mgr) * @param val [in] The value to be set. * @return void. */ -void settingmgr_set_relaunch_flag(struct setting_mgr *mgr, - unsigned int val) +void CSettingMgr::SetRelaunchFlag(unsigned int val) { - if (!mgr) - return; + ASSERT(m); - mgr->relaunch = val; + m->relaunch = val; } /** @@ -710,12 +723,11 @@ void settingmgr_set_relaunch_flag(struct setting_mgr *mgr, * @param mgr [in] The setting_mgr data pointer. * @return The refresh flag value, -1 if fail. */ -unsigned int settingmgr_get_relaunch_flag(struct setting_mgr *mgr) +unsigned int CSettingMgr::GetRelaunchFlag(void) { - if (!mgr) - return -1; + ASSERT(m); - return mgr->relaunch; + return m->relaunch; } /** @@ -724,15 +736,12 @@ unsigned int settingmgr_get_relaunch_flag(struct setting_mgr *mgr) * @param mgr [in] The setting_mgr data pointer. * @return void. */ -void settingmgr_freeze_timeout(struct setting_mgr *mgr) +void CSettingMgr::FreezeTimeout(void) { - if (!mgr) { - _ERR("Invalid argument"); - return; - } + ASSERT(m); - mgr->is_freeze = EINA_TRUE; - timeout_handler_freeze_timer(mgr->handler); + m->is_freeze = EINA_TRUE; + timeout_handler_freeze_timer(m->handler); } /** @@ -741,15 +750,12 @@ void settingmgr_freeze_timeout(struct setting_mgr *mgr) * @param mgr [in] The setting_mgr data pointer. * @return void. */ -void settingmgr_thaw_timeout(struct setting_mgr *mgr) +void CSettingMgr::ThawTimeout(void) { - if (!mgr) { - _ERR("Invalid argument"); - return; - } + ASSERT(m); - timeout_handler_thaw_timer(mgr->handler); - mgr->is_freeze = EINA_FALSE; + timeout_handler_thaw_timer(m->handler); + m->is_freeze = EINA_FALSE; } /** @@ -759,14 +765,11 @@ void settingmgr_thaw_timeout(struct setting_mgr *mgr) * @return EINA_TRUE if current state is frozen * EINA_FALSE if current state is normal or occurred error. */ -Eina_Bool settingmgr_get_timeout_freeze_state(struct setting_mgr *mgr) +Eina_Bool CSettingMgr::GetTimeoutFreezeState(void) { - if (!mgr) { - _ERR("Invalid argument"); - return EINA_FALSE; - } + ASSERT(m); - return mgr->is_freeze; + return m->is_freeze; } /** @@ -775,18 +778,20 @@ Eina_Bool settingmgr_get_timeout_freeze_state(struct setting_mgr *mgr) * @param mgr [in] The setting_mgr data pointer. * @return void. */ -void settingmgr_lang_changed(struct setting_mgr *mgr) +void CSettingMgr::LangChanged(void) { + ASSERT(m); + struct _settinginfo *sinfo; Eina_List *l; void* obj; - if (!mgr || !mgr->view_list) { + if (!m->view_list) { _ERR("Invalid argument"); return; } - EINA_LIST_FOREACH(mgr->view_list, l, obj) { + EINA_LIST_FOREACH(m->view_list, l, obj) { sinfo = (struct _settinginfo *) obj; if (!sinfo || !sinfo->sclass) { _ERR("settings info is NULL"); -- 2.7.4 From 473a826c4fa089d1d775f0611c0d342e33d8795a Mon Sep 17 00:00:00 2001 From: Kim Youngjin Date: Mon, 30 Mar 2015 17:27:33 +0900 Subject: [PATCH 15/16] Refactoring Change-Id: Ib44549f0a0d266c0315e8de76cba9beb97cd2984 Signed-off-by: Kim Youngjin --- CMakeLists.txt | 2 +- include/{viewmgr.h => settingviewmgr.h} | 56 +++++- include/view_maincatalog.h | 28 ++- include/view_need_pwd.h | 31 ++- include/view_pwd_popup.h | 27 ++- include/view_sublist.h | 43 ++++- include/view_system_clock.h | 38 +++- include/view_uigadget.h | 31 ++- src/main.cpp | 2 +- src/{viewmgr.cpp => settingviewmgr.cpp} | 206 ++++++++++++-------- src/view_maincatalog.cpp | 330 ++++++++++++++------------------ src/view_need_pwd.cpp | 239 +++++++++++------------ src/view_pwd_popup.cpp | 178 ++++++++--------- src/view_sublist.cpp | 316 +++++++++++++++--------------- src/view_system_clock.cpp | 293 +++++++++++++--------------- src/view_uigadget.cpp | 186 +++++++++--------- 16 files changed, 1072 insertions(+), 934 deletions(-) rename include/{viewmgr.h => settingviewmgr.h} (70%) rename src/{viewmgr.cpp => settingviewmgr.cpp} (77%) diff --git a/CMakeLists.txt b/CMakeLists.txt index b360141..c2acbc5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,7 +77,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) ADD_EXECUTABLE(${PROJECT_NAME} src/main.cpp - src/viewmgr.cpp + src/settingviewmgr.cpp src/parser.cpp src/data_wrapper.cpp src/utils.cpp diff --git a/include/viewmgr.h b/include/settingviewmgr.h similarity index 70% rename from include/viewmgr.h rename to include/settingviewmgr.h index d0120e0..3acf9d2 100644 --- a/include/viewmgr.h +++ b/include/settingviewmgr.h @@ -14,13 +14,13 @@ * limitations under the License. */ -#ifndef __VIEWMGR_H__ -#define __VIEWMGR_H__ +#ifndef __SETTING_VIEW_MGR_H__ +#define __SETTING_VIEW_MGR_H__ #include #include "data_wrapper.h" -#include "viewmgr.h" +//#include "viewmgr.h" #define SELECTED_ITEM_ID "bottomslider_selected_item" @@ -38,8 +38,6 @@ #define VCLASS_TITLE_NEED_PASSCODE "Need Passcode" -struct setting_mgr; - struct evas_obj_data { Evas_Object *subitem_box; Evas_Object *cur_btn; @@ -56,6 +54,48 @@ struct obj_geometry_data { class CSettingMgr; + +class CSettingBaseView { +private: + char *m_title; + +public: + CSettingBaseView(const char *pViewId); + virtual ~CSettingBaseView(); + const char *ViewId(void) { return m_title; } + + virtual bool Create(struct settingview_data *view, void *prev) { return false; } + virtual void Show(void) {} + virtual void Pause(void) {} + virtual void Resume(void) {} + virtual void Refresh(void) {} + virtual void Update(void) {} + virtual void Hide(void) {} + virtual void Destroy(void) {} + virtual void LangChanged(void) {} + virtual void Frozen(void) {} + virtual void Active(void) {} + + const char *Title(void) { return m_title; } + virtual Evas_Object *Base(void); + + int hide_view; + + + /*void(*show)(Evas_Object *base); + void(*pause)(Evas_Object *base); + void(*resume)(Evas_Object *base); + void(*refresh)(Evas_Object *base); + void(*update)(Evas_Object *base); + void(*hide)(Evas_Object *base); + void(*destroy)(Evas_Object *base); + void(*lang_changed)(Evas_Object *base); + void(*frozen)(Evas_Object *base); + void(*active)(Evas_Object *base); + int hide_view;*/ +}; + +/* struct setting_class { const char *title; Evas_Object * (*create)(CSettingMgr *mgr, @@ -71,13 +111,13 @@ struct setting_class { void (*frozen)(Evas_Object *base); void (*active)(Evas_Object *base); int hide_view; -}; +};*/ class CSettingMgr { private: static CSettingMgr *instance; - struct setting_mgr *m; + struct SSettingMgr *m; protected: CSettingMgr() : m(0) {} @@ -111,4 +151,4 @@ public: }; -#endif /* __VIEWMGR_H__ */ +#endif /* __SETTING_VIEW_MGR_H__ */ diff --git a/include/view_maincatalog.h b/include/view_maincatalog.h index 675379a..22ae52b 100644 --- a/include/view_maincatalog.h +++ b/include/view_maincatalog.h @@ -17,8 +17,32 @@ #ifndef __VIEW_MAINMENU_H__ #define __VIEW_MAINMENU_H__ -#include "viewmgr.h" -struct setting_class *view_maincatalog_get_vclass(void); +#include "settingviewmgr.h" + + +class CMainCatalogView : + public CSettingBaseView { +private: + struct SMainCatalog *m; + +public: + CMainCatalogView(const char *pViewId) : CSettingBaseView(pViewId), m(0) {} + virtual ~CMainCatalogView() {} + + Evas_Object *Base(void); + + virtual bool Create(struct settingview_data *view, void *prev); + virtual void Show(void); + virtual void Refresh(void); + virtual void Hide(void); + virtual void Destroy(void); + virtual void LangChanged(void); + virtual void Frozen(void); + virtual void Active(void); + +}; + +//struct setting_class *view_maincatalog_get_vclass(void); #endif /* __VIEW_MAINMENU_H__ */ diff --git a/include/view_need_pwd.h b/include/view_need_pwd.h index 7dafdf2..0ae50bc 100644 --- a/include/view_need_pwd.h +++ b/include/view_need_pwd.h @@ -17,8 +17,35 @@ #ifndef __VIEW_NEED_PASSCODE_H__ #define __VIEW_NEED_PASSCODE_H__ -#include "viewmgr.h" -struct setting_class *view_need_passcode_get_vclass(void); +#include "settingviewmgr.h" + + +class CNeedPasscodeView : + public CSettingBaseView { +private: + struct SNeedPasscodeView *m; + +private: + static void sm_CbCtxpopupDismissed(void *priv, Evas_Object *obj, void *ev); + void m_OnCtxpopupDismissed(Evas_Object *obj, void *ev); + + static void sm_CbKeyDown(void *priv, Evas *e, Evas_Object *obj, void *ei); + void m_OnKeyDown(Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev); + + int m_AddViewEntries(void); + +public: + CNeedPasscodeView(const char *pViewId) : CSettingBaseView(pViewId), m(0) {} + virtual ~CNeedPasscodeView() {} + + Evas_Object *Base(void); + + virtual bool Create(struct settingview_data *view, void *prev); + virtual void Show(void); + virtual void Refresh(void); + virtual void Hide(void); + virtual void Destroy(void); +}; #endif /* __VIEW_NEED_PASSCODE_H__ */ diff --git a/include/view_pwd_popup.h b/include/view_pwd_popup.h index 58cb88f..9a40adf 100644 --- a/include/view_pwd_popup.h +++ b/include/view_pwd_popup.h @@ -17,8 +17,31 @@ #ifndef __VIEW_PASSCODE_POPUP_H__ #define __VIEW_PASSCODE_POPUP_H__ -#include "viewmgr.h" -struct setting_class *view_passcode_popup_get_vclass(void); +#include "settingviewmgr.h" + + +//struct setting_class *view_passcode_popup_get_vclass(void); +class CPasscodePopupView : + public CSettingBaseView { +private: + struct SPasscodePopupView *m; + +private: + static void sm_CbCtxpopupDismissed(void *priv, Evas_Object *obj, void *ev); + void m_OnCtxpopupDismissed(Evas_Object *obj, void *ev); + +public: + CPasscodePopupView(const char *pViewId) : CSettingBaseView(pViewId), m(0) {} + virtual ~CPasscodePopupView() {} + + Evas_Object *Base(void); + + virtual bool Create(struct settingview_data *view, void *prev); + virtual void Show(void); + virtual void Hide(void); + virtual void Destroy(void); +}; + #endif /* __VIEW_PASSCODE_POPUP_H__ */ diff --git a/include/view_sublist.h b/include/view_sublist.h index 930faaa..9733191 100644 --- a/include/view_sublist.h +++ b/include/view_sublist.h @@ -17,8 +17,47 @@ #ifndef __VIEW_SUBLIST_H__ #define __VIEW_SUBLIST_H__ -#include "viewmgr.h" -struct setting_class *view_sublist_get_vclass(void); +#include "settingviewmgr.h" + + +class CSublistView : + public CSettingBaseView { +private: + struct SSublistView *m; + +private: + static void sm_CbSubitemBtnClicked(void *data, Evas_Object *obj, void *ev); + void m_OnSubitemBtnClicked(Evas_Object *obj, void *ev); + + static void sm_CbSubitemKeyPressed(void *data, Evas *e, Evas_Object *obj, void *ei); + void m_OnSubitemKeyPressed(Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev); + + static void sm_CbSubitemFocusOut(void *data, Evas_Object *obj, void *ev); + void m_OnSubitemFocusOut(Evas_Object *obj, void *ev); + + static void sm_CbSubitemFocusIn(void *data, Evas_Object *obj, void *ev); + void m_OnSubitemFocusIn(Evas_Object *obj, void *ev); + + static void sm_CbCtxpopupDismissed(void *data, Evas_Object *obj, void *ev); + void m_OnCtxpopupDismissed(Evas_Object *obj, void *ev); + + int m_DrawSublist(void); + void m_ExitView(void); + void m_SetSelectedValue(Evas_Object *obj); + int m_DrawListItems(Eina_List *list); + +public: + CSublistView(const char *pViewId) : CSettingBaseView(pViewId), m(0) {} + virtual ~CSublistView() {} + + Evas_Object *Base(void); + + virtual bool Create(struct settingview_data *view, void *prev); + virtual void Show(void); + virtual void Hide(void); + virtual void Destroy(void); +}; + #endif /* __VIEW_SUBLIST_H__ */ diff --git a/include/view_system_clock.h b/include/view_system_clock.h index 2e9eb3f..2881ff5 100644 --- a/include/view_system_clock.h +++ b/include/view_system_clock.h @@ -17,8 +17,42 @@ #ifndef _VIEW_SYSTEM_CLOCK_H__ #define _VIEW_SYSTEM_CLOCK_H__ -#include "viewmgr.h" -struct setting_class *view_system_clock_get_vclass(void); +#include "settingviewmgr.h" + + +class CSystemClockView : + public CSettingBaseView { +private: + struct SSystemClockView *m; + +private: + static void sm_CbSubitemClicked(void *priv, Evas_Object *obj, void *ev); + void m_OnSubitemClicked(Evas_Object *obj, void *ev); + + static void sm_CbSubitemKeypress(void *priv, Evas *e, Evas_Object *obj, void *ei); + void m_OnSubitemKeypress(Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ei); + + static void sm_CbCtxpopupDismissed(void *priv, Evas_Object *obj, void *ev); + void m_OnCtxpopupDismissed(Evas_Object *obj, void *ev); + + void m_ExitView(void); + + int m_DrawSysclkSublist(void); + int m_AddSysclkSublistItem(Eina_List *list, const char *selval); + +public: + CSystemClockView(const char *pViewId) : CSettingBaseView(pViewId), m(0) {} + virtual ~CSystemClockView() {} + + Evas_Object *Base(void); + + virtual bool Create(struct settingview_data *view, void *prev); + virtual void Show(void); + virtual void Refresh(void); + virtual void Hide(void); + virtual void Destroy(void); +}; + #endif /* _VIEW_SYSTEM_CLOCK_H__ */ diff --git a/include/view_uigadget.h b/include/view_uigadget.h index d35ee8b..88359e0 100644 --- a/include/view_uigadget.h +++ b/include/view_uigadget.h @@ -17,8 +17,35 @@ #ifndef __VIEW_UIGADGET_H__ #define __VIEW_UIGADGET_H__ -#include "viewmgr.h" -struct setting_class *view_uigadget_get_vclass(void); +#include +#include "settingviewmgr.h" + + +class CUiGadgetView : + public CSettingBaseView { +private: + struct SUiGadgetView *m; + +private: + static void sm_CbUgLayout(ui_gadget_h ug, enum ug_mode mode, void *priv); + static void sm_CbUgResult(ui_gadget_h ug, service_h result, void *priv); + static void sm_CbUgDestroy(ui_gadget_h ug, void *priv); + void m_OnUgDestroy(ui_gadget_h ug); + + bool m_Load(void); + void m_BackToMainview(void); + +public: + CUiGadgetView(const char *pViewId) : CSettingBaseView(pViewId), m(0) {} + virtual ~CUiGadgetView() {} + + Evas_Object *Base(void); + + virtual bool Create(struct settingview_data *view, void *prev); + virtual void Show(void); + virtual void Hide(void); + virtual void Destroy(void); +}; #endif /* __VIEW_UIGADGET_H__ */ diff --git a/src/main.cpp b/src/main.cpp index e043aad..c9d424a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,7 +19,7 @@ #include #include "dbg.h" #include "def.h" -#include "viewmgr.h" +#include "settingviewmgr.h" #include "utils.h" #include "json_marco.h" #include "settings_provider.h" diff --git a/src/viewmgr.cpp b/src/settingviewmgr.cpp similarity index 77% rename from src/viewmgr.cpp rename to src/settingviewmgr.cpp index bc98edd..4a85a31 100644 --- a/src/viewmgr.cpp +++ b/src/settingviewmgr.cpp @@ -16,9 +16,10 @@ #include #include -#include "viewmgr.h" -#include "data_wrapper.h" #include "dbg.h" + +#include "settingviewmgr.h" +#include "data_wrapper.h" #include "timeout_handler.h" #include "view_maincatalog.h" #include "view_uigadget.h" @@ -26,12 +27,12 @@ #include "view_pwd_popup.h" #include "view_system_clock.h" #include "view_need_pwd.h" -#include "viewmgr.h" +//#include "settingviewmgr.h" #define MAINCATALOG "maincatalog" #define PATH_FACTOR 3 -struct setting_mgr { +struct SSettingMgr { Evas_Object *win; int depth; @@ -46,16 +47,37 @@ struct setting_mgr { struct _settinginfo { Evas_Object *base; - struct setting_class *sclass; + CSettingBaseView *sclass; struct settingview_data *sview; }; struct settingui_func_map { const char *style; - struct setting_class* (*get_vclass)(void); + CSettingBaseView *view; + //struct setting_class* (*get_vclass)(void); }; -static struct settingui_func_map g_func_map[] = { + +CSettingBaseView::CSettingBaseView(const char *pViewId) +{ + m_title = new char[strlen(pViewId) + 1]; + strcpy(m_title, pViewId); +} + + +CSettingBaseView::~CSettingBaseView() +{ + delete[] m_title; +} + + +Evas_Object *CSettingBaseView::Base(void) +{ + return NULL; +} + + +static struct settingui_func_map g_func_map[5];/* = { { .style = STYLE_UIGADGET, .get_vclass = view_uigadget_get_vclass @@ -75,18 +97,18 @@ static struct settingui_func_map g_func_map[] = { { .style = STYLE_NEED_PASSCODE, .get_vclass = view_need_passcode_get_vclass - } -}; + }*/ +//}; /** * This function is invoked to build setting view data. * -* @param mgr [in] The setting_mgr data pointer. +* @param mgr [in] The SSettingMgr data pointer. * @param name[in] The item name to be created view. * @return The settingview_data data pointer, NULL on error. */ static struct settingview_data *_build_setting_view( - struct setting_mgr *mgr, const char *name) + struct SSettingMgr *mgr, const char *name) { struct settingview_data *data; int r; @@ -111,17 +133,20 @@ static struct settingview_data *_build_setting_view( return data; } + + +CMainCatalogView g_maincatalog(VCLASS_TITLE_MAIN_VIEW); /** * This function is invoked to get setting_class data pointer, this data stand for a kind of view. * -* @param mgr [in] The setting_mgr data pointer. +* @param mgr [in] The SSettingMgr data pointer. * @param view[in] The settingview_data data pointer. * @return The setting_class data pointer, NULL on error. */ -static struct setting_class *_get_view_class(struct setting_mgr *mgr, +static CSettingBaseView *_get_view_class(SSettingMgr *mgr, struct settingview_data *view) { - struct setting_class *vclass; + CSettingBaseView *vclass; struct settingitem *parent; Eina_List *list; const char *style; @@ -144,13 +169,13 @@ static struct setting_class *_get_view_class(struct setting_mgr *mgr, if (list && !style) { if (mgr->depth == 1) - vclass = view_maincatalog_get_vclass(); + vclass = &g_maincatalog;// view_maincatalog_get_vclass(); } else { size = sizeof(g_func_map) / sizeof(*g_func_map); for (i = 0; i < size; i++) { if (!strncmp(style, g_func_map[i].style, strlen(style)) - && g_func_map[i].get_vclass) { - vclass = g_func_map[i].get_vclass(); + && g_func_map[i].view) { + vclass = g_func_map[i].view;// get_vclass(); break; } } @@ -162,10 +187,10 @@ static struct setting_class *_get_view_class(struct setting_mgr *mgr, /** * This function is invoked to hide all views stored in view list. * -* @param mgr [in] The setting_mgr data pointer. +* @param mgr [in] The SSettingMgr data pointer. * @return void. */ -void _hide_view_in_list(struct setting_mgr *mgr) +void _hide_view_in_list(struct SSettingMgr *mgr) { Eina_List *l; struct _settinginfo *sinfo; @@ -178,18 +203,19 @@ void _hide_view_in_list(struct setting_mgr *mgr) EINA_LIST_FOREACH(mgr->view_list, l, obj) { sinfo = (struct _settinginfo *) obj; - if (sinfo->sclass->hide) - sinfo->sclass->hide(sinfo->base); + sinfo->sclass->Hide(); + //if (sinfo->sclass->hide) + // sinfo->sclass->hide(sinfo->base); } } /** * This function is invoked to show all views stored in view list. * -* @param mgr [in] The setting_mgr data pointer. +* @param mgr [in] The SSettingMgr data pointer. * @return void. */ -void _show_view_in_list(struct setting_mgr *mgr) +void _show_view_in_list(struct SSettingMgr *mgr) { Eina_List *l; struct _settinginfo *sinfo; @@ -202,18 +228,19 @@ void _show_view_in_list(struct setting_mgr *mgr) EINA_LIST_FOREACH(mgr->view_list, l, obj) { sinfo = (struct _settinginfo *) obj; - if (sinfo->sclass->show) - sinfo->sclass->show(sinfo->base); + sinfo->sclass->Show(); + //if (sinfo->sclass->show) + // sinfo->sclass->show(sinfo->base); } } /** * This function is invoked to destroy all views stored in view list. * -* @param mgr [in] The setting_mgr data pointer. +* @param mgr [in] The SSettingMgr data pointer. * @return void. */ -void _destroy_views_in_list(struct setting_mgr *mgr) +void _destroy_views_in_list(struct SSettingMgr *mgr) { Eina_List *l; struct _settinginfo *sinfo; @@ -226,18 +253,19 @@ void _destroy_views_in_list(struct setting_mgr *mgr) EINA_LIST_FOREACH(mgr->view_list, l, obj) { sinfo = (struct _settinginfo *) obj; - if (sinfo->sclass->destroy) - sinfo->sclass->destroy(sinfo->base); + sinfo->sclass->Destroy(); + //if (sinfo->sclass->destroy) + // sinfo->sclass->destroy(sinfo->base); } } /** * This function is invoked to freeze all views's event stored in view list. * -* @param mgr [in] The setting_mgr data pointer. +* @param mgr [in] The SSettingMgr data pointer. * @return void. */ -void _frozen_view_in_list(struct setting_mgr *mgr) +void _frozen_view_in_list(struct SSettingMgr *mgr) { Eina_List *l; struct _settinginfo *sinfo; @@ -250,18 +278,19 @@ void _frozen_view_in_list(struct setting_mgr *mgr) EINA_LIST_REVERSE_FOREACH(mgr->view_list, l, obj) { sinfo = (struct _settinginfo *)obj; - if (sinfo->sclass->frozen) - sinfo->sclass->frozen(sinfo->base); + sinfo->sclass->Frozen(); + //if (sinfo->sclass->frozen) + // sinfo->sclass->frozen(sinfo->base); } } /** * This function is invoked to activate all views's event stored in view list. * -* @param mgr [in] The setting_mgr data pointer. +* @param mgr [in] The SSettingMgr data pointer. * @return void. */ -void _active_view_in_list(struct setting_mgr *mgr) +void _active_view_in_list(struct SSettingMgr *mgr) { Eina_List *l; struct _settinginfo *sinfo; @@ -274,8 +303,9 @@ void _active_view_in_list(struct setting_mgr *mgr) EINA_LIST_REVERSE_FOREACH(mgr->view_list, l, obj) { sinfo = (struct _settinginfo *)obj; - if (sinfo->sclass->active) - sinfo->sclass->active(sinfo->base); + sinfo->sclass->Active(); + //if (sinfo->sclass->active) + // sinfo->sclass->active(sinfo->base); } } @@ -287,7 +317,7 @@ CSettingMgr *CSettingMgr::instance = NULL; * This function is invoked to initialize setting manager. * * @param win [in] The window's evas object. -* @return The setting_mgr data pointer. +* @return The SSettingMgr data pointer. */ bool CSettingMgr::Initialize(Evas_Object *win) { @@ -297,7 +327,7 @@ bool CSettingMgr::Initialize(Evas_Object *win) if (!instance) { return false; } - instance->m = new setting_mgr; + instance->m = new SSettingMgr; if (!instance->m) { delete instance; return false; @@ -328,6 +358,29 @@ bool CSettingMgr::Initialize(Evas_Object *win) return false; } + CUiGadgetView g_uigadget(VCLASS_TITLE_UG); + CSublistView g_sublist(VCLASS_TITLE_SUBLIST); + CPasscodePopupView g_passcodePopup(VCLASS_TITLE_CHANGE_PASSCODE); + CSystemClockView g_systemclock(VCLASS_TITLE_SYSTEM_CLOCK); + CNeedPasscodeView g_needpasscode(VCLASS_TITLE_NEED_PASSCODE); + + g_func_map[0].style = STYLE_UIGADGET; + g_func_map[0].view = &g_uigadget; + + g_func_map[1].style = STYLE_CTXPOPUP; + g_func_map[1].view = &g_sublist; + + g_func_map[2].style = STYLE_PASSCODE_POPUP; + g_func_map[2].view = &g_passcodePopup; + + g_func_map[3].style = STYLE_CLOCK_CTXPOPUP; + g_func_map[3].view = &g_systemclock; + + g_func_map[4].style = STYLE_NEED_PASSCODE; + g_func_map[4].view = &g_needpasscode; + + + instance->m->win = win; instance->m->depth = 0; @@ -341,9 +394,9 @@ bool CSettingMgr::Initialize(Evas_Object *win) /** * This function is invoked to destroy all views stored in view list and release -* setting_mgr data structure. +* SSettingMgr data structure. * -* @param mgr [in] The setting_mgr data pointer. +* @param mgr [in] The SSettingMgr data pointer. * @return void. */ void CSettingMgr::Finalize(void) @@ -387,7 +440,7 @@ CSettingMgr *CSettingMgr::GetInstance(void) * Firstly, it will build view data, then get specific view class to create view. * Otherwise, it will freeze or hide background view and store _settinginfo data into view list. * -* @param mgr [in] The setting_mgr data pointer. +* @param mgr [in] The SSettingMgr data pointer. * @param name [in] The item name to be pushed view. * @param data [in] The function specific data passed by caller. * @return 0 if success, -1 if fail. @@ -397,9 +450,8 @@ bool CSettingMgr::ViewPush(const char *name, void *data) ASSERT(m); ASSERT(name); - Evas_Object *base; struct _settinginfo *sinfo; - struct setting_class *sclass; + CSettingBaseView *sclass; struct settingview_data *view; m->depth++; @@ -420,8 +472,7 @@ bool CSettingMgr::ViewPush(const char *name, void *data) goto error; } - base = sclass->create(this, view, data); - if (!base) { + if (!sclass->Create(view, data)) { _ERR("failed to create base layout."); goto error; } @@ -431,10 +482,9 @@ bool CSettingMgr::ViewPush(const char *name, void *data) if (sclass->hide_view) _hide_view_in_list(m); - if (sclass->show) - sclass->show(base); + sclass->Show(); - sinfo->base = base; + sinfo->base = sclass->Base(); sinfo->sclass = sclass; sinfo->sview = view; @@ -456,7 +506,7 @@ error: * Firstly, get top view's _settinginfo data from view list, then call destroy interface of * view class, finally it will refresh second view, activate and show all views behind top view. * -* @param mgr [in] The setting_mgr data pointer. +* @param mgr [in] The SSettingMgr data pointer. * @return void. */ void CSettingMgr::ViewPop(void) @@ -464,7 +514,7 @@ void CSettingMgr::ViewPop(void) ASSERT(m); struct _settinginfo *sinfo, *prev; - struct setting_class *sclass; + CSettingBaseView *sclass; int hide; char *item; const char *title; @@ -478,15 +528,14 @@ void CSettingMgr::ViewPop(void) sclass = sinfo->sclass; hide = sclass->hide_view; - title = sclass->title; + title = sclass->Title(); item = NULL; if (!strncmp(title, VCLASS_TITLE_BOTTOM_SLIDER, strlen(title))) item = (char *)evas_object_data_del(sinfo->base, SELECTED_ITEM_ID); - if (sclass->destroy && sinfo->base) - sclass->destroy(sinfo->base); + sclass->Destroy(); m->view_list = eina_list_remove_list(m->view_list, m->view_list); free(sinfo); @@ -503,11 +552,8 @@ void CSettingMgr::ViewPop(void) if (item && !strncmp(title, VCLASS_TITLE_BOTTOM_SLIDER, strlen(title))) evas_object_data_set(prev->base, SELECTED_ITEM_ID, item); - if (sclass->refresh) - sclass->refresh(prev->base); - - if (sclass->update) - sclass->update(prev->base); + sclass->Refresh(); + sclass->Update(); _active_view_in_list(m); @@ -518,7 +564,7 @@ void CSettingMgr::ViewPop(void) /** * This function is invoked to get window's evas object. * -* @param mgr [in] The setting_mgr data pointer. +* @param mgr [in] The SSettingMgr data pointer. * @return The window's evas object, NULL on error. */ Evas_Object *CSettingMgr::Window(void) @@ -531,7 +577,7 @@ Evas_Object *CSettingMgr::Window(void) /** * This function is invoked to get view data with specific name. * -* @param mgr [in] The setting_mgr data pointer. +* @param mgr [in] The SSettingMgr data pointer. * @param name [in] The view name to be got. * @return The settingview_data data pointer, NULL on error. */ @@ -545,7 +591,7 @@ settingview_data *CSettingMgr::GetView(const char *name) /** * This function is invoked to get setting manager data. * -* @param mgr [in] The setting_mgr data pointer. +* @param mgr [in] The SSettingMgr data pointer. * @return The settingmgr_data data pointer, NULL on error. */ settingmgr_data *CSettingMgr::GetData(void) @@ -558,7 +604,7 @@ settingmgr_data *CSettingMgr::GetData(void) /** * This function is invoked to get view list. * -* @param mgr [in] The setting_mgr data pointer. +* @param mgr [in] The SSettingMgr data pointer. * @return The Eina_List data pointer, NULL on error. */ Eina_List *CSettingMgr::GetViewList(void) @@ -575,7 +621,7 @@ Eina_List *CSettingMgr::GetViewList(void) * When launch setting by command-line, this function will be invoked. In this launching * way, setting will be launched and move focus to specific item. * -* @param mgr [in] The setting_mgr data pointer. +* @param mgr [in] The SSettingMgr data pointer. * @param name [in] The item name. * @return 0 if success, -1 if fail. */ @@ -637,7 +683,7 @@ bool CSettingMgr::LaunchItem(const char *name) * Item path is a value described all node value from root node to item * in setting tree of json files. * -* @param mgr [in] The setting_mgr data pointer. +* @param mgr [in] The SSettingMgr data pointer. * @return The Eina_Array data pointer, NULL on error. */ Eina_Array *CSettingMgr::GetItemPath(void) @@ -650,7 +696,7 @@ Eina_Array *CSettingMgr::GetItemPath(void) /** * This function is invoked to refresh all view stored in view list. * -* @param mgr [in] The setting_mgr data pointer. +* @param mgr [in] The SSettingMgr data pointer. * @return void. */ void CSettingMgr::ViewRefresh(void) @@ -658,7 +704,7 @@ void CSettingMgr::ViewRefresh(void) ASSERT(m); struct _settinginfo *info; - struct setting_class *vclass; + CSettingBaseView *vclass; if (!m->view_list) return; @@ -669,17 +715,14 @@ void CSettingMgr::ViewRefresh(void) vclass = info->sclass; - if (vclass->refresh) - vclass->refresh(info->base); - - if (vclass->update) - vclass->update(info->base); + vclass->Refresh(); + vclass->Update(); } /** * This function is invoked to set refresh flag. * -* @param mgr [in] The setting_mgr data pointer. +* @param mgr [in] The SSettingMgr data pointer. * @param val [in] The value to be set. * @return void. */ @@ -693,7 +736,7 @@ void CSettingMgr::SetRefreshFlag(unsigned int val) /** * This function is invoked to get refresh flag. * -* @param mgr [in] The setting_mgr data pointer. +* @param mgr [in] The SSettingMgr data pointer. * @return The refresh flag value, -1 if fail. */ unsigned int CSettingMgr::GetRefreshFlag(void) @@ -706,7 +749,7 @@ unsigned int CSettingMgr::GetRefreshFlag(void) /** * This function is invoked to set relaunch flag. * -* @param mgr [in] The setting_mgr data pointer. +* @param mgr [in] The SSettingMgr data pointer. * @param val [in] The value to be set. * @return void. */ @@ -720,7 +763,7 @@ void CSettingMgr::SetRelaunchFlag(unsigned int val) /** * This function is invoked to get relaunch flag. * -* @param mgr [in] The setting_mgr data pointer. +* @param mgr [in] The SSettingMgr data pointer. * @return The refresh flag value, -1 if fail. */ unsigned int CSettingMgr::GetRelaunchFlag(void) @@ -733,7 +776,7 @@ unsigned int CSettingMgr::GetRelaunchFlag(void) /** * This function wrapped timeout_handler interface to freeze timer. * -* @param mgr [in] The setting_mgr data pointer. +* @param mgr [in] The SSettingMgr data pointer. * @return void. */ void CSettingMgr::FreezeTimeout(void) @@ -747,7 +790,7 @@ void CSettingMgr::FreezeTimeout(void) /** * This function wrapped timeout_handler interface to thaw timer. * -* @param mgr [in] The setting_mgr data pointer. +* @param mgr [in] The SSettingMgr data pointer. * @return void. */ void CSettingMgr::ThawTimeout(void) @@ -761,7 +804,7 @@ void CSettingMgr::ThawTimeout(void) /** * This function is invoked to get timeout freeze state. * -* @param mgr [in] The setting_mgr data pointer. +* @param mgr [in] The SSettingMgr data pointer. * @return EINA_TRUE if current state is frozen * EINA_FALSE if current state is normal or occurred error. */ @@ -775,7 +818,7 @@ Eina_Bool CSettingMgr::GetTimeoutFreezeState(void) /** * This function is invoked to refresh all views when system language changed. * -* @param mgr [in] The setting_mgr data pointer. +* @param mgr [in] The SSettingMgr data pointer. * @return void. */ void CSettingMgr::LangChanged(void) @@ -798,7 +841,6 @@ void CSettingMgr::LangChanged(void) return; } - if (sinfo->sclass->lang_changed) - sinfo->sclass->lang_changed(sinfo->base); + sinfo->sclass->LangChanged(); } } diff --git a/src/view_maincatalog.cpp b/src/view_maincatalog.cpp index 277740c..61331df 100644 --- a/src/view_maincatalog.cpp +++ b/src/view_maincatalog.cpp @@ -19,12 +19,12 @@ #include "dbg.h" #include "def.h" #include "stdbool.h" -#include "viewmgr.h" +#include "settingviewmgr.h" #include "utils.h" #include "view_maincatalog.h" #include "data_wrapper.h" #include "settings_provider.h" -#include "viewmgr.h" +#include "settingviewmgr.h" #define DATA_ID "main_setting_data" #define SUBITEM_DATA_ID "subitem_data_id" @@ -49,7 +49,7 @@ enum focused_state { FOCUS_SUB_ITEM }; -struct _view_data { +struct SMainCatalog { Evas_Object *win; Evas_Object *base; Eina_Array *sub_item_btn; @@ -78,7 +78,7 @@ struct _view_data { * * @return: void. */ -static void _move_from_subitem_to_main_item(struct _view_data *data, +static void _move_from_subitem_to_main_item(SMainCatalog *data, Evas_Object *btn) { if (!data || !btn) @@ -104,7 +104,7 @@ static void _subitem_key_pressed_cb(void *data, Evas *e, Evas_Object *obj, void *ei) { Evas_Event_Key_Down *ev; - struct _view_data *priv; + SMainCatalog *priv; Evas_Object *pb; Evas_Object *next; @@ -115,7 +115,7 @@ static void _subitem_key_pressed_cb(void *data, Evas *e, if (!ev->keyname) return; - priv = (struct _view_data *)data; + priv = (SMainCatalog *)data; if (!strcmp(ev->keyname, KEY_LEFT) || !strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) { pb = (Evas_Object *) evas_object_data_get(obj, PROGRESS_BAR_DATA); @@ -199,7 +199,7 @@ static void _get_geometry_data(Evas_Object *obj, * * @return: 0 - success, -1 - fail. */ -static int _push_ug_view(struct _view_data *data, +static int _push_ug_view(SMainCatalog *data, struct settingitem *item, Evas_Object *obj) { const char *id; @@ -237,7 +237,7 @@ static int _push_ug_view(struct _view_data *data, * * @return: 0 - success, -1 - fail. */ -static int _push_sublist_view(struct _view_data *data, +static int _push_sublist_view(SMainCatalog *data, struct settingitem *item, Evas_Object *obj) { const char *id; @@ -275,7 +275,7 @@ static int _push_sublist_view(struct _view_data *data, * * @return: 0 - success, -1 - fail. */ -static int _push_bottom_sublist_view(struct _view_data *data, +static int _push_bottom_sublist_view(SMainCatalog *data, struct settingitem *item) { const char *id; @@ -308,7 +308,7 @@ static int _push_bottom_sublist_view(struct _view_data *data, * * @return: 0 - success, -1 - fail. */ -static int _push_bottom_slider_view(struct _view_data *data, +static int _push_bottom_slider_view(SMainCatalog *data, struct settingitem *item, Evas_Object *obj) { const char *id; @@ -351,7 +351,7 @@ static int _push_bottom_slider_view(struct _view_data *data, * * @return: 0 - success, -1 - fail. */ -static int _push_passcode_popup_view(struct _view_data *data, +static int _push_passcode_popup_view(SMainCatalog *data, struct settingitem *item) { const char *id; @@ -383,7 +383,7 @@ static int _push_passcode_popup_view(struct _view_data *data, * * @return: 0 - success, -1 - fail. */ -static int _push_device_manager_view(struct _view_data *data, +static int _push_device_manager_view(SMainCatalog *data, struct settingitem *item) { const char *id; @@ -419,7 +419,7 @@ static int _push_device_manager_view(struct _view_data *data, * * @return: 0 - success, -1 - fail. */ -static int _push_reset_popup_view(struct _view_data *data, +static int _push_reset_popup_view(SMainCatalog *data, struct settingitem *item) { const char *id; @@ -451,7 +451,7 @@ static int _push_reset_popup_view(struct _view_data *data, * * @return: 0 - success, -1 - fail. */ -static int _push_upgrade_popup_view(struct _view_data *data, +static int _push_upgrade_popup_view(SMainCatalog *data, struct settingitem *item) { const char *id; @@ -484,7 +484,7 @@ static int _push_upgrade_popup_view(struct _view_data *data, * * @return: 0 - success, -1 - fail. */ -static int _push_clock_sublist_view(struct _view_data *data, +static int _push_clock_sublist_view(SMainCatalog *data, struct settingitem *item, Evas_Object *obj) { const char *id; @@ -529,7 +529,7 @@ static int _push_clock_sublist_view(struct _view_data *data, * * @return: 0 - success, -1 - fail. */ -static int _push_need_passcode_view(struct _view_data *data, +static int _push_need_passcode_view(SMainCatalog *data, struct settingitem *item, Evas_Object *obj) { const char *id; @@ -569,7 +569,7 @@ static int _push_need_passcode_view(struct _view_data *data, */ static void _submenu_item_clicked(void *data, Evas_Object *obj) { - struct _view_data *priv; + SMainCatalog *priv; const char *style; struct settingitem *item; @@ -578,7 +578,7 @@ static void _submenu_item_clicked(void *data, Evas_Object *obj) return; } - priv = (struct _view_data *) data; + priv = (SMainCatalog *) data; if (priv->focus_status != FOCUS_SUB_ITEM) return; @@ -656,7 +656,7 @@ static void _submenu_item_clicked(void *data, Evas_Object *obj) static void _subitem_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) { - struct _view_data *priv; + SMainCatalog *priv; Evas_Object *icon; if (!data || !obj) { @@ -664,7 +664,7 @@ static void _subitem_btn_clicked_cb(void *data, return; } - priv = (struct _view_data *)data; + priv = (SMainCatalog *)data; _submenu_item_clicked(priv, obj); @@ -938,7 +938,7 @@ static void _draw_subitem_with_style(Evas_Object *base, Evas_Object *obj, * * @return: void. */ -static void _release_subitems(struct _view_data *data) +static void _release_subitems(SMainCatalog *data) { Evas_Object *btn; void* obj; @@ -973,7 +973,7 @@ static void _release_subitems(struct _view_data *data) * * @return: 0 - success, -1 - fail. */ -static int _refresh_subitems(struct _view_data *data) +static int _refresh_subitems(SMainCatalog *data) { Evas_Object *btn; void* obj; @@ -1027,13 +1027,13 @@ static void _subitem_btn_mouse_out_cb(void *data, Evas *e, static void _subitem_btn_mouse_in_cb(void *data, Evas *e, Evas_Object *obj, void *ei) { - struct _view_data *priv; + SMainCatalog *priv; Evas_Object *icon, *pb; if (!obj || !data) return; - priv = (struct _view_data *)data; + priv = (SMainCatalog *)data; elm_object_focus_set(obj, EINA_TRUE); @@ -1071,7 +1071,7 @@ static void _subitem_btn_mouse_in_cb(void *data, Evas *e, * * @return: 0 - success, -1 - fail. */ -static int _draw_subitems(struct _view_data *data, const char *name) +static int _draw_subitems(SMainCatalog *data, const char *name) { Evas_Object *box, *btn, *tmp; struct settingview_data *view; @@ -1209,7 +1209,7 @@ static int _draw_subitems(struct _view_data *data, const char *name) * * @return: void. */ -static void _move_from_main_item_to_subitem(struct _view_data *data, +static void _move_from_main_item_to_subitem(SMainCatalog *data, Evas_Object *mainbtn) { Evas_Object *btn, *pb, *icon; @@ -1266,7 +1266,7 @@ static void _main_setting_key_pressed_cb(void *data, Evas *e, Evas_Object *obj, void *ei) { Evas_Event_Key_Down *ev; - struct _view_data *priv; + SMainCatalog *priv; Evas_Object *next, *icon; const char *name; @@ -1277,7 +1277,7 @@ static void _main_setting_key_pressed_cb(void *data, Evas *e, if (!ev->keyname) return; - priv = (struct _view_data *)data; + priv = (SMainCatalog *)data; if (!strcmp(ev->keyname, KEY_DOWN)) { icon = elm_object_part_content_get(obj, @@ -1367,7 +1367,7 @@ static void _main_setting_key_pressed_cb(void *data, Evas *e, static void _mainitem_btn_mouse_in_cb(void *data, Evas *e, Evas_Object *obj, void *ei) { - struct _view_data *priv; + SMainCatalog *priv; const char *name; Evas_Object *icon; @@ -1376,7 +1376,7 @@ static void _mainitem_btn_mouse_in_cb(void *data, Evas *e, return; } - priv = (struct _view_data *)data; + priv = (SMainCatalog *)data; if (priv->focus_status == FOCUS_SUB_ITEM) _move_from_subitem_to_main_item(priv, @@ -1429,14 +1429,14 @@ static void _mainitem_btn_mouse_out_cb(void *data, Evas *e, static void _mainitem_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) { - struct _view_data *priv; + SMainCatalog *priv; if (!data || !obj) { _ERR("Invalid argument"); return; } - priv = (struct _view_data *)data; + priv = (SMainCatalog *)data; _move_from_main_item_to_subitem(priv, obj); } @@ -1448,7 +1448,7 @@ static void _mainitem_btn_clicked_cb(void *data, * * @return: 0 - success, -1 - fail. */ -static int _add_icon_btns(struct _view_data *data, Eina_List *list) +static int _add_icon_btns(SMainCatalog *data, Eina_List *list) { Evas_Object *btn, *icon; const char *id, *name; @@ -1520,7 +1520,7 @@ static int _add_icon_btns(struct _view_data *data, Eina_List *list) * * @return: 0 - success, -1 - fail. */ -static int _draw_main_items(struct _view_data *data) +static int _draw_main_items(SMainCatalog *data) { Evas_Object *box, *btn, *tmp, *icon; Eina_Array *btns, *icons; @@ -1644,12 +1644,12 @@ static void _view_anim_finish(void *data, Evas_Object *obj, const char *emission, const char *source) { _DBG("START ========================================================="); - struct _view_data *priv; + SMainCatalog *priv; if (!data) return; - priv = (struct _view_data *)data; + priv = (SMainCatalog *)data; _draw_main_items(priv); _DBG("END ========================================================="); @@ -1663,7 +1663,7 @@ static void _view_anim_finish(void *data, Evas_Object *obj, * * @return: void. */ -void _move_focus_on_subitem(struct _view_data *data) +void _move_focus_on_subitem(SMainCatalog *data) { const char *path, *id; unsigned int i; @@ -1747,6 +1747,15 @@ static void _change_buttons_name(Eina_List *list, } } + +Evas_Object* CMainCatalogView::Base(void) +{ + ASSERT(m); + + return m->base; +} + + /** * Create all UI components of settings view. * @@ -1756,65 +1765,61 @@ static void _change_buttons_name(Eina_List *list, * * @return: the base layout of settings or null if error occurred. */ -static Evas_Object *_create(CSettingMgr *mgr, - struct settingview_data *view, void *prev) +bool CMainCatalogView::Create(struct settingview_data *view, void *prev) { + ASSERT(!m); + ASSERT(view); + _DBG("START =================================================================="); Evas_Object *base, *win; - struct _view_data *data; - - if (!mgr || !view) { - _ERR("Invalid argument"); - return NULL; - } + CSettingMgr *mgr = CSettingMgr::GetInstance(); win = mgr->Window(); - if (!win) { - _ERR("Fail to get win"); - return NULL; - } + ASSERT(win); - data = (struct _view_data *) calloc(1, sizeof(*data)); - if (!data) - return NULL; + m = (SMainCatalog *) calloc(1, sizeof(*m)); + if (!m) + return false; base = elm_layout_add(win); if (!base) { - free(data); - return NULL; + delete m; + m = NULL; + return false; } if (!elm_layout_file_set(base, EDJ_FILE, MAIN_VIEW_PAGE)) goto error; - data->mgr = mgr; - data->win = win; - data->base = base; - data->main_setting_view = view; - data->subsetting_view = NULL; - data->item_path = mgr->GetItemPath(); + m->mgr = mgr; + m->win = win; + m->base = base; + m->main_setting_view = view; + m->subsetting_view = NULL; + m->item_path = mgr->GetItemPath(); - evas_object_data_set(base, DATA_ID, data); + evas_object_data_set(base, DATA_ID, m); elm_object_signal_callback_add(base, MAIN_VIEW_ANIM_FINISH, - MAIN_VIEW_SOURCE, _view_anim_finish, data); + MAIN_VIEW_SOURCE, _view_anim_finish, m); - if (!data->item_path) - elm_object_signal_emit(data->base, MAIN_VIEW_LOAD, ""); + if (!m->item_path) + elm_object_signal_emit(m->base, MAIN_VIEW_LOAD, ""); else - _view_anim_finish(data, NULL, NULL, NULL); + _view_anim_finish(m, NULL, NULL, NULL); - return base; _DBG("END =================================================================="); + return true; error: - evas_object_del(base); - free(data); _DBG("END-ERROR =================================================================="); - - return NULL; + evas_object_del(base); + delete m; + m = NULL; + return false; } + /** * Show the view of settings. * @@ -1822,9 +1827,10 @@ error: * * @return: void. */ -static void _show(Evas_Object *base) +void CMainCatalogView::Show(void) { - struct _view_data *data; + ASSERT(m); + unsigned int cnt, i; const char *name, *path; Evas_Object *btn, *icon; @@ -1832,25 +1838,14 @@ static void _show(Evas_Object *base) Eina_Array *btns; Eina_Array_Iterator a; - if (!base) { - _ERR("Invalid argument"); - return; - } - - data = (struct _view_data *) evas_object_data_get(base, DATA_ID); - if (!data) { - _ERR("evas object data get failed. id: %s", DATA_ID); - return; - } - path = NULL; - if (data->item_path) { - btns = data->main_item_btn; + if (m->item_path) { + btns = m->main_item_btn; - cnt = eina_array_count(data->item_path); + cnt = eina_array_count(m->item_path); if (cnt > 1) { - path = (const char *) eina_array_data_get(data->item_path, cnt - 2); + path = (const char *) eina_array_data_get(m->item_path, cnt - 2); if (!path) return; } @@ -1862,10 +1857,10 @@ static void _show(Evas_Object *base) return; if (!strncmp(name, path, ARRAY_SIZE)) { - _draw_subitems(data, name); + _draw_subitems(m, name); icon = (Evas_Object *)eina_array_data_get( - data->main_icon_base, i); + m->main_icon_base, i); if (icon) elm_object_signal_emit(icon, MAIN_BTN_FOCUSED, @@ -1873,15 +1868,15 @@ static void _show(Evas_Object *base) elm_object_focus_set(btn, EINA_TRUE); - data->focus_status = FOCUS_MAIN_ITEM; - data->focused_main_item_btn = btn; + m->focus_status = FOCUS_MAIN_ITEM; + m->focused_main_item_btn = btn; - _move_focus_on_subitem(data); + _move_focus_on_subitem(m); } } } - evas_object_show(base); + evas_object_show(m->base); } /** @@ -1891,14 +1886,11 @@ static void _show(Evas_Object *base) * * @return: void. */ -static void _hide(Evas_Object *base) +void CMainCatalogView::Hide(void) { - if (!base) { - _ERR("Invalid argument"); - return; - } + ASSERT(m); - evas_object_hide(base); + evas_object_hide(m->base); } /** @@ -1908,9 +1900,10 @@ static void _hide(Evas_Object *base) * * @return: void. */ -static void _refresh(Evas_Object *base) +void CMainCatalogView::Refresh(void) { - struct _view_data *data; + ASSERT(m); + char *sld; const char *id; int i; @@ -1919,16 +1912,9 @@ static void _refresh(Evas_Object *base) Evas_Object *btn, *pb, *icon; void* obj; - if (!base) - return; - - data = (struct _view_data *) evas_object_data_get(base, DATA_ID); - if (!data) - return; - - sld = (char *) evas_object_data_del(base, SELECTED_ITEM_ID); + sld = (char *) evas_object_data_del(m->base, SELECTED_ITEM_ID); if (sld) { - EINA_ARRAY_ITER_NEXT(data->sub_item_btn, i, obj, a) { + EINA_ARRAY_ITER_NEXT(m->sub_item_btn, i, obj, a) { btn = (Evas_Object *) obj; item = (struct settingitem *) evas_object_data_get(btn, SUBITEM_DATA_ID); id = settingitem_get_id(item); @@ -1936,37 +1922,37 @@ static void _refresh(Evas_Object *base) continue; if (item && !strncmp(sld, id, strlen(sld))) { - data->focused_sub_item_btn = btn; + m->focused_sub_item_btn = btn; break; } } } - if (data->focus_status == FOCUS_SUB_ITEM) { - elm_object_focus_set(data->focused_sub_item_btn, EINA_TRUE); + if (m->focus_status == FOCUS_SUB_ITEM) { + elm_object_focus_set(m->focused_sub_item_btn, EINA_TRUE); - elm_object_signal_emit(data->focused_main_item_btn, + elm_object_signal_emit(m->focused_main_item_btn, MAINICONBTN_FOCUSED_ON_SUBITEM, MAINICONBTN_MAIN_ITEM_SOURCE); - icon = elm_object_part_content_get(data->focused_main_item_btn, + icon = elm_object_part_content_get(m->focused_main_item_btn, MAINICONBTN_ICON_SWALLOW); if (icon) elm_object_signal_emit(icon, MAIN_BTN_HIGHLIGHT, MAIN_BTN); - if (_refresh_subitems(data) == -1) + if (_refresh_subitems(m) == -1) _ERR("Refresh subitems failed"); - pb = (Evas_Object *) evas_object_data_get(data->focused_sub_item_btn, + pb = (Evas_Object *) evas_object_data_get(m->focused_sub_item_btn, PROGRESS_BAR_DATA); if (pb) elm_object_signal_emit(pb, SIG_UNCTRL_PB_FOCUSED, SRC_PB_PROG); } - if (data->mgr->GetTimeoutFreezeState() == EINA_TRUE) - data->mgr->ThawTimeout(); + if (m->mgr->GetTimeoutFreezeState() == EINA_TRUE) + m->mgr->ThawTimeout(); } /** @@ -1976,56 +1962,51 @@ static void _refresh(Evas_Object *base) * * @return: void. */ -static void _destroy(Evas_Object *base) +void CMainCatalogView::Destroy(void) { - struct _view_data *data; + ASSERT(m); + Eina_Array_Iterator a; Evas_Object *tmp; void* obj; unsigned int i; - if (!base) { - _ERR("Parameter error!"); - return; - } - - data = (struct _view_data *) evas_object_data_get(base, DATA_ID); - - if (data->sub_item_btn) { - EINA_ARRAY_ITER_NEXT(data->sub_item_btn, i, obj, a) + if (m->sub_item_btn) { + EINA_ARRAY_ITER_NEXT(m->sub_item_btn, i, obj, a) { tmp = (Evas_Object *) obj; evas_object_del(tmp); } - eina_array_free(data->sub_item_btn); + eina_array_free(m->sub_item_btn); } - if (data->main_item_btn) { - EINA_ARRAY_ITER_NEXT(data->main_item_btn, i, obj, a) + if (m->main_item_btn) { + EINA_ARRAY_ITER_NEXT(m->main_item_btn, i, obj, a) { tmp = (Evas_Object *) obj; evas_object_del(tmp); } - eina_array_free(data->main_item_btn); + eina_array_free(m->main_item_btn); } - if (data->main_icon_base) { - EINA_ARRAY_ITER_NEXT(data->main_icon_base, i, obj, a) + if (m->main_icon_base) { + EINA_ARRAY_ITER_NEXT(m->main_icon_base, i, obj, a) { tmp = (Evas_Object *) obj; evas_object_del(tmp); } - eina_array_free(data->main_icon_base); + eina_array_free(m->main_icon_base); } - if (data->main_setting_view) - viewdata_release(data->main_setting_view); + if (m->main_setting_view) + viewdata_release(m->main_setting_view); - if (data->subsetting_view) - viewdata_release(data->subsetting_view); + if (m->subsetting_view) + viewdata_release(m->subsetting_view); - free(data); - evas_object_del(base); + evas_object_del(m->base); + delete m; + m = NULL; } /** @@ -2035,34 +2016,26 @@ static void _destroy(Evas_Object *base) * * @return: void. */ -static void _lang_changed(Evas_Object *base) +void CMainCatalogView::LangChanged(void) { - struct _view_data *data; + ASSERT(m); + Eina_List *l; int cnt; - if (!base) { - _ERR("Invalid argument"); - return; - } - - data = (struct _view_data *) evas_object_data_get(base, DATA_ID); - if (!data) - return; - cnt = 0; - l = viewdata_get_childitems_list(data->main_setting_view); + l = viewdata_get_childitems_list(m->main_setting_view); if (l) cnt = eina_list_count(l); - _change_buttons_name(l, data->main_item_btn, cnt); + _change_buttons_name(l, m->main_item_btn, cnt); cnt = 0; - l = viewdata_get_childitems_list(data->subsetting_view); + l = viewdata_get_childitems_list(m->subsetting_view); if (l) cnt = eina_list_count(l); - _change_buttons_name(l, data->sub_item_btn, cnt); + _change_buttons_name(l, m->sub_item_btn, cnt); } /** @@ -2072,23 +2045,12 @@ static void _lang_changed(Evas_Object *base) * * @return: void. */ -static void _frozen(Evas_Object *base) +void CMainCatalogView::Frozen(void) { - struct _view_data *data; - - if (!base) { - _ERR("Invalid argument"); - return; - } - - data = (struct _view_data *)evas_object_data_get(base, DATA_ID); - if (!data) { - _ERR("Fail to get mainview data"); - return; - } + ASSERT(m); - evas_object_freeze_events_set(data->mainitem_box, EINA_TRUE); - evas_object_freeze_events_set(data->subitem_box, EINA_TRUE); + evas_object_freeze_events_set(m->mainitem_box, EINA_TRUE); + evas_object_freeze_events_set(m->subitem_box, EINA_TRUE); } /** @@ -2098,25 +2060,16 @@ static void _frozen(Evas_Object *base) * * @return: void. */ -static void _active(Evas_Object *base) +void CMainCatalogView::Active(void) { - struct _view_data *data; + ASSERT(m); - if (!base) { - _ERR("Invalid argument"); - return; - } - - data = (struct _view_data *)evas_object_data_get(base, DATA_ID); - if (!data) { - _ERR("Fail to get mainview data"); - return; - } - - evas_object_freeze_events_set(data->mainitem_box, EINA_FALSE); - evas_object_freeze_events_set(data->subitem_box, EINA_FALSE); + evas_object_freeze_events_set(m->mainitem_box, EINA_FALSE); + evas_object_freeze_events_set(m->subitem_box, EINA_FALSE); } + +#if 0 static struct setting_class _vclass = { VCLASS_TITLE_MAIN_VIEW, _create, @@ -2144,3 +2097,4 @@ struct setting_class *view_maincatalog_get_vclass(void) { return &_vclass; } +#endif \ No newline at end of file diff --git a/src/view_need_pwd.cpp b/src/view_need_pwd.cpp index d314894..0716ff4 100644 --- a/src/view_need_pwd.cpp +++ b/src/view_need_pwd.cpp @@ -50,7 +50,7 @@ enum { PWD_ENTRY_MAX }; -struct _chnllock_data { +struct SNeedPasscodeView { Evas_Object *win; Evas_Object *bg; Evas_Object *base; @@ -67,8 +67,8 @@ struct _chnllock_data { struct obj_geometry_data gd; }; -static void _free_priv_data(struct _chnllock_data *data); -static void _hide(Evas_Object *base); +static void _free_priv_data(SNeedPasscodeView *data); +//static void _hide(Evas_Object *base); /** * Free user data. @@ -77,7 +77,7 @@ static void _hide(Evas_Object *base); * * @return: void. */ -static void _free_priv_data(struct _chnllock_data *data) +static void _free_priv_data(SNeedPasscodeView *data) { if (!data) return; @@ -94,7 +94,6 @@ static void _free_priv_data(struct _chnllock_data *data) if (data->array) eina_array_free(data->array); - free(data); } /** @@ -166,12 +165,12 @@ static Evas_Object *_add_view_base(Evas_Object *ctxpopup) static void _cancel_btn_clicked_cb(void *priv, Evas_Object *obj, void *ev) { - struct _chnllock_data *data; + SNeedPasscodeView *data; if (!priv || !obj) return; - data = (struct _chnllock_data *) priv; + data = (SNeedPasscodeView *) priv; data->mgr->ViewPop(); } @@ -183,7 +182,7 @@ static void _cancel_btn_clicked_cb(void *priv, Evas_Object *obj, * * @return: the created cancel button or null if error occurred. */ -static Evas_Object *_add_view_cancel_btn(struct _chnllock_data *data) +static Evas_Object *_add_view_cancel_btn(SNeedPasscodeView *data) { Evas_Object *btn; @@ -211,7 +210,7 @@ static Evas_Object *_add_view_cancel_btn(struct _chnllock_data *data) * * @return: 0 - wrong passcode, 1 - right passcode. */ -static int _check_passcode(struct _chnllock_data *data) +static int _check_passcode(SNeedPasscodeView *data) { char *passcode; @@ -238,7 +237,7 @@ static int _check_passcode(struct _chnllock_data *data) * * @return: void. */ -static void _push_next_view(struct _chnllock_data *data) +static void _push_next_view(SNeedPasscodeView *data) { struct settingitem *item; Eina_List *list; @@ -272,27 +271,30 @@ static void _push_next_view(struct _chnllock_data *data) * * @return: void. */ -static void _key_down_cb(void *priv, Evas *e, Evas_Object *obj, - void *ei) +void CNeedPasscodeView::sm_CbKeyDown(void *priv, Evas *e, Evas_Object *obj, void *ei) +{ + CNeedPasscodeView *root = (CNeedPasscodeView*)priv; + if (root) + root->m_OnKeyDown(e, obj, (Evas_Event_Key_Down*)ei); +} + + +void CNeedPasscodeView::m_OnKeyDown(Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev) { - Evas_Event_Key_Down *event; Eina_Array *array; Evas_Object *entry, *next_entry; - struct _chnllock_data *data; const char *keyname; char *text; int btn_num, i; - if (!priv || !ei || !obj) + if (!obj) return; - data = (struct _chnllock_data *)priv; - array = data->array; + array = m->array; if (!array) return; - event = (Evas_Event_Key_Down *) ei; - keyname = event->keyname; + keyname = ev->keyname; if (!keyname) return; @@ -308,9 +310,9 @@ static void _key_down_cb(void *priv, Evas *e, Evas_Object *obj, return; if (!strncmp(keyname, KEY_BACK, strlen(keyname)) || !strncmp(keyname, KEY_BACK_REMOTE, strlen(keyname))) { - data->mgr->ViewPop(); + m->mgr->ViewPop(); } else if (!strncmp(keyname, KEY_DOWN, strlen(keyname))) { - elm_object_focus_set(data->cancel_btn, EINA_TRUE); + elm_object_focus_set(m->cancel_btn, EINA_TRUE); } else if (!strncmp(keyname, KEY_0, strlen(keyname)) || !strncmp(keyname, KEY_1, strlen(keyname)) || !strncmp(keyname, KEY_2, strlen(keyname)) || @@ -322,7 +324,7 @@ static void _key_down_cb(void *priv, Evas *e, Evas_Object *obj, !strncmp(keyname, KEY_8, strlen(keyname)) || !strncmp(keyname, KEY_9, strlen(keyname))) { elm_entry_entry_set(obj, PWD_SYMBOL); - data->passcode[btn_num] = keyname[0]; + m->passcode[btn_num] = keyname[0]; if (btn_num < PWD_ENTRY_3) { elm_object_focus_next(obj, ELM_FOCUS_NEXT); @@ -331,16 +333,16 @@ static void _key_down_cb(void *priv, Evas *e, Evas_Object *obj, if (!next_entry) return; - elm_object_focus_next_object_set(data->cancel_btn, + elm_object_focus_next_object_set(m->cancel_btn, next_entry, ELM_FOCUS_UP); } else { - if (_check_passcode(data)) { - _hide(data->base); - _push_next_view(data); + if (_check_passcode(m)) { + Hide(); + _push_next_view(m); } else { text = utils_get_translation_str( MSGID_WRONG_PWD); - elm_object_part_text_set(data->base, + elm_object_part_text_set(m->base, PART_UPTEXT, text); entry = (Evas_Object *) eina_array_data_get(array, PWD_ENTRY_0); @@ -442,19 +444,14 @@ static Evas_Object *_add_entry(Evas_Object *parent) * * @return: 0 - Success, -1 - Fail. */ -static int _add_view_entries(struct _chnllock_data *data) +int CNeedPasscodeView::m_AddViewEntries(void) { Eina_Array *array; Evas_Object *box; Evas_Object *entry, *base; int idx; - if (!data || !data->base) { - _ERR("invalid arguments."); - return -1; - } - - box = utils_add_box(data->base); + box = utils_add_box(m->base); if (!box) return -1; @@ -468,7 +465,7 @@ static int _add_view_entries(struct _chnllock_data *data) } for (idx = PWD_ENTRY_0; idx < PWD_ENTRY_MAX; idx++) { - base = utils_add_base(data->base); + base = utils_add_base(m->base); if (!base) { _ERR("utils add base failed."); evas_object_del(box); @@ -491,7 +488,7 @@ static int _add_view_entries(struct _chnllock_data *data) elm_box_pack_end(box, base); evas_object_event_callback_add(entry, EVAS_CALLBACK_KEY_DOWN, - _key_down_cb, data); + sm_CbKeyDown, this); } elm_object_focus_allow_set((Evas_Object*) eina_array_data_get(array, PWD_ENTRY_0), @@ -499,12 +496,12 @@ static int _add_view_entries(struct _chnllock_data *data) elm_object_focus_set((Evas_Object *)eina_array_data_get(array, PWD_ENTRY_0), EINA_TRUE); - elm_object_part_content_set(data->base, SWALLOW_CONTENT_AREA, box); + elm_object_part_content_set(m->base, SWALLOW_CONTENT_AREA, box); - _set_entry_directions(array, data->cancel_btn); + _set_entry_directions(array, m->cancel_btn); - data->array = array; - data->box = box; + m->array = array; + m->box = box; return 0; } @@ -518,23 +515,34 @@ static int _add_view_entries(struct _chnllock_data *data) * * @return: void. */ -static void _ctxpopup_dismissed(void *priv, Evas_Object *obj, - void *ev) +void CNeedPasscodeView::sm_CbCtxpopupDismissed(void *priv, Evas_Object *obj, void *ev) { - struct _chnllock_data *data; + CNeedPasscodeView *root = (CNeedPasscodeView*)priv; + if (root) + root->m_OnCtxpopupDismissed(obj, ev); +} - if (!priv || !obj) - return; - data = (struct _chnllock_data *) priv; - if (!data->base || !data->mgr) +void CNeedPasscodeView::m_OnCtxpopupDismissed(Evas_Object *obj, void *ev) +{ + if (!obj) return; - _hide(data->base); + Hide(); - data->mgr->ViewPop(); + m->mgr->ViewPop(); } + + +Evas_Object* CNeedPasscodeView::Base(void) +{ + ASSERT(m); + + return m->base; +} + + /** * Create all the UI components of channel lock view. * @@ -545,37 +553,33 @@ static void _ctxpopup_dismissed(void *priv, Evas_Object *obj, * @return: the base layout of channel lock view or null * if error occurred. */ -static Evas_Object *_create(CSettingMgr *mgr, - struct settingview_data *view, void *prev) +bool CNeedPasscodeView::Create(struct settingview_data *view, void *prev) { + ASSERT(!m); + ASSERT(view); + ASSERT(prev); + + CSettingMgr *mgr = CSettingMgr::GetInstance(); + Evas_Object *win, *base, *bg; Evas_Object *ctxpopup; Evas_Object *cancel_btn; - struct _chnllock_data *data; int ret, width, height, xpos, ypos; struct obj_geometry_data *tmp; - if (!mgr || !view || !prev) { - _ERR("invalid argument."); - return NULL; - } - win = mgr->Window(); - if (!win) { - _ERR("settings manager get window failed."); - return NULL; - } + ASSERT(win); - data = (struct _chnllock_data *) calloc(1, sizeof(*data)); - if (!data) { + m = new SNeedPasscodeView; + if (!m) { _ERR("calloc memory for _priv_data failed."); - return NULL; + return false; } tmp = (struct obj_geometry_data *) prev; - data->win = win; - data->gd = *tmp; + m->win = win; + m->gd = *tmp; bg = _add_view_bg(win); if (!bg) { @@ -583,7 +587,7 @@ static Evas_Object *_create(CSettingMgr *mgr, goto error; } - data->bg = bg; + m->bg = bg; ctxpopup = utils_add_ctxpopup(win, (char *)CHANGE_PWD_CTXPOPUP_STYLE); if (!ctxpopup) { @@ -591,15 +595,15 @@ static Evas_Object *_create(CSettingMgr *mgr, goto error; } - data->ctxpopup = ctxpopup; + m->ctxpopup = ctxpopup; - base = _add_view_base(data->ctxpopup); + base = _add_view_base(m->ctxpopup); if (!base) { _ERR("add view base failed."); goto error; } - data->base = base; + m->base = base; elm_object_content_set(ctxpopup, base); @@ -608,34 +612,36 @@ static Evas_Object *_create(CSettingMgr *mgr, xpos = (width - CTXPOPUP_WIDTH) / 2; ypos = (height - CTXPOPUP_HEIGHT) / 2; - evas_object_move(data->ctxpopup, xpos * ELM_SCALE, + evas_object_move(m->ctxpopup, xpos * ELM_SCALE, ypos * ELM_SCALE); - evas_object_smart_callback_add(data->ctxpopup, - SIG_DISMISSED, _ctxpopup_dismissed, data); + evas_object_smart_callback_add(m->ctxpopup, + SIG_DISMISSED, sm_CbCtxpopupDismissed, this); - cancel_btn = _add_view_cancel_btn(data); + cancel_btn = _add_view_cancel_btn(m); if (!cancel_btn) { _ERR("add cancel button faield."); goto error; } - data->cancel_btn = cancel_btn; + m->cancel_btn = cancel_btn; - ret = _add_view_entries(data); + ret = m_AddViewEntries(); if (ret != 0) goto error; - data->mgr = mgr; - data->view = view; + m->mgr = mgr; + m->view = view; - evas_object_data_set(base, CHNLLOCK_DATA_ID, data); + evas_object_data_set(base, CHNLLOCK_DATA_ID, m); - return base; + return true; error: - _free_priv_data(data); - return NULL; + _free_priv_data(m); + delete m; + m = NULL; + return false; } /** @@ -645,22 +651,13 @@ error: * * @return: void. */ -static void _show(Evas_Object *base) +void CNeedPasscodeView::Show(void) { - struct _chnllock_data *data; + ASSERT(m); - if (!base) - return; - - data = (struct _chnllock_data *) evas_object_data_get(base, CHNLLOCK_DATA_ID); - if (!data) { - _ERR("get data from base failed. ID: %s.", CHNLLOCK_DATA_ID); - return; - } - - evas_object_show(data->ctxpopup); - evas_object_show(data->bg); - evas_object_show(data->base); + evas_object_show(m->ctxpopup); + evas_object_show(m->bg); + evas_object_show(m->base); } /** @@ -670,20 +667,13 @@ static void _show(Evas_Object *base) * * @return: void. */ -static void _destroy(Evas_Object *base) +void CNeedPasscodeView::Destroy(void) { - struct _chnllock_data *data; - - if (!base) - return; - - data = (struct _chnllock_data *) evas_object_data_get(base, CHNLLOCK_DATA_ID); - if (!data) { - _ERR("get data from base failed. ID: %s.", CHNLLOCK_DATA_ID); - return; - } + ASSERT(m); - _free_priv_data(data); + _free_priv_data(m); + delete m; + m = NULL; } /** @@ -693,20 +683,13 @@ static void _destroy(Evas_Object *base) * * @return: void. */ -static void _hide(Evas_Object *base) +void CNeedPasscodeView::Hide(void) { - struct _chnllock_data *data; - - if (!base) - return; + ASSERT(m); - data = (struct _chnllock_data *) evas_object_data_get(base, CHNLLOCK_DATA_ID); - if (!data) - return; - - evas_object_hide(data->base); - evas_object_hide(data->ctxpopup); - evas_object_hide(data->bg); + evas_object_hide(m->base); + evas_object_hide(m->ctxpopup); + evas_object_hide(m->bg); } /** @@ -716,20 +699,15 @@ static void _hide(Evas_Object *base) * * @return: void. */ -static void _refresh(Evas_Object *base) +void CNeedPasscodeView::Refresh(void) { - struct _chnllock_data *data; + ASSERT(m); - if (!base) - return; - - data = (struct _chnllock_data *) evas_object_data_get(base, CHNLLOCK_DATA_ID); - if (!data) - return; - - data->mgr->ViewPop(); + m->mgr->ViewPop(); } + +#if 0 /** * view class of channel lock view. */ @@ -760,3 +738,4 @@ struct setting_class *view_need_passcode_get_vclass(void) { return &_vclass; } +#endif \ No newline at end of file diff --git a/src/view_pwd_popup.cpp b/src/view_pwd_popup.cpp index 592614b..20a6e74 100644 --- a/src/view_pwd_popup.cpp +++ b/src/view_pwd_popup.cpp @@ -19,7 +19,7 @@ #include "view_pwd_popup.h" #include "utils.h" #include "settings_provider.h" -#include "viewmgr.h" +#include "settingviewmgr.h" #define PWD_DATA_ID "change_passcode_data" #define CTXPOPUP_WIDTH 688 @@ -51,7 +51,7 @@ enum { ENTRY_MAX }; -struct _pwd_data { +struct SPasscodePopupView { Evas_Object *win; Evas_Object *bg; Evas_Object *base; @@ -73,7 +73,7 @@ struct _pwd_data { struct settingview_data *view; }; -static void _hide(Evas_Object *base); +//static void _hide(Evas_Object *base); /** * Free user data. @@ -82,7 +82,7 @@ static void _hide(Evas_Object *base); * * @return: void. */ -static void _free_pwd_data(struct _pwd_data *data) +static void _free_pwd_data(SPasscodePopupView *data) { if (!data) return; @@ -98,8 +98,6 @@ static void _free_pwd_data(struct _pwd_data *data) if (data->array) eina_array_free(data->array); - - free(data); } /** @@ -170,12 +168,12 @@ static Evas_Object *_add_pwd_base(Evas_Object *ctxpopup) */ static void _cancelbtn_clicked_cb(void *priv, Evas_Object *obj, void *ev) { - struct _pwd_data *data; + SPasscodePopupView *data; if (!priv || !obj) return; - data = (struct _pwd_data *) priv; + data = (SPasscodePopupView *) priv; data->mgr->ViewPop(); } @@ -187,7 +185,7 @@ static void _cancelbtn_clicked_cb(void *priv, Evas_Object *obj, void *ev) * * @return: the created cancel button or null if error occurred. */ -static Evas_Object *_add_pwd_cancel_btn(struct _pwd_data *data) +static Evas_Object *_add_pwd_cancel_btn(SPasscodePopupView *data) { Evas_Object *btn; @@ -289,7 +287,7 @@ static char *_get_pwd(struct settingview_data *vdata) * * @return: 0 - wrong passcode, 1 - right passcode. */ -static int _check_pwd(struct _pwd_data *data) +static int _check_pwd(SPasscodePopupView *data) { char *pwd; @@ -343,7 +341,7 @@ static void _clear_pwd(char *pwd) * * @return: void. */ -static void _reset_pwd(struct _pwd_data *data) +static void _reset_pwd(SPasscodePopupView *data) { Evas_Object *btn, *first; Eina_Array *array; @@ -377,7 +375,7 @@ static void _reset_pwd(struct _pwd_data *data) * * @return: 0 - Success, -1 - Fail. */ -static int _set_pwd(struct _pwd_data *data) +static int _set_pwd(SPasscodePopupView *data) { int ret; struct settingitem *item; @@ -407,7 +405,7 @@ static int _set_pwd(struct _pwd_data *data) * * @return: 0 - Success, -1 - Fail. */ -static int _check_reentered_pwd(struct _pwd_data *data) +static int _check_reentered_pwd(SPasscodePopupView *data) { if (!data) return 0; @@ -428,7 +426,7 @@ static int _check_reentered_pwd(struct _pwd_data *data) * * @return: void. */ -static void _update_pwd_ui(struct _pwd_data *data, +static void _update_pwd_ui(SPasscodePopupView *data, const char *part, const char *msgid) { char *text; @@ -458,14 +456,14 @@ static void _entry_keypress_cb(void *priv, Evas *e, Evas_Event_Key_Down *event; Eina_Array *array; Evas_Object *next_entry; - struct _pwd_data *data; + SPasscodePopupView *data; const char *keyname; int entry_idx, i; if (!priv || !ei || !obj) return; - data = (struct _pwd_data *) priv; + data = (SPasscodePopupView *) priv; array = data->array; if (!array) return; @@ -603,7 +601,7 @@ static Evas_Object *_add_entry(Evas_Object *parent) * * @return: 0 - Success, -1 - Fail. */ -static int _add_pwd_entry(struct _pwd_data *data) +static int _add_pwd_entry(SPasscodePopupView *data) { Eina_Array *array; Evas_Object *box; @@ -683,24 +681,37 @@ static int _add_pwd_entry(struct _pwd_data *data) * * @return: void. */ -static void _ctxpopup_dismissed(void *priv, Evas_Object *obj, - void *ev) +void CPasscodePopupView::sm_CbCtxpopupDismissed(void *priv, Evas_Object *obj, void *ev) { - struct _pwd_data *data; + CPasscodePopupView *root = (CPasscodePopupView*)priv; + if (root) + root->m_OnCtxpopupDismissed(obj, ev); +} - if (!priv || !obj) - return; - data = (struct _pwd_data *) priv; +void CPasscodePopupView::m_OnCtxpopupDismissed(Evas_Object *obj, void *ev) +{ + if (!obj) + return; - if (!data->base || !data->mgr) + if (!m->base || !m->mgr) return; - _hide(data->base); + Hide(); - data->mgr->ViewPop(); + m->mgr->ViewPop(); } + + +Evas_Object* CPasscodePopupView::Base(void) +{ + ASSERT(m); + + return m->base; +} + + /** * Create all the UI components of change passcode view. * @@ -711,40 +722,34 @@ static void _ctxpopup_dismissed(void *priv, Evas_Object *obj, * @return: the base layout of change passcode view or null * if error occurred. */ -static Evas_Object *_create(CSettingMgr *mgr, - struct settingview_data *view, void *prev) +bool CPasscodePopupView::Create(struct settingview_data *view, void *prev) { + ASSERT(!m); + ASSERT(view); + + CSettingMgr *mgr = CSettingMgr::GetInstance(); ASSERT(mgr); Evas_Object *base, *bg; Evas_Object *win; Evas_Object *cancel_btn; Evas_Object *ctxpopup; - struct _pwd_data *data; int ret; int width, height; int xpos, ypos; - if (!view) { - _ERR("invalid argument."); - return NULL; - } - win = mgr->Window(); - if (!win) { - _ERR("settingmgr get window failed."); - return NULL; - } + ASSERT(win); - data = (struct _pwd_data *)calloc(1, sizeof(*data)); - if (!data) { + m = new SPasscodePopupView; + if (!m) { _ERR("calloc _change_passcode_data failed."); - return NULL; + return false; } - data->win = win; + m->win = win; - _clear_pwd(data->pwd); + _clear_pwd(m->pwd); bg = _add_pwd_bg(win); if (!bg) { @@ -758,15 +763,15 @@ static Evas_Object *_create(CSettingMgr *mgr, goto error; } - data->ctxpopup = ctxpopup; + m->ctxpopup = ctxpopup; - base = _add_pwd_base(data->ctxpopup); + base = _add_pwd_base(m->ctxpopup); if (!base) { _ERR("add change passcode base layout failed."); goto error; } - data->base = base; + m->base = base; elm_object_content_set(ctxpopup, base); @@ -775,36 +780,38 @@ static Evas_Object *_create(CSettingMgr *mgr, xpos = (width - CTXPOPUP_WIDTH) / 2; ypos = (height - CTXPOPUP_HEIGHT) / 2; - evas_object_move(data->ctxpopup, xpos * ELM_SCALE, ypos * ELM_SCALE); + evas_object_move(m->ctxpopup, xpos * ELM_SCALE, ypos * ELM_SCALE); - cancel_btn = _add_pwd_cancel_btn(data); + cancel_btn = _add_pwd_cancel_btn(m); if (!cancel_btn) { _ERR("add change passcode cancel button failed."); goto error; } - data->cancel_btn = cancel_btn; + m->cancel_btn = cancel_btn; - ret = _add_pwd_entry(data); + ret = _add_pwd_entry(m); if (ret != 0) { _ERR("add change passcode input buttons failed."); goto error; } - data->mgr = mgr; - data->bg = bg; - data->view = view; + m->mgr = mgr; + m->bg = bg; + m->view = view; - evas_object_smart_callback_add(data->ctxpopup, - SIG_DISMISSED, _ctxpopup_dismissed, data); + evas_object_smart_callback_add(m->ctxpopup, + SIG_DISMISSED, sm_CbCtxpopupDismissed, this); - evas_object_data_set(base, PWD_DATA_ID, data); + evas_object_data_set(base, PWD_DATA_ID, m); - return base; + return true; error: - _free_pwd_data(data); - return NULL; + _free_pwd_data(m); + delete m; + m = NULL; + return false; } /** @@ -814,20 +821,11 @@ error: * * @return: void. */ -static void _show(Evas_Object *base) +void CPasscodePopupView::Show(void) { - struct _pwd_data *data; - - if (!base) - return; + ASSERT(m); - data = (struct _pwd_data *)evas_object_data_get(base, PWD_DATA_ID); - if (!data) { - _ERR("get data from base failed. ID: %s.", PWD_DATA_ID); - return; - } - - evas_object_show(data->ctxpopup); + evas_object_show(m->ctxpopup); } /** @@ -837,20 +835,13 @@ static void _show(Evas_Object *base) * * @return: void. */ -static void _destroy(Evas_Object *base) +void CPasscodePopupView::Destroy(void) { - struct _pwd_data *data; - - if (!base) - return; + ASSERT(m); - data = (struct _pwd_data *)evas_object_data_get(base, PWD_DATA_ID); - if (!data) { - _ERR("get data from base failed. ID: %s.", PWD_DATA_ID); - return; - } - - _free_pwd_data(data); + _free_pwd_data(m); + delete m; + m = NULL; } /** @@ -860,24 +851,16 @@ static void _destroy(Evas_Object *base) * * @return: void. */ -static void _hide(Evas_Object *base) +void CPasscodePopupView::Hide(void) { - struct _pwd_data *data; - - if (!base) - return; + ASSERT(m); - data = (struct _pwd_data *)evas_object_data_get(base, PWD_DATA_ID); - if (!data) { - _ERR("get data from base failed. ID: %s.", - PWD_DATA_ID); - return; - } - - evas_object_hide(data->bg); - evas_object_hide(data->ctxpopup); + evas_object_hide(m->bg); + evas_object_hide(m->ctxpopup); } + +#if 0 /** * view class of change passcode view. */ @@ -908,3 +891,4 @@ struct setting_class *view_passcode_popup_get_vclass(void) { return &_vclass; } +#endif \ No newline at end of file diff --git a/src/view_sublist.cpp b/src/view_sublist.cpp index 9f538ab..5c3c6be 100644 --- a/src/view_sublist.cpp +++ b/src/view_sublist.cpp @@ -17,12 +17,12 @@ #include "dbg.h" #include "def.h" #include "stdbool.h" -#include "viewmgr.h" +#include "settingviewmgr.h" #include "utils.h" #include "data_wrapper.h" #include "settings_provider.h" #include "view_sublist.h" -#include "viewmgr.h" +#include "settingviewmgr.h" #define DATA_ID "SUBLISTDATA" #define MAX_ITEMS 8 @@ -41,7 +41,7 @@ #define SIG_ITEM_CLICKED "clicked" #define SIG_CTXPOPUP_DISMISSED "dismissed" -struct _sublist_data { +struct SSublistView { Evas_Object *win; Evas_Object *base; Evas_Object *ctxpopup; @@ -56,8 +56,8 @@ struct _sublist_data { CSettingMgr *mgr; }; -static void _destroy(Evas_Object *base); -static void _hide(Evas_Object *base); +//static void _destroy(Evas_Object *base); +//static void _hide(Evas_Object *base); /** * This function is invoked to exit and pop current view. @@ -65,13 +65,11 @@ static void _hide(Evas_Object *base); * @param data [in] The _sublist_data data pointer. * @return void. */ -static void _exit_view(struct _sublist_data *data) +void CSublistView::m_ExitView(void) { - if (!data) - return; - - _hide(data->base); - data->mgr->ViewPop(); + Hide(); + + m->mgr->ViewPop(); } /** @@ -107,7 +105,7 @@ static Eina_List *_get_list_data(struct settingview_data *data, int *cnt) * @param data [in] The _sublist_data data pointer. * @return The selected string value, NULL on error. */ -static char *_get_selected_value(struct _sublist_data *data) +static char *_get_selected_value(SSublistView *data) { struct settingitem *item; @@ -132,19 +130,18 @@ static char *_get_selected_value(struct _sublist_data *data) * @param obj [in] The evas object user selected. * @return void. */ -static void _set_selected_value(struct _sublist_data *data, - Evas_Object *obj) +void CSublistView::m_SetSelectedValue(Evas_Object *obj) { struct settingitem *item; char *val; int r; - if (!data || !data->sublist_view || !obj) { + if (!m->sublist_view || !obj) { _ERR("Invalid argument"); return; } - item = viewdata_get_parentitem(data->sublist_view); + item = viewdata_get_parentitem(m->sublist_view); if (!item) { _ERR("Get item failed"); return; @@ -168,14 +165,14 @@ static void _set_selected_value(struct _sublist_data *data, */ static void _scroller_bottom_cb(void *data, Evas_Object *obj, void *event) { - struct _sublist_data *priv; + SSublistView *priv; if (!data) { _ERR("Invalid argument"); return; } - priv = (struct _sublist_data *) data; + priv = (SSublistView *) data; elm_object_signal_emit(priv->ctxpopup, SUBLIST_SHOW_UP_ARROW, ""); } @@ -190,14 +187,14 @@ static void _scroller_bottom_cb(void *data, Evas_Object *obj, void *event) */ static void _scroller_top_cb(void *data, Evas_Object *obj, void *event) { - struct _sublist_data *priv; + SSublistView *priv; if (!data) { _ERR("Invalid argument"); return; } - priv = (struct _sublist_data *) data; + priv = (SSublistView *) data; elm_object_signal_emit(priv->ctxpopup, SUBLIST_SHOW_DOWN_ARROW, ""); } @@ -212,14 +209,14 @@ static void _scroller_top_cb(void *data, Evas_Object *obj, void *event) */ static void _scroll_event_cb(void *data, Evas_Object *obj, void *event) { - struct _sublist_data *priv; + SSublistView *priv; if (!data) { _ERR("Invalid argument"); return; } - priv = (struct _sublist_data *) data; + priv = (SSublistView *) data; elm_object_signal_emit(priv->ctxpopup, SUBLIST_SHOW_BOTH_ARROW, ""); } @@ -232,25 +229,30 @@ static void _scroll_event_cb(void *data, Evas_Object *obj, void *event) * @param ev [in] The event infomation. * @return void. */ -static void _subitem_focus_in_cb(void *data, Evas_Object *obj, void *ev) +void CSublistView::sm_CbSubitemFocusIn(void *data, Evas_Object *obj, void *ev) +{ + CSublistView *root = (CSublistView*)data; + if (root) + root->m_OnSubitemFocusIn(obj, ev); +} + + +void CSublistView::m_OnSubitemFocusIn(Evas_Object *obj, void *ev) { - struct _sublist_data *priv; char *val, *sel; - if (!obj || !data) { + if (!obj) { _ERR("Invalid arguments\n"); return; } - priv = (struct _sublist_data *) data; - val = (char *) evas_object_data_get(obj, ITEMID); if (!val) { _ERR("Get value from btn failed\n"); return; } - sel = _get_selected_value(priv); + sel = _get_selected_value(m); if (!sel) { _ERR("_get_selected_value failed\n"); return; @@ -274,25 +276,30 @@ static void _subitem_focus_in_cb(void *data, Evas_Object *obj, void *ev) * @param ev [in] The event infomation. * @return void. */ -static void _subitem_focus_out_cb(void *data, Evas_Object *obj, void *ev) +void CSublistView::sm_CbSubitemFocusOut(void *data, Evas_Object *obj, void *ev) +{ + CSublistView *root = (CSublistView*)data; + if (root) + root->m_OnSubitemFocusOut(obj, ev); +} + + +void CSublistView::m_OnSubitemFocusOut(Evas_Object *obj, void *ev) { - struct _sublist_data *priv; char *val, *sel; - if (!obj || !data) { + if (!obj) { _ERR("Invalid arguments\n"); return; } - priv = (struct _sublist_data *)data; - val = (char *) evas_object_data_get(obj, ITEMID); if (!val) { _ERR("Get value from btn failed\n"); return; } - sel = _get_selected_value(priv); + sel = _get_selected_value(m); if (!sel) { _ERR("_get_selected_value failed\n"); return; @@ -316,18 +323,22 @@ static void _subitem_focus_out_cb(void *data, Evas_Object *obj, void *ev) * @param ev [in] The event infomation. * @return void. */ -static void _subitem_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) +void CSublistView::sm_CbSubitemBtnClicked(void *data, Evas_Object *obj, void *ev) { - struct _sublist_data *priv; + CSublistView *root = (CSublistView*)data; + if (root) + root->m_OnSubitemBtnClicked(obj, ev); +} - if (!data || !obj) - return; - priv = (struct _sublist_data *)data; +void CSublistView::m_OnSubitemBtnClicked(Evas_Object *obj, void *ev) +{ + if (!obj) + return; - _set_selected_value(priv, obj); + m_SetSelectedValue(obj); - _exit_view(priv); + m_ExitView(); } /** @@ -339,16 +350,17 @@ static void _subitem_btn_clicked_cb(void *data, Evas_Object *obj, void *ev) * @param ev [in] The event infomation. * @return void. */ -static void _ctxpopup_dismissed_cb(void *data, Evas_Object *obj, void *ev) +void CSublistView::sm_CbCtxpopupDismissed(void *data, Evas_Object *obj, void *ev) { - struct _sublist_data *priv; - - if (!data) - return; + CSublistView *root = (CSublistView*)data; + if (root) + root->m_OnCtxpopupDismissed(obj, ev); +} - priv = (struct _sublist_data *)data; - _exit_view(priv); +void CSublistView::m_OnCtxpopupDismissed(Evas_Object *obj, void *ev) +{ + m_ExitView(); } /** @@ -361,20 +373,18 @@ static void _ctxpopup_dismissed_cb(void *data, Evas_Object *obj, void *ev) * @param ei [in] The event infomation. * @return void. */ -static void _subitem_key_pressed_cb(void *data, Evas *e, - Evas_Object *obj, void *ei) +void CSublistView::sm_CbSubitemKeyPressed(void *data, Evas *e, Evas_Object *obj, void *ei) { - Evas_Event_Key_Down *ev; - struct _sublist_data *priv; - - if (!data || !ei) - return; + CSublistView *root = (CSublistView*)data; + if (root) + root->m_OnSubitemKeyPressed(e, obj, (Evas_Event_Key_Down*)ei); +} - ev = (Evas_Event_Key_Down *) ei; - priv = (struct _sublist_data *)data; +void CSublistView::m_OnSubitemKeyPressed(Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev) +{ if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) - _exit_view(priv); + m_ExitView(); } /** @@ -383,7 +393,7 @@ static void _subitem_key_pressed_cb(void *data, Evas *e, * @param data [in] The _sublist_data data pointer. * @return 0 if success, -1 if fail. */ -static int _draw_ctxpopup_layout(struct _sublist_data *data) +static int _draw_ctxpopup_layout(SSublistView *data) { Evas_Object *box, *ctxpopup, *scroller; @@ -447,7 +457,7 @@ static int _draw_ctxpopup_layout(struct _sublist_data *data) * @param list [in] The eina list data pointer. * @return 0 if success, -1 if fail. */ -static int _draw_list_items(struct _sublist_data *data, Eina_List *list) +int CSublistView::m_DrawListItems(Eina_List *list) { struct listitem *ldata; void* obj; @@ -459,12 +469,12 @@ static int _draw_list_items(struct _sublist_data *data, Eina_List *list) const char *name, *val; int check, i, j; - if (!data || !list || !data->popup_box) { + if (!list || !m->popup_box) { _ERR("Invalid argument"); return -1; } - sel = _get_selected_value(data); + sel = _get_selected_value(m); if (!sel) { _ERR("Get selected value failed"); return -1; @@ -485,7 +495,7 @@ static int _draw_list_items(struct _sublist_data *data, Eina_List *list) ldata = (struct listitem *) obj; name = listitem_get_display_name(ldata); - btn = utils_add_btn(data->popup_box, (char *) CTXPOPUPBTN_STYLE, + btn = utils_add_btn(m->popup_box, (char *) CTXPOPUPBTN_STYLE, name, EINA_TRUE); if (!btn) { _ERR("Add button failed\n"); @@ -510,15 +520,15 @@ static int _draw_list_items(struct _sublist_data *data, Eina_List *list) evas_object_data_set(btn, ITEMID, val); evas_object_smart_callback_add(btn, SIG_ITEM_FOCUSED, - _subitem_focus_in_cb, data); + sm_CbSubitemFocusIn, this); evas_object_smart_callback_add(btn, SIG_ITEM_UNFOCUSED, - _subitem_focus_out_cb, data); + sm_CbSubitemFocusOut, this); evas_object_smart_callback_add(btn, SIG_ITEM_CLICKED, - _subitem_btn_clicked_cb, data); + sm_CbSubitemBtnClicked, this); evas_object_event_callback_add(btn, EVAS_CALLBACK_KEY_DOWN, - _subitem_key_pressed_cb, data); + sm_CbSubitemKeyPressed, this); - elm_box_pack_end(data->popup_box, btn); + elm_box_pack_end(m->popup_box, btn); eina_array_push(btns, btn); if (i == 0) @@ -527,8 +537,8 @@ static int _draw_list_items(struct _sublist_data *data, Eina_List *list) i++; } - data->sub_btn_array = btns; - data->selected_index = check; + m->sub_btn_array = btns; + m->selected_index = check; provider_release_list_value(sel); @@ -541,7 +551,7 @@ static int _draw_list_items(struct _sublist_data *data, Eina_List *list) * @param data [in] The _sublist_data data pointer. * @return 0 if success, -1 if fail. */ -static int _draw_sublist(struct _sublist_data *data) +int CSublistView::m_DrawSublist(void) { struct settingview_data *view; Eina_List *list; @@ -549,12 +559,12 @@ static int _draw_sublist(struct _sublist_data *data) int cnt, x, y, height, screen_h; struct obj_geometry_data *param; - if (!data || !data->sublist_view || !data->geometry_data) { + if (!m->sublist_view || !m->geometry_data) { _ERR("Invalid argument\n"); return -1; } - view = data->sublist_view; + view = m->sublist_view; cnt = 0; list = _get_list_data(view, &cnt); @@ -563,21 +573,21 @@ static int _draw_sublist(struct _sublist_data *data) return -1; } - data->sub_items_count = cnt; + m->sub_items_count = cnt; - if (_draw_ctxpopup_layout(data) == -1) { + if (_draw_ctxpopup_layout(m) == -1) { _ERR("Fail to draw ctxpopup layout"); return -1; } - if (_draw_list_items(data, list) == -1) { + if (m_DrawListItems(list) == -1) { _ERR("Fail to draw list items"); return -1; } screen_h = WIN_HEIGHT; - param = data->geometry_data; + param = m->geometry_data; w = param->width; if (w <= 0) { @@ -590,8 +600,8 @@ static int _draw_sublist(struct _sublist_data *data) x = param->x + param->width * ratio; y = param->y; - if (data->sub_items_count < MAX_ITEMS) - height = data->sub_items_count * ITEM_HEIGHT; + if (m->sub_items_count < MAX_ITEMS) + height = m->sub_items_count * ITEM_HEIGHT; else height = MAX_ITEMS * ITEM_HEIGHT + ITEM_OFFSET; @@ -602,13 +612,23 @@ static int _draw_sublist(struct _sublist_data *data) } _DBG("x : %d , y : %d, ELM_SCALE = %f, height = %d", x , y , ELM_SCALE, height); - evas_object_move(data->ctxpopup, x * ELM_SCALE, (y * ELM_SCALE) + height); + evas_object_move(m->ctxpopup, x * ELM_SCALE, (y * ELM_SCALE) + height); - utils_set_focus_directions(data->sub_btn_array, data->sub_items_count); + utils_set_focus_directions(m->sub_btn_array, m->sub_items_count); return 0; } + + +Evas_Object* CSublistView::Base(void) +{ + ASSERT(m); + + return m->base; +} + + /** * This function is invoked to create view layout. * @@ -617,33 +637,29 @@ static int _draw_sublist(struct _sublist_data *data) * @param prev [in] The parameter data which passed by prev view or NULL. * @return View layout evas object, NULL on error. */ -static Evas_Object *_create(CSettingMgr *mgr, - struct settingview_data *view, void *prev) +bool CSublistView::Create(struct settingview_data *view, void *prev) { - Evas_Object *base, *ctxpopup, *win; - struct _sublist_data *data; + ASSERT(!m); + ASSERT(view); + ASSERT(prev); - if (!mgr || !view || !prev) { - _ERR("Invalid argument!\n"); - return NULL; - } + Evas_Object *base, *ctxpopup, *win; + CSettingMgr *mgr = CSettingMgr::GetInstance(); win = mgr->Window(); - if (!win) { - _ERR("Fail to get win"); - return NULL; - } + ASSERT(win); - data = (struct _sublist_data *) calloc(1, sizeof(*data)); - if (!data) { + m = new SSublistView; + if (!m) { _ERR("Unable to allocate memory\n"); - return NULL; + return false; } base = elm_layout_add(win); if (!base) { - free(data); - return NULL; + delete m; + m = NULL; + return false; } elm_layout_file_set(base, EDJ_FILE, SUBLIST_VIEW_PAGE); @@ -652,36 +668,37 @@ static Evas_Object *_create(CSettingMgr *mgr, if (!ctxpopup) { _ERR("Fail to add ctxpopup"); evas_object_del(base); - free(data); - return NULL; + delete m; + m = NULL; + return false; } evas_object_smart_callback_add(ctxpopup, SIG_CTXPOPUP_DISMISSED, - _ctxpopup_dismissed_cb, data); + sm_CbCtxpopupDismissed, m); - data->geometry_data = (struct obj_geometry_data *) prev; + m->geometry_data = (struct obj_geometry_data *) prev; - data->mgr = mgr; - data->win = win; - data->base = base; - data->ctxpopup = ctxpopup; - data->sublist_view = view; + m->mgr = mgr; + m->win = win; + m->base = base; + m->ctxpopup = ctxpopup; + m->sublist_view = view; - evas_object_data_set(base, DATA_ID, data); + evas_object_data_set(base, DATA_ID, m); - if (_draw_sublist(data) == -1) { + if (m_DrawSublist() == -1) { _ERR("Error in drawing items function\n"); evas_object_del(base); evas_object_del(ctxpopup); - if (data->sub_btn_array) - eina_array_free(data->sub_btn_array); + if (m->sub_btn_array) + eina_array_free(m->sub_btn_array); - free(data); - return NULL; + delete m; + m = NULL; + return false; } - return base; - + return true; } /** @@ -690,23 +707,12 @@ static Evas_Object *_create(CSettingMgr *mgr, * @param base [in] The view layout evas object. * @return void. */ -static void _show(Evas_Object *base) +void CSublistView::Show(void) { - struct _sublist_data *data; - - if (!base) { - _ERR("Invalid argument\n"); - return; - } - - data = (struct _sublist_data *) evas_object_data_get(base, DATA_ID); - if (!data) { - _ERR("Get sublist data failed\n"); - return; - } + ASSERT(m); - evas_object_show(data->ctxpopup); - evas_object_show(base); + evas_object_show(m->ctxpopup); + evas_object_show(m->base); } /** @@ -715,31 +721,21 @@ static void _show(Evas_Object *base) * @param base [in] The view layout evas object. * @return void. */ -static void _destroy(Evas_Object *base) +void CSublistView::Destroy(void) { - struct _sublist_data *data; - - if (!base) - return; - - data = (struct _sublist_data *) evas_object_data_get(base, DATA_ID); - if (!data) { - _ERR("Invalid arguments"); - evas_object_del(data->ctxpopup); - evas_object_del(base); - return; - } + ASSERT(m); - if (data->sub_btn_array) - eina_array_free(data->sub_btn_array); + if (m->sub_btn_array) + eina_array_free(m->sub_btn_array); - evas_object_del(data->ctxpopup); - evas_object_del(base); + evas_object_del(m->ctxpopup); + evas_object_del(m->base); - if (data->sublist_view) - viewdata_release(data->sublist_view); + if (m->sublist_view) + viewdata_release(m->sublist_view); - free(data); + delete m; + m = NULL; } /** @@ -748,23 +744,16 @@ static void _destroy(Evas_Object *base) * @param base [in] The view layout evas object. * @return void. */ -static void _hide(Evas_Object *base) +void CSublistView::Hide(void) { - struct _sublist_data *data; + ASSERT(m); - if (!base) - return; - - data = (struct _sublist_data *) evas_object_data_get(base, DATA_ID); - if (!data) { - _ERR("Invalid arguments"); - return; - } - - evas_object_hide(base); - evas_object_hide(data->ctxpopup); + evas_object_hide(m->base); + evas_object_hide(m->ctxpopup); } +#if 0 + static struct setting_class _vclass = { VCLASS_TITLE_SUBLIST, _create, @@ -790,3 +779,4 @@ struct setting_class *view_sublist_get_vclass(void) { return &_vclass; } +#endif \ No newline at end of file diff --git a/src/view_system_clock.cpp b/src/view_system_clock.cpp index e396d26..cf57833 100644 --- a/src/view_system_clock.cpp +++ b/src/view_system_clock.cpp @@ -17,7 +17,7 @@ #include "dbg.h" #include "def.h" #include "stdbool.h" -#include "viewmgr.h" +#include "settingviewmgr.h" #include "utils.h" #include "data_wrapper.h" #include "settings_provider.h" @@ -40,7 +40,7 @@ #define SIG_UNFOCUSED "unfocused" #define SIG_CLICKED "clicked" -struct _sysclk_data { +struct SSystemClockView { Evas_Object *win; Evas_Object *base; Evas_Object *ctxpopup; @@ -56,8 +56,6 @@ struct _sysclk_data { struct obj_geometry_data *ogd; }; -static void _destroy(Evas_Object *base); -static void _hide(Evas_Object *base); /** * Exit system clock sublist view. @@ -66,14 +64,13 @@ static void _hide(Evas_Object *base); * * @return: void. */ -static void _exit_view(struct _sysclk_data *data) +void CSystemClockView::m_ExitView(void) { - if (!data || !data->base) - return; + ASSERT(m); - _hide(data->base); + Hide(); - data->mgr->ViewPop(); + m->mgr->ViewPop(); } /** @@ -111,7 +108,7 @@ static Eina_List *_get_item_list(struct settingview_data *vdata, int *count) * * @return: the selected value or null if error occurred. */ -static char *_get_selected_value(struct _sysclk_data *data) +static char *_get_selected_value(SSystemClockView *data) { struct settingitem *item; @@ -137,7 +134,7 @@ static char *_get_selected_value(struct _sysclk_data *data) * * @return: void. */ -static void _set_selected_value(struct _sysclk_data *data, Evas_Object *obj) +static void _set_selected_value(SSystemClockView *data, Evas_Object *obj) { struct settingitem *item; char *selval; @@ -173,7 +170,7 @@ static void _set_selected_value(struct _sysclk_data *data, Evas_Object *obj) */ static void _subitem_focusin_cb(void *priv, Evas_Object *obj, void *ev) { - struct _sysclk_data *data; + SSystemClockView *data; char *value; char *selval; @@ -182,7 +179,7 @@ static void _subitem_focusin_cb(void *priv, Evas_Object *obj, void *ev) return; } - data = (struct _sysclk_data *) priv; + data = (SSystemClockView *) priv; value = (char *) evas_object_data_get(obj, ITEMID); if (!value) { @@ -218,7 +215,7 @@ static void _subitem_focusin_cb(void *priv, Evas_Object *obj, void *ev) */ static void _subitem_focusout_cb(void *priv, Evas_Object *obj, void *ev) { - struct _sysclk_data *data; + SSystemClockView *data; char *value; char *selval; @@ -227,7 +224,7 @@ static void _subitem_focusout_cb(void *priv, Evas_Object *obj, void *ev) return; } - data = (struct _sysclk_data *) priv; + data = (SSystemClockView *) priv; value = (char *) evas_object_data_get(obj, ITEMID); if (!value) { @@ -260,21 +257,26 @@ static void _subitem_focusout_cb(void *priv, Evas_Object *obj, void *ev) * * @return: void. */ -static void _subitem_clicked_cb(void *priv, Evas_Object *obj, void *ev) +void CSystemClockView::sm_CbSubitemClicked(void *priv, Evas_Object *obj, void *ev) +{ + CSystemClockView *root = (CSystemClockView*)priv; + if (root) + root->m_OnSubitemClicked(obj, ev); +} + + +void CSystemClockView::m_OnSubitemClicked(Evas_Object *obj, void *ev) { - struct _sysclk_data *data; struct settingitem *item; Eina_List *list; char *value; const char *id; const char *name; - if (!priv || !obj) + if (!obj) return; - data = (struct _sysclk_data *) priv; - - _set_selected_value(data, obj); + _set_selected_value(m, obj); value = (char *) evas_object_data_get(obj, ITEMID); if (!value) { @@ -283,9 +285,9 @@ static void _subitem_clicked_cb(void *priv, Evas_Object *obj, void *ev) } if (!strncmp(value, MANUAL, BUF_SIZE)) { - _hide(data->base); + Hide(); - list = viewdata_get_childitems_list(data->vdata); + list = viewdata_get_childitems_list(m->vdata); if (!list) { _ERR("list of clock is null."); return; @@ -309,11 +311,11 @@ static void _subitem_clicked_cb(void *priv, Evas_Object *obj, void *ev) return; } - data->ugd.display_name = name; + m->ugd.display_name = name; - data->mgr->ViewPush(id, (void *)&data->ugd); + m->mgr->ViewPush(id, (void *)&m->ugd); } else { - _exit_view(data); + m_ExitView(); } } @@ -327,23 +329,24 @@ static void _subitem_clicked_cb(void *priv, Evas_Object *obj, void *ev) * * @return: void. */ -static void _subitem_keypress_cb(void *priv, Evas *e, - Evas_Object *obj, void *ei) +void CSystemClockView::sm_CbSubitemKeypress(void *priv, Evas *e, Evas_Object *obj, void *ei) { - Evas_Event_Key_Down *ev; - struct _sysclk_data *data; + CSystemClockView *root = (CSystemClockView*)priv; + if (root) + root->m_OnSubitemKeypress(e, obj, (Evas_Event_Key_Down*)ei); +} - if (!priv || !ei) - return; - data = (struct _sysclk_data *) priv; - ev = (Evas_Event_Key_Down *) ei; +void CSystemClockView::m_OnSubitemKeypress(Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev) +{ + if (!ev) + return; if (!ev->keyname) return; if (!strncmp(ev->keyname, KEY_BACK, BUF_SIZE) || !strncmp(ev->keyname, KEY_BACK_REMOTE, BUF_SIZE)) - _exit_view(data); + m_ExitView(); } /** @@ -355,8 +358,7 @@ static void _subitem_keypress_cb(void *priv, Evas *e, * * @return: 0 - Success, -1 - Fail. */ -static int _add_sysclk_sublist_item(struct _sysclk_data *data, - Eina_List *list, const char *selval) +int CSystemClockView::m_AddSysclkSublistItem(Eina_List *list, const char *selval) { Evas_Object *box, *cp, *btn, *del_btn; Eina_Array *array; @@ -367,12 +369,12 @@ static int _add_sysclk_sublist_item(struct _sysclk_data *data, const char *disp, *value; int idx, i, j; - if (!data || !list || !data->ctxpopup || !selval) { + if (!list || !m->ctxpopup || !selval) { _ERR("invalid arguments."); return -1; } - cp = data->ctxpopup; + cp = m->ctxpopup; box = utils_add_box(cp); if (!box) { @@ -420,13 +422,13 @@ static int _add_sysclk_sublist_item(struct _sysclk_data *data, evas_object_data_set(btn, ITEMID, value); evas_object_smart_callback_add(btn, SIG_FOCUSED, - _subitem_focusin_cb, data); + _subitem_focusin_cb, m); evas_object_smart_callback_add(btn, SIG_UNFOCUSED, - _subitem_focusout_cb, data); + _subitem_focusout_cb, m); evas_object_smart_callback_add(btn, SIG_CLICKED, - _subitem_clicked_cb, data); + sm_CbSubitemClicked, this); evas_object_event_callback_add(btn, EVAS_CALLBACK_KEY_DOWN, - _subitem_keypress_cb, data); + sm_CbSubitemKeypress, this); elm_box_pack_end(box, btn); eina_array_push(array, btn); @@ -437,9 +439,9 @@ static int _add_sysclk_sublist_item(struct _sysclk_data *data, i++; } - data->box = box; - data->array = array; - data->sel_idx = idx; + m->box = box; + m->array = array; + m->sel_idx = idx; return 0; @@ -463,7 +465,7 @@ error: * * @return: 0 - Success, -1 - Fail. */ -static int _draw_sysclk_sublist(struct _sysclk_data *data) +int CSystemClockView::m_DrawSysclkSublist(void) { Evas_Object *ctxpopup; char *selval; @@ -473,14 +475,14 @@ static int _draw_sysclk_sublist(struct _sysclk_data *data) int xpos, ypos, height, count, r; double ratio; - if (!data || !data->ctxpopup || !data->ogd || !data->vdata) { + if (!m->ctxpopup || !m->ogd || !m->vdata) { _ERR("Invalid argument\n"); return -1; } - ctxpopup = data->ctxpopup; - vdata = data->vdata; - ogd = data->ogd; + ctxpopup = m->ctxpopup; + vdata = m->vdata; + ogd = m->ogd; count = 0; itlist = _get_item_list(vdata, &count); @@ -489,9 +491,9 @@ static int _draw_sysclk_sublist(struct _sysclk_data *data) return -1; } - data->count = count; + m->count = count; - selval = _get_selected_value(data); + selval = _get_selected_value(m); if (!selval) { _ERR("Get selected value failed"); return -1; @@ -502,7 +504,7 @@ static int _draw_sysclk_sublist(struct _sysclk_data *data) goto error; } - r = _add_sysclk_sublist_item(data, itlist, selval); + r = m_AddSysclkSublistItem(itlist, selval); if (r != 0) { _ERR("add system clock sublist items failed."); goto error; @@ -517,14 +519,14 @@ static int _draw_sysclk_sublist(struct _sysclk_data *data) xpos = ogd->x + ogd->width * ratio; ypos = ogd->y; - height = data->count * ITEM_HEIGHT; + height = m->count * ITEM_HEIGHT; if (ypos > WIN_HEIGHT) ypos = ypos - height; evas_object_move(ctxpopup, xpos * ELM_SCALE, ypos * ELM_SCALE); - utils_set_focus_directions(data->array, data->count); + utils_set_focus_directions(m->array, m->count); provider_release_list_value(selval); @@ -544,21 +546,36 @@ error: * * @return: void. */ -static void _ctxpopup_dismissed(void *priv, Evas_Object *obj, - void *ev) +void CSystemClockView::sm_CbCtxpopupDismissed(void *priv, Evas_Object *obj, void *ev) { - struct _sysclk_data *data; + CSystemClockView *root = (CSystemClockView*)priv; + + if (root) + root->m_OnCtxpopupDismissed(obj, ev); +} + - if (!priv || !obj) +void CSystemClockView::m_OnCtxpopupDismissed(Evas_Object *obj, void *ev) +{ + if (!obj) return; - data = (struct _sysclk_data *) priv; + Hide(); - _hide(data->base); + m->mgr->ViewPop(); +} - data->mgr->ViewPop(); + + +Evas_Object* CSystemClockView::Base(void) +{ + ASSERT(m); + + return m->base; } + + /** * Create all the UI components of system clock sublist view. * @@ -569,43 +586,38 @@ static void _ctxpopup_dismissed(void *priv, Evas_Object *obj, * @return: the base layout of system clock view or null * if error occurred. */ -static Evas_Object *_create(CSettingMgr *mgr, - struct settingview_data *view, void *prev) +bool CSystemClockView::Create(struct settingview_data *view, void *prev) { + ASSERT(!m); + ASSERT(view); + ASSERT(prev); + Evas_Object *base; Evas_Object *ctxpopup; Evas_Object *win; - struct _sysclk_data *data; struct evas_obj_data *ugd; struct obj_geometry_data *ogd; - - if (!mgr || !view || !prev) { - _ERR("Invalid argument!\n"); - return NULL; - } + CSettingMgr *mgr = CSettingMgr::GetInstance(); ugd = (struct evas_obj_data *) prev; ogd = (struct obj_geometry_data *) evas_object_data_get(ugd->cur_btn, DATA_ID); win = mgr->Window(); + ASSERT(win); - if (!win) { - _ERR("settingmgr get window failed."); - return NULL; - } - - data = (struct _sysclk_data *) calloc(1, sizeof(*data)); - if (!data) { + m = new SSystemClockView; + if (!m) { _ERR("Unable to allocate memory."); - return NULL; + return false; } - data->ugd = *ugd; + m->ugd = *ugd; base = elm_layout_add(win); if (!base) { - free(data); - return NULL; + delete m; + m = NULL; + return false; } elm_layout_file_set(base, EDJ_FILE, SUBLIST_VIEW_PAGE); @@ -614,31 +626,33 @@ static Evas_Object *_create(CSettingMgr *mgr, if (!ctxpopup) { _ERR("Fail to add ctxpopup"); evas_object_del(base); - free(data); - return NULL; + delete m; + m = NULL; + return false; } evas_object_smart_callback_add(ctxpopup, SIG_DISMISSED, - _ctxpopup_dismissed, data); + sm_CbCtxpopupDismissed, this); - data->mgr = mgr; - data->win = win; - data->base = base; - data->ctxpopup = ctxpopup; - data->vdata = view; - data->ogd = ogd; + m->mgr = mgr; + m->win = win; + m->base = base; + m->ctxpopup = ctxpopup; + m->vdata = view; + m->ogd = ogd; - evas_object_data_set(base, DATA_ID, data); + evas_object_data_set(base, DATA_ID, m); - if (_draw_sysclk_sublist(data) == -1) { + if (m_DrawSysclkSublist() == -1) { _ERR("Error in drawing items function\n"); evas_object_del(base); evas_object_del(ctxpopup); - free(data); - return NULL; + delete m; + m = NULL; + return false; } - return base; + return true; } /** @@ -648,23 +662,12 @@ static Evas_Object *_create(CSettingMgr *mgr, * * @return: void. */ -static void _show(Evas_Object *base) +void CSystemClockView::Show(void) { - struct _sysclk_data *data; - - if (!base) { - _ERR("Invalid argument\n"); - return; - } + ASSERT(m); - data = (struct _sysclk_data *) evas_object_data_get(base, DATA_ID); - if (!data) { - _ERR("Get sublist data failed\n"); - return; - } - - evas_object_show(data->ctxpopup); - evas_object_show(base); + evas_object_show(m->ctxpopup); + evas_object_show(m->base); } /** @@ -674,33 +677,23 @@ static void _show(Evas_Object *base) * * @return: void. */ -static void _destroy(Evas_Object *base) +void CSystemClockView::Destroy(void) { - struct _sysclk_data *data; - - if (!base) - return; - - data = (struct _sysclk_data *)evas_object_data_get(base, DATA_ID); - if (!data) { - _ERR("Invalid arguments"); - evas_object_del(data->ctxpopup); - evas_object_del(base); - return; - } + ASSERT(m); - if (data->array) { - eina_array_free(data->array); - data->array = NULL; + if (m->array) { + eina_array_free(m->array); + m->array = NULL; } - evas_object_del(data->ctxpopup); - evas_object_del(base); + evas_object_del(m->ctxpopup); + evas_object_del(m->base); - if (data->vdata) - viewdata_release(data->vdata); + if (m->vdata) + viewdata_release(m->vdata); - free(data); + delete m; + m = NULL; } /** @@ -710,21 +703,12 @@ static void _destroy(Evas_Object *base) * * @return: void. */ -static void _hide(Evas_Object *base) +void CSystemClockView::Hide(void) { - struct _sysclk_data *data; - - if (!base) - return; - - data = (struct _sysclk_data *)evas_object_data_get(base, DATA_ID); - if (!data) { - _ERR("Invalid arguments"); - return; - } + ASSERT(m); - evas_object_hide(base); - evas_object_hide(data->ctxpopup); + evas_object_hide(m->base); + evas_object_hide(m->ctxpopup); } /** @@ -734,23 +718,15 @@ static void _hide(Evas_Object *base) * * @return: void. */ -static void _refresh(Evas_Object *base) +void CSystemClockView::Refresh(void) { - struct _sysclk_data *data; + ASSERT(m); - if (!base) { - _ERR("the base of system clock is null."); - return; - } + m_ExitView(); +} - data = (struct _sysclk_data *)evas_object_data_get(base, DATA_ID); - if (!data) { - _ERR("data get failed. DATA_ID: %s", DATA_ID); - return; - } - _exit_view(data); -} +#if 0 /** * view class of system clock view. @@ -783,3 +759,4 @@ struct setting_class *view_system_clock_get_vclass(void) return &_vclass; } +#endif \ No newline at end of file diff --git a/src/view_uigadget.cpp b/src/view_uigadget.cpp index 715d7f0..0eb479e 100644 --- a/src/view_uigadget.cpp +++ b/src/view_uigadget.cpp @@ -18,11 +18,11 @@ #include "view_uigadget.h" #include "dbg.h" #include "def.h" -#include "viewmgr.h" +#include "settingviewmgr.h" #define DATA_ID "ugdata" -struct _data { +struct SUiGadgetView { Evas_Object *win; Evas_Object *base; Evas_Object *subbtn; @@ -42,12 +42,11 @@ struct _data { * @param base [in] The view layout evas object. * @return void. */ -static void _hide(Evas_Object *base) +void CUiGadgetView::Hide(void) { - if (!base) - return; + ASSERT(m); - evas_object_hide(base); + evas_object_hide(m->base); } /** @@ -56,13 +55,11 @@ static void _hide(Evas_Object *base) * @param data [in] The function specific data which hold _data pointer. * @return void. */ -static void _back_to_mainview(struct _data *data) +void CUiGadgetView::m_BackToMainview(void) { - if (!data) - return; + Hide(); - _hide(data->base); - data->mgr->ViewPop(); + m->mgr->ViewPop(); } /** @@ -74,7 +71,7 @@ static void _back_to_mainview(struct _data *data) * @param priv [in] The function specific data passed by UG caller. * @return void. */ -static void _ug_layout_cb(ui_gadget_h ug, enum ug_mode mode, void *priv) +void CUiGadgetView::sm_CbUgLayout(ui_gadget_h ug, enum ug_mode mode, void *priv) { } @@ -87,7 +84,7 @@ static void _ug_layout_cb(ui_gadget_h ug, enum ug_mode mode, void *priv) * @param priv [in] The function specific data passed by UG caller. * @return void. */ -static void _ug_result_cb(ui_gadget_h ug, service_h result, void *priv) +void CUiGadgetView::sm_CbUgResult(ui_gadget_h ug, service_h result, void *priv) { } @@ -129,25 +126,29 @@ static void _show_item_btns(Evas_Object *box) * @param priv [in] The function specific data passed by UG caller. * @return void. */ -static void _ug_destroy_cb(ui_gadget_h ug, void *priv) +void CUiGadgetView::sm_CbUgDestroy(ui_gadget_h ug, void *priv) { - struct _data *data; + CUiGadgetView *root = (CUiGadgetView*)priv; + if (root) + root->m_OnUgDestroy(ug); +} - if (!ug || !priv) { + +void CUiGadgetView::m_OnUgDestroy(ui_gadget_h ug) +{ + if (!ug) { _ERR("Invalid parameters in ug destroy callback."); return; } - data = (struct _data *) priv; - - _show_item_btns(data->subitem_box); + _show_item_btns(m->subitem_box); - elm_object_focus_set(data->subbtn, EINA_TRUE); - elm_object_part_text_set(data->base, UG_TITLE_TEXT, ""); + elm_object_focus_set(m->subbtn, EINA_TRUE); + elm_object_part_text_set(m->base, UG_TITLE_TEXT, ""); ug_destroy(ug); - data->ug_is_existed = EINA_FALSE; - _back_to_mainview(data); + m->ug_is_existed = EINA_FALSE; + m_BackToMainview(); } /** @@ -156,42 +157,37 @@ static void _ug_destroy_cb(ui_gadget_h ug, void *priv) * @param data [in] The function specific data which hold _data pointer. * @return 0 if success, -1 if fail. */ -static int _load_uigadget(struct _data *data) +bool CUiGadgetView::m_Load(void) { ui_gadget_h ug; const char *name; struct settingitem *parent; struct ug_cbs cbs = { - .layout_cb = _ug_layout_cb, - .result_cb = _ug_result_cb, - .destroy_cb = _ug_destroy_cb, + .layout_cb = sm_CbUgLayout, + .result_cb = sm_CbUgResult, + .destroy_cb = sm_CbUgDestroy, .end_cb = NULL }; - if (!data) { - _ERR("private data is null."); - return -1; - } - - cbs.priv = data; + cbs.priv = this; - parent = viewdata_get_parentitem(data->view); + parent = viewdata_get_parentitem(m->view); name = settingitem_get_settingui_name(parent); - elm_object_part_text_set(data->base, - UG_TITLE_TEXT, data->display_name); + elm_object_part_text_set(m->base, + UG_TITLE_TEXT, m->display_name); ug = ug_create(NULL, name, UG_MODE_FRAMEVIEW, NULL, &cbs); if (!ug) { _ERR("ug create failed."); - return -1; + return false; } else { - data->ug_is_existed = EINA_TRUE; - data->ug_handler = ug; - data->mgr->FreezeTimeout(); + m->ug_is_existed = EINA_TRUE; + m->ug_handler = ug; + m->mgr->FreezeTimeout(); } - return 0; + return true; } /** @@ -226,6 +222,17 @@ static void _hide_item_btns(Evas_Object *box) eina_list_free(list); } + + +Evas_Object *CUiGadgetView::Base(void) +{ + ASSERT(m); + + return m->base; +} + + + /** * This function is invoked to create UG launcher view layout. * @@ -234,18 +241,17 @@ static void _hide_item_btns(Evas_Object *box) * @param prev [in] The parameter data which passed by prev view or NULL. * @return View layout evas object, NULL on error. */ -static Evas_Object *_create(CSettingMgr *mgr, - struct settingview_data *view, void *prev) +bool CUiGadgetView::Create(struct settingview_data *view, void *prev) { + ASSERT(!m); + ASSERT(view); + ASSERT(prev); + Evas_Object *win, *base; - struct _data *data; + SUiGadgetView *m; struct evas_obj_data *param; - int r; - if (!mgr || !prev || !view) { - _ERR("mgr is null."); - return NULL; - } + CSettingMgr *mgr = CSettingMgr::GetInstance(); param = (struct evas_obj_data *) prev; @@ -257,41 +263,43 @@ static Evas_Object *_create(CSettingMgr *mgr, return NULL; } - data = (struct _data *) calloc(1, sizeof(struct _data)); - if (!data) { - _ERR("calloc struct _data failed."); - return NULL; + m = new SUiGadgetView; + if (!m) { + _ERR("calloc SUiGadgetView failed."); + return false; } base = elm_layout_add(win); if (!base) { _ERR("add base layout failed."); - free(data); - return NULL; + delete m; + m = NULL; + return false; } elm_layout_file_set(base, EDJ_FILE, UG_GROUP); - data->win = win; - data->base = base; - data->mgr = mgr; - data->view = view; - data->subitem_box = param->subitem_box; - data->display_name = param->display_name; - data->subbtn = param->cur_btn; - data->ug_is_existed = EINA_FALSE; + m->win = win; + m->base = base; + m->mgr = mgr; + m->view = view; + m->subitem_box = param->subitem_box; + m->display_name = param->display_name; + m->subbtn = param->cur_btn; + m->ug_is_existed = EINA_FALSE; - evas_object_data_set(base, DATA_ID, data); + evas_object_data_set(base, DATA_ID, m); - r = _load_uigadget(data); - if (r == -1) { + if (!m_Load()) { _ERR("load ui gadget failed."); - free(data); evas_object_del(base); - return NULL; + delete m; + m = NULL; + + return false; } - return base; + return true; } /** @@ -300,14 +308,11 @@ static Evas_Object *_create(CSettingMgr *mgr, * @param base [in] The view layout evas object. * @return void. */ -static void _show(Evas_Object *base) +void CUiGadgetView::Show(void) { - if (!base) { - _ERR("Invalid argument!"); - return; - } + ASSERT(m); - evas_object_show(base); + evas_object_show(m->base); } /** @@ -316,31 +321,23 @@ static void _show(Evas_Object *base) * @param base [in] The view layout evas object. * @return void. */ -static void _destroy(Evas_Object *base) +void CUiGadgetView::Destroy(void) { - struct _data *data; + ASSERT(m); - if (!base) { - _ERR("Invalid argument!"); - return; - } - - data = (struct _data *) evas_object_data_get(base, DATA_ID); - if (!data) { - _ERR("Fail to get uglauncher data"); - return; - } + if (m->ug_is_existed == EINA_TRUE) + ug_destroy(m->ug_handler); - if (data->ug_is_existed == EINA_TRUE) - ug_destroy(data->ug_handler); + if (m->view) + viewdata_release(m->view); - if (data->view) - viewdata_release(data->view); - - evas_object_del(base); - free(data); + evas_object_del(m->base); + delete m; + m = NULL; } +#if 0 + static struct setting_class _vclass = { VCLASS_TITLE_UG, _create, @@ -366,3 +363,4 @@ struct setting_class *view_uigadget_get_vclass(void) { return &_vclass; } +#endif \ No newline at end of file -- 2.7.4 From ad9dfe235f2169e251f417a5cf903d337b9864fa Mon Sep 17 00:00:00 2001 From: JuWan Kim Date: Tue, 31 Mar 2015 14:04:13 +0900 Subject: [PATCH 16/16] Fix launch bug after refactoring Signed-off-by: JuWan Kim Change-Id: Ie1ea8410d6ba7e0a777ff75784d1a4a6de914112 --- src/settingviewmgr.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/settingviewmgr.cpp b/src/settingviewmgr.cpp index 4a85a31..4da9d71 100644 --- a/src/settingviewmgr.cpp +++ b/src/settingviewmgr.cpp @@ -276,11 +276,13 @@ void _frozen_view_in_list(struct SSettingMgr *mgr) return; } - EINA_LIST_REVERSE_FOREACH(mgr->view_list, l, obj) { - sinfo = (struct _settinginfo *)obj; - sinfo->sclass->Frozen(); - //if (sinfo->sclass->frozen) - // sinfo->sclass->frozen(sinfo->base); + if(mgr->view_list) { + EINA_LIST_REVERSE_FOREACH(mgr->view_list, l, obj) { + sinfo = (struct _settinginfo *)obj; + sinfo->sclass->Frozen(); + //if (sinfo->sclass->frozen) + // sinfo->sclass->frozen(sinfo->base); + } } } @@ -387,6 +389,8 @@ bool CSettingMgr::Initialize(Evas_Object *win) instance->m->data = data; instance->m->handler = handler; instance->m->is_freeze = EINA_FALSE; + instance->m->view_list = NULL; + instance->m->item_path = NULL; return true; } -- 2.7.4