From e06517bdd410254dd5f0caaccefdd3093301df18 Mon Sep 17 00:00:00 2001 From: nowrep Date: Sun, 1 Jul 2012 20:38:37 +0200 Subject: [PATCH] Added EasyPrivacy into known third party subscriptions - also fixed crashes when not having adblock enabled on startup see #329 --- .../adblock/adblockaddsubscriptiondialog.cpp | 10 ++++- src/lib/adblock/adblockdialog.cpp | 39 +++++++++++++++---- src/lib/adblock/adblockdialog.h | 5 +++ src/lib/adblock/adblockmanager.cpp | 11 +++++- 4 files changed, 54 insertions(+), 11 deletions(-) diff --git a/src/lib/adblock/adblockaddsubscriptiondialog.cpp b/src/lib/adblock/adblockaddsubscriptiondialog.cpp index 4d4aa64c5..2f56433ce 100644 --- a/src/lib/adblock/adblockaddsubscriptiondialog.cpp +++ b/src/lib/adblock/adblockaddsubscriptiondialog.cpp @@ -38,6 +38,7 @@ AdBlockAddSubscriptionDialog::AdBlockAddSubscriptionDialog(QWidget* parent) << Subscription("PLgeneral (Polish)", "http://www.niecko.pl/adblock/adblock.txt") << Subscription("Schacks Adblock Plus liste (Danish)", "http://adblock.schack.dk/block.txt") << Subscription("Xfiles (Italian)", "http://mozilla.gfsolone.com/filtri.txt") + << Subscription("EasyPrivacy (English)", "http://easylist-downloads.adblockplus.org/easyprivacy.txt") << Subscription("Antisocial (English)", "http://adversity.googlecode.com/hg/Antisocial.txt"); foreach(const Subscription & subscription, m_knownSubscriptions) { @@ -62,7 +63,14 @@ void AdBlockAddSubscriptionDialog::indexChanged(int index) { const Subscription &subscription = m_knownSubscriptions.at(index); - ui->title->setText(subscription.title); + int pos = subscription.title.indexOf('('); + QString title = subscription.title; + + if (pos > 0) { + title = title.left(pos).trimmed(); + } + + ui->title->setText(title); ui->title->setCursorPosition(0); ui->url->setText(subscription.url); diff --git a/src/lib/adblock/adblockdialog.cpp b/src/lib/adblock/adblockdialog.cpp index 1ee167aee..1ddb34b63 100644 --- a/src/lib/adblock/adblockdialog.cpp +++ b/src/lib/adblock/adblockdialog.cpp @@ -31,6 +31,7 @@ AdBlockDialog::AdBlockDialog(QWidget* parent) , m_manager(AdBlockManager::instance()) , m_currentTreeWidget(0) , m_currentSubscription(0) + , m_loaded(false) { setAttribute(Qt::WA_DeleteOnClose); setupUi(this); @@ -50,14 +51,11 @@ AdBlockDialog::AdBlockDialog(QWidget* parent) buttonMenu->setMenu(menu); connect(menu, SIGNAL(aboutToShow()), this, SLOT(aboutToShowMenu())); - connect(adblockCheckBox, SIGNAL(toggled(bool)), m_manager, SLOT(setEnabled(bool))); + connect(adblockCheckBox, SIGNAL(toggled(bool)), this, SLOT(enableAdBlock(bool))); connect(search, SIGNAL(textChanged(QString)), this, SLOT(filterString(QString))); connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(currentChanged(int))); - foreach(AdBlockSubscription * subscription, m_manager->subscriptions()) { - AdBlockTreeWidget* tree = new AdBlockTreeWidget(subscription, tabWidget); - tabWidget->addTab(tree, subscription->title()); - } + load(); buttonBox->setFocus(); } @@ -125,13 +123,24 @@ void AdBlockDialog::currentChanged(int index) void AdBlockDialog::filterString(const QString &string) { - m_currentTreeWidget->filterString(string); + if (m_currentTreeWidget && adblockCheckBox->isChecked()) { + m_currentTreeWidget->filterString(string); + } +} + +void AdBlockDialog::enableAdBlock(bool state) +{ + m_manager->setEnabled(state); + + if (state) { + load(); + } } void AdBlockDialog::aboutToShowMenu() { - bool subscriptionEditable = m_currentSubscription->canEditRules(); - bool subscriptionRemovable = m_currentSubscription->canBeRemoved(); + bool subscriptionEditable = m_currentSubscription && m_currentSubscription->canEditRules(); + bool subscriptionRemovable = m_currentSubscription && m_currentSubscription->canBeRemoved(); m_actionAddRule->setEnabled(subscriptionEditable); m_actionRemoveRule->setEnabled(subscriptionEditable); @@ -142,3 +151,17 @@ void AdBlockDialog::learnAboutRules() { mApp->addNewTab(QUrl("http://adblockplus.org/en/filters")); } + +void AdBlockDialog::load() +{ + if (m_loaded || !adblockCheckBox->isChecked()) { + return; + } + + foreach(AdBlockSubscription * subscription, m_manager->subscriptions()) { + AdBlockTreeWidget* tree = new AdBlockTreeWidget(subscription, tabWidget); + tabWidget->addTab(tree, subscription->title()); + } + + m_loaded = true; +} diff --git a/src/lib/adblock/adblockdialog.h b/src/lib/adblock/adblockdialog.h index 2930217b5..849a37c86 100644 --- a/src/lib/adblock/adblockdialog.h +++ b/src/lib/adblock/adblockdialog.h @@ -46,11 +46,14 @@ private slots: void currentChanged(int index); void filterString(const QString &string); + void enableAdBlock(bool state); void aboutToShowMenu(); void learnAboutRules(); private: + void load(); + AdBlockManager* m_manager; AdBlockTreeWidget* m_currentTreeWidget; AdBlockSubscription* m_currentSubscription; @@ -59,6 +62,8 @@ private: QAction* m_actionRemoveRule; QAction* m_actionAddSubscription; QAction* m_actionRemoveSubscription; + + bool m_loaded; }; #endif // ADBLOCKDIALOG_H diff --git a/src/lib/adblock/adblockmanager.cpp b/src/lib/adblock/adblockmanager.cpp index 24460cb68..bbce35519 100644 --- a/src/lib/adblock/adblockmanager.cpp +++ b/src/lib/adblock/adblockmanager.cpp @@ -53,12 +53,19 @@ AdBlockManager* AdBlockManager::instance() void AdBlockManager::setEnabled(bool enabled) { - if (isEnabled() == enabled) { + if (m_enabled == enabled) { return; } m_enabled = enabled; mApp->sendMessages(Qz::AM_SetAdBlockIconEnabled, enabled); + + Settings settings; + settings.beginGroup("AdBlock"); + settings.setValue("enabled", m_enabled); + settings.endGroup(); + + load(); } QList AdBlockManager::subscriptions() const @@ -157,7 +164,7 @@ bool AdBlockManager::removeSubscription(AdBlockSubscription* subscription) void AdBlockManager::load() { - if (!m_enabled || m_loaded) { + if (m_loaded) { return; }