From 675dc59c9a8b57126de7e26c1bcb7d809358d130 Mon Sep 17 00:00:00 2001 From: RobertPiet <70648461+RobertPiet@users.noreply.github.com> Date: Fri, 27 Nov 2020 15:38:19 +0100 Subject: [PATCH] [EGD-3572] SettingsTable exchanged to settings::Settings (#968) (#1044) [EGD-3572] Application has an instance of Settings - removed from derived apps [EGD-3572] Application is the owner of Settings handling for its windows/widgets [EGD-3572] Settings header moved to service-db public section --- image/user/db/settings_001.sql | 8 ++ module-apps/Application.cpp | 30 ++++--- module-apps/Application.hpp | 22 ++--- .../windows/CalendarMainWindow.cpp | 1 + .../windows/CalendarMainWindow.hpp | 5 ++ .../application-calllog/CalllogModel.cpp | 5 +- .../application-calllog/CalllogModel.hpp | 1 + .../ApplicationDesktop.cpp | 46 ++++++---- .../ApplicationDesktop.hpp | 12 ++- .../widgets/PinLockHandler.cpp | 8 +- .../widgets/PinLockHandler.hpp | 3 +- module-apps/application-notes/NotesModel.cpp | 10 +-- .../ApplicationSettings.cpp | 84 +++++++++++++++++-- .../ApplicationSettings.hpp | 37 +++++++- .../windows/DateTimeWindow.cpp | 26 +++--- .../windows/DateTimeWindow.hpp | 7 +- .../windows/LanguageWindow.cpp | 5 +- .../windows/LanguageWindow.hpp | 8 +- .../windows/SettingsChange.cpp | 31 ++++--- .../windows/SettingsChange.hpp | 9 +- .../windows/SimSelectWindow.cpp | 19 ++--- .../windows/SimSelectWindow.hpp | 8 +- module-db/CMakeLists.txt | 2 - module-db/Databases/SettingsDB.cpp | 4 +- module-db/Databases/SettingsDB.hpp | 2 - module-db/Interface/BaseInterface.hpp | 3 - module-db/Interface/SettingsRecord.cpp | 71 ---------------- .../settings/QuerySettingsUpdate_v2.cpp | 1 - module-db/tests/CMakeLists.txt | 2 - module-db/tests/SMSTable_tests.cpp | 2 - module-db/tests/SettingsTable_v2_tests.cpp | 2 - .../model/ApplicationManager.cpp | 82 ++++++++---------- .../model/ApplicationManager.hpp | 11 ++- module-services/service-db/DBServiceAPI.cpp | 36 -------- module-services/service-db/ServiceDB.cpp | 19 ----- module-services/service-db/ServiceDB.hpp | 3 - .../service-db/agents/settings/Settings.cpp | 5 +- .../service-db/agents/settings/settings.sql | 68 +++++++++++++++ .../service-db/messages/DBSettingsMessage.cpp | 12 --- .../service-db/service-db/DBServiceAPI.hpp | 3 - .../service-db/DBSettingsMessage.hpp | 16 +--- .../settings => service-db}/Settings.hpp | 10 +-- .../test/test-service-db-settings-api.cpp | 2 +- .../test-service-db-settings-testservices.hpp | 18 ++-- 44 files changed, 409 insertions(+), 350 deletions(-) create mode 100644 image/user/db/settings_001.sql delete mode 100644 module-db/Interface/SettingsRecord.cpp create mode 100644 module-services/service-db/agents/settings/settings.sql rename module-services/service-db/{agents/settings => service-db}/Settings.hpp (87%) diff --git a/image/user/db/settings_001.sql b/image/user/db/settings_001.sql new file mode 100644 index 0000000000000000000000000000000000000000..b41ba8c797107e3c5e7d3d986f7a3876f507fac3 --- /dev/null +++ b/image/user/db/settings_001.sql @@ -0,0 +1,8 @@ +INSERT OR REPLACE INTO settings_tab (path, value) VALUES + ('timeFormat12', '0'), + ('timeDateFormat', '1'), + ('activeSim', '1'), + ('lockPassHash', '0'), + ('lockTime', '30000'), + ('displayLanguage', 'En'), + ('inputLanguag', 'En'); diff --git a/module-apps/Application.cpp b/module-apps/Application.cpp index c7ca1b7aa327d2c184d2303b3e66cea66767cbfb..1baec801c7f8a7a8a5efbfcd6ae1e511978e64a6 100644 --- a/module-apps/Application.cpp +++ b/module-apps/Application.cpp @@ -7,7 +7,6 @@ #include "Item.hpp" // for Item #include "MessageType.hpp" // for MessageType #include "Service/Timer.hpp" // for Timer -#include "SettingsRecord.hpp" // for SettingsRecord #include "Timer.hpp" // for Timer #include "Translator.hpp" // for KeyInputSim... #include "common_data/EventStore.hpp" // for Battery @@ -30,7 +29,8 @@ #include // for add_const<>... #include #include -#include // for DBServiceAPI +#include +#include #include // for GetOutputVolume @@ -70,7 +70,7 @@ namespace app uint32_t stackDepth, sys::ServicePriority priority) : Service(name, parent, stackDepth, priority), default_window(gui::name::window::main_window), - windowsStack(this), startInBackground{startInBackground} + windowsStack(this), startInBackground{startInBackground}, settings(std::make_unique(this)) { keyTranslator = std::make_unique(); busChannels.push_back(sys::BusChannels::ServiceCellularNotifications); @@ -80,6 +80,9 @@ namespace app connect(typeid(AppRefreshMessage), [this](sys::Message *msg) -> sys::MessagePointer { return handleAppRefresh(msg); }); + + settings->registerValueChange(settings::SystemProperties::timeFormat12, + [this](std::string value) { timeFormatChanged(value); }); } Application::~Application() = default; @@ -324,7 +327,7 @@ namespace app sys::MessagePointer Application::handleMinuteUpdated(sys::Message *msgl) { auto *msg = static_cast(msgl); - getCurrentWindow()->updateTime(msg->timestamp, !settings.timeFormat12); + getCurrentWindow()->updateTime(msg->timestamp, !timeFormat12); if (state == State::ACTIVE_FORGROUND) { refreshWindow(gui::RefreshModes::GUI_REFRESH_FAST); } @@ -485,14 +488,8 @@ namespace app sys::ReturnCodes Application::InitHandler() { setState(State::INITIALIZING); - settings = DBServiceAPI::SettingsGet(this); - const auto status = (settings.dbID == 1) ? StartupStatus::Success : StartupStatus::Failure; - app::manager::Controller::applicationInitialised(this, status, startInBackground); - if (status == StartupStatus::Failure) { - setState(State::DEACTIVATED); - return sys::ReturnCodes::Failure; - } + app::manager::Controller::applicationInitialised(this, StartupStatus::Success, startInBackground); if (startInBackground) { setState(State::ACTIVE_BACKGROUND); @@ -703,4 +700,15 @@ namespace app { receivers.insert_or_assign(actionId, std::move(callback)); } + + void Application::timeFormatChanged(std::string value) + { + timeFormat12 = utils::getNumericValue(value); + } + + bool Application::isTimeFormat12() const noexcept + { + return timeFormat12; + } + } /* namespace app */ diff --git a/module-apps/Application.hpp b/module-apps/Application.hpp index b79d84e6703235094cb7f8f9889bded91d4425be..b6f3f7c2fdc2366411d4dd9e74911faafe979d40 100644 --- a/module-apps/Application.hpp +++ b/module-apps/Application.hpp @@ -5,7 +5,6 @@ #include "Audio/AudioCommon.hpp" // for Volume, Play... #include "Audio/Profiles/Profile.hpp" // for Profile, Pro... -#include "Interface/SettingsRecord.hpp" // for SettingsRecord #include "Service/Bus.hpp" // for Bus #include "Service/Common.hpp" // for ReturnCodes #include "Service/Message.hpp" // for MessagePointer @@ -52,6 +51,10 @@ namespace sys { class Timer; } +namespace settings +{ + class Settings; +} namespace app { @@ -247,12 +250,6 @@ namespace app /// it modifies windows stack void setActiveWindow(const std::string &windowName); - /// getter for settings record - SettingsRecord &getSettings() - { - return settings; - } - /// see suspendInProgress documentation virtual void setSuspendFlag(bool val) { @@ -304,9 +301,6 @@ namespace app /// @} protected: - /// application's settings taken from database - SettingsRecord settings; - void longPressTimerCallback(); /// Method used to register all windows and widgets in application virtual void createUserInterface() = 0; @@ -365,6 +359,14 @@ namespace app const gui::InputEvent &event); void addActionReceiver(manager::actions::ActionId actionId, OnActionReceived &&callback); + + /// application's settings + std::unique_ptr settings; + virtual void timeFormatChanged(std::string value); + bool timeFormat12 = false; + + public: + bool isTimeFormat12() const noexcept; }; /// Parameter pack used by application launch action. diff --git a/module-apps/application-calendar/windows/CalendarMainWindow.cpp b/module-apps/application-calendar/windows/CalendarMainWindow.cpp index 95e2f05ea1b12791acdde671064fac0d6b907677..b6c61af0832c9cbf2ff5fc53da1d8fba90b030c4 100644 --- a/module-apps/application-calendar/windows/CalendarMainWindow.cpp +++ b/module-apps/application-calendar/windows/CalendarMainWindow.cpp @@ -12,6 +12,7 @@ #include