c1403dc668cdb71714e4a46c6f3678fd6cac6db9
[apps/native/ug-mobile-ap.git] / src / mh_view_main.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
20 #include <time.h>
21 #include <limits.h>
22 #include <efl_extension.h>
23 #include <dpm/restriction.h>
24
25 #include "mh_view_main.h"
26 #include "mh_popup.h"
27 #include "mh_string.h"
28
29 static void __ctx_move_more_ctxpopup(Evas_Object *ctx, mh_appdata_t *ad);
30 static void __ctx_delete_more_ctxpopup_cb(void *data, Evas *e, Evas_Object *obj,
31                                           void *event_info);
32 static void __create_ctxpopup_more_button(void *data, Evas_Object *obj,
33                                           void *event_info);
34
35 static Eina_Bool rotate_flag = EINA_FALSE;
36
37 void _genlist_update_device_item(mh_appdata_t *ad);
38 mh_appdata_t *g_ad = NULL;
39 #define UPDATE_INTERVAL 1
40
41 void _list_connected_dev(mh_appdata_t *ap)
42 {
43         __MOBILE_AP_FUNC_ENTER__;
44
45         if (ap == NULL) {
46                 ERR("data is NULL\n");
47                 return;
48         }
49
50         _add_connected_clients(ap);
51         __MOBILE_AP_FUNC_EXIT__;
52 }
53
54 static bool _connected_clients_cb(tethering_client_h client, void *user_data)
55 {
56         __MOBILE_AP_FUNC_ENTER__;
57
58         if (user_data == NULL) {
59                 ERR("user_data is NULL\n");
60                 return true;
61         }
62
63         mh_appdata_t *ad = (mh_appdata_t *)user_data;
64
65         _append_list_client_handle(ad, client);
66
67         __MOBILE_AP_FUNC_EXIT__;
68         return true;
69 }
70
71 void ap_update_data_device(mh_appdata_t *ad)
72 {
73         __MOBILE_AP_FUNC_ENTER__;
74
75         if (ad == NULL) {
76                 ERR("Invalid param\n");
77                 return;
78         }
79
80         _genlist_update_device_item(ad);
81
82         __MOBILE_AP_FUNC_EXIT__;
83 }
84
85 #ifdef TETHERING_DATA_USAGE_SUPPORT
86 Eina_Bool ap_update_data_packet_usage(mh_appdata_t *ad)
87 {
88         if (ad == NULL) {
89                 ERR("Invalid param\n");
90                 return EINA_FALSE;
91         }
92
93         if (ad->main.usage_item)
94                 elm_genlist_item_update(ad->main.usage_item);
95
96         return EINA_TRUE;
97 }
98
99 Eina_Bool ap_get_data_statistics(void *data)
100 {
101         if (!data) {
102                 ERR("The param is NULL\n");
103                 return ECORE_CALLBACK_CANCEL;
104         }
105         mh_appdata_t *ad = (mh_appdata_t *)data;
106
107         if (ad->main.hotspot_mode == VCONFKEY_MOBILE_HOTSPOT_MODE_NONE) {
108                 ad->update_statistics_handle = NULL;
109                 return ECORE_CALLBACK_CANCEL;
110         }
111
112         /* If previous data is not updated, new data is not required */
113         if (ad->data_statistics.is_updated == false)
114                 return ECORE_CALLBACK_RENEW;
115
116         /* Because previous data is updated, new data is required.
117            It will be returned asynchronously. */
118         tethering_get_data_usage(ad->handle, _data_usage_cb, (void *)ad);
119         ad->data_statistics.is_updated = false;
120
121         return ECORE_CALLBACK_RENEW;
122 }
123 #endif
124
125 Eina_Bool ap_update_device_conn_time(void * data)
126 {
127         if (!data) {
128                 ERR("The param is NULL\n");
129                 return ECORE_CALLBACK_CANCEL;
130         }
131         mh_appdata_t *ad = (mh_appdata_t *)data;
132
133         int count = 0;
134         if (ad->main.hotspot_mode == VCONFKEY_MOBILE_HOTSPOT_MODE_NONE) {
135                 _stop_update_device_conn_time(ad);
136                 __MOBILE_AP_FUNC_EXIT__;
137                 return ECORE_CALLBACK_CANCEL;
138         }
139
140         while (count < ad->main.no_of_clients) {
141                 if (ad->main.station_items[count])
142                         elm_genlist_item_fields_update(ad->main.station_items[count++],
143                                         "elm.text.sub", ELM_GENLIST_ITEM_FIELD_TEXT);
144         }
145         return ECORE_CALLBACK_RENEW;
146 }
147
148 void _start_update_device_conn_time(mh_appdata_t *ad)
149 {
150         __MOBILE_AP_FUNC_ENTER__;
151
152         if (ad == NULL) {
153                 ERR("Invalid param\n");
154                 __MOBILE_AP_FUNC_EXIT__;
155                 return;
156         }
157
158         if (ad->update_conn_time_handle)
159                 _stop_update_device_conn_time(ad);
160
161         ad->update_conn_time_handle = ecore_timer_add(UPDATE_INTERVAL,
162                         ap_update_device_conn_time, (void *)ad);
163
164         __MOBILE_AP_FUNC_EXIT__;
165 }
166
167 void _stop_update_device_conn_time(mh_appdata_t *ad)
168 {
169         __MOBILE_AP_FUNC_ENTER__;
170
171         if (ad == NULL) {
172                 ERR("Invalid param\n");
173                 return;
174         }
175
176         if (ad->update_conn_time_handle) {
177                 ecore_timer_del(ad->update_conn_time_handle);
178                 ad->update_conn_time_handle = NULL;
179         }
180         __MOBILE_AP_FUNC_EXIT__;
181 }
182
183 #ifdef TETHERING_DATA_USAGE_SUPPORT
184 void _start_update_data_packet_usage(mh_appdata_t *ad)
185 {
186         __MOBILE_AP_FUNC_ENTER__;
187
188         if (ad == NULL) {
189                 ERR("Invalid param\n");
190                 return;
191         }
192
193         if (ad->update_statistics_handle)
194                 _stop_update_data_packet_usage(ad);
195
196         ad->data_statistics.is_updated = false;
197         tethering_get_data_usage(ad->handle, _data_usage_cb, (void *)ad);
198         ad->update_statistics_handle = ecore_timer_add(MH_UPDATE_INTERVAL,
199                         ap_get_data_statistics, (void *)ad);
200
201         __MOBILE_AP_FUNC_EXIT__;
202         return;
203 }
204
205 void _stop_update_data_packet_usage(mh_appdata_t *ad)
206 {
207         __MOBILE_AP_FUNC_ENTER__;
208
209         if (ad == NULL) {
210                 ERR("Invalid param\n");
211                 return;
212         }
213
214         if (ad->update_statistics_handle) {
215                 ecore_timer_del(ad->update_statistics_handle);
216                 ad->data_statistics.is_updated = false;
217                 ad->update_statistics_handle = NULL;
218         }
219
220         __MOBILE_AP_FUNC_EXIT__;
221         return;
222 }
223 #endif
224
225 static void __read_setting(mh_appdata_t *ad)
226 {
227         __MOBILE_AP_FUNC_ENTER__;
228
229         if (ad == NULL) {
230                 ERR("Invalid param\n");
231                 return;
232         }
233
234         int ret = 0;
235         char *ssid = NULL;
236         char *passphrase = NULL;
237         bool visibility;
238         tethering_wifi_security_type_e type;
239
240         ad->main.hotspot_mode = _get_vconf_hotspot_mode();
241
242 #ifdef TETHERING_DATA_USAGE_SUPPORT
243         ad->data_statistics.pdp_total_sent = 0;
244         ad->data_statistics.pdp_total_receive = 0;
245         if (ad->main.hotspot_mode != VCONFKEY_MOBILE_HOTSPOT_MODE_NONE)
246                 tethering_get_data_usage(ad->handle, _data_usage_cb, (void *)ad);
247 #endif
248
249         ret = tethering_wifi_get_ssid(ad->handle, &ssid);
250         if (ret != TETHERING_ERROR_NONE || ssid == NULL) {
251                 ERR("tethering_wifi_get_ssid is failed : %d\n", ret);
252                 return;
253         }
254         g_strlcpy(ad->setup.device_name, ssid, sizeof(ad->setup.device_name));
255         free(ssid);
256
257         ret = tethering_wifi_get_passphrase(ad->handle, &passphrase);
258         if (ret != TETHERING_ERROR_NONE || passphrase == NULL) {
259                 ERR("tethering_wifi_get_passphrase is failed : %d\n", ret);
260                 return;
261         }
262
263         g_strlcpy(ad->setup.wifi_passphrase, passphrase,
264                         sizeof(ad->setup.wifi_passphrase));
265         g_strlcpy(ad->setup.wifi_passphrase_new, passphrase,
266                         sizeof(ad->setup.wifi_passphrase_new));
267         free(passphrase);
268
269         ret = tethering_wifi_get_ssid_visibility(ad->handle, &visibility);
270         if (ret != TETHERING_ERROR_NONE)
271                 ERR("tethering_wifi_get_ssid_visibility is failed\n");
272
273         ad->setup.visibility = visibility;
274         ad->setup.visibility_new = visibility;
275
276         ret = tethering_wifi_get_security_type(ad->handle, &type);
277         if (ret != TETHERING_ERROR_NONE)
278                 ERR("tethering_wifi_get_security_type is failed\n");
279
280         ad->setup.security_type = type;
281         ad->setup.security_type_new = type;
282
283         __MOBILE_AP_FUNC_EXIT__;
284 }
285
286 void _update_wifi_item(mh_appdata_t *ad, int wifi_state)
287 {
288         __MOBILE_AP_FUNC_ENTER__;
289
290         if (ad->main.wifi_state == wifi_state)
291                 return;
292
293         if (ad->main.wifi_state == MH_STATE_PROCESS) {
294                 ad->main.wifi_state = MH_STATE_NONE;
295                 elm_genlist_item_select_mode_set(ad->main.wifi_item, ELM_OBJECT_SELECT_MODE_DEFAULT);
296         } else if (ad->main.wifi_state == MH_STATE_NONE) {
297                 ad->main.wifi_state = MH_STATE_PROCESS;
298                 elm_genlist_item_select_mode_set(ad->main.wifi_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
299         }
300
301         if (ad->main.wifi_item)
302                 elm_genlist_item_update(ad->main.wifi_item);
303
304         if (ad->main.setup_item)
305                 elm_object_item_signal_emit(ad->main.setup_item, "elm,state,bottom", "");
306
307         __MOBILE_AP_FUNC_EXIT__;
308
309         return;
310 }
311
312 void _update_bt_item(mh_appdata_t *ad, int bt_state)
313 {
314         __MOBILE_AP_FUNC_ENTER__;
315
316         if (ad->main.bt_state == bt_state)
317                 return;
318
319         if (ad->main.bt_state == MH_STATE_PROCESS) {
320                 ad->main.bt_state = MH_STATE_NONE;
321                 elm_genlist_item_select_mode_set(ad->main.bt_item, ELM_OBJECT_SELECT_MODE_DEFAULT);
322         } else if (ad->main.bt_state == MH_STATE_NONE) {
323                 ad->main.bt_state = MH_STATE_PROCESS;
324                 elm_genlist_item_select_mode_set(ad->main.bt_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
325         }
326
327         if (ad->main.bt_item)
328                 elm_genlist_item_update(ad->main.bt_item);
329
330         __MOBILE_AP_FUNC_EXIT__;
331
332         return;
333 }
334
335 void _update_usb_item(mh_appdata_t *ad, int usb_state)
336 {
337         __MOBILE_AP_FUNC_ENTER__;
338
339         if (ad->main.usb_state == usb_state)
340                 return;
341
342         if (ad->main.usb_state == MH_STATE_PROCESS) {
343                 ad->main.usb_state = MH_STATE_NONE;
344                 elm_genlist_item_select_mode_set(ad->main.usb_item, ELM_OBJECT_SELECT_MODE_DEFAULT);
345         } else if (ad->main.usb_state == MH_STATE_NONE) {
346                 ad->main.usb_state = MH_STATE_PROCESS;
347                 elm_genlist_item_select_mode_set(ad->main.usb_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
348         }
349
350         elm_genlist_item_update(ad->main.usb_item);
351
352         __MOBILE_AP_FUNC_EXIT__;
353
354         return;
355 }
356
357 void _genlist_update_device_item(mh_appdata_t *ad)
358 {
359         __MOBILE_AP_FUNC_ENTER__;
360
361         if (ad == NULL) {
362                 ERR("Invalid param\n");
363                 return;
364         }
365         unsigned int no_of_dev = 0;
366         no_of_dev = _get_list_clients_count(ad);
367         Elm_Object_Item *item = NULL;
368
369         if (no_of_dev == 0) {
370                 if (ad->main.device_item) {
371                         elm_object_item_del(ad->main.device_item);
372                         ad->main.device_item = NULL;
373                         _update_conn_clients(ad);
374                 }
375         } else {
376                 if (ad->main.device_item) {
377                 _update_conn_clients(ad);
378                 } else {
379                         item = elm_genlist_item_append(ad->main.genlist,
380                                         ad->main.device_itc, ad, NULL,
381                                         ELM_GENLIST_ITEM_NONE, NULL, NULL);
382                         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
383                         ad->main.device_item = item;
384                         _list_connected_dev(ad);
385                         }
386                 }
387
388
389         __MOBILE_AP_FUNC_EXIT__;
390         return;
391 }
392
393 void _update_main_view(mh_appdata_t *ad, tethering_type_e type)
394 {
395         __MOBILE_AP_FUNC_ENTER__;
396
397         if (ad == NULL) {
398                 ERR("Invalid param\n");
399                 return;
400         }
401
402         int state = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
403         Eina_Bool wifi_state = EINA_FALSE;
404         Eina_Bool bt_state = EINA_FALSE;
405         Eina_Bool usb_state = EINA_FALSE;
406         Eina_Bool wifi_ap_state = EINA_FALSE;
407         Elm_Object_Item *item = NULL;
408         Evas_Object *obj;
409         int no_of_dev = 0;
410
411         ad->main.hotspot_mode = _get_vconf_hotspot_mode();
412         state = ad->main.hotspot_mode;
413
414         wifi_state = (Eina_Bool)(state & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI);
415         bt_state = (Eina_Bool)(state & VCONFKEY_MOBILE_HOTSPOT_MODE_BT);
416         usb_state = (Eina_Bool)(state & VCONFKEY_MOBILE_HOTSPOT_MODE_USB);
417         wifi_ap_state = (Eina_Bool)(state & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI_AP);
418
419         if (wifi_ap_state) {
420                 if (ad->main.wifi_item)
421                         elm_object_item_disabled_set(ad->main.wifi_item, EINA_TRUE);
422                 if (ad->main.setup_item)
423                         elm_object_item_disabled_set(ad->main.setup_item, EINA_TRUE);
424                 if (ad->main.bt_item)
425                         elm_object_item_disabled_set(ad->main.bt_item, EINA_TRUE);
426                 if (ad->main.usb_item)
427                         elm_object_item_disabled_set(ad->main.usb_item, EINA_TRUE);
428         } else {
429                 if (ad->main.setup_item)
430                         elm_object_item_disabled_set(ad->main.setup_item, EINA_FALSE);
431                 if (ad->main.bt_item)
432                         elm_object_item_disabled_set(ad->main.bt_item, EINA_FALSE);
433                 if (_get_vconf_usb_state() == VCONFKEY_SYSMAN_USB_DISCONNECTED) {
434                         if (ad->main.usb_item)
435                                 elm_object_item_disabled_set(ad->main.usb_item, EINA_TRUE);
436                 } else {
437                         if (ad->main.usb_item)
438                                 elm_object_item_disabled_set(ad->main.usb_item, EINA_FALSE);
439                 }
440         }
441
442         if (wifi_state || bt_state || usb_state) {
443 #ifdef TETHERING_DATA_USAGE_SUPPORT
444                 if (ad->main.usage_item == NULL) {
445                         item = elm_genlist_item_insert_before(ad->main.genlist,
446                                         ad->main.usage_itc, ad, NULL,
447                                         ad->main.sp_item[0],
448                                         ELM_GENLIST_ITEM_NONE, NULL, NULL);
449                         elm_genlist_item_select_mode_set(item,
450                                         ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
451                         ad->main.usage_item = item;
452                 }
453 #endif
454
455                 no_of_dev = _get_list_clients_count(ad);
456                 if (ad->main.device_item == NULL) {
457                         if (no_of_dev != 0) {
458                                 item = elm_genlist_item_append(ad->main.genlist,
459                                                 ad->main.device_itc, ad, NULL,
460                                                 ELM_GENLIST_ITEM_NONE, NULL, NULL);
461                                 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DEFAULT);
462                         _list_connected_dev(ad);
463                         _update_conn_clients(ad);
464                         }
465                         ad->main.device_item = item;
466                 }
467         } else {
468                 if (ad->main.device_item) {
469                         elm_object_item_del(ad->main.device_item);
470                         ad->main.device_item = NULL;
471                 }
472 #ifdef TETHERING_DATA_USAGE_SUPPORT
473                 if (ad->main.usage_item) {
474                         elm_object_item_del(ad->main.usage_item);
475                         ad->main.usage_item = NULL;
476                 }
477 #endif
478         }
479
480         if (wifi_state) {
481                 if (ad->main.help_item) {
482                         elm_genlist_item_update(ad->main.help_item);
483                 } else {
484                         item = elm_genlist_item_insert_after(ad->main.genlist,
485                                         ad->main.help_itc, ad, NULL,
486                                         ad->main.wifi_item,
487                                         ELM_GENLIST_ITEM_NONE, NULL,
488                                         NULL);
489                         if (item == NULL) {
490                                 ERR("elm_genlist_item_insert_after NULL\n");
491                         } else {
492                                 elm_genlist_item_select_mode_set(item,
493                                                 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
494                                 ad->main.help_item = item;
495                         }
496                 }
497         } else {
498                 if (ad->main.help_item) {
499                         elm_object_item_del(ad->main.help_item);
500                         ad->main.help_item = NULL;
501                 }
502         }
503
504         switch (type) {
505         case TETHERING_TYPE_WIFI:
506                 /* Update Wi-Fi tethering on / off button */
507                 if (ad->main.wifi_state != MH_STATE_NONE) {
508                         _update_wifi_item(ad, MH_STATE_NONE);
509                 } else {
510                         obj = elm_object_item_part_content_get(ad->main.wifi_item, "elm.swallow.end");
511                         if (obj != NULL)
512                                 elm_check_state_set(obj, wifi_state);
513
514                         if (ad->main.wifi_item)
515                                 elm_genlist_item_update(ad->main.wifi_item);
516                 }
517                 break;
518
519         case TETHERING_TYPE_BT:
520                 /* Update BT tethering on / off button */
521                 if (ad->main.bt_state != MH_STATE_NONE) {
522                         _update_bt_item(ad, MH_STATE_NONE);
523                 } else {
524                         obj = elm_object_item_part_content_get(ad->main.bt_item, "elm.swallow.end");
525                         if (obj != NULL)
526                                 elm_check_state_set(obj, bt_state);
527
528                         if (ad->main.bt_item)
529                                 elm_genlist_item_update(ad->main.bt_item);
530                 }
531                 break;
532
533         case TETHERING_TYPE_USB:
534                 /* Update USB tethering on / off button */
535                 if (ad->main.usb_state != MH_STATE_NONE) {
536                         _update_usb_item(ad, MH_STATE_NONE);
537                 } else {
538                         obj = elm_object_item_part_content_get(ad->main.usb_item, "elm.swallow.end");
539                         if (obj != NULL)
540                                 elm_check_state_set(obj, usb_state);
541
542                         if (ad->main.usb_item)
543                                 elm_genlist_item_update(ad->main.usb_item);
544                 }
545                 break;
546
547         default:
548                 DBG("Unknown tethering type : %d\n", type);
549                 break;
550         }
551
552         __MOBILE_AP_FUNC_EXIT__;
553
554         return;
555 }
556
557 static int __is_allowed(tethering_type_e type)
558 {
559         int state = 0;
560         device_policy_manager_h dpm = NULL;
561
562         dpm = dpm_manager_create();
563         if (dpm == NULL) {
564                 ERR("Failed to create device policy manager!!");
565                 return 0;
566         }
567
568         switch (type) {
569         case TETHERING_TYPE_WIFI:
570                 dpm_restriction_get_wifi_hotspot_state(dpm, &state);
571                 break;
572         case TETHERING_TYPE_USB:
573                 dpm_restriction_get_usb_tethering_state(dpm, &state);
574                 break;
575         case TETHERING_TYPE_BT:
576                 dpm_restriction_get_bluetooth_tethering_state(dpm, &state);
577                 break;
578         default:
579                 break;
580         }
581
582         dpm_manager_destroy(dpm);
583
584         return state;
585 }
586
587 static void __wifi_onoff_changed_cb(void *data, Evas_Object *obj,
588                                                         void *event_info)
589 {
590         __MOBILE_AP_FUNC_ENTER__;
591
592         if (!__is_allowed(TETHERING_TYPE_WIFI)) {
593                 ERR("Wi-Fi tethering is restricted!!");
594                 elm_check_state_set(obj, EINA_FALSE);
595                 _create_security_restriction_noti(TETHERING_TYPE_WIFI);
596                 return;
597         }
598
599         if (data == NULL) {
600                 ERR("The param is NULL\n");
601                 return;
602         }
603
604         mh_appdata_t *ad = (mh_appdata_t *)data;
605
606         _update_wifi_item(ad, MH_STATE_PROCESS);
607         ad->type = TETHERING_TYPE_WIFI;
608         ad->is_wifi_teth_enabling = true;
609         if (_handle_wifi_onoff_change(ad) != 0) {
610                 ERR("_handle_wifi_onoff_change is failed\n");
611                 _update_wifi_item(ad, MH_STATE_NONE);
612                 ad->is_wifi_teth_enabling = false;
613         }
614
615         __MOBILE_AP_FUNC_EXIT__;
616
617         return;
618 }
619
620 static void __select_wifi_item(void *data, Evas_Object *obj, void *event_info)
621 {
622         __MOBILE_AP_FUNC_ENTER__;
623
624         Evas_Object *content;
625         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
626
627         if (data == NULL) {
628                 ERR("The param is NULL\n");
629                 return;
630         }
631
632         elm_genlist_item_selected_set(item, EINA_FALSE);
633
634         content = elm_object_item_part_content_get(item, "elm.icon");
635         __wifi_onoff_changed_cb(data, content, NULL);
636
637         __MOBILE_AP_FUNC_EXIT__;
638
639         return;
640 }
641
642 static void __bt_onoff_changed_cb(void *data, Evas_Object *obj, void *event_info)
643 {
644         __MOBILE_AP_FUNC_ENTER__;
645
646         if (!__is_allowed(TETHERING_TYPE_BT)) {
647                 ERR("BT tethering is restricted!!");
648                 elm_check_state_set(obj, EINA_FALSE);
649                 _create_security_restriction_noti(TETHERING_TYPE_BT);
650                 return;
651         }
652
653         if (data == NULL) {
654                 ERR("The param is NULL\n");
655                 return;
656         }
657
658         mh_appdata_t *ad = (mh_appdata_t *)data;
659
660         _update_bt_item(ad, MH_STATE_PROCESS);
661         ad->type = TETHERING_TYPE_BT;
662         ad->is_bt_teth_enabling = true;
663
664         if (_handle_bt_onoff_change(ad) != 0) {
665                 ERR("_handle_bt_onoff_change is failed\n");
666                 _update_bt_item(ad, MH_STATE_NONE);
667                 ad->is_bt_teth_enabling = false;
668         }
669
670         __MOBILE_AP_FUNC_EXIT__;
671
672         return;
673 }
674
675 static void __select_bt_item(void *data, Evas_Object *obj, void *event_info)
676 {
677         __MOBILE_AP_FUNC_ENTER__;
678
679         Evas_Object *content;
680         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
681
682         if (data == NULL) {
683                 ERR("The param is NULL\n");
684                 return;
685         }
686
687         elm_genlist_item_selected_set(item, EINA_FALSE);
688
689         content = elm_object_item_part_content_get(item, "elm.icon");
690         __bt_onoff_changed_cb(data, content, NULL);
691
692         __MOBILE_AP_FUNC_EXIT__;
693
694         return;
695 }
696
697 static void __usb_onoff_changed_cb(void *data, Evas_Object *obj, void *event_info)
698 {
699         __MOBILE_AP_FUNC_ENTER__;
700
701         if (!__is_allowed(TETHERING_TYPE_USB)) {
702                 ERR("USB tethering is restricted!!");
703                 elm_check_state_set(obj, EINA_FALSE);
704                 _create_security_restriction_noti(TETHERING_TYPE_USB);
705                 return;
706         }
707
708         if (data == NULL) {
709                 ERR("The param is NULL\n");
710                 return;
711         }
712
713         mh_appdata_t *ad = (mh_appdata_t *)data;
714         _update_usb_item(ad, MH_STATE_PROCESS);
715         ad->type = TETHERING_TYPE_USB;
716         ad->is_usb_teth_enabling = true;
717         if (_handle_usb_onoff_change(ad) != 0) {
718                 ERR("_handle_usb_onoff_change is failed\n");
719                 _update_usb_item(ad, MH_STATE_NONE);
720                 ad->is_usb_teth_enabling = false;
721         }
722
723         __MOBILE_AP_FUNC_EXIT__;
724
725         return;
726 }
727
728 static void __select_usb_item(void *data, Evas_Object *obj, void *event_info)
729 {
730         __MOBILE_AP_FUNC_ENTER__;
731
732         Evas_Object *content;
733         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
734
735         if (data == NULL) {
736                 ERR("The param is NULL\n");
737                 return;
738         }
739
740         elm_genlist_item_selected_set(item, EINA_FALSE);
741
742         content = elm_object_item_part_content_get(item, "elm.icon");
743         __usb_onoff_changed_cb(data, content, NULL);
744
745         __MOBILE_AP_FUNC_EXIT__;
746
747         return;
748 }
749
750 static void  __back_btn_cb(void *data, Elm_Object_Item *navi_item)
751 {
752         INFO("+\n");
753
754         if (data == NULL) {
755                 ERR("The param is NULL\n");
756                 return;
757         }
758
759         mh_appdata_t *ad = (mh_appdata_t*)data;
760
761         _release_list_client_handle(ad);
762         _main_callback_del(ad);
763
764         ug_destroy_me(((mh_ugdata_t *)ad->gadget)->ug);
765
766         INFO("-\n");
767         return;
768 }
769
770 static char *__get_wifi_label(void *data, Evas_Object *obj, const char *part)
771 {
772         if (!strcmp("elm.text", part))
773                 return strdup(STR_MOBILE_HOTSPOT);
774
775         return NULL;
776 }
777
778 static Evas_Object *__get_wifi_icon(void *data, Evas_Object *obj,
779                 const char *part)
780 {
781         mh_appdata_t *ad = (mh_appdata_t*)data;
782         Evas_Object *btn = NULL;
783
784         if (data == NULL) {
785                 ERR("The param is NULL\n");
786                 return NULL;
787         }
788
789         if (!strcmp("elm.swallow.end", part)) {
790                 if (ad->main.wifi_state == MH_STATE_PROCESS) {
791                         btn = _create_progressbar(obj, "process_medium");
792                 } else {
793                         btn = elm_check_add(obj);
794                         elm_object_style_set(btn, "on&off");
795
796                         evas_object_propagate_events_set(btn, EINA_FALSE);
797                         evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
798                         evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
799                         elm_check_state_set(btn, ad->main.hotspot_mode &
800                                 VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI ? EINA_TRUE : EINA_FALSE);
801
802                         evas_object_smart_callback_add(btn, "changed", __wifi_onoff_changed_cb, ad);
803                         evas_object_show(btn);
804                 }
805         }
806
807         return btn;
808 }
809
810 static char *__get_bt_label(void *data, Evas_Object *obj, const char *part)
811 {
812         if (!strcmp("elm.text", part))
813                 return strdup(STR_BLUETOOTH_TETH);
814
815         return NULL;
816 }
817
818 static Evas_Object *__get_bt_icon(void *data, Evas_Object *obj, const char *part)
819 {
820         mh_appdata_t *ad = (mh_appdata_t *)data;
821         Evas_Object *btn = NULL;
822
823         if (data == NULL) {
824                 ERR("The param is NULL\n");
825                 return NULL;
826         }
827
828         if (!strcmp("elm.swallow.end", part)) {
829                 if (ad->main.bt_state == MH_STATE_PROCESS) {
830                         btn = _create_progressbar(obj, "process_medium");
831                 } else {
832                         btn = elm_check_add(obj);
833                         if (btn == NULL) {
834                                 ERR("btn is NULL\n");
835                                 return NULL;
836                         }
837                         elm_object_style_set(btn, "on&off");
838                         evas_object_pass_events_set(btn, EINA_TRUE);
839                         evas_object_propagate_events_set(btn, EINA_FALSE);
840                         elm_check_state_set(btn, ad->main.hotspot_mode &
841                                 VCONFKEY_MOBILE_HOTSPOT_MODE_BT ? EINA_TRUE : EINA_FALSE);
842                         evas_object_show(btn);
843                         evas_object_smart_callback_add(btn, "changed", __bt_onoff_changed_cb, ad);
844                 }
845         }
846
847         return btn;
848 }
849
850 static char *__get_usb_label(void *data, Evas_Object *obj, const char *part)
851 {
852         if (!strcmp("elm.text", part))
853                 return strdup(STR_USB_TETH);
854
855         return NULL;
856 }
857
858 static Evas_Object *__get_usb_icon(void *data, Evas_Object *obj,
859                                                         const char *part)
860 {
861         mh_appdata_t *ad = (mh_appdata_t *)data;
862         Evas_Object *btn = NULL;
863
864         if (data == NULL) {
865                 ERR("The param is NULL\n");
866                 return NULL;
867         }
868
869         if (!strcmp("elm.swallow.end", part)) {
870                 if (ad->main.usb_state == MH_STATE_PROCESS) {
871                         btn = _create_progressbar(obj, "process_medium");
872                 } else {
873                         btn = elm_check_add(obj);
874                         if (btn == NULL) {
875                                 ERR("btn is NULL\n");
876                                 return NULL;
877                         }
878                         elm_object_style_set(btn, "on&off");
879                         evas_object_pass_events_set(btn, EINA_TRUE);
880                         evas_object_propagate_events_set(btn, EINA_FALSE);
881                         elm_check_state_set(btn, ad->main.hotspot_mode &
882                                 VCONFKEY_MOBILE_HOTSPOT_MODE_USB ? EINA_TRUE : EINA_FALSE);
883                         evas_object_show(btn);
884                         evas_object_smart_callback_add(btn, "changed", __usb_onoff_changed_cb, ad);
885                 }
886         }
887
888         return btn;
889 }
890
891 static char *__get_help_label(void *data, Evas_Object *obj, const char *part)
892 {
893         mh_appdata_t *ad = (mh_appdata_t *)data;
894         char buf[MH_LABEL_LENGTH_MAX] = {0, };
895         char device_name[MH_LABEL_LENGTH_MAX] = {0, };
896         char passphrase[MH_LABEL_LENGTH_MAX] = {0, };
897         char security_type[MH_LABEL_LENGTH_MAX] = {0, };
898         char *fmt = STR_SECURITY_TYPE_PS;
899         char *hidden = "";
900         char *ptr = NULL;
901         char *device_name_utf = NULL;
902         int wifi_state = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
903
904         if (data == NULL) {
905                 ERR("The param is NULL\n");
906                 return NULL;
907         }
908
909         if (!strcmp("elm.text.multiline", part)) {
910                 device_name_utf = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
911                 if (device_name_utf == NULL) {
912                         ERR("vconf_get_str failed \n");
913                         return NULL;
914                 }
915
916                 ptr = elm_entry_utf8_to_markup(device_name_utf);
917                 if (ptr == NULL) {
918                         g_free(device_name_utf);
919                         ERR("elm_entry_utf8_to_markup is failed\n");
920                         return NULL;
921                 }
922
923                 g_strlcpy(ad->setup.device_name, ptr,
924                                 sizeof(ad->setup.device_name));
925                 g_strlcpy(device_name, ptr, MH_LABEL_LENGTH_MAX);
926                 g_free(device_name_utf);
927                 g_free(ptr);
928                 ptr = NULL;
929
930                 if (ad->setup.security_type != TETHERING_WIFI_SECURITY_TYPE_NONE) {
931                         ptr = elm_entry_utf8_to_markup(ad->setup.wifi_passphrase);
932                         if (ptr == NULL) {
933                                 ERR("elm_entry_utf8_to_markup is failed\n");
934                                 return NULL;
935                         }
936                         g_strlcpy(passphrase, ptr, MH_LABEL_LENGTH_MAX);
937                         g_free(ptr);
938
939                         snprintf(security_type, sizeof(security_type),
940                                         fmt, "WPA2 PSK");
941                 }
942
943                 wifi_state = ad->main.hotspot_mode & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI;
944
945                 if (wifi_state && ad->setup.visibility == false)
946                         hidden = STR_MOBILE_HOTSPOT_IS_HIDDEN;
947
948                 if (wifi_state && ad->setup.security_type != TETHERING_WIFI_SECURITY_TYPE_NONE) {
949                         snprintf(buf, MH_LABEL_LENGTH_MAX,
950                                         "<font_size=30>"
951                                         "%s: %s<br>"
952                                         "%s: %s<br>"
953                                         "%s<br>"
954                                         "%s%s"
955                                         "%s"
956                                         "</font_size>",
957                                         STR_DEV_NAME,
958                                         device_name,
959                                         STR_PASSWORD,
960                                         passphrase,
961                                         security_type,
962                                         STR_ENTER_THE_PASSWORD_ON_THE_OTHER_DEVICE,
963                                         hidden[0] != '\0' ? "<br>" : "",
964                                         hidden);
965                 } else {
966                         snprintf(buf, MH_LABEL_LENGTH_MAX,
967                                         "<font_size=30>"
968                                         "%s: %s%s"
969                                         "%s"
970                                         "</font_size>",
971                                         STR_DEV_NAME,
972                                         device_name,
973                                         hidden[0] != '\0' ? "<br>" : "",
974                                         hidden);
975                 }
976
977                 return strdup(buf);
978         }
979
980         return NULL;
981 }
982
983 static char *__get_device_label(void *data, Evas_Object *obj,
984                                                         const char *part)
985 {
986         char buf[MH_LABEL_LENGTH_MAX] = {0, };
987
988         if (data == NULL) {
989                 ERR("The param is NULL\n");
990                 return NULL;
991         }
992
993         if (!strcmp("elm.text", part)) {
994                 snprintf(buf, MH_LABEL_LENGTH_MAX, "<font_size=30>%s</font_size>", STR_CONNECTED_DEV);
995                 return strdup(buf);
996         }
997
998         return NULL;
999 }
1000
1001 #ifdef TETHERING_DATA_USAGE_SUPPORT
1002 static char *__get_usage_label(void *data, Evas_Object *obj, const char *part)
1003 {
1004         mh_appdata_t *ad = (mh_appdata_t*)data;
1005         unsigned long long total = 0;
1006         unsigned long long sent = 0;
1007         unsigned long long received = 0;
1008         char *fmt_str;
1009         char buf[MH_LABEL_LENGTH_MAX] = {0, };
1010         char label[MH_LABEL_LENGTH_MAX] = {0, };
1011
1012         if (data == NULL) {
1013                 ERR("The param is NULL\n");
1014                 return NULL;
1015         }
1016
1017         if (!strcmp("elm.text", part)) {
1018                 g_strlcpy(label, STR_DATA_USAGE, sizeof(label));
1019                 return strdup(label);
1020         } else if (!strcmp("elm.text.multiline", part)) {
1021                 sent = ad->data_statistics.pdp_total_sent;
1022                 received = ad->data_statistics.pdp_total_receive;
1023
1024                 if (sent >= MH_MB || received >= MH_MB) {
1025                         sent /= MH_MB;
1026                         received /= MH_MB;
1027
1028                         total = sent + received;
1029                         fmt_str = STR_MB;
1030                 } else if (sent + received >= MH_MB) {
1031                         total = (sent + received) / MH_MB;
1032                         fmt_str = STR_MB;
1033                 } else if (sent >= MH_KB || received >= MH_KB) {
1034                         sent /= MH_KB;
1035                         received /= MH_KB;
1036
1037                         total = sent + received;
1038                         fmt_str = STR_KB;
1039                 } else if (sent + received >= MH_KB) {
1040                         total = (sent + received) / MH_KB;
1041                         fmt_str = STR_KB;
1042                 } else {
1043                         total = sent + received;
1044                         fmt_str = STR_BYTE;
1045                 }
1046
1047                 if (total > INT_MAX) {
1048                         ERR("data usage overflow\n");
1049                         total = 0;
1050                 }
1051                 snprintf(label, MH_LABEL_LENGTH_MAX, fmt_str, (int)total);
1052                 return strdup(label);
1053         }
1054
1055         return NULL;
1056 }
1057 #endif
1058
1059 static void __set_genlist_itc(mh_appdata_t *ad)
1060 {
1061         /* On, Off view's item class for genlist */
1062         ad->main.wifi_itc = elm_genlist_item_class_new();
1063         if (ad->main.wifi_itc == NULL) {
1064                 ERR("elm_genlist_item_class_new failed\n");
1065                 return;
1066         }
1067
1068         ad->main.wifi_itc->item_style = MH_GENLIST_1LINE_TEXT_ICON_STYLE;
1069         ad->main.wifi_itc->func.text_get = __get_wifi_label;
1070         ad->main.wifi_itc->func.content_get =  __get_wifi_icon;
1071         ad->main.wifi_itc->func.state_get = NULL;
1072         ad->main.wifi_itc->func.del = NULL;
1073
1074         /* End of On, Off view's item class for genlist */
1075
1076         /* Off view's item class for genlist */
1077         ad->main.bt_itc = elm_genlist_item_class_new();
1078         if (ad->main.bt_itc == NULL) {
1079                 ERR("elm_genlist_item_class_new failed\n");
1080                 return;
1081         }
1082
1083         ad->main.bt_itc->item_style = MH_GENLIST_1LINE_TEXT_ICON_STYLE;
1084         ad->main.bt_itc->func.text_get = __get_bt_label;
1085         ad->main.bt_itc->func.content_get = __get_bt_icon;
1086         ad->main.bt_itc->func.state_get = NULL;
1087         ad->main.bt_itc->func.del = NULL;
1088
1089         ad->main.usb_itc = elm_genlist_item_class_new();
1090         if (ad->main.usb_itc == NULL) {
1091                 ERR("elm_genlist_item_class_new failed\n");
1092                 return;
1093         }
1094
1095         ad->main.usb_itc->item_style = MH_GENLIST_1LINE_TEXT_ICON_STYLE;
1096         ad->main.usb_itc->func.text_get = __get_usb_label;
1097         ad->main.usb_itc->func.content_get = __get_usb_icon;
1098         ad->main.usb_itc->func.state_get = NULL;
1099         ad->main.usb_itc->func.del = NULL;
1100
1101         ad->main.help_itc = elm_genlist_item_class_new();
1102         if (ad->main.help_itc == NULL) {
1103                 ERR("elm_genlist_item_class_new failed\n");
1104                 return;
1105         }
1106
1107         ad->main.help_itc->item_style = MH_GENLIST_MULTILINE_TEXT_STYLE;
1108         ad->main.help_itc->func.text_get = __get_help_label;
1109         ad->main.help_itc->func.content_get = NULL;
1110         ad->main.help_itc->func.state_get = NULL;
1111         ad->main.help_itc->func.del = NULL;
1112
1113         /* End of Off view's item class for genlist */
1114
1115
1116         ad->main.device_itc = elm_genlist_item_class_new();
1117         if (ad->main.device_itc == NULL) {
1118                 ERR("elm_genlist_item_class_new failed\n");
1119                 return;
1120         }
1121
1122         ad->main.device_itc->item_style = MH_GENLIST_GROUP_INDEX_STYLE;
1123         ad->main.device_itc->func.text_get = __get_device_label;
1124         ad->main.device_itc->func.content_get = NULL;
1125         ad->main.device_itc->func.state_get = NULL;
1126         ad->main.device_itc->func.del = NULL;
1127
1128 #ifdef TETHERING_DATA_USAGE_SUPPORT
1129         ad->main.usage_itc = elm_genlist_item_class_new();
1130         if (ad->main.usage_itc == NULL) {
1131                 ERR("elm_genlist_item_class_new failed\n");
1132                 return;
1133         }
1134
1135         ad->main.usage_itc->item_style = MH_GENLIST_MULTILINE_TEXT_STYLE;
1136         ad->main.usage_itc->func.text_get = __get_usage_label;
1137         ad->main.usage_itc->func.content_get = NULL;
1138         ad->main.usage_itc->func.state_get = NULL;
1139         ad->main.usage_itc->func.del = NULL;
1140 #endif
1141         /* End of On view's item class for genlist */
1142         return;
1143 }
1144
1145 static void __gl_realized(void *data, Evas_Object *obj, void *event_info)
1146 {
1147         if (data == NULL || event_info == NULL) {
1148                 ERR("Invalid param\n");
1149                 return;
1150         }
1151
1152         mh_appdata_t *ad = (mh_appdata_t *)data;
1153         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
1154         Evas_Object *ao;
1155         Evas_Object *btn;
1156         char str[MH_LABEL_LENGTH_MAX] = {0, };
1157         int i = 0;
1158
1159         if (item == ad->main.wifi_item || item == ad->main.bt_item || item == ad->main.usb_item) {
1160                 ao = elm_object_item_access_object_get(item);
1161                 btn = elm_object_item_part_content_get(item, "on&off");
1162                 snprintf(str, sizeof(str), "%s, %s", "On/off button",
1163                                 (elm_check_state_get(btn) ? "On" : "Off"));
1164                 elm_access_info_set(ao, ELM_ACCESS_CONTEXT_INFO, str);
1165
1166                 if (item == ad->main.wifi_item || item == ad->main.bt_item) {
1167                         DBG("Wi-Fi or BT item : %p\n", item);
1168                         elm_object_item_signal_emit(item, "elm,state,top", "");
1169                 } else if (item == ad->main.usb_item) {
1170                         DBG("USB item\n");
1171                         elm_object_item_signal_emit(item, "elm,state,bottom", "");
1172                 }
1173         } else if (item == ad->main.setup_item) {
1174                 DBG("setup_item\n");
1175                 ao = elm_object_item_access_object_get(item);
1176                 elm_access_info_set(ao, ELM_ACCESS_CONTEXT_INFO, "Item");
1177
1178                 elm_object_item_signal_emit(item, "elm,state,bottom", "");
1179         } else if (item == ad->main.device_item) {
1180                 DBG("device_item\n");
1181                 ao = elm_object_item_access_object_get(item);
1182                 snprintf(str, sizeof(str), "%s, %s", "Expandable list",
1183                                 "Double tap to open list");
1184                 elm_access_info_set(ao, ELM_ACCESS_CONTEXT_INFO, str);
1185
1186                 elm_object_item_signal_emit(item, "elm,state,top", "");
1187         } else if (ad->main.device_item != NULL &&
1188                         ad->main.device_item == elm_genlist_item_parent_get(item)) {
1189                 DBG("device_item's child\n");
1190                 elm_object_item_signal_emit(item, "elm,state,center", "");
1191         } else {
1192                 for (i = 0; i < 4; i++) {
1193                         if (item == ad->main.sp_item[i])
1194                                 elm_object_item_access_unregister(item);
1195                 }
1196         }
1197 #ifdef TETHERING_DATA_USAGE_SUPPORT
1198         if (item == ad->main.usage_item) {
1199                         DBG("usage_item\n");
1200                         elm_object_item_signal_emit(item, "elm,state,bottom", "");
1201         }
1202 #endif
1203         return;
1204 }
1205
1206 static void __create_inner_contents(mh_appdata_t *ad)
1207 {
1208         __MOBILE_AP_FUNC_ENTER__;
1209
1210         Elm_Object_Item *item = NULL;
1211         int no_of_dev = 0;
1212
1213         __read_setting(ad);
1214         ad->main.genlist = elm_genlist_add(ad->naviframe);
1215         elm_genlist_mode_set(ad->main.genlist, ELM_LIST_COMPRESS);
1216         evas_object_smart_callback_add(ad->main.genlist, "realized", __gl_realized, ad);
1217
1218         __set_genlist_itc(ad);
1219
1220         item = elm_genlist_item_append(ad->main.genlist, ad->main.wifi_itc,
1221                         ad, NULL, ELM_GENLIST_ITEM_NONE,
1222                         __select_wifi_item, ad);
1223         ad->main.wifi_item = item;
1224
1225         if (ad->main.hotspot_mode & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI) {
1226                 item = elm_genlist_item_append(ad->main.genlist, ad->main.help_itc,
1227                                 ad, NULL, ELM_GENLIST_ITEM_NONE,
1228                                 NULL, NULL);
1229                 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1230                 ad->main.help_item = item;
1231         }
1232
1233         item = elm_genlist_item_append(ad->main.genlist, ad->main.bt_itc,
1234                         ad, NULL, ELM_GENLIST_ITEM_NONE,
1235                         __select_bt_item, ad);
1236         ad->main.bt_item = item;
1237
1238         item = elm_genlist_item_append(ad->main.genlist, ad->main.usb_itc,
1239                         ad, NULL, ELM_GENLIST_ITEM_NONE,
1240                         __select_usb_item, ad);
1241         ad->main.usb_item = item;
1242         if (_get_vconf_usb_state() == VCONFKEY_SYSMAN_USB_DISCONNECTED) {
1243                 if (ad->main.usb_item)
1244                         elm_object_item_disabled_set(ad->main.usb_item, EINA_TRUE);
1245         } else {
1246                 if (ad->main.usb_item)
1247                         elm_object_item_disabled_set(ad->main.usb_item, EINA_FALSE);
1248         }
1249         if (ad->main.hotspot_mode & (VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI |
1250                                 VCONFKEY_MOBILE_HOTSPOT_MODE_USB |
1251                                 VCONFKEY_MOBILE_HOTSPOT_MODE_BT)) {
1252 #ifdef TETHERING_DATA_USAGE_SUPPORT
1253                 item = elm_genlist_item_append(ad->main.genlist, ad->main.usage_itc,
1254                                 ad, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
1255                 elm_genlist_item_select_mode_set(item,
1256                                 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1257                 ad->main.usage_item = item;
1258 #endif
1259                 /* Insert "Connected devices" item */
1260                 tethering_foreach_connected_clients(ad->handle, TETHERING_TYPE_ALL,
1261                                 _connected_clients_cb, (void *)ad);
1262
1263                 no_of_dev = _get_list_clients_count(ad);
1264                 if (no_of_dev != 0) {
1265                         item = elm_genlist_item_append(ad->main.genlist,
1266                                                 ad->main.device_itc, ad, NULL,
1267                                                 ELM_GENLIST_ITEM_NONE, NULL, NULL);
1268                         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1269                         _list_connected_dev(ad);
1270                         _update_conn_clients(ad);
1271                 }
1272                 ad->main.device_item = item;
1273         }
1274
1275         if (ad->main.hotspot_mode & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI_AP) {
1276                 if (ad->main.wifi_item)
1277                         elm_object_item_disabled_set(ad->main.wifi_item, EINA_TRUE);
1278                 if (ad->main.setup_item)
1279                         elm_object_item_disabled_set(ad->main.setup_item, EINA_TRUE);
1280                 if (ad->main.bt_item)
1281                         elm_object_item_disabled_set(ad->main.bt_item, EINA_TRUE);
1282                 if (ad->main.usb_item)
1283                         elm_object_item_disabled_set(ad->main.usb_item, EINA_TRUE);
1284         }
1285
1286         __MOBILE_AP_FUNC_EXIT__;
1287         return;
1288 }
1289
1290 void _main_free_genlist_itc(mh_appdata_t *ad)
1291 {
1292         __MOBILE_AP_FUNC_ENTER__;
1293
1294         if (ad == NULL)
1295                 return;
1296
1297         mh_main_view_t *mv = &ad->main;
1298
1299 #ifdef TETHERING_DATA_USAGE_SUPPORT
1300         _free_genlist_itc(&mv->usage_itc);
1301 #endif
1302         _free_genlist_itc(&mv->device_itc);
1303         _free_genlist_itc(&mv->device0_itc);
1304         _free_genlist_itc(&mv->help_itc);
1305         _free_genlist_itc(&mv->usb_itc);
1306         _free_genlist_itc(&mv->bt_itc);
1307         _free_genlist_itc(&mv->setup_itc);
1308         _free_genlist_itc(&mv->wifi_itc);
1309         __MOBILE_AP_FUNC_EXIT__;
1310         return;
1311 }
1312
1313 void _main_callback_del(mh_appdata_t *ad)
1314 {
1315         __MOBILE_AP_FUNC_ENTER__;
1316
1317         if (ad == NULL) {
1318                 ERR("ad is NULL\n");
1319                 return;
1320         }
1321
1322         Evas_Object *obj;
1323
1324         obj = elm_object_item_part_content_get(ad->main.wifi_item, "elm.swallow.end");
1325         if (obj != NULL)
1326                 evas_object_smart_callback_del(obj, "changed", __wifi_onoff_changed_cb);
1327
1328         obj = elm_object_item_part_content_get(ad->main.bt_item, "elm.swallow.end");
1329         if (obj != NULL)
1330                 evas_object_smart_callback_del(obj, "changed", __bt_onoff_changed_cb);
1331
1332         obj = elm_object_item_part_content_get(ad->main.usb_item, "elm.swallow.end");
1333         if (obj != NULL)
1334                 evas_object_smart_callback_del(obj, "changed", __usb_onoff_changed_cb);
1335
1336         evas_object_smart_callback_del(ad->main.genlist, "realized", __gl_realized);
1337
1338         __MOBILE_AP_FUNC_EXIT__;
1339 }
1340
1341 void _ctxpopup_more_button_callback_add(mh_appdata_t *ad)
1342 {
1343         eext_object_event_callback_add(ad->naviframe, EEXT_CALLBACK_MORE,
1344                         __create_ctxpopup_more_button, ad);
1345 }
1346
1347 void _ctxpopup_more_button_callback_del(mh_appdata_t *ad)
1348 {
1349         eext_object_event_callback_del(ad->naviframe, EEXT_CALLBACK_MORE,
1350                         __create_ctxpopup_more_button);
1351 }
1352
1353 static void __ctx_move_more_ctxpopup(Evas_Object *ctx, mh_appdata_t *ad)
1354 {
1355         Evas_Coord w;
1356         Evas_Coord h;
1357         int pos = -1;
1358         __MOBILE_AP_FUNC_ENTER__;
1359
1360         elm_win_screen_size_get(ad->win, NULL, NULL, &w, &h);
1361         pos = elm_win_rotation_get(ad->win);
1362
1363         switch (pos) {
1364         case 0:
1365         case 180:
1366                 evas_object_move(ctx, w/2, h);
1367                 break;
1368         case 90:
1369                 evas_object_move(ctx, h/2, w);
1370                 break;
1371         case 270:
1372                 evas_object_move(ctx, h/2, w);
1373                 break;
1374         }
1375         __MOBILE_AP_FUNC_EXIT__;
1376 }
1377
1378 static void __rotate_more_ctxpopup_cb(void *data, Evas_Object *obj, void *event_info)
1379 {
1380         __MOBILE_AP_FUNC_ENTER__;
1381
1382         mh_appdata_t *ad = (mh_appdata_t *)data;
1383         Evas_Object *ctx = ad->ctxpopup;
1384
1385         __ctx_move_more_ctxpopup(ctx, ad);
1386         evas_object_show(ctx);
1387
1388         __MOBILE_AP_FUNC_EXIT__;
1389 }
1390
1391 static void __dismissed_more_ctxpopup_cb(void *data, Evas_Object *obj, void *event)
1392 {
1393         __MOBILE_AP_FUNC_ENTER__;
1394
1395         mh_appdata_t *ad = (mh_appdata_t *)data;
1396         Evas_Object *ctx = ad->ctxpopup;
1397
1398         if (!rotate_flag) {
1399                 evas_object_del(ctx);
1400                 ctx = NULL;
1401         } else {
1402                 __ctx_move_more_ctxpopup(ctx, ad);
1403                 evas_object_show(ctx);
1404                 rotate_flag = EINA_FALSE;
1405         }
1406         __MOBILE_AP_FUNC_EXIT__;
1407 }
1408
1409 static void __ctx_delete_more_ctxpopup_cb(void *data, Evas *e, Evas_Object *obj,
1410                 void *event_info)
1411 {
1412         Evas_Object *navi = (Evas_Object *)data;
1413         Evas_Object *ctx = obj;
1414
1415         if (navi == NULL) {
1416                 ERR("data is null\n");
1417                 return;
1418         }
1419         __MOBILE_AP_FUNC_ENTER__;
1420
1421         evas_object_smart_callback_del(ctx, "dismissed",
1422                         __dismissed_more_ctxpopup_cb);
1423         evas_object_smart_callback_del(elm_object_top_widget_get(ctx),
1424                         "rotation,changed", __rotate_more_ctxpopup_cb);
1425         evas_object_event_callback_del_full(ctx, EVAS_CALLBACK_DEL,
1426                         __ctx_delete_more_ctxpopup_cb, navi);
1427         __MOBILE_AP_FUNC_EXIT__;
1428 }
1429
1430 static void __gl_configure_wifi_tethering(void *data, Evas_Object *obj, void *event_info)
1431 {
1432         __MOBILE_AP_FUNC_ENTER__;
1433
1434         if (data == NULL) {
1435                 ERR("The param is NULL\n");
1436                 return;
1437         }
1438         mh_appdata_t *ad = (mh_appdata_t *)data;
1439
1440         evas_object_del(ad->ctxpopup);
1441         ad->ctxpopup = NULL;
1442
1443         elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
1444         _ctxpopup_more_button_callback_del(ad);
1445         mh_draw_wifi_setup_view(ad);
1446
1447         __MOBILE_AP_FUNC_EXIT__;
1448
1449         return;
1450 }
1451
1452 static void __create_ctxpopup_more_button(void *data, Evas_Object *obj,
1453                 void *event_info)
1454 {
1455         mh_appdata_t *ad = (mh_appdata_t *)data;
1456         Evas_Object *ctxpopup = NULL;
1457
1458         if (ad == NULL) {
1459                 ERR("ad is null\n");
1460                 return;
1461         }
1462         __MOBILE_AP_FUNC_ENTER__;
1463
1464         ctxpopup = elm_ctxpopup_add(ad->win);
1465         elm_ctxpopup_auto_hide_disabled_set(ctxpopup, EINA_TRUE);
1466
1467         eext_object_event_callback_add(ctxpopup, EEXT_CALLBACK_BACK,
1468                         eext_ctxpopup_back_cb, ad);
1469         eext_object_event_callback_add(ctxpopup, EEXT_CALLBACK_MORE,
1470                         eext_ctxpopup_back_cb, ad);
1471         elm_object_style_set(ctxpopup, "more/default");
1472         evas_object_smart_callback_add(ctxpopup, "dismissed",
1473                         __dismissed_more_ctxpopup_cb, ad);
1474         evas_object_smart_callback_add(elm_object_top_widget_get(ctxpopup), "rotation,changed",
1475                         __rotate_more_ctxpopup_cb, ad);
1476         evas_object_event_callback_add(ctxpopup, EVAS_CALLBACK_DEL,
1477                         __ctx_delete_more_ctxpopup_cb, ad->naviframe);
1478
1479         elm_ctxpopup_direction_priority_set(ctxpopup, ELM_CTXPOPUP_DIRECTION_UP,
1480                         ELM_CTXPOPUP_DIRECTION_DOWN,
1481                         ELM_CTXPOPUP_DIRECTION_UNKNOWN,
1482                         ELM_CTXPOPUP_DIRECTION_UNKNOWN);
1483
1484         __ctx_move_more_ctxpopup(ctxpopup, ad);
1485         elm_ctxpopup_item_append(ctxpopup, STR_CONFIGURE_MOBILE_HOTSPOT,
1486                         NULL, __gl_configure_wifi_tethering, ad);
1487
1488         evas_object_show(ctxpopup);
1489
1490         ad->ctxpopup = ctxpopup;
1491
1492         __MOBILE_AP_FUNC_EXIT__;
1493 }
1494
1495
1496 void _main_draw_contents(mh_appdata_t *ad)
1497 {
1498         INFO("+\n");
1499
1500         Elm_Object_Item *navi_item;
1501
1502         __create_inner_contents(ad);
1503
1504         ad->main.back_btn = elm_button_add(ad->naviframe);
1505         if (ad->main.back_btn == NULL) {
1506                 ERR("elm_button_add is failed\n");
1507                 if (ad->main.genlist) {
1508                         evas_object_del(ad->main.genlist);
1509                         ad->main.genlist = NULL;
1510                 }
1511                 return;
1512         }
1513         elm_object_style_set(ad->main.back_btn, "naviframe/back_btn/default");
1514
1515         eext_object_event_callback_add(ad->naviframe, EEXT_CALLBACK_BACK,
1516                         eext_naviframe_back_cb, NULL);
1517         _ctxpopup_more_button_callback_add(ad);
1518         evas_object_smart_callback_add(ad->main.back_btn, "clicked", (Evas_Smart_Cb)__back_btn_cb, (void *)ad);
1519         elm_object_focus_allow_set(ad->main.back_btn, EINA_FALSE);
1520
1521         navi_item = elm_naviframe_item_push(ad->naviframe, IDS_TETH,
1522                                 ad->main.back_btn, NULL, ad->main.genlist, NULL);
1523         elm_object_item_domain_text_translatable_set(navi_item, PKGNAME, EINA_TRUE);
1524
1525         elm_naviframe_item_pop_cb_set(navi_item, (Elm_Naviframe_Item_Pop_Cb)__back_btn_cb, (void *)ad);
1526         ad->navi_item = navi_item;
1527         g_ad = ad;
1528         INFO("-\n");
1529         return;
1530 }