6 #include <QCoreApplication>
32 #define LOC QString("ThemeChooser: ")
33 #define LOC_WARN QString("ThemeChooser, Warning: ")
34 #define LOC_ERR QString("ThemeChooser, Error: ")
43 const QString &srcFile,
const QString &destDir) :
58 QCoreApplication::postEvent(
m_parent, me);
75 m_fullPreviewShowing(
false),
76 m_fullPreviewStateType(NULL),
77 m_fullScreenName(NULL),
78 m_fullScreenPreview(NULL),
79 m_refreshDownloadableThemes(
false),
80 m_downloadTheme(NULL),
81 m_downloadState(dsIdle),
97 return s1.fileName().toLower() < s2.fileName().toLower();
129 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Cannot load screen 'themechooser'");
149 QString MythVersion = MYTH_SOURCE_PATH;
150 QStringList themesSeen;
152 themes.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
153 themes.setSorting(QDir::Name | QDir::IgnoreCase);
156 if (MythVersion ==
"master")
157 MythVersion =
"trunk";
159 if (MythVersion !=
"trunk")
161 MythVersion = MYTH_BINARY_VERSION;
162 MythVersion.replace(QRegExp(
"\\.[0-9]{8,}.*"),
"");
167 for( QFileInfoList::iterator it =
m_infoList.begin();
173 themesSeen << (*it).fileName();
179 QFileInfoList sharedThemes = themes.entryInfoList();
180 for( QFileInfoList::iterator it = sharedThemes.begin();
181 it != sharedThemes.end();
184 if ((!themesSeen.contains((*it).fileName())) &&
188 themesSeen << (*it).fileName();
194 remoteThemesFile.append(
"/tmp/themes.zip");
195 QString themeSite = QString(
"%1/%2")
197 "http://themes.mythtv.org/themes/repository")).arg(MythVersion);
198 QDir remoteThemesDir(
GetMythUI()->GetThemeCacheDir()
199 .append(
"/themechooser/").append(MythVersion));
201 int downloadFailures =
205 QFileInfo finfo(remoteThemesFile);
206 if (finfo.lastModified().toUTC() <
209 LOG(VB_GUI, LOG_INFO,
LOC +
210 QString(
"%1 is over 10 minutes old, forcing "
211 "remote theme list download").arg(remoteThemesFile));
215 if (!remoteThemesDir.exists())
218 else if (downloadFailures < 2)
220 LOG(VB_GUI, LOG_INFO,
LOC +
221 QString(
"%1 does not exist, forcing remote theme "
222 "list download").arg(remoteThemesFile));
230 QString
url = themeSite;
231 url.append(
"/themes.zip");
233 destdir.append(
"/themechooser");
234 QString versiondir = QString(
"%1/%2").arg(destdir).arg(MythVersion);
242 if (!result || !
extractZIP(remoteThemesFile, destdir))
244 QFile::remove(remoteThemesFile);
253 (remoteThemesDir.exists()))
257 LOG(VB_GUI, LOG_INFO,
LOC +
258 QString(
"%1 and %2 exist, using cached remote themes list")
259 .arg(remoteThemesFile).arg(remoteThemesDir.absolutePath()));
261 QString themesPath = remoteThemesDir.absolutePath();
262 themes.setPath(themesPath);
264 QFileInfoList downloadableThemes = themes.entryInfoList();
265 for( QFileInfoList::iterator it = downloadableThemes.begin();
266 it != downloadableThemes.end();
269 QString dirName = (*it).fileName();
271 QString remoteDir = themeSite;
272 remoteDir.append(
"/").append(dirName);
273 QString localDir = themes.absolutePath();
274 localDir.append(
"/").append(dirName);
276 if (themesSeen.contains(dirName))
278 ThemeInfo remoteTheme((*it).absoluteFilePath());
281 themeName = remoteTheme.GetName();
283 int rmtMaj = remoteTheme.GetMajorVersion();
284 int rmtMin = remoteTheme.GetMinorVersion();
285 int locMaj = localTheme->GetMajorVersion();
286 int locMin = localTheme->GetMinorVersion();
288 if ((rmtMaj > locMaj) ||
289 ((rmtMaj == locMaj) &&
297 QFileInfo finfo(remoteTheme.GetPreviewPath());
299 remoteDir.append(
"/").append(finfo.fileName()),
300 localDir.append(
"/").append(finfo.fileName()),
304 else if ((rmtMaj == locMaj) &&
315 themeName = remoteTheme->
GetName();
316 themesSeen << dirName;
322 remoteDir.append(
"/").append(finfo.fileName()),
323 localDir.append(
"/").append(finfo.fileName()),
343 for( QFileInfoList::iterator it =
m_infoList.begin();
347 QFileInfo &theme = *it;
356 QString buttonText = QString(
"%1 %2.%3")
373 QHash<QString, QString> infomap;
374 themeinfo->
ToMap(infomap);
376 item->
SetData(qVariantFromValue(themeinfo));
379 QFileInfo fInfo(thumbnail);
382 thumbnail = thumbnail.append(
".thumb.jpg");
386 curThemeInfo = themeinfo;
404 if (theme.fileName() ==
"default" || theme.fileName() ==
"default-wide")
409 themeinfo =
new ThemeInfo(theme.absoluteFilePath());
411 themeinfo =
new ThemeInfo(theme.filePath());
434 QString label = tr(
"Theme Chooser Menu");
437 new MythDialogBox(label, popupStack,
"themechoosermenupopup");
502 bool handled =
false;
506 for (
int i = 0; i < actions.size() && !handled; ++i)
508 QString
action = actions[i];
511 if (action ==
"MENU")
513 else if (action ==
"DELETE")
515 else if ((action ==
"ESCAPE") &&
577 LOG(VB_GUI, LOG_INFO,
LOC +
"Forcing remote theme list refresh");
600 QFileInfo qfile(downloadURL);
601 QString baseName = qfile.fileName();
607 .split(
";", QString::SkipEmptyParts);
609 downloadURL.replace(tokens[0], tokens[1]);
610 LOG(VB_FILE, LOG_WARNING,
LOC +
611 QString(
"Theme download URL overridden from %1 to %2.")
612 .arg(origURL).arg(downloadURL));
622 QString localFile =
GetConfDir() +
"/tmp/" + baseName;
643 QHash<QString, QString> infomap;
644 info->
ToMap(infomap);
648 if (preview.exists())
660 if (preview.exists())
698 progressBar->
SetUsed(bytesReceived);
707 QStringList tokens = me->
Message().split(
" ", QString::SkipEmptyParts);
709 if (tokens.isEmpty())
712 if (tokens[0] ==
"DOWNLOAD_FILE")
716 (tokens.size() != 2) ||
721 if (tokens[1] ==
"UPDATE")
725 else if (tokens[1] ==
"FINISHED")
727 bool remoteFileIsLocal =
false;
728 int fileSize = args[2].toInt();
729 int errorCode = args[4].toInt();
739 if ((errorCode == 0) &&
745 file.setFile(localFile);
749 remoteFileIsLocal =
true;
765 ShowOkPopup(tr(
"ERROR downloading theme package on master backend."));
773 if ((errorCode == 0) &&
781 extractThread,
"ThemeExtract");
783 if (!remoteFileIsLocal)
792 ShowOkPopup(tr(
"ERROR downloading theme package from master backend."));
797 else if ((me->
Message() ==
"THEME_INSTALLED") &&
804 QFile::remove(args[0]);
806 QString
event = QString(
"THEME_INSTALLED PATH %1")
829 ShowOkPopup(tr(
"Error, unable to find current theme."));
835 ShowOkPopup(tr(
"%1 is not a user-installed theme and can not "
836 "be deleted.").arg(info->
GetName()));
848 (!dirname.startsWith(
GetMythUI()->GetThemeCacheDir())))
856 dir.setFilter(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
857 QFileInfoList list = dir.entryInfoList();
858 QFileInfoList::const_iterator it = list.begin();
861 while (it != list.end())
864 if (fi->isFile() && !fi->isSymLink())
866 QFile::remove(fi->absoluteFilePath());
868 else if (fi->isDir() && !fi->isSymLink())
880 m_updateTimer(new QTimer(this))
896 "remotethemes/themes.zip",
920 if (
GetMythUI()->GetCurrentLocation(
false,
true) !=
"mainmenu")
925 QString remoteThemeDir =
928 QString(
"remotethemes/%1/%2")
933 QString infoXML = remoteThemeDir;
934 infoXML.append(
"/themeinfo.xml");
941 LOG(VB_GENERAL, LOG_ERR,
942 QString(
"ThemeUpdateChecker::checkForUpdate(): "
943 "Unable to create ThemeInfo for %1")
951 LOG(VB_GENERAL, LOG_ERR,
952 "ThemeUpdateChecker::checkForUpdate(): "
953 "Unable to create ThemeInfo for current theme");
962 if ((rmtMaj > locMaj) ||
963 ((rmtMaj == locMaj) &&
967 QString(
"%1-%2.%3").arg(
GetMythUI()->GetThemeName())
968 .arg(rmtMaj).arg(rmtMin);
974 (currentLocation ==
"mainmenu"))
977 m_newVersion = QString(
"%1.%2").arg(rmtMaj).arg(rmtMin);
982 QString message = tr(
"Version %1 of the %2 theme is now "
983 "available in the Theme Chooser. The "
984 "currently installed version is %3.")