| 
									
										
										
										
											2017-04-27 20:26:05 +02:00
										 |  |  | // SPDX-License-Identifier: GPL-2.0
 | 
					
						
							| 
									
										
										
										
											2016-04-04 22:02:03 -07:00
										 |  |  | #include "desktop-widgets/downloadfromdivecomputer.h"
 | 
					
						
							|  |  |  | #include "core/helpers.h"
 | 
					
						
							|  |  |  | #include "desktop-widgets/mainwindow.h"
 | 
					
						
							|  |  |  | #include "desktop-widgets/divelistview.h"
 | 
					
						
							|  |  |  | #include "core/display.h"
 | 
					
						
							|  |  |  | #include "core/uemis.h"
 | 
					
						
							| 
									
										
										
										
											2016-08-10 18:10:15 -03:00
										 |  |  | #include "core/subsurface-qt/SettingsObjectWrapper.h"
 | 
					
						
							| 
									
										
										
										
											2016-04-04 22:02:03 -07:00
										 |  |  | #include "qt-models/models.h"
 | 
					
						
							| 
									
										
										
										
											2017-04-18 17:32:10 +02:00
										 |  |  | #include "qt-models/diveimportedmodel.h"
 | 
					
						
							| 
									
										
										
										
											2015-02-09 19:51:31 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-25 19:02:30 -03:00
										 |  |  | #include <QTimer>
 | 
					
						
							| 
									
										
										
										
											2013-12-24 16:26:00 -08:00
										 |  |  | #include <QFileDialog>
 | 
					
						
							| 
									
										
										
										
											2013-09-01 11:14:54 -03:00
										 |  |  | #include <QMessageBox>
 | 
					
						
							| 
									
										
										
										
											2014-04-25 10:44:23 -07:00
										 |  |  | #include <QShortcut>
 | 
					
						
							| 
									
										
										
										
											2013-05-20 17:58:06 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | namespace DownloadFromDcGlobal { | 
					
						
							| 
									
										
										
										
											2013-05-20 16:43:33 -03:00
										 |  |  | 	const char *err_string; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-18 14:50:40 +02:00
										 |  |  | // Workaround abuse of old libdc types
 | 
					
						
							|  |  |  | #define DC_TRANSPORT_BLUETOOTH 1024
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | DownloadFromDCWidget::DownloadFromDCWidget(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f), | 
					
						
							| 
									
										
										
										
											2014-02-09 19:38:26 +01:00
										 |  |  | 	downloading(false), | 
					
						
							|  |  |  | 	previousLast(0), | 
					
						
							|  |  |  | 	vendorModel(0), | 
					
						
							|  |  |  | 	productModel(0), | 
					
						
							|  |  |  | 	timer(new QTimer(this)), | 
					
						
							|  |  |  | 	dumpWarningShown(false), | 
					
						
							| 
									
										
										
										
											2014-12-30 00:25:54 +01:00
										 |  |  | 	ostcFirmwareCheck(0), | 
					
						
							|  |  |  | 	currentState(INITIAL) | 
					
						
							| 
									
										
										
										
											2013-05-20 16:43:33 -03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-04-18 19:14:03 +02:00
										 |  |  | 	diveImportedModel = new DiveImportedModel(this); | 
					
						
							|  |  |  | 	diveImportedModel->setDiveTable(&downloadTable); | 
					
						
							|  |  |  | 	vendorModel = new QStringListModel(vendorList); | 
					
						
							|  |  |  | 	QShortcut *close = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this); | 
					
						
							|  |  |  | 	QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int startingWidth = defaultModelFont().pointSize(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-09 14:39:43 -08:00
										 |  |  | 	clear_table(&downloadTable); | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 	ui.setupUi(this); | 
					
						
							|  |  |  | 	ui.progressBar->hide(); | 
					
						
							|  |  |  | 	ui.progressBar->setMinimum(0); | 
					
						
							|  |  |  | 	ui.progressBar->setMaximum(100); | 
					
						
							| 
									
										
										
										
											2015-01-08 11:29:28 -02:00
										 |  |  | 	ui.downloadedView->setModel(diveImportedModel); | 
					
						
							| 
									
										
										
										
											2015-01-08 11:19:01 -08:00
										 |  |  | 	ui.downloadedView->setSelectionBehavior(QAbstractItemView::SelectRows); | 
					
						
							|  |  |  | 	ui.downloadedView->setSelectionMode(QAbstractItemView::SingleSelection); | 
					
						
							|  |  |  | 	ui.downloadedView->setColumnWidth(0, startingWidth * 20); | 
					
						
							| 
									
										
										
										
											2015-01-13 21:20:32 +13:00
										 |  |  | 	ui.downloadedView->setColumnWidth(1, startingWidth * 10); | 
					
						
							| 
									
										
										
										
											2015-01-08 11:19:01 -08:00
										 |  |  | 	ui.downloadedView->setColumnWidth(2, startingWidth * 10); | 
					
						
							| 
									
										
										
										
											2017-04-18 19:14:03 +02:00
										 |  |  | 	ui.chooseDumpFile->setEnabled(ui.dumpToFile->isChecked()); | 
					
						
							|  |  |  | 	ui.chooseLogFile->setEnabled(ui.logToFile->isChecked()); | 
					
						
							|  |  |  | 	ui.selectAllButton->setEnabled(false); | 
					
						
							|  |  |  | 	ui.unselectAllButton->setEnabled(false); | 
					
						
							|  |  |  | 	ui.vendor->setModel(vendorModel); | 
					
						
							| 
									
										
										
										
											2013-09-16 18:04:42 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-26 13:37:13 -03:00
										 |  |  | 	progress_bar_text = ""; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-18 19:14:03 +02:00
										 |  |  | 	timer->setInterval(200); | 
					
						
							| 
									
										
										
										
											2013-05-20 17:58:06 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-18 19:14:03 +02:00
										 |  |  | 	connect(ui.downloadedView, SIGNAL(clicked(QModelIndex)), diveImportedModel, SLOT(changeSelected(QModelIndex))); | 
					
						
							| 
									
										
										
										
											2013-12-24 16:26:00 -08:00
										 |  |  | 	connect(ui.chooseDumpFile, SIGNAL(clicked()), this, SLOT(pickDumpFile())); | 
					
						
							|  |  |  | 	connect(ui.dumpToFile, SIGNAL(stateChanged(int)), this, SLOT(checkDumpFile(int))); | 
					
						
							|  |  |  | 	connect(ui.chooseLogFile, SIGNAL(clicked()), this, SLOT(pickLogFile())); | 
					
						
							|  |  |  | 	connect(ui.logToFile, SIGNAL(stateChanged(int)), this, SLOT(checkLogFile(int))); | 
					
						
							| 
									
										
										
										
											2015-01-08 12:54:53 -08:00
										 |  |  | 	connect(ui.selectAllButton, SIGNAL(clicked()), diveImportedModel, SLOT(selectAll())); | 
					
						
							|  |  |  | 	connect(ui.unselectAllButton, SIGNAL(clicked()), diveImportedModel, SLOT(selectNone())); | 
					
						
							| 
									
										
										
										
											2017-04-18 19:14:03 +02:00
										 |  |  | 	connect(timer, SIGNAL(timeout()), this, SLOT(updateProgressBar())); | 
					
						
							|  |  |  | 	connect(close, SIGNAL(activated()), this, SLOT(close())); | 
					
						
							|  |  |  | 	connect(quit, SIGNAL(activated()), parent, SLOT(close())); | 
					
						
							| 
									
										
										
										
											2016-08-10 18:10:15 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	auto dc = SettingsObjectWrapper::instance()->dive_computer_settings; | 
					
						
							|  |  |  | 	if (!dc->dc_vendor().isEmpty()) { | 
					
						
							|  |  |  | 		ui.vendor->setCurrentIndex(ui.vendor->findText(dc->dc_vendor())); | 
					
						
							|  |  |  | 		productModel = new QStringListModel(productList[dc->dc_vendor()]); | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 		ui.product->setModel(productModel); | 
					
						
							| 
									
										
										
										
											2016-08-10 18:10:15 -03:00
										 |  |  | 		if (!dc->dc_product().isEmpty()) | 
					
						
							|  |  |  | 			ui.product->setCurrentIndex(ui.product->findText(dc->dc_product())); | 
					
						
							| 
									
										
										
										
											2013-05-22 23:24:33 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-08-10 18:10:15 -03:00
										 |  |  | 	if (!dc->dc_device().isEmpty()) | 
					
						
							|  |  |  | 		ui.device->setEditText(dc->dc_device()); | 
					
						
							| 
									
										
										
										
											2013-08-25 19:02:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	updateState(INITIAL); | 
					
						
							| 
									
										
										
										
											2015-01-08 09:39:47 -08:00
										 |  |  | 	ui.ok->setEnabled(false); | 
					
						
							| 
									
										
										
										
											2015-01-09 15:01:48 -08:00
										 |  |  | 	ui.downloadCancelRetryButton->setEnabled(true); | 
					
						
							|  |  |  | 	ui.downloadCancelRetryButton->setText(tr("Download")); | 
					
						
							| 
									
										
										
										
											2015-07-06 16:35:13 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-08 19:50:22 +03:00
										 |  |  | #if defined(BT_SUPPORT) && defined(SSRF_CUSTOM_SERIAL)
 | 
					
						
							| 
									
										
										
										
											2015-09-04 23:25:35 +01:00
										 |  |  | 	ui.bluetoothMode->setText(tr("Choose Bluetooth download mode")); | 
					
						
							| 
									
										
										
										
											2016-08-10 18:10:15 -03:00
										 |  |  | 	ui.bluetoothMode->setChecked(dc->downloadMode() == DC_TRANSPORT_BLUETOOTH); | 
					
						
							| 
									
										
										
										
											2015-07-06 16:35:13 +03:00
										 |  |  | 	btDeviceSelectionDialog = 0; | 
					
						
							| 
									
										
										
										
											2017-05-28 12:29:26 +02:00
										 |  |  | 	connect(ui.bluetoothMode, SIGNAL(stateChanged(int)), this, SLOT(enableBluetoothMode(int))); | 
					
						
							|  |  |  | 	connect(ui.chooseBluetoothDevice, SIGNAL(clicked()), this, SLOT(selectRemoteBluetoothDevice())); | 
					
						
							| 
									
										
										
										
											2015-07-06 16:18:06 +03:00
										 |  |  | 	ui.chooseBluetoothDevice->setEnabled(ui.bluetoothMode->isChecked()); | 
					
						
							| 
									
										
										
										
											2015-07-20 09:35:00 -07:00
										 |  |  | #else
 | 
					
						
							|  |  |  | 	ui.bluetoothMode->hide(); | 
					
						
							|  |  |  | 	ui.chooseBluetoothDevice->hide(); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2013-05-20 17:58:06 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-25 19:02:30 -03:00
										 |  |  | void DownloadFromDCWidget::updateProgressBar() | 
					
						
							| 
									
										
										
										
											2013-05-30 18:21:08 +09:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-04-22 13:49:03 -07:00
										 |  |  | 	static char *last_text = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (same_string(last_text, "")) { | 
					
						
							|  |  |  | 		// if we get the first actual text after the download is finished
 | 
					
						
							|  |  |  | 		// (which happens for example on the OSTC), then don't bother
 | 
					
						
							|  |  |  | 		if (!same_string(progress_bar_text, "") && IS_FP_SAME(progress_bar_fraction, 1.0)) | 
					
						
							|  |  |  | 			progress_bar_text = NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (!same_string(progress_bar_text , "")) { | 
					
						
							| 
									
										
										
										
											2014-01-27 12:47:40 -08:00
										 |  |  | 		ui.progressBar->setFormat(progress_bar_text); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		ui.progressBar->setFormat("%p%"); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-23 08:13:49 +07:00
										 |  |  | 	ui.progressBar->setValue(lrint(progress_bar_fraction * 100)); | 
					
						
							| 
									
										
										
										
											2017-04-22 13:49:03 -07:00
										 |  |  | 	free(last_text); | 
					
						
							|  |  |  | 	last_text = strdup(progress_bar_text); | 
					
						
							| 
									
										
										
										
											2013-08-25 19:02:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DownloadFromDCWidget::updateState(states state) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (state == currentState) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (state == INITIAL) { | 
					
						
							| 
									
										
										
										
											2014-05-18 13:29:40 +09:00
										 |  |  | 		fill_device_list(DC_TYPE_OTHER); | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 		ui.progressBar->hide(); | 
					
						
							| 
									
										
										
										
											2013-08-25 19:02:30 -03:00
										 |  |  | 		markChildrenAsEnabled(); | 
					
						
							|  |  |  | 		timer->stop(); | 
					
						
							| 
									
										
										
										
											2017-04-22 13:49:03 -07:00
										 |  |  | 		progress_bar_text = ""; | 
					
						
							| 
									
										
										
										
											2013-08-25 19:02:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// tries to cancel an on going download
 | 
					
						
							|  |  |  | 	else if (currentState == DOWNLOADING && state == CANCELLING) { | 
					
						
							|  |  |  | 		import_thread_cancelled = true; | 
					
						
							| 
									
										
										
										
											2015-01-09 15:01:48 -08:00
										 |  |  | 		ui.downloadCancelRetryButton->setEnabled(false); | 
					
						
							| 
									
										
										
										
											2013-08-25 19:02:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// user pressed cancel but the application isn't doing anything.
 | 
					
						
							|  |  |  | 	// means close the window
 | 
					
						
							| 
									
										
										
										
											2015-01-09 15:01:48 -08:00
										 |  |  | 	else if ((currentState == INITIAL || currentState == DONE || currentState == ERROR) && state == CANCELLING) { | 
					
						
							| 
									
										
										
										
											2013-08-25 19:02:30 -03:00
										 |  |  | 		timer->stop(); | 
					
						
							|  |  |  | 		reject(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-01 11:14:54 -03:00
										 |  |  | 	// the cancelation process is finished
 | 
					
						
							| 
									
										
										
										
											2015-01-09 15:01:48 -08:00
										 |  |  | 	else if (currentState == CANCELLING && state == DONE) { | 
					
						
							| 
									
										
										
										
											2013-08-25 19:02:30 -03:00
										 |  |  | 		timer->stop(); | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 		ui.progressBar->setValue(0); | 
					
						
							|  |  |  | 		ui.progressBar->hide(); | 
					
						
							| 
									
										
										
										
											2013-08-25 19:02:30 -03:00
										 |  |  | 		markChildrenAsEnabled(); | 
					
						
							| 
									
										
										
										
											2017-04-22 13:49:03 -07:00
										 |  |  | 		progress_bar_text = ""; | 
					
						
							| 
									
										
										
										
											2013-08-25 19:02:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-27 12:47:40 -08:00
										 |  |  | 	// DOWNLOAD is finally done, but we don't know if there was an error as libdivecomputer doesn't pass
 | 
					
						
							| 
									
										
										
										
											2015-01-08 09:29:57 -08:00
										 |  |  | 	// that information on to us.
 | 
					
						
							|  |  |  | 	// If we find an error, offer to retry, otherwise continue the interaction to pick the dives the user wants
 | 
					
						
							| 
									
										
										
										
											2013-08-25 19:02:30 -03:00
										 |  |  | 	else if (currentState == DOWNLOADING && state == DONE) { | 
					
						
							|  |  |  | 		timer->stop(); | 
					
						
							| 
									
										
										
										
											2014-01-27 12:47:40 -08:00
										 |  |  | 		if (QString(progress_bar_text).contains("error", Qt::CaseInsensitive)) { | 
					
						
							|  |  |  | 			updateProgressBar(); | 
					
						
							|  |  |  | 			markChildrenAsEnabled(); | 
					
						
							|  |  |  | 			progress_bar_text = ""; | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2017-04-22 13:49:03 -07:00
										 |  |  | 			progress_bar_text = ""; | 
					
						
							| 
									
										
										
										
											2014-01-27 12:47:40 -08:00
										 |  |  | 			ui.progressBar->setValue(100); | 
					
						
							|  |  |  | 			markChildrenAsEnabled(); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-08-25 19:02:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// DOWNLOAD is started.
 | 
					
						
							|  |  |  | 	else if (state == DOWNLOADING) { | 
					
						
							|  |  |  | 		timer->start(); | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 		ui.progressBar->setValue(0); | 
					
						
							| 
									
										
										
										
											2017-04-22 13:55:43 -07:00
										 |  |  | 		progress_bar_fraction = 0.0; | 
					
						
							| 
									
										
										
										
											2014-01-27 12:47:40 -08:00
										 |  |  | 		updateProgressBar(); | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 		ui.progressBar->show(); | 
					
						
							| 
									
										
										
										
											2013-08-25 19:02:30 -03:00
										 |  |  | 		markChildrenAsDisabled(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-01 11:14:54 -03:00
										 |  |  | 	// got an error
 | 
					
						
							|  |  |  | 	else if (state == ERROR) { | 
					
						
							| 
									
										
										
										
											2017-04-22 13:46:27 -07:00
										 |  |  | 		timer->stop(); | 
					
						
							| 
									
										
										
										
											2017-05-19 11:23:11 +02:00
										 |  |  | 		QMessageBox::critical(this, TITLE_OR_TEXT(tr("Error"), thread.error), QMessageBox::Ok); | 
					
						
							| 
									
										
										
										
											2013-09-01 11:14:54 -03:00
										 |  |  | 		markChildrenAsEnabled(); | 
					
						
							| 
									
										
										
										
											2017-04-22 13:49:03 -07:00
										 |  |  | 		progress_bar_text = ""; | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 		ui.progressBar->hide(); | 
					
						
							| 
									
										
										
										
											2013-09-01 11:14:54 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-25 19:02:30 -03:00
										 |  |  | 	// properly updating the widget state
 | 
					
						
							|  |  |  | 	currentState = state; | 
					
						
							| 
									
										
										
										
											2013-05-30 18:21:08 +09:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void DownloadFromDCWidget::on_vendor_currentIndexChanged(const QString &vendor) | 
					
						
							| 
									
										
										
										
											2013-05-20 17:58:06 -03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-05-18 13:29:40 +09:00
										 |  |  | 	int dcType = DC_TYPE_SERIAL; | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 	QAbstractItemModel *currentModel = ui.product->model(); | 
					
						
							| 
									
										
										
										
											2013-05-20 17:58:06 -03:00
										 |  |  | 	if (!currentModel) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	productModel = new QStringListModel(productList[vendor]); | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 	ui.product->setModel(productModel); | 
					
						
							| 
									
										
										
										
											2013-05-20 17:58:06 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 13:29:40 +09:00
										 |  |  | 	if (vendor == QString("Uemis")) | 
					
						
							|  |  |  | 		dcType = DC_TYPE_UEMIS; | 
					
						
							|  |  |  | 	fill_device_list(dcType); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-20 17:58:06 -03:00
										 |  |  | 	// Memleak - but deleting gives me a crash.
 | 
					
						
							|  |  |  | 	//currentModel->deleteLater();
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-26 00:06:56 +02:00
										 |  |  | void DownloadFromDCWidget::on_product_currentIndexChanged(const QString &product) | 
					
						
							| 
									
										
										
										
											2013-12-27 12:50:13 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	// Set up the DC descriptor
 | 
					
						
							|  |  |  | 	dc_descriptor_t *descriptor = NULL; | 
					
						
							| 
									
										
										
										
											2014-05-26 00:06:56 +02:00
										 |  |  | 	descriptor = descriptorLookup[ui.vendor->currentText() + product]; | 
					
						
							| 
									
										
										
										
											2013-12-27 12:50:13 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// call dc_descriptor_get_transport to see if the dc_transport_t is DC_TRANSPORT_SERIAL
 | 
					
						
							|  |  |  | 	if (dc_descriptor_get_transport(descriptor) == DC_TRANSPORT_SERIAL) { | 
					
						
							|  |  |  | 		// if the dc_transport_t is DC_TRANSPORT_SERIAL, then enable the device node box.
 | 
					
						
							|  |  |  | 		ui.device->setEnabled(true); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		// otherwise disable the device node box
 | 
					
						
							|  |  |  | 		ui.device->setEnabled(false); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-18 17:20:35 -08:00
										 |  |  | void DownloadFromDCWidget::on_search_clicked() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (ui.vendor->currentText() == "Uemis") { | 
					
						
							|  |  |  | 		QString dirName = QFileDialog::getExistingDirectory(this, | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 								    tr("Find Uemis dive computer"), | 
					
						
							|  |  |  | 								    QDir::homePath(), | 
					
						
							|  |  |  | 								    QFileDialog::ShowDirsOnly); | 
					
						
							| 
									
										
										
										
											2014-02-18 17:20:35 -08:00
										 |  |  | 		if (ui.device->findText(dirName) == -1) | 
					
						
							|  |  |  | 			ui.device->addItem(dirName); | 
					
						
							|  |  |  | 		ui.device->setEditText(dirName); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-09 15:01:48 -08:00
										 |  |  | void DownloadFromDCWidget::on_downloadCancelRetryButton_clicked() | 
					
						
							| 
									
										
										
										
											2013-05-20 16:43:33 -03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-01-09 15:01:48 -08:00
										 |  |  | 	if (currentState == DOWNLOADING) { | 
					
						
							|  |  |  | 		updateState(CANCELLING); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-01-11 07:46:21 -08:00
										 |  |  | 	if (currentState == DONE) { | 
					
						
							|  |  |  | 		// this means we are retrying - so we better clean out the partial
 | 
					
						
							|  |  |  | 		// list of downloaded dives from the last attempt
 | 
					
						
							|  |  |  | 		diveImportedModel->clearTable(); | 
					
						
							|  |  |  | 		clear_table(&downloadTable); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-08-25 19:02:30 -03:00
										 |  |  | 	updateState(DOWNLOADING); | 
					
						
							| 
									
										
										
										
											2013-05-20 16:43:33 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-09 15:01:48 -08:00
										 |  |  | 	// you cannot cancel the dialog, just the download
 | 
					
						
							|  |  |  | 	ui.cancel->setEnabled(false); | 
					
						
							| 
									
										
										
										
											2017-04-23 09:51:44 +02:00
										 |  |  | 	ui.downloadCancelRetryButton->setText(tr("Cancel download")); | 
					
						
							| 
									
										
										
										
											2015-01-09 15:01:48 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 16:40:50 +02:00
										 |  |  | 	auto data = thread.data(); | 
					
						
							|  |  |  | 	data->setVendor(ui.vendor->currentText()); | 
					
						
							|  |  |  | 	data->setProduct(ui.product->currentText()); | 
					
						
							| 
									
										
										
										
											2015-07-20 09:35:00 -07:00
										 |  |  | #if defined(BT_SUPPORT)
 | 
					
						
							| 
									
										
										
										
											2017-05-26 16:40:50 +02:00
										 |  |  | 	data->setBluetoothMode(ui.bluetoothMode->isChecked()); | 
					
						
							|  |  |  | 	if (data->bluetoothMode() && btDeviceSelectionDialog != NULL) { | 
					
						
							| 
									
										
										
										
											2015-07-06 16:35:13 +03:00
										 |  |  | 		// Get the selected device address
 | 
					
						
							| 
									
										
										
										
											2017-05-26 16:40:50 +02:00
										 |  |  | 		data->setDevName(btDeviceSelectionDialog->getSelectedDeviceAddress()); | 
					
						
							| 
									
										
										
										
											2015-07-20 09:35:00 -07:00
										 |  |  | 	} else | 
					
						
							|  |  |  | 		// this breaks an "else if" across lines... not happy...
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2017-05-26 16:40:50 +02:00
										 |  |  | 	if (data->vendor() == "Uemis") { | 
					
						
							| 
									
										
										
										
											2015-04-30 16:35:46 -07:00
										 |  |  | 		char *colon; | 
					
						
							|  |  |  | 		char *devname = strdup(ui.device->currentText().toUtf8().data()); | 
					
						
							| 
									
										
										
										
											2013-08-25 10:01:59 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-30 16:35:46 -07:00
										 |  |  | 		if ((colon = strstr(devname, ":\\ (UEMISSDA)")) != NULL) { | 
					
						
							|  |  |  | 			*(colon + 2) = '\0'; | 
					
						
							| 
									
										
										
										
											2017-05-19 11:23:11 +02:00
										 |  |  | 			fprintf(stderr, "shortened devname to \"%s\"", devname); | 
					
						
							| 
									
										
										
										
											2015-04-30 16:35:46 -07:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-05-26 16:40:50 +02:00
										 |  |  | 		data->setDevName(devname); | 
					
						
							| 
									
										
										
										
											2015-04-30 16:35:46 -07:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2017-05-26 16:40:50 +02:00
										 |  |  | 		data->setDevName(ui.device->currentText()); | 
					
						
							| 
									
										
										
										
											2015-04-30 16:35:46 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-05-26 16:40:50 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	data->setForceDownload(ui.forceDownload->isChecked()); | 
					
						
							|  |  |  | 	data->setCreateNewTrip(ui.createNewTrip->isChecked()); | 
					
						
							|  |  |  | 	data->setSaveLog(ui.chooseLogFile->isChecked()); | 
					
						
							|  |  |  | 	data->setSaveDump(ui.chooseDumpFile->isChecked()); | 
					
						
							| 
									
										
										
										
											2016-08-10 18:10:15 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	auto dc = SettingsObjectWrapper::instance()->dive_computer_settings; | 
					
						
							| 
									
										
										
										
											2017-05-26 16:40:50 +02:00
										 |  |  | 	dc->setVendor(data->vendor()); | 
					
						
							|  |  |  | 	dc->setProduct(data->product()); | 
					
						
							|  |  |  | 	dc->setDevice(data->devName()); | 
					
						
							| 
									
										
										
										
											2017-05-19 11:23:11 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-08 22:16:04 +02:00
										 |  |  | #if defined(BT_SUPPORT) && defined(SSRF_CUSTOM_SERIAL)
 | 
					
						
							| 
									
										
										
										
											2016-08-10 18:10:15 -03:00
										 |  |  | 	dc->setDownloadMode(ui.bluetoothMode->isChecked() ? DC_TRANSPORT_BLUETOOTH : DC_TRANSPORT_SERIAL); | 
					
						
							| 
									
										
										
										
											2015-09-08 22:16:04 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2013-05-20 17:02:17 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-19 11:23:11 +02:00
										 |  |  | 	connect(&thread, SIGNAL(finished()), | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 		this, SLOT(onDownloadThreadFinished()), Qt::QueuedConnection); | 
					
						
							| 
									
										
										
										
											2013-08-25 19:02:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-10 18:10:15 -03:00
										 |  |  | 	//TODO: Don't call mainwindow.
 | 
					
						
							| 
									
										
										
										
											2014-02-12 15:22:54 +01:00
										 |  |  | 	MainWindow *w = MainWindow::instance(); | 
					
						
							| 
									
										
										
										
											2017-05-19 11:23:11 +02:00
										 |  |  | 	connect(&thread, SIGNAL(finished()), w, SLOT(refreshDisplay())); | 
					
						
							| 
									
										
										
										
											2013-05-20 17:02:17 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-08 06:33:46 +01:00
										 |  |  | 	// before we start, remember where the dive_table ended
 | 
					
						
							|  |  |  | 	previousLast = dive_table.nr; | 
					
						
							| 
									
										
										
										
											2017-05-19 11:23:11 +02:00
										 |  |  | 	thread.start(); | 
					
						
							| 
									
										
										
										
											2014-12-27 08:31:51 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-08 14:04:11 +01:00
										 |  |  | 	// FIXME: We should get the _actual_ device info instead of whatever
 | 
					
						
							|  |  |  | 	// the user entered in the dropdown.
 | 
					
						
							|  |  |  | 	// You can enter "OSTC 3" and download just fine from a "OSTC Sport", but
 | 
					
						
							|  |  |  | 	// this check will compair apples and oranges, firmware wise, then.
 | 
					
						
							| 
									
										
										
										
											2014-12-28 07:37:11 -08:00
										 |  |  | 	QString product(ui.product->currentText()); | 
					
						
							| 
									
										
										
										
											2017-04-24 18:29:33 +02:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// We shouldn't do this for memory dumps.
 | 
					
						
							|  |  |  | 	if ((product == "OSTC 3" || product == "OSTC 3+" || | 
					
						
							| 
									
										
										
										
											2016-12-28 16:49:14 +01:00
										 |  |  | 			product == "OSTC Cr" || product == "OSTC Sport" || | 
					
						
							| 
									
										
										
										
											2017-05-26 16:40:50 +02:00
										 |  |  | 			product == "OSTC 4") && ! data->saveDump()) | 
					
						
							| 
									
										
										
										
											2017-05-19 11:23:11 +02:00
										 |  |  | 	ostcFirmwareCheck = new OstcFirmwareCheck(product); | 
					
						
							| 
									
										
										
										
											2013-05-20 16:43:33 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-30 17:58:59 +09:00
										 |  |  | bool DownloadFromDCWidget::preferDownloaded() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 	return ui.preferDownloaded->isChecked(); | 
					
						
							| 
									
										
										
										
											2013-05-30 17:58:59 +09:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-24 16:26:00 -08:00
										 |  |  | void DownloadFromDCWidget::checkLogFile(int state) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ui.chooseLogFile->setEnabled(state == Qt::Checked); | 
					
						
							| 
									
										
										
										
											2017-05-19 11:23:11 +02:00
										 |  |  | 	// TODO: Verify the Thread.
 | 
					
						
							| 
									
										
										
										
											2017-05-19 11:29:03 +02:00
										 |  |  | 	if (state == Qt::Checked) { | 
					
						
							| 
									
										
										
										
											2013-12-24 16:26:00 -08:00
										 |  |  | 		pickLogFile(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DownloadFromDCWidget::pickLogFile() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	QString filename = existing_filename ?: prefs.default_filename; | 
					
						
							| 
									
										
										
										
											2013-12-24 16:26:00 -08:00
										 |  |  | 	QFileInfo fi(filename); | 
					
						
							|  |  |  | 	filename = fi.absolutePath().append(QDir::separator()).append("subsurface.log"); | 
					
						
							| 
									
										
										
										
											2017-05-19 11:29:03 +02:00
										 |  |  | 	QString logFile = QFileDialog::getSaveFileName(this, tr("Choose file for dive computer download logfile"), | 
					
						
							| 
									
										
										
										
											2013-12-24 16:26:00 -08:00
										 |  |  | 					       filename, tr("Log files (*.log)")); | 
					
						
							| 
									
										
										
										
											2014-01-07 16:41:21 +02:00
										 |  |  | 	if (!logFile.isEmpty()) { | 
					
						
							| 
									
										
										
										
											2014-05-12 14:58:15 -03:00
										 |  |  | 		free(logfile_name); | 
					
						
							| 
									
										
										
										
											2017-05-19 11:29:03 +02:00
										 |  |  | 		logfile_name = copy_string(logFile.toUtf8().data()); | 
					
						
							| 
									
										
										
										
											2014-01-07 16:41:21 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-12-24 16:26:00 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DownloadFromDCWidget::checkDumpFile(int state) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ui.chooseDumpFile->setEnabled(state == Qt::Checked); | 
					
						
							| 
									
										
										
										
											2013-12-26 09:18:57 -08:00
										 |  |  | 	if (state == Qt::Checked) { | 
					
						
							| 
									
										
										
										
											2017-05-19 11:29:03 +02:00
										 |  |  | 		pickDumpFile(); | 
					
						
							| 
									
										
										
										
											2013-12-26 09:18:57 -08:00
										 |  |  | 		if (!dumpWarningShown) { | 
					
						
							|  |  |  | 			QMessageBox::warning(this, tr("Warning"), | 
					
						
							|  |  |  | 					     tr("Saving the libdivecomputer dump will NOT download dives to the dive list.")); | 
					
						
							|  |  |  | 			dumpWarningShown = true; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-12-24 16:26:00 -08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DownloadFromDCWidget::pickDumpFile() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	QString filename = existing_filename ?: prefs.default_filename; | 
					
						
							| 
									
										
										
										
											2013-12-24 16:26:00 -08:00
										 |  |  | 	QFileInfo fi(filename); | 
					
						
							|  |  |  | 	filename = fi.absolutePath().append(QDir::separator()).append("subsurface.bin"); | 
					
						
							| 
									
										
										
										
											2017-05-19 11:29:03 +02:00
										 |  |  | 	QString dumpFile = QFileDialog::getSaveFileName(this, tr("Choose file for dive computer binary dump file"), | 
					
						
							| 
									
										
										
										
											2013-12-24 16:26:00 -08:00
										 |  |  | 						filename, tr("Dump files (*.bin)")); | 
					
						
							| 
									
										
										
										
											2014-01-07 16:41:21 +02:00
										 |  |  | 	if (!dumpFile.isEmpty()) { | 
					
						
							| 
									
										
										
										
											2014-05-12 14:58:15 -03:00
										 |  |  | 		free(dumpfile_name); | 
					
						
							| 
									
										
										
										
											2017-05-19 11:29:03 +02:00
										 |  |  | 		dumpfile_name = copy_string(dumpFile.toUtf8().data()); | 
					
						
							| 
									
										
										
										
											2014-01-07 16:41:21 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-12-24 16:26:00 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-25 10:01:59 -03:00
										 |  |  | void DownloadFromDCWidget::reject() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// we don't want the download window being able to close
 | 
					
						
							|  |  |  | 	// while we're still downloading.
 | 
					
						
							| 
									
										
										
										
											2013-08-25 19:02:30 -03:00
										 |  |  | 	if (currentState != DOWNLOADING && currentState != CANCELLING) | 
					
						
							| 
									
										
										
										
											2013-08-25 10:01:59 -03:00
										 |  |  | 		QDialog::reject(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-15 10:25:53 -07:00
										 |  |  | void DownloadFromDCWidget::onDownloadThreadFinished() | 
					
						
							| 
									
										
										
										
											2013-08-25 19:02:30 -03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-09-01 11:14:54 -03:00
										 |  |  | 	if (currentState == DOWNLOADING) { | 
					
						
							| 
									
										
										
										
											2017-05-19 11:23:11 +02:00
										 |  |  | 		if (thread.error.isEmpty()) | 
					
						
							| 
									
										
										
										
											2013-09-01 11:14:54 -03:00
										 |  |  | 			updateState(DONE); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			updateState(ERROR); | 
					
						
							| 
									
										
										
										
											2015-01-09 14:44:38 -08:00
										 |  |  | 	} else if (currentState == CANCELLING) { | 
					
						
							|  |  |  | 		updateState(DONE); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-04-23 09:51:44 +02:00
										 |  |  | 	ui.downloadCancelRetryButton->setText(tr("Retry download")); | 
					
						
							| 
									
										
										
										
											2015-01-09 15:01:48 -08:00
										 |  |  | 	ui.downloadCancelRetryButton->setEnabled(true); | 
					
						
							| 
									
										
										
										
											2015-01-09 14:44:38 -08:00
										 |  |  | 	// regardless, if we got dives, we should show them to the user
 | 
					
						
							|  |  |  | 	if (downloadTable.nr) { | 
					
						
							|  |  |  | 		diveImportedModel->setImportedDivesIndexes(0, downloadTable.nr - 1); | 
					
						
							| 
									
										
										
										
											2013-12-08 06:33:46 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-01-09 15:01:48 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DownloadFromDCWidget::on_cancel_clicked() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (currentState == DOWNLOADING || currentState == CANCELLING) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// now discard all the dives
 | 
					
						
							|  |  |  | 	clear_table(&downloadTable); | 
					
						
							|  |  |  | 	done(-1); | 
					
						
							| 
									
										
										
										
											2013-08-25 19:02:30 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-01-08 11:31:05 -02:00
										 |  |  | 
 | 
					
						
							|  |  |  | void DownloadFromDCWidget::on_ok_clicked() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-01-27 06:50:42 +02:00
										 |  |  | 	struct dive *dive; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-20 22:11:43 -07:00
										 |  |  | 	if (currentState != DONE && currentState != ERROR) | 
					
						
							| 
									
										
										
										
											2015-01-08 11:56:00 -02:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-09 14:44:38 -08:00
										 |  |  | 	// record all the dives in the 'real' dive_table
 | 
					
						
							|  |  |  | 	for (int i = 0; i < downloadTable.nr; i++) { | 
					
						
							|  |  |  | 		if (diveImportedModel->data(diveImportedModel->index(i, 0),Qt::CheckStateRole) == Qt::Checked) | 
					
						
							|  |  |  | 			record_dive(downloadTable.dives[i]); | 
					
						
							| 
									
										
										
										
											2017-05-29 10:32:32 -07:00
										 |  |  | 		else | 
					
						
							|  |  |  | 			clear_dive(downloadTable.dives[i]); | 
					
						
							| 
									
										
										
										
											2015-01-09 14:44:38 -08:00
										 |  |  | 		downloadTable.dives[i] = NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	downloadTable.nr = 0; | 
					
						
							| 
									
										
										
										
											2015-01-08 11:52:12 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-08 10:12:11 -02:00
										 |  |  | 	int uniqId, idx; | 
					
						
							|  |  |  | 	// remember the last downloaded dive (on most dive computers this will be the chronologically
 | 
					
						
							|  |  |  | 	// first new dive) and select it again after processing all the dives
 | 
					
						
							|  |  |  | 	MainWindow::instance()->dive_list()->unselectDives(); | 
					
						
							| 
									
										
										
										
											2015-01-27 06:50:42 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	dive = get_dive(dive_table.nr - 1); | 
					
						
							|  |  |  | 	if (dive != NULL) { | 
					
						
							|  |  |  | 		uniqId = get_dive(dive_table.nr - 1)->id; | 
					
						
							|  |  |  | 		process_dives(true, preferDownloaded()); | 
					
						
							|  |  |  | 		// after process_dives does any merging or resorting needed, we need
 | 
					
						
							|  |  |  | 		// to recreate the model for the dive list so we can select the newest dive
 | 
					
						
							|  |  |  | 		MainWindow::instance()->recreateDiveList(); | 
					
						
							|  |  |  | 		idx = get_idx_by_uniq_id(uniqId); | 
					
						
							|  |  |  | 		// this shouldn't be necessary - but there are reports that somehow existing dives stay selected
 | 
					
						
							|  |  |  | 		// (but not visible as selected)
 | 
					
						
							|  |  |  | 		MainWindow::instance()->dive_list()->unselectDives(); | 
					
						
							|  |  |  | 		MainWindow::instance()->dive_list()->selectDive(idx, true); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-01-08 11:53:16 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-19 11:23:11 +02:00
										 |  |  | 	if (ostcFirmwareCheck && currentState == DONE) { | 
					
						
							| 
									
										
										
										
											2017-05-26 16:40:50 +02:00
										 |  |  | 		ostcFirmwareCheck->checkLatest(this, thread.data()->internalData()); | 
					
						
							| 
									
										
										
										
											2017-05-19 11:23:11 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-01-08 09:59:01 -08:00
										 |  |  | 	accept(); | 
					
						
							| 
									
										
										
										
											2015-01-08 11:31:05 -02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-08-25 19:02:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-25 10:01:59 -03:00
										 |  |  | void DownloadFromDCWidget::markChildrenAsDisabled() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-01-08 12:56:17 -08:00
										 |  |  | 	ui.device->setEnabled(false); | 
					
						
							|  |  |  | 	ui.vendor->setEnabled(false); | 
					
						
							|  |  |  | 	ui.product->setEnabled(false); | 
					
						
							|  |  |  | 	ui.forceDownload->setEnabled(false); | 
					
						
							|  |  |  | 	ui.createNewTrip->setEnabled(false); | 
					
						
							|  |  |  | 	ui.preferDownloaded->setEnabled(false); | 
					
						
							|  |  |  | 	ui.ok->setEnabled(false); | 
					
						
							|  |  |  | 	ui.search->setEnabled(false); | 
					
						
							|  |  |  | 	ui.logToFile->setEnabled(false); | 
					
						
							|  |  |  | 	ui.dumpToFile->setEnabled(false); | 
					
						
							|  |  |  | 	ui.chooseLogFile->setEnabled(false); | 
					
						
							|  |  |  | 	ui.chooseDumpFile->setEnabled(false); | 
					
						
							|  |  |  | 	ui.selectAllButton->setEnabled(false); | 
					
						
							|  |  |  | 	ui.unselectAllButton->setEnabled(false); | 
					
						
							| 
									
										
										
										
											2015-07-06 16:18:06 +03:00
										 |  |  | 	ui.bluetoothMode->setEnabled(false); | 
					
						
							|  |  |  | 	ui.chooseBluetoothDevice->setEnabled(false); | 
					
						
							| 
									
										
										
										
											2013-08-25 10:01:59 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DownloadFromDCWidget::markChildrenAsEnabled() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-01-08 12:56:17 -08:00
										 |  |  | 	ui.device->setEnabled(true); | 
					
						
							|  |  |  | 	ui.vendor->setEnabled(true); | 
					
						
							|  |  |  | 	ui.product->setEnabled(true); | 
					
						
							|  |  |  | 	ui.forceDownload->setEnabled(true); | 
					
						
							|  |  |  | 	ui.createNewTrip->setEnabled(true); | 
					
						
							|  |  |  | 	ui.preferDownloaded->setEnabled(true); | 
					
						
							|  |  |  | 	ui.ok->setEnabled(true); | 
					
						
							|  |  |  | 	ui.cancel->setEnabled(true); | 
					
						
							|  |  |  | 	ui.search->setEnabled(true); | 
					
						
							|  |  |  | 	ui.logToFile->setEnabled(true); | 
					
						
							|  |  |  | 	ui.dumpToFile->setEnabled(true); | 
					
						
							|  |  |  | 	ui.chooseLogFile->setEnabled(true); | 
					
						
							|  |  |  | 	ui.chooseDumpFile->setEnabled(true); | 
					
						
							|  |  |  | 	ui.selectAllButton->setEnabled(true); | 
					
						
							|  |  |  | 	ui.unselectAllButton->setEnabled(true); | 
					
						
							| 
									
										
										
										
											2015-07-20 09:35:00 -07:00
										 |  |  | #if defined(BT_SUPPORT)
 | 
					
						
							| 
									
										
										
										
											2015-07-06 16:18:06 +03:00
										 |  |  | 	ui.bluetoothMode->setEnabled(true); | 
					
						
							|  |  |  | 	ui.chooseBluetoothDevice->setEnabled(true); | 
					
						
							| 
									
										
										
										
											2015-07-20 09:35:00 -07:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2015-07-06 16:18:06 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-20 09:35:00 -07:00
										 |  |  | #if defined(BT_SUPPORT)
 | 
					
						
							| 
									
										
										
										
											2015-07-06 16:18:06 +03:00
										 |  |  | void DownloadFromDCWidget::selectRemoteBluetoothDevice() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-07-06 16:35:13 +03:00
										 |  |  | 	if (!btDeviceSelectionDialog) { | 
					
						
							|  |  |  | 		btDeviceSelectionDialog = new BtDeviceSelectionDialog(this); | 
					
						
							|  |  |  | 		connect(btDeviceSelectionDialog, SIGNAL(finished(int)), | 
					
						
							|  |  |  | 			this, SLOT(bluetoothSelectionDialogIsFinished(int))); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	btDeviceSelectionDialog->show(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DownloadFromDCWidget::bluetoothSelectionDialogIsFinished(int result) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (result == QDialog::Accepted) { | 
					
						
							|  |  |  | 		/* Make the selected Bluetooth device default */ | 
					
						
							| 
									
										
										
										
											2015-08-18 22:43:42 +03:00
										 |  |  | 		QString selectedDeviceName = btDeviceSelectionDialog->getSelectedDeviceName(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (selectedDeviceName == NULL || selectedDeviceName.isEmpty()) { | 
					
						
							|  |  |  | 			ui.device->setCurrentText(btDeviceSelectionDialog->getSelectedDeviceAddress()); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			ui.device->setCurrentText(selectedDeviceName); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-07-06 16:35:13 +03:00
										 |  |  | 	} else if (result == QDialog::Rejected){ | 
					
						
							|  |  |  | 		/* Disable Bluetooth download mode */ | 
					
						
							|  |  |  | 		ui.bluetoothMode->setChecked(false); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-07-06 16:18:06 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DownloadFromDCWidget::enableBluetoothMode(int state) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ui.chooseBluetoothDevice->setEnabled(state == Qt::Checked); | 
					
						
							| 
									
										
										
										
											2015-09-07 00:12:00 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-06 16:18:06 +03:00
										 |  |  | 	if (state == Qt::Checked) | 
					
						
							|  |  |  | 		selectRemoteBluetoothDevice(); | 
					
						
							| 
									
										
										
										
											2015-09-07 00:12:00 +03:00
										 |  |  | 	else | 
					
						
							|  |  |  | 		ui.device->setCurrentIndex(-1); | 
					
						
							| 
									
										
										
										
											2013-08-25 10:01:59 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-07-20 09:35:00 -07:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2013-08-25 10:01:59 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-16 18:04:42 -03:00
										 |  |  | static void fillDeviceList(const char *name, void *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QComboBox *comboBox = (QComboBox *)data; | 
					
						
							|  |  |  | 	comboBox->addItem(name); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 13:29:40 +09:00
										 |  |  | void DownloadFromDCWidget::fill_device_list(int dc_type) | 
					
						
							| 
									
										
										
										
											2013-09-16 18:04:42 -03:00
										 |  |  | { | 
					
						
							|  |  |  | 	int deviceIndex; | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 	ui.device->clear(); | 
					
						
							| 
									
										
										
										
											2014-05-18 13:29:40 +09:00
										 |  |  | 	deviceIndex = enumerate_devices(fillDeviceList, ui.device, dc_type); | 
					
						
							| 
									
										
										
										
											2013-09-16 18:04:42 -03:00
										 |  |  | 	if (deviceIndex >= 0) | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 		ui.device->setCurrentIndex(deviceIndex); | 
					
						
							| 
									
										
										
										
											2013-09-16 18:04:42 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 |