From 0e1880a726f97def0117b53a4008fdbcaa6a7a34 Mon Sep 17 00:00:00 2001 From: Jakub Pyszczak Date: Wed, 10 Mar 2021 14:53:13 +0100 Subject: [PATCH] [EGD-5624] Added window update This PR introduces mechanism for passing data to the currently displayed window by switch data. --- module-apps/Application.cpp | 27 +++++++++++++++++++++ module-apps/Application.hpp | 7 ++++++ module-apps/messages/AppMessage.hpp | 37 +++++++++++++++++++++++++++++ module-gui/gui/widgets/Window.cpp | 2 +- module-gui/gui/widgets/Window.hpp | 2 +- 5 files changed, 73 insertions(+), 2 deletions(-) diff --git a/module-apps/Application.cpp b/module-apps/Application.cpp index d8edd123bdb591c3fb015b5a4c1e6ed58553f86b..c6768cd3f694296ea8fa8ddfd9ebe3a2ead10ec7 100644 --- a/module-apps/Application.cpp +++ b/module-apps/Application.cpp @@ -102,6 +102,9 @@ namespace app connect(sevm::BatteryStatusChangeMessage(), [&](sys::Message *) { return handleBatteryStatusChange(); }); connect(typeid(app::manager::DOMRequest), [&](sys::Message *msg) -> sys::MessagePointer { return handleGetDOM(msg); }); + + connect(typeid(AppUpdateWindowMessage), + [&](sys::Message *msg) -> sys::MessagePointer { return handleUpdateWindow(msg); }); } Application::~Application() noexcept @@ -174,6 +177,14 @@ namespace app suspendInProgress = false; } + void Application::updateWindow(const std::string &windowName, std::unique_ptr data) + { + const auto currentWindow = getCurrentWindow(); + auto msg = + std::make_shared(currentWindow ? currentWindow->getName() : "", std::move(data)); + bus.sendUnicast(std::move(msg), this->GetName()); + } + void Application::switchWindow(const std::string &windowName, gui::ShowMode cmd, std::unique_ptr data) @@ -429,6 +440,22 @@ namespace app return msgHandled(); } + sys::MessagePointer Application::handleUpdateWindow(sys::Message *msgl) + { + auto msg = static_cast(msgl); + + if (windowsFactory.isRegistered(msg->getWindowName()) && isCurrentWindow(msg->getWindowName())) { + const auto &switchData = msg->getData(); + getCurrentWindow()->handleSwitchData(switchData.get()); + getCurrentWindow()->onBeforeShow(msg->getCommand(), switchData.get()); + refreshWindow(msg->getRefreshMode()); + } + else { + LOG_ERROR("No such window: %s", msg->getWindowName().c_str()); + } + return msgHandled(); + } + sys::MessagePointer Application::handleAppClose(sys::Message *msgl) { setState(State::DEACTIVATING); diff --git a/module-apps/Application.hpp b/module-apps/Application.hpp index 530c3fb336cdbcaf532c63c4e2d139933bda8083..df278cfe166540dbf49b5dde5664074ee56d9067 100644 --- a/module-apps/Application.hpp +++ b/module-apps/Application.hpp @@ -179,6 +179,7 @@ namespace app sys::MessagePointer handleAction(sys::Message *msgl); sys::MessagePointer handleApplicationSwitch(sys::Message *msgl); sys::MessagePointer handleSwitchWindow(sys::Message *msgl); + sys::MessagePointer handleUpdateWindow(sys::Message *msgl); sys::MessagePointer handleAppClose(sys::Message *msgl); sys::MessagePointer handleAppRebuild(sys::Message *msgl); sys::MessagePointer handleAppRefresh(sys::Message *msgl); @@ -209,6 +210,12 @@ namespace app /// 2. loads rendering commands and send them to GUI renderer (sgui::ServiceGUI) void render(gui::RefreshModes mode); + /// Responsible for sending updated data to the current window. + /// @note Sending different window name than the current one won't cause switch. + /// @param windowName name of the window that suppose to be updated. + /// @param data contextual data for windows flow control. + void updateWindow(const std::string &windowName, std::unique_ptr data); + /// Method sending switch command for another window. It will switch window within active application. /// To switch windows between applications use app::manager::Controller::switchApplication /// it will effectively trigger setActiveWindow and change on windows stack diff --git a/module-apps/messages/AppMessage.hpp b/module-apps/messages/AppMessage.hpp index b0ebc92d978a1ca8c69ad4b79f9ba63fb9846293..aa152d8e5567786c233468707a102f1e4e40b41a 100644 --- a/module-apps/messages/AppMessage.hpp +++ b/module-apps/messages/AppMessage.hpp @@ -153,6 +153,43 @@ namespace app }; }; + class AppUpdateWindowMessage : public AppMessage + { + private: + const std::string window; + const std::unique_ptr data; + const gui::ShowMode command; + const gui::RefreshModes refreshMode; + + public: + AppUpdateWindowMessage(const std::string &window, + std::unique_ptr data, + gui::ShowMode command = gui::ShowMode::GUI_SHOW_INIT, + gui::RefreshModes refreshMode = gui::RefreshModes::GUI_REFRESH_FAST) + : AppMessage(), window{window}, data{std::move(data)}, command{command}, refreshMode{refreshMode} + {} + + [[nodiscard]] auto getWindowName() const + { + return window; + } + + [[nodiscard]] const auto &getData() const noexcept + { + return data; + } + + [[nodiscard]] auto getCommand() const noexcept + { + return command; + } + + [[nodiscard]] auto getRefreshMode() const noexcept + { + return refreshMode; + } + }; + class AppInputEventMessage : public AppMessage { protected: diff --git a/module-gui/gui/widgets/Window.cpp b/module-gui/gui/widgets/Window.cpp index e8ef2743193e93c27e281bc21ca83c3f7b042b51..8e484f87820307e080aeeace5f6fdc612b82f8d1 100644 --- a/module-gui/gui/widgets/Window.cpp +++ b/module-gui/gui/widgets/Window.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md /* diff --git a/module-gui/gui/widgets/Window.hpp b/module-gui/gui/widgets/Window.hpp index 487ec37306f754c171e8ade88f4b7294f8a4a0a0..538ac8b05a456b11f5913e722db7deefac4bd5ad 100644 --- a/module-gui/gui/widgets/Window.hpp +++ b/module-gui/gui/widgets/Window.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once