Work on network managers.
This commit is contained in:
parent
f537746fa0
commit
af56fbcf1a
@ -264,6 +264,7 @@ set(APP_SOURCES
|
|||||||
src/core/basenetworkaccessmanager.cpp
|
src/core/basenetworkaccessmanager.cpp
|
||||||
src/core/webpage.cpp
|
src/core/webpage.cpp
|
||||||
src/core/webbrowsernetworkaccessmanager.cpp
|
src/core/webbrowsernetworkaccessmanager.cpp
|
||||||
|
src/core/silentnetworkaccessmanager.cpp
|
||||||
src/core/textfactory.cpp
|
src/core/textfactory.cpp
|
||||||
src/core/databasefactory.cpp
|
src/core/databasefactory.cpp
|
||||||
src/core/messagesmodel.cpp
|
src/core/messagesmodel.cpp
|
||||||
@ -318,6 +319,7 @@ set(APP_HEADERS
|
|||||||
src/core/settings.h
|
src/core/settings.h
|
||||||
src/core/basenetworkaccessmanager.h
|
src/core/basenetworkaccessmanager.h
|
||||||
src/core/webbrowsernetworkaccessmanager.h
|
src/core/webbrowsernetworkaccessmanager.h
|
||||||
|
src/core/silentnetworkaccessmanager.h
|
||||||
src/core/webpage.h
|
src/core/webpage.h
|
||||||
src/core/systemfactory.h
|
src/core/systemfactory.h
|
||||||
src/core/databasefactory.h
|
src/core/databasefactory.h
|
||||||
|
@ -13,23 +13,22 @@ BaseNetworkAccessManager::BaseNetworkAccessManager(QObject *parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
BaseNetworkAccessManager::~BaseNetworkAccessManager() {
|
BaseNetworkAccessManager::~BaseNetworkAccessManager() {
|
||||||
qDebug("Destroying BaseNetworkAccessManager instance.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseNetworkAccessManager::loadSettings() {
|
void BaseNetworkAccessManager::loadSettings() {
|
||||||
qDebug("Settings of BaseNetworkAccessManager changed.");
|
qDebug("Settings of BaseNetworkAccessManager changed.");
|
||||||
|
|
||||||
QNetworkProxy new_proxy;
|
QNetworkProxy new_proxy;
|
||||||
|
|
||||||
// Load proxy values from settings.
|
|
||||||
QNetworkProxy::ProxyType selected_proxy_type = static_cast<QNetworkProxy::ProxyType>(Settings::getInstance()->value(APP_CFG_PROXY,
|
QNetworkProxy::ProxyType selected_proxy_type = static_cast<QNetworkProxy::ProxyType>(Settings::getInstance()->value(APP_CFG_PROXY,
|
||||||
"proxy_type",
|
"proxy_type",
|
||||||
QNetworkProxy::NoProxy).toInt());
|
QNetworkProxy::NoProxy).toInt());
|
||||||
|
|
||||||
if (selected_proxy_type == QNetworkProxy::NoProxy) {
|
if (selected_proxy_type == QNetworkProxy::NoProxy) {
|
||||||
// No extra setting is needed, set new proxy and exit this method.
|
// No extra setting is needed, set new proxy and exit this method.
|
||||||
setProxy(QNetworkProxy::NoProxy);
|
setProxy(QNetworkProxy::NoProxy);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings *settings = Settings::getInstance();
|
Settings *settings = Settings::getInstance();
|
||||||
|
|
||||||
// Custom proxy is selected, set it up.
|
// Custom proxy is selected, set it up.
|
||||||
|
@ -19,6 +19,7 @@ class BaseNetworkAccessManager : public QNetworkAccessManager {
|
|||||||
virtual void loadSettings();
|
virtual void loadSettings();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
QNetworkReply *createRequest(Operation op,
|
QNetworkReply *createRequest(Operation op,
|
||||||
const QNetworkRequest &request,
|
const QNetworkRequest &request,
|
||||||
QIODevice *outgoingData);
|
QIODevice *outgoingData);
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
#include "core/feeddownloader.h"
|
#include "core/feeddownloader.h"
|
||||||
|
|
||||||
#include "core/feedsmodelfeed.h"
|
#include "core/feedsmodelfeed.h"
|
||||||
|
#include "core/silentnetworkaccessmanager.h"
|
||||||
|
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
|
|
||||||
|
QPointer<SilentNetworkAccessManager> FeedDownloader::m_networkManager;
|
||||||
|
|
||||||
FeedDownloader::FeedDownloader(QObject *parent) : QObject(parent) {
|
FeedDownloader::FeedDownloader(QObject *parent) : QObject(parent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -13,7 +17,26 @@ FeedDownloader::~FeedDownloader() {
|
|||||||
qDebug("Destroying FeedDownloader instance.");
|
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) {
|
void FeedDownloader::updateFeeds(const QList<FeedsModelFeed *> &feeds) {
|
||||||
qDebug().nospace() << "Creating main application form in thread: \'" <<
|
qDebug().nospace() << "Creating main application form in thread: \'" <<
|
||||||
QThread::currentThreadId() << "\'.";
|
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();
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,11 @@
|
|||||||
#define FEEDDOWNLOADER_H
|
#define FEEDDOWNLOADER_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QPointer>
|
||||||
|
|
||||||
|
|
||||||
class FeedsModelFeed;
|
class FeedsModelFeed;
|
||||||
|
class SilentNetworkAccessManager;
|
||||||
|
|
||||||
// This class offers means to "update" feeds
|
// This class offers means to "update" feeds
|
||||||
// and "special" categories.
|
// and "special" categories.
|
||||||
@ -17,13 +19,21 @@ class FeedDownloader : public QObject {
|
|||||||
explicit FeedDownloader(QObject *parent = 0);
|
explicit FeedDownloader(QObject *parent = 0);
|
||||||
virtual ~FeedDownloader();
|
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:
|
signals:
|
||||||
// Emitted if all items from update queue are
|
// Emitted if all items from update queue are
|
||||||
// processed.
|
// processed.
|
||||||
void finished();
|
void finished();
|
||||||
|
|
||||||
// Emitted if any item is processed.
|
// 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);
|
void progress(FeedsModelFeed *feed, int current, int total);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
@ -32,6 +42,9 @@ class FeedDownloader : public QObject {
|
|||||||
// are stored persistently in the database.
|
// are stored persistently in the database.
|
||||||
// Appropriate signals are emitted.
|
// Appropriate signals are emitted.
|
||||||
void updateFeeds(const QList<FeedsModelFeed*> &feeds);
|
void updateFeeds(const QList<FeedsModelFeed*> &feeds);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static QPointer<SilentNetworkAccessManager> m_networkManager;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FEEDDOWNLOADER_H
|
#endif // FEEDDOWNLOADER_H
|
||||||
|
@ -6,8 +6,12 @@
|
|||||||
#include <QList>
|
#include <QList>
|
||||||
|
|
||||||
|
|
||||||
|
// This class contains methods to
|
||||||
|
// parse input Unicode textual data into
|
||||||
|
// another objects.
|
||||||
class ParsingFactory {
|
class ParsingFactory {
|
||||||
private:
|
private:
|
||||||
|
// Constructors and destructors.
|
||||||
explicit ParsingFactory();
|
explicit ParsingFactory();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
10
src/core/silentnetworkaccessmanager.cpp
Normal file
10
src/core/silentnetworkaccessmanager.cpp
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#include "core/silentnetworkaccessmanager.h"
|
||||||
|
|
||||||
|
|
||||||
|
SilentNetworkAccessManager::SilentNetworkAccessManager(QObject *parent)
|
||||||
|
: BaseNetworkAccessManager(parent) {
|
||||||
|
}
|
||||||
|
|
||||||
|
SilentNetworkAccessManager::~SilentNetworkAccessManager() {
|
||||||
|
qDebug("Destroying SilentNetworkAccessManages instance.");
|
||||||
|
}
|
17
src/core/silentnetworkaccessmanager.h
Normal file
17
src/core/silentnetworkaccessmanager.h
Normal 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
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
class TextFactory {
|
class TextFactory {
|
||||||
private:
|
private:
|
||||||
|
// Constructors and destructors.
|
||||||
explicit TextFactory();
|
explicit TextFactory();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -15,7 +16,7 @@ class TextFactory {
|
|||||||
// Returns invalid date/time if processing fails.
|
// Returns invalid date/time if processing fails.
|
||||||
static QDateTime parseDateTime(const QString &date_time);
|
static QDateTime parseDateTime(const QString &date_time);
|
||||||
|
|
||||||
// Strips "<....>" tags from given text.
|
// Strips "<....>" (HTML, XML) tags from given text.
|
||||||
static QString stripTags(QString text);
|
static QString stripTags(QString text);
|
||||||
|
|
||||||
// Shortens input string according to given length limit.
|
// Shortens input string according to given length limit.
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include "core/basenetworkaccessmanager.h"
|
#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 {
|
class WebBrowserNetworkAccessManager : public BaseNetworkAccessManager {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
@ -4,8 +4,10 @@
|
|||||||
#include "core/settings.h"
|
#include "core/settings.h"
|
||||||
#include "core/localization.h"
|
#include "core/localization.h"
|
||||||
#include "core/systemfactory.h"
|
#include "core/systemfactory.h"
|
||||||
|
#include "core/feeddownloader.h"
|
||||||
#include "core/dynamicshortcuts.h"
|
#include "core/dynamicshortcuts.h"
|
||||||
#include "core/webbrowsernetworkaccessmanager.h"
|
#include "core/webbrowsernetworkaccessmanager.h"
|
||||||
|
#include "core/silentnetworkaccessmanager.h"
|
||||||
#include "gui/iconthemefactory.h"
|
#include "gui/iconthemefactory.h"
|
||||||
#include "gui/skinfactory.h"
|
#include "gui/skinfactory.h"
|
||||||
#include "gui/systemtrayicon.h"
|
#include "gui/systemtrayicon.h"
|
||||||
@ -363,6 +365,7 @@ void FormSettings::saveProxy() {
|
|||||||
|
|
||||||
// Reload settings for all network access managers.
|
// Reload settings for all network access managers.
|
||||||
WebBrowser::globalNetworkManager()->loadSettings();
|
WebBrowser::globalNetworkManager()->loadSettings();
|
||||||
|
FeedDownloader::globalNetworkManager()->loadSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormSettings::loadLanguage() {
|
void FormSettings::loadLanguage() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user