From 29b242c70349cbd67aacc3e4f1206630d22c54eb Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Mon, 17 Jun 2013 15:58:26 -0700 Subject: 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 --- save-xml.c | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) (limited to 'save-xml.c') 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, "\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, "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, "\n\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, "\n"); fprintf(f, "\n\n"); -- cgit v1.2.3-70-g09d2