diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2017-05-19 11:23:11 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-05-27 11:07:19 -0700 |
commit | 09904ddff525ccf3f1165956e0d2d5483290bf12 (patch) | |
tree | b1c54567323913929bb1addbf5d19f11eb3c8db6 /core | |
parent | acbe5de1cbc446884a41e9c96b3777d2acc692c4 (diff) | |
download | subsurface-09904ddff525ccf3f1165956e0d2d5483290bf12.tar.gz |
Extract the device_data_t into helper class
Keeping the Desktop and QML versions of Subsurface
using the same codebase will keep the code saner,
this change makes the Desktop version use the
DCDeviceData helper sturct that encapsulates
the device_data_t member for easy access on the
QML. This also helped move a bit of initializations
from the UI to the Core - and that's always good.
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core')
-rw-r--r-- | core/downloadfromdcthread.cpp | 62 | ||||
-rw-r--r-- | core/downloadfromdcthread.h | 20 |
2 files changed, 69 insertions, 13 deletions
diff --git a/core/downloadfromdcthread.cpp b/core/downloadfromdcthread.cpp index 43a6334dc..e90481a0b 100644 --- a/core/downloadfromdcthread.cpp +++ b/core/downloadfromdcthread.cpp @@ -15,28 +15,27 @@ static QString str_error(const char *fmt, ...) return str; } -DownloadThread::DownloadThread(QObject *parent, device_data_t *data) : QThread(parent), - data(data) +DownloadThread::DownloadThread() { - data->download_table = nullptr; } void DownloadThread::setDiveTable(struct dive_table* table) { - data->download_table = table; + m_data.setDiveTable(table); } void DownloadThread::run() { - Q_ASSERT(data->download_table != nullptr); + auto internalData = m_data.internalData(); + Q_ASSERT(internalData->download_table != nullptr); const char *errorText; import_thread_cancelled = false; - if (!strcmp(data->vendor, "Uemis")) - errorText = do_uemis_import(data); + if (!strcmp(internalData->vendor, "Uemis")) + errorText = do_uemis_import(internalData); else - errorText = do_libdivecomputer_import(data); + errorText = do_libdivecomputer_import(internalData); if (errorText) - error = str_error(errorText, data->devname, data->vendor, data->product); + error = str_error(errorText, internalData->devname, internalData->vendor, internalData->product); } void fill_computer_list() @@ -86,6 +85,20 @@ void fill_computer_list() qSort(vendorList); } +DCDeviceData::DCDeviceData(QObject *parent) : QObject(parent) +{ + memset(&data, 0, sizeof(data)); + data.trip = nullptr; + data.download_table = nullptr; + data.diveid = 0; + data.deviceid = 0; +} + +DCDeviceData & DownloadThread::data() +{ + return m_data; +} + QString DCDeviceData::vendor() const { return data.vendor; @@ -104,7 +117,6 @@ QString DCDeviceData::devName() const QString DCDeviceData::descriptor() const { return ""; -// return data.descriptor; } bool DCDeviceData::bluetoothMode() const @@ -176,3 +188,33 @@ void DCDeviceData::setDiveId(int diveId) { data.diveid = diveId; } + +void DCDeviceData::setSaveDump(bool save) +{ + data.libdc_dump = save; +} + +bool DCDeviceData::saveDump() const +{ + return data.libdc_dump; +} + +void DCDeviceData::setSaveLog(bool saveLog) +{ + data.libdc_log = saveLog; +} + +bool DCDeviceData::saveLog() const +{ + return data.libdc_log; +} + +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 d0f088b51..d2c3408f2 100644 --- a/core/downloadfromdcthread.h +++ b/core/downloadfromdcthread.h @@ -20,6 +20,8 @@ class DCDeviceData : public QObject { Q_PROPERTY(bool createNewTrip READ createNewTrip WRITE setCreateNewTrip) Q_PROPERTY(int deviceId READ deviceId WRITE setDeviceId) Q_PROPERTY(int diveId READ diveId WRITE setDiveId) + Q_PROPERTY(bool saveDump READ saveDump WRITE setSaveDump) + Q_PROPERTY(bool saveLog READ saveLog WRITE setSaveLog) public: DCDeviceData(QObject *parent = nullptr); @@ -31,9 +33,16 @@ public: bool bluetoothMode() const; bool forceDownload() const; bool createNewTrip() const; + bool saveDump() const; + bool saveLog() const; 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(); + public slots: void setVendor(const QString& vendor); void setProduct(const QString& product); @@ -44,7 +53,8 @@ public slots: void setCreateNewTrip(bool create); void setDeviceId(int deviceId); void setDiveId(int diveId); - + void setSaveDump(bool dumpMode); + void setSaveLog(bool saveLog); private: device_data_t data; }; @@ -52,28 +62,32 @@ private: class DownloadThread : public QThread { Q_OBJECT public: - DownloadThread(QObject *parent, device_data_t *data); + DownloadThread(); void setDiveTable(struct dive_table *table); void run() override; + DCDeviceData& data(); QString error; private: - device_data_t *data; + DCDeviceData m_data; }; +//TODO: QList<product> ? struct product { const char *product; dc_descriptor_t *descriptor; struct product *next; }; +//TODO: QList<vendor> ? struct vendor { const char *vendor; struct product *productlist; struct vendor *next; }; +//TODO: C++ify descriptor? struct mydescriptor { const char *vendor; const char *product; |