Add index normalizer 78/40378/3
authorShuhrat Dehkanov <sh.dehkanov@samsung.com>
Wed, 3 Jun 2015 07:13:44 +0000 (16:13 +0900)
committerShuhrat Dehkanov <sh.dehkanov@samsung.com>
Thu, 4 Jun 2015 03:06:55 +0000 (12:06 +0900)
Index returned by elm_genlist_item_index_get() starts from 1, but
eina_list_nth() index starts from 0 consequently causing mismatch
in user selected AP and the actual AP being connected to.
This adds a normalizer to correct that.

Change-Id: Ia04044ea49d5bacc28606216d4985c8d0655bc00

ug/network/src/main_view.c

index 0f78e08..b20e2f8 100644 (file)
 
 #define TYPE_POPUP_X_OFFSET 190
 
+/*
+ * Index returned by elm_genlist_item_index_get() starts from 1,
+ * while eina_list_nth() index starts from 0
+ */
+#define ELM_GENLIST_ITEM_INDEX_GET_NORMALIZER 1
+
 enum action_btn_enum {
        CONNECT,
        REFRESH,
@@ -94,7 +100,7 @@ struct _priv {
        enum network_type_enum network_type;
        enum view_type cur_view;
 
-       int wifi_init;
+       Eina_Bool is_wifi_initialized;
        Eina_Bool wifi_conn;
        Eina_Bool wired_conn;
 
@@ -942,7 +948,7 @@ static void _item_select_cb(void *data, Evas_Object *obj, void *ei)
        int index;
 
        if (!data || !ei) {
-               _ERR("Parameter error!");
+               _ERR("Invalid parameter");
                return;
        }
 
@@ -950,6 +956,7 @@ static void _item_select_cb(void *data, Evas_Object *obj, void *ei)
        gen_item  = ei;
 
        if (priv->last_item == gen_item) {
+               _DBG("The same item is selected again");
                elm_object_item_signal_emit(gen_item, SIG_STATE_UNSELECTED, ELM);
 
                _disable_connect_btn(priv);
@@ -969,15 +976,16 @@ static void _item_select_cb(void *data, Evas_Object *obj, void *ei)
        _enable_connect_btn(priv);
        _enable_other_btn(priv);
 
-       index = elm_genlist_item_index_get(priv->last_item);
+       index = elm_genlist_item_index_get(priv->last_item)
+                       - ELM_GENLIST_ITEM_INDEX_GET_NORMALIZER;
        if (index < 0) {
-               _ERR("the index of item is invalid.");
+               _ERR("Invalid index");
                return;
        }
 
        ap_info = eina_list_nth(priv->ap_list, index);
        if (!ap_info) {
-               _ERR("ap info is NULL.");
+               _ERR("Failed to get AP info");
                return;
        }
 
@@ -988,9 +996,10 @@ static void _item_select_cb(void *data, Evas_Object *obj, void *ei)
 
        priv->ap_name = strdup(ap_info->essid);
        if (!priv->ap_name) {
-               _ERR("ap name gets failed.");
+               _ERR("Failed to get AP name");
                return;
        }
+       _DBG("Selected AP name: %s", priv->ap_name);
 
        if (priv->ap) {
                wifi_mgr_ap_destroy(priv->ap);
@@ -999,7 +1008,7 @@ static void _item_select_cb(void *data, Evas_Object *obj, void *ei)
 
        wifi_mgr_ap_clone(&priv->ap, ap_info->ap);
        if (!priv->ap) {
-               _ERR("ap clone failed.");
+               _ERR("AP clone failed");
                return;
        }
 
@@ -1178,7 +1187,7 @@ static void _wifi_activated_cb(wifi_error_e result, void *data)
 /**
 * Clear the genlist item list.
 *
-* Called when need clear the ap list,eg.refrsh button is clicked
+* Called when need clear the AP list, e.g., when the refresh button is clicked
 *
 * @param[in] priv _priv object bypassed
 */
@@ -1187,7 +1196,7 @@ static void _clear_genlist_item_list(struct _priv  *priv)
        void *temp;
 
        if (!priv || !priv->genlist) {
-               _ERR("Parameter error!");
+               _ERR("Invalid parameter");
                return;
        }
 
@@ -1213,26 +1222,26 @@ static int _display_wireless_setting(struct _priv  *priv)
        int ret;
 
        if (!priv) {
-               _ERR("the param is invalid.");
+               _ERR("Invalid parameter");
                return RET_FAILED;
        }
 
        _create_wireless_disconnect_part(priv);
 
-       if (!priv->wifi_init) {
+       if (!priv->is_wifi_initialized) {
                obj = _create_genlist_view(priv);
                if (!obj) {
-                       _ERR("fail to create genlist");
+                       _ERR("Failed to create genlist");
                        return RET_FAILED;
                }
 
                ret = wifi_mgr_init();
                if (ret != RET_SUCCESS) {
-                       _ERR("fail to init wifi network");
+                       _ERR("Failed to initialize Wi-Fi network");
                        return RET_FAILED;
                }
 
-               priv->wifi_init = 1;
+               priv->is_wifi_initialized = EINA_TRUE;
        }
 
        _clear_genlist_item_list(priv);
@@ -1240,7 +1249,7 @@ static int _display_wireless_setting(struct _priv  *priv)
        activated = EINA_FALSE;
        ret = wifi_mgr_is_activated(&activated);
        if (ret != RET_SUCCESS) {
-               _ERR("the wifi is not activated.");
+               _ERR("Wi-Fi is still not activated");
                return RET_FAILED;
        }
 
@@ -1855,17 +1864,18 @@ static void _connect_network(struct _priv *priv)
        int ret;
 
        if (!priv) {
-               _ERR("the param is NULL.");
+               _ERR("Invalid parameter");
                return;
        }
 
        if (priv->network_type == TYPE_WIRELESS) {
                if (priv->last_item) {
-                       index = elm_genlist_item_index_get(priv->last_item);
+                       index = elm_genlist_item_index_get(priv->last_item)
+                                       - ELM_GENLIST_ITEM_INDEX_GET_NORMALIZER;
 
                        ret = _wifi_connect_ap(priv, index);
                        if (ret != RET_SUCCESS) {
-                               _ERR("connect ap");
+                               _DBG("Failed to connect to selected AP");
                                _show_confirm_popup(priv);
                                return;
                        }
@@ -1873,7 +1883,7 @@ static void _connect_network(struct _priv *priv)
        } else {
                ret = _wired_connect_proc(priv);
                if (ret != RET_SUCCESS) {
-                       _ERR("connect ap");
+                       _DBG("Failed to connect to selected network");
                        _show_confirm_popup(priv);
                        return;
                }