Okay,

This is *completely* untested.
the code *makes sense* but I didn't figured out how to test without my dive
computers, so there may be bugs, crashes and a few other things, but it's
an step in the right direction.

my time for subsurrface today is over, but I'll try to get more at night.

all "testable" parts, I'v tested. and no crashes, the code should still
download stuff
from the dive computers and present on the table.
If that crashes, it's probably an off-by-one error, simple to fix.
From 718962cb81e74b3650441d90f7ad4ea83f8aadea Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Thu, 8 Jan 2015 10:12:11 -0200
Subject: [PATCH 01/15] Added skeleton for the Dialog to show the imported
 dives

So the user can remove the ones he doesn't like.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/downloadfromdivecomputer.cpp | 65 ++++++++++++++++++++++++++++----------
 qt-ui/downloadfromdivecomputer.h   | 16 ++++++++++
 2 files changed, 64 insertions(+), 17 deletions(-)

diff --git a/qt-ui/downloadfromdivecomputer.cpp b/qt-ui/downloadfromdivecomputer.cpp
index 7f5fd4a..b359aa5 100644
--- a/qt-ui/downloadfromdivecomputer.cpp
+++ b/qt-ui/downloadfromdivecomputer.cpp
@@ -53,6 +53,7 @@ DownloadFromDCWidget::DownloadFromDCWidget(QWidget *parent, Qt::WindowFlags f) :
 	ui.progressBar->hide();
 	ui.progressBar->setMinimum(0);
 	ui.progressBar->setMaximum(100);
+	diveImportedModel = new DiveImportedModel(this);
 
 	progress_bar_text = "";
 
@@ -388,23 +389,7 @@ void DownloadFromDCWidget::onDownloadThreadFinished()
 			for (int i = dive_table.nr - 1; i >= previousLast; i--)
 				delete_single_dive(i);
 		} else if (dive_table.nr) {
-			int uniqId, idx;
-			// remember the last downloaded dive (on most dive computers this will be the chronologically
-			// first new dive) and select it again after processing all the dives
-			MainWindow::instance()->dive_list()->unselectDives();
-			uniqId = get_dive(dive_table.nr - 1)->id;
-			process_dives(true, preferDownloaded());
-			// after process_dives does any merging or resorting needed, we need
-			// to recreate the model for the dive list so we can select the newest dive
-			MainWindow::instance()->recreateDiveList();
-			idx = get_idx_by_uniq_id(uniqId);
-			// this shouldn't be necessary - but there are reports that somehow existing dives stay selected
-			// (but not visible as selected)
-			MainWindow::instance()->dive_list()->unselectDives();
-			MainWindow::instance()->dive_list()->selectDive(idx, true);
-			QString dcName = data.devname;
-			if (ostcFirmwareCheck && currentState == DONE)
-				ostcFirmwareCheck->checkLatest(this, &data);
+			diveImportedModel->setImportedDivesIndexes(previousLast, dive_table.nr-1);
 		}
 	} else if (currentState == CANCELLING || currentState == CANCELLED) {
 		if (import_thread_cancelled) {
@@ -416,6 +401,27 @@ void DownloadFromDCWidget::onDownloadThreadFinished()
 		updateState(CANCELLED);
 	}
 }
+/*
+ * This needs to get moved somewhere else.
+	int uniqId, idx;
+	// remember the last downloaded dive (on most dive computers this will be the chronologically
+	// first new dive) and select it again after processing all the dives
+	MainWindow::instance()->dive_list()->unselectDives();
+	uniqId = get_dive(dive_table.nr - 1)->id;
+	process_dives(true, preferDownloaded());
+	// after process_dives does any merging or resorting needed, we need
+	// to recreate the model for the dive list so we can select the newest dive
+	MainWindow::instance()->recreateDiveList();
+	idx = get_idx_by_uniq_id(uniqId);
+	// this shouldn't be necessary - but there are reports that somehow existing dives stay selected
+	// (but not visible as selected)
+	MainWindow::instance()->dive_list()->unselectDives();
+	MainWindow::instance()->dive_list()->selectDive(idx, true);
+	QString dcName = data.devname;
+	if (ostcFirmwareCheck && currentState == DONE)
+		ostcFirmwareCheck->checkLatest(this, &data);
+
+*/
 
 void DownloadFromDCWidget::markChildrenAsDisabled()
 {
@@ -491,3 +497,28 @@ void DownloadThread::run()
 	if (errorText)
 		error = str_error(errorText, data->devname, data->vendor, data->product);
 }
+
+DiveImportedModel::DiveImportedModel(QObject *o)
+{
+
+}
+
+int DiveImportedModel::columnCount(const QModelIndex& model ) const
+{
+
+}
+
+int DiveImportedModel::rowCount(const QModelIndex& model) const
+{
+
+}
+
+QVariant DiveImportedModel::data(const QModelIndex& model, int role) const
+{
+
+}
+
+void DiveImportedModel::setImportedDivesIndexes(int first, int last)
+{
+
+}
diff --git a/qt-ui/downloadfromdivecomputer.h b/qt-ui/downloadfromdivecomputer.h
index dcb568c..799b0c9 100644
--- a/qt-ui/downloadfromdivecomputer.h
+++ b/qt-ui/downloadfromdivecomputer.h
@@ -5,6 +5,7 @@
 #include <QThread>
 #include <QHash>
 #include <QMap>
+#include <QAbstractTableModel>
 
 #include "libdivecomputer.h"
 #include "configuredivecomputerdialog.h"
@@ -24,6 +25,20 @@ private:
 	device_data_t *data;
 };
 
+class DiveImportedModel : public QAbstractTableModel
+{
+	Q_OBJECT
+public:
+	DiveImportedModel(QObject *o);
+	int columnCount(const QModelIndex& index = QModelIndex()) const;
+	int rowCount(const QModelIndex& index = QModelIndex()) const;
+	QVariant data(const QModelIndex& index, int role) const;
+	void setImportedDivesIndexes(int first, int last);
+private:
+	int firstIndex;
+	int lastIndex;
+};
+
 class DownloadFromDCWidget : public QDialog {
 	Q_OBJECT
 public:
@@ -77,6 +92,7 @@ private:
 	QTimer *timer;
 	bool dumpWarningShown;
 	OstcFirmwareCheck *ostcFirmwareCheck;
+	DiveImportedModel *diveImportedModel;
 
 public:
 	bool preferDownloaded();
-- 
2.2.1

From 11255f0c86e427adea2b3c25d2f1163f79bbf848 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Thu, 8 Jan 2015 10:13:36 -0200
Subject: [PATCH 02/15] Constructor, rowCount and ColumnCount

now - importedDivesIndexes and Data.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/downloadfromdivecomputer.cpp | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/qt-ui/downloadfromdivecomputer.cpp b/qt-ui/downloadfromdivecomputer.cpp
index b359aa5..cc695a7 100644
--- a/qt-ui/downloadfromdivecomputer.cpp
+++ b/qt-ui/downloadfromdivecomputer.cpp
@@ -498,19 +498,20 @@ void DownloadThread::run()
 		error = str_error(errorText, data->devname, data->vendor, data->product);
 }
 
-DiveImportedModel::DiveImportedModel(QObject *o)
+DiveImportedModel::DiveImportedModel(QObject *o) : QAbstractTableModel(o),
+	lastIndex(0),
+	firstIndex(0)
 {
-
 }
 
 int DiveImportedModel::columnCount(const QModelIndex& model ) const
 {
-
+	return 5;
 }
 
 int DiveImportedModel::rowCount(const QModelIndex& model) const
 {
-
+	return lastIndex - firstIndex;
 }
 
 QVariant DiveImportedModel::data(const QModelIndex& model, int role) const
-- 
2.2.1

From 2846c5633bec9d7a803c4e873dd4dbbfc730f69b Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Thu, 8 Jan 2015 10:15:34 -0200
Subject: [PATCH 03/15] setImportedDivesIndexes - implementation

Here we list to the model what are our dives, inside
the dive_table.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/downloadfromdivecomputer.cpp | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/qt-ui/downloadfromdivecomputer.cpp b/qt-ui/downloadfromdivecomputer.cpp
index cc695a7..6a1650e 100644
--- a/qt-ui/downloadfromdivecomputer.cpp
+++ b/qt-ui/downloadfromdivecomputer.cpp
@@ -521,5 +521,10 @@ QVariant DiveImportedModel::data(const QModelIndex& model, int role) const
 
 void DiveImportedModel::setImportedDivesIndexes(int first, int last)
 {
-
+	beginRemoveRows(QModelIndex(), 0, lastIndex - firstIndex);
+	endRemoveRows();
+	beginInsertRows(QModelIndex(), 0, last - first);
+	lastIndex = last;
+	firstIndex = first;
+	endInsertRows();
 }
-- 
2.2.1

From dc3fea7b63e5f6c30a73c9ee6775e478d3bf1104 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Thu, 8 Jan 2015 10:25:38 -0200
Subject: [PATCH 04/15] Display the downloaded data for the Dives in a table.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/downloadfromdivecomputer.cpp | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/qt-ui/downloadfromdivecomputer.cpp b/qt-ui/downloadfromdivecomputer.cpp
index 6a1650e..31d1dda 100644
--- a/qt-ui/downloadfromdivecomputer.cpp
+++ b/qt-ui/downloadfromdivecomputer.cpp
@@ -514,9 +514,24 @@ int DiveImportedModel::rowCount(const QModelIndex& model) const
 	return lastIndex - firstIndex;
 }
 
-QVariant DiveImportedModel::data(const QModelIndex& model, int role) const
+QVariant DiveImportedModel::data(const QModelIndex& index, int role) const
 {
-
+	if (!index.isValid())
+		return QVariant();
+
+	if (index.row() + firstIndex > lastIndex)
+		return QVariant();
+
+	struct dive* d = get_dive( index.row() + firstIndex);
+	if (role == Qt::DisplayRole) {
+		switch(index.column()){
+			case 0 : return QVariant(d->when);
+			case 1 : return QVariant(d->duration);
+			case 2 : return QVariant(d->maxdepth);
+			case 3 : return QVariant(d->latitude);
+			case 4 : return QVariant(d->longitude);
+		}
+	}
 }
 
 void DiveImportedModel::setImportedDivesIndexes(int first, int last)
-- 
2.2.1

From 08881ea162e34b835efae0758f3ac640bfca5787 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Thu, 8 Jan 2015 10:52:54 -0200
Subject: [PATCH 05/15] Added the check states.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/downloadfromdivecomputer.cpp | 19 +++++++++++++------
 qt-ui/downloadfromdivecomputer.h   |  1 +
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/qt-ui/downloadfromdivecomputer.cpp b/qt-ui/downloadfromdivecomputer.cpp
index 31d1dda..91e38ae 100644
--- a/qt-ui/downloadfromdivecomputer.cpp
+++ b/qt-ui/downloadfromdivecomputer.cpp
@@ -500,7 +500,8 @@ void DownloadThread::run()
 
 DiveImportedModel::DiveImportedModel(QObject *o) : QAbstractTableModel(o),
 	lastIndex(0),
-	firstIndex(0)
+	firstIndex(0),
+	checkStates(0)
 {
 }
 
@@ -525,13 +526,17 @@ QVariant DiveImportedModel::data(const QModelIndex& index, int role) const
 	struct dive* d = get_dive( index.row() + firstIndex);
 	if (role == Qt::DisplayRole) {
 		switch(index.column()){
-			case 0 : return QVariant(d->when);
-			case 1 : return QVariant(d->duration);
-			case 2 : return QVariant(d->maxdepth);
-			case 3 : return QVariant(d->latitude);
-			case 4 : return QVariant(d->longitude);
+			case 0 : return QVariant((int) d->when);
+			case 1 : return QVariant(d->duration.seconds);
+			case 2 : return QVariant(d->maxdepth.mm);
+			case 3 : return QVariant(d->latitude.udeg);
+			case 4 : return QVariant(d->longitude.udeg);
 		}
 	}
+	if (role == Qt::CheckStateRole) {
+		return checkStates[index.row() + firstIndex] ? Qt::Checked : Qt::Unchecked;
+	}
+	return QVariant();
 }
 
 void DiveImportedModel::setImportedDivesIndexes(int first, int last)
@@ -541,5 +546,7 @@ void DiveImportedModel::setImportedDivesIndexes(int first, int last)
 	beginInsertRows(QModelIndex(), 0, last - first);
 	lastIndex = last;
 	firstIndex = first;
+	delete[] checkStates;
+	checkStates = new bool[last-first];
 	endInsertRows();
 }
diff --git a/qt-ui/downloadfromdivecomputer.h b/qt-ui/downloadfromdivecomputer.h
index 799b0c9..c49ad9a 100644
--- a/qt-ui/downloadfromdivecomputer.h
+++ b/qt-ui/downloadfromdivecomputer.h
@@ -37,6 +37,7 @@ public:
 private:
 	int firstIndex;
 	int lastIndex;
+	bool *checkStates;
 };
 
 class DownloadFromDCWidget : public QDialog {
-- 
2.2.1

From ddd13f68fae0080afb16a1e0fd00450fe991a685 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Thu, 8 Jan 2015 10:55:38 -0200
Subject: [PATCH 06/15] Added the 'set data' method

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/downloadfromdivecomputer.cpp | 15 +++++++++++++++
 qt-ui/downloadfromdivecomputer.h   |  1 +
 2 files changed, 16 insertions(+)

diff --git a/qt-ui/downloadfromdivecomputer.cpp b/qt-ui/downloadfromdivecomputer.cpp
index 91e38ae..a7363c4 100644
--- a/qt-ui/downloadfromdivecomputer.cpp
+++ b/qt-ui/downloadfromdivecomputer.cpp
@@ -539,6 +539,21 @@ QVariant DiveImportedModel::data(const QModelIndex& index, int role) const
 	return QVariant();
 }
 
+bool DiveImportedModel::setData(const QModelIndex &index, const QVariant &value, int role)
+{
+	if (!index.isValid())
+		return false;
+
+	if (index.row() + firstIndex > lastIndex)
+		return false;
+
+	if (role != Qt::CheckStateRole)
+		return false;
+
+	checkStates[index.row() + firstIndex ] = value.toBool();
+	dataChanged(index, index, QVector<int>() << Qt::CheckStateRole);
+}
+
 void DiveImportedModel::setImportedDivesIndexes(int first, int last)
 {
 	beginRemoveRows(QModelIndex(), 0, lastIndex - firstIndex);
diff --git a/qt-ui/downloadfromdivecomputer.h b/qt-ui/downloadfromdivecomputer.h
index c49ad9a..028f7dd 100644
--- a/qt-ui/downloadfromdivecomputer.h
+++ b/qt-ui/downloadfromdivecomputer.h
@@ -33,6 +33,7 @@ public:
 	int columnCount(const QModelIndex& index = QModelIndex()) const;
 	int rowCount(const QModelIndex& index = QModelIndex()) const;
 	QVariant data(const QModelIndex& index, int role) const;
+	bool setData(const QModelIndex &index, const QVariant &value, int role);
 	void setImportedDivesIndexes(int first, int last);
 private:
 	int firstIndex;
-- 
2.2.1

From a623009302753d097f7f950ff123c35e48075629 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Thu, 8 Jan 2015 11:00:42 -0200
Subject: [PATCH 07/15] Set the item falgs so it's possible to check states.

now the user can click on the dives that he want to have.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/downloadfromdivecomputer.cpp | 6 ++++++
 qt-ui/downloadfromdivecomputer.h   | 1 +
 2 files changed, 7 insertions(+)

diff --git a/qt-ui/downloadfromdivecomputer.cpp b/qt-ui/downloadfromdivecomputer.cpp
index a7363c4..ff42d41 100644
--- a/qt-ui/downloadfromdivecomputer.cpp
+++ b/qt-ui/downloadfromdivecomputer.cpp
@@ -554,6 +554,12 @@ bool DiveImportedModel::setData(const QModelIndex &index, const QVariant &value,
 	dataChanged(index, index, QVector<int>() << Qt::CheckStateRole);
 }
 
+Qt::ItemFlags DiveImportedModel::flags(const QModelIndex &index) const {
+	if (index.column() != 0)
+		return QAbstractTableModel::flags(index);
+	return QAbstractTableModel::flags(index) | Qt::ItemIsUserCheckable;
+}
+
 void DiveImportedModel::setImportedDivesIndexes(int first, int last)
 {
 	beginRemoveRows(QModelIndex(), 0, lastIndex - firstIndex);
diff --git a/qt-ui/downloadfromdivecomputer.h b/qt-ui/downloadfromdivecomputer.h
index 028f7dd..8ab7e36 100644
--- a/qt-ui/downloadfromdivecomputer.h
+++ b/qt-ui/downloadfromdivecomputer.h
@@ -35,6 +35,7 @@ public:
 	QVariant data(const QModelIndex& index, int role) const;
 	bool setData(const QModelIndex &index, const QVariant &value, int role);
 	void setImportedDivesIndexes(int first, int last);
+	Qt::ItemFlags flags(const QModelIndex &index) const;
 private:
 	int firstIndex;
 	int lastIndex;
-- 
2.2.1

From e85e4b275f9a245cb8d727aca0385d8b74fa1fc3 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Thu, 8 Jan 2015 11:07:27 -0200
Subject: [PATCH 08/15] Fill the checked vector as true.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/downloadfromdivecomputer.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/qt-ui/downloadfromdivecomputer.cpp b/qt-ui/downloadfromdivecomputer.cpp
index ff42d41..e9cb942 100644
--- a/qt-ui/downloadfromdivecomputer.cpp
+++ b/qt-ui/downloadfromdivecomputer.cpp
@@ -569,5 +569,6 @@ void DiveImportedModel::setImportedDivesIndexes(int first, int last)
 	firstIndex = first;
 	delete[] checkStates;
 	checkStates = new bool[last-first];
+	memset(checkStates, true, last-first);
 	endInsertRows();
 }
-- 
2.2.1

From cc2b404077635d2fd6cb94514fa0c5abf19f1dba Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Thu, 8 Jan 2015 11:23:06 -0200
Subject: [PATCH 09/15] Added a table on the Import Dives from DC dialog

It will show the model that I just created.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/downloadfromdivecomputer.ui | 251 ++++++++++++++++++++++++--------------
 1 file changed, 158 insertions(+), 93 deletions(-)

diff --git a/qt-ui/downloadfromdivecomputer.ui b/qt-ui/downloadfromdivecomputer.ui
index 9ea85af..d67094a 100644
--- a/qt-ui/downloadfromdivecomputer.ui
+++ b/qt-ui/downloadfromdivecomputer.ui
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>331</width>
-    <height>314</height>
+    <width>625</width>
+    <height>535</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -18,63 +18,163 @@
     <normalon>:/subsurface-icon</normalon>
    </iconset>
   </property>
-  <layout class="QGridLayout" name="gridLayout">
-   <item row="2" column="0" colspan="3">
-    <widget class="QLabel" name="label_3">
-     <property name="text">
-      <string>Device or mount point</string>
-     </property>
-    </widget>
-   </item>
-   <item row="3" column="0" colspan="2">
-    <widget class="QComboBox" name="device">
-     <property name="editable">
-      <bool>true</bool>
-     </property>
-    </widget>
-   </item>
-   <item row="0" column="0">
-    <widget class="QLabel" name="label">
-     <property name="text">
-      <string>Vendor</string>
-     </property>
-    </widget>
-   </item>
-   <item row="0" column="1" colspan="2">
-    <widget class="QLabel" name="label_2">
-     <property name="text">
-      <string>Dive computer</string>
-     </property>
-    </widget>
-   </item>
-   <item row="1" column="0">
-    <widget class="QComboBox" name="vendor"/>
-   </item>
-   <item row="1" column="1" colspan="2">
-    <widget class="QComboBox" name="product"/>
-   </item>
-   <item row="3" column="2">
-    <widget class="QToolButton" name="search">
-     <property name="text">
-      <string>...</string>
-     </property>
-    </widget>
-   </item>
-   <item row="4" column="0" colspan="3">
-    <widget class="QCheckBox" name="forceDownload">
-     <property name="text">
-      <string>Force download of all dives</string>
-     </property>
-    </widget>
+  <layout class="QVBoxLayout" name="verticalLayout_2">
+   <item>
+    <layout class="QGridLayout" name="gridLayout">
+     <item row="0" column="0">
+      <widget class="QLabel" name="label">
+       <property name="text">
+        <string>Vendor</string>
+       </property>
+      </widget>
+     </item>
+     <item row="0" column="1">
+      <widget class="QLabel" name="label_2">
+       <property name="text">
+        <string>Dive computer</string>
+       </property>
+      </widget>
+     </item>
+     <item row="1" column="0">
+      <widget class="QComboBox" name="vendor"/>
+     </item>
+     <item row="1" column="1">
+      <widget class="QComboBox" name="product"/>
+     </item>
+    </layout>
    </item>
-   <item row="5" column="0" colspan="3">
-    <widget class="QCheckBox" name="preferDownloaded">
-     <property name="text">
-      <string>Always prefer downloaded dives</string>
-     </property>
-    </widget>
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout_4">
+     <item>
+      <layout class="QVBoxLayout" name="verticalLayout">
+       <item>
+        <layout class="QGridLayout" name="gridLayout_2">
+         <item row="0" column="0">
+          <widget class="QLabel" name="label_3">
+           <property name="text">
+            <string>Device or mount point</string>
+           </property>
+          </widget>
+         </item>
+         <item row="1" column="0">
+          <widget class="QComboBox" name="device">
+           <property name="editable">
+            <bool>true</bool>
+           </property>
+          </widget>
+         </item>
+         <item row="1" column="1">
+          <widget class="QToolButton" name="search">
+           <property name="text">
+            <string>...</string>
+           </property>
+          </widget>
+         </item>
+         <item row="2" column="0">
+          <widget class="QCheckBox" name="forceDownload">
+           <property name="text">
+            <string>Force download of all dives</string>
+           </property>
+          </widget>
+         </item>
+         <item row="3" column="0">
+          <widget class="QCheckBox" name="preferDownloaded">
+           <property name="text">
+            <string>Always prefer downloaded dives</string>
+           </property>
+          </widget>
+         </item>
+         <item row="4" column="0">
+          <widget class="QCheckBox" name="createNewTrip">
+           <property name="text">
+            <string>Download into new trip</string>
+           </property>
+          </widget>
+         </item>
+         <item row="5" column="0">
+          <widget class="QCheckBox" name="logToFile">
+           <property name="text">
+            <string>Save libdivecomputer logfile</string>
+           </property>
+          </widget>
+         </item>
+         <item row="5" column="1">
+          <widget class="QToolButton" name="chooseLogFile">
+           <property name="text">
+            <string>...</string>
+           </property>
+          </widget>
+         </item>
+         <item row="6" column="0">
+          <widget class="QCheckBox" name="dumpToFile">
+           <property name="text">
+            <string>Save libdivecomputer dumpfile</string>
+           </property>
+          </widget>
+         </item>
+         <item row="6" column="1">
+          <widget class="QToolButton" name="chooseDumpFile">
+           <property name="text">
+            <string>...</string>
+           </property>
+          </widget>
+         </item>
+        </layout>
+       </item>
+       <item>
+        <spacer name="verticalSpacer">
+         <property name="orientation">
+          <enum>Qt::Vertical</enum>
+         </property>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>20</width>
+           <height>40</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
+       <item>
+        <layout class="QHBoxLayout" name="horizontalLayout_3">
+         <item>
+          <spacer name="horizontalSpacer_2">
+           <property name="orientation">
+            <enum>Qt::Horizontal</enum>
+           </property>
+           <property name="sizeHint" stdset="0">
+            <size>
+             <width>40</width>
+             <height>20</height>
+            </size>
+           </property>
+          </spacer>
+         </item>
+         <item>
+          <widget class="QPushButton" name="pushButton">
+           <property name="text">
+            <string>Download</string>
+           </property>
+          </widget>
+         </item>
+        </layout>
+       </item>
+      </layout>
+     </item>
+     <item>
+      <widget class="QGroupBox" name="groupBox">
+       <property name="title">
+        <string>Downloaded Dives</string>
+       </property>
+       <layout class="QHBoxLayout" name="horizontalLayout_2">
+        <item>
+         <widget class="QTableView" name="downloadedView"/>
+        </item>
+       </layout>
+      </widget>
+     </item>
+    </layout>
    </item>
-   <item row="9" column="0" colspan="3">
+   <item>
     <layout class="QHBoxLayout" name="horizontalLayout">
      <item>
       <spacer name="horizontalSpacer">
@@ -105,48 +205,13 @@
      </item>
     </layout>
    </item>
-   <item row="10" column="0" colspan="3">
+   <item>
     <widget class="QProgressBar" name="progressBar">
      <property name="value">
       <number>24</number>
      </property>
     </widget>
    </item>
-   <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="8" column="0" colspan="2">
-    <widget class="QCheckBox" name="dumpToFile">
-     <property name="text">
-      <string>Save libdivecomputer dumpfile</string>
-     </property>
-    </widget>
-   </item>
-   <item row="7" column="2">
-    <widget class="QToolButton" name="chooseLogFile">
-     <property name="text">
-      <string>...</string>
-     </property>
-    </widget>
-   </item>
-   <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.2.1

From c7dfeb4dec1b83ecd8d3b307bbe36c76c9f45c6e Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Thu, 8 Jan 2015 11:29:28 -0200
Subject: [PATCH 10/15] Create a button to download the data from DC

now, ok should close the dialog, and not download the
dives from the DC, this way the user can choose what
goes around.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/downloadfromdivecomputer.cpp | 3 ++-
 qt-ui/downloadfromdivecomputer.h   | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/qt-ui/downloadfromdivecomputer.cpp b/qt-ui/downloadfromdivecomputer.cpp
index e9cb942..4e4a24f 100644
--- a/qt-ui/downloadfromdivecomputer.cpp
+++ b/qt-ui/downloadfromdivecomputer.cpp
@@ -54,6 +54,7 @@ DownloadFromDCWidget::DownloadFromDCWidget(QWidget *parent, Qt::WindowFlags f) :
 	ui.progressBar->setMinimum(0);
 	ui.progressBar->setMaximum(100);
 	diveImportedModel = new DiveImportedModel(this);
+	ui.downloadedView->setModel(diveImportedModel);
 
 	progress_bar_text = "";
 
@@ -270,7 +271,7 @@ void DownloadFromDCWidget::on_cancel_clicked()
 	updateState(CANCELLING);
 }
 
-void DownloadFromDCWidget::on_ok_clicked()
+void DownloadFromDCWidget::on_startDownload_clicked()
 {
 	updateState(DOWNLOADING);
 
diff --git a/qt-ui/downloadfromdivecomputer.h b/qt-ui/downloadfromdivecomputer.h
index 8ab7e36..a23beb0 100644
--- a/qt-ui/downloadfromdivecomputer.h
+++ b/qt-ui/downloadfromdivecomputer.h
@@ -59,7 +59,7 @@ public:
 
 public
 slots:
-	void on_ok_clicked();
+	void on_startDownload_clicked();
 	void on_cancel_clicked();
 	void on_search_clicked();
 	void on_vendor_currentIndexChanged(const QString &vendor);
-- 
2.2.1

From cb84e31f31d70871c7e34ce90620c8a38802dff4 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Thu, 8 Jan 2015 11:31:05 -0200
Subject: [PATCH 11/15] Created an on_ok_clicked that will do the actuall
 parsing of choosen dives.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/downloadfromdivecomputer.cpp | 8 ++++----
 qt-ui/downloadfromdivecomputer.h   | 1 +
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/qt-ui/downloadfromdivecomputer.cpp b/qt-ui/downloadfromdivecomputer.cpp
index 4e4a24f..abc6fff 100644
--- a/qt-ui/downloadfromdivecomputer.cpp
+++ b/qt-ui/downloadfromdivecomputer.cpp
@@ -402,8 +402,9 @@ void DownloadFromDCWidget::onDownloadThreadFinished()
 		updateState(CANCELLED);
 	}
 }
-/*
- * This needs to get moved somewhere else.
+
+void DownloadFromDCWidget::on_ok_clicked()
+{
 	int uniqId, idx;
 	// remember the last downloaded dive (on most dive computers this will be the chronologically
 	// first new dive) and select it again after processing all the dives
@@ -421,8 +422,7 @@ void DownloadFromDCWidget::onDownloadThreadFinished()
 	QString dcName = data.devname;
 	if (ostcFirmwareCheck && currentState == DONE)
 		ostcFirmwareCheck->checkLatest(this, &data);
-
-*/
+}
 
 void DownloadFromDCWidget::markChildrenAsDisabled()
 {
diff --git a/qt-ui/downloadfromdivecomputer.h b/qt-ui/downloadfromdivecomputer.h
index a23beb0..b567dfe 100644
--- a/qt-ui/downloadfromdivecomputer.h
+++ b/qt-ui/downloadfromdivecomputer.h
@@ -60,6 +60,7 @@ public:
 public
 slots:
 	void on_startDownload_clicked();
+	void on_ok_clicked();
 	void on_cancel_clicked();
 	void on_search_clicked();
 	void on_vendor_currentIndexChanged(const QString &vendor);
-- 
2.2.1

From 716e136cd748407edc7a004b54d757a2c009e027 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Thu, 8 Jan 2015 11:52:12 -0200
Subject: [PATCH 12/15] Added the method to remove unused dives from the import

This tries to relete from the dive list the dives that shouldn't
be imported.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/downloadfromdivecomputer.cpp | 18 ++++++++++++++++++
 qt-ui/downloadfromdivecomputer.h   |  1 +
 2 files changed, 19 insertions(+)

diff --git a/qt-ui/downloadfromdivecomputer.cpp b/qt-ui/downloadfromdivecomputer.cpp
index abc6fff..465d19a 100644
--- a/qt-ui/downloadfromdivecomputer.cpp
+++ b/qt-ui/downloadfromdivecomputer.cpp
@@ -405,6 +405,9 @@ void DownloadFromDCWidget::onDownloadThreadFinished()
 
 void DownloadFromDCWidget::on_ok_clicked()
 {
+	// remove all unselected dives from the dive-list.
+	diveImportedModel->removeUnused();
+
 	int uniqId, idx;
 	// remember the last downloaded dive (on most dive computers this will be the chronologically
 	// first new dive) and select it again after processing all the dives
@@ -573,3 +576,18 @@ void DiveImportedModel::setImportedDivesIndexes(int first, int last)
 	memset(checkStates, true, last-first);
 	endInsertRows();
 }
+
+void DiveImportedModel::removeUnused() {
+	beginRemoveRows(QModelIndex(), 0, rowCount()-1);
+	endRemoveRows();
+
+	for(int i = lastIndex; i >= firstIndex; i-- ){
+		if(!checkStates[firstIndex - i]) {
+			delete_single_dive(i);
+		}
+	}
+
+	lastIndex = 0;
+	firstIndex = 0;
+	delete[] checkStates;
+}
diff --git a/qt-ui/downloadfromdivecomputer.h b/qt-ui/downloadfromdivecomputer.h
index b567dfe..ea27259 100644
--- a/qt-ui/downloadfromdivecomputer.h
+++ b/qt-ui/downloadfromdivecomputer.h
@@ -36,6 +36,7 @@ public:
 	bool setData(const QModelIndex &index, const QVariant &value, int role);
 	void setImportedDivesIndexes(int first, int last);
 	Qt::ItemFlags flags(const QModelIndex &index) const;
+	void removeUnused();
 private:
 	int firstIndex;
 	int lastIndex;
-- 
2.2.1

From b8521ac3fe3c357ab5b03b9957788942694e43b2 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Thu, 8 Jan 2015 11:53:16 -0200
Subject: [PATCH 13/15] Remove unused variable

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/downloadfromdivecomputer.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qt-ui/downloadfromdivecomputer.cpp b/qt-ui/downloadfromdivecomputer.cpp
index 465d19a..08ba940 100644
--- a/qt-ui/downloadfromdivecomputer.cpp
+++ b/qt-ui/downloadfromdivecomputer.cpp
@@ -422,7 +422,7 @@ void DownloadFromDCWidget::on_ok_clicked()
 	// (but not visible as selected)
 	MainWindow::instance()->dive_list()->unselectDives();
 	MainWindow::instance()->dive_list()->selectDive(idx, true);
-	QString dcName = data.devname;
+
 	if (ostcFirmwareCheck && currentState == DONE)
 		ostcFirmwareCheck->checkLatest(this, &data);
 }
-- 
2.2.1

From 8e465e037101f045f2c9b2010aa8a150215dce69 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Thu, 8 Jan 2015 11:56:00 -0200
Subject: [PATCH 14/15] Only try to get the dive list if download was
 successfull.

This fixes a crash where we tried to get the stuff around
without actually having downloaded anything.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/downloadfromdivecomputer.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/qt-ui/downloadfromdivecomputer.cpp b/qt-ui/downloadfromdivecomputer.cpp
index 08ba940..3181fab 100644
--- a/qt-ui/downloadfromdivecomputer.cpp
+++ b/qt-ui/downloadfromdivecomputer.cpp
@@ -405,6 +405,9 @@ void DownloadFromDCWidget::onDownloadThreadFinished()
 
 void DownloadFromDCWidget::on_ok_clicked()
 {
+	if (currentState != DONE)
+		return;
+
 	// remove all unselected dives from the dive-list.
 	diveImportedModel->removeUnused();
 
-- 
2.2.1

From 765a249e6684143aa3852f1e921a923d9f3ed0d1 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Thu, 8 Jan 2015 11:57:18 -0200
Subject: [PATCH 15/15] Fixed the name of a button so the download from dc
 actually works.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/downloadfromdivecomputer.ui | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qt-ui/downloadfromdivecomputer.ui b/qt-ui/downloadfromdivecomputer.ui
index d67094a..50d5666 100644
--- a/qt-ui/downloadfromdivecomputer.ui
+++ b/qt-ui/downloadfromdivecomputer.ui
@@ -150,7 +150,7 @@
           </spacer>
          </item>
          <item>
-          <widget class="QPushButton" name="pushButton">
+          <widget class="QPushButton" name="startDownload">
            <property name="text">
             <string>Download</string>
            </property>
-- 
2.2.1

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

Reply via email to