[TSAM-9582] Fixed display issue when settings changed
[apps/native/ug-mobile-ap.git] / src / mh_view_wifi_setup.c
1 /*
2 * ug-mobile-ap
3 *
4 * Copyright 2012  Samsung Electronics Co., Ltd
5
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
9
10 * http://www.tizenopensource.org/license
11
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.
17 *
18 */
19 #include <efl_extension.h>
20
21 #include "mh_popup.h"
22 #include "mh_view_wifi_setup.h"
23 #include "mh_string.h"
24
25 static void __gl_realized(void *data, Evas_Object *obj, void *event_info);
26 static void __cancel_btn_cb(void *data, Evas_Object *object, void *event_info);
27 static void __save_btn_cb(void *data, Evas_Object *object, void *event_info);
28
29 static guint tethering_param_timer = 0;
30
31 static void __hide_btn_changed_cb(void *data, Evas_Object *obj, void *event_info)
32 {
33         __MOBILE_AP_FUNC_ENTER__;
34
35         if (data == NULL || obj == NULL) {
36                 ERR("Invalid param\n");
37                 return;
38         }
39
40         mh_appdata_t *ad = (mh_appdata_t *)data;
41
42         ad->setup.visibility_new = !ad->setup.visibility_new;
43
44         __MOBILE_AP_FUNC_EXIT__;
45 }
46
47 static bool __save_hide_btn_change(mh_appdata_t *ad)
48 {
49         __MOBILE_AP_FUNC_ENTER__;
50
51         if (ad == NULL) {
52                 ERR("Invalid param\n");
53                 return false;
54         }
55
56         int ret = 0;
57
58         ret = tethering_wifi_set_ssid_visibility(ad->handle,
59                         ad->setup.visibility_new);
60         if (ret != TETHERING_ERROR_NONE) {
61                 ERR("tethering_wifi_set_ssid_visibility is failed : %d\n", ret);
62                 return false;
63         }
64
65         __MOBILE_AP_FUNC_EXIT__;
66         return true;
67 }
68
69 static void __security_btn_changed_cb(void *data, Evas_Object *obj, void *event_info)
70 {
71         __MOBILE_AP_FUNC_ENTER__;
72
73         if (data == NULL || obj == NULL) {
74                 ERR("Invalid param\n");
75                 return;
76         }
77
78         mh_appdata_t *ad = (mh_appdata_t *)data;
79         mh_wifi_setting_view_t *st = &ad->setup;
80
81         if (st->security_type_new == TETHERING_WIFI_SECURITY_TYPE_NONE)
82                 st->security_type_new = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
83         else
84                 st->security_type_new = TETHERING_WIFI_SECURITY_TYPE_NONE;
85
86         /* update wifi passphrase item */
87         if (st->security_type_new == TETHERING_WIFI_SECURITY_TYPE_NONE) {
88                 elm_object_item_disabled_set(st->pw_item, EINA_TRUE);
89                 elm_object_disabled_set(st->save_button, EINA_FALSE);
90         } else {
91                 elm_object_item_disabled_set(st->pw_item, EINA_FALSE);
92         }
93
94         if (st->pw_item)
95                 elm_genlist_item_update(st->pw_item);
96
97         __MOBILE_AP_FUNC_EXIT__;
98 }
99
100 static bool __save_security_btn_change(mh_appdata_t *ad)
101 {
102         __MOBILE_AP_FUNC_ENTER__;
103
104         if (ad == NULL) {
105                 ERR("Invalid param\n");
106                 return false;
107         }
108
109         int ret = 0;
110
111         ret = tethering_wifi_set_security_type(ad->handle, ad->setup.security_type_new);
112         if (ret != TETHERING_ERROR_NONE) {
113                 ERR("tethering_wifi_set_security_type is failed : %d\n", ret);
114                 return false;
115         }
116
117         __MOBILE_AP_FUNC_EXIT__;
118         return true;
119 }
120
121 static char *__gl_device_name_title_label_get(void *data, Evas_Object *obj, const char *part)
122 {
123         __MOBILE_AP_FUNC_ENTER__;
124         mh_appdata_t *ad = (mh_appdata_t *)data;
125         char *device_name_utf = NULL;
126         char *ptr = NULL;
127         char buf[MH_LABEL_LENGTH_MAX] = {0, };
128
129         if (data == NULL || obj == NULL || part == NULL) {
130                 ERR("Invalid param\n");
131                 return NULL;
132         }
133
134         if (!strcmp("elm.text.multiline", part)) {
135                 device_name_utf = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
136                 if (device_name_utf == NULL)
137                         ERR("vconf_get_str failed \n");
138
139                 ptr = elm_entry_utf8_to_markup(device_name_utf);
140                 if (ptr == NULL) {
141                         ERR("elm_entry_utf8_to_markup is failed\n");
142                         free(device_name_utf);
143                         return NULL;
144                 }
145
146                 g_strlcpy(ad->setup.device_name, ptr,
147                                 sizeof(ad->setup.device_name));
148
149                 snprintf(buf, MH_LABEL_LENGTH_MAX, "<font_size=30>%s</font_size><br>%s", STR_MY_DEVICE_NAME, ptr);
150
151                 free(device_name_utf);
152                 free(ptr);
153
154                 return strdup(buf);
155         }
156
157         __MOBILE_AP_FUNC_EXIT__;
158         return NULL;
159 }
160
161 static char *__gl_hide_label_get(void *data, Evas_Object *obj, const char *part)
162 {
163         __MOBILE_AP_FUNC_ENTER__;
164
165         if (data == NULL || obj == NULL || part == NULL) {
166                 ERR("Invalid param\n");
167                 return NULL;
168         }
169
170         if (!strcmp("elm.text", part))
171                 return strdup(STR_HIDE_MY_DEV);
172
173         __MOBILE_AP_FUNC_EXIT__;
174         return NULL;
175 }
176
177 static char *__gl_security_label_get(void *data, Evas_Object *obj, const char *part)
178 {
179         __MOBILE_AP_FUNC_ENTER__;
180
181         if (data == NULL || obj == NULL || part == NULL) {
182                 ERR("Invalid param\n");
183                 return NULL;
184         }
185
186         if (!strcmp("elm.text", part))
187                 return strdup(STR_SECURITY_TYPE);
188
189         __MOBILE_AP_FUNC_EXIT__;
190         return NULL;
191 }
192
193 static Evas_Object *__gl_hide_icon_get(void *data, Evas_Object *obj,
194                 const char *part)
195 {
196         __MOBILE_AP_FUNC_ENTER__;
197
198         mh_appdata_t *ad = (mh_appdata_t *)data;
199         Evas_Object *btn = NULL;
200
201         if (data == NULL || obj == NULL || part == NULL) {
202                 ERR("Invalid param\n");
203                 return NULL;
204         }
205
206         if (!strcmp("elm.swallow.end", part)) {
207                 btn = elm_check_add(obj);
208                 if (btn == NULL) {
209                         ERR("btn is NULL\n");
210                         return NULL;
211                 }
212
213                 elm_object_style_set(btn, "on&off");
214                 evas_object_show(btn);
215                 evas_object_pass_events_set(btn, EINA_TRUE);
216                 evas_object_propagate_events_set(btn, EINA_FALSE);
217                 elm_object_focus_allow_set(btn, EINA_FALSE);
218                 elm_check_state_set(btn, ad->setup.visibility_new ? EINA_FALSE : EINA_TRUE);
219                 evas_object_smart_callback_add(btn, "changed",
220                                 __hide_btn_changed_cb, (void *)ad);
221                 ad->setup.hide_btn = btn;
222         }
223
224         __MOBILE_AP_FUNC_EXIT__;
225         return btn;
226 }
227
228 static Evas_Object *__gl_security_icon_get(void *data, Evas_Object *obj,
229                 const char *part)
230 {
231         __MOBILE_AP_FUNC_ENTER__;
232
233         mh_appdata_t *ad = (mh_appdata_t *)data;
234         Evas_Object *btn = NULL;
235
236         if (data == NULL || obj == NULL || part == NULL) {
237                 ERR("Invalid param\n");
238                 return NULL;
239         }
240
241         if (!strcmp("elm.swallow.end", part)) {
242                 btn = elm_check_add(obj);
243                 elm_object_style_set(btn, "on&off");
244                 evas_object_show(btn);
245                 evas_object_pass_events_set(btn, EINA_TRUE);
246                 evas_object_propagate_events_set(btn, EINA_FALSE);
247                 elm_check_state_set(btn, ad->setup.security_type_new ==
248                                 TETHERING_WIFI_SECURITY_TYPE_NONE ?
249                                 EINA_FALSE : EINA_TRUE);
250                 evas_object_smart_callback_add(btn, "changed",
251                                 __security_btn_changed_cb, (void *)ad);
252                 ad->setup.security_btn = btn;
253         }
254
255         __MOBILE_AP_FUNC_EXIT__;
256         return btn;
257 }
258
259 static bool __save_wifi_passphrase(mh_appdata_t *ad)
260 {
261         __MOBILE_AP_FUNC_ENTER__;
262
263         if (ad == NULL) {
264                 ERR("Invalid param\n");
265                 return false;
266         }
267
268         mh_wifi_setting_view_t *st = &ad->setup;
269         int ret = 0;
270
271         ret = tethering_wifi_set_passphrase(ad->handle, st->wifi_passphrase_new);
272         if (ret != TETHERING_ERROR_NONE) {
273                 ERR("tethering_wifi_set_passphrase is failed : %d\n", ret);
274                 return false;
275         }
276
277         __MOBILE_AP_FUNC_EXIT__;
278         return true;
279 }
280
281 static void __pw_entry_changed_cb(void *data, Evas_Object *obj,
282                                 void *event_info)
283 {
284         __MOBILE_AP_FUNC_ENTER__;
285
286         mh_appdata_t *ad = (mh_appdata_t *)data;
287         mh_wifi_setting_view_t *st = &ad->setup;
288         const char *changed_text;
289         char *utf8_string;
290         int len = 0;
291
292         changed_text = elm_entry_entry_get(obj);
293         if (changed_text == NULL) {
294                 ERR("elm_entry_entry_get is failed\n");
295                 return;
296         }
297
298         utf8_string = elm_entry_markup_to_utf8(changed_text);
299
300         if (utf8_string == NULL) {
301                 ERR("elm_entry_markup_to_utf8() Failed!!!\n");
302         } else {
303                 len = strlen(utf8_string);
304                 if (WIFI_PASSPHRASE_LENGTH_MIN <= len) {
305                         elm_object_disabled_set(st->save_button, EINA_FALSE);
306                         elm_entry_input_panel_return_key_disabled_set(obj, FALSE);
307                 } else {
308                         elm_object_disabled_set(st->save_button, EINA_TRUE);
309                         elm_entry_input_panel_return_key_disabled_set(obj, TRUE);
310                 }
311                 g_strlcpy(st->wifi_passphrase_new, utf8_string,
312                                                 sizeof(st->wifi_passphrase_new));
313                 free(utf8_string);
314                 utf8_string = NULL;
315         }
316
317         if (elm_object_part_content_get(obj, "elm.swallow.clear")) {
318                 if (elm_object_focus_get(obj)) {
319                         if (elm_entry_is_empty(obj))
320                                 elm_object_signal_emit(obj, "elm,state,clear,hidden", "");
321                         else
322                                 elm_object_signal_emit(obj, "elm,state,clear,visible", "");
323                 }
324         }
325
326         __MOBILE_AP_FUNC_EXIT__;
327         return;
328 }
329
330 static void __pw_entry_maxlength_reached_cb(void *data, Evas_Object *obj,
331                 void *event_info)
332 {
333         __MOBILE_AP_FUNC_ENTER__;
334
335         if (obj == NULL) {
336                 ERR("The param is NULL\n");
337                 __MOBILE_AP_FUNC_EXIT__;
338                 return;
339         }
340         char buf[MH_LABEL_LENGTH_MAX] = { 0, };
341         char *fmt = STR_PASSWORD_MIN_MAX;
342         notification_error_e ret;
343
344         snprintf(buf, sizeof(buf), fmt,
345                         WIFI_PASSPHRASE_LENGTH_MIN, WIFI_PASSPHRASE_LENGTH_MAX);
346
347         ret = notification_status_message_post(buf);
348         if (ret != NOTIFICATION_ERROR_NONE)
349                 ERR("notification_status_message_post() is failed : %d\n", ret);
350
351         __MOBILE_AP_FUNC_EXIT__;
352 }
353
354 static void __pw_entry_activated_cb(void *data, Evas_Object *obj, void *event_info)
355 {
356         __MOBILE_AP_FUNC_ENTER__;
357
358         if (obj == NULL) {
359                 ERR("Invalid parameter");
360                 return;
361         }
362
363         elm_object_focus_set(obj, EINA_FALSE);
364         __MOBILE_AP_FUNC_EXIT__;
365         return;
366 }
367
368 static void __pw_entry_focused_cb(void *data, Evas_Object *obj, void *event_info)
369 {
370         __MOBILE_AP_FUNC_ENTER__;
371         evas_object_smart_callback_del(obj, "focused", __pw_entry_focused_cb);
372
373          elm_object_focus_set(obj, EINA_TRUE);
374          elm_entry_cursor_end_set(obj);
375          __MOBILE_AP_FUNC_EXIT__;
376 }
377
378 static void __pw_entry_unfocused_cb(void *data, Evas_Object *obj, void *event_info)
379 {
380         __MOBILE_AP_FUNC_ENTER__;
381         if (elm_object_part_content_get(obj, "elm.swallow.clear"))
382                 elm_object_signal_emit(obj, "elm,state,clear,hidden", "");
383         elm_object_signal_emit(obj, "elm,state,focus,off", "");
384         __MOBILE_AP_FUNC_EXIT__;
385 }
386
387 static void __pw_entry_show_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
388 {
389         __MOBILE_AP_FUNC_ENTER__;
390          evas_object_event_callback_del(obj, EVAS_CALLBACK_SHOW, __pw_entry_show_cb);
391
392          elm_object_focus_set(obj, EINA_TRUE);
393          elm_entry_cursor_end_set(obj);
394          __MOBILE_AP_FUNC_EXIT__;
395 }
396
397 static void __eraser_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
398 {
399         __MOBILE_AP_FUNC_ENTER__;
400
401         elm_object_text_set(data, "");
402         elm_entry_input_panel_return_key_disabled_set(data, TRUE);
403
404         __MOBILE_AP_FUNC_EXIT__;
405 }
406
407 static void __pw_entry_language_changed_cb(void *data, Evas_Object *obj, void *event_info)
408 {
409         __MOBILE_AP_FUNC_ENTER__;
410
411         if (obj == NULL || data == NULL) {
412                 ERR("NULL param\n");
413                 return;
414         }
415         mh_appdata_t *ad = (mh_appdata_t *)data;
416         mh_wifi_setting_view_t *st = &ad->setup;
417         char buf[MH_LABEL_LENGTH_MAX];
418         char *fmt = STR_PW_GUIDE_TEXT;
419
420         snprintf(buf, sizeof(buf), fmt, WIFI_PASSPHRASE_LENGTH_MIN);
421
422         if (st->security_type_new == TETHERING_WIFI_SECURITY_TYPE_NONE) {
423                 if (st->pw_item)
424                         elm_genlist_item_update(st->pw_item);
425         } else {
426                 elm_object_part_text_set(obj, "elm.guide", buf);
427         }
428         __MOBILE_AP_FUNC_EXIT__;
429 }
430
431 static Evas_Object *__get_pw_entry(void *data, Evas_Object *parent)
432 {
433         __MOBILE_AP_FUNC_ENTER__;
434
435         static Elm_Entry_Filter_Limit_Size limit_filter_data;
436         Evas_Object *entry = NULL;
437         char *fmt = STR_PW_GUIDE_TEXT;
438         char *ptr = NULL;
439         Evas_Object * clr_btn = NULL;
440         char buf[MH_LABEL_LENGTH_MAX];
441
442         if (parent == NULL || data == NULL) {
443                 ERR("null param \n");
444                 return NULL;
445         }
446
447         mh_appdata_t *ad = (mh_appdata_t *)data;
448         mh_wifi_setting_view_t *st = &ad->setup;
449
450         entry = elm_entry_add(parent);
451
452         if (entry == NULL) {
453                 ERR("elm_entry_add returns NULL\n");
454                 st->pw_entry = NULL;
455                 return NULL;
456         }
457
458         elm_entry_single_line_set(entry, EINA_TRUE);
459         elm_entry_scrollable_set(entry, EINA_TRUE);
460         elm_entry_password_set(entry, EINA_FALSE);
461
462         evas_object_smart_callback_add(entry, "language,changed",
463                         __pw_entry_language_changed_cb, ad);
464
465         eext_entry_selection_back_event_allow_set(entry, EINA_TRUE);
466         elm_entry_prediction_allow_set(entry, EINA_FALSE);
467         elm_object_signal_emit(entry, "elm,action,hide,search_icon", "");
468         elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_PASSWORD);
469         snprintf(buf, sizeof(buf), fmt, WIFI_PASSPHRASE_LENGTH_MIN);
470         elm_object_part_text_set(entry, "guide", buf);
471         elm_entry_cnp_mode_set(entry, ELM_CNP_MODE_PLAINTEXT);
472
473         limit_filter_data.max_char_count = 0;
474         limit_filter_data.max_byte_count = WIFI_PASSPHRASE_LENGTH_MAX;
475         elm_entry_markup_filter_append(entry, elm_entry_filter_limit_size, &limit_filter_data);
476
477         if (st->security_type_new == TETHERING_WIFI_SECURITY_TYPE_NONE) {
478                 elm_object_part_text_set(entry, "default", buf);
479                 elm_entry_input_panel_enabled_set(entry, EINA_FALSE);
480                 elm_object_disabled_set(entry, EINA_TRUE);
481                 if (st->pw_item)
482                         elm_object_item_signal_emit(st->pw_item, "elm,state,rename,hide", "");
483                 return entry;
484         } else {
485                 elm_object_disabled_set(entry, EINA_FALSE);
486                 elm_entry_input_panel_enabled_set(entry, EINA_TRUE);
487                 ptr = elm_entry_utf8_to_markup(st->wifi_passphrase_new);
488                 if (ptr != NULL) {
489                         elm_object_text_set(entry, ptr);
490                         free(ptr);
491                 } else {
492                         ERR("elm_entry_utf8_to_markup is failed\n");
493                 }
494         }
495
496         elm_entry_input_panel_return_key_type_set(entry,
497                         ELM_INPUT_PANEL_RETURN_KEY_TYPE_DONE);
498
499         clr_btn = elm_button_add(entry);
500         elm_object_style_set(clr_btn, "search_clear");
501         elm_object_focus_allow_set(clr_btn, EINA_FALSE);
502         elm_object_part_content_set(entry, "elm.swallow.clear", clr_btn);
503         evas_object_smart_callback_add(clr_btn, "clicked", __eraser_btn_clicked_cb, entry);
504         evas_object_show(clr_btn);
505
506         evas_object_smart_callback_add(entry, "changed",
507                         __pw_entry_changed_cb, ad);
508         evas_object_smart_callback_add(entry, "maxlength,reached",
509                         __pw_entry_maxlength_reached_cb, ad);
510         evas_object_smart_callback_add(entry, "activated",
511                         __pw_entry_activated_cb, NULL);
512         evas_object_smart_callback_add(entry, "focused",
513                         __pw_entry_focused_cb, NULL);
514         evas_object_smart_callback_add(entry, "unfocused",
515                         __pw_entry_unfocused_cb, NULL);
516         evas_object_event_callback_add(entry, EVAS_CALLBACK_SHOW,
517                         __pw_entry_show_cb, NULL);
518
519         elm_object_focus_set(entry, EINA_TRUE);
520         elm_entry_input_panel_show(entry);
521         elm_object_part_content_set(parent, "elm.swallow.content", entry);
522
523         st->pw_entry = entry;
524
525         __MOBILE_AP_FUNC_EXIT__;
526         return st->pw_entry;
527 }
528
529 static Evas_Object *__gl_pw_content_get(void *data, Evas_Object *obj, const char *part)
530 {
531         __MOBILE_AP_FUNC_ENTER__;
532
533         int w = 720;
534         int h = 60;
535
536         if (data == NULL) {
537                 ERR("data is null \n");
538                 return NULL;
539         }
540
541         if (!strcmp(part, "elm.swallow.content")) {
542                 Evas_Object *box = elm_box_add(obj);
543                 Evas_Object *label = elm_label_add(box);
544                 Evas_Object *layout = elm_layout_add(box);
545                 char buf[MH_LABEL_LENGTH_MAX] = {0, };
546
547                 elm_box_align_set(box, 0.0, 0.0);
548
549                 /* Set label for name field */
550                 snprintf(buf, MH_LABEL_LENGTH_MAX, "<text align=left><font_size=30>%s</font_size></text>", STR_PASSWORD);
551                 elm_object_text_set(label, buf);
552                 evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
553                 evas_object_size_hint_weight_set(label, 0.9, EVAS_HINT_EXPAND);
554                 evas_object_size_hint_padding_set(label, ELM_SCALE_SIZE(10), ELM_SCALE_SIZE(10), 0, 0);
555                 elm_box_pack_end(box, label);
556                 evas_object_show(label);
557
558                 /* Set layout for entry field */
559                 elm_layout_theme_set(layout, "layout", "editfield", "singleline");
560                 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
561                 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
562
563                 __get_pw_entry(data, layout);
564                 evas_object_show(layout);
565                 elm_box_pack_end(box, layout);
566
567                 evas_object_size_hint_min_set(box, ELM_SCALE_SIZE(w), ELM_SCALE_SIZE(h));
568                 evas_object_show(box);
569
570                 return box;
571         }
572
573         __MOBILE_AP_FUNC_EXIT__;
574         return NULL;
575 }
576
577 static void __gl_hide_item_sel(void *data, Evas_Object *obj, void *event_info)
578 {
579         __MOBILE_AP_FUNC_ENTER__;
580
581         if (data == NULL || obj == NULL || event_info == NULL) {
582                 ERR("param is NULL\n");
583                 return;
584         }
585
586         mh_appdata_t *ad = (mh_appdata_t *)data;
587
588         elm_genlist_item_selected_set((Elm_Object_Item*)event_info, EINA_FALSE);
589         __hide_btn_changed_cb(ad, obj, NULL);
590
591         elm_check_state_set(ad->setup.hide_btn, ad->setup.visibility_new ?
592                         EINA_FALSE : EINA_TRUE);
593
594         __MOBILE_AP_FUNC_EXIT__;
595 }
596
597 static void __gl_security_item_sel(void *data, Evas_Object *obj, void *event_info)
598 {
599         __MOBILE_AP_FUNC_ENTER__;
600
601         if (data == NULL || obj == NULL || event_info == NULL) {
602                 ERR("param is NULL\n");
603                 return;
604         }
605
606         mh_appdata_t *ad = (mh_appdata_t *)data;
607
608         elm_genlist_item_selected_set((Elm_Object_Item*)event_info, EINA_FALSE);
609         __security_btn_changed_cb(data, obj, NULL);
610         elm_check_state_set(ad->setup.security_btn, ad->setup.security_type_new ==
611                         TETHERING_WIFI_SECURITY_TYPE_NONE ? EINA_FALSE : EINA_TRUE);
612
613         __MOBILE_AP_FUNC_EXIT__;
614 }
615
616 static void __set_genlist_itc(mh_appdata_t *ad)
617 {
618         __MOBILE_AP_FUNC_ENTER__;
619
620         ad->setup.name_itc = elm_genlist_item_class_new();
621         if (ad->setup.name_itc == NULL) {
622                 ERR("elm_genlist_item_class_new failed\n");
623                 __MOBILE_AP_FUNC_EXIT__;
624                 return;
625         }
626         ad->setup.name_itc->item_style = MH_GENLIST_MULTILINE_TEXT_STYLE;
627         ad->setup.name_itc->func.text_get = __gl_device_name_title_label_get;
628         ad->setup.name_itc->func.content_get = NULL;
629         ad->setup.name_itc->func.state_get = NULL;
630         ad->setup.name_itc->func.del = NULL;
631
632         ad->setup.hide_itc = elm_genlist_item_class_new();
633         if (ad->setup.hide_itc == NULL) {
634                 ERR("elm_genlist_item_class_new failed\n");
635                 __MOBILE_AP_FUNC_EXIT__;
636                 return;
637         }
638         ad->setup.hide_itc->item_style = MH_GENLIST_1LINE_TEXT_ICON_STYLE;
639         ad->setup.hide_itc->func.text_get = __gl_hide_label_get;
640         ad->setup.hide_itc->func.content_get = __gl_hide_icon_get;
641         ad->setup.hide_itc->func.state_get = NULL;
642         ad->setup.hide_itc->func.del = NULL;
643
644         ad->setup.security_itc = elm_genlist_item_class_new();
645         if (ad->setup.security_itc == NULL) {
646                 ERR("elm_genlist_item_class_new failed\n");
647                 __MOBILE_AP_FUNC_EXIT__;
648                 return;
649         }
650         ad->setup.security_itc->item_style = MH_GENLIST_1LINE_TEXT_ICON_STYLE;
651         ad->setup.security_itc->func.text_get = __gl_security_label_get;
652         ad->setup.security_itc->func.content_get = __gl_security_icon_get;
653         ad->setup.security_itc->func.state_get = NULL;
654         ad->setup.security_itc->func.del = NULL;
655
656         ad->setup.pw_itc = elm_genlist_item_class_new();
657         if (ad->setup.pw_itc == NULL) {
658                 ERR("elm_genlist_item_class_new failed\n");
659                 __MOBILE_AP_FUNC_EXIT__;
660                 return;
661         }
662         ad->setup.pw_itc->item_style = MH_GENLIST_FULL_CONTENT_STYLE;
663         ad->setup.pw_itc->func.text_get = NULL;
664         ad->setup.pw_itc->func.content_get = __gl_pw_content_get;
665         ad->setup.pw_itc->func.state_get = NULL;
666         ad->setup.pw_itc->func.del = NULL;
667
668         __MOBILE_AP_FUNC_EXIT__;
669         return;
670 }
671
672 static void __deconstruct_wifi_setup_view(mh_wifi_setting_view_t *st)
673 {
674         __MOBILE_AP_FUNC_ENTER__;
675
676         if (st == NULL) {
677                 ERR("st is NULL\n");
678                 return;
679         }
680
681         evas_object_smart_callback_del(st->hide_btn, "changed",
682                         __hide_btn_changed_cb);
683         evas_object_smart_callback_del(st->security_btn, "changed",
684                         __security_btn_changed_cb);
685         evas_object_smart_callback_del(st->cancel_button, "clicked",
686                         __cancel_btn_cb);
687         evas_object_smart_callback_del(st->save_button, "clicked",
688                         __save_btn_cb);
689         evas_object_smart_callback_del(st->genlist, "realized",
690                         __gl_realized);
691
692         __MOBILE_AP_FUNC_EXIT__;
693 }
694
695 static void __settings_reloaded_cb(tethering_error_e result, void *user_data)
696 {
697         if (user_data == NULL) {
698                 ERR("Invalid parameter\n");
699                 return;
700         }
701
702         __MOBILE_AP_FUNC_ENTER__;
703
704         g_source_remove(tethering_param_timer);
705
706         mh_appdata_t *ad = (mh_appdata_t *)user_data;
707
708         if (result != TETHERING_ERROR_NONE)
709                 ERR("tethering_wifi_reload_settings is failed [0x%X]\n", result);
710         _update_wifi_item(ad, MH_STATE_NONE);
711
712         __MOBILE_AP_FUNC_EXIT__;
713
714         return;
715 }
716
717 static gboolean _update_tethering_param(gpointer data)
718 {
719         __MOBILE_AP_FUNC_ENTER__;
720         mh_appdata_t *ad = (mh_appdata_t *)data;
721         int ret;
722
723         if (ad == NULL) {
724                 ERR("Invalid parameter\n");
725                 return FALSE;
726         }
727
728         /* reload wifi settings */
729         ret = tethering_wifi_reload_settings(ad->handle, __settings_reloaded_cb,
730                         (void *)ad);
731         if (ret != TETHERING_ERROR_NONE)
732                 ERR("reload_configuration is failed : %d\n", ret);
733
734         __MOBILE_AP_FUNC_EXIT__;
735         return FALSE;
736 }
737
738 static void __save_btn_cb(void *data, Evas_Object *object, void *event_info)
739 {
740         DBG("+\n");
741         if (data == NULL) {
742                 ERR("data is NULL\n");
743                 return;
744         }
745
746         mh_appdata_t *ad = (mh_appdata_t *)data;
747         mh_wifi_setting_view_t *st = &ad->setup;
748         bool ret = false;
749         bool is_setting_changed = false;
750
751         /* handle hide button change */
752         if (st->visibility != st->visibility_new) {
753                 ret = __save_hide_btn_change(ad);
754                 if (ret == false) {
755                         elm_check_state_set(st->hide_btn, st->visibility ?
756                                         EINA_FALSE : EINA_TRUE);
757                 } else {
758                         st->visibility = st->visibility_new;
759                         is_setting_changed = true;
760                 }
761         }
762         /* handle security button change */
763         if (st->security_type != st->security_type_new) {
764                 ret = __save_security_btn_change(ad);
765                 if (ret == false) {
766                         elm_check_state_set(st->security_btn, st->security_type ==
767                                         TETHERING_WIFI_SECURITY_TYPE_NONE ? EINA_FALSE : EINA_TRUE);
768                 } else {
769                                 st->security_type = st->security_type_new;
770                                 is_setting_changed = true;
771                 }
772         }
773
774         /* handle wifi passphrase change */
775         if (strcmp(st->wifi_passphrase, st->wifi_passphrase_new)) {
776                 ret = __save_wifi_passphrase(ad);
777                 if (ret == false) {
778                         g_strlcpy(st->wifi_passphrase_new, st->wifi_passphrase,
779                                         sizeof(st->wifi_passphrase_new));
780                         if (st->pw_item)
781                                 elm_genlist_item_update(st->pw_item);
782                 } else {
783                         g_strlcpy(st->wifi_passphrase, st->wifi_passphrase_new,
784                                         sizeof(st->wifi_passphrase));
785                         is_setting_changed = true;
786                         if (ad->main.help_item) {
787                                 if (ad->main.help_item)
788                                         elm_genlist_item_update(ad->main.help_item);
789                         }
790                 }
791         }
792
793         if (is_setting_changed) {
794                 _update_wifi_item(ad, MH_STATE_PROCESS);
795
796                 if (ad->main.help_item)
797                         elm_genlist_item_update(ad->main.help_item);
798
799                 /* Here, The Dbus takes some amount of time
800                    to set the tethering parameters, due to
801                    which UI shows incorrect display, to avoid
802                    this issue, CAPI will be called after 0.1sec for smooth
803                    transition of UI frames */
804                 tethering_param_timer = g_timeout_add(100,
805                                                   _update_tethering_param, ad);
806         }
807
808         elm_naviframe_item_pop(ad->naviframe);
809
810         DBG("-\n");
811         return;
812 }
813
814 static void __cancel_btn_cb(void *data, Evas_Object *object, void *event_info)
815 {
816         DBG("+\n");
817
818         if (data == NULL) {
819                 ERR("The param is NULL\n");
820                 return;
821         }
822
823         mh_appdata_t *ad = (mh_appdata_t *)data;
824
825         elm_naviframe_item_pop(ad->naviframe);
826         DBG("-\n");
827         return;
828 }
829
830 Eina_Bool _setting_back_btn_cb(void *data, Elm_Object_Item *navi_item)
831 {
832         DBG("+\n");
833
834         if (data == NULL) {
835                 ERR("The param is NULL\n");
836                 return EINA_FALSE;
837         }
838
839         mh_appdata_t *ad = (mh_appdata_t *)data;
840         mh_wifi_setting_view_t *st = &ad->setup;
841
842         if (st->visibility != st->visibility_new)
843                 st->visibility_new = st->visibility;
844
845         if (st->security_type != st->security_type_new)
846                 st->security_type_new = st->security_type;
847
848         if (strcmp(st->wifi_passphrase_new, st->wifi_passphrase)) {
849                 g_strlcpy(st->wifi_passphrase_new, st->wifi_passphrase,
850                                         sizeof(st->wifi_passphrase_new));
851         }
852         st->pw_entry = NULL;
853         __deconstruct_wifi_setup_view(st);
854
855         if (ad->rename_popup != NULL) {
856                 evas_object_del(ad->rename_popup);
857                 ad->rename_popup = NULL;
858         }
859         ad->setup.navi_it = NULL;
860
861         DBG("-\n");
862         return EINA_TRUE;
863 }
864
865 static void __gl_realized(void *data, Evas_Object *obj, void *event_info)
866 {
867         __MOBILE_AP_FUNC_ENTER__;
868
869         mh_appdata_t *ad = (mh_appdata_t *)data;
870         mh_wifi_setting_view_t *st = &(ad->setup);
871         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
872         Evas_Object *ao;
873         Evas_Object *btn;
874         char str[MH_LABEL_LENGTH_MAX] = {0, };
875         int no_of_sp;
876         int i;
877
878         if (item == st->hide_item)
879                 elm_object_item_signal_emit(item, "elm,state,top", "");
880         else if (item == st->security_item)
881                 elm_object_item_signal_emit(item, "elm,state,center", "");
882         else if (item == st->pw_item)
883                 elm_object_item_signal_emit(item, "elm,state,bottom", "");
884
885         no_of_sp = sizeof(st->sp_item) / sizeof(st->sp_item[0]);
886         for (i = 0; i < no_of_sp; i++) {
887                 if (item == st->sp_item[i])
888                         elm_object_item_access_unregister(item);
889         }
890
891         if (item == st->hide_item || item == st->security_item) {
892                 ao = elm_object_item_access_object_get(item);
893                 btn = elm_object_item_part_content_get(item, "on&off");
894                 snprintf(str, sizeof(str), "%s, %s", "On/off button",
895                                 (elm_check_state_get(btn) ? "On" : "Off"));
896                 elm_access_info_set(ao, ELM_ACCESS_CONTEXT_INFO, str);
897         }
898
899         if (item == st->pw_item) {
900                 elm_object_item_access_unregister(item);
901                 ao = elm_object_item_access_register(item);
902                 snprintf(str, sizeof(str), "%s, %s", STR_PASSWORD, st->wifi_passphrase_new);
903                 elm_access_info_set(ao, ELM_ACCESS_CONTEXT_INFO, str);
904         }
905
906         __MOBILE_AP_FUNC_EXIT__;
907
908         return;
909 }
910
911 static void __select_passphrase_item(void *data, Evas_Object *obj, void *event_info)
912 {
913         __MOBILE_AP_FUNC_ENTER__;
914
915         if (data == NULL) {
916                 ERR("The param is NULL\n");
917                 return;
918         }
919
920         mh_appdata_t *ad = (mh_appdata_t *)data;
921         mh_wifi_setting_view_t *st = &ad->setup;
922
923         elm_object_focus_set(st->pw_entry, EINA_TRUE);
924
925         __MOBILE_AP_FUNC_EXIT__;
926         return;
927 }
928
929 Evas_Object *__create_genlist(mh_appdata_t *ad)
930 {
931         __MOBILE_AP_FUNC_ENTER__;
932
933         if (ad == NULL) {
934                 ERR("ad is NULL\n");
935                 return NULL;
936         }
937
938         void *data = (void *)ad;
939         mh_wifi_setting_view_t *st = &ad->setup;
940         Evas_Object *genlist;
941
942         genlist = elm_genlist_add(ad->naviframe);
943         if (genlist == NULL) {
944                 ERR("genlist is NULL\n");
945                 return NULL;
946         }
947
948         elm_object_style_set(genlist, "dialogue");
949         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
950         evas_object_smart_callback_add(genlist, "realized", __gl_realized, ad);
951
952         __set_genlist_itc(ad);
953
954         st->name_item = elm_genlist_item_append(genlist, st->name_itc, data, NULL,
955                         ELM_GENLIST_ITEM_NONE, NULL, NULL);
956         elm_genlist_item_select_mode_set(st->name_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
957
958         if (st->name_item)
959                 elm_object_item_disabled_set(st->name_item, EINA_TRUE);
960
961         st->hide_item = elm_genlist_item_append(genlist, st->hide_itc, data, NULL,
962                         ELM_GENLIST_ITEM_NONE, __gl_hide_item_sel, data);
963
964         st->security_item = elm_genlist_item_append(genlist, st->security_itc, data, NULL,
965                         ELM_GENLIST_ITEM_NONE, __gl_security_item_sel, data);
966
967         st->pw_item = elm_genlist_item_append(genlist, st->pw_itc, data, NULL,
968                         ELM_GENLIST_ITEM_NONE, __select_passphrase_item, ad);
969         if (st->security_type == TETHERING_WIFI_SECURITY_TYPE_NONE)
970                 elm_object_item_disabled_set(st->pw_item, EINA_TRUE);
971         else
972                 elm_object_item_disabled_set(st->pw_item, EINA_FALSE);
973
974 /* End separator is removed because of P131104-03336. It is confirmed by UX team for this case.
975         item = elm_genlist_item_append(genlist, st->sp_itc, NULL, NULL,
976                         ELM_GENLIST_ITEM_NONE, NULL, NULL);
977         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
978         st->sp_item[i++] = item;
979 */
980
981         __MOBILE_AP_FUNC_EXIT__;
982
983         return genlist;
984 }
985
986 void mh_draw_wifi_setup_view(mh_appdata_t *ad)
987 {
988         DBG("+\n");
989
990         if (ad == NULL) {
991                 ERR("ad is NULL\n");
992                 DBG("-\n");
993                 return;
994         }
995         Evas_Object *btn;
996         mh_wifi_setting_view_t *st = &ad->setup;
997
998         if (ad->setup.navi_it != NULL) {
999                 ERR("Wi-Fi setup view already exists\n");
1000                 DBG("-\n");
1001                 return;
1002         }
1003
1004         st->genlist = __create_genlist(ad);
1005         if (st->genlist == NULL) {
1006                 ERR("__create_genlist returns NULL\n");
1007                 DBG("-\n");
1008                 return;
1009         }
1010
1011         st->navi_it = elm_naviframe_item_push(ad->naviframe, "IDS_MOBILEAP_BODY_CONFIGURE_MOBILE_HOTSPOT_ABB_US_TMO",
1012                         NULL, NULL, st->genlist, NULL);
1013         elm_object_item_domain_text_translatable_set(st->navi_it, PKGNAME, EINA_TRUE);
1014
1015         elm_naviframe_item_pop_cb_set(st->navi_it, _setting_back_btn_cb, (void *)ad);
1016
1017         btn = elm_button_add(ad->naviframe);
1018         elm_object_style_set(btn, "naviframe/title_cancel");
1019         evas_object_smart_callback_add(btn, "clicked", __cancel_btn_cb, ad);
1020         elm_object_item_part_content_set(st->navi_it, "title_left_btn", btn);
1021         st->cancel_button = btn;
1022
1023         btn = elm_button_add(ad->naviframe);
1024         elm_object_style_set(btn, "naviframe/title_done");
1025         evas_object_smart_callback_add(btn, "clicked", __save_btn_cb, ad);
1026         elm_object_item_part_content_set(st->navi_it, "title_right_btn", btn);
1027         st->save_button = btn;
1028         DBG("-\n");
1029 }