~aleteoryx/muditaos

muditaos/module-gui/gui/SwitchData.hpp -rw-r--r-- 3.4 KiB
a405cad6Aleteoryx trim readme 6 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

#pragma once

#include <string>
#include <optional>
#include <log/log.hpp>

namespace gui
{
    using NameOfApplication = std::optional<std::string>;

    /// base class storing information sent along with switch message
    /// for extended use with windows please inherit from this class to extend it
    ///
    /// used combined with:
    /// * Application->switchWindow(...) function changing window within current application
    /// * Application::handleSwitchWindow(...) ApplicationManager call changing window between apps (and within current
    /// if requested)
    class SwitchData
    {
        bool popup = false;

      protected:
        std::string description = "";

      public:
        SwitchData() = default;
        explicit SwitchData(std::string description) : description{std::move(description)} {};

        virtual ~SwitchData() = default;

        [[nodiscard]] virtual const std::string &getDescription() const
        {
            return description;
        };
        virtual void setDescription(const std::string desc)
        {
            description = desc;
        };
        /// informs ApplicationManager to not close caller application when switching from app to app
        bool disableAppClose = false;
        /// informs App window stack that requested window should be ignored on windows stack.
        ///
        /// This affects window back mechanics. Having switchWindow calls like that:
        /// `WinA = { ignoreCurrentWindowOnStack = true } => WinB  => WinC`
        /// requesting getting back in WinC will result in:
        /// `WinC => WinA`
        bool ignoreCurrentWindowOnStack = false;
        /// This can store name of Application when message came from
        /// This is helpful when going back to the previous Application (sender Application)
        NameOfApplication nameOfSenderApplication = std::nullopt;
    };

    class SwitchSpecialChar : public SwitchData
    {
      public:
        std::string requester = "";
        enum class Type
        {
            Request,
            Response,
        } type = Type::Request;
        SwitchSpecialChar(Type type, const std::string requester, const std::string &description = "")
            : SwitchData(description), requester(requester), type(type)
        {}
        virtual ~SwitchSpecialChar() = default;
    };

    /// class storing information for Window type class to switch bask to proper Application
    struct InfoAboutPreviousAppWhereWeComeFrom
    {
        NameOfApplication nameOfPreviousApplication = std::nullopt;
        bool ignoreCurrentApplicationOnSwitchBack   = false;

        // save info about Application where we come from and if we should switch back to this Application
        void saveInfoAboutPreviousAppForProperSwitchBack(const SwitchData *memo)
        {
            if (memo == nullptr) {
                LOG_ERROR("Empty pointer to SwitchData");
                return;
            }
            nameOfPreviousApplication            = memo->nameOfSenderApplication;
            ignoreCurrentApplicationOnSwitchBack = memo->ignoreCurrentWindowOnStack;
        }
        bool shouldCurrentAppBeIgnoredOnSwitchBack()
        {
            return ignoreCurrentApplicationOnSwitchBack && nameOfPreviousApplication.has_value();
        }
    };

} /* namespace gui */