MythTV  master
mythnotification.h
Go to the documentation of this file.
1 //
2 // mythnotification.h
3 // MythTV
4 //
5 // Created by Jean-Yves Avenard on 25/06/13.
6 // Copyright (c) 2013 Bubblestuff Pty Ltd. All rights reserved.
7 //
8 
9 #ifndef __MythTV__mythnotification__
10 #define __MythTV__mythnotification__
11 
12 #include <QMutex>
13 #include <QMap>
14 #include <QImage>
15 
16 #include "mythevent.h"
17 #include "mythuiexp.h"
18 
19 typedef QMap<QString,QString> DMAP;
20 typedef unsigned int VNMask;
21 
23 {
24  public:
25 
26  static Type New;
27  static Type Update;
28  static Type Info;
29  static Type Error;
30  static Type Warning;
31  static Type Check;
32  static Type Busy;
33 
34  MythNotification(Type type, void *parent = nullptr)
35  : MythEvent(type, "NOTIFICATION"), m_id(-1),
36  m_parent(parent), m_fullScreen(false),
37  m_duration(0), m_visibility(kAll), m_priority(kDefault)
38  {
39  }
40 
41  MythNotification(int id, void *parent)
42  : MythEvent(Update, "NOTIFICATION"), m_id(id),
43  m_parent(parent), m_fullScreen(false),
44  m_duration(0), m_visibility(kAll), m_priority(kDefault)
45  {
46  }
47 
48  MythNotification(const QString &title, const QString &author,
49  const QString &details = QString())
50  : MythEvent(New, "NOTIFICATION"), m_id(-1),
51  m_parent(nullptr), m_fullScreen(false),
52  m_description(title), m_duration(0), m_visibility(kAll),
53  m_priority(kDefault)
54  {
55  DMAP map;
56  map["minm"] = title;
57  map["asar"] = author;
58  map["asal"] = details;
59  m_metadata = map;
60  ToStringList();
61  }
62 
63  MythNotification(Type type, const QString &title, const QString &author,
64  const QString &details = QString(),
65  const QString &extra = QString())
66  : MythEvent(type, "NOTIFICATION"), m_id(-1), m_parent(nullptr),
67  m_fullScreen(false), m_description(title), m_duration(0),
68  m_visibility(kAll), m_priority(kDefault)
69  {
70  DMAP map;
71  map["minm"] = title;
72  map["asar"] = author;
73  map["asal"] = details;
74  map["asfm"] = extra;
75  m_metadata = map;
76  ToStringList();
77  }
78 
79  MythNotification(Type type, const DMAP &metadata)
80  : MythEvent(type, "NOTIFICATION"), m_id(-1), m_parent(nullptr),
81  m_fullScreen(false), m_duration(0), m_metadata(metadata),
82  m_visibility(kAll), m_priority(kDefault)
83  {
84  ToStringList();
85  }
86 
87  explicit MythNotification(const MythEvent &me)
88  : MythEvent(me), m_id(-1), m_parent(nullptr)
89  {
90  FromStringList();
91  }
92 
94  {
95  }
96 
97  MythEvent *clone(void) const override // MythEvent
98  { return new MythNotification(*this); }
99 
104  enum Priority {
105  kDefault = 0,
111  };
112 
119  enum Visibility {
120  kNone = 0,
121  kAll = ~0,
122  kPlayback = (1 << 0),
123  kSettings = (1 << 1),
124  kWizard = (1 << 2),
125  kVideos = (1 << 3),
126  kMusic = (1 << 4),
127  kRecordings = (1 << 5),
128  };
129 
130  // Setter
138  void SetId(int id);
145  void SetParent(void *parent) { m_parent = parent; }
151  void SetFullScreen(bool f) { m_fullScreen = f; ToStringList(); }
155  void SetDescription(const QString &desc)
156  { m_description = desc; ToStringList(); }
162  void SetMetaData(const DMAP &data) { m_metadata = data; ToStringList(); }
169  void SetDuration(int duration) { m_duration = duration; ToStringList(); }
175  void SetStyle(const QString &style) { m_style = style; ToStringList(); }
179  void SetVisibility(VNMask n) { m_visibility = n; ToStringList(); }
183  void SetPriority(Priority n) { m_priority = n; ToStringList(); }
184 
188  static Type TypeFromString(const QString &type);
189 
190  void ToStringList(void);
191  bool FromStringList(void);
192 
193  // Getter
194  int GetId(void) const { return m_id; }
195  void *GetParent(void) const { return m_parent; }
196  bool GetFullScreen(void) const { return m_fullScreen; }
197  QString GetDescription(void) const { return m_description; }
198  DMAP GetMetaData(void) const { return m_metadata; }
199  int GetDuration(void) const { return m_duration; };
200  QString GetStyle(void) const { return m_style; }
201  VNMask GetVisibility(void) const { return m_visibility; }
202  Priority GetPriority(void) const { return m_priority; }
203 
204  protected:
206  : MythEvent(o),
207  m_id(o.m_id), m_parent(o.m_parent), m_fullScreen(o.m_fullScreen),
208  m_description(o.m_description),
209  m_duration(o.m_duration), m_metadata(o.m_metadata),
210  m_style(o.m_style),
211  m_visibility(o.m_visibility), m_priority(o.m_priority)
212  {
213  ToStringList();
214  }
215 
216 #ifndef _MSC_VER
217  MythNotification &operator=(const MythNotification&);
218 #endif
219 
220  protected:
221  int m_id;
222  void *m_parent;
224  QString m_description;
227  QString m_style;
230 };
231 
233 {
234  public:
235  MythImageNotification(Type type, const QImage &image)
236  : MythNotification(type), m_image(image)
237  {
238  }
239 
240  MythImageNotification(Type type, const QString &imagePath)
241  : MythNotification(type), m_imagePath(imagePath)
242  {
243  }
244 
245  MythImageNotification(Type type, const QImage &image, const DMAP &metadata)
246  : MythNotification(type, metadata), m_image(image)
247  {
248  }
249 
250  MythImageNotification(Type type, const QString &imagePath, const DMAP &metadata)
251  : MythNotification(type, metadata), m_imagePath(imagePath)
252  {
253  }
254 
255  MythEvent *clone(void) const override // MythNotification
256  { return new MythImageNotification(*this); }
257 
258  // Setter
262  void SetImage(const QImage &image) { m_image = image; }
266  void SetImagePath(const QString &image) { m_imagePath = image; }
267 
268  //Getter
269  QImage GetImage(void) const { return m_image; }
270  QString GetImagePath(void) const { return m_imagePath; }
271 
272  protected:
274  : MythNotification(o), m_image(o.m_image), m_imagePath(o.m_imagePath)
275  {
276  }
277 
278  protected:
279  QImage m_image;
280  QString m_imagePath;
281 };
282 
284 {
285  public:
286  MythPlaybackNotification(Type type, float progress, const QString &progressText)
287  : MythNotification(type), m_progress(progress), m_progressText(progressText)
288  {
289  }
290 
291  MythPlaybackNotification(Type type, float progress, const QString &progressText,
292  const DMAP &metadata)
293  : MythNotification(type, metadata),
294  m_progress(progress), m_progressText(progressText)
295  {
296  }
297 
298  MythPlaybackNotification(Type type, int duration, int position)
300  {
301  m_progress = (float)position / (float)duration;
302  m_progressText = stringFromSeconds(duration);
303  }
304 
305  MythEvent *clone(void) const override // MythNotification
306  { return new MythPlaybackNotification(*this); }
307 
308  // Setter
314  void SetProgress(float progress) { m_progress = progress; }
318  void SetProgressText(const QString &text) { m_progressText = text; }
319 
320  //Getter
321  float GetProgress(void) const { return m_progress; }
322  QString GetProgressText(void) const { return m_progressText; }
323 
324  // utility methods
325  static QString stringFromSeconds(int time);
326 
327  protected:
329  : MythNotification(o),
330  m_progress(o.m_progress), m_progressText(o.m_progressText)
331  {
332  }
333 
334  protected:
335  float m_progress;
336  QString m_progressText;
337 };
338 
341 {
342  public:
343  MythMediaNotification(Type type, const QImage &image, const DMAP &metadata,
344  float progress, const QString &durationText)
345  : MythNotification(type, metadata), MythImageNotification(type, image),
346  MythPlaybackNotification(type, progress, durationText)
347  {
348  }
349 
350  MythMediaNotification(Type type, const QImage &image, const DMAP &metadata,
351  int duration, int position)
352  : MythNotification(type, metadata), MythImageNotification(type, image),
353  MythPlaybackNotification(type, duration, position)
354  {
355  }
356 
357  MythMediaNotification(Type type, const QString &imagePath, const DMAP &metadata,
358  float progress, const QString &durationText)
359  : MythNotification(type, metadata), MythImageNotification(type, imagePath),
360  MythPlaybackNotification(type, progress, durationText)
361  {
362  }
363 
364  MythMediaNotification(Type type, const QString &imagePath, const DMAP &metadata,
365  int duration, int position)
366  : MythNotification(type, metadata), MythImageNotification(type, imagePath),
367  MythPlaybackNotification(type, duration, position)
368  {
369  }
370 
371  MythEvent *clone(void) const override // MythImageNotification
372  { return new MythMediaNotification(*this); }
373 
374  protected:
377  {
378  }
379 };
380 
382 {
383  public:
384  MythErrorNotification(const QString &title, const QString &author,
385  const QString &details = QString())
386  : MythNotification(Error, title, author, details)
387  {
388  SetDuration(10);
389  }
390 };
391 
393 {
394  public:
395  MythWarningNotification(const QString &title, const QString &author,
396  const QString &details = QString())
397  : MythNotification(Warning, title, author, details)
398  {
399  SetDuration(10);
400  }
401 };
402 
404 {
405  public:
406  MythCheckNotification(const QString &title, const QString &author,
407  const QString &details = QString())
408  : MythNotification(Check, title, author, details)
409  {
410  SetDuration(5);
411  }
412 };
413 
415 {
416  public:
417  MythBusyNotification(const QString &title, const QString &author,
418  const QString &details = QString())
419  : MythNotification(Busy, title, author, details) { }
420 };
421 
422 #endif /* defined(__MythTV__mythnotification__) */
void SetParent(void *parent)
contains the parent address.
void SetProgress(float progress)
current playback position to be displayed with the notification.
MythPlaybackNotification(Type type, float progress, const QString &progressText)
int GetId(void) const
Visibility
Visibility enum A notification can be given visibility mask allowing to not be visible under some cir...
QString GetDescription(void) const
MythEvent * clone(void) const override
MythNotification(const QString &title, const QString &author, const QString &details=QString())
MythBusyNotification(const QString &title, const QString &author, const QString &details=QString())
unsigned int VNMask
int GetDuration(void) const
void SetProgressText(const QString &text)
text to be displayed with the notification as duration or progress.
MythWarningNotification(const QString &title, const QString &author, const QString &details=QString())
MythImageNotification(Type type, const QString &imagePath)
MythNotification(Type type, const DMAP &metadata)
void SetMetaData(const DMAP &data)
metadata of the notification.
MythMediaNotification(Type type, const QString &imagePath, const DMAP &metadata, int duration, int position)
MythImageNotification(Type type, const QImage &image)
MythEvent * clone(void) const override
MythPlaybackNotification(const MythPlaybackNotification &o)
static Type Warning
MythNotification(const MythNotification &o)
MythImageNotification(Type type, const QImage &image, const DMAP &metadata)
void SetImage(const QImage &image)
image to be displayed with the notification
QString GetStyle(void) const
MythPlaybackNotification(Type type, float progress, const QString &progressText, const DMAP &metadata)
void SetStyle(const QString &style)
contains an alternative notification style.
This class is used as a container for messages.
Definition: mythevent.h:15
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:85
Priority GetPriority(void) const
void SetPriority(Priority n)
For future use, not implemented at this stage.
MythMediaNotification(const MythMediaNotification &o)
MythPlaybackNotification(Type type, int duration, int position)
void SetDescription(const QString &desc)
contains a short description of the notification
void SetDuration(int duration)
contains a duration during which the notification will be displayed for.
MythMediaNotification(Type type, const QImage &image, const DMAP &metadata, int duration, int position)
MythEvent * clone(void) const override
QString GetImagePath(void) const
MythImageNotification(Type type, const QString &imagePath, const DMAP &metadata)
MythMediaNotification(Type type, const QImage &image, const DMAP &metadata, float progress, const QString &durationText)
QImage GetImage(void) const
virtual ~MythNotification()
float GetProgress(void) const
MythMediaNotification(Type type, const QString &imagePath, const DMAP &metadata, float progress, const QString &durationText)
MythErrorNotification(const QString &title, const QString &author, const QString &details=QString())
#define MUI_PUBLIC
Definition: mythuiexp.h:9
MythCheckNotification(const QString &title, const QString &author, const QString &details=QString())
void * GetParent(void) const
VNMask GetVisibility(void) const
QString GetProgressText(void) const
MythNotification(Type type, void *parent=nullptr)
void SetImagePath(const QString &image)
image filename to be displayed with the notification
void SetFullScreen(bool f)
a notification may request to be displayed in full screen, this request may not be fullfilled should ...
MythNotification(const MythEvent &me)
MythNotification(Type type, const QString &title, const QString &author, const QString &details=QString(), const QString &extra=QString())
bool GetFullScreen(void) const
static Type Update
MythNotification(int id, void *parent)
MythImageNotification(const MythImageNotification &o)
QMap< QString, QString > DMAP
void SetVisibility(VNMask n)
define a bitmask of Visibility
DMAP GetMetaData(void) const
MythEvent * clone(void) const override