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 <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"
34 static mh_popup_type_e popup_type = MH_POPUP_NONE;
35 static Evas_Object *popup_content = NULL;
36 static char *popup_string = NULL;
38 static void __launch_network_app(void)
40 int ret = APP_CONTROL_ERROR_NONE;
41 app_control_h app_control;
43 app_control_create(&app_control);
44 if (ret != APP_CONTROL_ERROR_NONE) {
45 ERR("app_control_create failed");
48 app_control_set_operation(app_control, APP_CONTROL_OPERATION_DEFAULT);
49 app_control_set_launch_mode(app_control, APP_CONTROL_LAUNCH_MODE_GROUP);
50 app_control_set_app_id(app_control, "setting-network-efl");
52 ret = app_control_send_launch_request(app_control, NULL, NULL);
53 if (ret == APP_CONTROL_ERROR_NONE)
54 DBG("Launch network ug successful");
56 ERR("Fail to launch network ug");
58 app_control_destroy(app_control);
61 static void __handle_popup_resp(void *data, bool response)
63 __MOBILE_AP_FUNC_ENTER__;
66 ERR("The param is NULL\n");
70 mh_appdata_t *ad = (mh_appdata_t *)data;
74 if (ad->popup_checkbox) {
75 state = elm_check_state_get(ad->popup_checkbox);
76 evas_object_del(ad->popup_checkbox);
77 ad->popup_checkbox = NULL;
78 DBG("Checkbox status is = %d\n", state);
81 evas_object_del(ad->popup);
85 if (response == true) {
87 case MH_POPUP_WIFI_ON_CHECKBOX:
89 _set_checkbox_status(TETHERING_TYPE_WIFI, 1);
91 ad->is_wifi_teth_enabling = false;
92 ret = tethering_enable(ad->handle, TETHERING_TYPE_WIFI);
93 if (ret != TETHERING_ERROR_NONE) {
94 ERR("wifi tethering on is failed : %d\n", ret);
95 _update_wifi_item(ad, MH_STATE_NONE);
97 _wifi_tethering_checkbox_popup_status_set(false);
98 _send_signal_qp(QP_SIGNAL_PROGRESS_ON);
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_AVAILABLE) {
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);
135 _send_signal_qp(QP_SIGNAL_PROGRESS_OFF);
138 case MH_POPUP_MOBILE_DATA_OFF:
139 __launch_network_app();
140 _update_tethering_enabling_item(ad, ad->type, MH_STATE_NONE);
144 ERR("Unknown popup_type : %d\n", popup_type);
148 switch (popup_type) {
149 case MH_POPUP_WIFI_ON_CHECKBOX:
150 _update_tethering_enabling_item(ad, TETHERING_TYPE_WIFI, MH_STATE_NONE);
151 _send_signal_qp(QP_SIGNAL_PROGRESS_RESET);
152 _wifi_tethering_checkbox_popup_status_set(false);
155 case MH_POPUP_BT_ON_CHECKBOX:
156 _update_tethering_enabling_item(ad, TETHERING_TYPE_BT, MH_STATE_NONE);
159 case MH_POPUP_USB_ON_CHECKBOX:
160 _update_tethering_enabling_item(ad, TETHERING_TYPE_USB, MH_STATE_NONE);
163 case MH_POPUP_WIFI_AP_OFF:
164 if (ad->setup.genlist)
165 elm_naviframe_item_pop(ad->naviframe);
166 elm_naviframe_item_pop(ad->naviframe);
169 case MH_POPUP_WIFI_OFF:
170 _update_tethering_enabling_item(ad, TETHERING_TYPE_WIFI, MH_STATE_NONE);
171 _send_signal_qp(QP_SIGNAL_PROGRESS_RESET);
174 case MH_POPUP_MOBILE_DATA_OFF:
175 _update_tethering_enabling_item(ad, ad->type, MH_STATE_NONE);
178 ERR("Unknown popup_type : %d\n", popup_type);
183 __MOBILE_AP_FUNC_EXIT__;
186 void _teth_on(mh_appdata_t *ad)
188 __handle_popup_resp(ad, true);
191 static void __popup_yes_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
193 if (data == NULL || obj == NULL) {
194 ERR("The param is NULL\n");
198 __handle_popup_resp(data, true);
201 static void __popup_no_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
203 if (data == NULL || obj == NULL) {
204 ERR("The param is NULL\n");
208 __handle_popup_resp(data, false);
211 static void __popup_no_btn_mouse_event_cb(void *data, Evas *evas, Evas_Object *obj, void *event_info)
213 if (data == NULL || obj == NULL) {
214 ERR("The param is NULL\n");
218 Evas_Event_Mouse_Up *ev = event_info;
221 __handle_popup_resp(data, false);
224 static void __popup_block_clicked_cb(void *data, Evas_Object *obj, void *event_info)
227 ERR("The param is NULL\n");
231 elm_popup_dismiss(obj);
234 static void __popup_hide_finished_cb(void *data, Evas_Object *obj, void *event_info)
237 ERR("The param is NULL\n");
241 __handle_popup_resp(data, false);
244 void _prepare_popup_with_content(int type, Evas_Object *obj)
246 __MOBILE_AP_FUNC_ENTER__;
249 ERR("param is NULL\n");
256 evas_object_del(popup_content);
264 __MOBILE_AP_FUNC_EXIT__;
267 void _prepare_popup(int type, const char *str)
269 __MOBILE_AP_FUNC_ENTER__;
272 ERR("param is NULL\n");
277 popup_content = NULL;
282 popup_string = strndup(str, MH_LABEL_LENGTH_MAX);
283 if (popup_string == NULL)
284 ERR("strndup is failed\n");
286 __MOBILE_AP_FUNC_EXIT__;
289 void _prepare_popup_type(int type)
294 static void __language_changed_cb(void *data, Evas_Object *obj, void *event_info)
296 __MOBILE_AP_FUNC_ENTER__;
298 mh_appdata_t *ad = (mh_appdata_t *)data;
299 Evas_Object *label = NULL;
300 bool wifi_state = false;
302 char str[MH_LABEL_LENGTH_MAX];
304 if (ad->type < TETHERING_TYPE_USB || ad->type > TETHERING_TYPE_BT) {
305 ERR("Invalid Tethering type\n");
310 case TETHERING_TYPE_WIFI:
311 wifi_is_activated(&wifi_state);
312 _set_vconf_prev_wifi_state(wifi_state);
313 if (wifi_state == true || _is_wifi_direct_on() == true)
314 fmt = STR_TETH_ON_DESC_1;
316 fmt = STR_TETH_ON_DESC_2;
318 snprintf(str, MH_LABEL_LENGTH_MAX, fmt, TETHERING_WIFI_MAX_CONNECTED_STA);
321 case TETHERING_TYPE_BT:
322 fmt = STR_TETH_ON_DESC_2;
323 snprintf(str, MH_LABEL_LENGTH_MAX, fmt, TETHERING_BT_MAX_CONNECTED_STA);
326 case TETHERING_TYPE_USB:
327 snprintf(str, MH_LABEL_LENGTH_MAX, STR_TETH_ON_DESC_3);
333 label = elm_label_add(ad->main.check_popup_ly);
334 elm_object_style_set(label, "popup/default");
335 elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
336 elm_object_text_set(label, str);
337 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
338 evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
339 evas_object_show(label);
340 elm_object_part_content_set(ad->main.check_popup_ly, "elm.swallow.content", label);
342 __MOBILE_AP_FUNC_EXIT__;
345 static void __popup_with_checkbox(mh_appdata_t *ad)
347 __MOBILE_AP_FUNC_ENTER__;
349 Evas_Object *popup = NULL;
350 Evas_Object *yes_button = NULL;
351 Evas_Object *cancel_button = NULL;
352 Evas_Object *layout = NULL;
353 Evas_Object *label = NULL;
354 Evas_Object *check = NULL;
356 popup = elm_popup_add(ad->win);
357 elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
358 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
361 case TETHERING_TYPE_WIFI:
362 elm_object_domain_translatable_part_text_set(popup, "title,text", PACKAGE,
363 "IDS_MOBILEAP_MBODY_WI_FI_TETHERING");
365 case TETHERING_TYPE_BT:
366 elm_object_domain_translatable_part_text_set(popup, "title,text", PACKAGE,
367 "IDS_MOBILEAP_BODY_BLUETOOTH_TETHERING");
369 case TETHERING_TYPE_USB:
370 elm_object_domain_translatable_part_text_set(popup, "title,text", PACKAGE,
371 "IDS_MOBILEAP_MBODY_USB_TETHERING");
378 layout = elm_layout_add(popup);
379 elm_layout_file_set(layout, FILE_PATH_OF_EDC, "popup_checkview_layout");
380 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
381 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, 1.0);
382 ad->main.check_popup_ly = layout;
385 check = elm_check_add(popup);
386 elm_object_style_set(check, "popup");
387 elm_object_domain_translatable_text_set(check, PACKAGE, STR_NO_SHOW_AGAIN);
388 evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL);
389 evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
390 elm_object_part_content_set(layout, "elm.swallow.end", check);
391 ad->popup_checkbox = check;
394 label = elm_label_add(layout);
395 elm_object_style_set(label, "popup/default");
396 elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
397 elm_object_text_set(label, popup_string);
398 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
399 evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
400 evas_object_show(label);
401 elm_object_part_content_set(layout, "elm.swallow.content", label);
403 cancel_button = _create_button(popup, "IDS_BR_SK_CANCEL",
404 "button1", __popup_no_btn_clicked_cb, ad);
405 yes_button = _create_button(popup, "IDS_ST_BUTTON_ENABLE_M_USE",
406 "button2", __popup_yes_btn_clicked_cb, ad);
408 evas_object_smart_callback_add(popup, "language,changed", __language_changed_cb, ad);
410 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK,
411 __popup_no_btn_clicked_cb, (void *)ad);
413 evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP,
414 __popup_no_btn_mouse_event_cb, (void *)ad);
415 evas_object_smart_callback_add(popup, "block,clicked",
416 __popup_block_clicked_cb, NULL);
417 evas_object_smart_callback_add(popup, "dismissed",
418 __popup_hide_finished_cb, ad);
421 if (check && yes_button) {
422 elm_object_focus_next_object_set(check, yes_button, ELM_FOCUS_PREVIOUS);
423 elm_object_focus_next_object_set(yes_button, check, ELM_FOCUS_NEXT);
425 elm_object_focus_next_object_set(cancel_button, check, ELM_FOCUS_PREVIOUS);
426 elm_object_focus_next_object_set(check , cancel_button, ELM_FOCUS_NEXT);
430 elm_object_content_set(popup, layout);
431 evas_object_show(popup);
434 __MOBILE_AP_FUNC_EXIT__;
437 Eina_Bool _create_popup(mh_appdata_t *ad)
439 __MOBILE_AP_FUNC_ENTER__;
441 Evas_Object *popup = NULL;
442 Evas_Object *cancel_button = NULL;
443 Evas_Object *yes_button = NULL;
446 ERR("The param is NULL\n");
451 popup_content = NULL;
456 if (ad->popup != NULL) {
457 evas_object_del(ad->popup);
460 ad->popup_checkbox = NULL;
461 DBG("popup type : %d", popup_type);
463 switch (popup_type) {
464 case MH_POPUP_WIFI_ON_CHECKBOX:
465 case MH_POPUP_BT_ON_CHECKBOX:
466 case MH_POPUP_USB_ON_CHECKBOX:
467 __popup_with_checkbox(ad);
470 case MH_POPUP_WIFI_OFF:
471 popup = elm_popup_add(ad->win);
474 elm_object_domain_translatable_part_text_set(popup, "title,text", PACKAGE,
475 "IDS_MOBILEAP_MBODY_WI_FI_TETHERING");
477 evas_object_size_hint_weight_set(popup,
478 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
480 if (popup_content == NULL)
481 elm_object_domain_translatable_text_set(popup, PACKAGE, popup_string);
483 elm_object_content_set(popup, popup_content);
485 cancel_button = _create_button(popup, STR_CANCEL,
486 "button1", __popup_no_btn_clicked_cb, ad);
487 yes_button = _create_button(popup, STR_TURN_OFF,
488 "button2", __popup_yes_btn_clicked_cb, ad);
490 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK,
491 __popup_no_btn_clicked_cb, (void *)ad);
492 evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP,
493 __popup_no_btn_mouse_event_cb, (void *)ad);
494 evas_object_smart_callback_add(popup, "block,clicked",
495 __popup_block_clicked_cb, NULL);
496 evas_object_smart_callback_add(popup, "dismissed",
497 __popup_hide_finished_cb, ad);
499 evas_object_show(popup);
502 case MH_POPUP_TETH_ENABLING_FAILED:
503 case MH_POPUP_NO_SIM:
504 case MH_POPUP_FLIGHT_MODE:
505 case MH_POPUP_NETWORK_OUT_OF_RANGE:
506 popup = elm_popup_add(ad->win);
508 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
511 if (popup_content == NULL)
512 elm_object_domain_translatable_text_set(popup, PACKAGE, popup_string);
514 elm_object_content_set(popup, popup_content);
515 elm_object_domain_translatable_part_text_set(popup, "title,text", PACKAGE,
517 cancel_button = _create_button(popup, STR_CANCEL,
518 "button1", __popup_no_btn_clicked_cb, ad);
520 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK,
521 __popup_no_btn_clicked_cb, (void *)ad);
522 evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP,
523 __popup_no_btn_mouse_event_cb, (void *)ad);
524 evas_object_smart_callback_add(popup, "block,clicked",
525 __popup_block_clicked_cb, NULL);
526 evas_object_smart_callback_add(popup, "dismissed",
527 __popup_hide_finished_cb, ad);
529 evas_object_show(popup);
532 case MH_POPUP_MOBILE_DATA_OFF:
533 popup = elm_popup_add(ad->win);
535 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
538 if (popup_content == NULL)
539 elm_object_domain_translatable_text_set(popup, PACKAGE, popup_string);
541 elm_object_content_set(popup, popup_content);
542 elm_object_domain_translatable_part_text_set(popup, "title,text", PACKAGE,
544 cancel_button = _create_button(popup, STR_CANCEL,
545 "button1", __popup_no_btn_clicked_cb, ad);
546 yes_button = _create_button(popup, STR_SETTING,
547 "button2", __popup_yes_btn_clicked_cb, ad);
549 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK,
550 __popup_no_btn_clicked_cb, (void *)ad);
551 evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP,
552 __popup_no_btn_mouse_event_cb, (void *)ad);
553 evas_object_smart_callback_add(popup, "block,clicked",
554 __popup_block_clicked_cb, NULL);
555 evas_object_smart_callback_add(popup, "dismissed",
556 __popup_hide_finished_cb, ad);
558 evas_object_show(popup);
561 case MH_POPUP_WIFI_AP_OFF:
562 popup = elm_popup_add(ad->win);
564 evas_object_size_hint_weight_set(popup,
565 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
567 elm_object_domain_translatable_part_text_set(popup, "title,text", PACKAGE,
569 if (popup_content == NULL)
570 elm_object_domain_translatable_text_set(popup, PACKAGE, popup_string);
572 elm_object_content_set(popup, popup_content);
574 cancel_button = _create_button(popup, STR_CANCEL,
575 "button1", __popup_no_btn_clicked_cb, ad);
576 yes_button = _create_button(popup, STR_ENABLE,
577 "button2", __popup_yes_btn_clicked_cb, ad);
579 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK,
580 __popup_no_btn_clicked_cb, (void *)ad);
581 evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP,
582 __popup_no_btn_mouse_event_cb, (void *)ad);
584 evas_object_show(popup);
588 ERR("Unknown popup_type : %d\n", popup_type);
592 if (cancel_button && yes_button) {
593 elm_object_focus_next_object_set(cancel_button, yes_button, ELM_FOCUS_PREVIOUS);
594 elm_object_focus_next_object_set(yes_button, cancel_button, ELM_FOCUS_NEXT);
601 popup_content = NULL;
603 __MOBILE_AP_FUNC_EXIT__;
608 void _destroy_popup(mh_appdata_t *ad)
610 __MOBILE_AP_FUNC_ENTER__;
618 evas_object_del(ad->popup);
621 ad->popup_checkbox = NULL;
627 popup_content = NULL;
628 popup_type = MH_POPUP_NONE;
630 __MOBILE_AP_FUNC_EXIT__;
635 void _create_security_restriction_noti(tethering_type_e type)
638 char restricted_type[MAX_BUF_SIZE] = {0, };
642 case TETHERING_TYPE_WIFI:
643 g_strlcpy(restricted_type, "wifi tethering", MAX_BUF_SIZE - 1);
645 case TETHERING_TYPE_USB:
646 g_strlcpy(restricted_type, "usb tethering", MAX_BUF_SIZE - 1);
648 case TETHERING_TYPE_BT:
649 g_strlcpy(restricted_type, "bt tethering", MAX_BUF_SIZE - 1);
652 ERR("Invalid type.\n");
657 bundle_add(b, "_SYSPOPUP_TYPE_", "toast_popup");
658 bundle_add(b, "_SYSPOPUP_CONTENT_", "security restriction");
659 bundle_add(b, "_RESTRICTED_TYPE_", restricted_type);
661 DBG("Launch security restriction alert network popup");
662 ret = aul_launch_app(NETPOPUP, b);
664 ERR("Fail to launch syspopup");