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