mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
ThemeManager: Implement removing locally installed themes
This commit is contained in:
parent
b5988bbe1f
commit
f792104be5
|
@ -26,15 +26,17 @@
|
||||||
#include "mainapplication.h"
|
#include "mainapplication.h"
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
ThemeManager::ThemeManager(QWidget* parent, Preferences* preferences)
|
ThemeManager::ThemeManager(QWidget* parent, Preferences* preferences)
|
||||||
: QWidget()
|
: QWidget(parent)
|
||||||
, ui(new Ui::ThemeManager)
|
, ui(new Ui::ThemeManager)
|
||||||
, m_preferences(preferences)
|
, m_preferences(preferences)
|
||||||
{
|
{
|
||||||
ui->setupUi(parent);
|
ui->setupUi(parent);
|
||||||
ui->listWidget->setLayoutDirection(Qt::LeftToRight);
|
ui->listWidget->setLayoutDirection(Qt::LeftToRight);
|
||||||
ui->license->hide();
|
ui->license->hide();
|
||||||
|
ui->remove->setIcon(QIcon::fromTheme(QSL("edit-delete")));
|
||||||
|
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings.beginGroup("Themes");
|
settings.beginGroup("Themes");
|
||||||
|
@ -67,6 +69,7 @@ ThemeManager::ThemeManager(QWidget* parent, Preferences* preferences)
|
||||||
|
|
||||||
connect(ui->listWidget, &QListWidget::currentItemChanged, this, &ThemeManager::currentChanged);
|
connect(ui->listWidget, &QListWidget::currentItemChanged, this, &ThemeManager::currentChanged);
|
||||||
connect(ui->license, &ClickableLabel::clicked, this, &ThemeManager::showLicense);
|
connect(ui->license, &ClickableLabel::clicked, this, &ThemeManager::showLicense);
|
||||||
|
connect(ui->remove, &QPushButton::clicked, this, &ThemeManager::removeTheme);
|
||||||
|
|
||||||
currentChanged();
|
currentChanged();
|
||||||
}
|
}
|
||||||
|
@ -85,6 +88,25 @@ void ThemeManager::showLicense()
|
||||||
v->show();
|
v->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ThemeManager::removeTheme()
|
||||||
|
{
|
||||||
|
QListWidgetItem* currentItem = ui->listWidget->currentItem();
|
||||||
|
if (!currentItem) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Theme currentTheme = m_themeHash[currentItem->data(Qt::UserRole).toString()];
|
||||||
|
|
||||||
|
const auto button = QMessageBox::warning(this, tr("Confirmation"),
|
||||||
|
tr("Are you sure you want to remove '%1'?").arg(currentTheme.name),
|
||||||
|
QMessageBox::Yes | QMessageBox::No);
|
||||||
|
if (button != QMessageBox::Yes) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDir(currentTheme.themePath).removeRecursively();
|
||||||
|
delete currentItem;
|
||||||
|
}
|
||||||
|
|
||||||
void ThemeManager::currentChanged()
|
void ThemeManager::currentChanged()
|
||||||
{
|
{
|
||||||
QListWidgetItem* currentItem = ui->listWidget->currentItem();
|
QListWidgetItem* currentItem = ui->listWidget->currentItem();
|
||||||
|
@ -98,6 +120,7 @@ void ThemeManager::currentChanged()
|
||||||
ui->author->setText(currentTheme.author);
|
ui->author->setText(currentTheme.author);
|
||||||
ui->description->setText(currentTheme.description);
|
ui->description->setText(currentTheme.description);
|
||||||
ui->license->setHidden(currentTheme.license.isEmpty());
|
ui->license->setHidden(currentTheme.license.isEmpty());
|
||||||
|
ui->remove->setEnabled(QFileInfo(currentTheme.themePath).isWritable());
|
||||||
}
|
}
|
||||||
|
|
||||||
ThemeManager::Theme ThemeManager::parseTheme(const QString &path, const QString &name)
|
ThemeManager::Theme ThemeManager::parseTheme(const QString &path, const QString &name)
|
||||||
|
@ -114,6 +137,7 @@ ThemeManager::Theme ThemeManager::parseTheme(const QString &path, const QString
|
||||||
info.name = metadata.name();
|
info.name = metadata.name();
|
||||||
info.description = metadata.comment();
|
info.description = metadata.comment();
|
||||||
info.author = metadata.value(QSL("X-Falkon-Author")).toString();
|
info.author = metadata.value(QSL("X-Falkon-Author")).toString();
|
||||||
|
info.themePath = path.chopped(1);
|
||||||
|
|
||||||
const QString iconName = metadata.icon();
|
const QString iconName = metadata.icon();
|
||||||
if (!iconName.isEmpty()) {
|
if (!iconName.isEmpty()) {
|
||||||
|
|
|
@ -45,6 +45,7 @@ public:
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void currentChanged();
|
void currentChanged();
|
||||||
void showLicense();
|
void showLicense();
|
||||||
|
void removeTheme();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Theme {
|
struct Theme {
|
||||||
|
@ -54,6 +55,7 @@ private:
|
||||||
QString author;
|
QString author;
|
||||||
QString description;
|
QString description;
|
||||||
QString license;
|
QString license;
|
||||||
|
QString themePath;
|
||||||
};
|
};
|
||||||
|
|
||||||
Theme parseTheme(const QString &path, const QString &name);
|
Theme parseTheme(const QString &path, const QString &name);
|
||||||
|
|
|
@ -137,6 +137,40 @@
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="Line" name="line">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="remove">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Remove</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user