Only try to save images on existing paths

Tue, 24 Jan 2023 16:08:16 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 24 Jan 2023 16:08:16 +0100
changeset 474
18b72c518d0d
parent 473
0d7441b39d41
child 475
895c5ae1dab1

Only try to save images on existing paths

src/EditProductTab13.cpp file | annotate | diff | comparison | revisions
--- a/src/EditProductTab13.cpp	Tue Jan 24 15:57:13 2023 +0100
+++ b/src/EditProductTab13.cpp	Tue Jan 24 16:08:16 2023 +0100
@@ -328,9 +328,20 @@
 void EditProduct::downloadImage_clicked()
 {
     QSettings settings(QSettings::IniFormat, QSettings::UserScope, "mbse", "bmsapp");
+    QString dirName;
+
+    /*
+     * First check if the directory stored in the settings file exists.
+     * It might be on a removable media that was last used ...
+     * If so, fallback to the user's home directory.
+     */
+    dirName = settings.value("paths/download").toString();
+    if (! QDir(dirName).exists()) {
+        dirName = QDir::homePath();
+    }
 
     QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),
-                       settings.value("paths/download").toString() + "/" + product->images_list.at(ui->filmStrip->currentRow()).filename, tr("Files (*.png)"));
+                       dirName + "/" + product->images_list.at(ui->filmStrip->currentRow()).filename, tr("Files (*.png)"));
     if (fileName == 0) {
         QMessageBox::warning(this, tr("Save File"), tr("No PNG file selected."));
         return;

mercurial