From 434df6d8b80a3e267475a6312a8fc04190e67c47 Mon Sep 17 00:00:00 2001 From: Tomasz Sobkowiak Date: Mon, 26 Apr 2021 22:10:10 +0200 Subject: [PATCH] [EGD-6520] Show factory data on technical information window Remove mocked data and read real data from settings db --- image/assets/lang/English.json | 5 + .../ApplicationSettings.cpp | 6 +- .../ApplicationSettings.hpp | 1 + .../application-settings-new/CMakeLists.txt | 2 + .../models/FactoryData.cpp | 32 +++++ .../models/FactoryData.hpp | 33 +++++ .../presenter/TechnicalWindowPresenter.cpp | 29 +++++ .../presenter/TechnicalWindowPresenter.hpp | 48 +++++++ .../widgets/SettingsStyle.hpp | 62 +--------- .../windows/TechnicalInformationWindow.cpp | 117 +++++++++--------- .../windows/TechnicalInformationWindow.hpp | 28 ++++- .../agents/settings/FactorySettings.cpp | 5 +- 12 files changed, 244 insertions(+), 124 deletions(-) create mode 100644 module-apps/application-settings-new/models/FactoryData.cpp create mode 100644 module-apps/application-settings-new/models/FactoryData.hpp create mode 100644 module-apps/application-settings-new/presenter/TechnicalWindowPresenter.cpp create mode 100644 module-apps/application-settings-new/presenter/TechnicalWindowPresenter.hpp diff --git a/image/assets/lang/English.json b/image/assets/lang/English.json index e53a2078d587763447e72be752df9e45d36403cb..8a8e82114e4e68f5d34ae20d5722f16fab5fc769 100644 --- a/image/assets/lang/English.json +++ b/image/assets/lang/English.json @@ -414,6 +414,11 @@ "app_settings_tech_info_serial_number": "Serial number", "app_settings_tech_info_os_version": "OS Version", "app_settings_tech_info_imei": "IMEI", + "app_settings_tech_info_battery": "Battery", + "app_settings_tech_info_pcb_mb": "pcbMB", + "app_settings_tech_info_pcb_lm": "pcbLM", + "app_settings_tech_info_pcb_um": "pcmUM", + "app_settings_tech_info_pcb_am": "pcbAM", "app_settings_certification": "Certification", "app_settings_us_fcc_id": "US FCC ID", "app_settings_canada_ic": "Canada IC", diff --git a/module-apps/application-settings-new/ApplicationSettings.cpp b/module-apps/application-settings-new/ApplicationSettings.cpp index 05ccda2868e39645bdff7c3d576c9f5e45ccc76d..0ebec2cdb79ccc3ea94f6c86584cc9a18b8aa26f 100644 --- a/module-apps/application-settings-new/ApplicationSettings.cpp +++ b/module-apps/application-settings-new/ApplicationSettings.cpp @@ -459,8 +459,10 @@ namespace app windowsFactory.attach(gui::window::name::certification, [](Application *app, const std::string &name) { return std::make_unique(app); }); - windowsFactory.attach(gui::window::name::technical_information, [](Application *app, const std::string &name) { - return std::make_unique(app); + windowsFactory.attach(gui::window::name::technical_information, [&](Application *app, const std::string &name) { + auto factoryData = std::make_unique(std::make_unique<::settings::Settings>(this)); + auto presenter = std::make_unique(std::move(factoryData)); + return std::make_unique(app, std::move(presenter)); }); windowsFactory.attach(gui::window::name::sar, [&](Application *app, const std::string &name) { auto sarInfoRepository = std::make_unique("assets/certification_info", "sar.txt"); diff --git a/module-apps/application-settings-new/ApplicationSettings.hpp b/module-apps/application-settings-new/ApplicationSettings.hpp index dae3bd1ab23d54f7fff1a2d5a60f15164cd0e7d0..02cd11384492c2e01955cacd3df0091866c945a4 100644 --- a/module-apps/application-settings-new/ApplicationSettings.hpp +++ b/module-apps/application-settings-new/ApplicationSettings.hpp @@ -163,6 +163,7 @@ namespace app virtual auto isFlightMode() const noexcept -> bool = 0; virtual void setFlightMode(bool flightModeOn) noexcept = 0; }; + }; // namespace settingsInterface class ApplicationSettingsNew : public app::Application, diff --git a/module-apps/application-settings-new/CMakeLists.txt b/module-apps/application-settings-new/CMakeLists.txt index 9c4c4858a41961c49370b5386d2d4c0afc4fb47e..7539c9a9841aad8f350ba7ab315d91a2c8fc3434 100644 --- a/module-apps/application-settings-new/CMakeLists.txt +++ b/module-apps/application-settings-new/CMakeLists.txt @@ -23,9 +23,11 @@ target_sources( ${PROJECT_NAME} models/QuotesModel.cpp models/CategoriesModel.cpp models/SARInfoRepository.cpp + models/FactoryData.cpp models/AudioSettingsModel.cpp models/SoundsModel.cpp presenter/SARInfoWindowPresenter.cpp + presenter/TechnicalWindowPresenter.cpp widgets/ChangePasscodeLockHandler.cpp widgets/QuoteWidget.cpp widgets/CategoryWidget.cpp diff --git a/module-apps/application-settings-new/models/FactoryData.cpp b/module-apps/application-settings-new/models/FactoryData.cpp new file mode 100644 index 0000000000000000000000000000000000000000..105b6efd4f10495f4cdd0b37d6f0ff38a7797c35 --- /dev/null +++ b/module-apps/application-settings-new/models/FactoryData.cpp @@ -0,0 +1,32 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "FactoryData.hpp" +#include +#include + +FactoryData::FactoryData(std::unique_ptr settingsProvider) : settings(std::move(settingsProvider)) +{} + +auto FactoryData::getModel() -> std::string +{ + return settings->getValue(settings::factory::entry_key + std::string("/model"), settings::SettingsScope::Global); +} +auto FactoryData::getCase() -> std::string +{ + return settings->getValue(settings::factory::entry_key + std::string("/case"), ::settings::SettingsScope::Global); +} +auto FactoryData::getSerial() -> std::string +{ + return settings->getValue(settings::factory::entry_key + std::string("/serial"), settings::SettingsScope::Global); +} +auto FactoryData::getBatteryRev() -> std::string +{ + return settings->getValue(settings::factory::entry_key + std::string("/battery_revision"), + settings::SettingsScope::Global); +} +auto FactoryData::getPcb(std::string type) -> std::string +{ + std::string full_pcb = "/pcb_" + type + "_version"; + return settings->getValue(settings::factory::entry_key + full_pcb, settings::SettingsScope::Global); +} diff --git a/module-apps/application-settings-new/models/FactoryData.hpp b/module-apps/application-settings-new/models/FactoryData.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f21f0393a514c20b38d98fe7abf345701e0a4276 --- /dev/null +++ b/module-apps/application-settings-new/models/FactoryData.hpp @@ -0,0 +1,33 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include + +class AbstractFactoryData +{ + public: + virtual ~AbstractFactoryData() noexcept = default; + + virtual auto getModel() -> std::string = 0; + virtual auto getCase() -> std::string = 0; + virtual auto getSerial() -> std::string = 0; + virtual auto getBatteryRev() -> std::string = 0; + virtual auto getPcb(std::string type) -> std::string = 0; +}; + +class FactoryData : public AbstractFactoryData +{ + public: + explicit FactoryData(std::unique_ptr settings); + + auto getModel() -> std::string override; + auto getCase() -> std::string override; + auto getSerial() -> std::string override; + auto getBatteryRev() -> std::string override; + auto getPcb(std::string type) -> std::string override; + + private: + std::unique_ptr settings; +}; diff --git a/module-apps/application-settings-new/presenter/TechnicalWindowPresenter.cpp b/module-apps/application-settings-new/presenter/TechnicalWindowPresenter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e7072e775ffe97d873db7ae092b2922c76049b72 --- /dev/null +++ b/module-apps/application-settings-new/presenter/TechnicalWindowPresenter.cpp @@ -0,0 +1,29 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "TechnicalWindowPresenter.hpp" + +TechnicalWindowPresenter::TechnicalWindowPresenter(std::unique_ptr &&factoryData) + : factoryData{std::move(factoryData)} +{} + +auto TechnicalWindowPresenter::getModel() -> std::string +{ + return factoryData->getModel(); +} +auto TechnicalWindowPresenter::getCase() -> std::string +{ + return factoryData->getCase(); +} +auto TechnicalWindowPresenter::getSerial() -> std::string +{ + return factoryData->getSerial(); +} +auto TechnicalWindowPresenter::getBatteryRev() -> std::string +{ + return factoryData->getBatteryRev(); +} +auto TechnicalWindowPresenter::getPcb(std::string type) -> std::string +{ + return factoryData->getPcb(type); +} \ No newline at end of file diff --git a/module-apps/application-settings-new/presenter/TechnicalWindowPresenter.hpp b/module-apps/application-settings-new/presenter/TechnicalWindowPresenter.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0c6292cf7571c1d090e624fc0206657ba2447ffb --- /dev/null +++ b/module-apps/application-settings-new/presenter/TechnicalWindowPresenter.hpp @@ -0,0 +1,48 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include "application-settings-new/models/FactoryData.hpp" +#include "BasePresenter.hpp" + +class TechnicalWindowContract +{ + public: + class View + { + public: + virtual ~View() noexcept = default; + }; + class Presenter : public app::BasePresenter + { + public: + virtual ~Presenter() noexcept override = default; + + virtual auto getModel() -> std::string = 0; + virtual auto getCase() -> std::string = 0; + virtual auto getSerial() -> std::string = 0; + virtual auto getBatteryRev() -> std::string = 0; + virtual auto getPcb(std::string type) -> std::string = 0; + }; +}; + +class TechnicalWindowPresenter : public TechnicalWindowContract::Presenter +{ + public: + static constexpr auto PCB_LM = "lm"; + static constexpr auto PCB_AM = "am"; + static constexpr auto PCB_MB = "mb"; + static constexpr auto PCB_UM = "um"; + + explicit TechnicalWindowPresenter(std::unique_ptr &&factoryData); + + auto getModel() -> std::string override; + auto getCase() -> std::string override; + auto getSerial() -> std::string override; + auto getBatteryRev() -> std::string override; + auto getPcb(std::string type) -> std::string override; + + private: + std::unique_ptr factoryData; +}; diff --git a/module-apps/application-settings-new/widgets/SettingsStyle.hpp b/module-apps/application-settings-new/widgets/SettingsStyle.hpp index b5c48aa5319d77fdfa74b890c391203a6c851cb1..e3f96590a7a1cbd6be167237438809aef3675513 100644 --- a/module-apps/application-settings-new/widgets/SettingsStyle.hpp +++ b/module-apps/application-settings-new/widgets/SettingsStyle.hpp @@ -237,65 +237,7 @@ namespace style namespace techinfo { - namespace textmodel - { - inline constexpr auto x = 30; - inline constexpr auto y = 117; - inline constexpr auto width = 400; - inline constexpr auto height = 30; - } // namespace textmodel - namespace valuemodel - { - inline constexpr auto x = 30; - inline constexpr auto y = 150; - inline constexpr auto width = 400; - inline constexpr auto height = 30; - } // namespace valuemodel - - namespace textserialnumber - { - inline constexpr auto x = 30; - inline constexpr auto y = 192; - inline constexpr auto width = 400; - inline constexpr auto height = 30; - } // namespace textserialnumber - namespace valueserialnumber - { - inline constexpr auto x = 30; - inline constexpr auto y = 225; - inline constexpr auto width = 400; - inline constexpr auto height = 30; - } // namespace valueserialnumber - - namespace textosversion - { - inline constexpr auto x = 30; - inline constexpr auto y = 267; - inline constexpr auto width = 400; - inline constexpr auto height = 30; - } // namespace textosversion - namespace valueosversion - { - inline constexpr auto x = 30; - inline constexpr auto y = 300; - inline constexpr auto width = 400; - inline constexpr auto height = 30; - } // namespace valueosversion - - namespace textimea - { - inline constexpr auto x = 30; - inline constexpr auto y = 342; - inline constexpr auto width = 400; - inline constexpr auto height = 30; - } // namespace textimea - namespace valueimea - { - inline constexpr auto x = 30; - inline constexpr auto y = 375; - inline constexpr auto width = 400; - inline constexpr auto height = 30; - } // namespace valueimea - + inline constexpr auto width = 400; + inline constexpr auto height = 30; } // namespace techinfo } // namespace style diff --git a/module-apps/application-settings-new/windows/TechnicalInformationWindow.cpp b/module-apps/application-settings-new/windows/TechnicalInformationWindow.cpp index 9ae9c350a32847da54ce771bb524983aa9a2f842..1db0a2014d747199f1e91f53c0713e055208a196 100644 --- a/module-apps/application-settings-new/windows/TechnicalInformationWindow.cpp +++ b/module-apps/application-settings-new/windows/TechnicalInformationWindow.cpp @@ -7,15 +7,14 @@ #include #include -static constexpr auto model = "1.0"; -static constexpr auto serialNumber = "XXXXXXXXXXXXXXX"; -static constexpr auto imei = "AA-BBBBBB-CCCCCC-D"; - namespace gui { - TechnicalInformationWindow::TechnicalInformationWindow(app::Application *app) - : AppWindow(app, gui::window::name::certification) + + TechnicalInformationWindow::TechnicalInformationWindow( + app::Application *app, std::unique_ptr technicalPresenter) + : AppWindow(app, gui::window::name::certification), presenter(std::move(technicalPresenter)) { + presenter->attach(this); buildInterface(); } @@ -25,64 +24,68 @@ namespace gui setTitle(utils::translate("app_settings_technical_information")); - modelText = new gui::Text(this, - style::techinfo::textmodel::x, - style::techinfo::textmodel::y, - style::techinfo::textmodel::width, - style::techinfo::textmodel::height); - modelValue = new gui::Text(this, - style::techinfo::valuemodel::x, - style::techinfo::valuemodel::y, - style::techinfo::valuemodel::width, - style::techinfo::valuemodel::height); - - serialNumberText = new gui::Text(this, - style::techinfo::textserialnumber::x, - style::techinfo::textserialnumber::y, - style::techinfo::textserialnumber::width, - style::techinfo::textserialnumber::height); - serialNumberValue = new gui::Text(this, - style::techinfo::valueserialnumber::x, - style::techinfo::valueserialnumber::y, - style::techinfo::valueserialnumber::width, - style::techinfo::valueserialnumber::height); - - osVersionText = new gui::Text(this, - style::techinfo::textosversion::x, - style::techinfo::textosversion::y, - style::techinfo::textosversion::width, - style::techinfo::textosversion::height); - osVersionValue = new gui::Text(this, - style::techinfo::valueosversion::x, - style::techinfo::valueosversion::y, - style::techinfo::valueosversion::width, - style::techinfo::valueosversion::height); - - imeiText = new gui::Text(this, - style::techinfo::textimea::x, - style::techinfo::textimea::y + 10, - style::techinfo::textimea::width, - style::techinfo::textimea::height); - imeiValue = new gui::Text(this, - style::techinfo::valueimea::x, - style::techinfo::valueimea::y + 20, - style::techinfo::valueimea::width, - style::techinfo::valueimea::height); - - bottomBar->setText(BottomBar::Side::RIGHT, utils::translate(style::strings::common::back)); - } + auto vBox = new VBox(this, + style::window::default_left_margin, + style::header::height + style::margins::very_big, + style::window::default_body_width, + style::window::default_body_height); + vBox->setEdges(RectangleEdge::None); - void TechnicalInformationWindow::onBeforeShow(ShowMode mode, SwitchData *data) - { - // dummy data for now + modelText = new gui::Text(vBox, 0, 0, style::techinfo::width, style::techinfo::height); modelText->setText(utils::translate("app_settings_tech_info_model")); - modelValue->setText(model); + modelText->setFont(style::window::font::smallbold); + modelValue = new gui::Text(vBox, 0, 0, style::techinfo::width, style::techinfo::height); + modelValue->setText(presenter->getModel()); + + serialNumberText = new gui::Text(vBox, 0, 0, style::techinfo::width, style::techinfo::height); + serialNumberText->setFont(style::window::font::smallbold); serialNumberText->setText(utils::translate("app_settings_tech_info_serial_number")); - serialNumberValue->setText(serialNumber); + serialNumberValue = new gui::Text(vBox, 0, 0, style::techinfo::width, style::techinfo::height); + serialNumberValue->setText(presenter->getSerial()); + + osVersionText = new gui::Text(vBox, 0, 0, style::techinfo::width, style::techinfo::height); + osVersionText->setFont(style::window::font::smallbold); osVersionText->setText(utils::translate("app_settings_tech_info_os_version")); + osVersionValue = new gui::Text(vBox, 0, 0, style::techinfo::width, style::techinfo::height); osVersionValue->setText(std::string(VERSION)); + + imeiText = new gui::Text(vBox, 0, 0, style::techinfo::width, style::techinfo::height); + imeiText->setFont(style::window::font::smallbold); imeiText->setText(utils::translate("app_settings_tech_info_imei")); + imeiValue = new gui::Text(vBox, 0, 0, style::techinfo::width, style::techinfo::height); imeiValue->setText(imei); + + batteryText = new gui::Text(vBox, 0, 0, style::techinfo::width, style::techinfo::height); + batteryText->setFont(style::window::font::smallbold); + batteryText->setText(utils::translate("app_settings_tech_info_battery")); + batteryValue = new gui::Text(vBox, 0, 0, style::techinfo::width, style::techinfo::height); + batteryValue->setText(presenter->getBatteryRev()); + + pcbMbText = new gui::Text(vBox, 0, 0, style::techinfo::width, style::techinfo::height); + pcbMbText->setText(utils::translate("app_settings_tech_info_pcb_mb")); + pcbMbText->setFont(style::window::font::smallbold); + pcbMbValue = new gui::Text(vBox, 0, 0, style::techinfo::width, style::techinfo::height); + pcbMbValue->setText(presenter->getPcb(TechnicalWindowPresenter::PCB_MB)); + + pcbLmText = new gui::Text(vBox, 0, 0, style::techinfo::width, style::techinfo::height); + pcbLmText->setFont(style::window::font::smallbold); + pcbLmText->setText(utils::translate("app_settings_tech_info_pcb_lm")); + pcbLmValue = new gui::Text(vBox, 0, 0, style::techinfo::width, style::techinfo::height); + pcbLmValue->setText(presenter->getPcb(TechnicalWindowPresenter::PCB_LM)); + + pcbAmText = new gui::Text(vBox, 0, 0, style::techinfo::width, style::techinfo::height); + pcbAmText->setFont(style::window::font::smallbold); + pcbAmText->setText(utils::translate("app_settings_tech_info_pcb_am")); + pcbAmValue = new gui::Text(vBox, 0, 0, style::techinfo::width, style::techinfo::height); + pcbAmValue->setText(presenter->getPcb(TechnicalWindowPresenter::PCB_AM)); + + pcbUmText = new gui::Text(vBox, 0, 0, style::techinfo::width, style::techinfo::height); + pcbUmText->setFont(style::window::font::smallbold); + pcbUmText->setText(utils::translate("app_settings_tech_info_pcb_um")); + pcbUmValue = new gui::Text(vBox, 0, 0, style::techinfo::width, style::techinfo::height); + pcbUmValue->setText(presenter->getPcb(TechnicalWindowPresenter::PCB_UM)); + + bottomBar->setText(BottomBar::Side::RIGHT, utils::translate(style::strings::common::back)); } void TechnicalInformationWindow::destroyInterface() diff --git a/module-apps/application-settings-new/windows/TechnicalInformationWindow.hpp b/module-apps/application-settings-new/windows/TechnicalInformationWindow.hpp index 835acf31333e9ea47a4478a8933edb8b960bd779..0bd045a8c41eea66fbef178f45dd8118081c2678 100644 --- a/module-apps/application-settings-new/windows/TechnicalInformationWindow.hpp +++ b/module-apps/application-settings-new/windows/TechnicalInformationWindow.hpp @@ -4,19 +4,24 @@ #pragma once #include "BaseSettingsWindow.hpp" +#include +#include namespace gui { - class TechnicalInformationWindow : public AppWindow + class TechnicalInformationWindow : public AppWindow, public TechnicalWindowContract::View { + static constexpr auto imei = "AA-BBBBBB-CCCCC-D"; + public: - TechnicalInformationWindow(app::Application *app); + TechnicalInformationWindow(app::Application *app, + std::unique_ptr presenter); ~TechnicalInformationWindow() override; + void destroyInterface() override; private: void buildInterface() override; - void onBeforeShow(ShowMode mode, SwitchData *data) override; gui::Text *modelText = nullptr; gui::Text *modelValue = nullptr; @@ -29,6 +34,23 @@ namespace gui gui::Text *imeiText = nullptr; gui::Text *imeiValue = nullptr; + + gui::Text *batteryText = nullptr; + gui::Text *batteryValue = nullptr; + + gui::Text *pcbMbText = nullptr; + gui::Text *pcbMbValue = nullptr; + + gui::Text *pcbAmText = nullptr; + gui::Text *pcbAmValue = nullptr; + + gui::Text *pcbUmText = nullptr; + gui::Text *pcbUmValue = nullptr; + + gui::Text *pcbLmText = nullptr; + gui::Text *pcbLmValue = nullptr; + + std::unique_ptr presenter; }; } // namespace gui diff --git a/module-services/service-db/agents/settings/FactorySettings.cpp b/module-services/service-db/agents/settings/FactorySettings.cpp index d484f1365fd6f20b7e64e527ffbf54d24a155ead..2d9c42de4bb74de9926adb7b629cb9dcb4999097 100644 --- a/module-services/service-db/agents/settings/FactorySettings.cpp +++ b/module-services/service-db/agents/settings/FactorySettings.cpp @@ -26,8 +26,9 @@ namespace settings settings::EntryPath variablePath{"", "", - settings::factory::entry_key, - (*factoryData)[0].getString(), + "", + settings::factory::entry_key + std::string("/") + + (*factoryData)[0].getString(), settings::SettingsScope::Global}; auto value = (*factoryData)[1].getString();