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"
24 #include "mythnotificationcenter.h"
25 #include "mythuistatetype.h"
26 
27 // Forward declarations
30 
31 #define MIN_LIFE 1000
32 
33 class NCPrivate : public QObject
34 {
35  Q_OBJECT
36 
37 public slots:
38  void ScreenDeleted(void);
39 
40 public:
41  NCPrivate(void);
42  ~NCPrivate() override;
43 
49  bool Queue(const MythNotification &notification);
50 
54  static MythNotificationCenter *GetInstance(void);
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);
98  void UpdateScreen(MythScreenType *screen);
102  int DisplayedNotifications(void) const;
106  int QueuedNotifications(void) const;
111  bool RemoveFirst(void);
117  void ProcessQueue(void);
118 
119  void ScreenStackDeleted(void);
120 
121 private:
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 
150 public:
151  explicit MythNotificationScreen(MythScreenStack *stack,
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  void Init(void) override; // MythScreenType
166 
167  void SetNotification(MythNotification &notification);
168 
169  void UpdateArtwork(const QImage &image);
170  void UpdateArtwork(const QString &image);
171  void UpdateMetaData(const DMAP &data);
172  void UpdatePlayback(float progress, const QString &text);
173  void UpdateFrom(const MythNotificationScreen &s);
174 
175  void SetSingleShotTimer(int s, bool update = false);
176  void SetErrorState(void) const;
177 
178  // UI methods
179  void AdjustYPosition(void);
180  void AdjustIndex(int by, bool set=false);
181  void SetIndex(int index);
182  int GetHeight(void);
183 
184  enum Content {
185  kNone = 0,
186  kImage = 1 << 0,
187  kDuration = 1 << 1,
188  kMetaData = 1 << 2,
189  kStyle = 1 << 3,
190  kNoArtwork = 1 << 4,
192  };
193 
194 signals:
195  void ScreenDeleted();
196 
197 public slots:
198  void ProcessTimer(void);
199 
200 public:
201  int m_id;
202  QImage m_image;
203  QString m_imagePath;
204  QString m_title;
205  QString m_origin;
206  QString m_description;
207  QString m_extra;
208  int m_duration {-1};
209  float m_progress {-1.0F};
210  QString m_progresstext;
211  bool m_fullscreen {false};
212  bool m_added {false};
213  bool m_created {false};
214  uint32_t m_content {kNone};
215  uint32_t m_update {(uint32_t)kAll};
216  MythNotification::Type m_type {MythNotification::New};
226  QDateTime m_creation;
227  QDateTime m_expiry;
228  int m_index {0};
230  QTimer *m_timer {nullptr};
231  QString m_style;
234  bool m_refresh {true};
235 };
236 
238 
240 {
241 public:
242  MythNotificationScreenStack(MythMainWindow *parent, const QString& name,
243  NCPrivate *owner)
244  : MythScreenStack(parent, name), m_owner(owner)
245  {
246  }
247 
249  {
251  }
252 
254  {
255  for (auto * screen : qAsConst(m_ToDelete))
256  {
257  screen->SetAlpha(0);
258  screen->SetVisible(false);
259  screen->Close();
260  }
262  }
263 
264  static const int kFadeVal = 20;
265 
266  void PopScreen(MythScreenType *screen, bool allowFade = true,
267  bool deleteScreen = true) override; // MythScreenStack
268  MythScreenType *GetTopScreen(void) const override; // MythScreenStack
269 private:
270  NCPrivate *m_owner {nullptr};
271 
272 };
273 
274 #endif
MythNotificationScreen::m_update
uint32_t m_update
Definition: mythnotificationcenter_private.h:215
MythNotificationScreen::UpdateFrom
void UpdateFrom(const MythNotificationScreen &s)
Copy metadata from another notification.
Definition: mythnotificationcenter.cpp:599
MythNotificationScreen::GetHeight
int GetHeight(void)
Definition: mythnotificationcenter.cpp:690
MythNotificationScreen::m_origin
QString m_origin
Definition: mythnotificationcenter_private.h:205
mythuitext.h
mythuiprogressbar.h
MythUIImage
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:97
NCPrivate::m_deletedScreens
QList< MythNotificationScreen * > m_deletedScreens
Definition: mythnotificationcenter_private.h:136
MythNotificationScreen::m_errorState
MythUIStateType * m_errorState
Definition: mythnotificationcenter_private.h:224
NCPrivate::ScreenStackDeleted
void ScreenStackDeleted(void)
Definition: mythnotificationcenter.cpp:860
MythNotificationScreen::m_expiry
QDateTime m_expiry
Definition: mythnotificationcenter_private.h:227
MythNotificationScreen::m_descriptionText
MythUIText * m_descriptionText
Definition: mythnotificationcenter_private.h:220
NCPrivate::RemoveFirst
bool RemoveFirst(void)
Will remove the oldest notification from the stack return true if a screen was removed; or false if n...
Definition: mythnotificationcenter.cpp:1286
NCPrivate::UpdateScreen
void UpdateScreen(MythScreenType *screen)
Will call ::doInit() if the screen is a MythNotificationScreen and ::Create() has been called for it ...
MythNotificationScreen::m_position
MythPoint m_position
Definition: mythnotificationcenter_private.h:229
NCPrivate::m_currentId
int m_currentId
Definition: mythnotificationcenter_private.h:142
NCPrivate::QueuedNotifications
int QueuedNotifications(void) const
Returns number of notifications currently queued.
Definition: mythnotificationcenter.cpp:1281
mythscreenstack.h
MythNotificationScreenStack::PopScreen
void PopScreen(MythScreenType *screen, bool allowFade=true, bool deleteScreen=true) override
Definition: mythnotificationcenter.cpp:43
NCPrivate::DeleteAllRegistrations
void DeleteAllRegistrations(void)
Definition: mythnotificationcenter.cpp:1058
progress
bool progress
Definition: mythtv/programs/mythcommflag/main.cpp:67
MythNotificationScreenStack::CheckDeletes
void CheckDeletes()
Definition: mythnotificationcenter_private.h:253
MythNotificationScreen::kDuration
@ kDuration
Definition: mythnotificationcenter_private.h:187
MythScreenStack
Definition: mythscreenstack.h:15
NCPrivate::Register
int Register(void *from)
An application can register in which case it will be assigned a reusable screen, which can be modifie...
Definition: mythnotificationcenter.cpp:1013
MythNotificationScreen::m_timer
QTimer * m_timer
Definition: mythnotificationcenter_private.h:230
MythNotification
Definition: mythnotification.h:26
MythNotificationScreen::m_added
bool m_added
Definition: mythnotificationcenter_private.h:212
slots
unsigned int slots[4]
Definition: element.cpp:38
NCPrivate::Queue
bool Queue(const MythNotification &notification)
Queue a notification Queue() is thread-safe and can be called from anywhere.
Definition: mythnotificationcenter.cpp:865
MythNotificationScreen::m_progresstext
QString m_progresstext
Definition: mythnotificationcenter_private.h:210
MythScreenStack::m_ToDelete
QVector< MythScreenType * > m_ToDelete
Definition: mythscreenstack.h:66
MythNotificationScreen::kImage
@ kImage
Definition: mythnotificationcenter_private.h:186
MythScreenType
Screen in which all other widgets are contained and rendered.
Definition: mythscreentype.h:44
mythuistatetype.h
MythNotificationScreen::SetNotification
void SetNotification(MythNotification &notification)
Definition: mythnotificationcenter.cpp:208
NCPrivate::DeleteUnregistered
void DeleteUnregistered(void)
Definition: mythnotificationcenter.cpp:1102
NCPrivate::m_screens
QList< MythNotificationScreen * > m_screens
Definition: mythnotificationcenter_private.h:135
MythNotificationScreen::m_extra
QString m_extra
Definition: mythnotificationcenter_private.h:207
NCPrivate::m_clients
QMap< int, void * > m_clients
Definition: mythnotificationcenter_private.h:140
mythuiimage.h
MythNotificationScreen::m_visibility
VNMask m_visibility
Definition: mythnotificationcenter_private.h:232
NCPrivate::m_converted
QMap< MythNotificationScreen *, MythNotificationScreen * > m_converted
Definition: mythnotificationcenter_private.h:143
NCPrivate::RefreshScreenPosition
void RefreshScreenPosition(int from=0)
Re-position screens on display.
Definition: mythnotificationcenter.cpp:1197
NCPrivate::m_lock
QMutex m_lock
Definition: mythnotificationcenter_private.h:141
MythNotificationScreen::m_title
QString m_title
Definition: mythnotificationcenter_private.h:204
NCPrivate
Definition: mythnotificationcenter_private.h:33
NCPrivate::NCPrivate
NCPrivate(void)
Definition: mythnotificationcenter.cpp:751
NCPrivate::m_screenStack
MythNotificationScreenStack * m_screenStack
Definition: mythnotificationcenter_private.h:133
MythNotificationScreen::m_fullscreen
bool m_fullscreen
Definition: mythnotificationcenter_private.h:211
MythScreenStack::CheckDeletes
void CheckDeletes(bool force=false)
Definition: mythscreenstack.cpp:294
MythNotificationScreenStack::MythNotificationScreenStack
MythNotificationScreenStack(MythMainWindow *parent, const QString &name, NCPrivate *owner)
Definition: mythnotificationcenter_private.h:242
MythNotificationScreen::m_type
MythNotification::Type m_type
Definition: mythnotificationcenter_private.h:216
MythNotificationScreen::m_index
int m_index
Definition: mythnotificationcenter_private.h:228
MythNotificationScreenStack::kFadeVal
static const int kFadeVal
Definition: mythnotificationcenter_private.h:264
MythNotificationScreen::kMetaData
@ kMetaData
Definition: mythnotificationcenter_private.h:188
NCPrivate::ProcessQueue
void ProcessQueue(void)
ProcessQueue will be called by the GUI event handler and will process all queued MythNotifications an...
Definition: mythnotificationcenter.cpp:909
NCPrivate::~NCPrivate
~NCPrivate() override
Definition: mythnotificationcenter.cpp:759
MythNotificationScreen::m_originText
MythUIText * m_originText
Definition: mythnotificationcenter_private.h:219
MythNotificationScreen::m_mediaState
MythUIStateType * m_mediaState
Definition: mythnotificationcenter_private.h:225
MythUIProgressBar
Progress bar widget.
Definition: mythuiprogressbar.h:12
MythNotificationScreen::~MythNotificationScreen
~MythNotificationScreen() override
Definition: mythnotificationcenter.cpp:198
VNMask
unsigned int VNMask
Definition: mythnotification.h:24
MythNotificationScreen
Definition: mythnotificationcenter_private.h:146
MythNotificationScreen::m_progresstextText
MythUIText * m_progresstextText
Definition: mythnotificationcenter_private.h:222
MythNotificationScreenStack::GetTopScreen
MythScreenType * GetTopScreen(void) const override
Definition: mythnotificationcenter.cpp:124
MythNotification::Priority
Priority
Priority enum A notification can be given a priority.
Definition: mythnotification.h:91
MythNotificationScreen::UpdatePlayback
void UpdatePlayback(float progress, const QString &text)
Update playback position information.
Definition: mythnotificationcenter.cpp:588
MythNotificationScreen::m_progress
float m_progress
Definition: mythnotificationcenter_private.h:209
NCPrivate::InsertScreen
int InsertScreen(MythNotificationScreen *screen)
Insert screen into list of screens.
Definition: mythnotificationcenter.cpp:1146
NCPrivate::GetInstance
static MythNotificationCenter * GetInstance(void)
returns the MythNotificationCenter singleton
MythNotificationScreen::kNoArtwork
@ kNoArtwork
Definition: mythnotificationcenter_private.h:190
MythNotificationScreen::m_id
int m_id
Definition: mythnotificationcenter_private.h:201
NCPrivate::RemoveScreen
int RemoveScreen(MythNotificationScreen *screen)
Remove screen from list of screens.
Definition: mythnotificationcenter.cpp:1175
MythNotificationScreen::MythNotificationScreen
MythNotificationScreen(MythScreenStack *stack, int id=-1)
Definition: mythnotificationcenter.cpp:155
NCPrivate::m_originalScreenStack
MythNotificationScreenStack * m_originalScreenStack
Definition: mythnotificationcenter_private.h:132
MythNotificationScreenStack::m_owner
NCPrivate * m_owner
Definition: mythnotificationcenter_private.h:270
MythNotificationScreen::kStyle
@ kStyle
Definition: mythnotificationcenter_private.h:189
NCPrivate::ScreenExpiryTime
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...
MythNotification::kDefault
@ kDefault
Definition: mythnotification.h:92
MythNotificationScreen::m_refresh
bool m_refresh
Definition: mythnotificationcenter_private.h:234
NCPrivate::UnRegister
void UnRegister(void *from, int id, bool closeimemdiately=false)
Unregister the client.
Definition: mythnotificationcenter.cpp:1027
MythNotificationScreen::AdjustYPosition
void AdjustYPosition(void)
Update Y position of the screen All children elements will be relocated.
Definition: mythnotificationcenter.cpp:652
NCPrivate::CreateScreen
MythNotificationScreen * CreateScreen(MythNotification *notification, int id=-1)
CreateScreen will create a MythNotificationScreen instance.
Definition: mythnotificationcenter.cpp:989
MythNotificationScreenStack
Definition: mythnotificationcenter_private.h:239
MythNotificationScreen::m_image
QImage m_image
Definition: mythnotificationcenter_private.h:202
MythNotificationScreen::m_duration
int m_duration
Definition: mythnotificationcenter_private.h:208
NCPrivate::DeleteAllScreens
void DeleteAllScreens(void)
Definition: mythnotificationcenter.cpp:1070
MythNotificationScreen::m_progressBar
MythUIProgressBar * m_progressBar
Definition: mythnotificationcenter_private.h:223
MythUIText
All purpose text widget, displays a text string.
Definition: mythuitext.h:28
NCPrivate::ScreenCreated
bool ScreenCreated(const MythScreenType *screen)
Return true if ::Create() has been called on screen.
MythNotificationScreen::m_style
QString m_style
Definition: mythnotificationcenter_private.h:231
NCPrivate::m_registrations
QMap< int, MythNotificationScreen * > m_registrations
Definition: mythnotificationcenter_private.h:137
MythNotificationScreen::m_priority
MythNotification::Priority m_priority
Definition: mythnotificationcenter_private.h:233
MythNotificationScreenStack::~MythNotificationScreenStack
~MythNotificationScreenStack() override
Definition: mythnotificationcenter_private.h:248
MythNotificationScreen::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: mythnotificationcenter.cpp:727
NCPrivate::m_suspended
QList< int > m_suspended
Definition: mythnotificationcenter_private.h:138
MythNotificationScreen::AdjustIndex
void AdjustIndex(int by, bool set=false)
Definition: mythnotificationcenter.cpp:665
MythNotificationScreen::m_extraText
MythUIText * m_extraText
Definition: mythnotificationcenter_private.h:221
MythNotificationScreen::m_description
QString m_description
Definition: mythnotificationcenter_private.h:206
MythNotificationScreen::SetIndex
void SetIndex(int index)
set index, without recalculating coordinates
Definition: mythnotificationcenter.cpp:681
MythNotificationScreen::m_content
uint32_t m_content
Definition: mythnotificationcenter_private.h:214
NCPrivate::GetNotificationScreens
void GetNotificationScreens(QList< MythScreenType * > &screens)
Return the list of notification screens being currently displayed.
Definition: mythnotificationcenter.cpp:1222
MythNotification::New
static Type New
Definition: mythnotification.h:30
NCPrivate::DisplayedNotifications
int DisplayedNotifications(void) const
Returns number of notifications currently displayed.
Definition: mythnotificationcenter.cpp:1276
MythNotificationScreen::ScreenDeleted
void ScreenDeleted()
MythNotificationScreen::kNone
@ kNone
Definition: mythnotificationcenter_private.h:185
MythNotificationScreen::UpdateMetaData
void UpdateMetaData(const DMAP &data)
Read some DMAP tag to extract title, artist, album and file format.
Definition: mythnotificationcenter.cpp:556
MythNotificationScreen::kAll
@ kAll
Definition: mythnotificationcenter_private.h:191
MythNotificationScreen::m_imagePath
QString m_imagePath
Definition: mythnotificationcenter_private.h:203
MythNotificationScreen::Init
void Init(void) override
Update the various fields of a MythNotificationScreen.
Definition: mythnotificationcenter.cpp:376
MythNotificationScreen::ProcessTimer
void ProcessTimer(void)
Definition: mythnotificationcenter.cpp:695
MythNotificationScreen::m_titleText
MythUIText * m_titleText
Definition: mythnotificationcenter_private.h:218
MythNotificationScreen::m_artworkImage
MythUIImage * m_artworkImage
Definition: mythnotificationcenter_private.h:217
MythNotificationScreen::SetErrorState
void SetErrorState(void) const
Definition: mythnotificationcenter.cpp:497
MythNotificationCenter
Definition: mythnotificationcenter.h:33
DMAP
QMap< QString, QString > DMAP
Definition: mythnotification.h:23
NCPrivate::ScreenDeleted
void ScreenDeleted(void)
Remove screen from screens list.
Definition: mythnotificationcenter.cpp:790
MythNotificationScreen::SetSingleShotTimer
void SetSingleShotTimer(int s, bool update=false)
Definition: mythnotificationcenter.cpp:703
NCPrivate::m_unregistered
QMap< int, bool > m_unregistered
Definition: mythnotificationcenter_private.h:139
MythNotificationScreen::UpdateArtwork
void UpdateArtwork(const QImage &image)
Update artwork image.
Definition: mythnotificationcenter.cpp:532
mythnotificationcenter.h
Content
Definition: content.h:33
MythNotification::kAll
@ kAll
Definition: mythnotification.h:108
MythMainWindow
Definition: mythmainwindow.h:32
MythUIStateType
This widget is used for grouping other widgets for display when a particular named state is called....
Definition: mythuistatetype.h:22
MythNotificationScreen::m_created
bool m_created
Definition: mythnotificationcenter_private.h:213
mythscreentype.h
NCPrivate::m_notifications
QList< MythNotification * > m_notifications
Definition: mythnotificationcenter_private.h:134
MythNotificationScreen::m_creation
QDateTime m_creation
Definition: mythnotificationcenter_private.h:226
MythNotificationScreen::Create
bool Create(void) override
Definition: mythnotificationcenter.cpp:302
MythPoint
Wrapper around QPoint allowing us to handle percentage and other relative values for positioning in m...
Definition: mythrect.h:85