support removal of wallpapers installed with ghns

wilder-5.14
Marco Martin 12 years ago
parent 2add7fb918
commit 5c669eaafa
  1. 15
      wallpapers/image/backgroundlistmodel.cpp
  2. 1
      wallpapers/image/backgroundlistmodel.h
  3. 52
      wallpapers/image/image.cpp
  4. 2
      wallpapers/image/imagepackage/contents/ui/WallpaperDelegate.qml

@ -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:

@ -69,6 +69,7 @@ public:
ScreenshotRole,
ResolutionRole,
PathRole,
PackageNameRole,
RemovableRole
};

@ -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);
}
}
}

@ -95,7 +95,7 @@ MouseArea {
iconSource: "list-remove"
flat: false
visible: model.removable
onClicked: imageWallpaper.removeWallpaper(model.path)
onClicked: imageWallpaper.removeWallpaper(model.packageName)
}
}
}

Loading…
Cancel
Save