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 // libmyth headers
10 #include "mythlogging.h"
11 #include "mythnotification.h"
12 
13 #include <QCoreApplication>
14 
15 QEvent::Type MythNotification::New =
16  (QEvent::Type) QEvent::registerEventType();
17 QEvent::Type MythNotification::Update =
18  (QEvent::Type) QEvent::registerEventType();
19 QEvent::Type MythNotification::Info =
20  (QEvent::Type) QEvent::registerEventType();
21 QEvent::Type MythNotification::Error =
22  (QEvent::Type) QEvent::registerEventType();
23 QEvent::Type MythNotification::Warning =
24  (QEvent::Type) QEvent::registerEventType();
25 QEvent::Type MythNotification::Check =
26  (QEvent::Type) QEvent::registerEventType();
27 QEvent::Type MythNotification::Busy =
28  (QEvent::Type) QEvent::registerEventType();
29 
31 {
32  m_id = id;
33  // default registered notification is to not expire
34  if (m_id > 0 && m_duration == 0)
35  {
36  m_duration = -1;
37  }
38 }
39 
41 {
42  m_extradata.clear();
43 
44  m_extradata << QString::number(Type())
45  << QString::number(m_fullScreen)
46  << m_description
47  << QString::number(m_duration)
48  << m_style
49  << QString::number(m_visibility)
50  << QString::number(m_priority)
51  << m_metadata.value("minm")
52  << m_metadata.value("asar")
53  << m_metadata.value("asal")
54  << m_metadata.value("asfm");
55 }
56 
58 {
59  if (m_extradata.size() != 11)
60  {
61  LOG(VB_GENERAL, LOG_ERR,
62  QString("MythNotification::FromStringList called with %1 items, "
63  "expecting 11. '%2'")
64  .arg(m_extradata.size()).arg(m_extradata.join(",")));
65  return false;
66  }
67 
68  QStringList::const_iterator Istr = m_extradata.begin();
69 
70  Type type = static_cast<Type>((*Istr++).toInt());
71  if (type != Type())
72  {
73  LOG(VB_GENERAL, LOG_ERR,
74  QString("MythNotification::FromStringList called with type '%1' "
75  "in StringList, expected '%2' as set in constructor.")
76  .arg(type).arg(Type()));
77  return false;
78  }
79  m_fullScreen = (*Istr++).toInt();
80  m_description = *Istr++;
81  m_duration = (*Istr++).toInt();
82  m_style = *Istr++;
83  m_visibility = static_cast<VNMask>((*Istr++).toInt());
84  m_priority = static_cast<Priority>((*Istr++).toInt());
85  m_metadata["minm"] = *Istr++;
86  m_metadata["asar"] = *Istr++;
87  m_metadata["asal"] = *Istr++;
88  m_metadata["asfm"] = *Istr++;
89 
90  return true;
91 }
92 
93 
102 {
103  int hour = time / 3600;
104  int minute = (time - hour * 3600) / 60;
105  int seconds = time - hour * 3600 - minute * 60;
106  QString str;
107 
108  if (hour)
109  {
110  str += QString("%1:").arg(hour);
111  }
112  if (minute < 10)
113  {
114  str += "0";
115  }
116  str += QString("%1:").arg(minute);
117  if (seconds < 10)
118  {
119  str += "0";
120  }
121  str += QString::number(seconds);
122  return str;
123 }
124 
125 MythNotification::Type MythNotification::TypeFromString(const QString &type)
126 {
127  if (type == "error")
128  {
130  }
131  else if (type == "warning")
132  {
134  }
135  else if (type == "check")
136  {
138  }
139  else if (type == "busy")
140  {
141  return MythNotification::Busy;
142  }
143  else
144  {
145  return MythNotification::New;
146  }
147 }
void SetId(int id)
Optional MythNotification elements.
static QString stringFromSeconds(int time)
stringFromSeconds:
static Type Warning
bool FromStringList(void)
static Type TypeFromString(const QString &type)
return Type object from type name
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
QStringList m_extradata
Definition: mythevent.h:80
static Type Update