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