Commit 2212a9af authored by Tranter Madi's avatar Tranter Madi 🌧
Browse files

Fix wallpaper destination path

Summary:
- Correct the destination path when downloading images.
- Switch from FileCopyJob to CopyJob to allow showing file overwrite dialog.

BUG: 379469

Test Plan: Drop files from Firefox to the desktop to set the wallpaper successfully.

Reviewers: #plasma, mart, ngraham

Reviewed By: #plasma, mart, ngraham

Subscribers: mart, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D26525
parent e2bfeb16
......@@ -46,6 +46,7 @@
#include <QFileDialog>
#include <KRandom>
#include <KIO/Job>
#include <KIO/CopyJob>
#include <krun.h>
#include <klocalizedstring.h>
......@@ -551,10 +552,12 @@ void Image::addUrl(const QUrl &url, bool setAsCurrent)
return;
}
} else {
QString wallpaperPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("wallpapers/") + url.path();
QDir wallpaperDir(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/wallpapers/");
const QString wallpaperPath = wallpaperDir.absoluteFilePath(url.fileName());
if (wallpaperDir.mkpath(wallpaperDir.absolutePath()) && !url.fileName().isEmpty()) {
KIO::CopyJob *job = KIO::copy(url, QUrl::fromLocalFile(wallpaperPath), KIO::HideProgressInfo);
if (!wallpaperPath.isEmpty()) {
KIO::FileCopyJob *job = KIO::file_copy(url, QUrl(wallpaperPath), -1, KIO::HideProgressInfo);
if (setAsCurrent) {
connect(job, &KJob::result, this, &Image::setWallpaperRetrieved);
} else {
......@@ -579,7 +582,7 @@ void Image::addUrl(const QUrl &url, bool setAsCurrent)
void Image::setWallpaperRetrieved(KJob *job)
{
KIO::FileCopyJob *copyJob = qobject_cast<KIO::FileCopyJob *>(job);
KIO::CopyJob *copyJob = qobject_cast<KIO::CopyJob *>(job);
if (copyJob && !copyJob->error()) {
setWallpaper(copyJob->destUrl().toLocalFile());
}
......@@ -587,7 +590,7 @@ void Image::setWallpaperRetrieved(KJob *job)
void Image::addWallpaperRetrieved(KJob *job)
{
KIO::FileCopyJob *copyJob = qobject_cast<KIO::FileCopyJob *>(job);
KIO::CopyJob *copyJob = qobject_cast<KIO::CopyJob *>(job);
if (copyJob && !copyJob->error()) {
addUrl(copyJob->destUrl(), false);
}
......
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