summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libdivecomputer.c2
-rw-r--r--libdivecomputer.h4
-rw-r--r--qt-ui/downloadfromdivecomputer.cpp29
-rw-r--r--qt-ui/downloadfromdivecomputer.h2
4 files changed, 24 insertions, 13 deletions
diff --git a/libdivecomputer.c b/libdivecomputer.c
index ecc90accc..6397018a3 100644
--- a/libdivecomputer.c
+++ b/libdivecomputer.c
@@ -652,7 +652,7 @@ static void event_cb(dc_device_t *device, dc_event_type_t event, const void *dat
}
}
-static int import_thread_done = 0, import_thread_cancelled;
+int import_thread_cancelled;
static int
cancel_cb(void *userdata)
diff --git a/libdivecomputer.h b/libdivecomputer.h
index 996037c8c..3cc8bd4b3 100644
--- a/libdivecomputer.h
+++ b/libdivecomputer.h
@@ -29,6 +29,10 @@ typedef struct device_data_t {
const char *do_libdivecomputer_import(device_data_t *data);
+extern int import_thread_cancelled;
+extern const char *progress_bar_text;
+extern double progress_bar_fraction;
+
#ifdef __cplusplus
}
#endif
diff --git a/qt-ui/downloadfromdivecomputer.cpp b/qt-ui/downloadfromdivecomputer.cpp
index 8be4e6cbb..385f39755 100644
--- a/qt-ui/downloadfromdivecomputer.cpp
+++ b/qt-ui/downloadfromdivecomputer.cpp
@@ -10,11 +10,8 @@ namespace DownloadFromDcGlobal{
const char *err_string;
};
-extern const char *progress_bar_text;
-extern double progress_bar_fraction;
-
DownloadFromDCWidget::DownloadFromDCWidget(QWidget* parent, Qt::WindowFlags f) :
- QDialog(parent, f), ui(new Ui::DownloadFromDiveComputer), thread(0)
+ QDialog(parent, f), ui(new Ui::DownloadFromDiveComputer), thread(0), downloading(false)
{
ui->setupUi(this);
ui->progressBar->hide();
@@ -24,11 +21,19 @@ DownloadFromDCWidget::DownloadFromDCWidget(QWidget* parent, Qt::WindowFlags f) :
void DownloadFromDCWidget::on_cancel_clicked()
{
+ import_thread_cancelled = true;
+ if(thread){
+ thread->wait();
+ thread->deleteLater();
+ thread = 0;
+ }
close();
}
void DownloadFromDCWidget::on_ok_clicked()
{
+ if (downloading)
+ return;
ui->progressBar->setValue(0);
ui->progressBar->show();
@@ -40,9 +45,13 @@ void DownloadFromDCWidget::on_ok_clicked()
device_data_t data;
// still need to fill the data info here.
thread = new InterfaceThread(this, &data);
- connect(thread, SIGNAL(updateInterface(int)), ui->progressBar, SLOT(setValue(int)), Qt::QueuedConnection); // Qt::QueuedConnection == threadsafe.
- connect(thread, SIGNAL(updateInterface(int)), this, SLOT(setValue(int)), Qt::QueuedConnection); // Qt::QueuedConnection == threadsafe.
+ 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;
}
DownloadThread::DownloadThread(device_data_t* data): data(data)
@@ -52,12 +61,10 @@ DownloadThread::DownloadThread(device_data_t* data): data(data)
void DownloadThread::run()
{
do_libdivecomputer_import(data);
- qDebug() << "Download thread started";
}
InterfaceThread::InterfaceThread(QObject* parent, device_data_t* data): QThread(parent), data(data)
{
-
}
void InterfaceThread::run()
@@ -65,9 +72,9 @@ void InterfaceThread::run()
DownloadThread *download = new DownloadThread(data);
download->start();
- while(download->isRunning()){
+ while(download->isRunning()){
msleep(200);
- updateInterface(progress_bar_fraction *100);
- }
+ updateInterface(progress_bar_fraction *100);
+ }
updateInterface(100);
}
diff --git a/qt-ui/downloadfromdivecomputer.h b/qt-ui/downloadfromdivecomputer.h
index 433d43779..ef17df8d4 100644
--- a/qt-ui/downloadfromdivecomputer.h
+++ b/qt-ui/downloadfromdivecomputer.h
@@ -40,7 +40,7 @@ public slots:
private:
Ui::DownloadFromDiveComputer *ui;
InterfaceThread *thread;
+ bool downloading;
};
-
#endif \ No newline at end of file