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

Port theme metadata to standard desktop file

This makes it possible to translate it.
This commit is contained in:
David Rosca 2018-02-11 11:19:27 +01:00
parent 4a1d807fec
commit 9db6745ee5
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
15 changed files with 154 additions and 56 deletions

View File

@ -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

View File

@ -22,10 +22,10 @@
#include "datapaths.h"
#include "licenseviewer.h"
#include "preferences.h"
#include "desktopfile.h"
#include "mainapplication.h"
#include <QDir>
#include <QTextBrowser>
#include <QRegularExpression>
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;

View File

@ -52,8 +52,7 @@ private:
QIcon icon;
QString name;
QString author;
QString shortDescription;
QString longDescription;
QString description;
QString license;
};

View File

@ -0,0 +1,55 @@
/* ============================================================
* Falkon - Qt web browser
* Copyright (C) 2018 David Rosca <nowrep@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
* ============================================================ */
#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);
}

View File

@ -0,0 +1,37 @@
/* ============================================================
* Falkon - Qt web browser
* Copyright (C) 2018 David Rosca <nowrep@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
* ============================================================ */
#pragma once
#include <QSettings>
#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;
};

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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