From bf039886e98f7718ba67e06723567efa30e4359b Mon Sep 17 00:00:00 2001 From: Michal Skorupinski Date: Thu, 10 Mar 2016 17:07:55 +0100 Subject: [PATCH] [UI] Tab ordering persistance Tab ordering is stored using the preference api. Whenever the user swaps the position of two tabs the preference keys are updated. When the aplication is launched the tab order is set using the positions stored in the preferences Change-Id: Ic2f639f7aba4d06e5a98736a736062e3da786950 Signed-off-by: Michal Skorupinski --- CMakeLists.txt | 1 + include/data/settings_preferences.h | 23 +++++++++++++ src/data/settings_preferences.c | 66 +++++++++++++++++++++++++++++++++++++ src/view/view_base.c | 40 ++++++++++++++++++++++ 4 files changed, 130 insertions(+) create mode 100644 include/data/settings_preferences.h create mode 100644 src/data/settings_preferences.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a79334..651df84 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,6 +73,7 @@ SET(SRCS src/common/utils.c src/common/viewmgr.c src/data/settings_picture.c + src/data/settings_preferences.c src/data/system/settings_clock.c src/data/system/settings_language.c src/data/system/settings_pincode.c diff --git a/include/data/settings_preferences.h b/include/data/settings_preferences.h new file mode 100644 index 0000000..45c7019 --- /dev/null +++ b/include/data/settings_preferences.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __AIR_SETTINGS_PREFERENCES_H__ +#define __AIR_SETTINGS_PREFERENCES_H__ + +bool settings_preferences_tab_order_get(int tab_index, char **ret_value); +bool settings_preferences_tab_order_set(int tab_index, const char *new_value); + +#endif diff --git a/src/data/settings_preferences.c b/src/data/settings_preferences.c new file mode 100644 index 0000000..3dd83b4 --- /dev/null +++ b/src/data/settings_preferences.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "app_debug.h" + +#define PREFERENCE_TAB_ORDERING_FORMAT "tab_ordering_%d" + +bool settings_preferences_tab_order_get(int tab_index, char **ret_value) +{ + Eina_Stringshare *key = eina_stringshare_printf(PREFERENCE_TAB_ORDERING_FORMAT, tab_index); + bool is_key_existing = false; + int ret = preference_is_existing(key, &is_key_existing); + + if(ret != PREFERENCE_ERROR_NONE) { + _ERR("Could not check the existence of key: %s. Error message: %s", key, get_error_message(ret)); + eina_stringshare_del(key); + return false; + } + + if(!is_key_existing) { + _ERR("The key: %s doesn't exist", key); + eina_stringshare_del(key); + return false; + } + + ret = preference_get_string(key, ret_value); + if(ret != PREFERENCE_ERROR_NONE) { + _ERR("Could not get the key value. Key: %s. Error message: %s", key, get_error_message(ret)); + eina_stringshare_del(key); + return false; + } + + eina_stringshare_del(key); + return true; +} + +bool settings_preferences_tab_order_set(int tab_index, const char *new_value) +{ + Eina_Stringshare *key = eina_stringshare_printf(PREFERENCE_TAB_ORDERING_FORMAT, tab_index); + + int ret = preference_set_string(key, new_value); + if(ret != PREFERENCE_ERROR_NONE) { + _ERR("Could not get the key value. Key: %s. Error message: %s", key, get_error_message(ret)); + eina_stringshare_del(key); + return false; + } + + eina_stringshare_del(key); + return true; +} diff --git a/src/view/view_base.c b/src/view/view_base.c index 4e819ac..c76a16e 100644 --- a/src/view/view_base.c +++ b/src/view/view_base.c @@ -23,6 +23,7 @@ #include "common/layoutmgr.h" #include "common/utils.h" #include "common/viewmgr.h" +#include "data/settings_preferences.h" #include "define.h" #include "layout.h" #include "view/view_action_menu.h" @@ -246,6 +247,9 @@ static void _swap_menu_items(struct _priv *priv, int item1, int item2, Eina_Bool inputmgr_add_callback(priv->menu[item1], item1, &_menu_input_handler, priv); inputmgr_add_callback(priv->menu[item2], item2, &_menu_input_handler, priv); + + settings_preferences_tab_order_set(item1, _mdata_p[item1]->layout_id); + settings_preferences_tab_order_set(item2, _mdata_p[item2]->layout_id); } static void _show_toast_message(Evas_Object *parent, char *text) @@ -413,6 +417,40 @@ static void _menu_focused_cb(int id, void *data, Evas_Object *obj, priv->cur_menu = i; } +static struct _menu_data *_find_layout_by_id(char *layout_id) +{ + int i = 0; + for (i = 0; i < LAYOUT_MAX; ++i) { + if (!strcmp(_mdata[i].layout_id, layout_id)) + return &_mdata[i]; + } + + _ERR("Layout %d NOT found", layout_id); + return NULL; +} + +static void _tab_order_restore(void) +{ + char *layout_id = NULL; + struct _menu_data *found_md = NULL; + + int i = 0; + for(i = 0; i < LAYOUT_MAX; ++i) + { + if(!settings_preferences_tab_order_get(i, &layout_id)) { + settings_preferences_tab_order_set(i, _mdata[i].layout_id); + } else { + found_md = _find_layout_by_id(layout_id); + if (!found_md) { + _ERR("found_md == NULL"); + continue; + } + + _mdata_p[i] = found_md; + } + } +} + static Evas_Object *_create(Evas_Object *win, void *data) { SETTING_TRACE_BEGIN; @@ -431,6 +469,8 @@ static Evas_Object *_create(Evas_Object *win, void *data) return NULL; } + _tab_order_restore(); + priv->base = utils_add_layout(win, GRP_VIEW_BASE, EINA_TRUE); if (!priv->base) { _ERR("Add layout failed."); -- 2.7.4