Some network related work.
This commit is contained in:
parent
78ca7325d6
commit
82136d72b9
@ -106,9 +106,10 @@ void FeedsModelStandardFeed::update() {
|
||||
|
||||
// TODO: Provide download time-measures debugging
|
||||
// outputs here.
|
||||
QNetworkReply::NetworkError download_result = NetworkFactory::downloadFile(url(),
|
||||
download_timeout,
|
||||
feed_contents);
|
||||
QNetworkReply::NetworkError download_result = NetworkFactory::downloadFeedFile(url(),
|
||||
download_timeout,
|
||||
feed_contents,
|
||||
this);
|
||||
|
||||
if (download_result != QNetworkReply::NoError) {
|
||||
qWarning("Error during fetching of new messages for feed '%s' (id %d).",
|
||||
|
@ -9,9 +9,10 @@
|
||||
NetworkFactory::NetworkFactory() {
|
||||
}
|
||||
|
||||
QNetworkReply::NetworkError NetworkFactory::downloadFile(const QString &url,
|
||||
int timeout,
|
||||
QByteArray &output) {
|
||||
QNetworkReply::NetworkError NetworkFactory::downloadFeedFile(const QString &url,
|
||||
int timeout,
|
||||
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);
|
||||
|
@ -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,
|
||||
int timeout,
|
||||
QByteArray &output);
|
||||
static QNetworkReply::NetworkError downloadFeedFile(const QString &url,
|
||||
int timeout,
|
||||
QByteArray &output,
|
||||
FeedsModelStandardFeed *feed);
|
||||
};
|
||||
|
||||
#endif // NETWORKFACTORY_H
|
||||
|
@ -1,6 +1,9 @@
|
||||
#include "core/silentnetworkaccessmanager.h"
|
||||
|
||||
#include "core/feedsmodelstandardfeed.h"
|
||||
|
||||
#include <QNetworkReply>
|
||||
#include <QAuthenticator>
|
||||
|
||||
|
||||
SilentNetworkAccessManager::SilentNetworkAccessManager(QObject *parent)
|
||||
@ -16,7 +19,7 @@ SilentNetworkAccessManager::~SilentNetworkAccessManager() {
|
||||
}
|
||||
|
||||
void SilentNetworkAccessManager::onSslErrors(QNetworkReply *reply,
|
||||
const QList<QSslError> &error) {
|
||||
const QList<QSslError> &error) {
|
||||
qDebug("SSL errors for '%s': '%s' (code %d).",
|
||||
qPrintable(reply->url().toString()),
|
||||
qPrintable(reply->errorString()),
|
||||
@ -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()));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user