~aleteoryx/muditaos

ref: c34a85f49470b224954fbb89342e1df79e6e5362 muditaos/module-apps/apps-common/messages/AppMessage.hpp -rw-r--r-- 7.6 KiB
c34a85f4 — Lefucjusz [MOS-1037] Fix disappearing 'Call' label in phonebook 2 years 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "Common.hpp"
#include "popups/Disposition.hpp"
#include "SwitchData.hpp"
#include "gui/input/InputEvent.hpp"
#include "BaseAppMessage.hpp"
#include "AppSwitchReason.hpp"
#include "AppStartupReason.hpp"
#include <memory>
#include <string>
#include <service-appmgr/Actions.hpp>
#include <utility>

namespace app
{

    class AppActionRequest : public AppMessage
    {
      public:
        AppActionRequest(manager::actions::ActionId _actionId, manager::actions::ActionParamsPtr _data)
            : AppMessage(MessageType::AppAction), actionId{_actionId}, data{std::move(_data)}
        {}

        manager::actions::ActionId getAction() const noexcept
        {
            return actionId;
        }

        manager::actions::ActionParamsPtr &getData() noexcept
        {
            return data;
        }

      private:
        manager::actions::ActionId actionId;
        manager::actions::ActionParamsPtr data;
    };

    class ActionHandledResponse : public sys::ResponseMessage
    {
      public:
        explicit ActionHandledResponse(sys::ReturnCodes retCode = sys::ReturnCodes::Success)
            : sys::ResponseMessage{retCode, MessageType::AppAction}
        {}
    };

    // this message is used to notify application about switching event. Application will gain or lose focus upon
    // receiving this message. Application gains focus when it was in init or active background state. Application loose
    // focus when it was in active foreground state. if no window is specified it is assumed that MainWindow is the
    // target
    class AppSwitchMessage : public AppMessage
    {
      private:
        // name of the application to which switch is performed.
        std::string targetApplication;
        // name of the window to which switch should be performed.
        std::string targetWindow;
        // optional data for the target window.
        std::unique_ptr<gui::SwitchData> data;
        StartupReason startupReason = StartupReason::Launch;

      public:
        AppSwitchMessage(const std::string &targetApplication,
                         const std::string &targetWindow,
                         std::unique_ptr<gui::SwitchData> data,
                         StartupReason startupReason)
            : AppMessage(MessageType::AppSwitch), targetApplication{targetApplication},
              targetWindow{targetWindow}, data{std::move(data)}, startupReason{startupReason} {};
        virtual ~AppSwitchMessage(){};

        [[nodiscard]] std::string getTargetWindowName() const noexcept
        {
            return targetWindow;
        };

        [[nodiscard]] std::unique_ptr<gui::SwitchData> &getData()
        {
            return data;
        };

        [[nodiscard]] std::string getTargetApplicationName() const noexcept
        {
            return targetApplication;
        };

        [[nodiscard]] StartupReason getApplicationStartupReason() const noexcept
        {
            return startupReason;
        };
    };

    class AppRefreshMessage : public AppMessage
    {
      protected:
        gui::RefreshModes mode;
        std::string window_name;

      public:
        AppRefreshMessage(gui::RefreshModes mode, std::string window_name)
            : mode{mode}, window_name(std::move(window_name)){};

        [[nodiscard]] const gui::RefreshModes &getMode() const
        {
            return mode;
        }

        [[nodiscard]] const std::string &getWindowName() const
        {
            return window_name;
        }
    };

    class AppSwitchWindowMessage : public AppMessage
    {
      protected:
        std::string window;
        std::string senderWindow;
        gui::ShowMode command;
        SwitchReason reason;
        std::unique_ptr<gui::SwitchData> data;

      public:
        AppSwitchWindowMessage() = delete;

        AppSwitchWindowMessage(const std::string &window,
                               const std::string senderWindow,
                               std::unique_ptr<gui::SwitchData> data,
                               gui::ShowMode command = gui::ShowMode::GUI_SHOW_INIT,
                               SwitchReason reason   = SwitchReason::SwitchRequest)
            : AppMessage(MessageType::AppSwitchWindow), window{window},
              senderWindow{senderWindow}, command{command}, reason{reason}, data{std::move(data)} {};

        virtual ~AppSwitchWindowMessage() = default;

        [[nodiscard]] virtual bool toPopupRequest() const
        {
            return false;
        }

        const std::string &getWindowName() const
        {
            return window;
        };
        const std::string &getSenderWindowName() const
        {
            return senderWindow;
        };
        const gui::ShowMode &getCommand() const
        {
            return command;
        };
        [[nodiscard]] SwitchReason getReason() const noexcept
        {
            return reason;
        }
        std::unique_ptr<gui::SwitchData> &getData()
        {
            return data;
        };

        virtual std::pair<const std::string &, gui::popup::Disposition> getSwitchData()
        {
            return {window, gui::popup::WindowDisposition};
        }
    };

    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:
        gui::InputEvent event;

      public:
        explicit AppInputEventMessage(gui::InputEvent evt) : AppMessage(MessageType::AppInputEvent), event{evt}
        {}

        const gui::InputEvent &getEvent()
        {
            return event;
        };

        operator std::string() const override
        {
            const auto &rawKey = event.getRawKey();
            std::stringstream ss;
            ss << "{ ";
            ss << "state:   " << c_str(event.getState()) << ", ";
            ss << "RawKey:  " << c_str(rawKey.keyCode) << "}";
            ss << "t0: " << rawKey.timePress << ", t1: " << rawKey.timeRelease;
            ss << " }";
            return ss.str().c_str();
        }
    };

    class AppRebuildMessage : public AppMessage
    {
      public:
        AppRebuildMessage() : AppMessage(MessageType::AppRebuild){};
        virtual ~AppRebuildMessage(){};
    };

    class AppLostFocusMessage : public AppMessage
    {
      public:
        AppLostFocusMessage() : AppMessage{MessageType::AppFocusLost}
        {}
    };

    class AppSwitchBackMessage : public AppMessage
    {
      public:
        AppSwitchBackMessage() : AppMessage(MessageType::AppSwitchBack)
        {}
    };
} // namespace app