diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2017-05-26 16:40:50 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-05-27 11:07:20 -0700 |
commit | 7858376727ee467ae59a18d84d40e3148ea3e38b (patch) | |
tree | 9dc19db2ec7facb3641e79f3804685803d2c063b | |
parent | 85e92597b561f349d24f2181e763c6ed381654ce (diff) | |
download | subsurface-7858376727ee467ae59a18d84d40e3148ea3e38b.tar.gz |
QML UI: add the DownloadThread
For this I had to also make the DCDeviceData accessible,
and for that it needed to be a pointer.
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | core/downloadfromdcthread.cpp | 24 | ||||
-rw-r--r-- | core/downloadfromdcthread.h | 9 | ||||
-rw-r--r-- | desktop-widgets/downloadfromdivecomputer.cpp | 42 | ||||
-rw-r--r-- | mobile-widgets/qml/DownloadFromDiveComputer.qml | 20 | ||||
-rw-r--r-- | subsurface-mobile-helper.cpp | 3 |
5 files changed, 56 insertions, 42 deletions
diff --git a/core/downloadfromdcthread.cpp b/core/downloadfromdcthread.cpp index 46adbe54c..3c3e0df0a 100644 --- a/core/downloadfromdcthread.cpp +++ b/core/downloadfromdcthread.cpp @@ -16,19 +16,20 @@ static QString str_error(const char *fmt, ...) return str; } -DownloadThread::DownloadThread() +DownloadThread::DownloadThread() : m_data(new DCDeviceData()) { } -void DownloadThread::setDiveTable(struct dive_table* table) -{ - m_data.setDiveTable(table); -} void DownloadThread::run() { - auto internalData = m_data.internalData(); - internalData->descriptor = descriptorLookup[m_data.vendor() + m_data.product()]; + auto internalData = m_data->internalData(); + internalData->descriptor = descriptorLookup[m_data->vendor() + m_data->product()]; + internalData->download_table = &downloadTable; + + downloadTable.nr = 0; + qDebug() << "Starting the thread" << downloadTable.nr; + Q_ASSERT(internalData->download_table != nullptr); const char *errorText; import_thread_cancelled = false; @@ -38,6 +39,8 @@ void DownloadThread::run() errorText = do_libdivecomputer_import(internalData); if (errorText) error = str_error(errorText, internalData->devname, internalData->vendor, internalData->product); + + qDebug() << "Finishing the thread" << errorText << "dives downloaded" << downloadTable.nr; } void fill_computer_list() @@ -96,7 +99,7 @@ DCDeviceData::DCDeviceData(QObject *parent) : QObject(parent) data.deviceid = 0; } -DCDeviceData & DownloadThread::data() +DCDeviceData * DownloadThread::data() { return m_data; } @@ -210,8 +213,3 @@ device_data_t* DCDeviceData::internalData() { return &data; } - -void DCDeviceData::setDiveTable(struct dive_table* downloadTable) -{ - data.download_table = downloadTable; -} diff --git a/core/downloadfromdcthread.h b/core/downloadfromdcthread.h index b20fe17a6..0a188dcad 100644 --- a/core/downloadfromdcthread.h +++ b/core/downloadfromdcthread.h @@ -38,8 +38,6 @@ public: int deviceId() const; int diveId() const; - void setDiveTable(struct dive_table* downloadTable); - /* this needs to be a pointer to make the C-API happy */ device_data_t* internalData(); @@ -60,16 +58,17 @@ private: class DownloadThread : public QThread { Q_OBJECT + Q_PROPERTY(DCDeviceData* deviceData MEMBER m_data) + public: DownloadThread(); - void setDiveTable(struct dive_table *table); void run() override; - DCDeviceData& data(); + DCDeviceData *data(); QString error; private: - DCDeviceData m_data; + DCDeviceData *m_data; }; //TODO: QList<product> ? diff --git a/desktop-widgets/downloadfromdivecomputer.cpp b/desktop-widgets/downloadfromdivecomputer.cpp index b6cdfa64f..e935dec6e 100644 --- a/desktop-widgets/downloadfromdivecomputer.cpp +++ b/desktop-widgets/downloadfromdivecomputer.cpp @@ -261,18 +261,18 @@ void DownloadFromDCWidget::on_downloadCancelRetryButton_clicked() ui.cancel->setEnabled(false); ui.downloadCancelRetryButton->setText(tr("Cancel download")); - auto& data = thread.data(); - data.setVendor(ui.vendor->currentText()); - data.setProduct(ui.product->currentText()); + auto data = thread.data(); + data->setVendor(ui.vendor->currentText()); + data->setProduct(ui.product->currentText()); #if defined(BT_SUPPORT) - data.setBluetoothMode(ui.bluetoothMode->isChecked()); - if (data.bluetoothMode() && btDeviceSelectionDialog != NULL) { + data->setBluetoothMode(ui.bluetoothMode->isChecked()); + if (data->bluetoothMode() && btDeviceSelectionDialog != NULL) { // Get the selected device address - data.setDevName(btDeviceSelectionDialog->getSelectedDeviceAddress()); + data->setDevName(btDeviceSelectionDialog->getSelectedDeviceAddress()); } else // this breaks an "else if" across lines... not happy... #endif - if (data.vendor() == "Uemis") { + if (data->vendor() == "Uemis") { char *colon; char *devname = strdup(ui.device->currentText().toUtf8().data()); @@ -280,21 +280,20 @@ void DownloadFromDCWidget::on_downloadCancelRetryButton_clicked() *(colon + 2) = '\0'; fprintf(stderr, "shortened devname to \"%s\"", devname); } - data.setDevName(devname); + data->setDevName(devname); } else { - data.setDevName(ui.device->currentText()); + data->setDevName(ui.device->currentText()); } - //TODO: Add the descriptor function. - // data.descriptor = descriptorLookup[ui.vendor->currentText() + ui.product->currentText()]; - data.setForceDownload(ui.forceDownload->isChecked()); - data.setCreateNewTrip(ui.createNewTrip->isChecked()); - data.setSaveLog(ui.chooseLogFile->isChecked()); - data.setSaveDump(ui.chooseDumpFile->isChecked()); + + data->setForceDownload(ui.forceDownload->isChecked()); + data->setCreateNewTrip(ui.createNewTrip->isChecked()); + data->setSaveLog(ui.chooseLogFile->isChecked()); + data->setSaveDump(ui.chooseDumpFile->isChecked()); auto dc = SettingsObjectWrapper::instance()->dive_computer_settings; - dc->setVendor(data.vendor()); - dc->setProduct(data.product()); - dc->setDevice(data.devName()); + dc->setVendor(data->vendor()); + dc->setProduct(data->product()); + dc->setDevice(data->devName()); #if defined(BT_SUPPORT) && defined(SSRF_CUSTOM_SERIAL) dc->setDownloadMode(ui.bluetoothMode->isChecked() ? DC_TRANSPORT_BLUETOOTH : DC_TRANSPORT_SERIAL); @@ -309,9 +308,6 @@ void DownloadFromDCWidget::on_downloadCancelRetryButton_clicked() // before we start, remember where the dive_table ended previousLast = dive_table.nr; - - // TODO: the downloadTable should something inside the thrad or should be something from outside? - thread.setDiveTable(&downloadTable); thread.start(); // FIXME: We should get the _actual_ device info instead of whatever @@ -323,7 +319,7 @@ void DownloadFromDCWidget::on_downloadCancelRetryButton_clicked() // We shouldn't do this for memory dumps. if ((product == "OSTC 3" || product == "OSTC 3+" || product == "OSTC Cr" || product == "OSTC Sport" || - product == "OSTC 4") && ! data.saveDump()) + product == "OSTC 4") && ! data->saveDump()) ostcFirmwareCheck = new OstcFirmwareCheck(product); } @@ -451,7 +447,7 @@ void DownloadFromDCWidget::on_ok_clicked() } if (ostcFirmwareCheck && currentState == DONE) { - ostcFirmwareCheck->checkLatest(this, thread.data().internalData()); + ostcFirmwareCheck->checkLatest(this, thread.data()->internalData()); } accept(); } diff --git a/mobile-widgets/qml/DownloadFromDiveComputer.qml b/mobile-widgets/qml/DownloadFromDiveComputer.qml index ecab94774..4587f2e98 100644 --- a/mobile-widgets/qml/DownloadFromDiveComputer.qml +++ b/mobile-widgets/qml/DownloadFromDiveComputer.qml @@ -28,6 +28,24 @@ Kirigami.Page { } ] */ + DCDownloadThread { + id: downlodaThread + deviceData.vendor : comboVendor.currentText + deviceData.product : comboProduct.currentText + + //TODO: make this dynamic? + deviceData.devName : "/tmp/ttyS1" + + //TODO: Make this the default on the C++ + deviceData.bluetoothMode : false + deviceData.forceDownload : false + deviceData.createNewTrip : false + deviceData.deviceId : 0 + deviceData.diveId : 0 + deviceData.saveDump : false + deviceData.saveLog : false + } + ColumnLayout { anchors.top: parent.top height: parent.height @@ -59,7 +77,7 @@ Kirigami.Page { text: qsTr("Download") onClicked: { text: qsTr("Retry") - stackView.pop(); + downlodaThread.start() } } Button { diff --git a/subsurface-mobile-helper.cpp b/subsurface-mobile-helper.cpp index 4d960181c..dec4fa160 100644 --- a/subsurface-mobile-helper.cpp +++ b/subsurface-mobile-helper.cpp @@ -37,6 +37,9 @@ void run_ui() qmlRegisterType<QMLManager>("org.subsurfacedivelog.mobile", 1, 0, "QMLManager"); qmlRegisterType<QMLProfile>("org.subsurfacedivelog.mobile", 1, 0, "QMLProfile"); + qmlRegisterType<DCDeviceData>("org.subsurfacedivelog.mobile", 1, 0, "DCDeviceData"); + qmlRegisterType<DownloadThread>("org.subsurfacedivelog.mobile", 1, 0, "DCDownloadThread"); + QQmlApplicationEngine engine; KirigamiPlugin::getInstance().registerTypes(); #if __APPLE__ |