2017-04-27 18:26:05 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2013-04-14 03:44:02 +00:00
|
|
|
/*
|
|
|
|
* mainwindow.cpp
|
|
|
|
*
|
|
|
|
* classes for the main UI window in Subsurface
|
|
|
|
*/
|
2013-04-07 22:20:43 +00:00
|
|
|
#include "mainwindow.h"
|
|
|
|
|
2013-04-13 13:17:59 +00:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QMessageBox>
|
2022-02-10 01:00:48 +00:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
2013-10-04 15:28:40 +00:00
|
|
|
#include <QDesktopWidget>
|
2022-02-10 01:00:48 +00:00
|
|
|
#endif
|
2014-02-13 21:48:07 +00:00
|
|
|
#include <QSettings>
|
2014-04-25 04:37:47 +00:00
|
|
|
#include <QShortcut>
|
2017-10-02 13:25:44 +00:00
|
|
|
#include <QStatusBar>
|
2018-09-13 15:12:36 +00:00
|
|
|
#include <QNetworkProxy>
|
|
|
|
#include <QUndoStack>
|
2015-10-09 23:15:26 +00:00
|
|
|
|
2018-09-13 15:12:36 +00:00
|
|
|
#include "core/color.h"
|
2019-06-22 19:12:09 +00:00
|
|
|
#include "core/device.h"
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
#include "core/divelog.h"
|
2018-09-13 15:12:36 +00:00
|
|
|
#include "core/divesitehelpers.h"
|
2019-08-05 17:41:15 +00:00
|
|
|
#include "core/errorhelper.h"
|
2019-03-03 21:29:40 +00:00
|
|
|
#include "core/file.h"
|
2018-06-17 21:28:44 +00:00
|
|
|
#include "core/gettextfromc.h"
|
2018-09-13 15:12:36 +00:00
|
|
|
#include "core/git-access.h"
|
2018-09-28 10:09:18 +00:00
|
|
|
#include "core/import-csv.h"
|
2018-09-13 15:12:36 +00:00
|
|
|
#include "core/planner.h"
|
|
|
|
#include "core/qthelper.h"
|
2022-04-04 16:57:28 +00:00
|
|
|
#include "core/selection.h"
|
2018-05-11 15:25:41 +00:00
|
|
|
#include "core/subsurface-string.h"
|
2019-05-31 14:09:14 +00:00
|
|
|
#include "core/trip.h"
|
2018-09-13 15:12:36 +00:00
|
|
|
#include "core/version.h"
|
|
|
|
#include "core/windowtitleupdate.h"
|
|
|
|
|
|
|
|
#include "core/settings/qPrefCloudStorage.h"
|
|
|
|
#include "core/settings/qPrefDisplay.h"
|
|
|
|
|
|
|
|
#include "desktop-widgets/about.h"
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "desktop-widgets/divelistview.h"
|
2018-09-13 15:12:36 +00:00
|
|
|
#include "desktop-widgets/divelogexportdialog.h"
|
|
|
|
#include "desktop-widgets/divelogimportdialog.h"
|
|
|
|
#include "desktop-widgets/diveplanner.h"
|
2022-09-18 11:49:29 +00:00
|
|
|
#include "desktop-widgets/divesiteimportdialog.h"
|
|
|
|
#include "desktop-widgets/divesitelistview.h"
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "desktop-widgets/downloadfromdivecomputer.h"
|
2018-09-13 15:12:36 +00:00
|
|
|
#include "desktop-widgets/findmovedimagesdialog.h"
|
|
|
|
#include "desktop-widgets/locationinformation.h"
|
|
|
|
#include "desktop-widgets/mapwidget.h"
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "desktop-widgets/subsurfacewebservices.h"
|
2018-09-13 15:12:36 +00:00
|
|
|
#include "desktop-widgets/tab-widgets/maintab.h"
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "desktop-widgets/updatemanager.h"
|
2018-10-21 16:00:02 +00:00
|
|
|
#include "desktop-widgets/simplewidgets.h"
|
2020-10-28 11:23:41 +00:00
|
|
|
#include "desktop-widgets/statswidget.h"
|
2019-11-13 14:08:40 +00:00
|
|
|
#include "commands/command.h"
|
2018-09-13 15:12:36 +00:00
|
|
|
|
2021-04-12 21:34:28 +00:00
|
|
|
#include "profilewidget.h"
|
2015-09-03 18:56:37 +00:00
|
|
|
#include "profile-widget/profilewidget2.h"
|
2018-09-13 15:12:36 +00:00
|
|
|
|
2014-03-26 22:36:06 +00:00
|
|
|
#ifndef NO_PRINTING
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "desktop-widgets/printdialog.h"
|
2020-12-13 12:32:40 +00:00
|
|
|
#include "desktop-widgets/templatelayout.h"
|
2014-03-26 22:36:06 +00:00
|
|
|
#endif
|
2018-09-13 15:12:36 +00:00
|
|
|
|
|
|
|
#include "qt-models/cylindermodel.h"
|
|
|
|
#include "qt-models/divepicturemodel.h"
|
|
|
|
#include "qt-models/diveplannermodel.h"
|
2019-12-09 14:22:02 +00:00
|
|
|
#include "qt-models/filtermodels.h"
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "qt-models/tankinfomodel.h"
|
2018-05-10 15:35:30 +00:00
|
|
|
#include "qt-models/weightsysteminfomodel.h"
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "qt-models/yearlystatisticsmodel.h"
|
2015-09-17 20:16:40 +00:00
|
|
|
#include "preferences/preferencesdialog.h"
|
2015-07-25 15:30:20 +00:00
|
|
|
|
2014-03-26 22:35:24 +00:00
|
|
|
#ifndef NO_USERMANUAL
|
|
|
|
#include "usermanual.h"
|
|
|
|
#endif
|
2013-04-13 13:17:59 +00:00
|
|
|
|
2018-09-13 15:55:47 +00:00
|
|
|
namespace {
|
|
|
|
QProgressDialog *progressDialog = nullptr;
|
|
|
|
bool progressDialogCanceled = false;
|
|
|
|
int progressCounter = 0;
|
|
|
|
}
|
2015-09-09 20:02:39 +00:00
|
|
|
|
2017-06-18 06:22:37 +00:00
|
|
|
extern "C" int updateProgress(const char *text)
|
2015-09-09 20:02:39 +00:00
|
|
|
{
|
2016-04-03 23:13:22 +00:00
|
|
|
if (verbose)
|
2024-03-26 19:23:50 +00:00
|
|
|
report_info("git storage: %s", text);
|
2017-06-18 06:22:37 +00:00
|
|
|
if (progressDialog) {
|
2018-06-16 03:54:12 +00:00
|
|
|
// apparently we don't always get enough space to show the full label
|
|
|
|
// so let's manually make enough space (but don't shrink the existing size)
|
2020-01-02 01:14:15 +00:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
|
2018-06-16 03:54:12 +00:00
|
|
|
int width = QFontMetrics(qApp->font()).width(text) + 100;
|
2020-01-02 01:14:15 +00:00
|
|
|
#else // QT 5.11 or newer
|
|
|
|
int width = QFontMetrics(qApp->font()).horizontalAdvance(text) + 100;
|
|
|
|
#endif
|
2018-06-16 03:54:12 +00:00
|
|
|
if (width > progressDialog->width())
|
|
|
|
progressDialog->resize(width + 20, progressDialog->height());
|
2017-06-18 06:22:37 +00:00
|
|
|
progressDialog->setLabelText(text);
|
2017-06-18 08:46:49 +00:00
|
|
|
progressDialog->setValue(++progressCounter);
|
|
|
|
if (progressCounter == 100)
|
|
|
|
progressCounter = 0; // yes this is silly, but we really don't know how long it will take
|
2017-06-18 06:22:37 +00:00
|
|
|
}
|
2016-04-06 06:01:16 +00:00
|
|
|
qApp->processEvents();
|
2015-09-09 20:02:39 +00:00
|
|
|
return progressDialogCanceled;
|
|
|
|
}
|
|
|
|
|
2019-09-27 23:26:54 +00:00
|
|
|
MainWindow *MainWindow::m_Instance = nullptr;
|
|
|
|
|
2018-01-26 09:40:04 +00:00
|
|
|
extern "C" void showErrorFromC(char *buf)
|
2017-10-26 13:50:19 +00:00
|
|
|
{
|
2018-01-26 09:40:04 +00:00
|
|
|
QString error(buf);
|
|
|
|
free(buf);
|
|
|
|
emit MainWindow::instance()->showError(error);
|
2017-10-31 20:28:59 +00:00
|
|
|
}
|
2017-10-26 13:50:19 +00:00
|
|
|
|
2022-03-13 17:45:50 +00:00
|
|
|
MainWindow::MainWindow() :
|
2021-02-14 19:59:02 +00:00
|
|
|
appState((ApplicationState)-1), // Invalid state
|
2018-09-15 15:25:10 +00:00
|
|
|
actionNextDive(nullptr),
|
|
|
|
actionPreviousDive(nullptr),
|
2018-05-31 14:36:34 +00:00
|
|
|
#ifndef NO_USERMANUAL
|
2014-02-09 19:04:21 +00:00
|
|
|
helpView(0),
|
2018-05-31 14:36:34 +00:00
|
|
|
#endif
|
2018-09-15 15:25:10 +00:00
|
|
|
findMovedImagesDialog(nullptr)
|
2013-04-07 22:20:43 +00:00
|
|
|
{
|
2019-09-27 23:26:54 +00:00
|
|
|
Q_ASSERT_X(m_Instance == NULL, "MainWindow", "MainWindow recreated!");
|
|
|
|
m_Instance = this;
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.setupUi(this);
|
2015-02-26 13:39:42 +00:00
|
|
|
read_hashes();
|
2019-03-30 17:39:27 +00:00
|
|
|
Command::init();
|
2015-02-09 18:23:30 +00:00
|
|
|
// Define the States of the Application Here, Currently the states are situations where the different
|
|
|
|
// widgets will change on the mainwindow.
|
|
|
|
|
2020-12-18 11:01:36 +00:00
|
|
|
topSplitter.reset(new QSplitter(Qt::Horizontal));
|
|
|
|
bottomSplitter.reset(new QSplitter(Qt::Horizontal));
|
desktop: remove the view-state
There was the "application state", which decided what to show
in the "quadrants" and the "view state" which decided which
quadrant to show. These interacted in a hard-to-grasp way.
The "view state" is used to show the map or dive list in
full screen.
I simply couldn't get these two orthogonal states to interact
properly. Moreover the thing was buggy: If a quadrant was hidden,
the user could still show it, by dragging from the side of the
window, at least under KDE.
To solve these woes, merge the two states into a single
application state. If the widget of a quadrant is set to null,
don't show it. So the four "view states" are now "application
states" where three of the four quadrants are not shown.
This also changes the memory management of the widgets:
widgets that are not shown are now removed from the QSplitter
objects. This makes it possible that the same widget is
shown in *different* quadrants.
While writing this, I stumbled upon a Qt bug, which is known
since 2014:
https://forum.qt.io/topic/43176/qsplitter-sizes-return-0
When restoring the quadrant sizes there was a test whether
the quadrant size is 0. If that was the case, a default size
was set. This seems not to work if the widgets were recently
added. Since this test now always fails, make the quadrants
non-collapsible and thus guarantee that 0 is never saved as
a size.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-17 21:27:40 +00:00
|
|
|
|
2015-02-09 18:23:30 +00:00
|
|
|
// for the "default" mode
|
2019-04-13 08:54:06 +00:00
|
|
|
mainTab.reset(new MainTab);
|
2020-12-18 11:01:36 +00:00
|
|
|
diveList.reset(new DiveListView);
|
2022-04-09 00:24:15 +00:00
|
|
|
#ifdef MAP_SUPPORT
|
2020-12-18 11:01:36 +00:00
|
|
|
mapWidget.reset(MapWidget::instance()); // Yes, this is ominous see comment in mapwidget.cpp.
|
2022-02-09 23:56:36 +00:00
|
|
|
#endif
|
2020-11-25 06:31:19 +00:00
|
|
|
plannerWidgets.reset(new PlannerWidgets);
|
2020-12-18 11:01:36 +00:00
|
|
|
statistics.reset(new StatsWidget);
|
2022-09-18 11:49:29 +00:00
|
|
|
diveSites.reset(new DiveSiteListView);
|
2021-04-12 21:34:28 +00:00
|
|
|
profile.reset(new ProfileWidget);
|
2015-07-25 15:30:20 +00:00
|
|
|
|
desktop: remove the view-state
There was the "application state", which decided what to show
in the "quadrants" and the "view state" which decided which
quadrant to show. These interacted in a hard-to-grasp way.
The "view state" is used to show the map or dive list in
full screen.
I simply couldn't get these two orthogonal states to interact
properly. Moreover the thing was buggy: If a quadrant was hidden,
the user could still show it, by dragging from the side of the
window, at least under KDE.
To solve these woes, merge the two states into a single
application state. If the widget of a quadrant is set to null,
don't show it. So the four "view states" are now "application
states" where three of the four quadrants are not shown.
This also changes the memory management of the widgets:
widgets that are not shown are now removed from the QSplitter
objects. This makes it possible that the same widget is
shown in *different* quadrants.
While writing this, I stumbled upon a Qt bug, which is known
since 2014:
https://forum.qt.io/topic/43176/qsplitter-sizes-return-0
When restoring the quadrant sizes there was a test whether
the quadrant size is 0. If that was the case, a default size
was set. This seems not to work if the widgets were recently
added. Since this test now always fails, make the quadrants
non-collapsible and thus guarantee that 0 is never saved as
a size.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-17 21:27:40 +00:00
|
|
|
diveSiteEdit.reset(new LocationInformationWidget);
|
2015-08-29 23:00:22 +00:00
|
|
|
|
2021-04-12 21:34:28 +00:00
|
|
|
registerApplicationState(ApplicationState::Default, { true, { mainTab.get(), FLAG_NONE }, { profile.get(), FLAG_NONE },
|
2020-12-18 11:01:36 +00:00
|
|
|
{ diveList.get(), FLAG_NONE }, { mapWidget.get(), FLAG_NONE } });
|
2021-04-12 21:34:28 +00:00
|
|
|
registerApplicationState(ApplicationState::PlanDive, { false, { &plannerWidgets->plannerWidget, FLAG_NONE }, { profile.get(), FLAG_NONE },
|
2020-12-17 22:13:06 +00:00
|
|
|
{ &plannerWidgets->plannerSettingsWidget, FLAG_NONE }, { &plannerWidgets->plannerDetails, FLAG_NONE } });
|
2021-04-12 21:34:28 +00:00
|
|
|
registerApplicationState(ApplicationState::EditDiveSite, { false, { diveSiteEdit.get(), FLAG_NONE }, { profile.get(), FLAG_DISABLED },
|
2020-12-18 11:01:36 +00:00
|
|
|
{ diveList.get(), FLAG_DISABLED }, { mapWidget.get(), FLAG_NONE } });
|
2021-04-12 21:34:28 +00:00
|
|
|
registerApplicationState(ApplicationState::FilterDive, { true, { mainTab.get(), FLAG_NONE }, { profile.get(), FLAG_NONE },
|
2020-12-18 11:01:36 +00:00
|
|
|
{ diveList.get(), FLAG_NONE }, { &filterWidget, FLAG_NONE } });
|
|
|
|
registerApplicationState(ApplicationState::Statistics, { true, { statistics.get(), FLAG_NONE }, { nullptr, FLAG_NONE },
|
|
|
|
{ diveList.get(), FLAG_DISABLED }, { &filterWidget, FLAG_NONE } });
|
2022-09-18 11:49:29 +00:00
|
|
|
registerApplicationState(ApplicationState::DiveSites, { false, { diveSites.get(), FLAG_NONE }, { profile.get(), FLAG_NONE },
|
|
|
|
{ diveList.get(), FLAG_NONE }, { mapWidget.get(), FLAG_NONE } });
|
2020-12-17 22:13:06 +00:00
|
|
|
registerApplicationState(ApplicationState::MapMaximized, { true, { nullptr, FLAG_NONE }, { nullptr, FLAG_NONE },
|
2020-12-18 11:01:36 +00:00
|
|
|
{ nullptr, FLAG_NONE }, { mapWidget.get(), FLAG_NONE } });
|
2021-04-12 21:34:28 +00:00
|
|
|
registerApplicationState(ApplicationState::ProfileMaximized, { true, { nullptr, FLAG_NONE }, { profile.get(), FLAG_NONE },
|
2020-12-17 22:13:06 +00:00
|
|
|
{ nullptr, FLAG_NONE }, { nullptr, FLAG_NONE } });
|
2020-12-18 11:01:36 +00:00
|
|
|
registerApplicationState(ApplicationState::ListMaximized, { true, { nullptr, FLAG_NONE }, { nullptr, FLAG_NONE },
|
|
|
|
{ diveList.get(), FLAG_NONE }, { nullptr, FLAG_NONE } });
|
2020-12-17 22:13:06 +00:00
|
|
|
registerApplicationState(ApplicationState::InfoMaximized, { true, { mainTab.get(), FLAG_NONE }, { nullptr, FLAG_NONE },
|
|
|
|
{ nullptr, FLAG_NONE }, { nullptr, FLAG_NONE } });
|
desktop: remove the view-state
There was the "application state", which decided what to show
in the "quadrants" and the "view state" which decided which
quadrant to show. These interacted in a hard-to-grasp way.
The "view state" is used to show the map or dive list in
full screen.
I simply couldn't get these two orthogonal states to interact
properly. Moreover the thing was buggy: If a quadrant was hidden,
the user could still show it, by dragging from the side of the
window, at least under KDE.
To solve these woes, merge the two states into a single
application state. If the widget of a quadrant is set to null,
don't show it. So the four "view states" are now "application
states" where three of the four quadrants are not shown.
This also changes the memory management of the widgets:
widgets that are not shown are now removed from the QSplitter
objects. This makes it possible that the same widget is
shown in *different* quadrants.
While writing this, I stumbled upon a Qt bug, which is known
since 2014:
https://forum.qt.io/topic/43176/qsplitter-sizes-return-0
When restoring the quadrant sizes there was a test whether
the quadrant size is 0. If that was the case, a default size
was set. This seems not to work if the widgets were recently
added. Since this test now always fails, make the quadrants
non-collapsible and thus guarantee that 0 is never saved as
a size.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-17 21:27:40 +00:00
|
|
|
restoreSplitterSizes();
|
2019-05-10 17:51:43 +00:00
|
|
|
setApplicationState(ApplicationState::Default);
|
2015-02-17 02:33:25 +00:00
|
|
|
|
2013-04-25 23:44:06 +00:00
|
|
|
setWindowIcon(QIcon(":subsurface-icon"));
|
2014-06-28 08:14:36 +00:00
|
|
|
if (!QIcon::hasThemeIcon("window-close")) {
|
|
|
|
QIcon::setThemeName("subsurface");
|
|
|
|
}
|
2022-09-03 20:45:08 +00:00
|
|
|
connect(diveList.get(), &DiveListView::divesSelected, this, &MainWindow::divesSelected);
|
2020-11-24 11:50:52 +00:00
|
|
|
connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &MainWindow::readSettings);
|
2017-11-30 16:44:32 +00:00
|
|
|
for (int i = 0; i < NUM_RECENT_FILES; i++) {
|
|
|
|
actionsRecent[i] = new QAction(this);
|
2017-11-30 16:56:16 +00:00
|
|
|
actionsRecent[i]->setData(i);
|
2017-11-30 16:44:32 +00:00
|
|
|
ui.menuFile->insertAction(ui.actionQuit, actionsRecent[i]);
|
|
|
|
connect(actionsRecent[i], SIGNAL(triggered(bool)), this, SLOT(recentFileTriggered(bool)));
|
|
|
|
}
|
|
|
|
ui.menuFile->insertSeparator(ui.actionQuit);
|
2014-07-16 22:23:02 +00:00
|
|
|
connect(DivePlannerPointsModel::instance(), SIGNAL(planCreated()), this, SLOT(planCreated()));
|
|
|
|
connect(DivePlannerPointsModel::instance(), SIGNAL(planCanceled()), this, SLOT(planCanceled()));
|
2018-01-28 21:08:30 +00:00
|
|
|
connect(this, &MainWindow::showError, ui.mainErrorMessage, &NotificationWidget::showError, Qt::AutoConnection);
|
2017-07-14 22:31:16 +00:00
|
|
|
|
2018-07-30 18:59:07 +00:00
|
|
|
connect(&windowTitleUpdate, &WindowTitleUpdate::updateTitle, this, &MainWindow::setAutomaticTitle);
|
2019-11-17 16:41:23 +00:00
|
|
|
connect(&diveListNotifier, &DiveListNotifier::numShownChanged, this, &MainWindow::setAutomaticTitle);
|
2020-02-18 01:16:11 +00:00
|
|
|
// monitor when dives changed - but only in verbose mode
|
|
|
|
// careful - changing verbose at runtime isn't enough (of course that could be added if we want it)
|
|
|
|
if (verbose)
|
|
|
|
connect(&diveListNotifier, &DiveListNotifier::divesChanged, this, &MainWindow::divesChanged);
|
|
|
|
|
2014-06-26 15:04:39 +00:00
|
|
|
#ifdef NO_PRINTING
|
2015-02-09 17:44:53 +00:00
|
|
|
ui.menuFile->removeAction(ui.actionPrint);
|
2014-06-26 15:04:39 +00:00
|
|
|
#endif
|
2015-06-14 22:42:28 +00:00
|
|
|
enableDisableCloudActions();
|
2014-06-26 15:04:39 +00:00
|
|
|
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.mainErrorMessage->hide();
|
2021-04-09 20:28:54 +00:00
|
|
|
setEnabledToolbar(false);
|
2013-06-04 12:40:09 +00:00
|
|
|
initialUiSetup();
|
2013-05-22 01:29:23 +00:00
|
|
|
readSettings();
|
2018-10-12 14:13:42 +00:00
|
|
|
diveList->setFocus();
|
|
|
|
diveList->expand(diveList->model()->index(0, 0));
|
|
|
|
diveList->scrollTo(diveList->model()->index(0, 0), QAbstractItemView::PositionAtCenter);
|
2014-03-26 22:35:24 +00:00
|
|
|
#ifdef NO_USERMANUAL
|
|
|
|
ui.menuHelp->removeAction(ui.actionUserManual);
|
2014-03-26 22:36:06 +00:00
|
|
|
#endif
|
2014-08-16 15:32:23 +00:00
|
|
|
memset(©PasteDive, 0, sizeof(copyPasteDive));
|
|
|
|
memset(&what, 0, sizeof(what));
|
2014-08-23 01:26:07 +00:00
|
|
|
|
2015-01-02 04:49:24 +00:00
|
|
|
updateManager = new UpdateManager(this);
|
2018-07-30 09:15:08 +00:00
|
|
|
undoAction = Command::undoAction(this);
|
|
|
|
redoAction = Command::redoAction(this);
|
2022-02-08 19:24:53 +00:00
|
|
|
undoAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Z));
|
|
|
|
redoAction->setShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_Z));
|
2018-07-30 09:15:08 +00:00
|
|
|
ui.menu_Edit->addActions({ undoAction, redoAction });
|
2015-05-10 15:44:35 +00:00
|
|
|
|
2015-07-24 07:26:25 +00:00
|
|
|
#ifndef NO_PRINTING
|
2017-11-24 20:54:54 +00:00
|
|
|
// copy the bundled print templates to the user path
|
|
|
|
QStringList templateBackupList;
|
|
|
|
QString templatePathUser(getPrintingTemplatePathUser());
|
|
|
|
copy_bundled_templates(getPrintingTemplatePathBundle(), templatePathUser, &templateBackupList);
|
|
|
|
if (templateBackupList.length()) {
|
|
|
|
QMessageBox msgBox(this);
|
|
|
|
templatePathUser.replace("\\", "/");
|
|
|
|
templateBackupList.replaceInStrings(templatePathUser + "/", "");
|
|
|
|
msgBox.setWindowTitle(tr("Template backup created"));
|
|
|
|
msgBox.setText(tr("The following backup printing templates were created:\n\n%1\n\n"
|
|
|
|
"Location:\n%2\n\n"
|
|
|
|
"Please note that as of this version of Subsurface the default templates\n"
|
|
|
|
"are read-only and should not be edited directly, since the application\n"
|
|
|
|
"can overwrite them on startup.").arg(templateBackupList.join("\n")).arg(templatePathUser));
|
|
|
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
|
|
|
msgBox.exec();
|
|
|
|
}
|
2017-11-22 23:59:26 +00:00
|
|
|
set_bundled_templates_as_read_only();
|
2015-07-24 07:26:25 +00:00
|
|
|
find_all_templates();
|
|
|
|
#endif
|
2015-08-25 08:56:07 +00:00
|
|
|
|
2015-11-09 20:05:30 +00:00
|
|
|
setupSocialNetworkMenu();
|
2015-09-09 20:02:39 +00:00
|
|
|
set_git_update_cb(&updateProgress);
|
2017-10-26 13:50:19 +00:00
|
|
|
set_error_cb(&showErrorFromC);
|
2016-01-25 17:54:23 +00:00
|
|
|
|
2017-10-21 20:25:42 +00:00
|
|
|
// full screen support is buggy on Windows and Ubuntu.
|
|
|
|
// require the FULLSCREEN_SUPPORT macro to enable it!
|
|
|
|
#ifndef FULLSCREEN_SUPPORT
|
|
|
|
ui.actionFullScreen->setEnabled(false);
|
|
|
|
ui.actionFullScreen->setVisible(false);
|
|
|
|
setWindowState(windowState() & ~Qt::WindowFullScreen);
|
|
|
|
#endif
|
2013-05-14 11:18:26 +00:00
|
|
|
}
|
|
|
|
|
2021-01-27 21:06:41 +00:00
|
|
|
static void clearSplitter(QSplitter &splitter)
|
|
|
|
{
|
|
|
|
// Qt's ownership model is absolutely hare-brained.
|
|
|
|
// To remove a widget from a splitter, you reparent it, which
|
|
|
|
// informs the splitter via a signal. Wow.
|
|
|
|
while (splitter.count() > 0)
|
|
|
|
splitter.widget(0)->setParent(nullptr);
|
|
|
|
}
|
|
|
|
|
2014-02-12 14:22:54 +00:00
|
|
|
MainWindow::~MainWindow()
|
|
|
|
{
|
2020-12-18 11:01:36 +00:00
|
|
|
// Remove widgets from the splitters so that they don't delete singletons.
|
2021-01-27 21:06:41 +00:00
|
|
|
clearSplitter(*topSplitter);
|
|
|
|
clearSplitter(*bottomSplitter);
|
|
|
|
clearSplitter(*ui.mainSplitter);
|
2015-02-26 13:39:42 +00:00
|
|
|
write_hashes();
|
2019-09-27 23:26:54 +00:00
|
|
|
m_Instance = nullptr;
|
2014-02-12 14:22:54 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 20:05:30 +00:00
|
|
|
void MainWindow::setupSocialNetworkMenu()
|
|
|
|
{
|
2015-11-08 23:50:12 +00:00
|
|
|
}
|
|
|
|
|
2019-03-16 10:35:44 +00:00
|
|
|
void MainWindow::editDiveSite(dive_site *ds)
|
2018-10-13 06:57:46 +00:00
|
|
|
{
|
2019-03-16 10:35:44 +00:00
|
|
|
if (!ds)
|
|
|
|
return;
|
|
|
|
diveSiteEdit->initFields(ds);
|
2022-09-18 13:25:41 +00:00
|
|
|
state_stack.push_back(appState);
|
2019-05-10 17:51:43 +00:00
|
|
|
setApplicationState(ApplicationState::EditDiveSite);
|
2015-07-25 15:30:20 +00:00
|
|
|
}
|
|
|
|
|
2019-03-16 10:51:42 +00:00
|
|
|
void MainWindow::startDiveSiteEdit()
|
2019-03-16 10:35:44 +00:00
|
|
|
{
|
2019-03-20 20:46:58 +00:00
|
|
|
if (current_dive)
|
|
|
|
editDiveSite(get_dive_site_for_dive(current_dive));
|
2019-03-16 10:35:44 +00:00
|
|
|
}
|
|
|
|
|
2015-06-14 22:42:28 +00:00
|
|
|
void MainWindow::enableDisableCloudActions()
|
|
|
|
{
|
2018-09-02 14:22:16 +00:00
|
|
|
ui.actionCloudstorageopen->setEnabled(prefs.cloud_verification_status == qPrefCloudStorage::CS_VERIFIED);
|
|
|
|
ui.actionCloudstoragesave->setEnabled(prefs.cloud_verification_status == qPrefCloudStorage::CS_VERIFIED);
|
2015-06-14 22:42:28 +00:00
|
|
|
}
|
|
|
|
|
2019-02-23 17:31:02 +00:00
|
|
|
void MainWindow::setDefaultState()
|
|
|
|
{
|
2019-05-10 17:51:43 +00:00
|
|
|
setApplicationState(ApplicationState::Default);
|
2015-02-11 15:58:23 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 23:26:54 +00:00
|
|
|
MainWindow *MainWindow::instance()
|
|
|
|
{
|
|
|
|
return m_Instance;
|
|
|
|
}
|
|
|
|
|
2017-11-25 15:15:57 +00:00
|
|
|
// This gets called after one or more dives were added, edited or downloaded for a dive computer
|
2020-05-05 08:37:02 +00:00
|
|
|
void MainWindow::refreshDisplay()
|
2013-05-30 08:58:59 +00:00
|
|
|
{
|
2019-05-10 17:51:43 +00:00
|
|
|
setApplicationState(ApplicationState::Default);
|
2018-10-12 14:13:42 +00:00
|
|
|
diveList->setEnabled(true);
|
|
|
|
diveList->setFocus();
|
2022-11-12 08:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::updateAutogroup()
|
|
|
|
{
|
|
|
|
ui.actionAutoGroup->setChecked(divelog.autogroup);
|
2013-05-30 08:58:59 +00:00
|
|
|
}
|
|
|
|
|
2022-09-03 20:45:08 +00:00
|
|
|
void MainWindow::divesSelected(const std::vector<dive *> &selection, dive *currentDive, int currentDC)
|
2013-05-14 11:18:26 +00:00
|
|
|
{
|
2022-09-17 17:07:35 +00:00
|
|
|
// We call plotDive first, so that the profile can decide which
|
|
|
|
// dive computer to plot. The plotted dive computer is then
|
|
|
|
// used for displaying data in the tab-widgets.
|
|
|
|
profile->plotDive(currentDive, currentDC);
|
|
|
|
mainTab->updateDiveInfo(selection, profile->d, profile->dc);
|
|
|
|
|
|
|
|
// Activate cursor keys to switch through DCs if there are more than one DC.
|
|
|
|
if (currentDive) {
|
|
|
|
bool nr = number_of_computers(current_dive) > 1;
|
|
|
|
enableShortcuts();
|
|
|
|
ui.actionNextDC->setEnabled(nr);
|
|
|
|
ui.actionPreviousDC->setEnabled(nr);
|
|
|
|
}
|
2014-01-15 20:13:20 +00:00
|
|
|
}
|
|
|
|
|
2013-04-09 08:35:44 +00:00
|
|
|
void MainWindow::on_actionNew_triggered()
|
|
|
|
{
|
2013-06-26 12:07:50 +00:00
|
|
|
on_actionClose_triggered();
|
2013-04-09 08:35:44 +00:00
|
|
|
}
|
2013-04-09 16:26:23 +00:00
|
|
|
|
2018-06-09 14:24:39 +00:00
|
|
|
static QString lastUsedDir()
|
|
|
|
{
|
|
|
|
QString lastDir = QDir::homePath();
|
|
|
|
|
2018-08-18 18:00:55 +00:00
|
|
|
if (QDir(qPrefDisplay::lastDir()).exists())
|
|
|
|
lastDir = qPrefDisplay::lastDir();
|
2018-06-09 14:24:39 +00:00
|
|
|
return lastDir;
|
|
|
|
}
|
|
|
|
|
2013-04-09 16:26:23 +00:00
|
|
|
void MainWindow::on_actionOpen_triggered()
|
|
|
|
{
|
2014-06-09 02:46:43 +00:00
|
|
|
if (!okToClose(tr("Please save or cancel the current dive edit before opening a new file.")))
|
2013-11-15 21:42:49 +00:00
|
|
|
return;
|
2014-06-09 02:46:43 +00:00
|
|
|
|
2014-11-21 17:46:24 +00:00
|
|
|
// yes, this look wrong to use getSaveFileName() for the open dialog, but we need to be able
|
|
|
|
// to enter file names that don't exist in order to use our git syntax /path/to/dir[branch]
|
|
|
|
// with is a potentially valid input, but of course won't exist. So getOpenFileName() wouldn't work
|
2017-10-27 12:52:27 +00:00
|
|
|
QFileDialog dialog(this, tr("Open file"), lastUsedDir(), filter_open());
|
2014-11-23 00:06:01 +00:00
|
|
|
dialog.setFileMode(QFileDialog::AnyFile);
|
|
|
|
dialog.setViewMode(QFileDialog::Detail);
|
|
|
|
dialog.setLabelText(QFileDialog::Accept, tr("Open"));
|
|
|
|
dialog.setLabelText(QFileDialog::Reject, tr("Cancel"));
|
2015-08-07 16:12:28 +00:00
|
|
|
dialog.setAcceptMode(QFileDialog::AcceptOpen);
|
2014-11-23 00:06:01 +00:00
|
|
|
QStringList filenames;
|
|
|
|
if (dialog.exec())
|
|
|
|
filenames = dialog.selectedFiles();
|
|
|
|
if (filenames.isEmpty())
|
2013-04-13 13:17:59 +00:00
|
|
|
return;
|
2014-11-23 00:06:01 +00:00
|
|
|
updateLastUsedDir(QFileInfo(filenames.first()).dir().path());
|
2014-06-09 02:46:43 +00:00
|
|
|
closeCurrentFile();
|
2015-06-21 23:28:38 +00:00
|
|
|
// some file dialogs decide to add the default extension to a filename without extension
|
|
|
|
// so we would get dir[branch].ssrf when trying to select dir[branch].
|
|
|
|
// let's detect that and remove the incorrect extension
|
2024-03-25 09:58:27 +00:00
|
|
|
std::vector<std::string> cleanFilenames;
|
2015-06-21 23:28:38 +00:00
|
|
|
QRegularExpression reg(".*\\[[^]]+]\\.ssrf", QRegularExpression::CaseInsensitiveOption);
|
|
|
|
|
2024-03-16 15:50:43 +00:00
|
|
|
for (QString filename: filenames) {
|
2015-06-21 23:28:38 +00:00
|
|
|
if (reg.match(filename).hasMatch())
|
|
|
|
filename.remove(QRegularExpression("\\.ssrf$", QRegularExpression::CaseInsensitiveOption));
|
2024-03-25 09:58:27 +00:00
|
|
|
cleanFilenames.push_back(filename.toStdString());
|
2015-06-21 23:28:38 +00:00
|
|
|
}
|
|
|
|
loadFiles(cleanFilenames);
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionSave_triggered()
|
|
|
|
{
|
2019-04-01 19:07:51 +00:00
|
|
|
mainTab->stealFocus(); // Make sure that any currently edited field is updated before saving.
|
2013-05-19 22:25:47 +00:00
|
|
|
file_save();
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionSaveAs_triggered()
|
|
|
|
{
|
2019-04-01 19:07:51 +00:00
|
|
|
mainTab->stealFocus(); // Make sure that any currently edited field is updated before saving.
|
2013-05-19 22:25:47 +00:00
|
|
|
file_save_as();
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
2013-09-23 05:24:28 +00:00
|
|
|
|
2024-03-25 09:58:27 +00:00
|
|
|
static std::string encodeFileName(const std::string &fn)
|
|
|
|
{
|
|
|
|
return QFile::encodeName(QString::fromStdString(fn)).toStdString();
|
|
|
|
}
|
|
|
|
|
2015-06-01 05:11:27 +00:00
|
|
|
void MainWindow::on_actionCloudstorageopen_triggered()
|
|
|
|
{
|
|
|
|
if (!okToClose(tr("Please save or cancel the current dive edit before opening a new file.")))
|
|
|
|
return;
|
|
|
|
|
2024-03-24 21:05:28 +00:00
|
|
|
auto filename = getCloudURL();
|
|
|
|
if (!filename)
|
2015-06-01 05:11:27 +00:00
|
|
|
return;
|
2017-10-26 13:55:49 +00:00
|
|
|
|
2017-04-22 19:29:46 +00:00
|
|
|
if (verbose)
|
2024-03-24 21:05:28 +00:00
|
|
|
report_info("Opening cloud storage from: %s", filename->c_str());
|
2015-06-01 05:11:27 +00:00
|
|
|
|
|
|
|
closeCurrentFile();
|
|
|
|
|
2015-09-09 20:02:39 +00:00
|
|
|
showProgressBar();
|
2024-03-25 09:58:27 +00:00
|
|
|
std::string encoded = encodeFileName(*filename);
|
|
|
|
if (!parse_file(encoded.c_str(), &divelog))
|
|
|
|
setCurrentFile(encoded);
|
2018-09-23 10:53:35 +00:00
|
|
|
process_loaded_dives();
|
2015-09-09 20:02:39 +00:00
|
|
|
hideProgressBar();
|
2015-06-01 05:11:27 +00:00
|
|
|
refreshDisplay();
|
2022-11-12 08:14:00 +00:00
|
|
|
updateAutogroup();
|
2015-06-01 05:11:27 +00:00
|
|
|
}
|
|
|
|
|
2018-05-14 18:17:08 +00:00
|
|
|
// Return whether saving to cloud is OK. If it isn't, show an error return false.
|
|
|
|
static bool saveToCloudOK()
|
|
|
|
{
|
2023-04-21 12:14:22 +00:00
|
|
|
if (!divelog.dives->nr) {
|
2024-03-12 08:17:50 +00:00
|
|
|
report_error("%s", qPrintable(gettextFromC::tr("Don't save an empty log to the cloud")));
|
2018-05-14 18:17:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-01 05:11:27 +00:00
|
|
|
void MainWindow::on_actionCloudstoragesave_triggered()
|
|
|
|
{
|
2018-05-14 18:17:08 +00:00
|
|
|
if (!saveToCloudOK())
|
2017-10-19 11:28:40 +00:00
|
|
|
return;
|
2024-03-24 21:05:28 +00:00
|
|
|
auto filename = getCloudURL();
|
|
|
|
if (!filename)
|
2015-06-01 05:11:27 +00:00
|
|
|
return;
|
2017-10-26 13:55:49 +00:00
|
|
|
|
2017-04-22 19:29:46 +00:00
|
|
|
if (verbose)
|
2024-03-24 21:05:28 +00:00
|
|
|
report_info("Saving cloud storage to: %s", filename->c_str());
|
2019-04-01 19:07:51 +00:00
|
|
|
mainTab->stealFocus(); // Make sure that any currently edited field is updated before saving.
|
2015-06-01 05:11:27 +00:00
|
|
|
|
2015-09-09 20:02:39 +00:00
|
|
|
showProgressBar();
|
2024-03-24 21:05:28 +00:00
|
|
|
int error = save_dives(filename->c_str());
|
2015-09-09 20:02:39 +00:00
|
|
|
hideProgressBar();
|
2017-12-01 17:20:43 +00:00
|
|
|
if (error)
|
|
|
|
return;
|
2015-08-25 19:49:48 +00:00
|
|
|
|
2024-03-24 21:05:28 +00:00
|
|
|
setCurrentFile(*filename);
|
2020-10-21 21:26:50 +00:00
|
|
|
Command::setClean();
|
2019-03-30 17:39:27 +00:00
|
|
|
}
|
|
|
|
|
2018-01-03 10:46:21 +00:00
|
|
|
void MainWindow::on_actionCloudOnline_triggered()
|
2016-07-30 20:09:31 +00:00
|
|
|
{
|
2018-01-03 10:46:21 +00:00
|
|
|
bool isOffline = !ui.actionCloudOnline->isChecked();
|
2018-09-10 13:30:01 +00:00
|
|
|
if (isOffline == git_local_only)
|
2018-01-03 10:46:21 +00:00
|
|
|
return;
|
|
|
|
|
2018-01-02 20:56:03 +00:00
|
|
|
// Refuse to go online if there is an edit in progress
|
2022-03-12 11:48:12 +00:00
|
|
|
if (!isOffline && inPlanner()) {
|
2018-01-02 20:56:03 +00:00
|
|
|
QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before going online"));
|
2018-01-03 10:46:21 +00:00
|
|
|
// We didn't switch to online, therefore uncheck the checkbox
|
|
|
|
ui.actionCloudOnline->setChecked(false);
|
2018-01-02 20:56:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-09-10 13:30:01 +00:00
|
|
|
git_local_only = isOffline;
|
2018-01-03 10:46:21 +00:00
|
|
|
if (!isOffline) {
|
|
|
|
// User requests to go online. Try to sync cloud storage
|
2020-10-21 21:20:46 +00:00
|
|
|
if (!Command::isClean()) {
|
2018-01-03 10:46:21 +00:00
|
|
|
// If there are unsaved changes, ask the user if they want to save them.
|
|
|
|
// If they don't, they have to sync manually.
|
|
|
|
if (QMessageBox::warning(this, tr("Save changes?"),
|
|
|
|
tr("You have unsaved changes. Do you want to commit them to the cloud storage?\n"
|
|
|
|
"If answering no, the cloud will only be synced on next call to "
|
|
|
|
"\"Open cloud storage\" or \"Save to cloud storage\"."),
|
|
|
|
QMessageBox::Yes|QMessageBox::No) == QMessageBox::Yes)
|
|
|
|
on_actionCloudstoragesave_triggered();
|
|
|
|
} else {
|
|
|
|
// If there are no unsaved changes, let's just try to load the remote cloud
|
|
|
|
on_actionCloudstorageopen_triggered();
|
|
|
|
}
|
2018-09-10 13:30:01 +00:00
|
|
|
if (git_local_only)
|
2024-03-12 08:17:50 +00:00
|
|
|
report_error("%s", qPrintable(tr("Failure taking cloud storage online")));
|
2018-01-02 20:56:03 +00:00
|
|
|
}
|
2018-01-03 10:46:21 +00:00
|
|
|
|
|
|
|
setTitle();
|
2018-01-03 16:11:52 +00:00
|
|
|
updateCloudOnlineStatus();
|
2016-07-30 20:09:31 +00:00
|
|
|
}
|
|
|
|
|
2014-06-09 02:46:43 +00:00
|
|
|
bool MainWindow::okToClose(QString message)
|
2013-04-09 16:26:23 +00:00
|
|
|
{
|
2022-03-12 11:48:12 +00:00
|
|
|
if (inPlanner()) {
|
2014-06-09 02:46:43 +00:00
|
|
|
QMessageBox::warning(this, tr("Warning"), message);
|
|
|
|
return false;
|
2013-11-15 21:42:49 +00:00
|
|
|
}
|
2020-10-21 21:20:46 +00:00
|
|
|
if (!Command::isClean() && askSaveChanges() == false)
|
2014-06-09 02:46:43 +00:00
|
|
|
return false;
|
2013-04-13 13:17:59 +00:00
|
|
|
|
2014-06-09 02:46:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::closeCurrentFile()
|
|
|
|
{
|
2013-04-13 13:17:59 +00:00
|
|
|
/* free the dives and trips */
|
2014-03-13 22:42:45 +00:00
|
|
|
clear_git_id();
|
cleanup: invert control-flow when resetting the core structures
To reset the core data structures, the mobile and desktop UIs
were calling into the dive-list models, which then reset the
core data structures, themselves and the unrelated
locationinformation model. The UI code then reset various other
things, such as the TankInformation model or the map. . This was
unsatisfying from a control-flow perspective, as the models should
display the core data, not act on it. Moreover, this meant lots
of intricate intermodule-dependencies.
Thus, straighten up the control flow: give the C core the
possibility to send a "all data reset" event. And do that
in those functions that reset the core data structures.
Let each module react to this event by itself. This removes
inter-module dependencies. For example, the MainWindow now
doesn't have to reset the TankInfoModel or the MapWidget.
Then, to reset the core data structures, let the UI code
simply directly call the respective core functions.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-04 22:12:36 +00:00
|
|
|
clear_dive_file_data(); // this clears all the core data structures and resets the models
|
2024-03-24 21:56:41 +00:00
|
|
|
setCurrentFile(std::string());
|
2019-11-15 18:38:27 +00:00
|
|
|
diveList->setSortOrder(DiveTripModelBase::NR, Qt::DescendingOrder);
|
2024-03-16 15:06:39 +00:00
|
|
|
if (existing_filename.empty())
|
2019-11-15 18:38:27 +00:00
|
|
|
setTitle();
|
|
|
|
disableShortcuts();
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
2018-01-03 16:11:52 +00:00
|
|
|
void MainWindow::updateCloudOnlineStatus()
|
|
|
|
{
|
2024-03-16 15:06:39 +00:00
|
|
|
bool is_cloud = !existing_filename.empty() && prefs.cloud_verification_status == qPrefCloudStorage::CS_VERIFIED &&
|
|
|
|
existing_filename.find(prefs.cloud_base_url) != std::string::npos;
|
2018-01-03 16:11:52 +00:00
|
|
|
ui.actionCloudOnline->setEnabled(is_cloud);
|
2018-09-10 13:30:01 +00:00
|
|
|
ui.actionCloudOnline->setChecked(is_cloud && !git_local_only);
|
2018-01-03 16:11:52 +00:00
|
|
|
}
|
|
|
|
|
2024-03-24 21:56:41 +00:00
|
|
|
void MainWindow::setCurrentFile(const std::string &f)
|
2018-01-03 16:11:52 +00:00
|
|
|
{
|
2024-03-16 15:06:39 +00:00
|
|
|
existing_filename = f;
|
2018-01-03 16:11:52 +00:00
|
|
|
setTitle();
|
|
|
|
updateCloudOnlineStatus();
|
|
|
|
}
|
|
|
|
|
2014-06-09 02:46:43 +00:00
|
|
|
void MainWindow::on_actionClose_triggered()
|
|
|
|
{
|
2014-12-10 03:16:39 +00:00
|
|
|
if (okToClose(tr("Please save or cancel the current dive edit before closing the file."))) {
|
2014-06-09 02:46:43 +00:00
|
|
|
closeCurrentFile();
|
2019-05-10 17:51:43 +00:00
|
|
|
setApplicationState(ApplicationState::Default);
|
2014-12-10 03:16:39 +00:00
|
|
|
}
|
2014-06-09 02:46:43 +00:00
|
|
|
}
|
|
|
|
|
2014-02-14 06:11:05 +00:00
|
|
|
void MainWindow::updateLastUsedDir(const QString &dir)
|
2013-11-14 15:42:26 +00:00
|
|
|
{
|
2018-08-18 18:00:55 +00:00
|
|
|
qPrefDisplay::set_lastDir(dir);
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
2024-03-16 15:06:39 +00:00
|
|
|
static QString get_current_filename()
|
|
|
|
{
|
|
|
|
return existing_filename.empty() ? QString(prefs.default_filename)
|
|
|
|
: QString::fromStdString(existing_filename);
|
|
|
|
}
|
2013-04-09 16:26:23 +00:00
|
|
|
void MainWindow::on_actionPrint_triggered()
|
|
|
|
{
|
2014-03-26 22:36:06 +00:00
|
|
|
#ifndef NO_PRINTING
|
2022-11-06 19:37:53 +00:00
|
|
|
// When in planner, only print the planned dive.
|
2022-11-05 19:27:49 +00:00
|
|
|
dive *singleDive = appState == ApplicationState::PlanDive ? plannerWidgets->getDive()
|
2022-11-06 19:37:53 +00:00
|
|
|
: nullptr;
|
2024-03-16 15:06:39 +00:00
|
|
|
QString filename = get_current_filename();
|
2024-03-16 12:39:15 +00:00
|
|
|
PrintDialog dlg(singleDive, filename, this);
|
2014-02-08 19:12:13 +00:00
|
|
|
|
|
|
|
dlg.exec();
|
2014-03-26 22:36:06 +00:00
|
|
|
#endif
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
2015-02-03 15:30:08 +00:00
|
|
|
void MainWindow::disableShortcuts(bool disablePaste)
|
2013-07-04 15:30:05 +00:00
|
|
|
{
|
2020-03-02 09:50:24 +00:00
|
|
|
undoAction->setEnabled(false);
|
|
|
|
redoAction->setEnabled(false);
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.actionPreviousDC->setShortcut(QKeySequence());
|
|
|
|
ui.actionNextDC->setShortcut(QKeySequence());
|
2015-02-03 15:30:08 +00:00
|
|
|
ui.copy->setShortcut(QKeySequence());
|
|
|
|
if (disablePaste)
|
|
|
|
ui.paste->setShortcut(QKeySequence());
|
2013-07-04 15:30:05 +00:00
|
|
|
}
|
|
|
|
|
2015-02-03 15:30:08 +00:00
|
|
|
void MainWindow::enableShortcuts()
|
2013-07-04 15:30:05 +00:00
|
|
|
{
|
2020-03-02 09:50:24 +00:00
|
|
|
undoAction->setEnabled(true);
|
|
|
|
redoAction->setEnabled(true);
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.actionPreviousDC->setShortcut(Qt::Key_Left);
|
|
|
|
ui.actionNextDC->setShortcut(Qt::Key_Right);
|
2022-02-08 19:24:53 +00:00
|
|
|
ui.copy->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_C));
|
|
|
|
ui.paste->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_V));
|
2013-07-04 15:30:05 +00:00
|
|
|
}
|
|
|
|
|
2013-06-27 17:48:03 +00:00
|
|
|
void MainWindow::showProfile()
|
|
|
|
{
|
2015-02-03 15:30:08 +00:00
|
|
|
enableShortcuts();
|
2023-09-10 17:24:57 +00:00
|
|
|
profile->plotDive(current_dive, profile->dc);
|
2019-05-10 17:51:43 +00:00
|
|
|
setApplicationState(ApplicationState::Default);
|
2013-06-20 21:48:21 +00:00
|
|
|
}
|
|
|
|
|
2013-04-09 16:26:23 +00:00
|
|
|
void MainWindow::on_actionPreferences_triggered()
|
|
|
|
{
|
Desktop UI: allow user defined cylinder as default
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-21 11:23:58 +00:00
|
|
|
// the refreshPages() is currently done for just one
|
|
|
|
// reason. Allow the user to define a default cylinder that
|
|
|
|
// is not hardcoded but coming from the logbook.
|
|
|
|
PreferencesDialog::instance()->refreshPages();
|
|
|
|
|
2013-05-24 18:19:48 +00:00
|
|
|
PreferencesDialog::instance()->show();
|
2015-10-06 22:02:38 +00:00
|
|
|
PreferencesDialog::instance()->raise();
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionQuit_triggered()
|
|
|
|
{
|
2020-05-03 14:04:34 +00:00
|
|
|
if (!okToClose(tr("Please save or cancel the current dive edit before quiting the application.")))
|
2013-04-27 09:09:57 +00:00
|
|
|
return;
|
2020-05-03 14:04:34 +00:00
|
|
|
|
2013-05-03 23:30:36 +00:00
|
|
|
writeSettings();
|
|
|
|
QApplication::quit();
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionDownloadDC_triggered()
|
|
|
|
{
|
2024-03-16 15:06:39 +00:00
|
|
|
QString filename = get_current_filename();
|
2024-03-16 09:02:54 +00:00
|
|
|
DownloadFromDCWidget dlg(filename, this);
|
2017-05-12 17:18:11 +00:00
|
|
|
dlg.exec();
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
2013-10-25 01:02:59 +00:00
|
|
|
void MainWindow::on_actionDivelogs_de_triggered()
|
|
|
|
{
|
2013-11-15 02:57:09 +00:00
|
|
|
DivelogsDeWebServices::instance()->downloadDives();
|
2013-10-25 01:02:59 +00:00
|
|
|
}
|
|
|
|
|
2022-03-12 11:48:12 +00:00
|
|
|
bool MainWindow::inPlanner()
|
|
|
|
{
|
|
|
|
return DivePlannerPointsModel::instance()->currentMode() == DivePlannerPointsModel::PLAN;
|
|
|
|
}
|
|
|
|
|
2014-05-25 18:19:36 +00:00
|
|
|
bool MainWindow::plannerStateClean()
|
2014-05-25 18:15:57 +00:00
|
|
|
{
|
2016-03-23 00:19:20 +00:00
|
|
|
if (progressDialog)
|
|
|
|
// we are accessing the cloud, so let's not switch into Add or Plan mode
|
|
|
|
return false;
|
|
|
|
|
2022-03-12 11:48:12 +00:00
|
|
|
if (inPlanner()) {
|
2014-05-25 18:19:36 +00:00
|
|
|
QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before trying to add a dive."));
|
|
|
|
return false;
|
2014-05-25 18:15:57 +00:00
|
|
|
}
|
2014-05-25 18:19:36 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-28 18:43:32 +00:00
|
|
|
void MainWindow::planCanceled()
|
|
|
|
{
|
2022-03-02 20:08:19 +00:00
|
|
|
showProfile();
|
2020-05-05 08:37:02 +00:00
|
|
|
refreshDisplay();
|
2014-05-28 18:43:32 +00:00
|
|
|
}
|
|
|
|
|
2014-05-28 18:54:04 +00:00
|
|
|
void MainWindow::planCreated()
|
|
|
|
{
|
2014-10-27 19:35:19 +00:00
|
|
|
// make sure our UI is in a consistent state
|
2014-05-28 18:54:04 +00:00
|
|
|
showProfile();
|
2019-05-10 17:51:43 +00:00
|
|
|
setApplicationState(ApplicationState::Default);
|
2018-10-12 14:13:42 +00:00
|
|
|
diveList->setEnabled(true);
|
|
|
|
diveList->setFocus();
|
2014-05-28 18:54:04 +00:00
|
|
|
}
|
|
|
|
|
2014-08-19 20:03:53 +00:00
|
|
|
void MainWindow::on_actionReplanDive_triggered()
|
|
|
|
{
|
2020-12-17 22:13:06 +00:00
|
|
|
if (!plannerStateClean() || !current_dive || !userMayChangeAppState())
|
2014-08-19 20:03:53 +00:00
|
|
|
return;
|
2019-01-01 17:02:04 +00:00
|
|
|
else if (!is_dc_planner(¤t_dive->dc)) {
|
2015-09-09 09:53:30 +00:00
|
|
|
if (QMessageBox::warning(this, tr("Warning"), tr("Trying to replan a dive that's not a planned dive."),
|
2015-06-04 03:44:00 +00:00
|
|
|
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Cancel)
|
2015-05-07 20:59:12 +00:00
|
|
|
return;
|
2014-08-19 20:03:53 +00:00
|
|
|
}
|
|
|
|
|
2020-11-25 06:31:19 +00:00
|
|
|
// put us in PLAN mode
|
2019-05-10 17:51:43 +00:00
|
|
|
setApplicationState(ApplicationState::PlanDive);
|
2020-11-25 06:31:19 +00:00
|
|
|
|
profile: remove [disable|enable]Shortcuts() signals
When switching to the "plan" or "add" (which should rather be
called "edit", by the way) mode of the profile, the "shortcuts"
for copy&paste, undo&redo, etc. are disabled. When switching
to "profile" mode, they are reenabled.
This was done in a most convoluted way:
- The MainWindow calls the set*State() function of the profile.
- The Profile emits [disable|enable]Shortcuts() signals.
- The MainWindow catches these signals and does the enabling
or disabling.
Not only is this very hard to reason about, it is also in
contradiction to the profile being part of the display layer.
Moreover, in editCurrentDive() the MainWindow disabled the
shortcuts itself, so this was all redundant.
For the sake of sanity, let's just move this logic to the
MainWindow, unslotify the [disable|enable]Shortcuts() functions
and make them private.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-04-09 19:51:42 +00:00
|
|
|
disableShortcuts(true);
|
2022-11-05 19:27:49 +00:00
|
|
|
plannerWidgets->prepareReplanDive(current_dive);
|
|
|
|
profile->setPlanState(plannerWidgets->getDive(), profile->dc);
|
2022-09-17 17:07:35 +00:00
|
|
|
plannerWidgets->replanDive(profile->dc);
|
2014-08-19 20:03:53 +00:00
|
|
|
}
|
|
|
|
|
2014-05-25 18:19:36 +00:00
|
|
|
void MainWindow::on_actionDivePlanner_triggered()
|
|
|
|
{
|
2020-12-17 22:13:06 +00:00
|
|
|
if (!plannerStateClean() || !userMayChangeAppState())
|
2014-05-25 18:19:36 +00:00
|
|
|
return;
|
|
|
|
|
2014-05-27 18:32:18 +00:00
|
|
|
// put us in PLAN mode
|
2019-05-10 17:51:43 +00:00
|
|
|
setApplicationState(ApplicationState::PlanDive);
|
2014-07-04 13:53:33 +00:00
|
|
|
|
profile: remove [disable|enable]Shortcuts() signals
When switching to the "plan" or "add" (which should rather be
called "edit", by the way) mode of the profile, the "shortcuts"
for copy&paste, undo&redo, etc. are disabled. When switching
to "profile" mode, they are reenabled.
This was done in a most convoluted way:
- The MainWindow calls the set*State() function of the profile.
- The Profile emits [disable|enable]Shortcuts() signals.
- The MainWindow catches these signals and does the enabling
or disabling.
Not only is this very hard to reason about, it is also in
contradiction to the profile being part of the display layer.
Moreover, in editCurrentDive() the MainWindow disabled the
shortcuts itself, so this was all redundant.
For the sake of sanity, let's just move this logic to the
MainWindow, unslotify the [disable|enable]Shortcuts() functions
and make them private.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-04-09 19:51:42 +00:00
|
|
|
disableShortcuts(true);
|
2022-11-05 19:27:49 +00:00
|
|
|
plannerWidgets->preparePlanDive(current_dive);
|
|
|
|
profile->setPlanState(plannerWidgets->getDive(), 0);
|
|
|
|
plannerWidgets->planDive();
|
2015-02-09 21:19:10 +00:00
|
|
|
}
|
|
|
|
|
2013-04-09 16:26:23 +00:00
|
|
|
void MainWindow::on_actionAddDive_triggered()
|
|
|
|
{
|
2014-09-17 22:39:49 +00:00
|
|
|
if (!plannerStateClean())
|
2013-11-09 00:09:46 +00:00
|
|
|
return;
|
2014-05-25 18:19:36 +00:00
|
|
|
|
2019-06-22 19:12:09 +00:00
|
|
|
// create a dive an hour from now with a default depth (15m/45ft) and duration (40 minutes)
|
|
|
|
// as a starting point for the user to edit
|
2019-06-22 23:55:27 +00:00
|
|
|
struct dive d = { 0 };
|
|
|
|
d.id = dive_getUniqID();
|
|
|
|
d.when = QDateTime::currentMSecsSinceEpoch() / 1000L + gettimezoneoffset() + 3600;
|
|
|
|
d.dc.duration.seconds = 40 * 60;
|
|
|
|
d.dc.maxdepth.mm = M_OR_FT(15, 45);
|
|
|
|
d.dc.meandepth.mm = M_OR_FT(13, 39); // this creates a resonable looking safety stop
|
2022-10-21 16:12:11 +00:00
|
|
|
make_manually_added_dc(&d.dc);
|
2019-06-22 23:55:27 +00:00
|
|
|
fake_dc(&d.dc);
|
|
|
|
fixup_dive(&d);
|
|
|
|
|
2022-11-12 08:14:00 +00:00
|
|
|
Command::addDive(&d, divelog.autogroup, true);
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionRenumber_triggered()
|
|
|
|
{
|
2020-05-27 12:00:47 +00:00
|
|
|
RenumberDialog dialog(false, this);
|
|
|
|
dialog.exec();
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionAutoGroup_triggered()
|
|
|
|
{
|
2022-11-12 08:14:00 +00:00
|
|
|
divelog.autogroup = ui.actionAutoGroup->isChecked();
|
|
|
|
if (divelog.autogroup)
|
2018-07-23 21:41:23 +00:00
|
|
|
Command::autogroupDives();
|
2013-10-17 23:30:32 +00:00
|
|
|
else
|
2018-07-23 21:41:23 +00:00
|
|
|
Command::removeAutogenTrips();
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionYearlyStatistics_triggered()
|
|
|
|
{
|
2014-08-25 18:46:08 +00:00
|
|
|
QDialog d;
|
|
|
|
QVBoxLayout *l = new QVBoxLayout(&d);
|
2014-08-25 18:48:26 +00:00
|
|
|
YearlyStatisticsModel *m = new YearlyStatisticsModel();
|
|
|
|
QTreeView *view = new QTreeView();
|
|
|
|
view->setModel(m);
|
|
|
|
l->addWidget(view);
|
2017-03-23 01:13:49 +00:00
|
|
|
d.resize(lrint(width() * .8), height() / 2);
|
|
|
|
d.move(lrint(width() * .1), height() / 4);
|
2022-02-08 19:24:53 +00:00
|
|
|
QShortcut *close = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_W), &d);
|
2014-11-17 18:19:51 +00:00
|
|
|
connect(close, SIGNAL(activated()), &d, SLOT(close()));
|
2022-02-08 19:24:53 +00:00
|
|
|
QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q), &d);
|
2014-11-17 18:19:51 +00:00
|
|
|
connect(quit, SIGNAL(activated()), this, SLOT(close()));
|
2014-11-20 15:34:49 +00:00
|
|
|
d.setWindowFlags(Qt::Window | Qt::CustomizeWindowHint
|
2020-03-12 15:23:57 +00:00
|
|
|
| Qt::WindowCloseButtonHint | Qt::WindowTitleHint | Qt::WindowMaximizeButtonHint);
|
2014-11-25 15:47:24 +00:00
|
|
|
d.setWindowTitle(tr("Yearly statistics"));
|
2017-11-28 07:37:01 +00:00
|
|
|
d.setWindowIcon(QIcon(":subsurface-icon"));
|
2020-03-12 15:23:57 +00:00
|
|
|
d.setSizeGripEnabled(true);
|
2014-08-25 18:46:08 +00:00
|
|
|
d.exec();
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionViewList_triggered()
|
|
|
|
{
|
2020-12-17 22:13:06 +00:00
|
|
|
if (!userMayChangeAppState())
|
|
|
|
return;
|
desktop: remove the view-state
There was the "application state", which decided what to show
in the "quadrants" and the "view state" which decided which
quadrant to show. These interacted in a hard-to-grasp way.
The "view state" is used to show the map or dive list in
full screen.
I simply couldn't get these two orthogonal states to interact
properly. Moreover the thing was buggy: If a quadrant was hidden,
the user could still show it, by dragging from the side of the
window, at least under KDE.
To solve these woes, merge the two states into a single
application state. If the widget of a quadrant is set to null,
don't show it. So the four "view states" are now "application
states" where three of the four quadrants are not shown.
This also changes the memory management of the widgets:
widgets that are not shown are now removed from the QSplitter
objects. This makes it possible that the same widget is
shown in *different* quadrants.
While writing this, I stumbled upon a Qt bug, which is known
since 2014:
https://forum.qt.io/topic/43176/qsplitter-sizes-return-0
When restoring the quadrant sizes there was a test whether
the quadrant size is 0. If that was the case, a default size
was set. This seems not to work if the widgets were recently
added. Since this test now always fails, make the quadrants
non-collapsible and thus guarantee that 0 is never saved as
a size.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-17 21:27:40 +00:00
|
|
|
setApplicationState(ApplicationState::ListMaximized);
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionViewProfile_triggered()
|
|
|
|
{
|
2020-12-17 22:13:06 +00:00
|
|
|
if (!userMayChangeAppState())
|
|
|
|
return;
|
desktop: remove the view-state
There was the "application state", which decided what to show
in the "quadrants" and the "view state" which decided which
quadrant to show. These interacted in a hard-to-grasp way.
The "view state" is used to show the map or dive list in
full screen.
I simply couldn't get these two orthogonal states to interact
properly. Moreover the thing was buggy: If a quadrant was hidden,
the user could still show it, by dragging from the side of the
window, at least under KDE.
To solve these woes, merge the two states into a single
application state. If the widget of a quadrant is set to null,
don't show it. So the four "view states" are now "application
states" where three of the four quadrants are not shown.
This also changes the memory management of the widgets:
widgets that are not shown are now removed from the QSplitter
objects. This makes it possible that the same widget is
shown in *different* quadrants.
While writing this, I stumbled upon a Qt bug, which is known
since 2014:
https://forum.qt.io/topic/43176/qsplitter-sizes-return-0
When restoring the quadrant sizes there was a test whether
the quadrant size is 0. If that was the case, a default size
was set. This seems not to work if the widgets were recently
added. Since this test now always fails, make the quadrants
non-collapsible and thus guarantee that 0 is never saved as
a size.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-17 21:27:40 +00:00
|
|
|
setApplicationState(ApplicationState::ProfileMaximized);
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionViewInfo_triggered()
|
|
|
|
{
|
2020-12-17 22:13:06 +00:00
|
|
|
if (!userMayChangeAppState())
|
|
|
|
return;
|
desktop: remove the view-state
There was the "application state", which decided what to show
in the "quadrants" and the "view state" which decided which
quadrant to show. These interacted in a hard-to-grasp way.
The "view state" is used to show the map or dive list in
full screen.
I simply couldn't get these two orthogonal states to interact
properly. Moreover the thing was buggy: If a quadrant was hidden,
the user could still show it, by dragging from the side of the
window, at least under KDE.
To solve these woes, merge the two states into a single
application state. If the widget of a quadrant is set to null,
don't show it. So the four "view states" are now "application
states" where three of the four quadrants are not shown.
This also changes the memory management of the widgets:
widgets that are not shown are now removed from the QSplitter
objects. This makes it possible that the same widget is
shown in *different* quadrants.
While writing this, I stumbled upon a Qt bug, which is known
since 2014:
https://forum.qt.io/topic/43176/qsplitter-sizes-return-0
When restoring the quadrant sizes there was a test whether
the quadrant size is 0. If that was the case, a default size
was set. This seems not to work if the widgets were recently
added. Since this test now always fails, make the quadrants
non-collapsible and thus guarantee that 0 is never saved as
a size.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-17 21:27:40 +00:00
|
|
|
setApplicationState(ApplicationState::InfoMaximized);
|
2013-06-12 18:53:23 +00:00
|
|
|
}
|
|
|
|
|
2017-07-14 22:48:53 +00:00
|
|
|
void MainWindow::on_actionViewMap_triggered()
|
2013-06-12 18:53:23 +00:00
|
|
|
{
|
2020-12-17 22:13:06 +00:00
|
|
|
if (!userMayChangeAppState())
|
|
|
|
return;
|
desktop: remove the view-state
There was the "application state", which decided what to show
in the "quadrants" and the "view state" which decided which
quadrant to show. These interacted in a hard-to-grasp way.
The "view state" is used to show the map or dive list in
full screen.
I simply couldn't get these two orthogonal states to interact
properly. Moreover the thing was buggy: If a quadrant was hidden,
the user could still show it, by dragging from the side of the
window, at least under KDE.
To solve these woes, merge the two states into a single
application state. If the widget of a quadrant is set to null,
don't show it. So the four "view states" are now "application
states" where three of the four quadrants are not shown.
This also changes the memory management of the widgets:
widgets that are not shown are now removed from the QSplitter
objects. This makes it possible that the same widget is
shown in *different* quadrants.
While writing this, I stumbled upon a Qt bug, which is known
since 2014:
https://forum.qt.io/topic/43176/qsplitter-sizes-return-0
When restoring the quadrant sizes there was a test whether
the quadrant size is 0. If that was the case, a default size
was set. This seems not to work if the widgets were recently
added. Since this test now always fails, make the quadrants
non-collapsible and thus guarantee that 0 is never saved as
a size.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-17 21:27:40 +00:00
|
|
|
setApplicationState(ApplicationState::MapMaximized);
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
2022-09-18 11:49:29 +00:00
|
|
|
void MainWindow::on_actionViewDiveSites_triggered()
|
|
|
|
{
|
|
|
|
if (!userMayChangeAppState())
|
|
|
|
return;
|
2022-09-18 13:25:41 +00:00
|
|
|
state_stack.push_back(appState);
|
2022-09-18 11:49:29 +00:00
|
|
|
setApplicationState(ApplicationState::DiveSites);
|
|
|
|
}
|
|
|
|
|
2013-04-09 16:26:23 +00:00
|
|
|
void MainWindow::on_actionViewAll_triggered()
|
|
|
|
{
|
2020-12-17 22:13:06 +00:00
|
|
|
if (!userMayChangeAppState())
|
|
|
|
return;
|
desktop: remove the view-state
There was the "application state", which decided what to show
in the "quadrants" and the "view state" which decided which
quadrant to show. These interacted in a hard-to-grasp way.
The "view state" is used to show the map or dive list in
full screen.
I simply couldn't get these two orthogonal states to interact
properly. Moreover the thing was buggy: If a quadrant was hidden,
the user could still show it, by dragging from the side of the
window, at least under KDE.
To solve these woes, merge the two states into a single
application state. If the widget of a quadrant is set to null,
don't show it. So the four "view states" are now "application
states" where three of the four quadrants are not shown.
This also changes the memory management of the widgets:
widgets that are not shown are now removed from the QSplitter
objects. This makes it possible that the same widget is
shown in *different* quadrants.
While writing this, I stumbled upon a Qt bug, which is known
since 2014:
https://forum.qt.io/topic/43176/qsplitter-sizes-return-0
When restoring the quadrant sizes there was a test whether
the quadrant size is 0. If that was the case, a default size
was set. This seems not to work if the widgets were recently
added. Since this test now always fails, make the quadrants
non-collapsible and thus guarantee that 0 is never saved as
a size.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-17 21:27:40 +00:00
|
|
|
setApplicationState(ApplicationState::Default);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::saveSplitterSizes()
|
|
|
|
{
|
|
|
|
// Only save splitters if all four quadrants are shown
|
|
|
|
if (ui.mainSplitter->count() < 2 || topSplitter->count() < 2 || bottomSplitter->count() < 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings settings;
|
|
|
|
settings.beginGroup("MainWindow");
|
|
|
|
settings.setValue("mainSplitter", ui.mainSplitter->saveState());
|
|
|
|
settings.setValue("topSplitter", topSplitter->saveState());
|
|
|
|
settings.setValue("bottomSplitter", bottomSplitter->saveState());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::restoreSplitterSizes()
|
|
|
|
{
|
|
|
|
// Only restore splitters if all four quadrants are shown
|
|
|
|
if (ui.mainSplitter->count() < 2 || topSplitter->count() < 2 || bottomSplitter->count() < 2)
|
|
|
|
return;
|
2018-09-13 15:45:14 +00:00
|
|
|
|
2013-11-22 01:52:21 +00:00
|
|
|
|
2018-08-29 10:08:47 +00:00
|
|
|
QSettings settings;
|
|
|
|
settings.beginGroup("MainWindow");
|
|
|
|
if (settings.value("mainSplitter").isValid()) {
|
|
|
|
ui.mainSplitter->restoreState(settings.value("mainSplitter").toByteArray());
|
2013-11-22 01:52:21 +00:00
|
|
|
|
desktop: remove the view-state
There was the "application state", which decided what to show
in the "quadrants" and the "view state" which decided which
quadrant to show. These interacted in a hard-to-grasp way.
The "view state" is used to show the map or dive list in
full screen.
I simply couldn't get these two orthogonal states to interact
properly. Moreover the thing was buggy: If a quadrant was hidden,
the user could still show it, by dragging from the side of the
window, at least under KDE.
To solve these woes, merge the two states into a single
application state. If the widget of a quadrant is set to null,
don't show it. So the four "view states" are now "application
states" where three of the four quadrants are not shown.
This also changes the memory management of the widgets:
widgets that are not shown are now removed from the QSplitter
objects. This makes it possible that the same widget is
shown in *different* quadrants.
While writing this, I stumbled upon a Qt bug, which is known
since 2014:
https://forum.qt.io/topic/43176/qsplitter-sizes-return-0
When restoring the quadrant sizes there was a test whether
the quadrant size is 0. If that was the case, a default size
was set. This seems not to work if the widgets were recently
added. Since this test now always fails, make the quadrants
non-collapsible and thus guarantee that 0 is never saved as
a size.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-17 21:27:40 +00:00
|
|
|
topSplitter->restoreState(settings.value("topSplitter").toByteArray());
|
|
|
|
bottomSplitter->restoreState(settings.value("bottomSplitter").toByteArray());
|
2013-11-07 16:37:27 +00:00
|
|
|
} else {
|
2022-02-10 01:00:48 +00:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
2021-02-06 11:48:40 +00:00
|
|
|
const int appH = qApp->desktop()->size().height();
|
|
|
|
const int appW = qApp->desktop()->size().width();
|
2022-02-10 01:00:48 +00:00
|
|
|
#else
|
|
|
|
const int appH = screen()->size().height();
|
|
|
|
const int appW = screen()->size().width();
|
|
|
|
#endif
|
2021-02-06 11:48:40 +00:00
|
|
|
ui.mainSplitter->setSizes({ appH * 3 / 5, appH * 2 / 5 });
|
|
|
|
topSplitter->setSizes({ appW / 2, appW / 2 });
|
|
|
|
bottomSplitter->setSizes({ appW * 3 / 5, appW * 2 / 5 });
|
2013-11-07 16:37:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-09 16:26:23 +00:00
|
|
|
void MainWindow::on_actionPreviousDC_triggered()
|
|
|
|
{
|
2022-09-17 17:07:35 +00:00
|
|
|
profile->prevDC();
|
2022-09-04 09:04:01 +00:00
|
|
|
// TODO: remove
|
2022-09-17 17:07:35 +00:00
|
|
|
mainTab->updateDiveInfo(getDiveSelection(), profile->d, profile->dc);
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionNextDC_triggered()
|
|
|
|
{
|
2022-09-17 17:07:35 +00:00
|
|
|
profile->nextDC();
|
2022-09-04 09:04:01 +00:00
|
|
|
// TODO: remove
|
2022-09-17 17:07:35 +00:00
|
|
|
mainTab->updateDiveInfo(getDiveSelection(), profile->d, profile->dc);
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
2014-01-14 17:36:07 +00:00
|
|
|
void MainWindow::on_actionFullScreen_triggered(bool checked)
|
|
|
|
{
|
|
|
|
if (checked) {
|
|
|
|
setWindowState(windowState() | Qt::WindowFullScreen);
|
2014-01-16 04:50:56 +00:00
|
|
|
} else {
|
2014-01-14 17:36:07 +00:00
|
|
|
setWindowState(windowState() & ~Qt::WindowFullScreen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-09 16:26:23 +00:00
|
|
|
void MainWindow::on_actionAboutSubsurface_triggered()
|
|
|
|
{
|
2014-02-08 07:50:39 +00:00
|
|
|
SubsurfaceAbout dlg(this);
|
|
|
|
|
|
|
|
dlg.exec();
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
2014-04-02 19:41:39 +00:00
|
|
|
void MainWindow::on_action_Check_for_Updates_triggered()
|
|
|
|
{
|
2014-04-02 19:56:14 +00:00
|
|
|
if (!updateManager)
|
|
|
|
updateManager = new UpdateManager(this);
|
|
|
|
|
2014-04-02 19:41:39 +00:00
|
|
|
updateManager->checkForUpdates();
|
|
|
|
}
|
|
|
|
|
2013-04-09 16:26:23 +00:00
|
|
|
void MainWindow::on_actionUserManual_triggered()
|
|
|
|
{
|
2014-03-26 22:35:24 +00:00
|
|
|
#ifndef NO_USERMANUAL
|
2018-05-25 21:08:18 +00:00
|
|
|
if (!helpView)
|
|
|
|
helpView = new UserManual(this);
|
2013-05-30 13:54:06 +00:00
|
|
|
helpView->show();
|
2014-03-26 22:35:24 +00:00
|
|
|
#endif
|
2013-04-09 16:26:23 +00:00
|
|
|
}
|
2013-04-13 13:17:59 +00:00
|
|
|
|
2018-06-10 14:40:23 +00:00
|
|
|
void MainWindow::on_actionHash_images_triggered()
|
|
|
|
{
|
|
|
|
if(!findMovedImagesDialog)
|
|
|
|
findMovedImagesDialog = new FindMovedImagesDialog(this);
|
|
|
|
findMovedImagesDialog->show();
|
|
|
|
}
|
|
|
|
|
2017-10-27 12:52:27 +00:00
|
|
|
QString MainWindow::filter_open()
|
2013-04-13 13:17:59 +00:00
|
|
|
{
|
2018-09-15 15:26:35 +00:00
|
|
|
QString f = tr("Dive log files") +
|
|
|
|
" (*.ssrf"
|
|
|
|
" *.xml"
|
|
|
|
" *.can"
|
|
|
|
" *.db"
|
|
|
|
" *.sql"
|
|
|
|
" *.dld"
|
|
|
|
" *.jlb"
|
|
|
|
" *.lvd"
|
|
|
|
" *.sde"
|
|
|
|
" *.udcf"
|
|
|
|
" *.uddf"
|
|
|
|
" *.dlf"
|
|
|
|
" *.log"
|
|
|
|
" *.txt"
|
|
|
|
" *.apd"
|
|
|
|
" *.dive"
|
|
|
|
" *.zxu *.zxl"
|
|
|
|
");;";
|
2013-04-13 13:17:59 +00:00
|
|
|
|
2017-10-27 12:52:27 +00:00
|
|
|
f += tr("Subsurface files") + " (*.ssrf *.xml);;";
|
|
|
|
f += tr("Cochran") + " (*.can);;";
|
|
|
|
f += tr("DiveLogs.de") + " (*.dld);;";
|
|
|
|
f += tr("JDiveLog") + " (*.jlb);;";
|
|
|
|
f += tr("Liquivision") + " (*.lvd);;";
|
|
|
|
f += tr("Suunto") + " (*.sde *.db);;";
|
|
|
|
f += tr("UDCF") + " (*.udcf);;";
|
|
|
|
f += tr("UDDF") + " (*.uddf);;";
|
|
|
|
f += tr("XML") + " (*.xml);;";
|
|
|
|
f += tr("Divesoft") + " (*.dlf);;";
|
|
|
|
f += tr("Datatrak/WLog") + " (*.log);;";
|
|
|
|
f += tr("MkVI files") + " (*.txt);;";
|
|
|
|
f += tr("APD log viewer") + " (*.apd);;";
|
|
|
|
f += tr("OSTCtools") + " (*.dive);;";
|
|
|
|
f += tr("DAN DL7") + " (*.zxu *.zxl)";
|
|
|
|
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString MainWindow::filter_import()
|
|
|
|
{
|
2018-09-15 15:26:35 +00:00
|
|
|
QString f = tr("Dive log files") +
|
|
|
|
" (*.ssrf"
|
|
|
|
" *.xml"
|
|
|
|
" *.can"
|
|
|
|
" *.csv"
|
|
|
|
" *.db"
|
|
|
|
" *.sql"
|
|
|
|
" *.dld"
|
|
|
|
" *.jlb"
|
|
|
|
" *.lvd"
|
|
|
|
" *.sde"
|
|
|
|
" *.udcf"
|
|
|
|
" *.uddf"
|
|
|
|
" *.dlf"
|
|
|
|
" *.log"
|
|
|
|
" *.txt"
|
|
|
|
" *.apd"
|
|
|
|
" *.dive"
|
|
|
|
" *.zxu *.zxl"
|
|
|
|
");;";
|
2017-10-27 12:52:27 +00:00
|
|
|
|
|
|
|
f += tr("Subsurface files") + " (*.ssrf *.xml);;";
|
|
|
|
f += tr("Cochran") + " (*.can);;";
|
|
|
|
f += tr("CSV") + " (*.csv *.CSV);;";
|
|
|
|
f += tr("DiveLogs.de") + " (*.dld);;";
|
|
|
|
f += tr("JDiveLog") + " (*.jlb);;";
|
|
|
|
f += tr("Liquivision") + " (*.lvd);;";
|
|
|
|
f += tr("Suunto") + " (*.sde *.db);;";
|
|
|
|
f += tr("UDCF") + " (*.udcf);;";
|
|
|
|
f += tr("UDDF") + " (*.uddf);;";
|
|
|
|
f += tr("XML") + " (*.xml);;";
|
|
|
|
f += tr("Divesoft") + " (*.dlf);;";
|
|
|
|
f += tr("Datatrak/WLog") + " (*.log);;";
|
|
|
|
f += tr("MkVI files") + " (*.txt);;";
|
|
|
|
f += tr("APD log viewer") + " (*.apd);;";
|
|
|
|
f += tr("OSTCtools") + " (*.dive);;";
|
|
|
|
f += tr("DAN DL7") + " (*.zxu *.zxl);;";
|
|
|
|
f += tr("All files") + " (*.*)";
|
2013-04-13 13:17:59 +00:00
|
|
|
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2019-05-05 03:46:42 +00:00
|
|
|
QString MainWindow::filter_import_dive_sites()
|
|
|
|
{
|
|
|
|
QString f = tr("Dive site files") +
|
|
|
|
" (*.ssrf"
|
|
|
|
" *.xml"
|
|
|
|
");;";
|
|
|
|
|
|
|
|
f += tr("All files") + " (*.*)";
|
|
|
|
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2013-04-13 13:17:59 +00:00
|
|
|
bool MainWindow::askSaveChanges()
|
|
|
|
{
|
2014-07-16 22:23:02 +00:00
|
|
|
QMessageBox response(this);
|
2013-04-13 13:17:59 +00:00
|
|
|
|
2024-03-16 15:06:39 +00:00
|
|
|
QString message = !existing_filename.empty() ?
|
2018-09-13 16:08:26 +00:00
|
|
|
tr("Do you want to save the changes that you made in the file %1?").arg(displayedFilename(existing_filename)) :
|
|
|
|
tr("Do you want to save the changes that you made in the data file?");
|
2013-05-24 07:28:48 +00:00
|
|
|
|
|
|
|
response.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
|
|
|
|
response.setDefaultButton(QMessageBox::Save);
|
|
|
|
response.setText(message);
|
2014-07-10 23:06:48 +00:00
|
|
|
response.setWindowTitle(tr("Save changes?")); // Not displayed on MacOSX as described in Qt API
|
2013-05-24 07:28:48 +00:00
|
|
|
response.setInformativeText(tr("Changes will be lost if you don't save them."));
|
|
|
|
response.setIcon(QMessageBox::Warning);
|
2014-03-14 23:00:18 +00:00
|
|
|
response.setWindowModality(Qt::WindowModal);
|
2013-05-24 07:28:48 +00:00
|
|
|
int ret = response.exec();
|
|
|
|
|
|
|
|
switch (ret) {
|
|
|
|
case QMessageBox::Save:
|
2013-05-19 22:25:47 +00:00
|
|
|
file_save();
|
2013-04-13 13:17:59 +00:00
|
|
|
return true;
|
2013-05-24 07:28:48 +00:00
|
|
|
case QMessageBox::Discard:
|
2013-05-19 21:46:53 +00:00
|
|
|
return true;
|
2013-04-13 13:17:59 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2013-04-27 09:09:57 +00:00
|
|
|
|
2013-06-04 12:40:09 +00:00
|
|
|
void MainWindow::initialUiSetup()
|
2013-04-27 09:09:57 +00:00
|
|
|
{
|
2018-08-29 10:08:47 +00:00
|
|
|
QSettings settings;
|
|
|
|
settings.beginGroup("MainWindow");
|
|
|
|
if (settings.value("maximized", isMaximized()).value<bool>()) {
|
2013-12-02 10:32:27 +00:00
|
|
|
showMaximized();
|
2015-10-09 16:03:12 +00:00
|
|
|
} else {
|
2018-08-29 10:08:47 +00:00
|
|
|
restoreGeometry(settings.value("geometry").toByteArray());
|
|
|
|
restoreState(settings.value("windowState", 0).toByteArray());
|
2015-10-09 16:03:12 +00:00
|
|
|
}
|
2013-10-04 18:07:36 +00:00
|
|
|
|
desktop: remove the view-state
There was the "application state", which decided what to show
in the "quadrants" and the "view state" which decided which
quadrant to show. These interacted in a hard-to-grasp way.
The "view state" is used to show the map or dive list in
full screen.
I simply couldn't get these two orthogonal states to interact
properly. Moreover the thing was buggy: If a quadrant was hidden,
the user could still show it, by dragging from the side of the
window, at least under KDE.
To solve these woes, merge the two states into a single
application state. If the widget of a quadrant is set to null,
don't show it. So the four "view states" are now "application
states" where three of the four quadrants are not shown.
This also changes the memory management of the widgets:
widgets that are not shown are now removed from the QSplitter
objects. This makes it possible that the same widget is
shown in *different* quadrants.
While writing this, I stumbled upon a Qt bug, which is known
since 2014:
https://forum.qt.io/topic/43176/qsplitter-sizes-return-0
When restoring the quadrant sizes there was a test whether
the quadrant size is 0. If that was the case, a default size
was set. This seems not to work if the widgets were recently
added. Since this test now always fails, make the quadrants
non-collapsible and thus guarantee that 0 is never saved as
a size.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-17 21:27:40 +00:00
|
|
|
setApplicationState((ApplicationState)settings.value("lastAppState", 0).toInt());
|
2018-08-29 10:08:47 +00:00
|
|
|
settings.endGroup();
|
2015-10-09 16:03:12 +00:00
|
|
|
show();
|
2013-06-04 12:40:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::readSettings()
|
|
|
|
{
|
2015-11-14 17:38:18 +00:00
|
|
|
init_proxy();
|
2014-06-26 16:20:34 +00:00
|
|
|
|
2015-11-10 21:45:13 +00:00
|
|
|
// now make sure that the cloud menu items are enabled IFF cloud account is verified
|
|
|
|
enableDisableCloudActions();
|
|
|
|
|
2017-11-30 10:52:42 +00:00
|
|
|
loadRecentFiles();
|
2013-04-27 09:09:57 +00:00
|
|
|
}
|
|
|
|
|
2014-03-02 21:37:29 +00:00
|
|
|
#undef TOOLBOX_PREF_BUTTON
|
|
|
|
|
2013-04-27 09:09:57 +00:00
|
|
|
void MainWindow::writeSettings()
|
|
|
|
{
|
2018-08-29 10:08:47 +00:00
|
|
|
QSettings settings;
|
|
|
|
|
|
|
|
settings.beginGroup("MainWindow");
|
|
|
|
settings.setValue("geometry", saveGeometry());
|
|
|
|
settings.setValue("windowState", saveState());
|
|
|
|
settings.setValue("maximized", isMaximized());
|
2021-02-14 19:59:02 +00:00
|
|
|
settings.setValue("lastState", (int)appState);
|
desktop: remove the view-state
There was the "application state", which decided what to show
in the "quadrants" and the "view state" which decided which
quadrant to show. These interacted in a hard-to-grasp way.
The "view state" is used to show the map or dive list in
full screen.
I simply couldn't get these two orthogonal states to interact
properly. Moreover the thing was buggy: If a quadrant was hidden,
the user could still show it, by dragging from the side of the
window, at least under KDE.
To solve these woes, merge the two states into a single
application state. If the widget of a quadrant is set to null,
don't show it. So the four "view states" are now "application
states" where three of the four quadrants are not shown.
This also changes the memory management of the widgets:
widgets that are not shown are now removed from the QSplitter
objects. This makes it possible that the same widget is
shown in *different* quadrants.
While writing this, I stumbled upon a Qt bug, which is known
since 2014:
https://forum.qt.io/topic/43176/qsplitter-sizes-return-0
When restoring the quadrant sizes there was a test whether
the quadrant size is 0. If that was the case, a default size
was set. This seems not to work if the widgets were recently
added. Since this test now always fails, make the quadrants
non-collapsible and thus guarantee that 0 is never saved as
a size.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-17 21:27:40 +00:00
|
|
|
saveSplitterSizes();
|
2018-08-29 10:08:47 +00:00
|
|
|
settings.endGroup();
|
2013-04-27 09:09:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
2022-03-12 11:48:12 +00:00
|
|
|
if (inPlanner()) {
|
2014-06-04 01:22:22 +00:00
|
|
|
on_actionQuit_triggered();
|
2013-12-17 00:37:44 +00:00
|
|
|
event->ignore();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-21 21:20:46 +00:00
|
|
|
if (!Command::isClean() && (askSaveChanges() == false)) {
|
2013-04-27 09:09:57 +00:00
|
|
|
event->ignore();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
event->accept();
|
|
|
|
writeSettings();
|
2014-03-11 16:31:01 +00:00
|
|
|
QApplication::closeAllWindows();
|
2013-04-28 03:47:47 +00:00
|
|
|
}
|
2013-05-19 03:09:36 +00:00
|
|
|
|
2017-11-30 10:52:42 +00:00
|
|
|
void MainWindow::loadRecentFiles()
|
2014-02-13 21:48:07 +00:00
|
|
|
{
|
2017-11-30 10:52:42 +00:00
|
|
|
recentFiles.clear();
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup("Recent_Files");
|
2024-03-16 15:50:43 +00:00
|
|
|
for (const QString &key: s.childKeys()) {
|
2017-11-30 10:52:42 +00:00
|
|
|
// TODO Sorting only correct up to 9 entries. Currently, only 4 used, so no problem.
|
|
|
|
if (!key.startsWith("File_"))
|
|
|
|
continue;
|
|
|
|
QString file = s.value(key).toString();
|
2019-08-12 17:00:48 +00:00
|
|
|
|
|
|
|
// never add our cloud URL to the recent files
|
2021-04-11 00:40:30 +00:00
|
|
|
if (file.startsWith(prefs.cloud_base_url))
|
2019-08-12 17:00:48 +00:00
|
|
|
continue;
|
|
|
|
// but allow local git repos
|
|
|
|
QRegularExpression gitrepo("(.*)\\[[^]]+]");
|
|
|
|
QRegularExpressionMatch match = gitrepo.match(file);
|
|
|
|
if (match.hasMatch()) {
|
|
|
|
const QFileInfo gitDirectory(match.captured(1) + "/.git");
|
|
|
|
if ((gitDirectory.exists()) && (gitDirectory.isDir()))
|
|
|
|
recentFiles.append(file);
|
|
|
|
} else if (QFile::exists(file)) {
|
2017-11-30 10:52:42 +00:00
|
|
|
recentFiles.append(file);
|
2019-08-12 17:00:48 +00:00
|
|
|
}
|
2017-11-30 10:52:42 +00:00
|
|
|
if (recentFiles.count() > NUM_RECENT_FILES)
|
2014-02-13 21:48:07 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-11-30 10:52:42 +00:00
|
|
|
s.endGroup();
|
|
|
|
updateRecentFilesMenu();
|
|
|
|
}
|
2014-02-13 21:48:07 +00:00
|
|
|
|
2017-11-30 10:52:42 +00:00
|
|
|
void MainWindow::updateRecentFilesMenu()
|
|
|
|
{
|
|
|
|
for (int c = 0; c < NUM_RECENT_FILES; c++) {
|
2017-11-30 16:44:32 +00:00
|
|
|
QAction *action = actionsRecent[c];
|
2014-02-13 21:48:07 +00:00
|
|
|
|
2017-11-30 10:52:42 +00:00
|
|
|
if (recentFiles.count() > c) {
|
|
|
|
QFileInfo fi(recentFiles.at(c));
|
2014-02-13 21:48:07 +00:00
|
|
|
action->setText(fi.fileName());
|
|
|
|
action->setToolTip(fi.absoluteFilePath());
|
|
|
|
action->setVisible(true);
|
2014-02-14 06:11:05 +00:00
|
|
|
} else {
|
2014-02-13 21:48:07 +00:00
|
|
|
action->setVisible(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-30 10:52:42 +00:00
|
|
|
void MainWindow::addRecentFile(const QString &file, bool update)
|
2014-02-13 21:48:07 +00:00
|
|
|
{
|
2019-08-12 17:00:48 +00:00
|
|
|
// never add Subsurface cloud file to the recent files - it has its own menu entry
|
2021-04-11 00:40:30 +00:00
|
|
|
if (file.startsWith(prefs.cloud_base_url))
|
2019-08-12 17:00:48 +00:00
|
|
|
return;
|
2017-11-30 10:52:42 +00:00
|
|
|
QString localFile = QDir::toNativeSeparators(file);
|
|
|
|
int index = recentFiles.indexOf(localFile);
|
|
|
|
if (index >= 0)
|
|
|
|
recentFiles.removeAt(index);
|
|
|
|
recentFiles.prepend(localFile);
|
|
|
|
while (recentFiles.count() > NUM_RECENT_FILES)
|
|
|
|
recentFiles.removeLast();
|
|
|
|
if (update)
|
|
|
|
updateRecentFiles();
|
2014-02-13 21:48:07 +00:00
|
|
|
}
|
|
|
|
|
2017-11-30 10:52:42 +00:00
|
|
|
void MainWindow::updateRecentFiles()
|
2014-02-28 09:04:00 +00:00
|
|
|
{
|
|
|
|
QSettings s;
|
|
|
|
|
|
|
|
s.beginGroup("Recent_Files");
|
2017-11-30 10:52:42 +00:00
|
|
|
s.remove(""); // Remove all old entries
|
|
|
|
for (int c = 1; c <= recentFiles.count(); c++) {
|
2014-02-28 09:04:00 +00:00
|
|
|
QString key = QString("File_%1").arg(c);
|
2017-11-30 10:52:42 +00:00
|
|
|
s.setValue(key, recentFiles.at(c - 1));
|
2014-02-28 09:04:00 +00:00
|
|
|
}
|
|
|
|
s.endGroup();
|
|
|
|
s.sync();
|
2017-11-30 10:52:42 +00:00
|
|
|
updateRecentFilesMenu();
|
2014-02-28 09:04:00 +00:00
|
|
|
}
|
|
|
|
|
2018-05-21 16:09:09 +00:00
|
|
|
void MainWindow::recentFileTriggered(bool)
|
2014-02-13 21:48:07 +00:00
|
|
|
{
|
2014-06-09 02:46:43 +00:00
|
|
|
if (!okToClose(tr("Please save or cancel the current dive edit before opening a new file.")))
|
|
|
|
return;
|
|
|
|
|
2017-11-30 16:56:16 +00:00
|
|
|
int filenr = ((QAction *)sender())->data().toInt();
|
|
|
|
if (filenr >= recentFiles.count())
|
|
|
|
return;
|
|
|
|
const QString &filename = recentFiles[filenr];
|
2014-02-13 21:48:07 +00:00
|
|
|
|
|
|
|
updateLastUsedDir(QFileInfo(filename).dir().path());
|
2014-06-09 02:46:43 +00:00
|
|
|
closeCurrentFile();
|
2024-03-25 09:58:27 +00:00
|
|
|
loadFiles(std::vector<std::string> { filename.toStdString() });
|
2014-02-13 21:48:07 +00:00
|
|
|
}
|
|
|
|
|
2014-03-14 17:19:23 +00:00
|
|
|
int MainWindow::file_save_as(void)
|
2013-05-19 22:25:47 +00:00
|
|
|
{
|
|
|
|
QString filename;
|
2024-03-16 15:06:39 +00:00
|
|
|
std::string default_filename = existing_filename;
|
2015-05-11 22:26:56 +00:00
|
|
|
|
2015-09-20 15:39:15 +00:00
|
|
|
// if the default is to save to cloud storage, pick something that will work as local file:
|
|
|
|
// simply extract the branch name which should be the users email address
|
2024-03-16 15:06:39 +00:00
|
|
|
if (!default_filename.empty() && QString::fromStdString(default_filename).contains(QRegularExpression(CLOUD_HOST_PATTERN))) {
|
|
|
|
QString filename = QString::fromStdString(default_filename);
|
2015-09-20 15:39:15 +00:00
|
|
|
filename.remove(0, filename.indexOf("[") + 1);
|
|
|
|
filename.replace("]", ".ssrf");
|
2024-03-16 15:06:39 +00:00
|
|
|
default_filename = filename.toStdString();
|
2015-09-20 15:39:15 +00:00
|
|
|
}
|
2015-05-11 22:26:56 +00:00
|
|
|
// create a file dialog that allows us to save to a new file
|
2024-03-16 15:06:39 +00:00
|
|
|
QFileDialog selection_dialog(this, tr("Save file as"), default_filename.c_str(),
|
2017-10-27 12:52:27 +00:00
|
|
|
tr("Subsurface files") + " (*.ssrf *.xml)");
|
2015-05-11 22:26:56 +00:00
|
|
|
selection_dialog.setAcceptMode(QFileDialog::AcceptSave);
|
|
|
|
selection_dialog.setFileMode(QFileDialog::AnyFile);
|
2015-05-27 18:14:26 +00:00
|
|
|
selection_dialog.setDefaultSuffix("");
|
2024-03-16 15:06:39 +00:00
|
|
|
if (default_filename.empty()) {
|
2015-10-05 02:34:27 +00:00
|
|
|
QFileInfo defaultFile(system_default_filename());
|
|
|
|
selection_dialog.setDirectory(qPrintable(defaultFile.absolutePath()));
|
|
|
|
}
|
2015-03-21 15:10:55 +00:00
|
|
|
/* if the exit/cancel button is pressed return */
|
|
|
|
if (!selection_dialog.exec())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* get the first selected file */
|
|
|
|
filename = selection_dialog.selectedFiles().at(0);
|
2015-05-27 18:14:26 +00:00
|
|
|
|
|
|
|
/* now for reasons I don't understand we appear to add a .ssrf to
|
|
|
|
* git style filenames <path>/directory[branch]
|
|
|
|
* so let's remove that */
|
2015-06-21 23:28:38 +00:00
|
|
|
QRegularExpression reg(".*\\[[^]]+]\\.ssrf", QRegularExpression::CaseInsensitiveOption);
|
|
|
|
if (reg.match(filename).hasMatch())
|
|
|
|
filename.remove(QRegularExpression("\\.ssrf$", QRegularExpression::CaseInsensitiveOption));
|
2014-03-14 17:19:23 +00:00
|
|
|
if (filename.isNull() || filename.isEmpty())
|
|
|
|
return report_error("No filename to save into");
|
2013-11-23 02:40:48 +00:00
|
|
|
|
2018-02-25 12:51:41 +00:00
|
|
|
if (save_dives(qPrintable(filename)))
|
2014-03-14 17:19:23 +00:00
|
|
|
return -1;
|
|
|
|
|
2024-03-24 21:56:41 +00:00
|
|
|
setCurrentFile(filename.toStdString());
|
2020-10-21 21:26:50 +00:00
|
|
|
Command::setClean();
|
2017-11-30 10:52:42 +00:00
|
|
|
addRecentFile(filename, true);
|
2014-03-14 17:19:23 +00:00
|
|
|
return 0;
|
2013-05-19 22:25:47 +00:00
|
|
|
}
|
|
|
|
|
2014-03-14 17:19:23 +00:00
|
|
|
int MainWindow::file_save(void)
|
2013-05-19 22:25:47 +00:00
|
|
|
{
|
|
|
|
const char *current_default;
|
2015-09-28 17:05:20 +00:00
|
|
|
bool is_cloud = false;
|
2013-05-19 22:25:47 +00:00
|
|
|
|
2024-03-16 15:06:39 +00:00
|
|
|
if (existing_filename.empty())
|
2013-05-19 22:25:47 +00:00
|
|
|
return file_save_as();
|
|
|
|
|
2024-03-16 15:06:39 +00:00
|
|
|
is_cloud = (starts_with(existing_filename, "http") == 0);
|
2018-05-14 18:17:08 +00:00
|
|
|
if (is_cloud && !saveToCloudOK())
|
|
|
|
return -1;
|
2015-09-28 17:05:20 +00:00
|
|
|
|
2013-05-19 22:25:47 +00:00
|
|
|
current_default = prefs.default_filename;
|
2024-03-16 15:06:39 +00:00
|
|
|
if (existing_filename == current_default) {
|
2013-05-19 22:25:47 +00:00
|
|
|
/* if we are using the default filename the directory
|
|
|
|
* that we are creating the file in may not exist */
|
2013-05-20 00:18:44 +00:00
|
|
|
QDir current_def_dir = QFileInfo(current_default).absoluteDir();
|
|
|
|
if (!current_def_dir.exists())
|
|
|
|
current_def_dir.mkpath(current_def_dir.absolutePath());
|
2013-05-19 22:25:47 +00:00
|
|
|
}
|
2015-09-28 17:05:20 +00:00
|
|
|
if (is_cloud)
|
|
|
|
showProgressBar();
|
2024-03-16 15:06:39 +00:00
|
|
|
if (save_dives(existing_filename.c_str())) {
|
2015-09-28 17:05:20 +00:00
|
|
|
if (is_cloud)
|
|
|
|
hideProgressBar();
|
2014-03-14 17:19:23 +00:00
|
|
|
return -1;
|
2014-03-14 17:35:09 +00:00
|
|
|
}
|
2015-09-28 17:05:20 +00:00
|
|
|
if (is_cloud)
|
|
|
|
hideProgressBar();
|
2020-10-21 21:26:50 +00:00
|
|
|
Command::setClean();
|
2024-03-16 15:06:39 +00:00
|
|
|
addRecentFile(QString::fromStdString(existing_filename), true);
|
2014-03-14 17:19:23 +00:00
|
|
|
return 0;
|
2013-05-19 22:25:47 +00:00
|
|
|
}
|
2013-05-22 06:13:45 +00:00
|
|
|
|
2015-02-26 14:07:39 +00:00
|
|
|
NotificationWidget *MainWindow::getNotificationWidget()
|
|
|
|
{
|
|
|
|
return ui.mainErrorMessage;
|
2013-05-22 06:13:45 +00:00
|
|
|
}
|
2013-06-26 12:13:06 +00:00
|
|
|
|
2024-03-16 15:06:39 +00:00
|
|
|
QString MainWindow::displayedFilename(const std::string &fullFilename)
|
2015-06-12 13:53:00 +00:00
|
|
|
{
|
2024-03-16 15:06:39 +00:00
|
|
|
QFile f(fullFilename.c_str());
|
2015-06-12 13:53:00 +00:00
|
|
|
QFileInfo fileInfo(f);
|
|
|
|
QString fileName(fileInfo.fileName());
|
|
|
|
|
2024-03-16 15:06:39 +00:00
|
|
|
if (fullFilename.find(prefs.cloud_base_url) != std::string::npos) {
|
2016-07-17 03:27:01 +00:00
|
|
|
QString email = fileName.left(fileName.indexOf('['));
|
2018-09-13 16:08:26 +00:00
|
|
|
return git_local_only ?
|
|
|
|
tr("[local cache for] %1").arg(email) :
|
|
|
|
tr("[cloud storage for] %1").arg(email);
|
2016-07-17 03:27:01 +00:00
|
|
|
} else {
|
2015-06-12 13:53:00 +00:00
|
|
|
return fileName;
|
2016-07-17 03:27:01 +00:00
|
|
|
}
|
2015-06-12 13:53:00 +00:00
|
|
|
}
|
|
|
|
|
2016-07-17 03:27:01 +00:00
|
|
|
|
2015-06-16 13:04:34 +00:00
|
|
|
void MainWindow::setAutomaticTitle()
|
|
|
|
{
|
|
|
|
setTitle();
|
|
|
|
}
|
|
|
|
|
2017-12-11 16:43:53 +00:00
|
|
|
void MainWindow::setTitle()
|
2013-06-26 12:13:06 +00:00
|
|
|
{
|
2024-03-16 15:06:39 +00:00
|
|
|
if (existing_filename.empty()) {
|
2013-06-26 12:13:06 +00:00
|
|
|
setWindowTitle("Subsurface");
|
2017-12-11 16:43:53 +00:00
|
|
|
return;
|
2013-06-26 12:13:06 +00:00
|
|
|
}
|
2017-12-11 16:43:53 +00:00
|
|
|
|
2020-10-21 21:20:46 +00:00
|
|
|
QString unsaved = (!Command::isClean() ? " *" : "");
|
2020-06-22 12:05:46 +00:00
|
|
|
QString shown = QString(" (%1)").arg(DiveFilter::instance()->shownText());
|
2019-02-18 20:47:20 +00:00
|
|
|
setWindowTitle("Subsurface: " + displayedFilename(existing_filename) + unsaved + shown);
|
2013-06-26 12:13:06 +00:00
|
|
|
}
|
2013-09-09 08:59:03 +00:00
|
|
|
|
2024-03-25 09:58:27 +00:00
|
|
|
void MainWindow::importFiles(const std::vector<std::string> &fileNames)
|
2013-09-09 08:59:03 +00:00
|
|
|
{
|
2024-03-25 09:58:27 +00:00
|
|
|
if (fileNames.empty())
|
2013-10-04 15:12:46 +00:00
|
|
|
return;
|
|
|
|
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
struct divelog log;
|
2014-03-14 18:26:07 +00:00
|
|
|
|
2024-03-25 09:58:27 +00:00
|
|
|
for (const std::string &fn: fileNames) {
|
|
|
|
std::string encoded = encodeFileName(fn);
|
|
|
|
parse_file(encoded.c_str(), &log);
|
2013-09-09 08:59:03 +00:00
|
|
|
}
|
2024-03-25 09:58:27 +00:00
|
|
|
QString source = fileNames.size() == 1 ? QString::fromStdString(fileNames[0]) : tr("multiple files");
|
2022-11-12 07:40:04 +00:00
|
|
|
Command::importDives(&log, IMPORT_MERGE_ALL_TRIPS, source);
|
2013-09-09 08:59:03 +00:00
|
|
|
}
|
|
|
|
|
2024-03-25 09:58:27 +00:00
|
|
|
void MainWindow::loadFiles(const std::vector<std::string> &fileNames)
|
2013-09-09 08:59:03 +00:00
|
|
|
{
|
2024-03-25 09:58:27 +00:00
|
|
|
if (fileNames.empty()) {
|
2015-10-08 06:40:29 +00:00
|
|
|
refreshDisplay();
|
2013-10-04 15:12:46 +00:00
|
|
|
return;
|
2015-10-08 06:40:29 +00:00
|
|
|
}
|
2013-09-09 08:59:03 +00:00
|
|
|
QByteArray fileNamePtr;
|
|
|
|
|
2015-09-23 19:16:45 +00:00
|
|
|
showProgressBar();
|
2024-03-25 09:58:27 +00:00
|
|
|
for (const std::string &fn: fileNames) {
|
|
|
|
fileNamePtr = QFile::encodeName(QString::fromStdString(fn));
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
if (!parse_file(fileNamePtr.data(), &divelog)) {
|
2024-03-24 21:56:41 +00:00
|
|
|
setCurrentFile(fileNamePtr.toStdString());
|
2017-11-30 10:52:42 +00:00
|
|
|
addRecentFile(fileNamePtr, false);
|
2013-09-09 08:59:03 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-23 19:16:45 +00:00
|
|
|
hideProgressBar();
|
2017-11-30 10:52:42 +00:00
|
|
|
updateRecentFiles();
|
2018-09-23 10:53:35 +00:00
|
|
|
process_loaded_dives();
|
2013-09-09 08:59:03 +00:00
|
|
|
|
2013-11-01 13:43:41 +00:00
|
|
|
refreshDisplay();
|
2022-11-12 08:14:00 +00:00
|
|
|
updateAutogroup();
|
2015-06-22 19:14:42 +00:00
|
|
|
|
2015-06-25 17:55:40 +00:00
|
|
|
int min_datafile_version = get_min_datafile_version();
|
|
|
|
if (min_datafile_version >0 && min_datafile_version < DATAFORMAT_VERSION) {
|
2015-06-22 19:14:42 +00:00
|
|
|
QMessageBox::warning(this, tr("Opening datafile from older version"),
|
2015-06-25 17:55:40 +00:00
|
|
|
tr("You opened a data file from an older version of Subsurface. We recommend "
|
2015-09-04 22:25:35 +00:00
|
|
|
"you read the manual to learn about the changes in the new version, especially "
|
|
|
|
"about dive site management which has changed significantly.\n"
|
|
|
|
"Subsurface has already tried to pre-populate the data but it might be worth "
|
|
|
|
"while taking a look at the new dive site management system and to make "
|
2015-06-22 19:14:42 +00:00
|
|
|
"sure that everything looks correct."));
|
|
|
|
}
|
2013-09-09 08:59:03 +00:00
|
|
|
}
|
2013-10-16 19:05:19 +00:00
|
|
|
|
2018-10-01 12:17:38 +00:00
|
|
|
static const char *csvExtensions[] = {
|
|
|
|
".csv", ".apd", ".zxu", ".zxl", ".txt"
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool isCsvFile(const QString &s)
|
|
|
|
{
|
|
|
|
for (const char *ext: csvExtensions) {
|
|
|
|
if (s.endsWith(ext, Qt::CaseInsensitive))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-12-29 16:11:20 +00:00
|
|
|
void MainWindow::on_actionImportDiveLog_triggered()
|
2013-10-16 19:05:19 +00:00
|
|
|
{
|
2017-10-27 12:52:27 +00:00
|
|
|
QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Open dive log file"), lastUsedDir(), filter_import());
|
2014-01-07 20:01:28 +00:00
|
|
|
|
|
|
|
if (fileNames.isEmpty())
|
|
|
|
return;
|
|
|
|
updateLastUsedDir(QFileInfo(fileNames[0]).dir().path());
|
|
|
|
|
2024-03-25 09:58:27 +00:00
|
|
|
std::vector<std::string> logFiles;
|
2018-10-01 12:17:38 +00:00
|
|
|
QStringList csvFiles;
|
|
|
|
for (const QString &fn: fileNames) {
|
|
|
|
if (isCsvFile(fn))
|
|
|
|
csvFiles.append(fn);
|
|
|
|
else
|
2024-03-25 09:58:27 +00:00
|
|
|
logFiles.push_back(fn.toStdString());
|
2018-10-01 12:17:38 +00:00
|
|
|
}
|
2014-10-28 20:34:33 +00:00
|
|
|
|
2024-01-16 16:39:19 +00:00
|
|
|
if (logFiles.size())
|
2014-01-07 20:01:28 +00:00
|
|
|
importFiles(logFiles);
|
|
|
|
|
|
|
|
if (csvFiles.size()) {
|
2024-01-15 20:22:20 +00:00
|
|
|
DiveLogImportDialog diveLogImport(std::move(csvFiles), this);
|
2018-10-01 16:12:59 +00:00
|
|
|
diveLogImport.exec();
|
2014-01-07 20:01:28 +00:00
|
|
|
}
|
2013-10-16 19:05:19 +00:00
|
|
|
}
|
2013-11-01 15:48:34 +00:00
|
|
|
|
2019-05-05 03:46:42 +00:00
|
|
|
void MainWindow::on_actionImportDiveSites_triggered()
|
|
|
|
{
|
|
|
|
QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Open dive site file"), lastUsedDir(), filter_import_dive_sites());
|
|
|
|
|
|
|
|
if (fileNames.isEmpty())
|
|
|
|
return;
|
|
|
|
updateLastUsedDir(QFileInfo(fileNames[0]).dir().path());
|
|
|
|
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
struct divelog log;
|
2019-05-05 03:46:42 +00:00
|
|
|
|
|
|
|
for (const QString &s: fileNames) {
|
|
|
|
QByteArray fileNamePtr = QFile::encodeName(s);
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
parse_file(fileNamePtr.data(), &log);
|
2019-05-05 03:46:42 +00:00
|
|
|
}
|
|
|
|
// The imported dive sites still have pointers to imported dives - remove them
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
for (int i = 0; i < log.sites->nr; ++i)
|
|
|
|
log.sites->dive_sites[i]->dives.nr = 0;
|
2019-05-05 03:46:42 +00:00
|
|
|
|
|
|
|
QString source = fileNames.size() == 1 ? fileNames[0] : tr("multiple files");
|
|
|
|
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
DivesiteImportDialog divesiteImport(*log.sites, source, this);
|
2019-05-05 03:46:42 +00:00
|
|
|
divesiteImport.exec();
|
|
|
|
}
|
|
|
|
|
2014-05-20 16:33:32 +00:00
|
|
|
void MainWindow::on_actionExport_triggered()
|
|
|
|
{
|
2014-07-10 22:53:58 +00:00
|
|
|
DiveLogExportDialog diveLogExport;
|
|
|
|
diveLogExport.exec();
|
2014-05-20 16:33:32 +00:00
|
|
|
}
|
2014-08-04 15:58:21 +00:00
|
|
|
|
2014-05-29 15:54:19 +00:00
|
|
|
void MainWindow::on_actionConfigure_Dive_Computer_triggered()
|
|
|
|
{
|
2024-03-16 15:06:39 +00:00
|
|
|
QString filename = get_current_filename();
|
2024-03-16 08:53:22 +00:00
|
|
|
ConfigureDiveComputerDialog *dcConfig = new ConfigureDiveComputerDialog(filename, this);
|
2014-05-29 15:54:19 +00:00
|
|
|
dcConfig->show();
|
|
|
|
}
|
|
|
|
|
2014-08-04 15:58:21 +00:00
|
|
|
void MainWindow::setEnabledToolbar(bool arg1)
|
|
|
|
{
|
2021-04-12 21:34:28 +00:00
|
|
|
profile->setEnabledToolbar(arg1);
|
2014-08-04 15:58:21 +00:00
|
|
|
}
|
2014-08-16 15:32:23 +00:00
|
|
|
|
|
|
|
void MainWindow::on_copy_triggered()
|
|
|
|
{
|
|
|
|
// open dialog to select what gets copied
|
|
|
|
// copy the displayed dive
|
|
|
|
DiveComponentSelection dialog(this, ©PasteDive, &what);
|
|
|
|
dialog.exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_paste_triggered()
|
|
|
|
{
|
2019-02-23 17:17:20 +00:00
|
|
|
Command::pasteDives(©PasteDive, what);
|
2014-08-16 15:32:23 +00:00
|
|
|
}
|
2014-09-17 17:50:41 +00:00
|
|
|
|
|
|
|
void MainWindow::on_actionFilterTags_triggered()
|
|
|
|
{
|
2020-12-17 22:13:06 +00:00
|
|
|
if (!userMayChangeAppState())
|
|
|
|
return;
|
2021-02-14 19:59:02 +00:00
|
|
|
setApplicationState(appState == ApplicationState::FilterDive ? ApplicationState::Default : ApplicationState::FilterDive);
|
2017-10-27 15:52:49 +00:00
|
|
|
}
|
|
|
|
|
2020-10-28 11:23:41 +00:00
|
|
|
void MainWindow::on_actionStats_triggered()
|
|
|
|
{
|
2020-12-17 22:13:06 +00:00
|
|
|
if (!userMayChangeAppState())
|
|
|
|
return;
|
2021-02-14 19:59:02 +00:00
|
|
|
setApplicationState(appState == ApplicationState::Statistics ? ApplicationState::Default : ApplicationState::Statistics);
|
2020-10-28 11:23:41 +00:00
|
|
|
}
|
|
|
|
|
desktop: remove the view-state
There was the "application state", which decided what to show
in the "quadrants" and the "view state" which decided which
quadrant to show. These interacted in a hard-to-grasp way.
The "view state" is used to show the map or dive list in
full screen.
I simply couldn't get these two orthogonal states to interact
properly. Moreover the thing was buggy: If a quadrant was hidden,
the user could still show it, by dragging from the side of the
window, at least under KDE.
To solve these woes, merge the two states into a single
application state. If the widget of a quadrant is set to null,
don't show it. So the four "view states" are now "application
states" where three of the four quadrants are not shown.
This also changes the memory management of the widgets:
widgets that are not shown are now removed from the QSplitter
objects. This makes it possible that the same widget is
shown in *different* quadrants.
While writing this, I stumbled upon a Qt bug, which is known
since 2014:
https://forum.qt.io/topic/43176/qsplitter-sizes-return-0
When restoring the quadrant sizes there was a test whether
the quadrant size is 0. If that was the case, a default size
was set. This seems not to work if the widgets were recently
added. Since this test now always fails, make the quadrants
non-collapsible and thus guarantee that 0 is never saved as
a size.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-17 21:27:40 +00:00
|
|
|
void MainWindow::registerApplicationState(ApplicationState state, Quadrants q)
|
2019-02-10 00:01:50 +00:00
|
|
|
{
|
desktop: remove the view-state
There was the "application state", which decided what to show
in the "quadrants" and the "view state" which decided which
quadrant to show. These interacted in a hard-to-grasp way.
The "view state" is used to show the map or dive list in
full screen.
I simply couldn't get these two orthogonal states to interact
properly. Moreover the thing was buggy: If a quadrant was hidden,
the user could still show it, by dragging from the side of the
window, at least under KDE.
To solve these woes, merge the two states into a single
application state. If the widget of a quadrant is set to null,
don't show it. So the four "view states" are now "application
states" where three of the four quadrants are not shown.
This also changes the memory management of the widgets:
widgets that are not shown are now removed from the QSplitter
objects. This makes it possible that the same widget is
shown in *different* quadrants.
While writing this, I stumbled upon a Qt bug, which is known
since 2014:
https://forum.qt.io/topic/43176/qsplitter-sizes-return-0
When restoring the quadrant sizes there was a test whether
the quadrant size is 0. If that was the case, a default size
was set. This seems not to work if the widgets were recently
added. Since this test now always fails, make the quadrants
non-collapsible and thus guarantee that 0 is never saved as
a size.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-17 21:27:40 +00:00
|
|
|
applicationState[(int)state] = q;
|
2019-02-10 00:01:50 +00:00
|
|
|
}
|
2019-05-10 18:51:25 +00:00
|
|
|
|
2021-01-27 21:06:41 +00:00
|
|
|
void MainWindow::setQuadrantWidget(QSplitter &splitter, const Quadrant &q, int pos)
|
2015-02-09 17:42:32 +00:00
|
|
|
{
|
2021-01-27 21:06:41 +00:00
|
|
|
if (!q.widget)
|
|
|
|
return;
|
|
|
|
if (splitter.count() > pos)
|
|
|
|
splitter.replaceWidget(pos, q.widget);
|
|
|
|
else
|
2020-12-18 11:01:36 +00:00
|
|
|
splitter.addWidget(q.widget);
|
2021-01-27 21:06:41 +00:00
|
|
|
splitter.setCollapsible(pos, false);
|
|
|
|
q.widget->setEnabled(!(q.flags & FLAG_DISABLED));
|
2019-05-10 18:51:25 +00:00
|
|
|
}
|
|
|
|
|
2021-01-27 21:06:41 +00:00
|
|
|
void MainWindow::setQuadrantWidgets(QSplitter &splitter, const Quadrant &left, const Quadrant &right)
|
2019-05-10 18:51:25 +00:00
|
|
|
{
|
2021-01-27 21:06:41 +00:00
|
|
|
int num = (left.widget != nullptr) + (right.widget != nullptr);
|
|
|
|
// Remove superfluous widgets by reparenting to null.
|
|
|
|
while (splitter.count() > num)
|
|
|
|
splitter.widget(splitter.count() - 1)->setParent(nullptr);
|
2019-05-10 18:51:25 +00:00
|
|
|
|
2021-01-27 21:06:41 +00:00
|
|
|
setQuadrantWidget(splitter, left, 0);
|
|
|
|
setQuadrantWidget(splitter, right, left.widget != nullptr ? 1 : 0);
|
2015-02-09 17:42:32 +00:00
|
|
|
}
|
2015-02-09 19:10:08 +00:00
|
|
|
|
2020-12-17 22:13:06 +00:00
|
|
|
bool MainWindow::userMayChangeAppState() const
|
|
|
|
{
|
2021-02-14 19:59:02 +00:00
|
|
|
return applicationState[(int)appState].allowUserChange;
|
2020-12-17 22:13:06 +00:00
|
|
|
}
|
|
|
|
|
2022-09-18 13:25:41 +00:00
|
|
|
// For the dive-site list view and the dive-site edit states,
|
|
|
|
// we remember the previous state and then switch back to that.
|
|
|
|
void MainWindow::enterPreviousState()
|
|
|
|
{
|
|
|
|
if (state_stack.empty())
|
|
|
|
setApplicationState(ApplicationState::Default);
|
|
|
|
ApplicationState prev = state_stack.back();
|
|
|
|
state_stack.pop_back();
|
|
|
|
setApplicationState(prev);
|
|
|
|
}
|
|
|
|
|
2019-05-10 17:51:43 +00:00
|
|
|
void MainWindow::setApplicationState(ApplicationState state)
|
2019-02-23 17:31:02 +00:00
|
|
|
{
|
2021-02-14 19:59:02 +00:00
|
|
|
if (appState == state)
|
2015-02-09 19:10:08 +00:00
|
|
|
return;
|
|
|
|
|
desktop: remove the view-state
There was the "application state", which decided what to show
in the "quadrants" and the "view state" which decided which
quadrant to show. These interacted in a hard-to-grasp way.
The "view state" is used to show the map or dive list in
full screen.
I simply couldn't get these two orthogonal states to interact
properly. Moreover the thing was buggy: If a quadrant was hidden,
the user could still show it, by dragging from the side of the
window, at least under KDE.
To solve these woes, merge the two states into a single
application state. If the widget of a quadrant is set to null,
don't show it. So the four "view states" are now "application
states" where three of the four quadrants are not shown.
This also changes the memory management of the widgets:
widgets that are not shown are now removed from the QSplitter
objects. This makes it possible that the same widget is
shown in *different* quadrants.
While writing this, I stumbled upon a Qt bug, which is known
since 2014:
https://forum.qt.io/topic/43176/qsplitter-sizes-return-0
When restoring the quadrant sizes there was a test whether
the quadrant size is 0. If that was the case, a default size
was set. This seems not to work if the widgets were recently
added. Since this test now always fails, make the quadrants
non-collapsible and thus guarantee that 0 is never saved as
a size.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-17 21:27:40 +00:00
|
|
|
saveSplitterSizes();
|
|
|
|
|
2021-02-14 19:59:02 +00:00
|
|
|
appState = state;
|
2015-08-12 10:06:52 +00:00
|
|
|
|
2021-01-27 21:06:41 +00:00
|
|
|
clearSplitter(*topSplitter);
|
|
|
|
clearSplitter(*bottomSplitter);
|
2019-05-10 18:51:25 +00:00
|
|
|
const Quadrants &quadrants = applicationState[(int)state];
|
2021-01-27 21:06:41 +00:00
|
|
|
setQuadrantWidgets(*topSplitter, quadrants.topLeft, quadrants.topRight);
|
|
|
|
setQuadrantWidgets(*bottomSplitter, quadrants.bottomLeft, quadrants.bottomRight);
|
|
|
|
|
desktop: remove the view-state
There was the "application state", which decided what to show
in the "quadrants" and the "view state" which decided which
quadrant to show. These interacted in a hard-to-grasp way.
The "view state" is used to show the map or dive list in
full screen.
I simply couldn't get these two orthogonal states to interact
properly. Moreover the thing was buggy: If a quadrant was hidden,
the user could still show it, by dragging from the side of the
window, at least under KDE.
To solve these woes, merge the two states into a single
application state. If the widget of a quadrant is set to null,
don't show it. So the four "view states" are now "application
states" where three of the four quadrants are not shown.
This also changes the memory management of the widgets:
widgets that are not shown are now removed from the QSplitter
objects. This makes it possible that the same widget is
shown in *different* quadrants.
While writing this, I stumbled upon a Qt bug, which is known
since 2014:
https://forum.qt.io/topic/43176/qsplitter-sizes-return-0
When restoring the quadrant sizes there was a test whether
the quadrant size is 0. If that was the case, a default size
was set. This seems not to work if the widgets were recently
added. Since this test now always fails, make the quadrants
non-collapsible and thus guarantee that 0 is never saved as
a size.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-17 21:27:40 +00:00
|
|
|
if (topSplitter->count() >= 1) {
|
2021-01-27 21:06:41 +00:00
|
|
|
// Add topSplitter if it is not already shown
|
|
|
|
if (ui.mainSplitter->count() == 0 ||
|
|
|
|
ui.mainSplitter->widget(0) != topSplitter.get()) {
|
|
|
|
ui.mainSplitter->insertWidget(0, topSplitter.get());
|
|
|
|
ui.mainSplitter->setCollapsible(ui.mainSplitter->count() - 1, false);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Remove topSplitter by reparenting it. So weird.
|
|
|
|
topSplitter->setParent(nullptr);
|
desktop: remove the view-state
There was the "application state", which decided what to show
in the "quadrants" and the "view state" which decided which
quadrant to show. These interacted in a hard-to-grasp way.
The "view state" is used to show the map or dive list in
full screen.
I simply couldn't get these two orthogonal states to interact
properly. Moreover the thing was buggy: If a quadrant was hidden,
the user could still show it, by dragging from the side of the
window, at least under KDE.
To solve these woes, merge the two states into a single
application state. If the widget of a quadrant is set to null,
don't show it. So the four "view states" are now "application
states" where three of the four quadrants are not shown.
This also changes the memory management of the widgets:
widgets that are not shown are now removed from the QSplitter
objects. This makes it possible that the same widget is
shown in *different* quadrants.
While writing this, I stumbled upon a Qt bug, which is known
since 2014:
https://forum.qt.io/topic/43176/qsplitter-sizes-return-0
When restoring the quadrant sizes there was a test whether
the quadrant size is 0. If that was the case, a default size
was set. This seems not to work if the widgets were recently
added. Since this test now always fails, make the quadrants
non-collapsible and thus guarantee that 0 is never saved as
a size.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-17 21:27:40 +00:00
|
|
|
}
|
2021-01-27 21:06:41 +00:00
|
|
|
|
desktop: remove the view-state
There was the "application state", which decided what to show
in the "quadrants" and the "view state" which decided which
quadrant to show. These interacted in a hard-to-grasp way.
The "view state" is used to show the map or dive list in
full screen.
I simply couldn't get these two orthogonal states to interact
properly. Moreover the thing was buggy: If a quadrant was hidden,
the user could still show it, by dragging from the side of the
window, at least under KDE.
To solve these woes, merge the two states into a single
application state. If the widget of a quadrant is set to null,
don't show it. So the four "view states" are now "application
states" where three of the four quadrants are not shown.
This also changes the memory management of the widgets:
widgets that are not shown are now removed from the QSplitter
objects. This makes it possible that the same widget is
shown in *different* quadrants.
While writing this, I stumbled upon a Qt bug, which is known
since 2014:
https://forum.qt.io/topic/43176/qsplitter-sizes-return-0
When restoring the quadrant sizes there was a test whether
the quadrant size is 0. If that was the case, a default size
was set. This seems not to work if the widgets were recently
added. Since this test now always fails, make the quadrants
non-collapsible and thus guarantee that 0 is never saved as
a size.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-17 21:27:40 +00:00
|
|
|
if (bottomSplitter->count() >= 1) {
|
2021-01-27 21:06:41 +00:00
|
|
|
// Add bottomSplitter if it is not already shown
|
|
|
|
if (ui.mainSplitter->count() == 0 ||
|
|
|
|
ui.mainSplitter->widget(ui.mainSplitter->count() - 1) != bottomSplitter.get()) {
|
|
|
|
ui.mainSplitter->addWidget(bottomSplitter.get());
|
|
|
|
ui.mainSplitter->setCollapsible(ui.mainSplitter->count() - 1, false);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Remove bottomSplitter by reparenting it. So weird.
|
|
|
|
bottomSplitter->setParent(nullptr);
|
desktop: remove the view-state
There was the "application state", which decided what to show
in the "quadrants" and the "view state" which decided which
quadrant to show. These interacted in a hard-to-grasp way.
The "view state" is used to show the map or dive list in
full screen.
I simply couldn't get these two orthogonal states to interact
properly. Moreover the thing was buggy: If a quadrant was hidden,
the user could still show it, by dragging from the side of the
window, at least under KDE.
To solve these woes, merge the two states into a single
application state. If the widget of a quadrant is set to null,
don't show it. So the four "view states" are now "application
states" where three of the four quadrants are not shown.
This also changes the memory management of the widgets:
widgets that are not shown are now removed from the QSplitter
objects. This makes it possible that the same widget is
shown in *different* quadrants.
While writing this, I stumbled upon a Qt bug, which is known
since 2014:
https://forum.qt.io/topic/43176/qsplitter-sizes-return-0
When restoring the quadrant sizes there was a test whether
the quadrant size is 0. If that was the case, a default size
was set. This seems not to work if the widgets were recently
added. Since this test now always fails, make the quadrants
non-collapsible and thus guarantee that 0 is never saved as
a size.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-17 21:27:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
restoreSplitterSizes();
|
2020-12-17 22:13:06 +00:00
|
|
|
|
|
|
|
bool allowChange = userMayChangeAppState();
|
|
|
|
ui.actionViewAll->setEnabled(allowChange);
|
|
|
|
ui.actionViewList->setEnabled(allowChange);
|
|
|
|
ui.actionViewProfile->setEnabled(allowChange);
|
|
|
|
ui.actionViewInfo->setEnabled(allowChange);
|
|
|
|
ui.actionViewMap->setEnabled(allowChange);
|
2022-09-18 11:49:29 +00:00
|
|
|
ui.actionViewDiveSites->setEnabled(allowChange);
|
2020-12-17 22:13:06 +00:00
|
|
|
ui.actionFilterTags->setEnabled(allowChange);
|
2015-02-09 19:10:08 +00:00
|
|
|
}
|
2015-08-25 19:49:48 +00:00
|
|
|
|
2015-09-09 20:02:39 +00:00
|
|
|
void MainWindow::showProgressBar()
|
2015-08-25 19:49:48 +00:00
|
|
|
{
|
2015-10-09 21:19:10 +00:00
|
|
|
delete progressDialog;
|
2015-09-09 20:02:39 +00:00
|
|
|
|
|
|
|
progressDialog = new QProgressDialog(tr("Contacting cloud service..."), tr("Cancel"), 0, 100, this);
|
|
|
|
progressDialog->setWindowModality(Qt::WindowModal);
|
2017-06-18 06:22:37 +00:00
|
|
|
progressDialog->setMinimumDuration(0);
|
2015-09-09 20:02:39 +00:00
|
|
|
progressDialogCanceled = false;
|
2017-06-18 08:46:49 +00:00
|
|
|
progressCounter = 0;
|
2015-09-09 20:02:39 +00:00
|
|
|
connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelCloudStorageOperation()));
|
2015-08-25 19:49:48 +00:00
|
|
|
}
|
|
|
|
|
2015-09-09 20:02:39 +00:00
|
|
|
void MainWindow::cancelCloudStorageOperation()
|
2015-08-25 19:49:48 +00:00
|
|
|
{
|
2015-09-09 20:02:39 +00:00
|
|
|
progressDialogCanceled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::hideProgressBar()
|
|
|
|
{
|
|
|
|
if (progressDialog) {
|
|
|
|
progressDialog->setValue(100);
|
2018-05-25 21:08:18 +00:00
|
|
|
delete progressDialog;
|
2018-09-15 15:25:10 +00:00
|
|
|
progressDialog = nullptr;
|
2015-09-09 20:02:39 +00:00
|
|
|
}
|
2015-08-25 19:49:48 +00:00
|
|
|
}
|
2018-03-17 09:48:45 +00:00
|
|
|
|
2024-01-16 16:39:19 +00:00
|
|
|
void MainWindow::divesChanged(const QVector<dive *> &dives, DiveField)
|
2020-02-18 01:16:11 +00:00
|
|
|
{
|
|
|
|
for (struct dive *d: dives) {
|
2024-03-26 19:23:50 +00:00
|
|
|
report_info("dive #%d changed, cache is %s", d->number, dive_cache_is_valid(d) ? "valid" : "invalidated");
|
2020-02-18 01:16:11 +00:00
|
|
|
// a brute force way to deal with that would of course be to call
|
|
|
|
// invalidate_dive_cache(d);
|
|
|
|
}
|
|
|
|
}
|