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
14 #include "mythlogging.h"
15 #include "mythnotification.h"
16 
17 MythNotification::MythNotification(Type nType, void* Parent)
18  : MythEvent(nType, "NOTIFICATION"),
19  m_parent(Parent)
20 {
21 }
22 
24  : MythEvent(Update, "NOTIFICATION"),
25  m_id(Id),
26  m_parent(Parent)
27 {
28 }
29 
30 MythNotification::MythNotification(const QString& Title, const QString& Author,
31  const QString& Details)
32  : MythEvent(New, "NOTIFICATION"),
33  m_description(Title),
34  m_metadata({{"minm", Title}, {"asar", Author}, {"asal", Details}})
35 {
36  ToStringList();
37 }
38 
39 MythNotification::MythNotification(Type nType, const QString& Title, const QString& Author,
40  const QString& Details, const QString& Extra)
41  : MythEvent(nType, "NOTIFICATION"),
42  m_description(Title),
43  m_metadata({{"minm", Title}, {"asar", Author}, {"asal", Details}, {"asfm", Extra}})
44 {
45  ToStringList();
46 }
47 
49  : MythEvent(nType, "NOTIFICATION"),
50  m_metadata(std::move(Metadata))
51 {
52  ToStringList();
53 }
54 
56  : MythEvent(Event)
57 {
59 }
60 
62  : MythEvent(Notification),
63  m_id(Notification.m_id),
64  m_parent(Notification.m_parent),
65  m_fullScreen(Notification.m_fullScreen),
66  m_description(Notification.m_description),
67  m_duration(Notification.m_duration),
68  m_metadata(Notification.m_metadata),
69  m_style(Notification.m_style),
70  m_visibility(Notification.m_visibility),
71  m_priority(Notification.m_priority)
72 {
73  ToStringList();
74 }
75 
77 {
78  return new MythNotification(*this);
79 }
80 
86 {
87  m_id = Id;
88  // default registered notification is to not expire
89  if (m_id > 0 && m_duration == 0)
90  m_duration = -1;
91 }
92 
98 void MythNotification::SetParent(void* Parent)
99 {
100  m_parent = Parent;
101 }
102 
107 void MythNotification::SetFullScreen(bool FullScreen)
108 {
109  m_fullScreen = FullScreen;
110  ToStringList();
111 }
112 
115 void MythNotification::SetDescription(const QString& Description)
116 {
117  m_description = Description;
118  ToStringList();
119 }
120 
125 void MythNotification::SetMetaData(const DMAP& MetaData)
126 {
127  m_metadata = MetaData;
128  ToStringList();
129 }
130 
137 {
138  m_duration = Duration;
139  ToStringList();
140 }
141 
146 void MythNotification::SetStyle(const QString& Style)
147 {
148  m_style = Style;
149  ToStringList();
150 }
151 
155 {
157  ToStringList();
158 }
159 
163 {
164  m_priority = nPriority;
165  ToStringList();
166 }
167 
169 {
170  m_extradata.clear();
171  m_extradata << QString::number(Type())
172  << QString::number(static_cast<int>(m_fullScreen))
173  << m_description
174  << QString::number(m_duration)
175  << m_style
176  << QString::number(m_visibility)
177  << QString::number(m_priority)
178  << m_metadata.value("minm")
179  << m_metadata.value("asar")
180  << m_metadata.value("asal")
181  << m_metadata.value("asfm");
182 }
183 
185 {
186  if (m_extradata.size() != 11)
187  {
188  LOG(VB_GENERAL, LOG_ERR,
189  QString("MythNotification::FromStringList called with %1 items, expecting 11. '%2'")
190  .arg(m_extradata.size()).arg(m_extradata.join(",")));
191  return false;
192  }
193 
194  QStringList::const_iterator it = m_extradata.cbegin();
195  Type type = static_cast<Type>((*it++).toInt());
196  if (type != Type())
197  {
198  LOG(VB_GENERAL, LOG_ERR,
199  QString("MythNotification::FromStringList called with type '%1' "
200  "in StringList, expected '%2' as set in constructor.")
201  .arg(type).arg(Type()));
202  return false;
203  }
204  m_fullScreen = ((*it++).toInt() != 0);
205  m_description = *it++;
206  m_duration = (*it++).toInt();
207  m_style = *it++;
208  m_visibility = static_cast<VNMask>((*it++).toInt());
209  m_priority = static_cast<Priority>((*it++).toInt());
210  m_metadata["minm"] = *it++;
211  m_metadata["asar"] = *it++;
212  m_metadata["asal"] = *it++;
213  m_metadata["asfm"] = *it++;
214  return true;
215 }
216 
217 
223 {
224  QTime ltime = QTime(0,0).addSecs(Time);
225  return ltime.toString(ltime.hour() > 0 ? "HH:mm:ss" : "mm:ss");
226 }
227 
228 MythNotification::Type MythNotification::TypeFromString(const QString& Type)
229 {
230  if (Type == "error") return MythNotification::Error;
231  if (Type == "warning") return MythNotification::Warning;
232  if (Type == "check") return MythNotification::Check;
233  if (Type == "busy") return MythNotification::Busy;
234  return MythNotification::New;
235 }
236 
238  : MythNotification(nType),
239  m_image(std::move(Image))
240 {
241 }
242 
243 MythImageNotification::MythImageNotification(Type nType, QString ImagePath)
244  : MythNotification(nType),
245  m_imagePath(std::move(ImagePath))
246 {
247 }
248 
249 MythImageNotification::MythImageNotification(Type nType, QImage Image, const DMAP& Metadata)
250  : MythNotification(nType, Metadata),
251  m_image(std::move(Image))
252 {
253 }
254 
255 MythImageNotification::MythImageNotification(Type nType, QString ImagePath, const DMAP& Metadata)
256  : MythNotification(nType, Metadata),
257  m_imagePath(std::move(ImagePath))
258 {
259 }
260 
262 {
263  return new MythImageNotification(*this);
264 }
265 
267  QString ProgressText)
268  : MythNotification(nType),
269  m_progress(Progress),
270  m_progressText(std::move(ProgressText))
271 {
272 }
273 
275  QString ProgressText,
276  const DMAP& Metadata)
277  : MythNotification(nType, Metadata),
278  m_progress(Progress),
279  m_progressText(std::move(ProgressText))
280 {
281 }
282 
284  int Position)
285  : MythNotification(nType),
286  m_progress(static_cast<float>(Position) / static_cast<float>(Duration)),
287  m_progressText(StringFromSeconds(Duration))
288 {
289 }
290 
292 {
293  return new MythPlaybackNotification(*this);
294 }
295 
296 MythMediaNotification::MythMediaNotification(Type nType, const QImage& Image, const DMAP& Metadata,
297  float Progress, const QString& DurationText)
298  : MythNotification(nType, Metadata),
300  MythPlaybackNotification(nType, Progress, DurationText)
301 {
302 }
303 
304 MythMediaNotification::MythMediaNotification(Type nType, const QImage& Image, const DMAP& Metadata,
305  int Duration, int Position)
306  : MythNotification(nType, Metadata),
308  MythPlaybackNotification(nType, Duration, Position)
309 {
310 }
311 
312 MythMediaNotification::MythMediaNotification(Type nType, const QString& Image, const DMAP& Metadata,
313  float Progress, const QString& DurationText)
314  : MythNotification(nType, Metadata),
316  MythPlaybackNotification(nType, Progress, DurationText)
317 {
318 }
319 
320 MythMediaNotification::MythMediaNotification(Type nType, const QString& Image, const DMAP& Metadata,
321  int Duration, int Position)
322  : MythNotification(nType, Metadata),
324  MythPlaybackNotification(nType, Duration, Position)
325 {
326 }
327 
329  : MythNotification(Notification),
330  MythImageNotification(Notification),
331  MythPlaybackNotification(Notification)
332 {
333 }
334 
336 {
337  return new MythMediaNotification(*this);
338 }
339 
340 MythErrorNotification::MythErrorNotification(const QString& Title, const QString& Author,
341  const QString& Details)
342  : MythNotification(Error, Title, Author, Details)
343 {
344  SetDuration(10);
345 }
346 
347 MythWarningNotification::MythWarningNotification(const QString& Title, const QString& Author,
348  const QString& Details)
349  : MythNotification(Warning, Title, Author, Details)
350 {
351  SetDuration(10);
352 }
353 
354 MythCheckNotification::MythCheckNotification(const QString& Title, const QString& Author,
355  const QString& Details)
356  : MythNotification(Check, Title, Author, Details)
357 {
358  SetDuration(5);
359 }
360 
361 MythBusyNotification::MythBusyNotification(const QString& Title, const QString& Author,
362  const QString& Details)
363  : MythNotification(Busy, Title, Author, Details)
364 {
365 }
MythNotification::Busy
static Type Busy
Definition: mythnotification.h:36
MythNotification::SetDuration
void SetDuration(int Duration)
Contains a duration during which the notification will be displayed for. The duration is informative ...
Definition: mythnotification.cpp:136
MythNotification::m_duration
int m_duration
Definition: mythnotification.h:117
MythNotification::m_parent
void * m_parent
Definition: mythnotification.h:114
MythEvent
This class is used as a container for messages.
Definition: mythevent.h:16
arg
arg(title).arg(filename).arg(doDelete))
MythNotification::SetPriority
void SetPriority(Priority nPriority)
Reserved for future use, not implemented at this stage.
Definition: mythnotification.cpp:162
MythNotification
Definition: mythnotification.h:27
MythNotification::m_fullScreen
bool m_fullScreen
Definition: mythnotification.h:115
MythImageNotification::clone
MythEvent * clone() const override
Definition: mythnotification.cpp:261
MythEvent::m_extradata
QStringList m_extradata
Definition: mythevent.h:88
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
MythNotification::SetDescription
void SetDescription(const QString &Description)
Contains a short description of the notification.
Definition: mythnotification.cpp:115
MythNotification::TypeFromString
static Type TypeFromString(const QString &Type)
Definition: mythnotification.cpp:228
Image
Definition: image.h:30
MythPlaybackNotification::MythPlaybackNotification
MythPlaybackNotification(Type nType, float Progress, QString ProgressText)
Definition: mythnotification.cpp:266
MythImageNotification
Definition: mythnotification.h:124
MythImageNotification::MythImageNotification
MythImageNotification(Type nType, QImage Image)
Definition: mythnotification.cpp:237
MythNotification::m_visibility
VNMask m_visibility
Definition: mythnotification.h:120
MythMediaNotification::clone
MythEvent * clone() const override
Definition: mythnotification.cpp:335
MythNotification::m_description
QString m_description
Definition: mythnotification.h:116
MythNotification::m_style
QString m_style
Definition: mythnotification.h:119
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:107
MythNotification::Visibility
Visibility
Definition: mythnotification.h:69
Event
Event details.
Definition: zmdefines.h:26
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:98
VNMask
unsigned int VNMask
Definition: mythnotification.h:25
MythNotification::clone
MythEvent * clone() const override
Definition: mythnotification.cpp:76
MythWarningNotification::MythWarningNotification
MythWarningNotification(const QString &Title, const QString &Author, const QString &Details=QString())
Definition: mythnotification.cpp:347
MythPlaybackNotification::StringFromSeconds
static QString StringFromSeconds(int Time)
Create a string in the format HH:mm:ss from a duration in seconds.
Definition: mythnotification.cpp:222
mythnotification.h
MythNotification::Check
static Type Check
Definition: mythnotification.h:35
MythMediaNotification
Definition: mythnotification.h:173
MythNotification::New
static Type New
Definition: mythnotification.h:30
MythPlaybackNotification::clone
MythEvent * clone() const override
Definition: mythnotification.cpp:291
MythNotification::FromStringList
bool FromStringList()
Definition: mythnotification.cpp:184
MythCheckNotification::MythCheckNotification
MythCheckNotification(const QString &Title, const QString &Author, const QString &Details=QString())
Definition: mythnotification.cpp:354
MythNotification::MythNotification
MythNotification(Type nType, void *Parent=nullptr)
Definition: mythnotification.cpp:17
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:125
MythNotification::SetVisibility
void SetVisibility(VNMask Visibility)
Define a bitmask of Visibility.
Definition: mythnotification.cpp:154
MythBusyNotification::MythBusyNotification
MythBusyNotification(const QString &Title, const QString &Author, const QString &Details=QString())
Definition: mythnotification.cpp:361
MythNotification::ToStringList
void ToStringList()
Definition: mythnotification.cpp:168
MythMediaNotification::MythMediaNotification
MythMediaNotification(Type nType, const QImage &Image, const DMAP &Metadata, float Progress, const QString &DurationText)
Definition: mythnotification.cpp:296
MythNotification::m_id
int m_id
Definition: mythnotification.h:113
MythNotification::m_priority
Priority m_priority
Definition: mythnotification.h:121
MythNotification::SetId
void SetId(int Id)
Contains the application registration id.
Definition: mythnotification.cpp:85
MythNotification::Warning
static Type Warning
Definition: mythnotification.h:34
MythNotification::m_metadata
DMAP m_metadata
Definition: mythnotification.h:118
DMAP
QMap< QString, QString > DMAP
Definition: mythnotification.h:24
MythErrorNotification::MythErrorNotification
MythErrorNotification(const QString &Title, const QString &Author, const QString &Details=QString())
Definition: mythnotification.cpp:340
MythNotification::Error
static Type Error
Definition: mythnotification.h:33
Priority
Definition: channelsettings.cpp:191
MythNotification::SetStyle
void SetStyle(const QString &Style)
Contains an alternative notification style. Should a style be defined, the Notification Center will a...
Definition: mythnotification.cpp:146
MythPlaybackNotification
Definition: mythnotification.h:146