From 4e481d0e66768cd71904be92f9d3de2bed4be20c Mon Sep 17 00:00:00 2001 From: Alexander Lohnau Date: Fri, 28 Aug 2020 15:32:44 +0000 Subject: [PATCH] Add uninstall button for kwin scripts BUG: 315829 FIXED-IN: 5.20 --- kcmkwin/kwinscripts/module.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/kcmkwin/kwinscripts/module.cpp b/kcmkwin/kwinscripts/module.cpp index a4935aa443..1dcb3b4a5a 100644 --- a/kcmkwin/kwinscripts/module.cpp +++ b/kcmkwin/kwinscripts/module.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include @@ -57,6 +58,32 @@ Module::Module(QWidget *parent, const QVariantList &args) : connect(ui->scriptSelector, &KPluginSelector::defaulted, this, qOverload(&KCModule::defaulted)); connect(ui->importScriptButton, &QPushButton::clicked, this, &Module::importScript); + ui->scriptSelector->setAdditionalButtonHandler([this](const KPluginInfo &info) { + QPushButton *button = new QPushButton(ui->scriptSelector); + button->setIcon(QIcon::fromTheme(QStringLiteral("delete"))); + button->setEnabled(QFileInfo(info.entryPath()).isWritable()); + connect(button, &QPushButton::clicked, this, [this, info](){ + using namespace KPackage; + PackageStructure *structure = PackageLoader::self()->loadPackageStructure(QStringLiteral("KWin/Script")); + Package package(structure); + // We can get the package root from the entry path + QDir root = QFileInfo(info.entryPath()).dir(); + root.cdUp(); + KJob *uninstallJob = Package(structure).uninstall(info.pluginName(), root.absolutePath()); + connect(uninstallJob, &KJob::result, this, [this, uninstallJob](){ + ui->scriptSelector->clearPlugins(); + updateListViewContents(); + // If the uninstallation is successful the entry will be immediately removed + if (!uninstallJob->errorString().isEmpty()) { + ui->messageWidget->setText(i18n("Error when uninstalling KWin Script: %1", uninstallJob->errorString())); + ui->messageWidget->setMessageType(KMessageWidget::Error); + ui->messageWidget->animatedShow(); + } + }); + }); + return button; + }); + updateListViewContents(); } @@ -115,7 +142,7 @@ void Module::importScriptInstallFinished(KJob *job) void Module::updateListViewContents() { auto filter = [](const KPluginMetaData &md) { - return !md.rawData().value("X-KWin-Exclude-Listing").toBool(); + return md.isValid() && !md.rawData().value("X-KWin-Exclude-Listing").toBool(); }; const QString scriptFolder = QStringLiteral("kwin/scripts/");