Adding some check's

-- 
Best regards,
Guido
From 3ee7ed771af499328c2414cabf342caa20345a5b Mon Sep 17 00:00:00 2001
From: Guido Lerch <[email protected]>
Date: Tue, 13 Oct 2015 00:59:05 +0200
Subject: [PATCH 3/4] Adding image management checks

Some checks and balances, making sure we have a location in the preferences.

Signed-off-by: Guido Lerch <[email protected]>
---
 dive.c                |  2 +-
 qt-ui/preferences.cpp | 16 +++++++++++-----
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/dive.c b/dive.c
index a9532ad..d9c8a5a 100644
--- a/dive.c
+++ b/dive.c
@@ -3298,7 +3298,7 @@ bool picture_check_valid(char *filename, int shift_time)
 void dive_create_picture(struct dive *dive, char *filename, int shift_time, 
bool match_all)
 {
        char *new_filename;
-       if (prefs.manage_images) {
+       if (prefs.manage_images && strcmp(prefs.image_location,"")) {
                copy_image_and_overwrite(filename, prefs.image_location, 
get_file_name(filename));
                new_filename = 
strdup(strcat(prefs.image_location,get_file_name(filename)));
        } else {
diff --git a/qt-ui/preferences.cpp b/qt-ui/preferences.cpp
index c47f364..6cc9bcb 100644
--- a/qt-ui/preferences.cpp
+++ b/qt-ui/preferences.cpp
@@ -254,6 +254,11 @@ void PreferencesDialog::setUiFromPrefs()
        // Images
        ui.manage_images->setChecked(prefs.manage_images);
        ui.image_location->setText(prefs.image_location);
+       QString il(prefs.image_location);
+       if (!il.isEmpty())
+               ui.manage_images->setEnabled(true);
+       else
+               ui.manage_images->setEnabled(false);
 }
 
 void PreferencesDialog::restorePrefs()
@@ -437,7 +442,6 @@ void PreferencesDialog::syncSettings()
        s.beginGroup("images");
        s.setValue("manage", ui.manage_images->isChecked());
        s.setValue("location", ui.image_location->text());
-
        s.endGroup();
 
        loadSettings();
@@ -572,9 +576,11 @@ void PreferencesDialog::on_chooseImageLocation_clicked()
 {
        QString oldDirectory = ui.image_location->text();
        QString choosenDirectory = QFileDialog::getExistingDirectory(this, 
tr("Open Image location"), oldDirectory, QFileDialog::ShowDirsOnly | 
QFileDialog::DontResolveSymlinks);
-       if (!choosenDirectory.isEmpty())
+       if (!choosenDirectory.isEmpty()) {
                ui.image_location->setText(choosenDirectory + "/");
-       QDir di(ui.image_location->text());
-       if (!di.exists())
-               di.mkpath(ui.image_location->text());
+               QDir di(ui.image_location->text());
+               if (!di.exists())
+                       di.mkpath(ui.image_location->text());
+               ui.manage_images->setEnabled(true);
+       }
 }
-- 
2.3.8 (Apple Git-58)

From 62cf4e9590991bbfec660f62e9df36edb57c989e Mon Sep 17 00:00:00 2001
From: Guido Lerch <[email protected]>
Date: Tue, 13 Oct 2015 01:13:28 +0200
Subject: [PATCH 4/4] Adding image management checks 2

More checking if the selected location is available and existing
before trying to copy the file.

Signed-off-by: Guido Lerch <[email protected]>
---
 dive.c       | 2 +-
 qthelper.cpp | 6 ++++++
 qthelper.h   | 1 +
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/dive.c b/dive.c
index d9c8a5a..4e6ef76 100644
--- a/dive.c
+++ b/dive.c
@@ -3298,7 +3298,7 @@ bool picture_check_valid(char *filename, int shift_time)
 void dive_create_picture(struct dive *dive, char *filename, int shift_time, 
bool match_all)
 {
        char *new_filename;
-       if (prefs.manage_images && strcmp(prefs.image_location,"")) {
+       if (prefs.manage_images && strcmp(prefs.image_location,"") && 
dir_exists(prefs.image_location)) {
                copy_image_and_overwrite(filename, prefs.image_location, 
get_file_name(filename));
                new_filename = 
strdup(strcat(prefs.image_location,get_file_name(filename)));
        } else {
diff --git a/qthelper.cpp b/qthelper.cpp
index da85ffe..3480e8c 100644
--- a/qthelper.cpp
+++ b/qthelper.cpp
@@ -1597,3 +1597,9 @@ extern "C" bool in_planner()
 {
        return (currentApplicationState == "PlanDive" || 
currentApplicationState == "EditPlannedDive");
 }
+
+extern "C" bool dir_exists(char *dir)
+{
+       QDir d(dir);
+       return d.exists();
+}
diff --git a/qthelper.h b/qthelper.h
index f5457b1..05c6973 100644
--- a/qthelper.h
+++ b/qthelper.h
@@ -130,5 +130,6 @@ bool parseGpsText(const QString &gps_text, double 
*latitude, double *longitude);
 QByteArray getCurrentAppState();
 void setCurrentAppState(QByteArray state);
 extern "C" bool in_planner();
+extern "C" bool dir_exists(char *dir);
 
 #endif // QTHELPER_H
-- 
2.3.8 (Apple Git-58)

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to