Prevent invalid characters to be used in save file names
This commit is contained in:
parent
ea84089687
commit
341c51365f
1 changed files with 20 additions and 17 deletions
|
@ -482,31 +482,34 @@ void DanbooruMainWindow::slotHandleDownload(const QUrl &url, const QVariant tags
|
|||
|
||||
QStringList tagList = tags.toStringList();
|
||||
|
||||
QFileDialog saveDialog(this);
|
||||
saveDialog.setFileMode(QFileDialog::AnyFile);
|
||||
saveDialog.setWindowTitle(i18n("Save file"));
|
||||
saveDialog.setAcceptMode(QFileDialog::AcceptSave);
|
||||
|
||||
KIO::MimetypeJob* mimeJob = KIO::mimetype(url, KIO::HideProgressInfo);
|
||||
|
||||
QString filters;
|
||||
QString remoteFile = url.fileName();
|
||||
|
||||
if (mimeJob->exec()) {
|
||||
saveDialog.setMimeTypeFilters(QStringList(mimeJob->mimetype()));
|
||||
filters = mimeJob->mimetype();
|
||||
} else {
|
||||
saveDialog.setNameFilter(i18n("Images (*.png *.gif *.jpg);;All files (*.*)"));
|
||||
filters = "Images (*.png *.gif *.jpg);;All files (*.*)";
|
||||
}
|
||||
|
||||
// Prevent invalid characters (":" can be a tag in Danbooru)
|
||||
if (remoteFile.contains(":")) {
|
||||
remoteFile.replace(":", "_");
|
||||
}
|
||||
|
||||
QUrl localFile = QFileDialog::getSaveFileUrl(
|
||||
this,
|
||||
i18n("Save file"),
|
||||
QDir::homePath() + QLatin1Char('/') + remoteFile,
|
||||
filters
|
||||
|
||||
);
|
||||
|
||||
|
||||
// TODO: Remember last user directory - settings?
|
||||
|
||||
saveDialog.setConfirmOverwrite(true);
|
||||
saveDialog.setDirectory(QDir::homePath());
|
||||
saveDialog.selectFile(url.fileName());
|
||||
|
||||
if (saveDialog.exec()) {
|
||||
QUrl localFile = saveDialog.selectedUrls().at(0);
|
||||
|
||||
if (localFile.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (!localFile.isEmpty()) {
|
||||
|
||||
KIO::FileCopyJob *job = KIO::file_copy(url, localFile, -1, KIO::DefaultFlags);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue