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.
20 #include "mh_view_main.h"
22 static void _gl_device_item_sel(void *data, Evas_Object *obj, void *event_info);
23 static void _gl_exp(void *data, Evas_Object *obj, void *event_info);
24 static void _gl_con(void *data, Evas_Object *obj, void *event_info);
26 static bool _connected_clients_cb(tethering_client_h client, void *user_data)
28 if (user_data == NULL) {
29 ERR("user_data is NULL\n");
33 mh_appdata_t *ad = (mh_appdata_t *)user_data;
34 int i = ad->clients.number++;
36 tethering_client_clone(&(ad->clients.handle[i]), client);
41 static void __genlist_update_device_subitem(mh_appdata_t *ad)
43 __MOBILE_AP_FUNC_ENTER__;
46 ERR("Invalid param\n");
50 Elm_Object_Item *item = NULL;
51 tethering_type_e connection_type = 0;
54 for (i = 0; i < ad->clients.number; i++) {
55 tethering_client_get_tethering_type(ad->clients.handle[i], &connection_type);
57 item = elm_genlist_item_append(ad->main.genlist,
58 ad->main.dev_itc[connection_type],
59 (void *)ad->clients.handle[i],
60 ad->main.device_item, ELM_GENLIST_ITEM_NONE,
63 ERR("elm_genlist_item_append is failed\n");
67 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
70 __MOBILE_AP_FUNC_EXIT__;
75 static void __genlist_update_device_item(mh_appdata_t *ad, int no_of_dev)
77 __MOBILE_AP_FUNC_ENTER__;
80 ERR("Invalid param\n");
84 Elm_Object_Item *item = NULL;
85 const Elm_Genlist_Item_Class *itc = NULL;
86 Elm_Genlist_Item_Type item_flags = ELM_GENLIST_ITEM_NONE;
87 Eina_Bool expanded = EINA_FALSE;
89 if (ad->main.device_item != NULL) {
90 itc = elm_genlist_item_item_class_get(ad->main.device_item);
96 if ((itc == ad->main.device0_itc && no_of_dev == 0) ||
97 (itc == ad->main.device_itc && no_of_dev > 0)) {
98 DBG("No need to change genlist item flags\n");
99 elm_genlist_item_update(ad->main.device_item);
101 expanded = elm_genlist_item_expanded_get(ad->main.device_item);
102 if (expanded == EINA_TRUE) {
103 elm_genlist_item_subitems_clear(ad->main.device_item);
104 __genlist_update_device_subitem(ad);
110 elm_genlist_item_subitems_clear(ad->main.device_item);
111 elm_object_item_del(ad->main.device_item);
112 ad->main.device_item = NULL;
115 if (no_of_dev == 0) {
116 itc = ad->main.device0_itc;
117 item_flags = ELM_GENLIST_ITEM_NONE;
118 } else if (no_of_dev > 0) {
119 itc = ad->main.device_itc;
120 item_flags = ELM_GENLIST_ITEM_TREE;
123 item = elm_genlist_item_insert_before(ad->main.genlist,
124 itc, ad, NULL, ad->main.usage_item, item_flags,
125 _gl_device_item_sel, NULL);
127 ERR("elm_genlist_item_insert_before is failed\n");
130 ad->main.device_item = item;
132 if (no_of_dev == 0) {
133 elm_genlist_item_select_mode_set(item,
134 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
135 evas_object_smart_callback_del(ad->main.genlist, "expanded",
137 evas_object_smart_callback_del(ad->main.genlist, "contracted",
139 } else if (no_of_dev > 0) {
140 evas_object_smart_callback_add(ad->main.genlist, "expanded",
142 evas_object_smart_callback_add(ad->main.genlist, "contracted",
146 __MOBILE_AP_FUNC_EXIT__;
151 void ap_update_data_device(mh_appdata_t *ad)
153 __MOBILE_AP_FUNC_ENTER__;
156 ERR("Invalid param\n");
162 if (ad->clients.number > 0) {
163 for (i = 0; i < ad->clients.number; i++) {
164 if (!ad->clients.handle[i])
167 tethering_client_destroy(ad->clients.handle[i]);
168 ad->clients.handle[i] = NULL;
171 ad->clients.number = 0;
173 tethering_foreach_connected_clients(ad->handle, TETHERING_TYPE_ALL,
174 _connected_clients_cb, (void *)ad);
175 __genlist_update_device_item(ad, ad->clients.number);
177 __MOBILE_AP_FUNC_EXIT__;
180 Eina_Bool ap_update_data_packet_usage(mh_appdata_t *ad)
183 ERR("Invalid param\n");
187 elm_genlist_item_update(ad->main.usage_item);
192 Eina_Bool ap_get_data_statistics(void *data)
195 ERR("The param is NULL\n");
196 return ECORE_CALLBACK_CANCEL;
198 mh_appdata_t *ad = (mh_appdata_t *)data;
200 if (ad->main.hotspot_mode == VCONFKEY_MOBILE_HOTSPOT_MODE_NONE) {
201 DBG("Mobile hotspot is turned off.\n");
202 ad->update_statistics_handle = NULL;
203 return ECORE_CALLBACK_CANCEL;
206 /* If previous data is not updated, new data is not required */
207 if (ad->data_statistics.is_updated == false)
208 return ECORE_CALLBACK_RENEW;
210 /* Because previous data is updated, new data is required.
211 It will be returned asynchronously. */
212 tethering_get_data_usage(ad->handle, _data_usage_cb, (void *)ad);
213 ad->data_statistics.is_updated = false;
215 return ECORE_CALLBACK_RENEW;
218 void _start_update_data_packet_usage(mh_appdata_t *ad)
220 __MOBILE_AP_FUNC_ENTER__;
223 ERR("Invalid param\n");
227 if (ad->update_statistics_handle) {
228 DBG("update_statistics_handle is not NULL.\n");
229 _stop_update_data_packet_usage(ad);
232 ad->data_statistics.is_updated = false;
233 tethering_get_data_usage(ad->handle, _data_usage_cb, (void *)ad);
234 ad->update_statistics_handle = ecore_timer_add(MH_UPDATE_INTERVAL,
235 ap_get_data_statistics, (void *)ad);
237 __MOBILE_AP_FUNC_EXIT__;
241 void _stop_update_data_packet_usage(mh_appdata_t *ad)
243 __MOBILE_AP_FUNC_ENTER__;
246 ERR("Invalid param\n");
250 if (ad->update_statistics_handle) {
251 ecore_timer_del(ad->update_statistics_handle);
252 ad->data_statistics.is_updated = false;
253 ad->update_statistics_handle = NULL;
256 __MOBILE_AP_FUNC_EXIT__;
260 static void __read_setting(mh_appdata_t *ad)
262 __MOBILE_AP_FUNC_ENTER__;
265 ERR("Invalid param\n");
271 char *passphrase = NULL;
273 ad->main.hotspot_mode = _get_vconf_hotspot_mode();
275 ret = vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_CONNECTED_DEVICE,
276 &ad->clients.number);
278 ERR("vconf_get_int is failed\n");
279 ad->clients.number = 0;
282 ad->data_statistics.pdp_total_sent = 0;
283 ad->data_statistics.pdp_total_receive = 0;
284 if (ad->main.hotspot_mode != VCONFKEY_MOBILE_HOTSPOT_MODE_NONE)
285 tethering_get_data_usage(ad->handle, _data_usage_cb, (void *)ad);
287 ret = tethering_wifi_get_ssid(ad->handle, &ssid);
288 if (ret != TETHERING_ERROR_NONE || ssid == NULL) {
289 ERR("tethering_wifi_get_ssid is failed : %d %s\n", ret, ssid);
292 g_strlcpy(ad->setup.device_name, ssid, sizeof(ad->setup.device_name));
295 ret = tethering_wifi_get_passphrase(ad->handle, &passphrase);
296 if (ret != TETHERING_ERROR_NONE || passphrase == NULL) {
297 ERR("tethering_wifi_get_ssid is failed : %d %s\n", ret, ssid);
300 g_strlcpy(ad->setup.wifi_passphrase, passphrase,
301 sizeof(ad->setup.wifi_passphrase));
304 ret = tethering_wifi_get_ssid_visibility(ad->handle, &ad->setup.visibility);
305 if (ret != TETHERING_ERROR_NONE) {
306 ERR("tethering_wifi_get_ssid_visibility is failed\n");
309 ret = tethering_wifi_get_security_type(ad->handle, &ad->setup.security_type);
310 if (ret != TETHERING_ERROR_NONE) {
311 ERR("tethering_wifi_get_security_type is failed\n");
314 DBG("VCONFKEY_MOBILE_HOTSPOT_MODE : %d\n", ad->main.hotspot_mode);
315 DBG("Device name - %s\n", ad->setup.device_name);
316 DBG("Wifi passphrase- %s\n", ad->setup.wifi_passphrase);
317 DBG("Connected device : %d\n", ad->clients.number);
318 DBG("Visibility: %d\n", ad->setup.visibility);
319 DBG("Security: %d\n", ad->setup.security_type);
320 DBG("End of Load setting value \n");
322 __MOBILE_AP_FUNC_EXIT__;
325 void _update_wifi_item(mh_appdata_t *ad, int wifi_state)
327 __MOBILE_AP_FUNC_ENTER__;
329 if (ad->main.wifi_state == wifi_state) {
330 DBG("aready updated\n");
334 if (ad->main.wifi_state == MH_STATE_PROCESS) {
335 ad->main.wifi_state = MH_STATE_NONE;
336 elm_genlist_item_select_mode_set(ad->main.wifi_item, ELM_OBJECT_SELECT_MODE_DEFAULT);
337 elm_object_item_disabled_set(ad->main.bt_item, EINA_FALSE);
338 elm_object_item_disabled_set(ad->main.usb_item, EINA_FALSE);
339 } else if (ad->main.wifi_state == MH_STATE_NONE) {
340 ad->main.wifi_state = MH_STATE_PROCESS;
341 elm_genlist_item_select_mode_set(ad->main.wifi_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
342 elm_object_item_disabled_set(ad->main.bt_item, EINA_TRUE);
343 elm_object_item_disabled_set(ad->main.usb_item, EINA_TRUE);
346 elm_genlist_item_update(ad->main.wifi_item);
348 __MOBILE_AP_FUNC_EXIT__;
353 void _update_usb_item(mh_appdata_t *ad, int usb_state)
355 __MOBILE_AP_FUNC_ENTER__;
357 if (ad->main.usb_state == usb_state) {
358 DBG("aready updated\n");
362 if (ad->main.usb_state == MH_STATE_PROCESS) {
363 ad->main.usb_state = MH_STATE_NONE;
364 elm_genlist_item_select_mode_set(ad->main.usb_item, ELM_OBJECT_SELECT_MODE_DEFAULT);
365 } else if (ad->main.usb_state == MH_STATE_NONE) {
366 ad->main.usb_state = MH_STATE_PROCESS;
367 elm_genlist_item_select_mode_set(ad->main.usb_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
370 elm_genlist_item_update(ad->main.usb_item);
372 __MOBILE_AP_FUNC_EXIT__;
377 void _update_main_view(mh_appdata_t *ad)
379 __MOBILE_AP_FUNC_ENTER__;
382 ERR("Invalid param\n");
386 int state = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
387 Eina_Bool wifi_state = EINA_FALSE;
388 Eina_Bool bt_state = EINA_FALSE;
389 Eina_Bool usb_state = EINA_FALSE;
390 Elm_Object_Item *item = NULL;
392 ad->main.hotspot_mode = _get_vconf_hotspot_mode();
393 state = ad->main.hotspot_mode;
395 ap_update_data_device(ad);
397 wifi_state = (Eina_Bool)(state & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI);
398 bt_state = (Eina_Bool)(state & VCONFKEY_MOBILE_HOTSPOT_MODE_BT);
399 usb_state = (Eina_Bool)(state & VCONFKEY_MOBILE_HOTSPOT_MODE_USB);
400 DBG("wifi_state : %d, bt_state : %d, usb_state : %d\n",
401 wifi_state, bt_state, usb_state);
403 /* Update Wi-Fi tethering on / off button */
404 if (ad->main.wifi_state != MH_STATE_NONE) {
405 _update_wifi_item(ad, MH_STATE_NONE);
407 elm_check_state_set(ad->main.wifi_btn, wifi_state);
409 elm_object_item_disabled_set(ad->main.setup_item, wifi_state);
411 /* Update BT tethering on / off button */
412 elm_check_state_set(ad->main.bt_btn, bt_state);
414 /* Update USB tethering on / off button */
415 if (ad->main.usb_state != MH_STATE_NONE) {
416 _update_usb_item(ad, MH_STATE_NONE);
418 elm_check_state_set(ad->main.usb_btn, usb_state);
421 if (wifi_state || bt_state || usb_state) {
422 _start_update_data_packet_usage(ad);
425 if (wifi_state || bt_state) {
426 if (ad->main.help_item) {
427 DBG("Just update genlist\n");
428 elm_genlist_item_update(ad->main.help_item);
431 DBG("Add help item\n");
432 item = elm_genlist_item_insert_after(ad->main.genlist,
433 ad->main.help_itc, ad, NULL,
435 ELM_GENLIST_ITEM_NONE, NULL,
438 ERR("elm_genlist_item_insert_after NULL\n");
441 ad->main.help_item = item;
444 if (!ad->main.help_item) {
445 DBG("No need to update\n");
448 DBG("Remove help item\n");
449 elm_object_item_del(ad->main.help_item);
450 ad->main.help_item = NULL;
454 __MOBILE_AP_FUNC_EXIT__;
457 static void __wifi_onoff_changed_cb(void *data, Evas_Object *obj,
460 __MOBILE_AP_FUNC_ENTER__;
463 ERR("The param is NULL\n");
467 mh_appdata_t *ad = (mh_appdata_t *)data;
468 Eina_Bool wifi_state = EINA_FALSE;
470 wifi_state = ad->main.hotspot_mode & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI ?
471 EINA_TRUE : EINA_FALSE;
473 _update_wifi_item(ad, MH_STATE_PROCESS);
474 elm_object_item_disabled_set(ad->main.setup_item, EINA_TRUE);
476 if (_handle_wifi_onoff_change(ad) != 0) {
477 ERR("_handle_wifi_onoff_change is failed\n");
478 _update_wifi_item(ad, MH_STATE_NONE);
479 elm_object_item_disabled_set(ad->main.setup_item, EINA_FALSE);
481 wifi_state = !wifi_state;
483 __MOBILE_AP_FUNC_EXIT__;
488 static void __select_wifi_item(void *data, Evas_Object *obj, void *event_info)
490 __MOBILE_AP_FUNC_ENTER__;
493 ERR("The param is NULL\n");
497 mh_appdata_t *ad = (mh_appdata_t *)data;
499 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
501 __wifi_onoff_changed_cb(data, ad->main.wifi_btn, NULL);
503 __MOBILE_AP_FUNC_EXIT__;
508 static void __select_setup_item(void *data, Evas_Object *obj, void *event_info)
510 __MOBILE_AP_FUNC_ENTER__;
512 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
513 mh_appdata_t *ad = (mh_appdata_t *)data;
516 ERR("The param is NULL\n");
520 elm_genlist_item_selected_set(item, EINA_FALSE);
521 mh_draw_wifi_setup_view(ad);
523 __MOBILE_AP_FUNC_EXIT__;
528 static void __bt_onoff_changed_cb(void *data, Evas_Object *obj, void *event_info)
530 __MOBILE_AP_FUNC_ENTER__;
533 ERR("The param is NULL\n");
537 mh_appdata_t *ad = (mh_appdata_t *)data;
540 bt_state = ad->main.hotspot_mode & VCONFKEY_MOBILE_HOTSPOT_MODE_BT ?
541 EINA_TRUE : EINA_FALSE;
543 if (_handle_bt_onoff_change(ad) == 0)
544 bt_state = !bt_state;
546 elm_check_state_set(ad->main.bt_btn, bt_state);
548 __MOBILE_AP_FUNC_EXIT__;
553 static void __select_bt_item(void *data, Evas_Object *obj, void *event_info)
555 __MOBILE_AP_FUNC_ENTER__;
557 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
558 mh_appdata_t *ad = (mh_appdata_t *)data;
561 ERR("The param is NULL\n");
565 elm_genlist_item_selected_set(item, EINA_FALSE);
567 __bt_onoff_changed_cb(data, ad->main.bt_btn, NULL);
569 __MOBILE_AP_FUNC_EXIT__;
574 static void __usb_onoff_changed_cb(void *data, Evas_Object *obj, void *event_info)
576 __MOBILE_AP_FUNC_ENTER__;
579 ERR("The param is NULL\n");
583 mh_appdata_t *ad = (mh_appdata_t *)data;
585 _update_usb_item(ad, MH_STATE_PROCESS);
586 if (_handle_usb_onoff_change(ad) != 0) {
587 ERR("_handle_usb_onoff_change is failed\n");
588 _update_usb_item(ad, MH_STATE_NONE);
591 __MOBILE_AP_FUNC_EXIT__;
596 static void __select_usb_item(void *data, Evas_Object *obj, void *event_info)
598 __MOBILE_AP_FUNC_ENTER__;
600 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
601 mh_appdata_t *ad = (mh_appdata_t *)data;
604 ERR("The param is NULL\n");
608 elm_genlist_item_selected_set(item, EINA_FALSE);
610 __usb_onoff_changed_cb(data, ad->main.usb_btn, NULL);
612 __MOBILE_AP_FUNC_EXIT__;
617 static void __quit_btn_cb(void *data, Evas_Object *obj, void *event_info)
619 __MOBILE_AP_FUNC_ENTER__;
622 ERR("The param is NULL\n");
626 mh_appdata_t *ad = (mh_appdata_t*)data;
628 ug_destroy_me(((mh_ugdata_t *)ad->gadget)->ug);
630 __MOBILE_AP_FUNC_EXIT__;
633 static char *__get_wifi_label(void *data, Evas_Object *obj, const char *part)
635 if (strcmp(part, "elm.text") != 0) {
636 ERR("Invalid param\n");
640 return strdup(_("IDS_MOBILEAP_MBODY_WI_FI_TETHERING"));
643 static Evas_Object *__get_wifi_icon(void *data, Evas_Object *obj,
646 __MOBILE_AP_FUNC_ENTER__;
649 ERR("The param is NULL\n");
653 if (strcmp(part, "elm.icon") != 0) {
654 ERR("Invalid param\n");
658 mh_appdata_t *ad = (mh_appdata_t*)data;
659 Evas_Object *btn = NULL;
660 Evas_Object *progressbar = NULL;
662 if (ad->main.wifi_state == MH_STATE_PROCESS) {
663 progressbar = elm_progressbar_add(obj);
664 if (progressbar == NULL) {
665 ERR("progressbar is NULL\n");
668 elm_object_style_set(progressbar, "list_process");
669 elm_progressbar_horizontal_set(progressbar, EINA_TRUE);
670 elm_progressbar_pulse(progressbar, EINA_TRUE);
671 evas_object_show(progressbar);
672 ad->main.wifi_btn = progressbar;
674 btn = elm_check_add(obj);
675 elm_object_style_set(btn, "on&off");
676 evas_object_show(btn);
678 evas_object_pass_events_set(btn, EINA_TRUE);
679 evas_object_propagate_events_set(btn, EINA_FALSE);
680 elm_check_state_set(btn, ad->main.hotspot_mode &
681 VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI ? EINA_TRUE : EINA_FALSE);
683 evas_object_smart_callback_add(btn, "changed", __wifi_onoff_changed_cb,
685 ad->main.wifi_btn = btn;
688 __MOBILE_AP_FUNC_EXIT__;
689 return ad->main.wifi_btn;
692 static char *__get_setup_label(void *data, Evas_Object *obj, const char *part)
696 ERR("The param is NULL\n");
700 mh_appdata_t *ad = (mh_appdata_t *)data;
702 if (strcmp(part, "elm.text") != 0) {
703 ERR("Invalid param\n");
707 elm_object_item_disabled_set(ad->main.setup_item,
708 ad->main.hotspot_mode & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI);
710 return strdup(_("IDS_MOBILEAP_MBODY_WI_FI_TETHERING_SETTINGS"));
713 static char *__get_bt_label(void *data, Evas_Object *obj, const char *part)
715 if (strcmp(part, "elm.text") != 0) {
716 ERR("Invalid param\n");
720 return strdup(_("IDS_MOBILEAP_BODY_BLUETOOTH_TETHERING"));
723 static Evas_Object *__get_bt_icon(void *data, Evas_Object *obj, const char *part)
725 __MOBILE_AP_FUNC_ENTER__;
727 mh_appdata_t *ad = (mh_appdata_t *)data;
728 Evas_Object *btn = NULL;
730 if (strcmp(part, "elm.icon") != 0) {
731 ERR("Invalid param\n");
736 ERR("The param is NULL\n");
740 btn = elm_check_add(obj);
741 elm_object_style_set(btn, "on&off");
742 evas_object_show(btn);
744 evas_object_pass_events_set(btn, EINA_TRUE);
745 evas_object_propagate_events_set(btn, EINA_FALSE);
746 elm_check_state_set(btn, ad->main.hotspot_mode &
747 VCONFKEY_MOBILE_HOTSPOT_MODE_BT ? EINA_TRUE : EINA_FALSE);
749 evas_object_smart_callback_add(btn, "changed", __bt_onoff_changed_cb,
751 ad->main.bt_btn = btn;
753 __MOBILE_AP_FUNC_EXIT__;
758 static char *__get_usb_label(void *data, Evas_Object *obj, const char *part)
760 if (strcmp(part, "elm.text") != 0) {
761 ERR("Invalid param\n");
765 return strdup(_("IDS_MOBILEAP_MBODY_USB_TETHERING"));
768 static Evas_Object *__get_usb_icon(void *data, Evas_Object *obj,
771 __MOBILE_AP_FUNC_ENTER__;
773 mh_appdata_t *ad = (mh_appdata_t *)data;
774 Evas_Object *btn = NULL;
775 Evas_Object *progressbar = NULL;
777 if (strcmp(part, "elm.icon") != 0) {
778 ERR("Invalid param\n");
783 ERR("The param is NULL\n");
787 ad->main.usb_btn = NULL;
788 if (ad->main.usb_state == MH_STATE_PROCESS) {
789 progressbar = elm_progressbar_add(obj);
790 if (progressbar == NULL) {
791 ERR("progressbar is NULL\n");
794 elm_object_style_set(progressbar, "list_process");
795 elm_progressbar_horizontal_set(progressbar, EINA_TRUE);
796 elm_progressbar_pulse(progressbar, EINA_TRUE);
797 evas_object_show(progressbar);
798 ad->main.usb_btn = progressbar;
800 btn = elm_check_add(obj);
802 ERR("btn is NULL\n");
805 elm_object_style_set(btn, "on&off");
806 evas_object_pass_events_set(btn, EINA_TRUE);
807 evas_object_propagate_events_set(btn, EINA_FALSE);
808 elm_check_state_set(btn, ad->main.hotspot_mode &
809 VCONFKEY_MOBILE_HOTSPOT_MODE_USB ? EINA_TRUE : EINA_FALSE);
810 evas_object_show(btn);
811 evas_object_smart_callback_add(btn, "changed", __usb_onoff_changed_cb,
813 ad->main.usb_btn = btn;
816 __MOBILE_AP_FUNC_EXIT__;
818 return ad->main.usb_btn;
821 static char *__get_setup_help_label(void *data, Evas_Object *obj,
824 __MOBILE_AP_FUNC_ENTER__;
826 if (strcmp(part, "elm.text.1") != 0) {
827 ERR("Invalid param\n");
831 __MOBILE_AP_FUNC_EXIT__;
833 return strdup(_("IDS_MOBILEAP_BODY_WI_FI_TETHERING_SETTINGS_ARE_ONLY_AVAILABLE_WHEN_WI_FI_TETHERING_IS_DISABLED"));
836 static char *__get_help_label(void *data, Evas_Object *obj, const char *part)
838 __MOBILE_AP_FUNC_ENTER__;
840 mh_appdata_t *ad = (mh_appdata_t *)data;
841 char buf[MH_LABEL_LENGTH_MAX] = {0, };
842 char device_name[MH_LABEL_LENGTH_MAX] = {0, };
843 char passphrase[MH_LABEL_LENGTH_MAX] = {0, };
846 int wifi_state = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
848 if (strcmp(part, "elm.text.1") != 0) {
849 ERR("Invalid param\n");
854 ERR("The param is NULL\n");
858 ptr = elm_entry_utf8_to_markup(ad->setup.device_name);
860 ERR("elm_entry_utf8_to_markup is failed\n");
863 g_strlcpy(device_name, ptr, MH_LABEL_LENGTH_MAX);
866 if (ad->setup.security_type != TETHERING_WIFI_SECURITY_TYPE_NONE) {
867 ptr = elm_entry_utf8_to_markup(ad->setup.wifi_passphrase);
869 ERR("elm_entry_utf8_to_markup is failed\n");
872 g_strlcpy(passphrase, ptr, MH_LABEL_LENGTH_MAX);
876 wifi_state = ad->main.hotspot_mode & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI;
878 if (wifi_state && ad->setup.visibility == false)
879 hidden = _("IDS_MOBILEAP_BODY_WI_FI_TETHERING_HIDDEN");
881 if (wifi_state && ad->setup.security_type != TETHERING_WIFI_SECURITY_TYPE_NONE) {
882 snprintf(buf, MH_LABEL_LENGTH_MAX,
888 _("IDS_MOBILEAP_BODY_DEVICE_NAME"),
890 _("IDS_MOBILEAP_BODY_PASSWORD"),
892 _("IDS_MOBILEAP_BODY_THIS_PASSWORD_IS_ONLY_FOR_WI_FI_TETHERING"),
893 hidden[0] != '\0' ? "<br>" : "",
897 snprintf(buf, MH_LABEL_LENGTH_MAX,
899 _("IDS_MOBILEAP_BODY_DEVICE_NAME"),
901 hidden[0] != '\0' ? "<br>" : "",
905 __MOBILE_AP_FUNC_EXIT__;
910 static char *__get_connected_device_label(void *data, Evas_Object *obj,
913 if (strcmp(part, "elm.text.1") != 0 && strcmp(part, "elm.text.2") != 0) {
914 ERR("Invalid param\n");
919 ERR("The param is NULL\n");
923 mh_appdata_t *ad = (mh_appdata_t*)data;
924 char buf[MH_LABEL_LENGTH_MAX] = {0, };
926 if (strcmp(part, "elm.text.1") != 0)
927 snprintf(buf, MH_LABEL_LENGTH_MAX, "%d",
929 else if (strcmp(part, "elm.text.2") != 0)
930 g_strlcpy(buf, _("IDS_MOBILEAP_BODY_CONNECTED_DEVICE"),
936 static char *__get_usage_label(void *data, Evas_Object *obj, const char *part)
939 ERR("The param is NULL\n");
943 if (strcmp(part, "elm.text.1") != 0 && strcmp(part, "elm.text.2") != 0) {
944 ERR("Invalid param\n");
948 mh_appdata_t *ad = (mh_appdata_t*)data;
951 char *sent_str = NULL;
952 char *received_str = NULL;
953 char fmt[MH_LABEL_LENGTH_MAX] = {0, };
954 char label[MH_LABEL_LENGTH_MAX] = {0, };
956 if (strcmp(part, "elm.text.1") != 0 ) {
957 sent = ad->data_statistics.pdp_total_sent;
958 received = ad->data_statistics.pdp_total_receive;
962 sent_str = _("IDS_MOBILEAP_BODY_PD_MB");
963 } else if (sent >= MH_KB) {
965 sent_str = _("IDS_MOBILEAP_BODY_PD_KB");
967 sent_str = _("IDS_MOBILEAP_BODY_PD_BYTES");
970 if (received >= MH_MB) {
972 received_str = _("IDS_MOBILEAP_BODY_PD_MB");
973 } else if (received >= MH_KB) {
975 received_str = _("IDS_MOBILEAP_BODY_PD_KB");
977 received_str = _("IDS_MOBILEAP_BODY_PD_BYTES");
980 snprintf(fmt, sizeof(fmt), "%s %s / %s %s",
981 _("IDS_MOBILEAP_BODY_SENT_C"),
983 _("IDS_MOBILEAP_BODY_RECEIVED_C"),
985 snprintf(label, sizeof(label), fmt, sent, received);
986 } else if (strcmp(part, "elm.text.2") != 0)
987 g_strlcpy(label, _("IDS_MOBILEAP_MBODY_DATA_USAGE"),
990 return strdup(label);
993 static char *__gl_get_dev_label(void *data, Evas_Object *obj, const char *part)
995 if (data == NULL || part == NULL) {
996 ERR("Invalid param\n");
1000 tethering_client_h client = (tethering_client_h)data;
1003 if (!strcmp(part, "elm.text")) {
1004 tethering_client_get_name(client, &name);
1005 DBG("Device name : %s\n", name);
1007 if (!strcmp(name, "UNKNOWN")) {
1008 return strdup(_(MH_DEVICE_LIST_NO_NAME));
1017 static Evas_Object *__gl_get_dev_wifi_icon(void *data, Evas_Object *obj,
1022 if (!strncmp(part, "elm.icon", 8)) {
1023 icon = elm_icon_add(obj);
1024 elm_icon_file_set(icon, MOBILE_AP_IMG_DIR"/Wifi.png", NULL);
1025 evas_object_size_hint_aspect_set(icon,
1026 EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
1032 static Evas_Object *__gl_get_dev_usb_icon(void *data, Evas_Object *obj,
1037 if (!strncmp(part, "elm.icon", 8)) {
1038 icon = elm_icon_add(obj);
1039 elm_icon_file_set(icon, MOBILE_AP_IMG_DIR"/USB.png", NULL);
1040 evas_object_size_hint_aspect_set(icon,
1041 EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
1047 static Evas_Object *__gl_get_dev_bt_icon(void *data, Evas_Object *obj,
1052 if (!strncmp(part, "elm.icon", 8)) {
1053 icon = elm_icon_add(obj);
1054 elm_icon_file_set(icon, MOBILE_AP_IMG_DIR"/Bluetooth.png", NULL);
1055 evas_object_size_hint_aspect_set(icon,
1056 EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
1062 static void _gl_exp(void *data, Evas_Object *obj, void *event_info)
1064 __MOBILE_AP_FUNC_ENTER__;
1067 ERR("Invalid param\n");
1071 mh_appdata_t *ad = (mh_appdata_t *)data;
1073 ap_update_data_device(ad);
1075 __MOBILE_AP_FUNC_EXIT__;
1078 static void _gl_con(void *data, Evas_Object *obj, void *event_info)
1080 __MOBILE_AP_FUNC_ENTER__;
1082 if (event_info == NULL) {
1083 ERR("Invalid param\n");
1087 mh_appdata_t *ad = (mh_appdata_t *)data;
1089 elm_genlist_item_subitems_clear(ad->main.device_item);
1091 __MOBILE_AP_FUNC_EXIT__;
1094 static void _gl_device_item_sel(void *data, Evas_Object *obj, void *event_info)
1096 __MOBILE_AP_FUNC_ENTER__;
1098 Elm_Object_Item *item = (Elm_Object_Item*)event_info;
1100 elm_genlist_item_selected_set(item, EINA_FALSE);
1102 Eina_Bool status = elm_genlist_item_expanded_get(item);
1103 DBG("+ expand status:%d\n", status);
1105 elm_genlist_item_expanded_set(item, !status);
1107 __MOBILE_AP_FUNC_EXIT__;
1112 static void __free_genlist_itc(mh_appdata_t *ad)
1114 elm_genlist_item_class_free(ad->main.sp_itc);
1115 elm_genlist_item_class_free(ad->main.wifi_itc);
1116 elm_genlist_item_class_free(ad->main.setup_itc);
1117 elm_genlist_item_class_free(ad->main.bt_itc);
1118 elm_genlist_item_class_free(ad->main.usb_itc);
1119 elm_genlist_item_class_free(ad->main.setup_help_itc);
1120 elm_genlist_item_class_free(ad->main.help_itc);
1121 elm_genlist_item_class_free(ad->main.device_itc);
1122 elm_genlist_item_class_free(ad->main.device0_itc);
1123 elm_genlist_item_class_free(ad->main.usage_itc);
1124 elm_genlist_item_class_free(ad->main.dev_itc[TETHERING_TYPE_WIFI]);
1125 elm_genlist_item_class_free(ad->main.dev_itc[TETHERING_TYPE_USB]);
1126 elm_genlist_item_class_free(ad->main.dev_itc[TETHERING_TYPE_BT]);
1130 static void __set_genlist_itc(mh_appdata_t *ad)
1132 /* On, Off view's item class for genlist */
1133 ad->main.sp_itc = elm_genlist_item_class_new();
1134 ad->main.sp_itc->item_style = "dialogue/separator/21/with_line";
1135 ad->main.sp_itc->func.text_get = NULL;
1136 ad->main.sp_itc->func.content_get = NULL;
1137 ad->main.sp_itc->func.state_get = NULL;
1138 ad->main.sp_itc->func.del = NULL;
1140 ad->main.wifi_itc = elm_genlist_item_class_new();
1141 ad->main.wifi_itc->item_style = "dialogue/1text.1icon";
1142 ad->main.wifi_itc->func.text_get = __get_wifi_label;
1143 ad->main.wifi_itc->func.content_get = __get_wifi_icon;
1144 ad->main.wifi_itc->func.state_get = NULL;
1145 ad->main.wifi_itc->func.del = NULL;
1147 ad->main.end_sp_itc = elm_genlist_item_class_new();
1148 ad->main.end_sp_itc->item_style = "dialogue/separator/end";
1149 ad->main.end_sp_itc->func.text_get = NULL;
1150 ad->main.end_sp_itc->func.content_get = NULL;
1151 ad->main.end_sp_itc->func.state_get = NULL;
1152 ad->main.end_sp_itc->func.del = NULL;
1153 /* End of On, Off view's item class for genlist */
1155 /* Off view's item class for genlist */
1156 ad->main.setup_itc = elm_genlist_item_class_new();
1157 ad->main.setup_itc->item_style = "dialogue/1text";
1158 ad->main.setup_itc->func.text_get = __get_setup_label;
1159 ad->main.setup_itc->func.content_get = NULL;
1160 ad->main.setup_itc->func.state_get = NULL;
1161 ad->main.setup_itc->func.del = NULL;
1163 ad->main.bt_itc = elm_genlist_item_class_new();
1164 ad->main.bt_itc->item_style = "dialogue/1text.1icon";
1165 ad->main.bt_itc->func.text_get = __get_bt_label;
1166 ad->main.bt_itc->func.content_get = __get_bt_icon;
1167 ad->main.bt_itc->func.state_get = NULL;
1168 ad->main.bt_itc->func.del = NULL;
1170 ad->main.usb_itc = elm_genlist_item_class_new();
1171 ad->main.usb_itc->item_style = "dialogue/1text.1icon";
1172 ad->main.usb_itc->func.text_get = __get_usb_label;
1173 ad->main.usb_itc->func.content_get = __get_usb_icon;
1174 ad->main.usb_itc->func.state_get = NULL;
1175 ad->main.usb_itc->func.del = NULL;
1177 ad->main.setup_help_itc = elm_genlist_item_class_new();
1178 ad->main.setup_help_itc->item_style = "multiline/1text";
1179 ad->main.setup_help_itc->func.text_get = __get_setup_help_label;
1180 ad->main.setup_help_itc->func.content_get = NULL;
1181 ad->main.setup_help_itc->func.state_get = NULL;
1182 ad->main.setup_help_itc->func.del = NULL;
1184 ad->main.help_itc = elm_genlist_item_class_new();
1185 ad->main.help_itc->item_style = "multiline/1text";
1186 ad->main.help_itc->func.text_get = __get_help_label;
1187 ad->main.help_itc->func.content_get = NULL;
1188 ad->main.help_itc->func.state_get = NULL;
1189 ad->main.help_itc->func.del = NULL;
1191 /* End of Off view's item class for genlist */
1193 /* On view's item class for genlist */
1194 ad->main.device_itc = elm_genlist_item_class_new();
1195 ad->main.device_itc->item_style = "dialogue/2text.3/expandable";
1196 ad->main.device_itc->func.text_get = __get_connected_device_label;
1197 ad->main.device_itc->func.content_get = NULL;
1198 ad->main.device_itc->func.state_get = NULL;
1199 ad->main.device_itc->func.del = NULL;
1201 ad->main.device0_itc = elm_genlist_item_class_new();
1202 ad->main.device0_itc->item_style = "dialogue/2text.3";
1203 ad->main.device0_itc->func.text_get = __get_connected_device_label;
1204 ad->main.device0_itc->func.content_get = NULL;
1205 ad->main.device0_itc->func.state_get = NULL;
1206 ad->main.device0_itc->func.del = NULL;
1208 ad->main.usage_itc = elm_genlist_item_class_new();
1209 ad->main.usage_itc->item_style = "dialogue/2text.3";
1210 ad->main.usage_itc->func.text_get = __get_usage_label;
1211 ad->main.usage_itc->func.content_get = NULL;
1212 ad->main.usage_itc->func.state_get = NULL;
1213 ad->main.usage_itc->func.del = NULL;
1215 ad->main.dev_itc[TETHERING_TYPE_WIFI] = elm_genlist_item_class_new();
1216 ad->main.dev_itc[TETHERING_TYPE_WIFI]->item_style =
1217 "dialogue/1text.1icon/expandable2";
1218 ad->main.dev_itc[TETHERING_TYPE_WIFI]->func.text_get = __gl_get_dev_label;
1219 ad->main.dev_itc[TETHERING_TYPE_WIFI]->func.content_get = __gl_get_dev_wifi_icon;
1220 ad->main.dev_itc[TETHERING_TYPE_WIFI]->func.state_get = NULL;
1221 ad->main.dev_itc[TETHERING_TYPE_WIFI]->func.del = NULL;
1223 ad->main.dev_itc[TETHERING_TYPE_USB] = elm_genlist_item_class_new();
1224 ad->main.dev_itc[TETHERING_TYPE_USB]->item_style =
1225 "dialogue/1text.1icon/expandable2";
1226 ad->main.dev_itc[TETHERING_TYPE_USB]->func.text_get = __gl_get_dev_label;
1227 ad->main.dev_itc[TETHERING_TYPE_USB]->func.content_get = __gl_get_dev_usb_icon;
1228 ad->main.dev_itc[TETHERING_TYPE_USB]->func.state_get = NULL;
1229 ad->main.dev_itc[TETHERING_TYPE_USB]->func.del = NULL;
1231 ad->main.dev_itc[TETHERING_TYPE_BT] = elm_genlist_item_class_new();
1232 ad->main.dev_itc[TETHERING_TYPE_BT]->item_style =
1233 "dialogue/1text.1icon/expandable2";
1234 ad->main.dev_itc[TETHERING_TYPE_BT]->func.text_get = __gl_get_dev_label;
1235 ad->main.dev_itc[TETHERING_TYPE_BT]->func.content_get = __gl_get_dev_bt_icon;
1236 ad->main.dev_itc[TETHERING_TYPE_BT]->func.state_get = NULL;
1237 ad->main.dev_itc[TETHERING_TYPE_BT]->func.del = NULL;
1238 /* End of On view's item class for genlist */
1243 static void _ap_inner_contents(mh_appdata_t *ad)
1245 __MOBILE_AP_FUNC_ENTER__;
1247 Elm_Object_Item *item = NULL;
1250 if (ad->main.hotspot_mode != VCONFKEY_MOBILE_HOTSPOT_MODE_NONE)
1251 _start_update_data_packet_usage(ad);
1253 ad->main.genlist = elm_genlist_add(ad->naviframe);
1254 elm_object_style_set(ad->main.genlist, "dialogue");
1255 elm_genlist_mode_set(ad->main.genlist, ELM_LIST_COMPRESS);
1256 elm_object_content_set(ad->main.conform, ad->main.genlist);
1257 __set_genlist_itc(ad);
1260 item = elm_genlist_item_append(ad->main.genlist, ad->main.sp_itc, ad,
1261 NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
1262 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1264 item = elm_genlist_item_append(ad->main.genlist, ad->main.wifi_itc,
1265 ad, NULL, ELM_GENLIST_ITEM_NONE,
1266 __select_wifi_item, ad);
1267 ad->main.wifi_item = item;
1269 item = elm_genlist_item_append(ad->main.genlist, ad->main.setup_itc,
1270 ad, NULL, ELM_GENLIST_ITEM_NONE,
1271 __select_setup_item, ad);
1272 ad->main.setup_item = item;
1274 item = elm_genlist_item_append(ad->main.genlist, ad->main.setup_help_itc,
1275 ad, NULL, ELM_GENLIST_ITEM_NONE,
1277 ad->main.setup_help_item = item;
1280 item = elm_genlist_item_append(ad->main.genlist, ad->main.sp_itc, ad,
1281 NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
1282 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1284 item = elm_genlist_item_append(ad->main.genlist, ad->main.bt_itc,
1285 ad, NULL, ELM_GENLIST_ITEM_NONE,
1286 __select_bt_item, ad);
1287 ad->main.bt_item = item;
1289 item = elm_genlist_item_append(ad->main.genlist, ad->main.usb_itc,
1290 ad, NULL, ELM_GENLIST_ITEM_NONE,
1291 __select_usb_item, ad);
1292 ad->main.usb_item = item;
1294 if (ad->main.hotspot_mode & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI ||
1295 ad->main.hotspot_mode & VCONFKEY_MOBILE_HOTSPOT_MODE_BT) {
1296 item = elm_genlist_item_append(ad->main.genlist, ad->main.help_itc,
1297 ad, NULL, ELM_GENLIST_ITEM_NONE,
1299 DBG("elm_genlist_item_append for help_itc : %x\n", item);
1300 ad->main.help_item = item;
1304 item = elm_genlist_item_append(ad->main.genlist, ad->main.sp_itc, ad,
1305 NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
1306 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1308 item = elm_genlist_item_append(ad->main.genlist, ad->main.usage_itc,
1309 ad, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
1310 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1311 ad->main.usage_item = item;
1313 /* Insert "Connected devices" item */
1314 ap_update_data_device(ad);
1316 item = elm_genlist_item_append(ad->main.genlist, ad->main.end_sp_itc, ad,
1317 NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
1318 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1320 __MOBILE_AP_FUNC_EXIT__;
1323 void ap_callback_del(void *data)
1325 __MOBILE_AP_FUNC_ENTER__;
1328 ERR("The param is NULL\n");
1331 mh_appdata_t *ad = (mh_appdata_t*)data;
1333 evas_object_smart_callback_del(ad->main.back_btn, "clicked",
1335 evas_object_smart_callback_del(ad->main.wifi_btn, "changed",
1336 __wifi_onoff_changed_cb);
1337 evas_object_smart_callback_del(ad->main.bt_btn, "changed",
1338 __bt_onoff_changed_cb);
1339 evas_object_smart_callback_del(ad->main.usb_btn, "changed",
1340 __usb_onoff_changed_cb);
1342 evas_object_smart_callback_del(ad->main.genlist, "expanded", _gl_exp);
1343 evas_object_smart_callback_del(ad->main.genlist, "contracted", _gl_con);
1345 __MOBILE_AP_FUNC_EXIT__;
1348 void ap_update_data_onoff(void* data)
1350 __MOBILE_AP_FUNC_ENTER__;
1352 __MOBILE_AP_FUNC_EXIT__;
1355 void ap_draw_contents(mh_appdata_t *ad)
1357 __MOBILE_AP_FUNC_ENTER__;
1359 elm_win_conformant_set(ad->win, 1);
1360 ad->main.conform = elm_conformant_add(ad->naviframe);
1361 elm_object_style_set(ad->main.conform, "internal_layout");
1362 evas_object_show(ad->main.conform);
1364 _ap_inner_contents(ad);
1366 ad->main.back_btn = elm_button_add(ad->naviframe);
1368 elm_naviframe_item_push(ad->naviframe,
1369 _("IDS_MOBILEAP_BODY_TETHERING"),
1370 ad->main.back_btn, NULL, ad->main.conform, NULL);
1372 /* Style set should be called after elm_naviframe_item_push(). */
1373 elm_object_style_set(ad->main.back_btn, "naviframe/back_btn/default");
1374 evas_object_smart_callback_add(ad->main.back_btn, "clicked",
1376 elm_object_focus_allow_set(ad->main.back_btn, EINA_FALSE);
1378 __MOBILE_AP_FUNC_EXIT__;