diff --git a/src/lib/adblock/adblockdialog.cpp b/src/lib/adblock/adblockdialog.cpp index a6bef2b83..c437aa261 100644 --- a/src/lib/adblock/adblockdialog.cpp +++ b/src/lib/adblock/adblockdialog.cpp @@ -102,10 +102,6 @@ void AdBlockDialog::currentChanged(int index) if (index != -1) { m_currentTreeWidget = qobject_cast(tabWidget->widget(index)); m_currentSubscription = m_currentTreeWidget->subscription(); - - if (!search->text().isEmpty()) { - filterString(search->text()); - } } } diff --git a/src/lib/adblock/adblocksubscription.cpp b/src/lib/adblock/adblocksubscription.cpp index 0d117cdcf..b5e449ee7 100644 --- a/src/lib/adblock/adblocksubscription.cpp +++ b/src/lib/adblock/adblocksubscription.cpp @@ -238,30 +238,24 @@ QList 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]; } diff --git a/src/lib/adblock/adblocksubscription.h b/src/lib/adblock/adblocksubscription.h index daa75991e..9afa72b90 100644 --- a/src/lib/adblock/adblocksubscription.h +++ b/src/lib/adblock/adblocksubscription.h @@ -79,15 +79,15 @@ public: QString elementHidingRulesForDomain(const QString &domain) const; QList 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 diff --git a/src/lib/adblock/adblocktreewidget.cpp b/src/lib/adblock/adblocktreewidget.cpp index 49aad5b2f..762ed3bc6 100644 --- a/src/lib/adblock/adblocktreewidget.cpp +++ b/src/lib/adblock/adblocktreewidget.cpp @@ -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; } diff --git a/src/lib/adblock/adblocktreewidget.h b/src/lib/adblock/adblocktreewidget.h index fffaa0495..674eaa535 100644 --- a/src/lib/adblock/adblocktreewidget.h +++ b/src/lib/adblock/adblocktreewidget.h @@ -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 diff --git a/src/lib/webview/webview.cpp b/src/lib/webview/webview.cpp index 7594ae2a2..d5e488d10 100644 --- a/src/lib/webview/webview.cpp +++ b/src/lib/webview/webview.cpp @@ -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