diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index f5d6de5b4..118617dc5 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -196,6 +196,7 @@ set(SRCS ${SRCS} tools/closedwindowsmanager.cpp tools/colors.cpp tools/delayedfilewatcher.cpp + tools/desktopfile.cpp tools/docktitlebarwidget.cpp tools/emptynetworkreply.cpp tools/enhancedmenu.cpp diff --git a/src/lib/preferences/thememanager.cpp b/src/lib/preferences/thememanager.cpp index bbeccbebe..beedc64cc 100644 --- a/src/lib/preferences/thememanager.cpp +++ b/src/lib/preferences/thememanager.cpp @@ -22,10 +22,10 @@ #include "datapaths.h" #include "licenseviewer.h" #include "preferences.h" +#include "desktopfile.h" +#include "mainapplication.h" #include -#include -#include ThemeManager::ThemeManager(QWidget* parent, Preferences* preferences) : QWidget() @@ -53,7 +53,7 @@ ThemeManager::ThemeManager(QWidget* parent, Preferences* preferences) } QListWidgetItem* item = new QListWidgetItem(ui->listWidget); - item->setText(themeInfo.name + "\n" + themeInfo.shortDescription); + item->setText(themeInfo.name); item->setIcon(themeInfo.icon); item->setData(Qt::UserRole, name); @@ -96,7 +96,7 @@ void ThemeManager::currentChanged() ui->name->setText(currentTheme.name); ui->author->setText(currentTheme.author); - ui->descirption->setText(currentTheme.longDescription); + ui->descirption->setText(currentTheme.description); ui->license->setHidden(currentTheme.license.isEmpty()); } @@ -105,52 +105,34 @@ ThemeManager::Theme ThemeManager::parseTheme(const QString &path, const QString Theme info; info.isValid = false; - if (!QFile(path + "main.css").exists() || !QFile(path + "theme.info").exists()) { + if (!QFile(path + "main.css").exists() || !QFile(path + "metadata.desktop").exists()) { info.isValid = false; return info; } - if (QFile(path + "theme.png").exists()) { - info.icon = QIcon(path + "theme.png"); - } - else { - info.icon = QIcon(":icons/preferences/style-default.png"); + DesktopFile metadata(path + QSL("metadata.desktop")); + info.name = metadata.name(mApp->currentLanguage()); + info.description = metadata.comment(mApp->currentLanguage()); + info.author = metadata.value(QSL("X-Falkon-Author")).toString(); + + const QString iconName = metadata.icon(); + if (!iconName.isEmpty()) { + if (QFileInfo::exists(path + iconName)) { + info.icon = QIcon(path + iconName); + } else { + info.icon = QIcon::fromTheme(iconName); + } } - if (QFile(path + "theme.license").exists()) { - info.license = QzTools::readAllFileContents(path + "theme.license"); - } - - QString theme_info = QzTools::readAllFileContents(path + "theme.info"); - - QRegularExpression rx(QSL("Name:(.*)\\n")); - QRegularExpressionMatch match = rx.match(theme_info); - if (match.hasMatch()) { - info.name = match.captured(1).trimmed(); + const QString licensePath = metadata.value(QSL("X-Falkon-License")).toString(); + if (!licensePath.isEmpty() && QFileInfo::exists(path + licensePath)) { + info.license = QzTools::readAllFileContents(path + licensePath); } if (info.name.isEmpty() || m_themeHash.contains(info.name)) { return info; } - rx.setPattern(QSL("Author:(.*)\\n")); - match = rx.match(theme_info); - if (match.hasMatch()) { - info.author = match.captured(1).trimmed(); - } - - rx.setPattern(QSL("Short Description:(.*)\\n")); - match = rx.match(theme_info); - if (match.hasMatch()) { - info.shortDescription = match.captured(1).trimmed(); - } - - rx.setPattern(QSL("Long Description:(.*)\\n")); - match = rx.match(theme_info); - if (match.hasMatch()) { - info.longDescription = match.captured(1).trimmed(); - } - info.isValid = true; m_themeHash.insert(name, info); return info; diff --git a/src/lib/preferences/thememanager.h b/src/lib/preferences/thememanager.h index e479f7b4a..7e4247c10 100644 --- a/src/lib/preferences/thememanager.h +++ b/src/lib/preferences/thememanager.h @@ -52,8 +52,7 @@ private: QIcon icon; QString name; QString author; - QString shortDescription; - QString longDescription; + QString description; QString license; }; diff --git a/src/lib/tools/desktopfile.cpp b/src/lib/tools/desktopfile.cpp new file mode 100644 index 000000000..75577180a --- /dev/null +++ b/src/lib/tools/desktopfile.cpp @@ -0,0 +1,55 @@ +/* ============================================================ +* Falkon - Qt web browser +* Copyright (C) 2018 David Rosca +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* ============================================================ */ +#include "desktopfile.h" + +DesktopFile::DesktopFile(const QString &filePath) + : m_settings(filePath, QSettings::IniFormat) +{ + m_settings.beginGroup(QSL("Desktop Entry")); +} + +QString DesktopFile::name(const QString &locale) const +{ + return value(QSL("Name"), locale).toString(); +} + +QString DesktopFile::comment(const QString &locale) const +{ + return value(QSL("Comment"), locale).toString(); +} + +QString DesktopFile::type() const +{ + return value(QSL("Type")).toString(); +} + +QString DesktopFile::icon() const +{ + return value(QSL("Icon")).toString(); +} + +QVariant DesktopFile::value(const QString &key, const QString &locale) const +{ + if (!locale.isEmpty()) { + const QString localeKey = QSL("%1[%2]").arg(key, locale); + if (m_settings.contains(localeKey)) { + return m_settings.value(localeKey); + } + } + return m_settings.value(key); +} diff --git a/src/lib/tools/desktopfile.h b/src/lib/tools/desktopfile.h new file mode 100644 index 000000000..fcff07f28 --- /dev/null +++ b/src/lib/tools/desktopfile.h @@ -0,0 +1,37 @@ +/* ============================================================ +* Falkon - Qt web browser +* Copyright (C) 2018 David Rosca +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* ============================================================ */ +#pragma once + +#include + +#include "qzcommon.h" + +class FALKON_EXPORT DesktopFile +{ +public: + explicit DesktopFile(const QString &filePath); + + QString name(const QString &locale = QString()) const; + QString comment(const QString &locale = QString()) const; + QString type() const; + QString icon() const; + QVariant value(const QString &key, const QString &locale = QString()) const; + +private: + QSettings m_settings; +}; diff --git a/themes/chrome/theme.license b/themes/chrome/license.txt similarity index 100% rename from themes/chrome/theme.license rename to themes/chrome/license.txt diff --git a/themes/chrome/metadata.desktop b/themes/chrome/metadata.desktop new file mode 100644 index 000000000..647815c93 --- /dev/null +++ b/themes/chrome/metadata.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Name=Chrome +Comment=Chrome like theme for Falkon based on Firefox Chromifox theme + +Icon=theme.png +Type=Service + +X-Falkon-Author=David Rosca +X-Falkon-Email=nowrep@gmail.com +X-Falkon-License=license.txt diff --git a/themes/chrome/theme.info b/themes/chrome/theme.info deleted file mode 100644 index 4d31e06b1..000000000 --- a/themes/chrome/theme.info +++ /dev/null @@ -1,4 +0,0 @@ -Name: Chrome -Author: David Rosca -Short Description: Chrome like theme -Long Description: Chrome like theme for Falkon based on Firefox Chromifox theme diff --git a/themes/linux/metadata.desktop b/themes/linux/metadata.desktop new file mode 100644 index 000000000..e8bbffb63 --- /dev/null +++ b/themes/linux/metadata.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Name=Linux +Comment=Default simple theme for Linux using native widget style and some basic icons from desktop icon set + +Icon=theme.png +Type=Service + +X-Falkon-Author=David Rosca +X-Falkon-Email=nowrep@gmail.com +X-Falkon-License=GPLv3 diff --git a/themes/linux/theme.info b/themes/linux/theme.info deleted file mode 100644 index 915914fbf..000000000 --- a/themes/linux/theme.info +++ /dev/null @@ -1,4 +0,0 @@ -Name: Linux Default -Author: David Rosca -Short Description: Native theme -Long Description: Default simple theme for Linux using native widget style and some basic icons from desktop icon set diff --git a/themes/mac/theme.license b/themes/mac/license.txt similarity index 100% rename from themes/mac/theme.license rename to themes/mac/license.txt diff --git a/themes/mac/metadata.desktop b/themes/mac/metadata.desktop new file mode 100644 index 000000000..30b87ed4e --- /dev/null +++ b/themes/mac/metadata.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Name=Mac +Comment=Mac like theme for Falkon based on Firefox Mac OS X theme + +Icon=theme.png +Type=Service + +X-Falkon-Author=David Rosca +X-Falkon-Email=nowrep@gmail.com +X-Falkon-License=license.txt diff --git a/themes/mac/theme.info b/themes/mac/theme.info deleted file mode 100644 index d18afe640..000000000 --- a/themes/mac/theme.info +++ /dev/null @@ -1,4 +0,0 @@ -Name: Mac -Author: David Rosca -Short Description: Mac like theme -Long Description: Mac like theme for Falkon based on Firefox Mac OS X theme diff --git a/themes/windows/metadata.desktop b/themes/windows/metadata.desktop new file mode 100644 index 000000000..3f60b8f86 --- /dev/null +++ b/themes/windows/metadata.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Name=Windows +Comment=Windows like theme based on Material design + +Icon=theme.png +Type=Service + +X-Falkon-Author=David Rosca +X-Falkon-Email=nowrep@gmail.com +X-Falkon-License=GPLv3 diff --git a/themes/windows/theme.info b/themes/windows/theme.info deleted file mode 100644 index 9461fd6a5..000000000 --- a/themes/windows/theme.info +++ /dev/null @@ -1,4 +0,0 @@ -Name: Windows -Author: David Rosca -Short Description: Windows default theme -Long Description: Windows default theme for Falkon based on Firefox Strata Aero theme. This theme supports transparent background on Windows 7