summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/dive.h14
-rw-r--r--core/divelist.c3
-rw-r--r--core/downloadfromdcthread.cpp11
-rw-r--r--core/downloadfromdcthread.h4
-rw-r--r--core/libdivecomputer.c2
5 files changed, 22 insertions, 12 deletions
diff --git a/core/dive.h b/core/dive.h
index d544bc9d1..6bc0f6fae 100644
--- a/core/dive.h
+++ b/core/dive.h
@@ -273,10 +273,10 @@ struct divecomputer {
#define W_IDX_PRIMARY 0
#define W_IDX_SECONDARY 1
-struct dive_table {
+typedef struct dive_table {
int nr, allocated;
struct dive **dives;
-};
+} dive_table_t;
typedef struct dive_trip
{
@@ -419,7 +419,7 @@ extern const struct units SI_units, IMPERIAL_units;
extern const struct units *get_units(void);
extern int run_survey, verbose, quit, force_root;
-extern struct dive_table dive_table, downloadTable;
+extern struct dive_table dive_table;
extern struct dive displayed_dive;
extern unsigned int dc_number;
extern struct dive *current_dive;
@@ -751,10 +751,14 @@ extern void average_max_depth(struct diveplan *dive, int *avg_depth, int *max_de
#ifdef __cplusplus
}
-/* Make pointers to dive and dive_trip "Qt metatypes" so that they can
- * be passed through QVariants. */
+/* Make pointers to dive, dive_trip and dive_table "Qt metatypes" so that they can
+ * be passed through QVariants and through QML.
+ * Note: we have to use the typedef "dive_table_t" instead of "struct dive_table",
+ * because MOC removes the "struct", but dive_table is already the name of a global
+ * variable, leading to compilation errors. */
Q_DECLARE_METATYPE(struct dive *);
Q_DECLARE_METATYPE(struct dive_trip *);
+Q_DECLARE_METATYPE(dive_table_t *);
#endif
diff --git a/core/divelist.c b/core/divelist.c
index 4b809da37..4659261cd 100644
--- a/core/divelist.c
+++ b/core/divelist.c
@@ -74,9 +74,6 @@ dive_trip_t *dive_trip_list;
unsigned int amount_selected;
-// We need to stop using globals, really.
-struct dive_table downloadTable;
-
#if DEBUG_SELECTION_TRACKING
void dump_selection(void)
{
diff --git a/core/downloadfromdcthread.cpp b/core/downloadfromdcthread.cpp
index ec0705cc1..2fdebf129 100644
--- a/core/downloadfromdcthread.cpp
+++ b/core/downloadfromdcthread.cpp
@@ -59,9 +59,9 @@ static void updateRememberedDCs()
}
-DownloadThread::DownloadThread()
+DownloadThread::DownloadThread() : downloadTable({ 0 }),
+ m_data(DCDeviceData::instance())
{
- m_data = DCDeviceData::instance();
}
void DownloadThread::run()
@@ -80,7 +80,7 @@ void DownloadThread::run()
internalData->devname = "ftdi";
#endif
qDebug() << "Starting download from " << (internalData->bluetooth_mode ? "BT" : internalData->devname);
- downloadTable.nr = 0;
+ clear_table(&downloadTable);
Q_ASSERT(internalData->download_table != nullptr);
const char *errorText;
@@ -302,6 +302,11 @@ DCDeviceData *DownloadThread::data()
return m_data;
}
+struct dive_table *DownloadThread::table()
+{
+ return &downloadTable;
+}
+
QString DCDeviceData::vendor() const
{
return data.vendor;
diff --git a/core/downloadfromdcthread.h b/core/downloadfromdcthread.h
index 1ae6a4087..b380a88a1 100644
--- a/core/downloadfromdcthread.h
+++ b/core/downloadfromdcthread.h
@@ -6,6 +6,7 @@
#include <QHash>
#include <QLoggingCategory>
+#include "dive.h"
#include "libdivecomputer.h"
#include "connectionlistmodel.h"
#if BT_SUPPORT
@@ -59,15 +60,18 @@ private:
class DownloadThread : public QThread {
Q_OBJECT
+ Q_PROPERTY(dive_table_t *table READ table CONSTANT)
public:
DownloadThread();
void run() override;
DCDeviceData *data();
+ struct dive_table *table();
QString error;
private:
+ struct dive_table downloadTable;
DCDeviceData *m_data;
};
diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c
index a2e2890b8..4d2d29bad 100644
--- a/core/libdivecomputer.c
+++ b/core/libdivecomputer.c
@@ -1387,7 +1387,7 @@ const char *do_libdivecomputer_import(device_data_t *data)
/* TODO: Show the logfile to the user on error. */
dc_device_close(data->device);
data->device = NULL;
- if (!downloadTable.nr)
+ if (!data->download_table->nr)
dev_info(data, translate("gettextFromC", "No new dives downloaded from dive computer"));
}
dc_iostream_close(data->iostream);