summaryrefslogtreecommitdiffstats
path: root/main.c
AgeCommit message (Collapse)Author
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>
2011-10-05Add an '--import' command line optionGravatar Dirk Hohndel
This option indicates that all files that come AFTER it on the command line are being added to our divelist. The dives in these files should receive numbers (assuming they are un-numbered and are all newer then the dives in the files before the --import option, and assuming those dives are numbered). This also marks the dive_list changed after the new dives are added. Using this option gives us a reasonable user experience in the case where a user has one file with all their dives and wants to add newer dives after this (after extracting them from a dive computer - as in the case of a uemis owner where there is no direct import from the dive computer, yet). Something like subsurface MyDives.xml --import NewDives.SDA It also doesn't break Linus' vision where the user has many files on the command line which don't imply a changed dive_list. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-10-05Mark divelist changed when renumbering or adding divesGravatar Dirk Hohndel
The behavior is not yet consistent when calling with multiple file names on the command line (as we don't add number to the later ones in this case), but at least it catches the case if you manually renumber the dives or if you import new dives that get added at the end - which are the two most typical cases. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-10-05Automatically renumber new dives when they are "obvious".Gravatar Linus Torvalds
When importing (or reading xml from files) new dives, we now renumber them based on preexisting dive data, *if* such re-numbering is obvious. NOTE! In order to be "obvious", there can be no overlap between old and new dives: all the new dives have to come at the end. That's what happens with a normal libdivecomputer import, since we cut the import short when we find a preexisting dive. But if any of the new dives overlap the old dives in any way, or already have been numbered separately, the automatic renumbering is not done, and you need to do a manual renumber. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-10-05Move 'dive_list_update_dives()' call into 'report_dives()'Gravatar Linus Torvalds
All the callers were always calling report_dives first, followed by dive_list_update_dives(). And there really was no reason to have the callers call two separate functions for the "I've added new dives" case. So just call dive_list_update_dives() directly from report_dives(), and remove it from the callers. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-27Add preference option to chose if SAC and/or OTU should be in divelistGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-09-21September comes before OctoberGravatar Tero Roponen
This patch fixes the ordering of month names. Signed-off-by: Tero Roponen <tero.roponen@gmail.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-20Separate out the UI from the program logicGravatar Dirk Hohndel
The following are UI toolkit specific: gtk-gui.c - overall layout, main window of the UI divelist.c - list of dives subsurface maintains equipment.c - equipment / tank information for each dive info.c - detailed dive info print.c - printing The rest is independent of the UI: main.c i - program frame dive.c i - creates and maintaines the internal dive list structure libdivecomputer.c uemis.c parse-xml.c save-xml.c - interface with dive computers and the XML files profile.c - creates the data for the profile and draws it using cairo This commit should contain NO functional changes, just moving code around and a couple of minor abstractions. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-09-20Make the divelist font configurableGravatar Linus Torvalds
Instead of the hardcoding to "Sans 8", allow people to set it in the preferences. Also, make the unit choice be a frame in the preferences dialog instead. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-20Merge git://github.com/sirowain/subsurfaceGravatar Linus Torvalds
* git://github.com/sirowain/subsurface: Fix Segmentation fault when trying to print an empty plot. Provide an icon for subsurface. Added a comment about libusb dependency in Makefile.
2011-09-20Make 'struct DiveList' entirely internal to divelist.cGravatar Linus Torvalds
Passing it around is just annoying, and we only ever have one. Let's not burden all the users with the silly thing. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-20Make a separate "Log" menuGravatar Linus Torvalds
Instead o fhaving everything in the "File" menu, make a separate menu for things that are very much specific about divelogs, rather than "generic" things like open/save/import. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-20Provide an icon for subsurface.Gravatar Riccardo Albertini
I designed a simple blue icon for subsurface with a diver in the middle. As suggested by Dirk Hohndel, I added the surface line above diver's head, so that now the icon reflects better the new application name. Signed-off-by: Riccardo Albertini <ssirowain@gmail.com>
2011-09-19Switch the dive list and dive profile panes aroundGravatar Linus Torvalds
It looks better this way, I think. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-19Update the divelist when dive info changesGravatar Linus Torvalds
This flushes the dive changes to the dive list, the way the old dive info frame would update as you update dive fields. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>