From: Oskar Chodowicz Date: Thu, 28 Mar 2019 15:08:29 +0000 (+0100) Subject: Use vconf class instead of vconf in c style X-Git-Tag: submit/tizen/20190402.051338~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ade536d511db833a8fb4797b3f5fc84789272df3;p=profile%2Fmobile%2Fapps%2Fnative%2Faccessibility-setting.git Use vconf class instead of vconf in c style Change-Id: I92999da9e560b3f617886747ec02904ee1fa6d3c --- diff --git a/src/AccessibilityLauncherPage.cpp b/src/AccessibilityLauncherPage.cpp index 8ab35f5..2addab1 100644 --- a/src/AccessibilityLauncherPage.cpp +++ b/src/AccessibilityLauncherPage.cpp @@ -21,6 +21,7 @@ #include "Button.hpp" #include "Genlist.hpp" #include "Singleton.hpp" +#include "VConf.hpp" #include "setting-accessibility.h" #include "utils.hpp" @@ -30,27 +31,20 @@ AccessibilityLauncherPage::AccessibilityLauncherPage() { - items_.resize(3); - int state = 0; - auto naviframe = Singleton::instance().getNaviframe(); auto genlist = Widget::make(naviframe); genlist->setMode(ELM_LIST_COMPRESS); genlist->setStyle("dialogue"); - auto ret = vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_STATE, &state); - if (ret != VCONF_OK) { - ERROR("FAIL: vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_STATE)"); - } - + auto launcherState = Singleton::instance().get(VCONFKEY_SETAPPL_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_STATE, false); auto item = genlist->appendItem({"type1", - state ? "IDS_ACCS_ACCESSIBILITY_LAUNCHER_ON" : "IDS_ACCS_ACCESSIBILITY_LAUNCHER_OFF", + launcherState ? "IDS_ACCS_ACCESSIBILITY_LAUNCHER_ON" : "IDS_ACCS_ACCESSIBILITY_LAUNCHER_OFF", {}, [this](auto item) { ERROR("onSelection_ lambda"); item->setText(item->getState() ? "IDS_ACCS_ACCESSIBILITY_LAUNCHER_ON" : "IDS_ACCS_ACCESSIBILITY_LAUNCHER_OFF"); - vconf_set_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_STATE, item->getState()); + Singleton::instance().set(VCONFKEY_SETAPPL_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_STATE, item->getState()); if (item->getState()) for (auto it : items_) @@ -58,54 +52,28 @@ AccessibilityLauncherPage::AccessibilityLauncherPage() else for (auto it : items_) it->disable(); - item->update(); }, GenlistItem::WidgetType::toggle}); + item->setState(launcherState); genlist->appendItem({"multiline", {}, "IDS_ACCS_ACCESSIBILITY_LAUNCHER_COMMENT"}); - int vconf_state; - ret = vconf_get_int(VCONFKEY_SETAPPL_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_LAUNCH, &vconf_state); - if (ret != VCONF_OK) { - ERROR("FAIL: vconf_get_int(VCONFKEY_SETAPPL_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_LAUNCH)"); - } - - items_[0] = genlist->appendItem({"type1", - "IDS_ST_BODY_ACCESSIBILITY", - {}, - [this](auto item) { - int value = 0; - for (auto i = 0u; i < items_.size(); i++) - if (items_[i]->getState()) - value = value | (1 << i); - vconf_set_int(VCONFKEY_SETAPPL_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_LAUNCH, value); - }, - GenlistItem::WidgetType::toggle}); - - items_[1] = genlist->appendItem({"type1", - "IDS_ST_MBODY_SCREEN_READER_HTTS", - {}, - [this](auto item) { - int value = 0; - for (auto i = 0u; i < items_.size(); i++) - if (items_[i]->getState()) - value = value | (1 << i); - vconf_set_int(VCONFKEY_SETAPPL_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_LAUNCH, value); - }, - GenlistItem::WidgetType::toggle}); - - items_[2] = genlist->appendItem({"type1", - "IDS_ACCS_UNIVERSAL_SWITCH", - {}, - [this](auto item) { - int value = 0; - for (auto i = 0u; i < items_.size(); i++) - if (items_[i]->getState()) - value = value | (1 << i); - vconf_set_int(VCONFKEY_SETAPPL_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_LAUNCH, value); - }, - GenlistItem::WidgetType::toggle}); + auto updateLaunchState = [this](GenlistItem *item) { + auto state = 0; + for (auto i = 0u; i < items_.size(); i++) + if (items_[i]->getState()) + state = state | (1 << i); + Singleton::instance().set(VCONFKEY_SETAPPL_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_LAUNCH, state); + }; + + items_.push_back(genlist->appendItem({"type1", "IDS_ST_BODY_ACCESSIBILITY", {}, updateLaunchState, GenlistItem::WidgetType::toggle})); + items_.push_back(genlist->appendItem({"type1", "IDS_ST_MBODY_SCREEN_READER_HTTS", {}, updateLaunchState, GenlistItem::WidgetType::toggle})); + items_.push_back(genlist->appendItem({"type1", "IDS_ACCS_UNIVERSAL_SWITCH", {}, updateLaunchState, GenlistItem::WidgetType::toggle})); + + auto accessibilityLauncherLaunchState = Singleton::instance().get(VCONFKEY_SETAPPL_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_LAUNCH, 0); + for (auto i = 0u; i < items_.size(); ++i) + items_[i]->setState(accessibilityLauncherLaunchState & (1 << i)); if (item->getState()) for (auto it : items_) diff --git a/src/MainPage.cpp b/src/MainPage.cpp index a56e394..b50af97 100644 --- a/src/MainPage.cpp +++ b/src/MainPage.cpp @@ -16,23 +16,20 @@ MainPage::MainPage() auto grp = genlist_->appendItem({"group_index", "IDS_ST_HEADER_VISION"}); - int screen_reader = 0; - auto r = vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &screen_reader); - if (r != VCONF_OK) - ERROR("Could not get value for key: %s", VCONFKEY_SETAPPL_ACCESSIBILITY_TTS); - - auto screenReaderItem = genlist_->appendItem( - {"type1", - "IDS_ST_MBODY_SCREEN_READER_HTTS", - screen_reader ? "IDS_ST_BODY_ON" : "IDS_ST_BODY_OFF", - [this](auto item) { screenReaderPage_ = std::make_unique(); }}, + auto screenReaderItem = genlist_->appendItem({"type1", + "IDS_ST_MBODY_SCREEN_READER_HTTS", + "IDS_ST_BODY_OFF", + [this](auto item) { + screenReaderPage_ = std::make_unique(); + }}, grp); - int vconf_ret = vconf_notify_key_changed( - VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, onScreenReaderVconfKeyChanged, screenReaderItem); - if (vconf_ret != 0) { - ERROR("FAIL: vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS)"); - } + auto onVConfValueChangeCb = [=](auto state) { + screenReaderItem->setDescription(state ? "IDS_ST_BODY_ON" : "IDS_ST_BODY_OFF"); + screenReaderItem->update(); + }; + + screenReaderStateHandle_ = Singleton::instance().registerAndGet({VCONFKEY_SETAPPL_ACCESSIBILITY_TTS}, false, onVConfValueChangeCb); genlist_->appendItem({"multiline", "IDS_ACCS_UNIVERSAL_SWITCH", @@ -51,18 +48,9 @@ MainPage::MainPage() "IDS_ST_BUTTON_BACK", Button::BACK_BUTTON_ARROW_STYLE); - context_.getNaviframe()->pushBack("IDS_ST_BODY_ACCESSIBILITY", - genlist_, - [this]() { - vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, onScreenReaderVconfKeyChanged); - ui_app_exit(); - }, + context_.getNaviframe()->pushBack("IDS_ST_BODY_ACCESSIBILITY", genlist_, [this]() { + screenReaderStateHandle_ = {}; + ui_app_exit(); + }, prevBtn); } - -void MainPage::onScreenReaderVconfKeyChanged(keynode_t *key, void *user_data) -{ - auto screenReaderItem = static_cast(user_data); - screenReaderItem->setDescription(vconf_keynode_get_bool(key) ? "IDS_ST_BODY_ON" : "IDS_ST_BODY_OFF"); - screenReaderItem->update(); -} diff --git a/src/MainPage.hpp b/src/MainPage.hpp index 93b84e7..9437687 100644 --- a/src/MainPage.hpp +++ b/src/MainPage.hpp @@ -5,6 +5,7 @@ #include "AppContext.hpp" #include "ScreenReaderPage.hpp" #include "UniversalSwitchPage.hpp" +#include "VConf.hpp" class MainPage { @@ -12,13 +13,12 @@ class MainPage MainPage(); private: - static void onScreenReaderVconfKeyChanged(keynode_t *key, void *user_data); - AppContext &context_; Genlist *genlist_ = nullptr; std::unique_ptr screenReaderPage_; std::unique_ptr universalSwitchPage_; std::unique_ptr accessibilityLauncherPage_; + VConfInterface::CallbackHandle screenReaderStateHandle_; }; #endif diff --git a/src/RemoveSwitchPage.cpp b/src/RemoveSwitchPage.cpp index f98653a..0b581dc 100644 --- a/src/RemoveSwitchPage.cpp +++ b/src/RemoveSwitchPage.cpp @@ -21,6 +21,7 @@ #include "Genlist.hpp" #include "Popup.hpp" #include "Singleton.hpp" +#include "VConf.hpp" #include "setting-accessibility.h" #include @@ -93,14 +94,10 @@ void RemoveSwitchPage::createPopupForSwitchesRemoving() auto popup = Widget::make(context_.getNaviframe(), "IDS_ACCS_UNIVERSAL_SWITCH_DELETE_SWITCHES"); popup->setOrientation(ELM_POPUP_ORIENT_CENTER); + auto areAllSwitchesSelectedToRemove = switchesToRemoveCounter_ == genlist_->size(); - int vconf_val; - int vconf_ret = vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_INTERACTION_SERVICE, &vconf_val); - PRINT_ERROR_MESSAGE_IF(vconf_ret != 0, - "Failed to get vconf bool value VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_INTERACTION_SERVICE. Error: %d", - vconf_ret); - - if (vconf_val && switchesToRemoveCounter_ == genlist_->size()) { + if (Singleton::instance().get(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_INTERACTION_SERVICE, false) && + areAllSwitchesSelectedToRemove) { popup->setText("IDS_ACCS_UNIVERSAL_SWITCH_DELETE_ALL_SWITCHES_DESC"); } else { auto s = std::to_string(switchesToRemoveCounter_) + " " + @@ -115,7 +112,7 @@ void RemoveSwitchPage::createPopupForSwitchesRemoving() auto cancelBtn = Widget::make