summaryrefslogtreecommitdiffstats
path: root/src/libs/installer/downloadfiletask.cpp
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@theqtcompany.com>2014-11-18 15:49:27 +0100
committerKai Koehne <kai.koehne@theqtcompany.com>2014-11-18 16:21:36 +0100
commit1f411319e4bb849487a85e8ea051b94417372ff4 (patch)
tree2441e1e371beffba129d7a8e8303eeabf3ff911a /src/libs/installer/downloadfiletask.cpp
parent6df883de4ae674a9b351f04e74c80bfa89d5faa6 (diff)
Ask for proxy credentials in modal dialog
If a proxy requires authentication, DownloadFileTask will throw an exception of type ProxyAuthenticationRequiredException. This exception is handled in MetadataJob to first ask the user for credentials, storing them in PackageManagerProxyFactory, and then retriggering the download. Change-Id: I0d69504d3f90d503d83c7b2229bc670756fa1463 GPush-Base: 9aeb0197e58d630ef7e657bb05671d6ec7b3f5ec Reviewed-by: Karsten Heimrich <karsten.heimrich@theqtcompany.com>
Diffstat (limited to 'src/libs/installer/downloadfiletask.cpp')
-rw-r--r--src/libs/installer/downloadfiletask.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/libs/installer/downloadfiletask.cpp b/src/libs/installer/downloadfiletask.cpp
index bbb3cc4e3..0bd38615e 100644
--- a/src/libs/installer/downloadfiletask.cpp
+++ b/src/libs/installer/downloadfiletask.cpp
@@ -36,6 +36,7 @@
#include "downloadfiletask_p.h"
#include "observer.h"
+#include <QCoreApplication>
#include <QEventLoop>
#include <QFile>
#include <QFileInfo>
@@ -46,6 +47,13 @@
namespace QInstaller {
+ProxyAuthenticationRequiredException::ProxyAuthenticationRequiredException(const QNetworkProxy &proxy)
+ : FileTaskException(QCoreApplication::translate("ProxyAuthenticationRequiredException",
+ "Proxy requires authentication.")),
+ m_proxy(proxy)
+{
+}
+
Downloader::Downloader()
: m_finished(0)
{
@@ -80,6 +88,8 @@ void Downloader::download(QFutureInterface<FileTaskResult> &fi, const QList<File
m_nam.setProxyFactory(networkProxyFactory);
connect(&m_nam, SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)), this,
SLOT(onAuthenticationRequired(QNetworkReply*, QAuthenticator*)));
+ connect(&m_nam, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), this,
+ SLOT(onProxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)));
QTimer::singleShot(0, this, SLOT(doDownload()));
}
@@ -224,6 +234,12 @@ void Downloader::onFinished(QNetworkReply *reply)
void Downloader::onError(QNetworkReply::NetworkError error)
{
QNetworkReply *const reply = qobject_cast<QNetworkReply *>(sender());
+
+ if (error == QNetworkReply::ProxyAuthenticationRequiredError) {
+ // already handled by onProxyAuthenticationRequired
+ return;
+ }
+
if (reply) {
const Data &data = m_downloads[reply];
//: %2 is a sentence describing the error
@@ -275,6 +291,13 @@ void Downloader::onAuthenticationRequired(QNetworkReply *reply, QAuthenticator *
}
}
+void Downloader::onProxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *)
+{
+ // Report to GUI thread.
+ // (MetadataJob will ask for username/password, and restart the download ...)
+ m_futureInterface->reportException(ProxyAuthenticationRequiredException(proxy));
+}
+
// -- private