mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +01:00
AdBlock: Showing different colors for each rule type
- black = normal rules green = exceptions gray = disabled rules blue = css rules
This commit is contained in:
parent
847469e0be
commit
b9476c9bbc
@ -102,10 +102,6 @@ void AdBlockDialog::currentChanged(int index)
|
|||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
m_currentTreeWidget = qobject_cast<AdBlockTreeWidget*>(tabWidget->widget(index));
|
m_currentTreeWidget = qobject_cast<AdBlockTreeWidget*>(tabWidget->widget(index));
|
||||||
m_currentSubscription = m_currentTreeWidget->subscription();
|
m_currentSubscription = m_currentTreeWidget->subscription();
|
||||||
|
|
||||||
if (!search->text().isEmpty()) {
|
|
||||||
filterString(search->text());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,30 +238,24 @@ QList<AdBlockRule> AdBlockSubscription::allRules() const
|
|||||||
return m_rules;
|
return m_rules;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockSubscription::enableRule(int offset)
|
const AdBlockRule* AdBlockSubscription::enableRule(int offset)
|
||||||
{
|
{
|
||||||
if (!qz_listContainsIndex(m_rules, offset)) {
|
if (!qz_listContainsIndex(m_rules, offset)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const AdBlockRule &rule = m_rules.at(offset);
|
m_rules[offset].setEnabled(true);
|
||||||
|
return &m_rules[offset];
|
||||||
if (rule.filter().startsWith("!")) {
|
|
||||||
m_rules[offset].setFilter(rule.filter().mid(1));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockSubscription::disableRule(int offset)
|
const AdBlockRule* AdBlockSubscription::disableRule(int offset)
|
||||||
{
|
{
|
||||||
if (!qz_listContainsIndex(m_rules, offset)) {
|
if (!qz_listContainsIndex(m_rules, offset)) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const AdBlockRule &rule = m_rules.at(offset);
|
m_rules[offset].setEnabled(false);
|
||||||
|
return &m_rules[offset];
|
||||||
if (!rule.filter().startsWith("!")) {
|
|
||||||
m_rules[offset].setFilter("!" + rule.filter());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AdBlockSubscription::canEditRules() const
|
bool AdBlockSubscription::canEditRules() const
|
||||||
@ -286,11 +280,11 @@ bool AdBlockSubscription::removeRule(int offset)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AdBlockSubscription::replaceRule(const AdBlockRule &rule, int offset)
|
const AdBlockRule* AdBlockSubscription::replaceRule(const AdBlockRule &rule, int offset)
|
||||||
{
|
{
|
||||||
Q_UNUSED(rule)
|
Q_UNUSED(rule)
|
||||||
Q_UNUSED(offset)
|
Q_UNUSED(offset)
|
||||||
return false;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockSubscription::populateCache()
|
void AdBlockSubscription::populateCache()
|
||||||
@ -394,14 +388,14 @@ bool AdBlockCustomList::removeRule(int offset)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AdBlockCustomList::replaceRule(const AdBlockRule &rule, int offset)
|
const AdBlockRule* AdBlockCustomList::replaceRule(const AdBlockRule &rule, int offset)
|
||||||
{
|
{
|
||||||
if (!qz_listContainsIndex(m_rules, offset)) {
|
if (!qz_listContainsIndex(m_rules, offset)) {
|
||||||
return false;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_rules[offset] = rule;
|
m_rules[offset] = rule;
|
||||||
populateCache();
|
populateCache();
|
||||||
|
|
||||||
return true;
|
return &m_rules[offset];
|
||||||
}
|
}
|
||||||
|
@ -79,15 +79,15 @@ public:
|
|||||||
QString elementHidingRulesForDomain(const QString &domain) const;
|
QString elementHidingRulesForDomain(const QString &domain) const;
|
||||||
QList<AdBlockRule> allRules() const;
|
QList<AdBlockRule> allRules() const;
|
||||||
|
|
||||||
void enableRule(int offset);
|
const AdBlockRule* enableRule(int offset);
|
||||||
void disableRule(int offset);
|
const AdBlockRule* disableRule(int offset);
|
||||||
|
|
||||||
virtual bool canEditRules() const;
|
virtual bool canEditRules() const;
|
||||||
virtual bool canBeRemoved() const;
|
virtual bool canBeRemoved() const;
|
||||||
|
|
||||||
virtual int addRule(const AdBlockRule &rule);
|
virtual int addRule(const AdBlockRule &rule);
|
||||||
virtual bool removeRule(int offset);
|
virtual bool removeRule(int offset);
|
||||||
virtual bool replaceRule(const AdBlockRule &rule, int offset);
|
virtual const AdBlockRule* replaceRule(const AdBlockRule &rule, int offset);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateSubscription();
|
void updateSubscription();
|
||||||
@ -142,7 +142,7 @@ public:
|
|||||||
|
|
||||||
int addRule(const AdBlockRule &rule);
|
int addRule(const AdBlockRule &rule);
|
||||||
bool removeRule(int offset);
|
bool removeRule(int offset);
|
||||||
bool replaceRule(const AdBlockRule &rule, int offset);
|
const AdBlockRule* replaceRule(const AdBlockRule &rule, int offset);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ADBLOCKSUBSCRIPTION_H
|
#endif // ADBLOCKSUBSCRIPTION_H
|
||||||
|
@ -79,28 +79,25 @@ void AdBlockTreeWidget::itemChanged(QTreeWidgetItem* item)
|
|||||||
if (item->checkState(0) == Qt::Unchecked && !item->text(0).startsWith("!")) {
|
if (item->checkState(0) == Qt::Unchecked && !item->text(0).startsWith("!")) {
|
||||||
// Disable rule
|
// Disable rule
|
||||||
int offset = item->data(0, Qt::UserRole + 10).toInt();
|
int offset = item->data(0, Qt::UserRole + 10).toInt();
|
||||||
QFont italicFont;
|
|
||||||
italicFont.setItalic(true);
|
|
||||||
item->setFont(0, italicFont);
|
|
||||||
item->setText(0, item->text(0).prepend("!"));
|
item->setText(0, item->text(0).prepend("!"));
|
||||||
|
|
||||||
m_subscription->disableRule(offset);
|
const AdBlockRule* rule = m_subscription->disableRule(offset);
|
||||||
|
adjustItemColor(item, *rule);
|
||||||
}
|
}
|
||||||
else if (item->checkState(0) == Qt::Checked && item->text(0).startsWith("!")) {
|
else if (item->checkState(0) == Qt::Checked && item->text(0).startsWith("!")) {
|
||||||
// Enable rule
|
// Enable rule
|
||||||
int offset = item->data(0, Qt::UserRole + 10).toInt();
|
int offset = item->data(0, Qt::UserRole + 10).toInt();
|
||||||
item->setFont(0, QFont());
|
item->setText(0, item->text(0).mid(1));
|
||||||
QString newText = item->text(0).mid(1);
|
|
||||||
item->setText(0, newText);
|
|
||||||
|
|
||||||
m_subscription->enableRule(offset);
|
const AdBlockRule* rule = m_subscription->enableRule(offset);
|
||||||
|
adjustItemColor(item, *rule);
|
||||||
}
|
}
|
||||||
else if (m_subscription->canEditRules()) {
|
else if (m_subscription->canEditRules()) {
|
||||||
// Custom rule has been changed
|
// Custom rule has been changed
|
||||||
int offset = item->data(0, Qt::UserRole + 10).toInt();
|
int offset = item->data(0, Qt::UserRole + 10).toInt();
|
||||||
|
|
||||||
AdBlockRule rul(item->text(0));
|
const AdBlockRule* rule = m_subscription->replaceRule(AdBlockRule(item->text(0)), offset);
|
||||||
m_subscription->replaceRule(rul, offset);
|
adjustItemColor(item, *rule);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_itemChangingBlock = false;
|
m_itemChangingBlock = false;
|
||||||
@ -153,6 +150,28 @@ void AdBlockTreeWidget::subscriptionUpdated()
|
|||||||
m_itemChangingBlock = false;
|
m_itemChangingBlock = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AdBlockTreeWidget::adjustItemColor(QTreeWidgetItem* item, const AdBlockRule &rule)
|
||||||
|
{
|
||||||
|
if (!rule.isEnabled()) {
|
||||||
|
QFont font;
|
||||||
|
font.setItalic(true);
|
||||||
|
item->setForeground(0, QColor(Qt::gray));
|
||||||
|
item->setFont(0, font);
|
||||||
|
}
|
||||||
|
else if (rule.isCssRule()) {
|
||||||
|
item->setForeground(0, QColor(Qt::darkBlue));
|
||||||
|
item->setFont(0, QFont());
|
||||||
|
}
|
||||||
|
else if (rule.isException()) {
|
||||||
|
item->setForeground(0, QColor(Qt::darkGreen));
|
||||||
|
item->setFont(0, QFont());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
item->setForeground(0, QColor());
|
||||||
|
item->setFont(0, QFont());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void AdBlockTreeWidget::refresh()
|
void AdBlockTreeWidget::refresh()
|
||||||
{
|
{
|
||||||
m_itemChangingBlock = true;
|
m_itemChangingBlock = true;
|
||||||
@ -160,8 +179,6 @@ void AdBlockTreeWidget::refresh()
|
|||||||
|
|
||||||
QFont boldFont;
|
QFont boldFont;
|
||||||
boldFont.setBold(true);
|
boldFont.setBold(true);
|
||||||
QFont italicFont;
|
|
||||||
italicFont.setItalic(true);
|
|
||||||
|
|
||||||
m_topItem = new QTreeWidgetItem(this);
|
m_topItem = new QTreeWidgetItem(this);
|
||||||
m_topItem->setText(0, m_subscription->title());
|
m_topItem->setText(0, m_subscription->title());
|
||||||
@ -182,10 +199,7 @@ void AdBlockTreeWidget::refresh()
|
|||||||
item->setFlags(item->flags() | Qt::ItemIsEditable);
|
item->setFlags(item->flags() | Qt::ItemIsEditable);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rule.isEnabled()) {
|
adjustItemColor(item, rule);
|
||||||
item->setFont(0, italicFont);
|
|
||||||
}
|
|
||||||
|
|
||||||
++index;
|
++index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include "treewidget.h"
|
#include "treewidget.h"
|
||||||
|
|
||||||
class AdBlockSubscription;
|
class AdBlockSubscription;
|
||||||
|
class AdBlockRule;
|
||||||
|
|
||||||
class QT_QUPZILLA_EXPORT AdBlockTreeWidget : public TreeWidget
|
class QT_QUPZILLA_EXPORT AdBlockTreeWidget : public TreeWidget
|
||||||
{
|
{
|
||||||
@ -33,8 +34,6 @@ public:
|
|||||||
|
|
||||||
AdBlockSubscription* subscription() const;
|
AdBlockSubscription* subscription() const;
|
||||||
|
|
||||||
signals:
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void addRule();
|
void addRule();
|
||||||
void removeRule();
|
void removeRule();
|
||||||
@ -47,11 +46,12 @@ private slots:
|
|||||||
void subscriptionUpdated();
|
void subscriptionUpdated();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void adjustItemColor(QTreeWidgetItem* item, const AdBlockRule &rule);
|
||||||
|
|
||||||
AdBlockSubscription* m_subscription;
|
AdBlockSubscription* m_subscription;
|
||||||
QTreeWidgetItem* m_topItem;
|
QTreeWidgetItem* m_topItem;
|
||||||
|
|
||||||
bool m_itemChangingBlock;
|
bool m_itemChangingBlock;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ADBLOCKTREEWIDGET_H
|
#endif // ADBLOCKTREEWIDGET_H
|
||||||
|
@ -146,7 +146,7 @@ void WebView::load(const QNetworkRequest &request, QNetworkAccessManager::Operat
|
|||||||
|
|
||||||
if (reqUrl.isEmpty() || isUrlValid(reqUrl)) {
|
if (reqUrl.isEmpty() || isUrlValid(reqUrl)) {
|
||||||
QWebView::load(request, operation, body);
|
QWebView::load(request, operation, body);
|
||||||
emit urlChanged(url());
|
emit urlChanged(reqUrl);
|
||||||
m_aboutToLoadUrl = reqUrl;
|
m_aboutToLoadUrl = reqUrl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -156,7 +156,6 @@ void WebView::load(const QNetworkRequest &request, QNetworkAccessManager::Operat
|
|||||||
|
|
||||||
emit urlChanged(searchUrl);
|
emit urlChanged(searchUrl);
|
||||||
m_aboutToLoadUrl = searchUrl;
|
m_aboutToLoadUrl = searchUrl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebView::loadingError() const
|
bool WebView::loadingError() const
|
||||||
|
Loading…
Reference in New Issue
Block a user