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