mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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:
parent
85e92597b5
commit
7858376727
5 changed files with 56 additions and 42 deletions
|
@ -16,19 +16,20 @@ static QString str_error(const char *fmt, ...)
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
DownloadThread::DownloadThread()
|
DownloadThread::DownloadThread() : m_data(new DCDeviceData())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadThread::setDiveTable(struct dive_table* table)
|
|
||||||
{
|
|
||||||
m_data.setDiveTable(table);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DownloadThread::run()
|
void DownloadThread::run()
|
||||||
{
|
{
|
||||||
auto internalData = m_data.internalData();
|
auto internalData = m_data->internalData();
|
||||||
internalData->descriptor = descriptorLookup[m_data.vendor() + m_data.product()];
|
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);
|
Q_ASSERT(internalData->download_table != nullptr);
|
||||||
const char *errorText;
|
const char *errorText;
|
||||||
import_thread_cancelled = false;
|
import_thread_cancelled = false;
|
||||||
|
@ -38,6 +39,8 @@ void DownloadThread::run()
|
||||||
errorText = do_libdivecomputer_import(internalData);
|
errorText = do_libdivecomputer_import(internalData);
|
||||||
if (errorText)
|
if (errorText)
|
||||||
error = str_error(errorText, internalData->devname, internalData->vendor, internalData->product);
|
error = str_error(errorText, internalData->devname, internalData->vendor, internalData->product);
|
||||||
|
|
||||||
|
qDebug() << "Finishing the thread" << errorText << "dives downloaded" << downloadTable.nr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fill_computer_list()
|
void fill_computer_list()
|
||||||
|
@ -96,7 +99,7 @@ DCDeviceData::DCDeviceData(QObject *parent) : QObject(parent)
|
||||||
data.deviceid = 0;
|
data.deviceid = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
DCDeviceData & DownloadThread::data()
|
DCDeviceData * DownloadThread::data()
|
||||||
{
|
{
|
||||||
return m_data;
|
return m_data;
|
||||||
}
|
}
|
||||||
|
@ -210,8 +213,3 @@ device_data_t* DCDeviceData::internalData()
|
||||||
{
|
{
|
||||||
return &data;
|
return &data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DCDeviceData::setDiveTable(struct dive_table* downloadTable)
|
|
||||||
{
|
|
||||||
data.download_table = downloadTable;
|
|
||||||
}
|
|
||||||
|
|
|
@ -38,8 +38,6 @@ public:
|
||||||
int deviceId() const;
|
int deviceId() const;
|
||||||
int diveId() const;
|
int diveId() const;
|
||||||
|
|
||||||
void setDiveTable(struct dive_table* downloadTable);
|
|
||||||
|
|
||||||
/* this needs to be a pointer to make the C-API happy */
|
/* this needs to be a pointer to make the C-API happy */
|
||||||
device_data_t* internalData();
|
device_data_t* internalData();
|
||||||
|
|
||||||
|
@ -60,16 +58,17 @@ private:
|
||||||
|
|
||||||
class DownloadThread : public QThread {
|
class DownloadThread : public QThread {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(DCDeviceData* deviceData MEMBER m_data)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DownloadThread();
|
DownloadThread();
|
||||||
void setDiveTable(struct dive_table *table);
|
|
||||||
void run() override;
|
void run() override;
|
||||||
|
|
||||||
DCDeviceData& data();
|
DCDeviceData *data();
|
||||||
QString error;
|
QString error;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DCDeviceData m_data;
|
DCDeviceData *m_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
//TODO: QList<product> ?
|
//TODO: QList<product> ?
|
||||||
|
|
|
@ -261,18 +261,18 @@ void DownloadFromDCWidget::on_downloadCancelRetryButton_clicked()
|
||||||
ui.cancel->setEnabled(false);
|
ui.cancel->setEnabled(false);
|
||||||
ui.downloadCancelRetryButton->setText(tr("Cancel download"));
|
ui.downloadCancelRetryButton->setText(tr("Cancel download"));
|
||||||
|
|
||||||
auto& data = thread.data();
|
auto data = thread.data();
|
||||||
data.setVendor(ui.vendor->currentText());
|
data->setVendor(ui.vendor->currentText());
|
||||||
data.setProduct(ui.product->currentText());
|
data->setProduct(ui.product->currentText());
|
||||||
#if defined(BT_SUPPORT)
|
#if defined(BT_SUPPORT)
|
||||||
data.setBluetoothMode(ui.bluetoothMode->isChecked());
|
data->setBluetoothMode(ui.bluetoothMode->isChecked());
|
||||||
if (data.bluetoothMode() && btDeviceSelectionDialog != NULL) {
|
if (data->bluetoothMode() && btDeviceSelectionDialog != NULL) {
|
||||||
// Get the selected device address
|
// Get the selected device address
|
||||||
data.setDevName(btDeviceSelectionDialog->getSelectedDeviceAddress());
|
data->setDevName(btDeviceSelectionDialog->getSelectedDeviceAddress());
|
||||||
} else
|
} else
|
||||||
// this breaks an "else if" across lines... not happy...
|
// this breaks an "else if" across lines... not happy...
|
||||||
#endif
|
#endif
|
||||||
if (data.vendor() == "Uemis") {
|
if (data->vendor() == "Uemis") {
|
||||||
char *colon;
|
char *colon;
|
||||||
char *devname = strdup(ui.device->currentText().toUtf8().data());
|
char *devname = strdup(ui.device->currentText().toUtf8().data());
|
||||||
|
|
||||||
|
@ -280,21 +280,20 @@ void DownloadFromDCWidget::on_downloadCancelRetryButton_clicked()
|
||||||
*(colon + 2) = '\0';
|
*(colon + 2) = '\0';
|
||||||
fprintf(stderr, "shortened devname to \"%s\"", devname);
|
fprintf(stderr, "shortened devname to \"%s\"", devname);
|
||||||
}
|
}
|
||||||
data.setDevName(devname);
|
data->setDevName(devname);
|
||||||
} else {
|
} 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.setForceDownload(ui.forceDownload->isChecked());
|
data->setCreateNewTrip(ui.createNewTrip->isChecked());
|
||||||
data.setCreateNewTrip(ui.createNewTrip->isChecked());
|
data->setSaveLog(ui.chooseLogFile->isChecked());
|
||||||
data.setSaveLog(ui.chooseLogFile->isChecked());
|
data->setSaveDump(ui.chooseDumpFile->isChecked());
|
||||||
data.setSaveDump(ui.chooseDumpFile->isChecked());
|
|
||||||
|
|
||||||
auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
|
auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
|
||||||
dc->setVendor(data.vendor());
|
dc->setVendor(data->vendor());
|
||||||
dc->setProduct(data.product());
|
dc->setProduct(data->product());
|
||||||
dc->setDevice(data.devName());
|
dc->setDevice(data->devName());
|
||||||
|
|
||||||
#if defined(BT_SUPPORT) && defined(SSRF_CUSTOM_SERIAL)
|
#if defined(BT_SUPPORT) && defined(SSRF_CUSTOM_SERIAL)
|
||||||
dc->setDownloadMode(ui.bluetoothMode->isChecked() ? DC_TRANSPORT_BLUETOOTH : DC_TRANSPORT_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
|
// before we start, remember where the dive_table ended
|
||||||
previousLast = dive_table.nr;
|
previousLast = dive_table.nr;
|
||||||
|
|
||||||
// TODO: the downloadTable should something inside the thrad or should be something from outside?
|
|
||||||
thread.setDiveTable(&downloadTable);
|
|
||||||
thread.start();
|
thread.start();
|
||||||
|
|
||||||
// FIXME: We should get the _actual_ device info instead of whatever
|
// 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.
|
// We shouldn't do this for memory dumps.
|
||||||
if ((product == "OSTC 3" || product == "OSTC 3+" ||
|
if ((product == "OSTC 3" || product == "OSTC 3+" ||
|
||||||
product == "OSTC Cr" || product == "OSTC Sport" ||
|
product == "OSTC Cr" || product == "OSTC Sport" ||
|
||||||
product == "OSTC 4") && ! data.saveDump())
|
product == "OSTC 4") && ! data->saveDump())
|
||||||
ostcFirmwareCheck = new OstcFirmwareCheck(product);
|
ostcFirmwareCheck = new OstcFirmwareCheck(product);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -451,7 +447,7 @@ void DownloadFromDCWidget::on_ok_clicked()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ostcFirmwareCheck && currentState == DONE) {
|
if (ostcFirmwareCheck && currentState == DONE) {
|
||||||
ostcFirmwareCheck->checkLatest(this, thread.data().internalData());
|
ostcFirmwareCheck->checkLatest(this, thread.data()->internalData());
|
||||||
}
|
}
|
||||||
accept();
|
accept();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
ColumnLayout {
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
height: parent.height
|
height: parent.height
|
||||||
|
@ -59,7 +77,7 @@ Kirigami.Page {
|
||||||
text: qsTr("Download")
|
text: qsTr("Download")
|
||||||
onClicked: {
|
onClicked: {
|
||||||
text: qsTr("Retry")
|
text: qsTr("Retry")
|
||||||
stackView.pop();
|
downlodaThread.start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Button {
|
Button {
|
||||||
|
|
|
@ -37,6 +37,9 @@ void run_ui()
|
||||||
qmlRegisterType<QMLManager>("org.subsurfacedivelog.mobile", 1, 0, "QMLManager");
|
qmlRegisterType<QMLManager>("org.subsurfacedivelog.mobile", 1, 0, "QMLManager");
|
||||||
qmlRegisterType<QMLProfile>("org.subsurfacedivelog.mobile", 1, 0, "QMLProfile");
|
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;
|
QQmlApplicationEngine engine;
|
||||||
KirigamiPlugin::getInstance().registerTypes();
|
KirigamiPlugin::getInstance().registerTypes();
|
||||||
#if __APPLE__
|
#if __APPLE__
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue