mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
When saving only selected dives, only include referenced dive computers
Since we should have far fewer dive computers than dives this straight forward algorithm shouldn't cause any performance issues. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
2365531c68
commit
1ee447b5a9
4 changed files with 28 additions and 6 deletions
2
device.h
2
device.h
|
@ -9,7 +9,7 @@ extern "C" {
|
||||||
extern struct divecomputer *fake_dc(struct divecomputer *dc);
|
extern struct divecomputer *fake_dc(struct divecomputer *dc);
|
||||||
extern void create_device_node(const char *model, uint32_t deviceid, const char *serial, const char *firmware, const char *nickname);
|
extern void create_device_node(const char *model, uint32_t deviceid, const char *serial, const char *firmware, const char *nickname);
|
||||||
extern void call_for_each_dc(void *f, void (*callback)(void *, const char *, uint32_t,
|
extern void call_for_each_dc(void *f, void (*callback)(void *, const char *, uint32_t,
|
||||||
const char *, const char *, const char *));
|
const char *, const char *, const char *), bool select_only);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,14 +90,36 @@ extern "C" bool compareDC(const DiveComputerNode &a, const DiveComputerNode &b)
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void call_for_each_dc (void *f, void (*callback)(void *, const char *, uint32_t,
|
extern "C" void call_for_each_dc (void *f, void (*callback)(void *, const char *, uint32_t,
|
||||||
const char *, const char *, const char *))
|
const char *, const char *, const char *),
|
||||||
|
bool select_only)
|
||||||
{
|
{
|
||||||
QList<DiveComputerNode> values = dcList.dcMap.values();
|
QList<DiveComputerNode> values = dcList.dcMap.values();
|
||||||
qSort(values.begin(), values.end(), compareDC);
|
qSort(values.begin(), values.end(), compareDC);
|
||||||
for (int i = 0; i < values.size(); i++) {
|
for (int i = 0; i < values.size(); i++) {
|
||||||
const DiveComputerNode *node = &values.at(i);
|
const DiveComputerNode *node = &values.at(i);
|
||||||
callback(f, node->model.toUtf8().data(), node->deviceId, node->nickName.toUtf8().data(),
|
bool found = false;
|
||||||
node->serialNumber.toUtf8().data(), node->firmware.toUtf8().data());
|
if (select_only) {
|
||||||
|
int j;
|
||||||
|
struct dive *d;
|
||||||
|
for_each_dive (j, d) {
|
||||||
|
struct divecomputer *dc;
|
||||||
|
if (!d->selected)
|
||||||
|
continue;
|
||||||
|
for_each_dc(d, dc) {
|
||||||
|
if (dc->deviceid == node->deviceId) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (found)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
if (found)
|
||||||
|
callback(f, node->model.toUtf8().data(), node->deviceId, node->nickName.toUtf8().data(),
|
||||||
|
node->serialNumber.toUtf8().data(), node->firmware.toUtf8().data());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -821,7 +821,7 @@ static void save_settings(git_repository *repo, struct dir *tree)
|
||||||
|
|
||||||
put_format(&b, "version %d\n", VERSION);
|
put_format(&b, "version %d\n", VERSION);
|
||||||
save_userid(&b);
|
save_userid(&b);
|
||||||
call_for_each_dc(&b, save_one_device);
|
call_for_each_dc(&b, save_one_device, false);
|
||||||
cond_put_format(autogroup, &b, "autogroup\n");
|
cond_put_format(autogroup, &b, "autogroup\n");
|
||||||
|
|
||||||
blob_insert(repo, tree, &b, "00-Subsurface");
|
blob_insert(repo, tree, &b, "00-Subsurface");
|
||||||
|
|
|
@ -501,7 +501,7 @@ void save_dives_buffer(struct membuffer *b, const bool select_only)
|
||||||
put_format(b, " <userid>%30s</userid>\n", prefs.userid);
|
put_format(b, " <userid>%30s</userid>\n", prefs.userid);
|
||||||
|
|
||||||
/* save the dive computer nicknames, if any */
|
/* save the dive computer nicknames, if any */
|
||||||
call_for_each_dc(b, save_one_device);
|
call_for_each_dc(b, save_one_device, select_only);
|
||||||
if (autogroup)
|
if (autogroup)
|
||||||
put_format(b, " <autogroup state='1' />\n");
|
put_format(b, " <autogroup state='1' />\n");
|
||||||
put_format(b, "</settings>\n");
|
put_format(b, "</settings>\n");
|
||||||
|
|
Loading…
Add table
Reference in a new issue