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