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