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 == 0s)
90  m_duration = -1s;
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 
136 void MythNotification::SetDuration(std::chrono::seconds Duration)
137 {
138  m_duration = Duration;
139  ToStringList();
140 }
141 
146 void MythNotification::SetStyle(const QString& sStyle)
147 {
148  m_style = sStyle;
149  ToStringList();
150 }
151 
155 {
156  m_visibility = nVisibility;
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.count())
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 = std::chrono::seconds((*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 
222 QString MythPlaybackNotification::StringFromSeconds(std::chrono::seconds Time)
223 {
224  QTime ltime = QTime(0,0).addSecs(Time.count());
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  std::chrono::seconds Duration,
285  int Position)
286  : MythNotification(nType),
287  m_progress(static_cast<float>(Position) / static_cast<float>(Duration.count())),
288  m_progressText(StringFromSeconds(Duration))
289 {
290 }
291 
293 {
294  return new MythPlaybackNotification(*this);
295 }
296 
297 MythMediaNotification::MythMediaNotification(Type nType, const QImage& Image, const DMAP& Metadata,
298  float Progress, const QString& DurationText)
299  : MythNotification(nType, Metadata),
300  MythImageNotification(nType, Image),
301  MythPlaybackNotification(nType, Progress, DurationText)
302 {
303 }
304 
305 MythMediaNotification::MythMediaNotification(Type nType, const QImage& Image, const DMAP& Metadata,
306  std::chrono::seconds Duration, int Position)
307  : MythNotification(nType, Metadata),
308  MythImageNotification(nType, Image),
309  MythPlaybackNotification(nType, Duration, Position)
310 {
311 }
312 
313 MythMediaNotification::MythMediaNotification(Type nType, const QString& Image, const DMAP& Metadata,
314  float Progress, const QString& DurationText)
315  : MythNotification(nType, Metadata),
316  MythImageNotification(nType, Image),
317  MythPlaybackNotification(nType, Progress, DurationText)
318 {
319 }
320 
321 MythMediaNotification::MythMediaNotification(Type nType, const QString& Image, const DMAP& Metadata,
322  std::chrono::seconds Duration, int Position)
323  : MythNotification(nType, Metadata),
324  MythImageNotification(nType, Image),
325  MythPlaybackNotification(nType, Duration, Position)
326 {
327 }
328 
330  : MythNotification(Notification),
331  MythImageNotification(Notification),
332  MythPlaybackNotification(Notification)
333 {
334 }
335 
337 {
338  return new MythMediaNotification(*this);
339 }
340 
341 MythErrorNotification::MythErrorNotification(const QString& Title, const QString& Author,
342  const QString& Details)
343  : MythNotification(Error, Title, Author, Details)
344 {
345  SetDuration(10s);
346 }
347 
348 MythWarningNotification::MythWarningNotification(const QString& Title, const QString& Author,
349  const QString& Details)
350  : MythNotification(Warning, Title, Author, Details)
351 {
352  SetDuration(10s);
353 }
354 
355 MythCheckNotification::MythCheckNotification(const QString& Title, const QString& Author,
356  const QString& Details)
357  : MythNotification(Check, Title, Author, Details)
358 {
359  SetDuration(5s);
360 }
361 
362 MythBusyNotification::MythBusyNotification(const QString& Title, const QString& Author,
363  const QString& Details)
364  : MythNotification(Busy, Title, Author, Details)
365 {
366 }
MythNotification::Busy
static Type Busy
Definition: mythnotification.h:38
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:136
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::SetPriority
void SetPriority(Priority nPriority)
Reserved for future use, not implemented at this stage.
Definition: mythnotification.cpp:162
MythNotification
Definition: mythnotification.h:29
MythNotification::m_fullScreen
bool m_fullScreen
Definition: mythnotification.h:122
MythImageNotification::clone
MythEvent * clone() const override
Definition: mythnotification.cpp:261
MythEvent::m_extradata
QStringList m_extradata
Definition: mythevent.h:101
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::SetVisibility
void SetVisibility(VNMask nVisibility)
Define a bitmask of Visibility.
Definition: mythnotification.cpp:154
MythNotification::TypeFromString
static Type TypeFromString(const QString &Type)
Definition: mythnotification.cpp:228
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:146
MythPlaybackNotification::MythPlaybackNotification
MythPlaybackNotification(Type nType, float Progress, QString ProgressText)
Definition: mythnotification.cpp:266
MythImageNotification
Definition: mythnotification.h:131
MythImageNotification::MythImageNotification
MythImageNotification(Type nType, QImage Image)
Definition: mythnotification.cpp:237
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:336
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:107
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:27
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:348
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:222
mythnotification.h
MythNotification::Check
static Type Check
Definition: mythnotification.h:37
MythMediaNotification
Definition: mythnotification.h:180
MythNotification::New
static Type New
Definition: mythnotification.h:32
MythPlaybackNotification::clone
MythEvent * clone() const override
Definition: mythnotification.cpp:292
MythNotification::FromStringList
bool FromStringList()
Definition: mythnotification.cpp:184
MythCheckNotification::MythCheckNotification
MythCheckNotification(const QString &Title, const QString &Author, const QString &Details=QString())
Definition: mythnotification.cpp:355
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
MythBusyNotification::MythBusyNotification
MythBusyNotification(const QString &Title, const QString &Author, const QString &Details=QString())
Definition: mythnotification.cpp:362
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:297
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::SetId
void SetId(int Id)
Contains the application registration id.
Definition: mythnotification.cpp:85
MythNotification::Warning
static Type Warning
Definition: mythnotification.h:36
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:341
MythNotification::Error
static Type Error
Definition: mythnotification.h:35
Priority
Definition: channelsettings.cpp:191
MythPlaybackNotification
Definition: mythnotification.h:153