| 
									
										
										
										
											2013-04-13 20:44:02 -07:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * mainwindow.cpp | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * classes for the main UI window in Subsurface | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-04-07 15:20:43 -07:00
										 |  |  | #include "mainwindow.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QVBoxLayout>
 | 
					
						
							| 
									
										
										
										
											2013-04-13 10:17:59 -03:00
										 |  |  | #include <QFileDialog>
 | 
					
						
							|  |  |  | #include <QMessageBox>
 | 
					
						
							| 
									
										
										
										
											2013-04-09 09:35:44 +01:00
										 |  |  | #include <QtDebug>
 | 
					
						
							| 
									
										
										
										
											2013-04-18 08:59:32 +01:00
										 |  |  | #include <QDateTime>
 | 
					
						
							| 
									
										
										
										
											2013-04-27 10:09:57 +01:00
										 |  |  | #include <QSettings>
 | 
					
						
							|  |  |  | #include <QCloseEvent>
 | 
					
						
							| 
									
										
										
										
											2013-05-02 14:05:53 -07:00
										 |  |  | #include <QApplication>
 | 
					
						
							|  |  |  | #include <QFontMetrics>
 | 
					
						
							| 
									
										
										
										
											2013-06-17 20:02:30 -03:00
										 |  |  | #include <QTableView>
 | 
					
						
							| 
									
										
										
										
											2013-10-04 12:28:40 -03:00
										 |  |  | #include <QDesktopWidget>
 | 
					
						
							| 
									
										
										
										
											2013-12-05 14:02:25 +02:00
										 |  |  | #include <QDesktopServices>
 | 
					
						
							| 
									
										
										
										
											2014-02-13 22:48:07 +01:00
										 |  |  | #include <QStringList>
 | 
					
						
							|  |  |  | #include <QSettings>
 | 
					
						
							| 
									
										
										
										
											2014-04-25 07:37:47 +03:00
										 |  |  | #include <QShortcut>
 | 
					
						
							| 
									
										
										
										
											2014-08-22 22:26:07 -03:00
										 |  |  | #include <QToolBar>
 | 
					
						
							| 
									
										
										
										
											2014-05-25 15:56:39 -03:00
										 |  |  | #include <fcntl.h>
 | 
					
						
							| 
									
										
										
										
											2013-04-12 08:24:07 +01:00
										 |  |  | #include "divelistview.h"
 | 
					
						
							| 
									
										
										
										
											2013-04-22 16:00:27 -07:00
										 |  |  | #include "starwidget.h"
 | 
					
						
							| 
									
										
										
										
											2014-06-13 10:56:46 -07:00
										 |  |  | #include "ssrf-version.h"
 | 
					
						
							| 
									
										
										
										
											2014-04-11 10:51:07 +02:00
										 |  |  | #include "dive.h"
 | 
					
						
							|  |  |  | #include "display.h"
 | 
					
						
							|  |  |  | #include "divelist.h"
 | 
					
						
							|  |  |  | #include "pref.h"
 | 
					
						
							|  |  |  | #include "helpers.h"
 | 
					
						
							| 
									
										
										
										
											2013-04-27 12:27:27 -03:00
										 |  |  | #include "modeldelegates.h"
 | 
					
						
							| 
									
										
										
										
											2013-05-02 20:32:57 -03:00
										 |  |  | #include "models.h"
 | 
					
						
							| 
									
										
										
										
											2013-05-20 16:43:33 -03:00
										 |  |  | #include "downloadfromdivecomputer.h"
 | 
					
						
							| 
									
										
										
										
											2013-05-24 15:19:48 -03:00
										 |  |  | #include "preferences.h"
 | 
					
						
							| 
									
										
										
										
											2013-06-06 10:33:15 -03:00
										 |  |  | #include "subsurfacewebservices.h"
 | 
					
						
							| 
									
										
										
										
											2013-06-07 11:43:45 -03:00
										 |  |  | #include "divecomputermanagementdialog.h"
 | 
					
						
							| 
									
										
										
										
											2013-06-17 13:41:00 -03:00
										 |  |  | #include "simplewidgets.h"
 | 
					
						
							| 
									
										
										
										
											2013-06-20 12:33:26 -03:00
										 |  |  | #include "diveplanner.h"
 | 
					
						
							| 
									
										
										
										
											2013-06-24 14:36:38 +03:00
										 |  |  | #include "about.h"
 | 
					
						
							| 
									
										
										
										
											2014-03-30 22:14:56 +02:00
										 |  |  | #include "worldmap-save.h"
 | 
					
						
							| 
									
										
										
										
											2014-04-02 22:41:39 +03:00
										 |  |  | #include "updatemanager.h"
 | 
					
						
							| 
									
										
										
										
											2014-06-04 23:34:09 +02:00
										 |  |  | #include "planner.h"
 | 
					
						
							| 
									
										
										
										
											2014-05-29 18:54:19 +03:00
										 |  |  | #include "configuredivecomputerdialog.h"
 | 
					
						
							| 
									
										
										
										
											2014-08-25 15:46:08 -03:00
										 |  |  | #include "statistics/statisticswidget.h"
 | 
					
						
							| 
									
										
										
										
											2014-03-26 23:36:06 +01:00
										 |  |  | #ifndef NO_PRINTING
 | 
					
						
							| 
									
										
										
										
											2014-06-23 15:43:51 +02:00
										 |  |  | #include <QPrintDialog>
 | 
					
						
							| 
									
										
										
										
											2013-07-09 15:37:53 +03:00
										 |  |  | #include "printdialog.h"
 | 
					
						
							| 
									
										
										
										
											2014-03-26 23:36:06 +01:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2013-12-29 18:11:20 +02:00
										 |  |  | #include "divelogimportdialog.h"
 | 
					
						
							| 
									
										
										
										
											2014-05-20 19:33:32 +03:00
										 |  |  | #include "divelogexportdialog.h"
 | 
					
						
							| 
									
										
										
										
											2014-06-13 10:56:46 -07:00
										 |  |  | #include "usersurvey.h"
 | 
					
						
							| 
									
										
										
										
											2014-03-26 23:35:24 +01:00
										 |  |  | #ifndef NO_USERMANUAL
 | 
					
						
							|  |  |  | #include "usermanual.h"
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2014-06-26 20:20:34 +04:00
										 |  |  | #include <QNetworkProxy>
 | 
					
						
							| 
									
										
										
										
											2013-04-13 10:17:59 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-12 15:22:54 +01:00
										 |  |  | MainWindow *MainWindow::m_Instance = NULL; | 
					
						
							| 
									
										
										
										
											2013-05-19 00:09:36 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 20:04:21 +01:00
										 |  |  | MainWindow::MainWindow() : QMainWindow(), | 
					
						
							|  |  |  | 	actionNextDive(0), | 
					
						
							|  |  |  | 	actionPreviousDive(0), | 
					
						
							|  |  |  | 	helpView(0), | 
					
						
							| 
									
										
										
										
											2014-04-02 12:56:14 -07:00
										 |  |  | 	state(VIEWALL), | 
					
						
							| 
									
										
										
										
											2014-05-27 15:02:45 -07:00
										 |  |  | 	updateManager(0), | 
					
						
							| 
									
										
										
										
											2014-06-13 10:56:46 -07:00
										 |  |  | 	survey(0) | 
					
						
							| 
									
										
										
										
											2013-04-07 15:20:43 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-18 16:47:21 -08:00
										 |  |  | 	Q_ASSERT_X(m_Instance == NULL, "MainWindow", "MainWindow recreated!"); | 
					
						
							| 
									
										
										
										
											2014-02-12 15:22:54 +01:00
										 |  |  | 	m_Instance = this; | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 	ui.setupUi(this); | 
					
						
							| 
									
										
										
										
											2014-10-31 15:22:21 -02:00
										 |  |  | 	ui.multiFilter->hide(); | 
					
						
							| 
									
										
										
										
											2014-08-22 22:26:07 -03:00
										 |  |  | 	profileToolbarActions << ui.profCalcAllTissues << ui.profCalcCeiling << ui.profDcCeiling << ui.profEad << | 
					
						
							|  |  |  | 		    ui.profHR << ui.profIncrement3m << ui.profMod << ui.profNdl_tts << ui.profNdl_tts << | 
					
						
							|  |  |  | 		    ui.profPhe << ui.profPn2 << ui.profPO2 << ui.profRuler << ui.profSAC << ui.profScaled << | 
					
						
							| 
									
										
										
										
											2014-09-15 14:09:00 +02:00
										 |  |  | 		    ui.profTogglePicture << ui.profTankbar << ui.profTissues; | 
					
						
							| 
									
										
										
										
											2013-04-25 20:44:06 -03:00
										 |  |  | 	setWindowIcon(QIcon(":subsurface-icon")); | 
					
						
							| 
									
										
										
										
											2014-06-28 12:14:36 +04:00
										 |  |  | 	if (!QIcon::hasThemeIcon("window-close")) { | 
					
						
							|  |  |  | 		QIcon::setThemeName("subsurface"); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 	connect(ui.ListWidget, SIGNAL(currentDiveChanged(int)), this, SLOT(current_dive_changed(int))); | 
					
						
							| 
									
										
										
										
											2013-05-26 11:33:45 -07:00
										 |  |  | 	connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(readSettings())); | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 	connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), ui.ListWidget, SLOT(update())); | 
					
						
							|  |  |  | 	connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), ui.ListWidget, SLOT(reloadHeaderActions())); | 
					
						
							| 
									
										
										
										
											2013-11-19 23:08:20 -08:00
										 |  |  | 	connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), ui.InfoWidget, SLOT(updateDiveInfo())); | 
					
						
							| 
									
										
										
										
											2013-12-09 07:43:00 +01:00
										 |  |  | 	connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), ui.divePlannerWidget, SLOT(settingsChanged())); | 
					
						
							| 
									
										
										
										
											2014-06-27 11:43:11 +02:00
										 |  |  | 	connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), ui.plannerSettingsWidget, SLOT(settingsChanged())); | 
					
						
							| 
									
										
										
										
											2014-01-11 21:57:06 +07:00
										 |  |  | 	connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), TankInfoModel::instance(), SLOT(update())); | 
					
						
							| 
									
										
										
										
											2014-02-13 22:48:07 +01:00
										 |  |  | 	connect(ui.actionRecent1, SIGNAL(triggered(bool)), this, SLOT(recentFileTriggered(bool))); | 
					
						
							|  |  |  | 	connect(ui.actionRecent2, SIGNAL(triggered(bool)), this, SLOT(recentFileTriggered(bool))); | 
					
						
							|  |  |  | 	connect(ui.actionRecent3, SIGNAL(triggered(bool)), this, SLOT(recentFileTriggered(bool))); | 
					
						
							|  |  |  | 	connect(ui.actionRecent4, SIGNAL(triggered(bool)), this, SLOT(recentFileTriggered(bool))); | 
					
						
							| 
									
										
										
										
											2014-05-21 20:34:06 -03:00
										 |  |  | 	connect(information(), SIGNAL(addDiveFinished()), ui.newProfile, SLOT(setProfileState())); | 
					
						
							| 
									
										
										
										
											2014-07-16 19:23:02 -03:00
										 |  |  | 	connect(DivePlannerPointsModel::instance(), SIGNAL(planCreated()), this, SLOT(planCreated())); | 
					
						
							|  |  |  | 	connect(DivePlannerPointsModel::instance(), SIGNAL(planCanceled()), this, SLOT(planCanceled())); | 
					
						
							| 
									
										
										
										
											2014-06-26 17:04:39 +02:00
										 |  |  | 	connect(ui.printPlan, SIGNAL(pressed()), ui.divePlannerWidget, SLOT(printDecoPlan())); | 
					
						
							|  |  |  | #ifdef NO_PRINTING
 | 
					
						
							|  |  |  | 	ui.printPlan->hide(); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 	ui.mainErrorMessage->hide(); | 
					
						
							| 
									
										
										
										
											2014-07-10 13:50:49 -03:00
										 |  |  | 	ui.newProfile->setEmptyState(); | 
					
						
							| 
									
										
										
										
											2013-06-04 21:40:09 +09:00
										 |  |  | 	initialUiSetup(); | 
					
						
							| 
									
										
										
										
											2013-05-21 18:29:23 -07:00
										 |  |  | 	readSettings(); | 
					
						
							| 
									
										
										
										
											2013-11-08 20:30:17 -02:00
										 |  |  | 	ui.ListWidget->reload(DiveTripModel::TREE); | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 	ui.ListWidget->reloadHeaderActions(); | 
					
						
							|  |  |  | 	ui.ListWidget->setFocus(); | 
					
						
							|  |  |  | 	ui.globe->reload(); | 
					
						
							| 
									
										
										
										
											2014-02-13 22:11:05 -08:00
										 |  |  | 	ui.ListWidget->expand(ui.ListWidget->model()->index(0, 0)); | 
					
						
							|  |  |  | 	ui.ListWidget->scrollTo(ui.ListWidget->model()->index(0, 0), QAbstractItemView::PositionAtCenter); | 
					
						
							| 
									
										
										
										
											2013-12-09 07:43:00 +01:00
										 |  |  | 	ui.divePlannerWidget->settingsChanged(); | 
					
						
							| 
									
										
										
										
											2014-06-27 11:43:11 +02:00
										 |  |  | 	ui.plannerSettingsWidget->settingsChanged(); | 
					
						
							| 
									
										
										
										
											2014-03-26 23:08:56 +01:00
										 |  |  | #ifdef NO_MARBLE
 | 
					
						
							| 
									
										
										
										
											2014-06-17 20:01:14 +02:00
										 |  |  | 	ui.globePane->hide(); | 
					
						
							| 
									
										
										
										
											2014-03-26 23:08:56 +01:00
										 |  |  | 	ui.menuView->removeAction(ui.actionViewGlobe); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2014-03-26 23:35:24 +01:00
										 |  |  | #ifdef NO_USERMANUAL
 | 
					
						
							|  |  |  | 	ui.menuHelp->removeAction(ui.actionUserManual); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2014-03-26 23:36:06 +01:00
										 |  |  | #ifdef NO_PRINTING
 | 
					
						
							|  |  |  | 	ui.menuFile->removeAction(ui.actionPrint); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2014-08-16 09:32:23 -06:00
										 |  |  | 	memset(©PasteDive, 0, sizeof(copyPasteDive)); | 
					
						
							|  |  |  | 	memset(&what, 0, sizeof(what)); | 
					
						
							| 
									
										
										
										
											2014-08-22 22:26:07 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	QToolBar *toolBar = new QToolBar(); | 
					
						
							| 
									
										
										
										
											2014-09-17 15:39:49 -07:00
										 |  |  | 	Q_FOREACH (QAction *a, profileToolbarActions) | 
					
						
							| 
									
										
										
										
											2014-08-22 22:26:07 -03:00
										 |  |  | 		toolBar->addAction(a); | 
					
						
							|  |  |  | 	toolBar->setOrientation(Qt::Vertical); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// since I'm adding the toolBar by hand, because designer
 | 
					
						
							|  |  |  | 	// has no concept of "toolbar" for a non-mainwindow widget (...)
 | 
					
						
							|  |  |  | 	// I need to take the current item that's in the toolbar Position
 | 
					
						
							|  |  |  | 	// and reposition it alongside the grid layout.
 | 
					
						
							|  |  |  | 	QLayoutItem *p = ui.gridLayout->takeAt(0); | 
					
						
							| 
									
										
										
										
											2014-09-17 15:39:49 -07:00
										 |  |  | 	ui.gridLayout->addWidget(toolBar, 0, 0); | 
					
						
							| 
									
										
										
										
											2014-08-22 22:26:07 -03:00
										 |  |  | 	ui.gridLayout->addItem(p, 0, 1); | 
					
						
							| 
									
										
										
										
											2013-05-14 08:18:26 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-12 15:22:54 +01:00
										 |  |  | MainWindow::~MainWindow() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_Instance = NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-11 18:54:28 -03:00
										 |  |  | void MainWindow::setLoadedWithFiles(bool f) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	filesAsArguments = f; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool MainWindow::filesFromCommandLine() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return filesAsArguments; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-12 15:22:54 +01:00
										 |  |  | MainWindow *MainWindow::instance() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return m_Instance; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-30 17:58:59 +09:00
										 |  |  | // this gets called after we download dives from a divecomputer
 | 
					
						
							| 
									
										
										
										
											2014-05-18 19:08:58 +09:00
										 |  |  | void MainWindow::refreshDisplay(bool doRecreateDiveList) | 
					
						
							| 
									
										
										
										
											2013-05-30 17:58:59 +09:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-03-14 11:26:07 -07:00
										 |  |  | 	showError(get_error_string()); | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 	ui.InfoWidget->reload(); | 
					
						
							| 
									
										
										
										
											2013-12-28 14:56:01 -08:00
										 |  |  | 	TankInfoModel::instance()->update(); | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 	ui.globe->reload(); | 
					
						
							| 
									
										
										
										
											2014-05-18 19:08:58 +09:00
										 |  |  | 	if (doRecreateDiveList) | 
					
						
							|  |  |  | 		recreateDiveList(); | 
					
						
							| 
									
										
										
										
											2014-05-31 20:59:36 -07:00
										 |  |  | 	ui.diveListPane->setCurrentIndex(0); // switch to the dive list
 | 
					
						
							| 
									
										
										
										
											2014-06-17 20:01:14 +02:00
										 |  |  | #ifdef NO_MARBLE
 | 
					
						
							|  |  |  | 	ui.globePane->hide(); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2014-06-10 17:40:02 +02:00
										 |  |  | 	ui.globePane->setCurrentIndex(0); | 
					
						
							| 
									
										
										
										
											2014-05-27 15:10:22 -07:00
										 |  |  | 	ui.ListWidget->setEnabled(true); | 
					
						
							| 
									
										
										
										
											2014-05-27 15:32:45 -07:00
										 |  |  | 	ui.ListWidget->setFocus(); | 
					
						
							| 
									
										
										
										
											2013-11-16 18:58:31 -02:00
										 |  |  | 	WSInfoModel::instance()->updateInfo(); | 
					
						
							| 
									
										
										
										
											2014-05-28 10:14:40 -07:00
										 |  |  | 	if (amount_selected == 0) | 
					
						
							|  |  |  | 		cleanUpEmpty(); | 
					
						
							| 
									
										
										
										
											2013-05-30 17:58:59 +09:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 19:08:58 +09:00
										 |  |  | void MainWindow::recreateDiveList() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ui.ListWidget->reload(DiveTripModel::CURRENT); | 
					
						
							| 
									
										
										
										
											2014-09-17 15:45:18 -03:00
										 |  |  | 	TagFilterModel::instance()->repopulate(); | 
					
						
							| 
									
										
										
										
											2014-10-31 16:49:52 -02:00
										 |  |  | 	BuddyFilterModel::instance()->repopulate(); | 
					
						
							| 
									
										
										
										
											2014-10-31 17:42:56 -02:00
										 |  |  | 	LocationFilterModel::instance()->repopulate(); | 
					
						
							| 
									
										
										
										
											2014-05-18 19:08:58 +09:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-14 08:18:26 -03:00
										 |  |  | void MainWindow::current_dive_changed(int divenr) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-06-05 09:51:40 +09:00
										 |  |  | 	if (divenr >= 0) { | 
					
						
							| 
									
										
										
										
											2013-05-31 21:05:33 +09:00
										 |  |  | 		select_dive(divenr); | 
					
						
							| 
									
										
										
										
											2014-05-07 13:58:07 -07:00
										 |  |  | 		ui.globe->centerOnCurrentDive(); | 
					
						
							| 
									
										
										
										
											2013-05-31 21:05:33 +09:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-07-02 20:00:57 -07:00
										 |  |  | 	ui.newProfile->plotDive(); | 
					
						
							| 
									
										
										
										
											2014-07-02 12:58:41 -07:00
										 |  |  | 	ui.InfoWidget->updateDiveInfo(); | 
					
						
							| 
									
										
										
										
											2014-01-15 18:13:20 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-09 09:35:44 +01:00
										 |  |  | void MainWindow::on_actionNew_triggered() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-06-26 15:07:50 +03:00
										 |  |  | 	on_actionClose_triggered(); | 
					
						
							| 
									
										
										
										
											2013-04-09 09:35:44 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::on_actionOpen_triggered() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-08 19:46:43 -07:00
										 |  |  | 	if (!okToClose(tr("Please save or cancel the current dive edit before opening a new file."))) | 
					
						
							| 
									
										
										
										
											2013-11-15 13:42:49 -08:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2014-06-08 19:46:43 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-11 00:06:48 +01:00
										 |  |  | 	QString filename = QFileDialog::getOpenFileName(this, tr("Open file"), lastUsedDir(), filter()); | 
					
						
							| 
									
										
										
										
											2013-04-27 20:47:47 -07:00
										 |  |  | 	if (filename.isEmpty()) | 
					
						
							| 
									
										
										
										
											2013-04-13 10:17:59 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2013-11-14 13:51:05 -02:00
										 |  |  | 	updateLastUsedDir(QFileInfo(filename).dir().path()); | 
					
						
							| 
									
										
										
										
											2014-06-08 19:46:43 -07:00
										 |  |  | 	closeCurrentFile(); | 
					
						
							| 
									
										
										
										
											2014-02-13 22:11:05 -08:00
										 |  |  | 	loadFiles(QStringList() << filename); | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::on_actionSave_triggered() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-05-19 15:25:47 -07:00
										 |  |  | 	file_save(); | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::on_actionSaveAs_triggered() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-05-19 15:25:47 -07:00
										 |  |  | 	file_save_as(); | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-09-22 22:24:28 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | ProfileWidget2 *MainWindow::graphics() const | 
					
						
							| 
									
										
										
										
											2014-03-07 12:42:13 -03:00
										 |  |  | { | 
					
						
							|  |  |  | 	return ui.newProfile; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-22 22:24:28 -07:00
										 |  |  | void MainWindow::cleanUpEmpty() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 	ui.InfoWidget->clearStats(); | 
					
						
							|  |  |  | 	ui.InfoWidget->clearInfo(); | 
					
						
							|  |  |  | 	ui.InfoWidget->clearEquipment(); | 
					
						
							| 
									
										
										
										
											2014-07-02 14:15:17 -07:00
										 |  |  | 	ui.InfoWidget->updateDiveInfo(true); | 
					
						
							| 
									
										
										
										
											2014-03-07 12:42:13 -03:00
										 |  |  | 	ui.newProfile->setEmptyState(); | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 	ui.ListWidget->reload(DiveTripModel::TREE); | 
					
						
							|  |  |  | 	ui.globe->reload(); | 
					
						
							| 
									
										
										
										
											2013-12-05 14:38:12 +02:00
										 |  |  | 	if (!existing_filename) | 
					
						
							|  |  |  | 		setTitle(MWTF_DEFAULT); | 
					
						
							| 
									
										
										
										
											2014-07-16 13:09:14 +04:00
										 |  |  | 	disableDcShortcuts(); | 
					
						
							| 
									
										
										
										
											2013-09-22 22:24:28 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-08 19:46:43 -07:00
										 |  |  | bool MainWindow::okToClose(QString message) | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 	if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING || | 
					
						
							|  |  |  | 	    ui.InfoWidget->isEditing()) { | 
					
						
							| 
									
										
										
										
											2014-06-08 19:46:43 -07:00
										 |  |  | 		QMessageBox::warning(this, tr("Warning"), message); | 
					
						
							|  |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2013-11-15 13:42:49 -08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-06-08 19:46:43 -07:00
										 |  |  | 	if (unsaved_changes() && askSaveChanges() == false) | 
					
						
							|  |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2013-04-13 10:17:59 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-08 19:46:43 -07:00
										 |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::closeCurrentFile() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-11 10:03:08 -08:00
										 |  |  | 	ui.newProfile->setEmptyState(); | 
					
						
							| 
									
										
										
										
											2013-04-13 10:17:59 -03:00
										 |  |  | 	/* free the dives and trips */ | 
					
						
							| 
									
										
										
										
											2014-03-13 15:42:45 -07:00
										 |  |  | 	clear_git_id(); | 
					
						
							| 
									
										
										
										
											2013-04-13 10:17:59 -03:00
										 |  |  | 	while (dive_table.nr) | 
					
						
							|  |  |  | 		delete_single_dive(0); | 
					
						
							| 
									
										
										
										
											2013-04-27 20:47:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-12 14:58:15 -03:00
										 |  |  | 	free((void *)existing_filename); | 
					
						
							|  |  |  | 	existing_filename = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-22 22:24:28 -07:00
										 |  |  | 	cleanUpEmpty(); | 
					
						
							| 
									
										
										
										
											2014-01-15 09:30:42 +01:00
										 |  |  | 	mark_divelist_changed(false); | 
					
						
							| 
									
										
										
										
											2013-04-13 10:17:59 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	clear_events(); | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-08 19:46:43 -07:00
										 |  |  | void MainWindow::on_actionClose_triggered() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (okToClose(tr("Please save or cancel the current dive edit before closing the file."))) | 
					
						
							|  |  |  | 		closeCurrentFile(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-14 13:42:26 -02:00
										 |  |  | QString MainWindow::lastUsedDir() | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-06-25 13:35:04 +03:00
										 |  |  | 	QSettings settings; | 
					
						
							|  |  |  | 	QString lastDir = QDir::homePath(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	settings.beginGroup("FileDialog"); | 
					
						
							|  |  |  | 	if (settings.contains("LastDir")) | 
					
						
							|  |  |  | 		if (QDir::setCurrent(settings.value("LastDir").toString())) | 
					
						
							|  |  |  | 			lastDir = settings.value("LastDir").toString(); | 
					
						
							| 
									
										
										
										
											2013-11-14 13:42:26 -02:00
										 |  |  | 	return lastDir; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-06-25 13:35:04 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-13 22:11:05 -08:00
										 |  |  | void MainWindow::updateLastUsedDir(const QString &dir) | 
					
						
							| 
									
										
										
										
											2013-11-14 13:42:26 -02:00
										 |  |  | { | 
					
						
							|  |  |  | 	QSettings s; | 
					
						
							|  |  |  | 	s.beginGroup("FileDialog"); | 
					
						
							|  |  |  | 	s.setValue("LastDir", dir); | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::on_actionPrint_triggered() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-03-26 23:36:06 +01:00
										 |  |  | #ifndef NO_PRINTING
 | 
					
						
							| 
									
										
										
										
											2014-02-08 20:12:13 +01:00
										 |  |  | 	PrintDialog dlg(this); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dlg.exec(); | 
					
						
							| 
									
										
										
										
											2014-03-26 23:36:06 +01:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-04 12:30:05 -03:00
										 |  |  | void MainWindow::disableDcShortcuts() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 	ui.actionPreviousDC->setShortcut(QKeySequence()); | 
					
						
							|  |  |  | 	ui.actionNextDC->setShortcut(QKeySequence()); | 
					
						
							| 
									
										
										
										
											2013-07-04 12:30:05 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::enableDcShortcuts() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 	ui.actionPreviousDC->setShortcut(Qt::Key_Left); | 
					
						
							|  |  |  | 	ui.actionNextDC->setShortcut(Qt::Key_Right); | 
					
						
							| 
									
										
										
										
											2013-07-04 12:30:05 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-27 14:48:03 -03:00
										 |  |  | void MainWindow::showProfile() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-07-04 12:30:05 -03:00
										 |  |  | 	enableDcShortcuts(); | 
					
						
							| 
									
										
										
										
											2014-05-27 15:44:47 -07:00
										 |  |  | 	ui.newProfile->setProfileState(); | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 	ui.infoPane->setCurrentIndex(MAINTAB); | 
					
						
							| 
									
										
										
										
											2013-06-20 18:48:21 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | void MainWindow::on_actionPreferences_triggered() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-05-24 15:19:48 -03:00
										 |  |  | 	PreferencesDialog::instance()->show(); | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::on_actionQuit_triggered() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-05-06 15:56:28 +02:00
										 |  |  | 	if (ui.InfoWidget->isEditing()) { | 
					
						
							| 
									
										
										
										
											2014-06-03 18:17:32 -07:00
										 |  |  | 		ui.InfoWidget->rejectChanges(); | 
					
						
							|  |  |  | 		if (ui.InfoWidget->isEditing()) | 
					
						
							|  |  |  | 			// didn't discard the edits
 | 
					
						
							|  |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2013-11-17 15:46:27 -08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-05-06 15:56:28 +02:00
										 |  |  | 	if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING) { | 
					
						
							|  |  |  | 		DivePlannerPointsModel::instance()->cancelPlan(); | 
					
						
							|  |  |  | 		if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING) | 
					
						
							|  |  |  | 			// The planned dive was not discarded
 | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-15 09:30:42 +01:00
										 |  |  | 	if (unsaved_changes() && (askSaveChanges() == false)) | 
					
						
							| 
									
										
										
										
											2013-04-27 10:09:57 +01:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2013-05-03 16:30:36 -07:00
										 |  |  | 	writeSettings(); | 
					
						
							|  |  |  | 	QApplication::quit(); | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::on_actionDownloadDC_triggered() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-08 20:22:09 +01:00
										 |  |  | 	DownloadFromDCWidget dlg(this); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dlg.exec(); | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::on_actionDownloadWeb_triggered() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-09 17:51:19 +01:00
										 |  |  | 	SubsurfaceWebServices dlg(this); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dlg.exec(); | 
					
						
							| 
									
										
										
										
											2013-06-06 10:33:15 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-24 23:02:59 -02:00
										 |  |  | void MainWindow::on_actionDivelogs_de_triggered() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-11-14 18:57:09 -08:00
										 |  |  | 	DivelogsDeWebServices::instance()->downloadDives(); | 
					
						
							| 
									
										
										
										
											2013-10-24 23:02:59 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | void MainWindow::on_actionEditDeviceNames_triggered() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-06-17 15:58:26 -07:00
										 |  |  | 	DiveComputerManagementDialog::instance()->init(); | 
					
						
							| 
									
										
										
										
											2013-06-07 11:43:45 -03:00
										 |  |  | 	DiveComputerManagementDialog::instance()->update(); | 
					
						
							|  |  |  | 	DiveComputerManagementDialog::instance()->show(); | 
					
						
							| 
									
										
										
										
											2013-06-10 15:34:57 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-25 15:19:36 -03:00
										 |  |  | bool MainWindow::plannerStateClean() | 
					
						
							| 
									
										
										
										
											2014-05-25 15:15:57 -03:00
										 |  |  | { | 
					
						
							|  |  |  | 	if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING || | 
					
						
							|  |  |  | 	    ui.InfoWidget->isEditing()) { | 
					
						
							| 
									
										
										
										
											2014-05-25 15:19:36 -03: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 15:15:57 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-05-25 15:19:36 -03:00
										 |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-28 15:43:32 -03:00
										 |  |  | void MainWindow::planCanceled() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-08-19 15:53:36 -05:00
										 |  |  | 	// while planning we might have modified the displayed_dive
 | 
					
						
							|  |  |  | 	// let's refresh what's shown on the profile
 | 
					
						
							| 
									
										
										
										
											2014-05-28 15:43:32 -03:00
										 |  |  | 	showProfile(); | 
					
						
							| 
									
										
										
										
											2014-08-19 15:53:36 -05:00
										 |  |  | 	ui.newProfile->replot(); | 
					
						
							| 
									
										
										
										
											2014-07-06 12:36:25 -07:00
										 |  |  | 	refreshDisplay(false); | 
					
						
							| 
									
										
										
										
											2014-07-16 19:29:01 -03:00
										 |  |  | 	ui.newProfile->plotDive(get_dive(selected_dive)); | 
					
						
							| 
									
										
										
										
											2014-08-02 22:05:52 +02:00
										 |  |  | 	DivePictureModel::instance()->updateDivePictures(); | 
					
						
							| 
									
										
										
										
											2014-05-28 15:43:32 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-28 15:54:04 -03:00
										 |  |  | void MainWindow::planCreated() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-08-18 14:12:05 -05:00
										 |  |  | 	// get the new dive selected and assign a number if reasonable
 | 
					
						
							| 
									
										
										
										
											2014-08-19 21:13:09 -05:00
										 |  |  | 	ui.newProfile->setProfileState(); | 
					
						
							| 
									
										
										
										
											2014-08-19 15:03:53 -05:00
										 |  |  | 	if (displayed_dive.id == 0) { | 
					
						
							|  |  |  | 		// we might have added a new dive (so displayed_dive was cleared out by clone_dive()
 | 
					
						
							|  |  |  | 		dive_list()->unselectDives(); | 
					
						
							|  |  |  | 		select_dive(dive_table.nr - 1); | 
					
						
							|  |  |  | 		dive_list()->selectDive(selected_dive); | 
					
						
							|  |  |  | 		set_dive_nr_for_current_dive(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-10-27 12:35:19 -07:00
										 |  |  | 	// make sure our UI is in a consistent state
 | 
					
						
							|  |  |  | 	ui.InfoWidget->updateDiveInfo(); | 
					
						
							| 
									
										
										
										
											2014-05-28 15:54:04 -03:00
										 |  |  | 	showProfile(); | 
					
						
							|  |  |  | 	refreshDisplay(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-31 21:14:44 -07:00
										 |  |  | void MainWindow::setPlanNotes(const char *notes) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-03 09:35:19 +02:00
										 |  |  | 	ui.divePlanOutput->setHtml(notes); | 
					
						
							| 
									
										
										
										
											2014-05-31 21:14:44 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-03 10:06:18 +02:00
										 |  |  | void MainWindow::printPlan() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-23 15:43:51 +02:00
										 |  |  | #ifndef NO_PRINTING
 | 
					
						
							| 
									
										
										
										
											2014-06-04 23:34:09 +02:00
										 |  |  | 	QString diveplan = ui.divePlanOutput->toHtml(); | 
					
						
							| 
									
										
										
										
											2014-07-01 09:57:54 +02:00
										 |  |  | 	QString withDisclaimer = QString("<img height=50 src=\":subsurface-icon\"> ") + diveplan + QString(disclaimer); | 
					
						
							| 
									
										
										
										
											2014-06-04 23:34:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-03 10:06:18 +02:00
										 |  |  | 	QPrinter printer; | 
					
						
							|  |  |  | 	QPrintDialog *dialog = new QPrintDialog(&printer, this); | 
					
						
							|  |  |  | 	dialog->setWindowTitle(tr("Print runtime table")); | 
					
						
							|  |  |  | 	if (dialog->exec() != QDialog::Accepted) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-04 23:34:09 +02:00
										 |  |  | 	ui.divePlanOutput->setHtml(withDisclaimer); | 
					
						
							| 
									
										
										
										
											2014-06-03 10:06:18 +02:00
										 |  |  | 	ui.divePlanOutput->print(&printer); | 
					
						
							| 
									
										
										
										
											2014-06-04 23:34:09 +02:00
										 |  |  | 	ui.divePlanOutput->setHtml(diveplan); | 
					
						
							| 
									
										
										
										
											2014-06-23 15:43:51 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2014-06-03 10:06:18 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-04 07:14:16 -07:00
										 |  |  | void MainWindow::setupForAddAndPlan(const char *model) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// clean out the dive and give it an id and the correct dc model
 | 
					
						
							|  |  |  | 	clear_dive(&displayed_dive); | 
					
						
							|  |  |  | 	displayed_dive.id = dive_getUniqID(&displayed_dive); | 
					
						
							|  |  |  | 	displayed_dive.when = QDateTime::currentMSecsSinceEpoch() / 1000L + gettimezoneoffset() + 3600; | 
					
						
							|  |  |  | 	displayed_dive.dc.model = model; // don't translate! this is stored in the XML file
 | 
					
						
							|  |  |  | 	// setup the dive cylinders
 | 
					
						
							|  |  |  | 	DivePlannerPointsModel::instance()->clear(); | 
					
						
							|  |  |  | 	DivePlannerPointsModel::instance()->setupCylinders(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-19 15:03:53 -05:00
										 |  |  | void MainWindow::on_actionReplanDive_triggered() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (!plannerStateClean()) | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2014-10-25 11:33:31 +03:00
										 |  |  | 	if (!current_dive || !current_dive->dc.model || strcmp(current_dive->dc.model, "planned dive")) { | 
					
						
							| 
									
										
										
										
											2014-10-27 12:35:19 -07:00
										 |  |  | 		qDebug() << "trying to replan a dive that's not a planned dive:" << current_dive->dc.model; | 
					
						
							| 
									
										
										
										
											2014-08-19 15:03:53 -05:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	// put us in PLAN mode
 | 
					
						
							| 
									
										
										
										
											2014-08-19 15:49:18 -05:00
										 |  |  | 	DivePlannerPointsModel::instance()->clear(); | 
					
						
							| 
									
										
										
										
											2014-08-19 15:03:53 -05:00
										 |  |  | 	DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ui.newProfile->setPlanState(); | 
					
						
							| 
									
										
										
										
											2014-08-19 21:54:18 -05:00
										 |  |  | 	ui.newProfile->clearHandlers(); | 
					
						
							| 
									
										
										
										
											2014-08-19 15:03:53 -05:00
										 |  |  | 	ui.infoPane->setCurrentIndex(PLANNERWIDGET); | 
					
						
							| 
									
										
										
										
											2014-11-04 12:15:27 +01:00
										 |  |  | 	ui.divePlannerWidget->setReplanButton(true); | 
					
						
							| 
									
										
										
										
											2014-08-19 15:03:53 -05:00
										 |  |  | 	DivePlannerPointsModel::instance()->loadFromDive(current_dive); | 
					
						
							|  |  |  | 	reset_cylinders(&displayed_dive, true); | 
					
						
							|  |  |  | 	ui.diveListPane->setCurrentIndex(1); // switch to the plan output
 | 
					
						
							|  |  |  | 	ui.globePane->setCurrentIndex(1); | 
					
						
							|  |  |  | #ifdef NO_MARBLE
 | 
					
						
							|  |  |  | 	ui.globePane->show(); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-25 15:19:36 -03:00
										 |  |  | void MainWindow::on_actionDivePlanner_triggered() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-08-19 15:03:53 -05:00
										 |  |  | 	if (!plannerStateClean()) | 
					
						
							| 
									
										
										
										
											2014-05-25 15:19:36 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-27 11:32:18 -07:00
										 |  |  | 	// put us in PLAN mode
 | 
					
						
							| 
									
										
										
										
											2014-05-26 17:43:52 -03:00
										 |  |  | 	DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN); | 
					
						
							| 
									
										
										
										
											2014-07-04 06:53:33 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-25 15:15:57 -03:00
										 |  |  | 	ui.newProfile->setPlanState(); | 
					
						
							|  |  |  | 	ui.infoPane->setCurrentIndex(PLANNERWIDGET); | 
					
						
							| 
									
										
										
										
											2014-05-27 11:32:18 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// create a simple starting dive, using the first gas from the just copied cylidners
 | 
					
						
							| 
									
										
										
										
											2014-07-04 07:14:16 -07:00
										 |  |  | 	setupForAddAndPlan("planned dive"); // don't translate, stored in XML file
 | 
					
						
							| 
									
										
										
										
											2014-06-28 08:07:28 -07:00
										 |  |  | 	DivePlannerPointsModel::instance()->setupStartTime(); | 
					
						
							| 
									
										
										
										
											2014-05-27 11:28:42 -07:00
										 |  |  | 	DivePlannerPointsModel::instance()->createSimpleDive(); | 
					
						
							| 
									
										
										
										
											2014-08-02 22:05:52 +02:00
										 |  |  | 	DivePictureModel::instance()->updateDivePictures(); | 
					
						
							| 
									
										
										
										
											2014-11-04 12:15:27 +01:00
										 |  |  | 	ui.divePlannerWidget->setReplanButton(false); | 
					
						
							| 
									
										
										
										
											2014-05-27 15:10:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-31 20:59:36 -07:00
										 |  |  | 	ui.diveListPane->setCurrentIndex(1); // switch to the plan output
 | 
					
						
							| 
									
										
										
										
											2014-06-10 17:40:02 +02:00
										 |  |  | 	ui.globePane->setCurrentIndex(1); | 
					
						
							| 
									
										
										
										
											2014-06-17 20:01:14 +02:00
										 |  |  | #ifdef NO_MARBLE
 | 
					
						
							|  |  |  | 	ui.globePane->show(); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2014-05-25 15:15:57 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | void MainWindow::on_actionAddDive_triggered() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-09-17 15:39:49 -07:00
										 |  |  | 	if (!plannerStateClean()) | 
					
						
							| 
									
										
										
										
											2013-11-08 22:09:46 -02:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2014-05-25 15:19:36 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-17 15:39:49 -07:00
										 |  |  | 	if (dive_list()->selectedTrips().count() >= 1) { | 
					
						
							| 
									
										
										
										
											2014-07-16 19:44:06 -03:00
										 |  |  | 		dive_list()->rememberSelection(); | 
					
						
							|  |  |  | 		dive_list()->clearSelection(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-08 22:09:46 -02:00
										 |  |  | 	DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD); | 
					
						
							| 
									
										
										
										
											2013-11-12 16:33:27 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-04 07:14:16 -07:00
										 |  |  | 	// setup things so we can later create our starting dive
 | 
					
						
							|  |  |  | 	setupForAddAndPlan("manually added dive"); // don't translate, stored in the XML file
 | 
					
						
							| 
									
										
										
										
											2014-07-03 14:45:01 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// now show the mostly empty main tab
 | 
					
						
							|  |  |  | 	ui.InfoWidget->updateDiveInfo(); | 
					
						
							| 
									
										
										
										
											2013-12-03 21:25:20 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-03 14:45:01 -07:00
										 |  |  | 	// show main tab
 | 
					
						
							| 
									
										
										
										
											2013-11-14 12:18:33 +09:00
										 |  |  | 	ui.InfoWidget->setCurrentIndex(0); | 
					
						
							| 
									
										
										
										
											2014-07-03 14:45:01 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-12 16:33:27 +09:00
										 |  |  | 	ui.InfoWidget->addDiveStarted(); | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 	ui.infoPane->setCurrentIndex(MAINTAB); | 
					
						
							| 
									
										
										
										
											2014-05-21 23:31:26 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ui.newProfile->setAddState(); | 
					
						
							| 
									
										
										
										
											2013-09-20 07:36:14 -05:00
										 |  |  | 	DivePlannerPointsModel::instance()->createSimpleDive(); | 
					
						
							| 
									
										
										
										
											2014-07-03 14:45:01 -07:00
										 |  |  | 	ui.newProfile->plotDive(); | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::on_actionRenumber_triggered() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-05-20 06:11:32 +09:00
										 |  |  | 	RenumberDialog::instance()->renumberOnlySelected(false); | 
					
						
							| 
									
										
										
										
											2013-06-17 13:41:00 -03:00
										 |  |  | 	RenumberDialog::instance()->show(); | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::on_actionAutoGroup_triggered() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-10-17 16:30:32 -07:00
										 |  |  | 	autogroup = ui.actionAutoGroup->isChecked(); | 
					
						
							|  |  |  | 	if (autogroup) | 
					
						
							|  |  |  | 		autogroup_dives(); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		remove_autogen_trips(); | 
					
						
							|  |  |  | 	refreshDisplay(); | 
					
						
							|  |  |  | 	mark_divelist_changed(true); | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::on_actionYearlyStatistics_triggered() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-08-25 15:46:08 -03:00
										 |  |  | 	QDialog d; | 
					
						
							| 
									
										
										
										
											2014-08-25 16:10:47 -03:00
										 |  |  | 	YearlyStatisticsWidget *newView = new YearlyStatisticsWidget(); | 
					
						
							| 
									
										
										
										
											2014-08-25 15:46:08 -03:00
										 |  |  | 	QVBoxLayout *l = new QVBoxLayout(&d); | 
					
						
							| 
									
										
										
										
											2014-08-25 16:10:47 -03:00
										 |  |  | 	l->addWidget(newView); | 
					
						
							| 
									
										
										
										
											2014-08-25 15:48:26 -03:00
										 |  |  | 	YearlyStatisticsModel *m = new YearlyStatisticsModel(); | 
					
						
							|  |  |  | 	QTreeView *view = new QTreeView(); | 
					
						
							|  |  |  | 	view->setModel(m); | 
					
						
							| 
									
										
										
										
											2014-08-25 16:10:47 -03:00
										 |  |  | 	newView->setModel(m); | 
					
						
							| 
									
										
										
										
											2014-08-25 15:48:26 -03:00
										 |  |  | 	l->addWidget(view); | 
					
						
							| 
									
										
										
										
											2014-08-25 15:46:08 -03:00
										 |  |  | 	d.exec(); | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-12 15:54:55 -03:00
										 |  |  | #define BEHAVIOR QList<int>()
 | 
					
						
							| 
									
										
										
										
											2014-10-31 14:00:52 -02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define TOGGLE_COLLAPSABLE( X ) \
 | 
					
						
							|  |  |  | 	ui.mainSplitter->setCollapsible(0, X); \ | 
					
						
							|  |  |  | 	ui.mainSplitter->setCollapsible(1, X); \ | 
					
						
							|  |  |  | 	ui.infoProfileSplitter->setCollapsible(0, X); \ | 
					
						
							|  |  |  | 	ui.infoProfileSplitter->setCollapsible(1, X); \ | 
					
						
							|  |  |  | 	ui.listGlobeSplitter->setCollapsible(0, X); \ | 
					
						
							|  |  |  | 	ui.listGlobeSplitter->setCollapsible(1, X); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | void MainWindow::on_actionViewList_triggered() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-10-31 14:00:52 -02:00
										 |  |  | 	TOGGLE_COLLAPSABLE( true ); | 
					
						
							| 
									
										
										
										
											2013-11-07 11:37:27 -05:00
										 |  |  | 	beginChangeState(LIST_MAXIMIZED); | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 	ui.listGlobeSplitter->setSizes(BEHAVIOR << EXPANDED << COLLAPSED); | 
					
						
							|  |  |  | 	ui.mainSplitter->setSizes(BEHAVIOR << COLLAPSED << EXPANDED); | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::on_actionViewProfile_triggered() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-10-31 14:00:52 -02:00
										 |  |  | 	TOGGLE_COLLAPSABLE( true ); | 
					
						
							| 
									
										
										
										
											2013-11-07 11:37:27 -05:00
										 |  |  | 	beginChangeState(PROFILE_MAXIMIZED); | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 	ui.infoProfileSplitter->setSizes(BEHAVIOR << COLLAPSED << EXPANDED); | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 	ui.mainSplitter->setSizes(BEHAVIOR << EXPANDED << COLLAPSED); | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::on_actionViewInfo_triggered() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-10-31 14:00:52 -02:00
										 |  |  | 	TOGGLE_COLLAPSABLE( true ); | 
					
						
							| 
									
										
										
										
											2013-11-07 11:37:27 -05:00
										 |  |  | 	beginChangeState(INFO_MAXIMIZED); | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 	ui.infoProfileSplitter->setSizes(BEHAVIOR << EXPANDED << COLLAPSED); | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 	ui.mainSplitter->setSizes(BEHAVIOR << EXPANDED << COLLAPSED); | 
					
						
							| 
									
										
										
										
											2013-06-12 14:53:23 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::on_actionViewGlobe_triggered() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-10-31 14:00:52 -02:00
										 |  |  | 	TOGGLE_COLLAPSABLE( true ); | 
					
						
							| 
									
										
										
										
											2013-11-07 11:37:27 -05:00
										 |  |  | 	beginChangeState(GLOBE_MAXIMIZED); | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 	ui.mainSplitter->setSizes(BEHAVIOR << COLLAPSED << EXPANDED); | 
					
						
							|  |  |  | 	ui.listGlobeSplitter->setSizes(BEHAVIOR << COLLAPSED << EXPANDED); | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-06-12 15:54:55 -03:00
										 |  |  | #undef BEHAVIOR
 | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::on_actionViewAll_triggered() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-10-31 14:00:52 -02:00
										 |  |  | 	TOGGLE_COLLAPSABLE( false ); | 
					
						
							| 
									
										
										
										
											2013-11-07 11:37:27 -05:00
										 |  |  | 	beginChangeState(VIEWALL); | 
					
						
							| 
									
										
										
										
											2013-11-21 23:52:21 -02:00
										 |  |  | 	static QList<int> mainSizes; | 
					
						
							|  |  |  | 	const int appH = qApp->desktop()->size().height(); | 
					
						
							|  |  |  | 	const int appW = qApp->desktop()->size().width(); | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 	if (mainSizes.empty()) { | 
					
						
							|  |  |  | 		mainSizes.append(appH * 0.7); | 
					
						
							|  |  |  | 		mainSizes.append(appH * 0.3); | 
					
						
							| 
									
										
										
										
											2013-11-21 23:52:21 -02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	static QList<int> infoProfileSizes; | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 	if (infoProfileSizes.empty()) { | 
					
						
							|  |  |  | 		infoProfileSizes.append(appW * 0.3); | 
					
						
							|  |  |  | 		infoProfileSizes.append(appW * 0.7); | 
					
						
							| 
									
										
										
										
											2013-11-21 23:52:21 -02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	static QList<int> listGlobeSizes; | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 	if (listGlobeSizes.empty()) { | 
					
						
							|  |  |  | 		listGlobeSizes.append(appW * 0.7); | 
					
						
							|  |  |  | 		listGlobeSizes.append(appW * 0.3); | 
					
						
							| 
									
										
										
										
											2013-11-21 23:52:21 -02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-07 11:37:27 -05:00
										 |  |  | 	QSettings settings; | 
					
						
							|  |  |  | 	settings.beginGroup("MainWindow"); | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 	if (settings.value("mainSplitter").isValid()) { | 
					
						
							| 
									
										
										
										
											2013-11-07 11:37:27 -05:00
										 |  |  | 		ui.mainSplitter->restoreState(settings.value("mainSplitter").toByteArray()); | 
					
						
							|  |  |  | 		ui.infoProfileSplitter->restoreState(settings.value("infoProfileSplitter").toByteArray()); | 
					
						
							|  |  |  | 		ui.listGlobeSplitter->restoreState(settings.value("listGlobeSplitter").toByteArray()); | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 		if (ui.mainSplitter->sizes().first() == 0 || ui.mainSplitter->sizes().last() == 0) | 
					
						
							| 
									
										
										
										
											2013-11-21 23:52:21 -02:00
										 |  |  | 			ui.mainSplitter->setSizes(mainSizes); | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 		if (ui.infoProfileSplitter->sizes().first() == 0 || ui.infoProfileSplitter->sizes().last() == 0) | 
					
						
							| 
									
										
										
										
											2013-11-21 23:52:21 -02:00
										 |  |  | 			ui.infoProfileSplitter->setSizes(infoProfileSizes); | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 		if (ui.listGlobeSplitter->sizes().first() == 0 || ui.listGlobeSplitter->sizes().last() == 0) | 
					
						
							| 
									
										
										
										
											2013-11-21 23:52:21 -02:00
										 |  |  | 			ui.listGlobeSplitter->setSizes(listGlobeSizes); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-07 11:37:27 -05:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 		ui.mainSplitter->setSizes(mainSizes); | 
					
						
							| 
									
										
										
										
											2013-11-07 11:37:27 -05:00
										 |  |  | 		ui.infoProfileSplitter->setSizes(infoProfileSizes); | 
					
						
							|  |  |  | 		ui.listGlobeSplitter->setSizes(listGlobeSizes); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-10-31 14:00:52 -02:00
										 |  |  | 	ui.mainSplitter->setCollapsible(0, false); | 
					
						
							|  |  |  | 	ui.mainSplitter->setCollapsible(1, false); | 
					
						
							|  |  |  | 	ui.infoProfileSplitter->setCollapsible(0, false); | 
					
						
							|  |  |  | 	ui.infoProfileSplitter->setCollapsible(1, false); | 
					
						
							|  |  |  | 	ui.listGlobeSplitter->setCollapsible(0,false); | 
					
						
							|  |  |  | 	ui.listGlobeSplitter->setCollapsible(1,false); | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-31 14:00:52 -02:00
										 |  |  | #undef TOGGLE_COLLAPSABLE
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-13 22:11:05 -08:00
										 |  |  | void MainWindow::beginChangeState(CurrentState s) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 	if (state == VIEWALL && state != s) { | 
					
						
							| 
									
										
										
										
											2013-11-07 11:37:27 -05:00
										 |  |  | 		saveSplitterSizes(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	state = s; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-13 22:11:05 -08:00
										 |  |  | void MainWindow::saveSplitterSizes() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-11-07 11:37:27 -05:00
										 |  |  | 	QSettings settings; | 
					
						
							|  |  |  | 	settings.beginGroup("MainWindow"); | 
					
						
							|  |  |  | 	settings.setValue("mainSplitter", ui.mainSplitter->saveState()); | 
					
						
							|  |  |  | 	settings.setValue("infoProfileSplitter", ui.infoProfileSplitter->saveState()); | 
					
						
							|  |  |  | 	settings.setValue("listGlobeSplitter", ui.listGlobeSplitter->saveState()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | void MainWindow::on_actionPreviousDC_triggered() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-03-17 08:19:09 -07:00
										 |  |  | 	unsigned nrdc = number_of_computers(current_dive); | 
					
						
							|  |  |  | 	dc_number = (dc_number + nrdc - 1) % nrdc; | 
					
						
							| 
									
										
										
										
											2014-07-02 20:00:57 -07:00
										 |  |  | 	ui.newProfile->plotDive(); | 
					
						
							| 
									
										
										
										
											2014-07-02 12:58:41 -07:00
										 |  |  | 	ui.InfoWidget->updateDiveInfo(); | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::on_actionNextDC_triggered() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-03-17 08:19:09 -07:00
										 |  |  | 	unsigned nrdc = number_of_computers(current_dive); | 
					
						
							|  |  |  | 	dc_number = (dc_number + 1) % nrdc; | 
					
						
							| 
									
										
										
										
											2014-07-02 20:00:57 -07:00
										 |  |  | 	ui.newProfile->plotDive(); | 
					
						
							| 
									
										
										
										
											2014-07-02 12:58:41 -07:00
										 |  |  | 	ui.InfoWidget->updateDiveInfo(); | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-14 18:36:07 +01:00
										 |  |  | void MainWindow::on_actionFullScreen_triggered(bool checked) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (checked) { | 
					
						
							|  |  |  | 		setWindowState(windowState() | Qt::WindowFullScreen); | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2014-01-14 18:36:07 +01:00
										 |  |  | 		setWindowState(windowState() & ~Qt::WindowFullScreen); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | void MainWindow::on_actionAboutSubsurface_triggered() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-08 08:50:39 +01:00
										 |  |  | 	SubsurfaceAbout dlg(this); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dlg.exec(); | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-02 22:41:39 +03:00
										 |  |  | void MainWindow::on_action_Check_for_Updates_triggered() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-04-02 12:56:14 -07:00
										 |  |  | 	if (!updateManager) | 
					
						
							|  |  |  | 		updateManager = new UpdateManager(this); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-02 22:41:39 +03:00
										 |  |  | 	updateManager->checkForUpdates(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | void MainWindow::on_actionUserManual_triggered() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-03-26 23:35:24 +01:00
										 |  |  | #ifndef NO_USERMANUAL
 | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 	if (!helpView) { | 
					
						
							| 
									
										
										
										
											2014-06-30 17:45:52 -03:00
										 |  |  | 		helpView = new UserManual(); | 
					
						
							| 
									
										
										
										
											2013-05-31 06:26:08 +09:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-30 10:54:06 -03:00
										 |  |  | 	helpView->show(); | 
					
						
							| 
									
										
										
										
											2014-03-26 23:35:24 +01:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2013-04-09 17:26:23 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-04-13 10:17:59 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | QString MainWindow::filter() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QString f; | 
					
						
							| 
									
										
										
										
											2013-10-02 08:34:12 +02:00
										 |  |  | 	f += "ALL ( *.ssrf *.xml *.XML *.uddf *.udcf *.UDFC *.jlb *.JLB "; | 
					
						
							| 
									
										
										
										
											2013-04-13 10:17:59 -03:00
										 |  |  | 	f += "*.sde *.SDE *.dld *.DLD "; | 
					
						
							| 
									
										
										
										
											2014-10-28 15:27:14 -04:00
										 |  |  | 	f += "*.db *.can"; | 
					
						
							| 
									
										
										
										
											2013-04-13 10:17:59 -03:00
										 |  |  | 	f += ");;"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-02 08:34:12 +02:00
										 |  |  | 	f += "Subsurface (*.ssrf);;"; | 
					
						
							| 
									
										
										
										
											2013-04-13 10:17:59 -03:00
										 |  |  | 	f += "XML (*.xml *.XML);;"; | 
					
						
							|  |  |  | 	f += "UDDF (*.uddf);;"; | 
					
						
							|  |  |  | 	f += "UDCF (*.udcf *.UDCF);;"; | 
					
						
							|  |  |  | 	f += "JLB  (*.jlb *.JLB);;"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	f += "SDE (*.sde *.SDE);;"; | 
					
						
							|  |  |  | 	f += "DLD (*.dld *.DLD);;"; | 
					
						
							| 
									
										
										
										
											2014-10-28 15:27:14 -04:00
										 |  |  | 	f += "DB (*.db);;"; | 
					
						
							|  |  |  | 	f += "CAN (*.can)"; | 
					
						
							| 
									
										
										
										
											2013-04-13 10:17:59 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return f; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool MainWindow::askSaveChanges() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-05-19 14:46:53 -07:00
										 |  |  | 	QString message; | 
					
						
							| 
									
										
										
										
											2014-07-16 19:23:02 -03:00
										 |  |  | 	QMessageBox response(this); | 
					
						
							| 
									
										
										
										
											2013-04-13 10:17:59 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-19 14:46:53 -07:00
										 |  |  | 	if (existing_filename) | 
					
						
							| 
									
										
										
										
											2014-07-11 00:06:48 +01:00
										 |  |  | 		message = tr("Do you want to save the changes that you made in the file %1?").arg(existing_filename); | 
					
						
							| 
									
										
										
										
											2013-05-19 14:46:53 -07:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2014-07-11 09:21:38 +01:00
										 |  |  | 		message = tr("Do you want to save the changes that you made in the data file?"); | 
					
						
							| 
									
										
										
										
											2013-05-24 09:28:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	response.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); | 
					
						
							|  |  |  | 	response.setDefaultButton(QMessageBox::Save); | 
					
						
							|  |  |  | 	response.setText(message); | 
					
						
							| 
									
										
										
										
											2014-07-11 00:06:48 +01:00
										 |  |  | 	response.setWindowTitle(tr("Save changes?")); // Not displayed on MacOSX as described in Qt API
 | 
					
						
							| 
									
										
										
										
											2013-05-24 09:28:48 +02:00
										 |  |  | 	response.setInformativeText(tr("Changes will be lost if you don't save them.")); | 
					
						
							|  |  |  | 	response.setIcon(QMessageBox::Warning); | 
					
						
							| 
									
										
										
										
											2014-03-14 16:00:18 -07:00
										 |  |  | 	response.setWindowModality(Qt::WindowModal); | 
					
						
							| 
									
										
										
										
											2013-05-24 09:28:48 +02:00
										 |  |  | 	int ret = response.exec(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (ret) { | 
					
						
							|  |  |  | 	case QMessageBox::Save: | 
					
						
							| 
									
										
										
										
											2013-05-19 15:25:47 -07:00
										 |  |  | 		file_save(); | 
					
						
							| 
									
										
										
										
											2013-04-13 10:17:59 -03:00
										 |  |  | 		return true; | 
					
						
							| 
									
										
										
										
											2013-05-24 09:28:48 +02:00
										 |  |  | 	case QMessageBox::Discard: | 
					
						
							| 
									
										
										
										
											2013-05-19 14:46:53 -07:00
										 |  |  | 		return true; | 
					
						
							| 
									
										
										
										
											2013-04-13 10:17:59 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-04-27 10:09:57 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-04 21:40:09 +09:00
										 |  |  | void MainWindow::initialUiSetup() | 
					
						
							| 
									
										
										
										
											2013-04-27 10:09:57 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-05-21 23:07:19 -03:00
										 |  |  | 	QSettings settings; | 
					
						
							| 
									
										
										
										
											2013-04-28 10:05:37 +01:00
										 |  |  | 	settings.beginGroup("MainWindow"); | 
					
						
							| 
									
										
										
										
											2013-10-04 12:28:40 -03:00
										 |  |  | 	QSize sz = settings.value("size", qApp->desktop()->size()).value<QSize>(); | 
					
						
							| 
									
										
										
										
											2013-12-02 12:32:27 +02:00
										 |  |  | 	if (settings.value("maximized", isMaximized()).value<bool>()) | 
					
						
							|  |  |  | 		showMaximized(); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		resize(sz); | 
					
						
							| 
									
										
										
										
											2013-10-04 15:07:36 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-13 22:11:05 -08:00
										 |  |  | 	state = (CurrentState)settings.value("lastState", 0).toInt(); | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 	switch (state) { | 
					
						
							| 
									
										
										
										
											2014-02-13 22:11:05 -08:00
										 |  |  | 	case VIEWALL: | 
					
						
							|  |  |  | 		on_actionViewAll_triggered(); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case GLOBE_MAXIMIZED: | 
					
						
							|  |  |  | 		on_actionViewGlobe_triggered(); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case INFO_MAXIMIZED: | 
					
						
							|  |  |  | 		on_actionViewInfo_triggered(); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case LIST_MAXIMIZED: | 
					
						
							|  |  |  | 		on_actionViewList_triggered(); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case PROFILE_MAXIMIZED: | 
					
						
							|  |  |  | 		on_actionViewProfile_triggered(); | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2013-10-04 15:07:36 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-11-08 19:59:21 -02:00
										 |  |  | 	settings.endGroup(); | 
					
						
							| 
									
										
										
										
											2013-06-04 21:40:09 +09:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-12 11:52:59 -07:00
										 |  |  | const char *getSetting(QSettings &s, QString name) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QVariant v; | 
					
						
							|  |  |  | 	v = s.value(name); | 
					
						
							|  |  |  | 	if (v.isValid()) { | 
					
						
							|  |  |  | 		return strdup(v.toString().toUtf8().data()); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-02 22:37:29 +01:00
										 |  |  | #define TOOLBOX_PREF_BUTTON(pref, setting, button) \
 | 
					
						
							| 
									
										
										
										
											2014-03-03 13:25:55 -08:00
										 |  |  | 	prefs.pref = s.value(#setting).toBool();   \ | 
					
						
							| 
									
										
										
										
											2014-03-02 22:37:29 +01:00
										 |  |  | 	ui.button->setChecked(prefs.pref); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-04 21:40:09 +09:00
										 |  |  | void MainWindow::readSettings() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-30 14:42:48 -07:00
										 |  |  | 	static bool firstRun = true; | 
					
						
							| 
									
										
										
										
											2013-06-04 21:40:09 +09:00
										 |  |  | 	QSettings s; | 
					
						
							| 
									
										
										
										
											2014-08-27 06:39:57 -07:00
										 |  |  | 	// the static object for preferences already reads in the settings
 | 
					
						
							|  |  |  | 	// and sets up the font, so just get what we need for the toolbox and other widgets here
 | 
					
						
							| 
									
										
										
										
											2014-02-06 14:59:06 -02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	s.beginGroup("TecDetails"); | 
					
						
							| 
									
										
										
										
											2014-04-16 22:03:44 +02:00
										 |  |  | 	TOOLBOX_PREF_BUTTON(calcalltissues, calcalltissues, profCalcAllTissues); | 
					
						
							|  |  |  | 	TOOLBOX_PREF_BUTTON(calcceiling, calcceiling, profCalcCeiling); | 
					
						
							|  |  |  | 	TOOLBOX_PREF_BUTTON(dcceiling, dcceiling, profDcCeiling); | 
					
						
							| 
									
										
										
										
											2014-03-02 22:37:29 +01:00
										 |  |  | 	TOOLBOX_PREF_BUTTON(ead, ead, profEad); | 
					
						
							| 
									
										
										
										
											2014-04-16 22:03:44 +02:00
										 |  |  | 	TOOLBOX_PREF_BUTTON(calcceiling3m, calcceiling3m, profIncrement3m); | 
					
						
							| 
									
										
										
										
											2014-03-02 22:37:29 +01:00
										 |  |  | 	TOOLBOX_PREF_BUTTON(mod, mod, profMod); | 
					
						
							| 
									
										
										
										
											2014-04-16 22:03:44 +02:00
										 |  |  | 	TOOLBOX_PREF_BUTTON(calcndltts, calcndltts, profNdl_tts); | 
					
						
							| 
									
										
										
										
											2014-03-02 22:37:29 +01:00
										 |  |  | 	TOOLBOX_PREF_BUTTON(pp_graphs.phe, phegraph, profPhe); | 
					
						
							|  |  |  | 	TOOLBOX_PREF_BUTTON(pp_graphs.pn2, pn2graph, profPn2); | 
					
						
							|  |  |  | 	TOOLBOX_PREF_BUTTON(pp_graphs.po2, po2graph, profPO2); | 
					
						
							| 
									
										
										
										
											2014-04-16 22:03:44 +02:00
										 |  |  | 	TOOLBOX_PREF_BUTTON(hrgraph, hrgraph, profHR); | 
					
						
							| 
									
										
										
										
											2014-05-05 15:53:46 -07:00
										 |  |  | 	TOOLBOX_PREF_BUTTON(rulergraph, rulergraph, profRuler); | 
					
						
							| 
									
										
										
										
											2014-03-02 22:37:29 +01:00
										 |  |  | 	TOOLBOX_PREF_BUTTON(show_sac, show_sac, profSAC); | 
					
						
							| 
									
										
										
										
											2014-07-10 21:33:06 -03:00
										 |  |  | 	TOOLBOX_PREF_BUTTON(show_pictures_in_profile, show_pictures_in_profile, profTogglePicture); | 
					
						
							| 
									
										
										
										
											2014-08-15 08:11:14 -06:00
										 |  |  | 	TOOLBOX_PREF_BUTTON(tankbar, tankbar, profTankbar); | 
					
						
							| 
									
										
										
										
											2014-09-20 17:56:56 -03:00
										 |  |  | 	TOOLBOX_PREF_BUTTON(percentagegraph, percentagegraph, profTissues); | 
					
						
							| 
									
										
										
										
											2014-06-12 11:52:59 -07:00
										 |  |  | 	s.endGroup(); | 
					
						
							|  |  |  | 	s.beginGroup("DiveComputer"); | 
					
						
							|  |  |  | 	default_dive_computer_vendor = getSetting(s, "dive_computer_vendor"); | 
					
						
							|  |  |  | 	default_dive_computer_product = getSetting(s, "dive_computer_product"); | 
					
						
							|  |  |  | 	default_dive_computer_device = getSetting(s, "dive_computer_device"); | 
					
						
							|  |  |  | 	s.endGroup(); | 
					
						
							| 
									
										
										
										
											2014-06-26 20:20:34 +04:00
										 |  |  | 	QNetworkProxy proxy; | 
					
						
							|  |  |  | 	proxy.setType(QNetworkProxy::ProxyType(prefs.proxy_type)); | 
					
						
							|  |  |  | 	proxy.setHostName(prefs.proxy_host); | 
					
						
							|  |  |  | 	proxy.setPort(prefs.proxy_port); | 
					
						
							|  |  |  | 	if (prefs.proxy_auth) { | 
					
						
							|  |  |  | 		proxy.setUser(prefs.proxy_user); | 
					
						
							|  |  |  | 		proxy.setPassword(prefs.proxy_pass); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	QNetworkProxy::setApplicationProxy(proxy); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-12 11:52:59 -07:00
										 |  |  | 	loadRecentFiles(&s); | 
					
						
							| 
									
										
										
										
											2014-06-30 14:42:48 -07:00
										 |  |  | 	if (firstRun) { | 
					
						
							|  |  |  | 		checkSurvey(&s); | 
					
						
							|  |  |  | 		firstRun = false; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-04-27 10:09:57 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-02 22:37:29 +01:00
										 |  |  | #undef TOOLBOX_PREF_BUTTON
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-13 10:56:46 -07:00
										 |  |  | void MainWindow::checkSurvey(QSettings *s) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	s->beginGroup("UserSurvey"); | 
					
						
							|  |  |  | 	if (!s->contains("FirstUse42")) { | 
					
						
							|  |  |  | 		QVariant value = QDate().currentDate(); | 
					
						
							|  |  |  | 		s->setValue("FirstUse42", value); | 
					
						
							| 
									
										
										
										
											2014-06-14 14:45:42 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	// wait a week for production versions, but not at all for non-tagged builds
 | 
					
						
							|  |  |  | 	QString ver(VERSION_STRING); | 
					
						
							|  |  |  | 	int waitTime = ver.contains('-') ? -1 : 7; | 
					
						
							|  |  |  | 	QDate firstUse42 = s->value("FirstUse42").toDate(); | 
					
						
							|  |  |  | 	if (run_survey || (firstUse42.daysTo(QDate().currentDate()) > waitTime && !s->contains("SurveyDone"))) { | 
					
						
							|  |  |  | 		if (!survey) | 
					
						
							|  |  |  | 			survey = new UserSurvey(this); | 
					
						
							|  |  |  | 		survey->show(); | 
					
						
							| 
									
										
										
										
											2014-06-13 10:56:46 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	s->endGroup(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-27 10:09:57 +01:00
										 |  |  | void MainWindow::writeSettings() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-05-21 23:07:19 -03:00
										 |  |  | 	QSettings settings; | 
					
						
							| 
									
										
										
										
											2013-05-02 22:06:01 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-27 10:09:57 +01:00
										 |  |  | 	settings.beginGroup("MainWindow"); | 
					
						
							| 
									
										
										
										
											2014-02-13 22:11:05 -08:00
										 |  |  | 	settings.setValue("lastState", (int)state); | 
					
						
							| 
									
										
										
										
											2013-12-02 12:32:27 +02:00
										 |  |  | 	settings.setValue("maximized", isMaximized()); | 
					
						
							|  |  |  | 	if (!isMaximized()) | 
					
						
							|  |  |  | 		settings.setValue("size", size()); | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 	if (state == VIEWALL) | 
					
						
							| 
									
										
										
										
											2013-11-07 11:37:27 -05:00
										 |  |  | 		saveSplitterSizes(); | 
					
						
							| 
									
										
										
										
											2013-04-27 10:09:57 +01:00
										 |  |  | 	settings.endGroup(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::closeEvent(QCloseEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 	if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING || | 
					
						
							|  |  |  | 	    ui.InfoWidget->isEditing()) { | 
					
						
							| 
									
										
										
										
											2014-06-03 18:22:22 -07:00
										 |  |  | 		on_actionQuit_triggered(); | 
					
						
							| 
									
										
										
										
											2013-12-16 16:37:44 -08:00
										 |  |  | 		event->ignore(); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-24 23:43:43 +02:00
										 |  |  | #ifndef NO_USERMANUAL
 | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 	if (helpView && helpView->isVisible()) { | 
					
						
							| 
									
										
										
										
											2013-05-30 10:54:06 -03:00
										 |  |  | 		helpView->close(); | 
					
						
							|  |  |  | 		helpView->deleteLater(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-08-24 23:43:43 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2013-05-31 06:26:08 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-15 09:30:42 +01:00
										 |  |  | 	if (unsaved_changes() && (askSaveChanges() == false)) { | 
					
						
							| 
									
										
										
										
											2013-04-27 10:09:57 +01:00
										 |  |  | 		event->ignore(); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	event->accept(); | 
					
						
							|  |  |  | 	writeSettings(); | 
					
						
							| 
									
										
										
										
											2014-03-11 18:31:01 +02:00
										 |  |  | 	QApplication::closeAllWindows(); | 
					
						
							| 
									
										
										
										
											2013-04-27 20:47:47 -07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-05-19 00:09:36 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-13 22:11:05 -08:00
										 |  |  | DiveListView *MainWindow::dive_list() | 
					
						
							| 
									
										
										
										
											2013-05-19 00:09:36 -03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 	return ui.ListWidget; | 
					
						
							| 
									
										
										
										
											2013-05-19 00:09:36 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-13 22:11:05 -08:00
										 |  |  | GlobeGPS *MainWindow::globe() | 
					
						
							| 
									
										
										
										
											2013-05-19 00:09:36 -03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 	return ui.globe; | 
					
						
							| 
									
										
										
										
											2013-05-19 00:09:36 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-13 22:11:05 -08:00
										 |  |  | MainTab *MainWindow::information() | 
					
						
							| 
									
										
										
										
											2013-05-19 00:09:36 -03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 	return ui.InfoWidget; | 
					
						
							| 
									
										
										
										
											2013-05-19 00:09:36 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-05-19 15:25:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-13 22:48:07 +01:00
										 |  |  | void MainWindow::loadRecentFiles(QSettings *s) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QStringList files; | 
					
						
							|  |  |  | 	bool modified = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	s->beginGroup("Recent_Files"); | 
					
						
							| 
									
										
										
										
											2014-02-13 22:11:05 -08:00
										 |  |  | 	for (int c = 1; c <= 4; c++) { | 
					
						
							| 
									
										
										
										
											2014-02-13 22:48:07 +01:00
										 |  |  | 		QString key = QString("File_%1").arg(c); | 
					
						
							| 
									
										
										
										
											2014-02-13 22:11:05 -08:00
										 |  |  | 		if (s->contains(key)) { | 
					
						
							| 
									
										
										
										
											2014-02-13 22:48:07 +01:00
										 |  |  | 			QString file = s->value(key).toString(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-13 22:11:05 -08:00
										 |  |  | 			if (QFile::exists(file)) { | 
					
						
							| 
									
										
										
										
											2014-02-13 22:48:07 +01:00
										 |  |  | 				files.append(file); | 
					
						
							| 
									
										
										
										
											2014-02-13 22:11:05 -08:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2014-02-13 22:48:07 +01:00
										 |  |  | 				modified = true; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-02-13 22:11:05 -08:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2014-02-13 22:48:07 +01:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-13 22:11:05 -08:00
										 |  |  | 	if (modified) { | 
					
						
							|  |  |  | 		for (int c = 0; c < 4; c++) { | 
					
						
							| 
									
										
										
										
											2014-02-13 22:48:07 +01:00
										 |  |  | 			QString key = QString("File_%1").arg(c + 1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-13 22:11:05 -08:00
										 |  |  | 			if (files.count() > c) { | 
					
						
							| 
									
										
										
										
											2014-02-13 22:48:07 +01:00
										 |  |  | 				s->setValue(key, files.at(c)); | 
					
						
							| 
									
										
										
										
											2014-02-13 22:11:05 -08:00
										 |  |  | 			} else { | 
					
						
							|  |  |  | 				if (s->contains(key)) { | 
					
						
							| 
									
										
										
										
											2014-02-13 22:48:07 +01:00
										 |  |  | 					s->remove(key); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		s->sync(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	s->endGroup(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-13 22:11:05 -08:00
										 |  |  | 	for (int c = 0; c < 4; c++) { | 
					
						
							| 
									
										
										
										
											2014-02-13 22:48:07 +01:00
										 |  |  | 		QAction *action = this->findChild<QAction *>(QString("actionRecent%1").arg(c + 1)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-13 22:11:05 -08:00
										 |  |  | 		if (files.count() > c) { | 
					
						
							| 
									
										
										
										
											2014-02-13 22:48:07 +01:00
										 |  |  | 			QFileInfo fi(files.at(c)); | 
					
						
							|  |  |  | 			action->setText(fi.fileName()); | 
					
						
							|  |  |  | 			action->setToolTip(fi.absoluteFilePath()); | 
					
						
							|  |  |  | 			action->setVisible(true); | 
					
						
							| 
									
										
										
										
											2014-02-13 22:11:05 -08:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2014-02-13 22:48:07 +01:00
										 |  |  | 			action->setVisible(false); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::addRecentFile(const QStringList &newFiles) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QStringList files; | 
					
						
							|  |  |  | 	QSettings s; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-28 12:04:00 +03:00
										 |  |  | 	if (newFiles.isEmpty()) | 
					
						
							| 
									
										
										
										
											2014-02-13 22:48:07 +01:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	s.beginGroup("Recent_Files"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-13 22:11:05 -08:00
										 |  |  | 	for (int c = 1; c <= 4; c++) { | 
					
						
							| 
									
										
										
										
											2014-02-13 22:48:07 +01:00
										 |  |  | 		QString key = QString("File_%1").arg(c); | 
					
						
							| 
									
										
										
										
											2014-02-13 22:11:05 -08:00
										 |  |  | 		if (s.contains(key)) { | 
					
						
							| 
									
										
										
										
											2014-02-13 22:48:07 +01:00
										 |  |  | 			QString file = s.value(key).toString(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			files.append(file); | 
					
						
							| 
									
										
										
										
											2014-02-13 22:11:05 -08:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2014-02-13 22:48:07 +01:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 	foreach (const QString &file, newFiles) { | 
					
						
							| 
									
										
										
										
											2014-08-02 22:52:46 +02:00
										 |  |  | 		int index = files.indexOf(QDir::toNativeSeparators(file)); | 
					
						
							| 
									
										
										
										
											2014-02-13 22:48:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-13 22:11:05 -08:00
										 |  |  | 		if (index >= 0) { | 
					
						
							| 
									
										
										
										
											2014-02-13 22:48:07 +01:00
										 |  |  | 			files.removeAt(index); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 	foreach (const QString &file, newFiles) { | 
					
						
							| 
									
										
										
										
											2014-02-13 22:11:05 -08:00
										 |  |  | 		if (QFile::exists(file)) { | 
					
						
							| 
									
										
										
										
											2014-08-02 22:52:46 +02:00
										 |  |  | 			files.prepend(QDir::toNativeSeparators(file)); | 
					
						
							| 
									
										
										
										
											2014-02-13 22:48:07 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-13 22:11:05 -08:00
										 |  |  | 	while (files.count() > 4) { | 
					
						
							| 
									
										
										
										
											2014-02-13 22:48:07 +01:00
										 |  |  | 		files.removeLast(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-28 12:04:00 +03:00
										 |  |  | 	for (int c = 1; c <= 4; c++) { | 
					
						
							|  |  |  | 		QString key = QString("File_%1").arg(c); | 
					
						
							| 
									
										
										
										
											2014-02-13 22:48:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-28 12:04:00 +03:00
										 |  |  | 		if (files.count() >= c) { | 
					
						
							|  |  |  | 			s.setValue(key, files.at(c - 1)); | 
					
						
							| 
									
										
										
										
											2014-02-13 22:11:05 -08:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			if (s.contains(key)) { | 
					
						
							| 
									
										
										
										
											2014-02-13 22:48:07 +01:00
										 |  |  | 				s.remove(key); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	s.endGroup(); | 
					
						
							|  |  |  | 	s.sync(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	loadRecentFiles(&s); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-28 12:04:00 +03:00
										 |  |  | void MainWindow::removeRecentFile(QStringList failedFiles) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QStringList files; | 
					
						
							|  |  |  | 	QSettings s; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (failedFiles.isEmpty()) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	s.beginGroup("Recent_Files"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (int c = 1; c <= 4; c++) { | 
					
						
							|  |  |  | 		QString key = QString("File_%1").arg(c); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (s.contains(key)) { | 
					
						
							|  |  |  | 			QString file = s.value(key).toString(); | 
					
						
							|  |  |  | 			files.append(file); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-29 13:06:30 -03:00
										 |  |  | 	foreach (const QString &file, failedFiles) | 
					
						
							| 
									
										
										
										
											2014-02-28 12:04:00 +03:00
										 |  |  | 		files.removeAll(file); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (int c = 1; c <= 4; c++) { | 
					
						
							|  |  |  | 		QString key = QString("File_%1").arg(c); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-29 13:06:30 -03:00
										 |  |  | 		if (files.count() >= c) | 
					
						
							| 
									
										
										
										
											2014-02-28 12:04:00 +03:00
										 |  |  | 			s.setValue(key, files.at(c - 1)); | 
					
						
							| 
									
										
										
										
											2014-07-29 13:06:30 -03:00
										 |  |  | 		else if (s.contains(key)) | 
					
						
							|  |  |  | 			s.remove(key); | 
					
						
							| 
									
										
										
										
											2014-02-28 12:04:00 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	s.endGroup(); | 
					
						
							|  |  |  | 	s.sync(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	loadRecentFiles(&s); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-13 22:48:07 +01:00
										 |  |  | void MainWindow::recentFileTriggered(bool checked) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Q_UNUSED(checked); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-08 19:46:43 -07:00
										 |  |  | 	if (!okToClose(tr("Please save or cancel the current dive edit before opening a new file."))) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-13 22:48:07 +01:00
										 |  |  | 	QAction *actionRecent = (QAction *)sender(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	const QString &filename = actionRecent->toolTip(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	updateLastUsedDir(QFileInfo(filename).dir().path()); | 
					
						
							| 
									
										
										
										
											2014-06-08 19:46:43 -07:00
										 |  |  | 	closeCurrentFile(); | 
					
						
							| 
									
										
										
										
											2014-02-13 22:48:07 +01:00
										 |  |  | 	loadFiles(QStringList() << filename); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-14 10:19:23 -07:00
										 |  |  | int MainWindow::file_save_as(void) | 
					
						
							| 
									
										
										
										
											2013-05-19 15:25:47 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	QString filename; | 
					
						
							| 
									
										
										
										
											2014-05-14 06:13:03 +09:00
										 |  |  | 	const char *default_filename = existing_filename; | 
					
						
							| 
									
										
										
										
											2014-07-11 00:06:48 +01:00
										 |  |  | 	filename = QFileDialog::getSaveFileName(this, tr("Save file as"), default_filename, | 
					
						
							| 
									
										
										
										
											2013-05-19 15:25:47 -07:00
										 |  |  | 						tr("Subsurface XML files (*.ssrf *.xml *.XML)")); | 
					
						
							| 
									
										
										
										
											2014-03-14 10:19:23 -07:00
										 |  |  | 	if (filename.isNull() || filename.isEmpty()) | 
					
						
							|  |  |  | 		return report_error("No filename to save into"); | 
					
						
							| 
									
										
										
										
											2013-11-23 00:40:48 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-14 10:19:23 -07:00
										 |  |  | 	if (ui.InfoWidget->isEditing()) | 
					
						
							|  |  |  | 		ui.InfoWidget->acceptChanges(); | 
					
						
							| 
									
										
										
										
											2013-11-23 00:40:48 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-14 10:35:09 -07:00
										 |  |  | 	if (save_dives(filename.toUtf8().data())) { | 
					
						
							|  |  |  | 		showError(get_error_string()); | 
					
						
							| 
									
										
										
										
											2014-03-14 10:19:23 -07:00
										 |  |  | 		return -1; | 
					
						
							| 
									
										
										
										
											2014-03-14 10:35:09 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-03-14 10:19:23 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-19 13:28:47 -07:00
										 |  |  | 	showError(get_error_string()); | 
					
						
							| 
									
										
										
										
											2014-03-14 10:19:23 -07:00
										 |  |  | 	set_filename(filename.toUtf8().data(), true); | 
					
						
							|  |  |  | 	setTitle(MWTF_FILENAME); | 
					
						
							|  |  |  | 	mark_divelist_changed(false); | 
					
						
							|  |  |  | 	addRecentFile(QStringList() << filename); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2013-05-19 15:25:47 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-14 10:19:23 -07:00
										 |  |  | int MainWindow::file_save(void) | 
					
						
							| 
									
										
										
										
											2013-05-19 15:25:47 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	const char *current_default; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!existing_filename) | 
					
						
							|  |  |  | 		return file_save_as(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 	if (ui.InfoWidget->isEditing()) | 
					
						
							| 
									
										
										
										
											2013-11-23 00:40:48 -02:00
										 |  |  | 		ui.InfoWidget->acceptChanges(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-19 15:25:47 -07:00
										 |  |  | 	current_default = prefs.default_filename; | 
					
						
							| 
									
										
										
										
											2014-02-13 22:11:05 -08:00
										 |  |  | 	if (strcmp(existing_filename, current_default) == 0) { | 
					
						
							| 
									
										
										
										
											2013-05-19 15:25:47 -07:00
										 |  |  | 		/* if we are using the default filename the directory
 | 
					
						
							|  |  |  | 		 * that we are creating the file in may not exist */ | 
					
						
							| 
									
										
										
										
											2013-05-19 17:18:44 -07: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 15:25:47 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-03-14 10:35:09 -07:00
										 |  |  | 	if (save_dives(existing_filename)) { | 
					
						
							|  |  |  | 		showError(get_error_string()); | 
					
						
							| 
									
										
										
										
											2014-03-14 10:19:23 -07:00
										 |  |  | 		return -1; | 
					
						
							| 
									
										
										
										
											2014-03-14 10:35:09 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-03-19 13:28:47 -07:00
										 |  |  | 	showError(get_error_string()); | 
					
						
							| 
									
										
										
										
											2014-01-15 09:30:42 +01:00
										 |  |  | 	mark_divelist_changed(false); | 
					
						
							| 
									
										
										
										
											2014-02-13 22:48:07 +01:00
										 |  |  | 	addRecentFile(QStringList() << QString(existing_filename)); | 
					
						
							| 
									
										
										
										
											2014-03-14 10:19:23 -07:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2013-05-19 15:25:47 -07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-05-21 23:13:45 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::showError(QString message) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (message.isEmpty()) | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 	ui.mainErrorMessage->setText(message); | 
					
						
							|  |  |  | 	ui.mainErrorMessage->setCloseButtonVisible(true); | 
					
						
							|  |  |  | 	ui.mainErrorMessage->setMessageType(KMessageWidget::Error); | 
					
						
							|  |  |  | 	ui.mainErrorMessage->animatedShow(); | 
					
						
							| 
									
										
										
										
											2013-05-21 23:13:45 -07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-06-26 15:13:06 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::setTitle(enum MainWindowTitleFormat format) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	switch (format) { | 
					
						
							|  |  |  | 	case MWTF_DEFAULT: | 
					
						
							|  |  |  | 		setWindowTitle("Subsurface"); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case MWTF_FILENAME: | 
					
						
							| 
									
										
										
										
											2013-12-05 14:38:12 +02:00
										 |  |  | 		if (!existing_filename) { | 
					
						
							|  |  |  | 			setTitle(MWTF_DEFAULT); | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-06-26 15:13:06 +03:00
										 |  |  | 		QFile f(existing_filename); | 
					
						
							|  |  |  | 		QFileInfo fileInfo(f); | 
					
						
							|  |  |  | 		QString fileName(fileInfo.fileName()); | 
					
						
							|  |  |  | 		setWindowTitle("Subsurface: " + fileName); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-09-09 05:59:03 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::importFiles(const QStringList fileNames) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-10-04 12:12:46 -03:00
										 |  |  | 	if (fileNames.isEmpty()) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-09 05:59:03 -03:00
										 |  |  | 	QByteArray fileNamePtr; | 
					
						
							| 
									
										
										
										
											2014-03-14 11:26:07 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-09 05:59:03 -03:00
										 |  |  | 	for (int i = 0; i < fileNames.size(); ++i) { | 
					
						
							| 
									
										
										
										
											2013-12-19 17:02:34 -08:00
										 |  |  | 		fileNamePtr = QFile::encodeName(fileNames.at(i)); | 
					
						
							| 
									
										
										
										
											2014-03-14 11:26:07 -07:00
										 |  |  | 		parse_file(fileNamePtr.data()); | 
					
						
							| 
									
										
										
										
											2013-09-09 05:59:03 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-01-15 09:30:42 +01:00
										 |  |  | 	process_dives(true, false); | 
					
						
							| 
									
										
										
										
											2013-11-01 09:43:41 -04:00
										 |  |  | 	refreshDisplay(); | 
					
						
							| 
									
										
										
										
											2013-09-09 05:59:03 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-28 09:55:46 +03:00
										 |  |  | void MainWindow::importTxtFiles(const QStringList fileNames) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (fileNames.isEmpty()) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	QByteArray fileNamePtr, csv; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (int i = 0; i < fileNames.size(); ++i) { | 
					
						
							|  |  |  | 		fileNamePtr = QFile::encodeName(fileNames.at(i)); | 
					
						
							|  |  |  | 		csv = fileNamePtr.data(); | 
					
						
							|  |  |  | 		csv.replace(strlen(csv.data()) - 3, 3, "csv"); | 
					
						
							|  |  |  | 		parse_txt_file(fileNamePtr.data(), csv); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	process_dives(true, false); | 
					
						
							|  |  |  | 	refreshDisplay(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-09 05:59:03 -03:00
										 |  |  | void MainWindow::loadFiles(const QStringList fileNames) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-10-04 12:12:46 -03:00
										 |  |  | 	if (fileNames.isEmpty()) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-09 05:59:03 -03:00
										 |  |  | 	QByteArray fileNamePtr; | 
					
						
							| 
									
										
										
										
											2014-02-28 12:04:00 +03:00
										 |  |  | 	QStringList failedParses; | 
					
						
							| 
									
										
										
										
											2013-09-09 05:59:03 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (int i = 0; i < fileNames.size(); ++i) { | 
					
						
							| 
									
										
										
										
											2014-03-14 11:26:07 -07:00
										 |  |  | 		int error; | 
					
						
							| 
									
										
										
										
											2013-09-09 05:59:03 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-14 11:26:07 -07:00
										 |  |  | 		fileNamePtr = QFile::encodeName(fileNames.at(i)); | 
					
						
							|  |  |  | 		error = parse_file(fileNamePtr.data()); | 
					
						
							|  |  |  | 		if (!error) { | 
					
						
							|  |  |  | 			set_filename(fileNamePtr.data(), true); | 
					
						
							|  |  |  | 			setTitle(MWTF_FILENAME); | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2014-02-28 12:04:00 +03:00
										 |  |  | 			failedParses.append(fileNames.at(i)); | 
					
						
							| 
									
										
										
										
											2013-09-09 05:59:03 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-15 09:30:42 +01:00
										 |  |  | 	process_dives(false, false); | 
					
						
							| 
									
										
										
										
											2014-02-13 22:48:07 +01:00
										 |  |  | 	addRecentFile(fileNames); | 
					
						
							| 
									
										
										
										
											2014-02-28 12:04:00 +03:00
										 |  |  | 	removeRecentFile(failedParses); | 
					
						
							| 
									
										
										
										
											2013-09-09 05:59:03 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-01 09:43:41 -04:00
										 |  |  | 	refreshDisplay(); | 
					
						
							| 
									
										
										
										
											2013-10-17 16:30:32 -07:00
										 |  |  | 	ui.actionAutoGroup->setChecked(autogroup); | 
					
						
							| 
									
										
										
										
											2013-09-09 05:59:03 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-10-16 22:05:19 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-29 18:11:20 +02:00
										 |  |  | void MainWindow::on_actionImportDiveLog_triggered() | 
					
						
							| 
									
										
										
										
											2013-10-16 22:05:19 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-07-11 00:06:48 +01:00
										 |  |  | 	QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Open dive log file"), lastUsedDir(), | 
					
						
							| 
									
										
										
										
											2014-10-17 21:03:37 -04:00
										 |  |  | 		tr("Dive log files (*.xml *.uddf *.udcf *.csv *.jlb *.dld *.sde *.db *.can);;" | 
					
						
							| 
									
										
										
										
											2014-07-11 00:06:48 +01:00
										 |  |  | 			"XML files (*.xml);;UDDF/UDCF files(*.uddf *.udcf);;JDiveLog files(*.jlb);;" | 
					
						
							| 
									
										
										
										
											2014-11-01 00:07:17 +00:00
										 |  |  | 			"Suunto files(*.sde *.db);;CSV files(*.csv);;MkVI files(*.txt);;All files(*)")); | 
					
						
							| 
									
										
										
										
											2014-01-07 22:01:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (fileNames.isEmpty()) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	updateLastUsedDir(QFileInfo(fileNames[0]).dir().path()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-28 16:34:33 -04:00
										 |  |  | 	QStringList logFiles = fileNames.filter(QRegExp("^.*\\.(?!(csv|txt))", Qt::CaseInsensitive)); | 
					
						
							| 
									
										
										
										
											2014-01-07 22:01:28 +02:00
										 |  |  | 	QStringList csvFiles = fileNames.filter(".csv", Qt::CaseInsensitive); | 
					
						
							| 
									
										
										
										
											2014-05-28 09:55:46 +03:00
										 |  |  | 	QStringList txtFiles = fileNames.filter(".txt", Qt::CaseInsensitive); | 
					
						
							| 
									
										
										
										
											2014-10-28 16:34:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-07 22:01:28 +02:00
										 |  |  | 	if (logFiles.size()) { | 
					
						
							|  |  |  | 		importFiles(logFiles); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (csvFiles.size()) { | 
					
						
							| 
									
										
										
										
											2014-04-25 10:44:23 -07:00
										 |  |  | 		DiveLogImportDialog *diveLogImport = new DiveLogImportDialog(&csvFiles, this); | 
					
						
							| 
									
										
										
										
											2014-01-07 22:01:28 +02:00
										 |  |  | 		diveLogImport->show(); | 
					
						
							| 
									
										
										
										
											2014-01-15 09:30:42 +01:00
										 |  |  | 		process_dives(true, false); | 
					
						
							| 
									
										
										
										
											2014-01-07 22:01:28 +02:00
										 |  |  | 		refreshDisplay(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-05-28 09:55:46 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (txtFiles.size()) { | 
					
						
							|  |  |  | 		importTxtFiles(txtFiles); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-10-16 22:05:19 +03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-11-01 11:48:34 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::editCurrentDive() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 	if (information()->isEditing() || DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING) { | 
					
						
							| 
									
										
										
										
											2014-02-26 15:59:06 +01:00
										 |  |  | 		QMessageBox::warning(this, tr("Warning"), tr("Please, first finish the current edition before trying to do another.")); | 
					
						
							| 
									
										
										
										
											2013-11-08 22:09:46 -02:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-01 11:48:34 -04:00
										 |  |  | 	struct dive *d = current_dive; | 
					
						
							|  |  |  | 	QString defaultDC(d->dc.model); | 
					
						
							| 
									
										
										
										
											2013-11-08 22:09:46 -02:00
										 |  |  | 	DivePlannerPointsModel::instance()->clear(); | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 	if (defaultDC == "manually added dive") { | 
					
						
							| 
									
										
										
										
											2013-11-01 11:48:34 -04:00
										 |  |  | 		disableDcShortcuts(); | 
					
						
							| 
									
										
										
										
											2013-11-08 22:09:46 -02:00
										 |  |  | 		DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD); | 
					
						
							| 
									
										
										
										
											2014-06-26 16:16:53 -03:00
										 |  |  | 		ui.newProfile->setAddState(); | 
					
						
							| 
									
										
										
										
											2013-11-01 11:48:34 -04:00
										 |  |  | 		ui.infoPane->setCurrentIndex(MAINTAB); | 
					
						
							|  |  |  | 		DivePlannerPointsModel::instance()->loadFromDive(d); | 
					
						
							|  |  |  | 		ui.InfoWidget->enableEdition(MainTab::MANUALLY_ADDED_DIVE); | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 	} else if (defaultDC == "planned dive") { | 
					
						
							| 
									
										
										
										
											2013-12-07 16:25:43 +01:00
										 |  |  | 		disableDcShortcuts(); | 
					
						
							|  |  |  | 		DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN); | 
					
						
							| 
									
										
										
										
											2014-05-25 00:51:05 -03:00
										 |  |  | 		//TODO: I BROKE THIS BY COMMENTING THE LINE BELOW
 | 
					
						
							|  |  |  | 		// and I'm sleepy now, so I think I should not try to fix right away.
 | 
					
						
							|  |  |  | 		// we don't setCurrentIndex anymore, we ->setPlanState() or ->setAddState() on the ProfileView.
 | 
					
						
							|  |  |  | 		//ui.stackedWidget->setCurrentIndex(PLANNERPROFILE); // Planner.
 | 
					
						
							| 
									
										
										
										
											2013-12-07 16:25:43 +01:00
										 |  |  | 		ui.infoPane->setCurrentIndex(PLANNERWIDGET); | 
					
						
							|  |  |  | 		DivePlannerPointsModel::instance()->loadFromDive(d); | 
					
						
							|  |  |  | 		ui.InfoWidget->enableEdition(MainTab::MANUALLY_ADDED_DIVE); | 
					
						
							| 
									
										
										
										
											2013-11-01 11:48:34 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-02-06 11:38:28 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-17 15:39:49 -07:00
										 |  |  | #define PREF_PROFILE(QT_PREFS)            \
 | 
					
						
							|  |  |  | 	QSettings s;                      \ | 
					
						
							|  |  |  | 	s.beginGroup("TecDetails");       \ | 
					
						
							| 
									
										
										
										
											2014-07-10 19:48:00 -03:00
										 |  |  | 	s.setValue(#QT_PREFS, triggered); \ | 
					
						
							| 
									
										
										
										
											2014-02-06 11:38:28 -02:00
										 |  |  | 	PreferencesDialog::instance()->emitSettingsChanged(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-17 15:39:49 -07:00
										 |  |  | #define TOOLBOX_PREF_PROFILE(METHOD, INTERNAL_PREFS, QT_PREFS)   \
 | 
					
						
							|  |  |  | 	void MainWindow::on_##METHOD##_triggered(bool triggered) \ | 
					
						
							|  |  |  | 	{                                                        \ | 
					
						
							|  |  |  | 		prefs.INTERNAL_PREFS = triggered;                \ | 
					
						
							|  |  |  | 		PREF_PROFILE(QT_PREFS);                          \ | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-07-10 19:48:00 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | TOOLBOX_PREF_PROFILE(profCalcAllTissues, calcalltissues, calcalltissues); | 
					
						
							|  |  |  | TOOLBOX_PREF_PROFILE(profCalcCeiling, calcceiling, calcceiling); | 
					
						
							|  |  |  | TOOLBOX_PREF_PROFILE(profDcCeiling, dcceiling, dcceiling); | 
					
						
							|  |  |  | TOOLBOX_PREF_PROFILE(profEad, ead, ead); | 
					
						
							|  |  |  | TOOLBOX_PREF_PROFILE(profIncrement3m, calcceiling3m, calcceiling3m); | 
					
						
							|  |  |  | TOOLBOX_PREF_PROFILE(profMod, mod, mod); | 
					
						
							|  |  |  | TOOLBOX_PREF_PROFILE(profNdl_tts, calcndltts, calcndltts); | 
					
						
							|  |  |  | TOOLBOX_PREF_PROFILE(profPhe, pp_graphs.phe, phegraph); | 
					
						
							|  |  |  | TOOLBOX_PREF_PROFILE(profPn2, pp_graphs.pn2, pn2graph); | 
					
						
							|  |  |  | TOOLBOX_PREF_PROFILE(profPO2, pp_graphs.po2, po2graph); | 
					
						
							|  |  |  | TOOLBOX_PREF_PROFILE(profHR, hrgraph, hrgraph); | 
					
						
							|  |  |  | TOOLBOX_PREF_PROFILE(profRuler, rulergraph, rulergraph); | 
					
						
							|  |  |  | TOOLBOX_PREF_PROFILE(profSAC, show_sac, show_sac); | 
					
						
							|  |  |  | TOOLBOX_PREF_PROFILE(profScaled, zoomed_plot, zoomed_plot); | 
					
						
							|  |  |  | TOOLBOX_PREF_PROFILE(profTogglePicture, show_pictures_in_profile, show_pictures_in_profile); | 
					
						
							| 
									
										
										
										
											2014-08-15 08:11:14 -06:00
										 |  |  | TOOLBOX_PREF_PROFILE(profTankbar, tankbar, tankbar); | 
					
						
							| 
									
										
										
										
											2014-09-15 14:09:00 +02:00
										 |  |  | TOOLBOX_PREF_PROFILE(profTissues, percentagegraph, percentagegraph); | 
					
						
							| 
									
										
										
										
											2014-07-10 21:15:20 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-04 13:41:50 -07:00
										 |  |  | void MainWindow::turnOffNdlTts() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-10 00:05:59 +03:00
										 |  |  | 	const bool triggered = false; | 
					
						
							|  |  |  | 	prefs.calcndltts = triggered; | 
					
						
							| 
									
										
										
										
											2014-07-10 19:48:00 -03:00
										 |  |  | 	PREF_PROFILE(calcndltts); | 
					
						
							| 
									
										
										
										
											2014-07-10 13:50:49 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-08 08:50:39 +01:00
										 |  |  | #undef TOOLBOX_PREF_PROFILE
 | 
					
						
							| 
									
										
										
										
											2014-07-10 19:48:00 -03:00
										 |  |  | #undef PERF_PROFILE
 | 
					
						
							| 
									
										
										
										
											2014-05-20 19:33:32 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::on_actionExport_triggered() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-07-10 19:53:58 -03:00
										 |  |  | 	DiveLogExportDialog diveLogExport; | 
					
						
							|  |  |  | 	diveLogExport.exec(); | 
					
						
							| 
									
										
										
										
											2014-05-20 19:33:32 +03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-08-04 12:58:21 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-29 18:54:19 +03:00
										 |  |  | void MainWindow::on_actionConfigure_Dive_Computer_triggered() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ConfigureDiveComputerDialog *dcConfig = new ConfigureDiveComputerDialog(this); | 
					
						
							|  |  |  | 	dcConfig->show(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-04 12:58:21 -03:00
										 |  |  | void MainWindow::setEnabledToolbar(bool arg1) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-09-17 15:39:49 -07:00
										 |  |  | 	Q_FOREACH (QAction *b, profileToolbarActions) | 
					
						
							| 
									
										
										
										
											2014-08-04 12:58:21 -03:00
										 |  |  | 		b->setEnabled(arg1); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-08-16 09:32:23 -06: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() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// take the data in our copyPasteDive and apply it to selected dives
 | 
					
						
							| 
									
										
										
										
											2014-08-17 08:26:09 -06:00
										 |  |  | 	selective_copy_dive(©PasteDive, &displayed_dive, what, false); | 
					
						
							|  |  |  | 	ui.InfoWidget->showAndTriggerEditSelective(what); | 
					
						
							| 
									
										
										
										
											2014-08-16 09:32:23 -06:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-09-17 14:50:41 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::on_actionFilterTags_triggered() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-10-31 15:22:21 -02:00
										 |  |  | 	ui.multiFilter->setVisible(!ui.multiFilter->isVisible()); | 
					
						
							| 
									
										
										
										
											2014-09-17 14:50:41 -03:00
										 |  |  | } |