diff options
-rw-r--r-- | core/dive.h | 9 | ||||
-rw-r--r-- | core/divesite.c | 4 | ||||
-rw-r--r-- | core/divesite.h | 1 | ||||
-rw-r--r-- | core/load-git.c | 5 | ||||
-rw-r--r-- | core/parse-xml.c | 3 | ||||
-rw-r--r-- | core/save-git.c | 1 | ||||
-rw-r--r-- | core/save-xml.c | 1 | ||||
-rw-r--r-- | desktop-widgets/locationinformation.cpp | 21 |
8 files changed, 21 insertions, 24 deletions
diff --git a/core/dive.h b/core/dive.h index a638cfd0c..51524500f 100644 --- a/core/dive.h +++ b/core/dive.h @@ -570,11 +570,14 @@ static inline struct dive_site *get_dive_site_for_dive(struct dive *dive) return NULL; } -static inline char *get_dive_country(struct dive *dive) +static inline const char *get_dive_country(struct dive *dive) { struct dive_site *ds = get_dive_site_by_uuid(dive->dive_site_uuid); - if (ds && ds->country) - return ds->country; + if (ds) { + int idx = taxonomy_index_for_category(&ds->taxonomy, TC_COUNTRY); + if (idx >= 0) + return ds->taxonomy.category[idx].value; + } return NULL; } diff --git a/core/divesite.c b/core/divesite.c index 159ac4d40..fd25bb965 100644 --- a/core/divesite.c +++ b/core/divesite.c @@ -205,7 +205,6 @@ uint32_t create_dive_site(const char *name, timestamp_t divetime) uint32_t uuid = create_divesite_uuid(name, divetime); struct dive_site *ds = alloc_or_get_dive_site(uuid); ds->name = copy_string(name); - ds->country = NULL; return uuid; } @@ -240,7 +239,6 @@ bool dive_site_is_empty(struct dive_site *ds) return same_string(ds->name, "") && same_string(ds->description, "") && same_string(ds->notes, "") && - same_string(ds->country, "") && ds->latitude.udeg == 0 && ds->longitude.udeg == 0; } @@ -304,7 +302,6 @@ void merge_dive_site(struct dive_site *a, struct dive_site *b) merge_string(&a->name, &b->name); merge_string(&a->notes, &b->notes); merge_string(&a->description, &b->description); - merge_string(&a->country, &b->country); if (!a->taxonomy.category) { a->taxonomy = b->taxonomy; @@ -325,7 +322,6 @@ void clear_dive_site(struct dive_site *ds) ds->longitude.udeg = 0; ds->uuid = 0; ds->taxonomy.nr = 0; - ds->country = 0; free_taxonomy(&ds->taxonomy); } diff --git a/core/divesite.h b/core/divesite.h index 452a27927..b44e34a31 100644 --- a/core/divesite.h +++ b/core/divesite.h @@ -17,7 +17,6 @@ struct dive_site { uint32_t uuid; char *name; - char *country; degrees_t latitude, longitude; char *description; char *notes; diff --git a/core/load-git.c b/core/load-git.c index c77d4c05d..e7732a69f 100644 --- a/core/load-git.c +++ b/core/load-git.c @@ -293,9 +293,6 @@ static void parse_dive_notrip(char *line, struct membuffer *str, void *_dive) struct dive *dive = _dive; dive->tripflag = NO_TRIP; } -static void parse_site_country(char *line, struct membuffer *str, void *_ds) -{ (void) line; struct dive_site *ds = _ds; ds->country = strdup(mb_cstring(str)); } - static void parse_site_description(char *line, struct membuffer *str, void *_ds) { (void) line; struct dive_site *ds = _ds; ds->description = strdup(mb_cstring(str)); } @@ -997,7 +994,7 @@ static void dive_parser(char *line, struct membuffer *str, void *_dive) struct keyword_action site_action[] = { #undef D #define D(x) { #x, parse_site_ ## x } - D(country), D(description), D(geo), D(gps), D(name), D(notes) + D(description), D(geo), D(gps), D(name), D(notes) }; static void site_parser(char *line, struct membuffer *str, void *_ds) diff --git a/core/parse-xml.c b/core/parse-xml.c index 27b7b484f..ece85022b 100644 --- a/core/parse-xml.c +++ b/core/parse-xml.c @@ -1057,6 +1057,7 @@ static void divinglog_place(char *place, uint32_t *uuid) if (*uuid == 0) *uuid = create_dive_site(buffer, cur_dive->when); + // TODO: capture the country / city info in the taxonomy instead city = NULL; country = NULL; } @@ -1506,8 +1507,6 @@ static void try_to_fill_dive_site(struct dive_site **ds_p, const char *name, cha return; if (MATCH("name", utf8_string, &ds->name)) return; - if (MATCH("country", utf8_string, &ds->country)) - return; if (MATCH("description", utf8_string, &ds->description)) return; if (MATCH("notes", utf8_string, &ds->notes)) diff --git a/core/save-git.c b/core/save-git.c index be0d3920b..548664239 100644 --- a/core/save-git.c +++ b/core/save-git.c @@ -961,7 +961,6 @@ static void save_divesites(git_repository *repo, struct dir *tree) } struct membuffer site_file_name = { 0 }; put_format(&site_file_name, "Site-%08x", ds->uuid); - show_utf8(&b, "country ", ds->country, "\n"); show_utf8(&b, "name ", ds->name, "\n"); show_utf8(&b, "description ", ds->description, "\n"); show_utf8(&b, "notes ", ds->notes, "\n"); diff --git a/core/save-xml.c b/core/save-xml.c index 0410975dc..d3b9e6c8d 100644 --- a/core/save-xml.c +++ b/core/save-xml.c @@ -598,7 +598,6 @@ void save_dives_buffer(struct membuffer *b, const bool select_only) put_format(b, "<site uuid='%8x'", ds->uuid); show_utf8(b, ds->name, " name='", "'", 1); - show_utf8(b, ds->country, " country='", "'", 1); if (ds->latitude.udeg || ds->longitude.udeg) { put_degrees(b, ds->latitude, " gps='", " "); put_degrees(b, ds->longitude, "", "'"); diff --git a/desktop-widgets/locationinformation.cpp b/desktop-widgets/locationinformation.cpp index 3c347b774..065f249f1 100644 --- a/desktop-widgets/locationinformation.cpp +++ b/desktop-widgets/locationinformation.cpp @@ -93,8 +93,9 @@ void LocationInformationWidget::updateLabels() ui.diveSiteName->setText(displayed_dive_site.name); else ui.diveSiteName->clear(); - if (displayed_dive_site.country) - ui.diveSiteCountry->setText(displayed_dive_site.country); + const char *country = taxonomy_get_country(&displayed_dive_site.taxonomy); + if (country) + ui.diveSiteCountry->setText(country); else ui.diveSiteCountry->clear(); if (displayed_dive_site.description) @@ -151,11 +152,15 @@ void LocationInformationWidget::acceptChanges() free(currentDs->description); currentDs->description = copy_string(uiString); } - uiString = ui.diveSiteCountry->text().toUtf8().data(); - if (!same_string(uiString, currentDs->country)) { - free(currentDs->country); - currentDs->country = copy_string(uiString); - } + uiString = copy_string(ui.diveSiteCountry->text().toUtf8().data()); + // if the user entered a different contriy, first update the taxonomy + // for the displayed dive site; this below will get copied into the currentDs + if (!same_string(uiString, taxonomy_get_country(&displayed_dive_site.taxonomy)) && + !same_string(uiString, "")) + taxonomy_set_country(&displayed_dive_site.taxonomy, copy_string(uiString), taxonomy_origin::GEOMANUAL); + // now update the currentDs (which we then later copy back ontop of displayed_dive_site + copy_dive_site_taxonomy(&displayed_dive_site, currentDs); + uiString = ui.diveSiteNotes->document()->toPlainText().toUtf8().data(); if (!same_string(uiString, currentDs->notes)) { free(currentDs->notes); @@ -254,7 +259,7 @@ void LocationInformationWidget::on_diveSiteCoordinates_textChanged(const QString void LocationInformationWidget::on_diveSiteCountry_textChanged(const QString& text) { - if (!same_string(qPrintable(text), displayed_dive_site.country)) + if (!same_string(qPrintable(text), taxonomy_get_country(&displayed_dive_site.taxonomy))) markChangedWidget(ui.diveSiteCountry); } |