Use a static QFileDialog again

This allows setting the proper directory *without* pointing somewhere non-existent.
At the same time, the default is changed to the user's picture folder.
This commit is contained in:
Luca Beltrame 2015-08-11 22:38:23 +02:00
parent e764ba2c9d
commit daf3e753d5

View file

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