4 * Copyright 2012 Samsung Electronics Co., Ltd
6 * Licensed under the Flora License, Version 1.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.tizenopensource.org/license
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 #include <efl_extension.h>
22 #include "view_detail.h"
23 #include "i18nmanager.h"
24 #include "viewer_manager.h"
25 #include "viewer_list.h"
26 #include "winset_popup.h"
27 #include "common_utils.h"
28 #include "common_ip_info.h"
29 #include "common_eap_connect.h"
31 typedef struct _view_detail_data {
36 eap_info_list_t *eap_info_list;
37 full_ip_info_t *ip_info;
38 Evas_Object *forget_confirm_popup;
39 Evas_Object *view_detail_list;
41 Evas_Object *ctxpopup;
44 static int view_detail_end = TRUE;
45 extern wifi_appdata *ug_app_state;
46 static view_detail_data *_detail_data = NULL;
47 static Eina_Bool rotate_flag = EINA_FALSE;
48 static int pos_changed = 0;
50 static Eina_Bool detailview_sk_cb(void *data, Elm_Object_Item *it);
51 static void forget_sk_cb(void *data, Evas_Object *obj, void *event_info);
52 static void _transition_finished_sub_cb(void *data, Evas_Object *obj, void *event_info);
53 static void _create_ctxpopup_forget_btn_cb(void *data, Evas_Object *obj, void *event_info);
54 static void _ctxpopup_del_cb(void *data, Evas_Object *obj, void *event_info);
55 static void _ctxpopup_move(Evas_Object *parent);
56 static void _ctxpopup_dismissed_cb(void *data, Evas_Object *obj, void *event_info);
57 static void _ctxpopup_delete_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
58 static void _ctxpopup_rotate_cb(void *data, Evas_Object *obj, void *event_info);
59 static void _ctxpopup_resize_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
61 static void _create_ctxpopup_forget_btn_cb(void *data, Evas_Object *obj, void *event_info)
63 struct ug_data *ugd = NULL;
64 Evas_Object *parent = NULL;
65 Elm_Object_Item *item = NULL;
67 ugd = (struct ug_data *)ug_app_state->gadget;
70 parent = ugd->win_main;
71 if (!parent || !_detail_data) {
75 if (_detail_data->ctxpopup) {
76 evas_object_del(_detail_data->ctxpopup);
79 _detail_data->ctxpopup = elm_ctxpopup_add(parent);
81 elm_ctxpopup_auto_hide_disabled_set(_detail_data->ctxpopup, EINA_TRUE);
82 elm_object_style_set(_detail_data->ctxpopup, "more/default");
83 eext_object_event_callback_add(_detail_data->ctxpopup, EA_CALLBACK_BACK,
84 _ctxpopup_del_cb, NULL);
85 eext_object_event_callback_add(_detail_data->ctxpopup, EA_CALLBACK_MORE,
86 _ctxpopup_del_cb, NULL);
87 evas_object_smart_callback_add(_detail_data->ctxpopup, "dismissed",
88 _ctxpopup_dismissed_cb, NULL);
89 evas_object_event_callback_add(_detail_data->ctxpopup, EVAS_CALLBACK_DEL,
90 _ctxpopup_delete_cb, parent);
91 evas_object_event_callback_add(parent, EVAS_CALLBACK_RESIZE,
92 _ctxpopup_resize_cb, _detail_data->ctxpopup);
94 evas_object_smart_callback_add(elm_object_top_widget_get(_detail_data->ctxpopup),
95 "rotation,changed", _ctxpopup_rotate_cb, _detail_data->ctxpopup);
97 item = elm_ctxpopup_item_append(_detail_data->ctxpopup,
98 "IDS_WIFI_SK_FORGET", NULL, forget_sk_cb, _detail_data);
99 elm_object_item_domain_text_translatable_set(item, PACKAGE, EINA_TRUE);
101 elm_ctxpopup_direction_priority_set(_detail_data->ctxpopup,
102 ELM_CTXPOPUP_DIRECTION_UP, ELM_CTXPOPUP_DIRECTION_UNKNOWN,
103 ELM_CTXPOPUP_DIRECTION_UNKNOWN, ELM_CTXPOPUP_DIRECTION_UNKNOWN);
105 _ctxpopup_move(_detail_data->ctxpopup);
106 evas_object_show(_detail_data->ctxpopup);
109 static void _ctxpopup_del_cb(void *data, Evas_Object *obj, void *event_info)
111 __COMMON_FUNC_ENTER__;
116 evas_object_del(_detail_data->ctxpopup);
117 _detail_data->ctxpopup = NULL;
119 __COMMON_FUNC_EXIT__;
122 static void _ctxpopup_move(Evas_Object *parent)
124 __COMMON_FUNC_ENTER__;
133 win = elm_object_top_widget_get(_detail_data->ctxpopup);
134 elm_win_screen_size_get(win, NULL, NULL, &w, &h);
135 pos = elm_win_rotation_get(win);
136 if (pos == 0 || pos == 180) {
138 } else if (pos == 90 || pos == 270) {
145 evas_object_move(_detail_data->ctxpopup, (w/2), h);
148 evas_object_move(_detail_data->ctxpopup, (h/2), w);
151 evas_object_move(_detail_data->ctxpopup, (h/2), w);
154 __COMMON_FUNC_EXIT__;
157 static void _ctxpopup_dismissed_cb(void *data, Evas_Object *obj, void *event_info)
159 __COMMON_FUNC_ENTER__;
164 Evas_Object *_win_main = data;
167 evas_object_del(_detail_data->ctxpopup);
168 _detail_data->ctxpopup = NULL;
170 _ctxpopup_move(_win_main);
171 evas_object_show(_detail_data->ctxpopup);
172 rotate_flag = EINA_FALSE;
175 __COMMON_FUNC_EXIT__;
178 static void _ctxpopup_delete_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
180 __COMMON_FUNC_ENTER__;
182 Evas_Object *navi = (Evas_Object *)data;
183 Evas_Object *ctx = obj;
191 evas_object_smart_callback_del(ctx, "dismissed",
192 _ctxpopup_dismissed_cb);
193 evas_object_event_callback_del(navi, EVAS_CALLBACK_RESIZE,
194 _ctxpopup_resize_cb);
195 evas_object_smart_callback_del(elm_object_top_widget_get(ctx),
196 "rotation,changed", _ctxpopup_rotate_cb);
197 evas_object_event_callback_del_full(ctx, EVAS_CALLBACK_DEL,
198 _ctxpopup_delete_cb, navi);
200 __COMMON_FUNC_EXIT__;
204 static void _ctxpopup_rotate_cb(void *data, Evas_Object *obj, void *event_info)
207 __COMMON_FUNC_ENTER__;
212 Evas_Object *_win_main = data;
214 _ctxpopup_move(_win_main);
215 evas_object_show(_detail_data->ctxpopup);
217 __COMMON_FUNC_EXIT__;
220 static void _ctxpopup_resize_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
222 __COMMON_FUNC_ENTER__;
224 if (_detail_data->ctxpopup) {
229 win = elm_object_top_widget_get(_detail_data->ctxpopup);
230 elm_win_screen_size_get(win, NULL, NULL, &w, &h);
231 pos = elm_win_rotation_get(win);
232 if (pos == 0 || pos == 180) {
234 } else if (pos == 90 || pos == 270) {
237 if (pos_changed != pos) {
238 rotate_flag = EINA_TRUE;
240 rotate_flag = EINA_FALSE;
243 rotate_flag = EINA_FALSE;
245 __COMMON_FUNC_EXIT__;
248 static char *_view_detail_grouptitle_text_get(void *data,
249 Evas_Object *obj, const char *part)
251 __COMMON_FUNC_ENTER__;
253 retvm_if(NULL == part, NULL);
259 if (!strcmp("elm.text.sub", part)) {
260 ret = (char*) g_strdup(dgettext(PACKAGE, "IDS_WIFI_BODY_NAME"));
261 } else if (!strcmp("elm.text", part)) {
262 _detail_data = (view_detail_data *)data;
263 retvm_if(NULL == _detail_data, NULL);
265 if (wifi_ap_get_essid(_detail_data->ap, &tmp) != WIFI_ERROR_NONE) {
269 txt = evas_textblock_text_utf8_to_markup(NULL, tmp);
275 __COMMON_FUNC_EXIT__;
279 static Evas_Object *_view_detail_grouptitle_content_get(void *data, Evas_Object *obj, const char *part)
281 retvm_if(NULL == data || NULL == part, NULL);
283 view_detail_data *_detail_data = (view_detail_data *)data;
284 _detail_data = (view_detail_data *)data;
285 Evas_Object* icon = NULL;
286 Evas_Object* ic = NULL;
288 if (!strcmp("elm.swallow.end", part)) {
289 char *temp_str = NULL;
291 ic = elm_layout_add(obj);
292 elm_layout_theme_set(ic, "layout", "list/C/type.1", "default");
294 icon = elm_image_add(ic);
295 retvm_if(NULL == icon, NULL);
297 if (_detail_data->ap_image_path != NULL) {
298 temp_str = g_strdup_printf("%s.png", _detail_data->ap_image_path);
300 /* if there is no ap_image_path (NO AP Found situation)
301 * So use a default image */
302 temp_str = g_strdup_printf("%s.png", "A01-3_icon_lock_00");
304 evas_object_color_set(icon, 2, 61, 132, 204);
306 elm_image_file_set(icon, CUSTOM_EDITFIELD_PATH, temp_str);
309 evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL);
310 evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
311 elm_layout_content_set(ic, "elm.swallow.content", icon);
316 static void _remove_all(view_detail_data *_detail_data)
318 __COMMON_FUNC_ENTER__;
322 if (_detail_data->forget_confirm_popup != NULL) {
323 evas_object_del(_detail_data->forget_confirm_popup);
324 _detail_data->forget_confirm_popup = NULL;
327 if (_detail_data->ctxpopup) {
328 evas_object_del(_detail_data->ctxpopup);
329 _detail_data->ctxpopup = NULL;
332 if (_detail_data->eap_info_list) {
333 eap_info_remove(_detail_data->eap_info_list);
336 ip_info_remove(_detail_data->ip_info->ip_info_list);
337 ip_info_delete_prev(_detail_data->ip_info->prev_ip_info);
338 _detail_data->ip_info->ip_info_list = NULL;
339 _detail_data->eap_info_list = NULL;
341 g_free(_detail_data->ap_image_path);
342 _detail_data->ap_image_path = NULL;
343 g_free(_detail_data);
348 __COMMON_FUNC_EXIT__;
351 static gboolean __forget_wifi_ap(gpointer data)
353 __COMMON_FUNC_ENTER__;
355 wifi_ap_h ap = (wifi_ap_h)data;
357 wlan_manager_forget(ap);
359 viewer_manager_update_item_favorite_status(ap);
362 __COMMON_FUNC_EXIT__;
366 static void ok_cb(void *data, Evas_Object *obj, void *event_info)
368 __COMMON_FUNC_ENTER__;
372 //view_detail_data *_detail_data;
374 if (view_detail_end == TRUE) {
378 view_detail_end = TRUE;
379 _detail_data = (view_detail_data *)data;
380 retm_if(NULL == _detail_data);
382 wifi_ap_clone(&ap, _detail_data->ap);
384 if (_detail_data->forget_confirm_popup != NULL) {
385 evas_object_del(_detail_data->forget_confirm_popup);
386 _detail_data->forget_confirm_popup = NULL;
389 _remove_all(_detail_data);
391 elm_naviframe_item_pop(viewer_manager_get_naviframe());
393 id = common_util_managed_idle_add(__forget_wifi_ap, (gpointer)ap);
398 __COMMON_FUNC_EXIT__;
401 static void cancel_cb(void *data, Evas_Object *obj, void *event_info)
403 __COMMON_FUNC_ENTER__;
405 // view_detail_data *_detail_data = (view_detail_data *)data;
406 _detail_data = (view_detail_data *)data;
407 retm_if(NULL == _detail_data);
409 if (_detail_data->forget_confirm_popup != NULL) {
410 evas_object_del(_detail_data->forget_confirm_popup);
411 _detail_data->forget_confirm_popup = NULL;
414 __COMMON_FUNC_EXIT__;
417 static void forget_sk_cb(void *data, Evas_Object *obj, void *event_info)
419 __COMMON_FUNC_ENTER__;
421 // view_detail_data *_detail_data = (view_detail_data *)data;
422 _detail_data = (view_detail_data *)data;
423 retm_if(NULL == _detail_data);
425 if (!_detail_data->forget_confirm_popup) {
426 popup_btn_info_t popup_data;
427 memset(&popup_data, 0, sizeof(popup_data));
429 popup_data.title_txt = "IDS_WIFI_OPT_FORGET_NETWORK";
430 popup_data.info_txt = "IDS_WIFI_POP_CURRENT_NETWORK_WILL_BE_DISCONNECTED";
431 popup_data.btn1_cb = cancel_cb;
432 popup_data.btn1_txt = "IDS_WIFI_SK_CANCEL";
433 popup_data.btn1_data = _detail_data;
434 popup_data.btn2_cb = ok_cb;
435 popup_data.btn2_txt = "IDS_WIFI_SK_FORGET";
436 popup_data.btn2_data = _detail_data;
438 _detail_data->forget_confirm_popup = common_utils_show_info_popup(_detail_data->win, &popup_data);
441 if (_detail_data->ctxpopup != NULL) {
442 evas_object_del(_detail_data->ctxpopup);
443 _detail_data->ctxpopup = NULL;
446 __COMMON_FUNC_EXIT__;
449 static Eina_Bool detailview_sk_cb(void *data, Elm_Object_Item *it)
451 __COMMON_FUNC_ENTER__;
453 Evas_Object *navi_frame = NULL;
455 if (view_detail_end == TRUE) {
459 view_detail_end = TRUE;
461 // view_detail_data *_detail_data = (view_detail_data *)data;
462 _detail_data = (view_detail_data *)data;
463 retvm_if(NULL == _detail_data, EINA_TRUE);
465 /* Delete context popup */
466 if (_detail_data->ctxpopup) {
467 evas_object_del(_detail_data->ctxpopup);
468 _detail_data->ctxpopup = NULL;
471 navi_frame = viewer_manager_get_naviframe();
472 retvm_if(NULL == navi_frame, EINA_TRUE);
474 evas_object_smart_callback_add(navi_frame, "transition,finished",
475 _transition_finished_sub_cb, _detail_data);
477 __COMMON_FUNC_EXIT__;
482 static void __view_detail_imf_ctxt_evnt_cb(void *data, Ecore_IMF_Context *ctx, int value)
487 if (value == ECORE_IMF_INPUT_PANEL_STATE_SHOW) {
488 DEBUG_LOG(UG_NAME_NORMAL, "Key pad is now open");
489 elm_object_item_signal_emit(data, "elm,state,sip,shown", "");
490 } else if (value == ECORE_IMF_INPUT_PANEL_STATE_HIDE) {
491 DEBUG_LOG(UG_NAME_NORMAL, "Key pad is now closed");
492 elm_object_item_signal_emit(data, "elm,state,sip,hidden", "");
497 static gboolean __view_detail_load_ip_info_list_cb(void *data)
499 __COMMON_FUNC_ENTER__;
500 Elm_Object_Item *navi_it = NULL;
501 Evas_Object *list = NULL;
503 _detail_data = (view_detail_data *)data;
509 navi_it = elm_naviframe_top_item_get(viewer_manager_get_naviframe());
510 layout = elm_object_item_part_content_get(navi_it, "elm.swallow.content");
512 /* Create an EAP connect view list */
513 list = elm_object_part_content_get(layout, "elm.swallow.content");
515 /* Append ip info list */
516 _detail_data->ip_info = ip_info_append_items(_detail_data->ap,
517 PACKAGE, list, __view_detail_imf_ctxt_evnt_cb, navi_it);
518 if (_detail_data && _detail_data->btn) {
519 elm_object_disabled_set(_detail_data->btn, EINA_FALSE);
521 __COMMON_FUNC_EXIT__;
525 static void _transition_finished_sub_cb(void *data, Evas_Object *obj, void *event_info)
527 __COMMON_FUNC_ENTER__;
529 Evas_Object *navi = NULL;
530 Elm_Object_Item *target_item = NULL;
531 wifi_connection_state_e connection_state;
533 _detail_data = (view_detail_data *)data;
535 __COMMON_FUNC_EXIT__;
540 if (_detail_data->eap_info_list) {
541 eap_info_save_data(_detail_data->eap_info_list);
545 navi = (Evas_Object *)viewer_manager_get_naviframe();
547 __COMMON_FUNC_EXIT__;
550 ip_info_save_data(_detail_data->ip_info);
552 evas_object_smart_callback_del(navi, "transition,finished",
553 _transition_finished_sub_cb);
555 if (_detail_data->ip_info->is_info_changed == TRUE &&
556 _detail_data->ap != NULL) {
557 wifi_ap_get_connection_state(_detail_data->ap, &connection_state);
558 if (WIFI_CONNECTION_STATE_CONNECTED == connection_state) {
559 target_item = item_get_for_ap(_detail_data->ap);
560 viewer_list_item_radio_mode_set(target_item,
561 VIEWER_ITEM_RADIO_MODE_CONNECTING);
565 _remove_all(_detail_data);
568 __COMMON_FUNC_EXIT__;
571 static void gl_lang_changed(void *data, Evas_Object *obj, void *event_info)
573 elm_genlist_realized_items_update(obj);
576 void view_detail(wifi_device_info_t *device_info, Evas_Object *win_main,
579 __COMMON_FUNC_ENTER__;
583 static Elm_Genlist_Item_Class grouptitle_itc;
584 Evas_Object *layout = NULL;
585 Evas_Object *navi_frame = NULL;
586 Evas_Object *detailview_list = NULL;
587 Elm_Object_Item *title = NULL;
588 Elm_Object_Item *navi_it = NULL;
589 Evas_Object *more_btn = NULL;
591 if (device_info == NULL) {
592 ERROR_LOG(UG_NAME_NORMAL, "Failed: device_info is NULL");
596 navi_frame = viewer_manager_get_naviframe();
597 if (navi_frame == NULL) {
598 ERROR_LOG(UG_NAME_NORMAL, "Failed to get naviframe");
601 ecore_imf_input_panel_hide();
602 view_detail_end = FALSE;
604 _detail_data = g_try_new0(view_detail_data, 1);
605 retm_if(NULL == _detail_data);
607 _detail_data->win = win_main;
608 _detail_data->nav = navi_frame;
609 _detail_data->ap = ap = device_info->ap;
610 wifi_ap_is_favorite(ap, &favorite);
612 if (device_info->ap_image_path) {
613 _detail_data->ap_image_path = g_strdup(device_info->ap_image_path);
615 _detail_data->btn = btn;
616 if (ug_app_state->ug_type == UG_VIEW_SETUP_WIZARD) {
617 layout = elm_layout_add(navi_frame);
619 elm_layout_file_set(layout, SETUP_WIZARD_EDJ_PATH, "detail_pwlock");
620 elm_object_domain_translatable_part_text_set(layout,
621 "text.title", PACKAGE, "IDS_WIFI_HEADER_WI_FI_NETWORK_INFO_ABB");
623 navi_it = elm_naviframe_item_push(navi_frame,
624 NULL, NULL, NULL, layout, NULL);
625 elm_naviframe_item_title_enabled_set(navi_it, EINA_FALSE, EINA_FALSE);
627 struct ug_data *ugd = (struct ug_data *)ug_app_state->gadget;
628 int change_ang = elm_win_rotation_get(ugd->win_main);
629 if (change_ang == 0 || change_ang == 180) {
630 common_utils_contents_rotation_adjust(UG_EVENT_ROTATE_PORTRAIT);
631 edje_object_signal_emit((Evas_Object *)elm_layout_edje_get(layout)
632 ,"location,vertical", "elm");
634 common_utils_contents_rotation_adjust(UG_EVENT_ROTATE_LANDSCAPE);
635 edje_object_signal_emit((Evas_Object *)elm_layout_edje_get(layout),
636 "location,horizontal", "elm");
639 layout = common_utils_create_layout(navi_frame);
641 navi_it = elm_naviframe_item_push(navi_frame,
642 "IDS_WIFI_HEADER_WI_FI_NETWORK_INFO_ABB",
643 NULL, NULL, layout, NULL);
644 elm_object_item_domain_text_translatable_set(navi_it,
648 evas_object_show(layout);
650 detailview_list = elm_genlist_add(layout);
651 assertm_if(NULL == detailview_list, "NULL!!");
653 elm_object_style_set(detailview_list, "dialogue");
654 _detail_data->view_detail_list = detailview_list;
656 evas_object_smart_callback_add(detailview_list, "language,changed",
657 gl_lang_changed, NULL);
659 grouptitle_itc.item_style = WIFI_GENLIST_2LINE_BOTTOM_TEXT_ICON_STYLE;
660 grouptitle_itc.func.text_get = _view_detail_grouptitle_text_get;
661 grouptitle_itc.func.content_get = _view_detail_grouptitle_content_get;
662 grouptitle_itc.func.state_get = NULL;
663 grouptitle_itc.func.del = NULL;
665 /* AP name and signal strength icon */
666 title = elm_genlist_item_append(detailview_list,
667 &grouptitle_itc, _detail_data, NULL, ELM_GENLIST_ITEM_GROUP,
669 elm_genlist_item_select_mode_set(title, ELM_OBJECT_SELECT_MODE_NONE);
671 elm_object_part_content_set(layout, "elm.swallow.content", detailview_list);
673 evas_object_data_set(navi_frame, SCREEN_TYPE_ID_KEY,
674 (void *)VIEW_MANAGER_VIEW_TYPE_DETAIL);
676 /* Set pop callback */
677 elm_naviframe_item_pop_cb_set(navi_it, detailview_sk_cb, _detail_data);
680 /* Toolbar Forget button */
682 Evas_Object *toolbar = NULL;
684 toolbar = elm_toolbar_add(navi_frame);
685 elm_toolbar_shrink_mode_set(toolbar, ELM_TOOLBAR_SHRINK_EXPAND);
686 elm_toolbar_transverse_expanded_set(toolbar, EINA_TRUE);
687 elm_toolbar_select_mode_set(toolbar, ELM_OBJECT_SELECT_MODE_NONE);
689 elm_toolbar_item_append(toolbar, NULL,
690 sc(PACKAGE, I18N_TYPE_Forget),
691 forget_sk_cb, _detail_data);
693 elm_object_item_part_content_set(navi_it, "toolbar", toolbar);
696 more_btn = elm_button_add(_detail_data->nav);
697 elm_object_style_set(more_btn, "naviframe/more/default");
698 evas_object_smart_callback_add(more_btn, "clicked",
699 _create_ctxpopup_forget_btn_cb, win_main);
700 elm_object_item_part_content_set(navi_it, "toolbar_more_btn", more_btn);
703 wifi_security_type_e type = WIFI_SECURITY_TYPE_NONE;
704 wifi_ap_get_security_type(ap, &type);
705 if (WIFI_SECURITY_TYPE_EAP == type) {
706 wifi_connection_state_e connection_state;
707 wifi_ap_get_connection_state(ap, &connection_state);
708 if (favorite || WIFI_CONNECTION_STATE_CONNECTED == connection_state) {
709 _detail_data->eap_info_list = eap_info_append_items(ap,
710 detailview_list, PACKAGE, __view_detail_imf_ctxt_evnt_cb,
715 /* Append the ip info details */
716 id = common_util_managed_idle_add(__view_detail_load_ip_info_list_cb, _detail_data);
718 g_free(_detail_data);
721 __COMMON_FUNC_EXIT__;