diff options
-rw-r--r-- | core/device.cpp | 22 | ||||
-rw-r--r-- | core/device.h | 3 | ||||
-rw-r--r-- | mobile-widgets/qmlmanager.cpp | 3 |
3 files changed, 26 insertions, 2 deletions
diff --git a/core/device.cpp b/core/device.cpp index 48d66244f..512d17d57 100644 --- a/core/device.cpp +++ b/core/device.cpp @@ -218,7 +218,7 @@ bool device::operator<(const device &a) const return strcoll(model.c_str(), a.model.c_str()) < 0; } -const struct device *get_device_for_dc(const struct device_table *table, const struct divecomputer *dc) +extern "C" const struct device *get_device_for_dc(const struct device_table *table, const struct divecomputer *dc) { const std::vector<device> &dcs = table->devices; device dev { dc->model, dc->deviceid, {}, {}, {} }; @@ -226,6 +226,12 @@ const struct device *get_device_for_dc(const struct device_table *table, const s return it != dcs.end() && same_device(*it, dev) ? &*it : NULL; } +extern "C" bool device_exists(const struct device_table *device_table, const struct device *dev) +{ + auto it = std::lower_bound(device_table->devices.begin(), device_table->devices.end(), *dev); + return it != device_table->devices.end() && same_device(*it, *dev); +} + /* * When setting the device ID, we also fill in the * serial number and firmware version data @@ -292,6 +298,20 @@ extern "C" void create_device_node(struct device_table *device_table, const char addDC(device_table->devices, model ?: "", deviceid, nickname ?: "", serial ?: "", firmware ?: ""); } +/* Does not check for duplicates! */ +extern "C" void add_to_device_table(struct device_table *device_table, const struct device *dev) +{ + auto it = std::lower_bound(device_table->devices.begin(), device_table->devices.end(), *dev); + device_table->devices.insert(it, *dev); +} + +extern "C" void remove_device(struct device_table *device_table, const struct device *dev) +{ + auto it = std::lower_bound(device_table->devices.begin(), device_table->devices.end(), *dev); + if (it != device_table->devices.end() && same_device(*it, *dev)) + device_table->devices.erase(it); +} + extern "C" void clear_device_table(struct device_table *device_table) { device_table->devices.clear(); diff --git a/core/device.h b/core/device.h index f3bb1e097..9c7fff31c 100644 --- a/core/device.h +++ b/core/device.h @@ -28,6 +28,9 @@ const char *get_dc_nickname(const struct divecomputer *dc); extern bool device_used_by_selected_dive(const struct device *dev); extern const struct device *get_device_for_dc(const struct device_table *table, const struct divecomputer *dc); +extern bool device_exists(const struct device_table *table, const struct device *dev); +extern void add_to_device_table(struct device_table *table, const struct device *dev); +extern void remove_device(struct device_table *table, const struct device *dev); // struct device accessors for C-code. The returned strings are not stable! const char *device_get_model(const struct device *dev); diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index f56e31551..dc22dbd6e 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -451,8 +451,9 @@ void QMLManager::mergeLocalRepo() struct dive_table table = empty_dive_table; struct trip_table trips = empty_trip_table; struct dive_site_table sites = empty_dive_site_table; + struct device_table devices; struct filter_preset_table filter_presets; - parse_file(qPrintable(nocloud_localstorage()), &table, &trips, &sites, &device_table, &filter_presets); + parse_file(qPrintable(nocloud_localstorage()), &table, &trips, &sites, &devices, &filter_presets); add_imported_dives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS); } |