mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-20 06:45:27 +00:00
improve DownloadDialog's error handling
shows an error message when libdivecomputer returns an error. Signed-off-by: Danilo Cesar Lemes de Paula <danilo.eu@gmail.com>
This commit is contained in:
parent
59da382613
commit
3f8e183008
2 changed files with 41 additions and 11 deletions
|
@ -11,6 +11,7 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QStringListModel>
|
#include <QStringListModel>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
struct product {
|
struct product {
|
||||||
const char *product;
|
const char *product;
|
||||||
|
@ -101,18 +102,18 @@ void DownloadFromDCWidget::updateState(states state)
|
||||||
|
|
||||||
// user pressed cancel but the application isn't doing anything.
|
// user pressed cancel but the application isn't doing anything.
|
||||||
// means close the window
|
// means close the window
|
||||||
else if ((currentState == INITIAL || currentState == CANCELLED || currentState == DONE)
|
else if ((currentState == INITIAL || currentState == CANCELLED || currentState == DONE || currentState == ERROR)
|
||||||
&& state == CANCELLING) {
|
&& state == CANCELLING) {
|
||||||
timer->stop();
|
timer->stop();
|
||||||
reject();
|
reject();
|
||||||
}
|
}
|
||||||
|
|
||||||
// A cancel is finished
|
// the cancelation process is finished
|
||||||
else if (currentState == CANCELLING && (state == DONE || state == CANCELLED)) {
|
else if (currentState == CANCELLING && (state == DONE || state == CANCELLED)) {
|
||||||
timer->stop();
|
timer->stop();
|
||||||
state = CANCELLED;
|
state = CANCELLED;
|
||||||
ui->progressBar->setValue(0);
|
ui->progressBar->setValue(0);
|
||||||
ui->progressbar->hide();
|
ui->progressBar->hide();
|
||||||
markChildrenAsEnabled();
|
markChildrenAsEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,6 +133,15 @@ void DownloadFromDCWidget::updateState(states state)
|
||||||
markChildrenAsDisabled();
|
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
|
// properly updating the widget state
|
||||||
currentState = state;
|
currentState = state;
|
||||||
}
|
}
|
||||||
|
@ -243,9 +253,12 @@ void DownloadFromDCWidget::reject()
|
||||||
|
|
||||||
void DownloadFromDCWidget::onDownloadThreadFinished()
|
void DownloadFromDCWidget::onDownloadThreadFinished()
|
||||||
{
|
{
|
||||||
if (currentState == DOWNLOADING)
|
if (currentState == DOWNLOADING) {
|
||||||
|
if (thread->error.isEmpty())
|
||||||
updateState(DONE);
|
updateState(DONE);
|
||||||
else
|
else
|
||||||
|
updateState(ERROR);
|
||||||
|
} else
|
||||||
updateState(CANCELLED);
|
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()
|
void DownloadThread::run()
|
||||||
{
|
{
|
||||||
DownloadFromDCWidget *dfdcw = DownloadFromDCWidget::instance();
|
DownloadFromDCWidget *dfdcw = DownloadFromDCWidget::instance();
|
||||||
|
const char *error;
|
||||||
|
|
||||||
if (!strcmp(data->vendor, "Uemis"))
|
if (!strcmp(data->vendor, "Uemis"))
|
||||||
do_uemis_import(data->devname, data->force_download);
|
error = do_uemis_import(data->devname, data->force_download);
|
||||||
else
|
else
|
||||||
// TODO: implement error handling
|
error = do_libdivecomputer_import(data);
|
||||||
do_libdivecomputer_import(data);
|
|
||||||
|
|
||||||
// I'm not sure if we should really process_dives even
|
if (error) {
|
||||||
|
this->error = str_error(error, data->devname, data->vendor, data->product);
|
||||||
|
}
|
||||||
|
|
||||||
|
// I'm not sure if we should really call process_dives even
|
||||||
// if there's an error or a cancelation
|
// if there's an error or a cancelation
|
||||||
process_dives(TRUE, dfdcw->preferDownloaded());
|
process_dives(TRUE, dfdcw->preferDownloaded());
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,10 @@ struct device_data_t;
|
||||||
class DownloadThread : public QThread{
|
class DownloadThread : public QThread{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit DownloadThread(QObject* parent, device_data_t* data);
|
DownloadThread(QObject* parent, device_data_t* data);
|
||||||
virtual void run();
|
virtual void run();
|
||||||
|
|
||||||
|
QString error;
|
||||||
private:
|
private:
|
||||||
device_data_t *data;
|
device_data_t *data;
|
||||||
};
|
};
|
||||||
|
@ -34,6 +36,7 @@ public:
|
||||||
DOWNLOADING,
|
DOWNLOADING,
|
||||||
CANCELLING,
|
CANCELLING,
|
||||||
CANCELLED,
|
CANCELLED,
|
||||||
|
ERROR,
|
||||||
DONE,
|
DONE,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue