MythTV  master
mythnotification.cpp
Go to the documentation of this file.
1 //
2 // mythnotification.cpp
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 // Qt
10 #include <QCoreApplication>
11 #include <QTime>
12 
13 // MythTV
15 #include "mythnotification.h"
16 
17 const QEvent::Type MythNotification::kNew = static_cast<QEvent::Type>(QEvent::registerEventType());
18 const QEvent::Type MythNotification::kUpdate = static_cast<QEvent::Type>(QEvent::registerEventType());
19 const QEvent::Type MythNotification::kInfo = static_cast<QEvent::Type>(QEvent::registerEventType());
20 const QEvent::Type MythNotification::kError = static_cast<QEvent::Type>(QEvent::registerEventType());
21 const QEvent::Type MythNotification::kWarning = static_cast<QEvent::Type>(QEvent::registerEventType());
22 const QEvent::Type MythNotification::kCheck = static_cast<QEvent::Type>(QEvent::registerEventType());
23 const QEvent::Type MythNotification::kBusy = static_cast<QEvent::Type>(QEvent::registerEventType());
24 
25 MythNotification::MythNotification(Type nType, void* Parent)
26  : MythEvent(nType, "NOTIFICATION"),
27  m_parent(Parent)
28 {
29 }
30 
32  : MythEvent(kUpdate, "NOTIFICATION"),
33  m_id(Id),
34  m_parent(Parent)
35 {
36 }
37 
38 MythNotification::MythNotification(const QString& Title, const QString& Author,
39  const QString& Details)
40  : MythEvent(kNew, "NOTIFICATION"),
41  m_description(Title),
42  m_metadata({{"minm", Title}, {"asar", Author}, {"asal", Details}})
43 {
44  ToStringList();
45 }
46 
47 MythNotification::MythNotification(Type nType, const QString& Title, const QString& Author,
48  const QString& Details, const QString& Extra)
49  : MythEvent(nType, "NOTIFICATION"),
50  m_description(Title),
51  m_metadata({{"minm", Title}, {"asar", Author}, {"asal", Details}, {"asfm", Extra}})
52 {
53  ToStringList();
54 }
55 
57  : MythEvent(nType, "NOTIFICATION"),
58  m_metadata(std::move(Metadata))
59 {
60  ToStringList();
61 }
62 
64  : MythEvent(Event)
65 {
67 }
68 
70  : MythEvent(Notification),
71  m_id(Notification.m_id),
72  m_parent(Notification.m_parent),
73  m_fullScreen(Notification.m_fullScreen),
74  m_description(Notification.m_description),
75  m_duration(Notification.m_duration),
76  m_metadata(Notification.m_metadata),
77  m_style(Notification.m_style),
78  m_visibility(Notification.m_visibility),
79  m_priority(Notification.m_priority)
80 {
81  ToStringList();
82 }
83 
85 {
86  return new MythNotification(*this);
87 }
88 
94 {
95  m_id = Id;
96  // default registered notification is to not expire
97  if (m_id > 0 && m_duration == 0s)
98  m_duration = -1s;
99 }
100 
106 void MythNotification::SetParent(void* Parent)
107 {
108  m_parent = Parent;
109 }
110 
115 void MythNotification::SetFullScreen(bool FullScreen)
116 {
117  m_fullScreen = FullScreen;
118  ToStringList();
119 }
120 
123 void MythNotification::SetDescription(const QString& Description)
124 {
125  m_description = Description;
126  ToStringList();
127 }
128 
133 void MythNotification::SetMetaData(const DMAP& MetaData)
134 {
135  m_metadata = MetaData;
136  ToStringList();
137 }
138 
144 void MythNotification::SetDuration(std::chrono::seconds Duration)
145 {
146  m_duration = Duration;
147  ToStringList();
148 }
149 
154 void MythNotification::SetStyle(const QString& sStyle)
155 {
156  m_style = sStyle;
157  ToStringList();
158 }
159 
163 {
164  m_visibility = nVisibility;
165  ToStringList();
166 }
167 
171 {
172  m_priority = nPriority;
173  ToStringList();
174 }
175 
177 {
178  m_extradata.clear();
179  m_extradata << QString::number(Type())
180  << QString::number(static_cast<int>(m_fullScreen))
181  << m_description
182  << QString::number(m_duration.count())
183  << m_style
184  << QString::number(m_visibility)
185  << QString::number(m_priority)
186  << m_metadata.value("minm")
187  << m_metadata.value("asar")
188  << m_metadata.value("asal")
189  << m_metadata.value("asfm");
190 }
191 
193 {
194  if (m_extradata.size() != 11)
195  {
196  LOG(VB_GENERAL, LOG_ERR,
197  QString("MythNotification::FromStringList called with %1 items, expecting 11. '%2'")
198  .arg(m_extradata.size()).arg(m_extradata.join(",")));
199  return false;
200  }
201 
202  QStringList::const_iterator it = m_extradata.cbegin();
203  Type type = static_cast<Type>((*it++).toInt());
204  if (type != Type())
205  {
206  LOG(VB_GENERAL, LOG_ERR,
207  QString("MythNotification::FromStringList called with type '%1' "
208  "in StringList, expected '%2' as set in constructor.")
209  .arg(type).arg(Type()));
210  return false;
211  }
212  m_fullScreen = ((*it++).toInt() != 0);
213  m_description = *it++;
214  m_duration = std::chrono::seconds((*it++).toInt());
215  m_style = *it++;
216  m_visibility = static_cast<VNMask>((*it++).toInt());
217  m_priority = static_cast<Priority>((*it++).toInt());
218  m_metadata["minm"] = *it++;
219  m_metadata["asar"] = *it++;
220  m_metadata["asal"] = *it++;
221  m_metadata["asfm"] = *it++;
222  return true;
223 }
224 
225 
230 QString MythPlaybackNotification::StringFromSeconds(std::chrono::seconds Time)
231 {
232  QTime ltime = QTime(0,0).addSecs(Time.count());
233  return ltime.toString(ltime.hour() > 0 ? "HH:mm:ss" : "mm:ss");
234 }
235 
236 MythNotification::Type MythNotification::TypeFromString(const QString& Type)
237 {
238  if (Type == "error") return MythNotification::kError;
239  if (Type == "warning") return MythNotification::kWarning;
240  if (Type == "check") return MythNotification::kCheck;
241  if (Type == "busy") return MythNotification::kBusy;
242  return MythNotification::kNew;
243 }
244 
246  : MythNotification(nType),
247  m_image(std::move(Image))
248 {
249 }
250 
251 MythImageNotification::MythImageNotification(Type nType, QString ImagePath)
252  : MythNotification(nType),
253  m_imagePath(std::move(ImagePath))
254 {
255 }
256 
257 MythImageNotification::MythImageNotification(Type nType, QImage Image, const DMAP& Metadata)
258  : MythNotification(nType, Metadata),
259  m_image(std::move(Image))
260 {
261 }
262 
263 MythImageNotification::MythImageNotification(Type nType, QString ImagePath, const DMAP& Metadata)
264  : MythNotification(nType, Metadata),
265  m_imagePath(std::move(ImagePath))
266 {
267 }
268 
270 {
271  return new MythImageNotification(*this);
272 }
273 
275  QString ProgressText)
276  : MythNotification(nType),
277  m_progress(Progress),
278  m_progressText(std::move(ProgressText))
279 {
280 }
281 
283  QString ProgressText,
284  const DMAP& Metadata)
285  : MythNotification(nType, Metadata),
286  m_progress(Progress),
287  m_progressText(std::move(ProgressText))
288 {
289 }
290 
292  std::chrono::seconds Duration,
293  int Position)
294  : MythNotification(nType),
295  m_progress(static_cast<float>(Position) / static_cast<float>(Duration.count())),
296  m_progressText(StringFromSeconds(Duration))
297 {
298 }
299 
301 {
302  return new MythPlaybackNotification(*this);
303 }
304 
305 MythMediaNotification::MythMediaNotification(Type nType, const QImage& Image, const DMAP& Metadata,
306  float Progress, const QString& DurationText)
307  : MythNotification(nType, Metadata),
308  MythImageNotification(nType, Image),
309  MythPlaybackNotification(nType, Progress, DurationText)
310 {
311 }
312 
313 MythMediaNotification::MythMediaNotification(Type nType, const QImage& Image, const DMAP& Metadata,
314  std::chrono::seconds Duration, int Position)
315  : MythNotification(nType, Metadata),
316  MythImageNotification(nType, Image),
317  MythPlaybackNotification(nType, Duration, Position)
318 {
319 }
320 
321 MythMediaNotification::MythMediaNotification(Type nType, const QString& Image, const DMAP& Metadata,
322  float Progress, const QString& DurationText)
323  : MythNotification(nType, Metadata),
324  MythImageNotification(nType, Image),
325  MythPlaybackNotification(nType, Progress, DurationText)
326 {
327 }
328 
329 MythMediaNotification::MythMediaNotification(Type nType, const QString& Image, const DMAP& Metadata,
330  std::chrono::seconds Duration, int Position)
331  : MythNotification(nType, Metadata),
332  MythImageNotification(nType, Image),
333  MythPlaybackNotification(nType, Duration, Position)
334 {
335 }
336 
338  : MythNotification(Notification),
339  MythImageNotification(Notification),
340  MythPlaybackNotification(Notification)
341 {
342 }
343 
345 {
346  return new MythMediaNotification(*this);
347 }
348 
349 MythErrorNotification::MythErrorNotification(const QString& Title, const QString& Author,
350  const QString& Details)
351  : MythNotification(kError, Title, Author, Details)
352 {
353  SetDuration(10s);
354 }
355 
356 MythWarningNotification::MythWarningNotification(const QString& Title, const QString& Author,
357  const QString& Details)
358  : MythNotification(kWarning, Title, Author, Details)
359 {
360  SetDuration(10s);
361 }
362 
363 MythCheckNotification::MythCheckNotification(const QString& Title, const QString& Author,
364  const QString& Details)
365  : MythNotification(kCheck, Title, Author, Details)
366 {
367  SetDuration(5s);
368 }
369 
370 MythBusyNotification::MythBusyNotification(const QString& Title, const QString& Author,
371  const QString& Details)
372  : MythNotification(kBusy, Title, Author, Details)
373 {
374 }
MythNotification::SetDuration
void SetDuration(std::chrono::seconds Duration)
Contains a duration during which the notification will be displayed for. The duration is informative ...
Definition: mythnotification.cpp:144
MythNotification::m_parent
void * m_parent
Definition: mythnotification.h:121
MythEvent
This class is used as a container for messages.
Definition: mythevent.h:16
MythNotification::kBusy
static const Type kBusy
Definition: mythnotification.h:38
MythNotification::SetPriority
void SetPriority(Priority nPriority)
Reserved for future use, not implemented at this stage.
Definition: mythnotification.cpp:170
MythNotification
Definition: mythnotification.h:29
MythNotification::m_fullScreen
bool m_fullScreen
Definition: mythnotification.h:122
MythImageNotification::clone
MythEvent * clone() const override
Definition: mythnotification.cpp:269
MythEvent::m_extradata
QStringList m_extradata
Definition: mythevent.h:102
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythNotification::SetDescription
void SetDescription(const QString &Description)
Contains a short description of the notification.
Definition: mythnotification.cpp:123
MythNotification::SetVisibility
void SetVisibility(VNMask nVisibility)
Define a bitmask of Visibility.
Definition: mythnotification.cpp:162
MythNotification::TypeFromString
static Type TypeFromString(const QString &Type)
Definition: mythnotification.cpp:236
MythNotification::SetStyle
void SetStyle(const QString &sStyle)
Contains an alternative notification style. Should a style be defined, the Notification Center will a...
Definition: mythnotification.cpp:154
MythPlaybackNotification::MythPlaybackNotification
MythPlaybackNotification(Type nType, float Progress, QString ProgressText)
Definition: mythnotification.cpp:274
MythImageNotification
Definition: mythnotification.h:131
MythImageNotification::MythImageNotification
MythImageNotification(Type nType, QImage Image)
Definition: mythnotification.cpp:245
MythNotification::m_duration
std::chrono::seconds m_duration
Definition: mythnotification.h:124
MythNotification::m_visibility
VNMask m_visibility
Definition: mythnotification.h:127
MythMediaNotification::clone
MythEvent * clone() const override
Definition: mythnotification.cpp:344
MythNotification::m_description
QString m_description
Definition: mythnotification.h:123
MythNotification::m_style
QString m_style
Definition: mythnotification.h:126
mythlogging.h
MythNotification::SetFullScreen
void SetFullScreen(bool FullScreen)
A notification may request to be displayed in full screen, this request may not be fullfilled should ...
Definition: mythnotification.cpp:115
Event
Event details.
Definition: zmdefines.h:26
MythNotification::kCheck
static const Type kCheck
Definition: mythnotification.h:37
MythNotification::SetParent
void SetParent(void *Parent)
Contains the parent address. Required if id is set Id provided must match the parent address as provi...
Definition: mythnotification.cpp:106
VNMask
unsigned int VNMask
Definition: mythnotification.h:27
MythNotification::kNew
static const Type kNew
Definition: mythnotification.h:32
MythNotification::clone
MythEvent * clone() const override
Definition: mythnotification.cpp:84
MythWarningNotification::MythWarningNotification
MythWarningNotification(const QString &Title, const QString &Author, const QString &Details=QString())
Definition: mythnotification.cpp:356
MythPlaybackNotification::StringFromSeconds
static QString StringFromSeconds(std::chrono::seconds Time)
Create a string in the format HH:mm:ss from a duration in seconds.
Definition: mythnotification.cpp:230
MythNotification::kError
static const Type kError
Definition: mythnotification.h:35
mythnotification.h
MythMediaNotification
Definition: mythnotification.h:180
MythPlaybackNotification::clone
MythEvent * clone() const override
Definition: mythnotification.cpp:300
MythNotification::FromStringList
bool FromStringList()
Definition: mythnotification.cpp:192
MythCheckNotification::MythCheckNotification
MythCheckNotification(const QString &Title, const QString &Author, const QString &Details=QString())
Definition: mythnotification.cpp:363
MythNotification::MythNotification
MythNotification(Type nType, void *Parent=nullptr)
Definition: mythnotification.cpp:25
MythNotification::SetMetaData
void SetMetaData(const DMAP &MetaData)
metadata of the notification. In DMAP format. DMAP can contains various information such as artist,...
Definition: mythnotification.cpp:133
MythBusyNotification::MythBusyNotification
MythBusyNotification(const QString &Title, const QString &Author, const QString &Details=QString())
Definition: mythnotification.cpp:370
MythNotification::ToStringList
void ToStringList()
Definition: mythnotification.cpp:176
MythNotification::kInfo
static const Type kInfo
Definition: mythnotification.h:34
MythMediaNotification::MythMediaNotification
MythMediaNotification(Type nType, const QImage &Image, const DMAP &Metadata, float Progress, const QString &DurationText)
Definition: mythnotification.cpp:305
MythNotification::m_id
int m_id
Definition: mythnotification.h:120
std
Definition: mythchrono.h:23
MythNotification::m_priority
Priority m_priority
Definition: mythnotification.h:128
MythNotification::kWarning
static const Type kWarning
Definition: mythnotification.h:36
MythNotification::kUpdate
static const Type kUpdate
Definition: mythnotification.h:33
MythNotification::SetId
void SetId(int Id)
Contains the application registration id.
Definition: mythnotification.cpp:93
MythNotification::m_metadata
DMAP m_metadata
Definition: mythnotification.h:125
DMAP
QMap< QString, QString > DMAP
Definition: mythnotification.h:26
MythErrorNotification::MythErrorNotification
MythErrorNotification(const QString &Title, const QString &Author, const QString &Details=QString())
Definition: mythnotification.cpp:349
Priority
Definition: channelsettings.cpp:216
MythPlaybackNotification
Definition: mythnotification.h:153