summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Jan Mulder <jlmulder@xs4all.nl>2018-01-04 22:22:34 +0100
committerGravatar Jan Mulder <jlmulder@xs4all.nl>2018-01-06 09:21:16 +0100
commit70e0e80de5470216df939f994ffda0222560def0 (patch)
treeef7729d24dcc20a3a141462c2570f06c99ba3648
parente762d2a23e9bea751ea0f1df1e283f4e5399543b (diff)
downloadsubsurface-70e0e80de5470216df939f994ffda0222560def0.tar.gz
GPS: use applyGpsLocation::applyLocations from core
Fixes a big duplication of code. The code to apply GPS locations from the location service was already in core, and used from mobile, but there was an almost literal copy in the desktop code. See also commits 6f42ab46da1b59 and ee9531f76ec31a, where only one side of the duplicated code was fixed. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
-rw-r--r--desktop-widgets/mainwindow.cpp4
-rw-r--r--desktop-widgets/subsurfacewebservices.cpp114
2 files changed, 3 insertions, 115 deletions
diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp
index bbccdc064..ad8b39dd7 100644
--- a/desktop-widgets/mainwindow.cpp
+++ b/desktop-widgets/mainwindow.cpp
@@ -111,7 +111,8 @@ MainWindow::MainWindow() : QMainWindow(),
actionPreviousDive(0),
helpView(0),
state(VIEWALL),
- survey(0)
+ survey(0),
+ locationProvider(new GpsLocation(nullptr, this))
{
Q_ASSERT_X(m_Instance == NULL, "MainWindow", "MainWindow recreated!");
m_Instance = this;
@@ -826,7 +827,6 @@ void MainWindow::on_actionDownloadDC_triggered()
void MainWindow::on_actionDownloadWeb_triggered()
{
SubsurfaceWebServices dlg(this);
-
dlg.exec();
}
diff --git a/desktop-widgets/subsurfacewebservices.cpp b/desktop-widgets/subsurfacewebservices.cpp
index b11a910f1..6e4f191d6 100644
--- a/desktop-widgets/subsurfacewebservices.cpp
+++ b/desktop-widgets/subsurfacewebservices.cpp
@@ -35,118 +35,6 @@
struct dive_table gps_location_table;
-// we don't overwrite any existing GPS info in the dive
-// so get the dive site and if there is none or there is one without GPS fix, add it
-static void copy_gps_location(struct dive *from, struct dive *to)
-{
- struct dive_site *ds = get_dive_site_for_dive(to);
- if (!ds || !dive_site_has_gps_location(ds)) {
- struct dive_site *gds = get_dive_site_for_dive(from);
- if (!ds) {
- // simply link to the one created for the fake dive
- to->dive_site_uuid = gds->uuid;
- } else {
- ds->latitude = gds->latitude;
- ds->longitude = gds->longitude;
- if (same_string(ds->name, ""))
- ds->name = copy_string(gds->name);
- }
- }
-}
-
-#define SAME_GROUP 6 * 3600 // six hours
-#define SET_LOCATION(_dive, _gpsfix, _mark) \
-{ \
- copy_gps_location(_gpsfix, _dive); \
- changed ++; \
- tracer = _mark; \
-}
-
-//TODO: C Code. static functions are not good if we plan to have a test for them.
-static bool merge_locations_into_dives(void)
-{
- int i, j, tracer=0, changed=0;
- struct dive *gpsfix, *nextgpsfix, *dive;
-
- sort_table(&gps_location_table);
-
- for_each_dive (i, dive) {
- if (!dive_has_gps_location(dive)) {
- for (j = tracer; (gpsfix = get_dive_from_table(j, &gps_location_table)) !=NULL; j++) {
- if (time_during_dive_with_offset(dive, gpsfix->when, SAME_GROUP)) {
- if (verbose)
- qDebug() << "processing gpsfix @" << get_dive_date_string(gpsfix->when) <<
- "which is withing six hours of dive from" <<
- get_dive_date_string(dive->when) << "until" <<
- get_dive_date_string(dive_endtime(dive));
- /*
- * If position is fixed during dive. This is the good one.
- * Asign and mark position, and end gps_location loop
- */
- if (time_during_dive_with_offset(dive, gpsfix->when, 0)) {
- if (verbose)
- qDebug() << "gpsfix is during the dive, pick that one";
- SET_LOCATION(dive, gpsfix, j);
- break;
- } else {
- /*
- * If it is not, check if there are more position fixes in SAME_GROUP range
- */
- if ((nextgpsfix = get_dive_from_table(j + 1, &gps_location_table)) &&
- time_during_dive_with_offset(dive, nextgpsfix->when, SAME_GROUP)) {
- if (verbose)
- qDebug() << "look at the next gps fix @" << get_dive_date_string(nextgpsfix->when);
- /* we know the gps fixes are sorted; if they are both before the dive, ignore the first,
- * if theay are both after the dive, take the first,
- * if the first is before and the second is after, take the closer one */
- if (nextgpsfix->when < dive->when) {
- if (verbose)
- qDebug() << "which is closer to the start of the dive, do continue with that";
- continue;
- } else if (gpsfix->when > dive_endtime(dive)) {
- if (verbose)
- qDebug() << "which is even later after the end of the dive, so pick the previous one";
- SET_LOCATION(dive, gpsfix, j);
- break;
- } else {
- /* ok, gpsfix is before, nextgpsfix is after */
- if (dive->when - gpsfix->when <= nextgpsfix->when - dive_endtime(dive)) {
- if (verbose)
- qDebug() << "pick the one before as it's closer to the start";
- SET_LOCATION(dive, gpsfix, j);
- break;
- } else {
- if (verbose)
- qDebug() << "pick the one after as it's closer to the start";
- SET_LOCATION(dive, nextgpsfix, j + 1);
- break;
- }
- }
- /*
- * If no more positions in range, the actual is the one. Asign, mark and end loop.
- */
- } else {
- if (verbose)
- qDebug() << "which seems to be the best one for this dive, so pick it";
- SET_LOCATION(dive, gpsfix, j);
- break;
- }
- }
- } else {
- /* If position is out of SAME_GROUP range and in the future, mark position for
- * next dive iteration and end the gps_location loop
- */
- if (gpsfix->when >= dive_endtime(dive) + SAME_GROUP) {
- tracer = j;
- break;
- }
- }
- }
- }
- }
- return changed > 0;
-}
-
// TODO: This looks like should be ported to C code. or a big part of it.
bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile, const bool selected)
{
@@ -427,7 +315,7 @@ void SubsurfaceWebServices::buttonClicked(QAbstractButton *button)
ds->notes = strdup("SubsurfaceWebservice");
}
/* now merge the data in the gps_location table into the dive_table */
- if (merge_locations_into_dives()) {
+ if (GpsLocation::instance()->applyLocations()) {
changed = true;
mark_divelist_changed(true);
MainWindow::instance()->information()->updateDiveInfo();