summaryrefslogtreecommitdiffstats
path: root/save-xml.c
AgeCommit message (Collapse)Author
2014-03-14Revert "If saving to a git repository fails, don't create oddly named XML file"Gravatar Dirk Hohndel
This reverts commit e70bbb637e1d Linus' solution in commit 27c36ec4cf41 ("Improved handling of git syntax names with no git repository") is much better and makes my hack unnecessary.
2014-03-14If saving to a git repository fails, don't create oddly named XML fileGravatar Dirk Hohndel
Before this change when the user gave a git style filename, say /tmp/mydives[myname], if Subsurface couldn't create a repository with that branch, it instead saved an XML file to this exact name, with '[' and ']'. That clearly is not the desired behavior, so report an error instead. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-14error handling: return errors for save functionsGravatar Linus Torvalds
Note! This just returns the error (and uses "report_error()" to generate a string that is currently printed to stderr). Nothing actually *uses* that error return yet, and we don't show the error string in the GUI. Baby steps. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-13git object format: make sure parenthood isn't lost when savingGravatar Linus Torvalds
This makes subsurface remember the git source commit of the dive data. If you save to an existing branch, subsurface will now complain and refuse to save if you try to save if the existing branch is not related to the original source. That would destroy the history of the dive data, which in turn would make it impossible to do sane merging of the data. If you save to a new branch, it will see if the previous parent commit is known in the repository you are saving to, and will save parenthood information if so. Otherwise it will save it as a new parentless commit ("root commit" in git parlance). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-12Stop using the "git descriptor file" modelGravatar Linus Torvalds
Instead, just encode the git repository information in the filename. We want to make it much harder to make it match a real filename, but to still allow easy browsing with the file manager interface. So the git repository "filename" format is the path to the git repository directory, with the branch name encoded as "[branch]" at the end rather than the "path:branch" format that we used in the descriptor file. [ For example, on Windows, a filename like "c:\my.xml" could be interpreted as the branchame "\my.xml" in the repository in the directory "c" ] In particular, with this model, no filename that ends with ".xml" could possibly ever be considered a git repository name, since the last character of a git pathname is always ']'. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-10Get rid of crazy empty tag_list element at the startGravatar Linus Torvalds
So this is totally unrelated to the git repository format, except for the fact that I noticed it while writing the git saving code. The subsurface divetag list handling is being stupid, and has a initial dummy entry at the head of the list for no good reason. I say "no good reason", because there *is* a reason for it: it allows code to avoid the special case of empty list and adding entries to before the first entry etc etc. But that reason is a really *bad* reason, because it's valid only because people don't understand basic list manipulation and pointers to pointers. So get rid of the dummy element, and do things right instead - by passing a *pointer* to the list, instead of the list. And then when traversing the list and looking for a place to insert things, don't go to the next entry - just update the "pointer to pointer" to point to the address of the next entry. Each entry in a C linked list is no different than the list itself, so you can use the pointer to the pointer to the next entry as a pointer to the list. This is a pet peeve of mine. The real beauty of pointers can never be understood unless you understand the indirection they allow. People who grew up with Pascal and were corrupted by that mindset are mentally stunted. Niklaus Wirth has a lot to answer for! But never fear. You too can overcome that mental limitation, it just needs some brain exercise. Reading this patch may help. In particular, contemplate the new "taglist_add_divetag()". Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-06Initial implementation of git save formatGravatar Linus Torvalds
This saves the dive data into a git object repository instead of a single XML file. We create a git object tree with each dive as a separate file, hierarchically by trip and date. NOTE 1: This largely duplicates the XML saving code, because trying to share it seemed just too painful: the logic is very similar, but the details of the actual strings end up differing sufficiently that there are tons of trivial differences. The git save format is line-based with minimal quoting, while XML quotes everything with either "<..\>" or using single quotes around attributes. NOTE 2: You currently need a dummy "file" to save to, which points to the real save location: the git repository and branch to be used. We should make this a config thing, but for testing, do something like this: echo git /home/torvalds/scuba:linus > git-test to create that git information file, and when you use "Save To" and specify "git-test" as the file to save to, subsurface will use the new git save logic to save to the branch "linus" in the repository found at "/home/torvalds/scuba". NOTE 3: The git save format uses just the git object directory, it does *not* check out the result in any git working tree or index. So after you do a save, you can do git log -p linus to see what actually happened in that branch, but it will not affect any actual checked-out state in the repository. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-05Mark ignored error return as intentionalGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-16Whitespace cleanup for parse-xml.c and save-xml.cGravatar Dirk Hohndel
This is looking really good. Done using our whitespace tool. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-16Allow backups for .ssrf files as wellGravatar Dirk Hohndel
In commit 102bf768944b ("Rename old 'xml' file as 'bak' file when saving") Linus forgot about our other standard filename extension... Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-16Rename old 'xml' file as 'bak' file when savingGravatar Linus Torvalds
If you use the standard naming convention and end your subsurface filename in ".xml", we will now save away any previous xml file as a "bak" file before writing a new one. This can be useful for: - recovering from mistakes that deleted old dives - seeing what changed (ie you can do things like "diff -u xyz.bak xyz.xml") after doing some operation and saving the result. However, this does only a single level of backups - if you save twice, you will obviously have lost the original. I'd strongly encourage some external backup system in addition to this very simplistic backup. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-10Clean up membuffer internal structure names, add strip functionGravatar Linus Torvalds
The "size" member was confusing - it's the size of the allocation, not the size of the current string. The size of the current string is the member called "used". This naming makes perfect sense for the internal implementation, but it's confusing to users who actually do want to get the size of the resulting string at the end. So rename the fields to "alloc" and "len" - which is pretty clear. This also adds a helper function to strip whitespace from the end: "strip_mb()". Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-10Add support for heartrate and bearing information in samplesGravatar Linus Torvalds
libdivecomputer already supports this, but we didn't save it. Tested-by: Oscar Isoz <jan.oscar.isoz@gmail.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-16Save XML files into a memory buffer rather than directly into a fileGravatar Linus Torvalds
This introduces a "struct membuffer" abstraction that you can write things into, and makes the XML saving code write to the memory buffer rather than a file. The UDDF export already really wanted this: it used to write to a file, only to then read that file back into memory, delete the file, and then *rewrite* the file after doing the magic xslt transform. But the longer-term reason for this is that I want to try to write other formats, and I want to try to share most helpers. And those other formats will need this memory buffer model. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-16Convert the C code to using stdbool and true/falseGravatar Anton Lundin
Earlier we converted the C++ code to using true/false, and this converts the C code to using the same style. We already depended on stdbool.h in subsurfacestartup.[ch], and we build with -std=gnu99 so nobody could build subsurface without a c99 compiler. [Dirk Hohndel: small change suggested by Thiago Macieira: don't include stdbool.h for C++] Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-19Files: use the new open() wrappersGravatar Lubomir I. Ivanov
Adds use of everything from the new wrappers(), but the opendir() one. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-06Really save airtemp and watertemp in the diveGravatar Dirk Hohndel
I thought I had this fixed, but a silly thinko broke my fix. Only abort the saving if both air AND water temperature are already covered by the divecomputer(s) in a dive. If at least one of them is different, then create a divetemperature tag and fill in that value at the dive level. Fixes #313 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-29Editing air or water temperature should modify dive computer, not diveGravatar Dirk Hohndel
The dive fields are summary fields, the actual data needs to be in the divecomputer specific fields. Fixes #307
2013-11-27Show/save weights up to and including last validGravatar Anton Lundin
Previous show and save code would have aborted at the first invalid weight system. This makes sure we save and show all weight systems up until and including the last valid. If we had: integrated: 1kg belt: 2kg ankle: 3kg And changed belt to 0 kg, we would have only saved integrated 1kg, and nothing about the belt or the ankle weights. This will save all of them, and show all of them. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-15Escape all problematic characters when saving a tagGravatar Maximilian Güntner
Signed-off-by: Maximilian Güntner <maximilian.guentner@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-02Replaced the tag implementationGravatar Maximilian Güntner
The new implementation supports custom tags which are provided by the user as well as default tags which are provided by subsurface. Default tags can be translated and will be written to XML in their non-localized form. Signed-off-by: Maximilian Güntner <maximilian.guentner@gmail.com>
2013-10-20Export dives in UDDF formatGravatar Miika Turkia
Implement exporting in UDDF format as was done in Gtk version. File menu exports all the dives, right click on selection exports the selected ones. Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-06First steps towards removing glib dependenciesGravatar Dirk Hohndel
- remove the build flags and libraries from the Makefile / Configure.mk - remove the glib types (gboolean, gchar, gint64, gint) - comment out / hack around gettext - replace the glib file helper functions - replace g_ascii_strtod - replace g_build_filename - use environment variables instead of g_get_home_dir() & g_get_user_name() - comment out GPS string parsing (uses glib utf8 macros) This needs massive cleanup, but it's a snapshot of what I have right now, in case people want to look at it. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-06-18Converting the device_info list into a Qt data structureGravatar Dirk Hohndel
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>
2013-05-21Remove Gtk crudGravatar Dirk Hohndel
The DEBUGFILE logic isn't needed anymore. Nor are helpers dealing with model / datastructure updates. Nor conditional compiles to use Gtk instead of Qt. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-09Store the tag names instead of an opaque numberGravatar Dirk Hohndel
And as we need the names for that, simplify the way we show the tags in the Dive Info tab (and mark them for translation while we are at it). In the process I renamed the constants to DTAG_ from DTYPE_ (and made their nature as being just bits more obvious). Also mark the box on the Info tab "Dive Tags", not "Dive Type". Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-09Add dive tags and support invalid divesGravatar Ďoďo
This started out as a way to keep dives in the dive list but being able to mark them as 'invalid' so they wouldn't be visible (with an option to disable that feature). Now it supports an (at this point, fixed) set of tags that can be assigned to a dive with 'invalid' being just one of them (but one that is special as it gets some additional support for hiding such dive and marking dives as (in)valid from the divelist). [Dirk Hohndel: merged with the latest code and minor changes for coding style and consistency. Ensure divelist is marked as modified when changing 'invalid' tag] Signed-Off-By: Jozef Ivanecký (dodo.sk@gmail.com) Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-03-07Fix potentially broken white space truncation on certain Windows versionsGravatar Lubomir I. Ivanov
Testing the Planner in Subsurface on a Windows XP SP3 installation, shows corrupted UTF-8 strings in the case of Cyrillic locales, but possibly others as well. Instead limited to the Planner, this affects the entire application. After some examination it appears that <ctype>'s isspace() in MSVC on the tested version of Windows is broken for some UTF-8 characters, after enabling the user locale using: setlocale(LC_ALL, ""); For example, characters such as the Cyrillic capital "BE" are defined as: 0xD091, where isspace() for the first byte returns 0x08, which is the bytemask for C1_SPACE and the character is treated as space. After a byte is treated as space, it is usually discarded from a UTF-8 character/string, where if only one byte left, corrupting the entire string. In Subsurface, usages of string trimming are present in multiple locations, so to make this work try to use GLib's g_ascii_isspace(), which is a locale agnostic version of isspace(). Affected versions of Windows could be everything up to XP SP3, but not apparently Vista. Reported-by: Sergey Starosek <sergey.starosek@gmail.com> Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-03-01Fix saving of po2 valuesGravatar Linus Torvalds
It was very broken, although it just happened to work for the values dirk had in his own XML file (0 and 0.800 bar). Because of confusion with number of digits it would save 1.080 bar as 1.80 bar. Use our "show_milli()" helper for showing things that are in milli-units (which is what we tend to use for most of our values: mK, mbar, mm, ml) Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-27Ensure all strings stored in XML are escaped correctlyGravatar Linus Torvalds
This does escaping / quoting for everything I found. Some of it was safe (the divecomputer model is supplied from libdivecomputer, and none of them have single quotes _yet_, afaik), but with this there are no '%s' strings left except for the ones used by the helper functions (for "pre" and "post" strings). It also takes some of our existing uses of show_utf8(), and removes the redundant "check if the string is NULL or empty". show_utf8() does that internally. Fixes #73 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-15Improve the code handling air temperatureGravatar Linus Torvalds
Better helper functions make for easier to understand code. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-14Better handling of manually edited air temperatureGravatar Dirk Hohndel
We now load and save this in the XML file, we do the right thing when merging dives and show the edited air temperature in the Dive Info notebook when a divecomputer doesn't have an air temperature. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-08Do more dive fixup for each dive computerGravatar Linus Torvalds
In commit b6c9301e5847 ("Move more dive computer filled data to the divecomputer structure") we moved the fields that get filled in by the dive computers to be per-divecomputer data structures. This patch re-creates some of those fields back in the "struct dive", but now the fields are initialized to be a reasonable average from the dive computer data. We already did some of this for the temperature min/max fields for the statistics, so this just continues that trend. The goal is to make it easy to look at "dive values" without having to iterate over dive computers every time you do. Just do it once in "fixup_dive()" instead. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-02Add 'Save As' entry to context menu shown when right clicking on a diveGravatar Pierre-Yves Chibon
Something which is nice especially when asked on the list to share an interesting dive is the possibility to save just some dives into a file. This commit adds to the context menu shown with right-click the 'Save As' entry. This entry allows to save selected dives. [Dirk Hohndel: clean up white space, commit message and remove unused variables] Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-24Centralization for Kelvin and Standardization to milliKelvinGravatar Jan Schubert
This centralizes all occurrences of Kelvin to dive.h and standardizes all usages to milliKelvin. [Dirk Hohndel: renamed the constant plus minor white space cleanup] Signed-off-by: Jan Schubert <Jan.Schubert@GMX.li> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-24Save all dive computer nicknames - whether used or notGravatar Linus Torvalds
We used to save dive computer information only if that dive computer was actually used in any of the dives we saved. But we can simplify the code if we just always save any dive computers we know about. And it does allow for some usage cases where you have nicknames for other peoples computers that you may not actively use, but you want to see if you end up loading multiple XML files in one go. So there's just no compelling reason to not just save all the info we have. And this will make it less painful to remove the "use system config for dive computer nicknames", because you can also use this to continue to gather dive computer info in a separate XML file if you want to. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-23Move more dive computer filled data to the divecomputer structureGravatar Linus Torvalds
This moves the fields 'duration', 'surfacetime', 'maxdepth', 'meandepth', 'airtemp', 'watertemp', 'salinity' and 'surface_pressure' to the per-divecomputer data structure. They are filled in by the dive computer, and normally not edited. NOTE! All actual *use* of this data was then changed from dive->field to dive->dc.field programmatically with a shell-script and sed, and the result then edited for details. So while the XML save and restore code has been updated, all the displaying etc will currently always just show the first dive computer entry. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-09Assemble the actual Suunto serial numberGravatar Linus Torvalds
It turns out that the serial number returned by libdivecomputer isn't really the serial number as interpreted by the vendor. Those tend to be strings, but libdivecomputer gives us a 32bit number. Some experimenting showed that for the Suunto devies tested the serial number is encoded in that 32bit number: It so happens that the Suunto serial number strings are strings that have all numbers, but they aren't *one* number. They are four bytes representing two numbers each, and the "23500027" string is actually the four bytes 23 50 00 27 (0x17 0x32 0x00 0x1b). And libdivecomputer has incorrectly parsed those four bytes as one number, not as the encoded serial number string it is. So the value 389152795 is actually hex 0x1732001b, which is 0x17 0x32 0x00 0x1b, which is - 23 50 00 27. This should be done by libdivecomputer, but hey, in the meantime this at least shows the concept. And helps test the XML save/restore code. It depends on the two patches that create the whole "device.c" infrastructure, of course. With this, my dive file ends up having the settings section look like this: <divecomputerid model='Suunto Vyper Air' deviceid='d4629110' serial='01201094' firmware='1.1.22'/> <divecomputerid model='Suunto HelO2' deviceid='995dd566' serial='23500027' firmware='1.0.4'/> where the format of the firmware version is something I guessed at, but it was the obvious choice (again, it's byte-based, I'm ignoring the high byte that is zero for both of my Suuntos). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-09Move device_info handling into a new 'device.c' fileGravatar Linus Torvalds
The legacy nickname wrappers (that use the device_info structure) are left in gtk-gui.c. We can slowly start moving away from them, we don't want to start exporting that thing as some kind of generic interface. This isn't a pure code movement - because we leave the legacy interfaces alone, there are a few new interfaces in device.c (like "create a new device_info entry") that were embedded into the legacy "create nickname" code, and needed to be abstracted out. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-09Add support to planner to use additional gases during the ascentGravatar Dirk Hohndel
This change ended up being quite a bit bigger than expected as it uncovered a number of bugs in the existing code. The planner now handles gas changes correctly by creating (and later parsing) events in the simulated divecomputer. At the end of the dive specified in the input form the algorithm starts with the deepest interesting depth: either the first stop below our ceiling or the deepest depth at which we can change gases. It then traverses all the stop and all the gas change depth and at each stage ensures that we are allowed to ascend further before going on. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-01Remove autogroup from the preferences and store per file insteadGravatar Dirk Hohndel
Having two spots to toggle autogroup had always been a clear sign of insanity. The inconsistent ludicrous semantic of when we remembered the state of autogroup was even worse. This finally gets rid of that disaster and drops the autogroup setting from the preferences and makes it instead a per file property. When you save a file, it saves the state of the autogroup toggle. This seems much more useful - you may have files where you want to create trips by default. And others, where you don't. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-01Clear divecomputer saved status before saving the nicknames to XMLGravatar Dirk Hohndel
In commit c7169bd24f22 "Fix nickname saving in XML file to deal with utf8 characters" I added the helper function to clear the "this divecomputer has already been saved"-flag. But then forgot to call it from save_dives before saving the divecomputer nicknames. Reported-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-30First step in cleaning up cylinder pressure sensor logicGravatar Linus Torvalds
This clarifies/changes the meaning of our "cylinderindex" entry in our samples. It has been rather confused, because different dive computers have done things differently, and the naming really hasn't helped. There are two totally different - and independent - cylinder "indexes": - the pressure sensor index, which indicates which cylinder the sensor data is from. - the "active cylinder" index, which indicates which cylinder we actually breathe from. These two values really are totally independent, and have nothing what-so-ever to do with each other. The sensor index may well be fixed: many dive computers only support a single pressure sensor (whether wireless or wired), and the sensor index is thus always zero. Other dive computers may support multiple pressure sensors, and the gas switch event may - or may not - indicate that the sensor changed too. A dive computer might give the sensor data for *all* cylinders it can read, regardless of which one is the one we're actively breathing. In fact, some dive computers might give sensor data for not just *your* cylinder, but your buddies. This patch renames "cylinderindex" in the samples as "sensor", making it quite clear that it's about which sensor index the pressure data in the sample is about. The way we figure out which is the currently active gas is with an explicit has change event. If a computer (like the Uemis Zurich) joins the two concepts together, then a sensor change should also create a gas switch event. This patch also changes the Uemis importer to do that. Finally, it should be noted that the plot info works totally separately from the sample data, and is about what we actually *display*, not about the sample pressures etc. In the plot info, the "cylinderindex" does in fact mean the currently active cylinder, and while it is initially set to match the sensor information from the samples, we then walk the gas change events and fix it up - and if the active cylinder differs from the sensor cylinder, we clear the sensor data. [Dirk Hohndel: this conflicted with some of my recent changes - I think I merged things correctly...] Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-30Fix nickname saving in XML file to deal with utf8 charactersGravatar Dirk Hohndel
This makes the whole code much cleaner and simpler. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-30Allow overlapping (and disjoint) dive tripsGravatar Linus Torvalds
We used to have the rule that a dive trip has to have all dives in it in sequential order, even though our XML file really is much more flexible, and allows arbitrary nesting of dives within a dive trip. Put another way, the old model had fairly inflexible rules: - the dive array is sorted by time - a dive trip is always a contiguous slice of this sorted array which makes perfect sense when you think of the dive and trip list as a physical activity by one person, but leads to various very subtle issues in the general case when there are no guarantees that the user then uses subsurface that way. In particular, if you load the XML files of two divers that have overlapping dive trips, the end result is incredibly messy, and does not conform to the above model at all. There's two ways to enforce such conformance: - disallow that kind of behavior entirely. This is actually hard. Our XML files aren't date-based, they are based on XML nesting rules, and even a single XML file can have nesting that violates the date ordering. With multiple XML files, it's trivial to do in practice, and while we could just fail at loading, the failure would have to be a hard failure that leaves the user no way to use the data at all. - try to "fix it up" by sorting, splitting, and combining dive trips automatically. Dirk had a patch to do this, but it really does destroy the actual dive data: if you load both mine and Dirk's dive trips, you ended up with a result that followed the above two technical rules, but that didn't actually make any *sense*. So this patch doesn't try to enforce the rules, and instead just changes them to be more generic: - the dive array is still sorted by dive time - a dive trip is just an arbitrary collection of dives. The relaxed rules means that mixing dives and dive trips for two people is trivial, and we can easily handle any XML file. The dive trip is defined by the XML nesting level, and is totally independent of any date-based sorting. It does require a few things: - when we save our dive data, we have to do it hierarchically by dive trip, not just by walking the dive array linearly. - similarly, when we create the dive tree model, we can't just blindly walk the array of dives one by one, we have to look up the correct trip (parent) - when we try to merge two dives that are adjacent (by date sorting), we can't do it if they are in different trips. but apart from that, nothing else really changes. NOTE! Despite the new relaxed model, creating totally disjoing dive trips is not all that easy (nor is there any *reason* for it to be easty). Our GUI interfaces still are "add dive to trip above" etc, and the automatic adding of dives to dive trips is obviously still based on date. So this does not really change the expected normal usage, the relaxed data structure rules just mean that we don't need to worry about the odd cases as much, because we can just let them be. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-30Update deco handlingGravatar Dirk Hohndel
This commit makes deco handling in Subsurface more compatible with the way libdivecomputer creates the data. Previously we assumed that having a stopdepth or stoptime and no ndl meant that we were in deco. But libdivecomputer supports many dive computers that provide the deco state of the diver but with no information about the next stop or the time needed there. In order to be able to model this in Subsurface this adds an in_deco flag to the samples. This is only stored to the XML file when it changes so it doesn't add much overhead but will allow us to display some deco information on dive computers like the Atomic Aquatics Cobalt or many of the Suuntos (among others). The commit also removes the old event based deco code that was commented out already. And fixes the code so that the deco / ndl information is stored for the very last sample as well. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-28Make add_dc_to_string() skip redundant entriesGravatar Linus Torvalds
There is no point writing out divecomputer nicknames that do not exist (or that match the dive computer model), so don't. Also, make the function to do this static to save-xml.c, which is the only user (I initially didn't _find_ the function to create the XML string because it was illogically hidden in gtk-gui.c), and change the calling convention to be more direct (pass in a string and return a result, rather than modify a "pointer to string"). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-26Add settings section to XML file format and store dive computer IDsGravatar Dirk Hohndel
We only store the model/deviceid/nickname for those dive computers that are mentioned in the XML file. This should make the XML files nicely selfcontained. This also changes the code to consistently use model & deviceid to identify a dive computer. The deviceid is NOT guaranteed to be collision free between different libdivecomputer backends... Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-21Remove nickname from divecomputer data structureGravatar Dirk Hohndel
Having it there with the model information seemed to make sense but on second thought it's the wrong spot to keep that information, especially since we were storing it in the XML file in every single dive. This change removes the nickname member from the divecomputer and makes the rest of the code reasonably self consistent. It does not add much of the new code for the new design to handle nicknames. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-13Add the ability to set a nickname for a dive computerGravatar Dirk Hohndel
We maintain a list of dive computers that we know about (by deviceid) and their nicknames in our config. If the user downloads dive from a dive computer that we haven't seen before, we give them the option to set a nickname for that dive computer. That nickname is displayed in the profile (and stored in the XML file, assuming it is not the same as the model). This implementation attempts to make sure that it correctly deals with utf8 nicknames. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>