1
mirror of https://invent.kde.org/network/falkon.git synced 2024-09-21 09:42:10 +02:00

Add possibility to load themes from profile directories.

Themes are now loaded from the following directories:
 1. Directory "themes" in user profile
 2. Directory "themes" in root profile directory
 3. System data path
      > /usr/share/qupzilla/themes on Linux
      > $EXECUTABLE_DIR/themes on Windows

Closes #928
This commit is contained in:
nowrep 2013-06-07 12:59:22 +02:00
parent 82701235ee
commit f149aaebf2
5 changed files with 109 additions and 64 deletions

View File

@ -9,6 +9,7 @@ Version 1.5.0
* added KWallet password backend plugin
* added Gnome-Keyring password backend plugin
* added StatusBar Icons plugin that adds extra icons to statusbar
* themes can now be loaded from profile directories
* pagescreen can now save output into number of formats, including PDF
* proxy exceptions now supports wildcards (*, ?)
* cancel upload when trying to upload non-readable files

View File

@ -338,53 +338,13 @@ void MainApplication::loadSettings()
settings.beginGroup("Themes");
QString activeTheme = settings.value("activeTheme", DEFAULT_THEME_NAME).toString();
settings.endGroup();
m_activeThemePath = THEMESDIR + activeTheme + "/";
QFile cssFile(m_activeThemePath + "main.css");
cssFile.open(QFile::ReadOnly);
QString css = cssFile.readAll();
cssFile.close();
#ifdef QZ_WS_X11
if (QFile(m_activeThemePath + "linux.css").exists()) {
cssFile.setFileName(m_activeThemePath + "linux.css");
cssFile.open(QFile::ReadOnly);
css.append(cssFile.readAll());
cssFile.close();
}
#endif
#ifdef Q_OS_MAC
if (QFile(m_activeThemePath + "mac.css").exists()) {
cssFile.setFileName(m_activeThemePath + "mac.css");
cssFile.open(QFile::ReadOnly);
css.append(cssFile.readAll());
cssFile.close();
}
#endif
#if defined(Q_OS_WIN) || defined(Q_OS_OS2)
if (QFile(m_activeThemePath + "windows.css").exists()) {
cssFile.setFileName(m_activeThemePath + "windows.css");
cssFile.open(QFile::ReadOnly);
css.append(cssFile.readAll());
cssFile.close();
}
#endif
//RTL Support
//loading 'rtl.css' when layout is right to left!
if (isRightToLeft() && QFile(m_activeThemePath + "rtl.css").exists()) {
cssFile.setFileName(m_activeThemePath + "rtl.css");
cssFile.open(QFile::ReadOnly);
css.append(cssFile.readAll());
cssFile.close();
}
QString relativePath = QDir::current().relativeFilePath(m_activeThemePath);
css.replace(QzRegExp("url\\s*\\(\\s*([^\\*:\\);]+)\\s*\\)", Qt::CaseSensitive),
QString("url(%1\\1)").arg(relativePath + "/"));
setStyleSheet(css);
loadTheme(activeTheme);
// Create global QWebSettings object
webSettings();
//Web browsing settings
// Web browsing settings
settings.beginGroup("Web-Browser-Settings");
if (!m_isPrivateSession) {
@ -707,6 +667,81 @@ void MainApplication::connectDatabase()
m_databaseConnected = true;
}
void MainApplication::loadTheme(const QString &name)
{
// Themes are loaded from the following directories:
// 1. Directory "themes" in user profile
// 2. Directory "themes" in root profile directory
// 3. System data path
// > /usr/share/qupzilla/themes on Linux
// > $EXECUTABLE_DIR/themes on Windows
QStringList themePaths;
themePaths << m_activeProfil + "themes/"
<< PROFILEDIR + "themes/"
<< THEMESDIR;
foreach (const QString &path, themePaths) {
const QString &theme = path + name + "/";
if (QFile::exists(theme + "main.css")) {
m_activeThemePath = theme;
break;
}
}
if (m_activeThemePath.isEmpty()) {
qWarning("Cannot load theme '%s'!", qPrintable(name));
m_activeThemePath = THEMESDIR + DEFAULT_THEME_NAME + "/";
}
QFile cssFile(m_activeThemePath + "main.css");
cssFile.open(QFile::ReadOnly);
QString css = cssFile.readAll();
cssFile.close();
#ifdef QZ_WS_X11
if (QFile(m_activeThemePath + "linux.css").exists()) {
cssFile.setFileName(m_activeThemePath + "linux.css");
cssFile.open(QFile::ReadOnly);
css.append(cssFile.readAll());
cssFile.close();
}
#endif
#ifdef Q_OS_MAC
if (QFile(m_activeThemePath + "mac.css").exists()) {
cssFile.setFileName(m_activeThemePath + "mac.css");
cssFile.open(QFile::ReadOnly);
css.append(cssFile.readAll());
cssFile.close();
}
#endif
#if defined(Q_OS_WIN) || defined(Q_OS_OS2)
if (QFile(m_activeThemePath + "windows.css").exists()) {
cssFile.setFileName(m_activeThemePath + "windows.css");
cssFile.open(QFile::ReadOnly);
css.append(cssFile.readAll());
cssFile.close();
}
#endif
// RTL Support
// Loading 'rtl.css' when layout is right to left!
if (isRightToLeft() && QFile(m_activeThemePath + "rtl.css").exists()) {
cssFile.setFileName(m_activeThemePath + "rtl.css");
cssFile.open(QFile::ReadOnly);
css.append(cssFile.readAll());
cssFile.close();
}
QString relativePath = QDir::current().relativeFilePath(m_activeThemePath);
css.replace(QzRegExp("url\\s*\\(\\s*([^\\*:\\);]+)\\s*\\)", Qt::CaseSensitive),
QString("url(%1\\1)").arg(relativePath + "/"));
setStyleSheet(css);
}
void MainApplication::translateApp()
{
Settings settings;

View File

@ -160,6 +160,7 @@ private slots:
private:
enum PostLaunchAction { OpenDownloadManager, OpenNewTab };
void loadTheme(const QString &name);
void translateApp();
void restoreOtherWindows();

View File

@ -40,11 +40,16 @@ ThemeManager::ThemeManager(QWidget* parent, Preferences* preferences)
m_activeTheme = settings.value("activeTheme", DEFAULT_THEME_NAME).toString();
settings.endGroup();
QDir themeDir(mApp->THEMESDIR);
QStringList list = themeDir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
QStringList themePaths;
themePaths << mApp->currentProfilePath() + "themes/"
<< mApp->PROFILEDIR + "themes/"
<< mApp->THEMESDIR;
foreach (const QString &path, themePaths) {
QDir dir(path);
QStringList list = dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
foreach (const QString &name, list) {
Theme themeInfo = parseTheme(name);
Theme themeInfo = parseTheme(dir.absoluteFilePath(name) + "/", name);
if (!themeInfo.isValid) {
continue;
}
@ -60,6 +65,7 @@ ThemeManager::ThemeManager(QWidget* parent, Preferences* preferences)
ui->listWidget->addItem(item);
}
}
connect(ui->listWidget, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(currentChanged()));
connect(ui->license, SIGNAL(clicked(QPoint)), this, SLOT(showLicense()));
@ -96,12 +102,10 @@ void ThemeManager::currentChanged()
ui->license->setHidden(currentTheme.license.isEmpty());
}
ThemeManager::Theme ThemeManager::parseTheme(const QString &name)
ThemeManager::Theme ThemeManager::parseTheme(const QString &path, const QString &name)
{
Theme info;
info.name = name;
QString path = mApp->THEMESDIR + name + "/";
if (!QFile(path + "main.css").exists() || !QFile(path + "theme.info").exists()) {
info.isValid = false;
return info;
@ -127,6 +131,10 @@ ThemeManager::Theme ThemeManager::parseTheme(const QString &name)
info.name = rx.cap(1).trimmed();
}
if (info.name.isEmpty() || m_themeHash.contains(info.name)) {
return info;
}
rx.setPattern("Author:(.*)\\n");
rx.indexIn(theme_info);
if (rx.captureCount() == 1) {

View File

@ -57,7 +57,7 @@ private:
QString license;
};
Theme parseTheme(const QString &name);
Theme parseTheme(const QString &path, const QString &name);
Ui::ThemeManager* ui;
Preferences* m_preferences;