19#include "ui_thememanager.h"
30#include <QtCoreVersion>
35 , m_preferences(preferences)
38 ui->listWidget->setLayoutDirection(Qt::LeftToRight);
40 ui->remove->setIcon(QIcon::fromTheme(
QSL(
"edit-delete")));
49 for (
const QString &path : themePaths) {
51 const QStringList list = dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
52 for (
const QString &name : list) {
53 Theme themeInfo = parseTheme(dir.absoluteFilePath(name) + QLatin1Char(
'/'), name);
54 if (!themeInfo.isValid) {
58 auto* item =
new QListWidgetItem(ui->listWidget);
59 item->setText(themeInfo.name);
60 item->setIcon(themeInfo.icon);
61 item->setData(Qt::UserRole, name);
63 if (m_activeTheme == name) {
64 ui->listWidget->setCurrentItem(item);
67 ui->listWidget->addItem(item);
71 connect(ui->listWidget, &QListWidget::currentItemChanged,
this, &ThemeManager::currentChanged);
73 connect(ui->remove, &QPushButton::clicked,
this, &ThemeManager::removeTheme);
78void ThemeManager::showLicense()
80 QListWidgetItem* currentItem = ui->listWidget->currentItem();
85 Theme currentTheme = m_themeHash[currentItem->data(Qt::UserRole).toString()];
88 v->setText(currentTheme.license);
92void ThemeManager::removeTheme()
94 QListWidgetItem* currentItem = ui->listWidget->currentItem();
98 Theme currentTheme = m_themeHash[currentItem->data(Qt::UserRole).toString()];
100 const auto button = QMessageBox::warning(
this, tr(
"Confirmation"),
101 tr(
"Are you sure you want to remove '%1'?").arg(currentTheme.name),
102 QMessageBox::Yes | QMessageBox::No);
103 if (button != QMessageBox::Yes) {
107 QDir(currentTheme.themePath).removeRecursively();
111void ThemeManager::currentChanged()
113 QListWidgetItem* currentItem = ui->listWidget->currentItem();
118 Theme currentTheme = m_themeHash[currentItem->data(Qt::UserRole).toString()];
120 ui->name->setText(currentTheme.name);
121 ui->author->setText(currentTheme.author);
122 ui->description->setText(currentTheme.description);
123 ui->license->setHidden(currentTheme.license.isEmpty());
124 ui->remove->setEnabled(QFileInfo(currentTheme.themePath).isWritable());
127ThemeManager::Theme ThemeManager::parseTheme(
const QString &path,
const QString &name)
130 info.isValid =
false;
132 if (!QFile(path + QStringLiteral(
"main.css")).exists() || !QFile(path +
QSL(
"metadata.desktop")).exists()) {
133 info.isValid =
false;
138 info.name = metadata.name();
139 info.description = metadata.comment();
140 info.author = metadata.value(
QSL(
"X-Falkon-Author")).toString();
141 info.themePath = path.chopped(1);
143 const QString iconName = metadata.icon();
144 if (!iconName.isEmpty()) {
145 if (QFileInfo::exists(path + iconName)) {
146 info.icon = QIcon(path + iconName);
148 info.icon = QIcon::fromTheme(iconName);
152 const QString licensePath = metadata.value(
QSL(
"X-Falkon-License")).toString();
153 if (!licensePath.isEmpty() && QFileInfo::exists(path + licensePath)) {
157 if (info.name.isEmpty() || m_themeHash.contains(name)) {
162 m_themeHash.insert(name, info);
168 QListWidgetItem* currentItem = ui->listWidget->currentItem();
175 settings.
setValue(
QSL(
"activeTheme"), currentItem->data(Qt::UserRole));
static QStringList allPaths(Path type)
void beginGroup(const QString &prefix)
QVariant value(const QString &key, const QVariant &defaultValue=QVariant())
void setValue(const QString &key, const QVariant &defaultValue=QVariant())
ThemeManager(QWidget *parent, Preferences *preferences)
#define DEFAULT_THEME_NAME