diff options
author | Tomaz Canabrava <tomaz.canabrava@intel.com> | 2015-09-23 16:55:48 -0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-09-23 14:15:50 -0700 |
commit | 1e88982d6fcc0f256ad33092dc516a62acc994e4 (patch) | |
tree | b2b5f7601139ec9f693d6a8522a3fa9eb00c4635 /qt-ui | |
parent | fec33cee93197bc33565b491e21ff191f1421f0a (diff) | |
download | subsurface-1e88982d6fcc0f256ad33092dc516a62acc994e4.tar.gz |
Much simpler code to set the dive site
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui')
-rw-r--r-- | qt-ui/maintab.cpp | 74 |
1 files changed, 21 insertions, 53 deletions
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 884f76c07..c7a75d47f 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -860,65 +860,33 @@ void MainTab::updateDiveSite(int divenr) if (!cd) return; - const uint32_t newUuid = displayed_dive_site.uuid; - const uint32_t pickedUuid = ui.location->currDiveSiteUuid(); + if (ui.location->text().isEmpty()) { + qDebug() << "No location data set, not updating the dive site."; + return; + } + + uint32_t pickedUuid = ui.location->currDiveSiteUuid(); const QString newName = displayed_dive_site.name; const uint32_t origUuid = cd->dive_site_uuid; struct dive_site *origDs = get_dive_site_by_uuid(origUuid); const QString origName = origDs ? origDs->name : ""; - // the user has accepted the changes made to the displayed_dive_site - // so let's make them permanent - if (!origUuid) { - // the dive edited didn't have a dive site - qDebug() << "current dive didn't have a dive site before edit"; - if (pickedUuid) { - qDebug() << "assign dive_site" << pickedUuid << "to current dive"; - cd->dive_site_uuid = pickedUuid; - } else if (newUuid) { - // user created a new divesite - cd->dive_site_uuid = newUuid; - } else if (!newName.isEmpty()) { - // user entered a name but didn't pick or create a dive site, so create a divesite - uint32_t createdUuid = create_dive_site(displayed_dive_site.name, cd->when); - struct dive_site *newDs = get_dive_site_by_uuid(createdUuid); - copy_dive_site(&displayed_dive_site, newDs); - 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; - } else { - qDebug() << "neither uuid picked, uuid created nor new name found"; - } - } else { - qDebug() << "current dive had dive site with uuid" << origUuid; - if (origUuid == newUuid) { - // looks like nothing changed - qDebug() << "same uuid"; - } else if (newName != origName) { - if (newUuid == 0) { - // so we created a new site, add it to the global list - uint32_t createdUuid = create_dive_site(displayed_dive_site.name, cd->when); - struct dive_site *newDs = get_dive_site_by_uuid(createdUuid); - copy_dive_site(&displayed_dive_site, newDs); - 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; - // what to do with the old site? - } + + if (pickedUuid == RECENTLY_ADDED_DIVESITE) { + pickedUuid = create_dive_site(ui.location->text().isEmpty() ? qPrintable(tr("New dive site")) : qPrintable(ui.location->text()), displayed_dive.when); + struct dive_site *newDs = get_dive_site_by_uuid(pickedUuid); + copy_dive_site(newDs, &displayed_dive_site); + } + + if (origDs && pickedUuid != origDs->uuid && 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); } } + + cd->dive_site_uuid = pickedUuid; + qDebug() << "Setting the dive site id on the dive:" << pickedUuid; } void MainTab::acceptChanges() |