core: introduce divelog structure

The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.

Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).

The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.

To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.

The whole commit is large, but was mostly an automatic
conversion.

One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2022-11-08 21:31:08 +01:00 committed by bstoeger
parent eebb47ec22
commit 9c253ee6c5
81 changed files with 661 additions and 698 deletions

View file

@ -55,6 +55,7 @@ SOURCES += subsurface-mobile-main.cpp \
core/filterconstraint.cpp \ core/filterconstraint.cpp \
core/filterpreset.cpp \ core/filterpreset.cpp \
core/divelist.c \ core/divelist.c \
core/divelog.cpp \
core/gas-model.c \ core/gas-model.c \
core/gaspressures.c \ core/gaspressures.c \
core/git-access.c \ core/git-access.c \
@ -227,6 +228,7 @@ HEADERS += \
core/filterconstraint.h \ core/filterconstraint.h \
core/filterpreset.h \ core/filterpreset.h \
core/divelist.h \ core/divelist.h \
core/divelog.h \
core/divelogexportlogic.h \ core/divelogexportlogic.h \
core/divesitehelpers.h \ core/divesitehelpers.h \
core/exif.h \ core/exif.h \

View file

@ -2,6 +2,7 @@
#include "exportfuncs.h" #include "exportfuncs.h"
#include "core/membuffer.h" #include "core/membuffer.h"
#include "core/dive.h" #include "core/dive.h"
#include "core/divelog.h"
#include "core/divesite.h" #include "core/divesite.h"
#include "core/gettextfromc.h" #include "core/gettextfromc.h"
#include "core/tag.h" #include "core/tag.h"
@ -62,7 +63,7 @@ void exportProfile(QString filename, bool selected_only, ExportCallback &cb)
filename = filename.append(".png"); filename = filename.append(".png");
QFileInfo fi(filename); QFileInfo fi(filename);
int todo = selected_only ? amount_selected : dive_table.nr; int todo = selected_only ? amount_selected : divelog.dives->nr;
int done = 0; int done = 0;
auto profile = getPrintProfile(); auto profile = getPrintProfile();
for_each_dive (i, dive) { for_each_dive (i, dive) {
@ -131,7 +132,7 @@ void export_TeX(const char *filename, bool selected_only, bool plain, ExportCall
put_format(&buf, "\n%%%%%%%%%% Begin Dive Data: %%%%%%%%%%\n"); put_format(&buf, "\n%%%%%%%%%% Begin Dive Data: %%%%%%%%%%\n");
int todo = selected_only ? amount_selected : dive_table.nr; int todo = selected_only ? amount_selected : divelog.dives->nr;
int done = 0; int done = 0;
auto profile = getPrintProfile(); auto profile = getPrintProfile();
for_each_dive (i, dive) { for_each_dive (i, dive) {
@ -330,9 +331,9 @@ std::vector<const dive_site *> getDiveSitesToExport(bool selectedOnly)
return res; return res;
} }
res.reserve(dive_site_table.nr); res.reserve(divelog.sites->nr);
for (int i = 0; i < dive_site_table.nr; i++) { for (int i = 0; i < divelog.sites->nr; i++) {
struct dive_site *ds = get_dive_site(i, &dive_site_table); struct dive_site *ds = get_dive_site(i, divelog.sites);
if (dive_site_is_empty(ds)) if (dive_site_is_empty(ds))
continue; continue;
if (selectedOnly && !is_dive_site_selected(ds)) if (selectedOnly && !is_dive_site_selected(ds))
@ -343,8 +344,8 @@ std::vector<const dive_site *> getDiveSitesToExport(bool selectedOnly)
/* walk the dive site list */ /* walk the dive site list */
int i; int i;
const struct dive_site *ds; const struct dive_site *ds;
for_each_dive_site (i, ds, &dive_site_table) for_each_dive_site (i, ds, divelog.sites)
res.push_back(get_dive_site(i, &dive_site_table)); res.push_back(get_dive_site(i, divelog.sites));
#endif #endif
return res; return res;
} }

View file

@ -2,6 +2,7 @@
#include "command.h" #include "command.h"
#include "command_base.h" #include "command_base.h"
#include "core/divelog.h"
#include "core/globals.h" #include "core/globals.h"
#include "core/qthelper.h" // for updateWindowTitle() #include "core/qthelper.h" // for updateWindowTitle()
#include "core/subsurface-qt/divelistnotifier.h" #include "core/subsurface-qt/divelistnotifier.h"
@ -65,7 +66,7 @@ QString diveNumberOrDate(struct dive *d)
QString getListOfDives(const std::vector<struct dive*> &dives) QString getListOfDives(const std::vector<struct dive*> &dives)
{ {
QString listOfDives; QString listOfDives;
if ((int)dives.size() == dive_table.nr) if ((int)dives.size() == divelog.dives->nr)
return Base::tr("all dives"); return Base::tr("all dives");
int i = 0; int i = 0;
for (dive *d: dives) { for (dive *d: dives) {

View file

@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include "command_device.h" #include "command_device.h"
#include "core/divelog.h"
#include "core/subsurface-qt/divelistnotifier.h" #include "core/subsurface-qt/divelistnotifier.h"
namespace Command { namespace Command {
@ -8,7 +9,7 @@ namespace Command {
EditDeviceNickname::EditDeviceNickname(const struct divecomputer *dc, const QString &nicknameIn) : EditDeviceNickname::EditDeviceNickname(const struct divecomputer *dc, const QString &nicknameIn) :
nickname(nicknameIn.toStdString()) nickname(nicknameIn.toStdString())
{ {
index = get_or_add_device_for_dc(&device_table, dc); index = get_or_add_device_for_dc(divelog.devices, dc);
if (index == -1) if (index == -1)
return; return;
@ -17,12 +18,12 @@ EditDeviceNickname::EditDeviceNickname(const struct divecomputer *dc, const QStr
bool EditDeviceNickname::workToBeDone() bool EditDeviceNickname::workToBeDone()
{ {
return get_device(&device_table, index) != nullptr; return get_device(divelog.devices, index) != nullptr;
} }
void EditDeviceNickname::redo() void EditDeviceNickname::redo()
{ {
device *dev = get_device_mutable(&device_table, index); device *dev = get_device_mutable(divelog.devices, index);
if (!dev) if (!dev)
return; return;
std::swap(dev->nickName, nickname); std::swap(dev->nickName, nickname);

View file

@ -2,6 +2,7 @@
#include "command_divelist.h" #include "command_divelist.h"
#include "core/divelist.h" #include "core/divelist.h"
#include "core/divelog.h"
#include "core/qthelper.h" #include "core/qthelper.h"
#include "core/selection.h" #include "core/selection.h"
#include "core/subsurface-qt/divelistnotifier.h" #include "core/subsurface-qt/divelistnotifier.h"
@ -17,7 +18,7 @@ static void remove_trip_from_backend(dive_trip *trip)
{ {
if (trip->selected) if (trip->selected)
deselect_trip(trip); deselect_trip(trip);
remove_trip(trip, &trip_table); // Remove trip from backend remove_trip(trip, divelog.trips); // Remove trip from backend
} }
// This helper function removes a dive, takes ownership of the dive and adds it to a DiveToAdd structure. // This helper function removes a dive, takes ownership of the dive and adds it to a DiveToAdd structure.
@ -77,9 +78,9 @@ dive *DiveListBase::addDive(DiveToAdd &d)
// dives have been added, their status will be updated. // dives have been added, their status will be updated.
res->hidden_by_filter = true; res->hidden_by_filter = true;
int idx = dive_table_get_insertion_index(&dive_table, res); int idx = dive_table_get_insertion_index(divelog.dives, res);
fulltext_register(res); // Register the dive's fulltext cache fulltext_register(res); // Register the dive's fulltext cache
add_to_dive_table(&dive_table, idx, res); // Return ownership to backend add_to_dive_table(divelog.dives, idx, res); // Return ownership to backend
invalidate_dive_cache(res); // Ensure that dive is written in git_save() invalidate_dive_cache(res); // Ensure that dive is written in git_save()
return res; return res;
@ -210,7 +211,7 @@ DivesAndSitesToRemove DiveListBase::addDives(DivesAndTripsToAdd &toAdd)
addedTrips.reserve(toAdd.trips.size()); addedTrips.reserve(toAdd.trips.size());
for (OwningTripPtr &trip: toAdd.trips) { for (OwningTripPtr &trip: toAdd.trips) {
addedTrips.push_back(trip.get()); addedTrips.push_back(trip.get());
insert_trip(trip.release(), &trip_table); // Return ownership to backend insert_trip(trip.release(), divelog.trips); // Return ownership to backend
} }
toAdd.trips.clear(); toAdd.trips.clear();
@ -300,7 +301,7 @@ static void moveDivesBetweenTrips(DivesToTrip &dives)
for (OwningTripPtr &trip: dives.tripsToAdd) { for (OwningTripPtr &trip: dives.tripsToAdd) {
dive_trip *t = trip.release(); // Give up ownership dive_trip *t = trip.release(); // Give up ownership
createdTrips.push_back(t); createdTrips.push_back(t);
insert_trip(t, &trip_table); // Return ownership to backend insert_trip(t, divelog.trips); // Return ownership to backend
} }
dives.tripsToAdd.clear(); dives.tripsToAdd.clear();
@ -430,7 +431,7 @@ AddDive::AddDive(dive *d, bool autogroup, bool newNumber)
allocTrip.reset(trip); allocTrip.reset(trip);
} }
int idx = dive_table_get_insertion_index(&dive_table, divePtr.get()); int idx = dive_table_get_insertion_index(divelog.dives, divePtr.get());
if (newNumber) if (newNumber)
divePtr->number = get_dive_nr_at_idx(idx); divePtr->number = get_dive_nr_at_idx(idx);
@ -451,7 +452,7 @@ void AddDive::redoit()
currentDive = current_dive; currentDive = current_dive;
divesAndSitesToRemove = addDives(divesToAdd); divesAndSitesToRemove = addDives(divesToAdd);
sort_trip_table(&trip_table); // Though unlikely, adding a dive may reorder trips sort_trip_table(divelog.trips); // Though unlikely, adding a dive may reorder trips
// Select the newly added dive // Select the newly added dive
setSelection(divesAndSitesToRemove.dives, divesAndSitesToRemove.dives[0]); setSelection(divesAndSitesToRemove.dives, divesAndSitesToRemove.dives[0]);
@ -461,7 +462,7 @@ void AddDive::undoit()
{ {
// Simply remove the dive that was previously added... // Simply remove the dive that was previously added...
divesToAdd = removeDives(divesAndSitesToRemove); divesToAdd = removeDives(divesAndSitesToRemove);
sort_trip_table(&trip_table); // Though unlikely, removing a dive may reorder trips sort_trip_table(divelog.trips); // Though unlikely, removing a dive may reorder trips
// ...and restore the selection // ...and restore the selection
setSelection(selection, currentDive); setSelection(selection, currentDive);
@ -517,9 +518,9 @@ ImportDives::ImportDives(struct dive_table *dives, struct trip_table *trips, str
if (filter_presets) { if (filter_presets) {
for (const filter_preset &preset: *filter_presets) { for (const filter_preset &preset: *filter_presets) {
QString name = preset.name; QString name = preset.name;
auto it = std::find_if(filter_preset_table.begin(), filter_preset_table.end(), auto it = std::find_if(divelog.filter_presets->begin(), divelog.filter_presets->end(),
[&name](const filter_preset &preset) { return preset.name == name; }); [&name](const filter_preset &preset) { return preset.name == name; });
if (it != filter_preset_table.end() && it->data == preset.data) if (it != divelog.filter_presets->end() && it->data == preset.data)
continue; continue;
filterPresetsToAdd.emplace_back(preset.name, preset.data); filterPresetsToAdd.emplace_back(preset.name, preset.data);
} }
@ -553,7 +554,7 @@ void ImportDives::redoit()
// Add devices // Add devices
for (const device &dev: devicesToAddAndRemove.devices) for (const device &dev: devicesToAddAndRemove.devices)
add_to_device_table(&device_table, &dev); add_to_device_table(divelog.devices, &dev);
// Add new filter presets // Add new filter presets
for (auto &it: filterPresetsToAdd) { for (auto &it: filterPresetsToAdd) {
@ -581,7 +582,7 @@ void ImportDives::undoit()
// Remove devices // Remove devices
for (const device &dev: devicesToAddAndRemove.devices) for (const device &dev: devicesToAddAndRemove.devices)
remove_device(&device_table, &dev); remove_device(divelog.devices, &dev);
// Remove filter presets. Do this in reverse order. // Remove filter presets. Do this in reverse order.
for (auto it = filterPresetsToRemove.rbegin(); it != filterPresetsToRemove.rend(); ++it) { for (auto it = filterPresetsToRemove.rbegin(); it != filterPresetsToRemove.rend(); ++it) {
@ -610,7 +611,7 @@ bool DeleteDive::workToBeDone()
void DeleteDive::undoit() void DeleteDive::undoit()
{ {
divesToDelete = addDives(divesToAdd); divesToDelete = addDives(divesToAdd);
sort_trip_table(&trip_table); // Though unlikely, removing a dive may reorder trips sort_trip_table(divelog.trips); // Though unlikely, removing a dive may reorder trips
// Select all re-added dives and make the first one current // Select all re-added dives and make the first one current
dive *currentDive = !divesToDelete.dives.empty() ? divesToDelete.dives[0] : nullptr; dive *currentDive = !divesToDelete.dives.empty() ? divesToDelete.dives[0] : nullptr;
@ -620,7 +621,7 @@ void DeleteDive::undoit()
void DeleteDive::redoit() void DeleteDive::redoit()
{ {
divesToAdd = removeDives(divesToDelete); divesToAdd = removeDives(divesToDelete);
sort_trip_table(&trip_table); // Though unlikely, adding a dive may reorder trips sort_trip_table(divelog.trips); // Though unlikely, adding a dive may reorder trips
// Deselect all dives and select dive that was close to the first deleted dive // Deselect all dives and select dive that was close to the first deleted dive
dive *newCurrent = nullptr; dive *newCurrent = nullptr;
@ -648,8 +649,8 @@ void ShiftTime::redoit()
} }
// Changing times may have unsorted the dive and trip tables // Changing times may have unsorted the dive and trip tables
sort_dive_table(&dive_table); sort_dive_table(divelog.dives);
sort_trip_table(&trip_table); sort_trip_table(divelog.trips);
for (dive_trip *trip: trips) for (dive_trip *trip: trips)
sort_dive_table(&trip->dives); // Keep the trip-table in order sort_dive_table(&trip->dives); // Keep the trip-table in order
@ -717,7 +718,7 @@ bool TripBase::workToBeDone()
void TripBase::redoit() void TripBase::redoit()
{ {
moveDivesBetweenTrips(divesToMove); moveDivesBetweenTrips(divesToMove);
sort_trip_table(&trip_table); // Though unlikely, moving dives may reorder trips sort_trip_table(divelog.trips); // Though unlikely, moving dives may reorder trips
// Select the moved dives // Select the moved dives
std::vector<dive *> dives; std::vector<dive *> dives;
@ -790,7 +791,7 @@ AutogroupDives::AutogroupDives()
dive_trip *trip; dive_trip *trip;
bool alloc; bool alloc;
int from, to; int from, to;
for(int i = 0; (trip = get_dives_to_autogroup(&dive_table, i, &from, &to, &alloc)) != NULL; i = to) { for(int i = 0; (trip = get_dives_to_autogroup(divelog.dives, i, &from, &to, &alloc)) != NULL; i = to) {
// If this is an allocated trip, take ownership // If this is an allocated trip, take ownership
if (alloc) if (alloc)
divesToMove.tripsToAdd.emplace_back(trip); divesToMove.tripsToAdd.emplace_back(trip);
@ -1009,7 +1010,7 @@ MergeDives::MergeDives(const QVector <dive *> &dives)
// like the best option. // like the best option.
int idx = get_divenr(dives[0]); int idx = get_divenr(dives[0]);
int num = dives.count(); int num = dives.count();
if (idx < 0 || idx + num > dive_table.nr) { if (idx < 0 || idx + num > divelog.dives->nr) {
// It was the callers responsibility to pass only known dives. // It was the callers responsibility to pass only known dives.
// Something is seriously wrong - give up. // Something is seriously wrong - give up.
qWarning("Merging unknown dives"); qWarning("Merging unknown dives");
@ -1017,7 +1018,7 @@ MergeDives::MergeDives(const QVector <dive *> &dives)
} }
// std::equal compares two ranges. The parameters are (begin_range1, end_range1, begin_range2). // std::equal compares two ranges. The parameters are (begin_range1, end_range1, begin_range2).
// Here, we can compare C-arrays, because QVector guarantees contiguous storage. // Here, we can compare C-arrays, because QVector guarantees contiguous storage.
if (std::equal(&dives[0], &dives[0] + num, &dive_table.dives[idx]) && if (std::equal(&dives[0], &dives[0] + num, &divelog.dives->dives[idx]) &&
dives[0]->number && dives.last()->number && dives[0]->number < dives.last()->number) { dives[0]->number && dives.last()->number && dives[0]->number < dives.last()->number) {
// We have a consecutive set of dives. Rename all following dives according to the // We have a consecutive set of dives. Rename all following dives according to the
// number of erased dives. This considers that there might be missing numbers. // number of erased dives. This considers that there might be missing numbers.
@ -1033,15 +1034,15 @@ MergeDives::MergeDives(const QVector <dive *> &dives)
// consecutive, and the difference will be 1, so the // consecutive, and the difference will be 1, so the
// above example is not supposed to be normal. // above example is not supposed to be normal.
int diff = dives.last()->number - dives[0]->number; int diff = dives.last()->number - dives[0]->number;
divesToRenumber.reserve(dive_table.nr - idx - num); divesToRenumber.reserve(divelog.dives->nr - idx - num);
int previousnr = dives[0]->number; int previousnr = dives[0]->number;
for (int i = idx + num; i < dive_table.nr; ++i) { for (int i = idx + num; i < divelog.dives->nr; ++i) {
int newnr = dive_table.dives[i]->number - diff; int newnr = divelog.dives->dives[i]->number - diff;
// Stop renumbering if stuff isn't in order (see also core/divelist.c) // Stop renumbering if stuff isn't in order (see also core/divelist.c)
if (newnr <= previousnr) if (newnr <= previousnr)
break; break;
divesToRenumber.append(QPair<dive *,int>(dive_table.dives[i], newnr)); divesToRenumber.append(QPair<dive *,int>(divelog.dives->dives[i], newnr));
previousnr = newnr; previousnr = newnr;
} }
} }

View file

@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include "command_divesite.h" #include "command_divesite.h"
#include "core/divelog.h"
#include "core/divesite.h" #include "core/divesite.h"
#include "core/subsurface-qt/divelistnotifier.h" #include "core/subsurface-qt/divelistnotifier.h"
#include "core/qthelper.h" #include "core/qthelper.h"
@ -154,8 +155,8 @@ void DeleteDiveSites::undo()
PurgeUnusedDiveSites::PurgeUnusedDiveSites() PurgeUnusedDiveSites::PurgeUnusedDiveSites()
{ {
setText(Command::Base::tr("purge unused dive sites")); setText(Command::Base::tr("purge unused dive sites"));
for (int i = 0; i < dive_site_table.nr; ++i) { for (int i = 0; i < divelog.sites->nr; ++i) {
dive_site *ds = dive_site_table.dive_sites[i]; dive_site *ds = divelog.sites->dive_sites[i];
if (ds->dives.nr == 0) if (ds->dives.nr == 0)
sitesToRemove.push_back(ds); sitesToRemove.push_back(ds);
} }
@ -404,7 +405,7 @@ ApplyGPSFixes::ApplyGPSFixes(const std::vector<DiveAndLocation> &fixes)
siteLocations.push_back({ ds, dl.location }); siteLocations.push_back({ ds, dl.location });
} }
} else { } else {
ds = create_dive_site(qPrintable(dl.name), &dive_site_table); ds = create_dive_site(qPrintable(dl.name), divelog.sites);
ds->location = dl.location; ds->location = dl.location;
add_dive_to_dive_site(dl.d, ds); add_dive_to_dive_site(dl.d, ds);
dl.d->dive_site = nullptr; // This will be set on redo() dl.d->dive_site = nullptr; // This will be set on redo()

View file

@ -2,6 +2,7 @@
#include "command_edit.h" #include "command_edit.h"
#include "core/divelist.h" #include "core/divelist.h"
#include "core/divelog.h"
#include "core/fulltext.h" #include "core/fulltext.h"
#include "core/qthelper.h" // for copy_qstring #include "core/qthelper.h" // for copy_qstring
#include "core/sample.h" #include "core/sample.h"
@ -1507,8 +1508,8 @@ void EditDive::exchangeDives()
QVector<dive *> dives = { oldDive }; QVector<dive *> dives = { oldDive };
timestamp_t delta = oldDive->when - newDive->when; timestamp_t delta = oldDive->when - newDive->when;
if (delta != 0) { if (delta != 0) {
sort_dive_table(&dive_table); sort_dive_table(divelog.dives);
sort_trip_table(&trip_table); sort_trip_table(divelog.trips);
if (newDive->divetrip != oldDive->divetrip) if (newDive->divetrip != oldDive->divetrip)
qWarning("Command::EditDive::redo(): This command does not support moving between trips!"); qWarning("Command::EditDive::redo(): This command does not support moving between trips!");
if (oldDive->divetrip) if (oldDive->divetrip)

View file

@ -68,6 +68,8 @@ set(SUBSURFACE_CORE_LIB_SRCS
divefilter.h divefilter.h
divelist.c divelist.c
divelist.h divelist.h
divelog.cpp
divelog.h
divelogexportlogic.cpp divelogexportlogic.cpp
divelogexportlogic.h divelogexportlogic.h
divesite-helper.cpp divesite-helper.cpp

View file

@ -22,6 +22,7 @@
#include "gettext.h" #include "gettext.h"
#include "cochran.h" #include "cochran.h"
#include "divelist.h" #include "divelist.h"
#include "divelog.h"
#include <libdivecomputer/parser.h> #include <libdivecomputer/parser.h>
@ -799,11 +800,9 @@ static void cochran_parse_dive(const unsigned char *decode, unsigned mod,
free(buf); free(buf);
} }
int try_to_open_cochran(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites) int try_to_open_cochran(const char *filename, struct memblock *mem, struct divelog *log)
{ {
UNUSED(filename); UNUSED(filename);
UNUSED(trips);
UNUSED(sites);
unsigned int i; unsigned int i;
unsigned int mod; unsigned int mod;
unsigned int *offsets, dive1, dive2; unsigned int *offsets, dive1, dive2;
@ -832,7 +831,7 @@ int try_to_open_cochran(const char *filename, struct memblock *mem, struct dive_
break; break;
cochran_parse_dive(decode, mod, mem->buffer + dive1, cochran_parse_dive(decode, mod, mem->buffer + dive1,
dive2 - dive1, table); dive2 - dive1, log->dives);
} }
return 1; // no further processing needed return 1; // no further processing needed

View file

@ -17,6 +17,7 @@
#include "file.h" #include "file.h"
#include "divesite.h" #include "divesite.h"
#include "dive.h" #include "dive.h"
#include "divelog.h"
#include "errorhelper.h" #include "errorhelper.h"
#include "ssrf.h" #include "ssrf.h"
#include "tag.h" #include "tag.h"
@ -679,10 +680,8 @@ static void wlog_compl_parser(struct memblock *wl_mem, struct dive *dt_dive, int
* Main function call from file.c memblock is allocated (and freed) there. * Main function call from file.c memblock is allocated (and freed) there.
* If parsing is aborted due to errors, stores correctly parsed dives. * If parsing is aborted due to errors, stores correctly parsed dives.
*/ */
int datatrak_import(struct memblock *mem, struct memblock *wl_mem, struct dive_table *table, struct trip_table *trips, int datatrak_import(struct memblock *mem, struct memblock *wl_mem, struct divelog *log)
struct dive_site_table *sites, struct device_table *devices)
{ {
UNUSED(trips);
unsigned char *runner; unsigned char *runner;
int i = 0, numdives = 0, rc = 0; int i = 0, numdives = 0, rc = 0;
@ -712,7 +711,7 @@ int datatrak_import(struct memblock *mem, struct memblock *wl_mem, struct dive_t
while ((i < numdives) && ((long) runner < maxbuf)) { while ((i < numdives) && ((long) runner < maxbuf)) {
struct dive *ptdive = alloc_dive(); struct dive *ptdive = alloc_dive();
runner = dt_dive_parser(runner, ptdive, sites, devices, maxbuf); runner = dt_dive_parser(runner, ptdive, log->sites, log->devices, maxbuf);
if (wl_mem) if (wl_mem)
wlog_compl_parser(wl_mem, ptdive, i); wlog_compl_parser(wl_mem, ptdive, i);
if (runner == NULL) { if (runner == NULL) {
@ -721,13 +720,13 @@ int datatrak_import(struct memblock *mem, struct memblock *wl_mem, struct dive_t
rc = 1; rc = 1;
goto out; goto out;
} else { } else {
record_dive_to_table(ptdive, table); record_dive_to_table(ptdive, log->dives);
} }
i++; i++;
} }
out: out:
taglist_cleanup(&g_tag_list); taglist_cleanup(&g_tag_list);
sort_dive_table(table); sort_dive_table(log->dives);
return rc; return rc;
bail: bail:
return 1; return 1;

View file

@ -2,12 +2,12 @@
#include "device.h" #include "device.h"
#include "dive.h" #include "dive.h"
#include "divelist.h" #include "divelist.h"
#include "divelog.h"
#include "subsurface-string.h" #include "subsurface-string.h"
#include "errorhelper.h" // for verbose flag #include "errorhelper.h" // for verbose flag
#include "selection.h" #include "selection.h"
#include "core/settings/qPrefDiveComputer.h" #include "core/settings/qPrefDiveComputer.h"
struct device_table device_table;
struct fingerprint_table fingerprint_table; struct fingerprint_table fingerprint_table;
static bool same_device(const device &dev1, const device &dev2) static bool same_device(const device &dev1, const device &dev2)
@ -140,7 +140,7 @@ extern "C" int is_default_dive_computer_device(const char *name)
const char *get_dc_nickname(const struct divecomputer *dc) const char *get_dc_nickname(const struct divecomputer *dc)
{ {
const device *existNode = get_device_for_dc(&device_table, dc); const device *existNode = get_device_for_dc(divelog.devices, dc);
if (existNode && !existNode->nickName.empty()) if (existNode && !existNode->nickName.empty())
return existNode->nickName.c_str(); return existNode->nickName.c_str();

View file

@ -14,7 +14,6 @@ struct device_table;
struct dive_table; struct dive_table;
// global device table // global device table
extern struct device_table device_table;
extern struct fingerprint_table fingerprint_table; extern struct fingerprint_table fingerprint_table;
extern int create_device_node(struct device_table *table, const char *model, const char *serial, const char *nickname); extern int create_device_node(struct device_table *table, const char *model, const char *serial, const char *nickname);

View file

@ -11,6 +11,7 @@
#include "libdivecomputer.h" #include "libdivecomputer.h"
#include "device.h" #include "device.h"
#include "divelist.h" #include "divelist.h"
#include "divelog.h"
#include "divesite.h" #include "divesite.h"
#include "errorhelper.h" #include "errorhelper.h"
#include "event.h" #include "event.h"
@ -2859,7 +2860,7 @@ static int split_dive_at(const struct dive *dive, int a, int b, struct dive **ou
* Otherwise the tail is unnumbered. * Otherwise the tail is unnumbered.
*/ */
if (d2->number) { if (d2->number) {
if (dive_table.nr == nr + 1) if (divelog.dives->nr == nr + 1)
d2->number++; d2->number++;
else else
d2->number = 0; d2->number = 0;
@ -3331,9 +3332,9 @@ depth_t gas_mnd(struct gasmix mix, depth_t end, const struct dive *dive, int rou
struct dive *get_dive(int nr) struct dive *get_dive(int nr)
{ {
if (nr >= dive_table.nr || nr < 0) if (nr >= divelog.dives->nr || nr < 0)
return NULL; return NULL;
return dive_table.dives[nr]; return divelog.dives->dives[nr];
} }
struct dive_site *get_dive_site_for_dive(const struct dive *dive) struct dive_site *get_dive_site_for_dive(const struct dive *dive)

View file

@ -2,6 +2,7 @@
#include "divefilter.h" #include "divefilter.h"
#include "divelist.h" #include "divelist.h"
#include "divelog.h"
#include "gettextfromc.h" #include "gettextfromc.h"
#include "qthelper.h" #include "qthelper.h"
#include "selection.h" #include "selection.h"
@ -73,7 +74,7 @@ void DiveFilter::reset()
{ {
int i; int i;
dive *d; dive *d;
shown_dives = dive_table.nr; shown_dives = divelog.dives->nr;
for_each_dive(i, d) for_each_dive(i, d)
d->hidden_by_filter = false; d->hidden_by_filter = false;
updateAll(); updateAll();
@ -201,10 +202,11 @@ bool DiveFilter::diveSiteMode() const
QString DiveFilter::shownText() const QString DiveFilter::shownText() const
{ {
int num = divelog.dives->nr;
if (diveSiteMode() || filterData.validFilter()) if (diveSiteMode() || filterData.validFilter())
return gettextFromC::tr("%L1/%L2 shown").arg(shown_dives).arg(dive_table.nr); return gettextFromC::tr("%L1/%L2 shown").arg(shown_dives).arg(num);
else else
return gettextFromC::tr("%L1 dives").arg(dive_table.nr); return gettextFromC::tr("%L1 dives").arg(num);
} }
int DiveFilter::shownDives() const int DiveFilter::shownDives() const

View file

@ -5,8 +5,9 @@
#include "subsurface-string.h" #include "subsurface-string.h"
#include "deco.h" #include "deco.h"
#include "device.h" #include "device.h"
#include "divesite.h"
#include "dive.h" #include "dive.h"
#include "divelog.h"
#include "divesite.h"
#include "event.h" #include "event.h"
#include "eventname.h" #include "eventname.h"
#include "filterpreset.h" #include "filterpreset.h"
@ -226,7 +227,7 @@ static int calculate_cns(struct dive *dive)
return dive->cns; return dive->cns;
divenr = get_divenr(dive); divenr = get_divenr(dive);
i = divenr >= 0 ? divenr : dive_table.nr; i = divenr >= 0 ? divenr : divelog.dives->nr;
#if DECO_CALC_DEBUG & 2 #if DECO_CALC_DEBUG & 2
if (i >= 0 && i < dive_table.nr) if (i >= 0 && i < dive_table.nr)
printf("\n\n*** CNS for dive #%d %d\n", i, get_dive(i)->number); printf("\n\n*** CNS for dive #%d %d\n", i, get_dive(i)->number);
@ -234,7 +235,7 @@ static int calculate_cns(struct dive *dive)
printf("\n\n*** CNS for dive #%d\n", i); printf("\n\n*** CNS for dive #%d\n", i);
#endif #endif
/* Look at next dive in dive list table and correct i when needed */ /* Look at next dive in dive list table and correct i when needed */
while (i < dive_table.nr - 1) { while (i < divelog.dives->nr - 1) {
struct dive *pdive = get_dive(i); struct dive *pdive = get_dive(i);
if (!pdive || pdive->when > dive->when) if (!pdive || pdive->when > dive->when)
break; break;
@ -279,7 +280,7 @@ static int calculate_cns(struct dive *dive)
#endif #endif
} }
/* Walk forward and add dives and surface intervals to CNS */ /* Walk forward and add dives and surface intervals to CNS */
while (++i < dive_table.nr) { while (++i < divelog.dives->nr) {
#if DECO_CALC_DEBUG & 2 #if DECO_CALC_DEBUG & 2
printf("Check if dive #%d %d will be really added to CNS calc: ", i, get_dive(i)->number); printf("Check if dive #%d %d will be really added to CNS calc: ", i, get_dive(i)->number);
#endif #endif
@ -463,7 +464,7 @@ int init_decompression(struct deco_state *ds, const struct dive *dive, bool in_p
return false; return false;
divenr = get_divenr(dive); divenr = get_divenr(dive);
i = divenr >= 0 ? divenr : dive_table.nr; i = divenr >= 0 ? divenr : divelog.dives->nr;
#if DECO_CALC_DEBUG & 2 #if DECO_CALC_DEBUG & 2
if (i >= 0 && i < dive_table.nr) if (i >= 0 && i < dive_table.nr)
printf("\n\n*** Init deco for dive #%d %d\n", i, get_dive(i)->number); printf("\n\n*** Init deco for dive #%d %d\n", i, get_dive(i)->number);
@ -471,7 +472,7 @@ int init_decompression(struct deco_state *ds, const struct dive *dive, bool in_p
printf("\n\n*** Init deco for dive #%d\n", i); printf("\n\n*** Init deco for dive #%d\n", i);
#endif #endif
/* Look at next dive in dive list table and correct i when needed */ /* Look at next dive in dive list table and correct i when needed */
while (i < dive_table.nr - 1) { while (i < divelog.dives->nr - 1) {
struct dive *pdive = get_dive(i); struct dive *pdive = get_dive(i);
if (!pdive || pdive->when > dive->when) if (!pdive || pdive->when > dive->when)
break; break;
@ -516,7 +517,7 @@ int init_decompression(struct deco_state *ds, const struct dive *dive, bool in_p
#endif #endif
} }
/* Walk forward an add dives and surface intervals to deco */ /* Walk forward an add dives and surface intervals to deco */
while (++i < dive_table.nr) { while (++i < divelog.dives->nr) {
#if DECO_CALC_DEBUG & 2 #if DECO_CALC_DEBUG & 2
printf("Check if dive #%d %d will be really added to deco calc: ", i, get_dive(i)->number); printf("Check if dive #%d %d will be really added to deco calc: ", i, get_dive(i)->number);
#endif #endif
@ -767,7 +768,7 @@ struct dive *unregister_dive(int idx)
/* When removing a dive from the global dive table, /* When removing a dive from the global dive table,
* we also have to unregister its fulltext cache. */ * we also have to unregister its fulltext cache. */
fulltext_unregister(dive); fulltext_unregister(dive);
remove_from_dive_table(&dive_table, idx); remove_from_dive_table(divelog.dives, idx);
if (dive->selected) if (dive->selected)
amount_selected--; amount_selected--;
dive->selected = false; dive->selected = false;
@ -783,18 +784,18 @@ void delete_single_dive(int idx)
return; /* this should never happen */ return; /* this should never happen */
if (dive->selected) if (dive->selected)
deselect_dive(dive); deselect_dive(dive);
remove_dive_from_trip(dive, &trip_table); remove_dive_from_trip(dive, divelog.trips);
unregister_dive_from_dive_site(dive); unregister_dive_from_dive_site(dive);
delete_dive_from_table(&dive_table, idx); delete_dive_from_table(divelog.dives, idx);
} }
void process_loaded_dives() void process_loaded_dives()
{ {
sort_dive_table(&dive_table); sort_dive_table(divelog.dives);
sort_trip_table(&trip_table); sort_trip_table(divelog.trips);
/* Autogroup dives if desired by user. */ /* Autogroup dives if desired by user. */
autogroup_dives(&dive_table, &trip_table); autogroup_dives(divelog.dives, divelog.trips);
fulltext_populate(); fulltext_populate();
@ -876,9 +877,9 @@ static bool try_to_merge_into(struct dive *dive_to_add, int idx, struct dive_tab
/* Check if a dive is ranked after the last dive of the global dive list */ /* Check if a dive is ranked after the last dive of the global dive list */
static bool dive_is_after_last(struct dive *d) static bool dive_is_after_last(struct dive *d)
{ {
if (dive_table.nr == 0) if (divelog.dives->nr == 0)
return true; return true;
return dive_less_than(dive_table.dives[dive_table.nr - 1], d); return dive_less_than(divelog.dives->dives[divelog.dives->nr - 1], d);
} }
/* Merge dives from "dives_from" into "dives_to". Overlapping dives will be merged, /* Merge dives from "dives_from" into "dives_to". Overlapping dives will be merged,
@ -967,9 +968,7 @@ 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" /* 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 * and dive_table "dives_to". If "prefer_imported" is true, dive data of "from" takes
* precedence */ * precedence */
void add_imported_dives(struct dive_table *import_table, struct trip_table *import_trip_table, void add_imported_dives(struct divelog *import_log, int flags)
struct dive_site_table *import_sites_table, struct device_table *import_device_table,
int flags)
{ {
int i, idx; int i, idx;
struct dive_table dives_to_add = empty_dive_table; struct dive_table dives_to_add = empty_dive_table;
@ -980,7 +979,7 @@ void add_imported_dives(struct dive_table *import_table, struct trip_table *impo
/* Process imported dives and generate lists of dives /* Process imported dives and generate lists of dives
* to-be-added and to-be-removed */ * to-be-added and to-be-removed */
process_imported_dives(import_table, import_trip_table, import_sites_table, import_device_table, process_imported_dives(import_log->dives, import_log->trips, import_log->sites, import_log->devices,
flags, &dives_to_add, &dives_to_remove, &trips_to_add, flags, &dives_to_add, &dives_to_remove, &trips_to_add,
&dive_sites_to_add, devices_to_add); &dive_sites_to_add, devices_to_add);
@ -1004,12 +1003,12 @@ void add_imported_dives(struct dive_table *import_table, struct trip_table *impo
/* Add new dives */ /* Add new dives */
for (i = 0; i < dives_to_add.nr; i++) for (i = 0; i < dives_to_add.nr; i++)
insert_dive(&dive_table, dives_to_add.dives[i]); insert_dive(divelog.dives, dives_to_add.dives[i]);
dives_to_add.nr = 0; dives_to_add.nr = 0;
/* Add new trips */ /* Add new trips */
for (i = 0; i < trips_to_add.nr; i++) for (i = 0; i < trips_to_add.nr; i++)
insert_trip(trips_to_add.trips[i], &trip_table); insert_trip(trips_to_add.trips[i], divelog.trips);
trips_to_add.nr = 0; trips_to_add.nr = 0;
/* Add new dive sites */ /* Add new dive sites */
@ -1020,12 +1019,12 @@ void add_imported_dives(struct dive_table *import_table, struct trip_table *impo
/* Add new devices */ /* Add new devices */
for (i = 0; i < nr_devices(devices_to_add); i++) { for (i = 0; i < nr_devices(devices_to_add); i++) {
const struct device *dev = get_device(devices_to_add, i); const struct device *dev = get_device(devices_to_add, i);
add_to_device_table(&device_table, dev); add_to_device_table(divelog.devices, dev);
} }
/* We might have deleted the old selected dive. /* We might have deleted the old selected dive.
* Choose the newest dive as selected (if any) */ * Choose the newest dive as selected (if any) */
current_dive = dive_table.nr > 0 ? dive_table.dives[dive_table.nr - 1] : NULL; current_dive = divelog.dives->nr > 0 ? divelog.dives->dives[divelog.dives->nr - 1] : NULL;
free_device_table(devices_to_add); free_device_table(devices_to_add);
@ -1051,8 +1050,8 @@ bool try_to_merge_trip(struct dive_trip *trip_import, struct dive_table *import_
int i; int i;
struct dive_trip *trip_old; struct dive_trip *trip_old;
for (i = 0; i < trip_table.nr; i++) { for (i = 0; i < divelog.trips->nr; i++) {
trip_old = trip_table.trips[i]; trip_old = divelog.trips->trips[i];
if (trips_overlap(trip_import, trip_old)) { if (trips_overlap(trip_import, trip_old)) {
*sequence_changed |= merge_dive_tables(&trip_import->dives, import_table, &trip_old->dives, *sequence_changed |= merge_dive_tables(&trip_import->dives, import_table, &trip_old->dives,
prefer_imported, trip_old, prefer_imported, trip_old,
@ -1144,7 +1143,7 @@ void process_imported_dives(struct dive_table *import_table, struct trip_table *
/* Add only the devices that we don't know about yet. */ /* Add only the devices that we don't know about yet. */
for (i = 0; i < nr_devices(import_device_table); i++) { for (i = 0; i < nr_devices(import_device_table); i++) {
const struct device *dev = get_device(import_device_table, i); const struct device *dev = get_device(import_device_table, i);
if (!device_exists(&device_table, dev)) if (!device_exists(divelog.devices, dev))
add_to_device_table(devices_to_add, dev); add_to_device_table(devices_to_add, dev);
} }
@ -1237,7 +1236,7 @@ void process_imported_dives(struct dive_table *import_table, struct trip_table *
/* The remaining dives in import_table are those that don't belong to /* The remaining dives in import_table are those that don't belong to
* a trip and the caller does not want them to be associated to a * a trip and the caller does not want them to be associated to a
* new trip. Merge them into the global table. */ * new trip. Merge them into the global table. */
sequence_changed |= merge_dive_tables(import_table, NULL, &dive_table, flags & IMPORT_PREFER_IMPORTED, NULL, sequence_changed |= merge_dive_tables(import_table, NULL, divelog.dives, flags & IMPORT_PREFER_IMPORTED, NULL,
dives_to_add, dives_to_remove, &start_renumbering_at); dives_to_add, dives_to_remove, &start_renumbering_at);
} }
@ -1246,13 +1245,13 @@ void process_imported_dives(struct dive_table *import_table, struct trip_table *
* - The last dive in the old dive table had a number itself (if there is a last dive). * - The last dive in the old dive table had a number itself (if there is a last dive).
* - None of the new dives has a number. * - None of the new dives has a number.
*/ */
last_old_dive_is_numbered = dive_table.nr == 0 || dive_table.dives[dive_table.nr - 1]->number > 0; last_old_dive_is_numbered = divelog.dives->nr == 0 || divelog.dives->dives[divelog.dives->nr - 1]->number > 0;
/* We counted the number of merged dives that were added to dives_to_add. /* We counted the number of merged dives that were added to dives_to_add.
* Skip those. Since sequence_changed is false all added dives are *after* * Skip those. Since sequence_changed is false all added dives are *after*
* all merged dives. */ * all merged dives. */
if (!sequence_changed && last_old_dive_is_numbered && !new_dive_has_number) { if (!sequence_changed && last_old_dive_is_numbered && !new_dive_has_number) {
nr = dive_table.nr > 0 ? dive_table.dives[dive_table.nr - 1]->number : 0; nr = divelog.dives->nr > 0 ? divelog.dives->dives[divelog.dives->nr - 1]->number : 0;
for (i = start_renumbering_at; i < dives_to_add->nr; i++) for (i = start_renumbering_at; i < dives_to_add->nr; i++)
dives_to_add->dives[i]->number = ++nr; dives_to_add->dives[i]->number = ++nr;
} }
@ -1261,9 +1260,9 @@ void process_imported_dives(struct dive_table *import_table, struct trip_table *
static struct dive *get_last_valid_dive() static struct dive *get_last_valid_dive()
{ {
int i; int i;
for (i = dive_table.nr - 1; i >= 0; i--) { for (i = divelog.dives->nr - 1; i >= 0; i--) {
if (!dive_table.dives[i]->invalid) if (!divelog.dives->dives[i]->invalid)
return dive_table.dives[i]; return divelog.dives->dives[i];
} }
return NULL; return NULL;
} }
@ -1277,7 +1276,7 @@ static struct dive *get_last_valid_dive()
*/ */
int get_dive_nr_at_idx(int idx) int get_dive_nr_at_idx(int idx)
{ {
if (idx < dive_table.nr) if (idx < divelog.dives->nr)
return 0; return 0;
struct dive *last_dive = get_last_valid_dive(); struct dive *last_dive = get_last_valid_dive();
if (!last_dive) if (!last_dive)
@ -1306,27 +1305,27 @@ void report_datafile_version(int version)
int get_dive_id_closest_to(timestamp_t when) int get_dive_id_closest_to(timestamp_t when)
{ {
int i; int i;
int nr = dive_table.nr; int nr = divelog.dives->nr;
// deal with pathological cases // deal with pathological cases
if (nr == 0) if (nr == 0)
return 0; return 0;
else if (nr == 1) else if (nr == 1)
return dive_table.dives[0]->id; return divelog.dives->dives[0]->id;
for (i = 0; i < nr && dive_table.dives[i]->when <= when; i++) for (i = 0; i < nr && divelog.dives->dives[i]->when <= when; i++)
; // nothing ; // nothing
// again, capture the two edge cases first // again, capture the two edge cases first
if (i == nr) if (i == nr)
return dive_table.dives[i - 1]->id; return divelog.dives->dives[i - 1]->id;
else if (i == 0) else if (i == 0)
return dive_table.dives[0]->id; return divelog.dives->dives[0]->id;
if (when - dive_table.dives[i - 1]->when < dive_table.dives[i]->when - when) if (when - divelog.dives->dives[i - 1]->when < divelog.dives->dives[i]->when - when)
return dive_table.dives[i - 1]->id; return divelog.dives->dives[i - 1]->id;
else else
return dive_table.dives[i]->id; return divelog.dives->dives[i]->id;
} }
void clear_dive_file_data() void clear_dive_file_data()
@ -1334,20 +1333,11 @@ void clear_dive_file_data()
fulltext_unregister_all(); fulltext_unregister_all();
select_single_dive(NULL); // This is propagate up to the UI and clears all the information. select_single_dive(NULL); // This is propagate up to the UI and clears all the information.
while (dive_table.nr)
delete_single_dive(0);
current_dive = NULL; current_dive = NULL;
while (dive_site_table.nr) clear_divelog(&divelog);
delete_dive_site(get_dive_site(0, &dive_site_table), &dive_site_table);
if (trip_table.nr != 0) {
fprintf(stderr, "Warning: trip table not empty in clear_dive_file_data()!\n");
trip_table.nr = 0;
}
clear_dive(&displayed_dive); clear_dive(&displayed_dive);
clear_device_table(&device_table);
clear_event_names(); clear_event_names();
clear_filter_presets();
reset_min_datafile_version(); reset_min_datafile_version();
clear_git_id(); clear_git_id();
@ -1418,14 +1408,14 @@ timestamp_t get_surface_interval(timestamp_t when)
timestamp_t prev_end; timestamp_t prev_end;
/* find previous dive. might want to use a binary search. */ /* find previous dive. might want to use a binary search. */
for (i = dive_table.nr - 1; i >= 0; --i) { for (i = divelog.dives->nr - 1; i >= 0; --i) {
if (dive_table.dives[i]->when < when) if (divelog.dives->dives[i]->when < when)
break; break;
} }
if (i < 0) if (i < 0)
return -1; return -1;
prev_end = dive_endtime(dive_table.dives[i]); prev_end = dive_endtime(divelog.dives->dives[i]);
if (prev_end > when) if (prev_end > when)
return 0; return 0;
return when - prev_end; return when - prev_end;
@ -1437,11 +1427,11 @@ struct dive *find_next_visible_dive(timestamp_t when)
{ {
int i, j; int i, j;
if (!dive_table.nr) if (!divelog.dives->nr)
return NULL; return NULL;
/* we might want to use binary search here */ /* we might want to use binary search here */
for (i = 0; i < dive_table.nr; i++) { for (i = 0; i < divelog.dives->nr; i++) {
if (when <= get_dive(i)->when) if (when <= get_dive(i)->when)
break; break;
} }
@ -1451,7 +1441,7 @@ struct dive *find_next_visible_dive(timestamp_t when)
return get_dive(j); return get_dive(j);
} }
for (j = i; j < dive_table.nr; j++) { for (j = i; j < divelog.dives->nr; j++) {
if (!get_dive(j)->hidden_by_filter) if (!get_dive(j)->hidden_by_filter)
return get_dive(j); return get_dive(j);
} }

View file

@ -9,6 +9,7 @@ extern "C" {
#endif #endif
struct dive; struct dive;
struct divelog;
struct trip_table; struct trip_table;
struct dive_site_table; struct dive_site_table;
struct device_table; struct device_table;
@ -19,7 +20,6 @@ struct dive_table {
struct dive **dives; struct dive **dives;
}; };
static const struct dive_table empty_dive_table = { 0, 0, (struct dive **)0 }; static const struct dive_table empty_dive_table = { 0, 0, (struct dive **)0 };
extern struct dive_table dive_table;
/* this is used for both git and xml format */ /* this is used for both git and xml format */
#define DATAFORMAT_VERSION 3 #define DATAFORMAT_VERSION 3
@ -35,9 +35,7 @@ extern void process_loaded_dives();
#define IMPORT_IS_DOWNLOADED (1 << 1) #define IMPORT_IS_DOWNLOADED (1 << 1)
#define IMPORT_MERGE_ALL_TRIPS (1 << 2) #define IMPORT_MERGE_ALL_TRIPS (1 << 2)
#define IMPORT_ADD_TO_NEW_TRIP (1 << 3) #define IMPORT_ADD_TO_NEW_TRIP (1 << 3)
extern void add_imported_dives(struct dive_table *import_table, struct trip_table *import_trip_table, extern void add_imported_dives(struct divelog *log, int flags);
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, 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, struct dive_site_table *import_sites_table, struct device_table *import_devices_table,
int flags, int flags,

56
core/divelog.cpp Normal file
View file

@ -0,0 +1,56 @@
// SPDX-License-Identifier: GPL-2.0
#include "divelog.h"
#include "divelist.h"
#include "divesite.h"
#include "device.h"
#include "filterpreset.h"
#include "trip.h"
struct divelog divelog;
// We can't use smart pointers, since this is used from C
// and it would be bold to presume that std::unique_ptr<>
// and a plain pointer have the same memory layout.
divelog::divelog() :
dives(new dive_table),
trips(new trip_table),
sites(new dive_site_table),
devices(new device_table),
filter_presets(new filter_preset_table),
autogroup(false)
{
*dives = empty_dive_table;
*trips = empty_trip_table;
*sites = empty_dive_site_table;
}
divelog::~divelog()
{
clear_dive_table(dives);
clear_trip_table(trips);
clear_dive_site_table(sites);
delete dives;
delete trips;
delete sites;
delete devices;
delete filter_presets;
}
void divelog::clear()
{
while (dives->nr)
delete_single_dive(0);
while (sites->nr)
delete_dive_site(get_dive_site(0, sites), sites);
if (trips->nr != 0) {
fprintf(stderr, "Warning: trip table not empty in divelog::clear()!\n");
trips->nr = 0;
}
clear_device_table(devices);
filter_presets->clear();
}
extern "C" void clear_divelog(struct divelog *log)
{
log->clear();
}

40
core/divelog.h Normal file
View file

@ -0,0 +1,40 @@
// SPDX-License-Identifier: GPL-2.0
// A structure that contains all the values we save in a divelog file
#ifndef DIVELOG_H
#define DIVELOG_H
struct dive_table;
struct trip_table;
struct dive_site_table;
struct device_table;
struct filter_preset_table;
#include <stdbool.h>
struct divelog {
struct dive_table *dives;
struct trip_table *trips;
struct dive_site_table *sites;
struct device_table *devices;
struct filter_preset_table *filter_presets;
bool autogroup;
#ifdef __cplusplus
void clear();
divelog();
~divelog();
#endif
};
extern struct divelog divelog;
#ifdef __cplusplus
extern "C" {
#endif
void clear_divelog(struct divelog *);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -2,16 +2,15 @@
/* divesite.c */ /* divesite.c */
#include "divesite.h" #include "divesite.h"
#include "dive.h" #include "dive.h"
#include "subsurface-string.h"
#include "divelist.h" #include "divelist.h"
#include "divelog.h"
#include "membuffer.h" #include "membuffer.h"
#include "subsurface-string.h"
#include "table.h" #include "table.h"
#include "sha1.h" #include "sha1.h"
#include <math.h> #include <math.h>
struct dive_site_table dive_site_table;
int get_divesite_idx(const struct dive_site *ds, struct dive_site_table *ds_table) int get_divesite_idx(const struct dive_site *ds, struct dive_site_table *ds_table)
{ {
int i; int i;
@ -110,7 +109,7 @@ struct dive_site *get_dive_site_by_gps_proximity(const location_t *loc, int dist
int register_dive_site(struct dive_site *ds) int register_dive_site(struct dive_site *ds)
{ {
return add_dive_site_to_table(ds, &dive_site_table); return add_dive_site_to_table(ds, divelog.sites);
} }
static int compare_sites(const struct dive_site *a, const struct dive_site *b) static int compare_sites(const struct dive_site *a, const struct dive_site *b)
@ -232,7 +231,7 @@ void free_dive_site(struct dive_site *ds)
int unregister_dive_site(struct dive_site *ds) int unregister_dive_site(struct dive_site *ds)
{ {
return remove_dive_site(ds, &dive_site_table); return remove_dive_site(ds, divelog.sites);
} }
void delete_dive_site(struct dive_site *ds, struct dive_site_table *ds_table) void delete_dive_site(struct dive_site *ds, struct dive_site_table *ds_table)
@ -319,7 +318,7 @@ struct dive_site *get_same_dive_site(const struct dive_site *site)
{ {
int i; int i;
struct dive_site *ds; struct dive_site *ds;
for_each_dive_site (i, ds, &dive_site_table) for_each_dive_site (i, ds, divelog.sites)
if (same_dive_site(ds, site)) if (same_dive_site(ds, site))
return ds; return ds;
return NULL; return NULL;

View file

@ -33,8 +33,6 @@ typedef struct dive_site_table {
static const dive_site_table_t empty_dive_site_table = { 0, 0, (struct dive_site **)0 }; static const dive_site_table_t empty_dive_site_table = { 0, 0, (struct dive_site **)0 };
extern struct dive_site_table dive_site_table;
static inline struct dive_site *get_dive_site(int nr, struct dive_site_table *ds_table) static inline struct dive_site *get_dive_site(int nr, struct dive_site_table *ds_table)
{ {
if (nr >= ds_table->nr || nr < 0) if (nr >= ds_table->nr || nr < 0)

View file

@ -15,6 +15,7 @@
#include "gettext.h" #include "gettext.h"
#include "dive.h" #include "dive.h"
#include "divelist.h" #include "divelist.h"
#include "divelog.h"
#include "pref.h" #include "pref.h"
#include "subsurface-string.h" #include "subsurface-string.h"
#include "table.h" #include "table.h"
@ -305,8 +306,8 @@ void reset_tank_info_table(struct tank_info_table *table)
add_default_tank_infos(table); add_default_tank_infos(table);
/* Add cylinders from dive list */ /* Add cylinders from dive list */
for (int i = 0; i < dive_table.nr; ++i) { for (int i = 0; i < divelog.dives->nr; ++i) {
const struct dive *dive = dive_table.dives[i]; const struct dive *dive = divelog.dives->dives[i];
for (int j = 0; j < dive->cylinders.nr; j++) { for (int j = 0; j < dive->cylinders.nr; j++) {
const cylinder_t *cyl = get_cylinder(dive, j); const cylinder_t *cyl = get_cylinder(dive, j);
add_cylinder_description(&cyl->type); add_cylinder_description(&cyl->type);

View file

@ -11,6 +11,7 @@
#include <time.h> #include <time.h>
#include "dive.h" #include "dive.h"
#include "divelog.h"
#include "subsurface-string.h" #include "subsurface-string.h"
#include "errorhelper.h" #include "errorhelper.h"
#include "file.h" #include "file.h"
@ -76,8 +77,7 @@ out:
} }
static void zip_read(struct zip_file *file, const char *filename, struct dive_table *table, struct trip_table *trips, static void zip_read(struct zip_file *file, const char *filename, struct divelog *log)
struct dive_site_table *sites, struct device_table *devices, struct filter_preset_table *filter_presets)
{ {
int size = 1024, n, read = 0; int size = 1024, n, read = 0;
char *mem = malloc(size); char *mem = malloc(size);
@ -88,12 +88,11 @@ static void zip_read(struct zip_file *file, const char *filename, struct dive_ta
mem = realloc(mem, size); mem = realloc(mem, size);
} }
mem[read] = 0; mem[read] = 0;
(void) parse_xml_buffer(filename, mem, read, table, trips, sites, devices, filter_presets, NULL); (void) parse_xml_buffer(filename, mem, read, log, NULL);
free(mem); free(mem);
} }
int try_to_open_zip(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, int try_to_open_zip(const char *filename, struct divelog *log)
struct device_table *devices, struct filter_preset_table *filter_presets)
{ {
int success = 0; int success = 0;
/* Grr. libzip needs to re-open the file, it can't take a buffer */ /* Grr. libzip needs to re-open the file, it can't take a buffer */
@ -108,7 +107,7 @@ int try_to_open_zip(const char *filename, struct dive_table *table, struct trip_
/* skip parsing the divelogs.de pictures */ /* skip parsing the divelogs.de pictures */
if (strstr(zip_get_name(zip, index, 0), "pictures/")) if (strstr(zip_get_name(zip, index, 0), "pictures/"))
continue; continue;
zip_read(file, filename, table, trips, sites, devices, filter_presets); zip_read(file, filename, log);
zip_fclose(file); zip_fclose(file);
success++; success++;
} }
@ -128,8 +127,7 @@ static int db_test_func(void *param, int columns, char **data, char **column)
return *data[0] == '0'; return *data[0] == '0';
} }
static int try_to_open_db(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips, static int try_to_open_db(const char *filename, struct memblock *mem, struct divelog *log)
struct dive_site_table *sites, struct device_table *devices)
{ {
sqlite3 *handle; sqlite3 *handle;
char dm4_test[] = "select count(*) from sqlite_master where type='table' and name='Dive' and sql like '%ProfileBlob%'"; char dm4_test[] = "select count(*) from sqlite_master where type='table' and name='Dive' and sql like '%ProfileBlob%'";
@ -151,7 +149,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div
/* Testing if DB schema resembles Suunto DM5 database format */ /* Testing if DB schema resembles Suunto DM5 database format */
retval = sqlite3_exec(handle, dm5_test, &db_test_func, 0, NULL); retval = sqlite3_exec(handle, dm5_test, &db_test_func, 0, NULL);
if (!retval) { if (!retval) {
retval = parse_dm5_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites, devices); retval = parse_dm5_buffer(handle, filename, mem->buffer, mem->size, log);
sqlite3_close(handle); sqlite3_close(handle);
return retval; return retval;
} }
@ -159,7 +157,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div
/* Testing if DB schema resembles Suunto DM4 database format */ /* Testing if DB schema resembles Suunto DM4 database format */
retval = sqlite3_exec(handle, dm4_test, &db_test_func, 0, NULL); retval = sqlite3_exec(handle, dm4_test, &db_test_func, 0, NULL);
if (!retval) { if (!retval) {
retval = parse_dm4_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites, devices); retval = parse_dm4_buffer(handle, filename, mem->buffer, mem->size, log);
sqlite3_close(handle); sqlite3_close(handle);
return retval; return retval;
} }
@ -167,7 +165,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div
/* Testing if DB schema resembles Shearwater database format */ /* Testing if DB schema resembles Shearwater database format */
retval = sqlite3_exec(handle, shearwater_test, &db_test_func, 0, NULL); retval = sqlite3_exec(handle, shearwater_test, &db_test_func, 0, NULL);
if (!retval) { if (!retval) {
retval = parse_shearwater_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites, devices); retval = parse_shearwater_buffer(handle, filename, mem->buffer, mem->size, log);
sqlite3_close(handle); sqlite3_close(handle);
return retval; return retval;
} }
@ -175,7 +173,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div
/* Testing if DB schema resembles Shearwater cloud database format */ /* Testing if DB schema resembles Shearwater cloud database format */
retval = sqlite3_exec(handle, shearwater_cloud_test, &db_test_func, 0, NULL); retval = sqlite3_exec(handle, shearwater_cloud_test, &db_test_func, 0, NULL);
if (!retval) { if (!retval) {
retval = parse_shearwater_cloud_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites, devices); retval = parse_shearwater_cloud_buffer(handle, filename, mem->buffer, mem->size, log);
sqlite3_close(handle); sqlite3_close(handle);
return retval; return retval;
} }
@ -183,7 +181,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div
/* Testing if DB schema resembles Atomic Cobalt database format */ /* Testing if DB schema resembles Atomic Cobalt database format */
retval = sqlite3_exec(handle, cobalt_test, &db_test_func, 0, NULL); retval = sqlite3_exec(handle, cobalt_test, &db_test_func, 0, NULL);
if (!retval) { if (!retval) {
retval = parse_cobalt_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites, devices); retval = parse_cobalt_buffer(handle, filename, mem->buffer, mem->size, log);
sqlite3_close(handle); sqlite3_close(handle);
return retval; return retval;
} }
@ -191,7 +189,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div
/* Testing if DB schema resembles Divinglog database format */ /* Testing if DB schema resembles Divinglog database format */
retval = sqlite3_exec(handle, divinglog_test, &db_test_func, 0, NULL); retval = sqlite3_exec(handle, divinglog_test, &db_test_func, 0, NULL);
if (!retval) { if (!retval) {
retval = parse_divinglog_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites, devices); retval = parse_divinglog_buffer(handle, filename, mem->buffer, mem->size, log);
sqlite3_close(handle); sqlite3_close(handle);
return retval; return retval;
} }
@ -199,7 +197,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div
/* Testing if DB schema resembles Seac database format */ /* Testing if DB schema resembles Seac database format */
retval = sqlite3_exec(handle, seacsync_test, &db_test_func, 0, NULL); retval = sqlite3_exec(handle, seacsync_test, &db_test_func, 0, NULL);
if (!retval) { if (!retval) {
retval = parse_seac_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites, devices); retval = parse_seac_buffer(handle, filename, mem->buffer, mem->size, log);
sqlite3_close(handle); sqlite3_close(handle);
return retval; return retval;
} }
@ -226,9 +224,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div
* *
* Followed by the data values (all comma-separated, all one long line). * Followed by the data values (all comma-separated, all one long line).
*/ */
static int open_by_filename(const char *filename, const char *fmt, struct memblock *mem, static int open_by_filename(const char *filename, const char *fmt, struct memblock *mem, struct divelog *log)
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices, struct filter_preset_table *filter_presets)
{ {
// hack to be able to provide a comment for the translated string // hack to be able to provide a comment for the translated string
static char *csv_warning = QT_TRANSLATE_NOOP3("gettextFromC", static char *csv_warning = QT_TRANSLATE_NOOP3("gettextFromC",
@ -237,40 +233,38 @@ static int open_by_filename(const char *filename, const char *fmt, struct memblo
/* Suunto Dive Manager files: SDE, ZIP; divelogs.de files: DLD */ /* Suunto Dive Manager files: SDE, ZIP; divelogs.de files: DLD */
if (!strcasecmp(fmt, "SDE") || !strcasecmp(fmt, "ZIP") || !strcasecmp(fmt, "DLD")) if (!strcasecmp(fmt, "SDE") || !strcasecmp(fmt, "ZIP") || !strcasecmp(fmt, "DLD"))
return try_to_open_zip(filename, table, trips, sites, devices, filter_presets); return try_to_open_zip(filename, log);
/* CSV files */ /* CSV files */
if (!strcasecmp(fmt, "CSV")) if (!strcasecmp(fmt, "CSV"))
return report_error(translate("gettextFromC", csv_warning), filename); return report_error(translate("gettextFromC", csv_warning), filename);
/* Truly nasty intentionally obfuscated Cochran Anal software */ /* Truly nasty intentionally obfuscated Cochran Anal software */
if (!strcasecmp(fmt, "CAN")) if (!strcasecmp(fmt, "CAN"))
return try_to_open_cochran(filename, mem, table, trips, sites); return try_to_open_cochran(filename, mem, log);
/* Cochran export comma-separated-value files */ /* Cochran export comma-separated-value files */
if (!strcasecmp(fmt, "DPT")) if (!strcasecmp(fmt, "DPT"))
return try_to_open_csv(mem, CSV_DEPTH, table, trips, sites); return try_to_open_csv(mem, CSV_DEPTH, log);
if (!strcasecmp(fmt, "LVD")) if (!strcasecmp(fmt, "LVD"))
return try_to_open_liquivision(filename, mem, table, trips, sites); return try_to_open_liquivision(filename, mem, log);
if (!strcasecmp(fmt, "TMP")) if (!strcasecmp(fmt, "TMP"))
return try_to_open_csv(mem, CSV_TEMP, table, trips, sites); return try_to_open_csv(mem, CSV_TEMP, log);
if (!strcasecmp(fmt, "HP1")) if (!strcasecmp(fmt, "HP1"))
return try_to_open_csv(mem, CSV_PRESSURE, table, trips, sites); return try_to_open_csv(mem, CSV_PRESSURE, log);
return 0; return 0;
} }
static int parse_file_buffer(const char *filename, struct memblock *mem, struct dive_table *table, static int parse_file_buffer(const char *filename, struct memblock *mem, struct divelog *log)
struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices, struct filter_preset_table *filter_presets)
{ {
int ret; int ret;
char *fmt = strrchr(filename, '.'); char *fmt = strrchr(filename, '.');
if (fmt && (ret = open_by_filename(filename, fmt + 1, mem, table, trips, sites, devices, filter_presets)) != 0) if (fmt && (ret = open_by_filename(filename, fmt + 1, mem, log)) != 0)
return ret; return ret;
if (!mem->size || !mem->buffer) if (!mem->size || !mem->buffer)
return report_error("Out of memory parsing file %s\n", filename); return report_error("Out of memory parsing file %s\n", filename);
return parse_xml_buffer(filename, mem->buffer, mem->size, table, trips, sites, devices, filter_presets, NULL); return parse_xml_buffer(filename, mem->buffer, mem->size, log, NULL);
} }
bool remote_repo_uptodate(const char *filename, struct git_info *info) bool remote_repo_uptodate(const char *filename, struct git_info *info)
@ -292,8 +286,7 @@ bool remote_repo_uptodate(const char *filename, struct git_info *info)
return false; return false;
} }
int parse_file(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, int parse_file(const char *filename, struct divelog *log)
struct device_table *devices, struct filter_preset_table *filter_presets)
{ {
struct git_info info; struct git_info info;
struct memblock mem; struct memblock mem;
@ -312,7 +305,7 @@ int parse_file(const char *filename, struct dive_table *table, struct trip_table
} }
} }
ret = git_load_dives(&info, table, trips, sites, devices, filter_presets); ret = git_load_dives(&info, log);
cleanup_git_info(&info); cleanup_git_info(&info);
return ret; return ret;
} }
@ -329,7 +322,7 @@ int parse_file(const char *filename, struct dive_table *table, struct trip_table
fmt = strrchr(filename, '.'); fmt = strrchr(filename, '.');
if (fmt && (!strcasecmp(fmt + 1, "DB") || !strcasecmp(fmt + 1, "BAK") || !strcasecmp(fmt + 1, "SQL"))) { if (fmt && (!strcasecmp(fmt + 1, "DB") || !strcasecmp(fmt + 1, "BAK") || !strcasecmp(fmt + 1, "SQL"))) {
if (!try_to_open_db(filename, &mem, table, trips, sites, devices)) { if (!try_to_open_db(filename, &mem, log)) {
free(mem.buffer); free(mem.buffer);
return 0; return 0;
} }
@ -337,7 +330,7 @@ int parse_file(const char *filename, struct dive_table *table, struct trip_table
/* Divesoft Freedom */ /* Divesoft Freedom */
if (fmt && (!strcasecmp(fmt + 1, "DLF"))) { if (fmt && (!strcasecmp(fmt + 1, "DLF"))) {
ret = parse_dlf_buffer(mem.buffer, mem.size, table, trips, sites, devices); ret = parse_dlf_buffer(mem.buffer, mem.size, log);
free(mem.buffer); free(mem.buffer);
return ret; return ret;
} }
@ -351,9 +344,9 @@ int parse_file(const char *filename, struct dive_table *table, struct trip_table
wl_name = strcat(wl_name, ".add"); wl_name = strcat(wl_name, ".add");
if((ret = readfile(wl_name, &wl_mem)) < 0) { if((ret = readfile(wl_name, &wl_mem)) < 0) {
fprintf(stderr, "No file %s found. No WLog extensions.\n", wl_name); fprintf(stderr, "No file %s found. No WLog extensions.\n", wl_name);
ret = datatrak_import(&mem, NULL, table, trips, sites, devices); ret = datatrak_import(&mem, NULL, log);
} else { } else {
ret = datatrak_import(&mem, &wl_mem, table, trips, sites, devices); ret = datatrak_import(&mem, &wl_mem, log);
free(wl_mem.buffer); free(wl_mem.buffer);
} }
free(mem.buffer); free(mem.buffer);
@ -364,11 +357,11 @@ int parse_file(const char *filename, struct dive_table *table, struct trip_table
/* OSTCtools */ /* OSTCtools */
if (fmt && (!strcasecmp(fmt + 1, "DIVE"))) { if (fmt && (!strcasecmp(fmt + 1, "DIVE"))) {
free(mem.buffer); free(mem.buffer);
ostctools_import(filename, table, trips, sites); ostctools_import(filename, log);
return 0; return 0;
} }
ret = parse_file_buffer(filename, &mem, table, trips, sites, devices, filter_presets); ret = parse_file_buffer(filename, &mem, log);
free(mem.buffer); free(mem.buffer);
return ret; return ret;
} }

View file

@ -12,26 +12,20 @@ struct memblock {
size_t size; size_t size;
}; };
struct trip_table; struct divelog;
struct device_table;
struct dive_site_table;
struct dive_table;
struct zip; struct zip;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
extern int try_to_open_cochran(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites); extern int try_to_open_cochran(const char *filename, struct memblock *mem, struct divelog *log);
extern int try_to_open_liquivision(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites); extern int try_to_open_liquivision(const char *filename, struct memblock *mem, struct divelog *log);
extern int datatrak_import(struct memblock *mem, struct memblock *wl_mem, struct dive_table *table, struct trip_table *trips, extern int datatrak_import(struct memblock *mem, struct memblock *wl_mem, struct divelog *log);
struct dive_site_table *sites, struct device_table *devices); extern void ostctools_import(const char *file, struct divelog *log);
extern void ostctools_import(const char *file, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
extern int readfile(const char *filename, struct memblock *mem); extern int readfile(const char *filename, struct memblock *mem);
extern int parse_file(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, extern int parse_file(const char *filename, struct divelog *log);
struct device_table *devices, struct filter_preset_table *filter_presets); extern int try_to_open_zip(const char *filename, struct divelog *log);
extern int try_to_open_zip(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices, struct filter_preset_table *filter_presets);
// Platform specific functions // Platform specific functions
extern int subsurface_rename(const char *path, const char *newpath); extern int subsurface_rename(const char *path, const char *newpath);
@ -40,7 +34,7 @@ extern int subsurface_open(const char *path, int oflags, mode_t mode);
extern FILE *subsurface_fopen(const char *path, const char *mode); extern FILE *subsurface_fopen(const char *path, const char *mode);
extern void *subsurface_opendir(const char *path); extern void *subsurface_opendir(const char *path);
extern int subsurface_access(const char *path, int mode); extern int subsurface_access(const char *path, int mode);
extern int subsurface_stat(const char* path, struct stat* buf); extern int subsurface_stat(const char *path, struct stat *buf);
extern struct zip *subsurface_zip_open_readonly(const char *path, int flags, int *errorp); extern struct zip *subsurface_zip_open_readonly(const char *path, int flags, int *errorp);
extern int subsurface_zip_close(struct zip *zip); extern int subsurface_zip_close(struct zip *zip);

View file

@ -1,18 +1,17 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include "filterpreset.h" #include "filterpreset.h"
#include "divelog.h"
#include "qthelper.h" #include "qthelper.h"
#include "subsurface-string.h" #include "subsurface-string.h"
struct filter_preset_table filter_preset_table; static filter_preset_table &global_table()
extern "C" void clear_filter_presets(void)
{ {
filter_preset_table.clear(); return *divelog.filter_presets;
} }
extern "C" int filter_presets_count(void) extern "C" int filter_presets_count(void)
{ {
return (int)filter_preset_table.size(); return (int)global_table().size();
} }
extern "C" char *filter_preset_name(int preset) extern "C" char *filter_preset_name(int preset)
@ -22,12 +21,12 @@ extern "C" char *filter_preset_name(int preset)
extern "C" char *filter_preset_fulltext_query(int preset) extern "C" char *filter_preset_fulltext_query(int preset)
{ {
return copy_qstring(filter_preset_table[preset].data.fullText.originalQuery); return copy_qstring(global_table()[preset].data.fullText.originalQuery);
} }
extern "C" const char *filter_preset_fulltext_mode(int preset) extern "C" const char *filter_preset_fulltext_mode(int preset)
{ {
switch (filter_preset_table[preset].data.fulltextStringMode) { switch (global_table()[preset].data.fulltextStringMode) {
default: default:
case StringFilterMode::SUBSTRING: case StringFilterMode::SUBSTRING:
return "substring"; return "substring";
@ -51,12 +50,12 @@ extern "C" void filter_preset_set_fulltext(struct filter_preset *preset, const c
extern "C" int filter_preset_constraint_count(int preset) extern "C" int filter_preset_constraint_count(int preset)
{ {
return (int)filter_preset_table[preset].data.constraints.size(); return (int)global_table()[preset].data.constraints.size();
} }
extern "C" const filter_constraint *filter_preset_constraint(int preset, int constraint) extern "C" const filter_constraint *filter_preset_constraint(int preset, int constraint)
{ {
return &filter_preset_table[preset].data.constraints[constraint]; return &global_table()[preset].data.constraints[constraint];
} }
extern "C" struct filter_preset *alloc_filter_preset() extern "C" struct filter_preset *alloc_filter_preset()
@ -113,33 +112,33 @@ extern "C" void filter_preset_add_constraint(struct filter_preset *preset, const
int filter_preset_id(const QString &name) int filter_preset_id(const QString &name)
{ {
auto it = std::find_if(filter_preset_table.begin(), filter_preset_table.end(), auto it = std::find_if(global_table().begin(), global_table().end(),
[&name] (filter_preset &p) { return p.name == name; }); [&name] (filter_preset &p) { return p.name == name; });
return it != filter_preset_table.end() ? it - filter_preset_table.begin() : -1; return it != global_table().end() ? it - global_table().begin() : -1;
} }
QString filter_preset_name_qstring(int preset) QString filter_preset_name_qstring(int preset)
{ {
return filter_preset_table[preset].name; return global_table()[preset].name;
} }
void filter_preset_set(int preset, const FilterData &data) void filter_preset_set(int preset, const FilterData &data)
{ {
filter_preset_table[preset].data = data; global_table()[preset].data = data;
} }
FilterData filter_preset_get(int preset) FilterData filter_preset_get(int preset)
{ {
return filter_preset_table[preset].data; return global_table()[preset].data;
} }
int filter_preset_add(const QString &nameIn, const FilterData &d) int filter_preset_add(const QString &nameIn, const FilterData &d)
{ {
QString name = get_unique_preset_name(nameIn, filter_preset_table); QString name = get_unique_preset_name(nameIn, global_table());
return filter_preset_add_to_table(name, d, filter_preset_table); return filter_preset_add_to_table(name, d, global_table());
} }
void filter_preset_delete(int preset) void filter_preset_delete(int preset)
{ {
filter_preset_table.erase(filter_preset_table.begin() + preset); global_table().erase(global_table().begin() + preset);
} }

View file

@ -32,7 +32,6 @@ struct filter_preset_table : public std::vector<filter_preset>
{ {
}; };
extern struct filter_preset_table filter_preset_table;
#else #else
struct filter_preset; struct filter_preset;
struct filter_preset_table; struct filter_preset_table;
@ -44,7 +43,6 @@ extern "C" {
#endif #endif
// The C IO code accesses the filter presets via integer indices. // The C IO code accesses the filter presets via integer indices.
extern void clear_filter_presets(void);
extern int filter_presets_count(void); extern int filter_presets_count(void);
extern char *filter_preset_name(int preset); // name of filter preset - caller must free the result. extern char *filter_preset_name(int preset); // name of filter preset - caller must free the result.
extern char *filter_preset_fulltext_query(int preset); // fulltext query of filter preset - caller must free the result. extern char *filter_preset_fulltext_query(int preset); // fulltext query of filter preset - caller must free the result.

View file

@ -2,6 +2,7 @@
#include "fulltext.h" #include "fulltext.h"
#include "dive.h" #include "dive.h"
#include "divelog.h"
#include "divesite.h" #include "divesite.h"
#include "tag.h" #include "tag.h"
#include "trip.h" #include "trip.h"
@ -155,7 +156,7 @@ void FullText::populate()
dive *d; dive *d;
for_each_dive(i, d) for_each_dive(i, d)
registerDive(d); registerDive(d);
uiNotification(QObject::tr("%1 dives processed").arg(dive_table.nr)); uiNotification(QObject::tr("%1 dives processed").arg(divelog.dives->nr));
} }
void FullText::registerDive(struct dive *d) void FullText::registerDive(struct dive *d)

View file

@ -5,9 +5,7 @@
#include "git2.h" #include "git2.h"
#include "filterpreset.h" #include "filterpreset.h"
struct dive_table; struct dive_log;
struct dive_site_table;
struct trip_table;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -26,7 +24,7 @@ enum remote_transport { RT_LOCAL, RT_HTTPS, RT_SSH, RT_OTHER };
struct git_oid; struct git_oid;
struct git_repository; struct git_repository;
struct device_table; struct divelog;
struct git_info { struct git_info {
const char *url; const char *url;
@ -43,9 +41,7 @@ extern bool open_git_repository(struct git_info *info);
extern bool remote_repo_uptodate(const char *filename, struct git_info *info); extern bool remote_repo_uptodate(const char *filename, struct git_info *info);
extern int sync_with_remote(struct git_info *); extern int sync_with_remote(struct git_info *);
extern int git_save_dives(struct git_info *, bool select_only); extern int git_save_dives(struct git_info *, bool select_only);
extern int git_load_dives(struct git_info *, struct dive_table *table, struct trip_table *trips, extern int git_load_dives(struct git_info *, struct divelog *log);
struct dive_site_table *sites, struct device_table *devices,
struct filter_preset_table *filter_presets);
extern const char *get_sha(git_repository *repo, const char *branch); extern const char *get_sha(git_repository *repo, const char *branch);
extern int do_git_save(struct git_info *, bool select_only, bool create_empty); extern int do_git_save(struct git_info *, bool select_only, bool create_empty);
extern void cleanup_git_info(struct git_info *); extern void cleanup_git_info(struct git_info *);

View file

@ -12,6 +12,7 @@
#include "sample.h" #include "sample.h"
#include "subsurface-string.h" #include "subsurface-string.h"
#include "divelist.h" #include "divelist.h"
#include "divelog.h"
#include "device.h" #include "device.h"
#include "membuffer.h" #include "membuffer.h"
#include "gettext.h" #include "gettext.h"
@ -219,9 +220,7 @@ static int cobalt_dive(void *param, int columns, char **data, char **column)
} }
int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, struct divelog *log)
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices)
{ {
UNUSED(buffer); UNUSED(buffer);
UNUSED(size); UNUSED(size);
@ -230,10 +229,10 @@ int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *buffer, in
struct parser_state state; struct parser_state state;
init_parser_state(&state); init_parser_state(&state);
state.target_table = table; state.target_table = log->dives;
state.trips = trips; state.trips = log->trips;
state.sites = sites; state.sites = log->sites;
state.devices = devices; state.devices = log->devices;
state.sql_handle = handle; state.sql_handle = handle;
char get_dives[] = "select Id,strftime('%s',DiveStartTime),LocationId,'buddy','notes',Units,(MaxDepthPressure*10000/SurfacePressure)-10000,DiveMinutes,SurfacePressure,SerialNumber,'model' from Dive where IsViewDeleted = 0"; char get_dives[] = "select Id,strftime('%s',DiveStartTime),LocationId,'buddy','notes',Units,(MaxDepthPressure*10000/SurfacePressure)-10000,DiveMinutes,SurfacePressure,SerialNumber,'model' from Dive where IsViewDeleted = 0";

View file

@ -8,6 +8,7 @@
#include "ssrf.h" #include "ssrf.h"
#include "subsurface-string.h" #include "subsurface-string.h"
#include "divelist.h" #include "divelist.h"
#include "divelog.h"
#include "file.h" #include "file.h"
#include "parse.h" #include "parse.h"
#include "sample.h" #include "sample.h"
@ -106,9 +107,7 @@ static char *parse_dan_new_line(char *buf, const char *NL)
} }
static int try_to_xslt_open_csv(const char *filename, struct memblock *mem, const char *tag); static int try_to_xslt_open_csv(const char *filename, struct memblock *mem, const char *tag);
static int parse_dan_format(const char *filename, struct xml_params *params, struct dive_table *table, static int parse_dan_format(const char *filename, struct xml_params *params, struct divelog *log)
struct trip_table *trips, struct dive_site_table *sites, struct device_table *devices,
struct filter_preset_table *filter_presets)
{ {
int ret = 0, i; int ret = 0, i;
size_t end_ptr = 0; size_t end_ptr = 0;
@ -212,7 +211,7 @@ static int parse_dan_format(const char *filename, struct xml_params *params, str
xml_params_add(params, "waterTemp", tmpbuf); xml_params_add(params, "waterTemp", tmpbuf);
} }
} }
ret |= parse_xml_buffer(filename, "<csv></csv>", 11, table, trips, sites, devices, filter_presets, params); ret |= parse_xml_buffer(filename, "<csv></csv>", 11, log, params);
continue; continue;
} }
@ -268,7 +267,7 @@ static int parse_dan_format(const char *filename, struct xml_params *params, str
if (try_to_xslt_open_csv(filename, &mem_csv, "csv")) if (try_to_xslt_open_csv(filename, &mem_csv, "csv"))
return -1; return -1;
ret |= parse_xml_buffer(filename, mem_csv.buffer, mem_csv.size, table, trips, sites, devices, filter_presets, params); ret |= parse_xml_buffer(filename, mem_csv.buffer, mem_csv.size, log, params);
free(mem_csv.buffer); free(mem_csv.buffer);
} }
@ -278,9 +277,7 @@ static int parse_dan_format(const char *filename, struct xml_params *params, str
return ret; return ret;
} }
int parse_csv_file(const char *filename, struct xml_params *params, const char *csvtemplate, int parse_csv_file(const char *filename, struct xml_params *params, const char *csvtemplate, struct divelog *log)
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices, struct filter_preset_table *filter_presets)
{ {
int ret; int ret;
struct memblock mem; struct memblock mem;
@ -300,7 +297,7 @@ int parse_csv_file(const char *filename, struct xml_params *params, const char *
mem.size = 0; mem.size = 0;
if (!strcmp("DL7", csvtemplate)) { if (!strcmp("DL7", csvtemplate)) {
return parse_dan_format(filename, params, table, trips, sites, devices, filter_presets); return parse_dan_format(filename, params, log);
} else if (strcmp(xml_params_get_key(params, 0), "date")) { } else if (strcmp(xml_params_get_key(params, 0), "date")) {
time(&now); time(&now);
timep = localtime(&now); timep = localtime(&now);
@ -332,7 +329,7 @@ int parse_csv_file(const char *filename, struct xml_params *params, const char *
fprintf(stderr, "%s/xslt/%s -\n", SUBSURFACE_SOURCE, csvtemplate); fprintf(stderr, "%s/xslt/%s -\n", SUBSURFACE_SOURCE, csvtemplate);
} }
#endif #endif
ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, sites, devices, filter_presets, params); ret = parse_xml_buffer(filename, mem.buffer, mem.size, log, params);
free(mem.buffer); free(mem.buffer);
@ -409,9 +406,8 @@ static int try_to_xslt_open_csv(const char *filename, struct memblock *mem, cons
return 0; return 0;
} }
int try_to_open_csv(struct memblock *mem, enum csv_format type, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites) int try_to_open_csv(struct memblock *mem, enum csv_format type, struct divelog *log)
{ {
UNUSED(sites);
char *p = mem->buffer; char *p = mem->buffer;
char *header[8]; char *header[8];
int i, time; int i, time;
@ -460,7 +456,7 @@ int try_to_open_csv(struct memblock *mem, enum csv_format type, struct dive_tabl
break; break;
p = end + 1; p = end + 1;
} }
record_dive_to_table(dive, table); record_dive_to_table(dive, log->dives);
return 1; return 1;
} }
@ -502,15 +498,12 @@ static char *next_mkvi_key(const char *haystack)
return ret; return ret;
} }
int parse_txt_file(const char *filename, const char *csv, struct dive_table *table, struct trip_table *trips, int parse_txt_file(const char *filename, const char *csv, struct divelog *log)
struct dive_site_table *sites, struct device_table *devices)
{ {
UNUSED(sites);
struct memblock memtxt, memcsv; struct memblock memtxt, memcsv;
if (readfile(filename, &memtxt) < 0) { if (readfile(filename, &memtxt) < 0)
return report_error(translate("gettextFromC", "Failed to read '%s'"), filename); return report_error(translate("gettextFromC", "Failed to read '%s'"), filename);
}
/* /*
* MkVI stores some information in .txt file but the whole profile and events are stored in .csv file. First * MkVI stores some information in .txt file but the whole profile and events are stored in .csv file. First
@ -786,7 +779,7 @@ int parse_txt_file(const char *filename, const char *csv, struct dive_table *tab
if (!lineptr || !*lineptr) if (!lineptr || !*lineptr)
break; break;
} }
record_dive_to_table(dive, table); record_dive_to_table(dive, log->dives);
return 1; return 1;
} else { } else {
return 0; return 0;
@ -799,17 +792,14 @@ int parse_txt_file(const char *filename, const char *csv, struct dive_table *tab
#define TIMESTR 6 #define TIMESTR 6
#define SBPARAMS 40 #define SBPARAMS 40
static int parse_seabear_csv_file(const char *filename, struct xml_params *params, const char *csvtemplate, static int parse_seabear_csv_file(const char *filename, struct xml_params *params, const char *csvtemplate, struct divelog *log);
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, int parse_seabear_log(const char *filename, struct divelog *log)
struct device_table *devices, struct filter_preset_table *filter_presets);
int parse_seabear_log(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices, struct filter_preset_table *filter_presets)
{ {
struct xml_params *params = alloc_xml_params(); struct xml_params *params = alloc_xml_params();
int ret; int ret;
parse_seabear_header(filename, params); parse_seabear_header(filename, params);
ret = parse_seabear_csv_file(filename, params, "csv", table, trips, sites, devices, filter_presets) < 0 ? -1 : 0; ret = parse_seabear_csv_file(filename, params, "csv", log) < 0 ? -1 : 0;
free_xml_params(params); free_xml_params(params);
@ -817,9 +807,7 @@ int parse_seabear_log(const char *filename, struct dive_table *table, struct tri
} }
static int parse_seabear_csv_file(const char *filename, struct xml_params *params, const char *csvtemplate, static int parse_seabear_csv_file(const char *filename, struct xml_params *params, const char *csvtemplate, struct divelog *log)
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices, struct filter_preset_table *filter_presets)
{ {
int ret, i; int ret, i;
struct memblock mem; struct memblock mem;
@ -937,14 +925,13 @@ static int parse_seabear_csv_file(const char *filename, struct xml_params *param
fprintf(stderr, "xslt/csv2xml.xslt\n"); fprintf(stderr, "xslt/csv2xml.xslt\n");
} }
ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, sites, devices, filter_presets, params); ret = parse_xml_buffer(filename, mem.buffer, mem.size, log, params);
free(mem.buffer); free(mem.buffer);
return ret; return ret;
} }
int parse_manual_file(const char *filename, struct xml_params *params, struct dive_table *table, struct trip_table *trips, int parse_manual_file(const char *filename, struct xml_params *params, struct divelog *log)
struct dive_site_table *sites, struct device_table *devices, struct filter_preset_table *filter_presets)
{ {
struct memblock mem; struct memblock mem;
time_t now; time_t now;
@ -980,7 +967,7 @@ int parse_manual_file(const char *filename, struct xml_params *params, struct di
fprintf(stderr, "%s/xslt/manualcsv2xml.xslt -\n", SUBSURFACE_SOURCE); fprintf(stderr, "%s/xslt/manualcsv2xml.xslt -\n", SUBSURFACE_SOURCE);
} }
#endif #endif
ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, sites, devices, filter_presets, params); ret = parse_xml_buffer(filename, mem.buffer, mem.size, log, params);
free(mem.buffer); free(mem.buffer);
return ret; return ret;

View file

@ -25,17 +25,12 @@ enum csv_format {
extern "C" { extern "C" {
#endif #endif
int parse_csv_file(const char *filename, struct xml_params *params, const char *csvtemplate, struct dive_table *table, int parse_csv_file(const char *filename, struct xml_params *params, const char *csvtemplate, struct divelog *log);
struct trip_table *trips, struct dive_site_table *sites, struct device_table *devices, int try_to_open_csv(struct memblock *mem, enum csv_format type, struct divelog *log);
struct filter_preset_table *filter_presets); int parse_txt_file(const char *filename, const char *csv, struct divelog *log);
int try_to_open_csv(struct memblock *mem, enum csv_format type, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
int parse_txt_file(const char *filename, const char *csv, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, struct device_table *devices);
int parse_seabear_log(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, int parse_seabear_log(const char *filename, struct divelog *log);
struct device_table *devices, struct filter_preset_table *filter_presets); int parse_manual_file(const char *filename, struct xml_params *params, struct divelog *log);
int parse_manual_file(const char *filename, struct xml_params *params, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, struct device_table *devices, struct filter_preset_table *filter_presets);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -11,6 +11,7 @@
#include "subsurface-string.h" #include "subsurface-string.h"
#include "parse.h" #include "parse.h"
#include "divelist.h" #include "divelist.h"
#include "divelog.h"
#include "device.h" #include "device.h"
#include "membuffer.h" #include "membuffer.h"
#include "gettext.h" #include "gettext.h"
@ -390,9 +391,7 @@ static int divinglog_dive(void *param, int columns, char **data, char **column)
} }
int parse_divinglog_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, int parse_divinglog_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, struct divelog *log)
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices)
{ {
UNUSED(buffer); UNUSED(buffer);
UNUSED(size); UNUSED(size);
@ -401,10 +400,10 @@ int parse_divinglog_buffer(sqlite3 *handle, const char *url, const char *buffer,
struct parser_state state; struct parser_state state;
init_parser_state(&state); init_parser_state(&state);
state.target_table = table; state.target_table = log->dives;
state.trips = trips; state.trips = log->trips;
state.sites = sites; state.sites = log->sites;
state.devices = devices; state.devices = log->devices;
state.sql_handle = handle; state.sql_handle = handle;
char get_dives[] = "select Number,strftime('%s',Divedate || ' ' || ifnull(Entrytime,'00:00')),Country || ' - ' || City || ' - ' || Place,Buddy,Comments,Depth,Divetime,Divemaster,Airtemp,Watertemp,Weight,Divesuit,Computer,ID,Visibility,SupplyType from Logbook where UUID not in (select UUID from DeletedRecords)"; char get_dives[] = "select Number,strftime('%s',Divedate || ' ' || ifnull(Entrytime,'00:00')),Country || ' - ' || City || ' - ' || Place,Buddy,Comments,Depth,Divetime,Divemaster,Airtemp,Watertemp,Weight,Divesuit,Computer,ID,Visibility,SupplyType from Logbook where UUID not in (select UUID from DeletedRecords)";

View file

@ -11,6 +11,7 @@
#include "subsurface-string.h" #include "subsurface-string.h"
#include "parse.h" #include "parse.h"
#include "divelist.h" #include "divelist.h"
#include "divelog.h"
#include "device.h" #include "device.h"
#include "membuffer.h" #include "membuffer.h"
#include "gettext.h" #include "gettext.h"
@ -262,9 +263,7 @@ static int seac_dive(void *param, int columns, char **data, char **column)
* The callback function performs another SQL query on the other * The callback function performs another SQL query on the other
* table, to read in the sample values. * table, to read in the sample values.
*/ */
int parse_seac_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, int parse_seac_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, struct divelog *log)
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices)
{ {
UNUSED(buffer); UNUSED(buffer);
UNUSED(size); UNUSED(size);
@ -274,10 +273,10 @@ int parse_seac_buffer(sqlite3 *handle, const char *url, const char *buffer, int
struct parser_state state; struct parser_state state;
init_parser_state(&state); init_parser_state(&state);
state.target_table = table; state.target_table = log->dives;
state.trips = trips; state.trips = log->trips;
state.sites = sites; state.sites = log->sites;
state.devices = devices; state.devices = log->devices;
state.sql_handle = handle; state.sql_handle = handle;
const char *get_dives = "SELECT dive_number, device_sn, date, timezone, time, elapsed_surface_time, dive_type, start_mode, water_type, comment, total_dive_time, max_depth, firmware_version, dive_id FROM headers_dive"; const char *get_dives = "SELECT dive_number, device_sn, date, timezone, time, elapsed_surface_time, dive_type, start_mode, water_type, comment, total_dive_time, max_depth, firmware_version, dive_id FROM headers_dive";

View file

@ -10,6 +10,7 @@
#include "subsurface-string.h" #include "subsurface-string.h"
#include "parse.h" #include "parse.h"
#include "divelist.h" #include "divelist.h"
#include "divelog.h"
#include "device.h" #include "device.h"
#include "membuffer.h" #include "membuffer.h"
#include "gettext.h" #include "gettext.h"
@ -487,9 +488,7 @@ static int shearwater_cloud_dive(void *param, int columns, char **data, char **c
return SQLITE_OK; return SQLITE_OK;
} }
int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, struct divelog *log)
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices)
{ {
UNUSED(buffer); UNUSED(buffer);
UNUSED(size); UNUSED(size);
@ -498,10 +497,10 @@ int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buffer
struct parser_state state; struct parser_state state;
init_parser_state(&state); init_parser_state(&state);
state.target_table = table; state.target_table = log->dives;
state.trips = trips; state.trips = log->trips;
state.sites = sites; state.sites = log->sites;
state.devices = devices; state.devices = log->devices;
state.sql_handle = handle; state.sql_handle = handle;
// So far have not seen any sample rate in Shearwater Desktop // So far have not seen any sample rate in Shearwater Desktop
@ -520,9 +519,7 @@ int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buffer
return 0; return 0;
} }
int parse_shearwater_cloud_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, int parse_shearwater_cloud_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, struct divelog *log)
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices)
{ {
UNUSED(buffer); UNUSED(buffer);
UNUSED(size); UNUSED(size);
@ -531,10 +528,10 @@ int parse_shearwater_cloud_buffer(sqlite3 *handle, const char *url, const char *
struct parser_state state; struct parser_state state;
init_parser_state(&state); init_parser_state(&state);
state.target_table = table; state.target_table = log->dives;
state.trips = trips; state.trips = log->trips;
state.sites = sites; state.sites = log->sites;
state.devices = devices; state.devices = log->devices;
state.sql_handle = handle; state.sql_handle = handle;
char get_dives[] = "select l.number,strftime('%s', DiveDate),location||' / '||site,buddy,notes,imperialUnits,maxDepth,DiveLengthTime,startSurfacePressure,computerSerial,computerModel,d.diveId,l.sampleRateMs / 1000 FROM dive_details AS d JOIN dive_logs AS l ON d.diveId=l.diveId"; char get_dives[] = "select l.number,strftime('%s', DiveDate),location||' / '||site,buddy,notes,imperialUnits,maxDepth,DiveLengthTime,startSurfacePressure,computerSerial,computerModel,d.diveId,l.sampleRateMs / 1000 FROM dive_details AS d JOIN dive_logs AS l ON d.diveId=l.diveId";

View file

@ -10,6 +10,7 @@
#include "sample.h" #include "sample.h"
#include "subsurface-string.h" #include "subsurface-string.h"
#include "divelist.h" #include "divelist.h"
#include "divelog.h"
#include "device.h" #include "device.h"
#include "membuffer.h" #include "membuffer.h"
#include "gettext.h" #include "gettext.h"
@ -292,9 +293,7 @@ static int dm4_dive(void *param, int columns, char **data, char **column)
return SQLITE_OK; return SQLITE_OK;
} }
int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, struct divelog *log)
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices)
{ {
UNUSED(buffer); UNUSED(buffer);
UNUSED(size); UNUSED(size);
@ -304,10 +303,10 @@ int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buffer, int s
struct parser_state state; struct parser_state state;
init_parser_state(&state); init_parser_state(&state);
state.target_table = table; state.target_table = log->dives;
state.trips = trips; state.trips = log->trips;
state.sites = sites; state.sites = log->sites;
state.devices = devices; state.devices = log->devices;
state.sql_handle = handle; state.sql_handle = handle;
/* StartTime is converted from Suunto's nano seconds to standard /* StartTime is converted from Suunto's nano seconds to standard
@ -579,9 +578,7 @@ static int dm5_dive(void *param, int columns, char **data, char **column)
return SQLITE_OK; return SQLITE_OK;
} }
int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, struct divelog *log)
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices)
{ {
UNUSED(buffer); UNUSED(buffer);
UNUSED(size); UNUSED(size);
@ -591,10 +588,10 @@ int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buffer, int s
struct parser_state state; struct parser_state state;
init_parser_state(&state); init_parser_state(&state);
state.target_table = table; state.target_table = log->dives;
state.trips = trips; state.trips = log->trips;
state.sites = sites; state.sites = log->sites;
state.devices = devices; state.devices = log->devices;
state.sql_handle = handle; state.sql_handle = handle;
/* StartTime is converted from Suunto's nano seconds to standard /* StartTime is converted from Suunto's nano seconds to standard

View file

@ -13,6 +13,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include "gettext.h" #include "gettext.h"
#include "divelog.h"
#include "divesite.h" #include "divesite.h"
#include "sample.h" #include "sample.h"
#include "subsurface-float.h" #include "subsurface-float.h"
@ -512,8 +513,8 @@ static int find_dive(struct divecomputer *match)
{ {
int i; int i;
for (i = dive_table.nr - 1; i >= 0; i--) { for (i = divelog.dives->nr - 1; i >= 0; i--) {
struct dive *old = dive_table.dives[i]; struct dive *old = divelog.dives->dives[i];
if (match_one_dive(match, old)) if (match_one_dive(match, old))
return 1; return 1;

View file

@ -4,6 +4,7 @@
#include "ssrf.h" #include "ssrf.h"
#include "divesite.h" #include "divesite.h"
#include "dive.h" #include "dive.h"
#include "divelog.h"
#include "file.h" #include "file.h"
#include "sample.h" #include "sample.h"
#include "strndup.h" #include "strndup.h"
@ -436,10 +437,9 @@ static void parse_dives(int log_version, const unsigned char *buf, unsigned int
free_dive(dive); free_dive(dive);
} }
int try_to_open_liquivision(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites) int try_to_open_liquivision(const char *filename, struct memblock *mem, struct divelog *log)
{ {
UNUSED(filename); UNUSED(filename);
UNUSED(trips);
const unsigned char *buf = mem->buffer; const unsigned char *buf = mem->buffer;
unsigned int buf_size = mem->size; unsigned int buf_size = mem->size;
unsigned int ptr; unsigned int ptr;
@ -461,7 +461,7 @@ int try_to_open_liquivision(const char *filename, struct memblock *mem, struct d
} }
ptr += 4; ptr += 4;
parse_dives(log_version, buf + ptr, buf_size - ptr, table, sites); parse_dives(log_version, buf + ptr, buf_size - ptr, log->dives, log->sites);
return 1; return 1;
} }

View file

@ -15,6 +15,7 @@
#include "gettext.h" #include "gettext.h"
#include "dive.h" #include "dive.h"
#include "divelog.h"
#include "divesite.h" #include "divesite.h"
#include "event.h" #include "event.h"
#include "errorhelper.h" #include "errorhelper.h"
@ -1961,17 +1962,16 @@ const char *get_sha(git_repository *repo, const char *branch)
* If it is a git repository, we return zero for success, * If it is a git repository, we return zero for success,
* or report an error and return 1 if the load failed. * or report an error and return 1 if the load failed.
*/ */
int git_load_dives(struct git_info *info, struct dive_table *table, struct trip_table *trips, int git_load_dives(struct git_info *info, struct divelog *log)
struct dive_site_table *sites, struct device_table *devices, struct filter_preset_table *filter_presets)
{ {
int ret; int ret;
struct git_parser_state state = { 0 }; struct git_parser_state state = { 0 };
state.repo = info->repo; state.repo = info->repo;
state.table = table; state.table = log->dives;
state.trips = trips; state.trips = log->trips;
state.sites = sites; state.sites = log->sites;
state.devices = devices; state.devices = log->devices;
state.filter_presets = filter_presets; state.filter_presets = log->filter_presets;
if (!info->repo) if (!info->repo)
return report_error("Unable to open git repository '%s[%s]'", info->url, info->branch); return report_error("Unable to open git repository '%s[%s]'", info->url, info->branch);

View file

@ -9,6 +9,7 @@
#include "gettext.h" #include "gettext.h"
#include "dive.h" #include "dive.h"
#include "divelist.h" #include "divelist.h"
#include "divelog.h"
#include "extradata.h" #include "extradata.h"
#include "file.h" #include "file.h"
#include "libdivecomputer.h" #include "libdivecomputer.h"
@ -39,10 +40,8 @@ static int ostc_prepare_data(int data_model, dc_family_t dc_fam, device_data_t *
* each file. So it's not necessary to iterate once and again on a parsing * each file. So it's not necessary to iterate once and again on a parsing
* function. Actually there's only one kind of archive for every DC model. * function. Actually there's only one kind of archive for every DC model.
*/ */
void ostctools_import(const char *file, struct dive_table *divetable, struct trip_table *trips, struct dive_site_table *sites) void ostctools_import(const char *file, struct divelog *log)
{ {
UNUSED(trips);
UNUSED(sites);
FILE *archive; FILE *archive;
device_data_t *devdata = calloc(1, sizeof(device_data_t)); device_data_t *devdata = calloc(1, sizeof(device_data_t));
dc_family_t dc_fam; dc_family_t dc_fam;
@ -184,8 +183,8 @@ void ostctools_import(const char *file, struct dive_table *divetable, struct tri
} else { } else {
add_extra_data(&ostcdive->dc, "Serial", ostcdive->dc.serial); add_extra_data(&ostcdive->dc, "Serial", ostcdive->dc.serial);
} }
record_dive_to_table(ostcdive, divetable); record_dive_to_table(ostcdive, log->dives);
sort_dive_table(divetable); sort_dive_table(log->dives);
close_out: close_out:
fclose(archive); fclose(archive);

View file

@ -22,6 +22,7 @@
#include "gettext.h" #include "gettext.h"
#include "dive.h" #include "dive.h"
#include "divelog.h"
#include "divesite.h" #include "divesite.h"
#include "errorhelper.h" #include "errorhelper.h"
#include "parse.h" #include "parse.h"
@ -1750,9 +1751,7 @@ static const char *preprocess_divelog_de(const char *buffer)
return buffer; return buffer;
} }
int parse_xml_buffer(const char *url, const char *buffer, int size, int parse_xml_buffer(const char *url, const char *buffer, int size, struct divelog *log,
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
struct device_table *devices, struct filter_preset_table *filter_presets,
const struct xml_params *params) const struct xml_params *params)
{ {
UNUSED(size); UNUSED(size);
@ -1762,12 +1761,12 @@ int parse_xml_buffer(const char *url, const char *buffer, int size,
struct parser_state state; struct parser_state state;
init_parser_state(&state); init_parser_state(&state);
state.target_table = table; state.target_table = log->dives;
state.trips = trips; state.trips = log->trips;
state.sites = sites; state.sites = log->sites;
state.devices = devices; state.devices = log->devices;
state.fingerprints = &fingerprint_table; // simply use the global table for now state.fingerprints = &fingerprint_table; // simply use the global table for now
state.filter_presets = filter_presets; state.filter_presets = log->filter_presets;
doc = xmlReadMemory(res, strlen(res), url, NULL, XML_PARSE_HUGE | XML_PARSE_RECOVER); doc = xmlReadMemory(res, strlen(res), url, NULL, XML_PARSE_HUGE | XML_PARSE_RECOVER);
if (!doc) if (!doc)
doc = xmlReadMemory(res, strlen(res), url, "latin1", XML_PARSE_HUGE | XML_PARSE_RECOVER); doc = xmlReadMemory(res, strlen(res), url, "latin1", XML_PARSE_HUGE | XML_PARSE_RECOVER);
@ -1809,8 +1808,7 @@ static timestamp_t parse_dlf_timestamp(unsigned char *buffer)
return offset + 946684800; return offset + 946684800;
} }
int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *table, struct trip_table *trips, int parse_dlf_buffer(unsigned char *buffer, size_t size, struct divelog *log)
struct dive_site_table *sites, struct device_table *devices)
{ {
unsigned char *ptr = buffer; unsigned char *ptr = buffer;
unsigned char event; unsigned char event;
@ -1831,10 +1829,10 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *tabl
struct parser_state state; struct parser_state state;
init_parser_state(&state); init_parser_state(&state);
state.target_table = table; state.target_table = log->dives;
state.trips = trips; state.trips = log->trips;
state.sites = sites; state.sites = log->sites;
state.devices = devices; state.devices = log->devices;
// Check for the correct file magic // Check for the correct file magic
if (ptr[0] != 'D' || ptr[1] != 'i' || ptr[2] != 'v' || ptr[3] != 'E') if (ptr[0] != 'D' || ptr[1] != 'i' || ptr[2] != 'v' || ptr[3] != 'E')

View file

@ -18,8 +18,6 @@
#include "device.h" #include "device.h"
#include "gettext.h" #include "gettext.h"
struct dive_table dive_table;
void init_parser_state(struct parser_state *state) void init_parser_state(struct parser_state *state)
{ {
memset(state, 0, sizeof(*state)); memset(state, 0, sizeof(*state));

View file

@ -14,6 +14,7 @@
#include <time.h> #include <time.h>
struct xml_params; struct xml_params;
struct divelog;
typedef union { typedef union {
struct event event; struct event event;
@ -105,10 +106,6 @@ extern "C" {
void init_parser_state(struct parser_state *state); void init_parser_state(struct parser_state *state);
void free_parser_state(struct parser_state *state); void free_parser_state(struct parser_state *state);
/* the dive table holds the overall dive list; target table points at
* the table we are currently filling */
extern struct dive_table dive_table;
int trimspace(char *buffer); int trimspace(char *buffer);
void start_match(const char *type, const char *name, char *buffer); void start_match(const char *type, const char *name, char *buffer);
void nonmatch(const char *type, const char *name, char *buffer); void nonmatch(const char *type, const char *name, char *buffer);
@ -156,25 +153,16 @@ void add_dive_site(char *ds_name, struct dive *dive, struct parser_state *state)
int atoi_n(char *ptr, unsigned int len); int atoi_n(char *ptr, unsigned int len);
void parse_xml_init(void); void parse_xml_init(void);
int parse_xml_buffer(const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, int parse_xml_buffer(const char *url, const char *buf, int size, struct divelog *log, const struct xml_params *params);
struct device_table *devices, struct filter_preset_table *filter_presets, const struct xml_params *params);
void parse_xml_exit(void); void parse_xml_exit(void);
int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct divelog *log);
struct dive_site_table *sites, struct device_table *devices); int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct divelog *log);
int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, int parse_seac_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct divelog *log);
struct dive_site_table *sites, struct device_table *devices); int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct divelog *log);
int parse_seac_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, int parse_shearwater_cloud_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct divelog *log);
struct dive_site_table *sites, struct device_table *devices); int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct divelog *log);
int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, int parse_divinglog_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct divelog *log);
struct dive_site_table *sites, struct device_table *devices); int parse_dlf_buffer(unsigned char *buffer, size_t size, struct divelog *log);
int parse_shearwater_cloud_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, struct device_table *devices);
int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, struct device_table *devices);
int parse_divinglog_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, struct device_table *devices);
int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, struct device_table *devices);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -2,6 +2,7 @@
#include "qthelper.h" #include "qthelper.h"
#include "dive.h" #include "dive.h"
#include "divelist.h" #include "divelist.h"
#include "divelog.h"
#include "core/settings/qPrefLanguage.h" #include "core/settings/qPrefLanguage.h"
#include "core/settings/qPrefUpdateManager.h" #include "core/settings/qPrefUpdateManager.h"
#include "core/subsurface-qt/divelistnotifier.h" #include "core/subsurface-qt/divelistnotifier.h"
@ -1025,12 +1026,14 @@ static QString get_dive_only_date_string(timestamp_t when)
QString get_first_dive_date_string() QString get_first_dive_date_string()
{ {
return dive_table.nr > 0 ? get_dive_only_date_string(dive_table.dives[0]->when) : gettextFromC::tr("no dives"); const dive_table *dives = divelog.dives;
return dives->nr > 0 ? get_dive_only_date_string(dives->dives[0]->when) : gettextFromC::tr("no dives");
} }
QString get_last_dive_date_string() QString get_last_dive_date_string()
{ {
return dive_table.nr > 0 ? get_dive_only_date_string(dive_table.dives[dive_table.nr - 1]->when) : gettextFromC::tr("no dives"); const dive_table *dives = divelog.dives;
return dives->nr > 0 ? get_dive_only_date_string(dives->dives[dives->nr - 1]->when) : gettextFromC::tr("no dives");
} }
extern "C" char *get_current_date() extern "C" char *get_current_date()

View file

@ -17,6 +17,7 @@
#include <git2.h> #include <git2.h>
#include "dive.h" #include "dive.h"
#include "divelog.h"
#include "divesite.h" #include "divesite.h"
#include "filterconstraint.h" #include "filterconstraint.h"
#include "filterpreset.h" #include "filterpreset.h"
@ -883,8 +884,8 @@ static void save_settings(git_repository *repo, struct dir *tree)
struct membuffer b = { 0 }; struct membuffer b = { 0 };
put_format(&b, "version %d\n", DATAFORMAT_VERSION); put_format(&b, "version %d\n", DATAFORMAT_VERSION);
for (int i = 0; i < nr_devices(&device_table); i++) for (int i = 0; i < nr_devices(divelog.devices); i++)
save_one_device(&b, get_device(&device_table, i)); save_one_device(&b, get_device(divelog.devices, i));
/* save the fingerprint data */ /* save the fingerprint data */
for (unsigned int i = 0; i < nr_fingerprints(&fingerprint_table); i++) for (unsigned int i = 0; i < nr_fingerprints(&fingerprint_table); i++)
save_one_fingerprint(&b, i); save_one_fingerprint(&b, i);
@ -913,10 +914,10 @@ static void save_divesites(git_repository *repo, struct dir *tree)
subdir = new_directory(repo, tree, &dirname); subdir = new_directory(repo, tree, &dirname);
free_buffer(&dirname); free_buffer(&dirname);
purge_empty_dive_sites(&dive_site_table); purge_empty_dive_sites(divelog.sites);
for (int i = 0; i < dive_site_table.nr; i++) { for (int i = 0; i < divelog.sites->nr; i++) {
struct membuffer b = { 0 }; struct membuffer b = { 0 };
struct dive_site *ds = get_dive_site(i, &dive_site_table); struct dive_site *ds = get_dive_site(i, divelog.sites);
struct membuffer site_file_name = { 0 }; struct membuffer site_file_name = { 0 };
put_format(&site_file_name, "Site-%08x", ds->uuid); put_format(&site_file_name, "Site-%08x", ds->uuid);
show_utf8(&b, "name ", ds->name, "\n"); show_utf8(&b, "name ", ds->name, "\n");
@ -1029,8 +1030,8 @@ static int create_git_tree(git_repository *repo, struct dir *root, bool select_o
save_divesites(repo, root); save_divesites(repo, root);
save_filter_presets(repo, root); save_filter_presets(repo, root);
for (i = 0; i < trip_table.nr; ++i) for (i = 0; i < divelog.trips->nr; ++i)
trip_table.trips[i]->saved = 0; divelog.trips->trips[i]->saved = 0;
/* save the dives */ /* save the dives */
git_storage_update_progress(translate("gettextFromC", "Start saving dives")); git_storage_update_progress(translate("gettextFromC", "Start saving dives"));
@ -1140,7 +1141,7 @@ int get_authorship(git_repository *repo, git_signature **authorp)
static void create_commit_message(struct membuffer *msg, bool create_empty) static void create_commit_message(struct membuffer *msg, bool create_empty)
{ {
int nr = dive_table.nr; int nr = divelog.dives->nr;
struct dive *dive = get_dive(nr-1); struct dive *dive = get_dive(nr-1);
char* changes_made = get_changes_made(); char* changes_made = get_changes_made();

View file

@ -6,6 +6,7 @@
#include "save-html.h" #include "save-html.h"
#include "dive.h" #include "dive.h"
#include "divelog.h"
#include "qthelper.h" #include "qthelper.h"
#include "gettext.h" #include "gettext.h"
#include "divesite.h" #include "divesite.h"
@ -452,8 +453,8 @@ static void write_trips(struct membuffer *b, const char *photos_dir, bool select
char sep_ = ' '; char sep_ = ' ';
char *sep = &sep_; char *sep = &sep_;
for (i = 0; i < trip_table.nr; ++i) for (i = 0; i < divelog.trips->nr; ++i)
trip_table.trips[i]->saved = 0; divelog.trips->trips[i]->saved = 0;
for_each_dive (i, dive) { for_each_dive (i, dive) {
trip = dive->divetrip; trip = dive->divetrip;

View file

@ -13,6 +13,7 @@
#include <fcntl.h> #include <fcntl.h>
#include "dive.h" #include "dive.h"
#include "divelog.h"
#include "divesite.h" #include "divesite.h"
#include "errorhelper.h" #include "errorhelper.h"
#include "extradata.h" #include "extradata.h"
@ -682,8 +683,8 @@ static void save_dives_buffer(struct membuffer *b, bool select_only, bool anonym
put_format(b, "<divelog program='subsurface' version='%d'>\n<settings>\n", DATAFORMAT_VERSION); put_format(b, "<divelog program='subsurface' version='%d'>\n<settings>\n", DATAFORMAT_VERSION);
/* save the dive computer nicknames, if any */ /* save the dive computer nicknames, if any */
for (int i = 0; i < nr_devices(&device_table); i++) { for (int i = 0; i < nr_devices(divelog.devices); i++) {
const struct device *d = get_device(&device_table, i); const struct device *d = get_device(divelog.devices, i);
if (!select_only || device_used_by_selected_dive(d)) if (!select_only || device_used_by_selected_dive(d))
save_one_device(b, d); save_one_device(b, d);
} }
@ -697,8 +698,8 @@ static void save_dives_buffer(struct membuffer *b, bool select_only, bool anonym
/* save the dive sites */ /* save the dive sites */
put_format(b, "<divesites>\n"); put_format(b, "<divesites>\n");
for (i = 0; i < dive_site_table.nr; i++) { for (i = 0; i < divelog.sites->nr; i++) {
struct dive_site *ds = get_dive_site(i, &dive_site_table); struct dive_site *ds = get_dive_site(i, divelog.sites);
/* Don't export empty dive sites */ /* Don't export empty dive sites */
if (dive_site_is_empty(ds)) if (dive_site_is_empty(ds))
continue; continue;
@ -726,8 +727,8 @@ static void save_dives_buffer(struct membuffer *b, bool select_only, bool anonym
put_format(b, "</site>\n"); put_format(b, "</site>\n");
} }
put_format(b, "</divesites>\n<dives>\n"); put_format(b, "</divesites>\n<dives>\n");
for (i = 0; i < trip_table.nr; ++i) for (i = 0; i < divelog.trips->nr; ++i)
trip_table.trips[i]->saved = 0; divelog.trips->trips[i]->saved = 0;
/* save the filter presets */ /* save the filter presets */
save_filter_presets(b); save_filter_presets(b);

View file

@ -3,6 +3,7 @@
#include "selection.h" #include "selection.h"
#include "divelist.h" #include "divelist.h"
#include "divelog.h"
#include "trip.h" #include "trip.h"
#include "subsurface-qt/divelistnotifier.h" #include "subsurface-qt/divelistnotifier.h"
@ -40,7 +41,7 @@ extern "C" void deselect_dive(struct dive *dive)
} }
} }
selected_dive = idx; selected_dive = idx;
while (++selected_dive < dive_table.nr) { while (++selected_dive < divelog.dives->nr) {
dive = get_dive(selected_dive); dive = get_dive(selected_dive);
if (dive && dive->selected) { if (dive && dive->selected) {
current_dive = dive; current_dive = dive;
@ -163,8 +164,8 @@ void setSelection(const std::vector<dive *> &selection, dive *currentDive)
// Since we select only dives, there are no selected trips! // Since we select only dives, there are no selected trips!
amount_trips_selected = 0; amount_trips_selected = 0;
for (int i = 0; i < trip_table.nr; ++i) for (int i = 0; i < divelog.trips->nr; ++i)
trip_table.trips[i]->selected = false; divelog.trips->trips[i]->selected = false;
// TODO: We might want to keep track of selected dives in a more efficient way! // TODO: We might want to keep track of selected dives in a more efficient way!
int i; int i;
@ -233,8 +234,8 @@ std::vector<dive *> getDiveSelection()
// Select the first dive that is visible // Select the first dive that is visible
extern "C" void select_newest_visible_dive() extern "C" void select_newest_visible_dive()
{ {
for (int i = dive_table.nr - 1; i >= 0; --i) { for (int i = divelog.dives->nr - 1; i >= 0; --i) {
dive *d = dive_table.dives[i]; dive *d = divelog.dives->dives[i];
if (!d->hidden_by_filter) if (!d->hidden_by_filter)
return select_single_dive(d); return select_single_dive(d);
} }
@ -263,9 +264,9 @@ extern "C" struct dive_trip *single_selected_trip()
{ {
if (amount_trips_selected != 1) if (amount_trips_selected != 1)
return NULL; return NULL;
for (int i = 0; i < trip_table.nr; ++i) { for (int i = 0; i < divelog.trips->nr; ++i) {
if (trip_table.trips[i]->selected) if (divelog.trips->trips[i]->selected)
return trip_table.trips[i]; return divelog.trips->trips[i];
} }
fprintf(stderr, "warning: found no selected trip even though one should be selected\n"); fprintf(stderr, "warning: found no selected trip even though one should be selected\n");
return NULL; // shouldn't happen return NULL; // shouldn't happen
@ -280,6 +281,6 @@ extern "C" void clear_selection(void)
struct dive *dive; struct dive *dive;
for_each_dive (i, dive) for_each_dive (i, dive)
dive->selected = false; dive->selected = false;
for (int i = 0; i < trip_table.nr; ++i) for (int i = 0; i < divelog.trips->nr; ++i)
trip_table.trips[i]->selected = false; divelog.trips->trips[i]->selected = false;
} }

View file

@ -8,6 +8,7 @@
#include "statistics.h" #include "statistics.h"
#include "dive.h" #include "dive.h"
#include "divelog.h"
#include "event.h" #include "event.h"
#include "gettext.h" #include "gettext.h"
#include "sample.h" #include "sample.h"
@ -105,17 +106,17 @@ void calculate_stats_summary(struct stats_summary *out, bool selected_only)
size_t size, tsize, dsize, tmsize; size_t size, tsize, dsize, tmsize;
stats_t stats = { 0 }; stats_t stats = { 0 };
if (dive_table.nr > 0) { if (divelog.dives->nr > 0) {
stats.shortest_time.seconds = dive_table.dives[0]->duration.seconds; stats.shortest_time.seconds = divelog.dives->dives[0]->duration.seconds;
stats.min_depth.mm = dive_table.dives[0]->maxdepth.mm; stats.min_depth.mm = divelog.dives->dives[0]->maxdepth.mm;
stats.selection_size = dive_table.nr; stats.selection_size = divelog.dives->nr;
} }
/* allocate sufficient space to hold the worst /* allocate sufficient space to hold the worst
* case (one dive per year or all dives during * case (one dive per year or all dives during
* one month) for yearly and monthly statistics*/ * one month) for yearly and monthly statistics*/
size = sizeof(stats_t) * (dive_table.nr + 1); size = sizeof(stats_t) * (divelog.dives->nr + 1);
tsize = sizeof(stats_t) * (NUM_DIVEMODE + 1); tsize = sizeof(stats_t) * (NUM_DIVEMODE + 1);
dsize = sizeof(stats_t) * ((STATS_MAX_DEPTH / STATS_DEPTH_BUCKET) + 1); dsize = sizeof(stats_t) * ((STATS_MAX_DEPTH / STATS_DEPTH_BUCKET) + 1);
tmsize = sizeof(stats_t) * ((STATS_MAX_TEMP / STATS_TEMP_BUCKET) + 1); tmsize = sizeof(stats_t) * ((STATS_MAX_TEMP / STATS_TEMP_BUCKET) + 1);

View file

@ -2,14 +2,13 @@
#include "trip.h" #include "trip.h"
#include "dive.h" #include "dive.h"
#include "divelog.h"
#include "subsurface-time.h" #include "subsurface-time.h"
#include "subsurface-string.h" #include "subsurface-string.h"
#include "selection.h" #include "selection.h"
#include "table.h" #include "table.h"
#include "core/qthelper.h" #include "core/qthelper.h"
struct trip_table trip_table;
#ifdef DEBUG_TRIP #ifdef DEBUG_TRIP
void dump_trip_list(void) void dump_trip_list(void)
{ {
@ -17,9 +16,9 @@ void dump_trip_list(void)
int i = 0; int i = 0;
timestamp_t last_time = 0; timestamp_t last_time = 0;
for (i = 0; i < trip_table.nr; ++i) { for (i = 0; i < divelog.trips->nr; ++i) {
struct tm tm; struct tm tm;
trip = trip_table.trips[i]; trip = divelog.trips->trips[i];
utc_mkdate(trip_date(trip), &tm); utc_mkdate(trip_date(trip), &tm);
if (trip_date(trip) < last_time) if (trip_date(trip) < last_time)
printf("\n\ntrip_table OUT OF ORDER!!!\n\n\n"); printf("\n\ntrip_table OUT OF ORDER!!!\n\n\n");
@ -203,9 +202,9 @@ dive_trip_t *get_trip_for_new_dive(struct dive *new_dive, bool *allocated)
/* lookup of trip in main trip_table based on its id */ /* lookup of trip in main trip_table based on its id */
dive_trip_t *get_trip_by_uniq_id(int tripId) dive_trip_t *get_trip_by_uniq_id(int tripId)
{ {
for (int i = 0; i < trip_table.nr; i++) { for (int i = 0; i < divelog.trips->nr; i++) {
if (trip_table.trips[i]->id == tripId) if (divelog.trips->trips[i]->id == tripId)
return trip_table.trips[i]; return divelog.trips->trips[i];
} }
return NULL; return NULL;
} }

View file

@ -63,7 +63,6 @@ void clear_trip_table(struct trip_table *table);
extern void dump_trip_list(void); extern void dump_trip_list(void);
#endif #endif
extern struct trip_table trip_table;
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -25,6 +25,7 @@
#include "libdivecomputer.h" #include "libdivecomputer.h"
#include "uemis.h" #include "uemis.h"
#include "divelist.h" #include "divelist.h"
#include "divelog.h"
#include "divesite.h" #include "divesite.h"
#include "errorhelper.h" #include "errorhelper.h"
#include "file.h" #include "file.h"
@ -1051,7 +1052,7 @@ static char *uemis_get_divenr(char *deviceidstr, struct dive_table *table, int f
* Otherwise, use the global dive table. * Otherwise, use the global dive table.
*/ */
if (!force && !table->nr) if (!force && !table->nr)
table = &dive_table; table = divelog.dives;
for (i = 0; i < table->nr; i++) { for (i = 0; i < table->nr; i++) {
struct dive *d = table->dives[i]; struct dive *d = table->dives[i];

View file

@ -14,6 +14,7 @@
#include "core/filterpreset.h" #include "core/filterpreset.h"
#include "core/qthelper.h" #include "core/qthelper.h"
#include "core/divesite.h" #include "core/divesite.h"
#include "core/divelog.h"
#include "core/device.h" #include "core/device.h"
#include "core/trip.h" #include "core/trip.h"
#include "core/import-csv.h" #include "core/import-csv.h"
@ -879,19 +880,15 @@ void DiveLogImportDialog::parseTxtHeader(QString fileName, xml_params &params)
void DiveLogImportDialog::on_buttonBox_accepted() void DiveLogImportDialog::on_buttonBox_accepted()
{ {
struct dive_table table = empty_dive_table; struct divelog log;
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;
QStringList r = resultModel->result(); QStringList r = resultModel->result();
if (ui->knownImports->currentText() != "Manual import") { if (ui->knownImports->currentText() != "Manual import") {
for (int i = 0; i < fileNames.size(); ++i) { for (int i = 0; i < fileNames.size(); ++i) {
if (ui->knownImports->currentText() == "Seabear CSV") { if (ui->knownImports->currentText() == "Seabear CSV") {
parse_seabear_log(qPrintable(fileNames[i]), &table, &trips, &sites, &devices, &filter_presets); parse_seabear_log(qPrintable(fileNames[i]), &log);
} else if (ui->knownImports->currentText() == "Poseidon MkVI") { } else if (ui->knownImports->currentText() == "Poseidon MkVI") {
QPair<QString, QString> pair = poseidonFileNames(fileNames[i]); QPair<QString, QString> pair = poseidonFileNames(fileNames[i]);
parse_txt_file(qPrintable(pair.second), qPrintable(pair.first), &table, &trips, &sites, &devices); parse_txt_file(qPrintable(pair.second), qPrintable(pair.first), &log);
} else { } else {
xml_params params; xml_params params;
@ -908,7 +905,7 @@ void DiveLogImportDialog::on_buttonBox_accepted()
setup_csv_params(r, params); setup_csv_params(r, params);
parse_csv_file(qPrintable(fileNames[i]), &params, parse_csv_file(qPrintable(fileNames[i]), &params,
specialCSV.contains(ui->knownImports->currentIndex()) ? qPrintable(CSVApps[ui->knownImports->currentIndex()].name) : "csv", specialCSV.contains(ui->knownImports->currentIndex()) ? qPrintable(CSVApps[ui->knownImports->currentIndex()].name) : "csv",
&table, &trips, &sites, &devices, &filter_presets); &log);
} }
} }
} else { } else {
@ -944,7 +941,7 @@ void DiveLogImportDialog::on_buttonBox_accepted()
xml_params_add_int(&params, "visibilityField", r.indexOf(tr("Visibility"))); xml_params_add_int(&params, "visibilityField", r.indexOf(tr("Visibility")));
xml_params_add_int(&params, "ratingField", r.indexOf(tr("Rating"))); xml_params_add_int(&params, "ratingField", r.indexOf(tr("Rating")));
parse_manual_file(qPrintable(fileNames[i]), &params, &table, &trips, &sites, &devices, &filter_presets); parse_manual_file(qPrintable(fileNames[i]), &params, &log);
} else { } else {
xml_params params; xml_params params;
@ -962,13 +959,13 @@ void DiveLogImportDialog::on_buttonBox_accepted()
setup_csv_params(r, params); setup_csv_params(r, params);
parse_csv_file(qPrintable(fileNames[i]), &params, parse_csv_file(qPrintable(fileNames[i]), &params,
specialCSV.contains(ui->knownImports->currentIndex()) ? qPrintable(CSVApps[ui->knownImports->currentIndex()].name) : "csv", specialCSV.contains(ui->knownImports->currentIndex()) ? qPrintable(CSVApps[ui->knownImports->currentIndex()].name) : "csv",
&table, &trips, &sites, &devices, &filter_presets); &log);
} }
} }
} }
QString source = fileNames.size() == 1 ? fileNames[0] : tr("multiple files"); QString source = fileNames.size() == 1 ? fileNames[0] : tr("multiple files");
Command::importDives(&table, &trips, &sites, &devices, nullptr, IMPORT_MERGE_ALL_TRIPS, source); Command::importDives(log.dives, log.trips, log.sites, log.devices, nullptr, IMPORT_MERGE_ALL_TRIPS, source);
} }
TagDragDelegate::TagDragDelegate(QObject *parent) : QStyledItemDelegate(parent) TagDragDelegate::TagDragDelegate(QObject *parent) : QStyledItemDelegate(parent)

View file

@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include "divesitelistview.h" #include "divesitelistview.h"
#include "core/subsurface-qt/divelistnotifier.h" #include "core/subsurface-qt/divelistnotifier.h"
#include "core/divelog.h"
#include "core/divesite.h" #include "core/divesite.h"
#include "core/divefilter.h" #include "core/divefilter.h"
#include "qt-models/divelocationmodel.h" #include "qt-models/divelocationmodel.h"
@ -96,7 +97,7 @@ void DiveSiteListView::diveSiteAdded(struct dive_site *, int idx)
void DiveSiteListView::diveSiteChanged(struct dive_site *ds, int field) void DiveSiteListView::diveSiteChanged(struct dive_site *ds, int field)
{ {
int idx = get_divesite_idx(ds, &dive_site_table); int idx = get_divesite_idx(ds, divelog.sites);
if (idx < 0) if (idx < 0)
return; return;
QModelIndex globalIdx = LocationInformationModel::instance()->index(idx, field); QModelIndex globalIdx = LocationInformationModel::instance()->index(idx, field);

View file

@ -3,6 +3,7 @@
#include "commands/command.h" #include "commands/command.h"
#include "core/qthelper.h" #include "core/qthelper.h"
#include "core/divelist.h" #include "core/divelist.h"
#include "core/divelog.h"
#include "core/settings/qPrefDiveComputer.h" #include "core/settings/qPrefDiveComputer.h"
#include "core/subsurface-float.h" #include "core/subsurface-float.h"
#include "core/subsurface-string.h" #include "core/subsurface-string.h"
@ -423,7 +424,7 @@ void DownloadFromDCWidget::on_downloadCancelRetryButton_clicked()
qPrefDiveComputer::set_device(data->devName()); qPrefDiveComputer::set_device(data->devName());
// before we start, remember where the dive_table ended // before we start, remember where the dive_table ended
previousLast = dive_table.nr; previousLast = divelog.dives->nr;
diveImportedModel->startDownload(); diveImportedModel->startDownload();
// FIXME: We should get the _actual_ device info instead of whatever // FIXME: We should get the _actual_ device info instead of whatever

View file

@ -8,6 +8,7 @@
#include "desktop-widgets/mapwidget.h" #include "desktop-widgets/mapwidget.h"
#include "core/color.h" #include "core/color.h"
#include "core/divefilter.h" #include "core/divefilter.h"
#include "core/divelog.h"
#include "core/divesite.h" #include "core/divesite.h"
#include "core/divesitehelpers.h" #include "core/divesitehelpers.h"
#include "desktop-widgets/modeldelegates.h" #include "desktop-widgets/modeldelegates.h"
@ -367,8 +368,8 @@ bool DiveLocationFilterProxyModel::lessThan(const QModelIndex &source_left, cons
// If there is a current location, sort by that - otherwise use the provided column // If there is a current location, sort by that - otherwise use the provided column
if (has_location(&currentLocation)) { if (has_location(&currentLocation)) {
// The dive sites are -2 because of the first two items. // The dive sites are -2 because of the first two items.
struct dive_site *ds1 = get_dive_site(source_left.row() - 2, &dive_site_table); struct dive_site *ds1 = get_dive_site(source_left.row() - 2, divelog.sites);
struct dive_site *ds2 = get_dive_site(source_right.row() - 2, &dive_site_table); struct dive_site *ds2 = get_dive_site(source_right.row() - 2, divelog.sites);
return get_distance(&ds1->location, &currentLocation) < get_distance(&ds2->location, &currentLocation); return get_distance(&ds1->location, &currentLocation) < get_distance(&ds2->location, &currentLocation);
} }
return source_left.data().toString().compare(source_right.data().toString(), Qt::CaseInsensitive) < 0; return source_left.data().toString().compare(source_right.data().toString(), Qt::CaseInsensitive) < 0;
@ -407,7 +408,7 @@ QVariant DiveLocationModel::data(const QModelIndex &index, int role) const
} }
// The dive sites are -2 because of the first two items. // The dive sites are -2 because of the first two items.
struct dive_site *ds = get_dive_site(index.row() - 2, &dive_site_table); struct dive_site *ds = get_dive_site(index.row() - 2, divelog.sites);
return LocationInformationModel::getDiveSiteData(ds, index.column(), role); return LocationInformationModel::getDiveSiteData(ds, index.column(), role);
} }
@ -418,7 +419,7 @@ int DiveLocationModel::columnCount(const QModelIndex&) const
int DiveLocationModel::rowCount(const QModelIndex&) const int DiveLocationModel::rowCount(const QModelIndex&) const
{ {
return dive_site_table.nr + 2; return divelog.sites->nr + 2;
} }
Qt::ItemFlags DiveLocationModel::flags(const QModelIndex &index) const Qt::ItemFlags DiveLocationModel::flags(const QModelIndex &index) const
@ -541,12 +542,11 @@ static struct dive_site *get_dive_site_name_start_which_str(const QString &str)
{ {
struct dive_site *ds; struct dive_site *ds;
int i; int i;
for_each_dive_site (i, ds, &dive_site_table) { for_each_dive_site (i, ds, divelog.sites) {
QString dsName(ds->name); QString dsName(ds->name);
if (dsName.toLower().startsWith(str.toLower())) { if (dsName.toLower().startsWith(str.toLower()))
return ds; return ds;
} }
}
return NULL; return NULL;
} }

View file

@ -19,6 +19,7 @@
#include "core/color.h" #include "core/color.h"
#include "core/device.h" #include "core/device.h"
#include "core/divelog.h"
#include "core/divesitehelpers.h" #include "core/divesitehelpers.h"
#include "core/errorhelper.h" #include "core/errorhelper.h"
#include "core/file.h" #include "core/file.h"
@ -413,7 +414,7 @@ void MainWindow::on_actionCloudstorageopen_triggered()
showProgressBar(); showProgressBar();
QByteArray fileNamePtr = QFile::encodeName(filename); QByteArray fileNamePtr = QFile::encodeName(filename);
if (!parse_file(fileNamePtr.data(), &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table)) if (!parse_file(fileNamePtr.data(), &divelog))
setCurrentFile(fileNamePtr.data()); setCurrentFile(fileNamePtr.data());
process_loaded_dives(); process_loaded_dives();
hideProgressBar(); hideProgressBar();
@ -423,7 +424,7 @@ void MainWindow::on_actionCloudstorageopen_triggered()
// Return whether saving to cloud is OK. If it isn't, show an error return false. // Return whether saving to cloud is OK. If it isn't, show an error return false.
static bool saveToCloudOK() static bool saveToCloudOK()
{ {
if (!dive_table.nr) { if (divelog.dives->nr) {
report_error(qPrintable(gettextFromC::tr("Don't save an empty log to the cloud"))); report_error(qPrintable(gettextFromC::tr("Don't save an empty log to the cloud")));
return false; return false;
} }
@ -1276,18 +1277,14 @@ void MainWindow::importFiles(const QStringList fileNames)
return; return;
QByteArray fileNamePtr; QByteArray fileNamePtr;
struct dive_table table = empty_dive_table; struct divelog log;
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;
for (int i = 0; i < fileNames.size(); ++i) { for (int i = 0; i < fileNames.size(); ++i) {
fileNamePtr = QFile::encodeName(fileNames.at(i)); fileNamePtr = QFile::encodeName(fileNames.at(i));
parse_file(fileNamePtr.data(), &table, &trips, &sites, &devices, &filter_presets); parse_file(fileNamePtr.data(), &log);
} }
QString source = fileNames.size() == 1 ? fileNames[0] : tr("multiple files"); QString source = fileNames.size() == 1 ? fileNames[0] : tr("multiple files");
Command::importDives(&table, &trips, &sites, &devices, &filter_presets, IMPORT_MERGE_ALL_TRIPS, source); Command::importDives(log.dives, log.trips, log.sites, log.devices, log.filter_presets, IMPORT_MERGE_ALL_TRIPS, source);
} }
void MainWindow::loadFiles(const QStringList fileNames) void MainWindow::loadFiles(const QStringList fileNames)
@ -1301,7 +1298,7 @@ void MainWindow::loadFiles(const QStringList fileNames)
showProgressBar(); showProgressBar();
for (int i = 0; i < fileNames.size(); ++i) { for (int i = 0; i < fileNames.size(); ++i) {
fileNamePtr = QFile::encodeName(fileNames.at(i)); fileNamePtr = QFile::encodeName(fileNames.at(i));
if (!parse_file(fileNamePtr.data(), &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table)) { if (!parse_file(fileNamePtr.data(), &divelog)) {
setCurrentFile(fileNamePtr.data()); setCurrentFile(fileNamePtr.data());
addRecentFile(fileNamePtr, false); addRecentFile(fileNamePtr, false);
} }
@ -1372,28 +1369,19 @@ void MainWindow::on_actionImportDiveSites_triggered()
return; return;
updateLastUsedDir(QFileInfo(fileNames[0]).dir().path()); updateLastUsedDir(QFileInfo(fileNames[0]).dir().path());
struct dive_table table = empty_dive_table; struct divelog log;
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;
for (const QString &s: fileNames) { for (const QString &s: fileNames) {
QByteArray fileNamePtr = QFile::encodeName(s); QByteArray fileNamePtr = QFile::encodeName(s);
parse_file(fileNamePtr.data(), &table, &trips, &sites, &devices, &filter_presets); parse_file(fileNamePtr.data(), &log);
} }
// The imported dive sites still have pointers to imported dives - remove them // The imported dive sites still have pointers to imported dives - remove them
for (int i = 0; i < sites.nr; ++i) for (int i = 0; i < log.sites->nr; ++i)
sites.dive_sites[i]->dives.nr = 0; log.sites->dive_sites[i]->dives.nr = 0;
// Now we can clear the imported dives and trips.
clear_dive_table(&table);
clear_trip_table(&trips);
QString source = fileNames.size() == 1 ? fileNames[0] : tr("multiple files"); QString source = fileNames.size() == 1 ? fileNames[0] : tr("multiple files");
// sites table will be cleared by DivesiteImportDialog constructor DivesiteImportDialog divesiteImport(*log.sites, source, this);
DivesiteImportDialog divesiteImport(sites, source, this);
divesiteImport.exec(); divesiteImport.exec();
} }

View file

@ -7,8 +7,8 @@
#include "desktop-widgets/mainwindow.h" #include "desktop-widgets/mainwindow.h"
#include "commands/command.h" #include "commands/command.h"
#include "core/device.h" #include "core/device.h"
#include "core/divesite.h" #include "core/divelist.h" // For IMPORT_MERGE_ALL_TRIPS
#include "core/trip.h" #include "core/divelog.h"
#include "core/errorhelper.h" #include "core/errorhelper.h"
#include "core/file.h" #include "core/file.h"
#include "desktop-widgets/mapwidget.h" #include "desktop-widgets/mapwidget.h"
@ -463,13 +463,9 @@ void DivelogsDeWebServices::buttonClicked(QAbstractButton *button)
break; break;
} }
/* parse file and import dives */ /* parse file and import dives */
struct dive_table table = empty_dive_table; struct divelog log;
struct trip_table trips = empty_trip_table; parse_file(QFile::encodeName(zipFile.fileName()), &log);
struct dive_site_table sites = empty_dive_site_table; Command::importDives(log.dives, log.trips, log.sites, log.devices, nullptr, IMPORT_MERGE_ALL_TRIPS, QStringLiteral("divelogs.de"));
struct device_table devices;
struct filter_preset_table filter_presets;
parse_file(QFile::encodeName(zipFile.fileName()), &table, &trips, &sites, &devices, &filter_presets);
Command::importDives(&table, &trips, &sites, &devices, nullptr, IMPORT_MERGE_ALL_TRIPS, QStringLiteral("divelogs.de"));
/* store last entered user/pass in config */ /* store last entered user/pass in config */
qPrefCloudStorage::set_divelogde_user(ui.userID->text()); qPrefCloudStorage::set_divelogde_user(ui.userID->text());

View file

@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include "tripselectiondialog.h" #include "tripselectiondialog.h"
#include "core/divelog.h"
#include "core/string-format.h" #include "core/string-format.h"
#include "core/trip.h" #include "core/trip.h"
#include <QShortcut> #include <QShortcut>
@ -17,9 +18,9 @@ TripSelectionDialog::TripSelectionDialog(QWidget *parent) : QDialog(parent)
// We could use a model, but it seems barely worth the hassle. // We could use a model, but it seems barely worth the hassle.
QStringList list; QStringList list;
list.reserve(trip_table.nr); list.reserve(divelog.trips->nr);
for (int i = 0; i < trip_table.nr; ++i) for (int i = 0; i < divelog.trips->nr; ++i)
list.push_back(formatTripTitleWithDives(trip_table.trips[i])); list.push_back(formatTripTitleWithDives(divelog.trips->trips[i]));
ui.trips->addItems(list); ui.trips->addItems(list);
} }
@ -36,9 +37,9 @@ dive_trip *TripSelectionDialog::selectedTrip() const
if (rows.size() != 1) if (rows.size() != 1)
return nullptr; return nullptr;
int idx = rows[0].row(); int idx = rows[0].row();
if (idx < 0 || idx >= trip_table.nr) if (idx < 0 || idx >= divelog.trips->nr)
return nullptr; return nullptr;
return trip_table.trips[idx]; return divelog.trips->trips[idx];
} }
dive_trip *TripSelectionDialog::getTrip() dive_trip *TripSelectionDialog::getTrip()

View file

@ -10,6 +10,7 @@
#include "core/qthelper.h" #include "core/qthelper.h"
#include "core/file.h" #include "core/file.h"
#include "core/device.h" #include "core/device.h"
#include "core/divelog.h"
#include "core/divesite.h" #include "core/divesite.h"
#include "core/trip.h" #include "core/trip.h"
#include "core/save-html.h" #include "core/save-html.h"
@ -45,7 +46,7 @@ int main(int argc, char **argv)
qDebug() << "need --source and --output"; qDebug() << "need --source and --output";
exit(1); exit(1);
} }
int ret = parse_file(qPrintable(source), &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table); int ret = parse_file(qPrintable(source), &divelog);
if (ret) { if (ret) {
fprintf(stderr, "parse_file returned %d\n", ret); fprintf(stderr, "parse_file returned %d\n", ret);
exit(1); exit(1);

View file

@ -28,6 +28,7 @@
#include "core/errorhelper.h" #include "core/errorhelper.h"
#include "core/file.h" #include "core/file.h"
#include "core/divefilter.h" #include "core/divefilter.h"
#include "core/divelog.h"
#include "core/filterconstraint.h" #include "core/filterconstraint.h"
#include "core/qthelper.h" #include "core/qthelper.h"
#include "core/qt-gui.h" #include "core/qt-gui.h"
@ -377,7 +378,7 @@ void QMLManager::openLocalThenRemote(QString url)
* we try to open this), parse_file (which is called by openAndMaybeSync) will ALWAYS connect * we try to open this), parse_file (which is called by openAndMaybeSync) will ALWAYS connect
* to the remote and populate the cache. * to the remote and populate the cache.
* Otherwise parse_file will respect the git_local_only flag and only update if that isn't set */ * Otherwise parse_file will respect the git_local_only flag and only update if that isn't set */
int error = parse_file(encodedFilename.constData(), &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table); int error = parse_file(encodedFilename.constData(), &divelog);
if (error) { if (error) {
/* there can be 2 reasons for this: /* there can be 2 reasons for this:
* 1) we have cloud credentials, but there is no local repo (yet). * 1) we have cloud credentials, but there is no local repo (yet).
@ -409,9 +410,9 @@ void QMLManager::openLocalThenRemote(QString url)
qPrefTechnicalDetails::set_show_ccr_sensors(git_prefs.show_ccr_sensors); qPrefTechnicalDetails::set_show_ccr_sensors(git_prefs.show_ccr_sensors);
qPrefPartialPressureGas::set_po2(git_prefs.pp_graphs.po2); qPrefPartialPressureGas::set_po2(git_prefs.pp_graphs.po2);
// the following steps can take a long time, so provide updates // the following steps can take a long time, so provide updates
setNotificationText(tr("Processing %1 dives").arg(dive_table.nr)); setNotificationText(tr("Processing %1 dives").arg(divelog.dives->nr));
process_loaded_dives(); process_loaded_dives();
setNotificationText(tr("%1 dives loaded from local dive data file").arg(dive_table.nr)); setNotificationText(tr("%1 dives loaded from local dive data file").arg(divelog.dives->nr));
} }
if (qPrefCloudStorage::cloud_verification_status() == qPrefCloudStorage::CS_NEED_TO_VERIFY) { if (qPrefCloudStorage::cloud_verification_status() == qPrefCloudStorage::CS_NEED_TO_VERIFY) {
appendTextToLog(QStringLiteral("have cloud credentials, but still needs PIN")); appendTextToLog(QStringLiteral("have cloud credentials, but still needs PIN"));
@ -472,13 +473,9 @@ static QString nocloud_localstorage()
void QMLManager::mergeLocalRepo() void QMLManager::mergeLocalRepo()
{ {
struct dive_table table = empty_dive_table; struct divelog log;
struct trip_table trips = empty_trip_table; parse_file(qPrintable(nocloud_localstorage()), &log);
struct dive_site_table sites = empty_dive_site_table; add_imported_dives(&log, IMPORT_MERGE_ALL_TRIPS);
struct device_table devices;
struct filter_preset_table filter_presets;
parse_file(qPrintable(nocloud_localstorage()), &table, &trips, &sites, &devices, &filter_presets);
add_imported_dives(&table, &trips, &sites, &devices, IMPORT_MERGE_ALL_TRIPS);
mark_divelist_changed(true); mark_divelist_changed(true);
} }
@ -578,7 +575,7 @@ void QMLManager::finishSetup()
qPrefCloudStorage::set_cloud_verification_status(qPrefCloudStorage::CS_NOCLOUD); qPrefCloudStorage::set_cloud_verification_status(qPrefCloudStorage::CS_NOCLOUD);
saveCloudCredentials(qPrefCloudStorage::cloud_storage_email(), qPrefCloudStorage::cloud_storage_password(), qPrefCloudStorage::cloud_storage_pin()); saveCloudCredentials(qPrefCloudStorage::cloud_storage_email(), qPrefCloudStorage::cloud_storage_password(), qPrefCloudStorage::cloud_storage_pin());
appendTextToLog(tr("working in no-cloud mode")); appendTextToLog(tr("working in no-cloud mode"));
int error = parse_file(existing_filename, &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table); int error = parse_file(existing_filename, &divelog);
if (error) { if (error) {
// we got an error loading the local file // we got an error loading the local file
setNotificationText(tr("Error parsing local storage, giving up")); setNotificationText(tr("Error parsing local storage, giving up"));
@ -587,7 +584,7 @@ void QMLManager::finishSetup()
// successfully opened the local file, now add thigs to the dive list // successfully opened the local file, now add thigs to the dive list
consumeFinishedLoad(); consumeFinishedLoad();
updateHaveLocalChanges(true); updateHaveLocalChanges(true);
appendTextToLog(QString("working in no-cloud mode, finished loading %1 dives from %2").arg(dive_table.nr).arg(existing_filename)); appendTextToLog(QString("working in no-cloud mode, finished loading %1 dives from %2").arg(divelog.dives->nr).arg(existing_filename));
} }
} else { } else {
qPrefCloudStorage::set_cloud_verification_status(qPrefCloudStorage::CS_UNKNOWN); qPrefCloudStorage::set_cloud_verification_status(qPrefCloudStorage::CS_UNKNOWN);
@ -664,7 +661,7 @@ void QMLManager::saveCloudCredentials(const QString &newEmail, const QString &ne
qPrefCloudStorage::set_cloud_storage_email(email); qPrefCloudStorage::set_cloud_storage_email(email);
qPrefCloudStorage::set_cloud_storage_password(newPassword); qPrefCloudStorage::set_cloud_storage_password(newPassword);
if (m_oldStatus == qPrefCloudStorage::CS_NOCLOUD && cloudCredentialsChanged && dive_table.nr) { if (m_oldStatus == qPrefCloudStorage::CS_NOCLOUD && cloudCredentialsChanged && divelog.dives->nr) {
// we came from NOCLOUD and are connecting to a cloud account; // we came from NOCLOUD and are connecting to a cloud account;
// since we already have dives in the table, let's remember that so we can keep them // since we already have dives in the table, let's remember that so we can keep them
noCloudToCloud = true; noCloudToCloud = true;
@ -795,10 +792,10 @@ void QMLManager::loadDivesWithValidCredentials()
} }
if (info.repo) { if (info.repo) {
appendTextToLog(QString("have repository and branch %1").arg(info.branch)); appendTextToLog(QString("have repository and branch %1").arg(info.branch));
error = git_load_dives(&info, &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table); error = git_load_dives(&info, &divelog);
} else { } else {
appendTextToLog(QString("didn't receive valid git repo, try again")); appendTextToLog(QString("didn't receive valid git repo, try again"));
error = parse_file(fileNamePrt.data(), &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table); error = parse_file(fileNamePrt.data(), &divelog);
} }
setDiveListProcessing(false); setDiveListProcessing(false);
if (!error) { if (!error) {
@ -822,7 +819,7 @@ void QMLManager::loadDivesWithValidCredentials()
if (noCloudToCloud) { if (noCloudToCloud) {
git_storage_update_progress(qPrintable(tr("Loading dives from local storage ('no cloud' mode)"))); git_storage_update_progress(qPrintable(tr("Loading dives from local storage ('no cloud' mode)")));
mergeLocalRepo(); mergeLocalRepo();
appendTextToLog(QStringLiteral("%1 dives loaded after importing nocloud local storage").arg(dive_table.nr)); appendTextToLog(QStringLiteral("%1 dives loaded after importing nocloud local storage").arg(divelog.dives->nr));
noCloudToCloud = false; noCloudToCloud = false;
mark_divelist_changed(true); mark_divelist_changed(true);
emit syncStateChanged(); emit syncStateChanged();
@ -886,8 +883,8 @@ void QMLManager::consumeFinishedLoad()
prefs.show_ccr_sensors = git_prefs.show_ccr_sensors; prefs.show_ccr_sensors = git_prefs.show_ccr_sensors;
prefs.pp_graphs.po2 = git_prefs.pp_graphs.po2; prefs.pp_graphs.po2 = git_prefs.pp_graphs.po2;
process_loaded_dives(); process_loaded_dives();
appendTextToLog(QStringLiteral("%1 dives loaded").arg(dive_table.nr)); appendTextToLog(QStringLiteral("%1 dives loaded").arg(divelog.dives->nr));
if (dive_table.nr == 0) if (divelog.dives->nr == 0)
setStartPageText(tr("Cloud storage open successfully. No dives in dive list.")); setStartPageText(tr("Cloud storage open successfully. No dives in dive list."));
} }
@ -1062,7 +1059,7 @@ bool QMLManager::checkLocation(DiveSiteChange &res, struct dive *d, QString loca
bool changed = false; bool changed = false;
QString oldLocation = get_dive_location(d); QString oldLocation = get_dive_location(d);
if (oldLocation != location) { if (oldLocation != location) {
ds = get_dive_site_by_name(qPrintable(location), &dive_site_table); ds = get_dive_site_by_name(qPrintable(location), divelog.sites);
if (!ds && !location.isEmpty()) { if (!ds && !location.isEmpty()) {
res.createdDs.reset(alloc_dive_site_with_name(qPrintable(location))); res.createdDs.reset(alloc_dive_site_with_name(qPrintable(location)));
res.changed = true; res.changed = true;
@ -1800,7 +1797,7 @@ QString QMLManager::getGpsFromSiteName(const QString &siteName)
{ {
struct dive_site *ds; struct dive_site *ds;
ds = get_dive_site_by_name(qPrintable(siteName), &dive_site_table); ds = get_dive_site_by_name(qPrintable(siteName), divelog.sites);
if (!ds) if (!ds)
return QString(); return QString();
return printGPSCoords(&ds->location); return printGPSCoords(&ds->location);
@ -2347,15 +2344,11 @@ void QMLManager::setDiveListProcessing(bool value)
void QMLManager::importCacheRepo(QString repo) void QMLManager::importCacheRepo(QString repo)
{ {
struct dive_table table = empty_dive_table; struct divelog log;
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;
QString repoPath = QString("%1/cloudstorage/%2").arg(system_default_directory()).arg(repo); QString repoPath = QString("%1/cloudstorage/%2").arg(system_default_directory()).arg(repo);
appendTextToLog(QString("importing %1").arg(repoPath)); appendTextToLog(QString("importing %1").arg(repoPath));
parse_file(qPrintable(repoPath), &table, &trips, &sites, &devices, &filter_presets); parse_file(qPrintable(repoPath), &log);
add_imported_dives(&table, &trips, &sites, &devices, IMPORT_MERGE_ALL_TRIPS); add_imported_dives(&log, IMPORT_MERGE_ALL_TRIPS);
changesNeedSaving(); changesNeedSaving();
} }
@ -2370,11 +2363,10 @@ QStringList QMLManager::cloudCacheList() const
if (dir == "localrepo") { if (dir == "localrepo") {
result << QString("localrepo[master]"); result << QString("localrepo[master]");
} else { } else {
foreach(QString branch, remote.entryList().filter(QRegularExpression("...+"))) { foreach(QString branch, remote.entryList().filter(QRegularExpression("...+")))
result << QString("%1[%2]").arg(dir).arg(branch); result << QString("%1[%2]").arg(dir).arg(branch);
} }
} }
}
return result; return result;
} }

View file

@ -4,6 +4,7 @@
#include "core/subsurface-qt/divelistnotifier.h" #include "core/subsurface-qt/divelistnotifier.h"
#include "core/qthelper.h" #include "core/qthelper.h"
#include "core/divesite.h" #include "core/divesite.h"
#include "core/divelog.h"
#include "core/metrics.h" #include "core/metrics.h"
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE
#include "cleanertablemodel.h" // for trashIcon() and editIcon() #include "cleanertablemodel.h" // for trashIcon() and editIcon()
@ -36,7 +37,7 @@ int LocationInformationModel::columnCount(const QModelIndex &) const
int LocationInformationModel::rowCount(const QModelIndex &) const int LocationInformationModel::rowCount(const QModelIndex &) const
{ {
return dive_site_table.nr; return divelog.sites->nr;
} }
QVariant LocationInformationModel::headerData(int section, Qt::Orientation orientation, int role) const QVariant LocationInformationModel::headerData(int section, Qt::Orientation orientation, int role) const
@ -124,7 +125,7 @@ QVariant LocationInformationModel::data(const QModelIndex &index, int role) cons
if (!index.isValid()) if (!index.isValid())
return QVariant(); return QVariant();
struct dive_site *ds = get_dive_site(index.row(), &dive_site_table); struct dive_site *ds = get_dive_site(index.row(), divelog.sites);
return getDiveSiteData(ds, index.column(), role); return getDiveSiteData(ds, index.column(), role);
} }
@ -136,7 +137,7 @@ void LocationInformationModel::update()
void LocationInformationModel::diveSiteDiveCountChanged(dive_site *ds) void LocationInformationModel::diveSiteDiveCountChanged(dive_site *ds)
{ {
int idx = get_divesite_idx(ds, &dive_site_table); int idx = get_divesite_idx(ds, divelog.sites);
if (idx >= 0) if (idx >= 0)
dataChanged(createIndex(idx, NUM_DIVES), createIndex(idx, NUM_DIVES)); dataChanged(createIndex(idx, NUM_DIVES), createIndex(idx, NUM_DIVES));
} }
@ -161,7 +162,7 @@ void LocationInformationModel::diveSiteDeleted(struct dive_site *, int idx)
void LocationInformationModel::diveSiteChanged(struct dive_site *ds, int field) void LocationInformationModel::diveSiteChanged(struct dive_site *ds, int field)
{ {
int idx = get_divesite_idx(ds, &dive_site_table); int idx = get_divesite_idx(ds, divelog.sites);
if (idx < 0) if (idx < 0)
return; return;
dataChanged(createIndex(idx, field), createIndex(idx, field)); dataChanged(createIndex(idx, field), createIndex(idx, field));
@ -169,7 +170,7 @@ void LocationInformationModel::diveSiteChanged(struct dive_site *ds, int field)
void LocationInformationModel::diveSiteDivesChanged(struct dive_site *ds) void LocationInformationModel::diveSiteDivesChanged(struct dive_site *ds)
{ {
int idx = get_divesite_idx(ds, &dive_site_table); int idx = get_divesite_idx(ds, divelog.sites);
if (idx < 0) if (idx < 0)
return; return;
dataChanged(createIndex(idx, NUM_DIVES), createIndex(idx, NUM_DIVES)); dataChanged(createIndex(idx, NUM_DIVES), createIndex(idx, NUM_DIVES));
@ -180,9 +181,9 @@ bool DiveSiteSortedModel::filterAcceptsRow(int sourceRow, const QModelIndex &sou
if (fullText.isEmpty()) if (fullText.isEmpty())
return true; return true;
if (sourceRow < 0 || sourceRow > dive_site_table.nr) if (sourceRow < 0 || sourceRow > divelog.sites->nr)
return false; return false;
struct dive_site *ds = dive_site_table.dive_sites[sourceRow]; struct dive_site *ds = divelog.sites->dive_sites[sourceRow];
QString text = QString(ds->name) + QString(ds->description) + QString(ds->notes); QString text = QString(ds->name) + QString(ds->description) + QString(ds->notes);
return text.contains(fullText, Qt::CaseInsensitive); return text.contains(fullText, Qt::CaseInsensitive);
} }
@ -192,8 +193,8 @@ bool DiveSiteSortedModel::lessThan(const QModelIndex &i1, const QModelIndex &i2)
// The source indices correspond to indices in the global dive site table. // The source indices correspond to indices in the global dive site table.
// Let's access them directly without going via the source model. // Let's access them directly without going via the source model.
// Kind of dirty, but less effort. // Kind of dirty, but less effort.
struct dive_site *ds1 = get_dive_site(i1.row(), &dive_site_table); struct dive_site *ds1 = get_dive_site(i1.row(), divelog.sites);
struct dive_site *ds2 = get_dive_site(i2.row(), &dive_site_table); struct dive_site *ds2 = get_dive_site(i2.row(), divelog.sites);
if (!ds1 || !ds2) // Invalid dive sites compare as different if (!ds1 || !ds2) // Invalid dive sites compare as different
return false; return false;
switch (i1.column()) { switch (i1.column()) {
@ -229,18 +230,18 @@ QStringList DiveSiteSortedModel::allSiteNames() const
// This shouldn't happen, but if model and core get out of sync, // This shouldn't happen, but if model and core get out of sync,
// (more precisely: the core has more sites than the model is aware of), // (more precisely: the core has more sites than the model is aware of),
// we might get an invalid index. // we might get an invalid index.
if (idx < 0 || idx > dive_site_table.nr) { if (idx < 0 || idx > divelog.sites->nr) {
SSRF_INFO("DiveSiteSortedModel::allSiteNames(): invalid index"); SSRF_INFO("DiveSiteSortedModel::allSiteNames(): invalid index");
continue; continue;
} }
locationNames << QString(dive_site_table.dive_sites[idx]->name); locationNames << QString(divelog.sites->dive_sites[idx]->name);
} }
return locationNames; return locationNames;
} }
struct dive_site *DiveSiteSortedModel::getDiveSite(const QModelIndex &idx) struct dive_site *DiveSiteSortedModel::getDiveSite(const QModelIndex &idx)
{ {
return get_dive_site(mapToSource(idx).row(), &dive_site_table); return get_dive_site(mapToSource(idx).row(), divelog.sites);
} }
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE

View file

@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include "diveplannermodel.h" #include "diveplannermodel.h"
#include "core/divelist.h" #include "core/divelist.h"
#include "core/divelog.h"
#include "core/subsurface-string.h" #include "core/subsurface-string.h"
#include "qt-models/cylindermodel.h" #include "qt-models/cylindermodel.h"
#include "core/planner.h" #include "core/planner.h"
@ -93,14 +94,13 @@ void DivePlannerPointsModel::setupStartTime()
// if the latest dive is in the future, then start an hour after it ends // if the latest dive is in the future, then start an hour after it ends
// otherwise start an hour from now // otherwise start an hour from now
startTime = QDateTime::currentDateTimeUtc().addSecs(3600 + gettimezoneoffset()); startTime = QDateTime::currentDateTimeUtc().addSecs(3600 + gettimezoneoffset());
if (dive_table.nr) { if (divelog.dives->nr > 0) {
struct dive *d = get_dive(dive_table.nr - 1); struct dive *d = get_dive(divelog.dives->nr - 1);
time_t ends = dive_endtime(d); time_t ends = dive_endtime(d);
time_t diff = ends - dateTimeToTimestamp(startTime); time_t diff = ends - dateTimeToTimestamp(startTime);
if (diff > 0) { if (diff > 0)
startTime = startTime.addSecs(diff + 3600); startTime = startTime.addSecs(diff + 3600);
} }
}
} }
void DivePlannerPointsModel::loadFromDive(dive *dIn) void DivePlannerPointsModel::loadFromDive(dive *dIn)

View file

@ -1,4 +1,5 @@
#include "divesiteimportmodel.h" #include "divesiteimportmodel.h"
#include "core/divelog.h"
#include "core/qthelper.h" #include "core/qthelper.h"
#include "core/taxonomy.h" #include "core/taxonomy.h"
@ -67,7 +68,7 @@ QVariant DivesiteImportedModel::data(const QModelIndex &index, int role) const
// 40075000 is circumference of the earth in meters // 40075000 is circumference of the earth in meters
struct dive_site *nearest_ds = struct dive_site *nearest_ds =
get_dive_site_by_gps_proximity(&ds->location, get_dive_site_by_gps_proximity(&ds->location,
40075000, &dive_site_table); 40075000, divelog.sites);
if (nearest_ds) if (nearest_ds)
return nearest_ds->name; return nearest_ds->name;
else else
@ -77,7 +78,7 @@ QVariant DivesiteImportedModel::data(const QModelIndex &index, int role) const
unsigned int distance = 0; unsigned int distance = 0;
struct dive_site *nearest_ds = struct dive_site *nearest_ds =
get_dive_site_by_gps_proximity(&ds->location, get_dive_site_by_gps_proximity(&ds->location,
40075000, &dive_site_table); 40075000, divelog.sites);
if (nearest_ds) if (nearest_ds)
distance = get_distance(&ds->location, distance = get_distance(&ds->location,
&nearest_ds->location); &nearest_ds->location);
@ -134,7 +135,7 @@ void DivesiteImportedModel::repopulate(struct dive_site_table *sites)
lastIndex = importedSitesTable->nr - 1; lastIndex = importedSitesTable->nr - 1;
checkStates.resize(importedSitesTable->nr); checkStates.resize(importedSitesTable->nr);
for (int row = 0; row < importedSitesTable->nr; row++) for (int row = 0; row < importedSitesTable->nr; row++)
if (get_dive_site_by_gps(&importedSitesTable->dive_sites[row]->location, &dive_site_table)) if (get_dive_site_by_gps(&importedSitesTable->dive_sites[row]->location, divelog.sites))
checkStates[row] = false; checkStates[row] = false;
else else
checkStates[row] = true; checkStates[row] = true;

View file

@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include "qt-models/divetripmodel.h" #include "qt-models/divetripmodel.h"
#include "core/divefilter.h" #include "core/divefilter.h"
#include "core/divelog.h"
#ifdef SUBSURFACE_MOBILE #ifdef SUBSURFACE_MOBILE
#include "qt-models/mobilelistmodel.h" #include "qt-models/mobilelistmodel.h"
#endif #endif
@ -711,7 +712,7 @@ void DiveTripModelTree::populate()
// we want this to be two calls as the second text is overwritten below by the lines starting with "\r" // we want this to be two calls as the second text is overwritten below by the lines starting with "\r"
uiNotification(QObject::tr("populate data model")); uiNotification(QObject::tr("populate data model"));
uiNotification(QObject::tr("start processing")); uiNotification(QObject::tr("start processing"));
for (int i = 0; i < dive_table.nr; ++i) { for (int i = 0; i < divelog.dives->nr; ++i) {
dive *d = get_dive(i); dive *d = get_dive(i);
if (!d) // should never happen if (!d) // should never happen
continue; continue;
@ -741,7 +742,7 @@ void DiveTripModelTree::populate()
// Remember the index of the current dive // Remember the index of the current dive
oldCurrent = current_dive; oldCurrent = current_dive;
uiNotification(QObject::tr("%1 dives processed").arg(dive_table.nr)); uiNotification(QObject::tr("%1 dives processed").arg(divelog.dives->nr));
} }
int DiveTripModelTree::rowCount(const QModelIndex &parent) const int DiveTripModelTree::rowCount(const QModelIndex &parent) const
@ -1470,8 +1471,8 @@ void DiveTripModelList::populate()
DiveFilter::instance()->reset(); // The data was reset - update filter status. TODO: should this really be done here? DiveFilter::instance()->reset(); // The data was reset - update filter status. TODO: should this really be done here?
// Fill model // Fill model
items.reserve(dive_table.nr); items.reserve(divelog.dives->nr);
for (int i = 0; i < dive_table.nr; ++i) { for (int i = 0; i < divelog.dives->nr; ++i) {
dive *d = get_dive(i); dive *d = get_dive(i);
if (!d || d->hidden_by_filter) if (!d || d->hidden_by_filter)
continue; continue;

View file

@ -3,6 +3,7 @@
#include "divelocationmodel.h" #include "divelocationmodel.h"
#include "core/divesite.h" #include "core/divesite.h"
#include "core/divefilter.h" #include "core/divefilter.h"
#include "core/divelog.h"
#include "core/settings/qPrefDisplay.h" #include "core/settings/qPrefDisplay.h"
#if !defined(SUBSURFACE_MOBILE) && !defined(SUBSURFACE_DOWNLOADER) #if !defined(SUBSURFACE_MOBILE) && !defined(SUBSURFACE_DOWNLOADER)
#include "qt-models/filtermodels.h" #include "qt-models/filtermodels.h"
@ -161,8 +162,8 @@ void MapLocationModel::reload(QObject *map)
if (diveSiteMode) if (diveSiteMode)
m_selectedDs = DiveFilter::instance()->filteredDiveSites(); m_selectedDs = DiveFilter::instance()->filteredDiveSites();
#endif #endif
for (int i = 0; i < dive_site_table.nr; ++i) { for (int i = 0; i < divelog.sites->nr; ++i) {
struct dive_site *ds = dive_site_table.dive_sites[i]; struct dive_site *ds = divelog.sites->dive_sites[i];
QGeoCoordinate dsCoord; QGeoCoordinate dsCoord;
// Don't show dive sites of hidden dives, unless we're in dive site edit mode. // Don't show dive sites of hidden dives, unless we're in dive site edit mode.

View file

@ -27,6 +27,7 @@
#endif #endif
#include "core/dive.h" #include "core/dive.h"
#include "core/divelog.h"
#include "core/subsurface-string.h" #include "core/subsurface-string.h"
#include "core/gettext.h" #include "core/gettext.h"
#include "core/divelist.h" #include "core/divelist.h"
@ -321,7 +322,7 @@ static void smtk_wreck_site(MdbHandle *mdb, char *site_idx, struct dive_site *ds
* Location format: * Location format:
* | Idx | Text | Province | Country | Depth | * | Idx | Text | Province | Country | Depth |
*/ */
static void smtk_build_location(MdbHandle *mdb, char *idx, struct dive_site **location) static void smtk_build_location(MdbHandle *mdb, char *idx, struct dive_site **location, struct divelog *log)
{ {
MdbTableDef *table; MdbTableDef *table;
MdbColumn *col[MDB_MAX_COLS]; MdbColumn *col[MDB_MAX_COLS];
@ -373,7 +374,7 @@ static void smtk_build_location(MdbHandle *mdb, char *idx, struct dive_site **lo
do { do {
rc = mdb_fetch_row(table); rc = mdb_fetch_row(table);
} while (strcasecmp(bound_values[0], loc_idx) && rc != 0); } while (strcasecmp(bound_values[0], loc_idx) && rc != 0);
if (rc == 0){ if (rc == 0) {
smtk_free(bound_values, table->num_cols); smtk_free(bound_values, table->num_cols);
mdb_free_tabledef(table); mdb_free_tabledef(table);
if(notes) if(notes)
@ -393,12 +394,12 @@ static void smtk_build_location(MdbHandle *mdb, char *idx, struct dive_site **lo
str = smtk_concat_str(str, ", ", "%s", bound_values[1]); // Locality str = smtk_concat_str(str, ", ", "%s", bound_values[1]); // Locality
str = smtk_concat_str(str, ", ", "%s", site); str = smtk_concat_str(str, ", ", "%s", site);
ds = get_dive_site_by_name(str, &dive_site_table); ds = get_dive_site_by_name(str, log->sites);
if (!ds) { if (!ds) {
if (!has_location(&loc)) if (!has_location(&loc))
ds = create_dive_site(str, &dive_site_table); ds = create_dive_site(str, log->sites);
else else
ds = create_dive_site_with_gps(str, &loc, &dive_site_table); ds = create_dive_site_with_gps(str, &loc, log->sites);
} }
*location = ds; *location = ds;
smtk_free(bound_values, table->num_cols); smtk_free(bound_values, table->num_cols);
@ -928,7 +929,7 @@ static dc_status_t libdc_buffer_complete(device_data_t *dev_data, unsigned char
* a single DB breaks binded row data, and so would break the top loop. * a single DB breaks binded row data, and so would break the top loop.
*/ */
void smartrak_import(const char *file, struct dive_table *divetable) void smartrak_import(const char *file, struct divelog *log)
{ {
MdbHandle *mdb, *mdb_clon; MdbHandle *mdb, *mdb_clon;
MdbTableDef *mdb_table; MdbTableDef *mdb_table;
@ -1097,7 +1098,7 @@ void smartrak_import(const char *file, struct dive_table *divetable)
weightsystem_t ws = { {lrint(strtod(col[coln(WEIGHT)]->bind_ptr, NULL) * 1000)}, "", false }; weightsystem_t ws = { {lrint(strtod(col[coln(WEIGHT)]->bind_ptr, NULL) * 1000)}, "", false };
add_cloned_weightsystem(&smtkdive->weightsystems, ws); add_cloned_weightsystem(&smtkdive->weightsystems, ws);
smtkdive->suit = copy_string(suit_list[atoi(col[coln(SUITIDX)]->bind_ptr) - 1]); smtkdive->suit = copy_string(suit_list[atoi(col[coln(SUITIDX)]->bind_ptr) - 1]);
smtk_build_location(mdb_clon, col[coln(SITEIDX)]->bind_ptr, &smtkdive->dive_site); smtk_build_location(mdb_clon, col[coln(SITEIDX)]->bind_ptr, &smtkdive->dive_site, log);
smtkdive->buddy = smtk_locate_buddy(mdb_clon, col[0]->bind_ptr, buddy_list); smtkdive->buddy = smtk_locate_buddy(mdb_clon, col[0]->bind_ptr, buddy_list);
smtk_parse_relations(mdb_clon, smtkdive, col[0]->bind_ptr, "Type", "TypeRelation", type_list, true); smtk_parse_relations(mdb_clon, smtkdive, col[0]->bind_ptr, "Type", "TypeRelation", type_list, true);
smtk_parse_relations(mdb_clon, smtkdive, col[0]->bind_ptr, "Activity", "ActivityRelation", activity_list, false); smtk_parse_relations(mdb_clon, smtkdive, col[0]->bind_ptr, "Activity", "ActivityRelation", activity_list, false);
@ -1109,7 +1110,7 @@ void smartrak_import(const char *file, struct dive_table *divetable)
smtk_parse_bookmarks(mdb_clon, smtkdive, col[0]->bind_ptr); smtk_parse_bookmarks(mdb_clon, smtkdive, col[0]->bind_ptr);
smtkdive->notes = smtk_concat_str(smtkdive->notes, "\n", "%s", col[coln(REMARKS)]->bind_ptr); smtkdive->notes = smtk_concat_str(smtkdive->notes, "\n", "%s", col[coln(REMARKS)]->bind_ptr);
record_dive_to_table(smtkdive, divetable); record_dive_to_table(smtkdive, log->dives);
device_data_free(devdata); device_data_free(devdata);
} }
mdb_free_tabledef(mdb_table); mdb_free_tabledef(mdb_table);
@ -1117,5 +1118,5 @@ void smartrak_import(const char *file, struct dive_table *divetable)
mdb->catalog = NULL; mdb->catalog = NULL;
mdb_close(mdb_clon); mdb_close(mdb_clon);
mdb_close(mdb); mdb_close(mdb);
sort_dive_table(divetable); sort_dive_table(log->dives);
} }

View file

@ -3,6 +3,7 @@
#include "ui_smrtk2ssrfc_window.h" #include "ui_smrtk2ssrfc_window.h"
#include "qt-models/filtermodels.h" #include "qt-models/filtermodels.h"
#include "core/dive.h" #include "core/dive.h"
#include "core/divelog.h"
#include "core/divelist.h" #include "core/divelist.h"
#include "core/errorhelper.h" #include "core/errorhelper.h"
#include "core/settings/qPrefDisplay.h" #include "core/settings/qPrefDisplay.h"
@ -84,7 +85,7 @@ void Smrtk2ssrfcWindow::on_importButton_clicked()
for (int i = 0; i < inputFiles.size(); ++i) { for (int i = 0; i < inputFiles.size(); ++i) {
ui->progressBar->setValue(i); ui->progressBar->setValue(i);
fileNamePtr = QFile::encodeName(inputFiles.at(i)); fileNamePtr = QFile::encodeName(inputFiles.at(i));
smartrak_import(fileNamePtr.data(), &dive_table); smartrak_import(fileNamePtr.data(), &divelog);
ui->plainTextEdit->appendPlainText(error_buf); ui->plainTextEdit->appendPlainText(error_buf);
} }
ui->progressBar->setValue(inputFiles.size()); ui->progressBar->setValue(inputFiles.size());

View file

@ -6,7 +6,8 @@
#include <QFileDialog> #include <QFileDialog>
#include <QFileInfo> #include <QFileInfo>
extern "C" void smartrak_import(const char *file, struct dive_table *divetable); struct divelog;
extern "C" void smartrak_import(const char *file, struct divelog *log);
namespace Ui { namespace Ui {
class Smrtk2ssrfcWindow; class Smrtk2ssrfcWindow;

View file

@ -3,12 +3,11 @@
#include <stdio.h> #include <stdio.h>
#include "core/dive.h" #include "core/dive.h"
#include "core/divelist.h" #include "core/divelist.h"
#include "core/divelog.h"
#include "smrtk2ssrfc_window.h" #include "smrtk2ssrfc_window.h"
#include <QApplication> #include <QApplication>
#include <QDebug> #include <QDebug>
extern "C" void smartrak_import(const char *file, struct dive_table *table);
/* /*
* Simple command line interface to call directly smartrak_import() or launch * Simple command line interface to call directly smartrak_import() or launch
* the GUI if called without arguments. * the GUI if called without arguments.
@ -48,7 +47,7 @@ int main(int argc, char *argv[])
for(i = 1; i < argc -1; i++) { for(i = 1; i < argc -1; i++) {
infile = argv[i]; infile = argv[i];
qDebug() << "\t" << infile << "\n"; qDebug() << "\t" << infile << "\n";
smartrak_import(infile, &dive_table); smartrak_import(infile, &divelog);
} }
qDebug() << "\n[Writing]\n\t" << outfile << "\n"; qDebug() << "\n[Writing]\n\t" << outfile << "\n";
save_dives_logic(outfile, false, false); save_dives_logic(outfile, false, false);

View file

@ -2,6 +2,7 @@
#include "statsvariables.h" #include "statsvariables.h"
#include "statstranslations.h" #include "statstranslations.h"
#include "core/dive.h" #include "core/dive.h"
#include "core/divelog.h"
#include "core/divemode.h" #include "core/divemode.h"
#include "core/divesite.h" #include "core/divesite.h"
#include "core/gas.h" #include "core/gas.h"
@ -1380,7 +1381,7 @@ struct DiveNrVariable : public StatsVariableTemplate<StatsVariable::Type::Numeri
return StatsTranslations::tr("Dive #"); return StatsTranslations::tr("Dive #");
} }
std::vector<const StatsBinner *> binners() const override { std::vector<const StatsBinner *> binners() const override {
if (dive_table.nr > 1000) if (divelog.dives->nr > 1000)
return { &dive_nr_binner_20, &dive_nr_binner_50, &dive_nr_binner_100, &dive_nr_binner_200 }; return { &dive_nr_binner_20, &dive_nr_binner_50, &dive_nr_binner_100, &dive_nr_binner_200 };
else else
return { &dive_nr_binner_5, &dive_nr_binner_10, &dive_nr_binner_20, &dive_nr_binner_50 }; return { &dive_nr_binner_5, &dive_nr_binner_10, &dive_nr_binner_20, &dive_nr_binner_50 };

View file

@ -7,6 +7,7 @@
#include <time.h> #include <time.h>
#include "core/downloadfromdcthread.h" // for fill_computer_list #include "core/downloadfromdcthread.h" // for fill_computer_list
#include "core/divelog.h"
#include "core/errorhelper.h" #include "core/errorhelper.h"
#include "core/parse.h" #include "core/parse.h"
#include "core/qt-gui.h" #include "core/qt-gui.h"
@ -109,6 +110,7 @@ int main(int argc, char **argv)
if (!quit) if (!quit)
run_ui(); run_ui();
exit_ui(); exit_ui();
clear_divelog(&divelog);
taglist_free(g_tag_list); taglist_free(g_tag_list);
parse_xml_exit(); parse_xml_exit();
free((void *)default_directory); free((void *)default_directory);

View file

@ -8,6 +8,7 @@
#include "core/settings/qPref.h" #include "core/settings/qPref.h"
#include "core/tag.h" #include "core/tag.h"
#include "core/dive.h" #include "core/dive.h"
#include "core/divelog.h"
#include "core/subsurface-string.h" #include "core/subsurface-string.h"
#include "core/file.h" #include "core/file.h"
#include "core/trip.h" #include "core/trip.h"
@ -40,10 +41,7 @@ int main(int argc, char **argv)
QStringList files; QStringList files;
QStringList importedFiles; QStringList importedFiles;
QStringList arguments = QCoreApplication::arguments(); QStringList arguments = QCoreApplication::arguments();
struct dive_table dive_table = empty_dive_table; struct divelog log;
struct dive_site_table sites = empty_dive_site_table;
struct device_table devices;
struct filter_preset_table presets;
// set a default logfile name for libdivecomputer so we always get a logfile // set a default logfile name for libdivecomputer so we always get a logfile
logfile_name = strdup("subsurface-downloader.log"); logfile_name = strdup("subsurface-downloader.log");
@ -95,7 +93,7 @@ int main(int argc, char **argv)
filesOnCommandLine = !files.isEmpty() || !importedFiles.isEmpty(); filesOnCommandLine = !files.isEmpty() || !importedFiles.isEmpty();
if (!files.isEmpty()) { if (!files.isEmpty()) {
qDebug() << "loading dive data from" << files; qDebug() << "loading dive data from" << files;
parse_file(qPrintable(files.first()), &dive_table, &trip_table, &sites, &devices, &presets); parse_file(qPrintable(files.first()), &log);
} }
print_files(); print_files();
if (!quit) { if (!quit) {
@ -106,6 +104,7 @@ int main(int argc, char **argv)
} }
} }
save_dives(qPrintable(files.first())); save_dives(qPrintable(files.first()));
clear_divelog(&divelog);
taglist_free(g_tag_list); taglist_free(g_tag_list);
parse_xml_exit(); parse_xml_exit();
free((void *)default_directory); free((void *)default_directory);

View file

@ -7,6 +7,7 @@
#include <time.h> #include <time.h>
#include "core/dive.h" #include "core/dive.h"
#include "core/divelog.h"
#include "core/color.h" #include "core/color.h"
#include "core/downloadfromdcthread.h" #include "core/downloadfromdcthread.h"
#include "core/parse.h" #include "core/parse.h"
@ -93,6 +94,7 @@ int main(int argc, char **argv)
if (!quit) if (!quit)
run_mobile_ui(initial_font_size); run_mobile_ui(initial_font_size);
exit_ui(); exit_ui();
clear_divelog(&divelog);
taglist_free(g_tag_list); taglist_free(g_tag_list);
parse_xml_exit(); parse_xml_exit();
subsurface_console_exit(); subsurface_console_exit();

View file

@ -2,6 +2,7 @@
#include "testAirPressure.h" #include "testAirPressure.h"
#include "core/device.h" #include "core/device.h"
#include "core/dive.h" #include "core/dive.h"
#include "core/divelog.h"
#include "core/divesite.h" #include "core/divesite.h"
#include "core/trip.h" #include "core/trip.h"
#include "core/file.h" #include "core/file.h"
@ -21,8 +22,7 @@ void TestAirPressure::get_dives()
struct dive *dive; struct dive *dive;
verbose = 1; verbose = 1;
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/TestAtmPress.xml", &dive_table, &trip_table, QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/TestAtmPress.xml", &divelog), 0);
&dive_site_table, &device_table, &filter_preset_table), 0);
dive = get_dive(0); dive = get_dive(0);
dive->selected = true; dive->selected = true;
QVERIFY(dive != NULL); QVERIFY(dive != NULL);
@ -57,8 +57,7 @@ void TestAirPressure::testWriteReadBackAirPressure()
dive->surface_pressure.mbar = ap; dive->surface_pressure.mbar = ap;
QCOMPARE(save_dives("./testout.ssrf"), 0); QCOMPARE(save_dives("./testout.ssrf"), 0);
clear_dive_file_data(); clear_dive_file_data();
QCOMPARE(parse_file("./testout.ssrf", &dive_table, &trip_table, &dive_site_table, QCOMPARE(parse_file("./testout.ssrf", &divelog), 0);
&device_table, &filter_preset_table), 0);
dive = get_dive(0); dive = get_dive(0);
QVERIFY(dive != NULL); QVERIFY(dive != NULL);
dive->selected = true; dive->selected = true;

View file

@ -1,18 +1,15 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include "testdivesiteduplication.h" #include "testdivesiteduplication.h"
#include "core/device.h" #include "core/divelog.h"
#include "core/dive.h"
#include "core/divesite.h" #include "core/divesite.h"
#include "core/trip.h"
#include "core/file.h" #include "core/file.h"
#include "core/pref.h" #include "core/pref.h"
void TestDiveSiteDuplication::testReadV2() void TestDiveSiteDuplication::testReadV2()
{ {
prefs.cloud_base_url = strdup(default_prefs.cloud_base_url); prefs.cloud_base_url = strdup(default_prefs.cloud_base_url);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/TwoTimesTwo.ssrf", &dive_table, &trip_table, QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/TwoTimesTwo.ssrf", &divelog), 0);
&dive_site_table, &device_table, &filter_preset_table), 0); QCOMPARE(divelog.sites->nr, 2);
QCOMPARE(dive_site_table.nr, 2);
} }
QTEST_GUILESS_MAIN(TestDiveSiteDuplication) QTEST_GUILESS_MAIN(TestDiveSiteDuplication)

View file

@ -4,13 +4,13 @@
#include "core/device.h" #include "core/device.h"
#include "core/dive.h" #include "core/dive.h"
#include "core/divesite.h" #include "core/divelist.h"
#include "core/divelog.h"
#include "core/file.h" #include "core/file.h"
#include "core/qthelper.h" #include "core/qthelper.h"
#include "core/subsurfacestartup.h" #include "core/subsurfacestartup.h"
#include "core/settings/qPrefProxy.h" #include "core/settings/qPrefProxy.h"
#include "core/settings/qPrefCloudStorage.h" #include "core/settings/qPrefCloudStorage.h"
#include "core/trip.h"
#include "core/git-access.h" #include "core/git-access.h"
#include <QDir> #include <QDir>
@ -152,8 +152,7 @@ void TestGitStorage::initTestCase()
// cleanup local and remote branches // cleanup local and remote branches
localRemoteCleanup(); localRemoteCleanup();
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
&dive_site_table, &device_table, &filter_preset_table), 0);
} }
void TestGitStorage::cleanupTestCase() void TestGitStorage::cleanupTestCase()
@ -185,8 +184,7 @@ void TestGitStorage::testGitStorageLocal()
{ {
// test writing and reading back from local git storage // test writing and reading back from local git storage
git_repository *repo; git_repository *repo;
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/SampleDivesV2.ssrf", &dive_table, &trip_table, QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/SampleDivesV2.ssrf", &divelog), 0);
&dive_site_table, &device_table, &filter_preset_table), 0);
QFETCH(QString, testDirName); QFETCH(QString, testDirName);
QFETCH(QString, prefixRead); QFETCH(QString, prefixRead);
QFETCH(QString, prefixWrite); QFETCH(QString, prefixWrite);
@ -199,8 +197,7 @@ void TestGitStorage::testGitStorageLocal()
QCOMPARE(save_dives(qPrintable(repoNameWrite + "[test]")), 0); QCOMPARE(save_dives(qPrintable(repoNameWrite + "[test]")), 0);
QCOMPARE(save_dives("./SampleDivesV3.ssrf"), 0); QCOMPARE(save_dives("./SampleDivesV3.ssrf"), 0);
clear_dive_file_data(); clear_dive_file_data();
QCOMPARE(parse_file(qPrintable(repoNameRead + "[test]"), &dive_table, &trip_table, QCOMPARE(parse_file(qPrintable(repoNameRead + "[test]"), &divelog), 0);
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(save_dives("./SampleDivesV3viagit.ssrf"), 0); QCOMPARE(save_dives("./SampleDivesV3viagit.ssrf"), 0);
QFile org("./SampleDivesV3.ssrf"); QFile org("./SampleDivesV3.ssrf");
org.open(QFile::ReadOnly); org.open(QFile::ReadOnly);
@ -218,12 +215,10 @@ void TestGitStorage::testGitStorageCloud()
// test writing and reading back from cloud storage // test writing and reading back from cloud storage
// connect to the ssrftest repository on the cloud server // connect to the ssrftest repository on the cloud server
// and repeat the same test as before with the local git storage // and repeat the same test as before with the local git storage
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/SampleDivesV2.ssrf", &dive_table, &trip_table, QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/SampleDivesV2.ssrf", &divelog), 0);
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0); QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
clear_dive_file_data(); clear_dive_file_data();
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(save_dives("./SampleDivesV3viacloud.ssrf"), 0); QCOMPARE(save_dives("./SampleDivesV3viacloud.ssrf"), 0);
QFile org("./SampleDivesV3.ssrf"); QFile org("./SampleDivesV3.ssrf");
org.open(QFile::ReadOnly); org.open(QFile::ReadOnly);
@ -241,10 +236,8 @@ void TestGitStorage::testGitStorageCloudOfflineSync()
// make a change to local cache repo (pretending that we did some offline changes) // make a change to local cache repo (pretending that we did some offline changes)
// and then open the remote one again and check that things were propagated correctly // and then open the remote one again and check that things were propagated correctly
// read the local repo from the previous test and add dive 10 // read the local repo from the previous test and add dive 10
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
&dive_site_table, &device_table, &filter_preset_table), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test10.xml", &divelog), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test10.xml", &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table), 0);
// calling process_loaded_dives() sorts the table, but calling add_imported_dives() // calling process_loaded_dives() sorts the table, but calling add_imported_dives()
// causes it to try to update the window title... let's not do that // causes it to try to update the window title... let's not do that
process_loaded_dives(); process_loaded_dives();
@ -255,8 +248,7 @@ void TestGitStorage::testGitStorageCloudOfflineSync()
clear_dive_file_data(); clear_dive_file_data();
// now pretend that we are online again and open the cloud storage and compare // now pretend that we are online again and open the cloud storage and compare
git_local_only = false; git_local_only = false;
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(save_dives("./SampleDivesV3plus10viacloud.ssrf"), 0); QCOMPARE(save_dives("./SampleDivesV3plus10viacloud.ssrf"), 0);
QFile org("./SampleDivesV3plus10local.ssrf"); QFile org("./SampleDivesV3plus10local.ssrf");
org.open(QFile::ReadOnly); org.open(QFile::ReadOnly);
@ -271,8 +263,7 @@ void TestGitStorage::testGitStorageCloudOfflineSync()
QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0); QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
clear_dive_file_data(); clear_dive_file_data();
moveDir(localCacheDir, localCacheDir + "save"); moveDir(localCacheDir, localCacheDir + "save");
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(save_dives("./SampleDivesV3plus10fromcloud.ssrf"), 0); QCOMPARE(save_dives("./SampleDivesV3plus10fromcloud.ssrf"), 0);
org.close(); org.close();
org.open(QFile::ReadOnly); org.open(QFile::ReadOnly);
@ -301,10 +292,8 @@ void TestGitStorage::testGitStorageCloudMerge()
// (1) open the repo, add dive test11 and save to the cloud // (1) open the repo, add dive test11 and save to the cloud
git_local_only = false; git_local_only = false;
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
&dive_site_table, &device_table, &filter_preset_table), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml", &divelog), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml", &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table), 0);
process_loaded_dives(); process_loaded_dives();
QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0); QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
clear_dive_file_data(); clear_dive_file_data();
@ -315,34 +304,27 @@ void TestGitStorage::testGitStorageCloudMerge()
// (3) open the repo from the old cache and add dive test12 while offline // (3) open the repo from the old cache and add dive test12 while offline
git_local_only = true; git_local_only = true;
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
&dive_site_table, &device_table, &filter_preset_table), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml", &divelog), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml", &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table), 0);
process_loaded_dives(); process_loaded_dives();
QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0); QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
clear_dive_file_data(); clear_dive_file_data();
// (4) now take things back online // (4) now take things back online
git_local_only = false; git_local_only = false;
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
&dive_site_table, &device_table, &filter_preset_table), 0);
clear_dive_file_data(); clear_dive_file_data();
// (5) now we should have all the dives in our repo on the second client // (5) now we should have all the dives in our repo on the second client
// first create the reference data from the xml files: // first create the reference data from the xml files:
QCOMPARE(parse_file("./SampleDivesV3plus10local.ssrf", &dive_table, &trip_table, QCOMPARE(parse_file("./SampleDivesV3plus10local.ssrf", &divelog), 0);
&dive_site_table, &device_table, &filter_preset_table), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml", &divelog), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml", &dive_table, &trip_table, QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml", &divelog), 0);
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml", &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table), 0);
process_loaded_dives(); process_loaded_dives();
QCOMPARE(save_dives("./SampleDivesV3plus10-11-12.ssrf"), 0); QCOMPARE(save_dives("./SampleDivesV3plus10-11-12.ssrf"), 0);
// then load from the cloud // then load from the cloud
clear_dive_file_data(); clear_dive_file_data();
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
&dive_site_table, &device_table, &filter_preset_table), 0);
process_loaded_dives(); process_loaded_dives();
QCOMPARE(save_dives("./SampleDivesV3plus10-11-12-merged.ssrf"), 0); QCOMPARE(save_dives("./SampleDivesV3plus10-11-12-merged.ssrf"), 0);
// finally compare what we have // finally compare what we have
@ -359,8 +341,7 @@ void TestGitStorage::testGitStorageCloudMerge()
// (6) move ourselves back to the first client and compare data there // (6) move ourselves back to the first client and compare data there
moveDir(localCacheDir + "client1", localCacheDir); moveDir(localCacheDir + "client1", localCacheDir);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
&dive_site_table, &device_table, &filter_preset_table), 0);
process_loaded_dives(); process_loaded_dives();
QCOMPARE(save_dives("./SampleDivesV3plus10-11-12-merged-client1.ssrf"), 0); QCOMPARE(save_dives("./SampleDivesV3plus10-11-12-merged-client1.ssrf"), 0);
QFile client1("./SampleDivesV3plus10-11-12-merged-client1.ssrf"); QFile client1("./SampleDivesV3plus10-11-12-merged-client1.ssrf");
@ -376,8 +357,7 @@ void TestGitStorage::testGitStorageCloudMerge2()
// edit the same dive in the cloud repo // edit the same dive in the cloud repo
// merge // merge
// (1) open repo, delete second dive, save offline // (1) open repo, delete second dive, save offline
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
&dive_site_table, &device_table, &filter_preset_table), 0);
process_loaded_dives(); process_loaded_dives();
struct dive *dive = get_dive(1); struct dive *dive = get_dive(1);
delete_single_dive(1); delete_single_dive(1);
@ -391,8 +371,7 @@ void TestGitStorage::testGitStorageCloudMerge2()
moveDir(localCacheDir, localCacheDir + "save"); moveDir(localCacheDir, localCacheDir + "save");
// (3) now we open the cloud storage repo and modify that second dive // (3) now we open the cloud storage repo and modify that second dive
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
&dive_site_table, &device_table, &filter_preset_table), 0);
process_loaded_dives(); process_loaded_dives();
dive = get_dive(1); dive = get_dive(1);
QVERIFY(dive != NULL); QVERIFY(dive != NULL);
@ -404,8 +383,7 @@ void TestGitStorage::testGitStorageCloudMerge2()
// (4) move the saved local cache backinto place and try to open the cloud repo // (4) move the saved local cache backinto place and try to open the cloud repo
// -> this forces a merge // -> this forces a merge
moveDir(localCacheDir + "save", localCacheDir); moveDir(localCacheDir + "save", localCacheDir);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(save_dives("./SampleDivesMinus1-merged.ssrf"), 0); QCOMPARE(save_dives("./SampleDivesMinus1-merged.ssrf"), 0);
QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0); QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
QFile org("./SampleDivesMinus1-merged.ssrf"); QFile org("./SampleDivesMinus1-merged.ssrf");
@ -428,8 +406,7 @@ void TestGitStorage::testGitStorageCloudMerge3()
// (1) open repo, edit notes of first three dives // (1) open repo, edit notes of first three dives
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
&dive_site_table, &device_table, &filter_preset_table), 0);
process_loaded_dives(); process_loaded_dives();
struct dive *dive; struct dive *dive;
QVERIFY((dive = get_dive(0)) != 0); QVERIFY((dive = get_dive(0)) != 0);
@ -445,8 +422,7 @@ void TestGitStorage::testGitStorageCloudMerge3()
clear_dive_file_data(); clear_dive_file_data();
// (2) make different edits offline // (2) make different edits offline
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
&dive_site_table, &device_table, &filter_preset_table), 0);
process_loaded_dives(); process_loaded_dives();
QVERIFY((dive = get_dive(0)) != 0); QVERIFY((dive = get_dive(0)) != 0);
free(dive->notes); free(dive->notes);
@ -465,8 +441,7 @@ void TestGitStorage::testGitStorageCloudMerge3()
// (3) simulate a second system by moving the cache away and open the cloud storage repo and modify // (3) simulate a second system by moving the cache away and open the cloud storage repo and modify
// those first dive notes differently while online // those first dive notes differently while online
moveDir(localCacheDir, localCacheDir + "save"); moveDir(localCacheDir, localCacheDir + "save");
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
&dive_site_table, &device_table, &filter_preset_table), 0);
process_loaded_dives(); process_loaded_dives();
QVERIFY((dive = get_dive(0)) != 0); QVERIFY((dive = get_dive(0)) != 0);
free(dive->notes); free(dive->notes);
@ -482,8 +457,7 @@ void TestGitStorage::testGitStorageCloudMerge3()
// (4) move the saved local cache back into place and open the cloud repo -> this forces a merge // (4) move the saved local cache back into place and open the cloud repo -> this forces a merge
moveDir(localCacheDir + "save", localCacheDir); moveDir(localCacheDir + "save", localCacheDir);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(save_dives("./SampleDivesMerge3.ssrf"), 0); QCOMPARE(save_dives("./SampleDivesMerge3.ssrf"), 0);
// we are not trying to compare this to a pre-determined result... what this test // we are not trying to compare this to a pre-determined result... what this test
// checks is that there are no parsing errors with the merge // checks is that there are no parsing errors with the merge

View file

@ -2,6 +2,7 @@
#include "testmerge.h" #include "testmerge.h"
#include "core/device.h" #include "core/device.h"
#include "core/dive.h" // for save_dives() #include "core/dive.h" // for save_dives()
#include "core/divelog.h"
#include "core/divesite.h" #include "core/divesite.h"
#include "core/file.h" #include "core/file.h"
#include "core/trip.h" #include "core/trip.h"
@ -25,15 +26,11 @@ void TestMerge::testMergeEmpty()
/* /*
* check that we correctly merge mixed cylinder dives * check that we correctly merge mixed cylinder dives
*/ */
struct dive_table table = empty_dive_table; struct divelog log;
struct trip_table trips = empty_trip_table; QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &log), 0);
struct dive_site_table sites = empty_dive_site_table; add_imported_dives(&log, IMPORT_MERGE_ALL_TRIPS);
struct device_table devices; QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &log), 0);
struct filter_preset_table filter_presets; add_imported_dives(&log, IMPORT_MERGE_ALL_TRIPS);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &table, &trips, &sites, &devices, &filter_presets), 0);
add_imported_dives(&table, &trips, &sites, &devices, IMPORT_MERGE_ALL_TRIPS);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &table, &trips, &sites, &devices, &filter_presets), 0);
add_imported_dives(&table, &trips, &sites, &devices, IMPORT_MERGE_ALL_TRIPS);
QCOMPARE(save_dives("./testmerge47+48.ssrf"), 0); QCOMPARE(save_dives("./testmerge47+48.ssrf"), 0);
QFile org(SUBSURFACE_TEST_DATA "/dives/test47+48.xml"); QFile org(SUBSURFACE_TEST_DATA "/dives/test47+48.xml");
org.open(QFile::ReadOnly); org.open(QFile::ReadOnly);
@ -43,9 +40,8 @@ void TestMerge::testMergeEmpty()
QTextStream outS(&out); QTextStream outS(&out);
QStringList readin = orgS.readAll().split("\n"); QStringList readin = orgS.readAll().split("\n");
QStringList written = outS.readAll().split("\n"); QStringList written = outS.readAll().split("\n");
while (readin.size() && written.size()) { while (readin.size() && written.size())
QCOMPARE(written.takeFirst().trimmed(), readin.takeFirst().trimmed()); QCOMPARE(written.takeFirst().trimmed(), readin.takeFirst().trimmed());
}
} }
void TestMerge::testMergeBackwards() void TestMerge::testMergeBackwards()
@ -53,15 +49,11 @@ void TestMerge::testMergeBackwards()
/* /*
* check that we correctly merge mixed cylinder dives * check that we correctly merge mixed cylinder dives
*/ */
struct dive_table table = empty_dive_table; struct divelog log;
struct trip_table trips = empty_trip_table; QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &log), 0);
struct dive_site_table sites = empty_dive_site_table; add_imported_dives(&log, IMPORT_MERGE_ALL_TRIPS);
struct device_table devices; QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &log), 0);
struct filter_preset_table filter_presets; add_imported_dives(&log, IMPORT_MERGE_ALL_TRIPS);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &table, &trips, &sites, &devices, &filter_presets), 0);
add_imported_dives(&table, &trips, &sites, &devices, IMPORT_MERGE_ALL_TRIPS);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &table, &trips, &sites, &devices, &filter_presets), 0);
add_imported_dives(&table, &trips, &sites, &devices, IMPORT_MERGE_ALL_TRIPS);
QCOMPARE(save_dives("./testmerge47+48.ssrf"), 0); QCOMPARE(save_dives("./testmerge47+48.ssrf"), 0);
QFile org(SUBSURFACE_TEST_DATA "/dives/test48+47.xml"); QFile org(SUBSURFACE_TEST_DATA "/dives/test48+47.xml");
org.open(QFile::ReadOnly); org.open(QFile::ReadOnly);
@ -71,9 +63,8 @@ void TestMerge::testMergeBackwards()
QTextStream outS(&out); QTextStream outS(&out);
QStringList readin = orgS.readAll().split("\n"); QStringList readin = orgS.readAll().split("\n");
QStringList written = outS.readAll().split("\n"); QStringList written = outS.readAll().split("\n");
while (readin.size() && written.size()) { while (readin.size() && written.size())
QCOMPARE(written.takeFirst().trimmed(), readin.takeFirst().trimmed()); QCOMPARE(written.takeFirst().trimmed(), readin.takeFirst().trimmed());
}
} }
QTEST_GUILESS_MAIN(TestMerge) QTEST_GUILESS_MAIN(TestMerge)

View file

@ -2,6 +2,7 @@
#include "testparse.h" #include "testparse.h"
#include "core/device.h" #include "core/device.h"
#include "core/dive.h" #include "core/dive.h"
#include "core/divelog.h"
#include "core/divesite.h" #include "core/divesite.h"
#include "core/errorhelper.h" #include "core/errorhelper.h"
#include "core/trip.h" #include "core/trip.h"
@ -85,19 +86,18 @@ int TestParse::parseCSV(int units, std::string file)
xml_params_add_int(&params, "airtempField", -1); xml_params_add_int(&params, "airtempField", -1);
xml_params_add_int(&params, "watertempField", -1); xml_params_add_int(&params, "watertempField", -1);
return parse_manual_file(file.c_str(), &params, &dive_table, &trip_table, return parse_manual_file(file.c_str(), &params, &divelog);
&dive_site_table, &device_table, &filter_preset_table);
} }
int TestParse::parseDivingLog() int TestParse::parseDivingLog()
{ {
// Parsing of DivingLog import from SQLite database // Parsing of DivingLog import from SQLite database
struct dive_site *ds = alloc_or_get_dive_site(0xdeadbeef, &dive_site_table); struct dive_site *ds = alloc_or_get_dive_site(0xdeadbeef, divelog.sites);
ds->name = copy_string("Suomi - - Hälvälä"); ds->name = copy_string("Suomi - - Hälvälä");
int ret = sqlite3_open(SUBSURFACE_TEST_DATA "/dives/TestDivingLog4.1.1.sql", &_sqlite3_handle); int ret = sqlite3_open(SUBSURFACE_TEST_DATA "/dives/TestDivingLog4.1.1.sql", &_sqlite3_handle);
if (ret == 0) if (ret == 0)
ret = parse_divinglog_buffer(_sqlite3_handle, 0, 0, 0, &dive_table, &trip_table, &dive_site_table, &device_table); ret = parse_divinglog_buffer(_sqlite3_handle, 0, 0, 0, &divelog);
else else
fprintf(stderr, "Can't open sqlite3 db: " SUBSURFACE_TEST_DATA "/dives/TestDivingLog4.1.1.sql"); fprintf(stderr, "Can't open sqlite3 db: " SUBSURFACE_TEST_DATA "/dives/TestDivingLog4.1.1.sql");
@ -107,30 +107,28 @@ int TestParse::parseDivingLog()
int TestParse::parseV2NoQuestion() int TestParse::parseV2NoQuestion()
{ {
// parsing of a V2 file should work // parsing of a V2 file should work
return parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table, return parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &divelog);
&dive_site_table, &device_table, &filter_preset_table);
} }
int TestParse::parseV3() int TestParse::parseV3()
{ {
// parsing of a V3 files should succeed // parsing of a V3 files should succeed
return parse_file(SUBSURFACE_TEST_DATA "/dives/test42.xml", &dive_table, &trip_table, return parse_file(SUBSURFACE_TEST_DATA "/dives/test42.xml", &divelog);
&dive_site_table, &device_table, &filter_preset_table);
} }
void TestParse::testParse() void TestParse::testParse()
{ {
QCOMPARE(parseCSV(0, SUBSURFACE_TEST_DATA "/dives/test41.csv"), 0); QCOMPARE(parseCSV(0, SUBSURFACE_TEST_DATA "/dives/test41.csv"), 0);
fprintf(stderr, "number of dives %d \n", dive_table.nr); fprintf(stderr, "number of dives %d \n", divelog.dives->nr);
QCOMPARE(parseDivingLog(), 0); QCOMPARE(parseDivingLog(), 0);
fprintf(stderr, "number of dives %d \n", dive_table.nr); fprintf(stderr, "number of dives %d \n", divelog.dives->nr);
QCOMPARE(parseV2NoQuestion(), 0); QCOMPARE(parseV2NoQuestion(), 0);
fprintf(stderr, "number of dives %d \n", dive_table.nr); fprintf(stderr, "number of dives %d \n", divelog.dives->nr);
QCOMPARE(parseV3(), 0); QCOMPARE(parseV3(), 0);
fprintf(stderr, "number of dives %d \n", dive_table.nr); fprintf(stderr, "number of dives %d \n", divelog.dives->nr);
QCOMPARE(save_dives("./testout.ssrf"), 0); QCOMPARE(save_dives("./testout.ssrf"), 0);
FILE_COMPARE("./testout.ssrf", FILE_COMPARE("./testout.ssrf",
@ -140,7 +138,7 @@ void TestParse::testParse()
void TestParse::testParseDM4() void TestParse::testParseDM4()
{ {
QCOMPARE(sqlite3_open(SUBSURFACE_TEST_DATA "/dives/TestDiveDM4.db", &_sqlite3_handle), 0); QCOMPARE(sqlite3_open(SUBSURFACE_TEST_DATA "/dives/TestDiveDM4.db", &_sqlite3_handle), 0);
QCOMPARE(parse_dm4_buffer(_sqlite3_handle, 0, 0, 0, &dive_table, &trip_table, &dive_site_table, &device_table), 0); QCOMPARE(parse_dm4_buffer(_sqlite3_handle, 0, 0, 0, &divelog), 0);
QCOMPARE(save_dives("./testdm4out.ssrf"), 0); QCOMPARE(save_dives("./testdm4out.ssrf"), 0);
FILE_COMPARE("./testdm4out.ssrf", FILE_COMPARE("./testdm4out.ssrf",
@ -150,7 +148,7 @@ void TestParse::testParseDM4()
void TestParse::testParseDM5() void TestParse::testParseDM5()
{ {
QCOMPARE(sqlite3_open(SUBSURFACE_TEST_DATA "/dives/TestDiveDM5.db", &_sqlite3_handle), 0); QCOMPARE(sqlite3_open(SUBSURFACE_TEST_DATA "/dives/TestDiveDM5.db", &_sqlite3_handle), 0);
QCOMPARE(parse_dm5_buffer(_sqlite3_handle, 0, 0, 0, &dive_table, &trip_table, &dive_site_table, &device_table), 0); QCOMPARE(parse_dm5_buffer(_sqlite3_handle, 0, 0, 0, &divelog), 0);
QCOMPARE(save_dives("./testdm5out.ssrf"), 0); QCOMPARE(save_dives("./testdm5out.ssrf"), 0);
FILE_COMPARE("./testdm5out.ssrf", FILE_COMPARE("./testdm5out.ssrf",
@ -179,18 +177,17 @@ void TestParse::testParseHUDC()
xml_params_add(&params, "hw", "\"DC text\""); xml_params_add(&params, "hw", "\"DC text\"");
QCOMPARE(parse_csv_file(SUBSURFACE_TEST_DATA "/dives/TestDiveSeabearHUDC.csv", QCOMPARE(parse_csv_file(SUBSURFACE_TEST_DATA "/dives/TestDiveSeabearHUDC.csv",
&params, "csv", &dive_table, &trip_table, &dive_site_table, &params, "csv", &divelog),
&device_table, &filter_preset_table),
0); 0);
QCOMPARE(dive_table.nr, 1); QCOMPARE(divelog.dives->nr, 1);
/* /*
* CSV import uses time and date stamps relative to current * CSV import uses time and date stamps relative to current
* time, thus we need to use a static (random) timestamp * time, thus we need to use a static (random) timestamp
*/ */
if (dive_table.nr > 0) { if (divelog.dives->nr > 0) {
struct dive *dive = dive_table.dives[dive_table.nr - 1]; struct dive *dive = divelog.dives->dives[divelog.dives->nr - 1];
dive->when = 1255152761; dive->when = 1255152761;
dive->dc.when = 1255152761; dive->dc.when = 1255152761;
} }
@ -225,13 +222,12 @@ void TestParse::testParseNewFormat()
"/dives/") "/dives/")
.append(files.at(i)) .append(files.at(i))
.toLatin1() .toLatin1()
.data(), &dive_table, &trip_table, &dive_site_table, .data(), &divelog),
&device_table, &filter_preset_table),
0); 0);
QCOMPARE(dive_table.nr, i + 1); QCOMPARE(divelog.dives->nr, i + 1);
} }
fprintf(stderr, "number of dives %d \n", dive_table.nr); fprintf(stderr, "number of dives %d \n", divelog.dives->nr);
QCOMPARE(save_dives("./testsbnewout.ssrf"), 0); QCOMPARE(save_dives("./testsbnewout.ssrf"), 0);
// Currently the CSV parse fails // Currently the CSV parse fails
@ -245,9 +241,9 @@ void TestParse::testParseDLD()
QString filename = SUBSURFACE_TEST_DATA "/dives/TestDiveDivelogsDE.DLD"; QString filename = SUBSURFACE_TEST_DATA "/dives/TestDiveDivelogsDE.DLD";
QVERIFY(readfile(filename.toLatin1().data(), &mem) > 0); QVERIFY(readfile(filename.toLatin1().data(), &mem) > 0);
QVERIFY(try_to_open_zip(filename.toLatin1().data(), &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table) > 0); QVERIFY(try_to_open_zip(filename.toLatin1().data(), &divelog) > 0);
fprintf(stderr, "number of dives from DLD: %d \n", dive_table.nr); fprintf(stderr, "number of dives from DLD: %d \n", divelog.dives->nr);
// Compare output // Compare output
QCOMPARE(save_dives("./testdldout.ssrf"), 0); QCOMPARE(save_dives("./testdldout.ssrf"), 0);
@ -260,10 +256,8 @@ void TestParse::testParseMerge()
/* /*
* check that we correctly merge mixed cylinder dives * check that we correctly merge mixed cylinder dives
*/ */
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/ostc.xml", &dive_table, &trip_table, &dive_site_table, QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/ostc.xml", &divelog), 0);
&device_table, &filter_preset_table), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/vyper.xml", &divelog), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/vyper.xml", &dive_table, &trip_table, &dive_site_table,
&device_table, &filter_preset_table), 0);
QCOMPARE(save_dives("./testmerge.ssrf"), 0); QCOMPARE(save_dives("./testmerge.ssrf"), 0);
FILE_COMPARE("./testmerge.ssrf", FILE_COMPARE("./testmerge.ssrf",
SUBSURFACE_TEST_DATA "/dives/mergedVyperOstc.xml"); SUBSURFACE_TEST_DATA "/dives/mergedVyperOstc.xml");
@ -303,22 +297,20 @@ int TestParse::parseCSVmanual(int units, std::string file)
xml_params_add_int(&params, "datefmt", 2); xml_params_add_int(&params, "datefmt", 2);
xml_params_add_int(&params, "durationfmt", 2); xml_params_add_int(&params, "durationfmt", 2);
xml_params_add_int(&params, "units", units); xml_params_add_int(&params, "units", units);
return parse_manual_file(file.c_str(), &params, &dive_table, &trip_table, return parse_manual_file(file.c_str(), &params, &divelog);
&dive_site_table, &device_table, &filter_preset_table);
} }
void TestParse::exportCSVDiveDetails() void TestParse::exportCSVDiveDetails()
{ {
int saved_sac = 0; int saved_sac = 0;
parse_file(SUBSURFACE_TEST_DATA "/dives/test25.xml", &dive_table, &trip_table, &dive_site_table, parse_file(SUBSURFACE_TEST_DATA "/dives/test25.xml", &divelog);
&device_table, &filter_preset_table);
export_dives_xslt("testcsvexportmanual.csv", 0, 0, "xml2manualcsv.xslt", false); export_dives_xslt("testcsvexportmanual.csv", 0, 0, "xml2manualcsv.xslt", false);
export_dives_xslt("testcsvexportmanualimperial.csv", 0, 1, "xml2manualcsv.xslt", false); export_dives_xslt("testcsvexportmanualimperial.csv", 0, 1, "xml2manualcsv.xslt", false);
if (dive_table.nr > 0) { if (divelog.dives->nr > 0) {
struct dive *dive = dive_table.dives[dive_table.nr - 1]; struct dive *dive = divelog.dives->dives[divelog.dives->nr - 1];
saved_sac = dive->sac; saved_sac = dive->sac;
} }
clear_dive_file_data(); clear_dive_file_data();
@ -326,8 +318,8 @@ void TestParse::exportCSVDiveDetails()
parseCSVmanual(1, "testcsvexportmanualimperial.csv"); parseCSVmanual(1, "testcsvexportmanualimperial.csv");
// We do not currently support reading SAC, thus faking it // We do not currently support reading SAC, thus faking it
if (dive_table.nr > 0) { if (divelog.dives->nr > 0) {
struct dive *dive = dive_table.dives[dive_table.nr - 1]; struct dive *dive = divelog.dives->dives[divelog.dives->nr - 1];
dive->sac = saved_sac; dive->sac = saved_sac;
} }
@ -347,14 +339,13 @@ void TestParse::exportSubsurfaceCSV()
xml_params params; xml_params params;
/* Test SubsurfaceCSV with multiple cylinders */ /* Test SubsurfaceCSV with multiple cylinders */
parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table, parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &divelog);
&dive_site_table, &device_table, &filter_preset_table);
export_dives_xslt("testcsvexportmanual-cyl.csv", 0, 0, "xml2manualcsv.xslt", false); export_dives_xslt("testcsvexportmanual-cyl.csv", 0, 0, "xml2manualcsv.xslt", false);
export_dives_xslt("testcsvexportmanualimperial-cyl.csv", 0, 1, "xml2manualcsv.xslt", false); export_dives_xslt("testcsvexportmanualimperial-cyl.csv", 0, 1, "xml2manualcsv.xslt", false);
if (dive_table.nr > 0) { if (divelog.dives->nr > 0) {
struct dive *dive = dive_table.dives[dive_table.nr - 1]; struct dive *dive = divelog.dives->dives[divelog.dives->nr - 1];
saved_sac = dive->sac; saved_sac = dive->sac;
} }
@ -362,12 +353,11 @@ void TestParse::exportSubsurfaceCSV()
xml_params_add_int(&params, "separatorIndex", 0); xml_params_add_int(&params, "separatorIndex", 0);
xml_params_add_int(&params, "units", 1); xml_params_add_int(&params, "units", 1);
parse_csv_file("testcsvexportmanualimperial-cyl.csv", &params, "SubsurfaceCSV", &dive_table, &trip_table, parse_csv_file("testcsvexportmanualimperial-cyl.csv", &params, "SubsurfaceCSV", &divelog);
&dive_site_table, &device_table, &filter_preset_table);
// We do not currently support reading SAC, thus faking it // We do not currently support reading SAC, thus faking it
if (dive_table.nr > 0) { if (divelog.dives->nr > 0) {
struct dive *dive = dive_table.dives[dive_table.nr - 1]; struct dive *dive = divelog.dives->dives[divelog.dives->nr - 1];
dive->sac = saved_sac; dive->sac = saved_sac;
} }
@ -396,14 +386,12 @@ int TestParse::parseCSVprofile(int units, std::string file)
xml_params_add_int(&params, "datefmt", 2); xml_params_add_int(&params, "datefmt", 2);
xml_params_add_int(&params, "units", units); xml_params_add_int(&params, "units", units);
return parse_csv_file(file.c_str(), &params, "csv", &dive_table, &trip_table, return parse_csv_file(file.c_str(), &params, "csv", &divelog);
&dive_site_table, &device_table, &filter_preset_table);
} }
void TestParse::exportCSVDiveProfile() void TestParse::exportCSVDiveProfile()
{ {
parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table, parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &divelog);
&dive_site_table, &device_table, &filter_preset_table);
export_dives_xslt("testcsvexportprofile.csv", 0, 0, "xml2csv.xslt", false); export_dives_xslt("testcsvexportprofile.csv", 0, 0, "xml2csv.xslt", false);
export_dives_xslt("testcsvexportprofileimperial.csv", 0, 1, "xml2csv.xslt", false); export_dives_xslt("testcsvexportprofileimperial.csv", 0, 1, "xml2csv.xslt", false);
@ -421,14 +409,13 @@ void TestParse::exportCSVDiveProfile()
void TestParse::exportUDDF() void TestParse::exportUDDF()
{ {
parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table, parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &divelog);
&dive_site_table, &device_table, &filter_preset_table);
export_dives_xslt("testuddfexport.uddf", 0, 1, "uddf-export.xslt", false); export_dives_xslt("testuddfexport.uddf", 0, 1, "uddf-export.xslt", false);
clear_dive_file_data(); clear_dive_file_data();
parse_file("testuddfexport.uddf", &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table); parse_file("testuddfexport.uddf", &divelog);
export_dives_xslt("testuddfexport2.uddf", 0, 1, "uddf-export.xslt", false); export_dives_xslt("testuddfexport2.uddf", 0, 1, "uddf-export.xslt", false);
FILE_COMPARE("testuddfexport.uddf", FILE_COMPARE("testuddfexport.uddf",
@ -472,9 +459,9 @@ void TestParse::parseDL7()
clear_dive_file_data(); clear_dive_file_data();
QCOMPARE(parse_csv_file(SUBSURFACE_TEST_DATA "/dives/DL7.zxu", QCOMPARE(parse_csv_file(SUBSURFACE_TEST_DATA "/dives/DL7.zxu",
&params, "DL7", &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table), &params, "DL7", &divelog),
0); 0);
QCOMPARE(dive_table.nr, 3); QCOMPARE(divelog.dives->nr, 3);
QCOMPARE(save_dives("./testdl7out.ssrf"), 0); QCOMPARE(save_dives("./testdl7out.ssrf"), 0);
FILE_COMPARE("./testdl7out.ssrf", FILE_COMPARE("./testdl7out.ssrf",

View file

@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include "testparseperformance.h" #include "testparseperformance.h"
#include "core/device.h" #include "core/device.h"
#include "core/divelog.h"
#include "core/divesite.h" #include "core/divesite.h"
#include "core/trip.h" #include "core/trip.h"
#include "core/file.h" #include "core/file.h"
@ -65,8 +66,7 @@ void TestParsePerformance::parseSsrf()
return; return;
} }
QBENCHMARK { QBENCHMARK {
parse_file(SUBSURFACE_TEST_DATA "/dives/large-anon.ssrf", &dive_table, &trip_table, parse_file(SUBSURFACE_TEST_DATA "/dives/large-anon.ssrf", &divelog);
&dive_site_table, &device_table, &filter_preset_table);
} }
} }
@ -77,14 +77,12 @@ void TestParsePerformance::parseGit()
// first parse this once to populate the local cache - this way network // first parse this once to populate the local cache - this way network
// effects don't dominate the parse time // effects don't dominate the parse time
parse_file(LARGE_TEST_REPO "[git]", &dive_table, &trip_table, &dive_site_table, parse_file(LARGE_TEST_REPO "[git]", &divelog);
&device_table, &filter_preset_table);
cleanup(); cleanup();
QBENCHMARK { QBENCHMARK {
parse_file(LARGE_TEST_REPO "[git]", &dive_table, &trip_table, &dive_site_table, parse_file(LARGE_TEST_REPO "[git]", &divelog);
&device_table, &filter_preset_table);
} }
} }

View file

@ -2,10 +2,9 @@
#include "testpicture.h" #include "testpicture.h"
#include "core/device.h" #include "core/device.h"
#include "core/dive.h" #include "core/dive.h"
#include "core/divesite.h" #include "core/divelog.h"
#include "core/errorhelper.h" #include "core/errorhelper.h"
#include "core/picture.h" #include "core/picture.h"
#include "core/trip.h"
#include "core/file.h" #include "core/file.h"
#include "core/pref.h" #include "core/pref.h"
#include <QString> #include <QString>
@ -29,7 +28,7 @@ void TestPicture::addPicture()
struct picture *pic1, *pic2; struct picture *pic1, *pic2;
verbose = 1; verbose = 1;
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test44.xml", &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test44.xml", &divelog), 0);
dive = get_dive(0); dive = get_dive(0);
// Pictures will be added to selected dives // Pictures will be added to selected dives
dive->selected = true; dive->selected = true;

View file

@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include "testprofile.h" #include "testprofile.h"
#include "core/device.h" #include "core/device.h"
#include "core/divelog.h"
#include "core/divesite.h" #include "core/divesite.h"
#include "core/trip.h" #include "core/trip.h"
#include "core/file.h" #include "core/file.h"
@ -34,7 +35,7 @@ void TestProfile::init()
void TestProfile::testProfileExport() void TestProfile::testProfileExport()
{ {
prefs.planner_deco_mode = BUEHLMANN; prefs.planner_deco_mode = BUEHLMANN;
parse_file(SUBSURFACE_TEST_DATA "/dives/abitofeverything.ssrf", &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table); parse_file(SUBSURFACE_TEST_DATA "/dives/abitofeverything.ssrf", &divelog);
save_profiledata("exportprofile.csv", false); save_profiledata("exportprofile.csv", false);
QFile org(SUBSURFACE_TEST_DATA "/dives/exportprofilereference.csv"); QFile org(SUBSURFACE_TEST_DATA "/dives/exportprofilereference.csv");
QCOMPARE(org.open(QFile::ReadOnly), true); QCOMPARE(org.open(QFile::ReadOnly), true);
@ -50,7 +51,7 @@ void TestProfile::testProfileExport()
void TestProfile::testProfileExportVPMB() void TestProfile::testProfileExportVPMB()
{ {
prefs.planner_deco_mode = VPMB; prefs.planner_deco_mode = VPMB;
parse_file(SUBSURFACE_TEST_DATA "/dives/abitofeverything.ssrf", &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table); parse_file(SUBSURFACE_TEST_DATA "/dives/abitofeverything.ssrf", &divelog);
save_profiledata("exportprofileVPMB.csv", false); save_profiledata("exportprofileVPMB.csv", false);
QFile org(SUBSURFACE_TEST_DATA "/dives/exportprofilereferenceVPMB.csv"); QFile org(SUBSURFACE_TEST_DATA "/dives/exportprofilereferenceVPMB.csv");
QCOMPARE(org.open(QFile::ReadOnly), true); QCOMPARE(org.open(QFile::ReadOnly), true);

View file

@ -2,6 +2,7 @@
#include "testrenumber.h" #include "testrenumber.h"
#include "core/device.h" #include "core/device.h"
#include "core/dive.h" #include "core/dive.h"
#include "core/divelog.h"
#include "core/divesite.h" #include "core/divesite.h"
#include "core/trip.h" #include "core/trip.h"
#include "core/file.h" #include "core/file.h"
@ -11,32 +12,24 @@
void TestRenumber::setup() void TestRenumber::setup()
{ {
prefs.cloud_base_url = strdup(default_prefs.cloud_base_url); prefs.cloud_base_url = strdup(default_prefs.cloud_base_url);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &divelog), 0);
process_loaded_dives(); process_loaded_dives();
} }
void TestRenumber::testMerge() void TestRenumber::testMerge()
{ {
struct dive_table table = empty_dive_table; struct divelog log;
struct trip_table trips = empty_trip_table; QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47b.xml", &log), 0);
struct dive_site_table sites = empty_dive_site_table; add_imported_dives(&log, IMPORT_MERGE_ALL_TRIPS);
struct device_table devices; QCOMPARE(divelog.dives->nr, 1);
struct filter_preset_table filter_presets;
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47b.xml", &table, &trips, &sites, &devices, &filter_presets), 0);
add_imported_dives(&table, &trips, &sites, &devices, IMPORT_MERGE_ALL_TRIPS);
QCOMPARE(dive_table.nr, 1);
} }
void TestRenumber::testMergeAndAppend() void TestRenumber::testMergeAndAppend()
{ {
struct dive_table table = empty_dive_table; struct divelog log;
struct trip_table trips = empty_trip_table; QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47c.xml", &log), 0);
struct dive_site_table sites = empty_dive_site_table; add_imported_dives(&log, IMPORT_MERGE_ALL_TRIPS);
struct device_table devices; QCOMPARE(divelog.dives->nr, 2);
struct filter_preset_table filter_presets;
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47c.xml", &table, &trips, &sites, &devices, &filter_presets), 0);
add_imported_dives(&table, &trips, &sites, &devices, IMPORT_MERGE_ALL_TRIPS);
QCOMPARE(dive_table.nr, 2);
struct dive *d = get_dive(1); struct dive *d = get_dive(1);
QVERIFY(d != NULL); QVERIFY(d != NULL);
if (d) if (d)