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