void DownloadFromDCWidget::on_ok_clicked() { updateState(DOWNLOADING); // I don't really think that create/destroy the thread // is really necessary. if (thread) { thread->deleteLater(); } data.devname = strdup(ui.device->currentText().toUtf8().data()); data.vendor = strdup(ui.vendor->currentText().toUtf8().data()); data.product = strdup(ui.product->currentText().toUtf8().data()); data.descriptor = descriptorLookup[ui.vendor->currentText() + ui.product->currentText()]; data.force_download = ui.forceDownload->isChecked(); data.deviceid = data.diveid = 0; set_default_dive_computer(data.vendor, data.product); set_default_dive_computer_device(data.devname); thread = new DownloadThread(this, &data); connect(thread, SIGNAL(finished()), this, SLOT(onDownloadThreadFinished()), Qt::QueuedConnection); MainWindow *w = MainWindow::instance(); connect(thread, SIGNAL(finished()), w, SLOT(refreshDisplay())); // before we start, remember where the dive_table ended previousLast = dive_table.nr; thread->start(); }
void DownloadFromDCWidget::on_ok_clicked() { if (downloading) return; ui->progressBar->setValue(0); ui->progressBar->show(); if (thread) { thread->deleteLater(); } data.devname = strdup(ui->device->text().toUtf8().data()); data.vendor = strdup(ui->vendor->currentText().toUtf8().data()); data.product = strdup(ui->product->currentText().toUtf8().data()); data.descriptor = descriptorLookup[ui->vendor->currentText() + ui->product->currentText()]; data.force_download = ui->forceDownload->isChecked(); set_default_dive_computer(data.vendor, data.product); set_default_dive_computer_device(data.devname); thread = new InterfaceThread(this, &data); connect(thread, SIGNAL(updateInterface(int)), ui->progressBar, SLOT(setValue(int)), Qt::QueuedConnection); // Qt::QueuedConnection == threadsafe. connect(thread, SIGNAL(finished()), this, SLOT(close())); thread->start(); downloading = true; }
void DownloadFromDCWidget::on_downloadCancelRetryButton_clicked() { if (currentState == DOWNLOADING) { updateState(CANCELLING); return; } 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); } if (ui.vendor->currentText() == "Uemis") { if (currentState == ERROR && downloadTable.nr > 0) // let the uemis code know how far we've gotten uemis_set_max_diveid_from_dialog(downloadTable.dives[downloadTable.nr - 1]->dc.diveid); else // fresh download, so only look at what's in the dive_table uemis_set_max_diveid_from_dialog(0); } updateState(DOWNLOADING); // you cannot cancel the dialog, just the download ui.cancel->setEnabled(false); ui.downloadCancelRetryButton->setText("Cancel download"); // I don't really think that create/destroy the thread // is really necessary. if (thread) { thread->deleteLater(); } data.vendor = strdup(ui.vendor->currentText().toUtf8().data()); data.product = strdup(ui.product->currentText().toUtf8().data()); #if defined(BT_SUPPORT) data.bluetooth_mode = ui.bluetoothMode->isChecked(); if (data.bluetooth_mode && btDeviceSelectionDialog != NULL) { // Get the selected device address data.devname = strdup(btDeviceSelectionDialog->getSelectedDeviceAddress().toUtf8().data()); } else // this breaks an "else if" across lines... not happy... #endif if (same_string(data.vendor, "Uemis")) { char *colon; char *devname = strdup(ui.device->currentText().toUtf8().data()); 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()); } data.descriptor = descriptorLookup[ui.vendor->currentText() + ui.product->currentText()]; data.force_download = ui.forceDownload->isChecked(); data.create_new_trip = ui.createNewTrip->isChecked(); data.trip = NULL; data.deviceid = data.diveid = 0; set_default_dive_computer(data.vendor, data.product); set_default_dive_computer_device(data.devname); set_default_dive_computer_download_mode(ui.bluetoothMode->isChecked() ? DC_TRANSPORT_BLUETOOTH : DC_TRANSPORT_SERIAL); thread = new DownloadThread(this, &data); connect(thread, SIGNAL(finished()), this, SLOT(onDownloadThreadFinished()), Qt::QueuedConnection); MainWindow *w = MainWindow::instance(); connect(thread, SIGNAL(finished()), w, SLOT(refreshDisplay())); // before we start, remember where the dive_table ended previousLast = dive_table.nr; thread->start(); QString product(ui.product->currentText()); if (product == "OSTC 3" || product == "OSTC Sport") ostcFirmwareCheck = new OstcFirmwareCheck(product); }