~aleteoryx/muditaos

7897f863809a3fe98844c2a520249decffe069d9 — Adam Dobrowolski 4 years ago 183d1be
[EGD-8164] Multiple same popups can be stored

On initial code there was option to store only one popup of set
priority, now we can store multiple ones
M .gdbinit-1051 => .gdbinit-1051 +1 -0
@@ 1,6 1,7 @@
source .gdb_macros

set pagination off
set python print-stack full
target remote localhost:2331
source tools/gdb_crash_extend.py
source tools/misc/puregdb/puregdb.py

M module-apps/apps-common/ApplicationCommon.cpp => module-apps/apps-common/ApplicationCommon.cpp +3 -4
@@ 839,9 839,9 @@ namespace app
            data->setDisposition(gui::popup::Disposition{
                gui::popup::Disposition::Priority::Normal, gui::popup::Disposition::WindowType::Popup, id});
        }
        auto request = gui::popup::Request(id, std::move(data), *blueprint);
        windowsPopupQueue->pushRequest(std::move(request));
        tryShowPopup();
        windowsPopupQueue->pushRequest(gui::popup::Request(id, std::move(data), *blueprint));
        auto result = tryShowPopup();
        LOG_INFO("tryShowPopup %s status: %s", magic_enum::enum_name(id).data(), result ? "shown" : "ignored");
    }

    gui::popup::Filter &ApplicationCommon::getPopupFilter() const


@@ 860,7 860,6 @@ namespace app
            if (not retval) {
                LOG_ERROR("Popup %s handling failure, please check registered blueprint!", popup.c_str());
            }
            LOG_ERROR("no blueprint for popup: %s", popup.c_str());
            return retval;
        }
        return false;

M module-apps/apps-common/WindowsPopupQueue.cpp => module-apps/apps-common/WindowsPopupQueue.cpp +3 -4
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "WindowsPopupQueue.hpp"


@@ 16,9 16,8 @@ namespace app
        return {std::nullopt};
    }

    bool WindowsPopupQueue::pushRequest(gui::popup::Request &&r)
    void WindowsPopupQueue::pushRequest(gui::popup::Request &&r)
    {
        const auto &[_, success] = requests.emplace(std::move(r));
        return success;
        requests.emplace(std::move(r));
    }
} // namespace app

M module-apps/apps-common/WindowsPopupQueue.hpp => module-apps/apps-common/WindowsPopupQueue.hpp +3 -3
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once


@@ 31,7 31,7 @@ namespace app

        /// append element to stack
        /// returns success/fail
        bool pushRequest(gui::popup::Request &&r);
        void pushRequest(gui::popup::Request &&r);

      private:
        /// set of requests to handle if there are more than one


@@ 40,6 40,6 @@ namespace app
        /// this behaviour can be easily changed - just change:
        /// - gui::popup::Disposition class to hold more data
        /// - change comparison algorithm in Request (please use std::set then)
        std::set<gui::popup::Request> requests{};
        std::multiset<gui::popup::Request> requests{};
    };
} // namespace app

M module-apps/tests/windows/test-WindowsPopupQueue.cpp => module-apps/tests/windows/test-WindowsPopupQueue.cpp +24 -13
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "WindowsPopupFilter.hpp"


@@ 20,18 20,32 @@ TEST_CASE("WindowsPopupQueue push")
    using namespace gui::popup;
    auto wp = app::WindowsPopupQueue();
    Blueprint blueprint;
    Request request(gui::popup::ID::Alarm, std::make_unique<gui::PopupRequestParams>(gui::popup::ID::Alarm), blueprint);
    {
        auto r = wp.pushRequest(std::move(request));
        REQUIRE(r);
    }
    SECTION("single")
    {
        Request request(
            gui::popup::ID::Alarm, std::make_unique<gui::PopupRequestParams>(gui::popup::ID::Alarm), blueprint);
        wp.pushRequest(std::move(request));
        wp.popRequest(filter);
        auto r = wp.popRequest(filter);
        REQUIRE(r);
        REQUIRE(not r);
    }

    /// we should be able to have multiple same requests stored on the popups queue
    SECTION("multiple")
    {
        auto r = wp.popRequest(filter);
        REQUIRE(not r);
        const auto count = 3;
        auto request_gen = [blueprint]() {
            return Request(
                gui::popup::ID::Alarm, std::make_unique<gui::PopupRequestParams>(gui::popup::ID::Alarm), blueprint);
        };
        Request request[count] = {request_gen(), request_gen(), request_gen()};
        for (auto &val : request) {
            wp.pushRequest(std::move(val));
        }
        for (auto i = count; i != 0; --i) {
            auto r = wp.popRequest(filter);
            REQUIRE(r);
        }
    }
}



@@ 50,10 64,7 @@ TEST_CASE("WindowsPopupQueue filter")
    Blueprint blueprint;
    auto noneFilter = NoneFilter();
    Request request(gui::popup::ID::Alarm, std::make_unique<gui::PopupRequestParams>(gui::popup::ID::Alarm), blueprint);
    {
        auto r = wp.pushRequest(std::move(request));
        REQUIRE(r);
    }
    wp.pushRequest(std::move(request));
    {
        auto r = wp.popRequest(noneFilter);
        REQUIRE(not r);

M module-gui/gui/SwitchData.hpp => module-gui/gui/SwitchData.hpp +1 -6
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once


@@ 25,14 25,9 @@ namespace gui
      public:
        SwitchData() = default;
        explicit SwitchData(std::string description) : description{std::move(description)} {};
        explicit SwitchData(std::string description, bool popup) : popup(popup), description{std::move(description)} {};

        virtual ~SwitchData() = default;

        [[nodiscard]] bool isPopup() const
        {
            return popup;
        }
        [[nodiscard]] virtual const std::string &getDescription() const
        {
            return description;