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