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