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
17ThemeInfo::ThemeInfo(const QString& theme)
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 {
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 {
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
248{
249 return m_aspect == "16:9" || m_aspect == "16:10";
250}
251
253{
254#ifdef Q_OS_ANDROID
255 return m_theme.fileName().remove("assets:/");
256#else
257 return m_theme.fileName();
258#endif
259}
260
261void ThemeInfo::ToMap(InfoMap &infoMap) const
262{
263 infoMap["description"] = m_description;
264 infoMap["name"] = m_name;
265 infoMap["basetheme"] = m_baseTheme;
266 infoMap["aspect"] = m_aspect;
267 infoMap["resolution"] = QString("%1x%2").arg(m_baseres.width())
268 .arg(m_baseres.height());
269 infoMap["errata"] = m_errata;
270 infoMap["majorversion"] = QString::number(m_majorver);
271 infoMap["minorversion"] = QString::number(m_minorver);
272 infoMap["version"] = QString("%1.%2").arg(m_majorver).arg(m_minorver);
273
274 infoMap["authorname"] = m_authorName;
275 infoMap["authoremail"] = m_authorEmail;
276}
bool download(const QString &url, const QString &dest, bool reload=false)
Downloads a URL to a file in blocking mode.
QString m_errata
Definition: themeinfo.h:58
QSize m_baseres
Definition: themeinfo.h:54
QFileInfo m_theme
Definition: themeinfo.h:50
QString m_authorName
Definition: themeinfo.h:62
bool parseThemeInfo()
Definition: themeinfo.cpp:51
ThemeInfo(const QString &theme)
Definition: themeinfo.cpp:17
QString m_themeurl
Definition: themeinfo.h:49
QString m_authorEmail
Definition: themeinfo.h:63
void ToMap(InfoMap &infoMap) const
Definition: themeinfo.cpp:261
QString m_aspect
Definition: themeinfo.h:53
QString m_downloadurl
Definition: themeinfo.h:65
bool IsWide() const
Definition: themeinfo.cpp:247
QString m_previewpath
Definition: themeinfo.h:56
int m_type
Definition: themeinfo.h:52
QString GetDirectoryName() const
Definition: themeinfo.cpp:252
int m_minorver
Definition: themeinfo.h:60
QString m_description
Definition: themeinfo.h:57
int m_majorver
Definition: themeinfo.h:59
QString m_name
Definition: themeinfo.h:55
QString m_baseTheme
Definition: themeinfo.h:51
static QString getFirstText(QDomElement &element)
static QString parseText(QDomElement &element)
MythDownloadManager * GetMythDownloadManager(void)
Gets the pointer to the MythDownloadManager singleton.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
#define LOC
Definition: themeinfo.cpp:15
@ THEME_OSD
Definition: themeinfo.h:16
@ THEME_UI
Definition: themeinfo.h:15
@ THEME_MENU
Definition: themeinfo.h:17
#define VERBOSE_XML(type, level, filename, element, msg)
Definition: xmlparsebase.h:15