Some network related work.

This commit is contained in:
Martin Rotter 2014-01-30 20:39:28 +01:00
parent 78ca7325d6
commit 82136d72b9
4 changed files with 34 additions and 12 deletions

View File

@ -106,9 +106,10 @@ void FeedsModelStandardFeed::update() {
// TODO: Provide download time-measures debugging
// outputs here.
QNetworkReply::NetworkError download_result = NetworkFactory::downloadFile(url(),
QNetworkReply::NetworkError download_result = NetworkFactory::downloadFeedFile(url(),
download_timeout,
feed_contents);
feed_contents,
this);
if (download_result != QNetworkReply::NoError) {
qWarning("Error during fetching of new messages for feed '%s' (id %d).",

View File

@ -9,9 +9,10 @@
NetworkFactory::NetworkFactory() {
}
QNetworkReply::NetworkError NetworkFactory::downloadFile(const QString &url,
QNetworkReply::NetworkError NetworkFactory::downloadFeedFile(const QString &url,
int timeout,
QByteArray &output) {
QByteArray &output,
FeedsModelStandardFeed *feed) {
// Original asynchronous behavior of QNetworkAccessManager
// is replaced by synchronous behavior in order to make
// process of downloading of a file easier to understand.
@ -22,6 +23,11 @@ QNetworkReply::NetworkError NetworkFactory::downloadFile(const QString &url,
QTimer timer;
QNetworkRequest request;
QNetworkReply *reply;
QObject originatingObject;
// Set feed as originating object.
originatingObject.setProperty("feed", QVariant::fromValue((void*) feed));
request.setOriginatingObject(&originatingObject);
// Set url for this reques.
request.setUrl(url);

View File

@ -4,6 +4,8 @@
#include <QNetworkReply>
class FeedsModelStandardFeed;
class NetworkFactory {
private:
// Constructor.
@ -12,9 +14,10 @@ class NetworkFactory {
public:
// Performs SYNCHRONOUS download of file with given URL
// and given timeout.
static QNetworkReply::NetworkError downloadFile(const QString &url,
static QNetworkReply::NetworkError downloadFeedFile(const QString &url,
int timeout,
QByteArray &output);
QByteArray &output,
FeedsModelStandardFeed *feed);
};
#endif // NETWORKFACTORY_H

View File

@ -1,6 +1,9 @@
#include "core/silentnetworkaccessmanager.h"
#include "core/feedsmodelstandardfeed.h"
#include <QNetworkReply>
#include <QAuthenticator>
SilentNetworkAccessManager::SilentNetworkAccessManager(QObject *parent)
@ -27,8 +30,17 @@ void SilentNetworkAccessManager::onSslErrors(QNetworkReply *reply,
void SilentNetworkAccessManager::onAuthenticationRequired(QNetworkReply *reply,
QAuthenticator *authenticator) {
Q_UNUSED(authenticator)
FeedsModelStandardFeed *feed = static_cast<FeedsModelStandardFeed*>(reply->request().originatingObject()->property("feed").value<void*>());
qDebug("Autorization problems for '%s'.",
// TODO: tady do autenticatoru dosadit udaje z feedu
// pokud je obsahuje
// a taky promyslet zda to delat takhle vubec, ale funguje
// to
/*
*authenticator->setUser("rotter.martinos");
*authenticator->setPassword("gorottin0151");
*/
qDebug("Authentication problems for '%s'.",
qPrintable(reply->url().toString()));
}