diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2013-06-17 15:58:26 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-06-18 00:24:28 -0700 |
commit | 29b242c70349cbd67aacc3e4f1206630d22c54eb (patch) | |
tree | 21edbec2770ddf9fb9eb333429c013aefca2f99d /save-xml.c | |
parent | 14ccbbf6e87b69267426ae69c402c1bae70ec5d5 (diff) | |
download | subsurface-29b242c70349cbd67aacc3e4f1206630d22c54eb.tar.gz |
Converting the device_info list into a Qt data structure
This data structure was quite fragile and made 'undo' when editing
rather hard to implement. So instead I decided to turn this into a
QMultiMap which seemed like the ideal data structure for it.
This map holds all the dive computer related data indexed by the model. As
QMultiMap it allows multiple entries per key (model string) and
disambiguates between them with the deviceId.
This commit turned out much larger than I wanted. But I didn't manage to
find a clean way to break it up and make the pieces make sense.
So this brings back the Ok / Cancel button for the dive computer edit
dialog. And it makes those two buttons actually do the right thing (which
is what started this whole process). For this to work we simply copy the
map to a working copy and do all edits on that one - and then copy that
over the 'real' map when we accept the changes.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'save-xml.c')
-rw-r--r-- | save-xml.c | 27 |
1 files changed, 6 insertions, 21 deletions
diff --git a/save-xml.c b/save-xml.c index 0e770ec62..454da8484 100644 --- a/save-xml.c +++ b/save-xml.c @@ -512,24 +512,20 @@ static void save_trip(FILE *f, dive_trip_t *trip) fprintf(f, "</trip>\n"); } -static void save_one_device(FILE *f, struct device_info *info) +static void save_one_device(FILE *f, const char * model, uint32_t deviceid, + const char *nickname, const char *serial_nr, const char *firmware) { - const char *nickname, *serial_nr, *firmware; - /* Nicknames that are empty or the same as the device model are not interesting */ - nickname = info->nickname; if (nickname) { - if (!*nickname || !strcmp(info->model, nickname)) + if (!*nickname || !strcmp(model, nickname)) nickname = NULL; } /* Serial numbers that are empty are not interesting */ - serial_nr = info->serial_nr; if (serial_nr && !*serial_nr) serial_nr = NULL; /* Firmware strings that are empty are not interesting */ - firmware = info->firmware; if (firmware && !*firmware) firmware = NULL; @@ -538,25 +534,14 @@ static void save_one_device(FILE *f, struct device_info *info) return; fprintf(f, "<divecomputerid"); - show_utf8(f, info->model, " model='", "'", 1); - fprintf(f, " deviceid='%08x'", info->deviceid); + show_utf8(f, model, " model='", "'", 1); + fprintf(f, " deviceid='%08x'", deviceid); show_utf8(f, serial_nr, " serial='", "'", 1); show_utf8(f, firmware, " firmware='", "'", 1); show_utf8(f, nickname, " nickname='", "'", 1); fprintf(f, "/>\n"); } -static void save_device_info(FILE *f) -{ - struct device_info *info; - - info = head_of_device_info_list(); - while (info) { - save_one_device(f, info); - info = info->next; - } -} - #define VERSION 2 void save_dives(const char *filename) @@ -578,7 +563,7 @@ void save_dives_logic(const char *filename, const gboolean select_only) fprintf(f, "<divelog program='subsurface' version='%d'>\n<settings>\n", VERSION); /* save the dive computer nicknames, if any */ - save_device_info(f); + call_for_each_dc(f, save_one_device); if (autogroup) fprintf(f, "<autogroup state='1' />\n"); fprintf(f, "</settings>\n<dives>\n"); |