2013-05-20 19:43:33 +00:00
|
|
|
#include "downloadfromdivecomputer.h"
|
2014-05-12 16:53:26 +00:00
|
|
|
#include "../divecomputer.h"
|
2013-05-20 19:43:33 +00:00
|
|
|
#include "../libdivecomputer.h"
|
2013-05-23 06:24:33 +00:00
|
|
|
#include "../helpers.h"
|
|
|
|
#include "../display.h"
|
2013-05-30 08:58:59 +00:00
|
|
|
#include "../divelist.h"
|
2014-05-12 16:53:26 +00:00
|
|
|
|
2013-05-30 08:58:59 +00:00
|
|
|
#include "mainwindow.h"
|
2013-05-20 20:58:06 +00:00
|
|
|
#include <cstdlib>
|
2013-05-20 19:43:33 +00:00
|
|
|
#include <QThread>
|
|
|
|
#include <QDebug>
|
2013-05-20 20:58:06 +00:00
|
|
|
#include <QStringListModel>
|
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-02-28 04:09:57 +00:00
|
|
|
namespace DownloadFromDcGlobal
|
|
|
|
{
|
2013-05-20 19:43:33 +00:00
|
|
|
const char *err_string;
|
|
|
|
};
|
|
|
|
|
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),
|
|
|
|
currentState(INITIAL)
|
2013-05-20 19:43:33 +00:00
|
|
|
{
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.setupUi(this);
|
|
|
|
ui.progressBar->hide();
|
|
|
|
ui.progressBar->setMinimum(0);
|
|
|
|
ui.progressBar->setMaximum(100);
|
2013-09-16 21:04:42 +00:00
|
|
|
|
2014-02-26 16:37:13 +00:00
|
|
|
progress_bar_text = "";
|
|
|
|
|
2013-09-16 21:04:42 +00:00
|
|
|
fill_device_list();
|
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)));
|
2013-05-20 20:58:06 +00:00
|
|
|
vendorModel = new QStringListModel(vendorList);
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.vendor->setModel(vendorModel);
|
2013-05-23 06:24:33 +00:00
|
|
|
if (default_dive_computer_vendor) {
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.vendor->setCurrentIndex(ui.vendor->findText(default_dive_computer_vendor));
|
2013-05-23 06:24:33 +00:00
|
|
|
productModel = new QStringListModel(productList[default_dive_computer_vendor]);
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.product->setModel(productModel);
|
2013-05-23 06:24:33 +00:00
|
|
|
if (default_dive_computer_product)
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.product->setCurrentIndex(ui.product->findText(default_dive_computer_product));
|
2013-05-23 06:24:33 +00:00
|
|
|
}
|
2013-12-27 10:50:13 +00:00
|
|
|
connect(ui.product, SIGNAL(currentIndexChanged(int)), this, SLOT(on_product_currentIndexChanged()), Qt::UniqueConnection);
|
2013-05-23 06:24:33 +00:00
|
|
|
if (default_dive_computer_device)
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.device->setEditText(default_dive_computer_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()));
|
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) {
|
2013-09-16 21:04:42 +00:00
|
|
|
fill_device_list();
|
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;
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.cancel->setEnabled(false);
|
2013-08-25 22:02:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// user pressed cancel but the application isn't doing anything.
|
|
|
|
// means close the window
|
2014-02-28 04:09:57 +00:00
|
|
|
else if ((currentState == INITIAL || currentState == CANCELLED || currentState == DONE || currentState == ERROR) && state == CANCELLING) {
|
2013-08-25 22:02:30 +00:00
|
|
|
timer->stop();
|
|
|
|
reject();
|
2013-11-09 06:57:36 +00:00
|
|
|
ui.ok->setText(tr("OK"));
|
2013-08-25 22:02:30 +00:00
|
|
|
}
|
|
|
|
|
2013-09-01 14:14:54 +00:00
|
|
|
// the cancelation process is finished
|
2013-08-25 22:02:30 +00:00
|
|
|
else if (currentState == CANCELLING && (state == DONE || state == CANCELLED)) {
|
|
|
|
timer->stop();
|
|
|
|
state = CANCELLED;
|
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
|
|
|
|
// that information on to us
|
|
|
|
// so check the progressBar text and if no error was reported, close the dialog and go back to the main window
|
|
|
|
// otherwise treat this as if the download was cancelled
|
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 = "";
|
|
|
|
ui.ok->setText(tr("Retry"));
|
|
|
|
} else {
|
|
|
|
ui.progressBar->setValue(100);
|
|
|
|
markChildrenAsEnabled();
|
|
|
|
ui.ok->setText(tr("OK"));
|
|
|
|
accept();
|
|
|
|
}
|
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-11-09 06:57:36 +00:00
|
|
|
ui.ok->setText(tr("Retry"));
|
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
|
|
|
{
|
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
|
|
|
|
|
|
|
// Memleak - but deleting gives me a crash.
|
|
|
|
//currentModel->deleteLater();
|
|
|
|
}
|
|
|
|
|
2013-12-27 10:50:13 +00:00
|
|
|
void DownloadFromDCWidget::on_product_currentIndexChanged()
|
|
|
|
{
|
|
|
|
// Set up the DC descriptor
|
|
|
|
dc_descriptor_t *descriptor = NULL;
|
|
|
|
descriptor = descriptorLookup[ui.vendor->currentText() + ui.product->currentText()];
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
|
|
|
descriptorLookup[QString("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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-20 19:43:33 +00:00
|
|
|
void DownloadFromDCWidget::on_cancel_clicked()
|
|
|
|
{
|
2013-08-25 22:02:30 +00:00
|
|
|
updateState(CANCELLING);
|
2013-05-20 19:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadFromDCWidget::on_ok_clicked()
|
|
|
|
{
|
2013-08-25 22:02:30 +00:00
|
|
|
updateState(DOWNLOADING);
|
2013-05-20 19:43:33 +00:00
|
|
|
|
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.devname = strdup(ui.device->currentText().toUtf8().data());
|
|
|
|
data.vendor = strdup(ui.vendor->currentText().toUtf8().data());
|
|
|
|
data.product = strdup(ui.product->currentText().toUtf8().data());
|
2013-08-25 13:01:59 +00:00
|
|
|
|
2013-10-03 18:54:25 +00:00
|
|
|
data.descriptor = descriptorLookup[ui.vendor->currentText() + ui.product->currentText()];
|
|
|
|
data.force_download = ui.forceDownload->isChecked();
|
2013-06-16 00:48:31 +00:00
|
|
|
data.deviceid = data.diveid = 0;
|
2013-05-23 06:24:33 +00:00
|
|
|
set_default_dive_computer(data.vendor, data.product);
|
|
|
|
set_default_dive_computer_device(data.devname);
|
2013-05-21 04:55:56 +00:00
|
|
|
|
2013-08-25 22:02:30 +00:00
|
|
|
thread = new DownloadThread(this, &data);
|
2013-05-20 20:02:17 +00:00
|
|
|
|
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
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
logFile = QFileDialog::getSaveFileName(this, tr("Choose file for divecomputer download logfile"),
|
|
|
|
filename, tr("Log files (*.log)"));
|
2014-01-07 14:41:21 +00:00
|
|
|
if (!logFile.isEmpty()) {
|
|
|
|
if (logfile_name)
|
|
|
|
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");
|
|
|
|
dumpFile = QFileDialog::getSaveFileName(this, tr("Choose file for divecomputer binary dump file"),
|
|
|
|
filename, tr("Dump files (*.bin)"));
|
2014-01-07 14:41:21 +00:00
|
|
|
if (!dumpFile.isEmpty()) {
|
|
|
|
if (dumpfile_name)
|
|
|
|
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);
|
2013-09-17 21:36:22 +00:00
|
|
|
|
|
|
|
// I'm not sure if we should really call process_dives even
|
2013-12-08 05:33:46 +00:00
|
|
|
// if there's an error
|
|
|
|
if (import_thread_cancelled) {
|
|
|
|
// walk backwards so we don't keep moving the dives
|
|
|
|
// down in the dive_table
|
|
|
|
for (int i = dive_table.nr - 1; i >= previousLast; i--)
|
|
|
|
delete_single_dive(i);
|
|
|
|
} else {
|
2014-01-15 08:30:42 +00:00
|
|
|
process_dives(true, preferDownloaded());
|
2013-12-08 05:33:46 +00:00
|
|
|
}
|
2014-04-24 16:16:57 +00:00
|
|
|
} else if (currentState == CANCELLING || currentState == CANCELLED){
|
|
|
|
if (import_thread_cancelled) {
|
|
|
|
// walk backwards so we don't keep moving the dives
|
|
|
|
// down in the dive_table
|
|
|
|
for (int i = dive_table.nr - 1; i >= previousLast; i--)
|
|
|
|
delete_single_dive(i);
|
|
|
|
}
|
2013-08-25 22:02:30 +00:00
|
|
|
updateState(CANCELLED);
|
2013-12-08 05:33:46 +00:00
|
|
|
}
|
2013-08-25 22:02:30 +00:00
|
|
|
}
|
|
|
|
|
2013-08-25 13:01:59 +00:00
|
|
|
void DownloadFromDCWidget::markChildrenAsDisabled()
|
|
|
|
{
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.device->setDisabled(true);
|
|
|
|
ui.vendor->setDisabled(true);
|
|
|
|
ui.product->setDisabled(true);
|
|
|
|
ui.forceDownload->setDisabled(true);
|
|
|
|
ui.preferDownloaded->setDisabled(true);
|
|
|
|
ui.ok->setDisabled(true);
|
|
|
|
ui.search->setDisabled(true);
|
2014-02-22 14:44:50 +00:00
|
|
|
ui.logToFile->setDisabled(true);
|
|
|
|
ui.dumpToFile->setDisabled(true);
|
|
|
|
ui.chooseLogFile->setDisabled(true);
|
|
|
|
ui.chooseDumpFile->setDisabled(true);
|
2013-08-25 13:01:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadFromDCWidget::markChildrenAsEnabled()
|
|
|
|
{
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.device->setDisabled(false);
|
|
|
|
ui.vendor->setDisabled(false);
|
|
|
|
ui.product->setDisabled(false);
|
|
|
|
ui.forceDownload->setDisabled(false);
|
|
|
|
ui.preferDownloaded->setDisabled(false);
|
|
|
|
ui.ok->setDisabled(false);
|
|
|
|
ui.cancel->setDisabled(false);
|
|
|
|
ui.search->setDisabled(false);
|
2014-02-22 14:44:50 +00:00
|
|
|
ui.logToFile->setDisabled(false);
|
|
|
|
ui.dumpToFile->setDisabled(false);
|
|
|
|
ui.chooseLogFile->setDisabled(false);
|
|
|
|
ui.chooseDumpFile->setDisabled(false);
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadFromDCWidget::fill_device_list()
|
|
|
|
{
|
|
|
|
int deviceIndex;
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.device->clear();
|
|
|
|
deviceIndex = enumerate_devices(fillDeviceList, ui.device);
|
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;
|
2013-06-24 22:14:07 +00:00
|
|
|
if (!strcmp(data->vendor, "Uemis"))
|
2014-02-12 13:51:25 +00:00
|
|
|
errorText = do_uemis_import(data->devname, data->force_download);
|
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
|
|
|
}
|