mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-02-03 18:57:37 +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);
|
||||
}
|
||||
|
||||
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) {
|
||||
if (title.isEmpty() || url.isEmpty()) {
|
||||
return nullptr;
|
||||
@ -303,8 +270,7 @@ bool AdBlockManager::isEnabled() const {
|
||||
|
||||
bool AdBlockManager::canRunOnScheme(const QString& scheme) const {
|
||||
return !(scheme == QSL("file") || scheme == QSL("qrc") ||
|
||||
scheme == QSL("data") || scheme == QSL("abp") ||
|
||||
scheme == QSL(APP_LOW_NAME));
|
||||
scheme == QSL("data") || scheme == QSL("abp"));
|
||||
}
|
||||
|
||||
bool AdBlockManager::canBeBlocked(const QUrl& url) const {
|
||||
@ -346,16 +312,6 @@ QString AdBlockManager::generateJsForElementHiding(const QString& css) const {
|
||||
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() {
|
||||
AdBlockDialog(qApp->mainFormWidget()).exec();
|
||||
}
|
||||
|
@ -46,6 +46,8 @@ class AdBlockManager : public QObject {
|
||||
// if "initial_load" is true, then we want to forcefully perform
|
||||
// initial loading of Adblock.
|
||||
void load(bool initial_load);
|
||||
|
||||
// Save all subscriptions to file(s).
|
||||
void save();
|
||||
|
||||
// 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 elementHidingRulesForDomain(const QUrl& url) const;
|
||||
|
||||
QString generateJsForElementHiding(const QString& css) const;
|
||||
|
||||
AdBlockSubscription* subscriptionByName(const QString& name) const;
|
||||
QList<AdBlockSubscription*> subscriptions() const;
|
||||
|
||||
QStringList disabledRules() const;
|
||||
void addDisabledRule(const QString& filter);
|
||||
void removeDisabledRule(const QString& filter);
|
||||
|
||||
bool addSubscriptionFromUrl(const QUrl& url);
|
||||
AdBlockSubscription* addSubscription(const QString& title, const QString& url);
|
||||
bool removeSubscription(AdBlockSubscription* subscription);
|
||||
|
||||
|
@ -738,21 +738,3 @@ QStringList AdBlockRule::parseRegExpFilter(const QString& filter) const {
|
||||
list.removeDuplicates();
|
||||
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;
|
||||
|
||||
AdBlockRule* copy() const;
|
||||
AdBlockSubscription* subscription() const;
|
||||
|
||||
AdBlockSubscription* subscription() const;
|
||||
void setSubscription(AdBlockSubscription* subscription);
|
||||
|
||||
QString filter() const;
|
||||
@ -135,10 +135,10 @@ class AdBlockRule {
|
||||
|
||||
Q_DECLARE_FLAGS(RuleOptions, RuleOption)
|
||||
|
||||
inline bool hasOption(const RuleOption& opt) const;
|
||||
inline bool hasException(const RuleOption& opt) const;
|
||||
inline void setOption(const RuleOption& opt);
|
||||
inline void setException(const RuleOption& opt, bool on);
|
||||
bool hasOption(const RuleOption& opt) const;
|
||||
bool hasException(const RuleOption& opt) const;
|
||||
void setOption(const RuleOption& opt);
|
||||
void setException(const RuleOption& opt, bool on);
|
||||
|
||||
void parseFilter();
|
||||
void parseDomains(const QString& domains, const QChar& separator);
|
||||
@ -174,4 +174,22 @@ class AdBlockRule {
|
||||
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
|
||||
|
@ -38,12 +38,11 @@ class AdBlockSearchTree {
|
||||
|
||||
private:
|
||||
struct Node {
|
||||
Node() : c(0), rule(0) {}
|
||||
|
||||
QChar c;
|
||||
const AdBlockRule* rule;
|
||||
QHash<QChar, Node*> children;
|
||||
|
||||
Node() : c(0), rule(0) { }
|
||||
|
||||
};
|
||||
|
||||
const AdBlockRule* prefixSearch(const AdblockRequestInfo& request, const QString& domain,
|
||||
|
@ -61,7 +61,7 @@ class AdBlockSubscription : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AdBlockSubscription(QString title, QObject* parent = 0);
|
||||
explicit AdBlockSubscription(QString title, QObject* parent = nullptr);
|
||||
virtual ~AdBlockSubscription();
|
||||
|
||||
QString title() const;
|
||||
@ -72,14 +72,14 @@ class AdBlockSubscription : public QObject {
|
||||
QUrl url() const;
|
||||
void setUrl(const QUrl& url);
|
||||
|
||||
virtual void loadSubscription(const QStringList& disabledRules);
|
||||
virtual void saveSubscription();
|
||||
const AdBlockRule* rule(int offset) const;
|
||||
|
||||
QVector<AdBlockRule*> allRules() const;
|
||||
|
||||
const AdBlockRule* enableRule(int offset);
|
||||
const AdBlockRule* disableRule(int offset);
|
||||
virtual void loadSubscription(const QStringList& disabledRules);
|
||||
virtual void saveSubscription();
|
||||
virtual bool canEditRules() const;
|
||||
virtual bool canBeRemoved() const;
|
||||
virtual int addRule(AdBlockRule* rule);
|
||||
@ -99,8 +99,9 @@ class AdBlockSubscription : public QObject {
|
||||
|
||||
protected:
|
||||
virtual bool saveDownloadedData(const QByteArray& data);
|
||||
QNetworkReply* m_reply;
|
||||
|
||||
protected:
|
||||
QNetworkReply* m_reply;
|
||||
QVector<AdBlockRule*> m_rules;
|
||||
|
||||
private:
|
||||
|
@ -48,9 +48,11 @@ class AdBlockTreeWidget : public TreeWidget {
|
||||
void subscriptionUpdated();
|
||||
void subscriptionError(const QString& message);
|
||||
|
||||
protected:
|
||||
virtual void keyPressEvent(QKeyEvent* event);
|
||||
|
||||
private:
|
||||
void adjustItemFeatures(QTreeWidgetItem* item, const AdBlockRule* rule);
|
||||
void keyPressEvent(QKeyEvent* event);
|
||||
|
||||
AdBlockSubscription* m_subscription;
|
||||
QTreeWidgetItem* m_topItem;
|
||||
|
Loading…
x
Reference in New Issue
Block a user