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(std::chrono::seconds 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  std::chrono::seconds m_duration {-1s};
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::kNew};
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 : std::as_const(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:598
MythNotificationScreen::GetHeight
int GetHeight(void)
Definition: mythnotificationcenter.cpp:688
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:858
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:1284
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
progress
bool progress
Definition: mythcommflag.cpp:69
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:1279
mythscreenstack.h
MythNotificationScreenStack::PopScreen
void PopScreen(MythScreenType *screen, bool allowFade=true, bool deleteScreen=true) override
Definition: mythnotificationcenter.cpp:42
NCPrivate::DeleteAllRegistrations
void DeleteAllRegistrations(void)
Definition: mythnotificationcenter.cpp:1056
MythNotificationScreenStack::CheckDeletes
void CheckDeletes()
Definition: mythnotificationcenter_private.h:253
MythNotificationScreen::kDuration
@ kDuration
Definition: mythnotificationcenter_private.h:187
MythScreenStack
Definition: mythscreenstack.h:16
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:1011
MythNotificationScreen::m_timer
QTimer * m_timer
Definition: mythnotificationcenter_private.h:230
MythNotification
Definition: mythnotification.h:29
MythNotificationScreen::m_added
bool m_added
Definition: mythnotificationcenter_private.h:212
NCPrivate::Queue
bool Queue(const MythNotification &notification)
Queue a notification Queue() is thread-safe and can be called from anywhere.
Definition: mythnotificationcenter.cpp:863
MythNotificationScreen::m_progresstext
QString m_progresstext
Definition: mythnotificationcenter_private.h:210
MythNotificationScreen::kImage
@ kImage
Definition: mythnotificationcenter_private.h:186
MythScreenType
Screen in which all other widgets are contained and rendered.
Definition: mythscreentype.h:45
mythuistatetype.h
MythNotificationScreen::SetNotification
void SetNotification(MythNotification &notification)
Definition: mythnotificationcenter.cpp:207
NCPrivate::DeleteUnregistered
void DeleteUnregistered(void)
Definition: mythnotificationcenter.cpp:1100
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:1195
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:749
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:297
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:907
MythNotificationScreen::m_duration
std::chrono::seconds m_duration
Definition: mythnotificationcenter_private.h:208
NCPrivate::~NCPrivate
~NCPrivate() override
Definition: mythnotificationcenter.cpp:757
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:197
VNMask
unsigned int VNMask
Definition: mythnotification.h:27
MythNotificationScreen
Definition: mythnotificationcenter_private.h:146
MythNotification::kNew
static const Type kNew
Definition: mythnotification.h:32
MythNotificationScreen::m_progresstextText
MythUIText * m_progresstextText
Definition: mythnotificationcenter_private.h:222
MythNotificationScreenStack::GetTopScreen
MythScreenType * GetTopScreen(void) const override
Definition: mythnotificationcenter.cpp:123
MythNotification::Priority
Priority
Definition: mythnotification.h:58
MythNotificationScreen::UpdatePlayback
void UpdatePlayback(float progress, const QString &text)
Update playback position information.
Definition: mythnotificationcenter.cpp:587
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:1144
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:1173
MythNotificationScreen::MythNotificationScreen
MythNotificationScreen(MythScreenStack *stack, int id=-1)
Definition: mythnotificationcenter.cpp:154
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:60
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:1025
MythNotificationScreen::AdjustYPosition
void AdjustYPosition(void)
Update Y position of the screen All children elements will be relocated.
Definition: mythnotificationcenter.cpp:650
NCPrivate::CreateScreen
MythNotificationScreen * CreateScreen(MythNotification *notification, int id=-1)
CreateScreen will create a MythNotificationScreen instance.
Definition: mythnotificationcenter.cpp:987
MythNotificationScreenStack
Definition: mythnotificationcenter_private.h:239
MythNotificationScreen::m_image
QImage m_image
Definition: mythnotificationcenter_private.h:202
NCPrivate::DeleteAllScreens
void DeleteAllScreens(void)
Definition: mythnotificationcenter.cpp:1068
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
MythScreenStack::m_toDelete
QVector< MythScreenType * > m_toDelete
Definition: mythscreenstack.h:67
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:725
NCPrivate::m_suspended
QList< int > m_suspended
Definition: mythnotificationcenter_private.h:138
MythNotificationScreen::AdjustIndex
void AdjustIndex(int by, bool set=false)
Definition: mythnotificationcenter.cpp:663
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:679
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:1220
NCPrivate::DisplayedNotifications
int DisplayedNotifications(void) const
Returns number of notifications currently displayed.
Definition: mythnotificationcenter.cpp:1274
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:555
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:375
MythNotificationScreen::ProcessTimer
void ProcessTimer(void)
Definition: mythnotificationcenter.cpp:693
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:496
MythNotificationCenter
Definition: mythnotificationcenter.h:40
DMAP
QMap< QString, QString > DMAP
Definition: mythnotification.h:26
NCPrivate::ScreenDeleted
void ScreenDeleted(void)
Remove screen from screens list.
Definition: mythnotificationcenter.cpp:788
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:531
mythnotificationcenter.h
Content
Definition: content.h:36
MythNotification::kAll
@ kAll
Definition: mythnotification.h:77
MythNotificationScreen::SetSingleShotTimer
void SetSingleShotTimer(std::chrono::seconds s, bool update=false)
Definition: mythnotificationcenter.cpp:701
MythMainWindow
Definition: mythmainwindow.h:28
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:301
MythPoint
Wrapper around QPoint allowing us to handle percentage and other relative values for positioning in m...
Definition: mythrect.h:88