aboutsummaryrefslogtreecommitdiffstats
path: root/desktop-widgets/mainwindow.cpp
AgeCommit message (Collapse)Author
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-01-31Make report_error() reentrantGravatar Berthold Stoeger
Remove the global error buffer and pass the error string directly to the frontend. The frontend is then responsible for accumulating errors. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-31Remove unnecessary check for MainWindow instanceGravatar Berthold Stoeger
The error-callback is installed in the MainWindow constructor. Therefore, in the error-callback the existence of the MainWindow instance is guaranteed. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-31Use queued connection to thread-safe MainWindow error handlingGravatar Berthold Stoeger
Up to now, errors produced by threads were not directly shown in the MainWindow. Code running in the GUI thread had to manually show the errors. This can be simplified by using Qt's queued connection as message passing facility. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-13Resize progress bar width to fit all textGravatar Robert C. Helling
At least on Mac with larger font sizes part of the label text of the git access progress bar is cut off (even though it should automatically resize). This patch adds explicit resize. Fixes #1041 Signed-off-by: Robert C. Helling <helling@atdotde.de>
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>
2018-01-08Remove redundant setting of prefs.git_local_onlyGravatar Berthold Stoeger
In MainWindow::on_actionCloudOnline_triggered(), prefs.git_local_only was set twice in the case of going online. Remove the second, unnecessary, assignment. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-08Move resetting of current file out of clear_dive_file_data()Gravatar Berthold Stoeger
This is the only case where C-code sets the current file. Remove this call for a better separation of C-backend and C++-frontend parts. There were four callers of clear_dive_file_data(). Two of them would call set_filename() anyway. For the remaining two add an explicit call to set_filename(). This commit fixes a bug introduced in commit b3901aa8f90499ee2a34efdddc2463105afc53f1: The cloud-online menu entry was still enabled after "closing" the cloud storage. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-06Enable cloud-online menu entry only if connected to cloudGravatar Berthold Stoeger
Enable the menu item cloud-online only if the current file is the cloud storage. Since this has to be checked every time the current file is set, factor this out into the new MainWindow::setCurrentFile() function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-06Turn take-cloud-online menu action into checkboxGravatar Berthold Stoeger
Replace the "Take cloud storage online" menu entry by a "Cloud online" checkbox. After this change, the user can also force going offline. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-06Sync cloud storage on take-cloud-onlineGravatar Berthold Stoeger
When taking the cloud online, actually sync with the online cloud storage. If there are no unsaved changes, do the same as "Open cloud storage". If there are unsaved changes, ask the user if they want to commit them (do the same as "Save to cloud storage") or if they want to sync manually. If syncing failed, inform the user. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-06GPS: use applyGpsLocation::applyLocations from coreGravatar Jan Mulder
Fixes a big duplication of code. The code to apply GPS locations from the location service was already in core, and used from mobile, but there was an almost literal copy in the desktop code. See also commits 6f42ab46da1b59 and ee9531f76ec31a, where only one side of the duplicated code was fixed. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-04Replace BEHAVIOR macro by initializer listsGravatar Berthold Stoeger
The macro BEHAVIOR expanded to "QList<int>()". This was used to generate temporary QList<int>s with constructs such as BEHAVIOR << COLLAPSED << EXPANDED Instead, simply use initializer lists such as {COLLAPSED, EXPANDED} Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-04Replace macro TOGGLE_COLLAPSABLE by function toggleCollapsible()Gravatar Berthold Stoeger
There was no reason to do this in a macro. Let the compiler decide if it wants to inline or not. Note that for consistency with the Qt functions, collapsAble was replaced by collabsIble. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-04Use set_autogroup() functionGravatar Berthold Stoeger
Since this function exists, use it instead of setting the global variable directly. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-02Desktop: follow autogroup setting in UIGravatar Jan Mulder
When importing a dive (using import from logfile) and it is a ssrf/xml file that contains the autogroup setting, the autogroup is effectuated in the dive list. Not sure that I like this behavior, but thats the way it currently is. Simply wrong is that in this case the menu item toggle is not adapted so we end up with a dive list that is autogrouped, but the menu toggle is off. This can be solved by setting the UI toggle in a more central location. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-29Desktop: Don't hide errors on opening cloud storageGravatar Berthold Stoeger
In MainWindow::on_actionCloudstorageopen_triggered(), getNotificationWidget()->hideNotification() was called, thus hiding any error message produced by the cloud code. Notably, the information "Cannot sync with cloud server, working with offline copy" was not shown. Therefore, remove this call. Note that on cloud save messages were not hidden. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-11Simplify mainwindow title logic: remove MainWindowTitleFormat enumGravatar Berthold Stoeger
The MainWindow::setTitle() function was passed an enum, which depended on whether existing_file is set or not. The check can be (and was!) done directly in setTitle(). Therefore, remove the whole enum. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-12Remove unused variable in on_actionCloudstorageopen_triggered()Gravatar Berthold Stoeger
This was an artifact of commit 136110784ebe2a188ca867bea3a7ff3037281a57 Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-11Remove second parameter (bool force) in set_filename()Gravatar Berthold Stoeger
The last force=false case was removed in commit 96d1cc570e31396039e4970d2bf75d5f00f1e550. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-04Use QDir::exists() instead of QDir::setCurrent() to check for existenceGravatar Berthold Stoeger
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-01On failed cloud save hide progress barGravatar Berthold Stoeger
The progressbar was not hidden on failed save to cloud. In return remove an unnecessary variable on loading from cloud. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-01Actually compute variations in backgroundGravatar Robert C. Helling
This reenables the computation of plan variations but now in a separate thread. Once finieshed, a signal is sent to update the notes. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-11-30Use icons relative path.Gravatar Martin Měřinský
Icon paths are defined in one place only - application's embedded resources. Signed-off-by: Martin Měřinský <mermar@centrum.cz>
2017-12-01Fix views in mainwindowGravatar Stefan Fuchs
Divelist only view was broken. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-12-01Don't use action tooltip to access recently used fileGravatar Berthold Stoeger
Currently, the path to the recently used file is stored in the tooltip of the corresponding recent file action. Instead, store the number of the recent file in the action. This allows for more flexibility concerning formating of the tooltips (think git repositories, etc.). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-01Dynamically generate recent files actionsGravatar Berthold Stoeger
Instead of using four recent files actions defined in mainwindow.ui, generate these actions dynamically depending on the macro NUM_RECENT_FILES. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-30Remove "#if !defined(SUBSURFACE_MOBILE)" in mainwindow.cppGravatar Berthold Stoeger
The file mainwindow.cpp is only compiled for desktop versions, so the condition is redundant. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-30Move creation of QSession object into MainWindow::checkSurvey()Gravatar Berthold Stoeger
Instead of handing the QSession object down, simply create it in MainWindow::checkSurvey() Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-30implify recent file handling in mainwindow.cppGravatar Berthold Stoeger
The old code used to be unnecessarily complex: the recent files list was extended for each file and shrunk if a load failed. By adding a file to the recent file list only if the load succeeded, a whole method could be removed. Other changes: keep track of the recent files using a QStringList and clearly separate the actions: - Read recent files from settings [loadRecentFiles()] - Write recent files to settings [updateRecentFiles()] - Update the recent files actions in the menu [updateRecentFilesMenu()] - Add a file to the list of recent files [addRecentFile()] With this reorganization the code hopefully became more clear. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-29Revert "Use icons relative path."Gravatar Dirk Hohndel
This reverts commit b0d98f6e269be9560de1b9c140855c85fecf1dd1.
2017-11-29Use icons relative path.Gravatar Martin Měřinský
Icon paths are defined in one place only - application's embedded resources. Signed-off-by: Martin Měřinský <mermar@centrum.cz>
2017-11-27When replanning logged dive call CylindersModel->updateDiveGravatar Stefan Fuchs
reset_cylinder may transform unused cylinders into zombie cylinders inside the planner because it adds a depth info and therefore the planner will use them. By calling CylindersModel->updateDive these cylinders will become visible and can be deleted by the user. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-11-26Simplify signal handling after dive site editingGravatar Berthold Stoeger
Since commit 01d961086c1d175732c597dc9acdba7cc4cd2d26, MainWindow::refreshDisplay() is called in the refreshDiveInfo() signal of maintab after editing a dive site. Since this was the only use of the refreshDiveInfo signal, remove this signal and instead connect to MainWindow::refreshDisplay directly. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-25Merge branch 'print' of https://github.com/neolit123/subsurfaceGravatar Dirk Hohndel
2017-11-25Update filters on refreshDisplay and remember old selecttionsGravatar Berthold Stoeger
Update the filters if the list of dives is updated by calling MultiFilterSortModel::instance()->myInvalidate(); This had the side effect of clearing all selections. Thus, in the repopulate() methods of the FilterModels, check those entries that were checked previously. Since all the filter models use the same code, introduce a base class FilterModelBase. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-24printing: update the coping of bundled templatesGravatar Lubomir I. Ivanov
This update includes: - Instead of copyPath() use a new specialized function: copy_bundled_templates() - The new function supports overwriting of templates in the user path, but only if a template file is read-only - If the file is RW create a backup of the file in the form of: <file-name>-User.html - Collect backup files and store them in a QStringList which is then shown in a QMessageBox from MainWindow to notifying the user about the backup This change allows moving the maintenance of the bundled templates back to the application developers and contributors as currently the only one who can edit the templates in the user path was the user. Suggested-by: Dirk Hohndel <dirk@hohndel.org> Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-11-24printing: add set_bundled_templates_as_read_only()Gravatar Lubomir I. Ivanov
Add the function set_bundled_templates_as_read_only() in templatelayout.cpp/h. The function is used to mark the bundled template files as read-only in the user folder. It is called in mainwindow.cpp, after the files are copied from the bundle. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-11-21Desktop UI: allow user defined cylinder as defaultGravatar Jan Mulder
Currently, it was only possible to use a hard-coded default cylinder in the preferences. At the same time, the user is allowed to add own cylinders to a dive (by just typing in a new name and cylinder properties). These own cylinders could not be selected in the preferences, requiring the user to manually add this every dive. Not sure the reason for all this was intentional, or just an overlooked aspect in the implementation. It appeared that the selection list in the UI was constructed before any logbook was parsed, so at that moment, there are only hard-coded cylinders. The fix is simple. Refresh the UI of the preferences just before it is shown. While opening the logbook, a new list of cylinders, including the own cylinders is constructed, so the UI is refreshed to that. While a simple change, there is a use case that might be considered strange. Open a logbook, choose new logbook, and change the default cylinder preference to an own (from the previously opened logbook). Do not add a dive with the new (own) cylinder and save this logbook. Reopen this new logbook, and see that the default cylinder in the preferences is empty. This is logical, as the list of own possible cylinders is constructed from the (new) logbook, that has no dive with that specific own cylinder. I consider this acceptable behavior, as it can be also be used to copy own cylinders to a new logbook. Fixes: #821 Proposed-by: Davide DB <dbdavide@gmail.com> Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-11-04Correct, cleanup, translate and unify file filtersGravatar Stefan Fuchs
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-04Planner copy salinity only if current dive existsGravatar Stefan Fuchs
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-31Postpone error message display if not in GUI threadGravatar Berthold Stoeger
Calls to report_error() crashed if not called from GUI thread. Fix this by postponing error message display if not in GUI thread. Code that creates a thread which possibly calls report_error() is responsible for calling MainWindow::showErrors() to flush the accumulated messages. Note that there is a race condition in report_error() and get_error_string(). Nevertheless, hitting it should be rather unlikely (two threads producing error messages at the same time) and hopefully it can be fixed rather easily. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-10-30New dive plan set salinity to current dive salinity if dive selectedGravatar Stefan Fuchs
This helps people who always use a std. salinity of e.g. 1020g/l. If they have a log with their dives open and plan a new dive they will have also for new planned dives the salinity set to their prefered value. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-28mainwindow.cpp: fix whitespaceGravatar Lubomir I. Ivanov
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-10-28Set checked status of menu entry for dive list filter correctlyGravatar Stefan Fuchs
When enabling the dive list filter via the menu entry "Log->Filter dives" and then switch off the filter via the small "close" button of the filter: Set the checked status of the menu entry correctly. Also set it correctly when switching on/off via the menu entry to avoid any situation where it is not synced. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-26desktop UI: no longer attempt to manually show error notificationsGravatar Dirk Hohndel
report_error() now does this automatically. So all these odd places in which we tried to make sure that we show errors are no longer needed. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-26desktop UI: always show errors when reportedGravatar Dirk Hohndel
Instead of waiting for a manual call to showError(), simply use the new callback to always immediately show the error in the notification widget. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-22mainwindow: disable fullscreen support by defaultGravatar Lubomir I. Ivanov
Require the FULLSCREEN_SUPPORT macro to enable fullscreen support. The toggle was added 4 years ago in Subsurface, but with the current version of Qt 5.9.x, it's very buggy on Windows and Ubuntu. While it's possible to make this work on Windows, it seems to behave broken in different ways on different versiosn of Ubuntu. Fixes #705 Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>