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 <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2015-07-15 21:26:33 -07:00
parent 1dbb6071bd
commit 874d3c4799

View file

@ -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;