Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[localthemedaemonclient] theme inheritance
  • Loading branch information
sledges committed Aug 12, 2013
1 parent 1ca5b43 commit e8e2034
Showing 1 changed file with 45 additions and 13 deletions.
58 changes: 45 additions & 13 deletions src/meego/themedaemon/mlocalthemedaemonclient.cpp
Expand Up @@ -42,6 +42,7 @@
#include <QCoreApplication>
#include <QDebug>
#include <QDir>
#include <QSettings>

MLocalThemeDaemonClient::MLocalThemeDaemonClient(const QString &testPath, QObject *parent) :
MAbstractThemeDaemonClient(parent),
Expand Down Expand Up @@ -73,20 +74,55 @@ MLocalThemeDaemonClient::MLocalThemeDaemonClient(const QString &testPath, QObjec
}

if (testMode == false) {
// we must always fallback to blanco for assets we don't provide in the custom theme
themeRoots += themeRoot + QDir::separator() + QLatin1String("blanco") + QDir::separator() + QLatin1String("meegotouch");

#ifdef HAVE_MLITE
// custom theme will be searched after blanco, meaning it will override assets from there
qDebug() << Q_FUNC_INFO << "Theme: " << themeItem.value("blanco").toString();
themeRoots += themeRoot + QDir::separator() + themeItem.value("blanco").toString() + QDir::separator() + QLatin1String("meegotouch");
#else
QString themeName;
# if !defined(THEME_NAME)
# define THEME_NAME "blanco"
# endif
#ifdef HAVE_MLITE
qDebug() << Q_FUNC_INFO << "Theme: " << themeItem.value(THEME_NAME).toString();
themeName = themeItem.value(THEME_NAME).toString();
#else
qDebug() << Q_FUNC_INFO << "Theme: " << THEME_NAME << " (hardcoded)";
themeRoots += themeRoot + QDir::separator() + QLatin1String(THEME_NAME) + QDir::separator() + QLatin1String("meegotouch");
themeName = QLatin1String(THEME_NAME);
#endif

// find out the inheritance chain for the new theme
QString nextTheme = themeName;
QSet<QString> inheritanceChain;

while (true) {
// Determine whether this is an m theme:
const QString themeIndexFileName = themeRoot + QDir::separator() + nextTheme + QDir::separator() + "index.theme";

// it needs to be a valid ini file
const QSettings themeIndexFile(themeIndexFileName, QSettings::IniFormat);
if (themeIndexFile.status() != QSettings::NoError) {
qWarning() << Q_FUNC_INFO << "Theme" << themeName << "does not exist! Falling back to " << THEME_NAME;
break;
}

// we need to have X-MeeGoTouch-Metatheme group in index.theme
if (!themeIndexFile.childGroups().contains(QString("X-MeeGoTouch-Metatheme"))) {
qWarning() << Q_FUNC_INFO << "Theme" << themeName << " is invalid";
break;
}

inheritanceChain.insert(nextTheme);
// the paths should be stored in reverse order than in the inheritance chain
themeRoots.prepend(themeRoot + QDir::separator() + nextTheme + QDir::separator() + QLatin1String("meegotouch"));

QString parentTheme = themeIndexFile.value("X-MeeGoTouch-Metatheme/X-Inherits", "").toString();

if (parentTheme.isEmpty()) {
break;
}
nextTheme = parentTheme;

// check that there are no cyclic dependencies
if (inheritanceChain.contains(parentTheme)) {
qFatal("%s: cyclic dependency in theme: %s", Q_FUNC_INFO, themeName.toUtf8().constData());
}
}
} else {
qDebug() << Q_FUNC_INFO << "Theme: test mode: " << themeRoot;
themeRoots += themeRoot;
Expand All @@ -97,13 +133,9 @@ MLocalThemeDaemonClient::MLocalThemeDaemonClient(const QString &testPath, QObjec
themeRoots[i].truncate(themeRoots.at(i).length() - 1);

buildHash(themeRoots.at(i) + QDir::separator() + "icons", QStringList() << "*.svg" << "*.png" << "*.jpg");
buildHash(themeRoots.at(i) + QDir::separator() + "images" + QDir::separator() + "theme", QStringList() << "*.png" << "*.jpg");
buildHash(themeRoots.at(i) + QDir::separator() + "images" + QDir::separator() + "backgrounds", QStringList() << "*.png" << "*.jpg");
}

m_imageDirNodes.append(ImageDirNode("icons" , QStringList() << ".svg" << ".png" << ".jpg"));
m_imageDirNodes.append(ImageDirNode(QLatin1String("images") + QDir::separator() + QLatin1String("theme"), QStringList() << ".png" << ".jpg"));
m_imageDirNodes.append(ImageDirNode(QLatin1String("images") + QDir::separator() + QLatin1String("backgrounds"), QStringList() << ".png" << ".jpg"));

qDebug() << "LocalThemeDaemonClient: Looking for assets in" << themeRoots;
}
Expand Down

0 comments on commit e8e2034

Please sign in to comment.