From 874d3c4799a65062ca60518199f877341301e1a1 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Wed, 15 Jul 2015 21:26:33 -0700 Subject: Dive site handling: special case for auto generated dives When we download GPS data from the webservice we can end up with dive sites that are simply a place holder for the the GPS fix. If we replace the name of one of those sites we should just delete the site (assuming it isn't used in another dive, which is unlikely but theoretically possible). Signed-off-by: Dirk Hohndel --- qt-ui/maintab.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index e9da1a53a..9b4166b35 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -815,18 +815,6 @@ void MainTab::updateDisplayedDiveSite() qDebug() << "Updating Displayed Dive Site"; -#if 0 - // this code is special casing for divesites that were downloaded from the webservice - if(current_dive) { - struct dive_site *ds_from_dive = get_dive_site_by_uuid(current_dive->dive_site_uuid); - if (!dive_site_has_gps_location(ds_from_dive) && - same_string(displayed_dive_site.notes, "SubsurfaceWebservice")) { - ds_from_dive->latitude = displayed_dive_site.latitude; - ds_from_dive->longitude = displayed_dive_site.longitude; - delete_dive_site(displayed_dive_site.uuid); - } - } -#endif if(orig_uuid) { if (new_uuid && orig_uuid != new_uuid) { // the user picked a different site @@ -908,6 +896,16 @@ void MainTab::updateDiveSite(int divenr) newDs->uuid = createdUuid; // the copy overwrote the uuid cd->dive_site_uuid = createdUuid; qDebug() << "create a new dive site with name" << newName << "which is now named" << newDs->name << "and assign it as uuid" << createdUuid; + qDebug() << "original dive had site" << origUuid << "and" << (origDs ? QString("notes %1").arg(origDs->notes) : QString("no dive site")); + if (origDs && same_string(origDs->notes, "SubsurfaceWebservice")) { + // this is a special case - let's remove the original dive site if this was the only user + if (!is_dive_site_used(origDs->uuid, false)) { + qDebug() << "delete the autogenerated dive site" << origDs->name; + delete_dive_site(origDs->uuid); + free(newDs->notes); + newDs->notes = NULL; + } + } } else { qDebug() << "switched to dive site" << newName << "uuid" << newUuid << "for current dive"; cd->dive_site_uuid = newUuid; -- cgit v1.2.3-70-g09d2