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:
parent
e764ba2c9d
commit
daf3e753d5
1 changed files with 40 additions and 19 deletions
|
@ -480,13 +480,22 @@ void DanbooruMainWindow::slotHandleDownload(const QUrl &url, const QVariant tags
|
||||||
|
|
||||||
KIO::MimetypeJob *mimeJob = KIO::mimetype(url, KIO::HideProgressInfo);
|
KIO::MimetypeJob *mimeJob = KIO::mimetype(url, KIO::HideProgressInfo);
|
||||||
|
|
||||||
QString filters;
|
|
||||||
QString remoteFile = url.fileName();
|
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()) {
|
if (mimeJob->exec()) {
|
||||||
filters = mimeJob->mimetype();
|
filters << mimeJob->mimetype();
|
||||||
|
saveDialog.setMimeTypeFilters(filters);
|
||||||
} else {
|
} 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)
|
// Prevent invalid characters (":" can be a tag in Danbooru)
|
||||||
|
@ -494,16 +503,10 @@ void DanbooruMainWindow::slotHandleDownload(const QUrl &url, const QVariant tags
|
||||||
remoteFile.replace(":", "_");
|
remoteFile.replace(":", "_");
|
||||||
}
|
}
|
||||||
|
|
||||||
QUrl localFile = QFileDialog::getSaveFileUrl(
|
saveDialog.selectFile(remoteFile);
|
||||||
this,
|
|
||||||
i18n("Save file"),
|
|
||||||
QDir::homePath() + QLatin1Char('/') + remoteFile,
|
|
||||||
filters
|
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
// TODO: Remember last user directory - settings?
|
|
||||||
|
|
||||||
|
if (saveDialog.exec()) {
|
||||||
|
QUrl localFile = saveDialog.selectedUrls().first();
|
||||||
if (!localFile.isEmpty()) {
|
if (!localFile.isEmpty()) {
|
||||||
|
|
||||||
KIO::FileCopyJob *job = KIO::file_copy(url, localFile, -1, KIO::DefaultFlags);
|
KIO::FileCopyJob *job = KIO::file_copy(url, localFile, -1, KIO::DefaultFlags);
|
||||||
|
@ -511,6 +514,7 @@ void DanbooruMainWindow::slotHandleDownload(const QUrl &url, const QVariant tags
|
||||||
connect(job, &KIO::Job::result, [this, localFile, tagList](KJob * job) {
|
connect(job, &KIO::Job::result, [this, localFile, tagList](KJob * job) {
|
||||||
|
|
||||||
if (job->error()) {
|
if (job->error()) {
|
||||||
|
qCDebug(DANBOORU_CLIENT) << "Error while downloading " << job->errorString();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -523,6 +527,23 @@ void DanbooruMainWindow::slotHandleDownload(const QUrl &url, const QVariant tags
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
|
||||||
|
QUrl localFile = QFileDialog::getSaveFileUrl(
|
||||||
|
this,
|
||||||
|
i18n("Save file"),
|
||||||
|
QDir::homePath() + QLatin1Char('/') + remoteFile,
|
||||||
|
filters
|
||||||
|
|
||||||
|
);*/
|
||||||
|
|
||||||
|
// TODO: Remember last user directory - settings?
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue