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
17const QEvent::Type MythNotification::kNew = static_cast<QEvent::Type>(QEvent::registerEventType());
18const QEvent::Type MythNotification::kUpdate = static_cast<QEvent::Type>(QEvent::registerEventType());
19const QEvent::Type MythNotification::kInfo = static_cast<QEvent::Type>(QEvent::registerEventType());
20const QEvent::Type MythNotification::kError = static_cast<QEvent::Type>(QEvent::registerEventType());
21const QEvent::Type MythNotification::kWarning = static_cast<QEvent::Type>(QEvent::registerEventType());
22const QEvent::Type MythNotification::kCheck = static_cast<QEvent::Type>(QEvent::registerEventType());
23const QEvent::Type MythNotification::kBusy = static_cast<QEvent::Type>(QEvent::registerEventType());
24
25MythNotification::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
38MythNotification::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{
45}
46
47MythNotification::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{
54}
55
57 : MythEvent(nType, "NOTIFICATION"),
58 m_metadata(std::move(Metadata))
59{
61}
62
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{
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
107{
108 m_parent = Parent;
109}
110
116{
117 m_fullScreen = FullScreen;
118 ToStringList();
119}
120
123void MythNotification::SetDescription(const QString& Description)
124{
125 m_description = Description;
126 ToStringList();
127}
128
134{
135 m_metadata = MetaData;
136 ToStringList();
137}
138
144void MythNotification::SetDuration(std::chrono::seconds Duration)
145{
146 m_duration = Duration;
147 ToStringList();
148}
149
154void 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))
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
230QString 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
236MythNotification::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;
243}
244
246 : MythNotification(nType),
247 m_image(std::move(Image))
248{
249}
250
252 : MythNotification(nType),
253 m_imagePath(std::move(ImagePath))
254{
255}
256
257MythImageNotification::MythImageNotification(Type nType, QImage Image, const DMAP& Metadata)
258 : MythNotification(nType, Metadata),
259 m_image(std::move(Image))
260{
261}
262
263MythImageNotification::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
305MythMediaNotification::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
313MythMediaNotification::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
321MythMediaNotification::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
329MythMediaNotification::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
349MythErrorNotification::MythErrorNotification(const QString& Title, const QString& Author,
350 const QString& Details)
351 : MythNotification(kError, Title, Author, Details)
352{
353 SetDuration(10s);
354}
355
356MythWarningNotification::MythWarningNotification(const QString& Title, const QString& Author,
357 const QString& Details)
358 : MythNotification(kWarning, Title, Author, Details)
359{
360 SetDuration(10s);
361}
362
363MythCheckNotification::MythCheckNotification(const QString& Title, const QString& Author,
364 const QString& Details)
365 : MythNotification(kCheck, Title, Author, Details)
366{
367 SetDuration(5s);
368}
369
370MythBusyNotification::MythBusyNotification(const QString& Title, const QString& Author,
371 const QString& Details)
372 : MythNotification(kBusy, Title, Author, Details)
373{
374}
Event details.
Definition: zmdefines.h:28
MythBusyNotification(const QString &Title, const QString &Author, const QString &Details=QString())
MythCheckNotification(const QString &Title, const QString &Author, const QString &Details=QString())
MythErrorNotification(const QString &Title, const QString &Author, const QString &Details=QString())
This class is used as a container for messages.
Definition: mythevent.h:17
QStringList m_extradata
Definition: mythevent.h:102
MythEvent * clone() const override
MythImageNotification(Type nType, QImage Image)
MythEvent * clone() const override
MythMediaNotification(Type nType, const QImage &Image, const DMAP &Metadata, float Progress, const QString &DurationText)
static const Type kCheck
void SetVisibility(VNMask nVisibility)
Define a bitmask of Visibility.
void SetId(int Id)
Contains the application registration id.
void SetMetaData(const DMAP &MetaData)
metadata of the notification. In DMAP format. DMAP can contains various information such as artist,...
static const Type kNew
static const Type kUpdate
static Type TypeFromString(const QString &Type)
void SetDescription(const QString &Description)
Contains a short description of the notification.
MythNotification(Type nType, void *Parent=nullptr)
void SetFullScreen(bool FullScreen)
A notification may request to be displayed in full screen, this request may not be fullfilled should ...
static const Type kError
static const Type kInfo
std::chrono::seconds m_duration
void SetStyle(const QString &sStyle)
Contains an alternative notification style. Should a style be defined, the Notification Center will a...
MythEvent * clone() const override
static const Type kWarning
void SetParent(void *Parent)
Contains the parent address. Required if id is set Id provided must match the parent address as provi...
void SetDuration(std::chrono::seconds Duration)
Contains a duration during which the notification will be displayed for. The duration is informative ...
static const Type kBusy
void SetPriority(Priority nPriority)
Reserved for future use, not implemented at this stage.
MythEvent * clone() const override
static QString StringFromSeconds(std::chrono::seconds Time)
Create a string in the format HH:mm:ss from a duration in seconds.
MythPlaybackNotification(Type nType, float Progress, QString ProgressText)
MythWarningNotification(const QString &Title, const QString &Author, const QString &Details=QString())
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
unsigned int VNMask
QMap< QString, QString > DMAP
MBASE_PUBLIC QStringList ToStringList(const FileSystemInfoList &fsInfos)
STL namespace.