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