[RFC PATCH] Add 'create new trip' option for downloading dives from the dive computer

Linus Torvalds torvalds at linux-foundation.org
Mon Jul 21 17:36:54 PDT 2014


So I've now had the occasional situation where I'm sharing dive computers 
with others - we've had it with Dirk and me switching computers, and last 
week I encountered it when wanting to look and compare dives with my 
daughter who used one of my computers during her dives.

I've also had it happen "indirectly" when just serviving my dive computer, 
and as a result the dive computer gets reset with test dives that may have 
odd times and dates, and generally being uninteresting.

That generally isn't a huge problem, *except* for the fact that when you 
download the dives, the auto-merging of dives ends up meaning that these 
dives can incorrectly pollute your own dive log. You might want to look at 
your and your daughters dives side by side in the same app, and switch 
between the two, for example - *without* merging the two into one dive.

And when having odd extraneous dives after servicing, since the date and 
time isn't ncessarily correctly set (think battery change etc), the extra 
dives may show up in random places in your history, and not be all that 
easy to see.

In other words, it can get messy.

Last time this happened, I mentioned to Dirk that maybe we should have a 
"download only last N days" in the dive computer download logic, but that 
ends up having its own set of problems, like the fact that some dive 
computers will only download things in a certain order (and not 
necessarily latest first), so it's hard to say "start at xyz". It also 
ends up being a messy interface.

This patch is small and simple, and takes a completely different approach: 
it adds a check box for creating a new dive trip that all the newly 
downloaded dives get put into.  That not only happens to be very easy for 
us to do, but it ends up being quite flexible, in that it basically 
"quarantines" the newly downloaded dives into a trip of their own.

That private trip means that:

 - the newly downloaded dives will not be merged with your old dives if 
   they are already in a trip.

 - the newly downloaded dives are easy to find even if they have odd 
   dates, because they are not spread out chronologically intermixed with 
   other dives, since we sort by trip first and dive date second.

 - you can now edit/delete the dives as you wish, and then you have the 
   choice to perhaps merge the trips/dives manually for those dives you 
   wish to merge.

In other words, it solves the mess problem. 

One caveat: it *only* solves the mess problem if you keep all your other 
dives in trips too. If you have old dives that aren't in some trip, and 
they overlap with the newly downloaded dives, the dive merging might still 
choose to merge that old non-trip dive with the newly downloaded dive that 
has the new private trip. But at least for my use case, this isn't really 
a problem.

Anyway, it's simple, and it solves one particular use-case. But the reason 
I mark the patch with an RFC is that while the thing works for me, it is 
kind of a subtle and indirect solution to the problem of mixing dives. At 
the same time, the whole concept of "create a new trip for the new dives" 
does make conceptual sense even on its own, so I don't think this is 
really wrong.

Comments?

Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
---

Oh, there's another caveat too: this only happens for libdivecomputer 
downloads. I did *not* add the logic to the Uemis downloader, although the 
trivial few added lines to "libdivecomputer.c" should probably work fine 
thetre too. It's just that my current only test-case is for my Suunto 
Vyper Air.

The uemis-download.c file has two separate "record_dive()" functions, and 
they should both need that logic, I think.

Hmm?

 libdivecomputer.c                  |  7 +++++++
 libdivecomputer.h                  |  2 ++
 qt-ui/downloadfromdivecomputer.cpp |  4 ++++
 qt-ui/downloadfromdivecomputer.ui  | 19 +++++++++++++------
 4 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/libdivecomputer.c b/libdivecomputer.c
index 22df874fe696..29aaeae03efa 100644
--- a/libdivecomputer.c
+++ b/libdivecomputer.c
@@ -509,6 +509,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/>


More information about the subsurface mailing list