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