From 9d8a7a59a231e144918506162278dc4e7ead56ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig=20B=2E=20D=C3=B8rm=C3=A6nen?= Date: Tue, 25 Feb 2014 14:23:37 +0100 Subject: [PATCH] Made the fault handling in TPDownload a little more user friendly If something goes wrong, we try to display the fault message to the user. --- src/TPDownload.cpp | 10 +++++++--- src/TPDownload.h | 2 +- src/TPDownloadDialog.cpp | 11 ++++++++--- src/TPDownloadDialog.h | 2 +- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/TPDownload.cpp b/src/TPDownload.cpp index 0ddf7e757..fd8baa8b9 100644 --- a/src/TPDownload.cpp +++ b/src/TPDownload.cpp @@ -63,9 +63,13 @@ TPAthlete::list(int type, QString user, QString pass) void TPAthlete::getResponse(const QtSoapMessage &message) { waiting = false; + QString resultStr; QList< QMap > athletelist; - if (!message.isFault()) { + if (message.isFault()) { + resultStr = tr("Error:") + qPrintable(message.faultString().toString()); + } + else { const QtSoapType &response = message.returnValue(); if (response.isValid()) { @@ -97,8 +101,8 @@ void TPAthlete::getResponse(const QtSoapMessage &message) } } - // return what we got (empty if failed) - completed(athletelist); + // return what we got (empty if non-valid response) + completed(resultStr, athletelist); } // diff --git a/src/TPDownload.h b/src/TPDownload.h index d5da19361..49d2264fa 100644 --- a/src/TPDownload.h +++ b/src/TPDownload.h @@ -34,7 +34,7 @@ public: void list(int type, QString user, QString pass); signals: - void completed(QList >); + void completed(QString, QList >); private slots: void getResponse(const QtSoapMessage &); diff --git a/src/TPDownloadDialog.cpp b/src/TPDownloadDialog.cpp index c51b21704..ac25ec560 100644 --- a/src/TPDownloadDialog.cpp +++ b/src/TPDownloadDialog.cpp @@ -31,7 +31,7 @@ TPDownloadDialog::TPDownloadDialog(MainWindow *main) : QDialog(main, Qt::Dialog) athleter = new TPAthlete(this); - connect (athleter, SIGNAL(completed(QList >)), this, SLOT(completedAthlete(QList >))); + connect (athleter, SIGNAL(completed(QString, QList >)), this, SLOT(completedAthlete(QString, QList >))); athleter->list(appsettings->cvalue(main->cyclist, GC_TPTYPE, "0").toInt(), appsettings->cvalue(main->cyclist, GC_TPUSER, "null").toString(), appsettings->cvalue(main->cyclist, GC_TPPASS, "null").toString()); @@ -40,7 +40,7 @@ TPDownloadDialog::TPDownloadDialog(MainWindow *main) : QDialog(main, Qt::Dialog) } void -TPDownloadDialog::completedAthlete(QList >athletes) +TPDownloadDialog::completedAthlete(QString errorStr, QList >athletes) { // did we get any athletes? if (athletes.count() == 0) { @@ -48,7 +48,12 @@ TPDownloadDialog::completedAthlete(QList >athletes) QMessageBox msgBox; msgBox.setWindowTitle(tr("Download from TrainingPeaks.com")); - msgBox.setText(tr("You must be a premium member to download from TrainingPeaks. Please check your cyclist configurations are correct on the Passwords tab.")); + if (errorStr.size() != 0) { // Something went wrong, so there should be a fault message + msgBox.setText(errorStr); + } + else { + msgBox.setText(tr("You must be a premium member to download from TrainingPeaks. Please check your cyclist configurations are correct on the Passwords tab.")); + } msgBox.setIcon(QMessageBox::Critical); msgBox.exec(); reject(); diff --git a/src/TPDownloadDialog.h b/src/TPDownloadDialog.h index dcb83ba83..e6c4bee91 100644 --- a/src/TPDownloadDialog.h +++ b/src/TPDownloadDialog.h @@ -44,7 +44,7 @@ class TPDownloadDialog : public QDialog bool useMetricUnits; public slots: - void completedAthlete(QList >); + void completedAthlete(QString, QList >); void completedWorkout(QList >); void completedDownload(QDomDocument); void completedUpload(QString);