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