From f11bc1f0d0120c04ee6f826f75c9e8a9f5894602 Mon Sep 17 00:00:00 2001 From: RobertPiet <70648461+RobertPiet@users.noreply.github.com> Date: Wed, 18 Nov 2020 10:40:29 +0100 Subject: [PATCH] [EGD-3572] SettingsTable exchanged to Settings::Settings (#968) [EGD-3572] Application has an instance of Settings - removed from derived apps [EGD-3572] review issues resolved [EGD-3572] shared_ptr -> unique_ptr [EGD-3572] Primary Key for settings_tab:path [EGD-3572] empty values handling --- module-apps/Application.cpp | 33 +++-- module-apps/Application.hpp | 20 +-- .../windows/CalendarMainWindow.hpp | 1 + .../application-calllog/CalllogModel.cpp | 9 +- .../application-calllog/CalllogModel.hpp | 1 + .../ApplicationDesktop.cpp | 37 ++--- .../ApplicationDesktop.hpp | 7 +- .../widgets/PinLockHandler.cpp | 19 ++- .../widgets/PinLockHandler.hpp | 9 +- module-apps/application-notes/NotesModel.cpp | 10 +- .../windows/SettingsMainWindow.cpp | 1 - .../windows/DateTimeWindow.cpp | 31 +++- .../windows/DateTimeWindow.hpp | 3 +- .../windows/LanguageWindow.cpp | 11 +- .../windows/LanguageWindow.hpp | 1 + .../windows/SettingsChange.cpp | 34 +++-- .../windows/SimSelectWindow.cpp | 12 +- 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 --------- module-db/Interface/SettingsRecord.hpp | 57 ------- module-db/Tables/SettingsTable.cpp | 139 ------------------ module-db/Tables/SettingsTable.hpp | 87 ----------- .../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 | 116 ++++++--------- .../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 | 2 + .../agents/settings/SystemSettings.hpp | 15 ++ .../service-db/agents/settings/settings.sql | 15 +- .../service-db/messages/DBSettingsMessage.cpp | 12 -- .../service-db/service-db/DBServiceAPI.hpp | 3 - .../service-db/DBSettingsMessage.hpp | 16 +- 40 files changed, 242 insertions(+), 617 deletions(-) delete mode 100644 module-db/Interface/SettingsRecord.cpp delete mode 100644 module-db/Interface/SettingsRecord.hpp delete mode 100644 module-db/Tables/SettingsTable.cpp delete mode 100644 module-db/Tables/SettingsTable.hpp create mode 100644 module-services/service-db/agents/settings/SystemSettings.hpp diff --git a/module-apps/Application.cpp b/module-apps/Application.cpp index 8acb655aff349621e114475eb6397ccf2c842ebb..55027c6d8e516d9ff0704e26f9cff03c041a5aac 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,8 @@ 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<::Settings::Settings>(this)) { keyTranslator = std::make_unique(); busChannels.push_back(sys::BusChannels::ServiceCellularNotifications); @@ -80,6 +81,10 @@ namespace app connect(typeid(AppRefreshMessage), [this](sys::Message *msg) -> sys::MessagePointer { return handleAppRefresh(msg); }); + + settings->registerValueChange( + ::Settings::SystemProperties::timeFormat12, + [this](const std::string &name, std::optional value) { timeFormatChanged(name, value); }); } Application::~Application() = default; @@ -330,7 +335,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); } @@ -489,14 +494,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); @@ -705,4 +704,16 @@ namespace app { receivers.insert_or_assign(actionId, std::move(callback)); } + + void Application::timeFormatChanged(const std::string &name, std::optional value) + { + if (value.has_value() && !value.value().empty()) { + timeFormat12 = utils::getValue(value.value()); + } + } + bool Application::isTimeFormat12() + { + return timeFormat12; + } + } /* namespace app */ diff --git a/module-apps/Application.hpp b/module-apps/Application.hpp index 20de925eb95569fa3794a2608cc3fcbf8dab7768..447d73f1e9d8e8a1820dc5934bfc3a68a0a1f363 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 @@ -26,6 +25,7 @@ #include // for vector #include "WindowsFactory.hpp" #include "WindowsStack.hpp" +#include namespace app { @@ -250,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) { @@ -307,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; @@ -370,6 +361,15 @@ namespace app const gui::InputEvent &event); void addActionReceiver(manager::actions::ActionId actionId, OnActionReceived &&callback); + + public: + /// application's settings + std::unique_ptr<::Settings::Settings> settings; + bool isTimeFormat12(); + + protected: + virtual void timeFormatChanged(const std::string &name, std::optional value); + bool timeFormat12 = false; }; /// Parameter pack used by application launch action. diff --git a/module-apps/application-calendar/windows/CalendarMainWindow.hpp b/module-apps/application-calendar/windows/CalendarMainWindow.hpp index 624a4d230903c6b1b30e35da4002b21ea203aa16..f2cdf2beb66f7acf12c5c35579e72e0f6ebb25df 100644 --- a/module-apps/application-calendar/windows/CalendarMainWindow.hpp +++ b/module-apps/application-calendar/windows/CalendarMainWindow.hpp @@ -13,6 +13,7 @@ #include #include #include +#include namespace gui { diff --git a/module-apps/application-calllog/CalllogModel.cpp b/module-apps/application-calllog/CalllogModel.cpp index adbe1b308722bfa55dc48555c66b1f334157cd56..1b67d07aa64d0aff6d0aea88c539f8a4e966fe8d 100644 --- a/module-apps/application-calllog/CalllogModel.cpp +++ b/module-apps/application-calllog/CalllogModel.cpp @@ -8,6 +8,8 @@ #include "data/CallLogInternals.hpp" #include "data/CallLogSwitchData.hpp" #include "widgets/CalllogItem.hpp" +#include +#include #include @@ -54,12 +56,7 @@ gui::ListItem *CalllogModel::getItem(gui::Order order) std::shared_ptr call = getRecord(order); - SettingsRecord &settings = application->getSettings(); - if (call.get() == nullptr) { - return nullptr; - } - - auto item = new gui::CalllogItem(this, !settings.timeFormat12); + auto item = new gui::CalllogItem(this, !(application->isTimeFormat12())); item->setCall(call); item->activatedCallback = [=](gui::Item &item) { diff --git a/module-apps/application-calllog/CalllogModel.hpp b/module-apps/application-calllog/CalllogModel.hpp index ce854c2485ea2491f64f90c5818abd6f5b03ba7a..9777d7db6584d444d0353a8de55bab09a9de733d 100644 --- a/module-apps/application-calllog/CalllogModel.hpp +++ b/module-apps/application-calllog/CalllogModel.hpp @@ -10,6 +10,7 @@ #include "CalllogRecord.hpp" #include "Application.hpp" #include "ListItemProvider.hpp" +#include /* * diff --git a/module-apps/application-desktop/ApplicationDesktop.cpp b/module-apps/application-desktop/ApplicationDesktop.cpp index 13c0522bb7c4ecb094e0792488cac9c27794f98e..f84baa61944e98061de1fa022f3e5fd700d5dbf0 100644 --- a/module-apps/application-desktop/ApplicationDesktop.cpp +++ b/module-apps/application-desktop/ApplicationDesktop.cpp @@ -22,12 +22,14 @@ #include #include #include +#include +#include #include namespace app { ApplicationDesktop::ApplicationDesktop(std::string name, std::string parent, StartInBackground startInBackground) - : Application(name, parent, startInBackground), lockHandler(this, settings) + : Application(name, parent, startInBackground), lockHandler(this) { busChannels.push_back(sys::BusChannels::ServiceDBNotifications); } @@ -145,9 +147,6 @@ namespace app auto ApplicationDesktop::handle(db::NotificationMessage *msg) -> bool { assert(msg); - if (msg->interface == db::Interface::Name::Settings) { - reloadSettings(); - } if (msg->interface == db::Interface::Name::Notifications && msg->type == db::Query::Type::Update) { return requestNotSeenNotifications(); @@ -232,7 +231,6 @@ namespace app return ret; } - reloadSettings(); requestNotReadNotifications(); requestNotSeenNotifications(); lockHandler.reloadScreenLock(); @@ -264,6 +262,11 @@ namespace app std::make_shared(updateos::UpdateMessageType::UpdateCheckForUpdateOnce); sys::Bus::SendUnicast(msgToSend, service::name::service_desktop, this); + settings->registerValueChange( + ::Settings::SystemProperties::activeSim, + [this](const std::string &name, std::optional value) { activeSimChanged(name, value); }); + Store::GSM::get()->selected = Store::GSM::SIM::NONE; + return sys::ReturnCodes::Success; } @@ -302,20 +305,20 @@ namespace app void ApplicationDesktop::destroyUserInterface() {} - void ApplicationDesktop::reloadSettings() + void ApplicationDesktop::activeSimChanged(const std::string &name, std::optional value) { - settings = DBServiceAPI::SettingsGet(this); - switch (settings.activeSIM) { - case SettingsRecord::ActiveSim::NONE: - Store::GSM::get()->selected = Store::GSM::SIM::NONE; + if (value.has_value() && !value.value().empty()) { + auto actSim = magic_enum::enum_cast(value.value()); + if (actSim.has_value()) { + Store::GSM::get()->selected = actSim.value(); + } + else { + Store::GSM::get()->selected = Store::GSM::SIM::NONE; + } + } + else { need_sim_select = true; - break; - case SettingsRecord::ActiveSim::SIM1: - Store::GSM::get()->selected = Store::GSM::SIM::SIM1; - break; - case SettingsRecord::ActiveSim::SIM2: - Store::GSM::get()->selected = Store::GSM::SIM::SIM2; - break; + Store::GSM::get()->selected = Store::GSM::SIM::NONE; } } diff --git a/module-apps/application-desktop/ApplicationDesktop.hpp b/module-apps/application-desktop/ApplicationDesktop.hpp index d9b1941a9f88557f95956c3d8f8b866f84285743..f4fb05ba82c917f62e65b119785e59d66117b602 100644 --- a/module-apps/application-desktop/ApplicationDesktop.hpp +++ b/module-apps/application-desktop/ApplicationDesktop.hpp @@ -14,6 +14,7 @@ #include #include #include +#include namespace app { @@ -21,9 +22,6 @@ namespace app class ApplicationDesktop : public Application { - protected: - void reloadSettings(); - public: bool need_sim_select = false; struct Notifications @@ -77,6 +75,9 @@ namespace app bool clearMessagesNotification(); bool requestNotSeenNotifications(); bool requestNotReadNotifications(); + + private: + void activeSimChanged(const std::string &name, std::optional value); }; template <> struct ManifestTraits diff --git a/module-apps/application-desktop/widgets/PinLockHandler.cpp b/module-apps/application-desktop/widgets/PinLockHandler.cpp index 5e3467be58f195f45f4ba7d919d04e631057d604..7e2974cc73882f5d2b306283145164806602cf1c 100644 --- a/module-apps/application-desktop/widgets/PinLockHandler.cpp +++ b/module-apps/application-desktop/widgets/PinLockHandler.cpp @@ -5,16 +5,20 @@ #include "PinHash.hpp" #include "application-desktop/ApplicationDesktop.hpp" #include +#include +#include namespace gui { constexpr unsigned int default_screen_pin_size = 4; constexpr unsigned int default_screen_attempts = 4; - PinLockHandler::PinLockHandler(app::ApplicationDesktop *app, SettingsRecord &settings) - : app(app), appSettings(settings), lock(this) + PinLockHandler::PinLockHandler(app::ApplicationDesktop *app) : app(app), lock(this) { reloadScreenLock(); + app->settings->registerValueChange( + ::Settings::SystemProperties::lockPassHash, + [this](const std::string &name, std::optional value) { lockPassHashChanged(name, value); }); } auto PinLockHandler::handle(CellularSimResponseMessage *msg) -> bool @@ -104,7 +108,7 @@ namespace gui std::hash> hashEngine; uint32_t hash = hashEngine(pin); lock.remainingAttempts--; - if (hash == appSettings.lockPassHash) { + if (hash == lockPassHash) { lock.remainingAttempts = default_screen_attempts; lock.state = gui::PinLock::State::VerifiedPin; } @@ -131,9 +135,16 @@ namespace gui lock.type = gui::PinLock::LockType::Screen; lock.state = gui::PinLock::State::EnterPin; - unsigned int pinSize = appSettings.lockPassHash == 0 ? 0 : default_screen_pin_size; + unsigned int pinSize = lockPassHash == 0 ? 0 : default_screen_pin_size; lock.pinValue = std::vector(pinSize, 0); lock.remainingAttempts = default_screen_attempts; } + void PinLockHandler::lockPassHashChanged(const std::string &name, std::optional value) + { + if (value.has_value() && !value.value().empty()) { + lockPassHash = utils::getValue(value.value()); + } + } + } // namespace gui diff --git a/module-apps/application-desktop/widgets/PinLockHandler.hpp b/module-apps/application-desktop/widgets/PinLockHandler.hpp index f2c66507cb1e232dbfa6b9c920f03044b5bebdfd..a2e74e5e045fec11d7ffbd3b292107e9804cffaa 100644 --- a/module-apps/application-desktop/widgets/PinLockHandler.hpp +++ b/module-apps/application-desktop/widgets/PinLockHandler.hpp @@ -5,8 +5,8 @@ #include "PinLock.hpp" #include +#include -#include "Interface/SettingsRecord.hpp" namespace app { class ApplicationDesktop; @@ -17,7 +17,6 @@ namespace gui class PinLockHandler { app::ApplicationDesktop *app = nullptr; - const SettingsRecord &appSettings; void parseSimCard(CellularSimResponseMessage *msg); void parseSimState(CellularSimResponseMessage *msg); @@ -27,11 +26,15 @@ namespace gui void handleSimPinOrPuk(const std::vector &pin); public: - PinLockHandler(app::ApplicationDesktop *app, SettingsRecord &settings); + explicit PinLockHandler(app::ApplicationDesktop *app); void reloadScreenLock(); auto handle(CellularSimResponseMessage *msg) -> bool; void handle(const std::vector &pin); gui::PinLock lock; + + private: + void lockPassHashChanged(const std::string &name, std::optional value); + unsigned int lockPassHash = 0; }; } // namespace gui diff --git a/module-apps/application-notes/NotesModel.cpp b/module-apps/application-notes/NotesModel.cpp index 408f2735b25f97c4abd6ee96a66c8a223ed17370..64d7a6363ad80cadad89edc1b064fdda1e753266 100644 --- a/module-apps/application-notes/NotesModel.cpp +++ b/module-apps/application-notes/NotesModel.cpp @@ -7,6 +7,9 @@ #include "NotesModel.hpp" #include "ListView.hpp" +#include +#include + NotesModel::NotesModel(app::Application *app) : DatabaseModel(app) {} @@ -47,12 +50,7 @@ gui::ListItem *NotesModel::getItem(gui::Order order) { std::shared_ptr note = getRecord(order); - SettingsRecord &settings = application->getSettings(); - - if (note == nullptr) - return nullptr; - - gui::NotesItem *item = new gui::NotesItem(this, !settings.timeFormat12); + auto *item = new gui::NotesItem(this, !(application->isTimeFormat12())); item->setNote(note); return item; diff --git a/module-apps/application-settings-new/windows/SettingsMainWindow.cpp b/module-apps/application-settings-new/windows/SettingsMainWindow.cpp index 4d4d55de80d61be2e4c878f750e7b0603ecad181..3747f0ab5edcac043d49e8e3e9e4733f08532020 100644 --- a/module-apps/application-settings-new/windows/SettingsMainWindow.cpp +++ b/module-apps/application-settings-new/windows/SettingsMainWindow.cpp @@ -34,7 +34,6 @@ std::list mainWindowOptionsNew(app::Application *app) LOG_INFO("switching to %s page", window.c_str()); app::manager::Controller::switchApplication( app, "ApplicationSettings", gui::name::window::main_window, nullptr); - app->switchWindow(window, nullptr); return true; }, gui::Arrow::Enabled}); diff --git a/module-apps/application-settings/windows/DateTimeWindow.cpp b/module-apps/application-settings/windows/DateTimeWindow.cpp index cd79b42e02d4ab927c69cac31aaa5589bb0bbc2e..c0d50a3098a52cfc770515706883c01f08abf191 100644 --- a/module-apps/application-settings/windows/DateTimeWindow.cpp +++ b/module-apps/application-settings/windows/DateTimeWindow.cpp @@ -26,11 +26,17 @@ #include #include +#include +#include + namespace gui { DateTimeWindow::DateTimeWindow(app::Application *app) : AppWindow(app, "DateTime") { + getApplication()->settings->registerValueChange( + ::Settings::SystemProperties::timeDateFormat, + [this](const std::string &name, std::optional value) { timeDateChanged(name, value); }); buildInterface(); } @@ -58,10 +64,6 @@ namespace gui utils::time::Timestamp time; - SettingsRecord appSettings = application->getSettings(); - timeFormat12h = appSettings.timeFormat12; - timeDateFormat = appSettings.timeDateFormat; - // create date widgets dateBody = new gui::HBox(this, style::window::default_left_margin, @@ -119,7 +121,7 @@ namespace gui auto hourValue = time.get_date_time_sub_value(utils::time::GetParameters::Hour); - if (timeFormat12h) { + if (application->isTimeFormat12()) { if (hourValue > 12) { hourValue -= 12; dayPeriod = true; @@ -142,7 +144,7 @@ namespace gui timeBody->addWidget(addSpacer("")); item = addDateTimeItem(nullptr, (""), ("")); - if (timeFormat12h) { + if (application->isTimeFormat12()) { if (dayPeriod) { item->setText("PM"); } @@ -341,7 +343,7 @@ namespace gui if (utils::time::validateTime(getDateTimeItemValue(DateTimeItems::Hour), getDateTimeItemValue(DateTimeItems::Minute), - timeFormat12h)) { + application->isTimeFormat12())) { application->refreshWindow(RefreshModes::GUI_REFRESH_FAST); } else { @@ -364,7 +366,7 @@ namespace gui timeinfo.tm_mday = std::stoi(getDateTimeItemValue(DateTimeItems::Day)); auto hourValue = std::stoi(getDateTimeItemValue(DateTimeItems::Hour)); - if (timeFormat12h) { + if (application->isTimeFormat12()) { if (dayPeriod) { hourValue += 12; } @@ -379,4 +381,17 @@ namespace gui bsp::rtc_SetDateTime(&timeinfo); application->refreshWindow(RefreshModes::GUI_REFRESH_FAST); } + + void DateTimeWindow::timeDateChanged(const std::string &name, std::optional value) + { + if (value.has_value()) { + auto newTimeDateFormat = utils::getValue(value.value()); + if (newTimeDateFormat != timeDateFormat) { + timeDateFormat = newTimeDateFormat; + if (visible) { + rebuild(); + } + } + } + } } /* namespace gui */ diff --git a/module-apps/application-settings/windows/DateTimeWindow.hpp b/module-apps/application-settings/windows/DateTimeWindow.hpp index 7761e07b27512efe08bbc489042d3af0ee5cde7c..b95619e53ab13a3085eb0f9662dc5a224ed6fac6 100644 --- a/module-apps/application-settings/windows/DateTimeWindow.hpp +++ b/module-apps/application-settings/windows/DateTimeWindow.hpp @@ -20,6 +20,7 @@ #include "gui/widgets/TopBar.hpp" #include "gui/widgets/Window.hpp" #include +#include namespace gui { @@ -41,7 +42,6 @@ namespace gui gui::HBox *dateBody = nullptr; gui::HBox *timeBody = nullptr; - bool timeFormat12h = false; bool timeDateFormat = false; // true europe format, flase american format bool dayPeriod = false; // day period indicator false am, true pm @@ -63,5 +63,6 @@ namespace gui private: void invalidate() noexcept; + void timeDateChanged(const std::string &name, std::optional value); }; } /* namespace gui */ diff --git a/module-apps/application-settings/windows/LanguageWindow.cpp b/module-apps/application-settings/windows/LanguageWindow.cpp index f0fbcec4a780994bc9daf5a23b188cb2d399ad39..67474d05aa83d617e87ec71a5f5f5e262ffe162d 100644 --- a/module-apps/application-settings/windows/LanguageWindow.cpp +++ b/module-apps/application-settings/windows/LanguageWindow.cpp @@ -13,6 +13,7 @@ #include "LanguageWindow.hpp" #include #include +#include namespace gui { @@ -52,25 +53,25 @@ namespace gui options.push_back(addOptionLabel(utils::localize.get("app_settings_language_english"), [=](gui::Item &item) { LOG_INFO("selected display language: english"); - app::manager::Controller::changeDisplayLanguage(application, utils::Lang::En); + getApplication()->settings->setValue(::Settings::SystemProperties::displayLanguage, "En"); return true; })); options.push_back(addOptionLabel(utils::localize.get("app_settings_language_polish"), [=](gui::Item &) { LOG_INFO("selected display language: polish"); - app::manager::Controller::changeDisplayLanguage(application, utils::Lang::Pl); + getApplication()->settings->setValue(::Settings::SystemProperties::displayLanguage, "Pl"); return true; })); options.push_back(addOptionLabel(utils::localize.get("app_settings_language_german"), [=](gui::Item &) { LOG_INFO("selected display language: german"); - app::manager::Controller::changeDisplayLanguage(application, utils::Lang::De); + getApplication()->settings->setValue(::Settings::SystemProperties::displayLanguage, "De"); return true; })); options.push_back(addOptionLabel(utils::localize.get("app_settings_language_spanish"), [=](gui::Item &) { - LOG_INFO("selected display language: spanish"); - app::manager::Controller::changeDisplayLanguage(application, utils::Lang::Sp); + LOG_INFO("selected language: spanish"); + getApplication()->settings->setValue(::Settings::SystemProperties::displayLanguage, "Sp"); return true; })); diff --git a/module-apps/application-settings/windows/LanguageWindow.hpp b/module-apps/application-settings/windows/LanguageWindow.hpp index 637f1ec2ce862df4d123e6830774f6591cc36291..0b7475f8c606456c67fcbb98cee1802166a04315 100644 --- a/module-apps/application-settings/windows/LanguageWindow.hpp +++ b/module-apps/application-settings/windows/LanguageWindow.hpp @@ -13,6 +13,7 @@ #include "gui/widgets/Window.hpp" #include "gui/widgets/BottomBar.hpp" #include "gui/widgets/TopBar.hpp" +#include namespace gui { diff --git a/module-apps/application-settings/windows/SettingsChange.cpp b/module-apps/application-settings/windows/SettingsChange.cpp index 0a789d7a86077d273d1ecd99a370d2698a4a386b..01ffd3c8ad6ecd7ec93e99f1ceaf4be1aaf7bcfc 100644 --- a/module-apps/application-settings/windows/SettingsChange.cpp +++ b/module-apps/application-settings/windows/SettingsChange.cpp @@ -9,6 +9,9 @@ #include #include #include +#include +#include +#include namespace style::option { @@ -32,10 +35,26 @@ namespace gui::option { private: app::Application *app = nullptr; + unsigned int lockPassHash; public: ChangePin(app::Application *app) : app(app) - {} + { + app->settings->registerValueChange( + ::Settings::SystemProperties::lockPassHash, + [this](const std::string &name, std::optional value) { settingsChanged(name, value); }); + } + void settingsChanged(const std::string &name, std::optional value) + { + if (::Settings::SystemProperties::lockPassHash == name) { + if (value.has_value()) { + lockPassHash = utils::getValue(value.value()); + } + } + else { + LOG_ERROR("Application not registered value changed received: %s", name.c_str()); + } + } [[nodiscard]] auto build() const -> Item * override { @@ -46,7 +65,6 @@ namespace gui::option style::window::label::big_h); auto font = FontManager::getInstance().getFont(style::window::font::medium); auto font_bold = FontManager::getInstance().getFont(style::window::font::mediumbold); - auto settings = app->getSettings(); rect->setEdges(RectangleEdge::None); rect->setReverseOrder(true); @@ -69,20 +87,17 @@ namespace gui::option pin_text->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Center)); pin_text->setEditMode(EditMode::EDIT); pin_text->setFont(font); - pin_text->setText(std::to_string(settings.lockPassHash)); + pin_text->setText(std::to_string(lockPassHash)); pin_text->setPenWidth(0); pin_text->setInputMode(new InputMode( {InputMode::digit}, [=](const UTF8 &text) {}, [=]() {}, [=]() {})); pin_text->setEdges(RectangleEdge::All); - auto lapp = app; - pin_text->activatedCallback = [pin_text, lapp](gui::Item &item) { - auto settings = lapp->getSettings(); + pin_text->activatedCallback = [pin_text, this](gui::Item &item) { auto text = pin_text->getText(); if (text.length() == 0) { LOG_DEBUG("remove pin"); - settings.lockPassHash = 0; - DBServiceAPI::SettingsUpdate(lapp, settings); + app->settings->setValue(::Settings::SystemProperties::lockPassHash, ""); } else if (text.length() != 4) { pin_text->setText("bad value - needs 4 digits"); @@ -90,8 +105,7 @@ namespace gui::option else { auto value = std::stoi(text); LOG_DEBUG("setting pin to: %d", value); - settings.lockPassHash = value; - DBServiceAPI::SettingsUpdate(lapp, settings); + app->settings->setValue(::Settings::SystemProperties::lockPassHash, std::to_string(value)); } return true; }; diff --git a/module-apps/application-settings/windows/SimSelectWindow.cpp b/module-apps/application-settings/windows/SimSelectWindow.cpp index 37d7003637a3963b2e8be80da591402b487f9ab5..c10e0018c2ebe5c4f97bf99090750b34185bacb7 100644 --- a/module-apps/application-settings/windows/SimSelectWindow.cpp +++ b/module-apps/application-settings/windows/SimSelectWindow.cpp @@ -9,11 +9,13 @@ #include #include #include +#include +#include +#include -void changeSim(app::Application *app, SettingsRecord::ActiveSim simsettings, Store::GSM::SIM sim) +void changeSim(app::Application *app, Store::GSM::SIM sim) { - app->getSettings().activeSIM = simsettings; - DBServiceAPI::SettingsUpdate(app, app->getSettings()); + app->settings->setValue(::Settings::SystemProperties::activeSim, utils::enumToString(sim)); Store::GSM::get()->selected = sim; bsp::cellular::sim::sim_sel(); bsp::cellular::sim::hotswap_trigger(); @@ -24,13 +26,13 @@ std::list simSelectWindow(app::Application *app) std::list l; l.emplace_back(gui::Option{"SIM 1", [=](gui::Item &item) { - changeSim(app, SettingsRecord::ActiveSim::SIM1, Store::GSM::SIM::SIM1); + changeSim(app, Store::GSM::SIM::SIM1); return true; }, gui::Arrow::Disabled}); l.emplace_back(gui::Option{"SIM 2", [=](gui::Item &item) { - changeSim(app, SettingsRecord::ActiveSim::SIM2, Store::GSM::SIM::SIM2); + changeSim(app, Store::GSM::SIM::SIM2); return true; }, gui::Arrow::Disabled}); diff --git a/module-db/CMakeLists.txt b/module-db/CMakeLists.txt index 7b58e516d44f79d016d2666c8bbec79983bc171f..ad5981a6ea7525faa17513464b01cf8c1256f8ef 100644 --- a/module-db/CMakeLists.txt +++ b/module-db/CMakeLists.txt @@ -36,7 +36,6 @@ set(SOURCES Tables/ContactsRingtonesTable.cpp Tables/ContactsAddressTable.cpp Tables/ContactsGroups.cpp - Tables/SettingsTable.cpp Tables/AlarmsTable.cpp Tables/NotesTable.cpp Tables/CalllogTable.cpp @@ -50,7 +49,6 @@ set(SOURCES Interface/SMSRecord.cpp Interface/ContactRecord.cpp Interface/ThreadRecord.cpp - Interface/SettingsRecord.cpp Interface/AlarmsRecord.cpp Interface/NotesRecord.cpp Interface/CalllogRecord.cpp diff --git a/module-db/Databases/SettingsDB.cpp b/module-db/Databases/SettingsDB.cpp index 459f2369d323bd4040a29cfc150a77acdf6cdf9f..e30f9b9a3314a30c1f4eeb4fee41fa86c0215eac 100644 --- a/module-db/Databases/SettingsDB.cpp +++ b/module-db/Databases/SettingsDB.cpp @@ -5,9 +5,9 @@ #include "SettingsDB.hpp" const char *SettingsDB::dbName = USER_PATH("settings.db"); -SettingsDB::SettingsDB() : Database(dbName), settings(this), settings_v2(this) +SettingsDB::SettingsDB() : Database(dbName), settings_v2(this) { - if (settings.create() == false || settings_v2.create() == false) + if (settings_v2.create() == false) return; isInitialized_ = true; diff --git a/module-db/Databases/SettingsDB.hpp b/module-db/Databases/SettingsDB.hpp index 78a41334bd3ea628dcd504dbc6e1143876661041..9fa0b5a2fd57bc178adc59b992b26e2fad632005 100644 --- a/module-db/Databases/SettingsDB.hpp +++ b/module-db/Databases/SettingsDB.hpp @@ -4,7 +4,6 @@ #pragma once #include "Database/Database.hpp" -#include "../Tables/SettingsTable.hpp" #include "../Tables/SettingsTable_v2.hpp" class SettingsDB : public Database @@ -13,7 +12,6 @@ class SettingsDB : public Database SettingsDB(); ~SettingsDB() override = default; - SettingsTable settings; SettingsTable_v2 settings_v2; static const char *GetDBName() diff --git a/module-db/Interface/BaseInterface.hpp b/module-db/Interface/BaseInterface.hpp index f1ebf73297005edd2beb55e32f0cab988e86f08f..bca6a2140bc7a5ccb8e61ca9e72ca3a9f1c0aebf 100644 --- a/module-db/Interface/BaseInterface.hpp +++ b/module-db/Interface/BaseInterface.hpp @@ -18,7 +18,6 @@ namespace db enum class Name { - Settings, SMS, SMSThread, SMSTemplate, @@ -37,8 +36,6 @@ namespace db constexpr const char *c_str(enum db::Interface::Name db) { switch (db) { - case db::Interface::Name::Settings: - return "Settings"; case db::Interface::Name::SMS: return "SMS"; case db::Interface::Name::SMSThread: diff --git a/module-db/Interface/SettingsRecord.cpp b/module-db/Interface/SettingsRecord.cpp deleted file mode 100644 index 2337caeb7437a4ba9cfcee7693ee6fba08af8eaf..0000000000000000000000000000000000000000 --- a/module-db/Interface/SettingsRecord.cpp +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -#include "SettingsRecord.hpp" - -SettingsRecord::ActiveSim SettingsRecord::to(const uint32_t sim) -{ - if (sim <= static_cast(ActiveSim::SIM2)) { - return ActiveSim(sim); - } - return ActiveSim::NONE; -} - -uint32_t SettingsRecord::from(const ActiveSim sim) -{ - return static_cast(sim); -} - -SettingsRecordInterface::SettingsRecordInterface(SettingsDB *db) : settingsDB(db) -{} - -SettingsRecordInterface::~SettingsRecordInterface() -{} - -SettingsRecord SettingsRecordInterface::GetByID(uint32_t id) -{ - - auto rec = settingsDB->settings.getById(1); - - return SettingsRecord{.dbID = rec.ID, - .timeFormat12 = rec.timeFormat12, - .timeAuto = rec.timeAuto, - .timeDateFormat = rec.timeDateFormat, - .brightnessAuto = rec.brightnessAuto, - .brightnessLevel = rec.brightnessLevel, - .fontSize = rec.fontSize, - .pinMode = rec.pinMode, - .pinDays = rec.pinDays, - .pinDaysLeft = rec.pinDaysLeft, - .pin1 = rec.pin1, - .pin2 = rec.pin2, - .activeSIM = SettingsRecord::to(rec.activeSIM), - .networkOperator = rec.networkOperator, - .lockPassHash = rec.lockPassHash, - .lockTime = rec.lockTime, - .displayLanguage = rec.displayLanguage, - .inputLanguage = rec.inputLanguage}; -} - -bool SettingsRecordInterface::Update(const SettingsRecord &rec) -{ - - return settingsDB->settings.update(SettingsTableRow{.ID = rec.dbID, - .timeFormat12 = rec.timeFormat12, - .timeAuto = rec.timeAuto, - .timeDateFormat = rec.timeDateFormat, - .brightnessAuto = rec.brightnessAuto, - .brightnessLevel = rec.brightnessLevel, - .fontSize = rec.fontSize, - .pinMode = rec.pinMode, - .pinDays = rec.pinDays, - .pinDaysLeft = rec.pinDaysLeft, - .pin1 = rec.pin1, - .pin2 = rec.pin2, - .activeSIM = SettingsRecord::from(rec.activeSIM), - .networkOperator = rec.networkOperator, - .lockPassHash = rec.lockPassHash, - .lockTime = rec.lockTime, - .displayLanguage = rec.displayLanguage, - .inputLanguage = rec.inputLanguage}); -} diff --git a/module-db/Interface/SettingsRecord.hpp b/module-db/Interface/SettingsRecord.hpp deleted file mode 100644 index 3d0db6f202a57a5fccb6e3c20787c388a0fa2e16..0000000000000000000000000000000000000000 --- a/module-db/Interface/SettingsRecord.hpp +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -#pragma once - -#include "Record.hpp" -#include "utf8/UTF8.hpp" -#include "../Common/Common.hpp" -#include "../Databases/SettingsDB.hpp" - -struct SettingsRecord -{ - uint32_t dbID; - bool timeFormat12; - bool timeAuto; - bool timeDateFormat; - bool brightnessAuto; - uint32_t brightnessLevel; - uint32_t fontSize; - SettingsPinMode pinMode; - uint32_t pinDays; - uint32_t pinDaysLeft; - std::string pin1; - std::string pin2; - enum class ActiveSim : uint32_t - { - NONE = 0, - SIM1 = 1, - SIM2 = 2, - } activeSIM = ActiveSim::NONE; - std::string networkOperator; - uint32_t lockPassHash; - uint32_t lockTime; - SettingsLanguage displayLanguage; - SettingsLanguage inputLanguage; - - static ActiveSim to(const uint32_t sim); - static uint32_t from(const ActiveSim sim); -}; - -enum class SettingsRecordField -{ - Dummy -}; - -class SettingsRecordInterface : public RecordInterface -{ - public: - SettingsRecordInterface(SettingsDB *db); - ~SettingsRecordInterface(); - - bool Update(const SettingsRecord &rec) override final; - SettingsRecord GetByID(uint32_t id) override final; - - private: - SettingsDB *settingsDB; -}; diff --git a/module-db/Tables/SettingsTable.cpp b/module-db/Tables/SettingsTable.cpp deleted file mode 100644 index 06bf78e0195383ec00372bf8baba3c3ae4d12417..0000000000000000000000000000000000000000 --- a/module-db/Tables/SettingsTable.cpp +++ /dev/null @@ -1,139 +0,0 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -#include "SettingsTable.hpp" -#include "magic_enum.hpp" - -SettingsTable::SettingsTable(Database *db) : Table(db) -{} - -SettingsTable::~SettingsTable() -{} - -bool SettingsTable::create() -{ - bool ret = true; - ret = db->execute(createTableQuery); - if (!ret) { - return false; - } - - ret = db->execute(settingsInitialization); - return ret; -} - -SettingsTableRow SettingsTable::getById(uint32_t id) -{ - - auto retQuery = db->query("SELECT * FROM settings WHERE _id= 1;"); - - if ((retQuery == nullptr) || (retQuery->getRowCount() == 0)) { - return SettingsTableRow(); - } - - if (!Language::ValidateLanguage(static_cast((*retQuery)[16].getUInt32())) || - !Language::ValidateLanguage(static_cast((*retQuery)[17].getUInt32()))) { - return SettingsTableRow{ - 1, - false, - true, - true, - true, - 0, - 0, - SettingsPinMode::DAYS, - 0, - 0, - "", - "", - 1, - "", - 0, - 30000, // time of inactivity of the user after which phone will be automatically blocked. - SettingsLanguage::ENGLISH, - SettingsLanguage::ENGLISH}; - } - - return SettingsTableRow{ - (*retQuery)[0].getUInt32(), // ID - (*retQuery)[1].getBool(), // timeFormat12 - (*retQuery)[2].getBool(), // timeAuto - (*retQuery)[3].getBool(), // timeDateFormat - (*retQuery)[4].getBool(), // brightnessAuto - (*retQuery)[5].getUInt32(), // brightnessLevel - (*retQuery)[6].getUInt32(), // fontSize - static_cast((*retQuery)[7].getUInt32()), // pinMode - (*retQuery)[8].getUInt32(), // pinDays - (*retQuery)[9].getUInt32(), // pinDaysLeft - (*retQuery)[10].getString(), // pin1 - (*retQuery)[11].getString(), // pin2 - (*retQuery)[12].getUInt32(), // activeSIM - (*retQuery)[13].getString(), // networkOperator - (*retQuery)[14].getUInt32(), // lockPassHash - (*retQuery)[15].getUInt32(), // lockTime - static_cast((*retQuery)[16].getUInt32()), // displayLanguage - static_cast((*retQuery)[17].getUInt32()), // inputLanguage - - }; -} - -bool SettingsTable::update(SettingsTableRow entry) -{ - return db->execute("UPDATE settings SET time_format_12 = %lu, time_auto = %lu, time_date_format = %lu " - ",brightness_auto = %lu, brightness_level = %lu, " - "bigger_font = %lu, pin_mode =%lu, pin_days = %lu ,pin_days_left = %lu, pin1_string = '%q', " - "pin2_string = '%q', active_sim = %lu, " - "network_operator = '%q', lock_pass_hash = %lu, lock_time = %lu, display_language = %lu, " - "input_language = %lu WHERE _id=1;", - entry.timeFormat12, - entry.timeAuto, - entry.timeDateFormat, - entry.brightnessAuto, - entry.brightnessLevel, - entry.fontSize, - entry.pinMode, - entry.pinDays, - entry.pinDaysLeft, - entry.pin1.c_str(), - entry.pin2.c_str(), - entry.activeSIM, - entry.networkOperator.c_str(), - entry.lockPassHash, - entry.lockTime, - entry.displayLanguage, - entry.inputLanguage); -} - -bool SettingsTable::add(SettingsTableRow entry) -{ - // dummy - return true; -} - -bool SettingsTable::removeById(uint32_t id) -{ - return true; -} - -std::vector SettingsTable::getLimitOffset(uint32_t offset, uint32_t limit) -{ - return std::vector{}; -} - -std::vector SettingsTable::getLimitOffsetByField(uint32_t offset, - uint32_t limit, - SettingsTableFields field, - const char *str) -{ - return std::vector{}; -} - -uint32_t SettingsTable::count() -{ - return 0; -} - -uint32_t SettingsTable::countByFieldId(const char *field, uint32_t id) -{ - return 0; -} diff --git a/module-db/Tables/SettingsTable.hpp b/module-db/Tables/SettingsTable.hpp deleted file mode 100644 index b46495f3abbae4553b394073b5c94aa27e7b7a5a..0000000000000000000000000000000000000000 --- a/module-db/Tables/SettingsTable.hpp +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -#pragma once - -#include "Table.hpp" -#include "Database/Database.hpp" -#include "utf8/UTF8.hpp" -#include "Common/Common.hpp" - -struct SettingsTableRow -{ - uint32_t ID; - bool timeFormat12; - bool timeAuto; - bool timeDateFormat; - bool brightnessAuto; - uint32_t brightnessLevel; - uint32_t fontSize; - SettingsPinMode pinMode; - uint32_t pinDays; - uint32_t pinDaysLeft; - std::string pin1; - std::string pin2; - uint32_t activeSIM; - std::string networkOperator; - uint32_t lockPassHash; - // time of inactivity of the user after which phone will be automatically blocked. - uint32_t lockTime; - SettingsLanguage displayLanguage; - SettingsLanguage inputLanguage; -}; - -enum class SettingsTableFields -{ - Dummy -}; - -class SettingsTable : public Table -{ - public: - SettingsTable(Database *db); - virtual ~SettingsTable(); - - bool create() override final; - bool update(SettingsTableRow entry) override final; - SettingsTableRow getById(uint32_t id) override final; - - bool add(SettingsTableRow entry) override final; - bool removeById(uint32_t id) override final; - std::vector getLimitOffset(uint32_t offset, uint32_t limit) override final; - std::vector getLimitOffsetByField(uint32_t offset, - uint32_t limit, - SettingsTableFields field, - const char *str) override final; - uint32_t count() override final; - uint32_t countByFieldId(const char *field, uint32_t id) override final; - - private: - const char *createTableQuery = "CREATE TABLE IF NOT EXISTS settings(" - "_id INTEGER PRIMARY KEY, " - "time_format_12 INTEGER DEFAULT 0, " - "time_auto INTEGER DEFAULT 1, " - "time_date_format INTEGER DEFAULT 1, " - "brightness_auto INTEGER DEFAULT 1, " - "brightness_level INTEGER DEFAULT 0, " - "bigger_font INTEGER DEFAULT 0, " - "pin_mode INTEGER DEFAULT 1, " - "pin_days INTEGER DEFAULT 0, " - "pin_days_left INTEGER DEFAULT 0, " - "pin1_string TEXT DEFAULT '', " - "pin2_string TEXT DEFAULT '', " - "active_sim INTEGER DEFAULT 1, " - "network_operator TEXT DEFAULT '', " - "lock_pass_hash INTEGER DEFAULT 0, " - "lock_time INTEGER DEFAULT 30000, " - "display_language INTEGER DEFAULT 1, " - "input_language INTEGER DEFAULT 1 " - ");"; - - const char *settingsInitialization = "INSERT OR IGNORE INTO settings (_id, time_format_12, time_auto, " - "time_date_format, brightness_auto, brightness_level, " - "bigger_font, pin_mode, pin_days, pin_days_left, pin1_string,pin2_string, " - "active_sim,network_operator,lock_pass_hash,lock_time, display_language, " - "input_language) " - "VALUES(1,0,1,1,1,0,0,1,0,0,'','',1,'',0,30000,1,1)"; -}; diff --git a/module-db/queries/settings/QuerySettingsUpdate_v2.cpp b/module-db/queries/settings/QuerySettingsUpdate_v2.cpp index 3758764d953ecf34a5b63c078fe331a142e37a40..1d77614ee6e4da32902f4266e934f663a2669c04 100644 --- a/module-db/queries/settings/QuerySettingsUpdate_v2.cpp +++ b/module-db/queries/settings/QuerySettingsUpdate_v2.cpp @@ -1,6 +1,5 @@ // Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - #include "QuerySettingsUpdate_v2.hpp" namespace db::query::settings diff --git a/module-db/tests/CMakeLists.txt b/module-db/tests/CMakeLists.txt index 83bf5d4a998ea7d082716196458fbd7f458db682..456b1830eda6c99302e9595e0de832de38e586f2 100644 --- a/module-db/tests/CMakeLists.txt +++ b/module-db/tests/CMakeLists.txt @@ -16,7 +16,6 @@ add_catch2_executable( "${CMAKE_CURRENT_SOURCE_DIR}/ContactsRingtonesTable_tests.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/ContactsAddressTable_tests.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/ContactGroups_tests.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/SettingsTable_tests.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/SettingsTable_v2_tests.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/AlarmsTable_tests.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/SMSTemplateTable_tests.cpp" @@ -28,7 +27,6 @@ add_catch2_executable( "${CMAKE_CURRENT_SOURCE_DIR}/ContactsRecord_tests.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/SMSRecord_tests.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/ThreadRecord_tests.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/SettingsRecord_tests.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/AlarmsRecord_tests.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/SMSTemplateRecord_tests.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/NotificationsRecord_tests.cpp" diff --git a/module-db/tests/SMSTable_tests.cpp b/module-db/tests/SMSTable_tests.cpp index e8857cf25fb6a371999b58c64af3221a6fa124d4..caad9d2d232c6faaaf09b833cb828b3b1a5fabb1 100644 --- a/module-db/tests/SMSTable_tests.cpp +++ b/module-db/tests/SMSTable_tests.cpp @@ -8,8 +8,6 @@ #include "Database/Database.hpp" #include "Databases/SmsDB.hpp" -#include "Tables/SettingsTable.hpp" - #include #include diff --git a/module-db/tests/SettingsTable_v2_tests.cpp b/module-db/tests/SettingsTable_v2_tests.cpp index 1cff707da8607539986475b417ced901947f71c1..c7047554f04a553e734fd1214a3d5b9fda8a5ec4 100644 --- a/module-db/tests/SettingsTable_v2_tests.cpp +++ b/module-db/tests/SettingsTable_v2_tests.cpp @@ -8,8 +8,6 @@ #include "Database/Database.hpp" #include "Databases/SettingsDB.hpp" -#include "Tables/SettingsTable.hpp" - TEST_CASE("Settings Table version 2 tests") { Database::initialize(); diff --git a/module-services/service-appmgr/model/ApplicationManager.cpp b/module-services/service-appmgr/model/ApplicationManager.cpp index b964c158578fdd43a112f2818cd1805f586332ec..9c857bd578e284b036f63bd8e625808cc8863f10 100644 --- a/module-services/service-appmgr/model/ApplicationManager.cpp +++ b/module-services/service-appmgr/model/ApplicationManager.cpp @@ -27,6 +27,8 @@ #include #include +#include +#include // Auto phone lock disabled for now till the times when it's debugged // #define AUTO_PHONE_LOCK_ENABLED @@ -36,36 +38,20 @@ namespace app::manager { constexpr auto default_application_locktime_ms = 30000; - utils::Lang toUtilsLanguage(SettingsLanguage language) + utils::Lang toUtilsLanguage(const std::string &language) { - switch (language) { - case SettingsLanguage::ENGLISH: + if ("En" == language) return utils::Lang::En; - case SettingsLanguage::POLISH: + if ("Pl" == language) return utils::Lang::Pl; - case SettingsLanguage::GERMAN: + if ("De" == language) return utils::Lang::De; - case SettingsLanguage::SPANISH: + if ("Sp" == language) return utils::Lang::Sp; - } return utils::Lang::En; } - SettingsLanguage toSettingsLanguage(utils::Lang language) - { - switch (language) { - case utils::Lang::En: - return SettingsLanguage::ENGLISH; - case utils::Lang::Pl: - return SettingsLanguage::POLISH; - case utils::Lang::De: - return SettingsLanguage::GERMAN; - case utils::Lang::Sp: - return SettingsLanguage::SPANISH; - } - return SettingsLanguage::ENGLISH; - } - } // namespace + }; // namespace ApplicationManagerBase::ApplicationManagerBase(std::vector> &&launchers) : applications{std::move(launchers)} @@ -131,18 +117,27 @@ namespace app::manager const ApplicationName &_rootApplicationName) : Service{serviceName}, ApplicationManagerBase(std::move(launchers)), rootApplicationName{_rootApplicationName}, blockingTimer{std::make_unique( - "BlockTimer", this, std::numeric_limits::max(), sys::Timer::Type::SingleShot)} + "BlockTimer", this, std::numeric_limits::max(), sys::Timer::Type::SingleShot)}, + settings(std::make_unique<::Settings::Settings>(this)) { registerMessageHandlers(); blockingTimer->connect([this](sys::Timer &) { onPhoneLocked(); }); + settings->registerValueChange( + ::Settings::SystemProperties::displayLanguage, + [this](const std::string &name, std::optional value) { displayLanguageChanged(name, value); }); + settings->registerValueChange( + ::Settings::SystemProperties::inputLanguage, + [this](const std::string &name, std::optional value) { inputLanguageChanged(name, value); }); + settings->registerValueChange( + ::Settings::SystemProperties::lockTime, + [this](const std::string &name, std::optional value) { lockTimeChanged(name, value); }); } sys::ReturnCodes ApplicationManager::InitHandler() { - settings = DBServiceAPI::SettingsGet(this); - blockingTimer->setInterval(settings.lockTime != 0 ? settings.lockTime : default_application_locktime_ms); - utils::localize.SetDisplayLanguage(toUtilsLanguage(settings.displayLanguage)); - utils::localize.setInputLanguage(toUtilsLanguage(settings.inputLanguage)); + utils::localize.SetDisplayLanguage(toUtilsLanguage(displayLanguage)); + utils::localize.setInputLanguage(toUtilsLanguage(inputLanguage)); + blockingTimer->setInterval(default_application_locktime_ms); startSystemServices(); startBackgroundApplications(); @@ -240,16 +235,6 @@ namespace app::manager handleInitApplication(msg); return std::make_shared(); }); - connect(typeid(DisplayLanguageChangeRequest), [this](sys::Message *request) { - auto msg = static_cast(request); - handleDisplayLanguageChange(msg); - return std::make_shared(); - }); - connect(typeid(InputLanguageChangeRequest), [this](sys::Message *request) { - auto msg = static_cast(request); - handleInputLanguageChange(msg); - return std::make_shared(); - }); connect(typeid(ShutdownRequest), [this](sys::Message *) { closeApplications(); closeServices(); @@ -531,37 +516,6 @@ namespace app::manager Controller::switchBack(this); } - auto ApplicationManager::handleDisplayLanguageChange(app::manager::DisplayLanguageChangeRequest *msg) -> bool - { - const auto requestedLanguage = toSettingsLanguage(msg->getLanguage()); - settings = DBServiceAPI::SettingsGet(this); - - if (requestedLanguage == settings.displayLanguage) { - LOG_WARN("The selected language is already set. Ignore."); - return true; - } - settings.displayLanguage = requestedLanguage; - utils::localize.SetDisplayLanguage(msg->getLanguage()); - rebuildActiveApplications(); - DBServiceAPI::SettingsUpdate(this, settings); - return true; - } - - auto ApplicationManager::handleInputLanguageChange(app::manager::InputLanguageChangeRequest *msg) -> bool - { - const auto requestedLanguage = toSettingsLanguage(msg->getLanguage()); - settings = DBServiceAPI::SettingsGet(this); - - if (requestedLanguage == settings.inputLanguage) { - LOG_WARN("The selected language is already set. Ignore."); - return true; - } - settings.inputLanguage = requestedLanguage; - utils::localize.setInputLanguage(msg->getLanguage()); - DBServiceAPI::SettingsUpdate(this, settings); - return true; - } - void ApplicationManager::rebuildActiveApplications() { for (const auto &app : getApplications()) { @@ -671,4 +625,30 @@ namespace app::manager } #endif } + void ApplicationManager::displayLanguageChanged(const std::string &name, std::optional value) + { + if (value.has_value()) { + if (displayLanguage != value.value()) { + displayLanguage = value.value(); + utils::localize.SetDisplayLanguage(toUtilsLanguage(displayLanguage)); + rebuildActiveApplications(); + } + else { + LOG_WARN("The selected language is already set. Ignore."); + } + } + } + void ApplicationManager::lockTimeChanged(const std::string &name, std::optional value) + { + if (value.has_value() && !value.value().empty()) { + blockingTimer->setInterval(utils::getValue(value.value())); + //?any additional action needed here? + } + } + void ApplicationManager::inputLanguageChanged(const std::string &name, std::optional value) + { + if (value.has_value()) { + inputLanguage = value.value(); + } + } } // namespace app::manager diff --git a/module-services/service-appmgr/service-appmgr/model/ApplicationManager.hpp b/module-services/service-appmgr/service-appmgr/model/ApplicationManager.hpp index 3a69ba5496461d6c239b06757efacbc1cebeed55..9f9a9d9e259bb62e65b6ffc716653a903e5c0024 100644 --- a/module-services/service-appmgr/service-appmgr/model/ApplicationManager.hpp +++ b/module-services/service-appmgr/service-appmgr/model/ApplicationManager.hpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include @@ -23,6 +22,8 @@ #include #include +#include + namespace app { class ApplicationLauncher; @@ -135,7 +136,6 @@ namespace app::manager void onPhoneLocked(); ApplicationName rootApplicationName; - SettingsRecord settings; std::unique_ptr blockingTimer; //< timer to count time from last user's activity. If it reaches time // defined in settings database application // manager is sending signal to power manager and changing window to @@ -143,5 +143,12 @@ namespace app::manager // Temporary solution - to be replaced with ActionsMiddleware. std::tuple pendingAction; + + std::unique_ptr<::Settings::Settings> settings; + void displayLanguageChanged(const std::string &name, std::optional value); + void lockTimeChanged(const std::string &name, std::optional value); + void inputLanguageChanged(const std::string &name, std::optional value); + std::string inputLanguage; + std::string displayLanguage; }; } // namespace app::manager diff --git a/module-services/service-db/DBServiceAPI.cpp b/module-services/service-db/DBServiceAPI.cpp index 17927e9d3d8fcbab77845906754eb203a8eeb117..f1c5be4ec446e15944fafd8e6330e3f96052ce7f 100644 --- a/module-services/service-db/DBServiceAPI.cpp +++ b/module-services/service-db/DBServiceAPI.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -44,41 +43,6 @@ namespace sys } // namespace sys struct NotesRecord; -SettingsRecord DBServiceAPI::SettingsGet(sys::Service *serv) -{ - - std::shared_ptr msg = std::make_shared(MessageType::DBSettingsGet); - - auto ret = sys::Bus::SendUnicast(msg, service::name::db, serv, DefaultTimeoutInMs); - if (ret.first == sys::ReturnCodes::Success) { - auto respMsg = ret.second; - DBSettingsResponseMessage *settingsResponse = reinterpret_cast(respMsg.get()); - - if (settingsResponse->retCode == true) { - return settingsResponse->record; - } - else { - return SettingsRecord{}; - } - } - else { - return SettingsRecord{}; - } -} - -bool DBServiceAPI::SettingsUpdate(sys::Service *serv, const SettingsRecord &rec) -{ - std::shared_ptr msg = std::make_shared(MessageType::DBSettingsUpdate, rec); - - auto ret = sys::Bus::SendUnicast(msg, service::name::db, serv, DefaultTimeoutInMs); - if (ret.first == sys::ReturnCodes::Success) { - return true; - } - else { - return false; - } -} - uint32_t DBServiceAPI::SMSAdd(sys::Service *serv, const SMSRecord &rec) { std::shared_ptr msg = std::make_shared(MessageType::DBSMSAdd, rec); diff --git a/module-services/service-db/ServiceDB.cpp b/module-services/service-db/ServiceDB.cpp index cd20d351a2517594f47d34a6690b52bd564c3bb9..37c4160904608aeeeacacef8aaae37ef34ac934d 100644 --- a/module-services/service-db/ServiceDB.cpp +++ b/module-services/service-db/ServiceDB.cpp @@ -40,7 +40,6 @@ #include #include #include -#include #include #include #include @@ -79,8 +78,6 @@ ServiceDB::~ServiceDB() db::Interface *ServiceDB::getInterface(db::Interface::Name interface) { switch (interface) { - case db::Interface::Name::Settings: - return settingsRecordInterface.get(); case db::Interface::Name::SMS: return smsRecordInterface.get(); case db::Interface::Name::SMSThread: @@ -115,21 +112,6 @@ sys::MessagePointer ServiceDB::DataReceivedHandler(sys::DataMessage *msgl, sys:: auto type = static_cast(msgl->messageType); switch (type) { - /* - * Settings record - */ - case MessageType::DBSettingsGet: { - auto time = utils::time::Scoped("DBSettingsGet"); - auto settingsRec = settingsRecordInterface->GetByID(1); - responseMsg = std::make_shared(settingsRec, settingsRec.dbID == 0 ? false : true); - } break; - case MessageType::DBSettingsUpdate: { - auto time = utils::time::Scoped("DBSettingsUpdate"); - DBSettingsMessage *msg = reinterpret_cast(msgl); - auto ret = settingsRecordInterface->Update(msg->record); - responseMsg = std::make_shared(SettingsRecord{}, ret); - sendUpdateNotification(db::Interface::Name::Settings, db::Query::Type::Update); - } break; /* * SMS records */ @@ -619,7 +601,6 @@ sys::ReturnCodes ServiceDB::InitHandler() eventsDB = std::make_unique(); // Create record interfaces - settingsRecordInterface = std::make_unique(settingsDB.get()); contactRecordInterface = std::make_unique(contactsDB.get()); smsRecordInterface = std::make_unique(smsDB.get(), contactsDB.get()); threadRecordInterface = std::make_unique(smsDB.get(), contactsDB.get()); diff --git a/module-services/service-db/ServiceDB.hpp b/module-services/service-db/ServiceDB.hpp index 4d4c504efc6df02d4335f9d11cbe91765d37c7c5..c1f43e1f3468bb786bf38c59bdcecc4530eaf739 100644 --- a/module-services/service-db/ServiceDB.hpp +++ b/module-services/service-db/ServiceDB.hpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -48,7 +47,6 @@ class NotificationsRecordInterface; class SMSRecordInterface; class SMSTemplateRecordInterface; class SettingsDB; -class SettingsRecordInterface; class SettingsRecordInterface_v2; class SmsDB; class ThreadRecordInterface; @@ -66,7 +64,6 @@ class ServiceDB : public sys::Service std::unique_ptr notificationsDB; std::unique_ptr eventsDB; - std::unique_ptr settingsRecordInterface; std::unique_ptr smsRecordInterface; std::unique_ptr threadRecordInterface; std::unique_ptr smsTemplateRecordInterface; diff --git a/module-services/service-db/agents/settings/Settings.cpp b/module-services/service-db/agents/settings/Settings.cpp index 7ec0bfb92375c76b287c271cbcc7292f9023ed7b..652e5421ae8b3867724e704c727dd558d14010d6 100644 --- a/module-services/service-db/agents/settings/Settings.cpp +++ b/module-services/service-db/agents/settings/Settings.cpp @@ -25,6 +25,7 @@ namespace Settings Settings::~Settings() { + LOG_DEBUG("Settings::~Settings on %s", app->GetName().c_str()); sys::Bus::Remove(std::static_pointer_cast(app)); } @@ -37,6 +38,7 @@ namespace Settings { using std::placeholders::_1; using std::placeholders::_2; + LOG_DEBUG("Settings::registerHandlers for %s", app->GetName().c_str()); app->connect(::Settings::Messages::VariableChanged(), std::bind(&Settings::handleVariableChanged, this, _1)); app->connect(::Settings::Messages::CurrentProfileChanged(), std::bind(&Settings::handleCurrentProfileChanged, this, _1)); diff --git a/module-services/service-db/agents/settings/SystemSettings.hpp b/module-services/service-db/agents/settings/SystemSettings.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ecc2fbdc45b71230ff9c0972ef610f2ccca4f145 --- /dev/null +++ b/module-services/service-db/agents/settings/SystemSettings.hpp @@ -0,0 +1,15 @@ +// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +namespace Settings::SystemProperties +{ + constexpr inline auto timeFormat12 = "gs_time_format_12"; + constexpr inline auto timeDateFormat = "gs_time_date_format"; + constexpr inline auto activeSim = "gs_active_sim"; + constexpr inline auto lockPassHash = "gs_lock_pass_hash"; + constexpr inline auto lockTime = "gs_lock_time"; + constexpr inline auto displayLanguage = "gs_display_language"; + constexpr inline auto inputLanguage = "gs_input_language"; +}; // namespace Settings::SystemProperties diff --git a/module-services/service-db/agents/settings/settings.sql b/module-services/service-db/agents/settings/settings.sql index 655a3152551583d5490e99f53d78e2a6f6753200..d01f06bde9cdf419cb193f41faec1aa478d75a28 100644 --- a/module-services/service-db/agents/settings/settings.sql +++ b/module-services/service-db/agents/settings/settings.sql @@ -9,7 +9,7 @@ BEGIN TRANSACTION; -- Main settings table, for string application persistent data -- CREATE TABLE IF NOT EXISTS settings_tab ( - path TEXT NOT NULL UNIQUE, + path TEXT NOT NULL UNIQUE PRIMARY KEY, value TEXT ); @@ -64,5 +64,18 @@ INSERT OR REPLACE INTO dictionary_tab (path, value) VALUES INSERT OR REPLACE INTO settings_tab (path, value) VALUES ('system/phone_mode', 'online'); +--language:En, Pl, De, Sp +--howto put value from magic_enum for activeSim? +--what about keeping available languages to dictionary_tab? +--a list based function to get all languages would be needed +INSERT OR REPLACE INTO settings_tab (path, value) VALUES + ('timeFormat12', '0'), + ('timeDateFormat', '1'), + ('activeSim', '1'), + ('lockPassHash', '0'), + ('lockTime', '30000'), + ('displayLanguage', 'En'), + ('inputLanguag', 'En'); + COMMIT TRANSACTION; -- )dbInitStr" diff --git a/module-services/service-db/messages/DBSettingsMessage.cpp b/module-services/service-db/messages/DBSettingsMessage.cpp index d6433008eba35346b7ceeba32df8765fdcd9c09b..2098dc99089afa5c5ba2e8e7b63451d66bca23cd 100644 --- a/module-services/service-db/messages/DBSettingsMessage.cpp +++ b/module-services/service-db/messages/DBSettingsMessage.cpp @@ -6,22 +6,10 @@ #include -struct SettingsRecord; - -DBSettingsMessage::DBSettingsMessage(MessageType messageType, const SettingsRecord &rec) - : DBMessage(messageType), record(rec) -{} - DBSettingsMessage::DBSettingsMessage(MessageType messageType, const SettingsRecord_v2 &rec, const std::string &path) : DBMessage(messageType), settingsRecord(rec), path(path) {} -DBSettingsResponseMessage::DBSettingsResponseMessage(const SettingsRecord &rec, - uint32_t retCode, - uint32_t count, - MessageType respTo) - : DBResponseMessage(retCode, count, respTo), record(rec){}; - DBSettingsResponseMessage::DBSettingsResponseMessage(const SettingsRecord_v2 &rec, uint32_t retCode, uint32_t count, diff --git a/module-services/service-db/service-db/DBServiceAPI.hpp b/module-services/service-db/service-db/DBServiceAPI.hpp index c5f854ae0d7efc0aee402f0df393c4b0ea63b2a5..a401116c83f6ed4723db79470eb753290c25349d 100644 --- a/module-services/service-db/service-db/DBServiceAPI.hpp +++ b/module-services/service-db/service-db/DBServiceAPI.hpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -51,8 +50,6 @@ class DBServiceAPI secondaryNumberError, noError }; - static SettingsRecord SettingsGet(sys::Service *serv); - static bool SettingsUpdate(sys::Service *serv, const SettingsRecord &rec); /** * @brief Function is adding new SMS to SMSDB. diff --git a/module-services/service-db/service-db/DBSettingsMessage.hpp b/module-services/service-db/service-db/DBSettingsMessage.hpp index 502d0895747b95743e6fe02d3ed9cc3247a28817..18db19ead8a6f9ea97b5886c4975d74d0a6f3992 100644 --- a/module-services/service-db/service-db/DBSettingsMessage.hpp +++ b/module-services/service-db/service-db/DBSettingsMessage.hpp @@ -5,19 +5,14 @@ #include "DBMessage.hpp" -#include -#include -#include - -#include -#include +#include "DBMessage.hpp" // for DBMessage, DBResponseMessage +#include "Interface/SettingsRecord_v2.hpp" // for SettingsRecord_v2 +#include "MessageType.hpp" // for MessageType, MessageType::MessageTypeUninitialized class DBSettingsMessage : public DBMessage { public: - DBSettingsMessage(MessageType messageType, const SettingsRecord &rec = SettingsRecord{}); DBSettingsMessage(MessageType messageType, const SettingsRecord_v2 &rec, const std::string &path); - SettingsRecord record; SettingsRecord_v2 settingsRecord; std::string path; }; @@ -25,14 +20,9 @@ class DBSettingsMessage : public DBMessage class DBSettingsResponseMessage : public DBResponseMessage { public: - DBSettingsResponseMessage(const SettingsRecord &rec, - uint32_t retCode = 0, - uint32_t count = 0, - MessageType respTo = MessageType::MessageTypeUninitialized); DBSettingsResponseMessage(const SettingsRecord_v2 &rec, uint32_t retCode = 0, uint32_t count = 0, MessageType respTo = MessageType::MessageTypeUninitialized); - SettingsRecord record; SettingsRecord_v2 settingsRecord; };