From 67ee073a3b6be35d9e605721d987dabcae9a84fb Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 29 May 2018 17:00:15 +0900 Subject: [PATCH] Report about errors that the user should know about (including the "consent not given" one) Using Connection::requestFailed() and BaseJob::isBackground() from the latest lib. --- client/mainwindow.cpp | 32 ++++++++++++++++++++++++++++++-- lib | 2 +- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/client/mainwindow.cpp b/client/mainwindow.cpp index f5b2c8d02..7b3e4ab5a 100644 --- a/client/mainwindow.cpp +++ b/client/mainwindow.cpp @@ -53,6 +53,7 @@ #include #include #include +#include using QMatrixClient::NetworkAccessManager; using QMatrixClient::AccountSettings; @@ -384,8 +385,10 @@ void MainWindow::addConnection(Connection* c, const QString& deviceName) connect( c, &Connection::syncError, this, [this,c] (const QString& message, const QByteArray& details) { QMessageBox msgBox(QMessageBox::Warning, tr("Sync failed"), - tr("The last sync of account %1 has failed with error: %3") - .arg(c->userId()).arg(message), + connections.size() > 1 + ? tr("The last sync of account %1 has failed with error: %2") + .arg(c->userId(), message) + : tr("The last sync has failed with error: %1").arg(message), QMessageBox::Retry|QMessageBox::Cancel, this); msgBox.setTextFormat(Qt::PlainText); msgBox.setDefaultButton(QMessageBox::Retry); @@ -397,6 +400,31 @@ void MainWindow::addConnection(Connection* c, const QString& deviceName) if (msgBox.exec() == QMessageBox::Retry) getNewEvents(c); }); + connect( c, &Connection::requestFailed, this, + [this] (QMatrixClient::BaseJob* job) + { + if (job->isBackground()) + return; + QMessageBox msgBox(QMessageBox::Warning, job->errorCaption(), + QMatrixClient::prettyPrint(job->errorString()), + QMessageBox::Close, this); + msgBox.setTextFormat(Qt::RichText); + msgBox.setDetailedText( + "Request URL: " + job->requestUrl().toDisplayString() + + "\nResponse:\n" + job->errorRawData()); + QPushButton* openUrlButton = nullptr; + if (job->errorUrl().isEmpty()) + msgBox.setDefaultButton(QMessageBox::Close); + else + { + openUrlButton = + msgBox.addButton(tr("Open URL"), QMessageBox::ActionRole); + openUrlButton->setDefault(true); + } + msgBox.exec(); + if (msgBox.clickedButton() == openUrlButton) + QDesktopServices::openUrl(job->errorUrl()); + }); connect( c, &Connection::loginError, this, [=](const QString& msg){ loginError(c, msg); } ); connect( c, &Connection::newRoom, systemTrayIcon, &SystemTrayIcon::newRoom ); diff --git a/lib b/lib index 6a4af80a7..c55c1cc83 160000 --- a/lib +++ b/lib @@ -1 +1 @@ -Subproject commit 6a4af80a7199753b493b17684162673b024d2191 +Subproject commit c55c1cc83985f808e9cfc7475e5113566a1ac5a8