UI issues are fixed
[apps/native/ug-mobile-ap.git] / src / mh_common_utility.c
index 84c2d43..b39eea2 100644 (file)
 #include "mh_common_utility.h"
 #include "mobile_hotspot.h"
 
+static mh_popup_type_e popup_type = MH_POPUP_NONE;
+static Evas_Object *popup_content = NULL;
+static char *popup_string = NULL;
+
 static void __one_btn_popup_resp(void *data, Evas_Object *obj, void *event_info)
 {
        __MOBILE_AP_FUNC_ENTER__;
@@ -34,8 +38,8 @@ static void __one_btn_popup_resp(void *data, Evas_Object *obj, void *event_info)
        evas_object_del(ad->popup);
        ad->popup = NULL;
 
-       DBG("popup_type : %d\n", ad->popup_type);
-       switch (ad->popup_type) {
+       DBG("popup_type : %d\n", popup_type);
+       switch (popup_type) {
        case MH_POP_USB_CONNECT:
                _update_usb_item(ad, MH_STATE_NONE);
                vconf_ignore_key_changed(VCONFKEY_SETAPPL_USB_MODE_INT,
@@ -45,16 +49,8 @@ static void __one_btn_popup_resp(void *data, Evas_Object *obj, void *event_info)
        case MH_POP_INFORMATION:
                break;
 
-       case MH_POP_WIFI_PASSWORD_SHORT:
-               if (ad->setup.pw_entry == NULL)
-                       break;
-
-               evas_object_show(ad->setup.pw_entry);
-               elm_object_focus_set(ad->setup.pw_entry, EINA_TRUE);
-               break;
-
        default:
-               DBG("Unknown popup_type : %d\n", ad->popup_type);
+               DBG("Unknown popup_type : %d\n", popup_type);
                break;
        }
 
@@ -75,13 +71,13 @@ static void __alert_popup_resp(void *data, Evas_Object *obj, void *event_info)
        evas_object_del(ad->popup);
        ad->popup = NULL;
 
-       DBG("popup_type : %d\n", ad->popup_type);
-       switch (ad->popup_type) {
+       DBG("popup_type : %d\n", popup_type);
+       switch (popup_type) {
        case MH_POP_INFORMATION_WO_BUTTON:
                break;
 
        default:
-               DBG("Unknown popup_type : %d\n", ad->popup_type);
+               DBG("Unknown popup_type : %d\n", popup_type);
                break;
        }
 
@@ -104,8 +100,8 @@ static void __popup_resp_yes(void *data, Evas_Object *obj, void *event_info)
        evas_object_del(ad->popup);
        ad->popup = NULL;
 
-       DBG("popup_type : %d\n", ad->popup_type);
-       switch (ad->popup_type) {
+       DBG("popup_type : %d\n", popup_type);
+       switch (popup_type) {
        case MH_POP_WIFI_ON_CONF:
                wifi_is_activated(&wifi_state);
                if (wifi_state == true) {
@@ -145,7 +141,7 @@ static void __popup_resp_yes(void *data, Evas_Object *obj, void *event_info)
 
        case MH_POP_USB_ON_CONF:
                if (_get_vconf_usb_state() != VCONFKEY_SYSMAN_USB_AVAILABLE) {
-                       _prepare_popup(ad, MH_POP_USB_CONNECT,
+                       _prepare_popup(MH_POP_USB_CONNECT,
                                        _("IDS_MOBILEAP_POP_CONNECT_USB_CABLE"));
                        _create_popup(ad);
                        vconf_notify_key_changed(VCONFKEY_SETAPPL_USB_MODE_INT,
@@ -153,6 +149,12 @@ static void __popup_resp_yes(void *data, Evas_Object *obj, void *event_info)
                        break;
                }
 
+               _prepare_popup(MH_POP_USB_ON_PREVCONN_CONF,
+                               _("IDS_MOBILEAP_POP_ENABLING_USB_TETHERING_WILL_DISCONNECT_PREVIOUS_USB_CONNECTION"));
+               _create_popup(ad);
+               break;
+
+       case MH_POP_USB_ON_PREVCONN_CONF:
                ret = tethering_enable(ad->handle, TETHERING_TYPE_USB);
                if (ret != TETHERING_ERROR_NONE) {
                        ERR("Error enable usb tethering : %d\n", ret);
@@ -164,16 +166,16 @@ static void __popup_resp_yes(void *data, Evas_Object *obj, void *event_info)
                _update_wifi_item(ad, MH_STATE_PROCESS);
                ret = tethering_disable(ad->handle, TETHERING_TYPE_WIFI);
                if (ret != TETHERING_ERROR_NONE) {
-                       ERR("wifi tethering off is failed : %d\n", ret);
+                       ERR("Wi-Fi tethering off is failed : %d\n", ret);
                        _update_wifi_item(ad, MH_STATE_NONE);
                } else
-                       ad->main.old_wifi_state = true;
+                       ad->main.need_recover_wifi_tethering = true;
 
                mh_draw_wifi_setup_view(ad);
                break;
 
        default:
-               DBG("Unknown popup_type : %d\n", ad->popup_type);
+               DBG("Unknown popup_type : %d\n", popup_type);
                break;
        }
 
@@ -194,8 +196,8 @@ static void __popup_resp_no(void *data, Evas_Object *obj, void *event_info)
        evas_object_del(ad->popup);
        ad->popup = NULL;
 
-       DBG("popup_type : %d\n", ad->popup_type);
-       switch (ad->popup_type) {
+       DBG("popup_type : %d\n", popup_type);
+       switch (popup_type) {
        case MH_POP_WIFI_ON_CONF:
                _update_wifi_item(ad, MH_STATE_NONE);
                break;
@@ -212,11 +214,15 @@ static void __popup_resp_no(void *data, Evas_Object *obj, void *event_info)
                _update_usb_item(ad, MH_STATE_NONE);
                break;
 
+       case MH_POP_USB_ON_PREVCONN_CONF:
+               _update_usb_item(ad, MH_STATE_NONE);
+               break;
+
        case MH_POP_ENTER_TO_WIFI_SETUP_CONF:
                break;
 
        default:
-               DBG("Unknown popup_type : %d\n", ad->popup_type);
+               DBG("Unknown popup_type : %d\n", popup_type);
                break;
        }
 
@@ -237,24 +243,47 @@ static bool _count_connected_clients_cb(tethering_client_h client, void *user_da
        return true;
 }
 
-void _prepare_popup(mh_appdata_t *ad, int type, const char *str)
+void _prepare_popup_with_content(int type, Evas_Object *obj)
+{
+       __MOBILE_AP_FUNC_ENTER__;
+
+       if (obj == NULL) {
+               ERR("param is NULL\n");
+               return;
+       }
+
+       popup_type = type;
+
+       if (popup_content)
+               evas_object_del(popup_content);
+       popup_content = obj;
+
+       if (popup_string) {
+               free(popup_string);
+               popup_string = NULL;
+       }
+
+       __MOBILE_AP_FUNC_EXIT__;
+}
+
+void _prepare_popup(int type, const char *str)
 {
        __MOBILE_AP_FUNC_ENTER__;
 
-       if (ad == NULL || str == NULL) {
-               ERR("param is NULL : ad[%x], str[%x]\n", ad, str);
+       if (str == NULL) {
+               ERR("param is NULL\n");
                return;
        }
 
-       int nLen = 0;
+       popup_type = type;
+       popup_content = NULL;
 
-       nLen = strlen(str);
-       if (sizeof(ad->popup_string) <= nLen)
-               ERR("We should make the message[%s] less than %d",
-                               str, sizeof(ad->popup_string));
+       if (popup_string)
+               free(popup_string);
 
-       ad->popup_type = type;
-       snprintf(ad->popup_string, sizeof(ad->popup_string), "%s", str);
+       popup_string = strndup(str, MH_LABEL_LENGTH_MAX);
+       if (popup_string == NULL)
+               ERR("strndup is failed\n");
 
        __MOBILE_AP_FUNC_EXIT__;
 }
@@ -267,7 +296,13 @@ Eina_Bool _create_popup(mh_appdata_t *ad)
 
        if (ad == NULL) {
                ERR("The param is NULL\n");
-               return 0;
+               if (popup_string) {
+                       free(popup_string);
+                       popup_string = NULL;
+               }
+               popup_content = NULL;
+
+               return EINA_FALSE;
        }
 
        if (ad->popup != NULL) {
@@ -276,14 +311,17 @@ Eina_Bool _create_popup(mh_appdata_t *ad)
                ad->popup = NULL;
        }
 
-       DBG("Create_popup %d\n", ad->popup_type);
-       switch (ad->popup_type) {
+       DBG("Create_popup %d\n", popup_type);
+       switch (popup_type) {
        case MH_POP_WIFI_ON_CONF:
                ad->popup = elm_popup_add(ad->win);
                evas_object_size_hint_weight_set(ad->popup,
                                EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
 
-               elm_object_text_set(ad->popup, ad->popup_string);
+               if (popup_content == NULL)
+                       elm_object_text_set(ad->popup, popup_string);
+               else
+                       elm_object_content_set(ad->popup, popup_content);
 
                btn = elm_button_add(ad->popup);
                elm_object_style_set(btn, "popup_button/default");
@@ -307,7 +345,10 @@ Eina_Bool _create_popup(mh_appdata_t *ad)
                evas_object_size_hint_weight_set(ad->popup,
                                EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
 
-               elm_object_text_set(ad->popup, ad->popup_string);
+               if (popup_content == NULL)
+                       elm_object_text_set(ad->popup, popup_string);
+               else
+                       elm_object_content_set(ad->popup, popup_content);
 
                btn = elm_button_add(ad->popup);
                elm_object_style_set(btn, "popup_button/default");
@@ -331,7 +372,10 @@ Eina_Bool _create_popup(mh_appdata_t *ad)
                evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND,
                                EVAS_HINT_EXPAND);
 
-               elm_object_text_set(ad->popup, ad->popup_string);
+               if (popup_content == NULL)
+                       elm_object_text_set(ad->popup, popup_string);
+               else
+                       elm_object_content_set(ad->popup, popup_content);
 
                btn = elm_button_add(ad->popup);
                elm_object_style_set(btn, "popup_button/default");
@@ -348,18 +392,21 @@ Eina_Bool _create_popup(mh_appdata_t *ad)
                evas_object_size_hint_weight_set(ad->popup,
                                EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
 
-               elm_object_text_set(ad->popup, ad->popup_string);
+               if (popup_content == NULL)
+                       elm_object_text_set(ad->popup, popup_string);
+               else
+                       elm_object_content_set(ad->popup, popup_content);
 
                btn = elm_button_add(ad->popup);
                elm_object_style_set(btn, "popup_button/default");
-               elm_object_text_set(btn, S_("IDS_COM_SK_YES"));
+               elm_object_text_set(btn, S_("IDS_COM_SK_OK"));
                elm_object_part_content_set(ad->popup, "button1", btn);
                evas_object_smart_callback_add(btn, "clicked",
                                __popup_resp_yes, (void *)ad);
 
                btn = elm_button_add(ad->popup);
                elm_object_style_set(btn, "popup_button/default");
-               elm_object_text_set(btn, S_("IDS_COM_SK_NO"));
+               elm_object_text_set(btn, S_("IDS_COM_SK_CANCEL"));
                elm_object_part_content_set(ad->popup, "button2", btn);
                evas_object_smart_callback_add(btn, "clicked",
                                __popup_resp_no, (void *)ad);
@@ -368,22 +415,26 @@ Eina_Bool _create_popup(mh_appdata_t *ad)
                break;
 
        case MH_POP_USB_ON_CONF:
+       case MH_POP_USB_ON_PREVCONN_CONF:
                ad->popup = elm_popup_add(ad->win);
                evas_object_size_hint_weight_set(ad->popup,
                                EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
 
-               elm_object_text_set(ad->popup, ad->popup_string);
+               if (popup_content == NULL)
+                       elm_object_text_set(ad->popup, popup_string);
+               else
+                       elm_object_content_set(ad->popup, popup_content);
 
                btn = elm_button_add(ad->popup);
                elm_object_style_set(btn, "popup_button/default");
-               elm_object_text_set(btn, S_("IDS_COM_SK_YES"));
+               elm_object_text_set(btn, S_("IDS_COM_SK_OK"));
                elm_object_part_content_set(ad->popup, "button1", btn);
                evas_object_smart_callback_add(btn, "clicked",
                                __popup_resp_yes, (void *)ad);
 
                btn = elm_button_add(ad->popup);
                elm_object_style_set(btn, "popup_button/default");
-               elm_object_text_set(btn, S_("IDS_COM_SK_NO"));
+               elm_object_text_set(btn, S_("IDS_COM_SK_CANCEL"));
                elm_object_part_content_set(ad->popup, "button2", btn);
                evas_object_smart_callback_add(btn, "clicked",
                                __popup_resp_no, (void *)ad);
@@ -396,24 +447,10 @@ Eina_Bool _create_popup(mh_appdata_t *ad)
                evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND,
                                EVAS_HINT_EXPAND);
 
-               elm_object_text_set(ad->popup, ad->popup_string);
-
-               btn = elm_button_add(ad->popup);
-               elm_object_style_set(btn, "popup_button/default");
-               elm_object_text_set(btn, S_("IDS_COM_POP_CLOSE"));
-               elm_object_part_content_set(ad->popup, "button1", btn);
-               evas_object_smart_callback_add(btn, "clicked",
-                               __one_btn_popup_resp, (void *)ad);
-
-               evas_object_show(ad->popup);
-               break;
-
-       case MH_POP_WIFI_PASSWORD_SHORT:
-               ad->popup = elm_popup_add(ad->win);
-               evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND,
-                               EVAS_HINT_EXPAND);
-
-               elm_object_text_set(ad->popup, ad->popup_string);
+               if (popup_content == NULL)
+                       elm_object_text_set(ad->popup, popup_string);
+               else
+                       elm_object_content_set(ad->popup, popup_content);
 
                btn = elm_button_add(ad->popup);
                elm_object_style_set(btn, "popup_button/default");
@@ -430,7 +467,10 @@ Eina_Bool _create_popup(mh_appdata_t *ad)
                evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND,
                                EVAS_HINT_EXPAND);
 
-               elm_object_text_set(ad->popup, ad->popup_string);
+               if (popup_content == NULL)
+                       elm_object_text_set(ad->popup, popup_string);
+               else
+                       elm_object_content_set(ad->popup, popup_content);
 
                elm_popup_timeout_set(ad->popup, MH_POPUP_TIMEOUT);
                evas_object_smart_callback_add(ad->popup, "timeout",
@@ -446,7 +486,10 @@ Eina_Bool _create_popup(mh_appdata_t *ad)
                evas_object_size_hint_weight_set(ad->popup,
                                EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
 
-               elm_object_text_set(ad->popup, ad->popup_string);
+               if (popup_content == NULL)
+                       elm_object_text_set(ad->popup, popup_string);
+               else
+                       elm_object_content_set(ad->popup, popup_content);
 
                btn = elm_button_add(ad->popup);
                elm_object_style_set(btn, "popup_button/default");
@@ -464,28 +507,37 @@ Eina_Bool _create_popup(mh_appdata_t *ad)
 
                evas_object_show(ad->popup);
                break;
+       default:
+               ERR("Unknown popup_type : %d\n", popup_type);
+               break;
        }
 
+       if (popup_string) {
+               free(popup_string);
+               popup_string = NULL;
+       }
+       popup_content = NULL;
+
        __MOBILE_AP_FUNC_EXIT__;
 
-       return TRUE;
+       return EINA_TRUE;
 }
 
 void _destroy_popup(mh_appdata_t *ad)
 {
        __MOBILE_AP_FUNC_ENTER__;
 
-       if (ad == NULL) {
-               ERR("ad is NULL\n");
-               return;
-       }
-
-       if (ad->popup) {
+       if (ad && ad->popup) {
                evas_object_del(ad->popup);
                ad->popup = NULL;
        }
 
-       ad->popup_type = MH_POPUP_NONE;
+       if (popup_string) {
+               free(popup_string);
+               popup_string = NULL;
+       }
+       popup_content = NULL;
+       popup_type = MH_POPUP_NONE;
 
        __MOBILE_AP_FUNC_EXIT__;
 
@@ -613,31 +665,6 @@ void _handle_usb_mode_change(keynode_t *key, void *data)
        }
 }
 
-Eina_Bool _hide_imf(Evas_Object *entry)
-{
-       __MOBILE_AP_FUNC_ENTER__;
-
-       if (entry == NULL) {
-               ERR("Invalid param\n");
-               return EINA_FALSE;
-       }
-
-       Ecore_IMF_Context *context = NULL;
-
-       context = elm_entry_imf_context_get(entry);
-       if (context == NULL) {
-               ERR("context is NULL\n");
-               return EINA_FALSE;
-       }
-       ecore_imf_context_input_panel_hide(context);
-
-       elm_object_focus_set(entry, EINA_FALSE);
-
-       __MOBILE_AP_FUNC_EXIT__;
-
-       return EINA_TRUE;
-}
-
 int _get_vconf_hotspot_mode(void)
 {
        int value = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
@@ -662,3 +689,43 @@ Eina_Bool _get_no_of_connected_device(tethering_h handle, int *no, tethering_typ
 
        return TRUE;
 }
+
+Evas_Object *_create_label(Evas_Object *parent, const char *text)
+{
+       Evas_Object *label;
+
+       label = elm_entry_add(parent);
+       if (label == NULL) {
+               ERR("elm_entry_add is failed\n");
+               return NULL;
+       }
+
+       elm_entry_editable_set(label, EINA_FALSE);
+       elm_entry_context_menu_disabled_set(label, EINA_TRUE);
+       elm_object_text_set(label, text);
+
+       evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
+       evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
+       evas_object_show(label);
+
+       return label;
+}
+
+Evas_Object *_create_slide_title(Evas_Object *parent, const char *text)
+{
+       if (parent == NULL || text == NULL)
+               return NULL;
+
+       Evas_Object *label;
+
+       label = elm_label_add(parent);
+       elm_object_style_set(label, "naviframe_title");
+       elm_label_slide_mode_set(label, ELM_LABEL_SLIDE_MODE_AUTO);
+       elm_label_wrap_width_set(label, 1);
+       elm_label_ellipsis_set(label, EINA_TRUE);
+       elm_object_text_set(label, text);
+       evas_object_show(label);
+
+       elm_access_object_unregister(label);
+       return label;
+}
\ No newline at end of file