MythTV  master
themeinfo.cpp
Go to the documentation of this file.
1 
2 // Own header
3 #include "themeinfo.h"
4 
5 // QT headers
6 #include <QCoreApplication>
7 #include <QFile>
8 #include <QDir>
9 #include <QDomElement>
10 
11 // MythTV headers
14 
15 #define LOC QString("ThemeInfo: ")
16 
17 ThemeInfo::ThemeInfo(const QString& theme)
18  :XMLParseBase()
19 {
20  QString themeNoTrailingSlash = theme;
21  if (themeNoTrailingSlash.endsWith('/'))
22  {
23  themeNoTrailingSlash.chop(1);
24  }
25  m_theme = QFileInfo(themeNoTrailingSlash);
26 
27  if (m_theme.exists())
28  {
29  // since all the usages have a / inserted, remove the one in the url
30  m_themeurl = m_theme.absoluteFilePath();
31  }
32  else
33  {
34  m_themeurl = theme;
35  }
36 
37  // since all the usages have a / insterted, remove the one in the url
38  if (m_themeurl.endsWith('/'))
39  {
40  m_themeurl.chop(1);
41  }
42 
43  if (!parseThemeInfo())
44  {
45  LOG(VB_GENERAL, LOG_ERR, LOC +
46  QString("The theme (%1) is missing a themeinfo.xml file.")
47  .arg(m_themeurl));
48  }
49 }
50 
52 {
53 
54  QDomDocument doc;
55 
56  if ((m_themeurl.startsWith("http://")) ||
57  (m_themeurl.startsWith("https://")) ||
58  (m_themeurl.startsWith("ftp://")) ||
59  (m_themeurl.startsWith("myth://")))
60  {
61  QByteArray data;
63  "/themeinfo.xml", &data);
64  if (!ok)
65  return false;
66 
67  if (!doc.setContent(data))
68  {
69  LOG(VB_GENERAL, LOG_ERR, LOC +
70  QString("Unable to parse themeinfo.xml for %1")
71  .arg(m_themeurl));
72  return false;
73  }
74  }
75  else
76  {
77  QFile f(m_themeurl + "/themeinfo.xml");
78 
79  if (!f.open(QIODevice::ReadOnly))
80  {
81  LOG(VB_GENERAL, LOG_WARNING, LOC +
82  QString("Unable to open themeinfo.xml for %1")
83  .arg(f.fileName()));
84  return false;
85  }
86 
87  if (!doc.setContent(&f))
88  {
89  LOG(VB_GENERAL, LOG_ERR, LOC +
90  QString("Unable to parse themeinfo.xml for %1")
91  .arg(f.fileName()));
92 
93  f.close();
94  return false;
95  }
96  f.close();
97  }
98 
99  QDomElement docElem = doc.documentElement();
100 
101  for (QDomNode n = docElem.firstChild(); !n.isNull();
102  n = n.nextSibling())
103  {
104  QDomElement e = n.toElement();
105  if (!e.isNull())
106  {
107  if (e.tagName() == "name")
108  {
109  m_name = getFirstText(e);
110  }
111  else if (e.tagName() == "basetheme")
112  {
114  }
115  else if (e.tagName() == "aspect")
116  {
117  m_aspect = getFirstText(e);
118  }
119  else if (e.tagName() == "baseres")
120  {
121  QString size = getFirstText(e);
122  m_baseres = QSize(size.section('x', 0, 0).toInt(),
123  size.section('x', 1, 1).toInt());
124  }
125  else if (e.tagName() == "types")
126  {
127  for (QDomNode child = e.firstChild(); !child.isNull();
128  child = child.nextSibling())
129  {
130  QDomElement ce = child.toElement();
131  if (!ce.isNull())
132  {
133  if (ce.tagName() == "type")
134  {
135  QString type = getFirstText(ce);
136 
137  if (type == "UI")
138  {
139  m_type |= THEME_UI;
140  }
141  else if (type == "OSD")
142  {
143  m_type |= THEME_OSD;
144  }
145  else if (type == "Menu")
146  {
147  m_type |= THEME_MENU;
148  }
149  else
150  {
151  VERBOSE_XML(VB_GENERAL, LOG_ERR,
152  m_theme.fileName(), ce,
153  "Invalid theme type");
154  }
155  }
156  }
157  }
158  }
159  else if (e.tagName() == "version")
160  {
161  for (QDomNode child = e.firstChild(); !child.isNull();
162  child = child.nextSibling())
163  {
164  QDomElement ce = child.toElement();
165  if (!ce.isNull())
166  {
167  if (ce.tagName() == "major")
168  {
169  m_majorver = getFirstText(ce).toInt();
170  }
171  else if (ce.tagName() == "minor")
172  {
173  m_minorver = getFirstText(ce).toInt();
174  }
175  }
176  }
177  }
178  else if (e.tagName() == "author")
179  {
180  for (QDomNode child = e.firstChild(); !child.isNull();
181  child = child.nextSibling())
182  {
183  QDomElement ce = child.toElement();
184  if (!ce.isNull())
185  {
186  if (ce.tagName() == "name")
187  {
189  }
190  else if (ce.tagName() == "email")
191  {
193  }
194  }
195  }
196  }
197  else if (e.tagName() == "detail")
198  {
199  for (QDomNode child = e.firstChild(); !child.isNull();
200  child = child.nextSibling())
201  {
202  QDomElement ce = child.toElement();
203  if (!ce.isNull())
204  {
205  if (ce.tagName() == "thumbnail")
206  {
207  if (ce.attribute("name") == "preview")
208  {
209  QString thumbnail = getFirstText(ce);
210  m_previewpath = m_themeurl + '/' + thumbnail;
211  }
212  }
213  else if (ce.tagName() == "description")
214  {
215  m_description = QCoreApplication::translate("ThemeUI",
216  parseText(ce).toUtf8());
217  }
218  else if (ce.tagName() == "errata")
219  {
220  m_errata = QCoreApplication::translate("ThemeUI",
221  parseText(ce).toUtf8());
222  }
223  }
224  }
225  }
226  else if (e.tagName() == "downloadinfo")
227  {
228  for (QDomNode child = e.firstChild(); !child.isNull();
229  child = child.nextSibling())
230  {
231  QDomElement ce = child.toElement();
232  if (!ce.isNull())
233  {
234  if (ce.tagName() == "url")
235  {
237  }
238  }
239  }
240  }
241  }
242  }
243 
244  return true;
245 }
246 
247 bool ThemeInfo::IsWide() const
248 {
249  return m_aspect == "16:9" || m_aspect == "16:10";
250 }
251 
252 void ThemeInfo::ToMap(InfoMap &infoMap) const
253 {
254  infoMap["description"] = m_description;
255  infoMap["name"] = m_name;
256  infoMap["basetheme"] = m_baseTheme;
257  infoMap["aspect"] = m_aspect;
258  infoMap["resolution"] = QString("%1x%2").arg(m_baseres.width())
259  .arg(m_baseres.height());
260  infoMap["errata"] = m_errata;
261  infoMap["majorversion"] = QString::number(m_majorver);
262  infoMap["minorversion"] = QString::number(m_minorver);
263  infoMap["version"] = QString("%1.%2").arg(m_majorver).arg(m_minorver);
264 
265  infoMap["authorname"] = m_authorName;
266  infoMap["authoremail"] = m_authorEmail;
267 }
ThemeInfo::m_themeurl
QString m_themeurl
Definition: themeinfo.h:49
ThemeInfo::m_name
QString m_name
Definition: themeinfo.h:55
ThemeInfo::m_minorver
int m_minorver
Definition: themeinfo.h:60
THEME_OSD
@ THEME_OSD
Definition: themeinfo.h:16
XMLParseBase
Definition: xmlparsebase.h:23
ThemeInfo::m_errata
QString m_errata
Definition: themeinfo.h:58
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
XMLParseBase::parseText
static QString parseText(QDomElement &element)
Definition: xmlparsebase.cpp:315
InfoMap
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
mythlogging.h
themeinfo.h
ThemeInfo::m_previewpath
QString m_previewpath
Definition: themeinfo.h:56
ThemeInfo::IsWide
bool IsWide() const
Definition: themeinfo.cpp:247
VERBOSE_XML
#define VERBOSE_XML(type, level, filename, element, msg)
Definition: xmlparsebase.h:15
XMLParseBase::getFirstText
static QString getFirstText(QDomElement &element)
Definition: xmlparsebase.cpp:52
MythDownloadManager::download
bool download(const QString &url, const QString &dest, bool reload=false)
Downloads a URL to a file in blocking mode.
Definition: mythdownloadmanager.cpp:430
ThemeInfo::m_authorName
QString m_authorName
Definition: themeinfo.h:62
ThemeInfo::m_majorver
int m_majorver
Definition: themeinfo.h:59
LOC
#define LOC
Definition: themeinfo.cpp:15
THEME_MENU
@ THEME_MENU
Definition: themeinfo.h:17
ThemeInfo::m_aspect
QString m_aspect
Definition: themeinfo.h:53
ThemeInfo::m_type
int m_type
Definition: themeinfo.h:52
ThemeInfo::m_authorEmail
QString m_authorEmail
Definition: themeinfo.h:63
ThemeInfo::m_description
QString m_description
Definition: themeinfo.h:57
ThemeInfo::ThemeInfo
ThemeInfo(const QString &theme)
Definition: themeinfo.cpp:17
ThemeInfo::m_baseres
QSize m_baseres
Definition: themeinfo.h:54
ThemeInfo::parseThemeInfo
bool parseThemeInfo()
Definition: themeinfo.cpp:51
mythdownloadmanager.h
ThemeInfo::m_downloadurl
QString m_downloadurl
Definition: themeinfo.h:65
THEME_UI
@ THEME_UI
Definition: themeinfo.h:15
ThemeInfo::ToMap
void ToMap(InfoMap &infoMap) const
Definition: themeinfo.cpp:252
ThemeInfo::m_baseTheme
QString m_baseTheme
Definition: themeinfo.h:51
ThemeInfo::m_theme
QFileInfo m_theme
Definition: themeinfo.h:50
GetMythDownloadManager
MythDownloadManager * GetMythDownloadManager(void)
Gets the pointer to the MythDownloadManager singleton.
Definition: mythdownloadmanager.cpp:145