We use mod calculations on multiple places, so make a separate helper
from it with proper types.
The "clumsiness" of defining a local variable to pass into the function
and out from it comes from the discrepancies in how c and c++ handles
initializations of variables in a struct.
Thanks goes to Tiago and Linus for pointing me in the right direction.
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The logic of removing the event was in the UI, and this makes
the code harder to test because we need to take into account
also the events that the interface is receiving, instead of
only relying on the algorithm to test.
so, now it lives in dive.h/.c and a unittest is easyer to make.
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
No attempt is made to ensure that what the user does is sane. So this can
result in duplicate numbers, non-consecutive numbers, non-monotonous
numbers, whatever floats the users boat.
You can renumber a single dive or all selected dives (with a starting
number given that is applied to the oldest selected dive and then for each
newer selected dive that number is incremented by one).
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
If a dive has multiple dive computers we enable a special context menu
when the user right-clicks on the dive computer name AND is not already
showing the first dive computer. In that case we offer to make the
currently shown dive computer the first one.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The original name was a really bad choice as we have a 'diveid' as part of
struct divecomputer - and that is not the diveid that is being used here.
Instead we use the 'id' member of struct dive which holds the "unique ID"
for this dive.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit renames getDiveById to get_dive_by_id, and it also removes the
Q_ASSERTS and if(!dive) return that the callers of this function were
calling. If it has a Q_ASSERT this means that the dive must exist,
so checking for nullness was bogus too. I've changed the assert (done
in a silly C-Way.
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
A bit longer, but we had a function named get_dive_by_diveid
and another one named getDiveByDiveid that did completely
different things, it was too easy to hit the wrong one..
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
I'll probably add prefixes to functions to make it easier to find method
via autocomplete from the grep or interface helpers, do you wanna know all
the functions that works with a dive? ask for the completion for dive_,
do you wanna know all the functions that works with a divelist? ask for
the completions on divelist_ or run grep -rIs divelist_ on the header
files.
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Those were from the ancient Gtk times where we hardcoded the white stars
and black stars as font glyphs instead of drawing them. get rid of it.
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The units are used everywhere in the application, we don't really
need to include "dive.h" to be able to use unit conversion, so I
changed them to a new file. There is still a lot of non-dive stuff
in dive.h / c, I'll try to move more later.
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This is based on Linus' idea on the mailing list.
Treat NULL strings and empty strings as identical.
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This patch adds an item to File menu to export all dives in CSV format.
Naturally this includes also the code to perform the export.
Fixes#434
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This is a preferences setting, it should belong to the preferences
structure.
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This marks a lot of todo's where I think there's core stuff being mangled
on the interface - we should remove this from the interface to make
testing and maintenability easier.
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We used to always just commit as "subsurface@hohndel.org" because
libgit-19 doesn't have the interfaces to do user name lookup. This does
better if you have libgit-20, using "git_signature_default()" to get the
actual user that does the saving.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The userid of Subsurface Webservice can be included in locally saved xml
files and git repository.
For xml files, it is stored in userid tag. For git repo, it is stored
in 00-Subsurface file present in the repo.
Preference dialog and webservice dialog modified to include option
for saving userid locally.
In case of difference in default userid and userid in local file,
some semantics are followed. These can be referred to here:
http://lists.hohndel.org/pipermail/subsurface/2014-April/011422.htmlFixes#473
Signed-off-by: Venkatesh Shukla <venkatesh.shukla.eee11@iitbhu.ac.in>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This patch adds the optional --win32console command line option.
It does nothing on OSx and Linux, while is only useable on Win32.
On Win32 if the application was built as GUI (not console),
there is no way to view stdout and stderr. With windows.c's
subsurface_console_init() we are able to either redirect
stdout and stderr to the terminal from which subsurface.exe
was started (always happens; --win32console does nothing in
this case) or if --win32console is explicitly added to
a shortcut, create a dedicated console window and monitor
the output there.
if set, WIN32_CONSOLE_APP is a condition that will make the
subsurface_console_init() and subsurface_console_exit()
functions NOP on Windows. The definition will be created if
the user passes 'CONFIG += console' to qmake.
Fixes#436
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This patch adds the current dive time and the adjusted time to the time
shift window. I added a function to dive.c to get the timestamp of the
first selected dive.
This will view the time of the first selected dive only even when multi
dives are selected but it does change the times for multiple dives
properly.
Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The selection logic was a bit random: some places would return NULL if
the dive computer index was out of range, others would return the
primary dive computer, and actually moving between dive computers would
just blindly increment and decrement the number.
This always selects the primary computer if the index is out of bounds,
and makes sure we stay in bound when switching beteen dive computers
(but switching between dives can then turn an in-bound number into an
out-of-bounds one)
Fixes#464
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This makes "is_git_repository()" return non-NULL for all file names that
match the git name pattern, even if we don't find an actual git
repository there. That way, we won't fall back to writing out an XML
file with an odd filename.
If there is no actual git repository, we return a special invalid dummy
pointer, and then the git reading and writing routines will catch it and
return the appropriate error.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The "report_error()" interface is a lot simpler, although some of the
C++ code uses QStrings which make them a bit annoying, especially for
the varargs model. Still, even with the explicit conversion to UTF8 and
"char *", the report_error() model is much nicer.
This also just makes refreshDisplay() do the error reporting in the UI
automatically, so a number of error paths don't even have to worry. And
the multi-line model of error reporting means that it all automatically
does the right thing, and reports errors for each file rather than just
for the last file that failed to open.
So this removes closer to a hundred lines of cruft, while being a
simpler interface and doing better error reporting.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This makes the error string just be an internal "membuffer", which the
GUI can fetch and show when errors occur. The error string keeps
accumulating until somebody retrieves it with "get_error_string()".
This should make any write errors actually show up to the user.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
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>
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>
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>
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>
It doesn't actually parse the files themselves, but it does walk the
object tree and print out the dives and trips it finds.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
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>
clang-format doesn't appear to reindent multi line #define statements
correctly - so this hopefully will clean those up.
The included whitespace corrections to the code should stay in place when
using the updated tool.
This includes cleaning up some multi-line comments that were messed up the
last time around as well as a few other minor changes.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The get_depth_units function was expecting an unsigned int as a first parameter.
When it received a negative integer, the function made a cast to an unsigned int,
resulting in a very big number.
Signed-off-by: Nicu Badescu <badescunicu@yahoo.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
I know everyone will hate it.
Go ahead. Complain. Call me names.
At least now things are consistent and reproducible.
If you want changes, have your complaint come with a patch to
scripts/whitespace.pl so that we can automate it.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
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>
Alternatively, we could use fabs() to determine the absolute value of
floating point arguments.
The author of commit b6a30dcdd3 ("Improve floating point equality
test") clearly has a rather loose definition of "improve". And the
maintainer who accepted that patch shares the blame...
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Sqlite database from Shearwater Desktop log software is imported. Just
the basic information like location, buddy, notes and dive profile
(depth and temperature).
This is tested with a DB in Imperial units, thus metric input might
contain errors.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Move the opening of DB connection to occur before DC dependent code.
This way we can try to detect log software before calling the DC
dependent import function. This prepares for adding support for
Shearwater sqlite database.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
rint() is "round to nearest integer", and does a better job than +0.5
(followed by the implicit truncation inherent in integer casting). We
already used 'rint()' for values that could be negative (where +0.5 is
actively wrong), let's just make it consistent.
Of course, as is usual for the messy C math functions, it depends on the
current rounding mode. But the default round-to-nearest is what we want
and use, and the functions that explicitly always round to nearest
aren't standard enough to worry about.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
SAC should be calculated in relationship to surface pressure, not "1 bar".
I also realize that we have a few other cases where we do the same
mistake: the partial pressure calculations do things like
po2 = o2 / 1000.0 * depth_to_mbar(sample->depth.mm, dive);
which is wrong as well - the partial pressure is also relative to
standard atmospheric pressures.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
* ensure include guard to every header
* comment endif guard block
Signed-off-by: Boris Barbulovski <bbarbulovski@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
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>
This adds an entry to the dive list context menu to load images. The user
can select image files and set a time offset to align camera and dive
computer clocks.
Using the exif time stamp the images are tried to match to the times of
the selected dives (with a grace period of an hour before and after the
dive). Upon success an event of type 123 is created per image with the
string value being the path to the image. Those images are displayed as
thumbnails in the profile. If the matching dive does not yet have a geo
location specified but the image provides one it is copied to the dive
(making the camera a poor man's companion app).
This patch includes easyexif https://code.google.com/p/easyexif/ which is
originally under a New BSD License to parse the image meta data.
This commit includes a new test dive dives/test31.xml with a matching
image wreck.jpg to try out the functionallity.
Obvious to do's:
Have images on the map
Have the images clickable
Have a proper picture viewer
Give visual reference for image time shifting.
Use the new profile
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This function wraps up the parsing of manually kept CSV log files. Set
up parameters received from C++ code for use in XSLT.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>