Encoding recognition upgraded. Added even more network error texts.
This commit is contained in:
parent
04f109654a
commit
4fd368c23a
@ -70,27 +70,21 @@ QPair<FeedsModelStandardFeed*, QNetworkReply::NetworkError> FeedsModelStandardFe
|
|||||||
if ((result.second = NetworkFactory::downloadFeedFile(url,
|
if ((result.second = NetworkFactory::downloadFeedFile(url,
|
||||||
Settings::instance()->value(APP_CFG_FEEDS, "feed_update_timeout", DOWNLOAD_TIMEOUT).toInt(),
|
Settings::instance()->value(APP_CFG_FEEDS, "feed_update_timeout", DOWNLOAD_TIMEOUT).toInt(),
|
||||||
feed_contents,
|
feed_contents,
|
||||||
true,
|
!username.isEmpty(),
|
||||||
username,
|
username,
|
||||||
password)) == QNetworkReply::NoError) {
|
password)) == QNetworkReply::NoError) {
|
||||||
// Feed XML was obtained, now we need to try to guess
|
// Feed XML was obtained, now we need to try to guess
|
||||||
// its encoding before we can read further data.
|
// its encoding before we can read further data.
|
||||||
QXmlStreamReader xml_stream_reader(feed_contents);
|
|
||||||
QString xml_schema_encoding;
|
QString xml_schema_encoding;
|
||||||
QString xml_contents_encoded;
|
QString xml_contents_encoded;
|
||||||
|
QRegExp encoding_rexp("encoding=\"[^\"]\\S+\"");
|
||||||
|
|
||||||
// TODO: Use QRegExp and capture encoding attribute with it
|
if (encoding_rexp.indexIn(feed_contents) != -1 &&
|
||||||
// instead of heavy QXmlStreamReader.
|
!(xml_schema_encoding = encoding_rexp.cap(0)).isEmpty()) {
|
||||||
|
// Some "encoding" attribute was found.
|
||||||
// We have several chances to read the XML version directly
|
encoding_rexp.setPattern("[^\"]\\S+[^\"]");
|
||||||
// from XML declaration.
|
encoding_rexp.indexIn(xml_schema_encoding, 9);
|
||||||
for (int i = 0; i < 2 && !xml_stream_reader.atEnd(); i++) {
|
xml_schema_encoding = encoding_rexp.cap(0);
|
||||||
if ((xml_schema_encoding = xml_stream_reader.documentEncoding().toString()).isEmpty()) {
|
|
||||||
xml_stream_reader.readNext();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.first == NULL) {
|
if (result.first == NULL) {
|
||||||
@ -175,8 +169,8 @@ QVariant FeedsModelStandardFeed::data(int column, int role) const {
|
|||||||
}
|
}
|
||||||
else if (column == FDS_MODEL_COUNTS_INDEX) {
|
else if (column == FDS_MODEL_COUNTS_INDEX) {
|
||||||
// TODO: Changeable text.
|
// TODO: Changeable text.
|
||||||
return QString("%1").arg(QString::number(countOfUnreadMessages()),
|
return QString("%1").arg(QString::number(countOfUnreadMessages()));
|
||||||
QString::number(countOfAllMessages()));
|
//QString::number(countOfAllMessages()));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
@ -13,6 +13,7 @@ NetworkFactory::NetworkFactory() {
|
|||||||
|
|
||||||
QString NetworkFactory::networkErrorText(QNetworkReply::NetworkError error_code) {
|
QString NetworkFactory::networkErrorText(QNetworkReply::NetworkError error_code) {
|
||||||
switch (error_code) {
|
switch (error_code) {
|
||||||
|
case QNetworkReply::ProtocolUnknownError:
|
||||||
case QNetworkReply::ProtocolFailure:
|
case QNetworkReply::ProtocolFailure:
|
||||||
return QObject::tr("protocol error");
|
return QObject::tr("protocol error");
|
||||||
|
|
||||||
@ -37,6 +38,9 @@ QString NetworkFactory::networkErrorText(QNetworkReply::NetworkError error_code)
|
|||||||
case QNetworkReply::TemporaryNetworkFailureError:
|
case QNetworkReply::TemporaryNetworkFailureError:
|
||||||
return QObject::tr("temporary failure");
|
return QObject::tr("temporary failure");
|
||||||
|
|
||||||
|
case QNetworkReply::AuthenticationRequiredError:
|
||||||
|
return QObject::tr("authentication failed");
|
||||||
|
|
||||||
case QNetworkReply::ProxyAuthenticationRequiredError:
|
case QNetworkReply::ProxyAuthenticationRequiredError:
|
||||||
return QObject::tr("proxy authentication required");
|
return QObject::tr("proxy authentication required");
|
||||||
|
|
||||||
@ -49,6 +53,9 @@ QString NetworkFactory::networkErrorText(QNetworkReply::NetworkError error_code)
|
|||||||
case QNetworkReply::UnknownContentError:
|
case QNetworkReply::UnknownContentError:
|
||||||
return QObject::tr("uknown content");
|
return QObject::tr("uknown content");
|
||||||
|
|
||||||
|
case QNetworkReply::ContentNotFoundError:
|
||||||
|
return QObject::tr("content not found");
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return QObject::tr("unknown error");
|
return QObject::tr("unknown error");
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,8 @@ WebBrowserNetworkAccessManager::WebBrowserNetworkAccessManager(QObject *parent)
|
|||||||
: BaseNetworkAccessManager(parent) {
|
: BaseNetworkAccessManager(parent) {
|
||||||
connect(this, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)),
|
connect(this, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)),
|
||||||
this, SLOT(onSslErrors(QNetworkReply*,QList<QSslError>)));
|
this, SLOT(onSslErrors(QNetworkReply*,QList<QSslError>)));
|
||||||
|
connect(this, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),
|
||||||
|
this, SLOT(onAuthenticationRequired(QNetworkReply*,QAuthenticator*)));
|
||||||
}
|
}
|
||||||
|
|
||||||
WebBrowserNetworkAccessManager::~WebBrowserNetworkAccessManager() {
|
WebBrowserNetworkAccessManager::~WebBrowserNetworkAccessManager() {
|
||||||
@ -22,3 +24,12 @@ void WebBrowserNetworkAccessManager::onSslErrors(QNetworkReply *reply,
|
|||||||
|
|
||||||
reply->ignoreSslErrors(error);
|
reply->ignoreSslErrors(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebBrowserNetworkAccessManager::onAuthenticationRequired(QNetworkReply *reply,
|
||||||
|
QAuthenticator *authenticator) {
|
||||||
|
Q_UNUSED(authenticator);
|
||||||
|
|
||||||
|
// Authentication is required but this feed does not contain it.
|
||||||
|
qDebug("URL '%s' requested authentication but username/password is not available.",
|
||||||
|
qPrintable(reply->url().toString()));
|
||||||
|
}
|
||||||
|
@ -15,6 +15,7 @@ class WebBrowserNetworkAccessManager : public BaseNetworkAccessManager {
|
|||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void onSslErrors(QNetworkReply *reply, const QList<QSslError> &error);
|
void onSslErrors(QNetworkReply *reply, const QList<QSslError> &error);
|
||||||
|
void onAuthenticationRequired(QNetworkReply * reply, QAuthenticator *authenticator);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WEBBROWSERNETWORKACCESSMANAGER_H
|
#endif // WEBBROWSERNETWORKACCESSMANAGER_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user