diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index bba0fd9..3f93f3b 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -480,13 +480,22 @@ void DanbooruMainWindow::slotHandleDownload(const QUrl &url, const QVariant tags KIO::MimetypeJob *mimeJob = KIO::mimetype(url, KIO::HideProgressInfo); - QString filters; QString remoteFile = url.fileName(); + QFileDialog saveDialog(this); + saveDialog.setAcceptMode(QFileDialog::AcceptSave); + saveDialog.setFileMode(QFileDialog::AnyFile); + saveDialog.setDirectory(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)); + saveDialog.setOption(QFileDialog::DontConfirmOverwrite, false); + + QStringList filters; + if (mimeJob->exec()) { - filters = mimeJob->mimetype(); + filters << mimeJob->mimetype(); + saveDialog.setMimeTypeFilters(filters); } else { - filters = "Images (*.png *.gif *.jpg);;All files (*.*)"; + filters << "Images (*.png *.gif *.jpg)" << "All files (*.*)"; + saveDialog.setNameFilters(filters); } // Prevent invalid characters (":" can be a tag in Danbooru) @@ -494,25 +503,20 @@ void DanbooruMainWindow::slotHandleDownload(const QUrl &url, const QVariant tags remoteFile.replace(":", "_"); } - QUrl localFile = QFileDialog::getSaveFileUrl( - this, - i18n("Save file"), - QDir::homePath() + QLatin1Char('/') + remoteFile, - filters + saveDialog.selectFile(remoteFile); - ); + if (saveDialog.exec()) { + QUrl localFile = saveDialog.selectedUrls().first(); + if (!localFile.isEmpty()) { - // TODO: Remember last user directory - settings? + KIO::FileCopyJob *job = KIO::file_copy(url, localFile, -1, KIO::DefaultFlags); - if (!localFile.isEmpty()) { + connect(job, &KIO::Job::result, [this, localFile, tagList](KJob * job) { - KIO::FileCopyJob *job = KIO::file_copy(url, localFile, -1, KIO::DefaultFlags); - - connect(job, &KIO::Job::result, [this, localFile, tagList](KJob * job) { - - if (job->error()) { - return; - } + if (job->error()) { + qCDebug(DANBOORU_CLIENT) << "Error while downloading " << job->errorString(); + return; + } #ifdef WITH_KFILEMETADATA qCDebug(DANBOORU_CLIENT) << "Local file" << localFile.toLocalFile(); @@ -520,10 +524,27 @@ void DanbooruMainWindow::slotHandleDownload(const QUrl &url, const QVariant tags meta.setTags(tagList); #endif - }); + }); + } } +/* + + + QUrl localFile = QFileDialog::getSaveFileUrl( + this, + i18n("Save file"), + QDir::homePath() + QLatin1Char('/') + remoteFile, + filters + + );*/ + + // TODO: Remember last user directory - settings? + + + + } void DanbooruMainWindow::searchTag(const QModelIndex &index)