~aleteoryx/muditaos

ref: 95d96b82b63c85af4f655d10e52c5612121c23f6 muditaos/module-gui/gui/widgets/StatusBar.hpp -rw-r--r-- 8.3 KiB
95d96b82 — Pawel.Paprocki [BH-370] Convert utils common_data into a libs 4 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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <BoxLayout.hpp>

#include <PhoneModes/Common.hpp>

#include <vector>
#include <map>

namespace gui
{
    class Label;
    class Image;

    namespace status_bar
    {
        class SignalStrengthBase;
        class PhoneMode;
        class BatteryBase;
        class NetworkAccessTechnology;
        class SIM;
        class Time;
        class Lock;
    } // 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
        SimCard,                 /// sim card info
        NetworkAccessTechnology, /// NAT (eg 3G, 4G, LTE)
        PhoneMode,               /// phone mode
    };

    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 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;

        /// 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::SimCard, false},
                                               {Indicator::NetworkAccessTechnology, false}};

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

        /// 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 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();

        /// 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 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
        void 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
        void showBattery(bool enabled);

        /// Show/hide signal strenght widget
        /// @param enabled true to show false to hide the widget
        void 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);

        /// 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 sim card status
        SIM *sim = nullptr;

        /// Pointer to widget with battery status
        BatteryBase *battery = 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