New winset change is applied and some bugs are fixed
[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
20 #include "mh_view_wifi_setup.h"
21
22 static void __back_btn_cb(void *data, Evas_Object *obj, void *event_info);
23 static void __gl_realized(void *data, Evas_Object *obj, void *event_info);
24
25 static void __input_panel_event_cb(void *data, Ecore_IMF_Context *ctx, int value)
26 {
27         if (value == ECORE_IMF_INPUT_PANEL_STATE_SHOW) {
28                 DBG("value == ECORE_IMF_INPUT_PANEL_STATE_SHOW\n");
29                 elm_object_item_signal_emit(data, "elm,state,sip,shown", "");
30         } else if(value == ECORE_IMF_INPUT_PANEL_STATE_HIDE) {
31                 DBG("value == ECORE_IMF_INPUT_PANEL_STATE_HIDE\n");
32                 elm_object_item_signal_emit(data, "elm,state,sip,hidden", "");
33         }
34
35         return;
36 }
37
38 static void __hide_btn_changed_cb(void *data, Evas_Object *obj, void *event_info)
39 {
40         __MOBILE_AP_FUNC_ENTER__;
41
42         if (data == NULL || obj == NULL) {
43                 ERR("Invalid param\n");
44                 return;
45         }
46
47         mh_appdata_t *ad = (mh_appdata_t *)data;
48         int ret = 0;
49
50         ret = tethering_wifi_set_ssid_visibility(ad->handle,
51                         !ad->setup.visibility);
52         if (ret != TETHERING_ERROR_NONE) {
53                 ERR("tethering_wifi_set_ssid_visibility is failed : %d\n", ret);
54                 return;
55         }
56
57         ad->setup.visibility = !ad->setup.visibility;
58
59         __MOBILE_AP_FUNC_EXIT__;
60 }
61
62 static void __security_btn_changed_cb(void *data, Evas_Object *obj, void *event_info)
63 {
64         __MOBILE_AP_FUNC_ENTER__;
65
66         if (data == NULL || obj == NULL) {
67                 ERR("Invalid param\n");
68                 return;
69         }
70
71         mh_appdata_t *ad = (mh_appdata_t *)data;
72         int ret = 0;
73
74         if (ad->setup.security_type == TETHERING_WIFI_SECURITY_TYPE_NONE)
75                 ad->setup.security_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
76         else
77                 ad->setup.security_type = TETHERING_WIFI_SECURITY_TYPE_NONE;
78
79         ret = tethering_wifi_set_security_type(ad->handle, ad->setup.security_type);
80         if (ret != TETHERING_ERROR_NONE) {
81                 ERR("tethering_wifi_set_security_type is failed : %d\n", ret);
82                 return;
83         }
84
85         elm_genlist_item_update(ad->setup.pw_item);
86
87         __MOBILE_AP_FUNC_EXIT__;
88 }
89
90 static char *__gl_hide_label_get(void *data, Evas_Object *obj, const char *part)
91 {
92         __MOBILE_AP_FUNC_ENTER__;
93
94         if (data == NULL || obj == NULL || part == NULL) {
95                 ERR("Invalid param\n");
96                 return NULL;
97         }
98
99         if (strcmp(part, "elm.text") != 0) {
100                 ERR("Invalid param\n");
101                 return NULL;
102         }
103
104         __MOBILE_AP_FUNC_EXIT__;
105         return strdup(_("IDS_MOBILEAP_BODY_HIDE_MY_DEVICE"));
106 }
107
108 static char *__gl_security_label_get(void *data, Evas_Object *obj, const char *part)
109 {
110         __MOBILE_AP_FUNC_ENTER__;
111
112         if (data == NULL || obj == NULL || part == NULL) {
113                 ERR("Invalid param\n");
114                 return NULL;
115         }
116
117         if (strcmp(part, "elm.text") != 0) {
118                 ERR("Invalid param\n");
119                 return NULL;
120         }
121
122         __MOBILE_AP_FUNC_EXIT__;
123         return strdup(_("IDS_MOBILEAP_BODY_SECURITY"));
124 }
125
126 static char *__gl_name_label_get(void *data, Evas_Object *obj, const char *part)
127 {
128         __MOBILE_AP_FUNC_ENTER__;
129
130         if (data == NULL || obj == NULL || part == NULL) {
131                 ERR("Invalid param\n");
132                 return NULL;
133         }
134
135         if (strcmp(part, "elm.text") != 0) {
136                 ERR("Invalid param : %s\n", part);
137                 return NULL;
138         }
139
140         mh_appdata_t *ad = (mh_appdata_t *)data;
141         char label[MH_LABEL_LENGTH_MAX] = {0, };
142         char name_change_label[MH_LABEL_LENGTH_MAX] = {0, };
143         char path[MH_LABEL_LENGTH_MAX] = {0, };
144         char *device_name = NULL;
145
146         DBG("Device name : %s\n", ad->setup.device_name);
147
148         device_name = elm_entry_utf8_to_markup(ad->setup.device_name);
149         if (device_name == NULL) {
150                 ERR("elm_entry_utf8_to_markup is failed\n");
151                 return NULL;
152         }
153
154         snprintf(path, sizeof(path), "%s > %s",
155                         S_("IDS_COM_BODY_SETTINGS"),
156                         _("IDS_ST_BODY_ABOUT_PHONE"));
157         snprintf(name_change_label, sizeof(name_change_label),
158                         _("IDS_MOBILEAP_BODY_DEVICE_NAME_CAN_BE_CHANGED_IN_PS"),
159                         path);
160         snprintf(label, sizeof(label), "%s: %s<br>%s",
161                         _("IDS_MOBILEAP_BODY_DEVICE_NAME"),
162                         device_name,
163                         name_change_label);
164         free(device_name);
165
166         __MOBILE_AP_FUNC_EXIT__;
167
168         return strdup(label);
169 }
170
171 static Evas_Object *__gl_hide_icon_get(void *data, Evas_Object *obj,
172                 const char *part)
173 {
174         __MOBILE_AP_FUNC_ENTER__;
175
176         if (data == NULL || obj == NULL || part == NULL) {
177                 ERR("Invalid param\n");
178                 return NULL;
179         }
180
181         if (strcmp(part, "elm.icon") != 0) {
182                 ERR("Invalid param\n");
183                 return NULL;
184         }
185
186         mh_appdata_t *ad = (mh_appdata_t *)data;
187         Evas_Object *btn = NULL;
188
189         btn = elm_check_add(obj);
190         if (btn == NULL) {
191                 ERR("btn is NULL\n");
192                 return NULL;
193         }
194         elm_object_style_set(btn, "on&off");
195         evas_object_show(btn);
196         evas_object_pass_events_set(btn, EINA_TRUE);
197         evas_object_propagate_events_set(btn, EINA_FALSE);
198         elm_check_state_set(btn, ad->setup.visibility ? EINA_FALSE : EINA_TRUE);
199         evas_object_smart_callback_add(btn, "changed",
200                         __hide_btn_changed_cb, (void *)ad);
201
202         ad->setup.hide_btn = btn;
203
204         __MOBILE_AP_FUNC_EXIT__;
205         return btn;
206 }
207
208 static Evas_Object *__gl_security_icon_get(void *data, Evas_Object *obj,
209                 const char *part)
210 {
211         __MOBILE_AP_FUNC_ENTER__;
212
213         if (data == NULL || obj == NULL || part == NULL) {
214                 ERR("Invalid param\n");
215                 return NULL;
216         }
217
218         if (strcmp(part, "elm.icon") != 0) {
219                 ERR("Invalid param\n");
220                 return NULL;
221         }
222
223         mh_appdata_t *ad = (mh_appdata_t *)data;
224         Evas_Object *btn = NULL;
225
226         btn = elm_check_add(obj);
227
228         elm_object_style_set(btn, "on&off");
229         evas_object_show(btn);
230         evas_object_pass_events_set(btn, EINA_TRUE);
231         evas_object_propagate_events_set(btn, EINA_FALSE);
232         elm_check_state_set(btn, ad->setup.security_type ==
233                         TETHERING_WIFI_SECURITY_TYPE_NONE ?
234                         EINA_FALSE : EINA_TRUE);
235         evas_object_smart_callback_add(btn, "changed",
236                         __security_btn_changed_cb, (void *)ad);
237
238         ad->setup.security_btn = btn;
239
240         __MOBILE_AP_FUNC_EXIT__;
241         return btn;
242 }
243
244 static Eina_Bool __save_wifi_passphrase(mh_appdata_t *ad)
245 {
246         __MOBILE_AP_FUNC_ENTER__;
247
248         if (ad == NULL) {
249                 ERR("Invalid param\n");
250                 return EINA_FALSE;
251         }
252
253         mh_wifi_setting_view_t *st = &ad->setup;
254         int ret = 0;
255
256         if (g_strcmp0(st->wifi_passphrase, st->wifi_passphrase_new) == 0) {
257                 DBG("Password is not changed\n");
258                 return EINA_TRUE;
259         }
260
261         if (strlen(st->wifi_passphrase_new) < WIFI_PASSPHRASE_LENGTH_MIN) {
262                 DBG("Password is shorter than %d\n", WIFI_PASSPHRASE_LENGTH_MIN);
263                 _prepare_popup(ad, MH_POP_WIFI_PASSWORD_SHORT,
264                                 _("IDS_ST_BODY_ENTER_PASSWORD_OF_AT_LEAST_8_CHARACTERS"));
265                 _create_popup(ad);
266                 return EINA_FALSE;
267         }
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 EINA_FALSE;
273         }
274
275         DBG("SUCCESS : setting up VCONFKEY_MOBILE_HOTSPOT_WIFI_KEY\n");
276         g_strlcpy(st->wifi_passphrase, st->wifi_passphrase_new, sizeof(st->wifi_passphrase));
277
278         __MOBILE_AP_FUNC_EXIT__;
279
280         return EINA_TRUE;
281 }
282
283 static void __passphrase_maxlength_reached_cb(void *data, Evas_Object *obj,
284                 void *event_info)
285 {
286         __MOBILE_AP_FUNC_ENTER__;
287
288         if (data == NULL || obj == NULL) {
289                 ERR("The param is NULL\n");
290                 return;
291         }
292
293         mh_appdata_t *ad = (mh_appdata_t *)data;
294         char buf[MH_LABEL_LENGTH_MAX] = {0, };
295
296         if (ad->popup != NULL) {
297                 ERR("Popup already exists\n");
298                 return;
299         }
300
301         if (_hide_imf(ad->setup.pw_entry) == EINA_FALSE) {
302                 ERR("_hide_imf is failed\n");
303         }
304
305         if (__save_wifi_passphrase(ad) == EINA_FALSE) {
306                 ERR("__save_wifi_passphrase is failed\n");
307                 return;
308         }
309
310         snprintf(buf, sizeof(buf),
311                         _("IDS_MOBILEAP_POP_PASSWORD_MUST_CONTAIN_AT_LEAST_PD_CHARACTERS_AND_NOT_EXCEED_PD_CHARACTERS"),
312                         WIFI_PASSPHRASE_LENGTH_MIN, WIFI_PASSPHRASE_LENGTH_MAX);
313
314         _prepare_popup(ad, MH_POP_INFORMATION_WO_BUTTON, buf);
315         _create_popup(ad);
316
317         __MOBILE_AP_FUNC_EXIT__;
318 }
319
320 static void __passphrase_activated_cb(void *data, Evas_Object *obj,
321                 void *event_info)
322 {
323         __MOBILE_AP_FUNC_ENTER__;
324
325         if (data == NULL || obj == NULL) {
326                 ERR("Invalid param\n");
327                 return;
328         }
329
330         mh_appdata_t *ad = (mh_appdata_t *)data;
331
332         if (_hide_imf(ad->setup.pw_entry) == EINA_FALSE) {
333                 ERR("_hide_imf is failed\n");
334         }
335
336         if (__save_wifi_passphrase(ad) == EINA_FALSE) {
337                 ERR("__save_wifi_passphrase is failed\n");
338                 return;
339         }
340
341         __MOBILE_AP_FUNC_EXIT__;
342
343         return;
344 }
345
346 static void __pw_entry_changed_cb(void *data, Evas_Object *obj,
347                 void *event_info)
348 {
349         __MOBILE_AP_FUNC_ENTER__;
350
351         if (data == NULL || obj == NULL) {
352                 ERR("Invalid param\n");
353                 return;
354         }
355
356         mh_appdata_t *ad = (mh_appdata_t *)data;
357         mh_wifi_setting_view_t *st = &ad->setup;
358         const char *changed_text;
359         char *utf8_string;
360
361         changed_text = elm_entry_entry_get(st->pw_entry);
362         if (changed_text == NULL) {
363                 ERR("elm_entry_entry_get is failed\n");
364                 return;
365         }
366
367         utf8_string = elm_entry_markup_to_utf8(changed_text);
368         if (utf8_string == NULL) {
369                 ERR("elm_entry_markup_to_utf8() Failed!!!\n");
370         } else {
371                 g_strlcpy(st->wifi_passphrase_new, utf8_string,
372                                 sizeof(st->wifi_passphrase_new));
373                 free(utf8_string);
374         }
375
376         if (!elm_object_focus_get(st->pw_layout))
377                 return;
378
379         if (elm_entry_is_empty(st->pw_entry)) {
380                 elm_object_signal_emit(st->pw_layout,
381                                 "elm,state,eraser,hide", "elm");
382         } else {
383                 elm_object_signal_emit(st->pw_layout,
384                                 "elm,state,eraser,show", "elm");
385         }
386
387         __MOBILE_AP_FUNC_EXIT__;
388
389         return;
390
391 }
392
393 static void __pw_entry_focused_cb(void *data, Evas_Object *obj,
394                 void *event_info)
395 {
396         __MOBILE_AP_FUNC_ENTER__;
397
398         if (data == NULL || obj == NULL) {
399                 ERR("Invalid param\n");
400                 return;
401         }
402
403         mh_appdata_t *ad = (mh_appdata_t *)data;
404         mh_wifi_setting_view_t *st = &ad->setup;
405
406         if (!elm_entry_is_empty(st->pw_entry))
407                 elm_object_signal_emit(st->pw_layout,
408                                 "elm,state,eraser,show", "elm");
409
410         elm_object_signal_emit(st->pw_layout,
411                         "elm,state,guidetext,hide", "elm");
412
413         __MOBILE_AP_FUNC_EXIT__;
414
415         return;
416
417 }
418
419 static void __pw_entry_unfocused_cb(void *data, Evas_Object *obj,
420                 void *event_info)
421 {
422         __MOBILE_AP_FUNC_ENTER__;
423
424         if (data == NULL || obj == NULL) {
425                 ERR("Invalid param\n");
426                 return;
427         }
428
429         mh_appdata_t *ad = (mh_appdata_t *)data;
430         mh_wifi_setting_view_t *st = &ad->setup;
431
432         if (elm_entry_is_empty(st->pw_entry))
433                 elm_object_signal_emit(st->pw_layout,
434                                 "elm,state,guidetext,show", "elm");
435
436         elm_object_signal_emit(st->pw_layout,
437                         "elm,state,eraser,hide", "elm");
438
439         __MOBILE_AP_FUNC_EXIT__;
440
441         return;
442
443 }
444
445 static void __pw_layout_eraser_clicked_cb(void *data, Evas_Object *obj,
446                 const char *emission, const char *source)
447 {
448         __MOBILE_AP_FUNC_ENTER__;
449
450         if (data == NULL || obj == NULL) {
451                 ERR("Invalid param\n");
452                 return;
453         }
454
455         mh_appdata_t *ad = (mh_appdata_t *)data;
456         mh_wifi_setting_view_t *st = &ad->setup;
457
458         elm_entry_entry_set(st->pw_entry, "");
459
460         __MOBILE_AP_FUNC_EXIT__;
461
462         return;
463
464 }
465
466 static Evas_Object *__gl_pw_icon_get(void *data, Evas_Object *obj,
467                 const char *part)
468 {
469         __MOBILE_AP_FUNC_ENTER__;
470
471         if (data == NULL || obj == NULL || part == NULL) {
472                 ERR("Invalid param\n");
473                 return NULL;
474         }
475
476         if (strcmp(part, "elm.icon") != 0) {
477                 ERR("Invalid part : %s\n", part);
478                 return NULL;
479         }
480
481         static Elm_Entry_Filter_Limit_Size limit_filter_data;
482
483         mh_appdata_t *ad = (mh_appdata_t *)data;
484         mh_wifi_setting_view_t *st = &ad->setup;
485         Evas_Object *entry = NULL;
486         char *ptr = NULL;
487         Ecore_IMF_Context *imf_context;
488
489         st->pw_layout = elm_layout_add(obj);
490         if (st->pw_layout == NULL) {
491                 ERR("elm_layout_add returns NULL\n");
492                 return NULL;
493         }
494         elm_layout_theme_set(st->pw_layout, "layout", "editfield", "title");
495         evas_object_size_hint_weight_set(st->pw_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
496
497         entry = elm_entry_add(st->pw_layout);
498         if (entry == NULL) {
499                 ERR("elm_entry_add returns NULL\n");
500                 evas_object_del(st->pw_layout);
501                 st->pw_layout = NULL;
502                 return NULL;
503         }
504         st->pw_entry = entry;
505
506         /* Set single line of entry */
507         elm_entry_scrollable_set(entry, EINA_TRUE);
508         elm_entry_single_line_set(entry, EINA_TRUE);
509         elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_PASSWORD);
510
511         /* Set the maximum length filter for passphrase entry */
512         limit_filter_data.max_char_count = 0;
513         limit_filter_data.max_byte_count = WIFI_PASSPHRASE_LENGTH_MAX;
514         elm_entry_markup_filter_append(entry,
515                         elm_entry_filter_limit_size, &limit_filter_data);
516
517         DBG("security_type : %d\n", st->security_type);
518         if (st->security_type == TETHERING_WIFI_SECURITY_TYPE_NONE) {
519                 ptr = elm_entry_utf8_to_markup(st->wifi_passphrase);
520                 if (ptr != NULL) {
521                         elm_entry_entry_set(entry, ptr);
522                         elm_entry_cursor_end_set(entry);
523                         free(ptr);
524                 } else {
525                         ERR("elm_entry_utf8_to_markup is failed\n");
526                 }
527
528                 /* Set editable mode */
529                 elm_entry_input_panel_enabled_set(entry, EINA_FALSE);
530                 elm_entry_context_menu_disabled_set(entry, EINA_TRUE);
531                 elm_object_item_disabled_set(st->pw_item, EINA_TRUE);
532         } else {
533                 ptr = elm_entry_utf8_to_markup(st->wifi_passphrase_new);
534                 if (ptr != NULL) {
535                         elm_entry_entry_set(entry, ptr);
536                         elm_entry_cursor_end_set(entry);
537                         free(ptr);
538                 } else {
539                         ERR("elm_entry_utf8_to_markup is failed\n");
540                 }
541                 elm_object_item_disabled_set(st->pw_item, EINA_FALSE);
542         }
543
544         evas_object_smart_callback_add(entry, "maxlength,reached",
545                         __passphrase_maxlength_reached_cb, data);
546         evas_object_smart_callback_add(entry, "activated",
547                         __passphrase_activated_cb, data);
548         evas_object_smart_callback_add(entry, "changed",
549                         __pw_entry_changed_cb, data);
550         evas_object_smart_callback_add(entry, "focused",
551                         __pw_entry_focused_cb, data);
552         evas_object_smart_callback_add(entry, "unfocused",
553                         __pw_entry_unfocused_cb, data);
554
555         imf_context = (Ecore_IMF_Context *)elm_entry_imf_context_get(entry);
556         if (imf_context)
557                 ecore_imf_context_input_panel_event_callback_add(imf_context,
558                                 ECORE_IMF_INPUT_PANEL_STATE_EVENT,
559                                 __input_panel_event_cb, (void *)st->navi_it);
560
561         evas_object_show(entry);
562
563         elm_object_part_content_set(st->pw_layout, "elm.swallow.content", entry);
564         elm_object_part_text_set(st->pw_layout, "elm.text",
565                         _("IDS_MOBILEAP_BODY_PASSWORD"));
566         elm_object_part_text_set(st->pw_layout, "elm.guidetext",
567                         _("IDS_ST_BODY_ENTER_PASSWORD_OF_AT_LEAST_8_CHARACTERS"));
568
569         if (!elm_entry_is_empty(entry))
570                 elm_object_signal_emit(st->pw_layout,
571                                 "elm,state,guidetext,hide", "elm");
572
573         elm_object_signal_callback_add(st->pw_layout, "elm,eraser,clicked", "elm",
574                         __pw_layout_eraser_clicked_cb, data);
575
576
577
578         __MOBILE_AP_FUNC_EXIT__;
579
580         return st->pw_layout;
581 }
582
583 static void __gl_hide_item_sel(void *data, Evas_Object *obj, void *event_info)
584 {
585         __MOBILE_AP_FUNC_ENTER__;
586
587         if (data == NULL || obj == NULL || event_info == NULL) {
588                 ERR("param is NULL\n");
589                 return;
590         }
591
592         mh_appdata_t *ad = (mh_appdata_t *)data;
593
594         elm_genlist_item_selected_set((Elm_Object_Item*)event_info, EINA_FALSE);
595
596         __hide_btn_changed_cb(data, obj, NULL);
597         elm_check_state_set(ad->setup.hide_btn, ad->setup.visibility ?
598                         EINA_FALSE : EINA_TRUE);
599
600         __MOBILE_AP_FUNC_EXIT__;
601 }
602
603 static void __gl_security_item_sel(void *data, Evas_Object *obj, void *event_info)
604 {
605         __MOBILE_AP_FUNC_ENTER__;
606
607         if (data == NULL || obj == NULL || event_info == NULL) {
608                 ERR("param is NULL\n");
609                 return;
610         }
611
612         mh_appdata_t *ad = (mh_appdata_t *)data;
613
614         elm_genlist_item_selected_set((Elm_Object_Item*)event_info, EINA_FALSE);
615
616         __security_btn_changed_cb(data, obj, NULL);
617         elm_check_state_set(ad->setup.security_btn, ad->setup.security_type ==
618                         TETHERING_WIFI_SECURITY_TYPE_NONE ? EINA_FALSE : EINA_TRUE);
619
620         __MOBILE_AP_FUNC_EXIT__;
621 }
622
623 static void __free_genlist_itc(mh_appdata_t *ad)
624 {
625         __MOBILE_AP_FUNC_ENTER__;
626
627         elm_genlist_item_class_free(ad->setup.sp_itc);
628         elm_genlist_item_class_free(ad->setup.hide_itc);
629         elm_genlist_item_class_free(ad->setup.security_itc);
630         elm_genlist_item_class_free(ad->setup.pw_itc);
631         elm_genlist_item_class_free(ad->setup.name_itc);
632
633         __MOBILE_AP_FUNC_EXIT__;
634         return;
635 }
636
637 static void __set_genlist_itc(mh_appdata_t *ad)
638 {
639         __MOBILE_AP_FUNC_ENTER__;
640
641         ad->setup.sp_itc = elm_genlist_item_class_new();
642         ad->setup.sp_itc->item_style = "dialogue/separator";
643         ad->setup.sp_itc->func.text_get = NULL;
644         ad->setup.sp_itc->func.content_get = NULL;
645         ad->setup.sp_itc->func.state_get = NULL;
646         ad->setup.sp_itc->func.del = NULL;
647
648         ad->setup.hide_itc = elm_genlist_item_class_new();
649         ad->setup.hide_itc->item_style = "dialogue/1text.1icon";
650         ad->setup.hide_itc->func.text_get = __gl_hide_label_get;
651         ad->setup.hide_itc->func.content_get = __gl_hide_icon_get;
652         ad->setup.hide_itc->func.state_get = NULL;
653         ad->setup.hide_itc->func.del = NULL;
654
655         ad->setup.security_itc = elm_genlist_item_class_new();
656         ad->setup.security_itc->item_style = "dialogue/1text.1icon";
657         ad->setup.security_itc->func.text_get = __gl_security_label_get;
658         ad->setup.security_itc->func.content_get = __gl_security_icon_get;
659         ad->setup.security_itc->func.state_get = NULL;
660         ad->setup.security_itc->func.del = NULL;
661
662         ad->setup.pw_itc = elm_genlist_item_class_new();
663         ad->setup.pw_itc->item_style = "dialogue/1icon";
664         ad->setup.pw_itc->func.text_get = NULL;
665         ad->setup.pw_itc->func.content_get = __gl_pw_icon_get;
666         ad->setup.pw_itc->func.state_get = NULL;
667         ad->setup.pw_itc->func.del = NULL;
668
669         ad->setup.name_itc = elm_genlist_item_class_new();
670         ad->setup.name_itc->item_style = "multiline/1text";
671         ad->setup.name_itc->func.text_get = __gl_name_label_get;
672         ad->setup.name_itc->func.content_get = NULL;
673         ad->setup.name_itc->func.state_get = NULL;
674         ad->setup.name_itc->func.del = NULL;
675
676         ad->setup.end_sp_itc = elm_genlist_item_class_new();
677         ad->setup.end_sp_itc->item_style = "dialogue/separator";
678         ad->setup.end_sp_itc->func.text_get = NULL;
679         ad->setup.end_sp_itc->func.content_get = NULL;
680         ad->setup.end_sp_itc->func.state_get = NULL;
681         ad->setup.end_sp_itc->func.del = NULL;
682
683         __MOBILE_AP_FUNC_EXIT__;
684         return;
685 }
686
687 static void __deconstruct_wifi_setup_view(mh_wifi_setting_view_t *st)
688 {
689         __MOBILE_AP_FUNC_ENTER__;
690
691         if (st == NULL) {
692                 ERR("st is NULL\n");
693                 return;
694         }
695
696         if (st->pw_entry == NULL) {
697                 ERR("pw_entry is NULL");
698                 return;
699         }
700
701         evas_object_smart_callback_del(st->hide_btn, "changed",
702                         __hide_btn_changed_cb);
703         evas_object_smart_callback_del(st->security_btn, "changed",
704                         __security_btn_changed_cb);
705         if (st->pw_entry) {
706                 evas_object_smart_callback_del(st->pw_entry,
707                                 "maxlength,reached",
708                                 __passphrase_maxlength_reached_cb);
709                 evas_object_smart_callback_del(st->pw_entry,
710                                 "activated",
711                                 __passphrase_activated_cb);
712         }
713         evas_object_smart_callback_del(st->back_btn, "clicked",
714                         __back_btn_cb);
715         evas_object_smart_callback_del(st->genlist, "realized",
716                         __gl_realized);
717
718         st->hide_btn = NULL;
719         st->security_btn = NULL;
720         st->pw_layout = NULL;
721         st->pw_entry = NULL;
722         st->back_btn = NULL;
723         st->genlist = NULL;
724
725         __MOBILE_AP_FUNC_EXIT__;
726 }
727
728 static void __back_btn_cb(void *data, Evas_Object *obj, void *event_info)
729 {
730         __MOBILE_AP_FUNC_ENTER__;
731
732         if (data == NULL) {
733                 ERR("The param is NULL\n");
734                 return;
735         }
736
737         mh_appdata_t *ad = (mh_appdata_t *)data;
738         mh_wifi_setting_view_t *st = &ad->setup;
739         int ret;
740
741         if (_hide_imf(st->pw_entry) == EINA_FALSE) {
742                 ERR("_hide_imf is failed\n");
743         }
744
745         if (__save_wifi_passphrase(ad) == EINA_FALSE) {
746                 ERR("__save_wifi_passphrase is failed\n");
747                 return;
748         }
749
750         if (tethering_is_enabled(ad->handle, TETHERING_TYPE_WIFI) == false &&
751                         ad->main.old_wifi_state == true) {
752                 _update_wifi_item(ad, MH_STATE_PROCESS);
753                 ret = tethering_enable(ad->handle, TETHERING_TYPE_WIFI);
754                 if (ret != TETHERING_ERROR_NONE) {
755                         ERR("wifi tethering on is failed : %d\n", ret);
756                         _update_wifi_item(ad, MH_STATE_NONE);
757                 }
758         }
759         ad->main.old_wifi_state = false;
760
761         __deconstruct_wifi_setup_view(st);
762
763         evas_object_del(ad->setup.genlist);
764         __free_genlist_itc(ad);
765
766         elm_naviframe_item_pop(ad->naviframe);
767
768         __MOBILE_AP_FUNC_EXIT__;
769 }
770
771 static void __title_back_btn_cb(void *data, Evas_Object *obj, void *event_info)
772 {
773         __MOBILE_AP_FUNC_ENTER__;
774
775         if (data == NULL || obj == NULL) {
776                 ERR("Invalid param\n");
777                 return;
778         }
779
780         mh_appdata_t *ad = (mh_appdata_t *)data;
781
782         if (_hide_imf(ad->setup.pw_entry) == EINA_FALSE) {
783                 ERR("_hide_imf is failed\n");
784         }
785
786         if (__save_wifi_passphrase(ad) == EINA_FALSE) {
787                 ERR("__save_wifi_passphrase is failed\n");
788                 return;
789         }
790
791         __MOBILE_AP_FUNC_EXIT__;
792
793         return;
794 }
795
796 static void __gl_realized(void *data, Evas_Object *obj, void *event_info)
797 {
798         mh_appdata_t *ad = (mh_appdata_t *)data;
799         mh_wifi_setting_view_t *st = &(ad->setup);
800         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
801
802         if (item == st->hide_item)
803                 elm_object_item_signal_emit(item, "elm,state,top", "");
804         else if (item == st->security_item)
805                 elm_object_item_signal_emit(item, "elm,state,center", "");
806         else if (item == st->pw_item)
807                 elm_object_item_signal_emit(item, "elm,state,bottom", "");
808
809         return;
810 }
811
812 Evas_Object *__create_genlist(mh_appdata_t *ad)
813 {
814         __MOBILE_AP_FUNC_ENTER__;
815
816         if (ad == NULL) {
817                 ERR("ad is NULL\n");
818                 return NULL;
819         }
820
821         void *data = (void *)ad;
822         mh_wifi_setting_view_t *st = &ad->setup;
823         Evas_Object *genlist = NULL;
824         Elm_Object_Item *item = NULL;
825
826         genlist = elm_genlist_add(ad->naviframe);
827         if (genlist == NULL) {
828                 ERR("genlist is NULL\n");
829                 return NULL;
830         }
831         elm_object_style_set(genlist, "dialogue");
832         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
833         evas_object_smart_callback_add(genlist, "realized", __gl_realized, ad);
834
835         __set_genlist_itc(ad);
836         item = elm_genlist_item_append(genlist, st->sp_itc, NULL, NULL,
837                         ELM_GENLIST_ITEM_NONE, NULL, NULL);
838         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
839
840         st->hide_item = elm_genlist_item_append(genlist, st->hide_itc, data, NULL,
841                         ELM_GENLIST_ITEM_NONE, __gl_hide_item_sel, data);
842
843         st->security_item = elm_genlist_item_append(genlist, st->security_itc, data, NULL,
844                         ELM_GENLIST_ITEM_NONE, __gl_security_item_sel, data);
845
846         DBG("security_type : %d\n", st->security_type);
847         st->pw_item = elm_genlist_item_append(genlist, st->pw_itc, data, NULL,
848                         ELM_GENLIST_ITEM_NONE, NULL, NULL);
849         elm_genlist_item_select_mode_set(st->pw_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
850
851         st->name_item = elm_genlist_item_append(genlist, st->name_itc, data, NULL,
852                         ELM_GENLIST_ITEM_NONE, NULL, NULL);
853         elm_genlist_item_select_mode_set(st->name_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
854
855         item = elm_genlist_item_append(genlist, st->end_sp_itc, NULL, NULL,
856                         ELM_GENLIST_ITEM_NONE, NULL, NULL);
857         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
858
859
860         __MOBILE_AP_FUNC_EXIT__;
861
862         return genlist;
863 }
864
865 void mh_draw_wifi_setup_view(mh_appdata_t *ad)
866 {
867         __MOBILE_AP_FUNC_ENTER__;
868
869         if (ad == NULL) {
870                 ERR("ad is NULL\n");
871                 return;
872         }
873
874         mh_wifi_setting_view_t *st = &ad->setup;
875
876         if (st->genlist != NULL) {
877                 ERR("Wi-Fi setup view already exists\n");
878                 return;
879         }
880
881         st->genlist = __create_genlist(ad);
882         if (st->genlist == NULL) {
883                 ERR("__create_genlist returns NULL\n");
884                 goto FAIL;
885         }
886
887         st->back_btn = elm_button_add(ad->naviframe);
888         if (st->back_btn == NULL) {
889                 ERR("elm_button_add returns NULL\n");
890                 goto FAIL;
891         }
892         elm_object_style_set(st->back_btn, "naviframe/back_btn/default");
893         evas_object_smart_callback_add(st->back_btn, "clicked",
894                         __back_btn_cb, ad);
895
896         st->navi_it = elm_naviframe_item_push(ad->naviframe,
897                         _("IDS_MOBILEAP_MBODY_WI_FI_TETHERING_SETTINGS"),
898                         st->back_btn, NULL, st->genlist, NULL);
899
900         st->title_back_btn = elm_button_add(ad->naviframe);
901         elm_object_style_set(st->title_back_btn, "naviframe/back_btn/default");
902         evas_object_smart_callback_add(st->title_back_btn, "clicked", __title_back_btn_cb, ad);
903         elm_object_item_part_content_set(st->navi_it, "title_prev_btn", st->title_back_btn);
904
905         __MOBILE_AP_FUNC_EXIT__;
906
907         return;
908
909 FAIL:
910         if (st->back_btn)
911                 evas_object_del(st->back_btn);
912         if (st->genlist)
913                 evas_object_del(st->genlist);
914
915         st->back_btn = NULL;
916         st->genlist = NULL;
917 }