Replaced Wi-Fi CAPI with Wi-Fi manager CAPI
[apps/native/ug-mobile-ap.git] / src / mh_popup.c
index 8793aa8..2c9a088 100755 (executable)
@@ -3,7 +3,7 @@
 *
 * Copyright 2012  Samsung Electronics Co., Ltd
 
-* Licensed under the Flora License, Version 1.0 (the "License");
+* Licensed under the Flora License, Version 1.1 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 
 
 #include <efl_extension.h>
 #include <app_control_internal.h>
+#include <bundle.h>
+#include <bundle_internal.h>
+#include <aul.h>
 
 #include "mh_common_utility.h"
 #include "mobile_hotspot.h"
 #include "mh_popup.h"
 #include "mh_string.h"
 
+#define MAX_BUF_SIZE   (256u)
+#define NETPOPUP               "net.netpopup"
+#define NETWORK_SETTING_APP    "org.tizen.setting-network"
+
 static mh_popup_type_e popup_type = MH_POPUP_NONE;
 static Evas_Object *popup_content = NULL;
 static char *popup_string = NULL;
@@ -34,21 +41,20 @@ static void __launch_network_app(void)
        int ret = APP_CONTROL_ERROR_NONE;
        app_control_h app_control;
 
-       app_control_create(&app_control);
-       if(ret != APP_CONTROL_ERROR_NONE) {
+       ret = app_control_create(&app_control);
+       if (ret != APP_CONTROL_ERROR_NONE) {
                ERR("app_control_create failed");
                return;
        }
        app_control_set_operation(app_control, APP_CONTROL_OPERATION_DEFAULT);
        app_control_set_launch_mode(app_control, APP_CONTROL_LAUNCH_MODE_GROUP);
-       app_control_set_app_id(app_control, "setting-network-efl");
+       app_control_set_app_id(app_control, NETWORK_SETTING_APP);
 
        ret = app_control_send_launch_request(app_control, NULL, NULL);
-       if(ret == APP_CONTROL_ERROR_NONE) {
+       if (ret == APP_CONTROL_ERROR_NONE)
                DBG("Launch network ug successful");
-       } else {
+       else
                ERR("Fail to launch network ug");
-       }
 
        app_control_destroy(app_control);
 }
@@ -80,9 +86,9 @@ static void __handle_popup_resp(void *data, bool response)
        if (response == true) {
                switch (popup_type) {
                case MH_POPUP_WIFI_ON_CHECKBOX:
-                       if(state) {
+                       if (state)
                                _set_checkbox_status(TETHERING_TYPE_WIFI, 1);
-                       }
+
                        ad->is_wifi_teth_enabling = false;
                        ret = tethering_enable(ad->handle, TETHERING_TYPE_WIFI);
                        if (ret != TETHERING_ERROR_NONE) {
@@ -94,9 +100,9 @@ static void __handle_popup_resp(void *data, bool response)
                        break;
 
                case MH_POPUP_BT_ON_CHECKBOX:
-                       if(state) {
+                       if (state)
                                _set_checkbox_status(TETHERING_TYPE_BT, 1);
-                       }
+
                        ad->is_bt_teth_enabling = false;
                        ret = tethering_enable(ad->handle, TETHERING_TYPE_BT);
                        if (ret != TETHERING_ERROR_NONE) {
@@ -106,10 +112,10 @@ static void __handle_popup_resp(void *data, bool response)
                        break;
 
                case MH_POPUP_USB_ON_CHECKBOX:
-                       if(state) {
+                       if (state)
                                _set_checkbox_status(TETHERING_TYPE_USB, 1);
-                       }
-                       if (_get_vconf_usb_state() != VCONFKEY_SYSMAN_USB_AVAILABLE) {
+
+                       if (_get_vconf_usb_state() == VCONFKEY_SYSMAN_USB_DISCONNECTED) {
                                _update_tethering_item(ad, MH_STATE_NONE);
                                break;
                        }
@@ -121,13 +127,6 @@ static void __handle_popup_resp(void *data, bool response)
                        }
                        break;
 
-               case MH_POPUP_WIFI_AP_OFF:
-                       ret = tethering_disable(ad->handle, TETHERING_TYPE_RESERVED);
-                       if (ret != TETHERING_ERROR_NONE) {
-                               ERR("MobileAP off is failed : %d\n", ret);
-                       }
-                       break;
-
                case MH_POPUP_WIFI_OFF:
                        ret = tethering_disable(ad->handle, TETHERING_TYPE_WIFI);
                        if (ret != TETHERING_ERROR_NONE) {
@@ -159,7 +158,7 @@ static void __handle_popup_resp(void *data, bool response)
                        break;
 
                case MH_POPUP_USB_ON_CHECKBOX:
-                       _update_tethering_enabling_item(ad,TETHERING_TYPE_USB, MH_STATE_NONE);
+                       _update_tethering_enabling_item(ad, TETHERING_TYPE_USB, MH_STATE_NONE);
                        break;
 
                case MH_POPUP_WIFI_AP_OFF:
@@ -185,9 +184,76 @@ static void __handle_popup_resp(void *data, bool response)
        __MOBILE_AP_FUNC_EXIT__;
 }
 
+#ifdef TIZEN_FEATURE_EMULATOR
+static void __handle_emul_popup_resp(void *data, bool response)
+{
+       __MOBILE_AP_FUNC_ENTER__;
+
+       if (data == NULL) {
+               ERR("The param is NULL\n");
+               return;
+       }
+
+       mh_appdata_t *ad = (mh_appdata_t *)data;
+       Eina_Bool state = 0;
+
+       if (ad->popup_checkbox) {
+               state = elm_check_state_get(ad->popup_checkbox);
+               evas_object_del(ad->popup_checkbox);
+               ad->popup_checkbox = NULL;
+               DBG("Checkbox status is = %d\n", state);
+       }
+       if (ad->popup) {
+               evas_object_del(ad->popup);
+               ad->popup = NULL;
+       }
+
+       if (response == true) {
+               switch (popup_type) {
+               case MH_POPUP_WIFI_ON_CHECKBOX:
+                       if (state)
+                               _set_checkbox_status(TETHERING_TYPE_WIFI, 1);
+                       ad->is_wifi_teth_enabling = false;
+                       break;
+
+               case MH_POPUP_BT_ON_CHECKBOX:
+                       if (state)
+                               _set_checkbox_status(TETHERING_TYPE_BT, 1);
+                       ad->is_bt_teth_enabling = false;
+                       break;
+
+               default:
+                       ERR("Unknown popup_type : %d\n", popup_type);
+                       break;
+               }
+       } else {
+               switch (popup_type) {
+               case MH_POPUP_WIFI_ON_CHECKBOX:
+                       _update_tethering_enabling_item(ad, TETHERING_TYPE_WIFI, MH_STATE_NONE);
+                       _wifi_tethering_checkbox_popup_status_set(false);
+                       break;
+
+               case MH_POPUP_BT_ON_CHECKBOX:
+                       _update_tethering_enabling_item(ad, TETHERING_TYPE_BT, MH_STATE_NONE);
+                       break;
+
+               default:
+                       ERR("Unknown popup_type : %d\n", popup_type);
+                       break;
+               }
+       }
+
+       __MOBILE_AP_FUNC_EXIT__;
+}
+#endif
+
 void _teth_on(mh_appdata_t *ad)
 {
+#ifndef TIZEN_FEATURE_EMULATOR
        __handle_popup_resp(ad, true);
+#else
+       __handle_emul_popup_resp(ad, true);
+#endif
 }
 
 static void __popup_yes_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
@@ -197,7 +263,14 @@ static void __popup_yes_btn_clicked_cb(void *data, Evas_Object *obj, void *event
                return;
        }
 
+#ifndef TIZEN_FEATURE_EMULATOR
        __handle_popup_resp(data, true);
+#else
+       mh_appdata_t *ad = (mh_appdata_t *)data;
+
+       __handle_emul_popup_resp(data, true);
+       _update_emul_main_view(ad, _get_selected_type(), _get_selected_state());
+#endif
 }
 
 static void __popup_no_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
@@ -207,7 +280,11 @@ static void __popup_no_btn_clicked_cb(void *data, Evas_Object *obj, void *event_
                return;
        }
 
+#ifndef TIZEN_FEATURE_EMULATOR
        __handle_popup_resp(data, false);
+#else
+       __handle_emul_popup_resp(data, false);
+#endif
 }
 
 static void __popup_no_btn_mouse_event_cb(void *data, Evas *evas, Evas_Object *obj, void *event_info)
@@ -219,9 +296,12 @@ static void __popup_no_btn_mouse_event_cb(void *data, Evas *evas, Evas_Object *o
 
        Evas_Event_Mouse_Up *ev = event_info;
 
-       if (ev->button == 3) {
+       if (ev->button == 3)
+#ifndef TIZEN_FEATURE_EMULATOR
                __handle_popup_resp(data, false);
-       }
+#else
+               __handle_emul_popup_resp(data, false);
+#endif
 }
 
 static void __popup_block_clicked_cb(void *data, Evas_Object *obj, void *event_info)
@@ -241,7 +321,11 @@ static void __popup_hide_finished_cb(void *data, Evas_Object *obj, void *event_i
                return;
        }
 
+#ifndef TIZEN_FEAUTRE_EMULATOR
        __handle_popup_resp(data, false);
+#else
+       __handle_emul_popup_resp(data, false);
+#endif
 }
 
 void _prepare_popup_with_content(int type, Evas_Object *obj)
@@ -304,25 +388,26 @@ static void __language_changed_cb(void *data, Evas_Object *obj, void *event_info
        char *fmt = NULL;
        char str[MH_LABEL_LENGTH_MAX];
 
-       if (ad->type < TETHERING_TYPE_USB || ad->type > TETHERING_TYPE_BT ) {
+       if (ad->type < TETHERING_TYPE_USB || ad->type > TETHERING_TYPE_BT) {
                ERR("Invalid Tethering type\n");
                return;
        }
 
-       switch(ad->type) {
+       switch (ad->type) {
        case TETHERING_TYPE_WIFI:
-               wifi_is_activated(&wifi_state);
+               wifi_manager_is_activated(ad->wifi_handle, &wifi_state);
                _set_vconf_prev_wifi_state(wifi_state);
-               if (wifi_state == true || _is_wifi_direct_on() == true) {
+               if (wifi_state == true || _is_wifi_direct_on() == true)
                        fmt = STR_TETH_ON_DESC_1;
-               } else {
+               else
                        fmt = STR_TETH_ON_DESC_2;
-               }
+
                snprintf(str, MH_LABEL_LENGTH_MAX, fmt, TETHERING_WIFI_MAX_CONNECTED_STA);
                break;
 
        case TETHERING_TYPE_BT:
-               snprintf(str, MH_LABEL_LENGTH_MAX, STR_TETH_ON_DESC_2, TETHERING_BT_MAX_CONNECTED_STA);
+               fmt = STR_TETH_ON_DESC_2;
+               snprintf(str, MH_LABEL_LENGTH_MAX, fmt, TETHERING_BT_MAX_CONNECTED_STA);
                break;
 
        case TETHERING_TYPE_USB:
@@ -425,7 +510,7 @@ static void __popup_with_checkbox(mh_appdata_t *ad)
                elm_object_focus_next_object_set(yes_button, check, ELM_FOCUS_NEXT);
                if (cancel_button) {
                        elm_object_focus_next_object_set(cancel_button, check, ELM_FOCUS_PREVIOUS);
-                       elm_object_focus_next_object_set(check ,cancel_button, ELM_FOCUS_NEXT);
+                       elm_object_focus_next_object_set(check , cancel_button, ELM_FOCUS_NEXT);
                }
        }
 
@@ -471,6 +556,7 @@ Eina_Bool _create_popup(mh_appdata_t *ad)
 
        case MH_POPUP_WIFI_OFF:
                popup = elm_popup_add(ad->win);
+               elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
                ad->popup = popup;
 
                elm_object_domain_translatable_part_text_set(popup, "title,text", PACKAGE,
@@ -484,7 +570,7 @@ Eina_Bool _create_popup(mh_appdata_t *ad)
                else
                        elm_object_content_set(popup, popup_content);
 
-               cancel_button =_create_button(popup, STR_CANCEL,
+               cancel_button = _create_button(popup, STR_CANCEL,
                                "button1", __popup_no_btn_clicked_cb, ad);
                yes_button = _create_button(popup, STR_TURN_OFF,
                                "button2", __popup_yes_btn_clicked_cb, ad);
@@ -506,6 +592,7 @@ Eina_Bool _create_popup(mh_appdata_t *ad)
        case MH_POPUP_FLIGHT_MODE:
        case MH_POPUP_NETWORK_OUT_OF_RANGE:
                popup = elm_popup_add(ad->win);
+               elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
                ad->popup = popup;
                evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
                                EVAS_HINT_EXPAND);
@@ -533,6 +620,7 @@ Eina_Bool _create_popup(mh_appdata_t *ad)
 
        case MH_POPUP_MOBILE_DATA_OFF:
                popup = elm_popup_add(ad->win);
+               elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
                ad->popup = popup;
                evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
                                EVAS_HINT_EXPAND);
@@ -562,6 +650,7 @@ Eina_Bool _create_popup(mh_appdata_t *ad)
 
        case MH_POPUP_WIFI_AP_OFF:
                popup = elm_popup_add(ad->win);
+               elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
                ad->popup = popup;
                evas_object_size_hint_weight_set(popup,
                                EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
@@ -633,3 +722,38 @@ void _destroy_popup(mh_appdata_t *ad)
 
        return;
 }
+
+void _create_security_restriction_noti(tethering_type_e type)
+{
+       bundle *b = NULL;
+       char restricted_type[MAX_BUF_SIZE] = {0, };
+       int ret;
+
+       switch (type) {
+       case TETHERING_TYPE_WIFI:
+               g_strlcpy(restricted_type, "wifi tethering", MAX_BUF_SIZE - 1);
+               break;
+       case TETHERING_TYPE_USB:
+               g_strlcpy(restricted_type, "usb tethering", MAX_BUF_SIZE - 1);
+               break;
+       case TETHERING_TYPE_BT:
+               g_strlcpy(restricted_type, "bt tethering", MAX_BUF_SIZE - 1);
+               break;
+       default:
+               ERR("Invalid type.\n");
+               return;
+       }
+       b = bundle_create();
+
+       bundle_add(b, "_SYSPOPUP_TYPE_", "toast_popup");
+       bundle_add(b, "_SYSPOPUP_CONTENT_", "security restriction");
+       bundle_add(b, "_RESTRICTED_TYPE_", restricted_type);
+
+       DBG("Launch security restriction alert network popup");
+       ret = aul_launch_app(NETPOPUP, b);
+       if (ret < 0)
+               ERR("Fail to launch syspopup");
+
+       bundle_free(b);
+       return;
+}