Simplified adblock dialog.
This commit is contained in:
parent
f0fadfcdbe
commit
8bf0926559
@ -26,6 +26,7 @@
|
||||
|
||||
#define ARGUMENTS_LIST_SEPARATOR "\n"
|
||||
|
||||
#define ADBLOCK_HOWTO_FILTERS "http://adblockplus.org/en/filters"
|
||||
#define ADBLOCK_UPDATE_DAYS_INTERVAL 5
|
||||
#define ADBLOCK_ICON_ACTIVE "adblock"
|
||||
#define ADBLOCK_ICON_DISABLED "adblock-disabled"
|
||||
|
@ -19,6 +19,8 @@
|
||||
#include "network-web/adblock/adblockaddsubscriptiondialog.h"
|
||||
|
||||
#include "definitions/definitions.h"
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/iconfactory.h"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QCheckBox>
|
||||
@ -58,6 +60,9 @@ AdBlockAddSubscriptionDialog::AdBlockAddSubscriptionDialog(QWidget* parent)
|
||||
|
||||
m_ui->m_cbUsePredefined->setChecked(true);
|
||||
indexChanged(0);
|
||||
|
||||
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint);
|
||||
setWindowIcon(qApp->icons()->miscIcon(ADBLOCK_ICON_ACTIVE));
|
||||
}
|
||||
|
||||
QString AdBlockAddSubscriptionDialog::title() const {
|
||||
|
@ -11,7 +11,7 @@
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Add Subscription</string>
|
||||
<string>Add subscription</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="1">
|
||||
|
@ -17,12 +17,16 @@
|
||||
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "network-web/adblock/adblockdialog.h"
|
||||
|
||||
#include "network-web/adblock/adblockmanager.h"
|
||||
#include "network-web/adblock/adblocksubscription.h"
|
||||
#include "network-web/adblock/adblocktreewidget.h"
|
||||
#include "network-web/adblock/adblockaddsubscriptiondialog.h"
|
||||
|
||||
#include "network-web/webfactory.h"
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/iconfactory.h"
|
||||
#include "definitions/definitions.h"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QTimer>
|
||||
@ -31,125 +35,139 @@
|
||||
|
||||
|
||||
AdBlockDialog::AdBlockDialog(QWidget* parent)
|
||||
: QWidget(parent), m_ui(new Ui::AdBlockDialog), m_manager(AdBlockManager::instance()), m_currentTreeWidget(0), m_currentSubscription(0),
|
||||
m_loaded(false) {
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
m_ui->setupUi(this);
|
||||
#ifdef Q_OS_MACOS
|
||||
m_ui->tabWidget->setDocumentMode(false);
|
||||
: QDialog(parent), m_ui(new Ui::AdBlockDialog), m_manager(AdBlockManager::instance()), m_currentTreeWidget(0), m_currentSubscription(0),
|
||||
m_loaded(false) {
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint);
|
||||
setWindowIcon(qApp->icons()->miscIcon(ADBLOCK_ICON_ACTIVE));
|
||||
|
||||
m_ui->setupUi(this);
|
||||
m_ui->m_cbEnable->setChecked(m_manager->isEnabled());
|
||||
|
||||
#if defined(Q_OS_MACOS)
|
||||
m_ui->m_tabSubscriptions->setDocumentMode(false);
|
||||
#endif
|
||||
m_ui->adblockCheckBox->setChecked(m_manager->isEnabled());
|
||||
QMenu* menu = new QMenu(m_ui->buttonOptions);
|
||||
m_actionAddRule = menu->addAction(tr("Add rule"), this, SLOT(addRule()));
|
||||
m_actionRemoveRule = menu->addAction(tr("Remove rule"), this, SLOT(removeRule()));
|
||||
menu->addSeparator();
|
||||
m_actionAddSubscription = menu->addAction(tr("Add subscription"), this, SLOT(addSubscription()));
|
||||
m_actionRemoveSubscription = menu->addAction(tr("Remove subscription"), this, SLOT(removeSubscription()));
|
||||
menu->addAction(tr("Update subscriptions"), m_manager, SLOT(updateAllSubscriptions()));
|
||||
menu->addSeparator();
|
||||
menu->addAction(tr("Learn about writing rules..."), this, SLOT(learnAboutRules()));
|
||||
m_ui->buttonOptions->setMenu(menu);
|
||||
connect(menu, SIGNAL(aboutToShow()), this, SLOT(aboutToShowMenu()));
|
||||
connect(m_ui->adblockCheckBox, SIGNAL(toggled(bool)), this, SLOT(enableAdBlock(bool)));
|
||||
connect(m_ui->tabWidget, SIGNAL(currentChanged(int)), this, SLOT(currentChanged(int)));
|
||||
connect(m_ui->buttonBox, &QDialogButtonBox::clicked, this, &AdBlockDialog::close);
|
||||
load();
|
||||
m_ui->buttonBox->setFocus();
|
||||
|
||||
QPushButton* btn_options = m_ui->m_buttonBox->addButton(QDialogButtonBox::FirstButton);
|
||||
btn_options->setText(tr("Options"));
|
||||
|
||||
QMenu* menu = new QMenu(btn_options);
|
||||
|
||||
m_actionAddRule = menu->addAction(tr("Add rule"), this, &AdBlockDialog::addRule);
|
||||
m_actionRemoveRule = menu->addAction(tr("Remove rule"), this, &AdBlockDialog::removeRule);
|
||||
|
||||
menu->addSeparator();
|
||||
|
||||
m_actionAddSubscription = menu->addAction(tr("Add subscription"), this, &AdBlockDialog::addSubscription);
|
||||
m_actionRemoveSubscription = menu->addAction(tr("Remove subscription"), this, &AdBlockDialog::removeSubscription);
|
||||
|
||||
menu->addAction(tr("Update subscriptions"), m_manager, &AdBlockManager::updateAllSubscriptions);
|
||||
menu->addSeparator();
|
||||
menu->addAction(tr("Learn about writing rules..."), this, &AdBlockDialog::learnAboutRules);
|
||||
btn_options->setMenu(menu);
|
||||
|
||||
|
||||
|
||||
connect(menu, &QMenu::aboutToShow, this, &AdBlockDialog::aboutToShowMenu);
|
||||
connect(m_ui->m_cbEnable, &QCheckBox::toggled, this, &AdBlockDialog::enableAdBlock);
|
||||
connect(m_ui->m_tabSubscriptions, &QTabWidget::currentChanged, this, &AdBlockDialog::currentChanged);
|
||||
connect(m_ui->m_buttonBox, &QDialogButtonBox::rejected, this, &AdBlockDialog::close);
|
||||
load();
|
||||
|
||||
m_ui->m_buttonBox->setFocus();
|
||||
}
|
||||
|
||||
void AdBlockDialog::showRule(const AdBlockRule* rule) const {
|
||||
AdBlockSubscription* subscription = rule->subscription();
|
||||
AdBlockSubscription* subscription = rule->subscription();
|
||||
|
||||
if (!subscription) {
|
||||
return;
|
||||
}
|
||||
if (subscription) {
|
||||
for (int i = 0; i < m_ui->m_tabSubscriptions->count(); ++i) {
|
||||
AdBlockTreeWidget* treeWidget = qobject_cast<AdBlockTreeWidget*>(m_ui->m_tabSubscriptions->widget(i));
|
||||
|
||||
for (int i = 0; i < m_ui->tabWidget->count(); ++i) {
|
||||
AdBlockTreeWidget* treeWidget = qobject_cast<AdBlockTreeWidget*>(m_ui->tabWidget->widget(i));
|
||||
|
||||
if (subscription == treeWidget->subscription()) {
|
||||
treeWidget->showRule(rule);
|
||||
m_ui->tabWidget->setCurrentIndex(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (subscription == treeWidget->subscription()) {
|
||||
treeWidget->showRule(rule);
|
||||
m_ui->m_tabSubscriptions->setCurrentIndex(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AdBlockDialog::addRule() {
|
||||
m_currentTreeWidget->addRule();
|
||||
m_currentTreeWidget->addRule();
|
||||
}
|
||||
|
||||
void AdBlockDialog::removeRule() {
|
||||
m_currentTreeWidget->removeRule();
|
||||
m_currentTreeWidget->removeRule();
|
||||
}
|
||||
|
||||
void AdBlockDialog::addSubscription() {
|
||||
AdBlockAddSubscriptionDialog dialog(this);
|
||||
AdBlockAddSubscriptionDialog dialog(this);
|
||||
|
||||
if (dialog.exec() != QDialog::Accepted) {
|
||||
return;
|
||||
}
|
||||
if (dialog.exec() != QDialog::Accepted) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString title = dialog.title();
|
||||
QString url = dialog.url();
|
||||
QString title = dialog.title();
|
||||
QString url = dialog.url();
|
||||
|
||||
if (AdBlockSubscription* subscription = m_manager->addSubscription(title, url)) {
|
||||
AdBlockTreeWidget* tree = new AdBlockTreeWidget(subscription, m_ui->tabWidget);
|
||||
int index = m_ui->tabWidget->insertTab(m_ui->tabWidget->count() - 1, tree, subscription->title());
|
||||
m_ui->tabWidget->setCurrentIndex(index);
|
||||
}
|
||||
if (AdBlockSubscription* subscription = m_manager->addSubscription(title, url)) {
|
||||
AdBlockTreeWidget* tree = new AdBlockTreeWidget(subscription, m_ui->m_tabSubscriptions);
|
||||
int index = m_ui->m_tabSubscriptions->insertTab(m_ui->m_tabSubscriptions->count() - 1, tree, subscription->title());
|
||||
m_ui->m_tabSubscriptions->setCurrentIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
void AdBlockDialog::removeSubscription() {
|
||||
if (m_manager->removeSubscription(m_currentSubscription)) {
|
||||
delete m_currentTreeWidget;
|
||||
}
|
||||
if (m_manager->removeSubscription(m_currentSubscription)) {
|
||||
delete m_currentTreeWidget;
|
||||
}
|
||||
}
|
||||
|
||||
void AdBlockDialog::currentChanged(int index) {
|
||||
if (index != -1) {
|
||||
m_currentTreeWidget = qobject_cast<AdBlockTreeWidget*>(m_ui->tabWidget->widget(index));
|
||||
m_currentSubscription = m_currentTreeWidget->subscription();
|
||||
}
|
||||
if (index != -1) {
|
||||
m_currentTreeWidget = qobject_cast<AdBlockTreeWidget*>(m_ui->m_tabSubscriptions->widget(index));
|
||||
m_currentSubscription = m_currentTreeWidget->subscription();
|
||||
}
|
||||
}
|
||||
|
||||
void AdBlockDialog::enableAdBlock(bool state) {
|
||||
m_manager->setEnabled(state);
|
||||
m_manager->setEnabled(state);
|
||||
|
||||
if (state) {
|
||||
load();
|
||||
}
|
||||
if (state) {
|
||||
load();
|
||||
}
|
||||
}
|
||||
|
||||
void AdBlockDialog::aboutToShowMenu() {
|
||||
bool subscriptionEditable = m_currentSubscription && m_currentSubscription->canEditRules();
|
||||
bool subscriptionRemovable = m_currentSubscription && m_currentSubscription->canBeRemoved();
|
||||
m_actionAddRule->setEnabled(subscriptionEditable);
|
||||
m_actionRemoveRule->setEnabled(subscriptionEditable);
|
||||
m_actionRemoveSubscription->setEnabled(subscriptionRemovable);
|
||||
bool subscriptionEditable = m_currentSubscription && m_currentSubscription->canEditRules();
|
||||
bool subscriptionRemovable = m_currentSubscription && m_currentSubscription->canBeRemoved();
|
||||
m_actionAddRule->setEnabled(subscriptionEditable);
|
||||
m_actionRemoveRule->setEnabled(subscriptionEditable);
|
||||
m_actionRemoveSubscription->setEnabled(subscriptionRemovable);
|
||||
}
|
||||
|
||||
void AdBlockDialog::learnAboutRules() {
|
||||
WebFactory::instance()->openUrlInExternalBrowser(QSL("http://adblockplus.org/en/filters"));
|
||||
WebFactory::instance()->openUrlInExternalBrowser(QSL(ADBLOCK_HOWTO_FILTERS));
|
||||
}
|
||||
|
||||
void AdBlockDialog::loadSubscriptions() {
|
||||
for (int i = 0; i < m_ui->tabWidget->count(); ++i) {
|
||||
AdBlockTreeWidget* treeWidget = qobject_cast<AdBlockTreeWidget*>(m_ui->tabWidget->widget(i));
|
||||
treeWidget->refresh();
|
||||
}
|
||||
for (int i = 0; i < m_ui->m_tabSubscriptions->count(); ++i) {
|
||||
AdBlockTreeWidget* treeWidget = qobject_cast<AdBlockTreeWidget*>(m_ui->m_tabSubscriptions->widget(i));
|
||||
treeWidget->refresh();
|
||||
}
|
||||
}
|
||||
|
||||
void AdBlockDialog::load() {
|
||||
if (m_loaded || !m_ui->adblockCheckBox->isChecked()) {
|
||||
return;
|
||||
}
|
||||
if (m_loaded || !m_ui->m_cbEnable->isChecked()) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (AdBlockSubscription* subscription, m_manager->subscriptions()) {
|
||||
AdBlockTreeWidget* tree = new AdBlockTreeWidget(subscription, m_ui->tabWidget);
|
||||
m_ui->tabWidget->addTab(tree, subscription->title());
|
||||
}
|
||||
foreach (AdBlockSubscription* subscription, m_manager->subscriptions()) {
|
||||
AdBlockTreeWidget* tree = new AdBlockTreeWidget(subscription, m_ui->m_tabSubscriptions);
|
||||
m_ui->m_tabSubscriptions->addTab(tree, subscription->title());
|
||||
}
|
||||
|
||||
m_loaded = true;
|
||||
QTimer::singleShot(50, this, SLOT(loadSubscriptions()));
|
||||
m_loaded = true;
|
||||
QTimer::singleShot(50, this, SLOT(loadSubscriptions()));
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
#ifndef ADBLOCKDIALOG_H
|
||||
#define ADBLOCKDIALOG_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QDialog>
|
||||
|
||||
#include "ui_adblockdialog.h"
|
||||
|
||||
@ -29,7 +29,7 @@ class AdBlockTreeWidget;
|
||||
class AdBlockManager;
|
||||
class AdBlockRule;
|
||||
|
||||
class AdBlockDialog : public QWidget {
|
||||
class AdBlockDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
@ -9,8 +9,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>546</width>
|
||||
<height>462</height>
|
||||
<width>438</width>
|
||||
<height>424</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -18,7 +18,7 @@
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="adblockCheckBox">
|
||||
<widget class="QCheckBox" name="m_cbEnable">
|
||||
<property name="text">
|
||||
<string>Enable AdBlock</string>
|
||||
</property>
|
||||
@ -28,110 +28,27 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="adblockWidget" native="true">
|
||||
<property name="enabled">
|
||||
<widget class="QTabWidget" name="m_tabSubscriptions">
|
||||
<property name="currentIndex">
|
||||
<number>-1</number>
|
||||
</property>
|
||||
<property name="documentMode">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="4" column="0" colspan="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonOptions">
|
||||
<property name="text">
|
||||
<string>Options</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normaloff>:/icons/other/adblock.png</normaloff>:/icons/other/adblock.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>AdBlock</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>-1</number>
|
||||
</property>
|
||||
<property name="documentMode">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Close</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<widget class="QDialogButtonBox" name="m_buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Close</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>adblockCheckBox</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>adblockWidget</receiver>
|
||||
<slot>setEnabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>106</x>
|
||||
<y>39</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>349</x>
|
||||
<y>74</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@ -82,7 +82,7 @@ QAction* AdBlockIcon::menuAction() {
|
||||
m_menuAction = new QAction(tr("AdBlock"), this);
|
||||
m_menuAction->setMenu(new QMenu(this));
|
||||
connect(m_menuAction->menu(), SIGNAL(aboutToShow()), this, SLOT(createMenu()));
|
||||
connect(m_menuAction, &QAction::triggered, AdBlockManager::instance(), &AdBlockManager::showDialog);
|
||||
connect(m_menuAction, &QAction::triggered, AdBlockManager::instance(), &AdBlockManager::showDialog);
|
||||
}
|
||||
|
||||
m_menuAction->setIcon(m_enabled ? qApp->icons()->miscIcon(ADBLOCK_ICON_ACTIVE) : qApp->icons()->miscIcon(ADBLOCK_ICON_DISABLED));
|
||||
@ -122,18 +122,6 @@ void AdBlockIcon::createMenu(QMenu* menu) {
|
||||
connect(act, SIGNAL(triggered()), this, SLOT(toggleCustomFilter()));
|
||||
menu->addSeparator();
|
||||
}
|
||||
|
||||
if (!m_blockedPopups.isEmpty()) {
|
||||
menu->addAction(tr("Blocked popup windows"))->setEnabled(false);
|
||||
|
||||
for (int i = 0; i < m_blockedPopups.count(); i++) {
|
||||
const QPair<AdBlockRule*, QUrl>& pair = m_blockedPopups.at(i);
|
||||
QString address = pair.second.toString().right(55);
|
||||
QString actionText = tr("%1 with (%2)").arg(address, pair.first->filter()).replace(QL1C('&'), QL1S("&&"));
|
||||
QAction* action = menu->addAction(actionText, manager, SLOT(showRule()));
|
||||
action->setData(QVariant::fromValue((void*)pair.first));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AdBlockIcon::showMenu(const QPoint& pos) {
|
||||
|
@ -357,23 +357,10 @@ AdBlockSubscription* AdBlockManager::subscriptionByName(const QString& name) con
|
||||
return 0;
|
||||
}
|
||||
|
||||
AdBlockDialog* AdBlockManager::showDialog() {
|
||||
void AdBlockManager::showDialog() {
|
||||
if (!m_adBlockDialog) {
|
||||
m_adBlockDialog = new AdBlockDialog;
|
||||
m_adBlockDialog = new AdBlockDialog();
|
||||
}
|
||||
|
||||
m_adBlockDialog.data()->show();
|
||||
m_adBlockDialog.data()->raise();
|
||||
m_adBlockDialog.data()->activateWindow();
|
||||
return m_adBlockDialog.data();
|
||||
}
|
||||
|
||||
void AdBlockManager::showRule() {
|
||||
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
||||
const AdBlockRule* rule = static_cast<const AdBlockRule*>(action->data().value<void*>());
|
||||
|
||||
if (rule) {
|
||||
showDialog()->showRule(rule);
|
||||
}
|
||||
}
|
||||
m_adBlockDialog.data()->exec();
|
||||
}
|
||||
|
@ -75,12 +75,9 @@ class AdBlockManager : public QObject {
|
||||
|
||||
public slots:
|
||||
void setEnabled(bool enabled);
|
||||
void showRule();
|
||||
|
||||
void updateMatcher();
|
||||
void updateAllSubscriptions();
|
||||
|
||||
AdBlockDialog* showDialog();
|
||||
void showDialog();
|
||||
|
||||
private:
|
||||
inline bool canBeBlocked(const QUrl& url) const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user