mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +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 <QDir>
|
||||
#include <QMessageBox>
|
||||
|
||||
ThemeManager::ThemeManager(QWidget* parent, Preferences* preferences)
|
||||
: QWidget()
|
||||
: QWidget(parent)
|
||||
, ui(new Ui::ThemeManager)
|
||||
, m_preferences(preferences)
|
||||
{
|
||||
ui->setupUi(parent);
|
||||
ui->listWidget->setLayoutDirection(Qt::LeftToRight);
|
||||
ui->license->hide();
|
||||
ui->remove->setIcon(QIcon::fromTheme(QSL("edit-delete")));
|
||||
|
||||
Settings settings;
|
||||
settings.beginGroup("Themes");
|
||||
@ -67,6 +69,7 @@ ThemeManager::ThemeManager(QWidget* parent, Preferences* preferences)
|
||||
|
||||
connect(ui->listWidget, &QListWidget::currentItemChanged, this, &ThemeManager::currentChanged);
|
||||
connect(ui->license, &ClickableLabel::clicked, this, &ThemeManager::showLicense);
|
||||
connect(ui->remove, &QPushButton::clicked, this, &ThemeManager::removeTheme);
|
||||
|
||||
currentChanged();
|
||||
}
|
||||
@ -85,6 +88,25 @@ void ThemeManager::showLicense()
|
||||
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()
|
||||
{
|
||||
QListWidgetItem* currentItem = ui->listWidget->currentItem();
|
||||
@ -98,6 +120,7 @@ void ThemeManager::currentChanged()
|
||||
ui->author->setText(currentTheme.author);
|
||||
ui->description->setText(currentTheme.description);
|
||||
ui->license->setHidden(currentTheme.license.isEmpty());
|
||||
ui->remove->setEnabled(QFileInfo(currentTheme.themePath).isWritable());
|
||||
}
|
||||
|
||||
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.description = metadata.comment();
|
||||
info.author = metadata.value(QSL("X-Falkon-Author")).toString();
|
||||
info.themePath = path.chopped(1);
|
||||
|
||||
const QString iconName = metadata.icon();
|
||||
if (!iconName.isEmpty()) {
|
||||
|
@ -45,6 +45,7 @@ public:
|
||||
private Q_SLOTS:
|
||||
void currentChanged();
|
||||
void showLicense();
|
||||
void removeTheme();
|
||||
|
||||
private:
|
||||
struct Theme {
|
||||
@ -54,6 +55,7 @@ private:
|
||||
QString author;
|
||||
QString description;
|
||||
QString license;
|
||||
QString themePath;
|
||||
};
|
||||
|
||||
Theme parseTheme(const QString &path, const QString &name);
|
||||
|
@ -137,6 +137,40 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</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>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
|
Loading…
Reference in New Issue
Block a user