wallpapers/image: fix drag and drop in config dialog

Use url data type directly, no need to convert url to string.
wilder-5.26
Fushan Wen 4 years ago
parent b768533890
commit 9f7c40f26e
No known key found for this signature in database
GPG Key ID: 2E48D1487C91DCAA
  1. 13
      wallpapers/image/imagepackage/contents/ui/config.qml
  2. 10
      wallpapers/image/plugin/imagebackend.cpp
  3. 2
      wallpapers/image/plugin/imagebackend.h

@ -169,18 +169,15 @@ ColumnLayout {
onEntered: {
if (drag.hasUrls) {
event.accept();
drag.accept();
}
}
onDropped: {
drop.urls.forEach(function (url) {
if (url.indexOf("file://") === 0) {
var path = url.substr(7); // 7 is length of "file://"
if (configDialog.currentWallpaper === "org.kde.image") {
imageWallpaper.addUsersWallpaper(path);
} else {
imageWallpaper.addSlidePath(path);
}
if (configDialog.currentWallpaper === "org.kde.image") {
imageWallpaper.addUsersWallpaper(url);
} else {
imageWallpaper.addSlidePath(url);
}
});
}

@ -321,16 +321,16 @@ void ImageBackend::showAddSlidePathsDialog()
dialog->show();
}
void ImageBackend::addSlidePath(const QString &_path)
void ImageBackend::addSlidePath(const QUrl &url)
{
if (_path.isEmpty()) {
if (url.isEmpty()) {
return;
}
QString path = _path;
QString path = url.toLocalFile();
// If path is a file, use its parent folder.
const QFileInfo info(QUrl(path).toLocalFile());
const QFileInfo info(path);
if (info.isFile()) {
path = info.dir().absolutePath();
@ -367,7 +367,7 @@ void ImageBackend::addDirFromSelectionDialog()
{
QFileDialog *dialog = qobject_cast<QFileDialog *>(sender());
if (dialog) {
addSlidePath(dialog->directoryUrl().toLocalFile());
addSlidePath(dialog->directoryUrl());
}
}

@ -82,7 +82,7 @@ public:
QUrl modelImage() const;
// this is for QML use
Q_INVOKABLE void addSlidePath(const QString &path);
Q_INVOKABLE void addSlidePath(const QUrl &url);
Q_INVOKABLE void removeSlidePath(const QString &path);
Q_INVOKABLE void openFolder(const QString &path);
Q_INVOKABLE void openModelImage() const;

Loading…
Cancel
Save