done fist implementation of ErrorLog, refs #48; added AdjustToMinimumContentsLength, closes #52

This commit is contained in:
Marc Wäckerlin
2011-05-26 06:31:19 +00:00
parent 7e6cdea4f2
commit 4670288d51
10 changed files with 548 additions and 336 deletions

View File

@@ -46,8 +46,7 @@ class DownloadManager: public QObject {
" close() before it was finished.");
case QNetworkReply::SslHandshakeFailedError:
return tr("The SSL/TLS handshake failed and the encrypted channel"
" could not be established. The sslErrors() signal should"
" have been emitted.");
" could not be established. See SSL-Errors above.");
case QNetworkReply::ProxyConnectionRefusedError:
return tr("The connection to the proxy server was refused (the"
" proxy server is not accepting requests).");
@@ -103,12 +102,13 @@ class DownloadManager: public QObject {
void progress(qint64 done, qint64 total);
void started();
void finished();
void error(QString);
public Q_SLOTS:
void add(QNetworkReply* reply) {
LOG<<reply->url().toString();
_downloads[reply] = Progress(0, 0);
_downloads[reply].progress = Progress(0, 0);
assert(connect(reply, SIGNAL(downloadProgress(qint64, qint64)),
SLOT(downloadProgress(qint64, qint64))));
assert(connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
@@ -136,8 +136,8 @@ class DownloadManager: public QObject {
qint64 total(0);
for (Downloads::iterator it(_downloads.begin());
it!=_downloads.end(); ++it) {
done += it->second.first;
total += it->second.second;
done += it->second.progress.first;
total += it->second.progress.second;
}
progress(done, total);
}
@@ -146,16 +146,30 @@ class DownloadManager: public QObject {
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal) {
//LOG<<bytesReceived<<bytesTotal;
_downloads[qobject_cast<QNetworkReply*>(sender())].first = bytesReceived;
_downloads[qobject_cast<QNetworkReply*>(sender())].second = bytesTotal;
_downloads[qobject_cast<QNetworkReply*>(sender())].progress.first
= bytesReceived;
_downloads[qobject_cast<QNetworkReply*>(sender())].progress.second
= bytesTotal;
calcProgress();
}
void error(QNetworkReply::NetworkError code) {
LOG<<"Status:"<<networkError(code);
QNetworkReply* reply(qobject_cast<QNetworkReply*>(sender()));
_downloads[reply].error +=
tr("<h1>Network Error</h1>"
"<dl><dt>URL:</dt><dd>%1</dd>"
"<dt>Error Code:</dt><dd>%3</dd>"
"<dt>Error Details:</dt><dd>%2</dd></dl>")
.arg(reply->url().toString())
.arg(networkError(code))
.arg(code);
}
void slotFinished() {
LOG;
_downloads.erase(qobject_cast<QNetworkReply*>(sender()));
QNetworkReply* reply(qobject_cast<QNetworkReply*>(sender()));
if (_downloads[reply].error.size())
error(_downloads[reply].error);
_downloads.erase(reply);
if (_downloads.size()==0) finished();
}
void metaDataChanged() {
@@ -163,7 +177,7 @@ class DownloadManager: public QObject {
}
void sslErrors(const QList<QSslError> & errors) {
LOG;
qobject_cast<QNetworkReply*>(sender())->ignoreSslErrors(errors);
QNetworkReply* reply(qobject_cast<QNetworkReply*>(sender()));
for (QList<QSslError>::const_iterator err(errors.begin());
err!=errors.end(); ++err) {
LOG<<"SSL-Error: "<<(int)err->error()<<": "<<err->errorString();
@@ -182,20 +196,64 @@ class DownloadManager: public QObject {
<<"C="<<err->certificate().subjectInfo(QSslCertificate::CountryName)
<<"ST="<<err->certificate().subjectInfo(QSslCertificate::StateOrProvinceName);
LOG<<"Certificate:\n"<<err->certificate().toPem();
_downloads[reply].error +=
tr("<h1>SSL Error</h1>"
"<dl><dt>URL:</dt><dd>%1</dd>"
"<dt>Error Code:</dt><dd>%3</dd>"
"<dt>Error Details:</dt><dd>%2</dd></dl>"
"<table>"
"<caption>Certificate Issuer</caption>"
"<tr><th>Organization:</th><td>%4</td></tr>"
"<tr><th>Common Name:</th><td>%5</td></tr>"
"<tr><th>Location:</th><td>%6</td></tr>"
"<tr><th>Organizational Unit:</th><td>%7</td></tr>"
"<tr><th>Country:</th><td>%8</td></tr>"
"<tr><th>State or Provive:</th><td>%9</td></tr>"
"</table>"
"<table>"
"<caption>Certificate Subject</caption>"
"<tr><th>Organization:</th><td>%10</td></tr>"
"<tr><th>Common Name:</th><td>%11</td></tr>"
"<tr><th>Location:</th><td>%12</td></tr>"
"<tr><th>Organizational Unit:</th><td>%13</td></tr>"
"<tr><th>Country:</th><td>%14</td></tr>"
"<tr><th>State or Provive:</th><td>%15</td></tr>"
"</table>")
.arg(reply->url().toString())
.arg(err->errorString())
.arg(err->error())
.arg(err->certificate().issuerInfo(QSslCertificate::Organization))
.arg(err->certificate().issuerInfo(QSslCertificate::CommonName))
.arg(err->certificate().issuerInfo(QSslCertificate::LocalityName))
.arg(err->certificate().issuerInfo(QSslCertificate::OrganizationalUnitName))
.arg(err->certificate().issuerInfo(QSslCertificate::CountryName))
.arg(err->certificate().issuerInfo(QSslCertificate::StateOrProvinceName))
.arg(err->certificate().subjectInfo(QSslCertificate::Organization))
.arg(err->certificate().subjectInfo(QSslCertificate::CommonName))
.arg(err->certificate().subjectInfo(QSslCertificate::LocalityName))
.arg(err->certificate().subjectInfo(QSslCertificate::OrganizationalUnitName))
.arg(err->certificate().subjectInfo(QSslCertificate::CountryName))
.arg(err->certificate().subjectInfo(QSslCertificate::StateOrProvinceName));
}
}
void uploadProgress(qint64 bytesSent, qint64 bytesTotal) {
//LOG<<bytesSent<<bytesTotal;
_downloads[qobject_cast<QNetworkReply*>(sender())].first = bytesSent;
_downloads[qobject_cast<QNetworkReply*>(sender())].second = bytesTotal;
_downloads[qobject_cast<QNetworkReply*>(sender())].progress.first
= bytesSent;
_downloads[qobject_cast<QNetworkReply*>(sender())].progress.second
= bytesTotal;
calcProgress();
}
private:
typedef std::pair<qint64, qint64> Progress;
typedef std::map<QNetworkReply*, Progress> Downloads;
struct Download {
Progress progress;
QString error;
};
typedef std::map<QNetworkReply*, Download> Downloads;
Downloads _downloads;
};