diff --git a/src/core/feedsmodelstandardfeed.cpp b/src/core/feedsmodelstandardfeed.cpp index 790937ae5..86d143bdd 100755 --- a/src/core/feedsmodelstandardfeed.cpp +++ b/src/core/feedsmodelstandardfeed.cpp @@ -70,27 +70,21 @@ QPair FeedsModelStandardFe if ((result.second = NetworkFactory::downloadFeedFile(url, Settings::instance()->value(APP_CFG_FEEDS, "feed_update_timeout", DOWNLOAD_TIMEOUT).toInt(), feed_contents, - true, + !username.isEmpty(), username, password)) == QNetworkReply::NoError) { // Feed XML was obtained, now we need to try to guess // its encoding before we can read further data. - QXmlStreamReader xml_stream_reader(feed_contents); QString xml_schema_encoding; QString xml_contents_encoded; + QRegExp encoding_rexp("encoding=\"[^\"]\\S+\""); - // TODO: Use QRegExp and capture encoding attribute with it - // instead of heavy QXmlStreamReader. - - // We have several chances to read the XML version directly - // from XML declaration. - for (int i = 0; i < 2 && !xml_stream_reader.atEnd(); i++) { - if ((xml_schema_encoding = xml_stream_reader.documentEncoding().toString()).isEmpty()) { - xml_stream_reader.readNext(); - } - else { - break; - } + if (encoding_rexp.indexIn(feed_contents) != -1 && + !(xml_schema_encoding = encoding_rexp.cap(0)).isEmpty()) { + // Some "encoding" attribute was found. + encoding_rexp.setPattern("[^\"]\\S+[^\"]"); + encoding_rexp.indexIn(xml_schema_encoding, 9); + xml_schema_encoding = encoding_rexp.cap(0); } if (result.first == NULL) { @@ -175,8 +169,8 @@ QVariant FeedsModelStandardFeed::data(int column, int role) const { } else if (column == FDS_MODEL_COUNTS_INDEX) { // TODO: Changeable text. - return QString("%1").arg(QString::number(countOfUnreadMessages()), - QString::number(countOfAllMessages())); + return QString("%1").arg(QString::number(countOfUnreadMessages())); + //QString::number(countOfAllMessages())); } else { return QVariant(); diff --git a/src/core/networkfactory.cpp b/src/core/networkfactory.cpp index c23e3ce5f..bc2ac3ce2 100644 --- a/src/core/networkfactory.cpp +++ b/src/core/networkfactory.cpp @@ -13,6 +13,7 @@ NetworkFactory::NetworkFactory() { QString NetworkFactory::networkErrorText(QNetworkReply::NetworkError error_code) { switch (error_code) { + case QNetworkReply::ProtocolUnknownError: case QNetworkReply::ProtocolFailure: return QObject::tr("protocol error"); @@ -37,6 +38,9 @@ QString NetworkFactory::networkErrorText(QNetworkReply::NetworkError error_code) case QNetworkReply::TemporaryNetworkFailureError: return QObject::tr("temporary failure"); + case QNetworkReply::AuthenticationRequiredError: + return QObject::tr("authentication failed"); + case QNetworkReply::ProxyAuthenticationRequiredError: return QObject::tr("proxy authentication required"); @@ -49,6 +53,9 @@ QString NetworkFactory::networkErrorText(QNetworkReply::NetworkError error_code) case QNetworkReply::UnknownContentError: return QObject::tr("uknown content"); + case QNetworkReply::ContentNotFoundError: + return QObject::tr("content not found"); + default: return QObject::tr("unknown error"); } diff --git a/src/core/webbrowsernetworkaccessmanager.cpp b/src/core/webbrowsernetworkaccessmanager.cpp index b340111d6..f16d496cd 100644 --- a/src/core/webbrowsernetworkaccessmanager.cpp +++ b/src/core/webbrowsernetworkaccessmanager.cpp @@ -7,6 +7,8 @@ WebBrowserNetworkAccessManager::WebBrowserNetworkAccessManager(QObject *parent) : BaseNetworkAccessManager(parent) { connect(this, SIGNAL(sslErrors(QNetworkReply*,QList)), this, SLOT(onSslErrors(QNetworkReply*,QList))); + connect(this, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), + this, SLOT(onAuthenticationRequired(QNetworkReply*,QAuthenticator*))); } WebBrowserNetworkAccessManager::~WebBrowserNetworkAccessManager() { @@ -22,3 +24,12 @@ void WebBrowserNetworkAccessManager::onSslErrors(QNetworkReply *reply, 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())); +} diff --git a/src/core/webbrowsernetworkaccessmanager.h b/src/core/webbrowsernetworkaccessmanager.h index 7e2df08bc..38dd60c62 100644 --- a/src/core/webbrowsernetworkaccessmanager.h +++ b/src/core/webbrowsernetworkaccessmanager.h @@ -15,6 +15,7 @@ class WebBrowserNetworkAccessManager : public BaseNetworkAccessManager { protected slots: void onSslErrors(QNetworkReply *reply, const QList &error); + void onAuthenticationRequired(QNetworkReply * reply, QAuthenticator *authenticator); }; #endif // WEBBROWSERNETWORKACCESSMANAGER_H