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>
This commit is contained in:
Tomaz Canabrava 2017-05-26 16:40:50 +02:00 committed by Dirk Hohndel
parent 85e92597b5
commit 7858376727
5 changed files with 56 additions and 42 deletions

View file

@ -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;
}

View file

@ -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> ?

View file

@ -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();
}

View file

@ -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 {

View file

@ -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__