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