MythTV master
mythnotificationcenter_private.h
Go to the documentation of this file.
1//
2// mythnotificationcenter_private.h
3// MythTV
4//
5// Created by Jean-Yves Avenard on 30/06/13.
6// Copyright (c) 2013 Bubblestuff Pty Ltd. All rights reserved.
7//
8
9#ifndef MythTV_mythnotificationcenter_private_h
10#define MythTV_mythnotificationcenter_private_h
11
12#include <QTimer>
13#include <QMutex>
14#include <QList>
15#include <QMap>
16
17#include <cstdint>
18
19#include "mythscreenstack.h"
20#include "mythscreentype.h"
21#include "mythuiimage.h"
22#include "mythuitext.h"
23#include "mythuiprogressbar.h"
25#include "mythuistatetype.h"
26
27// Forward declarations
30
31static constexpr int MIN_LIFE {1000};
32
33class NCPrivate : public QObject
34{
35 Q_OBJECT
36
37public slots:
38 void ScreenDeleted(void);
39
40public:
41 NCPrivate(void);
42 ~NCPrivate() override;
43
49 bool Queue(const MythNotification &notification);
50
55
65 int Register(void *from);
72 void UnRegister(void *from, int id, bool closeimemdiately = false);
73
74 /*
75 * OSD drawing utilities
76 */
77
82 QDateTime ScreenExpiryTime(const MythScreenType *screen);
87 bool ScreenCreated(const MythScreenType *screen);
93 void GetNotificationScreens(QList<MythScreenType*> &screens);
102 int DisplayedNotifications(void) const;
106 int QueuedNotifications(void) const;
111 bool RemoveFirst(void);
117 void ProcessQueue(void);
118
119 void ScreenStackDeleted(void);
120
121private:
122
124 int id = -1);
125 void DeleteAllRegistrations(void);
126 void DeleteAllScreens(void);
127 void DeleteUnregistered(void);
130 void RefreshScreenPosition(int from = 0);
131
134 QList<MythNotification*> m_notifications;
135 QList<MythNotificationScreen*> m_screens;
136 QList<MythNotificationScreen*> m_deletedScreens;
137 QMap<int, MythNotificationScreen*> m_registrations;
138 QList<int> m_suspended;
139 QMap<int,bool> m_unregistered;
140 QMap<int, void*> m_clients;
141 QMutex m_lock;
142 int m_currentId {0};
143 QMap<MythNotificationScreen*, MythNotificationScreen*> m_converted;
144};
145
147{
148 Q_OBJECT
149
150public:
152 int id = -1);
154 MythNotification &notification);
156 const MythNotificationScreen &screen);
157
158 ~MythNotificationScreen() override;
159
160 bool keyPressEvent(QKeyEvent *event) override; // MythScreenType
161
162 // These two methods are declared by MythScreenType and their signatures
163 // should not be changed
164 bool Create(void) override; // MythScreenType
165
166 void SetNotification(MythNotification &notification);
167
168 void UpdateArtwork(const QImage &image);
169 void UpdateArtwork(const QString &image);
170 void UpdateMetaData(const DMAP &data);
171 void UpdatePlayback(float progress, const QString &text);
172 void UpdateFrom(const MythNotificationScreen &s);
173
174 void SetSingleShotTimer(std::chrono::seconds s, bool update = false);
175 void SetErrorState(void) const;
176
177 // UI methods
178 void AdjustYPosition(void);
179 void AdjustIndex(int by, bool set=false);
180 void SetIndex(int index);
181 int GetHeight(void);
182
183 enum Content : uint8_t {
184 kNone = 0,
185 kImage = 1 << 0,
186 kDuration = 1 << 1,
187 kMetaData = 1 << 2,
188 kStyle = 1 << 3,
189 kNoArtwork = 1 << 4,
190 kAll = 0xFF,
191 };
192
193signals:
195
196public slots:
197 void ProcessTimer(void);
198
199protected:
200 void Init(void) override; // MythScreenType
201
202public:
203 int m_id;
204 QImage m_image;
205 QString m_imagePath;
206 QString m_title;
207 QString m_origin;
209 QString m_extra;
210 std::chrono::seconds m_duration {-1s};
211 float m_progress {-1.0F};
213 bool m_fullscreen {false};
214 bool m_added {false};
215 bool m_created {false};
216 std::underlying_type_t<Content> m_content {kNone};
217 std::underlying_type_t<Content> m_update {kAll};
218 MythNotification::Type m_type {MythNotification::kNew};
228 QDateTime m_creation;
229 QDateTime m_expiry;
230 int m_index {0};
232 QTimer *m_timer {nullptr};
233 QString m_style;
236 bool m_refresh {true};
237};
238
240
242{
243public:
244 MythNotificationScreenStack(MythMainWindow *parent, const QString& name,
245 NCPrivate *owner)
246 : MythScreenStack(parent, name), m_owner(owner)
247 {
248 }
249
251 {
253 }
254
256 {
257 for (auto * screen : std::as_const(m_toDelete))
258 {
259 screen->SetAlpha(0);
260 screen->SetVisible(false);
261 screen->Close();
262 }
264 }
265
266 static const int kFadeVal = 20;
267
268 void PopScreen(MythScreenType *screen, bool allowFade = true,
269 bool deleteScreen = true) override; // MythScreenStack
270 MythScreenType *GetTopScreen(void) const override; // MythScreenStack
271private:
272 NCPrivate *m_owner {nullptr};
273
274};
275
276#endif
void PopScreen(MythScreenType *screen, bool allowFade=true, bool deleteScreen=true) override
MythScreenType * GetTopScreen(void) const override
MythNotificationScreenStack(MythMainWindow *parent, const QString &name, NCPrivate *owner)
void UpdatePlayback(float progress, const QString &text)
Update playback position information.
void UpdateArtwork(const QImage &image)
Update artwork image.
MythNotificationScreen(MythScreenStack *stack, int id=-1)
std::underlying_type_t< Content > m_content
void UpdateFrom(const MythNotificationScreen &s)
Copy metadata from another notification.
void SetIndex(int index)
set index, without recalculating coordinates
void AdjustIndex(int by, bool set=false)
void SetSingleShotTimer(std::chrono::seconds s, bool update=false)
void SetNotification(MythNotification &notification)
std::underlying_type_t< Content > m_update
void UpdateMetaData(const DMAP &data)
Read some DMAP tag to extract title, artist, album and file format.
void AdjustYPosition(void)
Update Y position of the screen All children elements will be relocated.
MythNotification::Priority m_priority
void Init(void) override
Update the various fields of a MythNotificationScreen.
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
static const Type kNew
Wrapper around QPoint allowing us to handle percentage and other relative values for positioning in m...
Definition: mythrect.h:89
void CheckDeletes(bool force=false)
QVector< MythScreenType * > m_toDelete
Screen in which all other widgets are contained and rendered.
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:98
Progress bar widget.
This widget is used for grouping other widgets for display when a particular named state is called.
All purpose text widget, displays a text string.
Definition: mythuitext.h:29
int DisplayedNotifications(void) const
Returns number of notifications currently displayed.
QMap< int, bool > m_unregistered
void RefreshScreenPosition(int from=0)
Re-position screens on display.
QList< MythNotificationScreen * > m_deletedScreens
int InsertScreen(MythNotificationScreen *screen)
Insert screen into list of screens.
MythNotificationScreenStack * m_screenStack
int RemoveScreen(MythNotificationScreen *screen)
Remove screen from list of screens.
QMap< int, void * > m_clients
void DeleteUnregistered(void)
QMap< MythNotificationScreen *, MythNotificationScreen * > m_converted
void ScreenStackDeleted(void)
bool ScreenCreated(const MythScreenType *screen)
Return true if ::Create() has been called on screen.
bool Queue(const MythNotification &notification)
Queue a notification Queue() is thread-safe and can be called from anywhere.
bool RemoveFirst(void)
Will remove the oldest notification from the stack return true if a screen was removed; or false if n...
MythNotificationScreen * CreateScreen(MythNotification *notification, int id=-1)
CreateScreen will create a MythNotificationScreen instance.
void DeleteAllRegistrations(void)
void DeleteAllScreens(void)
void GetNotificationScreens(QList< MythScreenType * > &screens)
Return the list of notification screens being currently displayed.
void ScreenDeleted(void)
Remove screen from screens list.
void ProcessQueue(void)
ProcessQueue will be called by the GUI event handler and will process all queued MythNotifications an...
int QueuedNotifications(void) const
Returns number of notifications currently queued.
static MythNotificationCenter * GetInstance(void)
returns the MythNotificationCenter singleton
MythNotificationScreenStack * m_originalScreenStack
void UnRegister(void *from, int id, bool closeimemdiately=false)
Unregister the client.
QDateTime ScreenExpiryTime(const MythScreenType *screen)
Return when the given screen is going to expire will return an invalid QDateTime if screen isn't a My...
QMap< int, MythNotificationScreen * > m_registrations
int Register(void *from)
An application can register in which case it will be assigned a reusable screen, which can be modifie...
void UpdateScreen(MythScreenType *screen)
Will call ::doInit() if the screen is a MythNotificationScreen and ::Create() has been called for it ...
QList< MythNotificationScreen * > m_screens
QList< MythNotification * > m_notifications
unsigned int VNMask
QMap< QString, QString > DMAP
static constexpr int MIN_LIFE