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  virtual ~NCPrivate();
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:
152  int id = -1);
154  MythNotification &notification);
156  const MythNotificationScreen &screen);
157 
158  virtual ~MythNotificationScreen();
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);
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:
243  NCPrivate *owner)
244  : MythScreenStack(parent, name), m_owner(owner)
245  {
246  }
247 
249  {
251  }
252 
254  {
255  QVector<MythScreenType*>::const_iterator it;
256 
257  for (it = m_ToDelete.begin(); it != m_ToDelete.end(); ++it)
258  {
259  (*it)->SetAlpha(0);
260  (*it)->SetVisible(false);
261  (*it)->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
271 private:
272  NCPrivate *m_owner {nullptr};
273 
274 };
275 
276 #endif
This widget is used for grouping other widgets for display when a particular named state is called.
void AdjustIndex(int by, bool set=false)
void ScreenStackDeleted(void)
MythNotificationScreenStack(MythMainWindow *parent, const QString &name, NCPrivate *owner)
QVector< MythScreenType * > m_ToDelete
void UpdateScreen(MythScreenType *screen)
Will call ::doInit() if the screen is a MythNotificationScreen and ::Create() has been called for it ...
unsigned int slots[4]
Definition: element.c:38
MythNotificationScreen * CreateScreen(MythNotification *notification, int id=-1)
CreateScreen will create a MythNotificationScreen instance.
MythNotificationScreenStack * m_screenStack
MythNotification::Priority m_priority
void DeleteAllRegistrations(void)
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
void UpdateMetaData(const DMAP &data)
Read some DMAP tag to extract title, artist, album and file format.
All purpose text widget, displays a text string.
Definition: mythuitext.h:28
void DeleteUnregistered(void)
void ProcessQueue(void)
ProcessQueue will be called by the GUI event handler and will process all queued MythNotifications an...
bool ScreenCreated(const MythScreenType *screen)
Return true if ::Create() has been called on screen.
MythScreenType * GetTopScreen(void) const override
int Register(void *from)
An application can register in which case it will be assigned a reusable screen, which can be modifie...
void UpdateArtwork(const QImage &image)
Update artwork image.
unsigned int VNMask
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:97
Priority
Priority enum A notification can be given a priority.
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...
int DisplayedNotifications(void) const
Returns number of notifications currently displayed.
void RefreshScreenPosition(int from=0)
Re-position screens on display.
void SetSingleShotTimer(int s, bool update=false)
void AdjustYPosition(void)
Update Y position of the screen All children elements will be relocated.
bool Queue(const MythNotification &notification)
Queue a notification Queue() is thread-safe and can be called from anywhere.
void ScreenDeleted(void)
Remove screen from screens list.
void GetNotificationScreens(QList< MythScreenType * > &screens)
Return the list of notification screens being currently displayed.
void UnRegister(void *from, int id, bool closeimemdiately=false)
Unregister the client.
void DeleteAllScreens(void)
int InsertScreen(MythNotificationScreen *screen)
Insert screen into list of screens.
QMap< int, MythNotificationScreen * > m_registrations
static MythNotificationCenter * GetInstance(void)
returns the MythNotificationCenter singleton
MythNotificationScreenStack * m_originalScreenStack
void SetIndex(int index)
set index, without recalculating coordinates
void Init(void) override
Update the various fields of a MythNotificationScreen.
void CheckDeletes(bool force=false)
const char * name
Definition: ParseText.cpp:328
QList< MythNotificationScreen * > m_deletedScreens
void UpdateFrom(const MythNotificationScreen &s)
Copy metadata from another notification.
QMap< int, void * > m_clients
int RemoveScreen(MythNotificationScreen *screen)
Remove screen from list of screens.
QMap< int, bool > m_unregistered
void PopScreen(MythScreenType *screen, bool allowFade=true, bool deleteScreen=true) override
MythNotificationScreen(MythScreenStack *stack, int id=-1)
Wrapper around QPoint allowing us to handle percentage and other relative values for positioning in m...
Definition: mythrect.h:86
Screen in which all other widgets are contained and rendered.
Progress bar widget.
QList< MythNotificationScreen * > m_screens
QMap< MythNotificationScreen *, MythNotificationScreen * > m_converted
bool RemoveFirst(void)
Will remove the oldest notification from the stack return true if a screen was removed; or false if n...
void UpdatePlayback(float progress, const QString &text)
Update playback position information.
QList< MythNotification * > m_notifications
QMap< QString, QString > DMAP
void SetNotification(MythNotification &notification)
int QueuedNotifications(void) const
Returns number of notifications currently queued.