aboutsummaryrefslogtreecommitdiffstats
path: root/core/qthelper.cpp
AgeCommit message (Collapse)Author
2018-08-25core: remove QSettings from qthelperGravatar jan Iversen
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-23Cleanup: pass gasmix by valueGravatar Berthold Stoeger
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-07-17Cleanup: simplify dive_getUniqID()Gravatar Berthold Stoeger
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-15For media file open dialog add different file filtersGravatar Stefan Fuchs
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-12Don't show decimals on pressuresGravatar Jocke
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-12Dive media: add ".mov" to list of known video extensionsGravatar Berthold Stoeger
This was an oversight in b28dba6087f0433af8ece176b64fcac54ca370a4. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-07-08Dive pictures: Recognize video filesGravatar Berthold Stoeger
When generating thumbnails, test for video files. If it is, use a dummy-thumbnail. Write only the type (video), but no image to the thumbnail cache, for forward-compatibility. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-07-04Translations: unify gettextFromC::tr() and QObject::tr()Gravatar Berthold Stoeger
There were two catch-all classes for translations outside of class context. gettextFromC was used exclusively from C, but C++ used both, gettextFromC and QObject. Some of the string were even present in both. Therefore, unify to gettextFromC throughout the code base. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-07-04Dive pictures: implement FindMovedImagesDialogGravatar Berthold Stoeger
Move the find-moved-images functions into a new translation unit and present the user with the identified matches before applying them. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-07-04Dive pictures: remove hashesGravatar Berthold Stoeger
In the last commits, the canonical-to-local filename map was made independent from the image hashes and the location of moved images was based on filename not hashes. The hashes are now in principle unused (except for conversion of old-style local filename lookups). Therefore, remove the hashes in this commit. This makes addition of images distinctly faster. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-07-04Dive pictures: find moved pictures based on filenameGravatar Berthold Stoeger
Users might have edited their pictures. Therefore, instead of identifying pictures by the hash of the file-content, use the file path. The match between original and new filename is graded by a score. Currently, this is the number of path components that match, starting from the filename. Camparison is case-insensitive. After having identified the matching images, write the caches so that they are saved even if the user doesn't cleanly quit the application. Since the new code uses significantly less resources, it can be run in a single background thread. Thus, the multi-threading can be simplified. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-07-04Dive pictures: index local file name by canonical filnameGravatar Berthold Stoeger
The connection canonical filename to local filename was done via two maps: 1) canonical filename -> hash 2) hash -> local filename But the local filename was always queried from the canonical filename. Therefore, directly index the former with the latter. On startup, convert the old map to the new one. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-06-24Localization: don't go via C-string in qthelper.cppGravatar Berthold Stoeger
The purpose of the gettextFromC class is twofold: 1) It provides a static storage of C strings if the C part needs a translation and doesn't want to deal with memory-management. 2) It severs as a catch-all class for translations that do not come from a proper class (i.e. from helper functions). The second case was used a few times in qthelper.cpp. By using the trGettext() function, a cached C-string was obtained. But in every single instance, this C-string was then back-converted into a QString. Therefore, use the gettextFromC::tr() function directly, which returns a QString. Not only is the resulting code simpler - this also avoids superfluous caching of translation strings. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-06-07Dive pictures: remove cache_picture() call in dive_add_picture()Gravatar Berthold Stoeger
When adding a picture to a dive, cache_picture() was called, which calculated the hash of the picture in a background-thread. This made tests occasionally fail, because the tests depended on the filename-to-localfilename being overwritten in a call running in a different thread. Depending on which thread finished first, the test succeeded or failed. The easiest way to circumvent this problem is to remove the cache_picture() call. The hash will be calculated anyway with the thumbnails. And the only function of the hash is the "find moved images" function. Which is not an issue here, because the user just loaded the images from disk. Reported-by: Jan Iversen <jani@apache.org> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-06-05core: remove "static void copyPath" unusedGravatar jan Iversen
Remove copyPath since it is static and not called to avoid clang warning Signed-off-by: Jan Iversen <jani@apache.org>
2018-06-04Cleanup: fold core/helpers.h into core/qthelper.hGravatar Berthold Stoeger
helpers.h included qthelper.h and all functions declared in helpers.h were defined in qthelper.h. Therefore fold the former into the latter, since the split seems completely arbitrary. While doing so, change the return-type of get_dc_nichname from "const QString" to "QString". Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-06-04Cleanup: make copyPath() function of static linkageGravatar Berthold Stoeger
The function was only used in core/qthelper.cpp Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-05-26Dive pictures: Derive thumbnail file from picture filenameGravatar Berthold Stoeger
Since commit 6618c9ebfc6a7cebbef687fcb3aa74c70f504ff2, thumbnails are saved in individual files. The filename was simply the picture-hash. In a mailing-list discussion it turned out that in the future we might not hash images or change the hash. Therefore, derive the thumbnail filename from the image filename, using the SHA1 algorithm. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-05-24Cleanup: remove code related to picture-storage in git repositoriesGravatar Berthold Stoeger
Saving of pictures to git repositories was disabled. Finally remove this code and the corresponding load code. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-05-14Core: introduce new subsurface-string headerGravatar Dirk Hohndel
First small step to shrinking dive.h. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-05-13Dive pictures: Introduce thumbnailer classGravatar Berthold Stoeger
Create a new class, which performs all thumbnailing code. This is mostly code reshuffling. Thumbnails are extracted either from a cache or thumbnail calculation is started in a worker thread. Since getHashedImage() is called from a worker thread it makes no sense to call subfunctions in yet another worker thread. Remove these calls. In contrast to the previous code, on error the background thread produces a failure image, but it is not yet shown. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-05-13Dive pictures: replace picture struct by QStringGravatar Berthold Stoeger
In imagedownloader.cpp the only thing we need from the picture struct is the filename. Therefore, use QStrings instead of the picture struct. This simplifies memory management. Remove the clone_picture() function, which is not needed anymore. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-05-13Dive pictures: Convert thumbnailHash to individual filesGravatar Berthold Stoeger
On startup, convert an old-style thumbnailHash to individual thumbnail files. Show a modal progress bar while doing so. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-05-13Dive pictures: save thumbnails to individual filesGravatar Berthold Stoeger
The old code loaded all thumbnails into memory at once. This does not scale to logs with thousands of pictures. Therefore, save the pictures to individual files and only load the currently needed pictures. Currently, this will make changing switching between dives slower, because the thumbnails are loaded from disk. In the future, it is planned to do this in a background thread without blocking the user interface. A notable difference to the old code: Thumbnails are now indexed by the image-hash (i.e. the content of the raw image) and not by the filename of the image. Thus, different paths to the same image should only be saved once. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-04-11Cleanup: unconstify results of two functionsGravatar Berthold Stoeger
get_dive_date_c_string() and get_current_date() return copied strings. Make this explicit by returning non-const pointers. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-04-09Cleanup: Move *_loc formatting functions into new format.cpp fileGravatar Berthold Stoeger
qthelper.cpp is already quite voluminous. Move the recently introduced localized versions of (v)snprintf() and put_format() into their own translation unit. Moreover, adopt C-style semantics for asprintf_loc(). This function will be used to remove fixed-size buffers in core/plannernotes.c. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-04-09Change taglist_get_tagstring to support 'unlimited' tag list sizeGravatar Jeremie Guichard
Previous taglist_get_tagstring signature/implementation did not allow handling of cases where inputted buffer could not contain all tags. New implementation allocates buffer based on pre-computed size allowing to insert all tags in the returned string. Added get_taglist_string in qthelper to handle conversion to QString Added TestTagList with tests for taglist_get_tagstring Signed-off-by: Jeremie Guichard <djebrest@gmail.com>
2018-04-01Dive pictures: Move metadata functions into own translation unitGravatar Berthold Stoeger
Move all metadata function into new core/metadata.cpp file. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-22Use older API to remove dependency on Qt 5.8 or newerGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-03-19Dive pictures: If EXIF data couldn't be parsed, use creation dateGravatar Berthold Stoeger
This is a preparation for supporting videos. Some video formats may not possess such meta data, or we may not yet be able to parse them. In such a case, use the file creation date. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-03-19Dive pictures: Don't read whole file for parsing EXIF dataGravatar Berthold Stoeger
This is a preparation for video support. We don't want to read a whole potentially multi-GB file into memory just to detect that it isn't a JPEG. Especially since at the moment EXIF metadata are parsed twice, once for GPS, once for timestamp. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-03-14Cleanup: introduce copy_qstring() functionGravatar Berthold Stoeger
strdup(qPrintable(s)) and copy_string(qPrintable(s)) were such common occurrences that they seem worthy of a short helper-function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-14Cleanup: consistently use qPrintable()Gravatar Berthold Stoeger
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-05Cleanup: Remove hash field from picture-structureGravatar Berthold Stoeger
The hash field in the picture-structure was in principle non-operational. It was set on loading, but never actually changed. The authoritative hash comes from the filename->hash map. Therefore, make this explicit by removing the hash field from the picture structure. Instead of filling the picture structure on loading, add the hash directly to the filename->hash map. This is done in the register_hash() function, which does not overwrite old entries. I.e. the local hash has priority over the save-file. This policy might be refined in the future. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-05Cleanup: pass QString and QByteArray const-refs to qthelper functionsGravatar Berthold Stoeger
Passing of QStrings and QByteArrays was inconsistent in qthelper.cpp. Unify to passing const-references. Passing by value is no big deal, since QString and QByteArray do copy-on-write "optimization". Nevertheless, let's keep it as consistent and effective as possible. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-05Cleanup: Fold add_hash() call into learnHash() functionGravatar Berthold Stoeger
learnHash() was always called in conjunction with add_hash(). The pattern was that a local filename and a hash were connected in the hash-to-filename and the filename-to-hash maps. Then, the original picture-filename or url were registered in the filename-to-hash map. This commit changes learnHash() to take three parameters (original-filename, local-filename and hash) and do all of the above. The new code is simpler because no dummy picture struct has to be generated in DiveListView::loadImageFromURL(). The tests were extended to check for all hash<->filename associations. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-05Cleanup: Don't store hash in picture struct in learnHash()Gravatar Berthold Stoeger
learnHash() is called either on a local picture structure [DiveListView::loadImageFromURL()] or on a cloned picture structure [ImageDownloader::saveImage()]. In neither case the picture structure is passed to the frontend. Therefore, storing the new hash in the picture struct is not necessary. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-05Cleanup: Don't call learnHash() in hashPicture()Gravatar Berthold Stoeger
hashPicture() calls hashFile(), which calls add_hash(). add_hash() updates the filename-to-hash and hash-to-filename maps. Therefore, there is no point in calling learnHash() in hashPicture(), which updates the filename-to-hash map. Note that learnHash() updates the picture-struct with the new hash, but since hashPicture() works on a cloned picture-struct, which is free()d in hashPicture(), these changes are lost anyway. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-05Cleanup: remove updateHash() functionGravatar Berthold Stoeger
updateHash() and hashPicture() did the same thing, with the exception that hashPicture() marked the dive list as changed if a hash changed. This seems like a good idea in any case, therefore always use hashPicture(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-05Cleanup: Make helper function haveHash() of static linkageGravatar Berthold Stoeger
The function is only used in the qthelper.cpp translation unit. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-05Use correct numeric format based on selected locale (Qt domain part)Gravatar Stefan Fuchs
This changes the numeric format of many values printed to the UI to reflect the correct numeric format of the selected locale: - dot or comma as decimal separator - comma or dot as thousands separator In the Qt domain the `L` flag is used case specific mostly in qthelper.cpp. Then the helper functions get_xxx_string() are used more consistently. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-03-05Localization: Make Qt's locale-aware formatting accessible from CGravatar Berthold Stoeger
This commit introduces functions: - QString asprintf_loc(const char *cformat, ...); - int snprintf_loc(char *dst, size_t size, const char *cformat, ...); - put_format_loc(struct membuffer *, const char *fmt, ...); and their va_arg equivalents, which use Qt's QString::arg() formatting options to render the strings. The snprintf_loc() function takes care not to truncate multi-byte UTF-8 encodings. Thus, on overflow, the resulting string might be shorter than size-1. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-02-17Coding-style: remove superfluous parenthesesGravatar Berthold Stoeger
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-17Cleanup: return copied string from hashstring()Gravatar Berthold Stoeger
The following statement in the hashstring() function: return hashOf[QString(filename)].toHex().data(); returns data of the temporary QByteArray generated by toHex(). Thus, the caller will access released memory, which could lead to data corruption. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-02-04Do not remove seconds from duration input fieldGravatar Oliver Schwaneberg
This change deals with issue #554. If you enter a dive duration manually, the cell renderer cuts the seconds away when the changes are saved. I added the helper "render_seconds_to_string" as a counterpart to "parseDurationToSeconds". The helper keeps the seconds, if not null. The rendering of the cell is done at two places in the code, so I think it is cleaner to add a dedicated method for it. Signed-off-by: Oliver Schwaneberg <oliver.schwaneberg@gmail.com>
2018-01-11Use helper function empty_string() instead of manual checksGravatar Berthold Stoeger
For code consistency, substitute boolean expressions: s && *s -> !empty_string(s) s && s[0] -> !empty_string(s) !s || !*s -> empty_string(s) !s || !s[0] -> empty_string(s) Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-11Introduce helper function empty_string()Gravatar Berthold Stoeger
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>
2017-12-18Allow to read factor cache concurrentlyGravatar Robert C. Helling
In a session with the profile I saw that the planner spends a lot of time waiting to obtain the lock for the factor cache. Most of the time we are only reading that cache and that is save to do in parallel (according to the Qt IRC channel). So we can use a QReadWriteLock instead of a QMutex. This appears to be quite a performance boost, in particular for VPM-B Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-12-18Elevate "can't write hashes" message from debug to warning levelGravatar Berthold Stoeger
I never realized that my hashes weren't written, because it only outputs a debug instead of a warning message. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-14Remove function isCloudUrl()Gravatar Berthold Stoeger
The function isCloudUrl() was only called in one place, parse_file(). But, isCloudUrl() could only return true if the filename was of the git-repository kind (url[branch]). In such a case, control flow would never reach the point where isCloudUrl() is called, since is_git_repository() returns non-NULL and the function returns early. Therefore, remove this function. Moreover, adapt the affected if-statement by replacing "str && !strcmp(str, ...)" with the more concise "same_string(str, ...)". Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>