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