M module-apps/Application.cpp => module-apps/Application.cpp +27 -0
@@ 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<gui::SwitchData> data)
+ {
+ const auto currentWindow = getCurrentWindow();
+ auto msg =
+ std::make_shared<AppUpdateWindowMessage>(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<gui::SwitchData> data)
@@ 429,6 440,22 @@ namespace app
return msgHandled();
}
+ sys::MessagePointer Application::handleUpdateWindow(sys::Message *msgl)
+ {
+ auto msg = static_cast<AppUpdateWindowMessage *>(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);
M module-apps/Application.hpp => module-apps/Application.hpp +7 -0
@@ 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<gui::SwitchData> 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
M module-apps/messages/AppMessage.hpp => module-apps/messages/AppMessage.hpp +37 -0
@@ 153,6 153,43 @@ namespace app
};
};
+ class AppUpdateWindowMessage : public AppMessage
+ {
+ private:
+ const std::string window;
+ const std::unique_ptr<gui::SwitchData> data;
+ const gui::ShowMode command;
+ const gui::RefreshModes refreshMode;
+
+ public:
+ AppUpdateWindowMessage(const std::string &window,
+ std::unique_ptr<gui::SwitchData> 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:
M module-gui/gui/widgets/Window.cpp => module-gui/gui/widgets/Window.cpp +1 -1
@@ 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
/*
M module-gui/gui/widgets/Window.hpp => module-gui/gui/widgets/Window.hpp +1 -1
@@ 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