Commit graph

51 commits

Author SHA1 Message Date
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
Salvador Cuñat
b47d18b45a smtk-import: portability: rename DATE
DATE happens to be defined in wtypes.h. Redefining it may be a bad idea,
so move it to _DATE

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2017-06-11 13:50:59 -07:00
Salvador Cuñat
15c0a0a6ea smtk-import: portability: include windows.h
Include windows.h if we are cross building to windows

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2017-06-11 13:50:59 -07:00
Robert C. Helling
6963b52d96 Let command line version not open an X window
So we can run it on a headless system

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-06-11 13:50:30 -07:00
Salvador Cuñat
b012258617 smtk-import: add cmake modules and .nsi skeleton
Needed to crossbuild to windows.
The cmake modules are just clones from those under
subsurface/cmake/Modules, tweaked to build smtk-import for windows.
2017-06-11 13:50:30 -07:00
Salvador Cuñat
ddd39f20ff smtk-import: change CMakeLists.txt
As SmartTrak importer is building separately from Subsurface, a full
CMakeLists.txt file is necessary for the smtk-import directory.
It includes cross building to windows capability.
2017-06-11 13:50:30 -07:00
Dirk Hohndel
b641757a0c Add SPDX header to smartrak importer
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-04-29 13:32:55 -07:00
Salvador Cuñat
441cfb3f05 smtk-import: Add curly braces in nested conditionals
Curly braces are necessary in nested conditionals or results may not be
those expected. In this case, the "else" clause applied on second "if",
instead of first one.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2017-04-21 06:52:13 -07:00
Salvador Cuñat
75007aa4ef smtk-import reuse pre-existent code and fix leak
Use update_event_name() for bookmarks merge and free temp string.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2017-04-21 06:52:13 -07:00
Salvador Cuñat
329a6bc075 smtk-import: Abort bookmark parsing if table doesn't open
Do not just report the failure but abort parsing or we will get a crash

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2017-04-21 06:52:13 -07:00
Salvador Cuñat
e4086dc746 smtk-import Avoid duplicities in bookmarks
SmartTrak's bookmarks work in the same fashion Subsurface's do. The user
may set a bookmark while underwater or set it just on the divelog
software.
At this time we are parsing those set in the DC twice, as we get one
from libdivecomputer and another from smarttrak's database.

This patch just checks if we have a bookmark event downloaded by
libdivecomputer which has the same time that the one parsed from the
.slg file. If so, merge the names taking the one from smarttrak.

Text from smarttrak is preferred because the user may have entered some
interesting note there and libdivecomputer's name is just "bookmark".

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2017-04-04 10:54:55 -07:00
Salvador Cuñat
4864ea56cb smtk-import Fix wreck data import
It was assumed that every data field in a wreck table was filled or
zeroed.  This assumption is actually false, so this patch adds testing
for the existence of strings before working with them.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2017-04-04 10:54:55 -07:00
Salvador Cuñat
e2fe196d82 smtk-import fix is_same_cylinder()
Add return value to the gasmix condition, and fix the rest of the
conditions.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2017-03-18 08:33:31 -07:00
Salvador Cuñat
5c757d5c38 smtk-import - Change cylinder import logic
Until now, we did the cylinder import based on its initial pressure (a
tank without pressure is an unused tank). Based in this assumption, we
just dropped those tanks whose initial press was 0, losing user
introduced tank definitions  and getting some duplicities due to one
cylinder being numbered (e.g.) 2 by libdivecomputer and 3 by SmartTrak.

The new workflow is: get every single tank reported by SmartTrak (giving
preference to libdivecomputer parsed data), then clean the cylinder
table reverse order, dropping tanks without description and  init or end
pressures, and checkig them against the previous cylinder to do a merge,
if they look the same, and try to avoid duplicities.

The new logic assumes a heavier workload for the benefit of lower data
loss (e.g. a user may get his/her tanks descriptions despite he/she
hasn't recorded their pressures because forgot the values or had an issue
with the gas transmitter).

Suggested-by: Alessandro Volpi <volpial@gmail.com>
Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2017-03-18 08:33:31 -07:00
Salvador Cuñat
16d37c254c smtk-import - Remove tank number limitation
In the past subsurface managed up to 8 tanks, but now it manages up to
20.  SmartTrak manages 10 (3 in older no trimix versions) so there is no
more need to drop the last tanks.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2017-03-18 08:33:31 -07:00
Salvador Cuñat
20b348579b smtk-import rework smtk_build_tank_info()
The cylinder info is built one by one. This way, instead of passing dive
and tank number parameters, just passing a pointer to the tank been
worked seems preferable.

It also introduces lrint() in the function to round the doubles values
obtained from libmdb for tank size and workingpressure.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2017-03-18 08:33:31 -07:00
Salvador Cuñat
36658d87f3 smtk-import - Add helper funcs to manage tank info
Framed in a full rework of the cylinders info import management, this
funcs will be used in next patches.

Functions merge_cylinder_type(), merge_cylinder_mix() and
merge_cylinder_info(), have been shamelessly copied from dive.c as they
have been removed by 162767aa dated 2017-03-11 just when I was going to
use them.

Macros MERGE_MAX() and MERGE_MIN() have just been copied from dive.c,
but they could be moved to dive.h so they could be used elsewhere if
needed.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2017-03-18 08:33:31 -07:00
Salvador Cuñat
2cef8395b5 smtk-import Use lrint() when rounding to integer values
As commented on mailing list. Most numerical values from libmdb are
doubles obtained via strtod(), so, rounding them instead of just
truncating seems the correct way.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2017-03-18 08:33:31 -07:00
Salvador Cuñat
9ddf2d2ad8 smtk-import Add smarttrak bookmarks parse capability
User can manually add bookmarks on the profile display of SmartTrak.
These are stored in a table with column names which made me think of
cartesian spatial coordinates. In the end the X coordinate is the time.
This makes possible to build subsurface events in those moments of the
dive. The other interesting data is just the text entered by the user.

Suggested-by: Alessandro Volpi <volpial@gmail.com>
Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2017-03-18 08:33:31 -07:00
Salvador Cuñat
9073c3a860 smtk-import - Add function smtk_free()
Group some reiterative freeing task under the imaginative function name
of smtk_free().

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2017-03-18 08:33:31 -07:00
Salvador Cuñat
1413b910a2 smtk-import - Fix memory leaks
Fixes some memory leaks, most of them excesive use of copy_string() in
places where it was unnecesary.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2017-03-18 08:33:31 -07:00
Martin Měřinský
5fa64fd1ea SankTime > Sank Time 2017-03-04 12:08:17 -08:00
Salvador Cuñat
c2997c33c7 smtk-import: Fix freeing unallocated memory
hdr_buffer pointer was not always allocated (just on dc dives), but was
always freed.
This should cause a crash while processing a manually added dive (or a dive
whose dc model couldn't be stablished), but not always does, crashes only
if the pointed memory hasn't been previously allocated. In most cases causes
memory corruption, which goes easily unnoticed as it is correctly freed in
next parse run.
This means, obviously, I have some work TODO fixing leaks with valgrind.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2017-02-25 09:19:48 -08:00
Salvador Cuñat
8b2de77f91 smtk-import-change mktime with timegm
There were 1 or 2 hour differences between real dive time and the
imported time  because of the time zones and energy saving in some locales.
Using timegm() ensures us UTC times instead of localized times.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2017-02-10 20:30:58 -08:00
Salvador Cuñat
f7045c57cd smtk-import-improve smtk_time_to_secs()
Can't remember what I was thinking when wrote that crappy thing. A
simple sscanf call will do the job, and a sanity check, off course.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2017-02-10 20:30:58 -08:00
Salvador Cuñat
7c91cdd89e smtk-import-Fix crash due to localization issues
Libmdbº:xturns localized strings while parsing the data bases. This is
bad for time calculations as we may end with different strings formats
(e.g. en_US vs almost the rest of the world). Solution is simple: set a
fixed locale and parse only this format.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2017-02-10 20:30:58 -08:00
Dirk Hohndel
22267762ce Smart Trak tool compile fix
In commit 70e2404492 ("Stop accessing the internals of
dc_descriptor_t") the structure definition of the libdivecomputer
descriptor was removed from Subsurface and replaced with accessor
functions. This adapts the Smart Trakl import tool to use the same
accessor functions, which allows it to compile again in current master.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-01-17 09:57:40 -08:00
Salvador Cuñat
a71224b350 Locate included header files
After commit 7be962b some directories changed their names.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2017-01-05 13:14:17 -08:00
Salvador Cuñat
56b442ff97 SmartTrak import - Add building out of source tree
Enables auto uic in smtk-import directory and sets
CMAKE_INCLUDE_CURRENT_DIR to ON

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2017-01-05 13:14:01 -08:00
Salvador Cuñat
427c696c70 SmartTrak import - Add build capability to cmake
This enables posibility of building standalone import tool via cmake.
Adds an option SMARTRAK_IMPORT (defaults to OFF) which, if turned ON,
will require glib-2.0 and libmdb libraries to be installed, and, calling
will produce an executable with the highly original name of smtk2ssrf.

I have no capability to cross-compile to windows, so I haven't even
tried to put this in Win, less say in Mac. I expect linux users which
may be actual users of SmartTrak, to test this before trying to build on
windows, although the target public will probably be the windows users (or
at least, ex windows user).

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-11-12 07:39:18 -08:00
Salvador Cuñat
ddc7784514 SmartTrak import - CLI parser and GUI files
The tool can be called from CLI with or without arguments, if called with a
single argument (this is, no destination file specified) an usage message will
be displayed on the terminal; if called with arguments, these should be the .slg
file(s) to be imported and a single .xml file to store the resulting Subsurface
formatted data; if called without arguments a GUI will display to select the
file(s) to import and to store.
WARNING, if destination file exists, its previous content will be erased.

The GUI is pretty simple and don't think any more is needed but, as this is my
first QT thing, I expect those with much better knowledge of QT/C++ will
improve it as needed.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-11-12 07:39:14 -08:00