Work on network managers.

This commit is contained in:
Martin Rotter 2013-12-23 11:39:24 +01:00
parent f537746fa0
commit af56fbcf1a
11 changed files with 79 additions and 6 deletions

View File

@ -264,6 +264,7 @@ set(APP_SOURCES
src/core/basenetworkaccessmanager.cpp
src/core/webpage.cpp
src/core/webbrowsernetworkaccessmanager.cpp
src/core/silentnetworkaccessmanager.cpp
src/core/textfactory.cpp
src/core/databasefactory.cpp
src/core/messagesmodel.cpp
@ -318,6 +319,7 @@ set(APP_HEADERS
src/core/settings.h
src/core/basenetworkaccessmanager.h
src/core/webbrowsernetworkaccessmanager.h
src/core/silentnetworkaccessmanager.h
src/core/webpage.h
src/core/systemfactory.h
src/core/databasefactory.h

View File

@ -13,23 +13,22 @@ BaseNetworkAccessManager::BaseNetworkAccessManager(QObject *parent)
}
BaseNetworkAccessManager::~BaseNetworkAccessManager() {
qDebug("Destroying BaseNetworkAccessManager instance.");
}
void BaseNetworkAccessManager::loadSettings() {
qDebug("Settings of BaseNetworkAccessManager changed.");
QNetworkProxy new_proxy;
// Load proxy values from settings.
QNetworkProxy::ProxyType selected_proxy_type = static_cast<QNetworkProxy::ProxyType>(Settings::getInstance()->value(APP_CFG_PROXY,
"proxy_type",
QNetworkProxy::NoProxy).toInt());
if (selected_proxy_type == QNetworkProxy::NoProxy) {
// No extra setting is needed, set new proxy and exit this method.
setProxy(QNetworkProxy::NoProxy);
return;
}
Settings *settings = Settings::getInstance();
// Custom proxy is selected, set it up.

View File

@ -19,6 +19,7 @@ class BaseNetworkAccessManager : public QNetworkAccessManager {
virtual void loadSettings();
protected:
QNetworkReply *createRequest(Operation op,
const QNetworkRequest &request,
QIODevice *outgoingData);

View File

@ -1,11 +1,15 @@
#include "core/feeddownloader.h"
#include "core/feedsmodelfeed.h"
#include "core/silentnetworkaccessmanager.h"
#include <QThread>
#include <QDebug>
#include <QApplication>
QPointer<SilentNetworkAccessManager> FeedDownloader::m_networkManager;
FeedDownloader::FeedDownloader(QObject *parent) : QObject(parent) {
}
@ -13,7 +17,26 @@ FeedDownloader::~FeedDownloader() {
qDebug("Destroying FeedDownloader instance.");
}
SilentNetworkAccessManager *FeedDownloader::globalNetworkManager() {
if (m_networkManager.isNull()) {
m_networkManager = new SilentNetworkAccessManager(qApp);
}
return m_networkManager;
}
void FeedDownloader::updateFeeds(const QList<FeedsModelFeed *> &feeds) {
qDebug().nospace() << "Creating main application form in thread: \'" <<
QThread::currentThreadId() << "\'.";
for (int i = 0, total = feeds.size(); i < total; i++) {
feeds.at(i)->update();
emit progress(feeds.at(i), i + 1, total);
}
// Update of feeds has finished.
// NOTE: This means that now "update lock" can be unlocked
// and feeds can be added/edited/deleted and application
// can eventually quit.
emit finished();
}

View File

@ -2,9 +2,11 @@
#define FEEDDOWNLOADER_H
#include <QObject>
#include <QPointer>
class FeedsModelFeed;
class SilentNetworkAccessManager;
// This class offers means to "update" feeds
// and "special" categories.
@ -17,13 +19,21 @@ class FeedDownloader : public QObject {
explicit FeedDownloader(QObject *parent = 0);
virtual ~FeedDownloader();
// Returns pointer to global network access manager
// for feed online operations (primarily fetchich of new messages).
// NOTE: All feed online operations shar network access manager,
// which makes setting of custom network settings easy.
static SilentNetworkAccessManager *globalNetworkManager();
signals:
// Emitted if all items from update queue are
// processed.
void finished();
// Emitted if any item is processed.
// "Current" counts
// "Current" number indicates count of processed feeds
// and "total" number indicates total number of feeds
// which are in the initial queue.
void progress(FeedsModelFeed *feed, int current, int total);
public slots:
@ -32,6 +42,9 @@ class FeedDownloader : public QObject {
// are stored persistently in the database.
// Appropriate signals are emitted.
void updateFeeds(const QList<FeedsModelFeed*> &feeds);
private:
static QPointer<SilentNetworkAccessManager> m_networkManager;
};
#endif // FEEDDOWNLOADER_H

View File

@ -6,8 +6,12 @@
#include <QList>
// This class contains methods to
// parse input Unicode textual data into
// another objects.
class ParsingFactory {
private:
// Constructors and destructors.
explicit ParsingFactory();
public:

View File

@ -0,0 +1,10 @@
#include "core/silentnetworkaccessmanager.h"
SilentNetworkAccessManager::SilentNetworkAccessManager(QObject *parent)
: BaseNetworkAccessManager(parent) {
}
SilentNetworkAccessManager::~SilentNetworkAccessManager() {
qDebug("Destroying SilentNetworkAccessManages instance.");
}

View File

@ -0,0 +1,17 @@
#ifndef SILENTNETWORKACCESSMANAGES_H
#define SILENTNETWORKACCESSMANAGES_H
#include "core/basenetworkaccessmanager.h"
// Network manager used for more communication for feeds.
class SilentNetworkAccessManager : public BaseNetworkAccessManager {
Q_OBJECT
public:
// Constructors and destructors.
explicit SilentNetworkAccessManager(QObject *parent = 0);
virtual ~SilentNetworkAccessManager();
};
#endif // SILENTNETWORKACCESSMANAGES_H

View File

@ -8,6 +8,7 @@
class TextFactory {
private:
// Constructors and destructors.
explicit TextFactory();
public:
@ -15,7 +16,7 @@ class TextFactory {
// Returns invalid date/time if processing fails.
static QDateTime parseDateTime(const QString &date_time);
// Strips "<....>" tags from given text.
// Strips "<....>" (HTML, XML) tags from given text.
static QString stripTags(QString text);
// Shortens input string according to given length limit.

View File

@ -4,7 +4,7 @@
#include "core/basenetworkaccessmanager.h"
// This is custom network access manager for web browsers.
// This is network access manager for web browsers.
class WebBrowserNetworkAccessManager : public BaseNetworkAccessManager {
Q_OBJECT

View File

@ -4,8 +4,10 @@
#include "core/settings.h"
#include "core/localization.h"
#include "core/systemfactory.h"
#include "core/feeddownloader.h"
#include "core/dynamicshortcuts.h"
#include "core/webbrowsernetworkaccessmanager.h"
#include "core/silentnetworkaccessmanager.h"
#include "gui/iconthemefactory.h"
#include "gui/skinfactory.h"
#include "gui/systemtrayicon.h"
@ -363,6 +365,7 @@ void FormSettings::saveProxy() {
// Reload settings for all network access managers.
WebBrowser::globalNetworkManager()->loadSettings();
FeedDownloader::globalNetworkManager()->loadSettings();
}
void FormSettings::loadLanguage() {