~aleteoryx/muditaos

434df6d8b80a3e267475a6312a8fc04190e67c47 — Tomasz Sobkowiak 4 years ago cfb2b9c
[EGD-6520] Show factory data on technical information window

Remove mocked data and read real data from settings db
M image/assets/lang/English.json => image/assets/lang/English.json +5 -0
@@ 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",

M module-apps/application-settings-new/ApplicationSettings.cpp => module-apps/application-settings-new/ApplicationSettings.cpp +4 -2
@@ 459,8 459,10 @@ namespace app
        windowsFactory.attach(gui::window::name::certification, [](Application *app, const std::string &name) {
            return std::make_unique<gui::CertificationWindow>(app);
        });
        windowsFactory.attach(gui::window::name::technical_information, [](Application *app, const std::string &name) {
            return std::make_unique<gui::TechnicalInformationWindow>(app);
        windowsFactory.attach(gui::window::name::technical_information, [&](Application *app, const std::string &name) {
            auto factoryData = std::make_unique<FactoryData>(std::make_unique<::settings::Settings>(this));
            auto presenter   = std::make_unique<TechnicalWindowPresenter>(std::move(factoryData));
            return std::make_unique<gui::TechnicalInformationWindow>(app, std::move(presenter));
        });
        windowsFactory.attach(gui::window::name::sar, [&](Application *app, const std::string &name) {
            auto sarInfoRepository = std::make_unique<SARInfoRepository>("assets/certification_info", "sar.txt");

M module-apps/application-settings-new/ApplicationSettings.hpp => module-apps/application-settings-new/ApplicationSettings.hpp +1 -0
@@ 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,

M module-apps/application-settings-new/CMakeLists.txt => module-apps/application-settings-new/CMakeLists.txt +2 -0
@@ 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

A module-apps/application-settings-new/models/FactoryData.cpp => module-apps/application-settings-new/models/FactoryData.cpp +32 -0
@@ 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 <service-db/Settings.hpp>
#include <service-db/agents/settings/FactorySettings.hpp>

FactoryData::FactoryData(std::unique_ptr<settings::Settings> 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);
}

A module-apps/application-settings-new/models/FactoryData.hpp => module-apps/application-settings-new/models/FactoryData.hpp +33 -0
@@ 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 <service-db/Settings.hpp>

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::Settings> 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::Settings> settings;
};

A module-apps/application-settings-new/presenter/TechnicalWindowPresenter.cpp => module-apps/application-settings-new/presenter/TechnicalWindowPresenter.cpp +29 -0
@@ 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<AbstractFactoryData> &&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

A module-apps/application-settings-new/presenter/TechnicalWindowPresenter.hpp => module-apps/application-settings-new/presenter/TechnicalWindowPresenter.hpp +48 -0
@@ 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<TechnicalWindowContract::View>
    {
      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<AbstractFactoryData> &&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<AbstractFactoryData> factoryData;
};

M module-apps/application-settings-new/widgets/SettingsStyle.hpp => module-apps/application-settings-new/widgets/SettingsStyle.hpp +2 -60
@@ 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

M module-apps/application-settings-new/windows/TechnicalInformationWindow.cpp => module-apps/application-settings-new/windows/TechnicalInformationWindow.cpp +60 -57
@@ 7,15 7,14 @@
#include <application-settings-new/widgets/SettingsStyle.hpp>
#include <source/version.hpp>

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<TechnicalWindowContract::Presenter> 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()

M module-apps/application-settings-new/windows/TechnicalInformationWindow.hpp => module-apps/application-settings-new/windows/TechnicalInformationWindow.hpp +25 -3
@@ 4,19 4,24 @@
#pragma once

#include "BaseSettingsWindow.hpp"
#include <module-apps/application-settings-new/ApplicationSettings.hpp>
#include <module-apps/application-settings-new/presenter/TechnicalWindowPresenter.hpp>

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<TechnicalWindowContract::Presenter> 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<TechnicalWindowContract::Presenter> presenter;
    };

} // namespace gui

M module-services/service-db/agents/settings/FactorySettings.cpp => module-services/service-db/agents/settings/FactorySettings.cpp +3 -2
@@ 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();