mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-27 20:58:47 +00:00
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:
parent
eebb47ec22
commit
9c253ee6c5
81 changed files with 661 additions and 698 deletions
|
@ -55,6 +55,7 @@ SOURCES += subsurface-mobile-main.cpp \
|
|||
core/filterconstraint.cpp \
|
||||
core/filterpreset.cpp \
|
||||
core/divelist.c \
|
||||
core/divelog.cpp \
|
||||
core/gas-model.c \
|
||||
core/gaspressures.c \
|
||||
core/git-access.c \
|
||||
|
@ -227,6 +228,7 @@ HEADERS += \
|
|||
core/filterconstraint.h \
|
||||
core/filterpreset.h \
|
||||
core/divelist.h \
|
||||
core/divelog.h \
|
||||
core/divelogexportlogic.h \
|
||||
core/divesitehelpers.h \
|
||||
core/exif.h \
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "exportfuncs.h"
|
||||
#include "core/membuffer.h"
|
||||
#include "core/dive.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/divesite.h"
|
||||
#include "core/gettextfromc.h"
|
||||
#include "core/tag.h"
|
||||
|
@ -62,7 +63,7 @@ void exportProfile(QString filename, bool selected_only, ExportCallback &cb)
|
|||
filename = filename.append(".png");
|
||||
QFileInfo fi(filename);
|
||||
|
||||
int todo = selected_only ? amount_selected : dive_table.nr;
|
||||
int todo = selected_only ? amount_selected : divelog.dives->nr;
|
||||
int done = 0;
|
||||
auto profile = getPrintProfile();
|
||||
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");
|
||||
|
||||
int todo = selected_only ? amount_selected : dive_table.nr;
|
||||
int todo = selected_only ? amount_selected : divelog.dives->nr;
|
||||
int done = 0;
|
||||
auto profile = getPrintProfile();
|
||||
for_each_dive (i, dive) {
|
||||
|
@ -330,9 +331,9 @@ std::vector<const dive_site *> getDiveSitesToExport(bool selectedOnly)
|
|||
return res;
|
||||
}
|
||||
|
||||
res.reserve(dive_site_table.nr);
|
||||
for (int i = 0; i < dive_site_table.nr; i++) {
|
||||
struct dive_site *ds = get_dive_site(i, &dive_site_table);
|
||||
res.reserve(divelog.sites->nr);
|
||||
for (int i = 0; i < divelog.sites->nr; i++) {
|
||||
struct dive_site *ds = get_dive_site(i, divelog.sites);
|
||||
if (dive_site_is_empty(ds))
|
||||
continue;
|
||||
if (selectedOnly && !is_dive_site_selected(ds))
|
||||
|
@ -343,8 +344,8 @@ std::vector<const dive_site *> getDiveSitesToExport(bool selectedOnly)
|
|||
/* walk the dive site list */
|
||||
int i;
|
||||
const struct dive_site *ds;
|
||||
for_each_dive_site (i, ds, &dive_site_table)
|
||||
res.push_back(get_dive_site(i, &dive_site_table));
|
||||
for_each_dive_site (i, ds, divelog.sites)
|
||||
res.push_back(get_dive_site(i, divelog.sites));
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "command.h"
|
||||
#include "command_base.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/globals.h"
|
||||
#include "core/qthelper.h" // for updateWindowTitle()
|
||||
#include "core/subsurface-qt/divelistnotifier.h"
|
||||
|
@ -65,7 +66,7 @@ QString diveNumberOrDate(struct dive *d)
|
|||
QString getListOfDives(const std::vector<struct dive*> &dives)
|
||||
{
|
||||
QString listOfDives;
|
||||
if ((int)dives.size() == dive_table.nr)
|
||||
if ((int)dives.size() == divelog.dives->nr)
|
||||
return Base::tr("all dives");
|
||||
int i = 0;
|
||||
for (dive *d: dives) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
#include "command_device.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/subsurface-qt/divelistnotifier.h"
|
||||
|
||||
namespace Command {
|
||||
|
@ -8,7 +9,7 @@ namespace Command {
|
|||
EditDeviceNickname::EditDeviceNickname(const struct divecomputer *dc, const QString &nicknameIn) :
|
||||
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)
|
||||
return;
|
||||
|
||||
|
@ -17,12 +18,12 @@ EditDeviceNickname::EditDeviceNickname(const struct divecomputer *dc, const QStr
|
|||
|
||||
bool EditDeviceNickname::workToBeDone()
|
||||
{
|
||||
return get_device(&device_table, index) != nullptr;
|
||||
return get_device(divelog.devices, index) != nullptr;
|
||||
}
|
||||
|
||||
void EditDeviceNickname::redo()
|
||||
{
|
||||
device *dev = get_device_mutable(&device_table, index);
|
||||
device *dev = get_device_mutable(divelog.devices, index);
|
||||
if (!dev)
|
||||
return;
|
||||
std::swap(dev->nickName, nickname);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "command_divelist.h"
|
||||
#include "core/divelist.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/qthelper.h"
|
||||
#include "core/selection.h"
|
||||
#include "core/subsurface-qt/divelistnotifier.h"
|
||||
|
@ -17,7 +18,7 @@ static void remove_trip_from_backend(dive_trip *trip)
|
|||
{
|
||||
if (trip->selected)
|
||||
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.
|
||||
|
@ -77,9 +78,9 @@ dive *DiveListBase::addDive(DiveToAdd &d)
|
|||
// dives have been added, their status will be updated.
|
||||
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
|
||||
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()
|
||||
|
||||
return res;
|
||||
|
@ -210,7 +211,7 @@ DivesAndSitesToRemove DiveListBase::addDives(DivesAndTripsToAdd &toAdd)
|
|||
addedTrips.reserve(toAdd.trips.size());
|
||||
for (OwningTripPtr &trip: toAdd.trips) {
|
||||
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();
|
||||
|
||||
|
@ -300,7 +301,7 @@ static void moveDivesBetweenTrips(DivesToTrip &dives)
|
|||
for (OwningTripPtr &trip: dives.tripsToAdd) {
|
||||
dive_trip *t = trip.release(); // Give up ownership
|
||||
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();
|
||||
|
||||
|
@ -430,7 +431,7 @@ AddDive::AddDive(dive *d, bool autogroup, bool newNumber)
|
|||
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)
|
||||
divePtr->number = get_dive_nr_at_idx(idx);
|
||||
|
||||
|
@ -451,7 +452,7 @@ void AddDive::redoit()
|
|||
currentDive = current_dive;
|
||||
|
||||
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
|
||||
setSelection(divesAndSitesToRemove.dives, divesAndSitesToRemove.dives[0]);
|
||||
|
@ -461,7 +462,7 @@ void AddDive::undoit()
|
|||
{
|
||||
// Simply remove the dive that was previously added...
|
||||
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
|
||||
setSelection(selection, currentDive);
|
||||
|
@ -517,9 +518,9 @@ ImportDives::ImportDives(struct dive_table *dives, struct trip_table *trips, str
|
|||
if (filter_presets) {
|
||||
for (const filter_preset &preset: *filter_presets) {
|
||||
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; });
|
||||
if (it != filter_preset_table.end() && it->data == preset.data)
|
||||
if (it != divelog.filter_presets->end() && it->data == preset.data)
|
||||
continue;
|
||||
filterPresetsToAdd.emplace_back(preset.name, preset.data);
|
||||
}
|
||||
|
@ -553,7 +554,7 @@ void ImportDives::redoit()
|
|||
|
||||
// Add 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
|
||||
for (auto &it: filterPresetsToAdd) {
|
||||
|
@ -581,7 +582,7 @@ void ImportDives::undoit()
|
|||
|
||||
// Remove 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.
|
||||
for (auto it = filterPresetsToRemove.rbegin(); it != filterPresetsToRemove.rend(); ++it) {
|
||||
|
@ -610,7 +611,7 @@ bool DeleteDive::workToBeDone()
|
|||
void DeleteDive::undoit()
|
||||
{
|
||||
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
|
||||
dive *currentDive = !divesToDelete.dives.empty() ? divesToDelete.dives[0] : nullptr;
|
||||
|
@ -620,7 +621,7 @@ void DeleteDive::undoit()
|
|||
void DeleteDive::redoit()
|
||||
{
|
||||
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
|
||||
dive *newCurrent = nullptr;
|
||||
|
@ -648,8 +649,8 @@ void ShiftTime::redoit()
|
|||
}
|
||||
|
||||
// Changing times may have unsorted the dive and trip tables
|
||||
sort_dive_table(&dive_table);
|
||||
sort_trip_table(&trip_table);
|
||||
sort_dive_table(divelog.dives);
|
||||
sort_trip_table(divelog.trips);
|
||||
for (dive_trip *trip: trips)
|
||||
sort_dive_table(&trip->dives); // Keep the trip-table in order
|
||||
|
||||
|
@ -717,7 +718,7 @@ bool TripBase::workToBeDone()
|
|||
void TripBase::redoit()
|
||||
{
|
||||
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
|
||||
std::vector<dive *> dives;
|
||||
|
@ -790,7 +791,7 @@ AutogroupDives::AutogroupDives()
|
|||
dive_trip *trip;
|
||||
bool alloc;
|
||||
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 (alloc)
|
||||
divesToMove.tripsToAdd.emplace_back(trip);
|
||||
|
@ -1009,7 +1010,7 @@ MergeDives::MergeDives(const QVector <dive *> &dives)
|
|||
// like the best option.
|
||||
int idx = get_divenr(dives[0]);
|
||||
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.
|
||||
// Something is seriously wrong - give up.
|
||||
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).
|
||||
// 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) {
|
||||
// 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.
|
||||
|
@ -1033,15 +1034,15 @@ MergeDives::MergeDives(const QVector <dive *> &dives)
|
|||
// consecutive, and the difference will be 1, so the
|
||||
// above example is not supposed to be normal.
|
||||
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;
|
||||
for (int i = idx + num; i < dive_table.nr; ++i) {
|
||||
int newnr = dive_table.dives[i]->number - diff;
|
||||
for (int i = idx + num; i < divelog.dives->nr; ++i) {
|
||||
int newnr = divelog.dives->dives[i]->number - diff;
|
||||
|
||||
// Stop renumbering if stuff isn't in order (see also core/divelist.c)
|
||||
if (newnr <= previousnr)
|
||||
break;
|
||||
divesToRenumber.append(QPair<dive *,int>(dive_table.dives[i], newnr));
|
||||
divesToRenumber.append(QPair<dive *,int>(divelog.dives->dives[i], newnr));
|
||||
previousnr = newnr;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
#include "command_divesite.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/divesite.h"
|
||||
#include "core/subsurface-qt/divelistnotifier.h"
|
||||
#include "core/qthelper.h"
|
||||
|
@ -154,8 +155,8 @@ void DeleteDiveSites::undo()
|
|||
PurgeUnusedDiveSites::PurgeUnusedDiveSites()
|
||||
{
|
||||
setText(Command::Base::tr("purge unused dive sites"));
|
||||
for (int i = 0; i < dive_site_table.nr; ++i) {
|
||||
dive_site *ds = dive_site_table.dive_sites[i];
|
||||
for (int i = 0; i < divelog.sites->nr; ++i) {
|
||||
dive_site *ds = divelog.sites->dive_sites[i];
|
||||
if (ds->dives.nr == 0)
|
||||
sitesToRemove.push_back(ds);
|
||||
}
|
||||
|
@ -404,7 +405,7 @@ ApplyGPSFixes::ApplyGPSFixes(const std::vector<DiveAndLocation> &fixes)
|
|||
siteLocations.push_back({ ds, dl.location });
|
||||
}
|
||||
} else {
|
||||
ds = create_dive_site(qPrintable(dl.name), &dive_site_table);
|
||||
ds = create_dive_site(qPrintable(dl.name), divelog.sites);
|
||||
ds->location = dl.location;
|
||||
add_dive_to_dive_site(dl.d, ds);
|
||||
dl.d->dive_site = nullptr; // This will be set on redo()
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "command_edit.h"
|
||||
#include "core/divelist.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/fulltext.h"
|
||||
#include "core/qthelper.h" // for copy_qstring
|
||||
#include "core/sample.h"
|
||||
|
@ -1507,8 +1508,8 @@ void EditDive::exchangeDives()
|
|||
QVector<dive *> dives = { oldDive };
|
||||
timestamp_t delta = oldDive->when - newDive->when;
|
||||
if (delta != 0) {
|
||||
sort_dive_table(&dive_table);
|
||||
sort_trip_table(&trip_table);
|
||||
sort_dive_table(divelog.dives);
|
||||
sort_trip_table(divelog.trips);
|
||||
if (newDive->divetrip != oldDive->divetrip)
|
||||
qWarning("Command::EditDive::redo(): This command does not support moving between trips!");
|
||||
if (oldDive->divetrip)
|
||||
|
|
|
@ -68,6 +68,8 @@ set(SUBSURFACE_CORE_LIB_SRCS
|
|||
divefilter.h
|
||||
divelist.c
|
||||
divelist.h
|
||||
divelog.cpp
|
||||
divelog.h
|
||||
divelogexportlogic.cpp
|
||||
divelogexportlogic.h
|
||||
divesite-helper.cpp
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "gettext.h"
|
||||
#include "cochran.h"
|
||||
#include "divelist.h"
|
||||
#include "divelog.h"
|
||||
|
||||
#include <libdivecomputer/parser.h>
|
||||
|
||||
|
@ -799,11 +800,9 @@ static void cochran_parse_dive(const unsigned char *decode, unsigned mod,
|
|||
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(trips);
|
||||
UNUSED(sites);
|
||||
unsigned int i;
|
||||
unsigned int mod;
|
||||
unsigned int *offsets, dive1, dive2;
|
||||
|
@ -832,7 +831,7 @@ int try_to_open_cochran(const char *filename, struct memblock *mem, struct dive_
|
|||
break;
|
||||
|
||||
cochran_parse_dive(decode, mod, mem->buffer + dive1,
|
||||
dive2 - dive1, table);
|
||||
dive2 - dive1, log->dives);
|
||||
}
|
||||
|
||||
return 1; // no further processing needed
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "file.h"
|
||||
#include "divesite.h"
|
||||
#include "dive.h"
|
||||
#include "divelog.h"
|
||||
#include "errorhelper.h"
|
||||
#include "ssrf.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.
|
||||
* 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,
|
||||
struct dive_site_table *sites, struct device_table *devices)
|
||||
int datatrak_import(struct memblock *mem, struct memblock *wl_mem, struct divelog *log)
|
||||
{
|
||||
UNUSED(trips);
|
||||
unsigned char *runner;
|
||||
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)) {
|
||||
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)
|
||||
wlog_compl_parser(wl_mem, ptdive, i);
|
||||
if (runner == NULL) {
|
||||
|
@ -721,13 +720,13 @@ int datatrak_import(struct memblock *mem, struct memblock *wl_mem, struct dive_t
|
|||
rc = 1;
|
||||
goto out;
|
||||
} else {
|
||||
record_dive_to_table(ptdive, table);
|
||||
record_dive_to_table(ptdive, log->dives);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
out:
|
||||
taglist_cleanup(&g_tag_list);
|
||||
sort_dive_table(table);
|
||||
sort_dive_table(log->dives);
|
||||
return rc;
|
||||
bail:
|
||||
return 1;
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
#include "device.h"
|
||||
#include "dive.h"
|
||||
#include "divelist.h"
|
||||
#include "divelog.h"
|
||||
#include "subsurface-string.h"
|
||||
#include "errorhelper.h" // for verbose flag
|
||||
#include "selection.h"
|
||||
#include "core/settings/qPrefDiveComputer.h"
|
||||
|
||||
struct device_table device_table;
|
||||
struct fingerprint_table fingerprint_table;
|
||||
|
||||
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 device *existNode = get_device_for_dc(&device_table, dc);
|
||||
const device *existNode = get_device_for_dc(divelog.devices, dc);
|
||||
|
||||
if (existNode && !existNode->nickName.empty())
|
||||
return existNode->nickName.c_str();
|
||||
|
|
|
@ -14,7 +14,6 @@ struct device_table;
|
|||
struct dive_table;
|
||||
|
||||
// global device table
|
||||
extern struct device_table device_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);
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "libdivecomputer.h"
|
||||
#include "device.h"
|
||||
#include "divelist.h"
|
||||
#include "divelog.h"
|
||||
#include "divesite.h"
|
||||
#include "errorhelper.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.
|
||||
*/
|
||||
if (d2->number) {
|
||||
if (dive_table.nr == nr + 1)
|
||||
if (divelog.dives->nr == nr + 1)
|
||||
d2->number++;
|
||||
else
|
||||
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)
|
||||
{
|
||||
if (nr >= dive_table.nr || nr < 0)
|
||||
if (nr >= divelog.dives->nr || nr < 0)
|
||||
return NULL;
|
||||
return dive_table.dives[nr];
|
||||
return divelog.dives->dives[nr];
|
||||
}
|
||||
|
||||
struct dive_site *get_dive_site_for_dive(const struct dive *dive)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "divefilter.h"
|
||||
#include "divelist.h"
|
||||
#include "divelog.h"
|
||||
#include "gettextfromc.h"
|
||||
#include "qthelper.h"
|
||||
#include "selection.h"
|
||||
|
@ -73,7 +74,7 @@ void DiveFilter::reset()
|
|||
{
|
||||
int i;
|
||||
dive *d;
|
||||
shown_dives = dive_table.nr;
|
||||
shown_dives = divelog.dives->nr;
|
||||
for_each_dive(i, d)
|
||||
d->hidden_by_filter = false;
|
||||
updateAll();
|
||||
|
@ -201,10 +202,11 @@ bool DiveFilter::diveSiteMode() const
|
|||
|
||||
QString DiveFilter::shownText() const
|
||||
{
|
||||
int num = divelog.dives->nr;
|
||||
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
|
||||
return gettextFromC::tr("%L1 dives").arg(dive_table.nr);
|
||||
return gettextFromC::tr("%L1 dives").arg(num);
|
||||
}
|
||||
|
||||
int DiveFilter::shownDives() const
|
||||
|
|
104
core/divelist.c
104
core/divelist.c
|
@ -5,8 +5,9 @@
|
|||
#include "subsurface-string.h"
|
||||
#include "deco.h"
|
||||
#include "device.h"
|
||||
#include "divesite.h"
|
||||
#include "dive.h"
|
||||
#include "divelog.h"
|
||||
#include "divesite.h"
|
||||
#include "event.h"
|
||||
#include "eventname.h"
|
||||
#include "filterpreset.h"
|
||||
|
@ -226,7 +227,7 @@ static int calculate_cns(struct dive *dive)
|
|||
return dive->cns;
|
||||
|
||||
divenr = get_divenr(dive);
|
||||
i = divenr >= 0 ? divenr : dive_table.nr;
|
||||
i = divenr >= 0 ? divenr : divelog.dives->nr;
|
||||
#if DECO_CALC_DEBUG & 2
|
||||
if (i >= 0 && i < dive_table.nr)
|
||||
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);
|
||||
#endif
|
||||
/* 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);
|
||||
if (!pdive || pdive->when > dive->when)
|
||||
break;
|
||||
|
@ -279,7 +280,7 @@ static int calculate_cns(struct dive *dive)
|
|||
#endif
|
||||
}
|
||||
/* 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
|
||||
printf("Check if dive #%d %d will be really added to CNS calc: ", i, get_dive(i)->number);
|
||||
#endif
|
||||
|
@ -463,7 +464,7 @@ int init_decompression(struct deco_state *ds, const struct dive *dive, bool in_p
|
|||
return false;
|
||||
|
||||
divenr = get_divenr(dive);
|
||||
i = divenr >= 0 ? divenr : dive_table.nr;
|
||||
i = divenr >= 0 ? divenr : divelog.dives->nr;
|
||||
#if DECO_CALC_DEBUG & 2
|
||||
if (i >= 0 && i < dive_table.nr)
|
||||
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);
|
||||
#endif
|
||||
/* 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);
|
||||
if (!pdive || pdive->when > dive->when)
|
||||
break;
|
||||
|
@ -516,7 +517,7 @@ int init_decompression(struct deco_state *ds, const struct dive *dive, bool in_p
|
|||
#endif
|
||||
}
|
||||
/* 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
|
||||
printf("Check if dive #%d %d will be really added to deco calc: ", i, get_dive(i)->number);
|
||||
#endif
|
||||
|
@ -767,7 +768,7 @@ struct dive *unregister_dive(int idx)
|
|||
/* When removing a dive from the global dive table,
|
||||
* we also have to unregister its fulltext cache. */
|
||||
fulltext_unregister(dive);
|
||||
remove_from_dive_table(&dive_table, idx);
|
||||
remove_from_dive_table(divelog.dives, idx);
|
||||
if (dive->selected)
|
||||
amount_selected--;
|
||||
dive->selected = false;
|
||||
|
@ -783,18 +784,18 @@ void delete_single_dive(int idx)
|
|||
return; /* this should never happen */
|
||||
if (dive->selected)
|
||||
deselect_dive(dive);
|
||||
remove_dive_from_trip(dive, &trip_table);
|
||||
remove_dive_from_trip(dive, divelog.trips);
|
||||
unregister_dive_from_dive_site(dive);
|
||||
delete_dive_from_table(&dive_table, idx);
|
||||
delete_dive_from_table(divelog.dives, idx);
|
||||
}
|
||||
|
||||
void process_loaded_dives()
|
||||
{
|
||||
sort_dive_table(&dive_table);
|
||||
sort_trip_table(&trip_table);
|
||||
sort_dive_table(divelog.dives);
|
||||
sort_trip_table(divelog.trips);
|
||||
|
||||
/* Autogroup dives if desired by user. */
|
||||
autogroup_dives(&dive_table, &trip_table);
|
||||
autogroup_dives(divelog.dives, divelog.trips);
|
||||
|
||||
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 */
|
||||
static bool dive_is_after_last(struct dive *d)
|
||||
{
|
||||
if (dive_table.nr == 0)
|
||||
if (divelog.dives->nr == 0)
|
||||
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,
|
||||
|
@ -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"
|
||||
* and dive_table "dives_to". If "prefer_imported" is true, dive data of "from" takes
|
||||
* precedence */
|
||||
void add_imported_dives(struct dive_table *import_table, struct trip_table *import_trip_table,
|
||||
struct dive_site_table *import_sites_table, struct device_table *import_device_table,
|
||||
int flags)
|
||||
void add_imported_dives(struct divelog *import_log, int flags)
|
||||
{
|
||||
int i, idx;
|
||||
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
|
||||
* 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,
|
||||
&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 */
|
||||
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;
|
||||
|
||||
/* Add new trips */
|
||||
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;
|
||||
|
||||
/* Add new dive sites */
|
||||
|
@ -1020,12 +1019,12 @@ void add_imported_dives(struct dive_table *import_table, struct trip_table *impo
|
|||
/* Add new devices */
|
||||
for (i = 0; i < nr_devices(devices_to_add); i++) {
|
||||
const struct device *dev = get_device(devices_to_add, i);
|
||||
add_to_device_table(&device_table, dev);
|
||||
add_to_device_table(divelog.devices, dev);
|
||||
}
|
||||
|
||||
/* We might have deleted the old selected dive.
|
||||
* Choose the newest dive as selected (if any) */
|
||||
current_dive = dive_table.nr > 0 ? dive_table.dives[dive_table.nr - 1] : NULL;
|
||||
current_dive = divelog.dives->nr > 0 ? divelog.dives->dives[divelog.dives->nr - 1] : NULL;
|
||||
|
||||
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;
|
||||
struct dive_trip *trip_old;
|
||||
|
||||
for (i = 0; i < trip_table.nr; i++) {
|
||||
trip_old = trip_table.trips[i];
|
||||
for (i = 0; i < divelog.trips->nr; i++) {
|
||||
trip_old = divelog.trips->trips[i];
|
||||
if (trips_overlap(trip_import, trip_old)) {
|
||||
*sequence_changed |= merge_dive_tables(&trip_import->dives, import_table, &trip_old->dives,
|
||||
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. */
|
||||
for (i = 0; i < nr_devices(import_device_table); i++) {
|
||||
const struct device *dev = get_device(import_device_table, i);
|
||||
if (!device_exists(&device_table, dev))
|
||||
if (!device_exists(divelog.devices, 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
|
||||
* a trip and the caller does not want them to be associated to a
|
||||
* 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);
|
||||
}
|
||||
|
||||
|
@ -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).
|
||||
* - 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.
|
||||
* Skip those. Since sequence_changed is false all added dives are *after*
|
||||
* all merged dives. */
|
||||
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++)
|
||||
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()
|
||||
{
|
||||
int i;
|
||||
for (i = dive_table.nr - 1; i >= 0; i--) {
|
||||
if (!dive_table.dives[i]->invalid)
|
||||
return dive_table.dives[i];
|
||||
for (i = divelog.dives->nr - 1; i >= 0; i--) {
|
||||
if (!divelog.dives->dives[i]->invalid)
|
||||
return divelog.dives->dives[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1277,7 +1276,7 @@ static struct dive *get_last_valid_dive()
|
|||
*/
|
||||
int get_dive_nr_at_idx(int idx)
|
||||
{
|
||||
if (idx < dive_table.nr)
|
||||
if (idx < divelog.dives->nr)
|
||||
return 0;
|
||||
struct dive *last_dive = get_last_valid_dive();
|
||||
if (!last_dive)
|
||||
|
@ -1306,27 +1305,27 @@ void report_datafile_version(int version)
|
|||
int get_dive_id_closest_to(timestamp_t when)
|
||||
{
|
||||
int i;
|
||||
int nr = dive_table.nr;
|
||||
int nr = divelog.dives->nr;
|
||||
|
||||
// deal with pathological cases
|
||||
if (nr == 0)
|
||||
return 0;
|
||||
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
|
||||
|
||||
// again, capture the two edge cases first
|
||||
if (i == nr)
|
||||
return dive_table.dives[i - 1]->id;
|
||||
return divelog.dives->dives[i - 1]->id;
|
||||
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)
|
||||
return dive_table.dives[i - 1]->id;
|
||||
if (when - divelog.dives->dives[i - 1]->when < divelog.dives->dives[i]->when - when)
|
||||
return divelog.dives->dives[i - 1]->id;
|
||||
else
|
||||
return dive_table.dives[i]->id;
|
||||
return divelog.dives->dives[i]->id;
|
||||
}
|
||||
|
||||
void clear_dive_file_data()
|
||||
|
@ -1334,20 +1333,11 @@ void clear_dive_file_data()
|
|||
fulltext_unregister_all();
|
||||
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;
|
||||
while (dive_site_table.nr)
|
||||
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_divelog(&divelog);
|
||||
|
||||
clear_dive(&displayed_dive);
|
||||
clear_device_table(&device_table);
|
||||
clear_event_names();
|
||||
clear_filter_presets();
|
||||
|
||||
reset_min_datafile_version();
|
||||
clear_git_id();
|
||||
|
@ -1418,14 +1408,14 @@ timestamp_t get_surface_interval(timestamp_t when)
|
|||
timestamp_t prev_end;
|
||||
|
||||
/* find previous dive. might want to use a binary search. */
|
||||
for (i = dive_table.nr - 1; i >= 0; --i) {
|
||||
if (dive_table.dives[i]->when < when)
|
||||
for (i = divelog.dives->nr - 1; i >= 0; --i) {
|
||||
if (divelog.dives->dives[i]->when < when)
|
||||
break;
|
||||
}
|
||||
if (i < 0)
|
||||
return -1;
|
||||
|
||||
prev_end = dive_endtime(dive_table.dives[i]);
|
||||
prev_end = dive_endtime(divelog.dives->dives[i]);
|
||||
if (prev_end > when)
|
||||
return 0;
|
||||
return when - prev_end;
|
||||
|
@ -1437,11 +1427,11 @@ struct dive *find_next_visible_dive(timestamp_t when)
|
|||
{
|
||||
int i, j;
|
||||
|
||||
if (!dive_table.nr)
|
||||
if (!divelog.dives->nr)
|
||||
return NULL;
|
||||
|
||||
/* 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)
|
||||
break;
|
||||
}
|
||||
|
@ -1451,7 +1441,7 @@ struct dive *find_next_visible_dive(timestamp_t when)
|
|||
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)
|
||||
return get_dive(j);
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
struct dive;
|
||||
struct divelog;
|
||||
struct trip_table;
|
||||
struct dive_site_table;
|
||||
struct device_table;
|
||||
|
@ -19,7 +20,6 @@ struct dive_table {
|
|||
struct dive **dives;
|
||||
};
|
||||
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 */
|
||||
#define DATAFORMAT_VERSION 3
|
||||
|
@ -35,9 +35,7 @@ extern void process_loaded_dives();
|
|||
#define IMPORT_IS_DOWNLOADED (1 << 1)
|
||||
#define IMPORT_MERGE_ALL_TRIPS (1 << 2)
|
||||
#define IMPORT_ADD_TO_NEW_TRIP (1 << 3)
|
||||
extern void add_imported_dives(struct dive_table *import_table, struct trip_table *import_trip_table,
|
||||
struct dive_site_table *import_sites_table, struct device_table *devices_to_add,
|
||||
int flags);
|
||||
extern void add_imported_dives(struct divelog *log, int flags);
|
||||
extern void process_imported_dives(struct dive_table *import_table, struct trip_table *import_trip_table,
|
||||
struct dive_site_table *import_sites_table, struct device_table *import_devices_table,
|
||||
int flags,
|
||||
|
|
56
core/divelog.cpp
Normal file
56
core/divelog.cpp
Normal 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
40
core/divelog.h
Normal 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
|
|
@ -2,16 +2,15 @@
|
|||
/* divesite.c */
|
||||
#include "divesite.h"
|
||||
#include "dive.h"
|
||||
#include "subsurface-string.h"
|
||||
#include "divelist.h"
|
||||
#include "divelog.h"
|
||||
#include "membuffer.h"
|
||||
#include "subsurface-string.h"
|
||||
#include "table.h"
|
||||
#include "sha1.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 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)
|
||||
{
|
||||
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)
|
||||
|
@ -232,7 +231,7 @@ void free_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)
|
||||
|
@ -319,7 +318,7 @@ struct dive_site *get_same_dive_site(const struct dive_site *site)
|
|||
{
|
||||
int i;
|
||||
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))
|
||||
return ds;
|
||||
return NULL;
|
||||
|
|
|
@ -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 };
|
||||
|
||||
extern struct dive_site_table dive_site_table;
|
||||
|
||||
static inline struct dive_site *get_dive_site(int nr, struct dive_site_table *ds_table)
|
||||
{
|
||||
if (nr >= ds_table->nr || nr < 0)
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "gettext.h"
|
||||
#include "dive.h"
|
||||
#include "divelist.h"
|
||||
#include "divelog.h"
|
||||
#include "pref.h"
|
||||
#include "subsurface-string.h"
|
||||
#include "table.h"
|
||||
|
@ -305,8 +306,8 @@ void reset_tank_info_table(struct tank_info_table *table)
|
|||
add_default_tank_infos(table);
|
||||
|
||||
/* Add cylinders from dive list */
|
||||
for (int i = 0; i < dive_table.nr; ++i) {
|
||||
const struct dive *dive = dive_table.dives[i];
|
||||
for (int i = 0; i < divelog.dives->nr; ++i) {
|
||||
const struct dive *dive = divelog.dives->dives[i];
|
||||
for (int j = 0; j < dive->cylinders.nr; j++) {
|
||||
const cylinder_t *cyl = get_cylinder(dive, j);
|
||||
add_cylinder_description(&cyl->type);
|
||||
|
|
69
core/file.c
69
core/file.c
|
@ -11,6 +11,7 @@
|
|||
#include <time.h>
|
||||
|
||||
#include "dive.h"
|
||||
#include "divelog.h"
|
||||
#include "subsurface-string.h"
|
||||
#include "errorhelper.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,
|
||||
struct dive_site_table *sites, struct device_table *devices, struct filter_preset_table *filter_presets)
|
||||
static void zip_read(struct zip_file *file, const char *filename, struct divelog *log)
|
||||
{
|
||||
int size = 1024, n, read = 0;
|
||||
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[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);
|
||||
}
|
||||
|
||||
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)
|
||||
int try_to_open_zip(const char *filename, struct divelog *log)
|
||||
{
|
||||
int success = 0;
|
||||
/* 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 */
|
||||
if (strstr(zip_get_name(zip, index, 0), "pictures/"))
|
||||
continue;
|
||||
zip_read(file, filename, table, trips, sites, devices, filter_presets);
|
||||
zip_read(file, filename, log);
|
||||
zip_fclose(file);
|
||||
success++;
|
||||
}
|
||||
|
@ -128,8 +127,7 @@ static int db_test_func(void *param, int columns, char **data, char **column)
|
|||
return *data[0] == '0';
|
||||
}
|
||||
|
||||
static int try_to_open_db(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips,
|
||||
struct dive_site_table *sites, struct device_table *devices)
|
||||
static int try_to_open_db(const char *filename, struct memblock *mem, struct divelog *log)
|
||||
{
|
||||
sqlite3 *handle;
|
||||
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 */
|
||||
retval = sqlite3_exec(handle, dm5_test, &db_test_func, 0, NULL);
|
||||
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);
|
||||
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 */
|
||||
retval = sqlite3_exec(handle, dm4_test, &db_test_func, 0, NULL);
|
||||
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);
|
||||
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 */
|
||||
retval = sqlite3_exec(handle, shearwater_test, &db_test_func, 0, NULL);
|
||||
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);
|
||||
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 */
|
||||
retval = sqlite3_exec(handle, shearwater_cloud_test, &db_test_func, 0, NULL);
|
||||
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);
|
||||
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 */
|
||||
retval = sqlite3_exec(handle, cobalt_test, &db_test_func, 0, NULL);
|
||||
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);
|
||||
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 */
|
||||
retval = sqlite3_exec(handle, divinglog_test, &db_test_func, 0, NULL);
|
||||
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);
|
||||
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 */
|
||||
retval = sqlite3_exec(handle, seacsync_test, &db_test_func, 0, NULL);
|
||||
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);
|
||||
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).
|
||||
*/
|
||||
static int open_by_filename(const char *filename, const char *fmt, struct memblock *mem,
|
||||
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
|
||||
struct device_table *devices, struct filter_preset_table *filter_presets)
|
||||
static int open_by_filename(const char *filename, const char *fmt, struct memblock *mem, struct divelog *log)
|
||||
{
|
||||
// hack to be able to provide a comment for the translated string
|
||||
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 */
|
||||
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 */
|
||||
if (!strcasecmp(fmt, "CSV"))
|
||||
return report_error(translate("gettextFromC", csv_warning), filename);
|
||||
/* Truly nasty intentionally obfuscated Cochran Anal software */
|
||||
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 */
|
||||
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"))
|
||||
return try_to_open_liquivision(filename, mem, table, trips, sites);
|
||||
return try_to_open_liquivision(filename, mem, log);
|
||||
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"))
|
||||
return try_to_open_csv(mem, CSV_PRESSURE, table, trips, sites);
|
||||
return try_to_open_csv(mem, CSV_PRESSURE, log);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_file_buffer(const char *filename, struct memblock *mem, struct dive_table *table,
|
||||
struct trip_table *trips, struct dive_site_table *sites,
|
||||
struct device_table *devices, struct filter_preset_table *filter_presets)
|
||||
static int parse_file_buffer(const char *filename, struct memblock *mem, struct divelog *log)
|
||||
{
|
||||
int ret;
|
||||
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;
|
||||
|
||||
if (!mem->size || !mem->buffer)
|
||||
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)
|
||||
|
@ -292,8 +286,7 @@ bool remote_repo_uptodate(const char *filename, struct git_info *info)
|
|||
return false;
|
||||
}
|
||||
|
||||
int parse_file(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)
|
||||
int parse_file(const char *filename, struct divelog *log)
|
||||
{
|
||||
struct git_info info;
|
||||
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);
|
||||
return ret;
|
||||
}
|
||||
|
@ -329,7 +322,7 @@ int parse_file(const char *filename, struct dive_table *table, struct trip_table
|
|||
|
||||
fmt = strrchr(filename, '.');
|
||||
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);
|
||||
return 0;
|
||||
}
|
||||
|
@ -337,7 +330,7 @@ int parse_file(const char *filename, struct dive_table *table, struct trip_table
|
|||
|
||||
/* Divesoft Freedom */
|
||||
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);
|
||||
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");
|
||||
if((ret = readfile(wl_name, &wl_mem)) < 0) {
|
||||
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 {
|
||||
ret = datatrak_import(&mem, &wl_mem, table, trips, sites, devices);
|
||||
ret = datatrak_import(&mem, &wl_mem, log);
|
||||
free(wl_mem.buffer);
|
||||
}
|
||||
free(mem.buffer);
|
||||
|
@ -364,11 +357,11 @@ int parse_file(const char *filename, struct dive_table *table, struct trip_table
|
|||
/* OSTCtools */
|
||||
if (fmt && (!strcasecmp(fmt + 1, "DIVE"))) {
|
||||
free(mem.buffer);
|
||||
ostctools_import(filename, table, trips, sites);
|
||||
ostctools_import(filename, log);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = parse_file_buffer(filename, &mem, table, trips, sites, devices, filter_presets);
|
||||
ret = parse_file_buffer(filename, &mem, log);
|
||||
free(mem.buffer);
|
||||
return ret;
|
||||
}
|
||||
|
|
20
core/file.h
20
core/file.h
|
@ -12,26 +12,20 @@ struct memblock {
|
|||
size_t size;
|
||||
};
|
||||
|
||||
struct trip_table;
|
||||
struct device_table;
|
||||
struct dive_site_table;
|
||||
struct dive_table;
|
||||
struct divelog;
|
||||
struct zip;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#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_liquivision(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
|
||||
extern int datatrak_import(struct memblock *mem, struct memblock *wl_mem, struct dive_table *table, struct trip_table *trips,
|
||||
struct dive_site_table *sites, struct device_table *devices);
|
||||
extern void ostctools_import(const char *file, 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 divelog *log);
|
||||
extern int datatrak_import(struct memblock *mem, struct memblock *wl_mem, struct divelog *log);
|
||||
extern void ostctools_import(const char *file, struct divelog *log);
|
||||
|
||||
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,
|
||||
struct device_table *devices, struct filter_preset_table *filter_presets);
|
||||
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);
|
||||
extern int parse_file(const char *filename, struct divelog *log);
|
||||
extern int try_to_open_zip(const char *filename, struct divelog *log);
|
||||
|
||||
// Platform specific functions
|
||||
extern int subsurface_rename(const char *path, const char *newpath);
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include "filterpreset.h"
|
||||
#include "divelog.h"
|
||||
#include "qthelper.h"
|
||||
#include "subsurface-string.h"
|
||||
|
||||
struct filter_preset_table filter_preset_table;
|
||||
|
||||
extern "C" void clear_filter_presets(void)
|
||||
static filter_preset_table &global_table()
|
||||
{
|
||||
filter_preset_table.clear();
|
||||
return *divelog.filter_presets;
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -22,12 +21,12 @@ extern "C" char *filter_preset_name(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)
|
||||
{
|
||||
switch (filter_preset_table[preset].data.fulltextStringMode) {
|
||||
switch (global_table()[preset].data.fulltextStringMode) {
|
||||
default:
|
||||
case StringFilterMode::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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
return &filter_preset_table[preset].data.constraints[constraint];
|
||||
return &global_table()[preset].data.constraints[constraint];
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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; });
|
||||
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)
|
||||
{
|
||||
return filter_preset_table[preset].name;
|
||||
return global_table()[preset].name;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return filter_preset_table[preset].data;
|
||||
return global_table()[preset].data;
|
||||
}
|
||||
|
||||
int filter_preset_add(const QString &nameIn, const FilterData &d)
|
||||
{
|
||||
QString name = get_unique_preset_name(nameIn, filter_preset_table);
|
||||
return filter_preset_add_to_table(name, d, filter_preset_table);
|
||||
QString name = get_unique_preset_name(nameIn, global_table());
|
||||
return filter_preset_add_to_table(name, d, global_table());
|
||||
}
|
||||
|
||||
void filter_preset_delete(int preset)
|
||||
{
|
||||
filter_preset_table.erase(filter_preset_table.begin() + preset);
|
||||
global_table().erase(global_table().begin() + preset);
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ struct filter_preset_table : public std::vector<filter_preset>
|
|||
{
|
||||
};
|
||||
|
||||
extern struct filter_preset_table filter_preset_table;
|
||||
#else
|
||||
struct filter_preset;
|
||||
struct filter_preset_table;
|
||||
|
@ -44,7 +43,6 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
// The C IO code accesses the filter presets via integer indices.
|
||||
extern void clear_filter_presets(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_fulltext_query(int preset); // fulltext query of filter preset - caller must free the result.
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "fulltext.h"
|
||||
#include "dive.h"
|
||||
#include "divelog.h"
|
||||
#include "divesite.h"
|
||||
#include "tag.h"
|
||||
#include "trip.h"
|
||||
|
@ -155,7 +156,7 @@ void FullText::populate()
|
|||
dive *d;
|
||||
for_each_dive(i, 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)
|
||||
|
|
|
@ -5,9 +5,7 @@
|
|||
#include "git2.h"
|
||||
#include "filterpreset.h"
|
||||
|
||||
struct dive_table;
|
||||
struct dive_site_table;
|
||||
struct trip_table;
|
||||
struct dive_log;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -26,7 +24,7 @@ enum remote_transport { RT_LOCAL, RT_HTTPS, RT_SSH, RT_OTHER };
|
|||
|
||||
struct git_oid;
|
||||
struct git_repository;
|
||||
struct device_table;
|
||||
struct divelog;
|
||||
|
||||
struct git_info {
|
||||
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 int sync_with_remote(struct git_info *);
|
||||
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,
|
||||
struct dive_site_table *sites, struct device_table *devices,
|
||||
struct filter_preset_table *filter_presets);
|
||||
extern int git_load_dives(struct git_info *, struct divelog *log);
|
||||
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 void cleanup_git_info(struct git_info *);
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "sample.h"
|
||||
#include "subsurface-string.h"
|
||||
#include "divelist.h"
|
||||
#include "divelog.h"
|
||||
#include "device.h"
|
||||
#include "membuffer.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,
|
||||
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 *buffer, int size, struct divelog *log)
|
||||
{
|
||||
UNUSED(buffer);
|
||||
UNUSED(size);
|
||||
|
@ -230,10 +229,10 @@ int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *buffer, in
|
|||
struct parser_state state;
|
||||
|
||||
init_parser_state(&state);
|
||||
state.target_table = table;
|
||||
state.trips = trips;
|
||||
state.sites = sites;
|
||||
state.devices = devices;
|
||||
state.target_table = log->dives;
|
||||
state.trips = log->trips;
|
||||
state.sites = log->sites;
|
||||
state.devices = log->devices;
|
||||
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";
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "ssrf.h"
|
||||
#include "subsurface-string.h"
|
||||
#include "divelist.h"
|
||||
#include "divelog.h"
|
||||
#include "file.h"
|
||||
#include "parse.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 parse_dan_format(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)
|
||||
static int parse_dan_format(const char *filename, struct xml_params *params, struct divelog *log)
|
||||
{
|
||||
int ret = 0, i;
|
||||
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);
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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"))
|
||||
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);
|
||||
}
|
||||
|
@ -278,9 +277,7 @@ static int parse_dan_format(const char *filename, struct xml_params *params, str
|
|||
return ret;
|
||||
}
|
||||
|
||||
int parse_csv_file(const char *filename, struct xml_params *params, const char *csvtemplate,
|
||||
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
|
||||
struct device_table *devices, struct filter_preset_table *filter_presets)
|
||||
int parse_csv_file(const char *filename, struct xml_params *params, const char *csvtemplate, struct divelog *log)
|
||||
{
|
||||
int ret;
|
||||
struct memblock mem;
|
||||
|
@ -300,7 +297,7 @@ int parse_csv_file(const char *filename, struct xml_params *params, const char *
|
|||
|
||||
mem.size = 0;
|
||||
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")) {
|
||||
time(&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);
|
||||
}
|
||||
#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);
|
||||
|
||||
|
@ -409,9 +406,8 @@ static int try_to_xslt_open_csv(const char *filename, struct memblock *mem, cons
|
|||
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 *header[8];
|
||||
int i, time;
|
||||
|
@ -460,7 +456,7 @@ int try_to_open_csv(struct memblock *mem, enum csv_format type, struct dive_tabl
|
|||
break;
|
||||
p = end + 1;
|
||||
}
|
||||
record_dive_to_table(dive, table);
|
||||
record_dive_to_table(dive, log->dives);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -502,15 +498,12 @@ static char *next_mkvi_key(const char *haystack)
|
|||
return ret;
|
||||
}
|
||||
|
||||
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_txt_file(const char *filename, const char *csv, struct divelog *log)
|
||||
{
|
||||
UNUSED(sites);
|
||||
struct memblock memtxt, memcsv;
|
||||
|
||||
if (readfile(filename, &memtxt) < 0) {
|
||||
if (readfile(filename, &memtxt) < 0)
|
||||
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
|
||||
|
@ -786,7 +779,7 @@ int parse_txt_file(const char *filename, const char *csv, struct dive_table *tab
|
|||
if (!lineptr || !*lineptr)
|
||||
break;
|
||||
}
|
||||
record_dive_to_table(dive, table);
|
||||
record_dive_to_table(dive, log->dives);
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
|
@ -799,17 +792,14 @@ int parse_txt_file(const char *filename, const char *csv, struct dive_table *tab
|
|||
#define TIMESTR 6
|
||||
|
||||
#define SBPARAMS 40
|
||||
static int parse_seabear_csv_file(const char *filename, struct xml_params *params, const char *csvtemplate,
|
||||
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
|
||||
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)
|
||||
static int parse_seabear_csv_file(const char *filename, struct xml_params *params, const char *csvtemplate, struct divelog *log);
|
||||
int parse_seabear_log(const char *filename, struct divelog *log)
|
||||
{
|
||||
struct xml_params *params = alloc_xml_params();
|
||||
int ret;
|
||||
|
||||
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);
|
||||
|
||||
|
@ -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,
|
||||
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
|
||||
struct device_table *devices, struct filter_preset_table *filter_presets)
|
||||
static int parse_seabear_csv_file(const char *filename, struct xml_params *params, const char *csvtemplate, struct divelog *log)
|
||||
{
|
||||
int ret, i;
|
||||
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");
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
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)
|
||||
int parse_manual_file(const char *filename, struct xml_params *params, struct divelog *log)
|
||||
{
|
||||
struct memblock mem;
|
||||
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);
|
||||
}
|
||||
#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);
|
||||
return ret;
|
||||
|
|
|
@ -25,17 +25,12 @@ enum csv_format {
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
int parse_csv_file(const char *filename, struct xml_params *params, const char *csvtemplate, struct dive_table *table,
|
||||
struct trip_table *trips, struct dive_site_table *sites, struct device_table *devices,
|
||||
struct filter_preset_table *filter_presets);
|
||||
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_csv_file(const char *filename, struct xml_params *params, const char *csvtemplate, struct divelog *log);
|
||||
int try_to_open_csv(struct memblock *mem, enum csv_format type, struct divelog *log);
|
||||
int parse_txt_file(const char *filename, const char *csv, struct divelog *log);
|
||||
|
||||
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);
|
||||
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);
|
||||
int parse_seabear_log(const char *filename, struct divelog *log);
|
||||
int parse_manual_file(const char *filename, struct xml_params *params, struct divelog *log);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "subsurface-string.h"
|
||||
#include "parse.h"
|
||||
#include "divelist.h"
|
||||
#include "divelog.h"
|
||||
#include "device.h"
|
||||
#include "membuffer.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,
|
||||
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 *buffer, int size, struct divelog *log)
|
||||
{
|
||||
UNUSED(buffer);
|
||||
UNUSED(size);
|
||||
|
@ -401,10 +400,10 @@ int parse_divinglog_buffer(sqlite3 *handle, const char *url, const char *buffer,
|
|||
struct parser_state state;
|
||||
|
||||
init_parser_state(&state);
|
||||
state.target_table = table;
|
||||
state.trips = trips;
|
||||
state.sites = sites;
|
||||
state.devices = devices;
|
||||
state.target_table = log->dives;
|
||||
state.trips = log->trips;
|
||||
state.sites = log->sites;
|
||||
state.devices = log->devices;
|
||||
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)";
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "subsurface-string.h"
|
||||
#include "parse.h"
|
||||
#include "divelist.h"
|
||||
#include "divelog.h"
|
||||
#include "device.h"
|
||||
#include "membuffer.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
|
||||
* table, to read in the sample values.
|
||||
*/
|
||||
int parse_seac_buffer(sqlite3 *handle, const char *url, const char *buffer, int size,
|
||||
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
|
||||
struct device_table *devices)
|
||||
int parse_seac_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, struct divelog *log)
|
||||
{
|
||||
UNUSED(buffer);
|
||||
UNUSED(size);
|
||||
|
@ -274,10 +273,10 @@ int parse_seac_buffer(sqlite3 *handle, const char *url, const char *buffer, int
|
|||
struct parser_state state;
|
||||
|
||||
init_parser_state(&state);
|
||||
state.target_table = table;
|
||||
state.trips = trips;
|
||||
state.sites = sites;
|
||||
state.devices = devices;
|
||||
state.target_table = log->dives;
|
||||
state.trips = log->trips;
|
||||
state.sites = log->sites;
|
||||
state.devices = log->devices;
|
||||
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";
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "subsurface-string.h"
|
||||
#include "parse.h"
|
||||
#include "divelist.h"
|
||||
#include "divelog.h"
|
||||
#include "device.h"
|
||||
#include "membuffer.h"
|
||||
#include "gettext.h"
|
||||
|
@ -487,9 +488,7 @@ static int shearwater_cloud_dive(void *param, int columns, char **data, char **c
|
|||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buffer, int size,
|
||||
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
|
||||
struct device_table *devices)
|
||||
int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, struct divelog *log)
|
||||
{
|
||||
UNUSED(buffer);
|
||||
UNUSED(size);
|
||||
|
@ -498,10 +497,10 @@ int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buffer
|
|||
struct parser_state state;
|
||||
|
||||
init_parser_state(&state);
|
||||
state.target_table = table;
|
||||
state.trips = trips;
|
||||
state.sites = sites;
|
||||
state.devices = devices;
|
||||
state.target_table = log->dives;
|
||||
state.trips = log->trips;
|
||||
state.sites = log->sites;
|
||||
state.devices = log->devices;
|
||||
state.sql_handle = handle;
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
int parse_shearwater_cloud_buffer(sqlite3 *handle, const char *url, const char *buffer, int size,
|
||||
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
|
||||
struct device_table *devices)
|
||||
int parse_shearwater_cloud_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, struct divelog *log)
|
||||
{
|
||||
UNUSED(buffer);
|
||||
UNUSED(size);
|
||||
|
@ -531,10 +528,10 @@ int parse_shearwater_cloud_buffer(sqlite3 *handle, const char *url, const char *
|
|||
struct parser_state state;
|
||||
|
||||
init_parser_state(&state);
|
||||
state.target_table = table;
|
||||
state.trips = trips;
|
||||
state.sites = sites;
|
||||
state.devices = devices;
|
||||
state.target_table = log->dives;
|
||||
state.trips = log->trips;
|
||||
state.sites = log->sites;
|
||||
state.devices = log->devices;
|
||||
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";
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "sample.h"
|
||||
#include "subsurface-string.h"
|
||||
#include "divelist.h"
|
||||
#include "divelog.h"
|
||||
#include "device.h"
|
||||
#include "membuffer.h"
|
||||
#include "gettext.h"
|
||||
|
@ -292,9 +293,7 @@ static int dm4_dive(void *param, int columns, char **data, char **column)
|
|||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buffer, int size,
|
||||
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
|
||||
struct device_table *devices)
|
||||
int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, struct divelog *log)
|
||||
{
|
||||
UNUSED(buffer);
|
||||
UNUSED(size);
|
||||
|
@ -304,10 +303,10 @@ int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buffer, int s
|
|||
struct parser_state state;
|
||||
|
||||
init_parser_state(&state);
|
||||
state.target_table = table;
|
||||
state.trips = trips;
|
||||
state.sites = sites;
|
||||
state.devices = devices;
|
||||
state.target_table = log->dives;
|
||||
state.trips = log->trips;
|
||||
state.sites = log->sites;
|
||||
state.devices = log->devices;
|
||||
state.sql_handle = handle;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buffer, int size,
|
||||
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
|
||||
struct device_table *devices)
|
||||
int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, struct divelog *log)
|
||||
{
|
||||
UNUSED(buffer);
|
||||
UNUSED(size);
|
||||
|
@ -591,10 +588,10 @@ int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buffer, int s
|
|||
struct parser_state state;
|
||||
|
||||
init_parser_state(&state);
|
||||
state.target_table = table;
|
||||
state.trips = trips;
|
||||
state.sites = sites;
|
||||
state.devices = devices;
|
||||
state.target_table = log->dives;
|
||||
state.trips = log->trips;
|
||||
state.sites = log->sites;
|
||||
state.devices = log->devices;
|
||||
state.sql_handle = handle;
|
||||
|
||||
/* StartTime is converted from Suunto's nano seconds to standard
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include "gettext.h"
|
||||
#include "divelog.h"
|
||||
#include "divesite.h"
|
||||
#include "sample.h"
|
||||
#include "subsurface-float.h"
|
||||
|
@ -512,8 +513,8 @@ static int find_dive(struct divecomputer *match)
|
|||
{
|
||||
int i;
|
||||
|
||||
for (i = dive_table.nr - 1; i >= 0; i--) {
|
||||
struct dive *old = dive_table.dives[i];
|
||||
for (i = divelog.dives->nr - 1; i >= 0; i--) {
|
||||
struct dive *old = divelog.dives->dives[i];
|
||||
|
||||
if (match_one_dive(match, old))
|
||||
return 1;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "ssrf.h"
|
||||
#include "divesite.h"
|
||||
#include "dive.h"
|
||||
#include "divelog.h"
|
||||
#include "file.h"
|
||||
#include "sample.h"
|
||||
#include "strndup.h"
|
||||
|
@ -436,10 +437,9 @@ static void parse_dives(int log_version, const unsigned char *buf, unsigned int
|
|||
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(trips);
|
||||
const unsigned char *buf = mem->buffer;
|
||||
unsigned int buf_size = mem->size;
|
||||
unsigned int ptr;
|
||||
|
@ -461,7 +461,7 @@ int try_to_open_liquivision(const char *filename, struct memblock *mem, struct d
|
|||
}
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "gettext.h"
|
||||
|
||||
#include "dive.h"
|
||||
#include "divelog.h"
|
||||
#include "divesite.h"
|
||||
#include "event.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,
|
||||
* 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,
|
||||
struct dive_site_table *sites, struct device_table *devices, struct filter_preset_table *filter_presets)
|
||||
int git_load_dives(struct git_info *info, struct divelog *log)
|
||||
{
|
||||
int ret;
|
||||
struct git_parser_state state = { 0 };
|
||||
state.repo = info->repo;
|
||||
state.table = table;
|
||||
state.trips = trips;
|
||||
state.sites = sites;
|
||||
state.devices = devices;
|
||||
state.filter_presets = filter_presets;
|
||||
state.table = log->dives;
|
||||
state.trips = log->trips;
|
||||
state.sites = log->sites;
|
||||
state.devices = log->devices;
|
||||
state.filter_presets = log->filter_presets;
|
||||
|
||||
if (!info->repo)
|
||||
return report_error("Unable to open git repository '%s[%s]'", info->url, info->branch);
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "gettext.h"
|
||||
#include "dive.h"
|
||||
#include "divelist.h"
|
||||
#include "divelog.h"
|
||||
#include "extradata.h"
|
||||
#include "file.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
|
||||
* 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;
|
||||
device_data_t *devdata = calloc(1, sizeof(device_data_t));
|
||||
dc_family_t dc_fam;
|
||||
|
@ -184,8 +183,8 @@ void ostctools_import(const char *file, struct dive_table *divetable, struct tri
|
|||
} else {
|
||||
add_extra_data(&ostcdive->dc, "Serial", ostcdive->dc.serial);
|
||||
}
|
||||
record_dive_to_table(ostcdive, divetable);
|
||||
sort_dive_table(divetable);
|
||||
record_dive_to_table(ostcdive, log->dives);
|
||||
sort_dive_table(log->dives);
|
||||
|
||||
close_out:
|
||||
fclose(archive);
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "gettext.h"
|
||||
|
||||
#include "dive.h"
|
||||
#include "divelog.h"
|
||||
#include "divesite.h"
|
||||
#include "errorhelper.h"
|
||||
#include "parse.h"
|
||||
|
@ -1750,9 +1751,7 @@ static const char *preprocess_divelog_de(const char *buffer)
|
|||
return buffer;
|
||||
}
|
||||
|
||||
int parse_xml_buffer(const char *url, const char *buffer, int size,
|
||||
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
|
||||
struct device_table *devices, struct filter_preset_table *filter_presets,
|
||||
int parse_xml_buffer(const char *url, const char *buffer, int size, struct divelog *log,
|
||||
const struct xml_params *params)
|
||||
{
|
||||
UNUSED(size);
|
||||
|
@ -1762,12 +1761,12 @@ int parse_xml_buffer(const char *url, const char *buffer, int size,
|
|||
struct parser_state state;
|
||||
|
||||
init_parser_state(&state);
|
||||
state.target_table = table;
|
||||
state.trips = trips;
|
||||
state.sites = sites;
|
||||
state.devices = devices;
|
||||
state.target_table = log->dives;
|
||||
state.trips = log->trips;
|
||||
state.sites = log->sites;
|
||||
state.devices = log->devices;
|
||||
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);
|
||||
if (!doc)
|
||||
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;
|
||||
}
|
||||
|
||||
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)
|
||||
int parse_dlf_buffer(unsigned char *buffer, size_t size, struct divelog *log)
|
||||
{
|
||||
unsigned char *ptr = buffer;
|
||||
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;
|
||||
|
||||
init_parser_state(&state);
|
||||
state.target_table = table;
|
||||
state.trips = trips;
|
||||
state.sites = sites;
|
||||
state.devices = devices;
|
||||
state.target_table = log->dives;
|
||||
state.trips = log->trips;
|
||||
state.sites = log->sites;
|
||||
state.devices = log->devices;
|
||||
|
||||
// Check for the correct file magic
|
||||
if (ptr[0] != 'D' || ptr[1] != 'i' || ptr[2] != 'v' || ptr[3] != 'E')
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
#include "device.h"
|
||||
#include "gettext.h"
|
||||
|
||||
struct dive_table dive_table;
|
||||
|
||||
void init_parser_state(struct parser_state *state)
|
||||
{
|
||||
memset(state, 0, sizeof(*state));
|
||||
|
|
32
core/parse.h
32
core/parse.h
|
@ -14,6 +14,7 @@
|
|||
#include <time.h>
|
||||
|
||||
struct xml_params;
|
||||
struct divelog;
|
||||
|
||||
typedef union {
|
||||
struct event event;
|
||||
|
@ -105,10 +106,6 @@ extern "C" {
|
|||
void init_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);
|
||||
void start_match(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);
|
||||
|
||||
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,
|
||||
struct device_table *devices, struct filter_preset_table *filter_presets, const struct xml_params *params);
|
||||
int parse_xml_buffer(const char *url, const char *buf, int size, struct divelog *log, const struct xml_params *params);
|
||||
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,
|
||||
struct dive_site_table *sites, struct device_table *devices);
|
||||
int parse_dm5_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_seac_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_shearwater_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_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);
|
||||
int parse_dm4_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 divelog *log);
|
||||
int parse_seac_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 divelog *log);
|
||||
int parse_shearwater_cloud_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct divelog *log);
|
||||
int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct divelog *log);
|
||||
int parse_divinglog_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct divelog *log);
|
||||
int parse_dlf_buffer(unsigned char *buffer, size_t size, struct divelog *log);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "qthelper.h"
|
||||
#include "dive.h"
|
||||
#include "divelist.h"
|
||||
#include "divelog.h"
|
||||
#include "core/settings/qPrefLanguage.h"
|
||||
#include "core/settings/qPrefUpdateManager.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()
|
||||
{
|
||||
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()
|
||||
{
|
||||
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()
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include <git2.h>
|
||||
|
||||
#include "dive.h"
|
||||
#include "divelog.h"
|
||||
#include "divesite.h"
|
||||
#include "filterconstraint.h"
|
||||
#include "filterpreset.h"
|
||||
|
@ -883,8 +884,8 @@ static void save_settings(git_repository *repo, struct dir *tree)
|
|||
struct membuffer b = { 0 };
|
||||
|
||||
put_format(&b, "version %d\n", DATAFORMAT_VERSION);
|
||||
for (int i = 0; i < nr_devices(&device_table); i++)
|
||||
save_one_device(&b, get_device(&device_table, i));
|
||||
for (int i = 0; i < nr_devices(divelog.devices); i++)
|
||||
save_one_device(&b, get_device(divelog.devices, i));
|
||||
/* save the fingerprint data */
|
||||
for (unsigned int i = 0; i < nr_fingerprints(&fingerprint_table); 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);
|
||||
free_buffer(&dirname);
|
||||
|
||||
purge_empty_dive_sites(&dive_site_table);
|
||||
for (int i = 0; i < dive_site_table.nr; i++) {
|
||||
purge_empty_dive_sites(divelog.sites);
|
||||
for (int i = 0; i < divelog.sites->nr; i++) {
|
||||
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 };
|
||||
put_format(&site_file_name, "Site-%08x", ds->uuid);
|
||||
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_filter_presets(repo, root);
|
||||
|
||||
for (i = 0; i < trip_table.nr; ++i)
|
||||
trip_table.trips[i]->saved = 0;
|
||||
for (i = 0; i < divelog.trips->nr; ++i)
|
||||
divelog.trips->trips[i]->saved = 0;
|
||||
|
||||
/* save the 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)
|
||||
{
|
||||
int nr = dive_table.nr;
|
||||
int nr = divelog.dives->nr;
|
||||
struct dive *dive = get_dive(nr-1);
|
||||
char* changes_made = get_changes_made();
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "save-html.h"
|
||||
#include "dive.h"
|
||||
#include "divelog.h"
|
||||
#include "qthelper.h"
|
||||
#include "gettext.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 = &sep_;
|
||||
|
||||
for (i = 0; i < trip_table.nr; ++i)
|
||||
trip_table.trips[i]->saved = 0;
|
||||
for (i = 0; i < divelog.trips->nr; ++i)
|
||||
divelog.trips->trips[i]->saved = 0;
|
||||
|
||||
for_each_dive (i, dive) {
|
||||
trip = dive->divetrip;
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <fcntl.h>
|
||||
|
||||
#include "dive.h"
|
||||
#include "divelog.h"
|
||||
#include "divesite.h"
|
||||
#include "errorhelper.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);
|
||||
|
||||
/* save the dive computer nicknames, if any */
|
||||
for (int i = 0; i < nr_devices(&device_table); i++) {
|
||||
const struct device *d = get_device(&device_table, i);
|
||||
for (int i = 0; i < nr_devices(divelog.devices); i++) {
|
||||
const struct device *d = get_device(divelog.devices, i);
|
||||
if (!select_only || device_used_by_selected_dive(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 */
|
||||
put_format(b, "<divesites>\n");
|
||||
for (i = 0; i < dive_site_table.nr; i++) {
|
||||
struct dive_site *ds = get_dive_site(i, &dive_site_table);
|
||||
for (i = 0; i < divelog.sites->nr; i++) {
|
||||
struct dive_site *ds = get_dive_site(i, divelog.sites);
|
||||
/* Don't export empty dive sites */
|
||||
if (dive_site_is_empty(ds))
|
||||
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, "</divesites>\n<dives>\n");
|
||||
for (i = 0; i < trip_table.nr; ++i)
|
||||
trip_table.trips[i]->saved = 0;
|
||||
for (i = 0; i < divelog.trips->nr; ++i)
|
||||
divelog.trips->trips[i]->saved = 0;
|
||||
|
||||
/* save the filter presets */
|
||||
save_filter_presets(b);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "selection.h"
|
||||
#include "divelist.h"
|
||||
#include "divelog.h"
|
||||
#include "trip.h"
|
||||
#include "subsurface-qt/divelistnotifier.h"
|
||||
|
||||
|
@ -40,7 +41,7 @@ extern "C" void deselect_dive(struct dive *dive)
|
|||
}
|
||||
}
|
||||
selected_dive = idx;
|
||||
while (++selected_dive < dive_table.nr) {
|
||||
while (++selected_dive < divelog.dives->nr) {
|
||||
dive = get_dive(selected_dive);
|
||||
if (dive && dive->selected) {
|
||||
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!
|
||||
amount_trips_selected = 0;
|
||||
for (int i = 0; i < trip_table.nr; ++i)
|
||||
trip_table.trips[i]->selected = false;
|
||||
for (int i = 0; i < divelog.trips->nr; ++i)
|
||||
divelog.trips->trips[i]->selected = false;
|
||||
|
||||
// TODO: We might want to keep track of selected dives in a more efficient way!
|
||||
int i;
|
||||
|
@ -233,8 +234,8 @@ std::vector<dive *> getDiveSelection()
|
|||
// Select the first dive that is visible
|
||||
extern "C" void select_newest_visible_dive()
|
||||
{
|
||||
for (int i = dive_table.nr - 1; i >= 0; --i) {
|
||||
dive *d = dive_table.dives[i];
|
||||
for (int i = divelog.dives->nr - 1; i >= 0; --i) {
|
||||
dive *d = divelog.dives->dives[i];
|
||||
if (!d->hidden_by_filter)
|
||||
return select_single_dive(d);
|
||||
}
|
||||
|
@ -263,9 +264,9 @@ extern "C" struct dive_trip *single_selected_trip()
|
|||
{
|
||||
if (amount_trips_selected != 1)
|
||||
return NULL;
|
||||
for (int i = 0; i < trip_table.nr; ++i) {
|
||||
if (trip_table.trips[i]->selected)
|
||||
return trip_table.trips[i];
|
||||
for (int i = 0; i < divelog.trips->nr; ++i) {
|
||||
if (divelog.trips->trips[i]->selected)
|
||||
return divelog.trips->trips[i];
|
||||
}
|
||||
fprintf(stderr, "warning: found no selected trip even though one should be selected\n");
|
||||
return NULL; // shouldn't happen
|
||||
|
@ -280,6 +281,6 @@ extern "C" void clear_selection(void)
|
|||
struct dive *dive;
|
||||
for_each_dive (i, dive)
|
||||
dive->selected = false;
|
||||
for (int i = 0; i < trip_table.nr; ++i)
|
||||
trip_table.trips[i]->selected = false;
|
||||
for (int i = 0; i < divelog.trips->nr; ++i)
|
||||
divelog.trips->trips[i]->selected = false;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "statistics.h"
|
||||
#include "dive.h"
|
||||
#include "divelog.h"
|
||||
#include "event.h"
|
||||
#include "gettext.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;
|
||||
stats_t stats = { 0 };
|
||||
|
||||
if (dive_table.nr > 0) {
|
||||
stats.shortest_time.seconds = dive_table.dives[0]->duration.seconds;
|
||||
stats.min_depth.mm = dive_table.dives[0]->maxdepth.mm;
|
||||
stats.selection_size = dive_table.nr;
|
||||
if (divelog.dives->nr > 0) {
|
||||
stats.shortest_time.seconds = divelog.dives->dives[0]->duration.seconds;
|
||||
stats.min_depth.mm = divelog.dives->dives[0]->maxdepth.mm;
|
||||
stats.selection_size = divelog.dives->nr;
|
||||
}
|
||||
|
||||
/* allocate sufficient space to hold the worst
|
||||
* case (one dive per year or all dives during
|
||||
* 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);
|
||||
dsize = sizeof(stats_t) * ((STATS_MAX_DEPTH / STATS_DEPTH_BUCKET) + 1);
|
||||
tmsize = sizeof(stats_t) * ((STATS_MAX_TEMP / STATS_TEMP_BUCKET) + 1);
|
||||
|
|
13
core/trip.c
13
core/trip.c
|
@ -2,14 +2,13 @@
|
|||
|
||||
#include "trip.h"
|
||||
#include "dive.h"
|
||||
#include "divelog.h"
|
||||
#include "subsurface-time.h"
|
||||
#include "subsurface-string.h"
|
||||
#include "selection.h"
|
||||
#include "table.h"
|
||||
#include "core/qthelper.h"
|
||||
|
||||
struct trip_table trip_table;
|
||||
|
||||
#ifdef DEBUG_TRIP
|
||||
void dump_trip_list(void)
|
||||
{
|
||||
|
@ -17,9 +16,9 @@ void dump_trip_list(void)
|
|||
int i = 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;
|
||||
trip = trip_table.trips[i];
|
||||
trip = divelog.trips->trips[i];
|
||||
utc_mkdate(trip_date(trip), &tm);
|
||||
if (trip_date(trip) < last_time)
|
||||
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 */
|
||||
dive_trip_t *get_trip_by_uniq_id(int tripId)
|
||||
{
|
||||
for (int i = 0; i < trip_table.nr; i++) {
|
||||
if (trip_table.trips[i]->id == tripId)
|
||||
return trip_table.trips[i];
|
||||
for (int i = 0; i < divelog.trips->nr; i++) {
|
||||
if (divelog.trips->trips[i]->id == tripId)
|
||||
return divelog.trips->trips[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -63,7 +63,6 @@ void clear_trip_table(struct trip_table *table);
|
|||
extern void dump_trip_list(void);
|
||||
#endif
|
||||
|
||||
extern struct trip_table trip_table;
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "libdivecomputer.h"
|
||||
#include "uemis.h"
|
||||
#include "divelist.h"
|
||||
#include "divelog.h"
|
||||
#include "divesite.h"
|
||||
#include "errorhelper.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.
|
||||
*/
|
||||
if (!force && !table->nr)
|
||||
table = &dive_table;
|
||||
table = divelog.dives;
|
||||
|
||||
for (i = 0; i < table->nr; i++) {
|
||||
struct dive *d = table->dives[i];
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "core/filterpreset.h"
|
||||
#include "core/qthelper.h"
|
||||
#include "core/divesite.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/device.h"
|
||||
#include "core/trip.h"
|
||||
#include "core/import-csv.h"
|
||||
|
@ -879,19 +880,15 @@ void DiveLogImportDialog::parseTxtHeader(QString fileName, xml_params ¶ms)
|
|||
|
||||
void DiveLogImportDialog::on_buttonBox_accepted()
|
||||
{
|
||||
struct dive_table table = empty_dive_table;
|
||||
struct trip_table trips = empty_trip_table;
|
||||
struct dive_site_table sites = empty_dive_site_table;
|
||||
struct device_table devices;
|
||||
struct filter_preset_table filter_presets;
|
||||
struct divelog log;
|
||||
QStringList r = resultModel->result();
|
||||
if (ui->knownImports->currentText() != "Manual import") {
|
||||
for (int i = 0; i < fileNames.size(); ++i) {
|
||||
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") {
|
||||
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 {
|
||||
xml_params params;
|
||||
|
||||
|
@ -908,7 +905,7 @@ void DiveLogImportDialog::on_buttonBox_accepted()
|
|||
setup_csv_params(r, params);
|
||||
parse_csv_file(qPrintable(fileNames[i]), ¶ms,
|
||||
specialCSV.contains(ui->knownImports->currentIndex()) ? qPrintable(CSVApps[ui->knownImports->currentIndex()].name) : "csv",
|
||||
&table, &trips, &sites, &devices, &filter_presets);
|
||||
&log);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -944,7 +941,7 @@ void DiveLogImportDialog::on_buttonBox_accepted()
|
|||
xml_params_add_int(¶ms, "visibilityField", r.indexOf(tr("Visibility")));
|
||||
xml_params_add_int(¶ms, "ratingField", r.indexOf(tr("Rating")));
|
||||
|
||||
parse_manual_file(qPrintable(fileNames[i]), ¶ms, &table, &trips, &sites, &devices, &filter_presets);
|
||||
parse_manual_file(qPrintable(fileNames[i]), ¶ms, &log);
|
||||
} else {
|
||||
xml_params params;
|
||||
|
||||
|
@ -962,13 +959,13 @@ void DiveLogImportDialog::on_buttonBox_accepted()
|
|||
setup_csv_params(r, params);
|
||||
parse_csv_file(qPrintable(fileNames[i]), ¶ms,
|
||||
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");
|
||||
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)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include "divesitelistview.h"
|
||||
#include "core/subsurface-qt/divelistnotifier.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/divesite.h"
|
||||
#include "core/divefilter.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)
|
||||
{
|
||||
int idx = get_divesite_idx(ds, &dive_site_table);
|
||||
int idx = get_divesite_idx(ds, divelog.sites);
|
||||
if (idx < 0)
|
||||
return;
|
||||
QModelIndex globalIdx = LocationInformationModel::instance()->index(idx, field);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "commands/command.h"
|
||||
#include "core/qthelper.h"
|
||||
#include "core/divelist.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/settings/qPrefDiveComputer.h"
|
||||
#include "core/subsurface-float.h"
|
||||
#include "core/subsurface-string.h"
|
||||
|
@ -423,7 +424,7 @@ void DownloadFromDCWidget::on_downloadCancelRetryButton_clicked()
|
|||
qPrefDiveComputer::set_device(data->devName());
|
||||
|
||||
// before we start, remember where the dive_table ended
|
||||
previousLast = dive_table.nr;
|
||||
previousLast = divelog.dives->nr;
|
||||
diveImportedModel->startDownload();
|
||||
|
||||
// FIXME: We should get the _actual_ device info instead of whatever
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "desktop-widgets/mapwidget.h"
|
||||
#include "core/color.h"
|
||||
#include "core/divefilter.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/divesite.h"
|
||||
#include "core/divesitehelpers.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 (has_location(¤tLocation)) {
|
||||
// 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 *ds2 = get_dive_site(source_right.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, divelog.sites);
|
||||
return get_distance(&ds1->location, ¤tLocation) < get_distance(&ds2->location, ¤tLocation);
|
||||
}
|
||||
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.
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -418,7 +419,7 @@ int DiveLocationModel::columnCount(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
|
||||
|
@ -541,12 +542,11 @@ static struct dive_site *get_dive_site_name_start_which_str(const QString &str)
|
|||
{
|
||||
struct dive_site *ds;
|
||||
int i;
|
||||
for_each_dive_site (i, ds, &dive_site_table) {
|
||||
for_each_dive_site (i, ds, divelog.sites) {
|
||||
QString dsName(ds->name);
|
||||
if (dsName.toLower().startsWith(str.toLower())) {
|
||||
if (dsName.toLower().startsWith(str.toLower()))
|
||||
return ds;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include "core/color.h"
|
||||
#include "core/device.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/divesitehelpers.h"
|
||||
#include "core/errorhelper.h"
|
||||
#include "core/file.h"
|
||||
|
@ -413,7 +414,7 @@ void MainWindow::on_actionCloudstorageopen_triggered()
|
|||
|
||||
showProgressBar();
|
||||
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());
|
||||
process_loaded_dives();
|
||||
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.
|
||||
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")));
|
||||
return false;
|
||||
}
|
||||
|
@ -1276,18 +1277,14 @@ void MainWindow::importFiles(const QStringList fileNames)
|
|||
return;
|
||||
|
||||
QByteArray fileNamePtr;
|
||||
struct dive_table table = empty_dive_table;
|
||||
struct trip_table trips = empty_trip_table;
|
||||
struct dive_site_table sites = empty_dive_site_table;
|
||||
struct device_table devices;
|
||||
struct filter_preset_table filter_presets;
|
||||
struct divelog log;
|
||||
|
||||
for (int i = 0; i < fileNames.size(); ++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");
|
||||
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)
|
||||
|
@ -1301,7 +1298,7 @@ void MainWindow::loadFiles(const QStringList fileNames)
|
|||
showProgressBar();
|
||||
for (int i = 0; i < fileNames.size(); ++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());
|
||||
addRecentFile(fileNamePtr, false);
|
||||
}
|
||||
|
@ -1372,28 +1369,19 @@ void MainWindow::on_actionImportDiveSites_triggered()
|
|||
return;
|
||||
updateLastUsedDir(QFileInfo(fileNames[0]).dir().path());
|
||||
|
||||
struct dive_table table = empty_dive_table;
|
||||
struct trip_table trips = empty_trip_table;
|
||||
struct dive_site_table sites = empty_dive_site_table;
|
||||
struct device_table devices;
|
||||
struct filter_preset_table filter_presets;
|
||||
struct divelog log;
|
||||
|
||||
for (const QString &s: fileNames) {
|
||||
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
|
||||
for (int i = 0; i < sites.nr; ++i)
|
||||
sites.dive_sites[i]->dives.nr = 0;
|
||||
|
||||
// Now we can clear the imported dives and trips.
|
||||
clear_dive_table(&table);
|
||||
clear_trip_table(&trips);
|
||||
for (int i = 0; i < log.sites->nr; ++i)
|
||||
log.sites->dive_sites[i]->dives.nr = 0;
|
||||
|
||||
QString source = fileNames.size() == 1 ? fileNames[0] : tr("multiple files");
|
||||
|
||||
// sites table will be cleared by DivesiteImportDialog constructor
|
||||
DivesiteImportDialog divesiteImport(sites, source, this);
|
||||
DivesiteImportDialog divesiteImport(*log.sites, source, this);
|
||||
divesiteImport.exec();
|
||||
}
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
#include "desktop-widgets/mainwindow.h"
|
||||
#include "commands/command.h"
|
||||
#include "core/device.h"
|
||||
#include "core/divesite.h"
|
||||
#include "core/trip.h"
|
||||
#include "core/divelist.h" // For IMPORT_MERGE_ALL_TRIPS
|
||||
#include "core/divelog.h"
|
||||
#include "core/errorhelper.h"
|
||||
#include "core/file.h"
|
||||
#include "desktop-widgets/mapwidget.h"
|
||||
|
@ -463,13 +463,9 @@ void DivelogsDeWebServices::buttonClicked(QAbstractButton *button)
|
|||
break;
|
||||
}
|
||||
/* parse file and import dives */
|
||||
struct dive_table table = empty_dive_table;
|
||||
struct trip_table trips = empty_trip_table;
|
||||
struct dive_site_table sites = empty_dive_site_table;
|
||||
struct device_table devices;
|
||||
struct filter_preset_table filter_presets;
|
||||
parse_file(QFile::encodeName(zipFile.fileName()), &table, &trips, &sites, &devices, &filter_presets);
|
||||
Command::importDives(&table, &trips, &sites, &devices, nullptr, IMPORT_MERGE_ALL_TRIPS, QStringLiteral("divelogs.de"));
|
||||
struct divelog log;
|
||||
parse_file(QFile::encodeName(zipFile.fileName()), &log);
|
||||
Command::importDives(log.dives, log.trips, log.sites, log.devices, nullptr, IMPORT_MERGE_ALL_TRIPS, QStringLiteral("divelogs.de"));
|
||||
|
||||
/* store last entered user/pass in config */
|
||||
qPrefCloudStorage::set_divelogde_user(ui.userID->text());
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include "tripselectiondialog.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/string-format.h"
|
||||
#include "core/trip.h"
|
||||
#include <QShortcut>
|
||||
|
@ -17,9 +18,9 @@ TripSelectionDialog::TripSelectionDialog(QWidget *parent) : QDialog(parent)
|
|||
|
||||
// We could use a model, but it seems barely worth the hassle.
|
||||
QStringList list;
|
||||
list.reserve(trip_table.nr);
|
||||
for (int i = 0; i < trip_table.nr; ++i)
|
||||
list.push_back(formatTripTitleWithDives(trip_table.trips[i]));
|
||||
list.reserve(divelog.trips->nr);
|
||||
for (int i = 0; i < divelog.trips->nr; ++i)
|
||||
list.push_back(formatTripTitleWithDives(divelog.trips->trips[i]));
|
||||
ui.trips->addItems(list);
|
||||
}
|
||||
|
||||
|
@ -36,9 +37,9 @@ dive_trip *TripSelectionDialog::selectedTrip() const
|
|||
if (rows.size() != 1)
|
||||
return nullptr;
|
||||
int idx = rows[0].row();
|
||||
if (idx < 0 || idx >= trip_table.nr)
|
||||
if (idx < 0 || idx >= divelog.trips->nr)
|
||||
return nullptr;
|
||||
return trip_table.trips[idx];
|
||||
return divelog.trips->trips[idx];
|
||||
}
|
||||
|
||||
dive_trip *TripSelectionDialog::getTrip()
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "core/qthelper.h"
|
||||
#include "core/file.h"
|
||||
#include "core/device.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/divesite.h"
|
||||
#include "core/trip.h"
|
||||
#include "core/save-html.h"
|
||||
|
@ -45,7 +46,7 @@ int main(int argc, char **argv)
|
|||
qDebug() << "need --source and --output";
|
||||
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) {
|
||||
fprintf(stderr, "parse_file returned %d\n", ret);
|
||||
exit(1);
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "core/errorhelper.h"
|
||||
#include "core/file.h"
|
||||
#include "core/divefilter.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/filterconstraint.h"
|
||||
#include "core/qthelper.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
|
||||
* 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 */
|
||||
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) {
|
||||
/* there can be 2 reasons for this:
|
||||
* 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);
|
||||
qPrefPartialPressureGas::set_po2(git_prefs.pp_graphs.po2);
|
||||
// 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();
|
||||
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) {
|
||||
appendTextToLog(QStringLiteral("have cloud credentials, but still needs PIN"));
|
||||
|
@ -472,13 +473,9 @@ static QString nocloud_localstorage()
|
|||
|
||||
void QMLManager::mergeLocalRepo()
|
||||
{
|
||||
struct dive_table table = empty_dive_table;
|
||||
struct trip_table trips = empty_trip_table;
|
||||
struct dive_site_table sites = empty_dive_site_table;
|
||||
struct device_table devices;
|
||||
struct filter_preset_table filter_presets;
|
||||
parse_file(qPrintable(nocloud_localstorage()), &table, &trips, &sites, &devices, &filter_presets);
|
||||
add_imported_dives(&table, &trips, &sites, &devices, IMPORT_MERGE_ALL_TRIPS);
|
||||
struct divelog log;
|
||||
parse_file(qPrintable(nocloud_localstorage()), &log);
|
||||
add_imported_dives(&log, IMPORT_MERGE_ALL_TRIPS);
|
||||
mark_divelist_changed(true);
|
||||
}
|
||||
|
||||
|
@ -578,7 +575,7 @@ void QMLManager::finishSetup()
|
|||
qPrefCloudStorage::set_cloud_verification_status(qPrefCloudStorage::CS_NOCLOUD);
|
||||
saveCloudCredentials(qPrefCloudStorage::cloud_storage_email(), qPrefCloudStorage::cloud_storage_password(), qPrefCloudStorage::cloud_storage_pin());
|
||||
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) {
|
||||
// we got an error loading the local file
|
||||
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
|
||||
consumeFinishedLoad();
|
||||
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 {
|
||||
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_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;
|
||||
// since we already have dives in the table, let's remember that so we can keep them
|
||||
noCloudToCloud = true;
|
||||
|
@ -795,10 +792,10 @@ void QMLManager::loadDivesWithValidCredentials()
|
|||
}
|
||||
if (info.repo) {
|
||||
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 {
|
||||
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);
|
||||
if (!error) {
|
||||
|
@ -822,7 +819,7 @@ void QMLManager::loadDivesWithValidCredentials()
|
|||
if (noCloudToCloud) {
|
||||
git_storage_update_progress(qPrintable(tr("Loading dives from local storage ('no cloud' mode)")));
|
||||
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;
|
||||
mark_divelist_changed(true);
|
||||
emit syncStateChanged();
|
||||
|
@ -886,8 +883,8 @@ void QMLManager::consumeFinishedLoad()
|
|||
prefs.show_ccr_sensors = git_prefs.show_ccr_sensors;
|
||||
prefs.pp_graphs.po2 = git_prefs.pp_graphs.po2;
|
||||
process_loaded_dives();
|
||||
appendTextToLog(QStringLiteral("%1 dives loaded").arg(dive_table.nr));
|
||||
if (dive_table.nr == 0)
|
||||
appendTextToLog(QStringLiteral("%1 dives loaded").arg(divelog.dives->nr));
|
||||
if (divelog.dives->nr == 0)
|
||||
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;
|
||||
QString oldLocation = get_dive_location(d);
|
||||
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()) {
|
||||
res.createdDs.reset(alloc_dive_site_with_name(qPrintable(location)));
|
||||
res.changed = true;
|
||||
|
@ -1800,7 +1797,7 @@ QString QMLManager::getGpsFromSiteName(const QString &siteName)
|
|||
{
|
||||
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)
|
||||
return QString();
|
||||
return printGPSCoords(&ds->location);
|
||||
|
@ -2347,15 +2344,11 @@ void QMLManager::setDiveListProcessing(bool value)
|
|||
|
||||
void QMLManager::importCacheRepo(QString repo)
|
||||
{
|
||||
struct dive_table table = empty_dive_table;
|
||||
struct trip_table trips = empty_trip_table;
|
||||
struct dive_site_table sites = empty_dive_site_table;
|
||||
struct device_table devices;
|
||||
struct filter_preset_table filter_presets;
|
||||
struct divelog log;
|
||||
QString repoPath = QString("%1/cloudstorage/%2").arg(system_default_directory()).arg(repo);
|
||||
appendTextToLog(QString("importing %1").arg(repoPath));
|
||||
parse_file(qPrintable(repoPath), &table, &trips, &sites, &devices, &filter_presets);
|
||||
add_imported_dives(&table, &trips, &sites, &devices, IMPORT_MERGE_ALL_TRIPS);
|
||||
parse_file(qPrintable(repoPath), &log);
|
||||
add_imported_dives(&log, IMPORT_MERGE_ALL_TRIPS);
|
||||
changesNeedSaving();
|
||||
}
|
||||
|
||||
|
@ -2370,11 +2363,10 @@ QStringList QMLManager::cloudCacheList() const
|
|||
if (dir == "localrepo") {
|
||||
result << QString("localrepo[master]");
|
||||
} else {
|
||||
foreach(QString branch, remote.entryList().filter(QRegularExpression("...+"))) {
|
||||
foreach(QString branch, remote.entryList().filter(QRegularExpression("...+")))
|
||||
result << QString("%1[%2]").arg(dir).arg(branch);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "core/subsurface-qt/divelistnotifier.h"
|
||||
#include "core/qthelper.h"
|
||||
#include "core/divesite.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/metrics.h"
|
||||
#ifndef SUBSURFACE_MOBILE
|
||||
#include "cleanertablemodel.h" // for trashIcon() and editIcon()
|
||||
|
@ -36,7 +37,7 @@ int LocationInformationModel::columnCount(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
|
||||
|
@ -124,7 +125,7 @@ QVariant LocationInformationModel::data(const QModelIndex &index, int role) cons
|
|||
if (!index.isValid())
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -136,7 +137,7 @@ void LocationInformationModel::update()
|
|||
|
||||
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)
|
||||
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)
|
||||
{
|
||||
int idx = get_divesite_idx(ds, &dive_site_table);
|
||||
int idx = get_divesite_idx(ds, divelog.sites);
|
||||
if (idx < 0)
|
||||
return;
|
||||
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)
|
||||
{
|
||||
int idx = get_divesite_idx(ds, &dive_site_table);
|
||||
int idx = get_divesite_idx(ds, divelog.sites);
|
||||
if (idx < 0)
|
||||
return;
|
||||
dataChanged(createIndex(idx, NUM_DIVES), createIndex(idx, NUM_DIVES));
|
||||
|
@ -180,9 +181,9 @@ bool DiveSiteSortedModel::filterAcceptsRow(int sourceRow, const QModelIndex &sou
|
|||
if (fullText.isEmpty())
|
||||
return true;
|
||||
|
||||
if (sourceRow < 0 || sourceRow > dive_site_table.nr)
|
||||
if (sourceRow < 0 || sourceRow > divelog.sites->nr)
|
||||
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);
|
||||
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.
|
||||
// Let's access them directly without going via the source model.
|
||||
// Kind of dirty, but less effort.
|
||||
struct dive_site *ds1 = get_dive_site(i1.row(), &dive_site_table);
|
||||
struct dive_site *ds2 = get_dive_site(i2.row(), &dive_site_table);
|
||||
struct dive_site *ds1 = get_dive_site(i1.row(), divelog.sites);
|
||||
struct dive_site *ds2 = get_dive_site(i2.row(), divelog.sites);
|
||||
if (!ds1 || !ds2) // Invalid dive sites compare as different
|
||||
return false;
|
||||
switch (i1.column()) {
|
||||
|
@ -229,18 +230,18 @@ QStringList DiveSiteSortedModel::allSiteNames() const
|
|||
// 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),
|
||||
// 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");
|
||||
continue;
|
||||
}
|
||||
locationNames << QString(dive_site_table.dive_sites[idx]->name);
|
||||
locationNames << QString(divelog.sites->dive_sites[idx]->name);
|
||||
}
|
||||
return locationNames;
|
||||
}
|
||||
|
||||
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
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include "diveplannermodel.h"
|
||||
#include "core/divelist.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/subsurface-string.h"
|
||||
#include "qt-models/cylindermodel.h"
|
||||
#include "core/planner.h"
|
||||
|
@ -93,15 +94,14 @@ void DivePlannerPointsModel::setupStartTime()
|
|||
// if the latest dive is in the future, then start an hour after it ends
|
||||
// otherwise start an hour from now
|
||||
startTime = QDateTime::currentDateTimeUtc().addSecs(3600 + gettimezoneoffset());
|
||||
if (dive_table.nr) {
|
||||
struct dive *d = get_dive(dive_table.nr - 1);
|
||||
if (divelog.dives->nr > 0) {
|
||||
struct dive *d = get_dive(divelog.dives->nr - 1);
|
||||
time_t ends = dive_endtime(d);
|
||||
time_t diff = ends - dateTimeToTimestamp(startTime);
|
||||
if (diff > 0) {
|
||||
if (diff > 0)
|
||||
startTime = startTime.addSecs(diff + 3600);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DivePlannerPointsModel::loadFromDive(dive *dIn)
|
||||
{
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "divesiteimportmodel.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/qthelper.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
|
||||
struct dive_site *nearest_ds =
|
||||
get_dive_site_by_gps_proximity(&ds->location,
|
||||
40075000, &dive_site_table);
|
||||
40075000, divelog.sites);
|
||||
if (nearest_ds)
|
||||
return nearest_ds->name;
|
||||
else
|
||||
|
@ -77,7 +78,7 @@ QVariant DivesiteImportedModel::data(const QModelIndex &index, int role) const
|
|||
unsigned int distance = 0;
|
||||
struct dive_site *nearest_ds =
|
||||
get_dive_site_by_gps_proximity(&ds->location,
|
||||
40075000, &dive_site_table);
|
||||
40075000, divelog.sites);
|
||||
if (nearest_ds)
|
||||
distance = get_distance(&ds->location,
|
||||
&nearest_ds->location);
|
||||
|
@ -134,7 +135,7 @@ void DivesiteImportedModel::repopulate(struct dive_site_table *sites)
|
|||
lastIndex = importedSitesTable->nr - 1;
|
||||
checkStates.resize(importedSitesTable->nr);
|
||||
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;
|
||||
else
|
||||
checkStates[row] = true;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include "qt-models/divetripmodel.h"
|
||||
#include "core/divefilter.h"
|
||||
#include "core/divelog.h"
|
||||
#ifdef SUBSURFACE_MOBILE
|
||||
#include "qt-models/mobilelistmodel.h"
|
||||
#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"
|
||||
uiNotification(QObject::tr("populate data model"));
|
||||
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);
|
||||
if (!d) // should never happen
|
||||
continue;
|
||||
|
@ -741,7 +742,7 @@ void DiveTripModelTree::populate()
|
|||
|
||||
// Remember the index of the 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
|
||||
|
@ -1470,8 +1471,8 @@ void DiveTripModelList::populate()
|
|||
DiveFilter::instance()->reset(); // The data was reset - update filter status. TODO: should this really be done here?
|
||||
|
||||
// Fill model
|
||||
items.reserve(dive_table.nr);
|
||||
for (int i = 0; i < dive_table.nr; ++i) {
|
||||
items.reserve(divelog.dives->nr);
|
||||
for (int i = 0; i < divelog.dives->nr; ++i) {
|
||||
dive *d = get_dive(i);
|
||||
if (!d || d->hidden_by_filter)
|
||||
continue;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "divelocationmodel.h"
|
||||
#include "core/divesite.h"
|
||||
#include "core/divefilter.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/settings/qPrefDisplay.h"
|
||||
#if !defined(SUBSURFACE_MOBILE) && !defined(SUBSURFACE_DOWNLOADER)
|
||||
#include "qt-models/filtermodels.h"
|
||||
|
@ -161,8 +162,8 @@ void MapLocationModel::reload(QObject *map)
|
|||
if (diveSiteMode)
|
||||
m_selectedDs = DiveFilter::instance()->filteredDiveSites();
|
||||
#endif
|
||||
for (int i = 0; i < dive_site_table.nr; ++i) {
|
||||
struct dive_site *ds = dive_site_table.dive_sites[i];
|
||||
for (int i = 0; i < divelog.sites->nr; ++i) {
|
||||
struct dive_site *ds = divelog.sites->dive_sites[i];
|
||||
QGeoCoordinate dsCoord;
|
||||
|
||||
// Don't show dive sites of hidden dives, unless we're in dive site edit mode.
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#endif
|
||||
|
||||
#include "core/dive.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/subsurface-string.h"
|
||||
#include "core/gettext.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:
|
||||
* | 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;
|
||||
MdbColumn *col[MDB_MAX_COLS];
|
||||
|
@ -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", site);
|
||||
|
||||
ds = get_dive_site_by_name(str, &dive_site_table);
|
||||
ds = get_dive_site_by_name(str, log->sites);
|
||||
if (!ds) {
|
||||
if (!has_location(&loc))
|
||||
ds = create_dive_site(str, &dive_site_table);
|
||||
ds = create_dive_site(str, log->sites);
|
||||
else
|
||||
ds = create_dive_site_with_gps(str, &loc, &dive_site_table);
|
||||
ds = create_dive_site_with_gps(str, &loc, log->sites);
|
||||
}
|
||||
*location = ds;
|
||||
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.
|
||||
*/
|
||||
|
||||
void smartrak_import(const char *file, struct dive_table *divetable)
|
||||
void smartrak_import(const char *file, struct divelog *log)
|
||||
{
|
||||
MdbHandle *mdb, *mdb_clon;
|
||||
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 };
|
||||
add_cloned_weightsystem(&smtkdive->weightsystems, ws);
|
||||
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);
|
||||
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);
|
||||
|
@ -1109,7 +1110,7 @@ void smartrak_import(const char *file, struct dive_table *divetable)
|
|||
smtk_parse_bookmarks(mdb_clon, smtkdive, col[0]->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);
|
||||
}
|
||||
mdb_free_tabledef(mdb_table);
|
||||
|
@ -1117,5 +1118,5 @@ void smartrak_import(const char *file, struct dive_table *divetable)
|
|||
mdb->catalog = NULL;
|
||||
mdb_close(mdb_clon);
|
||||
mdb_close(mdb);
|
||||
sort_dive_table(divetable);
|
||||
sort_dive_table(log->dives);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "ui_smrtk2ssrfc_window.h"
|
||||
#include "qt-models/filtermodels.h"
|
||||
#include "core/dive.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/divelist.h"
|
||||
#include "core/errorhelper.h"
|
||||
#include "core/settings/qPrefDisplay.h"
|
||||
|
@ -84,7 +85,7 @@ void Smrtk2ssrfcWindow::on_importButton_clicked()
|
|||
for (int i = 0; i < inputFiles.size(); ++i) {
|
||||
ui->progressBar->setValue(i);
|
||||
fileNamePtr = QFile::encodeName(inputFiles.at(i));
|
||||
smartrak_import(fileNamePtr.data(), &dive_table);
|
||||
smartrak_import(fileNamePtr.data(), &divelog);
|
||||
ui->plainTextEdit->appendPlainText(error_buf);
|
||||
}
|
||||
ui->progressBar->setValue(inputFiles.size());
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
#include <QFileDialog>
|
||||
#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 {
|
||||
class Smrtk2ssrfcWindow;
|
||||
|
|
|
@ -3,12 +3,11 @@
|
|||
#include <stdio.h>
|
||||
#include "core/dive.h"
|
||||
#include "core/divelist.h"
|
||||
#include "core/divelog.h"
|
||||
#include "smrtk2ssrfc_window.h"
|
||||
#include <QApplication>
|
||||
#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
|
||||
* the GUI if called without arguments.
|
||||
|
@ -48,7 +47,7 @@ int main(int argc, char *argv[])
|
|||
for(i = 1; i < argc -1; i++) {
|
||||
infile = argv[i];
|
||||
qDebug() << "\t" << infile << "\n";
|
||||
smartrak_import(infile, &dive_table);
|
||||
smartrak_import(infile, &divelog);
|
||||
}
|
||||
qDebug() << "\n[Writing]\n\t" << outfile << "\n";
|
||||
save_dives_logic(outfile, false, false);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "statsvariables.h"
|
||||
#include "statstranslations.h"
|
||||
#include "core/dive.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/divemode.h"
|
||||
#include "core/divesite.h"
|
||||
#include "core/gas.h"
|
||||
|
@ -1380,7 +1381,7 @@ struct DiveNrVariable : public StatsVariableTemplate<StatsVariable::Type::Numeri
|
|||
return StatsTranslations::tr("Dive #");
|
||||
}
|
||||
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 };
|
||||
else
|
||||
return { &dive_nr_binner_5, &dive_nr_binner_10, &dive_nr_binner_20, &dive_nr_binner_50 };
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <time.h>
|
||||
|
||||
#include "core/downloadfromdcthread.h" // for fill_computer_list
|
||||
#include "core/divelog.h"
|
||||
#include "core/errorhelper.h"
|
||||
#include "core/parse.h"
|
||||
#include "core/qt-gui.h"
|
||||
|
@ -109,6 +110,7 @@ int main(int argc, char **argv)
|
|||
if (!quit)
|
||||
run_ui();
|
||||
exit_ui();
|
||||
clear_divelog(&divelog);
|
||||
taglist_free(g_tag_list);
|
||||
parse_xml_exit();
|
||||
free((void *)default_directory);
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "core/settings/qPref.h"
|
||||
#include "core/tag.h"
|
||||
#include "core/dive.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/subsurface-string.h"
|
||||
#include "core/file.h"
|
||||
#include "core/trip.h"
|
||||
|
@ -40,10 +41,7 @@ int main(int argc, char **argv)
|
|||
QStringList files;
|
||||
QStringList importedFiles;
|
||||
QStringList arguments = QCoreApplication::arguments();
|
||||
struct dive_table dive_table = empty_dive_table;
|
||||
struct dive_site_table sites = empty_dive_site_table;
|
||||
struct device_table devices;
|
||||
struct filter_preset_table presets;
|
||||
struct divelog log;
|
||||
|
||||
// set a default logfile name for libdivecomputer so we always get a logfile
|
||||
logfile_name = strdup("subsurface-downloader.log");
|
||||
|
@ -95,7 +93,7 @@ int main(int argc, char **argv)
|
|||
filesOnCommandLine = !files.isEmpty() || !importedFiles.isEmpty();
|
||||
if (!files.isEmpty()) {
|
||||
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();
|
||||
if (!quit) {
|
||||
|
@ -106,6 +104,7 @@ int main(int argc, char **argv)
|
|||
}
|
||||
}
|
||||
save_dives(qPrintable(files.first()));
|
||||
clear_divelog(&divelog);
|
||||
taglist_free(g_tag_list);
|
||||
parse_xml_exit();
|
||||
free((void *)default_directory);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <time.h>
|
||||
|
||||
#include "core/dive.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/color.h"
|
||||
#include "core/downloadfromdcthread.h"
|
||||
#include "core/parse.h"
|
||||
|
@ -93,6 +94,7 @@ int main(int argc, char **argv)
|
|||
if (!quit)
|
||||
run_mobile_ui(initial_font_size);
|
||||
exit_ui();
|
||||
clear_divelog(&divelog);
|
||||
taglist_free(g_tag_list);
|
||||
parse_xml_exit();
|
||||
subsurface_console_exit();
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "testAirPressure.h"
|
||||
#include "core/device.h"
|
||||
#include "core/dive.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/divesite.h"
|
||||
#include "core/trip.h"
|
||||
#include "core/file.h"
|
||||
|
@ -21,8 +22,7 @@ void TestAirPressure::get_dives()
|
|||
struct dive *dive;
|
||||
verbose = 1;
|
||||
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/TestAtmPress.xml", &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/TestAtmPress.xml", &divelog), 0);
|
||||
dive = get_dive(0);
|
||||
dive->selected = true;
|
||||
QVERIFY(dive != NULL);
|
||||
|
@ -57,8 +57,7 @@ void TestAirPressure::testWriteReadBackAirPressure()
|
|||
dive->surface_pressure.mbar = ap;
|
||||
QCOMPARE(save_dives("./testout.ssrf"), 0);
|
||||
clear_dive_file_data();
|
||||
QCOMPARE(parse_file("./testout.ssrf", &dive_table, &trip_table, &dive_site_table,
|
||||
&device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file("./testout.ssrf", &divelog), 0);
|
||||
dive = get_dive(0);
|
||||
QVERIFY(dive != NULL);
|
||||
dive->selected = true;
|
||||
|
|
|
@ -1,18 +1,15 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include "testdivesiteduplication.h"
|
||||
#include "core/device.h"
|
||||
#include "core/dive.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/divesite.h"
|
||||
#include "core/trip.h"
|
||||
#include "core/file.h"
|
||||
#include "core/pref.h"
|
||||
|
||||
void TestDiveSiteDuplication::testReadV2()
|
||||
{
|
||||
prefs.cloud_base_url = strdup(default_prefs.cloud_base_url);
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/TwoTimesTwo.ssrf", &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(dive_site_table.nr, 2);
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/TwoTimesTwo.ssrf", &divelog), 0);
|
||||
QCOMPARE(divelog.sites->nr, 2);
|
||||
}
|
||||
|
||||
QTEST_GUILESS_MAIN(TestDiveSiteDuplication)
|
||||
|
|
|
@ -4,13 +4,13 @@
|
|||
|
||||
#include "core/device.h"
|
||||
#include "core/dive.h"
|
||||
#include "core/divesite.h"
|
||||
#include "core/divelist.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/file.h"
|
||||
#include "core/qthelper.h"
|
||||
#include "core/subsurfacestartup.h"
|
||||
#include "core/settings/qPrefProxy.h"
|
||||
#include "core/settings/qPrefCloudStorage.h"
|
||||
#include "core/trip.h"
|
||||
#include "core/git-access.h"
|
||||
|
||||
#include <QDir>
|
||||
|
@ -152,8 +152,7 @@ void TestGitStorage::initTestCase()
|
|||
|
||||
// cleanup local and remote branches
|
||||
localRemoteCleanup();
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
|
||||
}
|
||||
|
||||
void TestGitStorage::cleanupTestCase()
|
||||
|
@ -185,8 +184,7 @@ void TestGitStorage::testGitStorageLocal()
|
|||
{
|
||||
// test writing and reading back from local git storage
|
||||
git_repository *repo;
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/SampleDivesV2.ssrf", &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/SampleDivesV2.ssrf", &divelog), 0);
|
||||
QFETCH(QString, testDirName);
|
||||
QFETCH(QString, prefixRead);
|
||||
QFETCH(QString, prefixWrite);
|
||||
|
@ -199,8 +197,7 @@ void TestGitStorage::testGitStorageLocal()
|
|||
QCOMPARE(save_dives(qPrintable(repoNameWrite + "[test]")), 0);
|
||||
QCOMPARE(save_dives("./SampleDivesV3.ssrf"), 0);
|
||||
clear_dive_file_data();
|
||||
QCOMPARE(parse_file(qPrintable(repoNameRead + "[test]"), &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(qPrintable(repoNameRead + "[test]"), &divelog), 0);
|
||||
QCOMPARE(save_dives("./SampleDivesV3viagit.ssrf"), 0);
|
||||
QFile org("./SampleDivesV3.ssrf");
|
||||
org.open(QFile::ReadOnly);
|
||||
|
@ -218,12 +215,10 @@ void TestGitStorage::testGitStorageCloud()
|
|||
// test writing and reading back from cloud storage
|
||||
// connect to the ssrftest repository on the cloud server
|
||||
// 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,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/SampleDivesV2.ssrf", &divelog), 0);
|
||||
QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
|
||||
clear_dive_file_data();
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
|
||||
QCOMPARE(save_dives("./SampleDivesV3viacloud.ssrf"), 0);
|
||||
QFile org("./SampleDivesV3.ssrf");
|
||||
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)
|
||||
// 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
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test10.xml", &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test10.xml", &divelog), 0);
|
||||
// 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
|
||||
process_loaded_dives();
|
||||
|
@ -255,8 +248,7 @@ void TestGitStorage::testGitStorageCloudOfflineSync()
|
|||
clear_dive_file_data();
|
||||
// now pretend that we are online again and open the cloud storage and compare
|
||||
git_local_only = false;
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
|
||||
QCOMPARE(save_dives("./SampleDivesV3plus10viacloud.ssrf"), 0);
|
||||
QFile org("./SampleDivesV3plus10local.ssrf");
|
||||
org.open(QFile::ReadOnly);
|
||||
|
@ -271,8 +263,7 @@ void TestGitStorage::testGitStorageCloudOfflineSync()
|
|||
QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
|
||||
clear_dive_file_data();
|
||||
moveDir(localCacheDir, localCacheDir + "save");
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
|
||||
QCOMPARE(save_dives("./SampleDivesV3plus10fromcloud.ssrf"), 0);
|
||||
org.close();
|
||||
org.open(QFile::ReadOnly);
|
||||
|
@ -301,10 +292,8 @@ void TestGitStorage::testGitStorageCloudMerge()
|
|||
|
||||
// (1) open the repo, add dive test11 and save to the cloud
|
||||
git_local_only = false;
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml", &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml", &divelog), 0);
|
||||
process_loaded_dives();
|
||||
QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
|
||||
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
|
||||
git_local_only = true;
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
|
||||
&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);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml", &divelog), 0);
|
||||
process_loaded_dives();
|
||||
QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
|
||||
clear_dive_file_data();
|
||||
|
||||
// (4) now take things back online
|
||||
git_local_only = false;
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
|
||||
clear_dive_file_data();
|
||||
|
||||
// (5) now we should have all the dives in our repo on the second client
|
||||
// first create the reference data from the xml files:
|
||||
QCOMPARE(parse_file("./SampleDivesV3plus10local.ssrf", &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml", &dive_table, &trip_table,
|
||||
&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);
|
||||
QCOMPARE(parse_file("./SampleDivesV3plus10local.ssrf", &divelog), 0);
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml", &divelog), 0);
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml", &divelog), 0);
|
||||
process_loaded_dives();
|
||||
QCOMPARE(save_dives("./SampleDivesV3plus10-11-12.ssrf"), 0);
|
||||
// then load from the cloud
|
||||
clear_dive_file_data();
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
|
||||
process_loaded_dives();
|
||||
QCOMPARE(save_dives("./SampleDivesV3plus10-11-12-merged.ssrf"), 0);
|
||||
// finally compare what we have
|
||||
|
@ -359,8 +341,7 @@ void TestGitStorage::testGitStorageCloudMerge()
|
|||
|
||||
// (6) move ourselves back to the first client and compare data there
|
||||
moveDir(localCacheDir + "client1", localCacheDir);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
|
||||
process_loaded_dives();
|
||||
QCOMPARE(save_dives("./SampleDivesV3plus10-11-12-merged-client1.ssrf"), 0);
|
||||
QFile client1("./SampleDivesV3plus10-11-12-merged-client1.ssrf");
|
||||
|
@ -376,8 +357,7 @@ void TestGitStorage::testGitStorageCloudMerge2()
|
|||
// edit the same dive in the cloud repo
|
||||
// merge
|
||||
// (1) open repo, delete second dive, save offline
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
|
||||
process_loaded_dives();
|
||||
struct dive *dive = get_dive(1);
|
||||
delete_single_dive(1);
|
||||
|
@ -391,8 +371,7 @@ void TestGitStorage::testGitStorageCloudMerge2()
|
|||
moveDir(localCacheDir, localCacheDir + "save");
|
||||
|
||||
// (3) now we open the cloud storage repo and modify that second dive
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
|
||||
process_loaded_dives();
|
||||
dive = get_dive(1);
|
||||
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
|
||||
// -> this forces a merge
|
||||
moveDir(localCacheDir + "save", localCacheDir);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
|
||||
QCOMPARE(save_dives("./SampleDivesMinus1-merged.ssrf"), 0);
|
||||
QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
|
||||
QFile org("./SampleDivesMinus1-merged.ssrf");
|
||||
|
@ -428,8 +406,7 @@ void TestGitStorage::testGitStorageCloudMerge3()
|
|||
|
||||
|
||||
// (1) open repo, edit notes of first three dives
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
|
||||
process_loaded_dives();
|
||||
struct dive *dive;
|
||||
QVERIFY((dive = get_dive(0)) != 0);
|
||||
|
@ -445,8 +422,7 @@ void TestGitStorage::testGitStorageCloudMerge3()
|
|||
clear_dive_file_data();
|
||||
|
||||
// (2) make different edits offline
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
|
||||
process_loaded_dives();
|
||||
QVERIFY((dive = get_dive(0)) != 0);
|
||||
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
|
||||
// those first dive notes differently while online
|
||||
moveDir(localCacheDir, localCacheDir + "save");
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
|
||||
process_loaded_dives();
|
||||
QVERIFY((dive = get_dive(0)) != 0);
|
||||
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
|
||||
moveDir(localCacheDir + "save", localCacheDir);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
|
||||
QCOMPARE(save_dives("./SampleDivesMerge3.ssrf"), 0);
|
||||
// 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
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "testmerge.h"
|
||||
#include "core/device.h"
|
||||
#include "core/dive.h" // for save_dives()
|
||||
#include "core/divelog.h"
|
||||
#include "core/divesite.h"
|
||||
#include "core/file.h"
|
||||
#include "core/trip.h"
|
||||
|
@ -25,15 +26,11 @@ void TestMerge::testMergeEmpty()
|
|||
/*
|
||||
* check that we correctly merge mixed cylinder dives
|
||||
*/
|
||||
struct dive_table table = empty_dive_table;
|
||||
struct trip_table trips = empty_trip_table;
|
||||
struct dive_site_table sites = empty_dive_site_table;
|
||||
struct device_table devices;
|
||||
struct filter_preset_table filter_presets;
|
||||
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);
|
||||
struct divelog log;
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &log), 0);
|
||||
add_imported_dives(&log, IMPORT_MERGE_ALL_TRIPS);
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &log), 0);
|
||||
add_imported_dives(&log, IMPORT_MERGE_ALL_TRIPS);
|
||||
QCOMPARE(save_dives("./testmerge47+48.ssrf"), 0);
|
||||
QFile org(SUBSURFACE_TEST_DATA "/dives/test47+48.xml");
|
||||
org.open(QFile::ReadOnly);
|
||||
|
@ -43,25 +40,20 @@ void TestMerge::testMergeEmpty()
|
|||
QTextStream outS(&out);
|
||||
QStringList readin = orgS.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());
|
||||
}
|
||||
}
|
||||
|
||||
void TestMerge::testMergeBackwards()
|
||||
{
|
||||
/*
|
||||
* check that we correctly merge mixed cylinder dives
|
||||
*/
|
||||
struct dive_table table = empty_dive_table;
|
||||
struct trip_table trips = empty_trip_table;
|
||||
struct dive_site_table sites = empty_dive_site_table;
|
||||
struct device_table devices;
|
||||
struct filter_preset_table filter_presets;
|
||||
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);
|
||||
struct divelog log;
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &log), 0);
|
||||
add_imported_dives(&log, IMPORT_MERGE_ALL_TRIPS);
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &log), 0);
|
||||
add_imported_dives(&log, IMPORT_MERGE_ALL_TRIPS);
|
||||
QCOMPARE(save_dives("./testmerge47+48.ssrf"), 0);
|
||||
QFile org(SUBSURFACE_TEST_DATA "/dives/test48+47.xml");
|
||||
org.open(QFile::ReadOnly);
|
||||
|
@ -71,9 +63,8 @@ void TestMerge::testMergeBackwards()
|
|||
QTextStream outS(&out);
|
||||
QStringList readin = orgS.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());
|
||||
}
|
||||
}
|
||||
|
||||
QTEST_GUILESS_MAIN(TestMerge)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "testparse.h"
|
||||
#include "core/device.h"
|
||||
#include "core/dive.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/divesite.h"
|
||||
#include "core/errorhelper.h"
|
||||
#include "core/trip.h"
|
||||
|
@ -85,19 +86,18 @@ int TestParse::parseCSV(int units, std::string file)
|
|||
xml_params_add_int(¶ms, "airtempField", -1);
|
||||
xml_params_add_int(¶ms, "watertempField", -1);
|
||||
|
||||
return parse_manual_file(file.c_str(), ¶ms, &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table);
|
||||
return parse_manual_file(file.c_str(), ¶ms, &divelog);
|
||||
}
|
||||
|
||||
int TestParse::parseDivingLog()
|
||||
{
|
||||
// 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ä");
|
||||
|
||||
int ret = sqlite3_open(SUBSURFACE_TEST_DATA "/dives/TestDivingLog4.1.1.sql", &_sqlite3_handle);
|
||||
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
|
||||
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()
|
||||
{
|
||||
// parsing of a V2 file should work
|
||||
return parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table);
|
||||
return parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &divelog);
|
||||
}
|
||||
|
||||
int TestParse::parseV3()
|
||||
{
|
||||
// parsing of a V3 files should succeed
|
||||
return parse_file(SUBSURFACE_TEST_DATA "/dives/test42.xml", &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table);
|
||||
return parse_file(SUBSURFACE_TEST_DATA "/dives/test42.xml", &divelog);
|
||||
}
|
||||
|
||||
void TestParse::testParse()
|
||||
{
|
||||
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);
|
||||
fprintf(stderr, "number of dives %d \n", dive_table.nr);
|
||||
fprintf(stderr, "number of dives %d \n", divelog.dives->nr);
|
||||
|
||||
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);
|
||||
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);
|
||||
FILE_COMPARE("./testout.ssrf",
|
||||
|
@ -140,7 +138,7 @@ void TestParse::testParse()
|
|||
void TestParse::testParseDM4()
|
||||
{
|
||||
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);
|
||||
FILE_COMPARE("./testdm4out.ssrf",
|
||||
|
@ -150,7 +148,7 @@ void TestParse::testParseDM4()
|
|||
void TestParse::testParseDM5()
|
||||
{
|
||||
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);
|
||||
FILE_COMPARE("./testdm5out.ssrf",
|
||||
|
@ -179,18 +177,17 @@ void TestParse::testParseHUDC()
|
|||
xml_params_add(¶ms, "hw", "\"DC text\"");
|
||||
|
||||
QCOMPARE(parse_csv_file(SUBSURFACE_TEST_DATA "/dives/TestDiveSeabearHUDC.csv",
|
||||
¶ms, "csv", &dive_table, &trip_table, &dive_site_table,
|
||||
&device_table, &filter_preset_table),
|
||||
¶ms, "csv", &divelog),
|
||||
0);
|
||||
|
||||
QCOMPARE(dive_table.nr, 1);
|
||||
QCOMPARE(divelog.dives->nr, 1);
|
||||
|
||||
/*
|
||||
* CSV import uses time and date stamps relative to current
|
||||
* time, thus we need to use a static (random) timestamp
|
||||
*/
|
||||
if (dive_table.nr > 0) {
|
||||
struct dive *dive = dive_table.dives[dive_table.nr - 1];
|
||||
if (divelog.dives->nr > 0) {
|
||||
struct dive *dive = divelog.dives->dives[divelog.dives->nr - 1];
|
||||
dive->when = 1255152761;
|
||||
dive->dc.when = 1255152761;
|
||||
}
|
||||
|
@ -225,13 +222,12 @@ void TestParse::testParseNewFormat()
|
|||
"/dives/")
|
||||
.append(files.at(i))
|
||||
.toLatin1()
|
||||
.data(), &dive_table, &trip_table, &dive_site_table,
|
||||
&device_table, &filter_preset_table),
|
||||
.data(), &divelog),
|
||||
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);
|
||||
|
||||
// Currently the CSV parse fails
|
||||
|
@ -245,9 +241,9 @@ void TestParse::testParseDLD()
|
|||
QString filename = SUBSURFACE_TEST_DATA "/dives/TestDiveDivelogsDE.DLD";
|
||||
|
||||
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
|
||||
QCOMPARE(save_dives("./testdldout.ssrf"), 0);
|
||||
|
@ -260,10 +256,8 @@ void TestParse::testParseMerge()
|
|||
/*
|
||||
* check that we correctly merge mixed cylinder dives
|
||||
*/
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/ostc.xml", &dive_table, &trip_table, &dive_site_table,
|
||||
&device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/vyper.xml", &dive_table, &trip_table, &dive_site_table,
|
||||
&device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/ostc.xml", &divelog), 0);
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/vyper.xml", &divelog), 0);
|
||||
QCOMPARE(save_dives("./testmerge.ssrf"), 0);
|
||||
FILE_COMPARE("./testmerge.ssrf",
|
||||
SUBSURFACE_TEST_DATA "/dives/mergedVyperOstc.xml");
|
||||
|
@ -303,22 +297,20 @@ int TestParse::parseCSVmanual(int units, std::string file)
|
|||
xml_params_add_int(¶ms, "datefmt", 2);
|
||||
xml_params_add_int(¶ms, "durationfmt", 2);
|
||||
xml_params_add_int(¶ms, "units", units);
|
||||
return parse_manual_file(file.c_str(), ¶ms, &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table);
|
||||
return parse_manual_file(file.c_str(), ¶ms, &divelog);
|
||||
}
|
||||
|
||||
void TestParse::exportCSVDiveDetails()
|
||||
{
|
||||
int saved_sac = 0;
|
||||
|
||||
parse_file(SUBSURFACE_TEST_DATA "/dives/test25.xml", &dive_table, &trip_table, &dive_site_table,
|
||||
&device_table, &filter_preset_table);
|
||||
parse_file(SUBSURFACE_TEST_DATA "/dives/test25.xml", &divelog);
|
||||
|
||||
export_dives_xslt("testcsvexportmanual.csv", 0, 0, "xml2manualcsv.xslt", false);
|
||||
export_dives_xslt("testcsvexportmanualimperial.csv", 0, 1, "xml2manualcsv.xslt", false);
|
||||
|
||||
if (dive_table.nr > 0) {
|
||||
struct dive *dive = dive_table.dives[dive_table.nr - 1];
|
||||
if (divelog.dives->nr > 0) {
|
||||
struct dive *dive = divelog.dives->dives[divelog.dives->nr - 1];
|
||||
saved_sac = dive->sac;
|
||||
}
|
||||
clear_dive_file_data();
|
||||
|
@ -326,8 +318,8 @@ void TestParse::exportCSVDiveDetails()
|
|||
parseCSVmanual(1, "testcsvexportmanualimperial.csv");
|
||||
|
||||
// We do not currently support reading SAC, thus faking it
|
||||
if (dive_table.nr > 0) {
|
||||
struct dive *dive = dive_table.dives[dive_table.nr - 1];
|
||||
if (divelog.dives->nr > 0) {
|
||||
struct dive *dive = divelog.dives->dives[divelog.dives->nr - 1];
|
||||
dive->sac = saved_sac;
|
||||
}
|
||||
|
||||
|
@ -347,14 +339,13 @@ void TestParse::exportSubsurfaceCSV()
|
|||
xml_params params;
|
||||
|
||||
/* Test SubsurfaceCSV with multiple cylinders */
|
||||
parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table);
|
||||
parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &divelog);
|
||||
|
||||
export_dives_xslt("testcsvexportmanual-cyl.csv", 0, 0, "xml2manualcsv.xslt", false);
|
||||
export_dives_xslt("testcsvexportmanualimperial-cyl.csv", 0, 1, "xml2manualcsv.xslt", false);
|
||||
|
||||
if (dive_table.nr > 0) {
|
||||
struct dive *dive = dive_table.dives[dive_table.nr - 1];
|
||||
if (divelog.dives->nr > 0) {
|
||||
struct dive *dive = divelog.dives->dives[divelog.dives->nr - 1];
|
||||
saved_sac = dive->sac;
|
||||
}
|
||||
|
||||
|
@ -362,12 +353,11 @@ void TestParse::exportSubsurfaceCSV()
|
|||
|
||||
xml_params_add_int(¶ms, "separatorIndex", 0);
|
||||
xml_params_add_int(¶ms, "units", 1);
|
||||
parse_csv_file("testcsvexportmanualimperial-cyl.csv", ¶ms, "SubsurfaceCSV", &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table);
|
||||
parse_csv_file("testcsvexportmanualimperial-cyl.csv", ¶ms, "SubsurfaceCSV", &divelog);
|
||||
|
||||
// We do not currently support reading SAC, thus faking it
|
||||
if (dive_table.nr > 0) {
|
||||
struct dive *dive = dive_table.dives[dive_table.nr - 1];
|
||||
if (divelog.dives->nr > 0) {
|
||||
struct dive *dive = divelog.dives->dives[divelog.dives->nr - 1];
|
||||
dive->sac = saved_sac;
|
||||
}
|
||||
|
||||
|
@ -396,14 +386,12 @@ int TestParse::parseCSVprofile(int units, std::string file)
|
|||
xml_params_add_int(¶ms, "datefmt", 2);
|
||||
xml_params_add_int(¶ms, "units", units);
|
||||
|
||||
return parse_csv_file(file.c_str(), ¶ms, "csv", &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table);
|
||||
return parse_csv_file(file.c_str(), ¶ms, "csv", &divelog);
|
||||
}
|
||||
|
||||
void TestParse::exportCSVDiveProfile()
|
||||
{
|
||||
parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table);
|
||||
parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &divelog);
|
||||
|
||||
export_dives_xslt("testcsvexportprofile.csv", 0, 0, "xml2csv.xslt", false);
|
||||
export_dives_xslt("testcsvexportprofileimperial.csv", 0, 1, "xml2csv.xslt", false);
|
||||
|
@ -421,14 +409,13 @@ void TestParse::exportCSVDiveProfile()
|
|||
|
||||
void TestParse::exportUDDF()
|
||||
{
|
||||
parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table);
|
||||
parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &divelog);
|
||||
|
||||
export_dives_xslt("testuddfexport.uddf", 0, 1, "uddf-export.xslt", false);
|
||||
|
||||
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);
|
||||
|
||||
FILE_COMPARE("testuddfexport.uddf",
|
||||
|
@ -472,9 +459,9 @@ void TestParse::parseDL7()
|
|||
|
||||
clear_dive_file_data();
|
||||
QCOMPARE(parse_csv_file(SUBSURFACE_TEST_DATA "/dives/DL7.zxu",
|
||||
¶ms, "DL7", &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table),
|
||||
¶ms, "DL7", &divelog),
|
||||
0);
|
||||
QCOMPARE(dive_table.nr, 3);
|
||||
QCOMPARE(divelog.dives->nr, 3);
|
||||
|
||||
QCOMPARE(save_dives("./testdl7out.ssrf"), 0);
|
||||
FILE_COMPARE("./testdl7out.ssrf",
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include "testparseperformance.h"
|
||||
#include "core/device.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/divesite.h"
|
||||
#include "core/trip.h"
|
||||
#include "core/file.h"
|
||||
|
@ -65,8 +66,7 @@ void TestParsePerformance::parseSsrf()
|
|||
return;
|
||||
}
|
||||
QBENCHMARK {
|
||||
parse_file(SUBSURFACE_TEST_DATA "/dives/large-anon.ssrf", &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table);
|
||||
parse_file(SUBSURFACE_TEST_DATA "/dives/large-anon.ssrf", &divelog);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,14 +77,12 @@ void TestParsePerformance::parseGit()
|
|||
|
||||
// first parse this once to populate the local cache - this way network
|
||||
// effects don't dominate the parse time
|
||||
parse_file(LARGE_TEST_REPO "[git]", &dive_table, &trip_table, &dive_site_table,
|
||||
&device_table, &filter_preset_table);
|
||||
parse_file(LARGE_TEST_REPO "[git]", &divelog);
|
||||
|
||||
cleanup();
|
||||
|
||||
QBENCHMARK {
|
||||
parse_file(LARGE_TEST_REPO "[git]", &dive_table, &trip_table, &dive_site_table,
|
||||
&device_table, &filter_preset_table);
|
||||
parse_file(LARGE_TEST_REPO "[git]", &divelog);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,10 +2,9 @@
|
|||
#include "testpicture.h"
|
||||
#include "core/device.h"
|
||||
#include "core/dive.h"
|
||||
#include "core/divesite.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/errorhelper.h"
|
||||
#include "core/picture.h"
|
||||
#include "core/trip.h"
|
||||
#include "core/file.h"
|
||||
#include "core/pref.h"
|
||||
#include <QString>
|
||||
|
@ -29,7 +28,7 @@ void TestPicture::addPicture()
|
|||
struct picture *pic1, *pic2;
|
||||
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);
|
||||
// Pictures will be added to selected dives
|
||||
dive->selected = true;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include "testprofile.h"
|
||||
#include "core/device.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/divesite.h"
|
||||
#include "core/trip.h"
|
||||
#include "core/file.h"
|
||||
|
@ -34,7 +35,7 @@ void TestProfile::init()
|
|||
void TestProfile::testProfileExport()
|
||||
{
|
||||
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);
|
||||
QFile org(SUBSURFACE_TEST_DATA "/dives/exportprofilereference.csv");
|
||||
QCOMPARE(org.open(QFile::ReadOnly), true);
|
||||
|
@ -50,7 +51,7 @@ void TestProfile::testProfileExport()
|
|||
void TestProfile::testProfileExportVPMB()
|
||||
{
|
||||
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);
|
||||
QFile org(SUBSURFACE_TEST_DATA "/dives/exportprofilereferenceVPMB.csv");
|
||||
QCOMPARE(org.open(QFile::ReadOnly), true);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "testrenumber.h"
|
||||
#include "core/device.h"
|
||||
#include "core/dive.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/divesite.h"
|
||||
#include "core/trip.h"
|
||||
#include "core/file.h"
|
||||
|
@ -11,32 +12,24 @@
|
|||
void TestRenumber::setup()
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
void TestRenumber::testMerge()
|
||||
{
|
||||
struct dive_table table = empty_dive_table;
|
||||
struct trip_table trips = empty_trip_table;
|
||||
struct dive_site_table sites = empty_dive_site_table;
|
||||
struct device_table devices;
|
||||
struct filter_preset_table filter_presets;
|
||||
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);
|
||||
struct divelog log;
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47b.xml", &log), 0);
|
||||
add_imported_dives(&log, IMPORT_MERGE_ALL_TRIPS);
|
||||
QCOMPARE(divelog.dives->nr, 1);
|
||||
}
|
||||
|
||||
void TestRenumber::testMergeAndAppend()
|
||||
{
|
||||
struct dive_table table = empty_dive_table;
|
||||
struct trip_table trips = empty_trip_table;
|
||||
struct dive_site_table sites = empty_dive_site_table;
|
||||
struct device_table devices;
|
||||
struct filter_preset_table filter_presets;
|
||||
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 divelog log;
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47c.xml", &log), 0);
|
||||
add_imported_dives(&log, IMPORT_MERGE_ALL_TRIPS);
|
||||
QCOMPARE(divelog.dives->nr, 2);
|
||||
struct dive *d = get_dive(1);
|
||||
QVERIFY(d != NULL);
|
||||
if (d)
|
||||
|
|
Loading…
Reference in a new issue