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