From eb11ba27077cc290ff2979acc414216dbd7f9a6e Mon Sep 17 00:00:00 2001 From: Floris Bos Date: Mon, 23 Nov 2020 19:43:16 +0100 Subject: [PATCH] Remember last selected custom image path Closes #123 --- imagewriter.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/imagewriter.cpp b/imagewriter.cpp index 942c647..97a8b33 100644 --- a/imagewriter.cpp +++ b/imagewriter.cpp @@ -421,8 +421,15 @@ void ImageWriter::onPreparationStatusUpdate(QString msg) void ImageWriter::openFileDialog() { #ifndef QT_NO_WIDGETS + QSettings settings; + QString path = settings.value("General/lastpath").toString(); + QFileInfo fi(path); + + if (path.isEmpty() || !fi.exists() || !fi.isReadable() ) + path = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); + QFileDialog *fd = new QFileDialog(nullptr, tr("Select image"), - QStandardPaths::writableLocation(QStandardPaths::DownloadLocation), + path, "Image files (*.img *.zip *.gz *.xz);;All files (*.*)"); connect(fd, SIGNAL(fileSelected(QString)), SLOT(onFileSelected(QString))); @@ -443,10 +450,19 @@ void ImageWriter::openFileDialog() void ImageWriter::onFileSelected(QString filename) { +#ifndef QT_NO_WIDGETS QFileInfo fi(filename); + QSettings settings; if (fi.isFile()) { + QString path = fi.path(); + if (path != settings.value("General/lastpath")) + { + settings.setValue("General/lastpath", path); + settings.sync(); + } + emit fileSelected(QUrl::fromLocalFile(filename)); } else @@ -455,6 +471,7 @@ void ImageWriter::onFileSelected(QString filename) } sender()->deleteLater(); +#endif } void ImageWriter::_parseCompressedFile()