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