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,25 +503,20 @@ 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
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                     );
 | 
					    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);
 | 
					                if (job->error()) {
 | 
				
			||||||
 | 
					                    qCDebug(DANBOORU_CLIENT) << "Error while downloading " << job->errorString();
 | 
				
			||||||
        connect(job, &KIO::Job::result, [this, localFile, tagList](KJob  * job) {
 | 
					                    return;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            if (job->error()) {
 | 
					 | 
				
			||||||
                return;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef WITH_KFILEMETADATA
 | 
					#ifdef WITH_KFILEMETADATA
 | 
				
			||||||
            qCDebug(DANBOORU_CLIENT) << "Local file" << localFile.toLocalFile();
 | 
					            qCDebug(DANBOORU_CLIENT) << "Local file" << localFile.toLocalFile();
 | 
				
			||||||
| 
						 | 
					@ -520,10 +524,27 @@ void DanbooruMainWindow::slotHandleDownload(const QUrl &url, const QVariant tags
 | 
				
			||||||
            meta.setTags(tagList);
 | 
					            meta.setTags(tagList);
 | 
				
			||||||
#endif
 | 
					#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)
 | 
					void DanbooruMainWindow::searchTag(const QModelIndex &index)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue