Commit 8936b4db authored by Alexander Lohnau's avatar Alexander Lohnau 💬 Committed by Kurt Hindenburg
Browse files

Port away from deprecated KNSCore::DownloadManager

We can just remove the files on disk and with the RemoveDeadEntries
option set to true KNS will check if the files still exist. If
not the entry will be marked as not installed.
parent 9e28c446
...@@ -4,3 +4,4 @@ Categories=Konsole Color Schemes ...@@ -4,3 +4,4 @@ Categories=Konsole Color Schemes
TargetDir=konsole TargetDir=konsole
AcceptHtmlDownloads=false AcceptHtmlDownloads=false
Uncompress=archive Uncompress=archive
RemoveDeadEntries=true
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include <KIconDialog> #include <KIconDialog>
#include <KLocalizedString> #include <KLocalizedString>
#include <KMessageBox> #include <KMessageBox>
#include <KNSCore/DownloadManager> #include <KNSCore/Engine>
#include <KWindowSystem> #include <KWindowSystem>
#include <kconfigwidgets_version.h> #include <kconfigwidgets_version.h>
...@@ -1152,51 +1152,15 @@ void EditProfileDialog::updateFontPreview(QFont font) ...@@ -1152,51 +1152,15 @@ void EditProfileDialog::updateFontPreview(QFont font)
void EditProfileDialog::removeColorScheme() void EditProfileDialog::removeColorScheme()
{ {
QModelIndexList selected = _appearanceUi->colorSchemeList->selectionModel()->selectedIndexes(); const QModelIndexList selected = _appearanceUi->colorSchemeList->selectionModel()->selectedIndexes();
if (selected.isEmpty()) { if (selected.isEmpty()) {
return; return;
} }
const QString &name = selected.first().data(Qt::UserRole + 1).value<const ColorScheme *>()->name();
// The actual delete runs async because we need to on-demand query Q_ASSERT(!name.isEmpty());
// files managed by KNS. Deleting files managed by KNS screws up the if (ColorSchemeManager::instance()->deleteColorScheme(name)) {
// KNS states (entry gets shown as installed when in fact we deleted it). _appearanceUi->colorSchemeList->model()->removeRow(selected.first().row());
auto *manager = new KNSCore::DownloadManager(QStringLiteral("konsole.knsrc"), this); }
connect(manager, &KNSCore::DownloadManager::searchResult,
this, [=](const KNSCore::EntryInternal::List &entries) {
const QString &name = selected.first().data(Qt::UserRole + 1).value<const ColorScheme *>()->name();
Q_ASSERT(!name.isEmpty());
bool uninstalled = false;
// Check if the theme was installed by KNS, if so uninstall it through
// there and unload it.
for (auto &entry : entries) {
for (const auto &file : entry.installedFiles()) {
if (ColorSchemeManager::colorSchemeNameFromPath(file) != name) {
continue;
}
// Make sure the manager can unload it before uninstalling it.
if (ColorSchemeManager::instance()->unloadColorScheme(file)) {
manager->uninstallEntry(entry);
uninstalled = true;
}
}
if (uninstalled) {
break;
}
}
// If KNS wasn't able to remove it is a custom theme and we'll drop
// it manually.
if (!uninstalled) {
uninstalled = ColorSchemeManager::instance()->deleteColorScheme(name);
}
if (uninstalled) {
_appearanceUi->colorSchemeList->model()->removeRow(selected.first().row());
}
manager->deleteLater();
});
manager->checkForInstalled();
} }
void EditProfileDialog::gotNewColorSchemes(const KNS3::Entry::List &changedEntries) void EditProfileDialog::gotNewColorSchemes(const KNS3::Entry::List &changedEntries)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment