Skip to content

Commit

Permalink
Report about errors that the user should know about (including the "c…
Browse files Browse the repository at this point in the history
…onsent not given" one)

Using Connection::requestFailed() and BaseJob::isBackground() from the latest lib.
  • Loading branch information
KitsuneRal committed May 29, 2018
1 parent 55c0faf commit 67ee073
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
32 changes: 30 additions & 2 deletions client/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include <QtWidgets/QFormLayout>
#include <QtGui/QMovie>
#include <QtGui/QCloseEvent>
#include <QtGui/QDesktopServices>

using QMatrixClient::NetworkAccessManager;
using QMatrixClient::AccountSettings;
Expand Down Expand Up @@ -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);
Expand All @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion lib
Submodule lib updated from 6a4af8 to c55c1c

0 comments on commit 67ee073

Please sign in to comment.