diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-10-23 18:55:42 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-10-29 00:09:31 +0000 |
commit | 8de471f90e95a5a75d0fec78d5bbf900eb90f235 (patch) | |
tree | 62812fb5aab9f6a8cb17db8969ab4e10eb041de0 | |
parent | 14ab95608cc0694caff580825666d2009177e0a2 (diff) | |
download | subsurface-8de471f90e95a5a75d0fec78d5bbf900eb90f235.tar.gz |
Dive site: pass dive-site pointer to is_dive_site_used()
Instead of passing a uuid, pass a pointer to the dive site.
This is small step in an effort to remove uuids.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r-- | core/divesite.c | 6 | ||||
-rw-r--r-- | core/divesite.h | 2 | ||||
-rw-r--r-- | core/save-git.c | 4 | ||||
-rw-r--r-- | core/save-xml.c | 6 | ||||
-rw-r--r-- | desktop-widgets/tab-widgets/maintab.cpp | 13 |
5 files changed, 15 insertions, 16 deletions
diff --git a/core/divesite.c b/core/divesite.c index 437605b71..163ecc892 100644 --- a/core/divesite.c +++ b/core/divesite.c @@ -145,13 +145,15 @@ int nr_of_dives_at_dive_site(struct dive_site *ds, bool select_only) return nr; } -bool is_dive_site_used(uint32_t uuid, bool select_only) +bool is_dive_site_used(struct dive_site *ds, bool select_only) { int j; bool found = false; struct dive *d; + if (!ds) + return false; for_each_dive(j, d) { - if (d->dive_site_uuid == uuid && (!select_only || d->selected)) { + if (d->dive_site_uuid == ds->uuid && (!select_only || d->selected)) { found = true; break; } diff --git a/core/divesite.h b/core/divesite.h index f5754f5da..2d5c02110 100644 --- a/core/divesite.h +++ b/core/divesite.h @@ -55,7 +55,7 @@ static inline struct dive_site *get_dive_site_by_uuid(uint32_t uuid) void dive_site_table_sort(); struct dive_site *alloc_or_get_dive_site(uint32_t uuid); int nr_of_dives_at_dive_site(struct dive_site *ds, bool select_only); -bool is_dive_site_used(uint32_t uuid, bool select_only); +bool is_dive_site_used(struct dive_site *ds, bool select_only); void free_dive_site(struct dive_site *ds); void delete_dive_site(uint32_t id); struct dive_site *create_dive_site(const char *name, timestamp_t divetime); diff --git a/core/save-git.c b/core/save-git.c index 938b7d3a5..524c350ed 100644 --- a/core/save-git.c +++ b/core/save-git.c @@ -883,7 +883,7 @@ static void save_divesites(git_repository *repo, struct dir *tree) for (int i = 0; i < dive_site_table.nr; i++) { struct membuffer b = { 0 }; struct dive_site *ds = get_dive_site(i); - if (dive_site_is_empty(ds) || !is_dive_site_used(ds->uuid, false)) { + if (dive_site_is_empty(ds) || !is_dive_site_used(ds, false)) { int j; struct dive *d; for_each_dive(j, d) { @@ -900,7 +900,7 @@ static void save_divesites(git_repository *repo, struct dir *tree) // these are the two default names for sites from // the web service; if the site isn't used in any // dive (really? you didn't rename it?), delete it - if (!is_dive_site_used(ds->uuid, false)) { + if (!is_dive_site_used(ds, false)) { if (verbose) fprintf(stderr, "Deleted unused auto-created dive site %s\n", ds->name); delete_dive_site(ds->uuid); diff --git a/core/save-xml.c b/core/save-xml.c index fad5f584a..b4c952468 100644 --- a/core/save-xml.c +++ b/core/save-xml.c @@ -600,7 +600,7 @@ void save_dives_buffer(struct membuffer *b, const bool select_only, bool anonymi int j; struct dive *d; struct dive_site *ds = get_dive_site(i); - if (dive_site_is_empty(ds) || !is_dive_site_used(ds->uuid, false)) { + if (dive_site_is_empty(ds) || !is_dive_site_used(ds, false)) { for_each_dive(j, d) { if (d->dive_site_uuid == ds->uuid) d->dive_site_uuid = 0; @@ -614,7 +614,7 @@ void save_dives_buffer(struct membuffer *b, const bool select_only, bool anonymi // these are the two default names for sites from // the web service; if the site isn't used in any // dive (really? you didn't rename it?), delete it - if (!is_dive_site_used(ds->uuid, false)) { + if (!is_dive_site_used(ds, false)) { if (verbose) fprintf(stderr, "Deleted unused auto-created dive site %s\n", ds->name); delete_dive_site(ds->uuid); @@ -622,7 +622,7 @@ void save_dives_buffer(struct membuffer *b, const bool select_only, bool anonymi continue; } } - if (select_only && !is_dive_site_used(ds->uuid, true)) + if (select_only && !is_dive_site_used(ds, true)) continue; put_format(b, "<site uuid='%8x'", ds->uuid); diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index e617a8140..3b727126a 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -713,7 +713,6 @@ uint32_t MainTab::updateDiveSite(uint32_t pickedUuid, dive *d) return pickedUuid; } - // Get the list of selected dives, but put the current dive at the last position of the vector static QVector<dive *> getSelectedDivesCurrentLast() { @@ -880,18 +879,16 @@ void MainTab::acceptChanges() } // update the dive site for the selected dives that had the same dive site as the current dive - uint32_t oldUuid = cd->dive_site_uuid; + struct dive_site *oldDs = get_dive_site_by_uuid(cd->dive_site_uuid); uint32_t newUuid = 0; MODIFY_DIVES(selectedDives, if (mydive->dive_site_uuid == current_dive->dive_site_uuid) newUuid = updateDiveSite(newUuid == 0 ? ui.location->currDiveSiteUuid() : newUuid, mydive); ); - if (!is_dive_site_used(oldUuid, false)) { - if (verbose) { - struct dive_site *ds = get_dive_site_by_uuid(oldUuid); - qDebug() << "delete now unused dive site" << ((ds && ds->name) ? ds->name : "without name"); - } - delete_dive_site(oldUuid); + if (oldDs && !is_dive_site_used(oldDs, false)) { + if (verbose) + qDebug() << "delete now unused dive site" << (oldDs->name ? oldDs->name : "without name"); + delete_dive_site(oldDs->uuid); MapWidget::instance()->reload(); } // the code above can change the correct uuid for the displayed dive site - and the |