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_parent(parent) {}
36 
37  MythNotification(int id, void *parent)
38  : MythEvent(Update, "NOTIFICATION"), m_id(id), m_parent(parent) {}
39 
40  MythNotification(const QString &title, const QString &author,
41  const QString &details = QString())
42  : MythEvent(New, "NOTIFICATION"), m_description(title)
43  {
44  DMAP map;
45  map["minm"] = title;
46  map["asar"] = author;
47  map["asal"] = details;
48  m_metadata = map;
49  ToStringList();
50  }
51 
52  MythNotification(Type type, const QString &title, const QString &author,
53  const QString &details = QString(),
54  const QString &extra = QString())
55  : MythEvent(type, "NOTIFICATION"), m_description(title)
56  {
57  DMAP map;
58  map["minm"] = title;
59  map["asar"] = author;
60  map["asal"] = details;
61  map["asfm"] = extra;
62  m_metadata = map;
63  ToStringList();
64  }
65 
66  MythNotification(Type type, const DMAP &metadata)
67  : MythEvent(type, "NOTIFICATION"), m_metadata(metadata)
68  {
69  ToStringList();
70  }
71 
72  explicit MythNotification(const MythEvent &me)
73  : MythEvent(me)
74  {
75  FromStringList();
76  }
77 
79  {
80  }
81 
82  MythEvent *clone(void) const override // MythEvent
83  { return new MythNotification(*this); }
84 
89  enum Priority {
90  kDefault = 0,
96  };
97 
104  enum Visibility {
105  kNone = 0,
106  kAll = ~0,
107  kPlayback = (1 << 0),
108  kSettings = (1 << 1),
109  kWizard = (1 << 2),
110  kVideos = (1 << 3),
111  kMusic = (1 << 4),
112  kRecordings = (1 << 5),
113  };
114 
115  // Setter
123  void SetId(int id);
130  void SetParent(void *parent) { m_parent = parent; }
136  void SetFullScreen(bool f) { m_fullScreen = f; ToStringList(); }
140  void SetDescription(const QString &desc)
141  { m_description = desc; ToStringList(); }
147  void SetMetaData(const DMAP &data) { m_metadata = data; ToStringList(); }
154  void SetDuration(int duration) { m_duration = duration; ToStringList(); }
160  void SetStyle(const QString &style) { m_style = style; ToStringList(); }
164  void SetVisibility(VNMask n) { m_visibility = n; ToStringList(); }
168  void SetPriority(Priority n) { m_priority = n; ToStringList(); }
169 
173  static Type TypeFromString(const QString &type);
174 
175  void ToStringList(void);
176  bool FromStringList(void);
177 
178  // Getter
179  int GetId(void) const { return m_id; }
180  void *GetParent(void) const { return m_parent; }
181  bool GetFullScreen(void) const { return m_fullScreen; }
182  QString GetDescription(void) const { return m_description; }
183  DMAP GetMetaData(void) const { return m_metadata; }
184  int GetDuration(void) const { return m_duration; };
185  QString GetStyle(void) const { return m_style; }
186  VNMask GetVisibility(void) const { return m_visibility; }
187  Priority GetPriority(void) const { return m_priority; }
188 
189  protected:
191  : MythEvent(o),
192  m_id(o.m_id), m_parent(o.m_parent), m_fullScreen(o.m_fullScreen),
193  m_description(o.m_description),
194  m_duration(o.m_duration), m_metadata(o.m_metadata),
195  m_style(o.m_style),
196  m_visibility(o.m_visibility), m_priority(o.m_priority)
197  {
198  ToStringList();
199  }
200 
201 #ifndef _MSC_VER
202  MythNotification &operator=(const MythNotification&);
203 #endif
204 
205  protected:
206  int m_id {-1};
207  void *m_parent {nullptr};
208  bool m_fullScreen {false};
209  QString m_description;
210  int m_duration {0};
212  QString m_style;
213  VNMask m_visibility {(VNMask)kAll};
214  Priority m_priority {kDefault};
215 };
216 
218 {
219  public:
220  MythImageNotification(Type type, const QImage &image)
221  : MythNotification(type), m_image(image)
222  {
223  }
224 
225  MythImageNotification(Type type, const QString &imagePath)
226  : MythNotification(type), m_imagePath(imagePath)
227  {
228  }
229 
230  MythImageNotification(Type type, const QImage &image, const DMAP &metadata)
231  : MythNotification(type, metadata), m_image(image)
232  {
233  }
234 
235  MythImageNotification(Type type, const QString &imagePath, const DMAP &metadata)
236  : MythNotification(type, metadata), m_imagePath(imagePath)
237  {
238  }
239 
240  MythEvent *clone(void) const override // MythNotification
241  { return new MythImageNotification(*this); }
242 
243  // Setter
247  void SetImage(const QImage &image) { m_image = image; }
251  void SetImagePath(const QString &image) { m_imagePath = image; }
252 
253  //Getter
254  QImage GetImage(void) const { return m_image; }
255  QString GetImagePath(void) const { return m_imagePath; }
256 
257  protected:
259  : MythNotification(o), m_image(o.m_image), m_imagePath(o.m_imagePath)
260  {
261  }
262 
263  protected:
264  QImage m_image;
265  QString m_imagePath;
266 };
267 
269 {
270  public:
271  MythPlaybackNotification(Type type, float progress, const QString &progressText)
272  : MythNotification(type), m_progress(progress), m_progressText(progressText)
273  {
274  }
275 
276  MythPlaybackNotification(Type type, float progress, const QString &progressText,
277  const DMAP &metadata)
278  : MythNotification(type, metadata),
279  m_progress(progress), m_progressText(progressText)
280  {
281  }
282 
283  MythPlaybackNotification(Type type, int duration, int position)
285  {
286  m_progress = (float)position / (float)duration;
287  m_progressText = stringFromSeconds(duration);
288  }
289 
290  MythEvent *clone(void) const override // MythNotification
291  { return new MythPlaybackNotification(*this); }
292 
293  // Setter
299  void SetProgress(float progress) { m_progress = progress; }
303  void SetProgressText(const QString &text) { m_progressText = text; }
304 
305  //Getter
306  float GetProgress(void) const { return m_progress; }
307  QString GetProgressText(void) const { return m_progressText; }
308 
309  // utility methods
310  static QString stringFromSeconds(int time);
311 
312  protected:
314  : MythNotification(o),
315  m_progress(o.m_progress), m_progressText(o.m_progressText)
316  {
317  }
318 
319  protected:
320  float m_progress;
321  QString m_progressText;
322 };
323 
326 {
327  public:
328  MythMediaNotification(Type type, const QImage &image, const DMAP &metadata,
329  float progress, const QString &durationText)
330  : MythNotification(type, metadata), MythImageNotification(type, image),
331  MythPlaybackNotification(type, progress, durationText)
332  {
333  }
334 
335  MythMediaNotification(Type type, const QImage &image, const DMAP &metadata,
336  int duration, int position)
337  : MythNotification(type, metadata), MythImageNotification(type, image),
338  MythPlaybackNotification(type, duration, position)
339  {
340  }
341 
342  MythMediaNotification(Type type, const QString &imagePath, const DMAP &metadata,
343  float progress, const QString &durationText)
344  : MythNotification(type, metadata), MythImageNotification(type, imagePath),
345  MythPlaybackNotification(type, progress, durationText)
346  {
347  }
348 
349  MythMediaNotification(Type type, const QString &imagePath, const DMAP &metadata,
350  int duration, int position)
351  : MythNotification(type, metadata), MythImageNotification(type, imagePath),
352  MythPlaybackNotification(type, duration, position)
353  {
354  }
355 
356  MythEvent *clone(void) const override // MythImageNotification
357  { return new MythMediaNotification(*this); }
358 
359  protected:
362  {
363  }
364 };
365 
367 {
368  public:
369  MythErrorNotification(const QString &title, const QString &author,
370  const QString &details = QString())
371  : MythNotification(Error, title, author, details)
372  {
373  SetDuration(10);
374  }
375 };
376 
378 {
379  public:
380  MythWarningNotification(const QString &title, const QString &author,
381  const QString &details = QString())
382  : MythNotification(Warning, title, author, details)
383  {
384  SetDuration(10);
385  }
386 };
387 
389 {
390  public:
391  MythCheckNotification(const QString &title, const QString &author,
392  const QString &details = QString())
393  : MythNotification(Check, title, author, details)
394  {
395  SetDuration(5);
396  }
397 };
398 
400 {
401  public:
402  MythBusyNotification(const QString &title, const QString &author,
403  const QString &details = QString())
404  : MythNotification(Busy, title, author, details) { }
405 };
406 
407 #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:16
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