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>
25 #include "mh_common_utility.h"
26 #include "mobile_hotspot.h"
28 #include "mh_string.h"
30 #define MAX_BUF_SIZE (256u)
31 #define NETPOPUP "net.netpopup"
33 static mh_popup_type_e popup_type = MH_POPUP_NONE;
34 static Evas_Object *popup_content = NULL;
35 static char *popup_string = NULL;
37 static void __launch_network_app(void)
39 int ret = APP_CONTROL_ERROR_NONE;
40 app_control_h app_control;
42 app_control_create(&app_control);
43 if (ret != APP_CONTROL_ERROR_NONE) {
44 ERR("app_control_create failed");
47 app_control_set_operation(app_control, APP_CONTROL_OPERATION_DEFAULT);
48 app_control_set_launch_mode(app_control, APP_CONTROL_LAUNCH_MODE_GROUP);
49 app_control_set_app_id(app_control, "setting-network-efl");
51 ret = app_control_send_launch_request(app_control, NULL, NULL);
52 if (ret == APP_CONTROL_ERROR_NONE)
53 DBG("Launch network ug successful");
55 ERR("Fail to launch network ug");
57 app_control_destroy(app_control);
60 static void __handle_popup_resp(void *data, bool response)
62 __MOBILE_AP_FUNC_ENTER__;
65 ERR("The param is NULL\n");
69 mh_appdata_t *ad = (mh_appdata_t *)data;
73 if (ad->popup_checkbox) {
74 state = elm_check_state_get(ad->popup_checkbox);
75 evas_object_del(ad->popup_checkbox);
76 ad->popup_checkbox = NULL;
77 DBG("Checkbox status is = %d\n", state);
80 evas_object_del(ad->popup);
84 if (response == true) {
86 case MH_POPUP_WIFI_ON_CHECKBOX:
88 _set_checkbox_status(TETHERING_TYPE_WIFI, 1);
90 ad->is_wifi_teth_enabling = false;
91 ret = tethering_enable(ad->handle, TETHERING_TYPE_WIFI);
92 if (ret != TETHERING_ERROR_NONE) {
93 ERR("wifi tethering on is failed : %d\n", ret);
94 _update_wifi_item(ad, MH_STATE_NONE);
96 _wifi_tethering_checkbox_popup_status_set(false);
97 _send_signal_qp(QP_SIGNAL_PROGRESS_ON);
100 case MH_POPUP_BT_ON_CHECKBOX:
102 _set_checkbox_status(TETHERING_TYPE_BT, 1);
104 ad->is_bt_teth_enabling = false;
105 ret = tethering_enable(ad->handle, TETHERING_TYPE_BT);
106 if (ret != TETHERING_ERROR_NONE) {
107 ERR("Error enable bt tethering : %d\n", ret);
108 _update_bt_item(ad, MH_STATE_NONE);
112 case MH_POPUP_USB_ON_CHECKBOX:
114 _set_checkbox_status(TETHERING_TYPE_USB, 1);
116 if (_get_vconf_usb_state() != VCONFKEY_SYSMAN_USB_AVAILABLE) {
117 _update_tethering_item(ad, MH_STATE_NONE);
120 ad->is_usb_teth_enabling = false;
121 ret = tethering_enable(ad->handle, TETHERING_TYPE_USB);
122 if (ret != TETHERING_ERROR_NONE) {
123 ERR("Error enable usb tethering : %d\n", ret);
124 _update_usb_item(ad, MH_STATE_NONE);
128 case MH_POPUP_WIFI_OFF:
129 ret = tethering_disable(ad->handle, TETHERING_TYPE_WIFI);
130 if (ret != TETHERING_ERROR_NONE) {
131 ERR("wifi tethering off is failed : %d\n", ret);
132 _update_wifi_item(ad, MH_STATE_NONE);
134 _send_signal_qp(QP_SIGNAL_PROGRESS_OFF);
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 _send_signal_qp(QP_SIGNAL_PROGRESS_RESET);
151 _wifi_tethering_checkbox_popup_status_set(false);
154 case MH_POPUP_BT_ON_CHECKBOX:
155 _update_tethering_enabling_item(ad, TETHERING_TYPE_BT, MH_STATE_NONE);
158 case MH_POPUP_USB_ON_CHECKBOX:
159 _update_tethering_enabling_item(ad, TETHERING_TYPE_USB, MH_STATE_NONE);
162 case MH_POPUP_WIFI_AP_OFF:
163 if (ad->setup.genlist)
164 elm_naviframe_item_pop(ad->naviframe);
165 elm_naviframe_item_pop(ad->naviframe);
168 case MH_POPUP_WIFI_OFF:
169 _update_tethering_enabling_item(ad, TETHERING_TYPE_WIFI, MH_STATE_NONE);
170 _send_signal_qp(QP_SIGNAL_PROGRESS_RESET);
173 case MH_POPUP_MOBILE_DATA_OFF:
174 _update_tethering_enabling_item(ad, ad->type, MH_STATE_NONE);
177 ERR("Unknown popup_type : %d\n", popup_type);
182 __MOBILE_AP_FUNC_EXIT__;
185 void _teth_on(mh_appdata_t *ad)
187 __handle_popup_resp(ad, true);
190 static void __popup_yes_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
192 if (data == NULL || obj == NULL) {
193 ERR("The param is NULL\n");
197 __handle_popup_resp(data, true);
200 static void __popup_no_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
202 if (data == NULL || obj == NULL) {
203 ERR("The param is NULL\n");
207 __handle_popup_resp(data, false);
210 static void __popup_no_btn_mouse_event_cb(void *data, Evas *evas, Evas_Object *obj, void *event_info)
212 if (data == NULL || obj == NULL) {
213 ERR("The param is NULL\n");
217 Evas_Event_Mouse_Up *ev = event_info;
220 __handle_popup_resp(data, false);
223 static void __popup_block_clicked_cb(void *data, Evas_Object *obj, void *event_info)
226 ERR("The param is NULL\n");
230 elm_popup_dismiss(obj);
233 static void __popup_hide_finished_cb(void *data, Evas_Object *obj, void *event_info)
236 ERR("The param is NULL\n");
240 __handle_popup_resp(data, false);
243 void _prepare_popup_with_content(int type, Evas_Object *obj)
245 __MOBILE_AP_FUNC_ENTER__;
248 ERR("param is NULL\n");
255 evas_object_del(popup_content);
263 __MOBILE_AP_FUNC_EXIT__;
266 void _prepare_popup(int type, const char *str)
268 __MOBILE_AP_FUNC_ENTER__;
271 ERR("param is NULL\n");
276 popup_content = NULL;
281 popup_string = strndup(str, MH_LABEL_LENGTH_MAX);
282 if (popup_string == NULL)
283 ERR("strndup is failed\n");
285 __MOBILE_AP_FUNC_EXIT__;
288 void _prepare_popup_type(int type)
293 static void __language_changed_cb(void *data, Evas_Object *obj, void *event_info)
295 __MOBILE_AP_FUNC_ENTER__;
297 mh_appdata_t *ad = (mh_appdata_t *)data;
298 Evas_Object *label = NULL;
299 bool wifi_state = false;
301 char str[MH_LABEL_LENGTH_MAX];
303 if (ad->type < TETHERING_TYPE_USB || ad->type > TETHERING_TYPE_BT) {
304 ERR("Invalid Tethering type\n");
309 case TETHERING_TYPE_WIFI:
310 wifi_is_activated(&wifi_state);
311 _set_vconf_prev_wifi_state(wifi_state);
312 if (wifi_state == true || _is_wifi_direct_on() == true)
313 fmt = STR_TETH_ON_DESC_1;
315 fmt = STR_TETH_ON_DESC_2;
317 snprintf(str, MH_LABEL_LENGTH_MAX, fmt, TETHERING_WIFI_MAX_CONNECTED_STA);
320 case TETHERING_TYPE_BT:
321 fmt = STR_TETH_ON_DESC_2;
322 snprintf(str, MH_LABEL_LENGTH_MAX, fmt, TETHERING_BT_MAX_CONNECTED_STA);
325 case TETHERING_TYPE_USB:
326 snprintf(str, MH_LABEL_LENGTH_MAX, STR_TETH_ON_DESC_3);
332 label = elm_label_add(ad->main.check_popup_ly);
333 elm_object_style_set(label, "popup/default");
334 elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
335 elm_object_text_set(label, str);
336 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
337 evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
338 evas_object_show(label);
339 elm_object_part_content_set(ad->main.check_popup_ly, "elm.swallow.content", label);
341 __MOBILE_AP_FUNC_EXIT__;
344 static void __popup_with_checkbox(mh_appdata_t *ad)
346 __MOBILE_AP_FUNC_ENTER__;
348 Evas_Object *popup = NULL;
349 Evas_Object *yes_button = NULL;
350 Evas_Object *cancel_button = NULL;
351 Evas_Object *layout = NULL;
352 Evas_Object *label = NULL;
353 Evas_Object *check = NULL;
355 popup = elm_popup_add(ad->win);
356 elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
357 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
360 case TETHERING_TYPE_WIFI:
361 elm_object_domain_translatable_part_text_set(popup, "title,text", PACKAGE,
362 "IDS_MOBILEAP_MBODY_WI_FI_TETHERING");
364 case TETHERING_TYPE_BT:
365 elm_object_domain_translatable_part_text_set(popup, "title,text", PACKAGE,
366 "IDS_MOBILEAP_BODY_BLUETOOTH_TETHERING");
368 case TETHERING_TYPE_USB:
369 elm_object_domain_translatable_part_text_set(popup, "title,text", PACKAGE,
370 "IDS_MOBILEAP_MBODY_USB_TETHERING");
377 layout = elm_layout_add(popup);
378 elm_layout_file_set(layout, FILE_PATH_OF_EDC, "popup_checkview_layout");
379 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
380 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, 1.0);
381 ad->main.check_popup_ly = layout;
384 check = elm_check_add(popup);
385 elm_object_style_set(check, "popup");
386 elm_object_domain_translatable_text_set(check, PACKAGE, STR_NO_SHOW_AGAIN);
387 evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL);
388 evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
389 elm_object_part_content_set(layout, "elm.swallow.end", check);
390 ad->popup_checkbox = check;
393 label = elm_label_add(layout);
394 elm_object_style_set(label, "popup/default");
395 elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
396 elm_object_text_set(label, popup_string);
397 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
398 evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
399 evas_object_show(label);
400 elm_object_part_content_set(layout, "elm.swallow.content", label);
402 cancel_button = _create_button(popup, "IDS_BR_SK_CANCEL",
403 "button1", __popup_no_btn_clicked_cb, ad);
404 yes_button = _create_button(popup, "IDS_ST_BUTTON_ENABLE_M_USE",
405 "button2", __popup_yes_btn_clicked_cb, ad);
407 evas_object_smart_callback_add(popup, "language,changed", __language_changed_cb, ad);
409 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK,
410 __popup_no_btn_clicked_cb, (void *)ad);
412 evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP,
413 __popup_no_btn_mouse_event_cb, (void *)ad);
414 evas_object_smart_callback_add(popup, "block,clicked",
415 __popup_block_clicked_cb, NULL);
416 evas_object_smart_callback_add(popup, "dismissed",
417 __popup_hide_finished_cb, ad);
420 if (check && yes_button) {
421 elm_object_focus_next_object_set(check, yes_button, ELM_FOCUS_PREVIOUS);
422 elm_object_focus_next_object_set(yes_button, check, ELM_FOCUS_NEXT);
424 elm_object_focus_next_object_set(cancel_button, check, ELM_FOCUS_PREVIOUS);
425 elm_object_focus_next_object_set(check , cancel_button, ELM_FOCUS_NEXT);
429 elm_object_content_set(popup, layout);
430 evas_object_show(popup);
433 __MOBILE_AP_FUNC_EXIT__;
436 Eina_Bool _create_popup(mh_appdata_t *ad)
438 __MOBILE_AP_FUNC_ENTER__;
440 Evas_Object *popup = NULL;
441 Evas_Object *cancel_button = NULL;
442 Evas_Object *yes_button = NULL;
445 ERR("The param is NULL\n");
450 popup_content = NULL;
455 if (ad->popup != NULL) {
456 evas_object_del(ad->popup);
459 ad->popup_checkbox = NULL;
460 DBG("popup type : %d", popup_type);
462 switch (popup_type) {
463 case MH_POPUP_WIFI_ON_CHECKBOX:
464 case MH_POPUP_BT_ON_CHECKBOX:
465 case MH_POPUP_USB_ON_CHECKBOX:
466 __popup_with_checkbox(ad);
469 case MH_POPUP_WIFI_OFF:
470 popup = elm_popup_add(ad->win);
473 elm_object_domain_translatable_part_text_set(popup, "title,text", PACKAGE,
474 "IDS_MOBILEAP_MBODY_WI_FI_TETHERING");
476 evas_object_size_hint_weight_set(popup,
477 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
479 if (popup_content == NULL)
480 elm_object_domain_translatable_text_set(popup, PACKAGE, popup_string);
482 elm_object_content_set(popup, popup_content);
484 cancel_button = _create_button(popup, STR_CANCEL,
485 "button1", __popup_no_btn_clicked_cb, ad);
486 yes_button = _create_button(popup, STR_TURN_OFF,
487 "button2", __popup_yes_btn_clicked_cb, ad);
489 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK,
490 __popup_no_btn_clicked_cb, (void *)ad);
491 evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP,
492 __popup_no_btn_mouse_event_cb, (void *)ad);
493 evas_object_smart_callback_add(popup, "block,clicked",
494 __popup_block_clicked_cb, NULL);
495 evas_object_smart_callback_add(popup, "dismissed",
496 __popup_hide_finished_cb, ad);
498 evas_object_show(popup);
501 case MH_POPUP_TETH_ENABLING_FAILED:
502 case MH_POPUP_NO_SIM:
503 case MH_POPUP_FLIGHT_MODE:
504 case MH_POPUP_NETWORK_OUT_OF_RANGE:
505 popup = elm_popup_add(ad->win);
507 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
510 if (popup_content == NULL)
511 elm_object_domain_translatable_text_set(popup, PACKAGE, popup_string);
513 elm_object_content_set(popup, popup_content);
514 elm_object_domain_translatable_part_text_set(popup, "title,text", PACKAGE,
516 cancel_button = _create_button(popup, STR_CANCEL,
517 "button1", __popup_no_btn_clicked_cb, ad);
519 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK,
520 __popup_no_btn_clicked_cb, (void *)ad);
521 evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP,
522 __popup_no_btn_mouse_event_cb, (void *)ad);
523 evas_object_smart_callback_add(popup, "block,clicked",
524 __popup_block_clicked_cb, NULL);
525 evas_object_smart_callback_add(popup, "dismissed",
526 __popup_hide_finished_cb, ad);
528 evas_object_show(popup);
531 case MH_POPUP_MOBILE_DATA_OFF:
532 popup = elm_popup_add(ad->win);
534 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
537 if (popup_content == NULL)
538 elm_object_domain_translatable_text_set(popup, PACKAGE, popup_string);
540 elm_object_content_set(popup, popup_content);
541 elm_object_domain_translatable_part_text_set(popup, "title,text", PACKAGE,
543 cancel_button = _create_button(popup, STR_CANCEL,
544 "button1", __popup_no_btn_clicked_cb, ad);
545 yes_button = _create_button(popup, STR_SETTING,
546 "button2", __popup_yes_btn_clicked_cb, ad);
548 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK,
549 __popup_no_btn_clicked_cb, (void *)ad);
550 evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP,
551 __popup_no_btn_mouse_event_cb, (void *)ad);
552 evas_object_smart_callback_add(popup, "block,clicked",
553 __popup_block_clicked_cb, NULL);
554 evas_object_smart_callback_add(popup, "dismissed",
555 __popup_hide_finished_cb, ad);
557 evas_object_show(popup);
560 case MH_POPUP_WIFI_AP_OFF:
561 popup = elm_popup_add(ad->win);
563 evas_object_size_hint_weight_set(popup,
564 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
566 elm_object_domain_translatable_part_text_set(popup, "title,text", PACKAGE,
568 if (popup_content == NULL)
569 elm_object_domain_translatable_text_set(popup, PACKAGE, popup_string);
571 elm_object_content_set(popup, popup_content);
573 cancel_button = _create_button(popup, STR_CANCEL,
574 "button1", __popup_no_btn_clicked_cb, ad);
575 yes_button = _create_button(popup, STR_ENABLE,
576 "button2", __popup_yes_btn_clicked_cb, ad);
578 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK,
579 __popup_no_btn_clicked_cb, (void *)ad);
580 evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP,
581 __popup_no_btn_mouse_event_cb, (void *)ad);
583 evas_object_show(popup);
587 ERR("Unknown popup_type : %d\n", popup_type);
591 if (cancel_button && yes_button) {
592 elm_object_focus_next_object_set(cancel_button, yes_button, ELM_FOCUS_PREVIOUS);
593 elm_object_focus_next_object_set(yes_button, cancel_button, ELM_FOCUS_NEXT);
600 popup_content = NULL;
602 __MOBILE_AP_FUNC_EXIT__;
607 void _destroy_popup(mh_appdata_t *ad)
609 __MOBILE_AP_FUNC_ENTER__;
617 evas_object_del(ad->popup);
620 ad->popup_checkbox = NULL;
626 popup_content = NULL;
627 popup_type = MH_POPUP_NONE;
629 __MOBILE_AP_FUNC_EXIT__;
634 void _create_security_restriction_noti(tethering_type_e type)
637 char restricted_type[MAX_BUF_SIZE] = {0, };
641 case TETHERING_TYPE_WIFI:
642 g_strlcpy(restricted_type, "wifi tethering", MAX_BUF_SIZE - 1);
644 case TETHERING_TYPE_USB:
645 g_strlcpy(restricted_type, "usb tethering", MAX_BUF_SIZE - 1);
647 case TETHERING_TYPE_BT:
648 g_strlcpy(restricted_type, "bt tethering", MAX_BUF_SIZE - 1);
651 ERR("Invalid type.\n");
656 bundle_add(b, "_SYSPOPUP_TYPE_", "toast_popup");
657 bundle_add(b, "_SYSPOPUP_CONTENT_", "security restriction");
658 bundle_add(b, "_RESTRICTED_TYPE_", restricted_type);
660 DBG("Launch security restriction alert network popup");
661 ret = aul_launch_app(NETPOPUP, b);
663 ERR("Fail to launch syspopup");