mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 02:36:34 +01: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:
parent
82701235ee
commit
f149aaebf2
@ -9,6 +9,7 @@ Version 1.5.0
|
|||||||
* added KWallet password backend plugin
|
* added KWallet password backend plugin
|
||||||
* added Gnome-Keyring password backend plugin
|
* added Gnome-Keyring password backend plugin
|
||||||
* added StatusBar Icons plugin that adds extra icons to statusbar
|
* 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
|
* pagescreen can now save output into number of formats, including PDF
|
||||||
* proxy exceptions now supports wildcards (*, ?)
|
* proxy exceptions now supports wildcards (*, ?)
|
||||||
* cancel upload when trying to upload non-readable files
|
* cancel upload when trying to upload non-readable files
|
||||||
|
@ -338,53 +338,13 @@ void MainApplication::loadSettings()
|
|||||||
settings.beginGroup("Themes");
|
settings.beginGroup("Themes");
|
||||||
QString activeTheme = settings.value("activeTheme", DEFAULT_THEME_NAME).toString();
|
QString activeTheme = settings.value("activeTheme", DEFAULT_THEME_NAME).toString();
|
||||||
settings.endGroup();
|
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
|
loadTheme(activeTheme);
|
||||||
//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);
|
|
||||||
|
|
||||||
|
// Create global QWebSettings object
|
||||||
webSettings();
|
webSettings();
|
||||||
|
|
||||||
//Web browsing settings
|
// Web browsing settings
|
||||||
settings.beginGroup("Web-Browser-Settings");
|
settings.beginGroup("Web-Browser-Settings");
|
||||||
|
|
||||||
if (!m_isPrivateSession) {
|
if (!m_isPrivateSession) {
|
||||||
@ -707,6 +667,81 @@ void MainApplication::connectDatabase()
|
|||||||
m_databaseConnected = true;
|
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()
|
void MainApplication::translateApp()
|
||||||
{
|
{
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
@ -160,6 +160,7 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
enum PostLaunchAction { OpenDownloadManager, OpenNewTab };
|
enum PostLaunchAction { OpenDownloadManager, OpenNewTab };
|
||||||
|
|
||||||
|
void loadTheme(const QString &name);
|
||||||
void translateApp();
|
void translateApp();
|
||||||
void restoreOtherWindows();
|
void restoreOtherWindows();
|
||||||
|
|
||||||
|
@ -40,25 +40,31 @@ ThemeManager::ThemeManager(QWidget* parent, Preferences* preferences)
|
|||||||
m_activeTheme = settings.value("activeTheme", DEFAULT_THEME_NAME).toString();
|
m_activeTheme = settings.value("activeTheme", DEFAULT_THEME_NAME).toString();
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
QDir themeDir(mApp->THEMESDIR);
|
QStringList themePaths;
|
||||||
QStringList list = themeDir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
|
themePaths << mApp->currentProfilePath() + "themes/"
|
||||||
|
<< mApp->PROFILEDIR + "themes/"
|
||||||
|
<< mApp->THEMESDIR;
|
||||||
|
|
||||||
foreach (const QString &name, list) {
|
foreach (const QString &path, themePaths) {
|
||||||
Theme themeInfo = parseTheme(name);
|
QDir dir(path);
|
||||||
if (!themeInfo.isValid) {
|
QStringList list = dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
|
||||||
continue;
|
foreach (const QString &name, list) {
|
||||||
|
Theme themeInfo = parseTheme(dir.absoluteFilePath(name) + "/", name);
|
||||||
|
if (!themeInfo.isValid) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
QListWidgetItem* item = new QListWidgetItem(ui->listWidget);
|
||||||
|
item->setText(themeInfo.name + "\n" + themeInfo.shortDescription);
|
||||||
|
item->setIcon(themeInfo.icon);
|
||||||
|
item->setData(Qt::UserRole, name);
|
||||||
|
|
||||||
|
if (m_activeTheme == name) {
|
||||||
|
ui->listWidget->setCurrentItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->listWidget->addItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
QListWidgetItem* item = new QListWidgetItem(ui->listWidget);
|
|
||||||
item->setText(themeInfo.name + "\n" + themeInfo.shortDescription);
|
|
||||||
item->setIcon(themeInfo.icon);
|
|
||||||
item->setData(Qt::UserRole, name);
|
|
||||||
|
|
||||||
if (m_activeTheme == name) {
|
|
||||||
ui->listWidget->setCurrentItem(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
ui->listWidget->addItem(item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(ui->listWidget, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(currentChanged()));
|
connect(ui->listWidget, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(currentChanged()));
|
||||||
@ -96,12 +102,10 @@ void ThemeManager::currentChanged()
|
|||||||
ui->license->setHidden(currentTheme.license.isEmpty());
|
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;
|
Theme info;
|
||||||
info.name = name;
|
|
||||||
|
|
||||||
QString path = mApp->THEMESDIR + name + "/";
|
|
||||||
if (!QFile(path + "main.css").exists() || !QFile(path + "theme.info").exists()) {
|
if (!QFile(path + "main.css").exists() || !QFile(path + "theme.info").exists()) {
|
||||||
info.isValid = false;
|
info.isValid = false;
|
||||||
return info;
|
return info;
|
||||||
@ -127,6 +131,10 @@ ThemeManager::Theme ThemeManager::parseTheme(const QString &name)
|
|||||||
info.name = rx.cap(1).trimmed();
|
info.name = rx.cap(1).trimmed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (info.name.isEmpty() || m_themeHash.contains(info.name)) {
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
rx.setPattern("Author:(.*)\\n");
|
rx.setPattern("Author:(.*)\\n");
|
||||||
rx.indexIn(theme_info);
|
rx.indexIn(theme_info);
|
||||||
if (rx.captureCount() == 1) {
|
if (rx.captureCount() == 1) {
|
||||||
|
@ -57,7 +57,7 @@ private:
|
|||||||
QString license;
|
QString license;
|
||||||
};
|
};
|
||||||
|
|
||||||
Theme parseTheme(const QString &name);
|
Theme parseTheme(const QString &path, const QString &name);
|
||||||
|
|
||||||
Ui::ThemeManager* ui;
|
Ui::ThemeManager* ui;
|
||||||
Preferences* m_preferences;
|
Preferences* m_preferences;
|
||||||
|
Loading…
Reference in New Issue
Block a user