[WGID-89732] Fix dereference issue
[apps/native/ug-mobile-ap.git] / src / mh_view_main.c
index c1403dc..ecc39e5 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
 
@@ -23,6 +23,7 @@
 #include <dpm/restriction.h>
 
 #include "mh_view_main.h"
+#include "mh_common_utility.h"
 #include "mh_popup.h"
 #include "mh_string.h"
 
@@ -38,6 +39,27 @@ void _genlist_update_device_item(mh_appdata_t *ad);
 mh_appdata_t *g_ad = NULL;
 #define UPDATE_INTERVAL 1
 
+#ifdef TIZEN_FEATURE_EMULATOR
+static tethering_type_e updated_type = TETHERING_TYPE_ALL;
+static tethering_type_e selected_type = TETHERING_TYPE_ALL;
+static Eina_Bool selected_state = EINA_FALSE;
+
+tethering_type_e _get_updated_type(void)
+{
+       return updated_type;
+}
+
+tethering_type_e _get_selected_type(void)
+{
+       return selected_type;
+}
+
+Eina_Bool _get_selected_state(void)
+{
+       return selected_state;
+}
+#endif
+
 void _list_connected_dev(mh_appdata_t *ap)
 {
        __MOBILE_AP_FUNC_ENTER__;
@@ -129,8 +151,37 @@ Eina_Bool ap_update_device_conn_time(void * data)
                return ECORE_CALLBACK_CANCEL;
        }
        mh_appdata_t *ad = (mh_appdata_t *)data;
-
        int count = 0;
+
+#ifdef TIZEN_FEATURE_EMULATOR
+       if (ad->main.hotspot_mode == VCONFKEY_MOBILE_HOTSPOT_MODE_NONE) {
+               _stop_update_device_conn_time(ad);
+               return ECORE_CALLBACK_CANCEL;
+       }
+
+       if (ad->main.hotspot_mode & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI) {
+               updated_type = TETHERING_TYPE_WIFI;
+               elm_genlist_item_fields_update(ad->main.emul_station_items[TETHERING_TYPE_WIFI],
+                                       "elm.text.sub", ELM_GENLIST_ITEM_FIELD_TEXT);
+       }
+
+       if (ad->main.hotspot_mode & VCONFKEY_MOBILE_HOTSPOT_MODE_BT) {
+               updated_type = TETHERING_TYPE_BT;
+               elm_genlist_item_fields_update(ad->main.emul_station_items[TETHERING_TYPE_BT],
+                                       "elm.text.sub", ELM_GENLIST_ITEM_FIELD_TEXT);
+       }
+
+       if (ad->main.hotspot_mode & VCONFKEY_MOBILE_HOTSPOT_MODE_USB) {
+               updated_type = TETHERING_TYPE_USB;
+               elm_genlist_item_fields_update(ad->main.emul_station_items[TETHERING_TYPE_USB],
+                                       "elm.text.sub", ELM_GENLIST_ITEM_FIELD_TEXT);
+       }
+
+       updated_type = TETHERING_TYPE_ALL;
+
+       return ECORE_CALLBACK_RENEW;
+#endif
+
        if (ad->main.hotspot_mode == VCONFKEY_MOBILE_HOTSPOT_MODE_NONE) {
                _stop_update_device_conn_time(ad);
                __MOBILE_AP_FUNC_EXIT__;
@@ -554,6 +605,99 @@ void _update_main_view(mh_appdata_t *ad, tethering_type_e type)
        return;
 }
 
+#ifdef TIZEN_FEATURE_EMULATOR
+void _update_emul_main_view(mh_appdata_t *ad, tethering_type_e type, Eina_Bool state)
+{
+       __MOBILE_AP_FUNC_ENTER__;
+
+       if (ad == NULL) {
+               ERR("Invalid param\n");
+               return;
+       }
+
+       Elm_Object_Item *item = NULL;
+
+       switch (type) {
+       case TETHERING_TYPE_WIFI:
+               /* Update Wi-Fi tethering on / off button */
+               _update_wifi_item(ad, MH_STATE_NONE);
+               if (state) {
+                       ad->main.hotspot_mode |= VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI;
+                       if (ad->main.help_item) {
+                               elm_genlist_item_update(ad->main.help_item);
+                       } else {
+                               item = elm_genlist_item_insert_after(ad->main.genlist,
+                                               ad->main.help_itc, ad, NULL,
+                                               ad->main.wifi_item,
+                                               ELM_GENLIST_ITEM_NONE, NULL,
+                                               NULL);
+                               if (item == NULL) {
+                                       ERR("elm_genlist_item_insert_after NULL\n");
+                               } else {
+                                       elm_genlist_item_select_mode_set(item,
+                                                       ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
+                                       ad->main.help_item = item;
+                               }
+                       }
+               } else {
+                       ad->main.hotspot_mode ^= VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI;
+                       if (ad->main.help_item) {
+                               elm_object_item_del(ad->main.help_item);
+                               ad->main.help_item = NULL;
+                       }
+               }
+
+               if (ad->main.wifi_item)
+                       elm_genlist_item_update(ad->main.wifi_item);
+               break;
+
+       case TETHERING_TYPE_BT:
+               /* Update BT tethering on / off button */
+               _update_bt_item(ad, MH_STATE_NONE);
+               if (state)
+                       ad->main.hotspot_mode |= VCONFKEY_MOBILE_HOTSPOT_MODE_BT;
+               else
+                       ad->main.hotspot_mode ^= VCONFKEY_MOBILE_HOTSPOT_MODE_BT;
+
+               if (ad->main.bt_item)
+                       elm_genlist_item_update(ad->main.bt_item);
+               break;
+
+       case TETHERING_TYPE_USB:
+               /* Update USB tethering on / off button */
+               _update_usb_item(ad, MH_STATE_NONE);
+               if (state)
+                       ad->main.hotspot_mode |= VCONFKEY_MOBILE_HOTSPOT_MODE_USB;
+               else
+                       ad->main.hotspot_mode ^= VCONFKEY_MOBILE_HOTSPOT_MODE_USB;
+
+               if (ad->main.usb_item)
+                       elm_genlist_item_update(ad->main.usb_item);
+               break;
+
+       default:
+               DBG("Unknown tethering type : %d\n", type);
+               break;
+       }
+
+       if (ad->main.hotspot_mode && ad->main.device_item == NULL) {
+               item = elm_genlist_item_append(ad->main.genlist,
+                               ad->main.device_itc, ad, NULL,
+                               ELM_GENLIST_ITEM_NONE, NULL, NULL);
+               elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DEFAULT);
+               ad->main.device_item = item;
+       } else if (ad->main.hotspot_mode == 0 && ad->main.device_item) {
+                       elm_object_item_del(ad->main.device_item);
+                       ad->main.device_item = NULL;
+       }
+
+       __update_emul_clients_genlist(ad);
+
+       __MOBILE_AP_FUNC_EXIT__;
+       return;
+}
+#endif
+
 static int __is_allowed(tethering_type_e type)
 {
        int state = 0;
@@ -606,12 +750,24 @@ static void __wifi_onoff_changed_cb(void *data, Evas_Object *obj,
        _update_wifi_item(ad, MH_STATE_PROCESS);
        ad->type = TETHERING_TYPE_WIFI;
        ad->is_wifi_teth_enabling = true;
+
+#ifdef TIZEN_FEATURE_EMULATOR
+       selected_type = TETHERING_TYPE_WIFI;
+       selected_state = (ad->main.hotspot_mode & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI) ? EINA_FALSE : EINA_TRUE;
+       DBG("type [%d] state[%d]", selected_type, selected_state);
+#endif
+
        if (_handle_wifi_onoff_change(ad) != 0) {
                ERR("_handle_wifi_onoff_change is failed\n");
                _update_wifi_item(ad, MH_STATE_NONE);
                ad->is_wifi_teth_enabling = false;
        }
 
+#ifdef TIZEN_FEATURE_EMULATOR
+       if (_get_checkbox_status(selected_type) || !selected_state)
+               _update_emul_main_view(ad, selected_type, selected_state);
+#endif
+
        __MOBILE_AP_FUNC_EXIT__;
 
        return;
@@ -661,12 +817,23 @@ static void __bt_onoff_changed_cb(void *data, Evas_Object *obj, void *event_info
        ad->type = TETHERING_TYPE_BT;
        ad->is_bt_teth_enabling = true;
 
+#ifdef TIZEN_FEATURE_EMULATOR
+       selected_type = TETHERING_TYPE_BT;
+       selected_state = (ad->main.hotspot_mode & VCONFKEY_MOBILE_HOTSPOT_MODE_BT) ? EINA_FALSE : EINA_TRUE;
+       DBG("type [%d] state[%d]", selected_type, selected_state);
+#endif
+
        if (_handle_bt_onoff_change(ad) != 0) {
                ERR("_handle_bt_onoff_change is failed\n");
                _update_bt_item(ad, MH_STATE_NONE);
                ad->is_bt_teth_enabling = false;
        }
 
+#ifdef TIZEN_FEATURE_EMULATOR
+       if (_get_checkbox_status(selected_type) || !selected_state)
+               _update_emul_main_view(ad, selected_type, selected_state);
+#endif
+
        __MOBILE_AP_FUNC_EXIT__;
 
        return;
@@ -714,12 +881,23 @@ static void __usb_onoff_changed_cb(void *data, Evas_Object *obj, void *event_inf
        _update_usb_item(ad, MH_STATE_PROCESS);
        ad->type = TETHERING_TYPE_USB;
        ad->is_usb_teth_enabling = true;
+
+#ifdef TIZEN_FEATURE_EMULATOR
+       selected_type = TETHERING_TYPE_USB;
+       selected_state = (ad->main.hotspot_mode & VCONFKEY_MOBILE_HOTSPOT_MODE_USB) ? EINA_FALSE : EINA_TRUE;
+#endif
+
        if (_handle_usb_onoff_change(ad) != 0) {
                ERR("_handle_usb_onoff_change is failed\n");
                _update_usb_item(ad, MH_STATE_NONE);
                ad->is_usb_teth_enabling = false;
        }
 
+#ifdef TIZEN_FEATURE_EMULATOR
+       if (_get_checkbox_status(selected_type) || !selected_state)
+               _update_emul_main_view(ad, selected_type, selected_state);
+#endif
+
        __MOBILE_AP_FUNC_EXIT__;
 
        return;
@@ -960,7 +1138,7 @@ static char *__get_help_label(void *data, Evas_Object *obj, const char *part)
                                        passphrase,
                                        security_type,
                                        STR_ENTER_THE_PASSWORD_ON_THE_OTHER_DEVICE,
-                                       hidden[0] != '\0' ? "<br>" : "",
+                                       hidden && hidden[0] != '\0' ? "<br>" : "",
                                        hidden);
                } else {
                        snprintf(buf, MH_LABEL_LENGTH_MAX,
@@ -970,7 +1148,7 @@ static char *__get_help_label(void *data, Evas_Object *obj, const char *part)
                                        "</font_size>",
                                        STR_DEV_NAME,
                                        device_name,
-                                       hidden[0] != '\0' ? "<br>" : "",
+                                       hidden && hidden[0] != '\0' ? "<br>" : "",
                                        hidden);
                }