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