diff --git a/src/tl/tl/PasswordDialog.ui b/src/tl/tl/PasswordDialog.ui index c038b7d635..a8d0724df8 100644 --- a/src/tl/tl/PasswordDialog.ui +++ b/src/tl/tl/PasswordDialog.ui @@ -1,155 +1,227 @@ - + + PasswordDialog - - + + 0 0 338 - 230 + 229 - + Authentication Required - - + + 9 - + + 9 + + + 9 + + + 9 + + 6 - - - - Password + + + + Qt::Vertical - + + + 20 + 0 + + + - - - - - 5 - 0 + + + + 0 0 - + QLineEdit::Password - - - - - 5 - 0 + + + + User + + + + + + + Password + + + + + + + 0 0 - - - + + + Qt::Horizontal - - QSizePolicy::Expanding - - - - 10 - 20 - + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok - + - - - - User + + + + - + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + false - + - + Qt::Vertical - - QSizePolicy::Expanding + + QSizePolicy::Fixed - + 20 - 0 + 16 - + - + Qt::Horizontal - + + QSizePolicy::Expanding + + - 40 + 10 20 - - - - Qt::Horizontal + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 190 + 190 + 190 + + + + + + + + + 75 + true + - - QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok + + # of attempt - - - - - - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + Qt::Horizontal - - false + + + 40 + 20 + - + - - - + + + - - + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - + false - - - + + + Qt::Vertical - + + QSizePolicy::Fixed + + 20 - 0 + 10 @@ -169,11 +241,11 @@ PasswordDialog accept() - + 248 254 - + 157 274 @@ -185,11 +257,11 @@ PasswordDialog reject() - + 316 260 - + 286 274 diff --git a/src/tl/tl/tlHttpStream.cc b/src/tl/tl/tlHttpStream.cc index e45223a562..87069b588e 100644 --- a/src/tl/tl/tlHttpStream.cc +++ b/src/tl/tl/tlHttpStream.cc @@ -54,13 +54,20 @@ class PasswordDialog setupUi (this); } - bool exec_auth (bool proxy, const QString &where, QAuthenticator *auth) + bool exec_auth (bool proxy, int attempt, const QString &where, QAuthenticator *auth) { - realm_label->setText (QString::fromUtf8 ("Realm: ") + auth->realm ()); + realm_label->setText (tr ("Realm: ") + auth->realm ()); if (proxy) { - where_label->setText (QString::fromUtf8 ("Proxy: ") + where); + where_label->setText (tr ("Proxy: ") + where); } else { - where_label->setText (QString::fromUtf8 ("URL: ") + where); + where_label->setText (tr ("URL: ") + where); + } + + if (attempt > 1) { + attempt_label->setText (tr ("Authentication failed - please try again")); + attempt_label->show (); + } else { + attempt_label->hide (); } if (QDialog::exec ()) { @@ -78,23 +85,30 @@ class PasswordDialog // AuthenticationHandler implementation AuthenticationHandler::AuthenticationHandler () - : QObject (0) + : QObject (0), m_retry (0), m_proxy_retry (0) { // .. nothing yet .. } +void +AuthenticationHandler::reset () +{ + m_retry = 0; + m_proxy_retry = 0; +} + void AuthenticationHandler::authenticationRequired (QNetworkReply *reply, QAuthenticator *auth) { PasswordDialog pw_dialog (0 /*no parent*/); - pw_dialog.exec_auth (false, reply->url ().toString (), auth); + pw_dialog.exec_auth (false, ++m_retry, reply->url ().toString (), auth); } void AuthenticationHandler::proxyAuthenticationRequired (const QNetworkProxy &proxy, QAuthenticator *auth) { PasswordDialog pw_dialog (0 /*no parent*/); - pw_dialog.exec_auth (true, proxy.hostName (), auth); + pw_dialog.exec_auth (true, ++m_proxy_retry, proxy.hostName (), auth); } // --------------------------------------------------------------- @@ -176,6 +190,9 @@ InputHttpStream::issue_request (const QUrl &url) delete mp_buffer; mp_buffer = 0; + // reset the retry counters -> this way we can detect authentication failures + s_auth_handler->reset (); + QNetworkRequest request (url); if (tl::verbosity() >= 30) { tl::info << "HTTP request URL: " << url.toString ().toUtf8 ().constData (); @@ -230,17 +247,42 @@ InputHttpStream::read (char *b, size_t n) } if (mp_reply->error () != QNetworkReply::NoError) { + // throw an error std::string em = tl::to_string (mp_reply->attribute (QNetworkRequest::HttpReasonPhraseAttribute).toString ()); if (tl::verbosity() >= 30) { tl::info << "HTTP response error: " << em; } + int ec = mp_reply->attribute (QNetworkRequest::HttpStatusCodeAttribute).toInt (); if (ec == 0) { + switch (mp_reply->error ()) { + case QNetworkReply::ConnectionRefusedError: + em = tl::to_string (QObject::tr ("Connection refused")); + break; + case QNetworkReply::RemoteHostClosedError: + em = tl::to_string (QObject::tr ("Remote host closed connection")); + break; + case QNetworkReply::HostNotFoundError: + em = tl::to_string (QObject::tr ("Host not found")); + break; + case QNetworkReply::TimeoutError: + em = tl::to_string (QObject::tr ("Timeout")); + break; + case QNetworkReply::ContentAccessDenied: + em = tl::to_string (QObject::tr ("Access denied")); + break; + case QNetworkReply::ContentNotFoundError: + em = tl::to_string (QObject::tr ("Content not found")); + break; + default: + em = tl::to_string (QObject::tr ("Network API error")); + } ec = int (mp_reply->error ()); - em = tl::to_string (QObject::tr ("Network API error")); } + throw HttpErrorException (em, ec, m_url); + } QByteArray data = mp_reply->read (n); diff --git a/src/tl/tl/tlHttpStream.h b/src/tl/tl/tlHttpStream.h index cb82a2007c..b5c6115d25 100644 --- a/src/tl/tl/tlHttpStream.h +++ b/src/tl/tl/tlHttpStream.h @@ -60,6 +60,10 @@ Q_OBJECT public slots: void authenticationRequired (QNetworkReply *, QAuthenticator *); void proxyAuthenticationRequired (const QNetworkProxy &, QAuthenticator *); + void reset (); + +private: + int m_retry, m_proxy_retry; }; /**