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() {
// FIXME: Use this to solve #112.
const QModelIndexList selected_rows = selectionModel()->selectedRows();
int active_row;

View File

@ -45,6 +45,8 @@
#include <QWebEngineProfile>
#include <QWebEngineDownloadItem>
#include <QWebEngineScript>
#include <QWebEngineScriptCollection>
#endif
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)
connect(QWebEngineProfile::defaultProfile(), &QWebEngineProfile::downloadRequested, this, &Application::downloadRequested);
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();
#endif
}

View File

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

View File

@ -102,17 +102,8 @@ bool AdBlockManager::block(QWebEngineUrlRequestInfo& request) {
res = true;
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.
// 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);
}
@ -191,9 +182,8 @@ AdBlockSubscription* AdBlockManager::addSubscription(const QString& title, const
subscription->setFilePath(filePath);
subscription->loadSubscription(m_disabledRules);
m_subscriptions.insert(m_subscriptions.count() - 1, subscription);
// TODO: po změně subskripce přehrat user css?
// connect(subscription, SIGNAL(subscriptionUpdated()), mApp,
// SLOT(reloadUserStyleSheet()));
// TODO: Reload user stylesheet.
// connect(subscription, SIGNAL(subscriptionUpdated()), mApp, SLOT(reloadUserStyleSheet()));
connect(subscription, SIGNAL(subscriptionChanged()), this, SLOT(updateMatcher()));
return subscription;
}
@ -282,12 +272,11 @@ void AdBlockManager::load() {
AdBlockCustomList* customList = new AdBlockCustomList(this);
m_subscriptions.append(customList);
// Load all subscriptions
// Load all subscriptions.
foreach (AdBlockSubscription* subscription, m_subscriptions) {
subscription->loadSubscription(m_disabledRules);
// TODO: po zmene subskripce prehrat user css?
// connect(subscription, SIGNAL(subscriptionUpdated()), mApp,
// SLOT(reloadUserStyleSheet()));
// TODO: Reload user stylesheet.
// connect(subscription, SIGNAL(subscriptionUpdated()), mApp, SLOT(reloadUserStyleSheet()));
connect(subscription, SIGNAL(subscriptionChanged()), this, SLOT(updateMatcher()));
}

View File

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

View File

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

View File

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

View File

@ -18,20 +18,18 @@
#ifndef WEBFACTORY_H
#define WEBFACTORY_H
#include <QObject>
#include "core/messagesmodel.h"
#include <QPointer>
#include <QMap>
class QWebEngineSettings;
class WebFactory : public QObject {
Q_OBJECT
class WebFactory {
public:
// Constructor.
explicit WebFactory();
// Destructor.
virtual ~WebFactory();
@ -42,8 +40,6 @@ class WebFactory : public QObject {
QString escapeHtml(const QString& html);
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);
// Singleton getter.
@ -55,18 +51,12 @@ class WebFactory : public QObject {
bool sendMessageViaEmail(const Message& message);
private:
// Constructor.
explicit WebFactory(QObject* parent = 0);
// Escape sequences generators.
void generetaEscapes();
void genereteEscapes();
void generateDeescapes();
QMap<QString, QString> m_escapes;
QMap<QString, QString> m_escapes;
QMap<QString, QString> m_deEscapes;
// Singleton.
static QPointer<WebFactory> s_instance;
};
#endif // WEBFACTORY_H