diff options
Diffstat (limited to 'qt-ui')
-rw-r--r-- | qt-ui/downloadfromdivecomputer.cpp | 47 | ||||
-rw-r--r-- | qt-ui/downloadfromdivecomputer.h | 5 |
2 files changed, 41 insertions, 11 deletions
diff --git a/qt-ui/downloadfromdivecomputer.cpp b/qt-ui/downloadfromdivecomputer.cpp index f5c6fd51f..acdca89d3 100644 --- a/qt-ui/downloadfromdivecomputer.cpp +++ b/qt-ui/downloadfromdivecomputer.cpp @@ -11,6 +11,7 @@ #include <QDebug> #include <QStringListModel> #include <QTimer> +#include <QMessageBox> struct product { const char *product; @@ -101,18 +102,18 @@ void DownloadFromDCWidget::updateState(states state) // user pressed cancel but the application isn't doing anything. // means close the window - else if ((currentState == INITIAL || currentState == CANCELLED || currentState == DONE) + else if ((currentState == INITIAL || currentState == CANCELLED || currentState == DONE || currentState == ERROR) && state == CANCELLING) { timer->stop(); reject(); } - // A cancel is finished + // the cancelation process is finished else if (currentState == CANCELLING && (state == DONE || state == CANCELLED)) { timer->stop(); state = CANCELLED; ui->progressBar->setValue(0); - ui->progressbar->hide(); + ui->progressBar->hide(); markChildrenAsEnabled(); } @@ -132,6 +133,15 @@ void DownloadFromDCWidget::updateState(states state) markChildrenAsDisabled(); } + // got an error + else if (state == ERROR) { + QMessageBox::critical(this, tr("Error"), this->thread->error, QMessageBox::Ok); + + markChildrenAsEnabled(); + ui->progressBar->hide(); + ui->ok->setText(tr("retry")); + } + // properly updating the widget state currentState = state; } @@ -243,9 +253,12 @@ void DownloadFromDCWidget::reject() void DownloadFromDCWidget::onDownloadThreadFinished() { - if (currentState == DOWNLOADING) - updateState(DONE); - else + if (currentState == DOWNLOADING) { + if (thread->error.isEmpty()) + updateState(DONE); + else + updateState(ERROR); + } else updateState(CANCELLED); } @@ -277,17 +290,31 @@ DownloadThread::DownloadThread(QObject* parent, device_data_t* data): QThread(pa { } +static QString str_error(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + const QString str = QString().vsprintf( fmt, args ); + va_end(args); + + return str; +} + void DownloadThread::run() { DownloadFromDCWidget *dfdcw = DownloadFromDCWidget::instance(); + const char *error; if (!strcmp(data->vendor, "Uemis")) - do_uemis_import(data->devname, data->force_download); + error = do_uemis_import(data->devname, data->force_download); else - // TODO: implement error handling - do_libdivecomputer_import(data); + error = do_libdivecomputer_import(data); + + if (error) { + this->error = str_error(error, data->devname, data->vendor, data->product); + } - // I'm not sure if we should really process_dives even + // I'm not sure if we should really call process_dives even // if there's an error or a cancelation process_dives(TRUE, dfdcw->preferDownloaded()); } diff --git a/qt-ui/downloadfromdivecomputer.h b/qt-ui/downloadfromdivecomputer.h index f092314c0..e10d61b38 100644 --- a/qt-ui/downloadfromdivecomputer.h +++ b/qt-ui/downloadfromdivecomputer.h @@ -15,8 +15,10 @@ struct device_data_t; class DownloadThread : public QThread{ Q_OBJECT public: - explicit DownloadThread(QObject* parent, device_data_t* data); + DownloadThread(QObject* parent, device_data_t* data); virtual void run(); + + QString error; private: device_data_t *data; }; @@ -34,6 +36,7 @@ public: DOWNLOADING, CANCELLING, CANCELLED, + ERROR, DONE, }; |