Changeset 09904dd in subsurface


Ignore:
Timestamp:
May 27, 2017, 11:07:19 AM (4 weeks ago)
Author:
Dirk Hohndel <dirk@…>
Branches:
master
Children:
c370b87
Parents:
acbe5de
git-author:
Tomaz Canabrava <tcanabrava@…> (05/19/17 02:23:11)
git-committer:
Dirk Hohndel <dirk@…> (05/27/17 11:07:19)
Message:

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@…>
Signed-off-by: Dirk Hohndel <dirk@…>

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • core/downloadfromdcthread.cpp

    racbe5de r09904dd  
    1616}
    1717
    18 DownloadThread::DownloadThread(QObject *parent, device_data_t *data) : QThread(parent),
    19         data(data)
    20 {
    21         data->download_table = nullptr;
     18DownloadThread::DownloadThread()
     19{
    2220}
    2321
    2422void DownloadThread::setDiveTable(struct dive_table* table)
    2523{
    26         data->download_table = table;
     24        m_data.setDiveTable(table);
    2725}
    2826
    2927void DownloadThread::run()
    3028{
    31         Q_ASSERT(data->download_table != nullptr);
     29        auto internalData = m_data.internalData();
     30        Q_ASSERT(internalData->download_table != nullptr);
    3231        const char *errorText;
    3332        import_thread_cancelled = false;
    34         if (!strcmp(data->vendor, "Uemis"))
    35                 errorText = do_uemis_import(data);
     33        if (!strcmp(internalData->vendor, "Uemis"))
     34                errorText = do_uemis_import(internalData);
    3635        else
    37                 errorText = do_libdivecomputer_import(data);
     36                errorText = do_libdivecomputer_import(internalData);
    3837        if (errorText)
    39                 error = str_error(errorText, data->devname, data->vendor, data->product);
     38                error = str_error(errorText, internalData->devname, internalData->vendor, internalData->product);
    4039}
    4140
     
    8786}
    8887
     88DCDeviceData::DCDeviceData(QObject *parent) : QObject(parent)
     89{
     90        memset(&data, 0, sizeof(data));
     91        data.trip = nullptr;
     92        data.download_table = nullptr;
     93        data.diveid = 0;
     94        data.deviceid = 0;
     95}
     96
     97DCDeviceData & DownloadThread::data()
     98{
     99        return m_data;
     100}
     101
    89102QString DCDeviceData::vendor() const
    90103{
     
    105118{
    106119        return "";
    107 //      return data.descriptor;
    108120}
    109121
     
    177189        data.diveid = diveId;
    178190}
     191
     192void DCDeviceData::setSaveDump(bool save)
     193{
     194        data.libdc_dump = save;
     195}
     196
     197bool DCDeviceData::saveDump() const
     198{
     199        return data.libdc_dump;
     200}
     201
     202void DCDeviceData::setSaveLog(bool saveLog)
     203{
     204        data.libdc_log = saveLog;
     205}
     206
     207bool DCDeviceData::saveLog() const
     208{
     209        return data.libdc_log;
     210}
     211
     212device_data_t* DCDeviceData::internalData()
     213{
     214        return &data;
     215}
     216
     217void DCDeviceData::setDiveTable(struct dive_table* downloadTable)
     218{
     219        data.download_table = downloadTable;
     220}
  • core/downloadfromdcthread.h

    racbe5de r09904dd  
    2121        Q_PROPERTY(int deviceId READ deviceId WRITE setDeviceId)
    2222        Q_PROPERTY(int diveId READ diveId WRITE setDiveId)
     23        Q_PROPERTY(bool saveDump READ saveDump WRITE setSaveDump)
     24        Q_PROPERTY(bool saveLog READ saveLog WRITE setSaveLog)
    2325
    2426public:
     
    3234        bool forceDownload() const;
    3335        bool createNewTrip() const;
     36        bool saveDump() const;
     37        bool saveLog() const;
    3438        int deviceId() const;
    3539        int diveId() const;
     40
     41        void setDiveTable(struct dive_table* downloadTable);
     42
     43        /* this needs to be a pointer to make the C-API happy */
     44        device_data_t* internalData();
    3645
    3746public slots:
     
    4554        void setDeviceId(int deviceId);
    4655        void setDiveId(int diveId);
    47 
     56        void setSaveDump(bool dumpMode);
     57        void setSaveLog(bool saveLog);
    4858private:
    4959        device_data_t data;
     
    5363        Q_OBJECT
    5464public:
    55         DownloadThread(QObject *parent, device_data_t *data);
     65        DownloadThread();
    5666        void setDiveTable(struct dive_table *table);
    5767        void run() override;
    5868
     69        DCDeviceData& data();
    5970        QString error;
    6071
    6172private:
    62         device_data_t *data;
     73        DCDeviceData m_data;
    6374};
    6475
     76//TODO: QList<product> ?
    6577struct product {
    6678        const char *product;
     
    6981};
    7082
     83//TODO: QList<vendor> ?
    7184struct vendor {
    7285        const char *vendor;
     
    7588};
    7689
     90//TODO: C++ify descriptor?
    7791struct mydescriptor {
    7892        const char *vendor;
  • desktop-widgets/downloadfromdivecomputer.cpp

    ra55efcf r09904dd  
    2323
    2424DownloadFromDCWidget::DownloadFromDCWidget(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f),
    25         thread(0),
    2625        downloading(false),
    2726        previousLast(0),
     
    8988
    9089        updateState(INITIAL);
    91         memset(&data, 0, sizeof(data));
    9290        ui.ok->setEnabled(false);
    9391        ui.downloadCancelRetryButton->setEnabled(true);
     
    189187        else if (state == ERROR) {
    190188                timer->stop();
    191                 QMessageBox::critical(this, TITLE_OR_TEXT(tr("Error"), this->thread->error), QMessageBox::Ok);
     189                QMessageBox::critical(this, TITLE_OR_TEXT(tr("Error"), thread.error), QMessageBox::Ok);
    192190                markChildrenAsEnabled();
    193191                progress_bar_text = "";
     
    264262        ui.downloadCancelRetryButton->setText(tr("Cancel download"));
    265263
    266         // I don't really think that create/destroy the thread
    267         // is really necessary.
    268         if (thread) {
    269                 thread->deleteLater();
    270         }
    271 
    272         data.vendor = strdup(ui.vendor->currentText().toUtf8().data());
    273         data.product = strdup(ui.product->currentText().toUtf8().data());
     264        auto& data = thread.data();
     265        data.setVendor(ui.vendor->currentText());
     266        data.setProduct(ui.product->currentText());
    274267#if defined(BT_SUPPORT)
    275         data.bluetooth_mode = ui.bluetoothMode->isChecked();
    276         if (data.bluetooth_mode && btDeviceSelectionDialog != NULL) {
     268        data.setBluetoothMode(ui.bluetoothMode->isChecked());
     269        if (data.bluetoothMode() && btDeviceSelectionDialog != NULL) {
    277270                // Get the selected device address
    278                 data.devname = strdup(btDeviceSelectionDialog->getSelectedDeviceAddress().toUtf8().data());
     271                data.setDevName(btDeviceSelectionDialog->getSelectedDeviceAddress());
    279272        } else
    280273                // this breaks an "else if" across lines... not happy...
    281274#endif
    282         if (same_string(data.vendor, "Uemis")) {
     275        if (data.vendor() == "Uemis") {
    283276                char *colon;
    284277                char *devname = strdup(ui.device->currentText().toUtf8().data());
     
    286279                if ((colon = strstr(devname, ":\\ (UEMISSDA)")) != NULL) {
    287280                        *(colon + 2) = '\0';
    288                         fprintf(stderr, "shortened devname to \"%s\"", data.devname);
     281                        fprintf(stderr, "shortened devname to \"%s\"", devname);
    289282                }
    290                 data.devname = devname;
     283                data.setDevName(devname);
    291284        } else {
    292                 data.devname = strdup(ui.device->currentText().toUtf8().data());
    293         }
    294         data.descriptor = descriptorLookup[ui.vendor->currentText() + ui.product->currentText()];
    295         data.force_download = ui.forceDownload->isChecked();
    296         data.create_new_trip = ui.createNewTrip->isChecked();
    297         data.trip = NULL;
    298         data.deviceid = data.diveid = 0;
     285                data.setDevName(ui.device->currentText());
     286        }
     287        //TODO: Add the descriptor function.
     288        // data.descriptor = descriptorLookup[ui.vendor->currentText() + ui.product->currentText()];
     289        data.setForceDownload(ui.forceDownload->isChecked());
     290        data.setCreateNewTrip(ui.createNewTrip->isChecked());
     291        data.setSaveLog(ui.chooseLogFile->isChecked());
     292        data.setSaveDump(ui.chooseDumpFile->isChecked());
    299293
    300294        auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
    301         dc->setVendor(data.vendor);
    302         dc->setProduct(data.product);
    303         dc->setDevice(data.devname);
     295        dc->setVendor(data.vendor());
     296        dc->setProduct(data.product());
     297        dc->setDevice(data.devName());
     298
    304299#if defined(BT_SUPPORT) && defined(SSRF_CUSTOM_SERIAL)
    305300        dc->setDownloadMode(ui.bluetoothMode->isChecked() ? DC_TRANSPORT_BLUETOOTH : DC_TRANSPORT_SERIAL);
    306301#endif
    307302
    308         thread = new DownloadThread(this, &data);
    309         connect(thread, SIGNAL(finished()),
     303        connect(&thread, SIGNAL(finished()),
    310304                this, SLOT(onDownloadThreadFinished()), Qt::QueuedConnection);
    311305
    312306        //TODO: Don't call mainwindow.
    313307        MainWindow *w = MainWindow::instance();
    314         connect(thread, SIGNAL(finished()), w, SLOT(refreshDisplay()));
     308        connect(&thread, SIGNAL(finished()), w, SLOT(refreshDisplay()));
    315309
    316310        // before we start, remember where the dive_table ended
    317311        previousLast = dive_table.nr;
    318312
    319         thread->setDiveTable(&downloadTable);
    320         thread->start();
     313        // TODO: the downloadTable should something inside the thrad or should be something from outside?
     314        thread.setDiveTable(&downloadTable);
     315        thread.start();
    321316
    322317        // FIXME: We should get the _actual_ device info instead of whatever
     
    329324        if ((product == "OSTC 3" || product == "OSTC 3+" ||
    330325                        product == "OSTC Cr" || product == "OSTC Sport" ||
    331                         product == "OSTC 4") && !data.libdc_dump)
    332                 ostcFirmwareCheck = new OstcFirmwareCheck(product);
     326                        product == "OSTC 4") && ! data.saveDump())
     327        ostcFirmwareCheck = new OstcFirmwareCheck(product);
    333328}
    334329
     
    341336{
    342337        ui.chooseLogFile->setEnabled(state == Qt::Checked);
    343         data.libdc_log = (state == Qt::Checked);
     338        // TODO: Verify the Thread.
    344339        if (state == Qt::Checked && logFile.isEmpty()) {
    345340                pickLogFile();
     
    363358{
    364359        ui.chooseDumpFile->setEnabled(state == Qt::Checked);
    365         data.libdc_dump = (state == Qt::Checked);
    366360        if (state == Qt::Checked) {
    367361                if (dumpFile.isEmpty())
     
    399393{
    400394        if (currentState == DOWNLOADING) {
    401                 if (thread->error.isEmpty())
     395                if (thread.error.isEmpty())
    402396                        updateState(DONE);
    403397                else
     
    412406                diveImportedModel->setImportedDivesIndexes(0, downloadTable.nr - 1);
    413407        }
    414 
    415408}
    416409
     
    459452        }
    460453
    461         if (ostcFirmwareCheck && currentState == DONE)
    462                 ostcFirmwareCheck->checkLatest(this, &data);
     454        if (ostcFirmwareCheck && currentState == DONE) {
     455                ostcFirmwareCheck->checkLatest(this, thread.data().internalData());
     456        }
    463457        accept();
    464458}
  • desktop-widgets/downloadfromdivecomputer.h

    ra55efcf r09904dd  
    6161
    6262        Ui::DownloadFromDiveComputer ui;
    63         DownloadThread *thread;
     63        DownloadThread thread;
    6464        bool downloading;
    6565
    66         device_data_t data;
    6766        int previousLast;
    6867
Note: See TracChangeset for help on using the changeset viewer.