Commit graph

81 commits

Author SHA1 Message Date
Robert C. Helling
285fa8acbc Grammar: replaces 'indexes' by 'indices'
Grammar-nazi ran

git grep -l 'indexes' | xargs sed -i '' -e 's/indexes/indices/g'

to prevent future wincing when reading the source code.

Unfortunatly, Qt itself is infected as in
QModelIndexList QItemSelection::indexes() const

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2020-03-11 08:26:30 -07:00
Berthold Stoeger
794066b236 Cylinders: access cylinders with get_cylinder()
Instead of accessing the cylinder table directly, use the get_cylinder()
function. This gives less unwieldy expressions. But more importantly,
the function does bound checking. This is crucial for now as the code
hasn't be properly audited since the change to arbitrarily sized
cylinder tables. Accesses of invalid cylinder indexes may lead to
silent data-corruption that is sometimes not even noticed by
valgrind. Returning NULL instead of an invalid pointer will make
debugging much easier.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
7c9f46acd2 Core: remove MAX_CYLINDERS restriction
Instead of using fixed size arrays, use a new cylinder_table structure.
The code copies the weightsystem code, but is significantly more complex
because cylinders are such an integral part of the core.

Two functions to access the cylinders were added:
get_cylinder() and get_or_create_cylinder()
The former does a simple array access and supposes that the cylinder
exists. The latter is used by the parser(s) and if a cylinder with
the given id does not exist, cylinders up to that id are generated.

One point will make C programmers cringe: the cylinder structure is
passed by value. This is due to the way the table-macros work. A
refactoring of the table macros is planned. It has to be noted that
the size of a cylinder_t is 64 bytes, i.e. 8 long words on a 64-bit
architecture, so passing on the stack is probably not even significantly
slower than passing as reference.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
5da09a21bb Cleanup: move error reporting function declarations to errorhelper.h
Move the declarations of the "report_error()" and "set_error_cb()"
functions and the "verbose" variable to errorhelper.h.
Thus, error-reporting translation units don't have to import the
big dive.h header file.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08 16:26:30 -07:00
Salvador Cuñat
99b5106381 [smtk-import] fix mem leaks on site/location failure management
Signed-off-by: Salvador Cuñat <salvador,cunat@gmail.com>
2019-08-02 08:58:35 +02:00
Salvador Cuñat
ac1408af5f [smtk-import] avoid infinite loop on index failure
As Berthold points out, a failure to match the site or location index
will result in an infinite loop with previous patch.
With this one the loop will end after reading the last table row even if
no idx is matched. But ... If we asume this situation is possible the
retrieved data would be wrong, and ending the function without filling
the site structure is mandatory too.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2019-08-02 08:58:35 +02:00
Salvador Cuñat
218567bb86 fix site/location build issue
We were assuming these tables were sorted with their indexes, but it
happens to be false, under some circustances at least.

Reported-by: Andreas Hagberg <scubasoft@gmail.com>
Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2019-08-02 08:58:35 +02:00
Berthold Stoeger
a5e7f4253a Core: dynamically resize weight table
Replace the fixed-size weightsystem table by a dynamically
relocated table. Reuse the table-macros used in other parts
of the code.

The table stores weightsystem entries, not pointers to
weightsystems. Thus, ownership of the description string is
taken when adding a weightsystem. An extra function adds
a cloned weightsystem at the end of the table.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-18 06:01:07 -07:00
Berthold Stoeger
6200909ba4 Cleanup: move tag functions into own translation unit
Make dive.h a bit slimmer. It's only a drop in the bucket - but at
least when modifying tag functions not the *whole* application is
rebuilt anymore.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19 13:11:10 -07:00
Berthold Stoeger
9ed5cf16a4 Coding style: remove Java-style function definition
Remove a few cases of
	void fun() {
		...
	}

While touching these functions, fix a few other whitespace
coding style violations.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
31291b1c56 Dive site: set UUID only on save or load
Since the UUID will be overwritten on save and is only used on save
and load, set it only on save or load. For other created dive sites,
leave the UUID field uninitialized.

This means that the UUID will change between saves. Let's see how
the git saver handles that.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
f6e7bdc5ef Dive site: add dive site table parameter to dive site functions
To enable undo of dive site functions, it is crucial to work
with different dive site tables. Therefore add a dive site table
parameter to dive site functions. For now, always pass the global
dive site table. Thus, this commit shouldn't alter any functionality.

After this change, a simple search for dive_site_table reveals all
places where the global dive site table is accessed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
643a964d09 Cleanup: unconstify string argument to add_to_string()
add_to_string() frees the original string that is passed in. This
should therefore not be of "const char *" type, as the contents
of the string *will* be modified (or more precisely: destroyed).

Same for the congener smtk_concat_str().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-03-27 13:58:15 +01:00
Rolf Eike Beer
dc254716cf CMake: call cmake_minimim_required() before project()
Some policies can affect how project() works.

Signed-off-by: Rolf Eike Beer <eike@sf-mail.de>
2019-03-19 12:41:32 -07:00
Rolf Eike Beer
d0acee4083 CMake: let CMake set the needed flags for C and C++ standards
Signed-off-by: Rolf Eike Beer <eike@sf-mail.de>
2019-03-19 12:41:32 -07:00
Rolf Eike Beer
f667129ed9 CMake: simplify check if library was found
Signed-off-by: Rolf Eike Beer <eike@sf-mail.de>
2019-03-05 13:27:54 -08:00
Rolf Eike Beer
f555fa787f CMake: simplify writing qt.conf on Windows
Signed-off-by: Rolf Eike Beer <eike@sf-mail.de>
2019-03-05 13:27:54 -08:00
Berthold Stoeger
d1971a64f9 Core: Rename functions to more generic names
Rename
 - dive_get_insertion_index() -> dive_table_get_insertion_index()
 - unregister_dive_from_table() -> remove_from_dive_table()
 - get_idx_in_table() -> get_idx_in_dive_table()
 - sort_table() -> sort_dive_table()
This will make it more straight-forward to generate these functions
from macros.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-09 20:58:04 -08:00
Berthold Stoeger
724055f0af Dive site: replace dive->dive_site_uuid by dive_site
Replace the UUID reference of struct dive by a pointer to dive_site.
This commit is rather large in lines, but nevertheless quite simple
since most of the UUID->pointer work was done in previous commits.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-29 00:09:31 +00:00
Berthold Stoeger
d3a7c5448f Dive site: return pointer to dive_site in create_dive_site_*()
This changes more of the dive-site interface to return pointers
instead of UUIDs. Currently, most call sites directly extract
UUIDs afterwards. Ultimately, the UUIDs will be generally replaced
by pointers, which will then simplify these callers.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-29 00:09:31 +00:00
Berthold Stoeger
68961a169e Dive site: return pointer to dive_site in get_dive_site_*()
As a first step in removing dive-site uuids, change the interface
of the get_dive_site_*() functions to return pointers instead
of uuids. This makes code a bit more complicated in places where
the uuid is extracted afterwards (needed NULL check). Nevertheless,
these places should disappear once pointers instead of uuids are
stored in the dive-structures.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-29 00:09:31 +00:00
Linus Torvalds
28e3413ff6 Add 'location_t' data structure
Instead of having people treat latitude and longitude as separate
things, just add a 'location_t' data structure that contains both.

Almost all cases want to always act on them together.

This is really just prep-work for adding a few more locations that we
track: I want to add a entry/exit location to each dive (independent of
the dive site) because of how the Garmin Descent gives us the
information (and hopefully, some day, other dive computers too).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-10-21 19:55:09 +03:00
Salvador Cuñat
639388e2d8 include libftdi in smtk-import windows build
In windows builds, we don't build stripped subsurface binaries but
depend on previously built ones. For any reason, in regular windows
build libftdi is excluded, and library is not installed/built; on the
other side, in containerized build libftdi is included and we need to
include it in smtk.import build.
Setting pkg_config_library to QUIET works for both builds.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2018-10-15 06:35:14 -04:00
Robert C. Helling
afe363fa85 Optional anonymization upon export
Add a checkbox that triggers replacement of all English characters by
x's in notes, buddy, dive guide and (while we are at it) suit.

This is ment for people sharing logs for debugging that are concious
about privacy issues. It leaves the lenth of strings in tact as well
as special charcters as those might be needed to track down a particular
parsing problem.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-09-13 08:16:54 -07:00
Dirk Hohndel
93ba8c583a smtk2ssrf: build fix
This allows building on Mac and deals with the new dependency in the core
library.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-11 17:25:00 -07:00
Salvador Cuñat
5ebe4195e5 [smtk-import] Apply arrays to the main smartrak_import() function
Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2018-09-06 12:23:51 -07:00
Salvador Cuñat
4c9aeca0df [smtk-import] Remove now unused smtk-value-by-idx()
Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2018-09-06 12:23:51 -07:00
Salvador Cuñat
650b198715 [smtk-import] Apply arrays to parsing tables functions
And add a fuction to parse tables that are not "relational", meaning
tables which are directly refered from Dives table.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2018-09-06 12:23:51 -07:00
Salvador Cuñat
856848466a [smtk-import] Add a function to get the size of an array
We can allocate fixed size arrays for smartrak tables as its size can
be known in advance. Simply reading table->num_rows is too dangereous
as smartrak tables have "holes" commonly. This is, they can look like:
            Idx     |       Txt
             1      |       blablabla
             2      |       blebleble
             4      |       blobloblo
table->num_rows would give us 3, but we need to allocate 4 to get an
array like:

            |0|blablabla |1|blebleble |2|     |3|blobloblo

as the idea is to use the table index to reference the array data.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2018-09-06 12:23:51 -07:00
jan Iversen
3436734bb9 smtk_import: remove QSettings
Update smtk_import to use qPrefDisplay (amended variable)

Signed-off-by: Jan Iversen <jani@apache.org>
2018-08-25 11:49:47 -07:00
Salvador Cuñat
b87cbddfc1 smtk-import: Apply lists to main smartrak_import() function
Previously we built arrays for the tables each time we parsed a dive.
Now we simply build the lists once, and use them in each dive parsing.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2018-08-25 11:11:51 -07:00
Salvador Cuñat
272dcf9514 smtk-import: move from arrys to lists while parsing tables
In most cases we can not foresee the maximum number of data of a given
type. It can be quite low or really big (a concerned diver can store
thousands of different fishes in Fish table).
Moving from arrays, where size has to be preset, to linked lists seems
the more logical option.
Here we set a (very limited) data structure, just an index and a text
fields following the format of most SmartTrak tables. Some special
table, like Buddy, needs a bit of processing before placing the data in
the list.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2018-08-25 11:11:51 -07:00
Salvador Cuñat
25491cf077 smtk-import: Do not set build type in CMakeLists.txt
We set the build type from the building script. Setting this in
CMakeLists.txt make the script setting useless and always build Release
type.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2018-08-25 11:11:51 -07:00
Berthold Stoeger
360f07e453 Cleanup: pass gasmix by value
In a previous commit, the get_gasmix_* functions were changed to
return by value. For consistency, also pass gasmix by value.

Note that on common 64-bit platforms struct gasmix is the size
of a pointer [2 * 32 bit vs. 64 bit] and therefore uses the
same space on the stack. On 32-bit platforms, the stack use
is probably doubled, but in return a dereference is avoided.

Supporting arbitrary gas-mixes (H2, Ar, ...) will be such an
invasive change that going back to pointers is probably the
least of our worries.

This commit is a step in const-ifying input parameters (passing
by value is the ultimate way of signaling that the input parameter
will not be changed [unless there are references to said parameter]).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-23 05:16:38 -07:00
Berthold Stoeger
4e8079f527 Cleanup: make lastUsedDir() functions static and non-slot, respectively
The lastUsedDir() functions of MainWindow and Smrtk2ssrfcWindow don't
use any member-objects and are only used in their respective translation
units. Therefore, remove them from the class and made of static linkage.

The lastUsedImageDir() function was declared as a slog, which makes
no sense. Make it a normal static function (though one might argue
why it is assiociated with the DiveListView class in the first place).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-06-09 17:11:29 +02:00
Dirk Hohndel
d577467f97 Core: introduce new subsurface-string header
First small step to shrinking dive.h.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-05-14 10:13:39 -07:00
Berthold Stoeger
b72cc1f317 Cleanup: consistently use qPrintable()
Replace constructs of the kind
  s.toUtf8().data(),
  s.toUtf8().constData(),
  s.toLocal8Bit().data(),
  s.toLocal8Bit.constData() or
  qUtf8Printable(s)
by
  qPrintable(s).

This is concise, consistent and - in principle - more performant than
the .data() versions.

Sadly, owing to a suboptimal implementation, qPrintable(s) currently
is a pessimization compared to s.toUtf8().data(). A fix is scheduled for
new Qt versions: https://codereview.qt-project.org/#/c/221331/

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-14 13:55:36 +02:00
Salvador Cuñat
3036791d90 smtk-import: Add smtk2ssrf.desktop to sources
Without this file AppImage won't build and travisbuild.sh will fail
miserably.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2018-02-24 13:42:01 -08:00
Berthold Stoeger
5c248d91cd Coding-style: remove superfluous parentheses
Mostly replace "return (expression);" by "return expression;" and one
case of "function((parameter))" by "function(parameter)".

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-02-17 19:38:52 -08:00
Salvador Cuñat
08c4a287a4 smtk-import: Fix error management issue
In commits eccd4b993 to 8f81a22e7 global error buffer and get_error_string()
func, were moved to a call back function.
This patch makes smtk2ssrf suport those changes and build again.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2018-02-11 20:40:23 -08:00
Berthold Stoeger
e85ecdd925 Introduce helper function empty_string()
There are ca. 50 constructs of the kind
  same_string(s, "")
to test for empty or null strings. Replace them by the new helper
function empty_string().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-11 06:07:13 +01:00
Berthold Stoeger
0a2e53caf2 Use QDir::exists() instead of QDir::setCurrent() to check for existence
Don't change into a directory just to see if it exists.
Remove unnecessary braces of one of the changed if statements.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-04 18:35:44 +01:00
Martin Měřinský
0855f6f315 Use icons relative path.
Icon paths are defined in one place only - application's embedded resources.

Signed-off-by: Martin Měřinský <mermar@centrum.cz>
2017-11-30 23:14:46 -08:00
Dirk Hohndel
fd9c905ba3 Revert "Use icons relative path."
This reverts commit b0d98f6e26.
2017-11-29 14:05:07 -08:00
Martin Měřinský
b0d98f6e26 Use icons relative path.
Icon paths are defined in one place only - application's embedded resources.

Signed-off-by: Martin Měřinský <mermar@centrum.cz>
2017-11-29 11:46:35 +01:00
Stefan Fuchs
72318f2897 In strings start lower case in parenthesis
Start with lower case letter inside a parenthesis.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-11-25 15:41:28 -08:00
Stefan Fuchs
8b56dc30d7 Correct, cleanup, translate and unify file filters
Correct spelling and typos in file filters.
Unify and translate file filter names.

Don't pass a file filter to a directory open dialog - not needed.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-11-04 14:27:00 +01:00
Salvador Cuñat
6e2e363c57 smtk-import: partially revert and complete 6963b52d
6963b52d introduced a cmake option, COMMANDLINE to enable building a
pure command line version of smtk2ssrf importer, but then the
 #define COMMANDLINE=1 forces building CLI mode.

This patch allows building GUI or CLI versions depending on selection of
the COMMANDLINE option.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2017-06-22 10:40:04 +09:00
Salvador Cuñat
bde73f05d4 smtk-import portability: avoid using %m[] in sscanf
As Lubomir pointed out in his patch for datatrak.c, the format option %m
for sscanf doesn't work in mingw/windows. Fortunately it's unnecessary
as dates are dropped and we just get times.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2017-06-11 13:50:59 -07:00
Salvador Cuñat
95ee579150 smtk-import: portability: rework non portable funcs
For different reasons some used functions aren't portable or simply are
not included in mingw. This includes index, rindex, strptime, and
timegm.

A workaround for this is needed, if we want to build for windows using
mingw based mxe environment.  This patch does:

- drops index and rindex in favor of strchr and strrchr
- substitute strptime with a sscanf parsing
- emulate timegm with a private func smtk_timegm()
- remove definitions needed by strptime

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2017-06-11 13:50:59 -07:00