summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/CMakeLists.txt2
-rw-r--r--core/btdiscovery.cpp98
-rw-r--r--core/connectionlistmodel.cpp7
-rw-r--r--core/dive.c36
-rw-r--r--core/dive.h12
-rw-r--r--core/load-git.c1
-rw-r--r--core/parse-xml.c1
-rw-r--r--core/parse.c1
-rw-r--r--core/picture.c21
-rw-r--r--core/picture.h18
-rw-r--r--core/qthelper.cpp1
-rw-r--r--core/save-git.c1
-rw-r--r--core/save-html.c1
-rw-r--r--core/save-xml.c1
14 files changed, 92 insertions, 109 deletions
diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt
index d325f9280..7699877bc 100644
--- a/core/CMakeLists.txt
+++ b/core/CMakeLists.txt
@@ -125,6 +125,8 @@ set(SUBSURFACE_CORE_LIB_SRCS
parse-xml.c
parse.c
parse.h
+ picture.c
+ picture.h
planner.c
planner.h
plannernotes.c
diff --git a/core/btdiscovery.cpp b/core/btdiscovery.cpp
index ce12f40d6..b70330410 100644
--- a/core/btdiscovery.cpp
+++ b/core/btdiscovery.cpp
@@ -34,45 +34,36 @@ static dc_descriptor_t *getDeviceType(QString btName)
// just use a default product that allows the codoe to download from the
// user's dive computer
else product = "OSTC 2";
- }
-
- if (btName.startsWith("Predator") ||
- btName.startsWith("Petrel") ||
- btName.startsWith("Perdix") ||
- btName.startsWith("Teric") ||
- btName.startsWith("NERD")) {
+ } else if (btName.startsWith("Predator") ||
+ btName.startsWith("Petrel") ||
+ btName.startsWith("Perdix") ||
+ btName.startsWith("Teric") ||
+ btName.startsWith("NERD")) {
vendor = "Shearwater";
- if (btName.startsWith("Petrel")) product = "Petrel"; // or petrel 2?
+ // both the Petrel and Petrel 2 identify as "Petrel" as BT/BLE device
+ // but only the Petrel 2 is listed as available dive computer on iOS (which requires BLE support)
+ // so always pick the "Petrel 2" as product when seeing a Petrel
+ if (btName.startsWith("Petrel")) product = "Petrel 2";
if (btName.startsWith("Perdix")) product = "Perdix";
if (btName.startsWith("Predator")) product = "Predator";
if (btName.startsWith("Teric")) product = "Teric";
if (btName.startsWith("NERD")) product = "Nerd"; // next line might override this
if (btName.startsWith("NERD 2")) product = "Nerd 2";
- }
-
- if (btName.startsWith("EON Steel")) {
+ } else if (btName.startsWith("EON Steel")) {
vendor = "Suunto";
product = "EON Steel";
- }
-
- if (btName.startsWith("EON Core")) {
+ } else if (btName.startsWith("EON Core")) {
vendor = "Suunto";
product = "EON Core";
- }
-
- if (btName.startsWith("Suunto D5")) {
+ } else if (btName.startsWith("Suunto D5")) {
vendor = "Suunto";
product = "D5";
- }
-
- if (btName.startsWith("G2") || btName.startsWith("Aladin") || btName.startsWith("HUD")) {
+ } else if (btName.startsWith("G2") || btName.startsWith("Aladin") || btName.startsWith("HUD")) {
vendor = "Scubapro";
if (btName.startsWith("G2")) product = "G2";
if (btName.startsWith("HUD")) product = "G2 HUD";
if (btName.startsWith("Aladin")) product = "Aladin Sport Matrix";
- }
-
- if (btName.startsWith("Mares")) {
+ } else if (btName.startsWith("Mares")) {
vendor = "Mares";
// we don't know which of the dive computers it is,
// so let's just randomly pick one
@@ -80,66 +71,51 @@ static dc_descriptor_t *getDeviceType(QString btName)
// Some we can pick out directly
if (btName.startsWith("Mares Genius"))
product = "Genius";
- }
-
- if (btName.startsWith("CARTESIO_")) {
+ } else if (btName.startsWith("CARTESIO_")) {
vendor = "Cressi";
product = "Cartesio";
- }
-
- if (btName.startsWith("GOA_")) {
+ } else if (btName.startsWith("GOA_")) {
vendor = "Cressi";
product = "Goa";
- }
-
- // The Pelagic dive computers (generally branded as Oceanic or Aqualung)
- // show up with a two-byte model code followed by six bytes of serial
- // number. The model code matches the hex model (so "FQ" is 0x4651,
- // where 'F' is 46h and 'Q' is 51h in ASCII).
- if (btName.contains(QRegularExpression("^FI\\d{6}$"))) {
+ } else if (btName.contains(QRegularExpression("^FI\\d{6}$"))) {
+ // The Pelagic dive computers (generally branded as Oceanic or Aqualung)
+ // show up with a two-byte model code followed by six bytes of serial
+ // number. The model code matches the hex model (so "FQ" is 0x4651,
+ // where 'F' is 46h and 'Q' is 51h in ASCII).
vendor = "Aqualung";
product = "i200c";
- }
-
- if (btName.contains(QRegularExpression("^FH\\d{6}$"))) {
+ } else if (btName.contains(QRegularExpression("^FH\\d{6}$"))) {
vendor = "Aqualung";
product = "i300c";
- }
-
- if (btName.contains(QRegularExpression("^FQ\\d{6}$"))) {
+ } else if (btName.contains(QRegularExpression("^FQ\\d{6}$"))) {
vendor = "Aqualung";
product = "i770R";
- }
-
- if (btName.contains(QRegularExpression("^FR\\d{6}$"))) {
+ } else if (btName.contains(QRegularExpression("^FR\\d{6}$"))) {
vendor = "Aqualung";
product = "i550c";
- }
-
- if (btName.contains(QRegularExpression("^ER\\d{6}$"))) {
+ } else if (btName.contains(QRegularExpression("^ER\\d{6}$"))) {
vendor = "Oceanic";
product = "Pro Plus X";
- }
-
- if (btName.contains(QRegularExpression("^FS\\d{6}$"))) {
+ } else if (btName.contains(QRegularExpression("^FS\\d{6}$"))) {
vendor = "Oceanic";
product = "Geo 4.0";
- }
-
- // The Ratio bluetooth name looks like the Pelagic ones,
- // but that seems to be just happenstance.
- if (btName.contains(QRegularExpression("^DS\\d{6}"))) {
+ } else if (btName.contains(QRegularExpression("^DS\\d{6}"))) {
+ // The Ratio bluetooth name looks like the Pelagic ones,
+ // but that seems to be just happenstance.
vendor = "Ratio";
product = "iX3M GPS Easy"; // we don't know which of the GPS models, so set one
- }
-
- if (btName == "COSMIQ") {
+ } else if (btName == "COSMIQ") {
vendor = "Deepblu";
product = "Cosmiq+";
}
- if (!vendor.isEmpty() && !product.isEmpty())
- return descriptorLookup.value(vendor + product);
+ // check if we found a known dive computer
+ if (!vendor.isEmpty() && !product.isEmpty()) {
+ dc_descriptor_t *lookup = descriptorLookup.value(vendor + product);
+ if (!lookup)
+ qWarning("known dive computer %s not found in descriptorLookup", qPrintable(QString(vendor + product)));
+ return lookup;
+ }
return nullptr;
}
diff --git a/core/connectionlistmodel.cpp b/core/connectionlistmodel.cpp
index e4ac8bfeb..d97d4722c 100644
--- a/core/connectionlistmodel.cpp
+++ b/core/connectionlistmodel.cpp
@@ -39,9 +39,12 @@ void ConnectionListModel::addAddress(const QString &address)
void ConnectionListModel::removeAllAddresses()
{
- beginRemoveRows(QModelIndex(), 0, rowCount());
+ if (rowCount() == 0)
+ return;
+
+ beginResetModel();
m_addresses.clear();
- endRemoveRows();
+ endResetModel();
}
int ConnectionListModel::indexOf(const QString &address) const
diff --git a/core/dive.c b/core/dive.c
index ffdf91ae3..c97c229f6 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -14,6 +14,7 @@
#include "qthelper.h"
#include "metadata.h"
#include "membuffer.h"
+#include "picture.h"
#include "tag.h"
#include "trip.h"
#include "structured_list.h"
@@ -2697,14 +2698,6 @@ static void free_dc(struct divecomputer *dc)
free(dc);
}
-void free_picture(struct picture *picture)
-{
- if (picture) {
- free(picture->filename);
- free(picture);
- }
-}
-
static int same_sample(struct sample *a, struct sample *b)
{
if (a->time.seconds != b->time.seconds)
@@ -3410,15 +3403,6 @@ void set_git_prefs(const char *prefs)
git_prefs.pp_graphs.po2 = 1;
}
-struct picture *alloc_picture()
-{
- struct picture *pic = malloc(sizeof(struct picture));
- if (!pic)
- exit(1);
- memset(pic, 0, sizeof(struct picture));
- return pic;
-}
-
static bool new_picture_for_dive(struct dive *d, const char *filename)
{
FOR_EACH_PICTURE (d) {
@@ -3538,22 +3522,6 @@ void dive_add_picture(struct dive *dive, struct picture *newpic)
return;
}
-unsigned int dive_get_picture_count(struct dive *dive)
-{
- unsigned int i = 0;
- FOR_EACH_PICTURE (dive)
- i++;
- return i;
-}
-
-void picture_free(struct picture *picture)
-{
- if (!picture)
- return;
- free(picture->filename);
- free(picture);
-}
-
// Return true if picture was found and deleted
bool dive_remove_picture(struct dive *d, const char *filename)
{
@@ -3562,7 +3530,7 @@ bool dive_remove_picture(struct dive *d, const char *filename)
picture = &(*picture)->next;
if (*picture) {
struct picture *temp = (*picture)->next;
- picture_free(*picture);
+ free_picture(*picture);
*picture = temp;
invalidate_dive_cache(current_dive);
return true;
diff --git a/core/dive.h b/core/dive.h
index acd0c7e72..13de360ed 100644
--- a/core/dive.h
+++ b/core/dive.h
@@ -211,25 +211,13 @@ extern struct event *get_next_divemodechange(const struct event **evd, bool upda
extern enum divemode_t get_divemode_at_time(const struct divecomputer *dc, int dtime, const struct event **ev_dmc);
/* picture list and methods related to dive picture handling */
-struct picture {
- char *filename;
- offset_t offset;
- location_t location;
- struct picture *next;
-};
-
#define FOR_EACH_PICTURE(_dive) \
if (_dive) \
for (struct picture *picture = (_dive)->picture_list; picture; picture = picture->next)
-
-extern struct picture *alloc_picture();
-extern void free_picture(struct picture *picture);
extern void create_picture(const char *filename, int shift_time, bool match_all);
extern void dive_add_picture(struct dive *d, struct picture *newpic);
extern bool dive_remove_picture(struct dive *d, const char *filename);
-extern unsigned int dive_get_picture_count(struct dive *d);
extern bool picture_check_valid_time(timestamp_t timestamp, int shift_time);
-extern void picture_free(struct picture *picture);
extern bool has_gaschange_event(const struct dive *dive, const struct divecomputer *dc, int idx);
extern int explicit_first_cylinder(const struct dive *dive, const struct divecomputer *dc);
diff --git a/core/load-git.c b/core/load-git.c
index cc6f42ce3..a372d1186 100644
--- a/core/load-git.c
+++ b/core/load-git.c
@@ -22,6 +22,7 @@
#include "device.h"
#include "membuffer.h"
#include "git-access.h"
+#include "picture.h"
#include "qthelper.h"
#include "tag.h"
diff --git a/core/parse-xml.c b/core/parse-xml.c
index 6218fc74d..490e56275 100644
--- a/core/parse-xml.c
+++ b/core/parse-xml.c
@@ -29,6 +29,7 @@
#include "trip.h"
#include "device.h"
#include "membuffer.h"
+#include "picture.h"
#include "qthelper.h"
#include "tag.h"
diff --git a/core/parse.c b/core/parse.c
index ceefa23bb..be10d65e3 100644
--- a/core/parse.c
+++ b/core/parse.c
@@ -11,6 +11,7 @@
#include "errorhelper.h"
#include "subsurface-string.h"
#include "parse.h"
+#include "picture.h"
#include "trip.h"
#include "device.h"
#include "gettext.h"
diff --git a/core/picture.c b/core/picture.c
new file mode 100644
index 000000000..3f887efe8
--- /dev/null
+++ b/core/picture.c
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "picture.h"
+#include <stdlib.h>
+#include <string.h>
+
+struct picture *alloc_picture()
+{
+ struct picture *pic = malloc(sizeof(struct picture));
+ if (!pic)
+ exit(1);
+ memset(pic, 0, sizeof(struct picture));
+ return pic;
+}
+
+void free_picture(struct picture *picture)
+{
+ if (picture) {
+ free(picture->filename);
+ free(picture);
+ }
+}
diff --git a/core/picture.h b/core/picture.h
new file mode 100644
index 000000000..93b644d71
--- /dev/null
+++ b/core/picture.h
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0
+#ifndef PICTURE_H
+#define PICTURE_H
+
+// picture (more precisely media) related strutures and functions
+#include "units.h"
+
+struct picture {
+ char *filename;
+ offset_t offset;
+ location_t location;
+ struct picture *next;
+};
+
+extern struct picture *alloc_picture();
+extern void free_picture(struct picture *picture);
+
+#endif // PICTURE_H
diff --git a/core/qthelper.cpp b/core/qthelper.cpp
index 7b879e7d6..eb755bf20 100644
--- a/core/qthelper.cpp
+++ b/core/qthelper.cpp
@@ -19,6 +19,7 @@
#include <sys/time.h>
#include "exif.h"
#include "file.h"
+#include "picture.h"
#include "tag.h"
#include "trip.h"
#include "imagedownloader.h"
diff --git a/core/save-git.c b/core/save-git.c
index aaf8d5742..2d58f931a 100644
--- a/core/save-git.c
+++ b/core/save-git.c
@@ -25,6 +25,7 @@
#include "membuffer.h"
#include "git-access.h"
#include "version.h"
+#include "picture.h"
#include "qthelper.h"
#include "gettext.h"
#include "tag.h"
diff --git a/core/save-html.c b/core/save-html.c
index d5f472058..82defeed3 100644
--- a/core/save-html.c
+++ b/core/save-html.c
@@ -10,6 +10,7 @@
#include "divesite.h"
#include "errorhelper.h"
#include "file.h"
+#include "picture.h"
#include "tag.h"
#include "trip.h"
#include <stdio.h>
diff --git a/core/save-xml.c b/core/save-xml.c
index 6662069d8..c7ef3a7c2 100644
--- a/core/save-xml.c
+++ b/core/save-xml.c
@@ -20,6 +20,7 @@
#include "device.h"
#include "file.h"
#include "membuffer.h"
+#include "picture.h"
#include "strndup.h"
#include "git-access.h"
#include "qthelper.h"