mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-02-04 03:08:04 +01:00
Cleanups.
This commit is contained in:
parent
f4c11d94e1
commit
f7776f5aba
@ -88,39 +88,6 @@ void AdBlockManager::removeDisabledRule(const QString& filter) {
|
|||||||
m_disabledRules.removeOne(filter);
|
m_disabledRules.removeOne(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AdBlockManager::addSubscriptionFromUrl(const QUrl& url) {
|
|
||||||
const QList<QPair<QString, QString>> queryItems = QUrlQuery(url).queryItems(QUrl::FullyDecoded);
|
|
||||||
QString subscriptionTitle;
|
|
||||||
QString subscriptionUrl;
|
|
||||||
|
|
||||||
for (int i = 0; i < queryItems.count(); ++i) {
|
|
||||||
QPair<QString, QString> pair = queryItems.at(i);
|
|
||||||
|
|
||||||
if (pair.first == QL1S("location")) {
|
|
||||||
subscriptionUrl = pair.second;
|
|
||||||
}
|
|
||||||
else if (pair.first == QL1S("title")) {
|
|
||||||
subscriptionTitle = pair.second;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (subscriptionTitle.isEmpty() || subscriptionUrl.isEmpty()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QString message = tr("Do you want to add <b>%1</b> subscription?").arg(subscriptionTitle);
|
|
||||||
|
|
||||||
QMessageBox::StandardButton result = QMessageBox::question(nullptr, tr("Add AdBlock subscription"), message,
|
|
||||||
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
|
|
||||||
|
|
||||||
if (result == QMessageBox::StandardButton::Yes) {
|
|
||||||
qApp->web()->adBlock()->addSubscription(subscriptionTitle, subscriptionUrl);
|
|
||||||
qApp->web()->adBlock()->showDialog();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
AdBlockSubscription* AdBlockManager::addSubscription(const QString& title, const QString& url) {
|
AdBlockSubscription* AdBlockManager::addSubscription(const QString& title, const QString& url) {
|
||||||
if (title.isEmpty() || url.isEmpty()) {
|
if (title.isEmpty() || url.isEmpty()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -303,8 +270,7 @@ bool AdBlockManager::isEnabled() const {
|
|||||||
|
|
||||||
bool AdBlockManager::canRunOnScheme(const QString& scheme) const {
|
bool AdBlockManager::canRunOnScheme(const QString& scheme) const {
|
||||||
return !(scheme == QSL("file") || scheme == QSL("qrc") ||
|
return !(scheme == QSL("file") || scheme == QSL("qrc") ||
|
||||||
scheme == QSL("data") || scheme == QSL("abp") ||
|
scheme == QSL("data") || scheme == QSL("abp"));
|
||||||
scheme == QSL(APP_LOW_NAME));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AdBlockManager::canBeBlocked(const QUrl& url) const {
|
bool AdBlockManager::canBeBlocked(const QUrl& url) const {
|
||||||
@ -346,16 +312,6 @@ QString AdBlockManager::generateJsForElementHiding(const QString& css) const {
|
|||||||
return source.arg(style);
|
return source.arg(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
AdBlockSubscription* AdBlockManager::subscriptionByName(const QString& name) const {
|
|
||||||
for (AdBlockSubscription* subscription : m_subscriptions) {
|
|
||||||
if (subscription->title() == name) {
|
|
||||||
return subscription;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AdBlockManager::showDialog() {
|
void AdBlockManager::showDialog() {
|
||||||
AdBlockDialog(qApp->mainFormWidget()).exec();
|
AdBlockDialog(qApp->mainFormWidget()).exec();
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,8 @@ class AdBlockManager : public QObject {
|
|||||||
// if "initial_load" is true, then we want to forcefully perform
|
// if "initial_load" is true, then we want to forcefully perform
|
||||||
// initial loading of Adblock.
|
// initial loading of Adblock.
|
||||||
void load(bool initial_load);
|
void load(bool initial_load);
|
||||||
|
|
||||||
|
// Save all subscriptions to file(s).
|
||||||
void save();
|
void save();
|
||||||
|
|
||||||
// General method for adblocking. Returns pointer to rule if request should
|
// General method for adblocking. Returns pointer to rule if request should
|
||||||
@ -57,17 +59,14 @@ class AdBlockManager : public QObject {
|
|||||||
|
|
||||||
QString elementHidingRules(const QUrl& url) const;
|
QString elementHidingRules(const QUrl& url) const;
|
||||||
QString elementHidingRulesForDomain(const QUrl& url) const;
|
QString elementHidingRulesForDomain(const QUrl& url) const;
|
||||||
|
|
||||||
QString generateJsForElementHiding(const QString& css) const;
|
QString generateJsForElementHiding(const QString& css) const;
|
||||||
|
|
||||||
AdBlockSubscription* subscriptionByName(const QString& name) const;
|
|
||||||
QList<AdBlockSubscription*> subscriptions() const;
|
QList<AdBlockSubscription*> subscriptions() const;
|
||||||
|
|
||||||
QStringList disabledRules() const;
|
QStringList disabledRules() const;
|
||||||
void addDisabledRule(const QString& filter);
|
void addDisabledRule(const QString& filter);
|
||||||
void removeDisabledRule(const QString& filter);
|
void removeDisabledRule(const QString& filter);
|
||||||
|
|
||||||
bool addSubscriptionFromUrl(const QUrl& url);
|
|
||||||
AdBlockSubscription* addSubscription(const QString& title, const QString& url);
|
AdBlockSubscription* addSubscription(const QString& title, const QString& url);
|
||||||
bool removeSubscription(AdBlockSubscription* subscription);
|
bool removeSubscription(AdBlockSubscription* subscription);
|
||||||
|
|
||||||
|
@ -738,21 +738,3 @@ QStringList AdBlockRule::parseRegExpFilter(const QString& filter) const {
|
|||||||
list.removeDuplicates();
|
list.removeDuplicates();
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AdBlockRule::hasOption(const AdBlockRule::RuleOption& opt) const {
|
|
||||||
return (m_options & opt) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AdBlockRule::hasException(const AdBlockRule::RuleOption& opt) const {
|
|
||||||
return (m_exceptions & opt) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AdBlockRule::setOption(const AdBlockRule::RuleOption& opt) {
|
|
||||||
m_options |= opt;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AdBlockRule::setException(const AdBlockRule::RuleOption& opt, bool on) {
|
|
||||||
if (on) {
|
|
||||||
m_exceptions |= opt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -64,8 +64,8 @@ class AdBlockRule {
|
|||||||
virtual ~AdBlockRule() = default;
|
virtual ~AdBlockRule() = default;
|
||||||
|
|
||||||
AdBlockRule* copy() const;
|
AdBlockRule* copy() const;
|
||||||
AdBlockSubscription* subscription() const;
|
|
||||||
|
|
||||||
|
AdBlockSubscription* subscription() const;
|
||||||
void setSubscription(AdBlockSubscription* subscription);
|
void setSubscription(AdBlockSubscription* subscription);
|
||||||
|
|
||||||
QString filter() const;
|
QString filter() const;
|
||||||
@ -135,10 +135,10 @@ class AdBlockRule {
|
|||||||
|
|
||||||
Q_DECLARE_FLAGS(RuleOptions, RuleOption)
|
Q_DECLARE_FLAGS(RuleOptions, RuleOption)
|
||||||
|
|
||||||
inline bool hasOption(const RuleOption& opt) const;
|
bool hasOption(const RuleOption& opt) const;
|
||||||
inline bool hasException(const RuleOption& opt) const;
|
bool hasException(const RuleOption& opt) const;
|
||||||
inline void setOption(const RuleOption& opt);
|
void setOption(const RuleOption& opt);
|
||||||
inline void setException(const RuleOption& opt, bool on);
|
void setException(const RuleOption& opt, bool on);
|
||||||
|
|
||||||
void parseFilter();
|
void parseFilter();
|
||||||
void parseDomains(const QString& domains, const QChar& separator);
|
void parseDomains(const QString& domains, const QChar& separator);
|
||||||
@ -174,4 +174,22 @@ class AdBlockRule {
|
|||||||
friend class AdBlockSubscription;
|
friend class AdBlockSubscription;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline bool AdBlockRule::hasOption(const AdBlockRule::RuleOption& opt) const {
|
||||||
|
return (m_options & opt) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool AdBlockRule::hasException(const AdBlockRule::RuleOption& opt) const {
|
||||||
|
return (m_exceptions & opt) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void AdBlockRule::setOption(const AdBlockRule::RuleOption& opt) {
|
||||||
|
m_options |= opt;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void AdBlockRule::setException(const AdBlockRule::RuleOption& opt, bool on) {
|
||||||
|
if (on) {
|
||||||
|
m_exceptions |= opt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif // ADBLOCKRULE_H
|
#endif // ADBLOCKRULE_H
|
||||||
|
@ -38,12 +38,11 @@ class AdBlockSearchTree {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
struct Node {
|
struct Node {
|
||||||
|
Node() : c(0), rule(0) {}
|
||||||
|
|
||||||
QChar c;
|
QChar c;
|
||||||
const AdBlockRule* rule;
|
const AdBlockRule* rule;
|
||||||
QHash<QChar, Node*> children;
|
QHash<QChar, Node*> children;
|
||||||
|
|
||||||
Node() : c(0), rule(0) { }
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const AdBlockRule* prefixSearch(const AdblockRequestInfo& request, const QString& domain,
|
const AdBlockRule* prefixSearch(const AdblockRequestInfo& request, const QString& domain,
|
||||||
|
@ -61,7 +61,7 @@ class AdBlockSubscription : public QObject {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AdBlockSubscription(QString title, QObject* parent = 0);
|
explicit AdBlockSubscription(QString title, QObject* parent = nullptr);
|
||||||
virtual ~AdBlockSubscription();
|
virtual ~AdBlockSubscription();
|
||||||
|
|
||||||
QString title() const;
|
QString title() const;
|
||||||
@ -72,14 +72,14 @@ class AdBlockSubscription : public QObject {
|
|||||||
QUrl url() const;
|
QUrl url() const;
|
||||||
void setUrl(const QUrl& url);
|
void setUrl(const QUrl& url);
|
||||||
|
|
||||||
virtual void loadSubscription(const QStringList& disabledRules);
|
|
||||||
virtual void saveSubscription();
|
|
||||||
const AdBlockRule* rule(int offset) const;
|
const AdBlockRule* rule(int offset) const;
|
||||||
|
|
||||||
QVector<AdBlockRule*> allRules() const;
|
QVector<AdBlockRule*> allRules() const;
|
||||||
|
|
||||||
const AdBlockRule* enableRule(int offset);
|
const AdBlockRule* enableRule(int offset);
|
||||||
const AdBlockRule* disableRule(int offset);
|
const AdBlockRule* disableRule(int offset);
|
||||||
|
virtual void loadSubscription(const QStringList& disabledRules);
|
||||||
|
virtual void saveSubscription();
|
||||||
virtual bool canEditRules() const;
|
virtual bool canEditRules() const;
|
||||||
virtual bool canBeRemoved() const;
|
virtual bool canBeRemoved() const;
|
||||||
virtual int addRule(AdBlockRule* rule);
|
virtual int addRule(AdBlockRule* rule);
|
||||||
@ -99,8 +99,9 @@ class AdBlockSubscription : public QObject {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool saveDownloadedData(const QByteArray& data);
|
virtual bool saveDownloadedData(const QByteArray& data);
|
||||||
QNetworkReply* m_reply;
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QNetworkReply* m_reply;
|
||||||
QVector<AdBlockRule*> m_rules;
|
QVector<AdBlockRule*> m_rules;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -48,9 +48,11 @@ class AdBlockTreeWidget : public TreeWidget {
|
|||||||
void subscriptionUpdated();
|
void subscriptionUpdated();
|
||||||
void subscriptionError(const QString& message);
|
void subscriptionError(const QString& message);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void keyPressEvent(QKeyEvent* event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void adjustItemFeatures(QTreeWidgetItem* item, const AdBlockRule* rule);
|
void adjustItemFeatures(QTreeWidgetItem* item, const AdBlockRule* rule);
|
||||||
void keyPressEvent(QKeyEvent* event);
|
|
||||||
|
|
||||||
AdBlockSubscription* m_subscription;
|
AdBlockSubscription* m_subscription;
|
||||||
QTreeWidgetItem* m_topItem;
|
QTreeWidgetItem* m_topItem;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user