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