diff --git a/qt-ui/downloadfromdivecomputer.cpp b/qt-ui/downloadfromdivecomputer.cpp index 9411ddd88..c1d74fb3a 100644 --- a/qt-ui/downloadfromdivecomputer.cpp +++ b/qt-ui/downloadfromdivecomputer.cpp @@ -4,6 +4,8 @@ #include "../libdivecomputer.h" #include "../helpers.h" #include "../display.h" +#include "../divelist.h" +#include "mainwindow.h" #include #include #include @@ -32,6 +34,12 @@ namespace DownloadFromDcGlobal{ const char *err_string; }; +DownloadFromDCWidget *DownloadFromDCWidget::instance() +{ + static DownloadFromDCWidget *dialog = new DownloadFromDCWidget(); + return dialog; +} + DownloadFromDCWidget::DownloadFromDCWidget(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f), ui(new Ui::DownloadFromDiveComputer), thread(0), downloading(false) { @@ -54,6 +62,12 @@ DownloadFromDCWidget::DownloadFromDCWidget(QWidget* parent, Qt::WindowFlags f) : ui->device->setText(default_dive_computer_device); } +void DownloadFromDCWidget::runDialog() +{ + ui->progressBar->hide(); + show(); +} + void DownloadFromDCWidget::on_vendor_currentIndexChanged(const QString& vendor) { QAbstractItemModel *currentModel = ui->product->model(); @@ -151,13 +165,20 @@ void DownloadFromDCWidget::on_ok_clicked() downloading = true; } +bool DownloadFromDCWidget::preferDownloaded() +{ + return ui->preferDownloaded->isChecked(); +} + DownloadThread::DownloadThread(device_data_t* data): data(data) { } void DownloadThread::run() { + DownloadFromDCWidget *dfdcw = DownloadFromDCWidget::instance(); do_libdivecomputer_import(data); + process_dives(TRUE, dfdcw->preferDownloaded()); } InterfaceThread::InterfaceThread(QObject* parent, device_data_t* data): QThread(parent), data(data) @@ -167,7 +188,8 @@ InterfaceThread::InterfaceThread(QObject* parent, device_data_t* data): QThread( void InterfaceThread::run() { DownloadThread *download = new DownloadThread(data); - + MainWindow *w = mainWindow(); + connect(download, SIGNAL(finished()), w, SLOT(refreshDisplay())); download->start(); while (download->isRunning()) { msleep(200); diff --git a/qt-ui/downloadfromdivecomputer.h b/qt-ui/downloadfromdivecomputer.h index fdc730753..27e64c96f 100644 --- a/qt-ui/downloadfromdivecomputer.h +++ b/qt-ui/downloadfromdivecomputer.h @@ -38,11 +38,11 @@ class DownloadFromDCWidget : public QDialog{ Q_OBJECT public: explicit DownloadFromDCWidget(QWidget* parent = 0, Qt::WindowFlags f = 0); - + static DownloadFromDCWidget *instance(); public slots: void on_ok_clicked(); void on_cancel_clicked(); - + void runDialog(); void on_vendor_currentIndexChanged(const QString& vendor); private: Ui::DownloadFromDiveComputer *ui; @@ -57,6 +57,8 @@ private: QStringListModel *vendorModel; QStringListModel *productModel; void fill_computer_list(); +public: + bool preferDownloaded(); }; #endif diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 8c600ea19..14958b50f 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -52,6 +52,14 @@ MainWindow::MainWindow() : ui(new Ui::MainWindow()) instance = this; } +// this gets called after we download dives from a divecomputer +void MainWindow::refreshDisplay() +{ + if (!selected_dive) + current_dive_changed(dive_table.nr - 1); + ui->ListWidget->reload(); +} + void MainWindow::current_dive_changed(int divenr) { select_dive(divenr); @@ -162,8 +170,8 @@ void MainWindow::on_actionQuit_triggered() void MainWindow::on_actionDownloadDC_triggered() { - DownloadFromDCWidget* downloadWidget = new DownloadFromDCWidget(); - downloadWidget->show(); + DownloadFromDCWidget* downloadWidget = DownloadFromDCWidget::instance(); + downloadWidget->runDialog(); } void MainWindow::on_actionDownloadWeb_triggered() diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index 2366617c6..36b174284 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -87,6 +87,7 @@ protected: public Q_SLOTS: void readSettings(); + void refreshDisplay(); private: Ui::MainWindow *ui;