mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
Port theme metadata to standard desktop file
This makes it possible to translate it.
This commit is contained in:
parent
4a1d807fec
commit
9db6745ee5
|
@ -196,6 +196,7 @@ set(SRCS ${SRCS}
|
||||||
tools/closedwindowsmanager.cpp
|
tools/closedwindowsmanager.cpp
|
||||||
tools/colors.cpp
|
tools/colors.cpp
|
||||||
tools/delayedfilewatcher.cpp
|
tools/delayedfilewatcher.cpp
|
||||||
|
tools/desktopfile.cpp
|
||||||
tools/docktitlebarwidget.cpp
|
tools/docktitlebarwidget.cpp
|
||||||
tools/emptynetworkreply.cpp
|
tools/emptynetworkreply.cpp
|
||||||
tools/enhancedmenu.cpp
|
tools/enhancedmenu.cpp
|
||||||
|
|
|
@ -22,10 +22,10 @@
|
||||||
#include "datapaths.h"
|
#include "datapaths.h"
|
||||||
#include "licenseviewer.h"
|
#include "licenseviewer.h"
|
||||||
#include "preferences.h"
|
#include "preferences.h"
|
||||||
|
#include "desktopfile.h"
|
||||||
|
#include "mainapplication.h"
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QTextBrowser>
|
|
||||||
#include <QRegularExpression>
|
|
||||||
|
|
||||||
ThemeManager::ThemeManager(QWidget* parent, Preferences* preferences)
|
ThemeManager::ThemeManager(QWidget* parent, Preferences* preferences)
|
||||||
: QWidget()
|
: QWidget()
|
||||||
|
@ -53,7 +53,7 @@ ThemeManager::ThemeManager(QWidget* parent, Preferences* preferences)
|
||||||
}
|
}
|
||||||
|
|
||||||
QListWidgetItem* item = new QListWidgetItem(ui->listWidget);
|
QListWidgetItem* item = new QListWidgetItem(ui->listWidget);
|
||||||
item->setText(themeInfo.name + "\n" + themeInfo.shortDescription);
|
item->setText(themeInfo.name);
|
||||||
item->setIcon(themeInfo.icon);
|
item->setIcon(themeInfo.icon);
|
||||||
item->setData(Qt::UserRole, name);
|
item->setData(Qt::UserRole, name);
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ void ThemeManager::currentChanged()
|
||||||
|
|
||||||
ui->name->setText(currentTheme.name);
|
ui->name->setText(currentTheme.name);
|
||||||
ui->author->setText(currentTheme.author);
|
ui->author->setText(currentTheme.author);
|
||||||
ui->descirption->setText(currentTheme.longDescription);
|
ui->descirption->setText(currentTheme.description);
|
||||||
ui->license->setHidden(currentTheme.license.isEmpty());
|
ui->license->setHidden(currentTheme.license.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,52 +105,34 @@ ThemeManager::Theme ThemeManager::parseTheme(const QString &path, const QString
|
||||||
Theme info;
|
Theme info;
|
||||||
info.isValid = false;
|
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;
|
info.isValid = false;
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (QFile(path + "theme.png").exists()) {
|
DesktopFile metadata(path + QSL("metadata.desktop"));
|
||||||
info.icon = QIcon(path + "theme.png");
|
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);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
info.icon = QIcon(":icons/preferences/style-default.png");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (QFile(path + "theme.license").exists()) {
|
const QString licensePath = metadata.value(QSL("X-Falkon-License")).toString();
|
||||||
info.license = QzTools::readAllFileContents(path + "theme.license");
|
if (!licensePath.isEmpty() && QFileInfo::exists(path + licensePath)) {
|
||||||
}
|
info.license = QzTools::readAllFileContents(path + licensePath);
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info.name.isEmpty() || m_themeHash.contains(info.name)) {
|
if (info.name.isEmpty() || m_themeHash.contains(info.name)) {
|
||||||
return info;
|
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;
|
info.isValid = true;
|
||||||
m_themeHash.insert(name, info);
|
m_themeHash.insert(name, info);
|
||||||
return info;
|
return info;
|
||||||
|
|
|
@ -52,8 +52,7 @@ private:
|
||||||
QIcon icon;
|
QIcon icon;
|
||||||
QString name;
|
QString name;
|
||||||
QString author;
|
QString author;
|
||||||
QString shortDescription;
|
QString description;
|
||||||
QString longDescription;
|
|
||||||
QString license;
|
QString license;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
55
src/lib/tools/desktopfile.cpp
Normal file
55
src/lib/tools/desktopfile.cpp
Normal 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);
|
||||||
|
}
|
37
src/lib/tools/desktopfile.h
Normal file
37
src/lib/tools/desktopfile.h
Normal 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;
|
||||||
|
};
|
10
themes/chrome/metadata.desktop
Normal file
10
themes/chrome/metadata.desktop
Normal 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
|
|
@ -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
|
|
10
themes/linux/metadata.desktop
Normal file
10
themes/linux/metadata.desktop
Normal 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
|
|
@ -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
|
|
10
themes/mac/metadata.desktop
Normal file
10
themes/mac/metadata.desktop
Normal 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
|
|
@ -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
|
|
10
themes/windows/metadata.desktop
Normal file
10
themes/windows/metadata.desktop
Normal 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
|
|
@ -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
|
|
Loading…
Reference in New Issue
Block a user