4 * Copyright 2012 Samsung Electronics Co., Ltd
6 * Licensed under the Flora License, Version 1.1 (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 <efl_extension.h>
21 #include <app_control_internal.h>
23 #include <bundle_internal.h>
26 #include "mh_common_utility.h"
27 #include "mobile_hotspot.h"
29 #include "mh_string.h"
31 #define MAX_BUF_SIZE (256u)
32 #define NETPOPUP "net.netpopup"
33 #define NETWORK_SETTING_APP "org.tizen.setting-network"
35 static mh_popup_type_e popup_type = MH_POPUP_NONE;
36 static Evas_Object *popup_content = NULL;
37 static char *popup_string = NULL;
39 static void __launch_network_app(void)
41 int ret = APP_CONTROL_ERROR_NONE;
42 app_control_h app_control;
44 ret = app_control_create(&app_control);
45 if (ret != APP_CONTROL_ERROR_NONE) {
46 ERR("app_control_create failed");
49 app_control_set_operation(app_control, APP_CONTROL_OPERATION_DEFAULT);
50 app_control_set_launch_mode(app_control, APP_CONTROL_LAUNCH_MODE_GROUP);
51 app_control_set_app_id(app_control, NETWORK_SETTING_APP);
53 ret = app_control_send_launch_request(app_control, NULL, NULL);
54 if (ret == APP_CONTROL_ERROR_NONE)
55 DBG("Launch network ug successful");
57 ERR("Fail to launch network ug");
59 app_control_destroy(app_control);
62 static void __handle_popup_resp(void *data, bool response)
64 __MOBILE_AP_FUNC_ENTER__;
67 ERR("The param is NULL\n");
71 mh_appdata_t *ad = (mh_appdata_t *)data;
75 if (ad->popup_checkbox) {
76 state = elm_check_state_get(ad->popup_checkbox);
77 evas_object_del(ad->popup_checkbox);
78 ad->popup_checkbox = NULL;
79 DBG("Checkbox status is = %d\n", state);
82 evas_object_del(ad->popup);
86 if (response == true) {
88 case MH_POPUP_WIFI_ON_CHECKBOX:
90 _set_checkbox_status(TETHERING_TYPE_WIFI, 1);
92 ad->is_wifi_teth_enabling = false;
93 ret = tethering_enable(ad->handle, TETHERING_TYPE_WIFI);
94 if (ret != TETHERING_ERROR_NONE) {
95 ERR("wifi tethering on is failed : %d\n", ret);
96 _update_wifi_item(ad, MH_STATE_NONE);
98 _wifi_tethering_checkbox_popup_status_set(false);
101 case MH_POPUP_BT_ON_CHECKBOX:
103 _set_checkbox_status(TETHERING_TYPE_BT, 1);
105 ad->is_bt_teth_enabling = false;
106 ret = tethering_enable(ad->handle, TETHERING_TYPE_BT);
107 if (ret != TETHERING_ERROR_NONE) {
108 ERR("Error enable bt tethering : %d\n", ret);
109 _update_bt_item(ad, MH_STATE_NONE);
113 case MH_POPUP_USB_ON_CHECKBOX:
115 _set_checkbox_status(TETHERING_TYPE_USB, 1);
117 if (_get_vconf_usb_state() == VCONFKEY_SYSMAN_USB_DISCONNECTED) {
118 _update_tethering_item(ad, MH_STATE_NONE);
121 ad->is_usb_teth_enabling = false;
122 ret = tethering_enable(ad->handle, TETHERING_TYPE_USB);
123 if (ret != TETHERING_ERROR_NONE) {
124 ERR("Error enable usb tethering : %d\n", ret);
125 _update_usb_item(ad, MH_STATE_NONE);
129 case MH_POPUP_WIFI_OFF:
130 ret = tethering_disable(ad->handle, TETHERING_TYPE_WIFI);
131 if (ret != TETHERING_ERROR_NONE) {
132 ERR("wifi tethering off is failed : %d\n", ret);
133 _update_wifi_item(ad, MH_STATE_NONE);
137 case MH_POPUP_MOBILE_DATA_OFF:
138 __launch_network_app();
139 _update_tethering_enabling_item(ad, ad->type, MH_STATE_NONE);
143 ERR("Unknown popup_type : %d\n", popup_type);
147 switch (popup_type) {
148 case MH_POPUP_WIFI_ON_CHECKBOX:
149 _update_tethering_enabling_item(ad, TETHERING_TYPE_WIFI, MH_STATE_NONE);
150 _wifi_tethering_checkbox_popup_status_set(false);
153 case MH_POPUP_BT_ON_CHECKBOX:
154 _update_tethering_enabling_item(ad, TETHERING_TYPE_BT, MH_STATE_NONE);
157 case MH_POPUP_USB_ON_CHECKBOX:
158 _update_tethering_enabling_item(ad, TETHERING_TYPE_USB, MH_STATE_NONE);
161 case MH_POPUP_WIFI_AP_OFF:
162 if (ad->setup.genlist)
163 elm_naviframe_item_pop(ad->naviframe);
164 elm_naviframe_item_pop(ad->naviframe);
167 case MH_POPUP_WIFI_OFF:
168 _update_tethering_enabling_item(ad, TETHERING_TYPE_WIFI, MH_STATE_NONE);
171 case MH_POPUP_MOBILE_DATA_OFF:
172 _update_tethering_enabling_item(ad, ad->type, MH_STATE_NONE);
175 ERR("Unknown popup_type : %d\n", popup_type);
180 __MOBILE_AP_FUNC_EXIT__;
183 #ifdef TIZEN_FEATURE_EMULATOR
184 static void __handle_emul_popup_resp(void *data, bool response)
186 __MOBILE_AP_FUNC_ENTER__;
189 ERR("The param is NULL\n");
193 mh_appdata_t *ad = (mh_appdata_t *)data;
196 if (ad->popup_checkbox) {
197 state = elm_check_state_get(ad->popup_checkbox);
198 evas_object_del(ad->popup_checkbox);
199 ad->popup_checkbox = NULL;
200 DBG("Checkbox status is = %d\n", state);
203 evas_object_del(ad->popup);
207 if (response == true) {
208 switch (popup_type) {
209 case MH_POPUP_WIFI_ON_CHECKBOX:
211 _set_checkbox_status(TETHERING_TYPE_WIFI, 1);
212 ad->is_wifi_teth_enabling = false;
215 case MH_POPUP_BT_ON_CHECKBOX:
217 _set_checkbox_status(TETHERING_TYPE_BT, 1);
218 ad->is_bt_teth_enabling = false;
222 ERR("Unknown popup_type : %d\n", popup_type);
226 switch (popup_type) {
227 case MH_POPUP_WIFI_ON_CHECKBOX:
228 _update_tethering_enabling_item(ad, TETHERING_TYPE_WIFI, MH_STATE_NONE);
229 _wifi_tethering_checkbox_popup_status_set(false);
232 case MH_POPUP_BT_ON_CHECKBOX:
233 _update_tethering_enabling_item(ad, TETHERING_TYPE_BT, MH_STATE_NONE);
237 ERR("Unknown popup_type : %d\n", popup_type);
242 __MOBILE_AP_FUNC_EXIT__;
246 void _teth_on(mh_appdata_t *ad)
248 #ifndef TIZEN_FEATURE_EMULATOR
249 __handle_popup_resp(ad, true);
251 __handle_emul_popup_resp(ad, true);
255 static void __popup_yes_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
257 if (data == NULL || obj == NULL) {
258 ERR("The param is NULL\n");
262 #ifndef TIZEN_FEATURE_EMULATOR
263 __handle_popup_resp(data, true);
265 mh_appdata_t *ad = (mh_appdata_t *)data;
267 __handle_emul_popup_resp(data, true);
268 _update_emul_main_view(ad, _get_selected_type(), _get_selected_state());
272 static void __popup_no_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
274 if (data == NULL || obj == NULL) {
275 ERR("The param is NULL\n");
279 #ifndef TIZEN_FEATURE_EMULATOR
280 __handle_popup_resp(data, false);
282 __handle_emul_popup_resp(data, false);
286 static void __popup_no_btn_mouse_event_cb(void *data, Evas *evas, Evas_Object *obj, void *event_info)
288 if (data == NULL || obj == NULL) {
289 ERR("The param is NULL\n");
293 Evas_Event_Mouse_Up *ev = event_info;
296 #ifndef TIZEN_FEATURE_EMULATOR
297 __handle_popup_resp(data, false);
299 __handle_emul_popup_resp(data, false);
303 static void __popup_block_clicked_cb(void *data, Evas_Object *obj, void *event_info)
306 ERR("The param is NULL\n");
310 elm_popup_dismiss(obj);
313 static void __popup_hide_finished_cb(void *data, Evas_Object *obj, void *event_info)
316 ERR("The param is NULL\n");
320 #ifndef TIZEN_FEAUTRE_EMULATOR
321 __handle_popup_resp(data, false);
323 __handle_emul_popup_resp(data, false);
327 void _prepare_popup_with_content(int type, Evas_Object *obj)
329 __MOBILE_AP_FUNC_ENTER__;
332 ERR("param is NULL\n");
339 evas_object_del(popup_content);
347 __MOBILE_AP_FUNC_EXIT__;
350 void _prepare_popup(int type, const char *str)
352 __MOBILE_AP_FUNC_ENTER__;
355 ERR("param is NULL\n");
360 popup_content = NULL;
365 popup_string = strndup(str, MH_LABEL_LENGTH_MAX);
366 if (popup_string == NULL)
367 ERR("strndup is failed\n");
369 __MOBILE_AP_FUNC_EXIT__;
372 void _prepare_popup_type(int type)
377 static void __language_changed_cb(void *data, Evas_Object *obj, void *event_info)
379 __MOBILE_AP_FUNC_ENTER__;
381 mh_appdata_t *ad = (mh_appdata_t *)data;
382 Evas_Object *label = NULL;
383 bool wifi_state = false;
385 char str[MH_LABEL_LENGTH_MAX];
387 if (ad->type < TETHERING_TYPE_USB || ad->type > TETHERING_TYPE_BT) {
388 ERR("Invalid Tethering type\n");
393 case TETHERING_TYPE_WIFI:
394 wifi_manager_is_activated(ad->wifi_handle, &wifi_state);
395 _set_vconf_prev_wifi_state(wifi_state);
396 if (wifi_state == true || _is_wifi_direct_on() == true)
397 fmt = STR_TETH_ON_DESC_1;
399 fmt = STR_TETH_ON_DESC_2;
401 snprintf(str, MH_LABEL_LENGTH_MAX, fmt, TETHERING_WIFI_MAX_CONNECTED_STA);
404 case TETHERING_TYPE_BT:
405 fmt = STR_TETH_ON_DESC_2;
406 snprintf(str, MH_LABEL_LENGTH_MAX, fmt, TETHERING_BT_MAX_CONNECTED_STA);
409 case TETHERING_TYPE_USB:
410 snprintf(str, MH_LABEL_LENGTH_MAX, STR_TETH_ON_DESC_3);
416 label = elm_label_add(ad->main.check_popup_ly);
417 elm_object_style_set(label, "popup/default");
418 elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
419 elm_object_text_set(label, str);
420 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
421 evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
422 evas_object_show(label);
423 elm_object_part_content_set(ad->main.check_popup_ly, "elm.swallow.content", label);
425 __MOBILE_AP_FUNC_EXIT__;
428 static void __popup_with_checkbox(mh_appdata_t *ad)
430 __MOBILE_AP_FUNC_ENTER__;
432 Evas_Object *popup = NULL;
433 Evas_Object *yes_button = NULL;
434 Evas_Object *cancel_button = NULL;
435 Evas_Object *layout = NULL;
436 Evas_Object *label = NULL;
437 Evas_Object *check = NULL;
439 popup = elm_popup_add(ad->win);
440 elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
441 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
444 case TETHERING_TYPE_WIFI:
445 elm_object_domain_translatable_part_text_set(popup, "title,text", PACKAGE,
446 "IDS_MOBILEAP_MBODY_WI_FI_TETHERING");
448 case TETHERING_TYPE_BT:
449 elm_object_domain_translatable_part_text_set(popup, "title,text", PACKAGE,
450 "IDS_MOBILEAP_BODY_BLUETOOTH_TETHERING");
452 case TETHERING_TYPE_USB:
453 elm_object_domain_translatable_part_text_set(popup, "title,text", PACKAGE,
454 "IDS_MOBILEAP_MBODY_USB_TETHERING");
461 layout = elm_layout_add(popup);
462 elm_layout_file_set(layout, FILE_PATH_OF_EDC, "popup_checkview_layout");
463 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
464 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, 1.0);
465 ad->main.check_popup_ly = layout;
468 check = elm_check_add(popup);
469 elm_object_style_set(check, "popup");
470 elm_object_domain_translatable_text_set(check, PACKAGE, STR_NO_SHOW_AGAIN);
471 evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL);
472 evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
473 elm_object_part_content_set(layout, "elm.swallow.end", check);
474 ad->popup_checkbox = check;
477 label = elm_label_add(layout);
478 elm_object_style_set(label, "popup/default");
479 elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
480 elm_object_text_set(label, popup_string);
481 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
482 evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
483 evas_object_show(label);
484 elm_object_part_content_set(layout, "elm.swallow.content", label);
486 cancel_button = _create_button(popup, "IDS_BR_SK_CANCEL",
487 "button1", __popup_no_btn_clicked_cb, ad);
488 yes_button = _create_button(popup, "IDS_ST_BUTTON_ENABLE_M_USE",
489 "button2", __popup_yes_btn_clicked_cb, ad);
491 evas_object_smart_callback_add(popup, "language,changed", __language_changed_cb, ad);
493 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK,
494 __popup_no_btn_clicked_cb, (void *)ad);
496 evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP,
497 __popup_no_btn_mouse_event_cb, (void *)ad);
498 evas_object_smart_callback_add(popup, "block,clicked",
499 __popup_block_clicked_cb, NULL);
500 evas_object_smart_callback_add(popup, "dismissed",
501 __popup_hide_finished_cb, ad);
504 if (check && yes_button) {
505 elm_object_focus_next_object_set(check, yes_button, ELM_FOCUS_PREVIOUS);
506 elm_object_focus_next_object_set(yes_button, check, ELM_FOCUS_NEXT);
508 elm_object_focus_next_object_set(cancel_button, check, ELM_FOCUS_PREVIOUS);
509 elm_object_focus_next_object_set(check , cancel_button, ELM_FOCUS_NEXT);
513 elm_object_content_set(popup, layout);
514 evas_object_show(popup);
517 __MOBILE_AP_FUNC_EXIT__;
520 Eina_Bool _create_popup(mh_appdata_t *ad)
522 __MOBILE_AP_FUNC_ENTER__;
524 Evas_Object *popup = NULL;
525 Evas_Object *cancel_button = NULL;
526 Evas_Object *yes_button = NULL;
529 ERR("The param is NULL\n");
534 popup_content = NULL;
539 if (ad->popup != NULL) {
540 evas_object_del(ad->popup);
543 ad->popup_checkbox = NULL;
544 DBG("popup type : %d", popup_type);
546 switch (popup_type) {
547 case MH_POPUP_WIFI_ON_CHECKBOX:
548 case MH_POPUP_BT_ON_CHECKBOX:
549 case MH_POPUP_USB_ON_CHECKBOX:
550 __popup_with_checkbox(ad);
553 case MH_POPUP_WIFI_OFF:
554 popup = elm_popup_add(ad->win);
555 elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
558 elm_object_domain_translatable_part_text_set(popup, "title,text", PACKAGE,
559 "IDS_MOBILEAP_MBODY_WI_FI_TETHERING");
561 evas_object_size_hint_weight_set(popup,
562 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
564 if (popup_content == NULL)
565 elm_object_domain_translatable_text_set(popup, PACKAGE, popup_string);
567 elm_object_content_set(popup, popup_content);
569 cancel_button = _create_button(popup, STR_CANCEL,
570 "button1", __popup_no_btn_clicked_cb, ad);
571 yes_button = _create_button(popup, STR_TURN_OFF,
572 "button2", __popup_yes_btn_clicked_cb, ad);
574 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK,
575 __popup_no_btn_clicked_cb, (void *)ad);
576 evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP,
577 __popup_no_btn_mouse_event_cb, (void *)ad);
578 evas_object_smart_callback_add(popup, "block,clicked",
579 __popup_block_clicked_cb, NULL);
580 evas_object_smart_callback_add(popup, "dismissed",
581 __popup_hide_finished_cb, ad);
583 evas_object_show(popup);
586 case MH_POPUP_TETH_ENABLING_FAILED:
587 case MH_POPUP_NO_SIM:
588 case MH_POPUP_FLIGHT_MODE:
589 case MH_POPUP_NETWORK_OUT_OF_RANGE:
590 popup = elm_popup_add(ad->win);
591 elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
593 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
596 if (popup_content == NULL)
597 elm_object_domain_translatable_text_set(popup, PACKAGE, popup_string);
599 elm_object_content_set(popup, popup_content);
600 elm_object_domain_translatable_part_text_set(popup, "title,text", PACKAGE,
602 cancel_button = _create_button(popup, STR_CANCEL,
603 "button1", __popup_no_btn_clicked_cb, ad);
605 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK,
606 __popup_no_btn_clicked_cb, (void *)ad);
607 evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP,
608 __popup_no_btn_mouse_event_cb, (void *)ad);
609 evas_object_smart_callback_add(popup, "block,clicked",
610 __popup_block_clicked_cb, NULL);
611 evas_object_smart_callback_add(popup, "dismissed",
612 __popup_hide_finished_cb, ad);
614 evas_object_show(popup);
617 case MH_POPUP_MOBILE_DATA_OFF:
618 popup = elm_popup_add(ad->win);
619 elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
621 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
624 if (popup_content == NULL)
625 elm_object_domain_translatable_text_set(popup, PACKAGE, popup_string);
627 elm_object_content_set(popup, popup_content);
628 elm_object_domain_translatable_part_text_set(popup, "title,text", PACKAGE,
630 cancel_button = _create_button(popup, STR_CANCEL,
631 "button1", __popup_no_btn_clicked_cb, ad);
632 yes_button = _create_button(popup, STR_SETTING,
633 "button2", __popup_yes_btn_clicked_cb, ad);
635 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK,
636 __popup_no_btn_clicked_cb, (void *)ad);
637 evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP,
638 __popup_no_btn_mouse_event_cb, (void *)ad);
639 evas_object_smart_callback_add(popup, "block,clicked",
640 __popup_block_clicked_cb, NULL);
641 evas_object_smart_callback_add(popup, "dismissed",
642 __popup_hide_finished_cb, ad);
644 evas_object_show(popup);
647 case MH_POPUP_WIFI_AP_OFF:
648 popup = elm_popup_add(ad->win);
649 elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
651 evas_object_size_hint_weight_set(popup,
652 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
654 elm_object_domain_translatable_part_text_set(popup, "title,text", PACKAGE,
656 if (popup_content == NULL)
657 elm_object_domain_translatable_text_set(popup, PACKAGE, popup_string);
659 elm_object_content_set(popup, popup_content);
661 cancel_button = _create_button(popup, STR_CANCEL,
662 "button1", __popup_no_btn_clicked_cb, ad);
663 yes_button = _create_button(popup, STR_ENABLE,
664 "button2", __popup_yes_btn_clicked_cb, ad);
666 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK,
667 __popup_no_btn_clicked_cb, (void *)ad);
668 evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP,
669 __popup_no_btn_mouse_event_cb, (void *)ad);
671 evas_object_show(popup);
675 ERR("Unknown popup_type : %d\n", popup_type);
679 if (cancel_button && yes_button) {
680 elm_object_focus_next_object_set(cancel_button, yes_button, ELM_FOCUS_PREVIOUS);
681 elm_object_focus_next_object_set(yes_button, cancel_button, ELM_FOCUS_NEXT);
688 popup_content = NULL;
690 __MOBILE_AP_FUNC_EXIT__;
695 void _destroy_popup(mh_appdata_t *ad)
697 __MOBILE_AP_FUNC_ENTER__;
705 evas_object_del(ad->popup);
708 ad->popup_checkbox = NULL;
714 popup_content = NULL;
715 popup_type = MH_POPUP_NONE;
717 __MOBILE_AP_FUNC_EXIT__;
722 void _create_security_restriction_noti(tethering_type_e type)
725 char restricted_type[MAX_BUF_SIZE] = {0, };
729 case TETHERING_TYPE_WIFI:
730 g_strlcpy(restricted_type, "wifi tethering", MAX_BUF_SIZE - 1);
732 case TETHERING_TYPE_USB:
733 g_strlcpy(restricted_type, "usb tethering", MAX_BUF_SIZE - 1);
735 case TETHERING_TYPE_BT:
736 g_strlcpy(restricted_type, "bt tethering", MAX_BUF_SIZE - 1);
739 ERR("Invalid type.\n");
744 bundle_add(b, "_SYSPOPUP_TYPE_", "toast_popup");
745 bundle_add(b, "_SYSPOPUP_CONTENT_", "security restriction");
746 bundle_add(b, "_RESTRICTED_TYPE_", restricted_type);
748 DBG("Launch security restriction alert network popup");
749 ret = aul_launch_app(NETPOPUP, b);
751 ERR("Fail to launch syspopup");