32 #include "network-web/networkfactory.h"
34 #include "definitions/definitions.h"
35 #include "miscellaneous/settings.h"
36 #include "network-web/silentnetworkaccessmanager.h"
42 #include <QTextDocument>
45 NetworkFactory::NetworkFactory() {
50 case QNetworkReply::ProtocolUnknownError:
51 case QNetworkReply::ProtocolFailure:
53 return tr(
"protocol error");
55 case QNetworkReply::HostNotFoundError:
57 return tr(
"host not found");
59 case QNetworkReply::RemoteHostClosedError:
60 case QNetworkReply::ConnectionRefusedError:
62 return tr(
"connection refused");
64 case QNetworkReply::TimeoutError:
65 case QNetworkReply::ProxyTimeoutError:
67 return tr(
"connection timed out");
69 case QNetworkReply::SslHandshakeFailedError:
71 return tr(
"SSL handshake failed");
73 case QNetworkReply::ProxyConnectionClosedError:
74 case QNetworkReply::ProxyConnectionRefusedError:
76 return tr(
"proxy server connection refused");
78 case QNetworkReply::TemporaryNetworkFailureError:
80 return tr(
"temporary failure");
82 case QNetworkReply::AuthenticationRequiredError:
84 return tr(
"authentication failed");
86 case QNetworkReply::ProxyAuthenticationRequiredError:
88 return tr(
"proxy authentication required");
90 case QNetworkReply::ProxyNotFoundError:
92 return tr(
"proxy server not found");
94 case QNetworkReply::NoError:
98 case QNetworkReply::UnknownContentError:
100 return tr(
"uknown content");
102 case QNetworkReply::ContentNotFoundError:
104 return tr(
"content not found");
108 return tr(
"unknown error");
115 bool protected_contents,
116 const QString &username,
117 const QString &password) {
126 QNetworkRequest request;
127 QNetworkReply *reply;
128 QObject originatingObject;
131 originatingObject.setProperty(
"protected", protected_contents);
132 originatingObject.setProperty(
"username", username);
133 originatingObject.setProperty(
"password", password);
134 request.setOriginatingObject(&originatingObject);
141 QObject::connect(qApp, SIGNAL(aboutToQuit()), &loop, SLOT(quit()));
142 QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
143 QObject::connect(&manager, SIGNAL(finished(QNetworkReply*)), &loop, SLOT(quit()));
147 timer.setSingleShot(
true);
150 reply = manager.get(request);
153 timer.start(timeout);
162 if (timer.isActive()) {
173 return QNetworkReply::TimeoutError;
177 QUrl redirection_url = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
179 if (redirection_url.isValid()) {
182 request.setUrl(redirection_url);
195 output = reply->readAll();
197 QNetworkReply::NetworkError reply_error = reply->error();
199 qDebug(
"File '%s' fetched with status '%s' (code %d).",
Network access manager with supressed authentication dialogs.
static QString networkErrorText(QNetworkReply::NetworkError error_code)
Gets human readable text for given network error.
static QNetworkReply::NetworkError downloadFile(const QString &url, int timeout, QByteArray &output, bool protected_contents=false, const QString &username=QString(), const QString &password=QString())
Performs SYNCHRONOUS download of file with given URL and given timeout.