summaryrefslogtreecommitdiffstats
path: root/qt-ui/downloadfromdivecomputer.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-05-20 16:43:33 -0300
committerGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-05-20 16:43:33 -0300
commitc7a5d0490fa5f4e8579e6a8e0fbdc7baf7c34145 (patch)
tree615ec1dbf0887d0e1ffeecf4ed7b1600ca0c0d6a /qt-ui/downloadfromdivecomputer.cpp
parent15bb4fccbb14c0e69637ca5920a1e68071700b8e (diff)
downloadsubsurface-c7a5d0490fa5f4e8579e6a8e0fbdc7baf7c34145.tar.gz
Skeleton code for a non-blocking UI thread for downloading dives from the DC
This is the skeleton code for a non-blocking ui-thread It already creates the first-thread ( 'do not block the ui' ) and the second thread ('download from the dive computer') We can in the future merge both in the same place - I didn't want to do that now because the download function is written in the libdivecomputer.c code, and I cant just transform that to a QThread and use signals, so I used two threads for that. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Diffstat (limited to 'qt-ui/downloadfromdivecomputer.cpp')
-rw-r--r--qt-ui/downloadfromdivecomputer.cpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/qt-ui/downloadfromdivecomputer.cpp b/qt-ui/downloadfromdivecomputer.cpp
new file mode 100644
index 000000000..8be4e6cbb
--- /dev/null
+++ b/qt-ui/downloadfromdivecomputer.cpp
@@ -0,0 +1,73 @@
+#include "downloadfromdivecomputer.h"
+#include "ui_downloadfromdivecomputer.h"
+
+#include "../libdivecomputer.h"
+
+#include <QThread>
+#include <QDebug>
+
+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)
+{
+ ui->setupUi(this);
+ ui->progressBar->hide();
+ ui->progressBar->setMinimum(0);
+ ui->progressBar->setMaximum(100);
+}
+
+void DownloadFromDCWidget::on_cancel_clicked()
+{
+ close();
+}
+
+void DownloadFromDCWidget::on_ok_clicked()
+{
+
+ ui->progressBar->setValue(0);
+ ui->progressBar->show();
+
+ if(thread){
+ thread->deleteLater();
+ }
+
+ 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.
+ thread->start();
+}
+
+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()
+{
+ DownloadThread *download = new DownloadThread(data);
+
+ download->start();
+ while(download->isRunning()){
+ msleep(200);
+ updateInterface(progress_bar_fraction *100);
+ }
+ updateInterface(100);
+}