[Bug fix] Modified Wi-Fi tethering pw entry
[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         __MOBILE_AP_FUNC_ENTER__;
376         evas_object_event_callback_del(obj, EVAS_CALLBACK_SHOW, __pw_entry_focused_cb);
377
378          elm_object_focus_set(obj, EINA_TRUE);
379          elm_entry_cursor_end_set(obj);
380          __MOBILE_AP_FUNC_EXIT__;
381 }
382
383 static void __pw_entry_unfocused_cb(void *data, Evas_Object *obj, void *event_info)
384 {
385         __MOBILE_AP_FUNC_ENTER__;
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         __MOBILE_AP_FUNC_EXIT__;
390 }
391
392 static void __pw_entry_show_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
393 {
394         __MOBILE_AP_FUNC_ENTER__;
395          evas_object_event_callback_del(obj, EVAS_CALLBACK_SHOW, __pw_entry_show_cb);
396
397          elm_object_focus_set(obj, EINA_TRUE);
398          elm_entry_cursor_end_set(obj);
399          __MOBILE_AP_FUNC_EXIT__;
400 }
401
402 static void __eraser_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
403 {
404         __MOBILE_AP_FUNC_ENTER__;
405
406         elm_object_text_set(data, "");
407         elm_entry_input_panel_return_key_disabled_set(data, TRUE);
408
409         __MOBILE_AP_FUNC_EXIT__;
410 }
411
412 static void __pw_entry_language_changed_cb(void *data, Evas_Object *obj, void *event_info)
413 {
414         __MOBILE_AP_FUNC_ENTER__;
415
416         if (obj == NULL || data == NULL) {
417                 ERR("NULL param\n");
418                 return;
419         }
420         mh_appdata_t *ad = (mh_appdata_t *)data;
421         mh_wifi_setting_view_t *st = &ad->setup;
422         char buf[MH_LABEL_LENGTH_MAX];
423         char *fmt = STR_PW_GUIDE_TEXT;
424
425         snprintf(buf, sizeof(buf), fmt, WIFI_PASSPHRASE_LENGTH_MIN);
426
427         if (st->security_type_new == TETHERING_WIFI_SECURITY_TYPE_NONE) {
428                 if (st->pw_item)
429                         elm_genlist_item_update(st->pw_item);
430         } else {
431                 elm_object_part_text_set(obj, "elm.guide", buf);
432         }
433         __MOBILE_AP_FUNC_EXIT__;
434 }
435
436 static Evas_Object *__get_pw_entry(void *data, Evas_Object *parent)
437 {
438         __MOBILE_AP_FUNC_ENTER__;
439
440         static Elm_Entry_Filter_Limit_Size limit_filter_data;
441         Evas_Object *entry = NULL;
442         char *fmt = STR_PW_GUIDE_TEXT;
443         char *ptr = NULL;
444         Evas_Object * clr_btn = NULL;
445         char buf[MH_LABEL_LENGTH_MAX];
446
447         if (parent == NULL || data == NULL) {
448                 ERR("null param \n");
449                 return NULL;
450         }
451
452         mh_appdata_t *ad = (mh_appdata_t *)data;
453         mh_wifi_setting_view_t *st = &ad->setup;
454
455         entry = elm_entry_add(parent);
456
457         if (entry == NULL) {
458                 ERR("elm_entry_add returns NULL\n");
459                 st->pw_entry = NULL;
460                 return NULL;
461         }
462
463         elm_entry_single_line_set(entry, EINA_TRUE);
464         elm_entry_scrollable_set(entry, EINA_TRUE);
465         elm_entry_password_set(entry, EINA_FALSE);
466
467         evas_object_smart_callback_add(entry, "language,changed",
468                         __pw_entry_language_changed_cb, ad);
469
470         eext_entry_selection_back_event_allow_set(entry, EINA_TRUE);
471         elm_entry_prediction_allow_set(entry, EINA_FALSE);
472         elm_object_signal_emit(entry, "elm,action,hide,search_icon", "");
473         elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_PASSWORD);
474         snprintf(buf, sizeof(buf), fmt, WIFI_PASSPHRASE_LENGTH_MIN);
475         elm_object_part_text_set(entry, "guide", buf);
476         elm_entry_cnp_mode_set(entry, ELM_CNP_MODE_PLAINTEXT);
477
478         limit_filter_data.max_char_count = 0;
479         limit_filter_data.max_byte_count = WIFI_PASSPHRASE_LENGTH_MAX;
480         elm_entry_markup_filter_append(entry, elm_entry_filter_limit_size, &limit_filter_data);
481
482         if (st->security_type_new == TETHERING_WIFI_SECURITY_TYPE_NONE) {
483                 elm_object_part_text_set(entry, "default", buf);
484                 elm_entry_input_panel_enabled_set(entry, EINA_FALSE);
485                 elm_object_disabled_set(entry, EINA_TRUE);
486                 if (st->pw_item)
487                         elm_object_item_signal_emit(st->pw_item, "elm,state,rename,hide", "");
488                 return entry;
489         } else {
490                 elm_object_disabled_set(entry, EINA_FALSE);
491                 elm_entry_input_panel_enabled_set(entry, EINA_TRUE);
492                 ptr = elm_entry_utf8_to_markup(st->wifi_passphrase_new);
493                 if (ptr != NULL) {
494                         elm_object_text_set(entry, ptr);
495                         free(ptr);
496                 } else {
497                         ERR("elm_entry_utf8_to_markup is failed\n");
498                 }
499         }
500
501         elm_entry_input_panel_return_key_type_set(entry,
502                         ELM_INPUT_PANEL_RETURN_KEY_TYPE_DONE);
503
504         clr_btn = elm_button_add(entry);
505         elm_object_style_set(clr_btn, "search_clear");
506         elm_object_focus_allow_set(clr_btn, EINA_FALSE);
507         elm_object_part_content_set(entry, "elm.swallow.clear", clr_btn);
508         evas_object_smart_callback_add(clr_btn, "clicked", __eraser_btn_clicked_cb, entry);
509         evas_object_show(clr_btn);
510
511         evas_object_smart_callback_add(entry, "changed",
512                         __pw_entry_changed_cb, ad);
513         evas_object_smart_callback_add(entry, "maxlength,reached",
514                         __pw_entry_maxlength_reached_cb, ad);
515         evas_object_smart_callback_add(entry, "activated",
516                         __pw_entry_activated_cb, NULL);
517         evas_object_smart_callback_add(entry, "focused",
518                         __pw_entry_focused_cb, NULL);
519         evas_object_smart_callback_add(entry, "unfocused",
520                         __pw_entry_unfocused_cb, NULL);
521         evas_object_event_callback_add(entry, EVAS_CALLBACK_SHOW,
522                         __pw_entry_show_cb, NULL);
523
524         elm_object_focus_set(entry, EINA_TRUE);
525         elm_entry_input_panel_show(entry);
526         elm_object_part_content_set(parent, "elm.swallow.content", entry);
527
528         st->pw_entry = entry;
529
530         __MOBILE_AP_FUNC_EXIT__;
531         return st->pw_entry;
532 }
533
534 static char *__gl_pw_text_get(void *data, Evas_Object *obj, const char *part)
535 {
536         __MOBILE_AP_FUNC_ENTER__;
537         char buf[MH_LABEL_LENGTH_MAX] = {0, };
538
539         if (data == NULL || obj == NULL || part == NULL) {
540                 ERR("Invalid param\n");
541                 return NULL;
542         }
543
544         if (!strcmp("elm.text.main", part)) {
545                 snprintf(buf, MH_LABEL_LENGTH_MAX, "<font_size=30>%s</font_size>", STR_PASSWORD);
546                 return strdup(buf);
547         }
548
549         __MOBILE_AP_FUNC_EXIT__;
550         return NULL;
551 }
552
553 static Evas_Object *__gl_pw_content_get(void *data, Evas_Object *obj, const char *part)
554 {
555         __MOBILE_AP_FUNC_ENTER__;
556
557         int w = 720;
558         int h = 60;
559
560         if (data == NULL) {
561                 ERR("data is null \n");
562                 return NULL;
563         }
564
565         if (!strcmp(part, "elm.swallow.content")) {
566                 Evas_Object *box = elm_box_add(obj);
567                 Evas_Object *label = elm_label_add(box);
568                 Evas_Object *layout = elm_layout_add(box);
569                 char buf[MH_LABEL_LENGTH_MAX] = {0, };
570
571                 elm_box_align_set(box, 0.5, 0.5);
572
573                 /* Set label for name field */
574                 snprintf(buf, MH_LABEL_LENGTH_MAX, "<text align=left><font_size=30>%s</font_size></text>", STR_PASSWORD);
575                 elm_object_text_set(label, buf);
576                 evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
577                 evas_object_size_hint_weight_set(label, 0.9, EVAS_HINT_EXPAND);
578                 evas_object_size_hint_padding_set(label, ELM_SCALE_SIZE(10), ELM_SCALE_SIZE(10), ELM_SCALE_SIZE(10), ELM_SCALE_SIZE(10));
579                 elm_box_pack_end(box, label);
580                 evas_object_show(label);
581
582                 /* Set layout for entry field */
583                 elm_layout_theme_set(layout, "layout", "editfield", "singleline");
584                 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
585                 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
586
587                 __get_pw_entry(data, layout);
588                 evas_object_show(layout);
589                 elm_box_pack_end(box, layout);
590
591                 evas_object_size_hint_min_set(box, ELM_SCALE_SIZE(w), ELM_SCALE_SIZE(h));
592                 evas_object_show(box);
593
594         return box;
595         }
596
597         __MOBILE_AP_FUNC_EXIT__;
598         return NULL;
599 }
600
601 static void __gl_hide_item_sel(void *data, Evas_Object *obj, void *event_info)
602 {
603         __MOBILE_AP_FUNC_ENTER__;
604
605         if (data == NULL || obj == NULL || event_info == NULL) {
606                 ERR("param is NULL\n");
607                 return;
608         }
609
610         mh_appdata_t *ad = (mh_appdata_t *)data;
611
612         elm_genlist_item_selected_set((Elm_Object_Item*)event_info, EINA_FALSE);
613         __hide_btn_changed_cb(ad, obj, NULL);
614
615         elm_check_state_set(ad->setup.hide_btn, ad->setup.visibility_new ?
616                         EINA_FALSE : EINA_TRUE);
617
618         __MOBILE_AP_FUNC_EXIT__;
619 }
620
621 static void __gl_security_item_sel(void *data, Evas_Object *obj, void *event_info)
622 {
623         __MOBILE_AP_FUNC_ENTER__;
624
625         if (data == NULL || obj == NULL || event_info == NULL) {
626                 ERR("param is NULL\n");
627                 return;
628         }
629
630         mh_appdata_t *ad = (mh_appdata_t *)data;
631
632         elm_genlist_item_selected_set((Elm_Object_Item*)event_info, EINA_FALSE);
633         __security_btn_changed_cb(data, obj, NULL);
634         elm_check_state_set(ad->setup.security_btn, ad->setup.security_type_new ==
635                         TETHERING_WIFI_SECURITY_TYPE_NONE ? EINA_FALSE : EINA_TRUE);
636
637         __MOBILE_AP_FUNC_EXIT__;
638 }
639
640 static void __set_genlist_itc(mh_appdata_t *ad)
641 {
642         __MOBILE_AP_FUNC_ENTER__;
643
644 #if 0 /* not used */
645         ad->setup.sp_itc = elm_genlist_item_class_new();
646         if (ad->setup.sp_itc == NULL) {
647                 ERR("elm_genlist_item_class_new failed\n");
648                 __MOBILE_AP_FUNC_EXIT__;
649                 return;
650         }
651         ad->setup.sp_itc->item_style = "dialogue/separator";
652         ad->setup.sp_itc->func.text_get = NULL;
653         ad->setup.sp_itc->func.content_get = NULL;
654         ad->setup.sp_itc->func.state_get = NULL;
655         ad->setup.sp_itc->func.del = NULL;
656 #endif
657         ad->setup.name_itc = elm_genlist_item_class_new();
658         if (ad->setup.name_itc == NULL) {
659                 ERR("elm_genlist_item_class_new failed\n");
660                 __MOBILE_AP_FUNC_EXIT__;
661                 return;
662         }
663         ad->setup.name_itc->item_style = MH_GENLIST_MULTILINE_TEXT_STYLE;
664         ad->setup.name_itc->func.text_get = __gl_device_name_title_label_get;
665         ad->setup.name_itc->func.content_get = NULL;
666         ad->setup.name_itc->func.state_get = NULL;
667         ad->setup.name_itc->func.del = NULL;
668
669         ad->setup.hide_itc = elm_genlist_item_class_new();
670         if (ad->setup.hide_itc == NULL) {
671                 ERR("elm_genlist_item_class_new failed\n");
672                 __MOBILE_AP_FUNC_EXIT__;
673                 return;
674         }
675         ad->setup.hide_itc->item_style = MH_GENLIST_1LINE_TEXT_ICON_STYLE;
676         ad->setup.hide_itc->func.text_get = __gl_hide_label_get;
677         ad->setup.hide_itc->func.content_get = __gl_hide_icon_get;
678         ad->setup.hide_itc->func.state_get = NULL;
679         ad->setup.hide_itc->func.del = NULL;
680
681         ad->setup.security_itc = elm_genlist_item_class_new();
682         if (ad->setup.security_itc == NULL) {
683                 ERR("elm_genlist_item_class_new failed\n");
684                 __MOBILE_AP_FUNC_EXIT__;
685                 return;
686         }
687         ad->setup.security_itc->item_style = MH_GENLIST_1LINE_TEXT_ICON_STYLE;
688         ad->setup.security_itc->func.text_get = __gl_security_label_get;
689         ad->setup.security_itc->func.content_get = __gl_security_icon_get;
690         ad->setup.security_itc->func.state_get = NULL;
691         ad->setup.security_itc->func.del = NULL;
692
693         ad->setup.pw_itc = elm_genlist_item_class_new();
694         if (ad->setup.pw_itc == NULL) {
695                 ERR("elm_genlist_item_class_new failed\n");
696                 __MOBILE_AP_FUNC_EXIT__;
697                 return;
698         }
699         ad->setup.pw_itc->item_style = MH_GENLIST_FULL_CONTENT_STYLE;
700         ad->setup.pw_itc->func.text_get = NULL;
701         ad->setup.pw_itc->func.content_get = __gl_pw_content_get;
702         ad->setup.pw_itc->func.state_get = NULL;
703         ad->setup.pw_itc->func.del = NULL;
704
705 #if 0 /* not used */
706         ad->setup.sp2_itc = elm_genlist_item_class_new();
707         if (ad->setup.sp2_itc == NULL) {
708                 ERR("elm_genlist_item_class_new failed\n");
709                 __MOBILE_AP_FUNC_EXIT__;
710                 return;
711         }
712         ad->setup.sp2_itc->item_style = "dialogue/separator.2";
713         ad->setup.sp2_itc->func.text_get = NULL;
714         ad->setup.sp2_itc->func.content_get = NULL;
715         ad->setup.sp2_itc->func.state_get = NULL;
716         ad->setup.sp2_itc->func.del = NULL;
717 #endif
718         __MOBILE_AP_FUNC_EXIT__;
719         return;
720 }
721
722 static void __deconstruct_wifi_setup_view(mh_wifi_setting_view_t *st)
723 {
724         __MOBILE_AP_FUNC_ENTER__;
725
726         if (st == NULL) {
727                 ERR("st is NULL\n");
728                 return;
729         }
730
731         evas_object_smart_callback_del(st->hide_btn, "changed",
732                         __hide_btn_changed_cb);
733         evas_object_smart_callback_del(st->security_btn, "changed",
734                         __security_btn_changed_cb);
735         evas_object_smart_callback_del(st->cancel_button, "clicked",
736                         __cancel_btn_cb);
737         evas_object_smart_callback_del(st->save_button, "clicked",
738                         __save_btn_cb);
739         evas_object_smart_callback_del(st->genlist, "realized",
740                         __gl_realized);
741
742         __MOBILE_AP_FUNC_EXIT__;
743 }
744
745 static void __settings_reloaded_cb(tethering_error_e result, void *user_data)
746 {
747         if (user_data == NULL) {
748                 ERR("Invalid parameter\n");
749                 return;
750         }
751
752         __MOBILE_AP_FUNC_ENTER__;
753
754         mh_appdata_t *ad = (mh_appdata_t *)user_data;
755
756         if (result != TETHERING_ERROR_NONE)
757                 ERR("tethering_wifi_reload_settings is failed [0x%X]\n", result);
758         _update_wifi_item(ad, MH_STATE_NONE);
759
760         __MOBILE_AP_FUNC_EXIT__;
761
762         return;
763 }
764
765 static void __save_btn_cb(void *data, Evas_Object *object, void *event_info)
766 {
767         DBG("+\n");
768         if (data == NULL) {
769                 ERR("data is NULL\n");
770                 return;
771         }
772
773         mh_appdata_t *ad = (mh_appdata_t *)data;
774         mh_wifi_setting_view_t *st = &ad->setup;
775         bool ret = false;
776         bool is_setting_changed = false;
777
778         /* handle hide button change */
779         if (st->visibility != st->visibility_new) {
780                 ret = __save_hide_btn_change(ad);
781                 if (ret == false) {
782                         elm_check_state_set(st->hide_btn, st->visibility ?
783                                         EINA_FALSE : EINA_TRUE);
784                 } else {
785                         st->visibility = st->visibility_new;
786                         is_setting_changed = true;
787                 }
788         }
789         /* handle security button change */
790         if (st->security_type != st->security_type_new) {
791                 ret = __save_security_btn_change(ad);
792                 if (ret == false) {
793                         elm_check_state_set(st->security_btn, st->security_type ==
794                                         TETHERING_WIFI_SECURITY_TYPE_NONE ? EINA_FALSE : EINA_TRUE);
795                 } else {
796                                 st->security_type = st->security_type_new;
797                                 is_setting_changed = true;
798                 }
799         }
800
801         /* handle wifi passphrase change */
802         if (strcmp(st->wifi_passphrase, st->wifi_passphrase_new)) {
803                 ret = __save_wifi_passphrase(ad);
804                 if (ret == false) {
805                         g_strlcpy(st->wifi_passphrase_new, st->wifi_passphrase,
806                                         sizeof(st->wifi_passphrase_new));
807                         if(st->pw_item)
808                                 elm_genlist_item_update(st->pw_item);
809                 } else {
810                         g_strlcpy(st->wifi_passphrase, st->wifi_passphrase_new,
811                                         sizeof(st->wifi_passphrase));
812                         is_setting_changed = true;
813                         if (ad->main.help_item) {
814                                 if (ad->main.help_item)
815                                         elm_genlist_item_update(ad->main.help_item);
816                         }
817                 }
818         }
819
820         if (is_setting_changed) {
821                 _update_wifi_item(ad, MH_STATE_PROCESS);
822
823                 if (ad->main.help_item)
824                         elm_genlist_item_update(ad->main.help_item);
825
826                 /* reload wifi settings */
827                 ret = tethering_wifi_reload_settings(ad->handle, __settings_reloaded_cb,
828                                 (void *)ad);
829                 if (ret != TETHERING_ERROR_NONE)
830                         ERR("reload_configuration is failed : %d\n", ret);
831         }
832
833         elm_naviframe_item_pop(ad->naviframe);
834
835         DBG("-\n");
836         return;
837 }
838
839 static void __cancel_btn_cb(void *data, Evas_Object *object, void *event_info)
840 {
841         DBG("+\n");
842
843         if (data == NULL) {
844                 ERR("The param is NULL\n");
845                 return;
846         }
847
848         mh_appdata_t *ad = (mh_appdata_t *)data;
849
850         elm_naviframe_item_pop(ad->naviframe);
851         DBG("-\n");
852         return;
853 }
854
855 Eina_Bool _setting_back_btn_cb(void *data, Elm_Object_Item *navi_item)
856 {
857         DBG("+\n");
858
859         if (data == NULL) {
860                 ERR("The param is NULL\n");
861                 return EINA_FALSE;
862         }
863
864         mh_appdata_t *ad = (mh_appdata_t *)data;
865         mh_wifi_setting_view_t *st = &ad->setup;
866
867         if (st->visibility != st->visibility_new) {
868                 st->visibility_new = st->visibility;
869         }
870
871         if (st->security_type != st->security_type_new) {
872                 st->security_type_new = st->security_type;
873         }
874
875         if (strcmp(st->wifi_passphrase_new, st->wifi_passphrase)) {
876                 g_strlcpy(st->wifi_passphrase_new, st->wifi_passphrase,
877                                         sizeof(st->wifi_passphrase_new));
878         }
879         st->pw_entry = NULL;
880         __deconstruct_wifi_setup_view(st);
881
882         if (ad->rename_popup != NULL) {
883                 evas_object_del(ad->rename_popup);
884                 ad->rename_popup = NULL;
885         }
886         ad->setup.navi_it = NULL;
887
888         DBG("-\n");
889         return EINA_TRUE;
890 }
891
892 static void __gl_realized(void *data, Evas_Object *obj, void *event_info)
893 {
894         __MOBILE_AP_FUNC_ENTER__;
895
896         mh_appdata_t *ad = (mh_appdata_t *)data;
897         mh_wifi_setting_view_t *st = &(ad->setup);
898         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
899         Evas_Object *ao;
900         Evas_Object *btn;
901         char str[MH_LABEL_LENGTH_MAX] = {0, };
902         int no_of_sp;
903         int i;
904
905         if (item == st->hide_item) {
906                 elm_object_item_signal_emit(item, "elm,state,top", "");
907         } else if (item == st->security_item) {
908                 elm_object_item_signal_emit(item, "elm,state,center", "");
909         } else if (item == st->pw_item) {
910                 elm_object_item_signal_emit(item, "elm,state,bottom", "");
911         } else if (item == st->name_item) {
912         }
913
914         no_of_sp = sizeof(st->sp_item) / sizeof(st->sp_item[0]);
915         for (i = 0; i < no_of_sp; i++) {
916                 if (item == st->sp_item[i])
917                         elm_object_item_access_unregister(item);
918         }
919
920         if (item == st->hide_item || item == st->security_item) {
921                 ao = elm_object_item_access_object_get(item);
922                 btn = elm_object_item_part_content_get(item, "on&off");
923                 snprintf(str, sizeof(str), "%s, %s", "On/off button",
924                                 (elm_check_state_get(btn) ? "On" : "Off"));
925                 elm_access_info_set(ao, ELM_ACCESS_CONTEXT_INFO, str);
926         }
927
928         if (item == st->pw_item) {
929                 elm_object_item_access_unregister(item);
930                 ao = elm_object_item_access_register(item);
931                 snprintf(str, sizeof(str), "%s, %s", STR_PASSWORD, st->wifi_passphrase_new);
932                 elm_access_info_set(ao, ELM_ACCESS_CONTEXT_INFO, str);
933         }
934
935         __MOBILE_AP_FUNC_EXIT__;
936
937         return;
938 }
939
940 static void __select_passphrase_item(void *data, Evas_Object *obj, void *event_info)
941 {
942         __MOBILE_AP_FUNC_ENTER__;
943
944         if (data == NULL) {
945                 ERR("The param is NULL\n");
946                 return;
947         }
948
949         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
950         Evas_Object *layout = NULL;
951         mh_appdata_t *ad = (mh_appdata_t *)data;
952         mh_wifi_setting_view_t *st = &ad->setup;
953
954         elm_object_focus_set(st->pw_entry, EINA_TRUE);
955
956         __MOBILE_AP_FUNC_EXIT__;
957         return;
958 }
959
960 Evas_Object *__create_genlist(mh_appdata_t *ad)
961 {
962         __MOBILE_AP_FUNC_ENTER__;
963
964         if (ad == NULL) {
965                 ERR("ad is NULL\n");
966                 return NULL;
967         }
968
969         void *data = (void *)ad;
970         mh_wifi_setting_view_t *st = &ad->setup;
971         Evas_Object *genlist;
972
973         genlist = elm_genlist_add(ad->naviframe);
974         if (genlist == NULL) {
975                 ERR("genlist is NULL\n");
976                 return NULL;
977         }
978
979         elm_object_style_set(genlist, "dialogue");
980         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
981         evas_object_smart_callback_add(genlist, "realized", __gl_realized, ad);
982         //elm_genlist_realization_mode_set(genlist, EINA_TRUE);
983
984         __set_genlist_itc(ad);
985
986         st->name_item = elm_genlist_item_append(genlist, st->name_itc, data, NULL,
987                         ELM_GENLIST_ITEM_NONE, NULL, NULL);
988         elm_genlist_item_select_mode_set(st->name_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
989
990         if (st->name_item)
991                 elm_object_item_disabled_set(st->name_item, EINA_TRUE);
992
993         st->hide_item = elm_genlist_item_append(genlist, st->hide_itc, data, NULL,
994                         ELM_GENLIST_ITEM_NONE, __gl_hide_item_sel, data);
995
996         st->security_item = elm_genlist_item_append(genlist, st->security_itc, data, NULL,
997                         ELM_GENLIST_ITEM_NONE, __gl_security_item_sel, data);
998
999         st->pw_item = elm_genlist_item_append(genlist, st->pw_itc, data, NULL,
1000                         ELM_GENLIST_ITEM_NONE, __select_passphrase_item, ad);
1001         if (st->security_type == TETHERING_WIFI_SECURITY_TYPE_NONE)
1002                 elm_object_item_disabled_set(st->pw_item, EINA_TRUE);
1003         else
1004                 elm_object_item_disabled_set(st->pw_item, EINA_FALSE);
1005
1006 /* End separator is removed because of P131104-03336. It is confirmed by UX team for this case.
1007         item = elm_genlist_item_append(genlist, st->sp_itc, NULL, NULL,
1008                         ELM_GENLIST_ITEM_NONE, NULL, NULL);
1009         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1010         st->sp_item[i++] = item;
1011 */
1012
1013         __MOBILE_AP_FUNC_EXIT__;
1014
1015         return genlist;
1016 }
1017
1018 void mh_draw_wifi_setup_view(mh_appdata_t *ad)
1019 {
1020         DBG("+\n");
1021
1022         if (ad == NULL) {
1023                 ERR("ad is NULL\n");
1024                 DBG("-\n");
1025                 return;
1026         }
1027         Evas_Object *btn;
1028         mh_wifi_setting_view_t *st = &ad->setup;
1029
1030         if (ad->setup.navi_it != NULL) {
1031                 ERR("Wi-Fi setup view already exists\n");
1032                 DBG("-\n");
1033                 return;
1034         }
1035
1036         st->genlist = __create_genlist(ad);
1037         if (st->genlist == NULL) {
1038                 ERR("__create_genlist returns NULL\n");
1039                 DBG("-\n");
1040                 return;
1041         }
1042
1043         st->navi_it = elm_naviframe_item_push(ad->naviframe, "IDS_MOBILEAP_MBODY_WI_FI_TETHERING",
1044                         NULL, NULL, st->genlist, NULL);
1045         elm_object_item_domain_text_translatable_set(st->navi_it, PKGNAME, EINA_TRUE);
1046
1047         elm_naviframe_item_pop_cb_set(st->navi_it, _setting_back_btn_cb, (void *)ad);
1048
1049         btn = elm_button_add(ad->naviframe);
1050         elm_object_style_set(btn, "naviframe/title_cancel");
1051         evas_object_smart_callback_add(btn, "clicked", __cancel_btn_cb, ad);
1052         elm_object_item_part_content_set(st->navi_it, "title_left_btn", btn);
1053         st->cancel_button = btn;
1054
1055         btn = elm_button_add(ad->naviframe);
1056         elm_object_style_set(btn, "naviframe/title_done");
1057         evas_object_smart_callback_add(btn, "clicked", __save_btn_cb, ad);
1058         elm_object_item_part_content_set(st->navi_it, "title_right_btn", btn);
1059         st->save_button = btn;
1060         DBG("-\n");
1061 }