[PATCH] Add "download into private trip" dialog checkmark

Linus Torvalds torvalds at linux-foundation.org
Thu Aug 14 09:29:26 PDT 2014


From: Linus Torvalds <torvalds at linux-foundation.org>
Date: Thu, 24 Jul 2014 13:59:11 -0700
Subject: [PATCH 1/2] Add "download into private trip" dialog checkmark

This adds a checkbox for the divecomputer download dialog that allows you 
to tell the download to put the newly downloaded dives into a trip of 
their own. That in turn will disable the dive merging with any existing 
dives, which means that you will not mix up your newly downloaded dives 
with any old dives.

That, in turn, is very convenient of you know that some of the dives were 
done by other divers (or from testing that happened during servicing etc), 
or the dive dates etc were wrong because the dive computer date had reset 
due to battery changes etc.

Once you have all the dives in a private trip of their own, you can then 
fix them up (delete dives you don't want to merge etc), and then after all 
the data is ok you might want to merge the cleaned-up results with 
previous trips etc, and then manually ask subsurface to merge the dives or 
whatever.

Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
---
 dive.c                             | 18 +++++++++++++++---
 libdivecomputer.c                  |  7 +++++++
 libdivecomputer.h                  |  2 ++
 qt-ui/downloadfromdivecomputer.cpp |  4 ++++
 qt-ui/downloadfromdivecomputer.ui  | 19 +++++++++++++------
 5 files changed, 41 insertions(+), 9 deletions(-)

diff --git a/dive.c b/dive.c
index 4e81f8a70fff..8e51351fb8be 100644
--- a/dive.c
+++ b/dive.c
@@ -1860,6 +1860,11 @@ static int match_dc_dive(struct divecomputer *a, struct divecomputer *b)
 	return 0;
 }
 
+static bool new_without_trip(struct dive *a)
+{
+	return a->downloaded && !a->divetrip;
+}
+
 /*
  * Do we want to automatically try to merge two dives that
  * look like they are the same dive?
@@ -1893,9 +1898,16 @@ static int likely_same_dive(struct dive *a, struct dive *b)
 {
 	int match, fuzz = 20 * 60;
 
-	/* Don't try to merge dives in different trips */
-	if (a->divetrip && b->divetrip && a->divetrip != b->divetrip)
-		return 0;
+	/* Don't try to merge dives with different trip information */
+	if (a->divetrip != b->divetrip) {
+		/*
+		 * Exception: if the dive is downloaded without any
+		 * explicit trip information, we do want to merge it
+		 * with existing old dives even if they have trips.
+		 */
+		if (!new_without_trip(a) && !new_without_trip(b))
+			return 0;
+	}
 
 	/*
 	 * Do some basic sanity testing of the values we
diff --git a/libdivecomputer.c b/libdivecomputer.c
index 0011a201d981..401fd8a6f4af 100644
--- a/libdivecomputer.c
+++ b/libdivecomputer.c
@@ -515,6 +515,13 @@ static int dive_cb(const unsigned char *data, unsigned int size,
 		dive->dc.sample[0].temperature.mkelvin = 0;
 	}
 
+	if (devdata->create_new_trip) {
+		if (!devdata->trip)
+			devdata->trip = create_and_hookup_trip_from_dive(dive);
+		else
+			add_dive_to_trip(dive, devdata->trip);
+	}
+
 	dive->downloaded = true;
 	record_dive(dive);
 	mark_divelist_changed(true);
diff --git a/libdivecomputer.h b/libdivecomputer.h
index d9c5ac90a28a..f277e298fe1a 100644
--- a/libdivecomputer.h
+++ b/libdivecomputer.h
@@ -23,8 +23,10 @@ typedef struct device_data_t
 	uint32_t deviceid, diveid;
 	dc_device_t *device;
 	dc_context_t *context;
+	struct dive_trip *trip;
 	int preexisting;
 	bool force_download;
+	bool create_new_trip;
 	bool libdc_log;
 	bool libdc_dump;
 	FILE *libdc_logfile;
diff --git a/qt-ui/downloadfromdivecomputer.cpp b/qt-ui/downloadfromdivecomputer.cpp
index d2a5fae1c6af..fe5d4ee9a26b 100644
--- a/qt-ui/downloadfromdivecomputer.cpp
+++ b/qt-ui/downloadfromdivecomputer.cpp
@@ -284,6 +284,8 @@ void DownloadFromDCWidget::on_ok_clicked()
 
 	data.descriptor = descriptorLookup[ui.vendor->currentText() + ui.product->currentText()];
 	data.force_download = ui.forceDownload->isChecked();
+	data.create_new_trip = ui.createNewTrip->isChecked();
+	data.trip = NULL;
 	data.deviceid = data.diveid = 0;
 	set_default_dive_computer(data.vendor, data.product);
 	set_default_dive_computer_device(data.devname);
@@ -413,6 +415,7 @@ void DownloadFromDCWidget::markChildrenAsDisabled()
 	ui.vendor->setDisabled(true);
 	ui.product->setDisabled(true);
 	ui.forceDownload->setDisabled(true);
+	ui.createNewTrip->setDisabled(true);
 	ui.preferDownloaded->setDisabled(true);
 	ui.ok->setDisabled(true);
 	ui.search->setDisabled(true);
@@ -428,6 +431,7 @@ void DownloadFromDCWidget::markChildrenAsEnabled()
 	ui.vendor->setDisabled(false);
 	ui.product->setDisabled(false);
 	ui.forceDownload->setDisabled(false);
+	ui.createNewTrip->setDisabled(false);
 	ui.preferDownloaded->setDisabled(false);
 	ui.ok->setDisabled(false);
 	ui.cancel->setDisabled(false);
diff --git a/qt-ui/downloadfromdivecomputer.ui b/qt-ui/downloadfromdivecomputer.ui
index e99782ee8d06..9ea85afc80c8 100644
--- a/qt-ui/downloadfromdivecomputer.ui
+++ b/qt-ui/downloadfromdivecomputer.ui
@@ -74,7 +74,7 @@
      </property>
     </widget>
    </item>
-   <item row="8" column="0" colspan="3">
+   <item row="9" column="0" colspan="3">
     <layout class="QHBoxLayout" name="horizontalLayout">
      <item>
       <spacer name="horizontalSpacer">
@@ -105,41 +105,48 @@
      </item>
     </layout>
    </item>
-   <item row="9" column="0" colspan="3">
+   <item row="10" column="0" colspan="3">
     <widget class="QProgressBar" name="progressBar">
      <property name="value">
       <number>24</number>
      </property>
     </widget>
    </item>
-   <item row="6" column="0" colspan="2">
+   <item row="7" column="0" colspan="2">
     <widget class="QCheckBox" name="logToFile">
      <property name="text">
       <string>Save libdivecomputer logfile</string>
      </property>
     </widget>
    </item>
-   <item row="7" column="0" colspan="2">
+   <item row="8" column="0" colspan="2">
     <widget class="QCheckBox" name="dumpToFile">
      <property name="text">
       <string>Save libdivecomputer dumpfile</string>
      </property>
     </widget>
    </item>
-   <item row="6" column="2">
+   <item row="7" column="2">
     <widget class="QToolButton" name="chooseLogFile">
      <property name="text">
       <string>...</string>
      </property>
     </widget>
    </item>
-   <item row="7" column="2">
+   <item row="8" column="2">
     <widget class="QToolButton" name="chooseDumpFile">
      <property name="text">
       <string>...</string>
      </property>
     </widget>
    </item>
+   <item row="6" column="0">
+    <widget class="QCheckBox" name="createNewTrip">
+     <property name="text">
+      <string>Download into new trip</string>
+     </property>
+    </widget>
+   </item>
   </layout>
  </widget>
  <resources/>
-- 
2.0.1.563.g66f467c



More information about the subsurface mailing list