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