Refactoring.

This commit is contained in:
Martin Rotter 2017-07-21 09:30:38 +02:00
parent 222622fb66
commit 768c430bd2
8 changed files with 30 additions and 61 deletions

View File

@ -453,7 +453,6 @@ void MessagesView::selectPreviousItem() {
} }
void MessagesView::selectNextUnreadItem() { void MessagesView::selectNextUnreadItem() {
// FIXME: Use this to solve #112.
const QModelIndexList selected_rows = selectionModel()->selectedRows(); const QModelIndexList selected_rows = selectionModel()->selectedRows();
int active_row; int active_row;

View File

@ -45,6 +45,8 @@
#include <QWebEngineProfile> #include <QWebEngineProfile>
#include <QWebEngineDownloadItem> #include <QWebEngineDownloadItem>
#include <QWebEngineScript>
#include <QWebEngineScriptCollection>
#endif #endif
Application::Application(const QString& id, int& argc, char** argv) Application::Application(const QString& id, int& argc, char** argv)
@ -65,8 +67,9 @@ Application::Application(const QString& id, int& argc, char** argv)
#if defined(USE_WEBENGINE) #if defined(USE_WEBENGINE)
connect(QWebEngineProfile::defaultProfile(), &QWebEngineProfile::downloadRequested, this, &Application::downloadRequested); connect(QWebEngineProfile::defaultProfile(), &QWebEngineProfile::downloadRequested, this, &Application::downloadRequested);
QWebEngineProfile::defaultProfile()->setRequestInterceptor(m_urlInterceptor); QWebEngineProfile::defaultProfile()->setRequestInterceptor(m_urlInterceptor);
// TODO: Teď tam žádný nastavení není, ale jestli se DNT třeba
// přidá do dialogu nastavení, tak toto volat při ukládání nastavení. // TODO: Call load settings when saving app settings from dialog.
// Will need add that if I add more settings in the future.
m_urlInterceptor->loadSettings(); m_urlInterceptor->loadSettings();
#endif #endif
} }

View File

@ -26,7 +26,7 @@
// AdBlock. // AdBlock.
DKEY AdBlock::ID = "adblock"; DKEY AdBlock::ID = "adblock";
DKEY AdBlock::DisabledRules = "disabled_rules"; DKEY AdBlock::DisabledRules = "disabled_rules";
DVALUE(QStringList) AdBlock::DisabledRulesDef = QStringList(); DVALUE(QStringList) AdBlock::DisabledRulesDef = QStringList();

View File

@ -102,17 +102,8 @@ bool AdBlockManager::block(QWebEngineUrlRequestInfo& request) {
res = true; res = true;
if (request.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeMainFrame) { if (request.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeMainFrame) {
// We are blocking main URL frame, we can display "AdBlock error page" or // NOTE: We are blocking main URL frame, we can display "AdBlock error page" or
// redirect to somewhere. // redirect to somewhere.
// TODO: dodělat lepší
// TODO request.redirect() přesměrovat na "chybovou stranku";
// QUrl url(QSL("rssguard:adblock"));
// QUrlQuery query;
// query.addQueryItem(QSL("rule"), blockedRule->filter());
// query.addQueryItem(QSL("subscription"),
// blockedRule->subscription()->title());
// url.setQuery(query);
// request.redirect(url);
request.block(true); request.block(true);
} }
@ -191,9 +182,8 @@ AdBlockSubscription* AdBlockManager::addSubscription(const QString& title, const
subscription->setFilePath(filePath); subscription->setFilePath(filePath);
subscription->loadSubscription(m_disabledRules); subscription->loadSubscription(m_disabledRules);
m_subscriptions.insert(m_subscriptions.count() - 1, subscription); m_subscriptions.insert(m_subscriptions.count() - 1, subscription);
// TODO: po změně subskripce přehrat user css? // TODO: Reload user stylesheet.
// connect(subscription, SIGNAL(subscriptionUpdated()), mApp, // connect(subscription, SIGNAL(subscriptionUpdated()), mApp, SLOT(reloadUserStyleSheet()));
// SLOT(reloadUserStyleSheet()));
connect(subscription, SIGNAL(subscriptionChanged()), this, SLOT(updateMatcher())); connect(subscription, SIGNAL(subscriptionChanged()), this, SLOT(updateMatcher()));
return subscription; return subscription;
} }
@ -282,12 +272,11 @@ void AdBlockManager::load() {
AdBlockCustomList* customList = new AdBlockCustomList(this); AdBlockCustomList* customList = new AdBlockCustomList(this);
m_subscriptions.append(customList); m_subscriptions.append(customList);
// Load all subscriptions // Load all subscriptions.
foreach (AdBlockSubscription* subscription, m_subscriptions) { foreach (AdBlockSubscription* subscription, m_subscriptions) {
subscription->loadSubscription(m_disabledRules); subscription->loadSubscription(m_disabledRules);
// TODO: po zmene subskripce prehrat user css? // TODO: Reload user stylesheet.
// connect(subscription, SIGNAL(subscriptionUpdated()), mApp, // connect(subscription, SIGNAL(subscriptionUpdated()), mApp, SLOT(reloadUserStyleSheet()));
// SLOT(reloadUserStyleSheet()));
connect(subscription, SIGNAL(subscriptionChanged()), this, SLOT(updateMatcher())); connect(subscription, SIGNAL(subscriptionChanged()), this, SLOT(updateMatcher()));
} }

View File

@ -208,8 +208,7 @@ const AdBlockRule* AdBlockSubscription::enableRule(int offset) {
emit subscriptionChanged(); emit subscriptionChanged();
if (rule->isCssRule()) { if (rule->isCssRule()) {
// TODO: opravdu? // TODO: Reload user stylesheet.
//mApp->reloadUserStyleSheet();
} }
return rule; return rule;
@ -231,8 +230,7 @@ const AdBlockRule* AdBlockSubscription::disableRule(int offset) {
emit subscriptionChanged(); emit subscriptionChanged();
if (rule->isCssRule()) { if (rule->isCssRule()) {
// TODO: opravdu? // TODO: Reload user stylesheet.
//mApp->reloadUserStyleSheet();
} }
return rule; return rule;
@ -367,8 +365,7 @@ int AdBlockCustomList::addRule(AdBlockRule* rule) {
emit subscriptionChanged(); emit subscriptionChanged();
if (rule->isCssRule()) { if (rule->isCssRule()) {
// TODO: opravdu // TODO: Reload user stylesheet.
//mApp->reloadUserStyleSheet();
} }
return m_rules.count() - 1; return m_rules.count() - 1;
@ -385,8 +382,7 @@ bool AdBlockCustomList::removeRule(int offset) {
emit subscriptionChanged(); emit subscriptionChanged();
if (rule->isCssRule()) { if (rule->isCssRule()) {
// TODO: opravdu // TODO: Reload user stylesheet.
//mApp->reloadUserStyleSheet();
} }
AdBlockManager::instance()->removeDisabledRule(filter); AdBlockManager::instance()->removeDisabledRule(filter);
@ -404,8 +400,7 @@ const AdBlockRule* AdBlockCustomList::replaceRule(AdBlockRule* rule, int offset)
emit subscriptionChanged(); emit subscriptionChanged();
if (rule->isCssRule() || oldRule->isCssRule()) { if (rule->isCssRule() || oldRule->isCssRule()) {
// TODO: opravdu // TODO: Reload user stylesheet.
//mApp->reloadUserStyleSheet();
} }
delete oldRule; delete oldRule;

View File

@ -32,9 +32,7 @@ void NetworkUrlInterceptor::interceptRequest(QWebEngineUrlRequestInfo& info) {
info.setHttpHeader(QByteArrayLiteral("DNT"), QByteArrayLiteral("1")); info.setHttpHeader(QByteArrayLiteral("DNT"), QByteArrayLiteral("1"));
} }
// TODO: mužeme zde nastavovat custom věci pro každej webengine sitovej pozadavek // NOTE: Here we can add custom headers for each webengine request, for example "User-Agent".
// treba user agenta
//info.setHttpHeader(QByteArrayLiteral("User-Agent"), mApp->userAgentManager()->userAgentForUrl(info.firstPartyUrl()).toUtf8());
foreach (UrlInterceptor* interceptor, m_interceptors) { foreach (UrlInterceptor* interceptor, m_interceptors) {
interceptor->interceptRequest(info); interceptor->interceptRequest(info);

View File

@ -24,12 +24,11 @@
#include <QUrl> #include <QUrl>
#include <QDesktopServices> #include <QDesktopServices>
Q_GLOBAL_STATIC(WebFactory, qz_webfactory)
QPointer<WebFactory> WebFactory::s_instance;
WebFactory::WebFactory(QObject* parent) WebFactory::WebFactory()
: QObject(parent), m_escapes(QMap<QString, QString>()), : m_escapes(QMap<QString, QString>()), m_deEscapes(QMap<QString, QString>()) {
m_deEscapes(QMap<QString, QString>()) {
} }
WebFactory::~WebFactory() { WebFactory::~WebFactory() {
@ -72,11 +71,7 @@ bool WebFactory::openUrlInExternalBrowser(const QString& url) {
} }
WebFactory* WebFactory::instance() { WebFactory* WebFactory::instance() {
if (s_instance.isNull()) { return qz_webfactory();
s_instance = new WebFactory(qApp);
}
return s_instance;
} }
QString WebFactory::stripTags(QString text) { QString WebFactory::stripTags(QString text) {
@ -85,7 +80,7 @@ QString WebFactory::stripTags(QString text) {
QString WebFactory::escapeHtml(const QString& html) { QString WebFactory::escapeHtml(const QString& html) {
if (m_escapes.isEmpty()) { if (m_escapes.isEmpty()) {
generetaEscapes(); genereteEscapes();
} }
QString output = html; QString output = html;
@ -136,7 +131,7 @@ QString WebFactory::toSecondLevelDomain(const QUrl& url) {
return domain + top_level_domain; return domain + top_level_domain;
} }
void WebFactory::generetaEscapes() { void WebFactory::genereteEscapes() {
m_escapes[QSL("&lt;")] = QL1C('<'); m_escapes[QSL("&lt;")] = QL1C('<');
m_escapes[QSL("&gt;")] = QL1C('>'); m_escapes[QSL("&gt;")] = QL1C('>');
m_escapes[QSL("&amp;")] = QL1C('&'); m_escapes[QSL("&amp;")] = QL1C('&');

View File

@ -18,20 +18,18 @@
#ifndef WEBFACTORY_H #ifndef WEBFACTORY_H
#define WEBFACTORY_H #define WEBFACTORY_H
#include <QObject>
#include "core/messagesmodel.h" #include "core/messagesmodel.h"
#include <QPointer>
#include <QMap> #include <QMap>
class QWebEngineSettings; class QWebEngineSettings;
class WebFactory : public QObject { class WebFactory {
Q_OBJECT
public: public:
// Constructor.
explicit WebFactory();
// Destructor. // Destructor.
virtual ~WebFactory(); virtual ~WebFactory();
@ -42,8 +40,6 @@ class WebFactory : public QObject {
QString escapeHtml(const QString& html); QString escapeHtml(const QString& html);
QString deEscapeHtml(const QString& text); QString deEscapeHtml(const QString& text);
// BUG: Version for Qt < 4.8 has one issue, it will wrongly
// count .co.uk (and others) as second-level domain
QString toSecondLevelDomain(const QUrl& url); QString toSecondLevelDomain(const QUrl& url);
// Singleton getter. // Singleton getter.
@ -55,18 +51,12 @@ class WebFactory : public QObject {
bool sendMessageViaEmail(const Message& message); bool sendMessageViaEmail(const Message& message);
private: private:
// Constructor.
explicit WebFactory(QObject* parent = 0);
// Escape sequences generators. // Escape sequences generators.
void generetaEscapes(); void genereteEscapes();
void generateDeescapes(); void generateDeescapes();
QMap<QString, QString> m_escapes; QMap<QString, QString> m_escapes;
QMap<QString, QString> m_deEscapes; QMap<QString, QString> m_deEscapes;
// Singleton.
static QPointer<WebFactory> s_instance;
}; };
#endif // WEBFACTORY_H #endif // WEBFACTORY_H