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_H
10 #define MYTHTV_MYTHNOTIFICATION_H
11 
12 #include <utility>
13 
14 // Qt headers
15 #include <QImage>
16 #include <QMap>
17 #include <QMutex>
18 
19 // MythTV headers
20 #include "mythevent.h"
21 #include "mythuiexp.h"
22 
23 using DMAP = QMap<QString,QString>;
24 using VNMask = unsigned int;
25 
27 {
28  public:
29 
30  static Type New;
31  static Type Update;
32  static Type Info;
33  static Type Error;
34  static Type Warning;
35  static Type Check;
36  static Type Busy;
37 
38  explicit MythNotification(Type type, void *parent = nullptr)
39  : MythEvent(type, "NOTIFICATION"), m_parent(parent) {}
40 
41  MythNotification(int id, void *parent)
42  : MythEvent(Update, "NOTIFICATION"), m_id(id), m_parent(parent) {}
43 
44  MythNotification(const QString &title, const QString &author,
45  const QString &details = QString())
46  : MythEvent(New, "NOTIFICATION"), m_description(title)
47  {
48  DMAP map;
49  map["minm"] = title;
50  map["asar"] = author;
51  map["asal"] = details;
52  m_metadata = map;
53  ToStringList();
54  }
55 
56  MythNotification(Type type, const QString &title, const QString &author,
57  const QString &details = QString(),
58  const QString &extra = QString())
59  : MythEvent(type, "NOTIFICATION"), m_description(title)
60  {
61  DMAP map;
62  map["minm"] = title;
63  map["asar"] = author;
64  map["asal"] = details;
65  map["asfm"] = extra;
66  m_metadata = map;
67  ToStringList();
68  }
69 
70  MythNotification(Type type, DMAP metadata)
71  : MythEvent(type, "NOTIFICATION"), m_metadata(std::move(metadata))
72  {
73  ToStringList();
74  }
75 
76  explicit MythNotification(const MythEvent &me)
77  : MythEvent(me)
78  {
79  FromStringList();
80  }
81 
82  ~MythNotification() override = default;
83 
84  MythEvent *clone(void) const override // MythEvent
85  { return new MythNotification(*this); }
86 
91  enum Priority {
92  kDefault = 0,
98  };
99 
106  enum Visibility {
107  kNone = 0,
108  kAll = ~0,
109  kPlayback = (1 << 0),
110  kSettings = (1 << 1),
111  kWizard = (1 << 2),
112  kVideos = (1 << 3),
113  kMusic = (1 << 4),
114  kRecordings = (1 << 5),
115  };
116 
117  // Setter
125  void SetId(int id);
132  void SetParent(void *parent) { m_parent = parent; }
138  void SetFullScreen(bool f) { m_fullScreen = f; ToStringList(); }
142  void SetDescription(const QString &desc)
143  { m_description = desc; ToStringList(); }
149  void SetMetaData(const DMAP &data) { m_metadata = data; ToStringList(); }
156  void SetDuration(int duration) { m_duration = duration; ToStringList(); }
162  void SetStyle(const QString &style) { m_style = style; ToStringList(); }
166  void SetVisibility(VNMask n) { m_visibility = n; ToStringList(); }
170  void SetPriority(Priority n) { m_priority = n; ToStringList(); }
171 
175  static Type TypeFromString(const QString &type);
176 
177  void ToStringList(void);
178  bool FromStringList(void);
179 
180  // Getter
181  int GetId(void) const { return m_id; }
182  void *GetParent(void) const { return m_parent; }
183  bool GetFullScreen(void) const { return m_fullScreen; }
184  QString GetDescription(void) const { return m_description; }
185  DMAP GetMetaData(void) const { return m_metadata; }
186  int GetDuration(void) const { return m_duration; };
187  QString GetStyle(void) const { return m_style; }
188  VNMask GetVisibility(void) const { return m_visibility; }
189  Priority GetPriority(void) const { return m_priority; }
190 
191  protected:
193  : MythEvent(o),
194  m_id(o.m_id), m_parent(o.m_parent), m_fullScreen(o.m_fullScreen),
195  m_description(o.m_description),
196  m_duration(o.m_duration), m_metadata(o.m_metadata),
197  m_style(o.m_style),
198  m_visibility(o.m_visibility), m_priority(o.m_priority)
199  {
200  ToStringList();
201  }
202 
203 #ifndef _MSC_VER
205 #endif
206 
207  protected:
208  int m_id {-1};
209  void *m_parent {nullptr};
210  bool m_fullScreen {false};
211  QString m_description;
212  int m_duration {0};
214  QString m_style;
215  VNMask m_visibility {(VNMask)kAll};
216  Priority m_priority {kDefault};
217 };
218 
220 {
221  public:
222  MythImageNotification(Type type, QImage image)
223  : MythNotification(type), m_image(std::move(image))
224  {
225  }
226 
227  MythImageNotification(Type type, QString imagePath)
228  : MythNotification(type), m_imagePath(std::move(imagePath))
229  {
230  }
231 
232  MythImageNotification(Type type, QImage image, const DMAP &metadata)
233  : MythNotification(type, metadata), m_image(std::move(image))
234  {
235  }
236 
237  MythImageNotification(Type type, QString imagePath, const DMAP &metadata)
238  : MythNotification(type, metadata), m_imagePath(std::move(imagePath))
239  {
240  }
241 
242  MythEvent *clone(void) const override // MythNotification
243  { return new MythImageNotification(*this); }
244 
245  // Setter
249  void SetImage(const QImage &image) { m_image = image; }
253  void SetImagePath(const QString &image) { m_imagePath = image; }
254 
255  //Getter
256  QImage GetImage(void) const { return m_image; }
257  QString GetImagePath(void) const { return m_imagePath; }
258 
259  protected:
261 
262  protected:
263  QImage m_image;
264  QString m_imagePath;
265 };
266 
268 {
269  public:
270  MythPlaybackNotification(Type type, float progress, QString progressText)
271  : MythNotification(type), m_progress(progress), m_progressText(std::move(progressText))
272  {
273  }
274 
275  MythPlaybackNotification(Type type, float progress, QString progressText,
276  const DMAP &metadata)
277  : MythNotification(type, metadata),
278  m_progress(progress), m_progressText(std::move(progressText))
279  {
280  }
281 
282  MythPlaybackNotification(Type type, int duration, int position)
284  {
285  m_progress = (float)position / (float)duration;
286  m_progressText = stringFromSeconds(duration);
287  }
288 
289  MythEvent *clone(void) const override // MythNotification
290  { return new MythPlaybackNotification(*this); }
291 
292  // Setter
298  void SetProgress(float progress) { m_progress = progress; }
302  void SetProgressText(const QString &text) { m_progressText = text; }
303 
304  //Getter
305  float GetProgress(void) const { return m_progress; }
306  QString GetProgressText(void) const { return m_progressText; }
307 
308  // utility methods
309  static QString stringFromSeconds(int time);
310 
311  protected:
313 
314  protected:
315  float m_progress;
316  QString m_progressText;
317 };
318 
321 {
322  public:
323  MythMediaNotification(Type type, const QImage &image, const DMAP &metadata,
324  float progress, const QString &durationText)
325  : MythNotification(type, metadata), MythImageNotification(type, image),
326  MythPlaybackNotification(type, progress, durationText)
327  {
328  }
329 
330  MythMediaNotification(Type type, const QImage &image, const DMAP &metadata,
331  int duration, int position)
332  : MythNotification(type, metadata), MythImageNotification(type, image),
333  MythPlaybackNotification(type, duration, position)
334  {
335  }
336 
337  MythMediaNotification(Type type, const QString &imagePath, const DMAP &metadata,
338  float progress, const QString &durationText)
339  : MythNotification(type, metadata), MythImageNotification(type, imagePath),
340  MythPlaybackNotification(type, progress, durationText)
341  {
342  }
343 
344  MythMediaNotification(Type type, const QString &imagePath, const DMAP &metadata,
345  int duration, int position)
346  : MythNotification(type, metadata), MythImageNotification(type, imagePath),
347  MythPlaybackNotification(type, duration, position)
348  {
349  }
350 
351  MythEvent *clone(void) const override // MythImageNotification
352  { return new MythMediaNotification(*this); }
353 
354  protected:
357  {
358  }
359 };
360 
362 {
363  public:
364  MythErrorNotification(const QString &title, const QString &author,
365  const QString &details = QString())
366  : MythNotification(Error, title, author, details)
367  {
368  SetDuration(10);
369  }
370 };
371 
373 {
374  public:
375  MythWarningNotification(const QString &title, const QString &author,
376  const QString &details = QString())
377  : MythNotification(Warning, title, author, details)
378  {
379  SetDuration(10);
380  }
381 };
382 
384 {
385  public:
386  MythCheckNotification(const QString &title, const QString &author,
387  const QString &details = QString())
388  : MythNotification(Check, title, author, details)
389  {
390  SetDuration(5);
391  }
392 };
393 
395 {
396  public:
397  MythBusyNotification(const QString &title, const QString &author,
398  const QString &details = QString())
399  : MythNotification(Busy, title, author, details) { }
400 };
401 
402 #endif /* defined(MYTHTV_MYTHNOTIFICATION_H) */
MythImageNotification::MythImageNotification
MythImageNotification(const MythImageNotification &)=default
mythevent.h
MythNotification::GetParent
void * GetParent(void) const
Definition: mythnotification.h:182
MythNotification::GetStyle
QString GetStyle(void) const
Definition: mythnotification.h:187
MythPlaybackNotification::MythPlaybackNotification
MythPlaybackNotification(Type type, float progress, QString progressText)
Definition: mythnotification.h:270
MythMediaNotification::MythMediaNotification
MythMediaNotification(Type type, const QImage &image, const DMAP &metadata, int duration, int position)
Definition: mythnotification.h:330
MythImageNotification::MythImageNotification
MythImageNotification(Type type, QImage image)
Definition: mythnotification.h:222
MUI_PUBLIC
#define MUI_PUBLIC
Definition: mythuiexp.h:9
MythMediaNotification::MythMediaNotification
MythMediaNotification(Type type, const QImage &image, const DMAP &metadata, float progress, const QString &durationText)
Definition: mythnotification.h:323
MythNotification::operator=
MythNotification & operator=(const MythNotification &)
MythImageNotification::MythImageNotification
MythImageNotification(Type type, QString imagePath, const DMAP &metadata)
Definition: mythnotification.h:237
MythNotification::MythNotification
MythNotification(const MythNotification &o)
Definition: mythnotification.h:192
MythCheckNotification
Definition: mythnotification.h:384
MythMediaNotification::MythMediaNotification
MythMediaNotification(Type type, const QString &imagePath, const DMAP &metadata, float progress, const QString &durationText)
Definition: mythnotification.h:337
MythNotification::kLow
@ kLow
Definition: mythnotification.h:93
MythNotification::SetStyle
void SetStyle(const QString &style)
contains an alternative notification style.
Definition: mythnotification.h:162
title
QString title
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:639
MythNotification::GetFullScreen
bool GetFullScreen(void) const
Definition: mythnotification.h:183
MythErrorNotification::MythErrorNotification
MythErrorNotification(const QString &title, const QString &author, const QString &details=QString())
Definition: mythnotification.h:364
MythBusyNotification
Definition: mythnotification.h:395
progress
bool progress
Definition: mythtv/programs/mythcommflag/main.cpp:74
MythEvent
This class is used as a container for messages.
Definition: mythevent.h:17
MythWarningNotification
Definition: mythnotification.h:373
MythImageNotification::m_imagePath
QString m_imagePath
Definition: mythnotification.h:264
MythNotification
Definition: mythnotification.h:27
MythNotification::MythNotification
MythNotification(int id, void *parent)
Definition: mythnotification.h:41
MythNotification::MythNotification
MythNotification(Type type, const QString &title, const QString &author, const QString &details=QString(), const QString &extra=QString())
Definition: mythnotification.h:56
MythCheckNotification::MythCheckNotification
MythCheckNotification(const QString &title, const QString &author, const QString &details=QString())
Definition: mythnotification.h:386
MythImageNotification::MythImageNotification
MythImageNotification(Type type, QImage image, const DMAP &metadata)
Definition: mythnotification.h:232
MythMediaNotification::MythMediaNotification
MythMediaNotification(Type type, const QString &imagePath, const DMAP &metadata, int duration, int position)
Definition: mythnotification.h:344
MythImageNotification
Definition: mythnotification.h:220
MythImageNotification::GetImage
QImage GetImage(void) const
Definition: mythnotification.h:256
MythNotification::~MythNotification
~MythNotification() override=default
MythPlaybackNotification::MythPlaybackNotification
MythPlaybackNotification(Type type, int duration, int position)
Definition: mythnotification.h:282
MythNotification::SetParent
void SetParent(void *parent)
contains the parent address.
Definition: mythnotification.h:132
MythNotification::m_description
QString m_description
Definition: mythnotification.h:211
MythPlaybackNotification::GetProgress
float GetProgress(void) const
Definition: mythnotification.h:305
MythNotification::Error
static Type Error
Definition: mythnotification.h:33
MythNotification::m_style
QString m_style
Definition: mythnotification.h:214
MythPlaybackNotification::MythPlaybackNotification
MythPlaybackNotification(Type type, float progress, QString progressText, const DMAP &metadata)
Definition: mythnotification.h:275
MythImageNotification::clone
MythEvent * clone(void) const override
Definition: mythnotification.h:242
MythNotification::GetVisibility
VNMask GetVisibility(void) const
Definition: mythnotification.h:188
MythNotification::Visibility
Visibility
Visibility enum A notification can be given visibility mask allowing to not be visible under some cir...
Definition: mythnotification.h:106
MythNotification::GetId
int GetId(void) const
Definition: mythnotification.h:181
MythNotification::GetDuration
int GetDuration(void) const
Definition: mythnotification.h:186
MythMediaNotification::clone
MythEvent * clone(void) const override
Definition: mythnotification.h:351
MythNotification::MythNotification
MythNotification(Type type, void *parent=nullptr)
Definition: mythnotification.h:38
VNMask
unsigned int VNMask
Definition: mythnotification.h:24
MythImageNotification::m_image
QImage m_image
Definition: mythnotification.h:263
MythNotification::MythNotification
MythNotification(const MythEvent &me)
Definition: mythnotification.h:76
MythMediaNotification::MythMediaNotification
MythMediaNotification(const MythMediaNotification &o)
Definition: mythnotification.h:355
MythNotification::kHigh
@ kHigh
Definition: mythnotification.h:95
MythNotification::SetMetaData
void SetMetaData(const DMAP &data)
metadata of the notification.
Definition: mythnotification.h:149
MythErrorNotification
Definition: mythnotification.h:362
MythImageNotification::GetImagePath
QString GetImagePath(void) const
Definition: mythnotification.h:257
MythPlaybackNotification::SetProgress
void SetProgress(float progress)
current playback position to be displayed with the notification.
Definition: mythnotification.h:298
MythNotification::Busy
static Type Busy
Definition: mythnotification.h:36
MythPlaybackNotification::SetProgressText
void SetProgressText(const QString &text)
text to be displayed with the notification as duration or progress.
Definition: mythnotification.h:302
MythPlaybackNotification::GetProgressText
QString GetProgressText(void) const
Definition: mythnotification.h:306
f
QTextStream t & f
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:606
MythMediaNotification
Definition: mythnotification.h:321
MythNotification::SetFullScreen
void SetFullScreen(bool f)
a notification may request to be displayed in full screen, this request may not be fullfilled should ...
Definition: mythnotification.h:138
MythPlaybackNotification::m_progressText
QString m_progressText
Definition: mythnotification.h:316
MythPlaybackNotification::clone
MythEvent * clone(void) const override
Definition: mythnotification.h:289
MythNotification::Check
static Type Check
Definition: mythnotification.h:35
MythNotification::Update
static Type Update
Definition: mythnotification.h:31
MythPlaybackNotification::MythPlaybackNotification
MythPlaybackNotification(const MythPlaybackNotification &)=default
MythNotification::GetDescription
QString GetDescription(void) const
Definition: mythnotification.h:184
MythNotification::MythNotification
MythNotification(Type type, DMAP metadata)
Definition: mythnotification.h:70
MythNotification::SetPriority
void SetPriority(Priority n)
For future use, not implemented at this stage.
Definition: mythnotification.h:170
MythNotification::SetVisibility
void SetVisibility(VNMask n)
define a bitmask of Visibility
Definition: mythnotification.h:166
MythNotification::MythNotification
MythNotification(const QString &title, const QString &author, const QString &details=QString())
Definition: mythnotification.h:44
MythNotification::GetMetaData
DMAP GetMetaData(void) const
Definition: mythnotification.h:185
MythNotification::SetDuration
void SetDuration(int duration)
contains a duration during which the notification will be displayed for.
Definition: mythnotification.h:156
MythNotification::SetDescription
void SetDescription(const QString &desc)
contains a short description of the notification
Definition: mythnotification.h:142
MythNotification::New
static Type New
Definition: mythnotification.h:30
MythNotification::clone
MythEvent * clone(void) const override
Definition: mythnotification.h:84
MythNotification::GetPriority
Priority GetPriority(void) const
Definition: mythnotification.h:189
MythNotification::kHighest
@ kHighest
Definition: mythnotification.h:97
MythNotification::m_metadata
DMAP m_metadata
Definition: mythnotification.h:213
MythBusyNotification::MythBusyNotification
MythBusyNotification(const QString &title, const QString &author, const QString &details=QString())
Definition: mythnotification.h:397
MythImageNotification::SetImagePath
void SetImagePath(const QString &image)
image filename to be displayed with the notification
Definition: mythnotification.h:253
MythNotification::kMedium
@ kMedium
Definition: mythnotification.h:94
DMAP
QMap< QString, QString > DMAP
Definition: mythnotification.h:23
MythImageNotification::MythImageNotification
MythImageNotification(Type type, QString imagePath)
Definition: mythnotification.h:227
MythImageNotification::SetImage
void SetImage(const QImage &image)
image to be displayed with the notification
Definition: mythnotification.h:249
MythNotification::kHigher
@ kHigher
Definition: mythnotification.h:96
MythPlaybackNotification::m_progress
float m_progress
Definition: mythnotification.h:315
Priority
Definition: channelsettings.cpp:192
mythuiexp.h
MythWarningNotification::MythWarningNotification
MythWarningNotification(const QString &title, const QString &author, const QString &details=QString())
Definition: mythnotification.h:375
MythNotification::Warning
static Type Warning
Definition: mythnotification.h:34
MythPlaybackNotification
Definition: mythnotification.h:268
MythNotification::Info
static Type Info
Definition: mythnotification.h:32