When autosync to cloud was enabled, the old code would crash,
because it synced to cloud from a signal handler, which executed
the main loop when checking the cloud connection, which deleted
the object which was causing the original signal. Or something
like that. See discussion in #4119.
To avoid such problems, send a signal via a 'QueuedConnection'
from QMLManager to itself. The slot will be called once the
signal handler terminates and the main event loop retakes
control.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When changes need saving, the notification text was set quite
deep in the calltree in "saveChangesLocal()". I don't know why
this was put so deep in the call tree. In any case, it prevents
asynchronous saving of the data. Therefore, pull it up to
chnagesNeedSaving().
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In January it would just show the year for every day. That's
silly. Show the year only for Jan 1st.
Moreover, it would never show the month, because day-of-month
is counted from 1 (whereas month-of-year is counted from 0).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The signals of the undo-stack can only be connected after it
was initialized. One of those cases where I would have preferred
a crash over a warning message. The mobile version is extremely
noisy!
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This fixes a crash condition when opening the cloud from
desktop: The old code passed a NULL pointer that was then
assigned to an std::string, which is not supported.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Remove the options to expand entities and so continue when encountering invalid /
malformed XML, as both of these can be exploited by supplying
maliciously crafted XML.
Signed-off-by: Michael Keller <mikeller@042.ch>
Q_FOREACH and foreach are anachronisms.
Range based for may cause a performance regression: it can
lead to a copy of shared containers (one reason why Qt's
COW containers are broken). However, as long as there is no
user noticeable delay, there is no point in analyzing each case.
And also no point in slapping an 'asConst' on every container
that is looped over.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of accessing a global variable, pass the filename
from the MainWindow to the dialog. This is supposed to cut
down on the global variable mess.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
To avoid memory management woes. These shouldn't be global
variables, but let's fix that later.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of accessing a global variable, pass the filename
from the MainWindow to the dialog. This is supposed to cut
down on the global variable mess.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of accessing a global variable, pass the filename
from the MainWindow to the dialog. This is supposed to cut
down on the global variable mess.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There is no subclass of ConfigureDiveComputerDialog, so there
seems no reason for protected members.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The memory managements for DeviceDetails was very sketchy.
First of all, sharing a pointer to a structure between threads
seems like a recipe for disaster. Secondly, the structure was
a QObject and when first generated included in the (silly)
Qt object tree, but when generated in the threads it was not.
Clearly, this leaks.
Instead, use value semantics and use local copies of the
structure. I didn't go full length and use std::move to
move the data, because this doesn't work through signals
(which are the wrong abstraction here, but OK) and secondly
I didn't have time to analyze whether the caller still
needs the data after passing it down to the worker thread.
To be able to pass an object through signals, the class
has to be registered in the Qt MetaType system. Super
ugly, but fine for now. Ultimately, this whole thing should
probably be replaced by futures, co-routines, or whatever.
Moreover, this removes the prefix from number of "m_*"
function parameters. By convention, "m_" marks member
variables, which function parameters are not.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
make DeviceDetails a metatype
So that we can pass it as value through the signal/slot system.
(squash with original commit)
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Add a build for subsurface-downloader to the CI pipeline. The artifact
is currently not used, but this will ensure pull requests breaking the
downloader are spotted before they are merged.
Signed-off-by: Michael Keller <mikeller@042.ch>
Downloder builds pull in show_computer_list() from
downloadfromdcthread.cpp, but it's declared as extern "C". With 76c2069f
having converted subsurfacestartup.c to .cpp, we can remove the extern
"C"
Signed-off-by: Richard Fuchs <dfx@dfx.at>
Add 'Country' to the fields that are indexed for fulltext search - this
seems to be a quite intuitive choice as 'Country' is also a field that
is available in the dive list view.
Fixes#4134.
Signed-off-by: Michael Keller <mikeller@042.ch>
Opportunistically fix some problems newly raised by a recent Coverity
scan.
Not touching any of the string memory allocation issues as this is being
handled by the move towards C++ strings.
Signed-off-by: Michael Keller <mikeller@042.ch>
This give compile time checking. In fact, one of the connections was
not working (currentIndexChanged(QString) doesn't exist in newer(?)
Qt versions).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
printf() is a horrible interface as it does no type checking.
Let's at least use the compiler to check format strings and
arguments. This obviously doesn't work for translated strings
and using report_error on translated strings is dubious. But OK.
Had to convert a number of report_error() calls to supress
warnings.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
qthelper.h is an absolute monstrosity and it is unclear what
report_info and SSRF_INFO have to do with Qt.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This mimics the code added in commit cf990b0f39 ("preferences: choose language
code with one '-'") and adds some debugging for the mobile case - some people
are being presented with Subsurface-mobile in Korean for some reason.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
When initializing a string with multiple characters, first
comes the length, then the size. Not the other way around.
Fixes#4127.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Fix bug introduced in 505e4e47eb.
Nobody complained, so not clear if that was user visible.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
On initialization, the old code searched for the first language
code containing a '-'. However, my Qt version gives de-Latn-DE
as the first entry. That messed up the preferences code: it
didn't recognize that entry. Thus, simply opening and closing
the preferences switched the language to Bulgarian.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There was a pattern of code like
match_action(line, state, dive_action, ARRAY_SIZE(dive_action));
The doubling of the array might cause copy & paste errors, where
only one array is replaced.
Therefore, determine the length of the array with (hopefully
easily understood) template tricksery.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When iterating over the converted strings of a line, the
first entry of the array would be popped off, leading to
a full copy of the remaining array.
Instead, use an index in the parser state.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The converted strings were stored in a membuffer and later
converted to std::strings. Generate an std::string directly
to avoid unnecessary copying.
Ultimately, when the core structures are converted to
std::string, there should be no copying of the string data
at all (unless formatting is applied or small string
optimization kicks in, of course).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Create a format_string_std function that works like format_string,
but does return a std::string instead of a strdup()ed C string.
Make it a global function to be used in other parts of the code.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This avoid memory-management troubles. Had to convert a few
of the parsers (cochran, datatrak, liquivision) to C++.
Also had to convert libdivecomputer.c. This was less
painful than expected.
std::string is used because parts of the code assumes
that the data is null terminated after the last character
of the data. std::string does precisely that.
One disadvantage is that std::string clears its memory
when resizing / initializing. Thus we read the file onto
freshly cleared data, which some might thing is a
performance regression. Until someone shows me that this
matters, I don't care.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>