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) {
|
||||
m_currentTreeWidget = qobject_cast<AdBlockTreeWidget*>(tabWidget->widget(index));
|
||||
m_currentSubscription = m_currentTreeWidget->subscription();
|
||||
|
||||
if (!search->text().isEmpty()) {
|
||||
filterString(search->text());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -238,30 +238,24 @@ QList<AdBlockRule> AdBlockSubscription::allRules() const
|
||||
return m_rules;
|
||||
}
|
||||
|
||||
void AdBlockSubscription::enableRule(int offset)
|
||||
const AdBlockRule* AdBlockSubscription::enableRule(int offset)
|
||||
{
|
||||
if (!qz_listContainsIndex(m_rules, offset)) {
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
const AdBlockRule &rule = m_rules.at(offset);
|
||||
|
||||
if (rule.filter().startsWith("!")) {
|
||||
m_rules[offset].setFilter(rule.filter().mid(1));
|
||||
}
|
||||
m_rules[offset].setEnabled(true);
|
||||
return &m_rules[offset];
|
||||
}
|
||||
|
||||
void AdBlockSubscription::disableRule(int offset)
|
||||
const AdBlockRule* AdBlockSubscription::disableRule(int offset)
|
||||
{
|
||||
if (!qz_listContainsIndex(m_rules, offset)) {
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
const AdBlockRule &rule = m_rules.at(offset);
|
||||
|
||||
if (!rule.filter().startsWith("!")) {
|
||||
m_rules[offset].setFilter("!" + rule.filter());
|
||||
}
|
||||
m_rules[offset].setEnabled(false);
|
||||
return &m_rules[offset];
|
||||
}
|
||||
|
||||
bool AdBlockSubscription::canEditRules() const
|
||||
@ -286,11 +280,11 @@ bool AdBlockSubscription::removeRule(int offset)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AdBlockSubscription::replaceRule(const AdBlockRule &rule, int offset)
|
||||
const AdBlockRule* AdBlockSubscription::replaceRule(const AdBlockRule &rule, int offset)
|
||||
{
|
||||
Q_UNUSED(rule)
|
||||
Q_UNUSED(offset)
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AdBlockSubscription::populateCache()
|
||||
@ -394,14 +388,14 @@ bool AdBlockCustomList::removeRule(int offset)
|
||||
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)) {
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
m_rules[offset] = rule;
|
||||
populateCache();
|
||||
|
||||
return true;
|
||||
return &m_rules[offset];
|
||||
}
|
||||
|
@ -79,15 +79,15 @@ public:
|
||||
QString elementHidingRulesForDomain(const QString &domain) const;
|
||||
QList<AdBlockRule> allRules() const;
|
||||
|
||||
void enableRule(int offset);
|
||||
void disableRule(int offset);
|
||||
const AdBlockRule* enableRule(int offset);
|
||||
const AdBlockRule* disableRule(int offset);
|
||||
|
||||
virtual bool canEditRules() const;
|
||||
virtual bool canBeRemoved() const;
|
||||
|
||||
virtual int addRule(const AdBlockRule &rule);
|
||||
virtual bool removeRule(int offset);
|
||||
virtual bool replaceRule(const AdBlockRule &rule, int offset);
|
||||
virtual const AdBlockRule* replaceRule(const AdBlockRule &rule, int offset);
|
||||
|
||||
public slots:
|
||||
void updateSubscription();
|
||||
@ -142,7 +142,7 @@ public:
|
||||
|
||||
int addRule(const AdBlockRule &rule);
|
||||
bool removeRule(int offset);
|
||||
bool replaceRule(const AdBlockRule &rule, int offset);
|
||||
const AdBlockRule* replaceRule(const AdBlockRule &rule, int offset);
|
||||
};
|
||||
|
||||
#endif // ADBLOCKSUBSCRIPTION_H
|
||||
|
@ -79,28 +79,25 @@ void AdBlockTreeWidget::itemChanged(QTreeWidgetItem* item)
|
||||
if (item->checkState(0) == Qt::Unchecked && !item->text(0).startsWith("!")) {
|
||||
// Disable rule
|
||||
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("!"));
|
||||
|
||||
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("!")) {
|
||||
// Enable rule
|
||||
int offset = item->data(0, Qt::UserRole + 10).toInt();
|
||||
item->setFont(0, QFont());
|
||||
QString newText = item->text(0).mid(1);
|
||||
item->setText(0, newText);
|
||||
item->setText(0, item->text(0).mid(1));
|
||||
|
||||
m_subscription->enableRule(offset);
|
||||
const AdBlockRule* rule = m_subscription->enableRule(offset);
|
||||
adjustItemColor(item, *rule);
|
||||
}
|
||||
else if (m_subscription->canEditRules()) {
|
||||
// Custom rule has been changed
|
||||
int offset = item->data(0, Qt::UserRole + 10).toInt();
|
||||
|
||||
AdBlockRule rul(item->text(0));
|
||||
m_subscription->replaceRule(rul, offset);
|
||||
const AdBlockRule* rule = m_subscription->replaceRule(AdBlockRule(item->text(0)), offset);
|
||||
adjustItemColor(item, *rule);
|
||||
}
|
||||
|
||||
m_itemChangingBlock = false;
|
||||
@ -153,6 +150,28 @@ void AdBlockTreeWidget::subscriptionUpdated()
|
||||
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()
|
||||
{
|
||||
m_itemChangingBlock = true;
|
||||
@ -160,8 +179,6 @@ void AdBlockTreeWidget::refresh()
|
||||
|
||||
QFont boldFont;
|
||||
boldFont.setBold(true);
|
||||
QFont italicFont;
|
||||
italicFont.setItalic(true);
|
||||
|
||||
m_topItem = new QTreeWidgetItem(this);
|
||||
m_topItem->setText(0, m_subscription->title());
|
||||
@ -182,10 +199,7 @@ void AdBlockTreeWidget::refresh()
|
||||
item->setFlags(item->flags() | Qt::ItemIsEditable);
|
||||
}
|
||||
|
||||
if (!rule.isEnabled()) {
|
||||
item->setFont(0, italicFont);
|
||||
}
|
||||
|
||||
adjustItemColor(item, rule);
|
||||
++index;
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "treewidget.h"
|
||||
|
||||
class AdBlockSubscription;
|
||||
class AdBlockRule;
|
||||
|
||||
class QT_QUPZILLA_EXPORT AdBlockTreeWidget : public TreeWidget
|
||||
{
|
||||
@ -33,8 +34,6 @@ public:
|
||||
|
||||
AdBlockSubscription* subscription() const;
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
void addRule();
|
||||
void removeRule();
|
||||
@ -47,11 +46,12 @@ private slots:
|
||||
void subscriptionUpdated();
|
||||
|
||||
private:
|
||||
void adjustItemColor(QTreeWidgetItem* item, const AdBlockRule &rule);
|
||||
|
||||
AdBlockSubscription* m_subscription;
|
||||
QTreeWidgetItem* m_topItem;
|
||||
|
||||
bool m_itemChangingBlock;
|
||||
|
||||
};
|
||||
|
||||
#endif // ADBLOCKTREEWIDGET_H
|
||||
|
@ -146,7 +146,7 @@ void WebView::load(const QNetworkRequest &request, QNetworkAccessManager::Operat
|
||||
|
||||
if (reqUrl.isEmpty() || isUrlValid(reqUrl)) {
|
||||
QWebView::load(request, operation, body);
|
||||
emit urlChanged(url());
|
||||
emit urlChanged(reqUrl);
|
||||
m_aboutToLoadUrl = reqUrl;
|
||||
return;
|
||||
}
|
||||
@ -156,7 +156,6 @@ void WebView::load(const QNetworkRequest &request, QNetworkAccessManager::Operat
|
||||
|
||||
emit urlChanged(searchUrl);
|
||||
m_aboutToLoadUrl = searchUrl;
|
||||
|
||||
}
|
||||
|
||||
bool WebView::loadingError() const
|
||||
|
Loading…
Reference in New Issue
Block a user