Don't add separate country field, use taxonomy

The more I looked at the code that added the country to the dive site,
the more it seemed redundant given what we have with the taxonomy.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2017-10-02 23:03:44 -07:00
parent de10fd4021
commit 21d78121ad
8 changed files with 21 additions and 24 deletions

View file

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

View file

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

View file

@ -17,7 +17,6 @@ struct dive_site
{
uint32_t uuid;
char *name;
char *country;
degrees_t latitude, longitude;
char *description;
char *notes;

View file

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

View file

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

View file

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

View file

@ -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, "", "'");

View file

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