4 * Copyright 2012 Samsung Electronics Co., Ltd
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
10 * http://www.tizenopensource.org/license
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.
22 #include <efl_extension.h>
23 #include <dpm/restriction.h>
25 #include "mh_view_main.h"
27 #include "mh_string.h"
29 void _genlist_update_device_item(mh_appdata_t *ad);
30 mh_appdata_t *g_ad = NULL;
31 #define UPDATE_INTERVAL 1
33 void _select_connected_dev(void *data, Evas_Object *obj, void *event_info)
35 __MOBILE_AP_FUNC_ENTER__;
38 ERR("data is NULL\n");
42 mh_appdata_t *ad = (mh_appdata_t *)data;
44 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
45 _create_connected_client_view(ad);
46 __MOBILE_AP_FUNC_EXIT__;
49 static bool _connected_clients_cb(tethering_client_h client, void *user_data)
51 __MOBILE_AP_FUNC_ENTER__;
53 if (user_data == NULL) {
54 ERR("user_data is NULL\n");
58 mh_appdata_t *ad = (mh_appdata_t *)user_data;
60 _append_list_client_handle(ad, client);
62 __MOBILE_AP_FUNC_EXIT__;
66 void ap_update_data_device(mh_appdata_t *ad)
68 __MOBILE_AP_FUNC_ENTER__;
71 ERR("Invalid param\n");
75 _genlist_update_device_item(ad);
77 __MOBILE_AP_FUNC_EXIT__;
80 #ifdef TETHERING_DATA_USAGE_SUPPORT
81 Eina_Bool ap_update_data_packet_usage(mh_appdata_t *ad)
84 ERR("Invalid param\n");
88 if (ad->main.usage_item)
89 elm_genlist_item_update(ad->main.usage_item);
94 Eina_Bool ap_get_data_statistics(void *data)
97 ERR("The param is NULL\n");
98 return ECORE_CALLBACK_CANCEL;
100 mh_appdata_t *ad = (mh_appdata_t *)data;
102 if (ad->main.hotspot_mode == VCONFKEY_MOBILE_HOTSPOT_MODE_NONE) {
103 ad->update_statistics_handle = NULL;
104 return ECORE_CALLBACK_CANCEL;
107 /* If previous data is not updated, new data is not required */
108 if (ad->data_statistics.is_updated == false)
109 return ECORE_CALLBACK_RENEW;
111 /* Because previous data is updated, new data is required.
112 It will be returned asynchronously. */
113 tethering_get_data_usage(ad->handle, _data_usage_cb, (void *)ad);
114 ad->data_statistics.is_updated = false;
116 return ECORE_CALLBACK_RENEW;
120 Eina_Bool ap_update_device_conn_time(void * data)
123 ERR("The param is NULL\n");
124 return ECORE_CALLBACK_CANCEL;
126 mh_appdata_t *ad = (mh_appdata_t *)data;
129 if (ad->main.hotspot_mode == VCONFKEY_MOBILE_HOTSPOT_MODE_NONE) {
130 _stop_update_device_conn_time(ad);
131 __MOBILE_AP_FUNC_EXIT__;
132 return ECORE_CALLBACK_CANCEL;
135 while (count < ad->connected_device.no_of_clients) {
136 if (ad->connected_device.station_items[count])
137 elm_genlist_item_fields_update(ad->connected_device.station_items[count++],
138 "elm.text.sub", ELM_GENLIST_ITEM_FIELD_TEXT);
140 return ECORE_CALLBACK_RENEW;
143 void _start_update_device_conn_time(mh_appdata_t *ad)
145 __MOBILE_AP_FUNC_ENTER__;
148 ERR("Invalid param\n");
149 __MOBILE_AP_FUNC_EXIT__;
153 if (ad->update_conn_time_handle)
154 _stop_update_device_conn_time(ad);
156 ad->update_conn_time_handle = ecore_timer_add(UPDATE_INTERVAL,
157 ap_update_device_conn_time, (void *)ad);
159 __MOBILE_AP_FUNC_EXIT__;
162 void _stop_update_device_conn_time(mh_appdata_t *ad)
164 __MOBILE_AP_FUNC_ENTER__;
167 ERR("Invalid param\n");
171 if (ad->update_conn_time_handle) {
172 ecore_timer_del(ad->update_conn_time_handle);
173 ad->update_conn_time_handle = NULL;
175 __MOBILE_AP_FUNC_EXIT__;
178 #ifdef TETHERING_DATA_USAGE_SUPPORT
179 void _start_update_data_packet_usage(mh_appdata_t *ad)
181 __MOBILE_AP_FUNC_ENTER__;
184 ERR("Invalid param\n");
188 if (ad->update_statistics_handle)
189 _stop_update_data_packet_usage(ad);
191 ad->data_statistics.is_updated = false;
192 tethering_get_data_usage(ad->handle, _data_usage_cb, (void *)ad);
193 ad->update_statistics_handle = ecore_timer_add(MH_UPDATE_INTERVAL,
194 ap_get_data_statistics, (void *)ad);
196 __MOBILE_AP_FUNC_EXIT__;
200 void _stop_update_data_packet_usage(mh_appdata_t *ad)
202 __MOBILE_AP_FUNC_ENTER__;
205 ERR("Invalid param\n");
209 if (ad->update_statistics_handle) {
210 ecore_timer_del(ad->update_statistics_handle);
211 ad->data_statistics.is_updated = false;
212 ad->update_statistics_handle = NULL;
215 __MOBILE_AP_FUNC_EXIT__;
220 static void __read_setting(mh_appdata_t *ad)
222 __MOBILE_AP_FUNC_ENTER__;
225 ERR("Invalid param\n");
231 char *passphrase = NULL;
233 tethering_wifi_security_type_e type;
235 ad->main.hotspot_mode = _get_vconf_hotspot_mode();
237 #ifdef TETHERING_DATA_USAGE_SUPPORT
238 ad->data_statistics.pdp_total_sent = 0;
239 ad->data_statistics.pdp_total_receive = 0;
240 if (ad->main.hotspot_mode != VCONFKEY_MOBILE_HOTSPOT_MODE_NONE)
241 tethering_get_data_usage(ad->handle, _data_usage_cb, (void *)ad);
244 ret = tethering_wifi_get_ssid(ad->handle, &ssid);
245 if (ret != TETHERING_ERROR_NONE || ssid == NULL) {
246 ERR("tethering_wifi_get_ssid is failed : %d\n", ret);
249 g_strlcpy(ad->setup.device_name, ssid, sizeof(ad->setup.device_name));
252 ret = tethering_wifi_get_passphrase(ad->handle, &passphrase);
253 if (ret != TETHERING_ERROR_NONE || passphrase == NULL) {
254 ERR("tethering_wifi_get_passphrase is failed : %d\n", ret);
258 g_strlcpy(ad->setup.wifi_passphrase, passphrase,
259 sizeof(ad->setup.wifi_passphrase));
260 g_strlcpy(ad->setup.wifi_passphrase_new, passphrase,
261 sizeof(ad->setup.wifi_passphrase_new));
264 ret = tethering_wifi_get_ssid_visibility(ad->handle, &visibility);
265 if (ret != TETHERING_ERROR_NONE)
266 ERR("tethering_wifi_get_ssid_visibility is failed\n");
268 ad->setup.visibility = visibility;
269 ad->setup.visibility_new = visibility;
271 ret = tethering_wifi_get_security_type(ad->handle, &type);
272 if (ret != TETHERING_ERROR_NONE)
273 ERR("tethering_wifi_get_security_type is failed\n");
275 ad->setup.security_type = type;
276 ad->setup.security_type_new = type;
278 __MOBILE_AP_FUNC_EXIT__;
281 void _update_wifi_item(mh_appdata_t *ad, int wifi_state)
283 __MOBILE_AP_FUNC_ENTER__;
285 if (ad->main.wifi_state == wifi_state)
288 if (ad->main.wifi_state == MH_STATE_PROCESS) {
289 ad->main.wifi_state = MH_STATE_NONE;
290 elm_genlist_item_select_mode_set(ad->main.wifi_item, ELM_OBJECT_SELECT_MODE_DEFAULT);
291 } else if (ad->main.wifi_state == MH_STATE_NONE) {
292 ad->main.wifi_state = MH_STATE_PROCESS;
293 elm_genlist_item_select_mode_set(ad->main.wifi_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
296 if (ad->main.wifi_item)
297 elm_genlist_item_update(ad->main.wifi_item);
299 if (ad->main.setup_item)
300 elm_object_item_signal_emit(ad->main.setup_item, "elm,state,bottom", "");
302 __MOBILE_AP_FUNC_EXIT__;
307 void _update_bt_item(mh_appdata_t *ad, int bt_state)
309 __MOBILE_AP_FUNC_ENTER__;
311 if (ad->main.bt_state == bt_state)
314 if (ad->main.bt_state == MH_STATE_PROCESS) {
315 ad->main.bt_state = MH_STATE_NONE;
316 elm_genlist_item_select_mode_set(ad->main.bt_item, ELM_OBJECT_SELECT_MODE_DEFAULT);
317 } else if (ad->main.bt_state == MH_STATE_NONE) {
318 ad->main.bt_state = MH_STATE_PROCESS;
319 elm_genlist_item_select_mode_set(ad->main.bt_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
322 if (ad->main.bt_item)
323 elm_genlist_item_update(ad->main.bt_item);
325 __MOBILE_AP_FUNC_EXIT__;
330 void _update_usb_item(mh_appdata_t *ad, int usb_state)
332 __MOBILE_AP_FUNC_ENTER__;
334 if (ad->main.usb_state == usb_state)
337 if (ad->main.usb_state == MH_STATE_PROCESS) {
338 ad->main.usb_state = MH_STATE_NONE;
339 elm_genlist_item_select_mode_set(ad->main.usb_item, ELM_OBJECT_SELECT_MODE_DEFAULT);
340 } else if (ad->main.usb_state == MH_STATE_NONE) {
341 ad->main.usb_state = MH_STATE_PROCESS;
342 elm_genlist_item_select_mode_set(ad->main.usb_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
345 elm_genlist_item_update(ad->main.usb_item);
347 __MOBILE_AP_FUNC_EXIT__;
352 void _genlist_update_device_item(mh_appdata_t *ad)
354 __MOBILE_AP_FUNC_ENTER__;
357 ERR("Invalid param\n");
360 unsigned int no_of_dev = 0;
361 no_of_dev = _get_list_clients_count(ad);
362 Elm_Object_Item *item = NULL;
364 if (ad->main.device_item) {
365 elm_object_item_del(ad->main.device_item);
366 ad->main.device_item = NULL;
367 if (no_of_dev == 0) {
368 item = elm_genlist_item_append(ad->main.genlist,
369 ad->main.device0_itc, ad, NULL,
370 ELM_GENLIST_ITEM_NONE, NULL, NULL);
371 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
373 item = elm_genlist_item_append(ad->main.genlist,
374 ad->main.device_itc, ad, NULL,
375 ELM_GENLIST_ITEM_NONE, _select_connected_dev, (void *)ad);
376 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DEFAULT);
378 ad->main.device_item = item;
381 if (ad->connected_device.navi_it)
382 _update_conn_clients(ad);
384 __MOBILE_AP_FUNC_EXIT__;
388 void _update_main_view(mh_appdata_t *ad, tethering_type_e type)
390 __MOBILE_AP_FUNC_ENTER__;
393 ERR("Invalid param\n");
397 int state = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
398 Eina_Bool wifi_state = EINA_FALSE;
399 Eina_Bool bt_state = EINA_FALSE;
400 Eina_Bool usb_state = EINA_FALSE;
401 Eina_Bool wifi_ap_state = EINA_FALSE;
402 Elm_Object_Item *item = NULL;
406 ad->main.hotspot_mode = _get_vconf_hotspot_mode();
407 state = ad->main.hotspot_mode;
409 wifi_state = (Eina_Bool)(state & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI);
410 bt_state = (Eina_Bool)(state & VCONFKEY_MOBILE_HOTSPOT_MODE_BT);
411 usb_state = (Eina_Bool)(state & VCONFKEY_MOBILE_HOTSPOT_MODE_USB);
412 wifi_ap_state = (Eina_Bool)(state & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI_AP);
415 if (ad->main.wifi_item)
416 elm_object_item_disabled_set(ad->main.wifi_item, EINA_TRUE);
417 if (ad->main.setup_item)
418 elm_object_item_disabled_set(ad->main.setup_item, EINA_TRUE);
419 if (ad->main.bt_item)
420 elm_object_item_disabled_set(ad->main.bt_item, EINA_TRUE);
421 if (ad->main.usb_item)
422 elm_object_item_disabled_set(ad->main.usb_item, EINA_TRUE);
424 if (ad->main.setup_item)
425 elm_object_item_disabled_set(ad->main.setup_item, EINA_FALSE);
426 if (ad->main.bt_item)
427 elm_object_item_disabled_set(ad->main.bt_item, EINA_FALSE);
428 if (_get_vconf_usb_state() != VCONFKEY_SYSMAN_USB_AVAILABLE) {
429 if (ad->main.usb_item)
430 elm_object_item_disabled_set(ad->main.usb_item, EINA_TRUE);
432 if (ad->main.usb_item)
433 elm_object_item_disabled_set(ad->main.usb_item, EINA_FALSE);
437 if (wifi_state || bt_state || usb_state) {
438 #ifdef TETHERING_DATA_USAGE_SUPPORT
439 if (ad->main.usage_item == NULL) {
440 item = elm_genlist_item_insert_before(ad->main.genlist,
441 ad->main.usage_itc, ad, NULL,
443 ELM_GENLIST_ITEM_NONE, NULL, NULL);
444 elm_genlist_item_select_mode_set(item,
445 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
446 ad->main.usage_item = item;
450 no_of_dev = _get_list_clients_count(ad);
451 if (ad->main.device_item == NULL) {
452 if (no_of_dev == 0) {
453 item = elm_genlist_item_append(ad->main.genlist,
454 ad->main.device0_itc, ad, NULL,
455 ELM_GENLIST_ITEM_NONE, NULL, NULL);
456 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
458 item = elm_genlist_item_append(ad->main.genlist,
459 ad->main.device_itc, ad, NULL,
460 ELM_GENLIST_ITEM_NONE, _select_connected_dev, (void *)ad);
461 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DEFAULT);
463 ad->main.device_item = item;
466 if (ad->main.device_item) {
467 elm_object_item_del(ad->main.device_item);
468 ad->main.device_item = NULL;
470 #ifdef TETHERING_DATA_USAGE_SUPPORT
471 if (ad->main.usage_item) {
472 elm_object_item_del(ad->main.usage_item);
473 ad->main.usage_item = NULL;
479 if (ad->main.help_item) {
480 elm_genlist_item_update(ad->main.help_item);
482 item = elm_genlist_item_insert_after(ad->main.genlist,
483 ad->main.help_itc, ad, NULL,
485 ELM_GENLIST_ITEM_NONE, NULL,
488 ERR("elm_genlist_item_insert_after NULL\n");
490 elm_genlist_item_select_mode_set(item,
491 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
492 ad->main.help_item = item;
496 if (ad->main.help_item) {
497 elm_object_item_del(ad->main.help_item);
498 ad->main.help_item = NULL;
503 case TETHERING_TYPE_WIFI:
504 /* Update Wi-Fi tethering on / off button */
505 if (ad->main.wifi_state != MH_STATE_NONE) {
506 _update_wifi_item(ad, MH_STATE_NONE);
508 obj = elm_object_item_part_content_get(ad->main.wifi_item, "elm.swallow.end");
510 elm_check_state_set(obj, wifi_state);
512 if (ad->main.wifi_item)
513 elm_genlist_item_update(ad->main.wifi_item);
517 case TETHERING_TYPE_BT:
518 /* Update BT tethering on / off button */
519 if (ad->main.bt_state != MH_STATE_NONE) {
520 _update_bt_item(ad, MH_STATE_NONE);
522 obj = elm_object_item_part_content_get(ad->main.bt_item, "elm.swallow.end");
524 elm_check_state_set(obj, bt_state);
526 if (ad->main.bt_item)
527 elm_genlist_item_update(ad->main.bt_item);
531 case TETHERING_TYPE_USB:
532 /* Update USB tethering on / off button */
533 if (ad->main.usb_state != MH_STATE_NONE) {
534 _update_usb_item(ad, MH_STATE_NONE);
536 obj = elm_object_item_part_content_get(ad->main.usb_item, "elm.swallow.end");
538 elm_check_state_set(obj, usb_state);
540 if (ad->main.usb_item)
541 elm_genlist_item_update(ad->main.usb_item);
546 DBG("Unknown tethering type : %d\n", type);
550 __MOBILE_AP_FUNC_EXIT__;
555 static int __is_allowed(tethering_type_e type)
558 device_policy_manager_h dpm = NULL;
560 dpm = dpm_manager_create();
562 ERR("Failed to create device policy manager!!");
567 case TETHERING_TYPE_WIFI:
568 dpm_restriction_get_wifi_hotspot_state(dpm, &state);
570 case TETHERING_TYPE_USB:
571 dpm_restriction_get_usb_tethering_state(dpm, &state);
573 case TETHERING_TYPE_BT:
574 dpm_restriction_get_bluetooth_tethering_state(dpm, &state);
580 dpm_manager_destroy(dpm);
585 static void __wifi_onoff_changed_cb(void *data, Evas_Object *obj,
588 __MOBILE_AP_FUNC_ENTER__;
590 if (!__is_allowed(TETHERING_TYPE_WIFI)) {
591 ERR("Wi-Fi tethering is restricted!!");
592 elm_check_state_set(obj, EINA_FALSE);
593 _create_security_restriction_noti(TETHERING_TYPE_WIFI);
598 ERR("The param is NULL\n");
602 mh_appdata_t *ad = (mh_appdata_t *)data;
604 _update_wifi_item(ad, MH_STATE_PROCESS);
605 ad->type = TETHERING_TYPE_WIFI;
606 ad->is_wifi_teth_enabling = true;
607 if (_handle_wifi_onoff_change(ad) != 0) {
608 ERR("_handle_wifi_onoff_change is failed\n");
609 _update_wifi_item(ad, MH_STATE_NONE);
610 ad->is_wifi_teth_enabling = false;
613 __MOBILE_AP_FUNC_EXIT__;
618 static void __select_wifi_item(void *data, Evas_Object *obj, void *event_info)
620 __MOBILE_AP_FUNC_ENTER__;
623 ERR("The param is NULL\n");
626 mh_appdata_t *ad = (mh_appdata_t *)data;
628 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
629 mh_draw_wifi_setup_view(ad);
631 __MOBILE_AP_FUNC_EXIT__;
636 static void __bt_onoff_changed_cb(void *data, Evas_Object *obj, void *event_info)
638 __MOBILE_AP_FUNC_ENTER__;
640 if (!__is_allowed(TETHERING_TYPE_BT)) {
641 ERR("BT tethering is restricted!!");
642 elm_check_state_set(obj, EINA_FALSE);
643 _create_security_restriction_noti(TETHERING_TYPE_BT);
648 ERR("The param is NULL\n");
652 mh_appdata_t *ad = (mh_appdata_t *)data;
654 _update_bt_item(ad, MH_STATE_PROCESS);
655 ad->type = TETHERING_TYPE_BT;
656 ad->is_bt_teth_enabling = true;
658 if (_handle_bt_onoff_change(ad) != 0) {
659 ERR("_handle_bt_onoff_change is failed\n");
660 _update_bt_item(ad, MH_STATE_NONE);
661 ad->is_bt_teth_enabling = false;
664 __MOBILE_AP_FUNC_EXIT__;
669 static void __select_bt_item(void *data, Evas_Object *obj, void *event_info)
671 __MOBILE_AP_FUNC_ENTER__;
673 Evas_Object *content;
674 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
677 ERR("The param is NULL\n");
681 elm_genlist_item_selected_set(item, EINA_FALSE);
683 content = elm_object_item_part_content_get(item, "elm.icon");
684 __bt_onoff_changed_cb(data, content, NULL);
686 __MOBILE_AP_FUNC_EXIT__;
691 static void __usb_onoff_changed_cb(void *data, Evas_Object *obj, void *event_info)
693 __MOBILE_AP_FUNC_ENTER__;
695 if (!__is_allowed(TETHERING_TYPE_USB)) {
696 ERR("USB tethering is restricted!!");
697 elm_check_state_set(obj, EINA_FALSE);
698 _create_security_restriction_noti(TETHERING_TYPE_USB);
703 ERR("The param is NULL\n");
707 mh_appdata_t *ad = (mh_appdata_t *)data;
708 _update_usb_item(ad, MH_STATE_PROCESS);
709 ad->type = TETHERING_TYPE_USB;
710 ad->is_usb_teth_enabling = true;
711 if (_handle_usb_onoff_change(ad) != 0) {
712 ERR("_handle_usb_onoff_change is failed\n");
713 _update_usb_item(ad, MH_STATE_NONE);
714 ad->is_usb_teth_enabling = false;
717 __MOBILE_AP_FUNC_EXIT__;
722 static void __select_usb_item(void *data, Evas_Object *obj, void *event_info)
724 __MOBILE_AP_FUNC_ENTER__;
726 Evas_Object *content;
727 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
730 ERR("The param is NULL\n");
734 elm_genlist_item_selected_set(item, EINA_FALSE);
736 content = elm_object_item_part_content_get(item, "elm.icon");
737 __usb_onoff_changed_cb(data, content, NULL);
739 __MOBILE_AP_FUNC_EXIT__;
744 static void __back_btn_cb(void *data, Elm_Object_Item *navi_item)
749 ERR("The param is NULL\n");
753 mh_appdata_t *ad = (mh_appdata_t*)data;
755 _release_list_client_handle(ad);
756 _main_callback_del(ad);
758 ug_destroy_me(((mh_ugdata_t *)ad->gadget)->ug);
764 static char *__get_wifi_label(void *data, Evas_Object *obj, const char *part)
766 if (!strcmp("elm.text", part))
767 return strdup(STR_WIFI_TETH);
772 static Evas_Object *__get_wifi_icon(void *data, Evas_Object *obj,
775 mh_appdata_t *ad = (mh_appdata_t*)data;
776 Evas_Object *btn = NULL;
779 ERR("The param is NULL\n");
783 if (!strcmp("elm.swallow.end", part)) {
784 if (ad->main.wifi_state == MH_STATE_PROCESS) {
785 btn = _create_progressbar(obj, "process_medium");
787 btn = elm_check_add(obj);
788 elm_object_style_set(btn, "on&off");
790 evas_object_propagate_events_set(btn, EINA_FALSE);
791 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
792 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
793 elm_check_state_set(btn, ad->main.hotspot_mode &
794 VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI ? EINA_TRUE : EINA_FALSE);
796 evas_object_smart_callback_add(btn, "changed", __wifi_onoff_changed_cb, ad);
797 evas_object_show(btn);
804 static char *__get_bt_label(void *data, Evas_Object *obj, const char *part)
806 if (!strcmp("elm.text", part))
807 return strdup(STR_BLUETOOTH_TETH);
812 static Evas_Object *__get_bt_icon(void *data, Evas_Object *obj, const char *part)
814 mh_appdata_t *ad = (mh_appdata_t *)data;
815 Evas_Object *btn = NULL;
818 ERR("The param is NULL\n");
822 if (!strcmp("elm.swallow.end", part)) {
823 if (ad->main.bt_state == MH_STATE_PROCESS) {
824 btn = _create_progressbar(obj, "process_medium");
826 btn = elm_check_add(obj);
828 ERR("btn is NULL\n");
831 elm_object_style_set(btn, "on&off");
832 evas_object_pass_events_set(btn, EINA_TRUE);
833 evas_object_propagate_events_set(btn, EINA_FALSE);
834 elm_check_state_set(btn, ad->main.hotspot_mode &
835 VCONFKEY_MOBILE_HOTSPOT_MODE_BT ? EINA_TRUE : EINA_FALSE);
836 evas_object_show(btn);
837 evas_object_smart_callback_add(btn, "changed", __bt_onoff_changed_cb, ad);
844 static char *__get_usb_label(void *data, Evas_Object *obj, const char *part)
846 if (!strcmp("elm.text", part))
847 return strdup(STR_USB_TETH);
852 static Evas_Object *__get_usb_icon(void *data, Evas_Object *obj,
855 mh_appdata_t *ad = (mh_appdata_t *)data;
856 Evas_Object *btn = NULL;
859 ERR("The param is NULL\n");
863 if (!strcmp("elm.swallow.end", part)) {
864 if (ad->main.usb_state == MH_STATE_PROCESS) {
865 btn = _create_progressbar(obj, "process_medium");
867 btn = elm_check_add(obj);
869 ERR("btn is NULL\n");
872 elm_object_style_set(btn, "on&off");
873 evas_object_pass_events_set(btn, EINA_TRUE);
874 evas_object_propagate_events_set(btn, EINA_FALSE);
875 elm_check_state_set(btn, ad->main.hotspot_mode &
876 VCONFKEY_MOBILE_HOTSPOT_MODE_USB ? EINA_TRUE : EINA_FALSE);
877 evas_object_show(btn);
878 evas_object_smart_callback_add(btn, "changed", __usb_onoff_changed_cb, ad);
885 static char *__get_help_label(void *data, Evas_Object *obj, const char *part)
887 mh_appdata_t *ad = (mh_appdata_t *)data;
888 char buf[MH_LABEL_LENGTH_MAX] = {0, };
889 char device_name[MH_LABEL_LENGTH_MAX] = {0, };
890 char passphrase[MH_LABEL_LENGTH_MAX] = {0, };
891 char security_type[MH_LABEL_LENGTH_MAX] = {0, };
892 char *fmt = STR_SECURITY_TYPE_PS;
895 char *device_name_utf = NULL;
896 int wifi_state = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
899 ERR("The param is NULL\n");
903 if (!strcmp("elm.text.multiline", part)) {
904 device_name_utf = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
905 if (device_name_utf == NULL) {
906 ERR("vconf_get_str failed \n");
910 ptr = elm_entry_utf8_to_markup(device_name_utf);
912 g_free(device_name_utf);
913 ERR("elm_entry_utf8_to_markup is failed\n");
917 g_strlcpy(ad->setup.device_name, ptr,
918 sizeof(ad->setup.device_name));
919 g_strlcpy(device_name, ptr, MH_LABEL_LENGTH_MAX);
920 g_free(device_name_utf);
924 if (ad->setup.security_type != TETHERING_WIFI_SECURITY_TYPE_NONE) {
925 ptr = elm_entry_utf8_to_markup(ad->setup.wifi_passphrase);
927 ERR("elm_entry_utf8_to_markup is failed\n");
930 g_strlcpy(passphrase, ptr, MH_LABEL_LENGTH_MAX);
933 snprintf(security_type, sizeof(security_type),
937 wifi_state = ad->main.hotspot_mode & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI;
939 if (wifi_state && ad->setup.visibility == false)
940 hidden = STR_WIFI_TETH_HIDDEN;
942 if (wifi_state && ad->setup.security_type != TETHERING_WIFI_SECURITY_TYPE_NONE) {
943 snprintf(buf, MH_LABEL_LENGTH_MAX,
956 STR_PASSWORD_FOR_WIFI_TETH,
957 hidden[0] != '\0' ? "<br>" : "",
960 snprintf(buf, MH_LABEL_LENGTH_MAX,
967 hidden[0] != '\0' ? "<br>" : "",
977 static char *__get_no_connected_device_label(void *data, Evas_Object *obj,
980 mh_appdata_t *ad = (mh_appdata_t*)data;
981 char buf[MH_LABEL_LENGTH_MAX] = {0, };
985 ERR("The param is NULL\n");
989 if (!strcmp("elm.text.multiline", part)) {
990 no_of_dev = _get_list_clients_count(ad);
991 snprintf(buf, MH_LABEL_LENGTH_MAX, "<font_size=30>%s<br>%d</font_size>", STR_CONNECTED_DEV, no_of_dev);
998 static char *__get_connected_device_label(void *data, Evas_Object *obj,
1001 mh_appdata_t *ad = (mh_appdata_t*)data;
1002 char buf[MH_LABEL_LENGTH_MAX] = {0, };
1006 ERR("The param is NULL\n");
1010 if (!strcmp("elm.text.sub", part)) {
1011 g_strlcpy(buf, STR_CONNECTED_DEV, sizeof(buf));
1013 } else if (!strcmp("elm.text", part)) {
1014 no_of_dev = _get_list_clients_count(ad);
1015 snprintf(buf, MH_LABEL_LENGTH_MAX, "%d", no_of_dev);
1022 #ifdef TETHERING_DATA_USAGE_SUPPORT
1023 static char *__get_usage_label(void *data, Evas_Object *obj, const char *part)
1025 mh_appdata_t *ad = (mh_appdata_t*)data;
1026 unsigned long long total = 0;
1027 unsigned long long sent = 0;
1028 unsigned long long received = 0;
1030 char buf[MH_LABEL_LENGTH_MAX] = {0, };
1031 char label[MH_LABEL_LENGTH_MAX] = {0, };
1034 ERR("The param is NULL\n");
1038 if (!strcmp("elm.text", part)) {
1039 g_strlcpy(label, STR_DATA_USAGE, sizeof(label));
1040 return strdup(label);
1041 } else if (!strcmp("elm.text.multiline", part)) {
1042 sent = ad->data_statistics.pdp_total_sent;
1043 received = ad->data_statistics.pdp_total_receive;
1045 if (sent >= MH_MB || received >= MH_MB) {
1049 total = sent + received;
1051 } else if (sent + received >= MH_MB) {
1052 total = (sent + received) / MH_MB;
1054 } else if (sent >= MH_KB || received >= MH_KB) {
1058 total = sent + received;
1060 } else if (sent + received >= MH_KB) {
1061 total = (sent + received) / MH_KB;
1064 total = sent + received;
1068 if (total > INT_MAX) {
1069 ERR("data usage overflow\n");
1072 snprintf(label, MH_LABEL_LENGTH_MAX, fmt_str, (int)total);
1073 return strdup(label);
1080 static void __set_genlist_itc(mh_appdata_t *ad)
1082 /* On, Off view's item class for genlist */
1083 ad->main.wifi_itc = elm_genlist_item_class_new();
1084 if (ad->main.wifi_itc == NULL) {
1085 ERR("elm_genlist_item_class_new failed\n");
1089 ad->main.wifi_itc->item_style = MH_GENLIST_1LINE_TEXT_ICON_STYLE;
1090 ad->main.wifi_itc->func.text_get = __get_wifi_label;
1091 ad->main.wifi_itc->func.content_get = __get_wifi_icon;
1092 ad->main.wifi_itc->func.state_get = NULL;
1093 ad->main.wifi_itc->func.del = NULL;
1095 /* End of On, Off view's item class for genlist */
1097 /* Off view's item class for genlist */
1098 ad->main.bt_itc = elm_genlist_item_class_new();
1099 if (ad->main.bt_itc == NULL) {
1100 ERR("elm_genlist_item_class_new failed\n");
1104 ad->main.bt_itc->item_style = MH_GENLIST_1LINE_TEXT_ICON_STYLE;
1105 ad->main.bt_itc->func.text_get = __get_bt_label;
1106 ad->main.bt_itc->func.content_get = __get_bt_icon;
1107 ad->main.bt_itc->func.state_get = NULL;
1108 ad->main.bt_itc->func.del = NULL;
1110 ad->main.usb_itc = elm_genlist_item_class_new();
1111 if (ad->main.usb_itc == NULL) {
1112 ERR("elm_genlist_item_class_new failed\n");
1116 ad->main.usb_itc->item_style = MH_GENLIST_1LINE_TEXT_ICON_STYLE;
1117 ad->main.usb_itc->func.text_get = __get_usb_label;
1118 ad->main.usb_itc->func.content_get = __get_usb_icon;
1119 ad->main.usb_itc->func.state_get = NULL;
1120 ad->main.usb_itc->func.del = NULL;
1122 ad->main.help_itc = elm_genlist_item_class_new();
1123 if (ad->main.help_itc == NULL) {
1124 ERR("elm_genlist_item_class_new failed\n");
1128 ad->main.help_itc->item_style = MH_GENLIST_MULTILINE_TEXT_STYLE;
1129 ad->main.help_itc->func.text_get = __get_help_label;
1130 ad->main.help_itc->func.content_get = NULL;
1131 ad->main.help_itc->func.state_get = NULL;
1132 ad->main.help_itc->func.del = NULL;
1134 /* End of Off view's item class for genlist */
1136 /* On view's item class for genlist */
1137 ad->main.device0_itc = elm_genlist_item_class_new();
1138 if (ad->main.device0_itc == NULL) {
1139 ERR("elm_genlist_item_class_new failed\n");
1143 ad->main.device0_itc->item_style = MH_GENLIST_MULTILINE_TEXT_STYLE;
1144 ad->main.device0_itc->func.text_get = __get_no_connected_device_label;
1145 ad->main.device0_itc->func.content_get = NULL;
1146 ad->main.device0_itc->func.state_get = NULL;
1147 ad->main.device0_itc->func.del = NULL;
1149 ad->main.device_itc = elm_genlist_item_class_new();
1150 if (ad->main.device_itc == NULL) {
1151 ERR("elm_genlist_item_class_new failed\n");
1155 ad->main.device_itc->item_style = MH_GENLIST_2LINE_BOTTOM_TEXT_STYLE;
1156 ad->main.device_itc->func.text_get = __get_connected_device_label;
1157 ad->main.device_itc->func.content_get = NULL;
1158 ad->main.device_itc->func.state_get = NULL;
1159 ad->main.device_itc->func.del = NULL;
1161 #ifdef TETHERING_DATA_USAGE_SUPPORT
1162 ad->main.usage_itc = elm_genlist_item_class_new();
1163 if (ad->main.usage_itc == NULL) {
1164 ERR("elm_genlist_item_class_new failed\n");
1168 ad->main.usage_itc->item_style = MH_GENLIST_MULTILINE_TEXT_STYLE;
1169 ad->main.usage_itc->func.text_get = __get_usage_label;
1170 ad->main.usage_itc->func.content_get = NULL;
1171 ad->main.usage_itc->func.state_get = NULL;
1172 ad->main.usage_itc->func.del = NULL;
1174 /* End of On view's item class for genlist */
1178 static void __gl_realized(void *data, Evas_Object *obj, void *event_info)
1180 if (data == NULL || event_info == NULL) {
1181 ERR("Invalid param\n");
1185 mh_appdata_t *ad = (mh_appdata_t *)data;
1186 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
1189 char str[MH_LABEL_LENGTH_MAX] = {0, };
1192 if (item == ad->main.wifi_item || item == ad->main.bt_item || item == ad->main.usb_item) {
1193 ao = elm_object_item_access_object_get(item);
1194 btn = elm_object_item_part_content_get(item, "on&off");
1195 snprintf(str, sizeof(str), "%s, %s", "On/off button",
1196 (elm_check_state_get(btn) ? "On" : "Off"));
1197 elm_access_info_set(ao, ELM_ACCESS_CONTEXT_INFO, str);
1199 if (item == ad->main.wifi_item || item == ad->main.bt_item) {
1200 DBG("Wi-Fi or BT item : %p\n", item);
1201 elm_object_item_signal_emit(item, "elm,state,top", "");
1202 } else if (item == ad->main.usb_item) {
1204 elm_object_item_signal_emit(item, "elm,state,bottom", "");
1206 } else if (item == ad->main.setup_item) {
1207 DBG("setup_item\n");
1208 ao = elm_object_item_access_object_get(item);
1209 elm_access_info_set(ao, ELM_ACCESS_CONTEXT_INFO, "Item");
1211 elm_object_item_signal_emit(item, "elm,state,bottom", "");
1212 } else if (item == ad->main.device_item) {
1213 DBG("device_item\n");
1214 ao = elm_object_item_access_object_get(item);
1215 snprintf(str, sizeof(str), "%s, %s", "Expandable list",
1216 "Double tap to open list");
1217 elm_access_info_set(ao, ELM_ACCESS_CONTEXT_INFO, str);
1219 elm_object_item_signal_emit(item, "elm,state,top", "");
1220 } else if (ad->main.device_item != NULL &&
1221 ad->main.device_item == elm_genlist_item_parent_get(item)) {
1222 DBG("device_item's child\n");
1223 elm_object_item_signal_emit(item, "elm,state,center", "");
1225 for (i = 0; i < 4; i++) {
1226 if (item == ad->main.sp_item[i])
1227 elm_object_item_access_unregister(item);
1230 #ifdef TETHERING_DATA_USAGE_SUPPORT
1231 if (item == ad->main.usage_item) {
1232 DBG("usage_item\n");
1233 elm_object_item_signal_emit(item, "elm,state,bottom", "");
1239 static void __create_inner_contents(mh_appdata_t *ad)
1241 __MOBILE_AP_FUNC_ENTER__;
1243 Elm_Object_Item *item = NULL;
1247 ad->main.genlist = elm_genlist_add(ad->naviframe);
1248 elm_genlist_mode_set(ad->main.genlist, ELM_LIST_COMPRESS);
1249 evas_object_smart_callback_add(ad->main.genlist, "realized", __gl_realized, ad);
1251 __set_genlist_itc(ad);
1253 item = elm_genlist_item_append(ad->main.genlist, ad->main.wifi_itc,
1254 ad, NULL, ELM_GENLIST_ITEM_NONE,
1255 __select_wifi_item, ad);
1256 ad->main.wifi_item = item;
1258 if (ad->main.hotspot_mode & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI) {
1259 item = elm_genlist_item_append(ad->main.genlist, ad->main.help_itc,
1260 ad, NULL, ELM_GENLIST_ITEM_NONE,
1262 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1263 ad->main.help_item = item;
1266 item = elm_genlist_item_append(ad->main.genlist, ad->main.bt_itc,
1267 ad, NULL, ELM_GENLIST_ITEM_NONE,
1268 __select_bt_item, ad);
1269 ad->main.bt_item = item;
1271 item = elm_genlist_item_append(ad->main.genlist, ad->main.usb_itc,
1272 ad, NULL, ELM_GENLIST_ITEM_NONE,
1273 __select_usb_item, ad);
1274 ad->main.usb_item = item;
1275 if (_get_vconf_usb_state() != VCONFKEY_SYSMAN_USB_AVAILABLE) {
1276 if (ad->main.usb_item)
1277 elm_object_item_disabled_set(ad->main.usb_item, EINA_TRUE);
1279 if (ad->main.usb_item)
1280 elm_object_item_disabled_set(ad->main.usb_item, EINA_FALSE);
1282 if (ad->main.hotspot_mode & (VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI |
1283 VCONFKEY_MOBILE_HOTSPOT_MODE_USB |
1284 VCONFKEY_MOBILE_HOTSPOT_MODE_BT)) {
1285 #ifdef TETHERING_DATA_USAGE_SUPPORT
1286 item = elm_genlist_item_append(ad->main.genlist, ad->main.usage_itc,
1287 ad, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
1288 elm_genlist_item_select_mode_set(item,
1289 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1290 ad->main.usage_item = item;
1292 /* Insert "Connected devices" item */
1293 tethering_foreach_connected_clients(ad->handle, TETHERING_TYPE_ALL,
1294 _connected_clients_cb, (void *)ad);
1296 no_of_dev = _get_list_clients_count(ad);
1297 if (no_of_dev == 0) {
1298 item = elm_genlist_item_append(ad->main.genlist,
1299 ad->main.device0_itc, ad, NULL,
1300 ELM_GENLIST_ITEM_NONE, NULL, NULL);
1301 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1303 item = elm_genlist_item_append(ad->main.genlist,
1304 ad->main.device_itc, ad, NULL,
1305 ELM_GENLIST_ITEM_NONE, _select_connected_dev, (void *)ad);
1306 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DEFAULT);
1308 ad->main.device_item = item;
1311 if (ad->main.hotspot_mode & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI_AP) {
1312 if (ad->main.wifi_item)
1313 elm_object_item_disabled_set(ad->main.wifi_item, EINA_TRUE);
1314 if (ad->main.setup_item)
1315 elm_object_item_disabled_set(ad->main.setup_item, EINA_TRUE);
1316 if (ad->main.bt_item)
1317 elm_object_item_disabled_set(ad->main.bt_item, EINA_TRUE);
1318 if (ad->main.usb_item)
1319 elm_object_item_disabled_set(ad->main.usb_item, EINA_TRUE);
1322 __MOBILE_AP_FUNC_EXIT__;
1326 void _main_free_genlist_itc(mh_appdata_t *ad)
1328 __MOBILE_AP_FUNC_ENTER__;
1333 mh_main_view_t *mv = &ad->main;
1335 #ifdef TETHERING_DATA_USAGE_SUPPORT
1336 _free_genlist_itc(&mv->usage_itc);
1338 _free_genlist_itc(&mv->device_itc);
1339 _free_genlist_itc(&mv->device0_itc);
1340 _free_genlist_itc(&mv->help_itc);
1341 _free_genlist_itc(&mv->usb_itc);
1342 _free_genlist_itc(&mv->bt_itc);
1343 _free_genlist_itc(&mv->setup_itc);
1344 _free_genlist_itc(&mv->wifi_itc);
1345 __MOBILE_AP_FUNC_EXIT__;
1349 void _main_callback_del(mh_appdata_t *ad)
1351 __MOBILE_AP_FUNC_ENTER__;
1354 ERR("ad is NULL\n");
1360 obj = elm_object_item_part_content_get(ad->main.wifi_item, "elm.swallow.end");
1362 evas_object_smart_callback_del(obj, "changed", __wifi_onoff_changed_cb);
1364 obj = elm_object_item_part_content_get(ad->main.bt_item, "elm.swallow.end");
1366 evas_object_smart_callback_del(obj, "changed", __bt_onoff_changed_cb);
1368 obj = elm_object_item_part_content_get(ad->main.usb_item, "elm.swallow.end");
1370 evas_object_smart_callback_del(obj, "changed", __usb_onoff_changed_cb);
1372 evas_object_smart_callback_del(ad->main.genlist, "realized", __gl_realized);
1374 __MOBILE_AP_FUNC_EXIT__;
1377 void _main_draw_contents(mh_appdata_t *ad)
1381 Elm_Object_Item *navi_item;
1383 __create_inner_contents(ad);
1385 ad->main.back_btn = elm_button_add(ad->naviframe);
1386 if (ad->main.back_btn == NULL) {
1387 ERR("elm_button_add is failed\n");
1388 if (ad->main.genlist) {
1389 evas_object_del(ad->main.genlist);
1390 ad->main.genlist = NULL;
1394 elm_object_style_set(ad->main.back_btn, "naviframe/back_btn/default");
1396 eext_object_event_callback_add(ad->naviframe, EEXT_CALLBACK_BACK,
1397 eext_naviframe_back_cb, NULL);
1399 evas_object_smart_callback_add(ad->main.back_btn, "clicked", (Evas_Smart_Cb)__back_btn_cb, (void *)ad);
1400 elm_object_focus_allow_set(ad->main.back_btn, EINA_FALSE);
1402 navi_item = elm_naviframe_item_push(ad->naviframe, IDS_TETH,
1403 ad->main.back_btn, NULL, ad->main.genlist, NULL);
1404 elm_object_item_domain_text_translatable_set(navi_item, PKGNAME, EINA_TRUE);
1406 elm_naviframe_item_pop_cb_set(navi_item, (Elm_Naviframe_Item_Pop_Cb)__back_btn_cb, (void *)ad);
1407 ad->navi_item = navi_item;