summaryrefslogtreecommitdiffstats
path: root/main.c
AgeCommit message (Collapse)Author
2013-01-24Don't set a default filename when called with multiple filenamesGravatar Dirk Hohndel
The behavior is just too illogical - it's too easy to unintentionally overwrite a file this way. The default filename is set if we have exactly one filename on the command line or if we we open the default file. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-24Don't mark divelist changed for automated merges after allGravatar Linus Torvalds
The intention was good, and this was added in commit 4982389ca762 ("Fix setting of the dive_table.preexisting logic"), but it turns out to not be that great idea after all. So the thinking is that merging two dives clearly changes the dive list, and it really does. At the same time, because it's an automated merge, if you re-read the old XML file, you'll get it done again, so saving the changes doesn't really *matter*. And it turns out to be somewhat annoying with test dives: we have - dives/test23.xml: <dive number='23' tripflag='INTRIP' date='2011-12-02' time='6:00:00' duration='30:00 min'> - dives/test25.xml: <dive number='26' date='2011-12-02' time='6:00:00' duration='30:00 min'> that merge automatically if you run subsurface on all the test dives together. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-24Merge branch 'webservice-import'Gravatar Dirk Hohndel
Update maxdepth / duration that have moved into the divecomputer structure. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-23Fix setting of the dive_table.preexisting logicGravatar Linus Torvalds
The 'preexisting' value is used for downloading dives: we want to add new dives but, but then compare those new dives against the preexisting ones before we start sorting things and possibly merging them. However, the value was only updated sporadically, resulting in it having stale information in it. Which would cause problems particularly if you deleted dives, so that the preexisting value would point past the actual existing values! So just update it unconditionally in dive_list_update_dives(), which anything that changes the dive list is supposed to call in order to display the changes anyway. Also, just for safety, when removing a dive, put NULL in the last dive table location. Nobody should ever access past the end anyway (this is enforced by 'get_dive()') but there are places that access the dive list table directly, and the libdivecomputer download was one of those. No reason to leave stale dive pointers possibly around for uses like that. Reported-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no> 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-23Import and merge GPS data from the webserviceGravatar Dirk Hohndel
Dive locations marked (and named) via the companion app are downloaded from the webservice, parsed and merged with the existing dives. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-13Add support for MOD, EAD, AND and EADD in the mouse over displayGravatar Dirk Hohndel
- MOD: Maximum Operation Depth based on a configurable limit - EAD: Equivalent Air Depth considering N2 and (!) O2 narcotic - END: Equivalent Nitrogen (Narcotic) Depth considering just N2 narcotic (ignoring O2) - EADD: Equivalent Air Density Depth Please note that some people and even diving organisations have opposite definitions for EAD and END. Considering A stands for Air, lets choose the above. And considering N for Nitrogen it also fits in this scheme. This patch moves N2_IN_AIR from deco.c to dive.h as this is already used in several places and might be useful for future use also. It also respecifies N2_IN_AIR to a more correct value of 78,084%, the former one also included all other gases than oxygen appearing in air. If someone needs to use the former value it would be more correct to use 1-O2_IN_AIR instead. Signed-off-by: Jan Schubert / Jan.Schubert@GMX.li Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-11Add default filename and divelist font to prefs structureGravatar Linus Torvalds
.. and add the usual logic to not save the default values. This also simplifies the initial system-specific setup of both of these: since we have defaults for all the preferences that get set up at startup, we can just initialize those defaults to the system-specific fonts then and there. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-10Make the default preferences explicitGravatar Linus Torvalds
This makes it explicit what the default preferences are, so that we can more easily avoid unnecessarily saving default settings. It also makes imperial metrics the default for the US (Burma and Liberia always get forgotten!) Right now we tend to be somewhat confused about defaults. We do have them, but then even if something has a default value, we tend to write it out to the config file. Which is not just unnecessary, but makes it really hard to see after-the-fact whether the user actually wanted that *specific* value, or whether they just wanted the default behavior. So this prepares for having explicit configuration for when we want something different than the defaults. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-10Split up preference data structure definition into 'pref.h'Gravatar Linus Torvalds
.. and rename the badly named 'output_units/input_units' variables. We used to have this confusing thing where we had two different units (input vs output) that *look* like they are mirror images, but in fact "output_units" was the user units, and "input_units" are the XML parsing units. So this renames them to be clearer. "output_units" is now just "units" (it's the units a user would ever see), and "input_units" is now "xml_parsing_units" and set by the XML file parsers to reflect the units of the parsed file. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-22Imrpove the nickname handlingGravatar Dirk Hohndel
We now store the model information together with the deviceid and nickname in order to be able to check if we have a record for any dive computer with the same model (as that now triggers our nickname dialog). This changes the format of the config entries for nicknames - the best solution might be to just delete those and start again. What is still missing is the code to store the nicknames in the XML file. 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>
2012-12-05When starting with an empty data file and downloading dives, number themGravatar Dirk Hohndel
We have been very careful not to mess with the numbering that a user may intend - but one obvious case where we should automatically number the dives appears to be the first time download from a dive computer. Right now all dives show up with number '0' and that's just really ugly and a bad experience for a first time user. With this change if a user starts with an empty data file and downloads dives from a computer for the first time, Subsurface will give them numbers starting with '1'. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-11Add special download modes to force updates from the divecomputerGravatar Dirk Hohndel
This will hopefully not be something we need often, but if we improve support for a divecomputer (either in libdivecomputer or in our native Uemis code or even in the way we handle (and potentially discard) events), then it is extremely useful to be able to say "re-download things from the divecomputer and for things that were not edited in Subsurface, don't try to merge the data (which gives BAD results if for example you fixed a bug in the depth calculation in libdivecomputer) but instead simply take the samples, the events and some of the other unedited data straight from the download". This commit implements just that - a "force download" checkbox in the download dialog that makes us reimport all dives from the dive computer, even the ones we already have, and an "always prefer downloaded dive" checkbox that then tells Subsurface not to merge but simply to take the data from the downloaded dive - without overwriting the things we have already edited in Subsurface (like location, buddy, equipment, etc). This, as a precaution, refuses to merge dives that don't have identical start times. So if you have edited the date / time of a dive or if you have previously merged your dive with a different dive computer (and therefore modified samples and events) you are out of luck. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-11Support merging of two adjacent divesGravatar Linus Torvalds
This introduces the notion of merging two disjoint dives: you can select two dives from the dive list, and if the selection is exactly two dives, and they are adjacent (and share the same dive trip), we support the notion of merging the dives into one dive. The most common reason for this is an extended surface event, which made the dive computer decide that the dive was ended, but maybe you were just waiting for a buddy or a student at the surface, and you want to stitch together two dives into one. There are still details to be sorted out: my Suunto dive computers don't actually do surface samples at the beginning or end of the dive, so when you stitch two dives together, the profile ends up being this odd "a couple of feet under water between the two parts of the dive" thing. But that's an independent thing from the actual merging logic, and I'll work on that separately. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-11Prepare to merge non-overlapping divesGravatar Linus Torvalds
This just re-organizes the dive merging code so that we expose a new "merge_dives(a, b, offset)" function that merges two dives together into one with the samples (and events) of 'b' at the specified offset after 'a'. We'll want to use this if a dive computer has decided that the dive ended (due to a pause at the surface), but we really want to just turn the two computer dives into one long one with an extended surface swim. No functional changes, but some independent cleanups due to the trip simplifications. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-09Fix dive trip merging logicGravatar Linus Torvalds
We used to have very spotty logic for picking the dive trip when merging two dives. It turns out that that spotty logic almost never really matters, because in practice you'll never hit the situation of merging two dives with different dive trips, but it *can* happen. In particular, it happens when you use multiple dive computers, and end up loading the dives from one computer on top of the dives of your other computer. If the clocks of the dive computers was set sufficiently close to each other, the dive merging logic will kick in and you may now have slightly different times for the dives that get merged, and the trip merging logic got *really* confused. The trip management also depends on the trip dates being updated correctly when the dives associated with a trip are updated (whether added or removed), and the trip merging code did none of that. This fixes it all up. Hopefully correctly. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-25Allow debug output to go either to log file or to stderrGravatar Dirk Hohndel
This makes it easier to debug things in a debugger, but the infrastructure to send out debug builds where an end user can send in a useful logfile is still in place. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-18Don't enable equipment notebook buttons if there is no diveGravatar Dirk Hohndel
The buttons didn't actually do anything when clicked, but this still was inconsistent behavior. Reported-by: Pierre-Yves Chibon <pingou@pingoured.fr> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-18Find translation files on Linux after Subsurface was installedGravatar Dirk Hohndel
So far we only looked in the a local subdirectory, but once Subsurface has been installed, we don't need to change the search path for translation files anymore. Fixes #2 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-15Set locale under WindowsGravatar Dirk Hohndel
This is mostly a quick hack to be able to test localization under Windows. It seems to work fine under Windows 7 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-15Forgot to localize names of months and weekdaysGravatar Dirk Hohndel
We marked the strings for translation, but then didn't actually call the translation function on them. Our dates are still not truely localized as we have hand written code for the date / time handling that constructs the dates according to US fashion as [Weekday], [Month] [Day of Month], [Year] [hh:mm] Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-15Support for gettext in MacOSX application bundleGravatar Henrik Brautaset Aronsen
The MacOSX applications bundle needs to be told where to bind the text domain from. Also copy the gettext .mo files in the install-macosx target. [Dirk Hohndel: minor change in main(): move the path declaration to the beginning of the function] Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-11Conversion to gettext to allow localizationGravatar Dirk Hohndel
This is just the first step - convert the string literals, try to catch all the places where this isn't possible and the program needs to convert string constants at runtime (those are the N_ macros). Add a very rough first German localization so I can at least test what I have done. Seriously, I have never used a localized OS, so I am certain that I have many of the 'standard' translations wrong. Someone please take over :-) Major issues with this: - right now it hardcodes the search path for the message catalog to be ./locale - that's of course bogus, but it works well while doing initial testing. Once the tooling support is there we just should use the OS default. - even though de_DE defaults to ISO-8859-15 (or ISO-8859-1 - the internets can't seem to agree) I went with UTF-8 as that is what Gtk appears to want to use internally. ISO-8859-15 encoded .mo files create funny looking artefacts instead of Umlaute. - no support at all in the Makefile - I was hoping someone with more experience in how to best set this up would contribute a good set of Makefile rules - likely this will help fix the first issue in that it will also install the .mo file(s) in the correct place(s) For now simply run msgfmt -c -o subsurface.mo deutsch.po to create the subsurface.mo file and then move it to ./locale/de_DE.UTF-8/LC_MESSAGES/subsurface.mo If you make changes to the sources and need to add new strings to be translated, this is what seems to work (again, should be tooled through the Makefile): xgettext -o subsurface-new.pot -s -k_ -kN_ --add-comments="++GETTEXT" *.c msgmerge -s -U po/deutsch.po subsurface-new.pot If you do this PLEASE do one commit that just has the new msgid as changes in line numbers create a TON of diff-noise. Do changes to translations in a SEPARATE commit. - no testing at all on Windows or Mac It builds on Windows :-) Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-09A file that we import should never become the default file we save toGravatar Dirk Hohndel
Only files that are opened should be considered r/w. Files that are imported should be treated as if they were r/o. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-04Provide a method to use unicode command line arguments on WindowsGravatar Lubomir I. Ivanov
For unicode command line characters Windows uses UTF-16, while Glib and GTK use UTF-8. To solve that we retrieve the command line via __wgetmainargs() and use g_utf16_to_utf8() to convert each argument. The used method should support wildcards passed as arguments (e.g. *.xml). Two new, OS abstracted functions appear in linux.c (NOP), macos.c (NOP), windows.c: subsurface_command_line_init(...) subsurface_command_line_exit(...) which are being called in main() Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-29Fix a number of obvious memory leaksGravatar Dirk Hohndel
Just the result of cppcheck and valgrind... Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-26Add the ability to create a log file for debugging outputGravatar Dirk Hohndel
Especially when asking non-developers for help debugging a problem it can be extremely useful to have debugging output not go to the console but to a log file instead. This just adds the infrastructure to create (and close) such a file. No changes to the debug output are made. All this is of course #ifdef'ed out. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-18Call xmlCleanupParser only once - when we are done with libxmlGravatar Lubomir I. Ivanov
Calling xmlCleanupParser in parse-xml.c:parse_xml_buffer() caused massive memory corruption mostly affecting gtk's FileChooser dialogs and the application menu. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-17Make sure dive info is displayed correctly at startGravatar Dirk Hohndel
Commit cdae2869d1dd ("Show the datafile name even with no dives") was a little too aggressive in making sure that we show the correct window title - we only should call show_dive_info(NULL) if there is indeed no dive in the dive table - otherwise we display empty dive info at program start. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-17Fix potential crash when importing divesGravatar Dirk Hohndel
If the last of the preexisting dives gets merged with a new dive we end up dereferencing a freed pointer. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-17Show the datafile name even with no divesGravatar Dirk Hohndel
That's especially useful if starting without a filename and without an existing default file - this way it's clear that Subsurface still considers itself synced with the default file. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-10Change the definition of "dive table changed"Gravatar Dirk Hohndel
We only ask to save changes if the dive table was changed. Yet we didn't consider the dive table changed if it was initially empty. So starting with an empty file and making changes we were quitting without saving. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-10Change behavior for the existing filenameGravatar Dirk Hohndel
Previously we always picked the last file that was openend as the file name to save to. That seems counterintuitive when importing files or when opening multiple files. Especially if Subsurface was executed without a file on the command line and we are using the default file. Now we only remember a file name if it was the first one to ever be openend or if it was used in save-as. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-09First cut of adding a default file nameGravatar Dirk Hohndel
The default file name is OS specific and tries to follow the customs on each of the OSs. It can be configured through the preferences dialog. On MacOS we get a strange warning which appears to be a well documented Gtk bug on MacOS. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-08-26Do some whitespace cleanupGravatar Linus Torvalds
The previous commit was a patch from Lubomir, which also had some whitespace fixes (to go with some new whitespace bugs to replace them) in it. I removed the whitespace changes from that patch (don't mix whitespace fixes with other fixes, unless they are on the same lines!) but decided to look for other whitespace issues, and this is the result. I left the non-C files alone, some of the spec and script files also have whitespace at the end of lines etc. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-08-15Redo dive editingGravatar Dirk Hohndel
This commit addresses two issues: We now can add / edit / delete equipment from the edit dive dialog We now can edit multiple dives at once The latter feature has some interesting design constraints: It picks the 'selected_dive' as the one to start the edit from - so if this dive already has some information filled in, that information needs to be overwritten before it is stored in all of the dives. Similarly, only changes to the cylinders or weightsystems are recorded. Also, the notes field is not editable in the multi dive edit mode (as that didn't seem useful). The workflow seems to work best if using the multi-edit right after importing new dives from a dive computer. The user then can select all the new dives and only needs to edit things like location, divemaster, buddy, weights, etc. once. This commit will create some obvious conflicts with the commit that adds exposure protection tracking. It was implemented on top of the tree_view changes as it reuses some of the infrastructure for tracking the selected dives. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-05-02Don't close config file when changing preferencesGravatar Linus Torvalds
On Linux and MacOS the subsurface_close_conf() doesn't really close the config file (it flushes writes on MacOS), but on Windows it does actually close the registry hkey. Which is bad, if you change the settings multiple times - we assume that the config file is open the whole time. So add a "subsurface_flush_conf()" function, and call *that* when changing configuration parameters. And call the close function only at the very end. Alternatively, maybe we should just open the config file separately every time. I don't much care, maybe somebody else does. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-01-26Split up file reading from 'parse-xml.c' into 'file.c'Gravatar Linus Torvalds
We're going to eventually import non-xml files too, so let's begin splitting the logic up. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-01-05Avoiding some potentially confusing name space clashesGravatar Dirk Hohndel
We have local variables or function arguments with the same names as function static variables (or in one case, function arguments). While all the current code was correct, it could potentially cause confusion when chasing bugs or reviewing patches. This should make things clearer. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-11-19Make double-clicking on the dive list bring up the dive editorGravatar Linus Torvalds
Now that the dive info window is read-only, we need to edit the dives some other way. We bring up a dive info edit dialog when you double-click on the dive list entry for that dive. I do want to have an "edit" button or keyboard shortcut or something too, though. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-11-02Merge branch 'add-info-stats-page' of git://github.com/dirkhh/subsurfaceGravatar Linus Torvalds
* 'add-info-stats-page' of git://github.com/dirkhh/subsurface: Add Info & Stats page to the notebook Even more places with pressure and volume conversions Further cleanup of pressure and volume conversions Use unit functions to get column headers, add unit function for pressure More consistency improvements Add new helper function to get temperature and unit
2011-11-02Add Info & Stats page to the notebookGravatar Dirk Hohndel
This provides the relevant information for the currently selected dive plus a bunch of statistics over all dives in the dive_table. The visual design has lots of room for improvement - right now the different fields change size - it might be nice to have a more modern look for the entries - the O2/He field is odd - for most divers the He value will always be 0, so maybe we should only show He if there's at least one dive that uses He? Also, we simply do a comma separated list of gases for all the tanks used Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-11-01Fix 'init_ui()' so that it can change argc/argvGravatar Linus Torvalds
That's what gtk_init() does with gtk-specific arguments. IOW, if you do things like subsurface --g-fatal-warnings dives.xml to get a real abort on gtk warnings, gtk_init needs to be able to actually change argc/argv. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-10-31Ignore process serial number argument when run as native MacOSX appGravatar Henrik Brautaset Aronsen
The subsurface binary is invoked with a -psn_x_xxxxxx argument when started from a native MacOSX app bundle. Signed-Off-By: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
2011-10-27Don't use gconf on WindowsGravatar Dirk Hohndel
So far this just removes the gconf code - so no preferences for Windows. It also removes the unsused gconf references in main.c Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-10-23Show dive number in dive listGravatar Dirk Hohndel
Make sure that renumbering the divelist correctly shows up on the display. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-10-05Fix import trackingGravatar Dirk Hohndel
Minor logical flaw that breaks the model. When the --import parameter is found we need to mark that the FOLLOWING dives are imported, not the ones loaded so far. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-10-05Add XML file import back and treat open and import differentlyGravatar Dirk Hohndel
Open (or adding a file name on the command line) means that this is just one of the files that you consider part of your dive history. So dives don't get automagically numbered and the dive_list is not considered "changed" just because another file was opened. Import (or adding a file on the command line after --import) means that you are importing the content of this file to your dive history. So if the imported file has un-numbered dives that are newer than everything else, those get correctly renumbered. And importing marks the dive_list as changed. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>