Changeset dec47e1 in subsurface


Ignore:
Timestamp:
May 27, 2017, 7:53:14 AM (7 months ago)
Author:
Dirk Hohndel <dirk@…>
Branches:
master
Children:
a55efcf
Parents:
3c3f91d
git-author:
Tomaz Canabrava <tcanabrava@…> (04/18/17 10:14:03)
git-committer:
Dirk Hohndel <dirk@…> (05/27/17 07:53:14)
Message:

Separate the download thread from the widget logic

This is important to not duplicate code for the Qml
view. Now the DownloadFromDiveComputer? widget is mostly
free from important code (that has been upgraded to the
core folder), and I can start coding the QML interface.

There are still a few functions on the desktop widget
that will die so I can call them via the QML code later.

I also touched the location of a few globals (please, let's
stop using those) - because it was declared on the
desktop code and being used in the core.

Signed-off-by: Tomaz Canabrava <tcanabrava@…>
Signed-off-by: Dirk Hohndel <dirk@…>

Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • core/CMakeLists.txt

    rb1ccd2f rdec47e1  
    8585        gpslocation.cpp
    8686        cloudstorage.cpp
     87        downloadfromdcthread.cpp
    8788
    8889        #Subsurface Qt have the Subsurface structs QObjectified for easy access via QML.
     
    9091        subsurface-qt/CylinderObjectHelper.cpp
    9192        subsurface-qt/SettingsObjectWrapper.cpp
     93
    9294        ${SERIAL_FTDI}
    9395        ${PLATFORM_SRC}
  • core/dive.h

    rbb6ceba rdec47e1  
    972972extern void average_max_depth(struct diveplan *dive, int *avg_depth, int *max_depth);
    973973
     974extern struct dive_table downloadTable;
     975
    974976#include "pref.h"
    975977
  • core/divelist.c

    r6399eaf rdec47e1  
    5656unsigned int amount_selected;
    5757
     58// We need to stop using globals, really.
     59struct dive_table downloadTable;
     60
    5861#if DEBUG_SELECTION_TRACKING
    5962void dump_selection(void)
  • core/uemis-downloader.c

    r6399eaf rdec47e1  
    7676
    7777static int max_deleted_seen = -1;
     78
     79extern struct dive_table downloadTable;
    7880
    7981/* helper function to parse the Uemis data structures */
  • desktop-widgets/downloadfromdivecomputer.cpp

    r3c3f91d rdec47e1  
    3838};
    3939
    40 struct dive_table downloadTable;
    41 
    4240// Workaround abuse of old libdc types
    4341#define DC_TRANSPORT_BLUETOOTH 1024
     
    5452        currentState(INITIAL)
    5553{
     54        fill_computer_list();
     55
     56        diveImportedModel = new DiveImportedModel(this);
     57        diveImportedModel->setDiveTable(&downloadTable);
     58        vendorModel = new QStringListModel(vendorList);
     59        QShortcut *close = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this);
     60        QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this);
     61
     62        int startingWidth = defaultModelFont().pointSize();
     63
    5664        clear_table(&downloadTable);
    5765        ui.setupUi(this);
     
    5967        ui.progressBar->setMinimum(0);
    6068        ui.progressBar->setMaximum(100);
    61         diveImportedModel = new DiveImportedModel(this);
    6269        ui.downloadedView->setModel(diveImportedModel);
    6370        ui.downloadedView->setSelectionBehavior(QAbstractItemView::SelectRows);
    6471        ui.downloadedView->setSelectionMode(QAbstractItemView::SingleSelection);
    65         int startingWidth = defaultModelFont().pointSize();
    6672        ui.downloadedView->setColumnWidth(0, startingWidth * 20);
    6773        ui.downloadedView->setColumnWidth(1, startingWidth * 10);
    6874        ui.downloadedView->setColumnWidth(2, startingWidth * 10);
     75        ui.chooseDumpFile->setEnabled(ui.dumpToFile->isChecked());
     76        ui.chooseLogFile->setEnabled(ui.logToFile->isChecked());
     77        ui.selectAllButton->setEnabled(false);
     78        ui.unselectAllButton->setEnabled(false);
     79        ui.vendor->setModel(vendorModel);
     80
     81        progress_bar_text = "";
     82
     83        timer->setInterval(200);
     84
    6985        connect(ui.downloadedView, SIGNAL(clicked(QModelIndex)), diveImportedModel, SLOT(changeSelected(QModelIndex)));
    70 
    71         progress_bar_text = "";
    72 
    73         fill_computer_list();
    74 
    75         ui.chooseDumpFile->setEnabled(ui.dumpToFile->isChecked());
    7686        connect(ui.chooseDumpFile, SIGNAL(clicked()), this, SLOT(pickDumpFile()));
    7787        connect(ui.dumpToFile, SIGNAL(stateChanged(int)), this, SLOT(checkDumpFile(int)));
    78         ui.chooseLogFile->setEnabled(ui.logToFile->isChecked());
    7988        connect(ui.chooseLogFile, SIGNAL(clicked()), this, SLOT(pickLogFile()));
    8089        connect(ui.logToFile, SIGNAL(stateChanged(int)), this, SLOT(checkLogFile(int)));
    81         ui.selectAllButton->setEnabled(false);
    82         ui.unselectAllButton->setEnabled(false);
    8390        connect(ui.selectAllButton, SIGNAL(clicked()), diveImportedModel, SLOT(selectAll()));
    8491        connect(ui.unselectAllButton, SIGNAL(clicked()), diveImportedModel, SLOT(selectNone()));
    85         vendorModel = new QStringListModel(vendorList);
    86         ui.vendor->setModel(vendorModel);
     92        connect(timer, SIGNAL(timeout()), this, SLOT(updateProgressBar()));
     93        connect(close, SIGNAL(activated()), this, SLOT(close()));
     94        connect(quit, SIGNAL(activated()), parent, SLOT(close()));
     95#if defined(BT_SUPPORT) && defined(SSRF_CUSTOM_SERIAL)
     96        connect(ui.bluetoothMode, SIGNAL(stateChanged(int)), this, SLOT(enableBluetoothMode(int)));
     97        connect(ui.chooseBluetoothDevice, SIGNAL(clicked()), this, SLOT(selectRemoteBluetoothDevice()));
     98#endif
    8799
    88100        auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
     
    97109                ui.device->setEditText(dc->dc_device());
    98110
    99         timer->setInterval(200);
    100         connect(timer, SIGNAL(timeout()), this, SLOT(updateProgressBar()));
    101111        updateState(INITIAL);
    102112        memset(&data, 0, sizeof(data));
    103         QShortcut *close = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this);
    104         connect(close, SIGNAL(activated()), this, SLOT(close()));
    105         QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this);
    106         connect(quit, SIGNAL(activated()), parent, SLOT(close()));
    107113        ui.ok->setEnabled(false);
    108114        ui.downloadCancelRetryButton->setEnabled(true);
     
    114120        btDeviceSelectionDialog = 0;
    115121        ui.chooseBluetoothDevice->setEnabled(ui.bluetoothMode->isChecked());
    116         connect(ui.bluetoothMode, SIGNAL(stateChanged(int)), this, SLOT(enableBluetoothMode(int)));
    117         connect(ui.chooseBluetoothDevice, SIGNAL(clicked()), this, SLOT(selectRemoteBluetoothDevice()));
    118122#else
    119123        ui.bluetoothMode->hide();
     
    381385        previousLast = dive_table.nr;
    382386
     387        thread->setDiveTable(&downloadTable);
    383388        thread->start();
    384389
     
    625630}
    626631
    627 DownloadThread::DownloadThread(QObject *parent, device_data_t *data) : QThread(parent),
    628         data(data)
    629 {
    630 }
    631 
    632 static QString str_error(const char *fmt, ...)
    633 {
    634         va_list args;
    635         va_start(args, fmt);
    636         const QString str = QString().vsprintf(fmt, args);
    637         va_end(args);
    638 
    639         return str;
    640 }
    641 
    642 void DownloadThread::run()
    643 {
    644         const char *errorText;
    645         import_thread_cancelled = false;
    646         data->download_table = &downloadTable;
    647         if (!strcmp(data->vendor, "Uemis"))
    648                 errorText = do_uemis_import(data);
    649         else
    650                 errorText = do_libdivecomputer_import(data);
    651         if (errorText)
    652                 error = str_error(errorText, data->devname, data->vendor, data->product);
    653 }
  • desktop-widgets/downloadfromdivecomputer.h

    r3c3f91d rdec47e1  
    1111#include "core/libdivecomputer.h"
    1212#include "desktop-widgets/configuredivecomputerdialog.h"
     13#include "core/downloadfromdcthread.h"
     14
    1315#include "ui_downloadfromdivecomputer.h"
    1416
     
    1921class QStringListModel;
    2022class DiveImportedModel;
    21 
    22 class DownloadThread : public QThread {
    23         Q_OBJECT
    24 public:
    25         DownloadThread(QObject *parent, device_data_t *data);
    26         virtual void run();
    27 
    28         QString error;
    29 
    30 private:
    31         device_data_t *data;
    32 };
    3323
    3424class DownloadFromDCWidget : public QDialog {
  • desktop-widgets/mainwindow.cpp

    r9021a44 rdec47e1  
    779779void MainWindow::on_actionDownloadDC_triggered()
    780780{
    781         DownloadFromDCWidget dlg(this);
    782 
    783         dlg.exec();
     781    DownloadFromDCWidget dlg(this);
     782         dlg.show();
    784783}
    785784
  • qt-models/diveimportedmodel.cpp

    r3c3f91d rdec47e1  
    55        firstIndex(0),
    66        lastIndex(-1),
    7         checkStates(0)
     7        checkStates(nullptr),
     8        diveTable(nullptr)
    89{
    910}
     
    3839}
    3940
     41void DiveImportedModel::setDiveTable(struct dive_table* table)
     42{
     43    diveTable = table;
     44}
     45
    4046QVariant DiveImportedModel::data(const QModelIndex &index, int role) const
    4147{
     
    4652                return QVariant();
    4753
    48         struct dive *d = get_dive_from_table(index.row() + firstIndex, &downloadTable);
     54        struct dive *d = get_dive_from_table(index.row() + firstIndex, diveTable);
    4955        if (!d)
    5056                return QVariant();
  • qt-models/diveimportedmodel.h

    r3c3f91d rdec47e1  
    33
    44#include <QAbstractTableModel>
     5#include "core/dive.h"
    56
    67class DiveImportedModel : public QAbstractTableModel
     
    910public:
    1011        DiveImportedModel(QObject *o);
     12    void setDiveTable(struct dive_table *table);
    1113        int columnCount(const QModelIndex& index = QModelIndex()) const;
    1214        int rowCount(const QModelIndex& index = QModelIndex()) const;
     
    2729        int lastIndex;
    2830        bool *checkStates;
     31    struct dive_table *diveTable;
    2932};
    3033
Note: See TracChangeset for help on using the changeset viewer.