~aleteoryx/muditaos

muditaos/module-gui/gui/widgets/StatusBar.hpp -rw-r--r-- 11.3 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
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
// 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 <BoxLayout.hpp>

#include <PhoneModes/Common.hpp>
#include <service-bluetooth/Constants.hpp>
#include "status-bar/AlarmClock.hpp"

#include <vector>
#include <map>

namespace gui
{
    class Label;
    class Image;

    namespace status_bar
    {
        class SignalStrengthBase;
        class PhoneMode;
        class BatteryBase;
        class NetworkAccessTechnology;
        class BT;
        class SIM;
        class Time;
        class Lock;
        class Tethering;
    } // namespace status_bar
} // namespace gui

class UTF8;

class StatusBarVisitor;

namespace gui::status_bar
{

    enum class Indicator
    {
        Signal,                  /// signal strenght
        Time,                    /// digital clock
        Lock,                    /// is phone locked
        Battery,                 /// battery status
        Bluetooth,               /// bluetooth status
        SimCard,                 /// sim card info
        NetworkAccessTechnology, /// NAT (eg 3G, 4G, LTE)
        PhoneMode,               /// phone mode
        AlarmClock,              /// alarm clock active
        Tethering,               /// tethering status
    };

    using Indicators          = std::vector<Indicator>;
    using IndicatorStatuses   = std::map<Indicator, bool>;
    using IndicatorsModifiers = std::map<Indicator, std::shared_ptr<StatusBarVisitor>>;

    /// Carries the status bar configuration.
    class Configuration
    {
      public:
        /// Enable specified indicator
        /// @param indicator indicator type to be enabled
        void enable(Indicator indicator);

        /// Enable number of specified indicators
        /// @param indicators vector of indicators to enable
        void enable(const Indicators &indicators);

        /// Disable specified indicator
        /// @param indicator indicator type to disable
        void disable(Indicator indicator);

        /// Set the state of specified indicator
        /// @param indicator indicator type to set state
        /// @param enabled desired status to be set (true=enabled, false=disabled)
        void setIndicator(Indicator indicator, bool enabled);

        /// Set phone mode (connected/dnd/offline)
        /// @param phoneMode desired phone mode configuration
        void setPhoneMode(sys::phone_modes::PhoneMode phoneMode);

        /// Set bluetooth mode
        /// @param bluetoothMode desired bluetooth mode configuration
        void setBluetoothMode(sys::bluetooth::BluetoothMode bluetoothMode);

        /// Set alarm clock status
        /// @param alarmClockStatus desired alarm clock status
        void setAlarmClockStatus(bool alarmClockStatus);

        /// Set tethering state
        /// @param tetheringState desired tethering state
        void setTetheringState(sys::phone_modes::Tethering tetheringState);

        /// Set a configuration modifier to the specified indicator
        /// @param indicator indicator type
        /// @param config desired indicator's configuration
        void setIndicatorModifier(Indicator indicator, std::shared_ptr<StatusBarVisitor> config);

        /// Get the phone mode configuration
        /// @return phone mode
        [[nodiscard]] auto getPhoneMode() const noexcept -> sys::phone_modes::PhoneMode;

        /// Get the bluetooth mode configuration
        /// @return bluetooth mode
        [[nodiscard]] auto getBluetoothMode() const noexcept -> sys::bluetooth::BluetoothMode;

        /// Get the Alarm Clock status configuration
        /// @return alarm clock status
        [[nodiscard]] auto getAlarmClockStatus() const noexcept -> bool;

        /// Get the tethering state configuration
        /// @return tethering state
        [[nodiscard]] auto getTetheringState() const noexcept -> sys::phone_modes::Tethering;

        /// Check if the specified indicator is enabled
        /// @param indicator indicator to be checked
        /// @return indicator status
        [[nodiscard]] auto isEnabled(Indicator indicator) const -> bool;

        /// Return the indicator statuses
        /// @return indicator statuses
        [[nodiscard]] auto getIndicatorsConfiguration() const noexcept -> const IndicatorStatuses &;

        /// Return the indicator modifiers
        /// @return indicator modifiers
        [[nodiscard]] auto getIndicatorsModifiers() const noexcept -> const IndicatorsModifiers &;

      private:
        /// Current indicator statuses
        IndicatorStatuses indicatorStatuses = {
            {Indicator::Signal, false},
            {Indicator::PhoneMode, false},
            {Indicator::Time, false},
            {Indicator::Lock, false},
            {Indicator::Battery, false},
            {Indicator::Bluetooth, false},
            {Indicator::SimCard, false},
            {Indicator::NetworkAccessTechnology, false},
            {Indicator::AlarmClock, false},
            {Indicator::Tethering, false},
        };

        /// Phone mode
        sys::phone_modes::PhoneMode mPhoneMode = sys::phone_modes::PhoneMode::Uninitialized;

        /// Bluetooth mode
        sys::bluetooth::BluetoothMode mBluetoothMode = sys::bluetooth::BluetoothMode::Disabled;

        /// Alarm Clock status
        bool mAlarmClockStatus = false;

        /// Tethering state
        sys::phone_modes::Tethering mTetheringState = sys::phone_modes::Tethering::Off;

        /// Indicator modifiers:
        IndicatorsModifiers indicatorsModifiers;
    };

    /// Status bar widget class.
    /// This is horizontal box with three sections
    /// * left showing signal strenght, NAT info, and/or phone mode
    /// * center showing lock info or digital clock
    /// * right showing sim card and battery status
    class StatusBar : public HBox
    {
      public:
        /// Constructor
        /// @param parent parent item pointer
        /// @param x widget x position
        /// @param y widget y position
        /// @param w widget width
        /// @param h widget height
        StatusBar(Item *parent, uint32_t x, uint32_t y, uint32_t w, uint32_t h);

        /// Set the configuration basing on the specialized gui::top_bar::Configuration class
        /// @param configuration desired configuration
        void configure(Configuration &&config);

        /// Returns the current configuration
        /// @return configuration stored in Configuration class
        [[nodiscard]] auto getConfiguration() const noexcept -> const Configuration &;

        /// Update bluetooth status widget state depending on the current configuration
        bool updateBluetooth(sys::bluetooth::BluetoothMode mode);

        /// Update alarm clock status widget state depending on the current configuration
        bool updateAlarmClock(bool status);

        /// Update sim card status widget state depending on the current configuration
        bool updateSim();

        /// Update clock widget state depending on the current configuration
        bool updateTime();

        /// Update battery status widget state depending on the current configuration
        bool updateBattery();

        /// Update signal widget state depending on the current configuration
        bool updateSignalStrength();

        /// Update phone mode widget state depending on the current configuration
        bool updatePhoneMode();

        /// Update NAT widget state depending on the current configuration
        bool updateNetworkAccessTechnology();

        /// Update tethering widget state depending on the current configuration
        bool updateTetheringState(sys::phone_modes::Tethering state);

        /// Accepts GuiVisitor to update the status bar
        void accept(GuiVisitor &visitor) override;

      protected:
        /// Set up and add all the widgets to the status bar
        void prepareWidget();

        /// Show/hide bluetooth status widget
        /// @param enabled true to show false to hide the widget
        void showBluetooth(bool enabled);

        /// Show/hide alarm clock status widget
        /// @param enabled true to show false to hide the widget
        void showAlarmClock(bool enabled);

        /// Show/hide sim card status widget
        /// @param enabled true to show false to hide the widget
        void showSim(bool enabled);

        /// Show/hide clock widget
        /// @param enabled true to show false to hide the widget
        bool showTime(bool enabled);

        /// Show/hide lock status widget
        /// @param enabled true to show false to hide the widget
        void showLock(bool enabled);

        /// Show/hide battery status widget
        /// @param enabled true to show false to hide the widget
        /// @return true if screen refresh is required, false if not required
        bool showBattery(bool enabled);

        /// Show/hide signal strenght widget
        /// @param enabled true to show false to hide the widget
        /// @return true if screen refresh is required, false if not required
        bool showSignalStrength(bool enabled);

        /// Show/hide phone mode widget
        /// @param enabled true to show false to hide the widget
        void showPhoneMode(bool enabled);

        /// Show/hide NAT widget
        /// @param enabled true to show false to hide the widget
        void showNetworkAccessTechnology(bool enabled);

        /// Show/hide tethering state widget
        /// @param enabled true to show false to hide the widget
        void showTethering(bool enabled);

        /// Show/hide phone mode or tethering widget
        void showPhoneModeOrTethering(bool signalEnabled, bool phoneModeEnabled, bool tetheringEnabled);

        /// Sets the status of the specified indicator on the Status bar
        /// @param indicator indicator id
        /// @param enabled enable or disable the specified indicator
        void setIndicatorStatus(Indicator indicator, bool enabled);

        /// Applies a modifier to specified indicator
        /// @param indicator indicator id
        /// @param modifier pointer to modifier
        void setIndicatorModifier(Indicator indicator, StatusBarVisitor &modifier);

        /// Pointer to widget showing digital clock
        Time *time = nullptr;

        /// Pointer to widget showing NAT (eg 3G, 4G, LTE)
        NetworkAccessTechnology *networkAccessTechnology = nullptr;

        /// Pointer to widget showing current signal strenght
        SignalStrengthBase *signal = nullptr;

        /// Pointer to widget with current phone mode
        PhoneMode *phoneMode = nullptr;

        /// Pointer to widget showing lock status
        Lock *lock = nullptr;

        /// Pointer to widget with bluetooth status
        BT *bluetooth = nullptr;

        /// Pointer to widget with alarm clock status
        AlarmClock *alarmClock = nullptr;

        /// Pointer to widget with sim card status
        SIM *sim = nullptr;

        /// Pointer to widget with battery status
        BatteryBase *battery = nullptr;

        /// Pointer to widget with tethering state
        Tethering *tethering = nullptr;

        /// Pointer to the left horizontal box
        HBox *leftBox = nullptr;

        /// Pointer to the central horizontal box
        HBox *centralBox = nullptr;

        /// Pointer to the right horizontal box
        HBox *rightBox = nullptr;

        /// Current configuration of the Statusbar
        Configuration configuration;
    };

} // namespace gui::status_bar