void LocationInformationWidget::setCurrentDiveSite(int dive_nr) { currentDs = get_dive_site(dive_nr); if (currentDs) setLocationId(currentDs->uuid); else setLocationId(displayed_dive.dive_site_uuid); }
QVariant LocationInformationModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); struct dive_site *ds = get_dive_site(index.row()); switch(role) { case Qt::DisplayRole : return qPrintable(ds->name); } return QVariant(); }
void delete_dive_site(uint32_t id) { int nr = dive_site_table.nr; for (int i = 0; i < nr; i++) { struct dive_site *ds = get_dive_site(i); if (ds->uuid == id) { free(ds->name); free(ds->notes); free(ds); if (nr - 1 > i) memmove(&dive_site_table.dive_sites[i], &dive_site_table.dive_sites[i+1], (nr - 1 - i) * sizeof(dive_site_table.dive_sites[0])); dive_site_table.nr = nr - 1; break; } } }
void save_dives_buffer(struct membuffer *b, const bool select_only) { int i; struct dive *dive; dive_trip_t *trip; put_format(b, "<divelog program='subsurface' version='%d'>\n<settings>\n", VERSION); if (prefs.save_userid_local) put_format(b, " <userid>%30s</userid>\n", prefs.userid); /* save the dive computer nicknames, if any */ call_for_each_dc(b, save_one_device); if (autogroup) put_format(b, " <autogroup state='1' />\n"); put_format(b, "</settings>\n"); /* save the dive sites */ put_format(b, "<divesites>\n"); for (i = 0; i < dive_site_table.nr; i++) { struct dive_site *ds = get_dive_site(i); if (dive_site_is_empty(ds)) { int j; struct dive *d; for_each_dive(j, d) { if (d->dive_site_uuid == ds->uuid) d->dive_site_uuid = 0; } delete_dive_site(get_dive_site(i)->uuid); i--; // since we just deleted that one continue; } put_format(b, "<site uuid='%8x'", ds->uuid); show_utf8(b, ds->name, " name='", "'", 1); if (ds->latitude.udeg || ds->longitude.udeg) { put_degrees(b, ds->latitude, " gps='", " "); put_degrees(b, ds->longitude, "", "'"); } show_utf8(b, ds->description, " description='", "'", 1); show_utf8(b, ds->notes, " notes='", "'", 1); put_format(b, "/>\n"); } put_format(b, "</divesites>\n<dives>\n"); for (trip = dive_trip_list; trip != NULL; trip = trip->next) trip->index = 0; /* save the dives */ for_each_dive(i, dive) { if (select_only) { if (!dive->selected) continue; save_one_dive_to_mb(b, dive); } else { trip = dive->divetrip; /* Bare dive without a trip? */ if (!trip) { save_one_dive_to_mb(b, dive); continue; } /* Have we already seen this trip (and thus saved this dive?) */ if (trip->index) continue; /* We haven't seen this trip before - save it and all dives */ trip->index = 1; save_trip(b, trip); } } put_format(b, "</dives>\n</divelog>\n"); }
void save_dives_buffer(struct membuffer *b, const bool select_only) { int i; struct dive *dive; dive_trip_t *trip; put_format(b, "<divelog program='subsurface' version='%d'>\n<settings>\n", DATAFORMAT_VERSION); if (prefs.save_userid_local) put_format(b, " <userid>%30s</userid>\n", prefs.userid); /* save the dive computer nicknames, if any */ call_for_each_dc(b, save_one_device, select_only); if (autogroup) put_format(b, " <autogroup state='1' />\n"); put_format(b, "</settings>\n"); /* save the dive sites - to make the output consistent let's sort the table, first */ dive_site_table_sort(); put_format(b, "<divesites>\n"); for (i = 0; i < dive_site_table.nr; i++) { int j; struct dive *d; struct dive_site *ds = get_dive_site(i); if (dive_site_is_empty(ds)) { for_each_dive(j, d) { if (d->dive_site_uuid == ds->uuid) d->dive_site_uuid = 0; } delete_dive_site(get_dive_site(i)->uuid); i--; // since we just deleted that one continue; } if (select_only && !is_dive_site_used(ds->uuid, true)) continue; put_format(b, "<site uuid='%8x'", ds->uuid); show_utf8(b, ds->name, " name='", "'", 1); if (ds->latitude.udeg || ds->longitude.udeg) { put_degrees(b, ds->latitude, " gps='", " "); put_degrees(b, ds->longitude, "", "'"); } show_utf8(b, ds->description, " description='", "'", 1); show_utf8(b, ds->notes, " notes='", "'", 1); if (ds->taxonomy.nr) { put_format(b, ">\n"); for (int j = 0; j < ds->taxonomy.nr; j++) { struct taxonomy *t = &ds->taxonomy.category[j]; if (t->category != TC_NONE) { put_format(b, "<geo cat='%d'", t->category); put_format(b, " origin='%d'", t->origin); show_utf8(b, t->value, " value='", "'/>\n", 1); } } put_format(b, "</site>\n"); } else { put_format(b, "/>\n"); } } put_format(b, "</divesites>\n<dives>\n"); for (trip = dive_trip_list; trip != NULL; trip = trip->next) trip->index = 0; /* save the dives */ for_each_dive(i, dive) { if (select_only) { if (!dive->selected) continue; save_one_dive_to_mb(b, dive); } else { trip = dive->divetrip; /* Bare dive without a trip? */ if (!trip) { save_one_dive_to_mb(b, dive); continue; } /* Have we already seen this trip (and thus saved this dive?) */ if (trip->index) continue; /* We haven't seen this trip before - save it and all dives */ trip->index = 1; save_trip(b, trip); } } put_format(b, "</dives>\n</divelog>\n"); }
void save_dives_buffer(struct membuffer *b, const bool select_only) { int i; struct dive *dive; dive_trip_t *trip; put_format(b, "<divelog program='subsurface' version='%d'>\n<settings>\n", DATAFORMAT_VERSION); if (prefs.save_userid_local) put_format(b, " <userid>%30s</userid>\n", prefs.userid); /* save the dive computer nicknames, if any */ call_for_each_dc(b, save_one_device, select_only); if (autogroup) put_format(b, " <autogroup state='1' />\n"); put_format(b, "</settings>\n"); /* save the dive sites - to make the output consistent let's sort the table, first */ dive_site_table_sort(); put_format(b, "<divesites>\n"); for (i = 0; i < dive_site_table.nr; i++) { int j; struct dive *d; struct dive_site *ds = get_dive_site(i); if (dive_site_is_empty(ds)) { for_each_dive(j, d) { if (d->dive_site_uuid == ds->uuid) d->dive_site_uuid = 0; } delete_dive_site(ds->uuid); i--; // since we just deleted that one continue; } else if (ds->name && (strncmp(ds->name, "Auto-created dive", 17) == 0 || strncmp(ds->name, "New Dive", 8) == 0)) { // 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 (verbose) fprintf(stderr, "Deleted unused auto-created dive site %s\n", ds->name); delete_dive_site(ds->uuid); i--; // since we just deleted that one continue; } } if (select_only && !is_dive_site_used(ds->uuid, true)) continue; put_format(b, "<site uuid='%8x'", ds->uuid); show_utf8(b, ds->name, " name='", "'", 1); if (ds->latitude.udeg || ds->longitude.udeg) { put_degrees(b, ds->latitude, " gps='", " "); put_degrees(b, ds->longitude, "", "'"); } show_utf8(b, ds->description, " description='", "'", 1); put_format(b, ">\n"); show_utf8(b, ds->notes, " <notes>", " </notes>\n", 0); if (ds->taxonomy.nr) { for (int j = 0; j < ds->taxonomy.nr; j++) { struct taxonomy *t = &ds->taxonomy.category[j]; if (t->category != TC_NONE && t->value) { put_format(b, " <geo cat='%d'", t->category); put_format(b, " origin='%d'", t->origin); show_utf8(b, t->value, " value='", "'/>\n", 1); } } } put_format(b, "</site>\n"); }