~aleteoryx/muditaos

60edb1fc348be88fd24a1ca7545fb6f3d32356d3 — mkamonMdt 4 years ago 7f8fd25
[BH-811] PowerNap basic app structure

The following commit provides basic structure of PowerNap Application.
The structure includes:
* Application declaration
* MainWindow window-presenter contract
* Mainwindow basic structure
M products/BellHybrid/BellHybridMain.cpp => products/BellHybrid/BellHybridMain.cpp +2 -0
@@ 7,6 7,7 @@
#include <application-bell-alarm/ApplicationBellAlarm.hpp>
#include <application-bell-main/ApplicationBellMain.hpp>
#include <application-bell-settings/ApplicationBellSettings.hpp>
#include <application-bell-powernap/ApplicationBellPowerNap.hpp>

// modules
#include <module-db/Databases/AlarmsDB.hpp>


@@ 102,6 103,7 @@ int main()
                app::CreateLauncher<app::ApplicationBellMain>(app::applicationBellName, app::Closeable::False));
            applications.push_back(app::CreateLauncher<app::ApplicationBellSettings>(app::applicationBellSettingsName));
            applications.push_back(app::CreateLauncher<app::ApplicationBellAlarm>(app::applicationBellAlarmName));
            applications.push_back(app::CreateLauncher<app::ApplicationBellPowerNap>(app::applicationBellPowerNapName));
            // start application manager
            return sysmgr->RunSystemService(
                std::make_shared<app::manager::ApplicationManager>(

M products/BellHybrid/CMakeLists.txt => products/BellHybrid/CMakeLists.txt +1 -0
@@ 39,6 39,7 @@ target_link_libraries(BellHybrid
        application-bell-alarm
        application-bell-main
        application-bell-settings
        application-bell-powernap
        application-music-player
        appmgr
        db

M products/BellHybrid/apps/CMakeLists.txt => products/BellHybrid/apps/CMakeLists.txt +1 -0
@@ 1,3 1,4 @@
add_subdirectory(application-bell-main)
add_subdirectory(application-bell-alarm)
add_subdirectory(application-bell-settings)
add_subdirectory(application-bell-powernap)

M products/BellHybrid/apps/application-bell-main/CMakeLists.txt => products/BellHybrid/apps/application-bell-main/CMakeLists.txt +2 -1
@@ 12,7 12,7 @@ target_sources(application-bell-main

        presenters/HomeScreenPresenter.cpp
        presenters/StateController.cpp
 

        windows/BellHomeScreenWindow.hpp
        windows/BellMainMenuWindow.hpp



@@ 38,6 38,7 @@ target_link_libraries(application-bell-main
    PRIVATE
        application-bell-alarm
        application-bell-settings
        application-bell-powernap
        apps-common
        bellgui
        i18n

M products/BellHybrid/apps/application-bell-main/windows/BellMainMenuWindow.cpp => products/BellHybrid/apps/application-bell-main/windows/BellMainMenuWindow.cpp +4 -1
@@ 6,6 6,7 @@
#include <application-bell-alarm/ApplicationBellAlarm.hpp>
#include <application-bell-main/ApplicationBellMain.hpp>
#include <application-bell-settings/ApplicationBellSettings.hpp>
#include <application-bell-powernap/ApplicationBellPowerNap.hpp>
#include <data/BellMainStyle.hpp>

#include <Dialog.hpp>


@@ 80,7 81,9 @@ namespace gui

        // for demo only - to be replaced by call o final window
        addWinMenu(utils::translate("app_bellmain_bedtime"), gui::window::name::bell_main_menu_dialog);
        addWinMenu(utils::translate("app_bellmain_power_nap"), gui::window::name::bell_main_menu_dialog);
        addAppMenu(utils::translate("app_bellmain_next_alarm"), app::applicationBellAlarmName);
        addAppMenu(utils::translate("app_bellmain_power_nap"), app::applicationBellPowerNapName);
        // for demo only - to be replaced by call o final window
        addWinMenu(utils::translate("app_bellmain_meditation_timer"), gui::window::name::bell_main_menu_dialog);
        addWinMenu(utils::translate("app_bellmain_background_sounds"), gui::window::name::bell_main_menu_dialog);


A products/BellHybrid/apps/application-bell-powernap/ApplicationBellPowerNap.cpp => products/BellHybrid/apps/application-bell-powernap/ApplicationBellPowerNap.cpp +45 -0
@@ 0,0 1,45 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "ApplicationBellPowerNap.hpp"
#include "presenter/PowerNapMainWindowPresenter.hpp"
#include "windows/PowerNapMainWindow.hpp"

namespace app
{
    ApplicationBellPowerNap::ApplicationBellPowerNap(std::string name,
                                                     std::string parent,
                                                     sys::phone_modes::PhoneMode mode,
                                                     StartInBackground startInBackground)
        : Application(std::move(name), std::move(parent), mode, startInBackground)
    {}

    sys::ReturnCodes ApplicationBellPowerNap::InitHandler()
    {
        auto ret = Application::InitHandler();
        if (ret != sys::ReturnCodes::Success) {
            return ret;
        }
        createUserInterface();

        return sys::ReturnCodes::Success;
    }

    void ApplicationBellPowerNap::createUserInterface()
    {
        windowsFactory.attach(gui::name::window::main_window, [](Application *app, const std::string &name) {
            auto presenter = std::make_unique<powernap::PowerNapMainWindowPresenter>();
            return std::make_unique<gui::PowerNapMainWindow>(app, std::move(presenter));
        });
    }

    sys::MessagePointer ApplicationBellPowerNap::DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp)
    {
        auto retMsg = Application::DataReceivedHandler(msgl);
        if (auto response = dynamic_cast<sys::ResponseMessage *>(retMsg.get());
            response != nullptr && response->retCode == sys::ReturnCodes::Success) {
            return retMsg;
        }
        return sys::msgHandled();
    }
} // namespace app

A products/BellHybrid/apps/application-bell-powernap/CMakeLists.txt => products/BellHybrid/apps/application-bell-powernap/CMakeLists.txt +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

add_library(application-bell-powernap STATIC)

target_include_directories(application-bell-powernap
    PRIVATE
        $<BUILD_INTERFACE:
            include/application-bell-powernap
        >
    PUBLIC
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)

target_sources(application-bell-powernap
    PRIVATE
        ApplicationBellPowerNap.cpp
        windows/PowerNapMainWindow.cpp

        presenter/PowerNapMainWindowPresenter.hpp
        windows/PowerNapMainWindow.hpp

    PUBLIC
        include/application-bell-powernap/ApplicationBellPowerNap.hpp
)

target_link_libraries(application-bell-powernap
    PRIVATE

    PUBLIC
        apps-common
        module-gui
)

A products/BellHybrid/apps/application-bell-powernap/include/application-bell-powernap/ApplicationBellPowerNap.hpp => products/BellHybrid/apps/application-bell-powernap/include/application-bell-powernap/ApplicationBellPowerNap.hpp +41 -0
@@ 0,0 1,41 @@
// 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 <apps-common/Application.hpp>

namespace app
{
    inline constexpr auto applicationBellPowerNapName = "ApplicationBellPowerNap";

    class ApplicationBellPowerNap : public Application
    {
      public:
        ApplicationBellPowerNap(std::string name                    = applicationBellPowerNapName,
                                std::string parent                  = "",
                                sys::phone_modes::PhoneMode mode    = sys::phone_modes::PhoneMode::Offline,
                                StartInBackground startInBackground = {false});

        sys::ReturnCodes InitHandler() override;

        void createUserInterface() override;
        void destroyUserInterface() override
        {}

        sys::MessagePointer DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp) override;

        sys::ReturnCodes SwitchPowerModeHandler(const sys::ServicePowerMode mode) override final
        {
            return sys::ReturnCodes::Success;
        }
    };

    template <> struct ManifestTraits<ApplicationBellPowerNap>
    {
        static auto GetManifest() -> manager::ApplicationManifest
        {
            return {{manager::actions::Launch}};
        }
    };
} // namespace app

A products/BellHybrid/apps/application-bell-powernap/presenter/PowerNapMainWindowPresenter.hpp => products/BellHybrid/apps/application-bell-powernap/presenter/PowerNapMainWindowPresenter.hpp +26 -0
@@ 0,0 1,26 @@
// 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 <apps-common/BasePresenter.hpp>

namespace app::powernap
{
    class PowerNapMainWindowContract
    {
      public:
        class View
        {
          public:
            virtual ~View() noexcept = default;
        };

        class Presenter : public BasePresenter<PowerNapMainWindowContract::View>
        {};
    };

    class PowerNapMainWindowPresenter : public PowerNapMainWindowContract::Presenter
    {};

} // namespace app::powernap

A products/BellHybrid/apps/application-bell-powernap/windows/PowerNapMainWindow.cpp => products/BellHybrid/apps/application-bell-powernap/windows/PowerNapMainWindow.cpp +16 -0
@@ 0,0 1,16 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "PowerNapMainWindow.hpp"

namespace gui
{
    PowerNapMainWindow::PowerNapMainWindow(
        app::Application *app, std::unique_ptr<app::powernap::PowerNapMainWindowContract::Presenter> &&windowPresenter)
        : AppWindow(app, gui::name::window::main_window), windowPresenter{std::move(windowPresenter)}
    {
        this->windowPresenter->attach(this);
        buildInterface();
    }

} // namespace gui

A products/BellHybrid/apps/application-bell-powernap/windows/PowerNapMainWindow.hpp => products/BellHybrid/apps/application-bell-powernap/windows/PowerNapMainWindow.hpp +18 -0
@@ 0,0 1,18 @@
// 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 "presenter/PowerNapMainWindowPresenter.hpp"
#include <AppWindow.hpp>
namespace gui
{
    class PowerNapMainWindow : public AppWindow, public app::powernap::PowerNapMainWindowContract::View
    {
        std::unique_ptr<app::powernap::PowerNapMainWindowContract::Presenter> windowPresenter;

      public:
        PowerNapMainWindow(app::Application *app,
                           std::unique_ptr<app::powernap::PowerNapMainWindowContract::Presenter> &&windowPresenter);
    };
} // namespace gui