From 5c669eaafaf3ff4fa4e383cc91d29962313da81a Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Mon, 2 Jun 2014 16:40:05 +0200 Subject: [PATCH] support removal of wallpapers installed with ghns --- wallpapers/image/backgroundlistmodel.cpp | 15 ++++-- wallpapers/image/backgroundlistmodel.h | 1 + wallpapers/image/image.cpp | 52 +++++++++++++------ .../contents/ui/WallpaperDelegate.qml | 2 +- 4 files changed, 48 insertions(+), 22 deletions(-) diff --git a/wallpapers/image/backgroundlistmodel.cpp b/wallpapers/image/backgroundlistmodel.cpp index 923f5ad42..439c642c3 100644 --- a/wallpapers/image/backgroundlistmodel.cpp +++ b/wallpapers/image/backgroundlistmodel.cpp @@ -74,6 +74,7 @@ BackgroundListModel::BackgroundListModel(Image *listener, QObject *parent) roleNames[ScreenshotRole] = "screenshot"; roleNames[ResolutionRole] = "resolution"; roleNames[PathRole] = "path"; + roleNames[PackageNameRole] = "packageName"; roleNames[RemovableRole] = "removable"; setRoleNames(roleNames); @@ -177,7 +178,6 @@ void BackgroundListModel::processPaths(const QStringList &paths) if (!contains(file) && QFile::exists(file)) { Plasma::Package package = Plasma::Package(new WallpaperPackage(m_structureParent.data(), m_structureParent.data())); package.setPath(file); - if (package.isValid()) { newPackages << package; } @@ -367,12 +367,19 @@ QVariant BackgroundListModel::data(const QModelIndex &index, int role) const } break; - case PathRole: + case PathRole: return QUrl::fromLocalFile(b.filePath("preferred")); break; - case RemovableRole: - return m_removableWallpapers.contains(b.filePath("preferred")); + case PackageNameRole: + return b.metadata().pluginName().isEmpty() ? b.filePath("preferred") : b.metadata().pluginName(); + break; + + case RemovableRole: { + QString localWallpapers = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/wallpapers/"; + QString path = b.filePath("preferred"); + return path.startsWith(localWallpapers) || m_removableWallpapers.contains(path); + } break; default: diff --git a/wallpapers/image/backgroundlistmodel.h b/wallpapers/image/backgroundlistmodel.h index e59afc780..64417a314 100644 --- a/wallpapers/image/backgroundlistmodel.h +++ b/wallpapers/image/backgroundlistmodel.h @@ -69,6 +69,7 @@ public: ScreenshotRole, ResolutionRole, PathRole, + PackageNameRole, RemovableRole }; diff --git a/wallpapers/image/image.cpp b/wallpapers/image/image.cpp index c3062d310..bbda401d5 100644 --- a/wallpapers/image/image.cpp +++ b/wallpapers/image/image.cpp @@ -660,26 +660,44 @@ void Image::pathDeleted(const QString &path) //FIXME: we have to save the configuration also when the dialog cancel button is clicked. void Image::removeWallpaper(QString name) { + QString localWallpapers = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/wallpapers/"; QUrl nameUrl(name); - // save it - KConfigGroup cfg = KConfigGroup(KSharedConfig::openConfig(QStringLiteral("plasmarc")), - QStringLiteral("Wallpapers")); - m_usersWallpapers = cfg.readEntry("usersWallpapers", m_usersWallpapers); - int wallpaperIndex = -1; - //passed as a path or as a file:// url? - if (nameUrl.isValid()) { - wallpaperIndex = m_usersWallpapers.indexOf(nameUrl.path()); - } else { - wallpaperIndex = m_usersWallpapers.indexOf(name); - } - if (wallpaperIndex >= 0){ - m_usersWallpapers.removeAt(wallpaperIndex); + //Package plugin name + if (!name.contains('/')) { + Plasma::Package p = Plasma::Package(new WallpaperPackage(this, this)); + KJob *j = p.uninstall(name, localWallpapers); + connect(j, &KJob::finished, [=] () { + m_model->reload(m_usersWallpapers); + }); + //absolute path in the home + } else if (nameUrl.path().startsWith(localWallpapers)) { + QFile f(nameUrl.path()); + if (f.exists()) { + f.remove(); + } m_model->reload(m_usersWallpapers); - cfg.writeEntry("usersWallpapers", m_usersWallpapers); - cfg.sync(); - emit usersWallpapersChanged(); - Q_EMIT settingsChanged(true); + } else { + // save it + KConfigGroup cfg = KConfigGroup(KSharedConfig::openConfig(QStringLiteral("plasmarc")), + QStringLiteral("Wallpapers")); + m_usersWallpapers = cfg.readEntry("usersWallpapers", m_usersWallpapers); + + int wallpaperIndex = -1; + //passed as a path or as a file:// url? + if (nameUrl.isValid()) { + wallpaperIndex = m_usersWallpapers.indexOf(nameUrl.path()); + } else { + wallpaperIndex = m_usersWallpapers.indexOf(name); + } + if (wallpaperIndex >= 0){ + m_usersWallpapers.removeAt(wallpaperIndex); + m_model->reload(m_usersWallpapers); + cfg.writeEntry("usersWallpapers", m_usersWallpapers); + cfg.sync(); + emit usersWallpapersChanged(); + Q_EMIT settingsChanged(true); + } } } diff --git a/wallpapers/image/imagepackage/contents/ui/WallpaperDelegate.qml b/wallpapers/image/imagepackage/contents/ui/WallpaperDelegate.qml index 0e154cf1a..8be342f13 100644 --- a/wallpapers/image/imagepackage/contents/ui/WallpaperDelegate.qml +++ b/wallpapers/image/imagepackage/contents/ui/WallpaperDelegate.qml @@ -95,7 +95,7 @@ MouseArea { iconSource: "list-remove" flat: false visible: model.removable - onClicked: imageWallpaper.removeWallpaper(model.path) + onClicked: imageWallpaper.removeWallpaper(model.packageName) } } }