2016-04-05 05:02:03 +00:00
|
|
|
#include "desktop-widgets/downloadfromdivecomputer.h"
|
|
|
|
#include "core/helpers.h"
|
|
|
|
#include "desktop-widgets/mainwindow.h"
|
|
|
|
#include "desktop-widgets/divelistview.h"
|
|
|
|
#include "core/display.h"
|
|
|
|
#include "core/uemis.h"
|
2016-08-10 21:10:15 +00:00
|
|
|
#include "core/subsurface-qt/SettingsObjectWrapper.h"
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "qt-models/models.h"
|
2015-02-09 21:51:31 +00:00
|
|
|
|
2013-08-25 22:02:30 +00:00
|
|
|
#include <QTimer>
|
2013-12-25 00:26:00 +00:00
|
|
|
#include <QFileDialog>
|
2013-09-01 14:14:54 +00:00
|
|
|
#include <QMessageBox>
|
2014-04-25 17:44:23 +00:00
|
|
|
#include <QShortcut>
|
2013-05-20 20:58:06 +00:00
|
|
|
|
|
|
|
struct product {
|
|
|
|
const char *product;
|
|
|
|
dc_descriptor_t *descriptor;
|
|
|
|
struct product *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct vendor {
|
|
|
|
const char *vendor;
|
|
|
|
struct product *productlist;
|
|
|
|
struct vendor *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mydescriptor {
|
|
|
|
const char *vendor;
|
|
|
|
const char *product;
|
|
|
|
dc_family_t type;
|
|
|
|
unsigned int model;
|
|
|
|
};
|
2013-05-20 19:43:33 +00:00
|
|
|
|
2014-05-22 18:40:22 +00:00
|
|
|
namespace DownloadFromDcGlobal {
|
2013-05-20 19:43:33 +00:00
|
|
|
const char *err_string;
|
|
|
|
};
|
|
|
|
|
2015-01-09 22:39:43 +00:00
|
|
|
struct dive_table downloadTable;
|
|
|
|
|
2016-09-18 12:50:40 +00:00
|
|
|
// Workaround abuse of old libdc types
|
|
|
|
#define DC_TRANSPORT_BLUETOOTH 1024
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
DownloadFromDCWidget::DownloadFromDCWidget(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f),
|
2014-02-09 18:38:26 +00:00
|
|
|
thread(0),
|
|
|
|
downloading(false),
|
|
|
|
previousLast(0),
|
|
|
|
vendorModel(0),
|
|
|
|
productModel(0),
|
|
|
|
timer(new QTimer(this)),
|
|
|
|
dumpWarningShown(false),
|
2014-12-29 23:25:54 +00:00
|
|
|
ostcFirmwareCheck(0),
|
|
|
|
currentState(INITIAL)
|
2013-05-20 19:43:33 +00:00
|
|
|
{
|
2015-01-09 22:39:43 +00:00
|
|
|
clear_table(&downloadTable);
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.setupUi(this);
|
|
|
|
ui.progressBar->hide();
|
|
|
|
ui.progressBar->setMinimum(0);
|
|
|
|
ui.progressBar->setMaximum(100);
|
2015-01-08 12:12:11 +00:00
|
|
|
diveImportedModel = new DiveImportedModel(this);
|
2015-01-08 13:29:28 +00:00
|
|
|
ui.downloadedView->setModel(diveImportedModel);
|
2015-01-08 19:19:01 +00:00
|
|
|
ui.downloadedView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
ui.downloadedView->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
int startingWidth = defaultModelFont().pointSize();
|
|
|
|
ui.downloadedView->setColumnWidth(0, startingWidth * 20);
|
2015-01-13 08:20:32 +00:00
|
|
|
ui.downloadedView->setColumnWidth(1, startingWidth * 10);
|
2015-01-08 19:19:01 +00:00
|
|
|
ui.downloadedView->setColumnWidth(2, startingWidth * 10);
|
2015-01-08 19:39:34 +00:00
|
|
|
connect(ui.downloadedView, SIGNAL(clicked(QModelIndex)), diveImportedModel, SLOT(changeSelected(QModelIndex)));
|
2013-09-16 21:04:42 +00:00
|
|
|
|
2014-02-26 16:37:13 +00:00
|
|
|
progress_bar_text = "";
|
|
|
|
|
2013-05-20 20:58:06 +00:00
|
|
|
fill_computer_list();
|
|
|
|
|
2013-12-25 00:26:00 +00:00
|
|
|
ui.chooseDumpFile->setEnabled(ui.dumpToFile->isChecked());
|
|
|
|
connect(ui.chooseDumpFile, SIGNAL(clicked()), this, SLOT(pickDumpFile()));
|
|
|
|
connect(ui.dumpToFile, SIGNAL(stateChanged(int)), this, SLOT(checkDumpFile(int)));
|
|
|
|
ui.chooseLogFile->setEnabled(ui.logToFile->isChecked());
|
|
|
|
connect(ui.chooseLogFile, SIGNAL(clicked()), this, SLOT(pickLogFile()));
|
|
|
|
connect(ui.logToFile, SIGNAL(stateChanged(int)), this, SLOT(checkLogFile(int)));
|
2015-01-08 20:54:53 +00:00
|
|
|
ui.selectAllButton->setEnabled(false);
|
|
|
|
ui.unselectAllButton->setEnabled(false);
|
|
|
|
connect(ui.selectAllButton, SIGNAL(clicked()), diveImportedModel, SLOT(selectAll()));
|
|
|
|
connect(ui.unselectAllButton, SIGNAL(clicked()), diveImportedModel, SLOT(selectNone()));
|
2013-05-20 20:58:06 +00:00
|
|
|
vendorModel = new QStringListModel(vendorList);
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.vendor->setModel(vendorModel);
|
2016-08-10 21:10:15 +00:00
|
|
|
|
|
|
|
auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
|
|
|
|
if (!dc->dc_vendor().isEmpty()) {
|
|
|
|
ui.vendor->setCurrentIndex(ui.vendor->findText(dc->dc_vendor()));
|
|
|
|
productModel = new QStringListModel(productList[dc->dc_vendor()]);
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.product->setModel(productModel);
|
2016-08-10 21:10:15 +00:00
|
|
|
if (!dc->dc_product().isEmpty())
|
|
|
|
ui.product->setCurrentIndex(ui.product->findText(dc->dc_product()));
|
2013-05-23 06:24:33 +00:00
|
|
|
}
|
2016-08-10 21:10:15 +00:00
|
|
|
if (!dc->dc_device().isEmpty())
|
|
|
|
ui.device->setEditText(dc->dc_device());
|
2013-08-25 22:02:30 +00:00
|
|
|
|
|
|
|
timer->setInterval(200);
|
|
|
|
connect(timer, SIGNAL(timeout()), this, SLOT(updateProgressBar()));
|
|
|
|
updateState(INITIAL);
|
2014-02-15 14:03:54 +00:00
|
|
|
memset(&data, 0, sizeof(data));
|
2014-04-25 17:44:23 +00:00
|
|
|
QShortcut *close = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this);
|
|
|
|
connect(close, SIGNAL(activated()), this, SLOT(close()));
|
|
|
|
QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this);
|
|
|
|
connect(quit, SIGNAL(activated()), parent, SLOT(close()));
|
2015-01-08 17:39:47 +00:00
|
|
|
ui.ok->setEnabled(false);
|
2015-01-09 23:01:48 +00:00
|
|
|
ui.downloadCancelRetryButton->setEnabled(true);
|
|
|
|
ui.downloadCancelRetryButton->setText(tr("Download"));
|
2015-07-06 13:35:13 +00:00
|
|
|
|
2015-09-08 16:50:22 +00:00
|
|
|
#if defined(BT_SUPPORT) && defined(SSRF_CUSTOM_SERIAL)
|
2015-09-04 22:25:35 +00:00
|
|
|
ui.bluetoothMode->setText(tr("Choose Bluetooth download mode"));
|
2016-08-10 21:10:15 +00:00
|
|
|
ui.bluetoothMode->setChecked(dc->downloadMode() == DC_TRANSPORT_BLUETOOTH);
|
2015-07-06 13:35:13 +00:00
|
|
|
btDeviceSelectionDialog = 0;
|
2015-07-06 13:18:06 +00:00
|
|
|
ui.chooseBluetoothDevice->setEnabled(ui.bluetoothMode->isChecked());
|
|
|
|
connect(ui.bluetoothMode, SIGNAL(stateChanged(int)), this, SLOT(enableBluetoothMode(int)));
|
|
|
|
connect(ui.chooseBluetoothDevice, SIGNAL(clicked()), this, SLOT(selectRemoteBluetoothDevice()));
|
2015-07-20 16:35:00 +00:00
|
|
|
#else
|
|
|
|
ui.bluetoothMode->hide();
|
|
|
|
ui.chooseBluetoothDevice->hide();
|
|
|
|
#endif
|
2013-05-20 20:58:06 +00:00
|
|
|
}
|
|
|
|
|
2013-08-25 22:02:30 +00:00
|
|
|
void DownloadFromDCWidget::updateProgressBar()
|
2013-05-30 09:21:08 +00:00
|
|
|
{
|
2014-01-27 20:47:40 +00:00
|
|
|
if (*progress_bar_text != '\0') {
|
|
|
|
ui.progressBar->setFormat(progress_bar_text);
|
|
|
|
} else {
|
|
|
|
ui.progressBar->setFormat("%p%");
|
|
|
|
}
|
2014-05-07 19:17:24 +00:00
|
|
|
ui.progressBar->setValue(progress_bar_fraction * 100);
|
2013-08-25 22:02:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadFromDCWidget::updateState(states state)
|
|
|
|
{
|
|
|
|
if (state == currentState)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (state == INITIAL) {
|
2014-05-18 04:29:40 +00:00
|
|
|
fill_device_list(DC_TYPE_OTHER);
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.progressBar->hide();
|
2013-08-25 22:02:30 +00:00
|
|
|
markChildrenAsEnabled();
|
|
|
|
timer->stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
// tries to cancel an on going download
|
|
|
|
else if (currentState == DOWNLOADING && state == CANCELLING) {
|
|
|
|
import_thread_cancelled = true;
|
2015-01-09 23:01:48 +00:00
|
|
|
ui.downloadCancelRetryButton->setEnabled(false);
|
2013-08-25 22:02:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// user pressed cancel but the application isn't doing anything.
|
|
|
|
// means close the window
|
2015-01-09 23:01:48 +00:00
|
|
|
else if ((currentState == INITIAL || currentState == DONE || currentState == ERROR) && state == CANCELLING) {
|
2013-08-25 22:02:30 +00:00
|
|
|
timer->stop();
|
|
|
|
reject();
|
|
|
|
}
|
|
|
|
|
2013-09-01 14:14:54 +00:00
|
|
|
// the cancelation process is finished
|
2015-01-09 23:01:48 +00:00
|
|
|
else if (currentState == CANCELLING && state == DONE) {
|
2013-08-25 22:02:30 +00:00
|
|
|
timer->stop();
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.progressBar->setValue(0);
|
|
|
|
ui.progressBar->hide();
|
2013-08-25 22:02:30 +00:00
|
|
|
markChildrenAsEnabled();
|
|
|
|
}
|
|
|
|
|
2014-01-27 20:47:40 +00:00
|
|
|
// DOWNLOAD is finally done, but we don't know if there was an error as libdivecomputer doesn't pass
|
2015-01-08 17:29:57 +00:00
|
|
|
// that information on to us.
|
|
|
|
// If we find an error, offer to retry, otherwise continue the interaction to pick the dives the user wants
|
2013-08-25 22:02:30 +00:00
|
|
|
else if (currentState == DOWNLOADING && state == DONE) {
|
|
|
|
timer->stop();
|
2014-01-27 20:47:40 +00:00
|
|
|
if (QString(progress_bar_text).contains("error", Qt::CaseInsensitive)) {
|
|
|
|
updateProgressBar();
|
|
|
|
markChildrenAsEnabled();
|
|
|
|
progress_bar_text = "";
|
|
|
|
} else {
|
|
|
|
ui.progressBar->setValue(100);
|
|
|
|
markChildrenAsEnabled();
|
|
|
|
}
|
2013-08-25 22:02:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DOWNLOAD is started.
|
|
|
|
else if (state == DOWNLOADING) {
|
|
|
|
timer->start();
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.progressBar->setValue(0);
|
2014-01-27 20:47:40 +00:00
|
|
|
updateProgressBar();
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.progressBar->show();
|
2013-08-25 22:02:30 +00:00
|
|
|
markChildrenAsDisabled();
|
|
|
|
}
|
|
|
|
|
2013-09-01 14:14:54 +00:00
|
|
|
// got an error
|
|
|
|
else if (state == ERROR) {
|
2013-11-21 12:23:10 +00:00
|
|
|
QMessageBox::critical(this, TITLE_OR_TEXT(tr("Error"), this->thread->error), QMessageBox::Ok);
|
2013-09-01 14:14:54 +00:00
|
|
|
|
|
|
|
markChildrenAsEnabled();
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.progressBar->hide();
|
2013-09-01 14:14:54 +00:00
|
|
|
}
|
|
|
|
|
2013-08-25 22:02:30 +00:00
|
|
|
// properly updating the widget state
|
|
|
|
currentState = state;
|
2013-05-30 09:21:08 +00:00
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void DownloadFromDCWidget::on_vendor_currentIndexChanged(const QString &vendor)
|
2013-05-20 20:58:06 +00:00
|
|
|
{
|
2014-05-18 04:29:40 +00:00
|
|
|
int dcType = DC_TYPE_SERIAL;
|
2013-10-03 18:54:25 +00:00
|
|
|
QAbstractItemModel *currentModel = ui.product->model();
|
2013-05-20 20:58:06 +00:00
|
|
|
if (!currentModel)
|
|
|
|
return;
|
|
|
|
|
|
|
|
productModel = new QStringListModel(productList[vendor]);
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.product->setModel(productModel);
|
2013-05-20 20:58:06 +00:00
|
|
|
|
2014-05-18 04:29:40 +00:00
|
|
|
if (vendor == QString("Uemis"))
|
|
|
|
dcType = DC_TYPE_UEMIS;
|
|
|
|
fill_device_list(dcType);
|
|
|
|
|
2013-05-20 20:58:06 +00:00
|
|
|
// Memleak - but deleting gives me a crash.
|
|
|
|
//currentModel->deleteLater();
|
|
|
|
}
|
|
|
|
|
2014-05-25 22:06:56 +00:00
|
|
|
void DownloadFromDCWidget::on_product_currentIndexChanged(const QString &product)
|
2013-12-27 10:50:13 +00:00
|
|
|
{
|
|
|
|
// Set up the DC descriptor
|
|
|
|
dc_descriptor_t *descriptor = NULL;
|
2014-05-25 22:06:56 +00:00
|
|
|
descriptor = descriptorLookup[ui.vendor->currentText() + product];
|
2013-12-27 10:50:13 +00:00
|
|
|
|
|
|
|
// call dc_descriptor_get_transport to see if the dc_transport_t is DC_TRANSPORT_SERIAL
|
|
|
|
if (dc_descriptor_get_transport(descriptor) == DC_TRANSPORT_SERIAL) {
|
|
|
|
// if the dc_transport_t is DC_TRANSPORT_SERIAL, then enable the device node box.
|
|
|
|
ui.device->setEnabled(true);
|
|
|
|
} else {
|
|
|
|
// otherwise disable the device node box
|
|
|
|
ui.device->setEnabled(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-20 20:58:06 +00:00
|
|
|
void DownloadFromDCWidget::fill_computer_list()
|
|
|
|
{
|
|
|
|
dc_iterator_t *iterator = NULL;
|
|
|
|
dc_descriptor_t *descriptor = NULL;
|
|
|
|
struct mydescriptor *mydescriptor;
|
|
|
|
|
|
|
|
QStringList computer;
|
|
|
|
dc_descriptor_iterator(&iterator);
|
2014-02-28 04:09:57 +00:00
|
|
|
while (dc_iterator_next(iterator, &descriptor) == DC_STATUS_SUCCESS) {
|
2013-05-20 20:58:06 +00:00
|
|
|
const char *vendor = dc_descriptor_get_vendor(descriptor);
|
|
|
|
const char *product = dc_descriptor_get_product(descriptor);
|
|
|
|
|
2013-05-23 04:25:05 +00:00
|
|
|
if (!vendorList.contains(vendor))
|
|
|
|
vendorList.append(vendor);
|
2013-05-20 20:58:06 +00:00
|
|
|
|
2013-05-23 04:25:05 +00:00
|
|
|
if (!productList[vendor].contains(product))
|
|
|
|
productList[vendor].push_back(product);
|
2013-05-21 04:55:56 +00:00
|
|
|
|
|
|
|
descriptorLookup[QString(vendor) + QString(product)] = descriptor;
|
2013-05-20 20:58:06 +00:00
|
|
|
}
|
|
|
|
dc_iterator_free(iterator);
|
2015-01-13 09:05:55 +00:00
|
|
|
Q_FOREACH (QString vendor, vendorList)
|
|
|
|
qSort(productList[vendor]);
|
2013-05-20 20:58:06 +00:00
|
|
|
|
|
|
|
/* and add the Uemis Zurich which we are handling internally
|
|
|
|
THIS IS A HACK as we magically have a data structure here that
|
|
|
|
happens to match a data structure that is internal to libdivecomputer;
|
|
|
|
this WILL BREAK if libdivecomputer changes the dc_descriptor struct...
|
|
|
|
eventually the UEMIS code needs to move into libdivecomputer, I guess */
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
mydescriptor = (struct mydescriptor *)malloc(sizeof(struct mydescriptor));
|
2013-05-20 20:58:06 +00:00
|
|
|
mydescriptor->vendor = "Uemis";
|
|
|
|
mydescriptor->product = "Zurich";
|
|
|
|
mydescriptor->type = DC_FAMILY_NULL;
|
|
|
|
mydescriptor->model = 0;
|
|
|
|
|
2013-05-23 04:25:05 +00:00
|
|
|
if (!vendorList.contains("Uemis"))
|
2013-05-20 20:58:06 +00:00
|
|
|
vendorList.append("Uemis");
|
|
|
|
|
2013-05-23 04:25:05 +00:00
|
|
|
if (!productList["Uemis"].contains("Zurich"))
|
|
|
|
productList["Uemis"].push_back("Zurich");
|
2013-05-21 04:55:56 +00:00
|
|
|
|
2014-05-12 17:58:15 +00:00
|
|
|
descriptorLookup["UemisZurich"] = (dc_descriptor_t *)mydescriptor;
|
2014-01-14 14:05:41 +00:00
|
|
|
|
|
|
|
qSort(vendorList);
|
2013-05-20 19:43:33 +00:00
|
|
|
}
|
|
|
|
|
2014-02-19 01:20:35 +00:00
|
|
|
void DownloadFromDCWidget::on_search_clicked()
|
|
|
|
{
|
|
|
|
if (ui.vendor->currentText() == "Uemis") {
|
|
|
|
QString dirName = QFileDialog::getExistingDirectory(this,
|
2014-02-28 04:09:57 +00:00
|
|
|
tr("Find Uemis dive computer"),
|
|
|
|
QDir::homePath(),
|
|
|
|
QFileDialog::ShowDirsOnly);
|
2014-02-19 01:20:35 +00:00
|
|
|
if (ui.device->findText(dirName) == -1)
|
|
|
|
ui.device->addItem(dirName);
|
|
|
|
ui.device->setEditText(dirName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-09 23:01:48 +00:00
|
|
|
void DownloadFromDCWidget::on_downloadCancelRetryButton_clicked()
|
2013-05-20 19:43:33 +00:00
|
|
|
{
|
2015-01-09 23:01:48 +00:00
|
|
|
if (currentState == DOWNLOADING) {
|
|
|
|
updateState(CANCELLING);
|
|
|
|
return;
|
|
|
|
}
|
2015-01-11 15:46:21 +00:00
|
|
|
if (currentState == DONE) {
|
|
|
|
// this means we are retrying - so we better clean out the partial
|
|
|
|
// list of downloaded dives from the last attempt
|
|
|
|
diveImportedModel->clearTable();
|
|
|
|
clear_table(&downloadTable);
|
|
|
|
}
|
2013-08-25 22:02:30 +00:00
|
|
|
updateState(DOWNLOADING);
|
2013-05-20 19:43:33 +00:00
|
|
|
|
2015-01-09 23:01:48 +00:00
|
|
|
// you cannot cancel the dialog, just the download
|
|
|
|
ui.cancel->setEnabled(false);
|
|
|
|
ui.downloadCancelRetryButton->setText("Cancel download");
|
|
|
|
|
2013-08-25 22:02:30 +00:00
|
|
|
// I don't really think that create/destroy the thread
|
|
|
|
// is really necessary.
|
2013-05-23 04:25:05 +00:00
|
|
|
if (thread) {
|
2013-05-20 19:43:33 +00:00
|
|
|
thread->deleteLater();
|
|
|
|
}
|
|
|
|
|
2013-10-03 18:54:25 +00:00
|
|
|
data.vendor = strdup(ui.vendor->currentText().toUtf8().data());
|
|
|
|
data.product = strdup(ui.product->currentText().toUtf8().data());
|
2015-07-20 16:35:00 +00:00
|
|
|
#if defined(BT_SUPPORT)
|
2015-07-06 13:35:13 +00:00
|
|
|
data.bluetooth_mode = ui.bluetoothMode->isChecked();
|
2015-09-06 20:59:28 +00:00
|
|
|
if (data.bluetooth_mode && btDeviceSelectionDialog != NULL) {
|
2015-07-06 13:35:13 +00:00
|
|
|
// Get the selected device address
|
|
|
|
data.devname = strdup(btDeviceSelectionDialog->getSelectedDeviceAddress().toUtf8().data());
|
2015-07-20 16:35:00 +00:00
|
|
|
} else
|
|
|
|
// this breaks an "else if" across lines... not happy...
|
|
|
|
#endif
|
|
|
|
if (same_string(data.vendor, "Uemis")) {
|
2015-04-30 23:35:46 +00:00
|
|
|
char *colon;
|
|
|
|
char *devname = strdup(ui.device->currentText().toUtf8().data());
|
2013-08-25 13:01:59 +00:00
|
|
|
|
2015-04-30 23:35:46 +00:00
|
|
|
if ((colon = strstr(devname, ":\\ (UEMISSDA)")) != NULL) {
|
|
|
|
*(colon + 2) = '\0';
|
|
|
|
fprintf(stderr, "shortened devname to \"%s\"", data.devname);
|
|
|
|
}
|
|
|
|
data.devname = devname;
|
|
|
|
} else {
|
|
|
|
data.devname = strdup(ui.device->currentText().toUtf8().data());
|
|
|
|
}
|
2013-10-03 18:54:25 +00:00
|
|
|
data.descriptor = descriptorLookup[ui.vendor->currentText() + ui.product->currentText()];
|
|
|
|
data.force_download = ui.forceDownload->isChecked();
|
2014-07-24 20:59:11 +00:00
|
|
|
data.create_new_trip = ui.createNewTrip->isChecked();
|
|
|
|
data.trip = NULL;
|
2013-06-16 00:48:31 +00:00
|
|
|
data.deviceid = data.diveid = 0;
|
2016-08-10 21:10:15 +00:00
|
|
|
|
|
|
|
auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
|
|
|
|
dc->setVendor(data.vendor);
|
|
|
|
dc->setProduct(data.product);
|
|
|
|
dc->setDevice(data.devname);
|
2015-09-08 20:16:04 +00:00
|
|
|
#if defined(BT_SUPPORT) && defined(SSRF_CUSTOM_SERIAL)
|
2016-08-10 21:10:15 +00:00
|
|
|
dc->setDownloadMode(ui.bluetoothMode->isChecked() ? DC_TRANSPORT_BLUETOOTH : DC_TRANSPORT_SERIAL);
|
2015-09-08 20:16:04 +00:00
|
|
|
#endif
|
2013-05-20 20:02:17 +00:00
|
|
|
|
2016-08-10 21:10:15 +00:00
|
|
|
thread = new DownloadThread(this, &data);
|
2013-08-25 22:02:30 +00:00
|
|
|
connect(thread, SIGNAL(finished()),
|
2014-02-28 04:09:57 +00:00
|
|
|
this, SLOT(onDownloadThreadFinished()), Qt::QueuedConnection);
|
2013-08-25 22:02:30 +00:00
|
|
|
|
2016-08-10 21:10:15 +00:00
|
|
|
//TODO: Don't call mainwindow.
|
2014-02-12 14:22:54 +00:00
|
|
|
MainWindow *w = MainWindow::instance();
|
2013-08-25 22:02:30 +00:00
|
|
|
connect(thread, SIGNAL(finished()), w, SLOT(refreshDisplay()));
|
2013-05-20 20:02:17 +00:00
|
|
|
|
2013-12-08 05:33:46 +00:00
|
|
|
// before we start, remember where the dive_table ended
|
|
|
|
previousLast = dive_table.nr;
|
|
|
|
|
2013-05-20 19:43:33 +00:00
|
|
|
thread->start();
|
2014-12-27 16:31:51 +00:00
|
|
|
|
2017-01-08 13:04:11 +00:00
|
|
|
// FIXME: We should get the _actual_ device info instead of whatever
|
|
|
|
// the user entered in the dropdown.
|
|
|
|
// You can enter "OSTC 3" and download just fine from a "OSTC Sport", but
|
|
|
|
// this check will compair apples and oranges, firmware wise, then.
|
2014-12-28 15:37:11 +00:00
|
|
|
QString product(ui.product->currentText());
|
2016-12-28 19:56:13 +00:00
|
|
|
if (product == "OSTC 3" || product == "OSTC 3+" ||
|
2016-12-28 15:49:14 +00:00
|
|
|
product == "OSTC Cr" || product == "OSTC Sport" ||
|
|
|
|
product == "OSTC 4")
|
2014-12-28 15:37:11 +00:00
|
|
|
ostcFirmwareCheck = new OstcFirmwareCheck(product);
|
2013-05-20 19:43:33 +00:00
|
|
|
}
|
|
|
|
|
2013-05-30 08:58:59 +00:00
|
|
|
bool DownloadFromDCWidget::preferDownloaded()
|
|
|
|
{
|
2013-10-03 18:54:25 +00:00
|
|
|
return ui.preferDownloaded->isChecked();
|
2013-05-30 08:58:59 +00:00
|
|
|
}
|
|
|
|
|
2013-12-25 00:26:00 +00:00
|
|
|
void DownloadFromDCWidget::checkLogFile(int state)
|
|
|
|
{
|
|
|
|
ui.chooseLogFile->setEnabled(state == Qt::Checked);
|
|
|
|
data.libdc_log = (state == Qt::Checked);
|
|
|
|
if (state == Qt::Checked && logFile.isEmpty()) {
|
|
|
|
pickLogFile();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadFromDCWidget::pickLogFile()
|
|
|
|
{
|
2014-02-28 04:09:57 +00:00
|
|
|
QString filename = existing_filename ?: prefs.default_filename;
|
2013-12-25 00:26:00 +00:00
|
|
|
QFileInfo fi(filename);
|
|
|
|
filename = fi.absolutePath().append(QDir::separator()).append("subsurface.log");
|
2017-02-20 07:15:18 +00:00
|
|
|
logFile = QFileDialog::getSaveFileName(this, tr("Choose file for dive computer download logfile"),
|
2013-12-25 00:26:00 +00:00
|
|
|
filename, tr("Log files (*.log)"));
|
2014-01-07 14:41:21 +00:00
|
|
|
if (!logFile.isEmpty()) {
|
2014-05-12 17:58:15 +00:00
|
|
|
free(logfile_name);
|
2013-12-25 00:26:00 +00:00
|
|
|
logfile_name = strdup(logFile.toUtf8().data());
|
2014-01-07 14:41:21 +00:00
|
|
|
}
|
2013-12-25 00:26:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadFromDCWidget::checkDumpFile(int state)
|
|
|
|
{
|
|
|
|
ui.chooseDumpFile->setEnabled(state == Qt::Checked);
|
|
|
|
data.libdc_dump = (state == Qt::Checked);
|
2013-12-26 17:18:57 +00:00
|
|
|
if (state == Qt::Checked) {
|
|
|
|
if (dumpFile.isEmpty())
|
|
|
|
pickDumpFile();
|
|
|
|
if (!dumpWarningShown) {
|
|
|
|
QMessageBox::warning(this, tr("Warning"),
|
|
|
|
tr("Saving the libdivecomputer dump will NOT download dives to the dive list."));
|
|
|
|
dumpWarningShown = true;
|
|
|
|
}
|
2013-12-25 00:26:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadFromDCWidget::pickDumpFile()
|
|
|
|
{
|
2014-02-28 04:09:57 +00:00
|
|
|
QString filename = existing_filename ?: prefs.default_filename;
|
2013-12-25 00:26:00 +00:00
|
|
|
QFileInfo fi(filename);
|
|
|
|
filename = fi.absolutePath().append(QDir::separator()).append("subsurface.bin");
|
2017-02-20 07:15:18 +00:00
|
|
|
dumpFile = QFileDialog::getSaveFileName(this, tr("Choose file for dive computer binary dump file"),
|
2013-12-25 00:26:00 +00:00
|
|
|
filename, tr("Dump files (*.bin)"));
|
2014-01-07 14:41:21 +00:00
|
|
|
if (!dumpFile.isEmpty()) {
|
2014-05-12 17:58:15 +00:00
|
|
|
free(dumpfile_name);
|
2013-12-25 00:26:00 +00:00
|
|
|
dumpfile_name = strdup(dumpFile.toUtf8().data());
|
2014-01-07 14:41:21 +00:00
|
|
|
}
|
2013-12-25 00:26:00 +00:00
|
|
|
}
|
|
|
|
|
2013-08-25 13:01:59 +00:00
|
|
|
void DownloadFromDCWidget::reject()
|
|
|
|
{
|
|
|
|
// we don't want the download window being able to close
|
|
|
|
// while we're still downloading.
|
2013-08-25 22:02:30 +00:00
|
|
|
if (currentState != DOWNLOADING && currentState != CANCELLING)
|
2013-08-25 13:01:59 +00:00
|
|
|
QDialog::reject();
|
|
|
|
}
|
|
|
|
|
2013-10-15 17:25:53 +00:00
|
|
|
void DownloadFromDCWidget::onDownloadThreadFinished()
|
2013-08-25 22:02:30 +00:00
|
|
|
{
|
2013-09-01 14:14:54 +00:00
|
|
|
if (currentState == DOWNLOADING) {
|
|
|
|
if (thread->error.isEmpty())
|
|
|
|
updateState(DONE);
|
|
|
|
else
|
|
|
|
updateState(ERROR);
|
2015-01-09 22:44:38 +00:00
|
|
|
} else if (currentState == CANCELLING) {
|
|
|
|
updateState(DONE);
|
|
|
|
}
|
2015-01-09 23:01:48 +00:00
|
|
|
ui.downloadCancelRetryButton->setText(tr("Retry"));
|
|
|
|
ui.downloadCancelRetryButton->setEnabled(true);
|
2015-01-09 22:44:38 +00:00
|
|
|
// regardless, if we got dives, we should show them to the user
|
|
|
|
if (downloadTable.nr) {
|
|
|
|
diveImportedModel->setImportedDivesIndexes(0, downloadTable.nr - 1);
|
2013-12-08 05:33:46 +00:00
|
|
|
}
|
2015-01-09 23:01:48 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadFromDCWidget::on_cancel_clicked()
|
|
|
|
{
|
|
|
|
if (currentState == DOWNLOADING || currentState == CANCELLING)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// now discard all the dives
|
|
|
|
clear_table(&downloadTable);
|
|
|
|
done(-1);
|
2013-08-25 22:02:30 +00:00
|
|
|
}
|
2015-01-08 13:31:05 +00:00
|
|
|
|
|
|
|
void DownloadFromDCWidget::on_ok_clicked()
|
|
|
|
{
|
2015-01-27 04:50:42 +00:00
|
|
|
struct dive *dive;
|
|
|
|
|
2015-04-21 05:11:43 +00:00
|
|
|
if (currentState != DONE && currentState != ERROR)
|
2015-01-08 13:56:00 +00:00
|
|
|
return;
|
|
|
|
|
2015-01-09 22:44:38 +00:00
|
|
|
// record all the dives in the 'real' dive_table
|
|
|
|
for (int i = 0; i < downloadTable.nr; i++) {
|
|
|
|
if (diveImportedModel->data(diveImportedModel->index(i, 0),Qt::CheckStateRole) == Qt::Checked)
|
|
|
|
record_dive(downloadTable.dives[i]);
|
|
|
|
downloadTable.dives[i] = NULL;
|
|
|
|
}
|
|
|
|
downloadTable.nr = 0;
|
2015-01-08 13:52:12 +00:00
|
|
|
|
2015-01-08 12:12:11 +00:00
|
|
|
int uniqId, idx;
|
|
|
|
// remember the last downloaded dive (on most dive computers this will be the chronologically
|
|
|
|
// first new dive) and select it again after processing all the dives
|
|
|
|
MainWindow::instance()->dive_list()->unselectDives();
|
2015-01-27 04:50:42 +00:00
|
|
|
|
|
|
|
dive = get_dive(dive_table.nr - 1);
|
|
|
|
if (dive != NULL) {
|
|
|
|
uniqId = get_dive(dive_table.nr - 1)->id;
|
|
|
|
process_dives(true, preferDownloaded());
|
|
|
|
// after process_dives does any merging or resorting needed, we need
|
|
|
|
// to recreate the model for the dive list so we can select the newest dive
|
|
|
|
MainWindow::instance()->recreateDiveList();
|
|
|
|
idx = get_idx_by_uniq_id(uniqId);
|
|
|
|
// this shouldn't be necessary - but there are reports that somehow existing dives stay selected
|
|
|
|
// (but not visible as selected)
|
|
|
|
MainWindow::instance()->dive_list()->unselectDives();
|
|
|
|
MainWindow::instance()->dive_list()->selectDive(idx, true);
|
|
|
|
}
|
2015-01-08 13:53:16 +00:00
|
|
|
|
2015-01-08 12:12:11 +00:00
|
|
|
if (ostcFirmwareCheck && currentState == DONE)
|
|
|
|
ostcFirmwareCheck->checkLatest(this, &data);
|
2015-01-08 17:59:01 +00:00
|
|
|
accept();
|
2015-01-08 13:31:05 +00:00
|
|
|
}
|
2013-08-25 22:02:30 +00:00
|
|
|
|
2013-08-25 13:01:59 +00:00
|
|
|
void DownloadFromDCWidget::markChildrenAsDisabled()
|
|
|
|
{
|
2015-01-08 20:56:17 +00:00
|
|
|
ui.device->setEnabled(false);
|
|
|
|
ui.vendor->setEnabled(false);
|
|
|
|
ui.product->setEnabled(false);
|
|
|
|
ui.forceDownload->setEnabled(false);
|
|
|
|
ui.createNewTrip->setEnabled(false);
|
|
|
|
ui.preferDownloaded->setEnabled(false);
|
|
|
|
ui.ok->setEnabled(false);
|
|
|
|
ui.search->setEnabled(false);
|
|
|
|
ui.logToFile->setEnabled(false);
|
|
|
|
ui.dumpToFile->setEnabled(false);
|
|
|
|
ui.chooseLogFile->setEnabled(false);
|
|
|
|
ui.chooseDumpFile->setEnabled(false);
|
|
|
|
ui.selectAllButton->setEnabled(false);
|
|
|
|
ui.unselectAllButton->setEnabled(false);
|
2015-07-06 13:18:06 +00:00
|
|
|
ui.bluetoothMode->setEnabled(false);
|
|
|
|
ui.chooseBluetoothDevice->setEnabled(false);
|
2013-08-25 13:01:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadFromDCWidget::markChildrenAsEnabled()
|
|
|
|
{
|
2015-01-08 20:56:17 +00:00
|
|
|
ui.device->setEnabled(true);
|
|
|
|
ui.vendor->setEnabled(true);
|
|
|
|
ui.product->setEnabled(true);
|
|
|
|
ui.forceDownload->setEnabled(true);
|
|
|
|
ui.createNewTrip->setEnabled(true);
|
|
|
|
ui.preferDownloaded->setEnabled(true);
|
|
|
|
ui.ok->setEnabled(true);
|
|
|
|
ui.cancel->setEnabled(true);
|
|
|
|
ui.search->setEnabled(true);
|
|
|
|
ui.logToFile->setEnabled(true);
|
|
|
|
ui.dumpToFile->setEnabled(true);
|
|
|
|
ui.chooseLogFile->setEnabled(true);
|
|
|
|
ui.chooseDumpFile->setEnabled(true);
|
|
|
|
ui.selectAllButton->setEnabled(true);
|
|
|
|
ui.unselectAllButton->setEnabled(true);
|
2015-07-20 16:35:00 +00:00
|
|
|
#if defined(BT_SUPPORT)
|
2015-07-06 13:18:06 +00:00
|
|
|
ui.bluetoothMode->setEnabled(true);
|
|
|
|
ui.chooseBluetoothDevice->setEnabled(true);
|
2015-07-20 16:35:00 +00:00
|
|
|
#endif
|
2015-07-06 13:18:06 +00:00
|
|
|
}
|
|
|
|
|
2015-07-20 16:35:00 +00:00
|
|
|
#if defined(BT_SUPPORT)
|
2015-07-06 13:18:06 +00:00
|
|
|
void DownloadFromDCWidget::selectRemoteBluetoothDevice()
|
|
|
|
{
|
2015-07-06 13:35:13 +00:00
|
|
|
if (!btDeviceSelectionDialog) {
|
|
|
|
btDeviceSelectionDialog = new BtDeviceSelectionDialog(this);
|
|
|
|
connect(btDeviceSelectionDialog, SIGNAL(finished(int)),
|
|
|
|
this, SLOT(bluetoothSelectionDialogIsFinished(int)));
|
|
|
|
}
|
|
|
|
|
|
|
|
btDeviceSelectionDialog->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadFromDCWidget::bluetoothSelectionDialogIsFinished(int result)
|
|
|
|
{
|
|
|
|
if (result == QDialog::Accepted) {
|
|
|
|
/* Make the selected Bluetooth device default */
|
2015-08-18 19:43:42 +00:00
|
|
|
QString selectedDeviceName = btDeviceSelectionDialog->getSelectedDeviceName();
|
|
|
|
|
|
|
|
if (selectedDeviceName == NULL || selectedDeviceName.isEmpty()) {
|
|
|
|
ui.device->setCurrentText(btDeviceSelectionDialog->getSelectedDeviceAddress());
|
|
|
|
} else {
|
|
|
|
ui.device->setCurrentText(selectedDeviceName);
|
|
|
|
}
|
2015-07-06 13:35:13 +00:00
|
|
|
} else if (result == QDialog::Rejected){
|
|
|
|
/* Disable Bluetooth download mode */
|
|
|
|
ui.bluetoothMode->setChecked(false);
|
|
|
|
}
|
2015-07-06 13:18:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadFromDCWidget::enableBluetoothMode(int state)
|
|
|
|
{
|
|
|
|
ui.chooseBluetoothDevice->setEnabled(state == Qt::Checked);
|
2015-09-06 21:12:00 +00:00
|
|
|
|
2015-07-06 13:18:06 +00:00
|
|
|
if (state == Qt::Checked)
|
|
|
|
selectRemoteBluetoothDevice();
|
2015-09-06 21:12:00 +00:00
|
|
|
else
|
|
|
|
ui.device->setCurrentIndex(-1);
|
2013-08-25 13:01:59 +00:00
|
|
|
}
|
2015-07-20 16:35:00 +00:00
|
|
|
#endif
|
2013-08-25 13:01:59 +00:00
|
|
|
|
2013-09-16 21:04:42 +00:00
|
|
|
static void fillDeviceList(const char *name, void *data)
|
|
|
|
{
|
|
|
|
QComboBox *comboBox = (QComboBox *)data;
|
|
|
|
comboBox->addItem(name);
|
|
|
|
}
|
|
|
|
|
2014-05-18 04:29:40 +00:00
|
|
|
void DownloadFromDCWidget::fill_device_list(int dc_type)
|
2013-09-16 21:04:42 +00:00
|
|
|
{
|
|
|
|
int deviceIndex;
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.device->clear();
|
2014-05-18 04:29:40 +00:00
|
|
|
deviceIndex = enumerate_devices(fillDeviceList, ui.device, dc_type);
|
2013-09-16 21:04:42 +00:00
|
|
|
if (deviceIndex >= 0)
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.device->setCurrentIndex(deviceIndex);
|
2013-09-16 21:04:42 +00:00
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
DownloadThread::DownloadThread(QObject *parent, device_data_t *data) : QThread(parent),
|
2013-08-25 22:02:30 +00:00
|
|
|
data(data)
|
2013-05-20 19:43:33 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-09-01 14:14:54 +00:00
|
|
|
static QString str_error(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
2014-02-28 04:09:57 +00:00
|
|
|
const QString str = QString().vsprintf(fmt, args);
|
2013-09-01 14:14:54 +00:00
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2013-05-20 19:43:33 +00:00
|
|
|
void DownloadThread::run()
|
|
|
|
{
|
2014-02-12 13:51:25 +00:00
|
|
|
const char *errorText;
|
2013-12-10 07:09:42 +00:00
|
|
|
import_thread_cancelled = false;
|
2015-01-09 22:44:38 +00:00
|
|
|
data->download_table = &downloadTable;
|
2013-06-24 22:14:07 +00:00
|
|
|
if (!strcmp(data->vendor, "Uemis"))
|
2014-10-12 10:57:32 +00:00
|
|
|
errorText = do_uemis_import(data);
|
2013-06-24 22:14:07 +00:00
|
|
|
else
|
2014-02-12 13:51:25 +00:00
|
|
|
errorText = do_libdivecomputer_import(data);
|
|
|
|
if (errorText)
|
2014-02-28 04:09:57 +00:00
|
|
|
error = str_error(errorText, data->devname, data->vendor, data->product);
|
2013-05-20 19:43:33 +00:00
|
|
|
}
|
2015-01-08 12:12:11 +00:00
|
|
|
|
2015-01-08 12:13:36 +00:00
|
|
|
DiveImportedModel::DiveImportedModel(QObject *o) : QAbstractTableModel(o),
|
2015-01-08 12:52:54 +00:00
|
|
|
firstIndex(0),
|
2015-02-15 18:25:22 +00:00
|
|
|
lastIndex(-1),
|
2015-01-08 12:52:54 +00:00
|
|
|
checkStates(0)
|
2015-01-08 12:12:11 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-01-08 18:02:28 +00:00
|
|
|
int DiveImportedModel::columnCount(const QModelIndex &model) const
|
2015-01-08 12:12:11 +00:00
|
|
|
{
|
2016-03-10 04:15:28 +00:00
|
|
|
Q_UNUSED(model)
|
2015-01-08 17:31:18 +00:00
|
|
|
return 3;
|
2015-01-08 12:12:11 +00:00
|
|
|
}
|
|
|
|
|
2015-01-08 18:02:28 +00:00
|
|
|
int DiveImportedModel::rowCount(const QModelIndex &model) const
|
2015-01-08 12:12:11 +00:00
|
|
|
{
|
2016-03-10 04:15:28 +00:00
|
|
|
Q_UNUSED(model)
|
2015-01-09 20:21:20 +00:00
|
|
|
return lastIndex - firstIndex + 1;
|
2015-01-08 12:12:11 +00:00
|
|
|
}
|
|
|
|
|
2015-01-08 18:12:43 +00:00
|
|
|
QVariant DiveImportedModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
{
|
|
|
|
if (orientation == Qt::Vertical)
|
|
|
|
return QVariant();
|
|
|
|
if (role == Qt::DisplayRole) {
|
|
|
|
switch (section) {
|
|
|
|
case 0:
|
|
|
|
return QVariant(tr("Date/time"));
|
|
|
|
case 1:
|
|
|
|
return QVariant(tr("Duration"));
|
|
|
|
case 2:
|
|
|
|
return QVariant(tr("Depth"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
2015-01-08 18:02:28 +00:00
|
|
|
QVariant DiveImportedModel::data(const QModelIndex &index, int role) const
|
2015-01-08 12:12:11 +00:00
|
|
|
{
|
2015-01-08 12:25:38 +00:00
|
|
|
if (!index.isValid())
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
if (index.row() + firstIndex > lastIndex)
|
|
|
|
return QVariant();
|
|
|
|
|
2015-01-09 22:44:38 +00:00
|
|
|
struct dive *d = get_dive_from_table(index.row() + firstIndex, &downloadTable);
|
|
|
|
if (!d)
|
|
|
|
return QVariant();
|
2015-01-08 12:25:38 +00:00
|
|
|
if (role == Qt::DisplayRole) {
|
2015-01-08 18:02:28 +00:00
|
|
|
switch (index.column()) {
|
|
|
|
case 0:
|
|
|
|
return QVariant(get_short_dive_date_string(d->when));
|
|
|
|
case 1:
|
|
|
|
return QVariant(get_dive_duration_string(d->duration.seconds, tr("h:"), tr("min")));
|
|
|
|
case 2:
|
|
|
|
return QVariant(get_depth_string(d->maxdepth.mm, true, false));
|
2015-01-08 12:25:38 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-08 12:52:54 +00:00
|
|
|
if (role == Qt::CheckStateRole) {
|
2015-01-08 17:43:29 +00:00
|
|
|
if (index.column() == 0)
|
2015-01-08 19:27:47 +00:00
|
|
|
return checkStates[index.row()] ? Qt::Checked : Qt::Unchecked;
|
2015-01-08 12:52:54 +00:00
|
|
|
}
|
|
|
|
return QVariant();
|
2015-01-08 12:12:11 +00:00
|
|
|
}
|
|
|
|
|
2015-01-09 20:17:02 +00:00
|
|
|
void DiveImportedModel::changeSelected(QModelIndex clickedIndex)
|
2015-01-08 19:39:34 +00:00
|
|
|
{
|
2015-01-09 20:17:02 +00:00
|
|
|
checkStates[clickedIndex.row()] = !checkStates[clickedIndex.row()];
|
2015-10-07 05:12:28 +00:00
|
|
|
dataChanged(index(clickedIndex.row(), 0), index(clickedIndex.row(), 0), QVector<int>() << Qt::CheckStateRole);
|
2015-01-08 19:39:34 +00:00
|
|
|
}
|
|
|
|
|
2015-01-08 20:54:53 +00:00
|
|
|
void DiveImportedModel::selectAll()
|
|
|
|
{
|
2015-01-27 04:33:34 +00:00
|
|
|
memset(checkStates, true, lastIndex - firstIndex + 1);
|
2015-10-07 05:12:28 +00:00
|
|
|
dataChanged(index(0, 0), index(lastIndex - firstIndex, 0), QVector<int>() << Qt::CheckStateRole);
|
2015-01-08 20:54:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DiveImportedModel::selectNone()
|
|
|
|
{
|
2015-01-27 04:33:34 +00:00
|
|
|
memset(checkStates, false, lastIndex - firstIndex + 1);
|
2015-10-07 05:12:28 +00:00
|
|
|
dataChanged(index(0, 0), index(lastIndex - firstIndex,0 ), QVector<int>() << Qt::CheckStateRole);
|
2015-01-08 20:54:53 +00:00
|
|
|
}
|
|
|
|
|
2015-01-08 18:02:28 +00:00
|
|
|
Qt::ItemFlags DiveImportedModel::flags(const QModelIndex &index) const
|
|
|
|
{
|
2015-01-08 13:00:42 +00:00
|
|
|
if (index.column() != 0)
|
|
|
|
return QAbstractTableModel::flags(index);
|
|
|
|
return QAbstractTableModel::flags(index) | Qt::ItemIsUserCheckable;
|
|
|
|
}
|
|
|
|
|
2015-01-11 15:46:21 +00:00
|
|
|
void DiveImportedModel::clearTable()
|
|
|
|
{
|
|
|
|
beginRemoveRows(QModelIndex(), 0, lastIndex - firstIndex);
|
|
|
|
lastIndex = -1;
|
|
|
|
firstIndex = 0;
|
|
|
|
endRemoveRows();
|
|
|
|
}
|
|
|
|
|
2015-01-08 12:12:11 +00:00
|
|
|
void DiveImportedModel::setImportedDivesIndexes(int first, int last)
|
|
|
|
{
|
2015-01-09 20:03:29 +00:00
|
|
|
Q_ASSERT(last >= first);
|
2015-01-08 12:15:34 +00:00
|
|
|
beginRemoveRows(QModelIndex(), 0, lastIndex - firstIndex);
|
|
|
|
endRemoveRows();
|
|
|
|
beginInsertRows(QModelIndex(), 0, last - first);
|
|
|
|
lastIndex = last;
|
|
|
|
firstIndex = first;
|
2015-01-08 12:52:54 +00:00
|
|
|
delete[] checkStates;
|
2015-01-09 20:03:29 +00:00
|
|
|
checkStates = new bool[last - first + 1];
|
|
|
|
memset(checkStates, true, last - first + 1);
|
2015-01-08 12:15:34 +00:00
|
|
|
endInsertRows();
|
2015-01-08 12:12:11 +00:00
|
|
|
}
|