2013-05-20 19:43:33 +00:00
|
|
|
#include "downloadfromdivecomputer.h"
|
|
|
|
#include "ui_downloadfromdivecomputer.h"
|
|
|
|
|
|
|
|
#include "../libdivecomputer.h"
|
|
|
|
|
|
|
|
#include <QThread>
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
namespace DownloadFromDcGlobal{
|
|
|
|
const char *err_string;
|
|
|
|
};
|
|
|
|
|
|
|
|
DownloadFromDCWidget::DownloadFromDCWidget(QWidget* parent, Qt::WindowFlags f) :
|
2013-05-20 20:02:17 +00:00
|
|
|
QDialog(parent, f), ui(new Ui::DownloadFromDiveComputer), thread(0), downloading(false)
|
2013-05-20 19:43:33 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
ui->progressBar->hide();
|
|
|
|
ui->progressBar->setMinimum(0);
|
|
|
|
ui->progressBar->setMaximum(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadFromDCWidget::on_cancel_clicked()
|
|
|
|
{
|
2013-05-20 20:02:17 +00:00
|
|
|
import_thread_cancelled = true;
|
|
|
|
if(thread){
|
|
|
|
thread->wait();
|
|
|
|
thread->deleteLater();
|
|
|
|
thread = 0;
|
|
|
|
}
|
2013-05-20 19:43:33 +00:00
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadFromDCWidget::on_ok_clicked()
|
|
|
|
{
|
2013-05-20 20:02:17 +00:00
|
|
|
if (downloading)
|
|
|
|
return;
|
2013-05-20 19:43:33 +00:00
|
|
|
|
|
|
|
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);
|
2013-05-20 20:02:17 +00:00
|
|
|
connect(thread, SIGNAL(updateInterface(int)),
|
|
|
|
ui->progressBar, SLOT(setValue(int)), Qt::QueuedConnection); // Qt::QueuedConnection == threadsafe.
|
|
|
|
|
|
|
|
connect(thread, SIGNAL(finished()), this, SLOT(close()));
|
|
|
|
|
2013-05-20 19:43:33 +00:00
|
|
|
thread->start();
|
2013-05-20 20:02:17 +00:00
|
|
|
downloading = true;
|
2013-05-20 19:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DownloadThread::DownloadThread(device_data_t* data): data(data)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadThread::run()
|
|
|
|
{
|
|
|
|
do_libdivecomputer_import(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
InterfaceThread::InterfaceThread(QObject* parent, device_data_t* data): QThread(parent), data(data)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void InterfaceThread::run()
|
|
|
|
{
|
|
|
|
DownloadThread *download = new DownloadThread(data);
|
|
|
|
|
|
|
|
download->start();
|
2013-05-20 20:02:17 +00:00
|
|
|
while(download->isRunning()){
|
2013-05-20 19:43:33 +00:00
|
|
|
msleep(200);
|
2013-05-20 20:02:17 +00:00
|
|
|
updateInterface(progress_bar_fraction *100);
|
|
|
|
}
|
2013-05-20 19:43:33 +00:00
|
|
|
updateInterface(100);
|
|
|
|
}
|