Refactoring of Adblock component.

This commit is contained in:
Martin Rotter 2015-06-17 11:11:12 +02:00
parent cc9c3680c1
commit 57428510d4
19 changed files with 562 additions and 653 deletions

1
.gitignore vendored
View File

@ -21,4 +21,5 @@
*.app
# Other files.
*.autosave
*.user*

View File

@ -703,6 +703,7 @@ include_directories (
${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/src/gui
${CMAKE_SOURCE_DIR}/src/network-web
${CMAKE_SOURCE_DIR}/src/network-web/adblock
${CMAKE_SOURCE_DIR}/src/dynamic-shortcuts
${CMAKE_BINARY_DIR}/src
)

View File

@ -93,6 +93,9 @@
#define PLACEHOLDER_UNREAD_COUNTS "%unread"
#define PLACEHOLDER_ALL_COUNTS "%all"
#define ADBLOCK_FILTERS_HELP "http://adblockplus.org/en/filters"
#define ADBLOCK_EASYLIST_URL "https://easylist-downloads.adblockplus.org/easylist.txt"
#define BACKUP_NAME_SETTINGS "config"
#define BACKUP_SUFFIX_SETTINGS ".ini.backup"
#define BACKUP_NAME_DATABASE "database"

25
src/gui/formsettings.ui Normal file → Executable file
View File

@ -88,7 +88,7 @@
<item row="0" column="1">
<widget class="QStackedWidget" name="m_stackedSettings">
<property name="currentIndex">
<number>6</number>
<number>0</number>
</property>
<widget class="QWidget" name="m_pageGeneral">
<layout class="QFormLayout" name="formLayout_5">
@ -345,6 +345,11 @@ Authors of this application are NOT responsible for lost data.</string>
</item>
<item row="6" column="0" colspan="2">
<widget class="QLabel" name="m_lblMysqlInfo">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Note that speed of used MySQL server and latency of used connection medium HEAVILY influences the final performance of this application. Using slow database connections leads to bad performance when browsing feeds or messages.
@ -414,8 +419,8 @@ MySQL backend will automatically use database with name &quot;rssguard&quot;. Do
<rect>
<x>0</x>
<y>0</y>
<width>100</width>
<height>30</height>
<width>740</width>
<height>451</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
@ -492,8 +497,8 @@ MySQL backend will automatically use database with name &quot;rssguard&quot;. Do
<rect>
<x>0</x>
<y>0</y>
<width>167</width>
<height>219</height>
<width>734</width>
<height>425</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
@ -896,6 +901,11 @@ MySQL backend will automatically use database with name &quot;rssguard&quot;. Do
</item>
<item row="5" column="0" colspan="2">
<widget class="QLabel" name="m_lblMouseGestures">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Mouse gestures work with middle mouse button. Possible gestures are:
• previous web page (drag mouse left),
@ -1361,6 +1371,11 @@ MySQL backend will automatically use database with name &quot;rssguard&quot;. Do
</item>
<item row="4" column="0" colspan="2">
<widget class="QLabel" name="label_9">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Enter format for count of messages displayed next to each feed/category in feed list. Use &quot;%all&quot; and &quot;%unread&quot; strings which are placeholders for the actual count of all (or unread) messages.</string>
</property>

4
src/gui/tabwidget.h Normal file → Executable file
View File

@ -59,6 +59,10 @@ class TabWidget : public QTabWidget {
return static_cast<TabContent*>(QTabWidget::widget(index));
}
inline TabContent *currentWidget() const {
return static_cast<TabContent*>(QTabWidget::currentWidget());
}
// Initializes TabWidget with tabs, this includes initialization
// of main "Feeds" widget.
void initializeTabs();

View File

@ -1,46 +1,38 @@
/* ============================================================
* QuiteRSS is a open-source cross-platform RSS/Atom news feeds reader
* Copyright (C) 2011-2015 QuiteRSS Team <quiterssteam@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "adblockaddsubscriptiondialog.h"
#include "adblockmanager.h"
#include "ui_adblockaddsubscriptiondialog.h"
// This file is part of RSS Guard.
//
// Copyright (C) 2014-2015 by Martin Rotter <rotter.martinos@gmail.com>
// Copyright (C) 2010-2014 by David Rosca <nowrep@gmail.com>
//
// RSS Guard is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// RSS Guard is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
AdBlockAddSubscriptionDialog::AdBlockAddSubscriptionDialog(QWidget* parent)
: QDialog(parent)
, ui(new Ui::AdBlockAddSubscriptionDialog)
{
ui->setupUi(this);
#include "network-web/adblock/adblockaddsubscriptiondialog.h"
#include "network-web/adblock/adblockmanager.h"
#include "definitions/definitions.h"
#include "miscellaneous/application.h"
#include "miscellaneous/iconfactory.h"
#include "gui/lineeditwithstatus.h"
#include <QPushButton>
AdBlockAddSubscriptionDialog::AdBlockAddSubscriptionDialog(QWidget *parent)
: QDialog(parent), m_ui(new Ui::AdBlockAddSubscriptionDialog) {
m_ui->setupUi(this);
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint);
setWindowIcon(qApp->icons()->fromTheme("web-adblock"));
m_knownSubscriptions << Subscription("EasyList (English)", ADBLOCK_EASYLIST_URL)
<< Subscription("Fanboy's List (English)", "http://www.fanboy.co.nz/adblock/fanboy-adblock.txt")
@ -63,52 +55,72 @@ AdBlockAddSubscriptionDialog::AdBlockAddSubscriptionDialog(QWidget* parent)
<< Subscription("RU AdList (Russian, Ukrainian)", "https://easylist-downloads.adblockplus.org/advblock.txt")
<< Subscription("ABPindo (Indonesian)", "https://indonesianadblockrules.googlecode.com/hg/subscriptions/abpindo.txt")
<< Subscription("ChinaList (Chinese)", "http://adblock-chinalist.googlecode.com/svn/trunk/adblock.txt")
<< Subscription("Malware Domains list", "https://easylist-downloads.adblockplus.org/malwaredomains_full.txt");
<< Subscription("Malware Domains list", "https://easylist-downloads.adblockplus.org/malwaredomains_full.txt") <<
Subscription(tr("Other list"), QString());
foreach (const Subscription &subscription, m_knownSubscriptions) {
ui->comboBox->addItem(subscription.title);
m_ui->m_cmbPresets->addItem(subscription.m_title);
}
connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(indexChanged(int)));
connect(m_ui->m_cmbPresets, SIGNAL(currentIndexChanged(int)), this, SLOT(indexChanged(int)));
connect(m_ui->m_txtTitle->lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(checkInputs()));
connect(m_ui->m_txtUrl->lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(checkInputs()));
indexChanged(0);
}
QString AdBlockAddSubscriptionDialog::title() const
{
return ui->title->text();
QString AdBlockAddSubscriptionDialog::title() const {
return m_ui->m_txtTitle->lineEdit()->text();
}
QString AdBlockAddSubscriptionDialog::url() const
{
return ui->url->text();
QString AdBlockAddSubscriptionDialog::url() const {
return m_ui->m_txtUrl->lineEdit()->text();
}
void AdBlockAddSubscriptionDialog::indexChanged(int index)
{
void AdBlockAddSubscriptionDialog::indexChanged(int index) {
const Subscription subscription = m_knownSubscriptions.at(index);
// "Other..." entry
if (subscription.url.isEmpty()) {
ui->title->clear();
ui->url->clear();
// "Other" entry.
if (subscription.m_url.isEmpty()) {
m_ui->m_txtTitle->lineEdit()->clear();
m_ui->m_txtUrl->lineEdit()->clear();
}
else {
int pos = subscription.title.indexOf(QLatin1Char('('));
QString title = subscription.title;
int pos = subscription.m_title.indexOf(QLatin1Char('('));
QString title = subscription.m_title;
if (pos > 0) {
title = title.left(pos).trimmed();
}
ui->title->setText(title);
ui->title->setCursorPosition(0);
ui->url->setText(subscription.url);
ui->url->setCursorPosition(0);
m_ui->m_txtTitle->lineEdit()->setText(title);
m_ui->m_txtTitle->lineEdit()->setCursorPosition(0);
m_ui->m_txtUrl->lineEdit()->setText(subscription.m_url);
m_ui->m_txtUrl->lineEdit()->setCursorPosition(0);
}
}
AdBlockAddSubscriptionDialog::~AdBlockAddSubscriptionDialog()
{
delete ui;
void AdBlockAddSubscriptionDialog::checkInputs() {
bool is_ok = true;
if (!m_ui->m_txtTitle->lineEdit()->text().simplified().isEmpty()) {
m_ui->m_txtTitle->setStatus(WidgetWithStatus::Ok, tr("Entered title is okay."));
}
else {
m_ui->m_txtTitle->setStatus(WidgetWithStatus::Error, tr("Entered title is empty."));
is_ok = false;
}
if (!m_ui->m_txtUrl->lineEdit()->text().simplified().isEmpty()) {
m_ui->m_txtUrl->setStatus(WidgetWithStatus::Ok, tr("Entered url is okay."));
}
else {
m_ui->m_txtUrl->setStatus(WidgetWithStatus::Error, tr("Entered url is empty."));
is_ok = false;
}
m_ui->m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(is_ok);
}
AdBlockAddSubscriptionDialog::~AdBlockAddSubscriptionDialog() {
delete m_ui;
}

View File

@ -1,78 +1,68 @@
/* ============================================================
* QuiteRSS is a open-source cross-platform RSS/Atom news feeds reader
* Copyright (C) 2011-2015 QuiteRSS Team <quiterssteam@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
// This file is part of RSS Guard.
//
// Copyright (C) 2014-2015 by Martin Rotter <rotter.martinos@gmail.com>
// Copyright (C) 2010-2014 by David Rosca <nowrep@gmail.com>
//
// RSS Guard is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// RSS Guard is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
#ifndef ADBLOCKADDSUBSCRIPTIONDIALOG_H
#define ADBLOCKADDSUBSCRIPTIONDIALOG_H
#include <QDialog>
#include "ui_adblockaddsubscriptiondialog.h"
#include <QVector>
namespace Ui
{
class AdBlockAddSubscriptionDialog;
namespace Ui {
class AdBlockAddSubscriptionDialog;
}
class AdBlockAddSubscriptionDialog : public QDialog
{
Q_OBJECT
class AdBlockAddSubscriptionDialog : public QDialog {
Q_OBJECT
public:
explicit AdBlockAddSubscriptionDialog(QWidget* parent = 0);
~AdBlockAddSubscriptionDialog();
public:
// Constructors.
explicit AdBlockAddSubscriptionDialog(QWidget *parent = 0);
virtual ~AdBlockAddSubscriptionDialog();
QString title() const;
QString url() const;
QString title() const;
QString url() const;
private slots:
void indexChanged(int index);
private slots:
// Index of selected list changed.
void indexChanged(int index);
void checkInputs();
private:
Ui::AdBlockAddSubscriptionDialog* ui;
private:
struct Subscription {
public:
QString m_title;
QString m_url;
struct Subscription {
QString title;
QString url;
explicit Subscription() {
}
Subscription() {}
explicit Subscription(const QString &title, const QString &url) {
m_title = title;
m_url = url;
}
};
Subscription(const QString &t, const QString &u) {
title = t;
url = u;
}
};
QVector<Subscription> m_knownSubscriptions;
Ui::AdBlockAddSubscriptionDialog *m_ui;
QVector<Subscription> m_knownSubscriptions;
};
#endif // ADBLOCKADDSUBSCRIPTIONDIALOG_H

View File

@ -7,38 +7,32 @@
<x>0</x>
<y>0</y>
<width>557</width>
<height>162</height>
<height>142</height>
</rect>
</property>
<property name="windowTitle">
<string>Add Subscription</string>
<string>Add subscription</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="1" column="0" colspan="2">
<widget class="QComboBox" name="comboBox"/>
<layout class="QFormLayout">
<item row="0" column="0" colspan="2">
<widget class="QComboBox" name="m_cmbPresets"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label">
<item row="1" column="0">
<widget class="QLabel" name="m_lblTitle">
<property name="text">
<string>Title:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="title"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<item row="2" column="0">
<widget class="QLabel" name="m_lblUrl">
<property name="text">
<string>Address:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="url"/>
</item>
<item row="4" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<widget class="QDialogButtonBox" name="m_buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@ -47,19 +41,39 @@
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Add new subscription to AdBlock:</string>
<item row="3" column="0" colspan="2">
<spacer name="m_vertSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1">
<widget class="LineEditWithStatus" name="m_txtTitle" native="true"/>
</item>
<item row="2" column="1">
<widget class="LineEditWithStatus" name="m_txtUrl" native="true"/>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>LineEditWithStatus</class>
<extends>QWidget</extends>
<header>lineeditwithstatus.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<sender>m_buttonBox</sender>
<signal>accepted()</signal>
<receiver>AdBlockAddSubscriptionDialog</receiver>
<slot>accept()</slot>
@ -75,7 +89,7 @@
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<sender>m_buttonBox</sender>
<signal>rejected()</signal>
<receiver>AdBlockAddSubscriptionDialog</receiver>
<slot>reject()</slot>

View File

@ -1,37 +1,21 @@
/* ============================================================
* QuiteRSS is a open-source cross-platform RSS/Atom news feeds reader
* Copyright (C) 2011-2015 QuiteRSS Team <quiterssteam@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
// This file is part of RSS Guard.
//
// Copyright (C) 2014-2015 by Martin Rotter <rotter.martinos@gmail.com>
// Copyright (C) 2010-2014 by David Rosca <nowrep@gmail.com>
//
// RSS Guard is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// RSS Guard is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
/**
* Copyright (c) 2009, Benjamin C. Meyer <ben@meyerhome.net>
*
@ -60,40 +44,38 @@
* SUCH DAMAGE.
*/
#include "adblockblockednetworkreply.h"
#include "adblocksubscription.h"
#include "adblockrule.h"
#include "network-web/adblock/adblockblockednetworkreply.h"
#include "network-web/adblock/adblocksubscription.h"
#include "network-web/adblock/adblockrule.h"
#include <QNetworkRequest>
#include <QTimer>
AdBlockBlockedNetworkReply::AdBlockBlockedNetworkReply(const AdBlockRule* rule, QObject* parent)
: QNetworkReply(parent)
{
AdBlockBlockedNetworkReply::AdBlockBlockedNetworkReply(const AdBlockRule *rule, QObject *parent)
: QNetworkReply(parent) {
setOperation(QNetworkAccessManager::GetOperation);
setError(QNetworkReply::ContentAccessDenied, QString("AdBlock: %1 (%2)").arg(rule->subscription()->title(), rule->filter()));
setError(QNetworkReply::ContentAccessDenied, QString("Adblock: %1 (%2)").arg(rule->subscription()->title(), rule->filter()));
open(QIODevice::ReadOnly);
QTimer::singleShot(0, this, SLOT(delayedFinished()));
}
void AdBlockBlockedNetworkReply::setRequest(const QNetworkRequest &request)
{
void AdBlockBlockedNetworkReply::abort() {
}
void AdBlockBlockedNetworkReply::setRequest(const QNetworkRequest &request) {
QNetworkReply::setRequest(request);
setUrl(request.url());
}
qint64 AdBlockBlockedNetworkReply::readData(char* data, qint64 maxSize)
{
qint64 AdBlockBlockedNetworkReply::readData(char *data, qint64 maxSize) {
Q_UNUSED(data);
Q_UNUSED(maxSize);
return -1;
}
void AdBlockBlockedNetworkReply::delayedFinished()
{
void AdBlockBlockedNetworkReply::delayedFinished() {
emit error(QNetworkReply::ContentAccessDenied);
emit finished();
}

View File

@ -1,37 +1,21 @@
/* ============================================================
* QuiteRSS is a open-source cross-platform RSS/Atom news feeds reader
* Copyright (C) 2011-2015 QuiteRSS Team <quiterssteam@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
// This file is part of RSS Guard.
//
// Copyright (C) 2014-2015 by Martin Rotter <rotter.martinos@gmail.com>
// Copyright (C) 2010-2014 by David Rosca <nowrep@gmail.com>
//
// RSS Guard is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// RSS Guard is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
/**
* Copyright (c) 2009, Benjamin C. Meyer <ben@meyerhome.net>
*
@ -65,25 +49,24 @@
#include <QNetworkReply>
class AdBlockRule;
class AdBlockSubscription;
class AdBlockBlockedNetworkReply : public QNetworkReply
{
Q_OBJECT
class AdBlockBlockedNetworkReply : public QNetworkReply{
Q_OBJECT
public:
AdBlockBlockedNetworkReply(const AdBlockRule* rule, QObject* parent = 0);
void abort() {}
public:
explicit AdBlockBlockedNetworkReply(const AdBlockRule *rule, QObject *parent = 0);
void setRequest(const QNetworkRequest &request);
void abort();
void setRequest(const QNetworkRequest &request);
protected:
qint64 readData(char* data, qint64 maxSize);
private slots:
void delayedFinished();
protected:
qint64 readData(char *data, qint64 maxSize);
private slots:
void delayedFinished();
};
#endif // ADBLOCKBLOCKEDNETWORKREPLY_H

View File

@ -1,42 +1,31 @@
/* ============================================================
* QuiteRSS is a open-source cross-platform RSS/Atom news feeds reader
* Copyright (C) 2011-2015 QuiteRSS Team <quiterssteam@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "adblockdialog.h"
#include "adblockmanager.h"
#include "adblocksubscription.h"
#include "adblocktreewidget.h"
#include "adblockaddsubscriptiondialog.h"
// This file is part of RSS Guard.
//
// Copyright (C) 2014-2015 by Martin Rotter <rotter.martinos@gmail.com>
// Copyright (C) 2010-2014 by David Rosca <nowrep@gmail.com>
//
// RSS Guard is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// RSS Guard is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// 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 "miscellaneous/application.h"
#include "miscellaneous/iconfactory.h"
#include "gui/tabwidget.h"
#include "gui/formmain.h"
#include <QDesktopWidget>
#include <QMenu>
@ -44,98 +33,99 @@
#include <QMessageBox>
#include <QInputDialog>
AdBlockDialog::AdBlockDialog(QWidget* parent)
: QWidget(parent)
, m_manager(AdBlockManager::instance())
, m_currentTreeWidget(0)
, m_currentSubscription(0)
, m_loaded(false)
, m_useLimitedEasyList(false)
{
AdBlockDialog::AdBlockDialog(QWidget* parent) : QDialog(parent), m_ui(new Ui::AdBlockDialog),
m_manager(AdBlockManager::instance()), m_currentTreeWidget(NULL),
m_currentSubscription(NULL), m_loaded(false), m_useLimitedEasyList(false) {
m_ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
setupUi(this);
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint);
setWindowIcon(qApp->icons()->fromTheme("web-adblock"));
const QRect screen = QApplication::desktop()->screenGeometry();
const QRect size = geometry();
move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2);
tabWidget->setDocumentMode(false);
#ifdef Q_OS_MAC
tabWidget->setDocumentMode(false);
#endif
adblockCheckBox->setChecked(m_manager->isEnabled());
m_ui->m_checkEnable->setChecked(m_manager->isEnabled());
m_ui->m_checkUseLimitedEasyList->setVisible(false);
m_ui->m_btnOptions->setIcon(qApp->icons()->fromTheme("web-adblock"));
m_ui->m_btnOptions->setText(m_ui->m_btnOptions->text() + " ");
buttonOptions->setText(buttonOptions->text() % " ");
// Setup the menu.
setupMenu();
QMenu* menu = new QMenu(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()));
buttonOptions->setMenu(menu);
connect(menu, SIGNAL(aboutToShow()), this, SLOT(aboutToShowMenu()));
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)));
connect(buttonBox, SIGNAL(accepted()), this, SLOT(close()));
// Initialize connections.
createConnections();
// Load the contents.
load();
buttonBox->setFocus();
m_ui->m_buttonBox->setFocus();
}
AdBlockDialog::~AdBlockDialog() {
qDebug("Destroying AdBlockDialog instance.");
delete m_ui;
}
void AdBlockDialog::showRule(const AdBlockRule* rule) const
{
void AdBlockDialog::setupMenu() {
QMenu *menu = new QMenu(m_ui->m_btnOptions);
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("Rules writing guide"), this, SLOT(learnAboutRules()));
m_ui->m_btnOptions->setMenu(menu);
}
void AdBlockDialog::createConnections() {
connect(m_ui->m_btnOptions->menu(), SIGNAL(aboutToShow()), this, SLOT(aboutToShowMenu()));
connect(m_ui->m_checkEnable, SIGNAL(toggled(bool)), this, SLOT(enableAdBlock(bool)));
connect(m_ui->m_txtFilter, SIGNAL(textChanged(QString)), this, SLOT(filterString(QString)));
connect(m_ui->m_tabs, SIGNAL(currentChanged(int)), this, SLOT(currentChanged(int)));
connect(m_ui->m_buttonBox, SIGNAL(accepted()), this, SLOT(close()));
}
void AdBlockDialog::showRule(const AdBlockRule* rule) const {
AdBlockSubscription* subscription = rule->subscription();
if (!subscription) {
if (subscription == NULL) {
return;
}
for (int i = 0; i < tabWidget->count(); ++i) {
AdBlockTreeWidget* treeWidget = qobject_cast<AdBlockTreeWidget*>(tabWidget->widget(i));
for (int i = 0; i < m_ui->m_tabs->count(); i++) {
AdBlockTreeWidget* treeWidget = qobject_cast<AdBlockTreeWidget*>(m_ui->m_tabs->widget(i));
if (subscription == treeWidget->subscription()) {
treeWidget->showRule(rule);
tabWidget->setCurrentIndex(i);
m_ui->m_tabs->setCurrentIndex(i);
break;
}
}
}
void AdBlockDialog::addRule()
{
void AdBlockDialog::addRule() {
m_currentTreeWidget->addRule();
}
void AdBlockDialog::removeRule()
{
void AdBlockDialog::removeRule() {
m_currentTreeWidget->removeRule();
}
void AdBlockDialog::addSubscription()
{
void AdBlockDialog::addSubscription() {
AdBlockAddSubscriptionDialog dialog(this);
if (dialog.exec() != QDialog::Accepted) {
return;
}
QString title = dialog.title();
QString url = dialog.url();
if (dialog.exec() == QDialog::Accepted) {
QString title = dialog.title();
QString url = dialog.url();
if (AdBlockSubscription* subscription = m_manager->addSubscription(title, url)) {
AdBlockTreeWidget* tree = new AdBlockTreeWidget(subscription, tabWidget);
int index = tabWidget->insertTab(tabWidget->count() - 1, tree, subscription->title());
if (AdBlockSubscription *subscription = m_manager->addSubscription(title, url)) {
AdBlockTreeWidget *tree = new AdBlockTreeWidget(subscription, m_ui->m_tabs);
int index = m_ui->m_tabs->insertTab(m_ui->m_tabs->count() - 1, tree, subscription->title());
tabWidget->setCurrentIndex(index);
m_ui->m_tabs->setCurrentIndex(index);
}
}
}
@ -146,26 +136,24 @@ void AdBlockDialog::removeSubscription()
}
}
void AdBlockDialog::currentChanged(int index)
{
void AdBlockDialog::currentChanged(int index) {
if (index != -1) {
m_currentTreeWidget = qobject_cast<AdBlockTreeWidget*>(tabWidget->widget(index));
m_currentTreeWidget = qobject_cast<AdBlockTreeWidget*>(m_ui->m_tabs->widget(index));
m_currentSubscription = m_currentTreeWidget->subscription();
bool isEasyList = m_currentSubscription->url() == QUrl(ADBLOCK_EASYLIST_URL);
useLimitedEasyList->setVisible(isEasyList);
bool is_easylist = m_currentSubscription->url() == QUrl(ADBLOCK_EASYLIST_URL);
m_ui->m_checkUseLimitedEasyList->setEnabled(is_easylist && m_ui->m_checkEnable->isChecked());
m_ui->m_checkUseLimitedEasyList->setVisible(is_easylist);
}
}
void AdBlockDialog::filterString(const QString &string)
{
if (m_currentTreeWidget && adblockCheckBox->isChecked()) {
void AdBlockDialog::filterString(const QString &string) {
if (m_currentTreeWidget && m_ui->m_checkEnable->isChecked()) {
m_currentTreeWidget->filterString(string);
}
}
void AdBlockDialog::enableAdBlock(bool state)
{
void AdBlockDialog::enableAdBlock(bool state) {
m_manager->setEnabled(state);
if (state) {
@ -173,8 +161,7 @@ void AdBlockDialog::enableAdBlock(bool state)
}
}
void AdBlockDialog::aboutToShowMenu()
{
void AdBlockDialog::aboutToShowMenu() {
bool subscriptionEditable = m_currentSubscription && m_currentSubscription->canEditRules();
bool subscriptionRemovable = m_currentSubscription && m_currentSubscription->canBeRemoved();
@ -183,34 +170,30 @@ void AdBlockDialog::aboutToShowMenu()
m_actionRemoveSubscription->setEnabled(subscriptionRemovable);
}
void AdBlockDialog::learnAboutRules()
{
// TODO
//mainApp->mainWindow()->openNewsTab_ = NEW_TAB_FOREGROUND;
//mainApp->mainWindow()->createWebTab(QUrl("http://adblockplus.org/en/filters"));
void AdBlockDialog::learnAboutRules() {
qApp->mainForm()->tabWidget()->addBrowser(true, true, QUrl(ADBLOCK_FILTERS_HELP));
QTimer::singleShot(100, this, SLOT(close()));
}
void AdBlockDialog::loadSubscriptions()
{
for (int i = 0; i < tabWidget->count(); ++i) {
AdBlockTreeWidget* treeWidget = qobject_cast<AdBlockTreeWidget*>(tabWidget->widget(i));
treeWidget->refresh();
void AdBlockDialog::loadSubscriptions() {
for (int i = 0; i < m_ui->m_tabs->count(); ++i) {
qobject_cast<AdBlockTreeWidget*>(m_ui->m_tabs->widget(i))->refresh();
}
}
void AdBlockDialog::load()
{
if (m_loaded || !adblockCheckBox->isChecked()) {
if (m_loaded || !m_ui->m_checkEnable->isChecked()) {
return;
}
foreach (AdBlockSubscription* subscription, m_manager->subscriptions()) {
AdBlockTreeWidget* tree = new AdBlockTreeWidget(subscription, tabWidget);
tabWidget->addTab(tree, subscription->title());
AdBlockTreeWidget* tree = new AdBlockTreeWidget(subscription, m_ui->m_tabs);
m_ui->m_tabs->addTab(tree, subscription->title());
}
m_useLimitedEasyList = m_manager->useLimitedEasyList();
useLimitedEasyList->setChecked(m_useLimitedEasyList);
m_ui->m_checkUseLimitedEasyList->setChecked(m_useLimitedEasyList);
m_loaded = true;
@ -219,8 +202,8 @@ void AdBlockDialog::load()
void AdBlockDialog::closeEvent(QCloseEvent* ev)
{
if (useLimitedEasyList->isChecked() != m_useLimitedEasyList) {
m_manager->setUseLimitedEasyList(useLimitedEasyList->isChecked());
if (m_ui->m_checkUseLimitedEasyList->isChecked() != m_useLimitedEasyList) {
m_manager->setUseLimitedEasyList(m_ui->m_checkUseLimitedEasyList->isChecked());
}
QWidget::closeEvent(ev);

View File

@ -1,58 +1,47 @@
/* ============================================================
* QuiteRSS is a open-source cross-platform RSS/Atom news feeds reader
* Copyright (C) 2011-2015 QuiteRSS Team <quiterssteam@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
// This file is part of RSS Guard.
//
// Copyright (C) 2011-2015 by Martin Rotter <rotter.martinos@gmail.com>
// Copyright (C) 2010-2014 by David Rosca <nowrep@gmail.com>
//
// RSS Guard is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// RSS Guard is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
#ifndef ADBLOCKDIALOG_H
#define ADBLOCKDIALOG_H
#include <QWidget>
#include <QDialog>
#include "ui_adblockdialog.h"
namespace Ui {
class AdBlockDialog;
}
class AdBlockSubscription;
class AdBlockTreeWidget;
class AdBlockManager;
class AdBlockRule;
class AdBlockDialog : public QWidget, public Ui_AdBlockDialog
{
class AdBlockDialog : public QDialog {
Q_OBJECT
public:
explicit AdBlockDialog(QWidget* parent = 0);
// Constructors.
explicit AdBlockDialog(QWidget *parent = 0);
virtual ~AdBlockDialog();
void showRule(const AdBlockRule* rule) const;
void showRule(const AdBlockRule *rule) const;
private slots:
void addRule();
@ -71,9 +60,14 @@ class AdBlockDialog : public QWidget, public Ui_AdBlockDialog
void loadSubscriptions();
void load();
private:
protected:
void closeEvent(QCloseEvent* ev);
private:
void setupMenu();
void createConnections();
Ui::AdBlockDialog *m_ui;
AdBlockManager* m_manager;
AdBlockTreeWidget* m_currentTreeWidget;
AdBlockSubscription* m_currentSubscription;
@ -88,4 +82,3 @@ class AdBlockDialog : public QWidget, public Ui_AdBlockDialog
};
#endif // ADBLOCKDIALOG_H

View File

@ -1,23 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AdBlockDialog</class>
<widget class="QWidget" name="AdBlockDialog">
<widget class="QDialog" name="AdBlockDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>546</width>
<height>462</height>
<width>451</width>
<height>408</height>
</rect>
</property>
<property name="windowTitle">
<string>AdBlock Configuration</string>
<string>Adblock settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="adblockCheckBox">
<widget class="QCheckBox" name="m_checkEnable">
<property name="text">
<string>Enable AdBlock</string>
<string>Enable Adblock</string>
</property>
<property name="checked">
<bool>true</bool>
@ -25,34 +25,22 @@
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLineEdit" name="search">
<property name="placeholderText">
<string>Search...</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>50</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
<widget class="QLabel" name="m_lblInfo">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Note that Adblock may significantly slow this application down once you activate huge subscriptions. Too many rules is not good for performance. Also, make sure you restart application after you disable Adblock if you wish to have low memory footprint. Adblock is known to use much system memory.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="adblockWidget" native="true">
<widget class="QWidget" name="m_adBlockWidget" native="true">
<property name="enabled">
<bool>true</bool>
</property>
@ -72,12 +60,19 @@
<item row="4" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="buttonOptions">
<widget class="QPushButton" name="m_btnOptions">
<property name="text">
<string>Options</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="m_txtFilter">
<property name="placeholderText">
<string>Filter rules</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
@ -91,30 +86,10 @@
</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>
<widget class="QTabWidget" name="m_tabs"/>
</item>
</layout>
</widget>
@ -122,14 +97,17 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QCheckBox" name="useLimitedEasyList">
<widget class="QCheckBox" name="m_checkUseLimitedEasyList">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Use only essential part of EasyList (for performance reasons)</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<widget class="QDialogButtonBox" name="m_buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@ -145,9 +123,9 @@
<resources/>
<connections>
<connection>
<sender>adblockCheckBox</sender>
<sender>m_checkEnable</sender>
<signal>toggled(bool)</signal>
<receiver>adblockWidget</receiver>
<receiver>m_adBlockWidget</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
@ -161,7 +139,7 @@
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<sender>m_buttonBox</sender>
<signal>clicked(QAbstractButton*)</signal>
<receiver>AdBlockDialog</receiver>
<slot>close()</slot>

View File

@ -1,37 +1,21 @@
/* ============================================================
* QuiteRSS is a open-source cross-platform RSS/Atom news feeds reader
* Copyright (C) 2011-2015 QuiteRSS Team <quiterssteam@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
// This file is part of RSS Guard.
//
// Copyright (C) 2014-2015 by Martin Rotter <rotter.martinos@gmail.com>
// Copyright (C) 2010-2014 by David Rosca <nowrep@gmail.com>
//
// RSS Guard is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// RSS Guard is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
#include "network-web/adblock/adblockicon.h"
#include "network-web/adblock/adblockrule.h"
@ -39,7 +23,6 @@
#include "network-web/adblock/adblocksubscription.h"
#include "network-web/webpage.h"
#include "network-web/webbrowser.h"
#include "miscellaneous/application.h"
#include "gui/plaintoolbutton.h"
#include "gui/formmain.h"
@ -52,20 +35,17 @@
AdBlockIcon::AdBlockIcon(QWidget *window, QWidget *parent)
: PlainToolButton(parent), m_window(window), m_menuAction(0), m_flashTimer(0), m_timerTicks(0), m_enabled(false) {
setToolTip(tr("Adblock lets you block unwanted content on web pages."));
: PlainToolButton(parent), m_window(window), m_menuAction(NULL), m_flashTimer(NULL), m_timerTicks(NULL), m_enabled(false) {
connect(this, SIGNAL(clicked(QPoint)), this, SLOT(showMenu(QPoint)));
connect(AdBlockManager::instance(), SIGNAL(enabledChanged(bool)), this, SLOT(setEnabled(bool)));
}
void AdBlockIcon::popupBlocked(const QString &ruleString, const QUrl &url)
{
int index = ruleString.lastIndexOf(QLatin1String(" ("));
void AdBlockIcon::popupBlocked(const QString &rule_string, const QUrl &url) {
int index = rule_string.lastIndexOf(QLatin1String(" ("));
const QString subscription_ame = rule_string.left(index);
const QString filter = rule_string.mid(index + 2, rule_string.size() - index - 3);
AdBlockSubscription* subscription = AdBlockManager::instance()->subscriptionByName(subscription_ame);
const QString subscriptionName = ruleString.left(index);
const QString filter = ruleString.mid(index + 2, ruleString.size() - index - 3);
AdBlockSubscription* subscription = AdBlockManager::instance()->subscriptionByName(subscriptionName);
if (filter.isEmpty() || !subscription) {
return;
}
@ -78,7 +58,7 @@ void AdBlockIcon::popupBlocked(const QString &ruleString, const QUrl &url)
//!** FIXME
// mApp->desktopNotifications()->showNotification(QPixmap(":images/images/adblock_big.png"), tr("Blocked popup window"), tr("AdBlock blocked unwanted popup window."));
if (!m_flashTimer) {
if (m_flashTimer == NULL) {
m_flashTimer = new QTimer(this);
}
@ -92,21 +72,20 @@ void AdBlockIcon::popupBlocked(const QString &ruleString, const QUrl &url)
connect(m_flashTimer, SIGNAL(timeout()), this, SLOT(animateIcon()));
}
QAction* AdBlockIcon::menuAction()
{
if (!m_menuAction) {
m_menuAction = new QAction(tr("AdBlock"), this);
m_menuAction->setMenu(new QMenu);
QAction *AdBlockIcon::menuAction() {
if (m_menuAction == NULL) {
m_menuAction = new QAction(tr("Adblock"), this);
m_menuAction->setMenu(new QMenu(this));
connect(m_menuAction->menu(), SIGNAL(aboutToShow()), this, SLOT(createMenu()));
}
m_menuAction->setIcon(QIcon(m_enabled ? ":images/images/adblock.png" : ":images/images/adblock-disabled.png"));
m_menuAction->setIcon(m_enabled ? qApp->icons()->fromTheme("web-adblock") : qApp->icons()->fromTheme("web-adblock"));
return m_menuAction;
}
void AdBlockIcon::createMenu(QMenu *menu)
{
void AdBlockIcon::createMenu(QMenu *menu) {
if (menu == NULL) {
menu = qobject_cast<QMenu*>(sender());
@ -118,43 +97,47 @@ void AdBlockIcon::createMenu(QMenu *menu)
menu->clear();
AdBlockManager *manager = AdBlockManager::instance();
AdBlockCustomList *customList = manager->customList();
AdBlockCustomList *custom_list = manager->customList();
WebPage* page = qApp->mainForm()->tabWidget()->widget(qApp->mainForm()->tabWidget()->currentIndex())->webBrowser()->view()->page();
const QUrl pageUrl = page->mainFrame()->url();
WebPage* page = qApp->mainForm()->tabWidget()->currentWidget()->webBrowser()->view()->page();
const QUrl page_url = page->mainFrame()->url();
menu->addAction(tr("Show Adblock &settings"), manager, SLOT(showDialog()));
menu->addSeparator();
if (!pageUrl.host().isEmpty() && m_enabled && manager->canRunOnScheme(pageUrl.scheme())) {
const QString host = pageUrl.host().contains(QLatin1String("www.")) ? pageUrl.host().mid(4) : pageUrl.host();
const QString hostFilter = QString("@@||%1^$document").arg(host);
const QString pageFilter = QString("@@|%1|$document").arg(pageUrl.toString());
if (!page_url.host().isEmpty() && m_enabled && manager->canRunOnScheme(page_url.scheme())) {
const QString host = page_url.host().contains(QLatin1String("www.")) ? page_url.host().mid(4) : page_url.host();
const QString host_filter = QString("@@||%1^$document").arg(host);
const QString page_filter = QString("@@|%1|$document").arg(page_url.toString());
QAction* act = menu->addAction(tr("Disable on %1").arg(host));
QAction *act;
act = menu->addAction(tr("Disable on %1").arg(host));
act->setCheckable(true);
act->setChecked(customList->containsFilter(hostFilter));
act->setData(hostFilter);
act->setChecked(custom_list->containsFilter(host_filter));
act->setData(host_filter);
connect(act, SIGNAL(triggered()), this, SLOT(toggleCustomFilter()));
act = menu->addAction(tr("Disable only on this page"));
act->setCheckable(true);
act->setChecked(customList->containsFilter(pageFilter));
act->setData(pageFilter);
act->setChecked(custom_list->containsFilter(page_filter));
act->setData(page_filter);
connect(act, SIGNAL(triggered()), this, SLOT(toggleCustomFilter()));
menu->addSeparator();
}
if (!m_blockedPopups.isEmpty()) {
menu->addAction(tr("Blocked Popup Windows"))->setEnabled(false);
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);
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(QLatin1Char('&'), QLatin1String("&&"));
QString actionText = tr("%1 with (%2)").arg(address,
pair.first->filter()).replace(QLatin1Char('&'), QLatin1String("&&"));
QAction* action = menu->addAction(actionText, manager, SLOT(showRule()));
QAction *action = menu->addAction(actionText, manager, SLOT(showRule()));
action->setData(QVariant::fromValue((void*)pair.first));
}
}
@ -162,98 +145,96 @@ void AdBlockIcon::createMenu(QMenu *menu)
menu->addSeparator();
QVector<WebPage::AdBlockedEntry> entries = page->adBlockedEntries();
if (entries.isEmpty()) {
menu->addAction(tr("No content blocked"))->setEnabled(false);
}
else {
menu->addAction(tr("Blocked URL (AdBlock Rule) - click to edit rule"))->setEnabled(false);
menu->addAction(tr("Blocked some content - click to edit rule"))->setEnabled(false);
foreach (const WebPage::AdBlockedEntry &entry, entries) {
QString address = entry.url.toString().right(55);
QString actionText = tr("%1 with (%2)").arg(address, entry.rule->filter()).replace(QLatin1Char('&'), QLatin1String("&&"));
QString action_text = tr("%1 with (%2)").arg(address,
entry.rule->filter()).replace(QLatin1Char('&'), QLatin1String("&&"));
QAction* action = menu->addAction(actionText, manager, SLOT(showRule()));
QAction *action = menu->addAction(action_text, manager, SLOT(showRule()));
action->setData(QVariant::fromValue((void*)entry.rule));
}
}
}
void AdBlockIcon::showMenu(const QPoint &pos)
{
void AdBlockIcon::showMenu(const QPoint &pos) {
QMenu menu;
createMenu(&menu);
menu.exec(pos);
}
void AdBlockIcon::toggleCustomFilter()
{
QAction* action = qobject_cast<QAction*>(sender());
if (!action) {
void AdBlockIcon::toggleCustomFilter() {
QAction *action = qobject_cast<QAction*>(sender());
if (action == NULL) {
return;
}
const QString filter = action->data().toString();
AdBlockManager* manager = AdBlockManager::instance();
AdBlockCustomList* customList = manager->customList();
AdBlockCustomList* custom_list = manager->customList();
if (customList->containsFilter(filter)) {
customList->removeFilter(filter);
if (custom_list->containsFilter(filter)) {
custom_list->removeFilter(filter);
}
else {
AdBlockRule* rule = new AdBlockRule(filter, customList);
customList->addRule(rule);
AdBlockRule *rule = new AdBlockRule(filter, custom_list);
custom_list->addRule(rule);
}
}
void AdBlockIcon::animateIcon()
{
++m_timerTicks;
void AdBlockIcon::animateIcon() {
m_timerTicks++;
if (m_timerTicks > 10) {
stopAnimation();
return;
}
if (icon().isNull()) {
setIcon(QIcon(":images/images/adblock.png"));
setIcon(qApp->icons()->fromTheme("web-adblock"));
}
else {
setIcon(QIcon());
}
}
void AdBlockIcon::stopAnimation()
{
void AdBlockIcon::stopAnimation() {
m_timerTicks = 0;
m_flashTimer->stop();
disconnect(m_flashTimer, SIGNAL(timeout()), this, SLOT(animateIcon()));
disconnect(m_flashTimer, SIGNAL(timeout()), this, SLOT(animateIcon()));
setEnabled(m_enabled);
}
void AdBlockIcon::setEnabled(bool enabled)
{
void AdBlockIcon::setEnabled(bool enabled) {
if (enabled) {
setToolTip(tr("Adblock - up and running"));
setIcon(qApp->icons()->fromTheme("web-adblock"));
}
else {
setToolTip(tr("Adblock - not running"));
setIcon(qApp->icons()->fromTheme("web-adblock-disabled"));
}
m_enabled = enabled;
}
void AdBlockIcon::mouseReleaseEvent(QMouseEvent* event)
{
if (event->button() == Qt::LeftButton && rect().contains(event->pos())) {
if (event->modifiers() != Qt::ControlModifier) {
void AdBlockIcon::mouseReleaseEvent(QMouseEvent *event) {
if (event->button() == Qt::LeftButton) {
emit clicked(event->globalPos());
}
}
else {
QToolButton::mouseReleaseEvent(event);
}
}
AdBlockIcon::~AdBlockIcon()
{
AdBlockIcon::~AdBlockIcon() {
qDebug("Destroying AdBlockIcon instance.");
}

View File

@ -1,37 +1,21 @@
/* ============================================================
* QuiteRSS is a open-source cross-platform RSS/Atom news feeds reader
* Copyright (C) 2011-2015 QuiteRSS Team <quiterssteam@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
// This file is part of RSS Guard.
//
// Copyright (C) 2014-2015 by Martin Rotter <rotter.martinos@gmail.com>
// Copyright (C) 2010-2014 by David Rosca <nowrep@gmail.com>
//
// RSS Guard is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// RSS Guard is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
#ifndef ADBLOCKICON_H
#define ADBLOCKICON_H
@ -44,12 +28,13 @@ class AdBlockRule;
class AdBlockIcon : public PlainToolButton {
Q_OBJECT
public:
// Constructors.
explicit AdBlockIcon(QWidget *window, QWidget *parent = 0);
virtual ~AdBlockIcon();
void popupBlocked(const QString &ruleString, const QUrl &url);
void popupBlocked(const QString &rule_string, const QUrl &url);
QAction *menuAction();
public slots:
@ -59,7 +44,6 @@ class AdBlockIcon : public PlainToolButton {
private slots:
void showMenu(const QPoint &pos);
void toggleCustomFilter();
void animateIcon();
void stopAnimation();
@ -71,10 +55,10 @@ class AdBlockIcon : public PlainToolButton {
private:
QWidget *m_window;
QAction* m_menuAction;
QAction *m_menuAction;
QVector<QPair<AdBlockRule*, QUrl> > m_blockedPopups;
QTimer* m_flashTimer;
QVector<QPair<AdBlockRule*,QUrl>> m_blockedPopups;
QTimer *m_flashTimer;
int m_timerTicks;
bool m_enabled;

View File

@ -58,26 +58,20 @@
#include <QElapsedTimer>
#endif
AdBlockManager* AdBlockManager::s_adBlockManager = 0;
AdBlockManager* AdBlockManager::s_adBlockManager = NULL;
AdBlockManager::AdBlockManager(QObject* parent)
: QObject(parent)
, m_loaded(false)
, m_enabled(true)
, m_useLimitedEasyList(true)
, m_matcher(new AdBlockMatcher(this)), m_subscriptions(QList<AdBlockSubscription*>())
{
: QObject(parent), m_loaded(false), m_enabled(false), m_useLimitedEasyList(true),
m_matcher(new AdBlockMatcher(this)), m_subscriptions(QList<AdBlockSubscription*>()) {
load();
}
AdBlockManager::~AdBlockManager()
{
AdBlockManager::~AdBlockManager() {
qDeleteAll(m_subscriptions);
}
AdBlockManager* AdBlockManager::instance()
{
if (!s_adBlockManager) {
AdBlockManager* AdBlockManager::instance() {
if (s_adBlockManager == NULL) {
s_adBlockManager = new AdBlockManager(SilentNetworkAccessManager::instance());
}
@ -132,6 +126,7 @@ void AdBlockManager::setEnabled(bool enabled)
}
m_enabled = enabled;
emit enabledChanged(enabled);
Settings *settings = qApp->settings();
@ -139,7 +134,10 @@ void AdBlockManager::setEnabled(bool enabled)
settings->setValue("enabled", m_enabled);
settings->endGroup();
// Load subscriptions and other data.
load();
// Inform others (mainly ICON and MATCHER), that there are some changes.
// TODO
//mainApp->reloadUserStyleBrowser();
}
@ -207,10 +205,10 @@ void AdBlockManager::removeDisabledRule(const QString &filter)
m_disabledRules.removeOne(filter);
}
AdBlockSubscription* AdBlockManager::addSubscription(const QString &title, const QString &url)
AdBlockSubscription *AdBlockManager::addSubscription(const QString &title, const QString &url)
{
if (title.isEmpty() || url.isEmpty()) {
return 0;
return NULL;
}
QString fileName = filterCharsFromFilename(title.toLower()) + ".txt";
@ -281,6 +279,7 @@ void AdBlockManager::load()
QDateTime lastUpdate = settings->value("AdBlock","lastUpdate", QDateTime()).toDateTime();
if (!m_enabled) {
// We loaded settings, but Adblock should be disabled. Do not continue to save memory.
return;
}
@ -447,22 +446,12 @@ AdBlockSubscription* AdBlockManager::subscriptionByName(const QString &name) con
}
AdBlockDialog *AdBlockManager::showDialog() {
QPointer<AdBlockDialog> form_pointer = new AdBlockDialog();
QPointer<AdBlockDialog> form_pointer = new AdBlockDialog(qApp->mainForm());
form_pointer.data()->show();
form_pointer.data()->raise();
form_pointer.data()->activateWindow();
form_pointer.data()->setAttribute(Qt::WA_DeleteOnClose, true);
return form_pointer.data();
/*
if (!m_adBlockDialog) {
m_adBlockDialog = new AdBlockDialog;
}
m_adBlockDialog.data()->show();
m_adBlockDialog.data()->raise();
m_adBlockDialog.data()->activateWindow();
return m_adBlockDialog.data();*/
}
void AdBlockManager::showRule()

View File

@ -35,8 +35,6 @@
#ifndef ADBLOCKMANAGER_H
#define ADBLOCKMANAGER_H
#define ADBLOCK_EASYLIST_URL "https://easylist-downloads.adblockplus.org/easylist.txt"
#ifndef QSL
#if QT_VERSION >= 0x050000
#define QSL(x) QStringLiteral(x)
@ -103,7 +101,7 @@ class AdBlockManager : public QObject
void addDisabledRule(const QString &filter);
void removeDisabledRule(const QString &filter);
AdBlockSubscription* addSubscription(const QString &title, const QString &url);
AdBlockSubscription *addSubscription(const QString &title, const QString &url);
bool removeSubscription(AdBlockSubscription* subscription);
AdBlockCustomList* customList() const;
@ -126,11 +124,10 @@ class AdBlockManager : public QObject
bool m_useLimitedEasyList;
QList<AdBlockSubscription*> m_subscriptions;
static AdBlockManager* s_adBlockManager;
AdBlockMatcher* m_matcher;
QStringList m_disabledRules;
QPointer<AdBlockDialog> m_adBlockDialog;
static AdBlockManager* s_adBlockManager;
};
#endif // ADBLOCKMANAGER_H

View File

@ -37,10 +37,7 @@
#include "adblockrule.h"
#include "adblocksubscription.h"
AdBlockMatcher::AdBlockMatcher(AdBlockManager* manager)
: QObject(manager)
, m_manager(manager)
{
AdBlockMatcher::AdBlockMatcher(AdBlockManager* manager) : QObject(manager), m_manager(manager) {
connect(manager, SIGNAL(enabledChanged(bool)), this, SLOT(enabledChanged(bool)));
}
@ -117,7 +114,7 @@ QString AdBlockMatcher::elementHidingRulesForDomain(const QString &domain) const
if (!rule->matchDomain(domain))
continue;
if (Q_UNLIKELY(addedRulesCount == 1000)) {
if (addedRulesCount == 1000) {
rules.append(rule->cssSelector());
rules.append(QLatin1String("{display:none !important;}\n"));
addedRulesCount = 0;
@ -205,7 +202,7 @@ void AdBlockMatcher::update()
if (rule->isDomainRestricted()) {
m_domainRestrictedCssRules.append(rule);
}
else if (Q_UNLIKELY(hidingRulesCount == 1000)) {
else if (hidingRulesCount == 1000) {
m_elementHidingRules.append(rule->cssSelector());
m_elementHidingRules.append(QLatin1String("{display:none !important;} "));
hidingRulesCount = 0;
@ -238,8 +235,10 @@ void AdBlockMatcher::clear()
void AdBlockMatcher::enabledChanged(bool enabled)
{
if (enabled)
if (enabled) {
update();
else
}
else {
clear();
}
}

View File

@ -74,7 +74,7 @@ class AdBlockSubscription;
class AdBlockRule
{
public:
AdBlockRule(const QString &filter = QString(), AdBlockSubscription* subscription = 0);
AdBlockRule(const QString &filter = QString(), AdBlockSubscription* subscription = NULL);
~AdBlockRule();
AdBlockRule* copy() const;