summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-10-17 16:07:39 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-10-24 09:51:37 -0700
commit39a4090c0a6e1d8fe12516be06ee7b31dd4bc96d (patch)
tree7587930b64bf95ec3a652cf761e6ded573931364 /core
parentfadea413cdb4644b821369b27fad6e5f019d32c2 (diff)
downloadsubsurface-39a4090c0a6e1d8fe12516be06ee7b31dd4bc96d.tar.gz
devices: add devices in Command::importTable()
Add a device_table parameters to Command::importTable() and add_imported_dives(). The content of this table will be added to the global device list (respectively removed on undo). This is currently a no-op, as the parser doesn't yet fill out the device table, but adds devices directly to the global device table. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r--core/device.cpp10
-rw-r--r--core/device.h4
-rw-r--r--core/divelist.c39
-rw-r--r--core/divelist.h10
-rw-r--r--core/subsurface-qt/divelistnotifier.h6
5 files changed, 58 insertions, 11 deletions
diff --git a/core/device.cpp b/core/device.cpp
index 764531414..3d3a476d9 100644
--- a/core/device.cpp
+++ b/core/device.cpp
@@ -416,3 +416,13 @@ extern "C" const char *device_get_nickname(const struct device *dev)
{
return dev ? dev->nickName.c_str() : NULL;
}
+
+extern "C" struct device_table *alloc_device_table()
+{
+ return new struct device_table;
+}
+
+extern "C" void free_device_table(struct device_table *devices)
+{
+ delete devices;
+}
diff --git a/core/device.h b/core/device.h
index 590609c45..b5467ea09 100644
--- a/core/device.h
+++ b/core/device.h
@@ -39,6 +39,10 @@ const char *device_get_serial(const struct device *dev);
const char *device_get_firmware(const struct device *dev);
const char *device_get_nickname(const struct device *dev);
+// for C code that needs to alloc/free a device table. (Let's try to get rid of those)
+extern struct device_table *alloc_device_table();
+extern void free_device_table(struct device_table *devices);
+
#ifdef __cplusplus
}
#endif
diff --git a/core/divelist.c b/core/divelist.c
index 5a47e3c44..3bc4ff229 100644
--- a/core/divelist.c
+++ b/core/divelist.c
@@ -999,18 +999,22 @@ static bool merge_dive_tables(struct dive_table *dives_from, struct dive_table *
/* Merge the dives of the trip "from" and the dive_table "dives_from" into the trip "to"
* and dive_table "dives_to". If "prefer_imported" is true, dive data of "from" takes
* precedence */
-void add_imported_dives(struct dive_table *import_table, struct trip_table *import_trip_table, struct dive_site_table *import_sites_table, int flags)
+void add_imported_dives(struct dive_table *import_table, struct trip_table *import_trip_table,
+ struct dive_site_table *import_sites_table, struct device_table *import_device_table,
+ int flags)
{
int i, idx;
struct dive_table dives_to_add = empty_dive_table;
struct dive_table dives_to_remove = empty_dive_table;
struct trip_table trips_to_add = empty_trip_table;
struct dive_site_table dive_sites_to_add = empty_dive_site_table;
+ struct device_table *devices_to_add = alloc_device_table();
/* Process imported dives and generate lists of dives
* to-be-added and to-be-removed */
- process_imported_dives(import_table, import_trip_table, import_sites_table, flags,
- &dives_to_add, &dives_to_remove, &trips_to_add, &dive_sites_to_add);
+ process_imported_dives(import_table, import_trip_table, import_sites_table, import_device_table,
+ flags, &dives_to_add, &dives_to_remove, &trips_to_add,
+ &dive_sites_to_add, devices_to_add);
/* Add new dives to trip and site to get reference count correct. */
for (i = 0; i < dives_to_add.nr; i++) {
@@ -1045,11 +1049,19 @@ void add_imported_dives(struct dive_table *import_table, struct trip_table *impo
register_dive_site(dive_sites_to_add.dive_sites[i]);
dive_sites_to_add.nr = 0;
+ /* Add new devices */
+ for (i = 0; i < nr_devices(devices_to_add); i++) {
+ const struct device *dev = get_device(devices_to_add, i);
+ add_to_device_table(&device_table, dev);
+ }
+
/* We might have deleted the old selected dive.
* Choose the newest dive as selected (if any) */
current_dive = dive_table.nr > 0 ? dive_table.dives[dive_table.nr - 1] : NULL;
mark_divelist_changed(true);
+ free_device_table(devices_to_add);
+
/* Inform frontend of reset data. This should reset all the models. */
emit_reset_signal();
}
@@ -1088,11 +1100,12 @@ bool try_to_merge_trip(struct dive_trip *trip_import, struct dive_table *import_
}
/* Process imported dives: take a table of dives to be imported and
- * generate four lists:
+ * generate five lists:
* 1) Dives to be added
* 2) Dives to be removed
* 3) Trips to be added
* 4) Dive sites to be added
+ * 5) Devices to be added
* The dives to be added are owning (i.e. the caller is responsible
* for freeing them).
* The dives, trips and sites in "import_table", "import_trip_table"
@@ -1120,10 +1133,12 @@ bool try_to_merge_trip(struct dive_trip *trip_import, struct dive_table *import_
* to a trip will be added to a newly generated trip.
*/
void process_imported_dives(struct dive_table *import_table, struct trip_table *import_trip_table,
- struct dive_site_table *import_sites_table, int flags,
+ struct dive_site_table *import_sites_table, struct device_table *import_device_table,
+ int flags,
/* output parameters: */
struct dive_table *dives_to_add, struct dive_table *dives_to_remove,
- struct trip_table *trips_to_add, struct dive_site_table *sites_to_add)
+ struct trip_table *trips_to_add, struct dive_site_table *sites_to_add,
+ struct device_table *devices_to_add)
{
int i, j, nr, start_renumbering_at = 0;
struct dive_trip *trip_import, *new_trip;
@@ -1143,6 +1158,7 @@ void process_imported_dives(struct dive_table *import_table, struct trip_table *
clear_dive_table(dives_to_remove);
clear_trip_table(trips_to_add);
clear_dive_site_table(sites_to_add);
+ clear_device_table(devices_to_add);
/* Check if any of the new dives has a number. This will be
* important later to decide if we want to renumber the added
@@ -1158,15 +1174,22 @@ void process_imported_dives(struct dive_table *import_table, struct trip_table *
if (!import_table->nr)
return;
+ /* Add only the devices that we don't know about yet. */
+ for (i = 0; i < nr_devices(import_device_table); i++) {
+ const struct device *dev = get_device(import_device_table, i);
+ if (!device_exists(&device_table, dev))
+ add_to_device_table(devices_to_add, dev);
+ }
+
/* check if we need a nickname for the divecomputer for newly downloaded dives;
* since we know they all came from the same divecomputer we just check for the
* first one */
if (flags & IMPORT_IS_DOWNLOADED) {
- set_dc_nickname(import_table->dives[0], &device_table);
+ set_dc_nickname(import_table->dives[0], devices_to_add);
} else {
/* they aren't downloaded, so record / check all new ones */
for (i = 0; i < import_table->nr; i++)
- set_dc_nickname(import_table->dives[i], &device_table);
+ set_dc_nickname(import_table->dives[i], devices_to_add);
}
/* Sort the table of dives to be imported and combine mergable dives */
diff --git a/core/divelist.h b/core/divelist.h
index cee52f9c4..1042c88cc 100644
--- a/core/divelist.h
+++ b/core/divelist.h
@@ -11,6 +11,7 @@ extern "C" {
struct dive;
struct trip_table;
struct dive_site_table;
+struct device_table;
struct deco_state;
extern int shown_dives;
@@ -36,12 +37,15 @@ extern void process_loaded_dives();
#define IMPORT_IS_DOWNLOADED (1 << 1)
#define IMPORT_MERGE_ALL_TRIPS (1 << 2)
#define IMPORT_ADD_TO_NEW_TRIP (1 << 3)
-extern void add_imported_dives(struct dive_table *import_table, struct trip_table *import_trip_table, struct dive_site_table *import_sites_table,
+extern void add_imported_dives(struct dive_table *import_table, struct trip_table *import_trip_table,
+ struct dive_site_table *import_sites_table, struct device_table *devices_to_add,
int flags);
-extern void process_imported_dives(struct dive_table *import_table, struct trip_table *import_trip_table, struct dive_site_table *import_sites_table,
+extern void process_imported_dives(struct dive_table *import_table, struct trip_table *import_trip_table,
+ struct dive_site_table *import_sites_table, struct device_table *import_devices_table,
int flags,
struct dive_table *dives_to_add, struct dive_table *dives_to_remove,
- struct trip_table *trips_to_add, struct dive_site_table *sites_to_add);
+ struct trip_table *trips_to_add, struct dive_site_table *sites_to_add,
+ struct device_table *devices_to_add);
extern char *get_dive_gas_string(const struct dive *dive);
extern int dive_table_get_insertion_index(struct dive_table *table, struct dive *dive);
diff --git a/core/subsurface-qt/divelistnotifier.h b/core/subsurface-qt/divelistnotifier.h
index eb44d6cde..7f7162dac 100644
--- a/core/subsurface-qt/divelistnotifier.h
+++ b/core/subsurface-qt/divelistnotifier.h
@@ -10,6 +10,8 @@
#include <QObject>
+struct device;
+
// Dive and trip fields that can be edited. Use bit fields so that we can pass multiple fields at once.
// Provides an inlined flag-based constructur because sadly C-style designated initializers are only supported since C++20.
struct DiveField {
@@ -125,6 +127,10 @@ signals:
void picturesRemoved(dive *d, QVector<QString> filenames);
void picturesAdded(dive *d, QVector<PictureObj> pics);
+ // Devices related signals
+ void deviceAdded(int index);
+ void deviceDeleted(int index);
+
// Filter related signals
void filterPresetAdded(int index);
void filterPresetRemoved(int index);