Commit graph

143 commits

Author SHA1 Message Date
Berthold Stoeger
95284c026e cleanup: move dive_table from dive.h to divelist.h
This allows us to decouple dive.h and divelist.h, a small step in
include disentangling.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01 09:42:31 -07:00
Berthold Stoeger
5ba7c68433 cleanup: remove unused function get_divepoint_gas_string()
The last user was removed way back in commit
9fbd11744f.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-27 22:48:15 +03:00
Berthold Stoeger
9386eb2a0b cleanup: move get_dc_nickname from qthelper.cpp to divecomputer.cpp
1) qthelper is already huge.
2) set_dc_nickname et al. is already there.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-24 10:40:12 -07:00
Dirk Hohndel
6d187b5f4a
Merge pull request #2643 from bstoeger/cylinder4
First steps of cylinder-editing undo
2020-04-11 11:03:05 -07:00
Berthold Stoeger
3f3869ff65 media: move picture function from dive.c to picture.c
Currently, move only those functions that do not access dive
structures.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-10 10:53:03 -07:00
Berthold Stoeger
5b7a316593 undo: reorder cylinders on remove-cylinder undo/redo
The cylinders in the events must be reordered if we remove
a cylinder. To avoid duplication of code, move the reordering
function into qthelper.cpp, though it might not be ideal
there.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Dirk Hohndel
f58bc91d8b core: add additional notification callback
Especially on slower devices with a large dive list the startup time has
become really long. This callback allows us to give the user an idea of
what the app is doing during that time.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-04 12:00:24 -07:00
Berthold Stoeger
0f30ca9b33 cleanup: remove memory leak in initUiLocale()
The prefs.locale.lang_locale field was overwritten without
free()ing the old value. Not that the function would be called
numerous times, but as a matter of principle...

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-22 12:01:09 -07:00
Berthold Stoeger
eb55ffde16 cleanup: split uiLanguage() in two functions
The uiLanguage() function was used for two purposes: to initialize
the language related preferences and to read the current language.
To make things more easy to follow, split this function in two:
one for initializing, one for getting the current language.

Moreover, don't return the current locale in an out-parameter
as there is already a function to do that [getLocale()].

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-22 12:01:09 -07:00
Berthold Stoeger
2dca7d0ce5 locale: store locate to preferences after fixing up mac-weirdness
In uiLanguage() the preferences fields are initialized and there
is fixup for a MacOS indiosyncrasy. For some reason the uncorrected
value is written to the preferences. Let's store the corrected
value instead.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-22 12:01:09 -07:00
Berthold Stoeger
2db7d5cc23 Revert "core: use set_lang_locale to modify prefs.locale.lang_locale"
This reverts commit 573a4a5e2d.

The commit broke setting the language in the desktop preferences:
Instead of setting the locale in the prefs struct, the locale
is set via qPrefLanguage. However, that saves the default language
(extracted from the system) to disk. Now when the language is
read from the preferences, we get that default value.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-21 21:06:36 -07:00
Dirk Hohndel
160d2ab071 core: make command texts available for C code
Create a C string (which the caller needs to free) with the executed commands
in this session.

The detour via the callback allows us to not make the corelib depend on the
commands, which is nice for tests, export-html, and smtk2ssrf.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-10 09:25:57 -07:00
Berthold Stoeger
2a97934db4 Cleanup: Move stringToList to core/qthelper.cpp
The same code was used in desktop and undo commands. Let's unify.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-06 10:00:13 +01:00
Berthold Stoeger
f3a3d93b85 filter: remove diveContainsText()
This function checked a dive for a search string. Its functionality
was replaced by a fulltext index.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-01 10:21:44 -08:00
Berthold Stoeger
f7c73f1987 mobile/summary: implement firstDiveDate and lastDiveDate
Instead of transporting the global first and last dive date
in the dive summary, calculate it in an external function.
Since we already have time and date functions in qthelper.cpp
implement those functions there. Provide a stub in QMLInterface
so that QML can access these standalone functions.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-08 10:29:36 -08:00
Berthold Stoeger
cf1e3524a1 Gps coordinates: be more graceful when parsing coordinates
Some Wikipedia pages use special (non-ASCII) unicode symbols for
representing the " and ' separators. Before parsing, replace these
by the ASCII symbols to enable copy & paste from Wikipedia (and
other sources?).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-06 08:50:22 -08:00
Berthold Stoeger
e5487f86a6 Coding style: remove braces around single-line if blocks
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-06 08:50:22 -08:00
Berthold Stoeger
1bebf55737 Coding style: move & from type to variable
Trivial white-space cleanup according to coding style document.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-06 08:50:22 -08:00
jan Iversen
573a4a5e2d core: use set_lang_locale to modify prefs.locale.lang_locale
Do not set prefs.locale_lang_locale directly, but do it
indirectly through qPrefLanguage::set_lang_locale(),
to ensure the file plist is consistent with prefs.

the difference (prefs. contra plist) cause surprises
when restarting mobile (and playing with language).

Signed-off-by: Jan Iversen <jani@apache.org>
2019-12-27 03:41:20 +09: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
11467fa326 Core: dynamically allocate the result of get_gas_used()
get_gas_used() returns the volume of used gases. Currently,
an array with MAX_CYLINDERS is passed in. If we want to make the
number of cylinders dynamic, the function must use an arbitrarilly
sized array.

Therefore, return a dynamically allocated array and free it
in the caller.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Dirk Hohndel
4458373488 Cleanup: remove bogus code that slipped in earlier
Commit df4fbf7699 ("Android: force different font on OnePlus devices")
inadvertantly added this hunk - let's undo it again.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-05 08:19:31 -07:00
Dirk Hohndel
9a35519a2a Android: bundle default font for use in OnePlus devices
This is working around a Qt Bug https://bugreports.qt.io/browse/QTBUG-69494
which prevents correct rendering of the OnePlus fonts.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-09-21 15:13:10 -07:00
Berthold Stoeger
37a3daf2dd Mobile: decouple full text search from DiveObjectHelper
1) The full text search was looping over the DiveListModel when
   it could simply loop over the core model. Do that instead.

2) Don't generate a DiveObjectHelper to do a full text search.
   Currently this is harmless as the DiveObjectHelper is only
   a disguised "dive *". But from a conceptual point of view,
   it represents the full representation of a dive and we don't
   want to generate that in a tight loop.

This will help in
1) Making the DiveObjectHelper a non-reference object.
2) Moving fulltext search to the core and thus making it available
   to desktop and more performant.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-14 13:20:59 +02:00
Berthold Stoeger
52e5d9c605 Cleanup: move planner/deco related declarations planner/deco.h
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08 16:26:31 -07: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
Berthold Stoeger
7f4d9db962 Cleanup: move trip-related functions into own translation unit
These functions were spread out over dive.c and divelist.c.
Move them into their own file to make all this a bit less monolithic.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19 13:11:10 -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
75767c456a Turn application state into enum
The application state was encoded in a QByteArray. Thus, there was
no compile-time checking. Typos would lead to silent failures.

Turn the application state into an enum. Use the enum-class construct,
so that the values don't polute the global namespace. Moreover,
this makes them strongly typed, i.e. they don't auto-convert to
integers.

A disadvantage is that the enums now have to be cast to int
explicitly when used to index an array.

Replace two hash-maps in MainWindow to arrays of fixed sizes.

Move the application-state details into their own files.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-12 12:33:55 -07:00
Berthold Stoeger
e362afe43c Cleanup: remove UTF8 macros
At some places we use UTF8 string literals. Therefore, we effectively
only support UTF8 build systems. We might just as well remove all
the other UTF_* macros and use direct string literals.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-12 12:25:43 -07:00
Berthold Stoeger
d5953318ca Cleanup: replace QString("") by QString()
That should be more effective.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Rolf Eike Beer
36644dc9f7 optimize selectedDivesGasUsed()
-return the result instead of storing in a parameter, we now know that the list
 contains only those results that are generated in the function
-allocate the result with the correct length right from the start
-do not iterate over keys of a map and then do a map lookup to get the value but
 use an iterator that gives us both right from the start
-remove one call alltogether as the results were not used there

Signed-off-by: Rolf Eike Beer <eike@sf-mail.de>
2019-04-12 12:59:17 +03:00
Rolf Eike Beer
e3d43b5696 replace deprecated qSort() with std::sort()
Signed-off-by: Rolf Eike Beer <eike@sf-mail.de>
2019-04-12 12:59:17 +03:00
Rolf Eike Beer
ee0acb0d40 use QStringLiteral for constants
Signed-off-by: Rolf Eike Beer <eike@sf-mail.de>
2019-04-12 12:59:17 +03:00
Rolf Eike Beer
c4c8094e32 get rid of some foreach and Q_FOREACH constructs
See https://www.kdab.com/goodbye-q_foreach/

This is reduced to the places where the container is const or can be made const
without the need to always introduce an extra variable. Sadly qAsConst (Qt 5.7)
and std::as_const (C++17) are not available in all supported setups.

Also do some minor cleanups along the way.

Signed-off-by: Rolf Eike Beer <eike@sf-mail.de>
2019-04-12 12:59:17 +03:00
Berthold Stoeger
40a3e562b0 Cleanup: provide printGPSCoords in C and C++ versions
printGPSCoords() returned a newly allocated C-style string. Most
callers simply made a QString out of it and freed the C-style string.
This is paradoxical, as printGPSCoords internally works with QStrings
and converts them to C-style on return.

Therefore, let printGPSCoords() return a QString and create a
printGPSCoordsC() wrapper for the two C-callers.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-03-27 13:58:15 +01:00
Berthold Stoeger
04593e8ec4 Cleanup: fix printGPSCoords signature and leaks
The printGPSCoords() function returns a copied C-style string. Since
the owndership is transferred to the caller, the correct return type
is "char *" instead of "const char *".

Thus a number of casts when calling free can be removed.

Moreover a number of callers didn't free the string and thus were
leaking memory. Fix them. Ultimately we might want two versions
of the function: one for QString, one for C-style strings.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-03-24 21:57:13 -07:00
Dirk Hohndel
b457965f50 Core: remove variable name conflict
Having a parameter representing a location with the same name as a global
variable representing our locale is confusing.

Found via LGTM.com

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-03-17 15:11:31 -07:00
Berthold Stoeger
6184f5d276 Core: remove count_dives_with_*() functions
The simplified filter-widget doesn't present lists of existing values
with counts. Thus, a whole slew of count_dives_with_*() functions
can be removed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-12-17 07:33:45 -08:00
Berthold Stoeger
70897dd1b7 Core: move is-single-day-trip and count-shown functions into core
These functionality was used by the desktop filter. To unify desktop
and mobile, move it into two new functions in divelist.c

Since one of them is the only caller of is_same_day() move that
likewise into divelist.c and make it of static linkage.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-11-23 13:22:24 -08:00
Berthold Stoeger
1b77255807 Dive list: correctly translate trip date
Adapt get_trip_date_string() to use the same logic as get_dive_date_string():
Use the static "loc" object to translate date. Before, the trip
date was shown in C locale.

Reported-by: Philippe Massart <philippe@philmassart.net>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-11-16 16:55:55 -08:00
Berthold Stoeger
b02fd072e7 Cleanup: remove dead code in qthelper.cpp
The reverseGeoLookup() function defined in qthelper.cpp has long
ago moved to its own compilation unit. It is not even defined in
the headers anymore. Remove it and the now unnecessary <QNetwork*>
includes.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-26 17:50:52 +01: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
jan Iversen
82b626b3fd core: remove QSettings from qthelper
uiLanguage overloaded qPrefLanguage and used useSystemLanguage instead
of use_system_language

Replace local load using QSettings with qPrefLanguage

Signed-off-by: Jan Iversen <jani@apache.org>
2018-08-25 11:49:47 -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
2c6b1a99af Cleanup: simplify dive_getUniqID()
dive_getUniqID() is used to create unique dive ids, which are
stable during application lifetime. It was passed a dive, checked
that the id was not set (if it was that it is know to the application)
and set a new id (in contradiction to its name!) if it hadn't any.

There were three callers:

alloc_dive(): called the function on a zeroed dive struct.
fixup_dive(): called the function only if the dive had a 0 id.
MainWindow::setupForAddAndPlan(): called the function on a zeroed dive
struct.

Thus, in all three callers the id is guaranteed to be zero and
the whole keeping-track-of-ids logic is moot. Remove the logic,
don't pass a dive struct to dive_getUniqID() and move the function
to the C-backend.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-07-17 15:20:52 -07:00
Stefan Fuchs
bb2dfdfe54 For media file open dialog add different file filters
On top of the file filter for all media files add a file filter
for images only, one for videos only and one for all files.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-07-15 09:38:12 -07:00
Jocke
59465b85f6 Don't show decimals on pressures
As per discussion in #1460 there is no point in showing decimal values
for pressures in the equipment tab on desktop or in the dive edit view on 
mobile.

Signed-off-by: Joakim Bygdell <j.bygdell@gmail.com>
2018-07-12 17:15:05 +03:00
Berthold Stoeger
a8bfa5f053 Dive media: add ".mov" to list of known video extensions
This was an oversight in b28dba6087.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-07-12 02:18:09 +03:00