mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
Initial AdBlock support
This commit is contained in:
parent
af92a1897e
commit
943d89870d
|
@ -21,7 +21,8 @@
|
||||||
Some files in 3rdparty/ folder are under different licenses
|
Some files in 3rdparty/ folder are under different licenses
|
||||||
|
|
||||||
-----------------------------------------------------------
|
-----------------------------------------------------------
|
||||||
lineedit.h, lineedit.cpp, squeezelabel.h, squeezelabel.cpp:
|
lineedit.h, lineedit.cpp, squeezelabel.h, squeezelabel.cpp
|
||||||
|
and all files in adblock/ folder:
|
||||||
-----------------------------------------------------------
|
-----------------------------------------------------------
|
||||||
* Copyright (c) 2008 - 2009, Benjamin C. Meyer <ben@meyerhome.net>
|
* Copyright (c) 2008 - 2009, Benjamin C. Meyer <ben@meyerhome.net>
|
||||||
*
|
*
|
||||||
|
|
0
plugins/AdBlock/adblockplugin.cpp
Normal file
0
plugins/AdBlock/adblockplugin.cpp
Normal file
0
plugins/AdBlock/adblockplugin.h
Normal file
0
plugins/AdBlock/adblockplugin.h
Normal file
|
@ -39,6 +39,7 @@ INCLUDEPATH += 3rdparty\
|
||||||
plugins\
|
plugins\
|
||||||
sidebar\
|
sidebar\
|
||||||
data\
|
data\
|
||||||
|
adblock\
|
||||||
|
|
||||||
SOURCES += main.cpp\
|
SOURCES += main.cpp\
|
||||||
3rdparty/squeezelabel.cpp \
|
3rdparty/squeezelabel.cpp \
|
||||||
|
@ -98,7 +99,14 @@ SOURCES += main.cpp\
|
||||||
preferences/sslmanager.cpp \
|
preferences/sslmanager.cpp \
|
||||||
tools/notification.cpp \
|
tools/notification.cpp \
|
||||||
tools/htmlhighlighter.cpp \
|
tools/htmlhighlighter.cpp \
|
||||||
other/sourceviewersearch.cpp
|
other/sourceviewersearch.cpp \
|
||||||
|
adblock/adblocksubscription.cpp \
|
||||||
|
adblock/adblockrule.cpp \
|
||||||
|
adblock/adblockpage.cpp \
|
||||||
|
adblock/adblocknetwork.cpp \
|
||||||
|
adblock/adblockmanager.cpp \
|
||||||
|
adblock/adblockdialog.cpp \
|
||||||
|
adblock/adblockblockednetworkreply.cpp
|
||||||
|
|
||||||
HEADERS += 3rdparty/squeezelabel.h \
|
HEADERS += 3rdparty/squeezelabel.h \
|
||||||
3rdparty/qtwin.h \
|
3rdparty/qtwin.h \
|
||||||
|
@ -157,7 +165,14 @@ HEADERS += 3rdparty/squeezelabel.h \
|
||||||
preferences/sslmanager.h \
|
preferences/sslmanager.h \
|
||||||
tools/notification.h \
|
tools/notification.h \
|
||||||
tools/htmlhighlighter.h \
|
tools/htmlhighlighter.h \
|
||||||
other/sourceviewersearch.h
|
other/sourceviewersearch.h \
|
||||||
|
adblock/adblocksubscription.h \
|
||||||
|
adblock/adblockrule.h \
|
||||||
|
adblock/adblockpage.h \
|
||||||
|
adblock/adblocknetwork.h \
|
||||||
|
adblock/adblockmanager.h \
|
||||||
|
adblock/adblockdialog.h \
|
||||||
|
adblock/adblockblockednetworkreply.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
preferences/autofillmanager.ui \
|
preferences/autofillmanager.ui \
|
||||||
|
@ -180,7 +195,8 @@ FORMS += \
|
||||||
preferences/sslmanager.ui \
|
preferences/sslmanager.ui \
|
||||||
other/clearprivatedata.ui \
|
other/clearprivatedata.ui \
|
||||||
other/sourceviewersearch.ui \
|
other/sourceviewersearch.ui \
|
||||||
other/closedialog.ui
|
other/closedialog.ui \
|
||||||
|
adblock/adblockdialog.ui
|
||||||
|
|
||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
data/icons.qrc \
|
data/icons.qrc \
|
||||||
|
|
75
src/adblock/adblockblockednetworkreply.cpp
Normal file
75
src/adblock/adblockblockednetworkreply.cpp
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
/* ============================================================
|
||||||
|
* QupZilla - WebKit based browser
|
||||||
|
* Copyright (C) 2010-2011 nowrep
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
* ============================================================ */
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2009, Benjamin C. Meyer <ben@meyerhome.net>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Benjamin Meyer nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "adblockblockednetworkreply.h"
|
||||||
|
|
||||||
|
#include "adblockrule.h"
|
||||||
|
|
||||||
|
#include <qnetworkrequest.h>
|
||||||
|
#include <qtimer.h>
|
||||||
|
|
||||||
|
AdBlockBlockedNetworkReply::AdBlockBlockedNetworkReply(const QNetworkRequest &request, const AdBlockRule *rule, QObject *parent)
|
||||||
|
: QNetworkReply(parent)
|
||||||
|
{
|
||||||
|
setOperation(QNetworkAccessManager::GetOperation);
|
||||||
|
setRequest(request);
|
||||||
|
setUrl(request.url());
|
||||||
|
setError(QNetworkReply::ContentAccessDenied, tr("Blocked by AdBlockRule: %1").arg(rule->filter()));
|
||||||
|
QTimer::singleShot(0, this, SLOT(delayedFinished()));
|
||||||
|
}
|
||||||
|
|
||||||
|
qint64 AdBlockBlockedNetworkReply::readData(char *data, qint64 maxSize)
|
||||||
|
{
|
||||||
|
Q_UNUSED(data);
|
||||||
|
Q_UNUSED(maxSize);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AdBlockBlockedNetworkReply::delayedFinished()
|
||||||
|
{
|
||||||
|
emit error(QNetworkReply::ContentAccessDenied);
|
||||||
|
emit finished();
|
||||||
|
}
|
||||||
|
|
52
src/adblock/adblockblockednetworkreply.h
Normal file
52
src/adblock/adblockblockednetworkreply.h
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2009, Benjamin C. Meyer <ben@meyerhome.net>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Benjamin Meyer nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ADBLOCKBLOCKEDNETWORKREPLY_H
|
||||||
|
#define ADBLOCKBLOCKEDNETWORKREPLY_H
|
||||||
|
|
||||||
|
#include <qnetworkreply.h>
|
||||||
|
|
||||||
|
class AdBlockRule;
|
||||||
|
class AdBlockBlockedNetworkReply : public QNetworkReply
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
AdBlockBlockedNetworkReply(const QNetworkRequest &request, const AdBlockRule *rule, QObject *parent = 0);
|
||||||
|
void abort() {};
|
||||||
|
|
||||||
|
protected:
|
||||||
|
qint64 readData(char *data, qint64 maxSize);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void delayedFinished();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ADBLOCKBLOCKEDNETWORKREPLY_H
|
||||||
|
|
192
src/adblock/adblockdialog.cpp
Normal file
192
src/adblock/adblockdialog.cpp
Normal file
|
@ -0,0 +1,192 @@
|
||||||
|
/* ============================================================
|
||||||
|
* QupZilla - WebKit based browser
|
||||||
|
* Copyright (C) 2010-2011 nowrep
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
* ============================================================ */
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2009, Benjamin C. Meyer <ben@meyerhome.net>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Benjamin Meyer nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
#include "adblockdialog.h"
|
||||||
|
#include "adblockmodel.h"
|
||||||
|
#include "adblockmanager.h"
|
||||||
|
#include "adblocksubscription.h"
|
||||||
|
#include "ui_adblockdialog.h"
|
||||||
|
|
||||||
|
AdBlockDialog::AdBlockDialog(QWidget *parent)
|
||||||
|
: QDialog(parent)
|
||||||
|
, m_itemChangingBlock(false)
|
||||||
|
{
|
||||||
|
setupUi(this);
|
||||||
|
// m_adBlockModel = new AdBlockModel(this);
|
||||||
|
// m_proxyModel = new TreeSortFilterProxyModel(this);
|
||||||
|
// m_proxyModel->setSourceModel(m_adBlockModel);
|
||||||
|
// treeWidget->setModel(m_proxyModel);
|
||||||
|
// connect(search, SIGNAL(textChanged(QString)), m_proxyModel, SLOT(setFilterFixedString(QString)));
|
||||||
|
|
||||||
|
AdBlockManager* manager = AdBlockManager::instance();
|
||||||
|
adblockCheckBox->setChecked(manager->isEnabled());
|
||||||
|
connect(adblockCheckBox, SIGNAL(toggled(bool)), manager, SLOT(setEnabled(bool)));
|
||||||
|
connect(addButton, SIGNAL(clicked()), this, SLOT(addCustomRule()));
|
||||||
|
connect(reloadButton, SIGNAL(clicked()), this, SLOT(updateSubscription()));
|
||||||
|
connect(search, SIGNAL(textChanged(QString)), treeWidget, SLOT(filterStringWithoutTopItems(QString)));
|
||||||
|
connect(manager->subscription(), SIGNAL(changed()), this, SLOT(refreshAfterUpdate()));
|
||||||
|
|
||||||
|
QTimer::singleShot(0, this, SLOT(firstRefresh()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void AdBlockDialog::firstRefresh()
|
||||||
|
{
|
||||||
|
refresh();
|
||||||
|
connect(treeWidget, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(itemChanged(QTreeWidgetItem*)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void AdBlockDialog::refreshAfterUpdate()
|
||||||
|
{
|
||||||
|
QMessageBox::information(this, tr("Update completed"), tr("EasyList has been successfuly updated."));
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AdBlockDialog::refresh()
|
||||||
|
{
|
||||||
|
m_itemChangingBlock = true;
|
||||||
|
treeWidget->setUpdatesEnabled(false);
|
||||||
|
treeWidget->clear();
|
||||||
|
AdBlockManager *manager = AdBlockManager::instance();
|
||||||
|
|
||||||
|
QFont boldFont;
|
||||||
|
boldFont.setBold(true);
|
||||||
|
QFont italicFont;
|
||||||
|
italicFont.setItalic(true);
|
||||||
|
|
||||||
|
m_customListItem = new QTreeWidgetItem(treeWidget);
|
||||||
|
m_customListItem->setText(0,tr("Custom List"));
|
||||||
|
m_customListItem->setFont(0, boldFont);
|
||||||
|
treeWidget->addTopLevelItem(m_customListItem);
|
||||||
|
|
||||||
|
m_easyListItem = new QTreeWidgetItem(treeWidget);
|
||||||
|
m_easyListItem->setText(0,"EasyList");
|
||||||
|
m_easyListItem->setFont(0, boldFont);
|
||||||
|
treeWidget->addTopLevelItem(m_easyListItem);
|
||||||
|
|
||||||
|
bool customRulesStarted = false;
|
||||||
|
QList<AdBlockRule> allRules = manager->subscription()->allRules();
|
||||||
|
|
||||||
|
int index = 0;
|
||||||
|
foreach (const AdBlockRule rule, allRules) {
|
||||||
|
index++;
|
||||||
|
if (rule.filter().contains("*******- user custom filters")) {
|
||||||
|
customRulesStarted = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
QTreeWidgetItem* item = new QTreeWidgetItem(customRulesStarted ? m_customListItem : m_easyListItem);
|
||||||
|
if (item->parent() == m_customListItem)
|
||||||
|
item->setFlags(item->flags() | Qt::ItemIsEditable);
|
||||||
|
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
||||||
|
item->setCheckState(0, (rule.filter().startsWith("!") ) ? Qt::Unchecked : Qt::Checked);
|
||||||
|
item->setText(0, rule.filter());
|
||||||
|
item->setWhatsThis(0, QString::number(index-1));
|
||||||
|
if (rule.filter().startsWith("!"))
|
||||||
|
item->setFont(0, italicFont);
|
||||||
|
}
|
||||||
|
treeWidget->expandAll();
|
||||||
|
treeWidget->setUpdatesEnabled(true);
|
||||||
|
m_itemChangingBlock = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AdBlockDialog::itemChanged(QTreeWidgetItem *item)
|
||||||
|
{
|
||||||
|
if (!item || m_itemChangingBlock)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_itemChangingBlock = true;
|
||||||
|
|
||||||
|
if (item->checkState(0) == Qt::Unchecked && !item->text(0).startsWith("!")) { //Disable rule
|
||||||
|
int offset = item->whatsThis(0).toInt();
|
||||||
|
QFont italicFont;
|
||||||
|
italicFont.setItalic(true);
|
||||||
|
item->setFont(0, italicFont);
|
||||||
|
item->setText(0, item->text(0).prepend("!"));
|
||||||
|
|
||||||
|
AdBlockRule rul(item->text(0));
|
||||||
|
AdBlockManager::instance()->subscription()->replaceRule(rul, offset);
|
||||||
|
|
||||||
|
} else if (item->checkState(0) == Qt::Checked && item->text(0).startsWith("!")) { //Enable rule
|
||||||
|
int offset = item->whatsThis(0).toInt();
|
||||||
|
item->setFont(0, QFont());
|
||||||
|
QString newText = item->text(0).mid(1);
|
||||||
|
item->setText(0, newText);
|
||||||
|
|
||||||
|
AdBlockRule rul(newText);
|
||||||
|
AdBlockManager::instance()->subscription()->replaceRule(rul, offset);
|
||||||
|
|
||||||
|
} else { //Custom rule has been changed
|
||||||
|
int offset = item->whatsThis(0).toInt();
|
||||||
|
|
||||||
|
AdBlockRule rul(item->text(0));
|
||||||
|
AdBlockManager::instance()->subscription()->replaceRule(rul, offset);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
m_itemChangingBlock = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AdBlockDialog::addCustomRule()
|
||||||
|
{
|
||||||
|
QString newRule = QInputDialog::getText(this, tr("Add Custom Rule"), tr("Please write your rule here:"));
|
||||||
|
if (newRule.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
AdBlockManager *manager = AdBlockManager::instance();
|
||||||
|
AdBlockSubscription *subscription = manager->subscription();
|
||||||
|
subscription->addRule(AdBlockRule(newRule));
|
||||||
|
m_itemChangingBlock = true;
|
||||||
|
QTreeWidgetItem* item = new QTreeWidgetItem(m_customListItem);
|
||||||
|
item->setText(0, newRule);
|
||||||
|
item->setFlags(item->flags() | Qt::ItemIsEditable);
|
||||||
|
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
||||||
|
item->setCheckState(0, Qt::Checked);
|
||||||
|
m_itemChangingBlock = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AdBlockDialog::updateSubscription()
|
||||||
|
{
|
||||||
|
AdBlockSubscription *subscription = AdBlockManager::instance()->subscription();
|
||||||
|
subscription->updateNow();
|
||||||
|
}
|
72
src/adblock/adblockdialog.h
Normal file
72
src/adblock/adblockdialog.h
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2009, Benjamin C. Meyer <ben@meyerhome.net>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Benjamin Meyer nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ADBLOCKDIALOG_H
|
||||||
|
#define ADBLOCKDIALOG_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QDesktopServices>
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QUrl>
|
||||||
|
#include <QSortFilterProxyModel>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QTreeWidget>
|
||||||
|
#include <QTreeWidgetItem>
|
||||||
|
#include <QInputDialog>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
#include "ui_adblockdialog.h"
|
||||||
|
|
||||||
|
class AdBlockModel;
|
||||||
|
class TreeSortFilterProxyModel;
|
||||||
|
class AdBlockDialog : public QDialog, public Ui_AdBlockDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
AdBlockDialog(QWidget *parent = 0);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void itemChanged(QTreeWidgetItem* item);
|
||||||
|
void updateSubscription();
|
||||||
|
void addCustomRule();
|
||||||
|
void firstRefresh();
|
||||||
|
void refreshAfterUpdate();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void refresh();
|
||||||
|
|
||||||
|
bool m_itemChangingBlock;
|
||||||
|
QTreeWidgetItem* m_customListItem;
|
||||||
|
QTreeWidgetItem* m_easyListItem;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ADBLOCKDIALOG_H
|
||||||
|
|
188
src/adblock/adblockdialog.ui
Normal file
188
src/adblock/adblockdialog.ui
Normal file
|
@ -0,0 +1,188 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>AdBlockDialog</class>
|
||||||
|
<widget class="QDialog" name="AdBlockDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>546</width>
|
||||||
|
<height>462</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>AdBlock Configuration</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
|
<item row="0" column="0" colspan="2">
|
||||||
|
<widget class="QCheckBox" name="adblockCheckBox">
|
||||||
|
<property name="text">
|
||||||
|
<string>Enable AdBlock</string>
|
||||||
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0" colspan="2">
|
||||||
|
<widget class="QWidget" name="adblockWidget" native="true">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<property name="margin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLineEdit" name="search">
|
||||||
|
<property name="placeholderText">
|
||||||
|
<string>Search...</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0" colspan="5">
|
||||||
|
<widget class="TreeWidget" name="treeWidget">
|
||||||
|
<property name="alternatingRowColors">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>Rule</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1" colspan="3">
|
||||||
|
<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>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0" colspan="4">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="addButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Add Rule</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="reloadButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Update EasyList</string>
|
||||||
|
</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>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<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>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>TreeWidget</class>
|
||||||
|
<extends>QTreeWidget</extends>
|
||||||
|
<header>treewidget.h</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>AdBlockDialog</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>75</x>
|
||||||
|
<y>495</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>157</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>AdBlockDialog</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>75</x>
|
||||||
|
<y>495</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>286</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<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>
|
||||||
|
</ui>
|
137
src/adblock/adblockmanager.cpp
Normal file
137
src/adblock/adblockmanager.cpp
Normal file
|
@ -0,0 +1,137 @@
|
||||||
|
/* ============================================================
|
||||||
|
* QupZilla - WebKit based browser
|
||||||
|
* Copyright (C) 2010-2011 nowrep
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
* ============================================================ */
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2009, Benjamin C. Meyer <ben@meyerhome.net>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Benjamin Meyer nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
#include "adblockmanager.h"
|
||||||
|
#include "adblockdialog.h"
|
||||||
|
#include "adblocknetwork.h"
|
||||||
|
#include "adblockpage.h"
|
||||||
|
#include "adblocksubscription.h"
|
||||||
|
#include "mainapplication.h"
|
||||||
|
#include "networkmanager.h"
|
||||||
|
#include "qupzilla.h"
|
||||||
|
|
||||||
|
AdBlockManager* AdBlockManager::s_adBlockManager = 0;
|
||||||
|
|
||||||
|
AdBlockManager::AdBlockManager(QObject* parent)
|
||||||
|
: QObject(parent)
|
||||||
|
, m_loaded(false)
|
||||||
|
, m_enabled(true)
|
||||||
|
, m_adBlockDialog(0)
|
||||||
|
, m_adBlockNetwork(0)
|
||||||
|
, m_adBlockPage(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
AdBlockManager* AdBlockManager::instance()
|
||||||
|
{
|
||||||
|
if (!s_adBlockManager) {
|
||||||
|
qDebug() << "creating adblock manager";
|
||||||
|
s_adBlockManager = new AdBlockManager(mApp->networkManager());
|
||||||
|
}
|
||||||
|
return s_adBlockManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AdBlockManager::setEnabled(bool enabled)
|
||||||
|
{
|
||||||
|
if (isEnabled() == enabled)
|
||||||
|
return;
|
||||||
|
m_enabled = enabled;
|
||||||
|
emit rulesChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
AdBlockNetwork* AdBlockManager::network()
|
||||||
|
{
|
||||||
|
if (!m_adBlockNetwork)
|
||||||
|
m_adBlockNetwork = new AdBlockNetwork(this);
|
||||||
|
return m_adBlockNetwork;
|
||||||
|
}
|
||||||
|
|
||||||
|
AdBlockPage* AdBlockManager::page()
|
||||||
|
{
|
||||||
|
if (!m_adBlockPage)
|
||||||
|
m_adBlockPage = new AdBlockPage(this);
|
||||||
|
return m_adBlockPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AdBlockManager::load()
|
||||||
|
{
|
||||||
|
if (m_loaded)
|
||||||
|
return;
|
||||||
|
m_loaded = true;
|
||||||
|
|
||||||
|
QSettings settings(mApp->getActiveProfil()+"settings.ini", QSettings::IniFormat);
|
||||||
|
settings.beginGroup("AdBlock");
|
||||||
|
m_enabled = settings.value("enabled", m_enabled).toBool();
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
|
m_subscription = new AdBlockSubscription(this);
|
||||||
|
connect(m_subscription, SIGNAL(rulesChanged()), this, SIGNAL(rulesChanged()));
|
||||||
|
connect(m_subscription, SIGNAL(changed()), this, SIGNAL(rulesChanged()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void AdBlockManager::save()
|
||||||
|
{
|
||||||
|
if (!m_loaded)
|
||||||
|
return;
|
||||||
|
m_subscription->saveRules();
|
||||||
|
|
||||||
|
QSettings settings(mApp->getActiveProfil()+"settings.ini", QSettings::IniFormat);
|
||||||
|
settings.beginGroup(QLatin1String("AdBlock"));
|
||||||
|
settings.setValue(QLatin1String("enabled"), m_enabled);
|
||||||
|
settings.endGroup();
|
||||||
|
}
|
||||||
|
|
||||||
|
AdBlockDialog* AdBlockManager::showDialog()
|
||||||
|
{
|
||||||
|
if (!m_adBlockDialog) {
|
||||||
|
m_adBlockDialog = new AdBlockDialog(mApp->getWindow());
|
||||||
|
m_adBlockDialog->setAttribute(Qt::WA_DeleteOnClose, true);
|
||||||
|
}
|
||||||
|
m_adBlockDialog->show();
|
||||||
|
return m_adBlockDialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
AdBlockManager::~AdBlockManager()
|
||||||
|
{
|
||||||
|
}
|
78
src/adblock/adblockmanager.h
Normal file
78
src/adblock/adblockmanager.h
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2009, Benjamin C. Meyer <ben@meyerhome.net>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Benjamin Meyer nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
#ifndef ADBLOCKMANAGER_H
|
||||||
|
#define ADBLOCKMANAGER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QSettings>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QPointer>
|
||||||
|
|
||||||
|
class QUrl;
|
||||||
|
class AdBlockDialog;
|
||||||
|
class AdBlockNetwork;
|
||||||
|
class AdBlockPage;
|
||||||
|
class AdBlockSubscription;
|
||||||
|
class AdBlockManager : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void rulesChanged();
|
||||||
|
|
||||||
|
public:
|
||||||
|
AdBlockManager(QObject *parent = 0);
|
||||||
|
~AdBlockManager();
|
||||||
|
|
||||||
|
void load();
|
||||||
|
void save();
|
||||||
|
static AdBlockManager* instance();
|
||||||
|
bool isEnabled() { if (!m_loaded) load(); return m_enabled; }
|
||||||
|
|
||||||
|
AdBlockSubscription* subscription() { return m_subscription; }
|
||||||
|
AdBlockNetwork *network();
|
||||||
|
AdBlockPage *page();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void setEnabled(bool enabled);
|
||||||
|
AdBlockDialog *showDialog();
|
||||||
|
|
||||||
|
private:
|
||||||
|
static AdBlockManager* s_adBlockManager;
|
||||||
|
|
||||||
|
bool m_loaded;
|
||||||
|
bool m_enabled;
|
||||||
|
QPointer<AdBlockDialog> m_adBlockDialog;
|
||||||
|
AdBlockNetwork *m_adBlockNetwork;
|
||||||
|
AdBlockPage *m_adBlockPage;
|
||||||
|
AdBlockSubscription* m_subscription;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ADBLOCKMANAGER_H
|
||||||
|
|
83
src/adblock/adblocknetwork.cpp
Normal file
83
src/adblock/adblocknetwork.cpp
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
/* ============================================================
|
||||||
|
* QupZilla - WebKit based browser
|
||||||
|
* Copyright (C) 2010-2011 nowrep
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
* ============================================================ */
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2009, Benjamin C. Meyer <ben@meyerhome.net>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Benjamin Meyer nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "adblocknetwork.h"
|
||||||
|
#include "adblockblockednetworkreply.h"
|
||||||
|
#include "adblockmanager.h"
|
||||||
|
#include "adblocksubscription.h"
|
||||||
|
#include "mainapplication.h"
|
||||||
|
|
||||||
|
AdBlockNetwork::AdBlockNetwork(QObject *parent)
|
||||||
|
: QObject(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QNetworkReply *AdBlockNetwork::block(const QNetworkRequest &request)
|
||||||
|
{
|
||||||
|
QUrl url = request.url();
|
||||||
|
if (url.scheme() == "data")
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
AdBlockManager *manager = AdBlockManager::instance();
|
||||||
|
if (!manager->isEnabled())
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
QString urlString = url.toEncoded();
|
||||||
|
const AdBlockRule* blockedRule = 0;
|
||||||
|
AdBlockSubscription* subscription = manager->subscription();
|
||||||
|
|
||||||
|
if (subscription->allow(urlString))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (const AdBlockRule *rule = subscription->block(urlString))
|
||||||
|
blockedRule = rule;
|
||||||
|
|
||||||
|
if (blockedRule) {
|
||||||
|
AdBlockBlockedNetworkReply *reply = new AdBlockBlockedNetworkReply(request, blockedRule, this);
|
||||||
|
return reply;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
46
src/adblock/adblocknetwork.h
Normal file
46
src/adblock/adblocknetwork.h
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2009, Benjamin C. Meyer <ben@meyerhome.net>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Benjamin Meyer nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ADBLOCKNETWORK_H
|
||||||
|
#define ADBLOCKNETWORK_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class QNetworkRequest;
|
||||||
|
class QNetworkReply;
|
||||||
|
class AdBlockNetwork : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
AdBlockNetwork(QObject *parent = 0);
|
||||||
|
QNetworkReply *block(const QNetworkRequest &request);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ADBLOCKNETWORK_H
|
||||||
|
|
118
src/adblock/adblockpage.cpp
Normal file
118
src/adblock/adblockpage.cpp
Normal file
|
@ -0,0 +1,118 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2009, Benjamin C. Meyer <ben@meyerhome.net>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Benjamin Meyer nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "adblockpage.h"
|
||||||
|
|
||||||
|
#include "adblockmanager.h"
|
||||||
|
#include "adblocksubscription.h"
|
||||||
|
#include "adblockrule.h"
|
||||||
|
|
||||||
|
#if QT_VERSION >= 0x040600
|
||||||
|
#include <qwebelement.h>
|
||||||
|
#endif
|
||||||
|
#include <qwebpage.h>
|
||||||
|
#include <qwebframe.h>
|
||||||
|
|
||||||
|
#include <qdebug.h>
|
||||||
|
|
||||||
|
// #define ADBLOCKPAGE_DEBUG
|
||||||
|
|
||||||
|
AdBlockPage::AdBlockPage(QObject *parent)
|
||||||
|
: QObject(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void AdBlockPage::checkRule(const AdBlockRule *rule, QWebPage *page, const QString &host)
|
||||||
|
{
|
||||||
|
if (!rule->isEnabled())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QString filter = rule->filter();
|
||||||
|
int offset = filter.indexOf(QLatin1String("##"));
|
||||||
|
if (offset == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QString selectorQuery;
|
||||||
|
if (offset > 0) {
|
||||||
|
QString domainRules = filter.mid(0, offset);
|
||||||
|
selectorQuery = filter.mid(offset + 2);
|
||||||
|
QStringList domains = domainRules.split(QLatin1Char(','));
|
||||||
|
|
||||||
|
bool match = false;
|
||||||
|
foreach (const QString &domain, domains) {
|
||||||
|
bool reverse = (domain[0] == QLatin1Char('~'));
|
||||||
|
if (reverse) {
|
||||||
|
QString xdomain = domain.mid(1);
|
||||||
|
if (host.endsWith(xdomain))
|
||||||
|
return;
|
||||||
|
match = true;
|
||||||
|
}
|
||||||
|
if (host.endsWith(domain))
|
||||||
|
match = true;
|
||||||
|
}
|
||||||
|
if (!match)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (offset == 0)
|
||||||
|
selectorQuery = filter.mid(2);
|
||||||
|
|
||||||
|
Q_UNUSED(page);
|
||||||
|
#if QT_VERSION >= 0x040600
|
||||||
|
QWebElement document = page->mainFrame()->documentElement();
|
||||||
|
QWebElementCollection elements = document.findAll(selectorQuery);
|
||||||
|
#if defined(ADBLOCKPAGE_DEBUG)
|
||||||
|
if (elements.count() != 0)
|
||||||
|
qDebug() << "AdBlockPage::" << __FUNCTION__ << "blocking" << elements.count() << "items" << selectorQuery << elements.count() << "rule:" << rule->filter();
|
||||||
|
#endif
|
||||||
|
foreach (QWebElement element, elements) {
|
||||||
|
element.setStyleProperty(QLatin1String("visibility"), QLatin1String("hidden"));
|
||||||
|
element.removeFromDocument();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void AdBlockPage::applyRulesToPage(QWebPage *page)
|
||||||
|
{
|
||||||
|
if (!page || !page->mainFrame())
|
||||||
|
return;
|
||||||
|
AdBlockManager *manager = AdBlockManager::instance();
|
||||||
|
if (!manager->isEnabled())
|
||||||
|
return;
|
||||||
|
#if QT_VERSION >= 0x040600
|
||||||
|
QString host = page->mainFrame()->url().host();
|
||||||
|
AdBlockSubscription* subscription = manager->subscription();
|
||||||
|
|
||||||
|
QList<const AdBlockRule*> rules = subscription->pageRules();
|
||||||
|
foreach (const AdBlockRule *rule, rules) {
|
||||||
|
checkRule(rule, page, host);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
50
src/adblock/adblockpage.h
Normal file
50
src/adblock/adblockpage.h
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2009, Benjamin C. Meyer <ben@meyerhome.net>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Benjamin Meyer nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ADBLOCKPAGE_H
|
||||||
|
#define ADBLOCKPAGE_H
|
||||||
|
|
||||||
|
#include <qobject.h>
|
||||||
|
|
||||||
|
class AdBlockRule;
|
||||||
|
class QWebPage;
|
||||||
|
class AdBlockPage : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
AdBlockPage(QObject *parent = 0);
|
||||||
|
|
||||||
|
void applyRulesToPage(QWebPage *page);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void checkRule(const AdBlockRule *rule, QWebPage *page, const QString &host);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ADBLOCKPAGE_H
|
||||||
|
|
217
src/adblock/adblockrule.cpp
Normal file
217
src/adblock/adblockrule.cpp
Normal file
|
@ -0,0 +1,217 @@
|
||||||
|
/* ============================================================
|
||||||
|
* QupZilla - WebKit based browser
|
||||||
|
* Copyright (C) 2010-2011 nowrep
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
* ============================================================ */
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2009, Zsombor Gegesy <gzsombor@gmail.com>
|
||||||
|
* Copyright (c) 2009, Benjamin C. Meyer <ben@meyerhome.net>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Benjamin Meyer nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "adblockrule.h"
|
||||||
|
|
||||||
|
#include "adblocksubscription.h"
|
||||||
|
|
||||||
|
#include <qdebug.h>
|
||||||
|
#include <qregexp.h>
|
||||||
|
#include <qurl.h>
|
||||||
|
|
||||||
|
// #define ADBLOCKRULE_DEBUG
|
||||||
|
|
||||||
|
AdBlockRule::AdBlockRule(const QString &filter)
|
||||||
|
{
|
||||||
|
setFilter(filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString AdBlockRule::filter() const
|
||||||
|
{
|
||||||
|
return m_filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AdBlockRule::setFilter(const QString &filter)
|
||||||
|
{
|
||||||
|
m_filter = filter;
|
||||||
|
|
||||||
|
m_cssRule = false;
|
||||||
|
m_enabled = true;
|
||||||
|
m_exception = false;
|
||||||
|
bool regExpRule = false;
|
||||||
|
|
||||||
|
if (filter.startsWith(QLatin1String("!"))
|
||||||
|
|| filter.trimmed().isEmpty())
|
||||||
|
m_enabled = false;
|
||||||
|
|
||||||
|
if (filter.contains(QLatin1String("##")))
|
||||||
|
m_cssRule = true;
|
||||||
|
|
||||||
|
QString parsedLine = filter;
|
||||||
|
if (parsedLine.startsWith(QLatin1String("@@"))) {
|
||||||
|
m_exception = true;
|
||||||
|
parsedLine = parsedLine.mid(2);
|
||||||
|
}
|
||||||
|
if (parsedLine.startsWith(QLatin1Char('/'))) {
|
||||||
|
if (parsedLine.endsWith(QLatin1Char('/'))) {
|
||||||
|
parsedLine = parsedLine.mid(1);
|
||||||
|
parsedLine = parsedLine.left(parsedLine.size() - 1);
|
||||||
|
regExpRule = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int options = parsedLine.indexOf(QLatin1String("$"), 0);
|
||||||
|
if (options >= 0) {
|
||||||
|
m_options = parsedLine.mid(options + 1).split(QLatin1Char(','));
|
||||||
|
parsedLine = parsedLine.left(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
setPattern(parsedLine, regExpRule);
|
||||||
|
|
||||||
|
if (m_options.contains(QLatin1String("match-case"))) {
|
||||||
|
m_regExp.setCaseSensitivity(Qt::CaseSensitive);
|
||||||
|
m_options.removeOne(QLatin1String("match-case"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AdBlockRule::networkMatch(const QString &encodedUrl) const
|
||||||
|
{
|
||||||
|
if (m_cssRule) {
|
||||||
|
#if defined(ADBLOCKRULE_DEBUG)
|
||||||
|
qDebug() << "AdBlockRule::" << __FUNCTION__ << "m_cssRule" << m_cssRule;
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_enabled) {
|
||||||
|
#if defined(ADBLOCKRULE_DEBUG)
|
||||||
|
qDebug() << "AdBlockRule::" << __FUNCTION__ << "is not enabled";
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool matched = m_regExp.indexIn(encodedUrl) != -1;
|
||||||
|
|
||||||
|
if (matched
|
||||||
|
&& !m_options.isEmpty()) {
|
||||||
|
|
||||||
|
// we only support domain right now
|
||||||
|
if (m_options.count() == 1) {
|
||||||
|
foreach (const QString &option, m_options) {
|
||||||
|
if (option.startsWith("domain=")) {
|
||||||
|
QUrl url = QUrl::fromEncoded(encodedUrl.toUtf8());
|
||||||
|
QString host = url.host();
|
||||||
|
QStringList domainOptions = option.mid(7).split('|');
|
||||||
|
foreach (QString domainOption, domainOptions) {
|
||||||
|
bool negate = domainOption.at(0) == '~';
|
||||||
|
if (negate)
|
||||||
|
domainOption = domainOption.mid(1);
|
||||||
|
bool hostMatched = domainOption == host;
|
||||||
|
if (hostMatched && !negate)
|
||||||
|
return true;
|
||||||
|
if (!hostMatched && negate)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(ADBLOCKRULE_DEBUG)
|
||||||
|
qDebug() << "AdBlockRule::" << __FUNCTION__ << "options are currently not supported" << m_options;
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#if defined(ADBLOCKRULE_DEBUG)
|
||||||
|
//qDebug() << "AdBlockRule::" << __FUNCTION__ << encodedUrl << "MATCHED" << matched << filter();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return matched;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AdBlockRule::isException() const
|
||||||
|
{
|
||||||
|
return m_exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AdBlockRule::setException(bool exception)
|
||||||
|
{
|
||||||
|
m_exception = exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AdBlockRule::isEnabled() const
|
||||||
|
{
|
||||||
|
return m_enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AdBlockRule::setEnabled(bool enabled)
|
||||||
|
{
|
||||||
|
m_enabled = enabled;
|
||||||
|
if (!enabled) {
|
||||||
|
m_filter = QLatin1String("!") + m_filter;
|
||||||
|
} else {
|
||||||
|
m_filter = m_filter.mid(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString AdBlockRule::regExpPattern() const
|
||||||
|
{
|
||||||
|
return m_regExp.pattern();
|
||||||
|
}
|
||||||
|
|
||||||
|
static QString convertPatternToRegExp(const QString &wildcardPattern) {
|
||||||
|
QString pattern = wildcardPattern;
|
||||||
|
return pattern.replace(QRegExp(QLatin1String("\\*+")), QLatin1String("*")) // remove multiple wildcards
|
||||||
|
.replace(QRegExp(QLatin1String("\\^\\|$")), QLatin1String("^")) // remove anchors following separator placeholder
|
||||||
|
.replace(QRegExp(QLatin1String("^(\\*)")), QLatin1String("")) // remove leading wildcards
|
||||||
|
.replace(QRegExp(QLatin1String("(\\*)$")), QLatin1String(""))
|
||||||
|
.replace(QRegExp(QLatin1String("(\\W)")), QLatin1String("\\\\1")) // escape special symbols
|
||||||
|
.replace(QRegExp(QLatin1String("^\\\\\\|\\\\\\|")),
|
||||||
|
QLatin1String("^[\\w\\-]+:\\/+(?!\\/)(?:[^\\/]+\\.)?")) // process extended anchor at expression start
|
||||||
|
.replace(QRegExp(QLatin1String("\\\\\\^")),
|
||||||
|
QLatin1String("(?:[^\\w\\d\\-.%]|$)")) // process separator placeholders
|
||||||
|
.replace(QRegExp(QLatin1String("^\\\\\\|")), QLatin1String("^")) // process anchor at expression start
|
||||||
|
.replace(QRegExp(QLatin1String("\\\\\\|$")), QLatin1String("$")) // process anchor at expression end
|
||||||
|
.replace(QRegExp(QLatin1String("\\\\\\*")), QLatin1String(".*")) // replace wildcards by .*
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AdBlockRule::setPattern(const QString &pattern, bool isRegExp)
|
||||||
|
{
|
||||||
|
if (isRegExp)
|
||||||
|
qDebug() << pattern;
|
||||||
|
m_regExp = QRegExp(isRegExp ? pattern : convertPatternToRegExp(pattern),
|
||||||
|
Qt::CaseInsensitive, QRegExp::RegExp);
|
||||||
|
}
|
||||||
|
|
85
src/adblock/adblockrule.h
Normal file
85
src/adblock/adblockrule.h
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
/* ============================================================
|
||||||
|
* QupZilla - WebKit based browser
|
||||||
|
* Copyright (C) 2010-2011 nowrep
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
* ============================================================ */
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2009, Benjamin C. Meyer <ben@meyerhome.net>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Benjamin Meyer nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ADBLOCKRULE_H
|
||||||
|
#define ADBLOCKRULE_H
|
||||||
|
|
||||||
|
#include <qstringlist.h>
|
||||||
|
|
||||||
|
class QUrl;
|
||||||
|
class QRegExp;
|
||||||
|
class AdBlockRule
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
AdBlockRule(const QString &filter = QString());
|
||||||
|
|
||||||
|
QString filter() const;
|
||||||
|
void setFilter(const QString &filter);
|
||||||
|
|
||||||
|
bool isCSSRule() const { return m_cssRule; }
|
||||||
|
bool networkMatch(const QString &encodedUrl) const;
|
||||||
|
|
||||||
|
bool isException() const;
|
||||||
|
void setException(bool exception);
|
||||||
|
|
||||||
|
bool isEnabled() const;
|
||||||
|
void setEnabled(bool enabled);
|
||||||
|
|
||||||
|
QString regExpPattern() const;
|
||||||
|
void setPattern(const QString &pattern, bool isRegExp);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_filter;
|
||||||
|
|
||||||
|
bool m_cssRule;
|
||||||
|
bool m_exception;
|
||||||
|
bool m_enabled;
|
||||||
|
QRegExp m_regExp;
|
||||||
|
QStringList m_options;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ADBLOCKRULE_H
|
||||||
|
|
227
src/adblock/adblocksubscription.cpp
Normal file
227
src/adblock/adblocksubscription.cpp
Normal file
|
@ -0,0 +1,227 @@
|
||||||
|
/* ============================================================
|
||||||
|
* QupZilla - WebKit based browser
|
||||||
|
* Copyright (C) 2010-2011 nowrep
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
* ============================================================ */
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2009, Benjamin C. Meyer <ben@meyerhome.net>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Benjamin Meyer nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
#include "adblocksubscription.h"
|
||||||
|
#include "mainapplication.h"
|
||||||
|
#include "networkmanager.h"
|
||||||
|
// #define ADBLOCKSUBSCRIPTION_DEBUG
|
||||||
|
|
||||||
|
AdBlockSubscription::AdBlockSubscription(QObject *parent)
|
||||||
|
: QObject(parent)
|
||||||
|
, m_downloading(0)
|
||||||
|
{
|
||||||
|
loadRules();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AdBlockSubscription::loadRules()
|
||||||
|
{
|
||||||
|
QString fileName = mApp->getActiveProfil()+"adblocklist.txt";
|
||||||
|
|
||||||
|
QFile file(fileName);
|
||||||
|
if (file.exists()) {
|
||||||
|
if (!file.open(QFile::ReadOnly)) {
|
||||||
|
qWarning() << "AdBlockSubscription::" << __FUNCTION__ << "Unable to open adblock file for reading" << fileName;
|
||||||
|
} else {
|
||||||
|
QTextStream textStream(&file);
|
||||||
|
QString header = textStream.readLine(1024);
|
||||||
|
if (!header.startsWith("[Adblock")) {
|
||||||
|
qWarning() << "AdBlockSubscription::" << __FUNCTION__ << "adblock file does not start with [Adblock" << fileName << "Header:" << header;
|
||||||
|
file.close();
|
||||||
|
file.remove();
|
||||||
|
} else {
|
||||||
|
m_rules.clear();
|
||||||
|
while (!textStream.atEnd()) {
|
||||||
|
QString line = textStream.readLine();
|
||||||
|
m_rules.append(AdBlockRule(line));
|
||||||
|
}
|
||||||
|
populateCache();
|
||||||
|
emit rulesChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AdBlockSubscription::updateNow()
|
||||||
|
{
|
||||||
|
if (m_downloading)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QNetworkRequest request(QUrl("https://easylist-downloads.adblockplus.org/easylist.txt"));
|
||||||
|
QNetworkReply *reply = mApp->networkManager()->get(request);
|
||||||
|
m_downloading = reply;
|
||||||
|
connect(reply, SIGNAL(finished()), this, SLOT(rulesDownloaded()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void AdBlockSubscription::rulesDownloaded()
|
||||||
|
{
|
||||||
|
QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
|
||||||
|
if (!reply)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QByteArray response = reply->readAll();
|
||||||
|
reply->close();
|
||||||
|
reply->deleteLater();
|
||||||
|
|
||||||
|
if (reply->error() != QNetworkReply::NoError)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (response.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QString fileName = mApp->getActiveProfil()+"adblocklist.txt";
|
||||||
|
QFile file(fileName);
|
||||||
|
if (!file.open(QFile::ReadWrite)) {
|
||||||
|
qWarning() << "AdBlockSubscription::" << __FUNCTION__ << "Unable to open adblock file for writing:" << fileName;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
response = response.left(response.indexOf("!-----------------General element hiding rules-----------------!"));
|
||||||
|
|
||||||
|
bool customRules = false;
|
||||||
|
foreach (const AdBlockRule rule, allRules()) {
|
||||||
|
if (rule.filter().contains("*******- user custom filters")) {
|
||||||
|
customRules = true;
|
||||||
|
response.append("! *******- user custom filters -*************\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!customRules)
|
||||||
|
continue;
|
||||||
|
response.append(rule.filter()+"\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
file.write(response);
|
||||||
|
file.close();
|
||||||
|
loadRules();
|
||||||
|
emit changed();
|
||||||
|
m_downloading = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AdBlockSubscription::saveRules()
|
||||||
|
{
|
||||||
|
QString fileName = mApp->getActiveProfil()+"adblocklist.txt";
|
||||||
|
|
||||||
|
QFile file(fileName);
|
||||||
|
if (!file.open(QFile::ReadWrite | QIODevice::Truncate)) {
|
||||||
|
qWarning() << "AdBlockSubscription::" << __FUNCTION__ << "Unable to open adblock file for writing:" << fileName;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QTextStream textStream(&file);
|
||||||
|
textStream << "[Adblock Plus 1.1.1]" << endl;
|
||||||
|
foreach (const AdBlockRule &rule, m_rules)
|
||||||
|
textStream << rule.filter() << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
const AdBlockRule* AdBlockSubscription::allow(const QString &urlString) const
|
||||||
|
{
|
||||||
|
foreach (const AdBlockRule *rule, m_networkExceptionRules) {
|
||||||
|
if (rule->networkMatch(urlString))
|
||||||
|
return rule;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const AdBlockRule* AdBlockSubscription::block(const QString &urlString) const
|
||||||
|
{
|
||||||
|
foreach (const AdBlockRule* rule, m_networkBlockRules) {
|
||||||
|
if (rule->networkMatch(urlString))
|
||||||
|
return rule;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<AdBlockRule> AdBlockSubscription::allRules() const
|
||||||
|
{
|
||||||
|
return m_rules;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AdBlockSubscription::addRule(const AdBlockRule &rule)
|
||||||
|
{
|
||||||
|
m_rules.append(rule);
|
||||||
|
populateCache();
|
||||||
|
emit rulesChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AdBlockSubscription::removeRule(int offset)
|
||||||
|
{
|
||||||
|
if (offset < 0 || offset >= m_rules.count())
|
||||||
|
return;
|
||||||
|
m_rules.removeAt(offset);
|
||||||
|
populateCache();
|
||||||
|
emit rulesChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AdBlockSubscription::replaceRule(const AdBlockRule &rule, int offset)
|
||||||
|
{
|
||||||
|
if (offset < 0 || offset >= m_rules.count())
|
||||||
|
return;
|
||||||
|
m_rules[offset] = rule;
|
||||||
|
populateCache();
|
||||||
|
emit rulesChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AdBlockSubscription::populateCache()
|
||||||
|
{
|
||||||
|
m_networkExceptionRules.clear();
|
||||||
|
m_networkBlockRules.clear();
|
||||||
|
m_pageRules.clear();
|
||||||
|
|
||||||
|
for (int i = 0; i < m_rules.count(); ++i) {
|
||||||
|
const AdBlockRule *rule = &m_rules.at(i);
|
||||||
|
if (!rule->isEnabled())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (rule->isCSSRule()) {
|
||||||
|
m_pageRules.append(rule);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rule->isException()) {
|
||||||
|
m_networkExceptionRules.append(rule);
|
||||||
|
} else {
|
||||||
|
m_networkBlockRules.append(rule);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
111
src/adblock/adblocksubscription.h
Normal file
111
src/adblock/adblocksubscription.h
Normal file
|
@ -0,0 +1,111 @@
|
||||||
|
/* ============================================================
|
||||||
|
* QupZilla - WebKit based browser
|
||||||
|
* Copyright (C) 2010-2011 nowrep
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
* ============================================================ */
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2009, Benjamin C. Meyer <ben@meyerhome.net>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Benjamin Meyer nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ADBLOCKSUBSCRIPTION_H
|
||||||
|
#define ADBLOCKSUBSCRIPTION_H
|
||||||
|
|
||||||
|
#include "adblockrule.h"
|
||||||
|
#include <QObject>
|
||||||
|
#include <QList>
|
||||||
|
#include <QDateTime>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
#include <QTextStream>
|
||||||
|
#include <QFileInfo>
|
||||||
|
|
||||||
|
class QNetworkReply;
|
||||||
|
class QUrl;
|
||||||
|
class AdBlockSubscription : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void changed();
|
||||||
|
void rulesChanged();
|
||||||
|
|
||||||
|
public:
|
||||||
|
AdBlockSubscription(QObject *parent = 0);
|
||||||
|
|
||||||
|
QString title() const { return m_title; }
|
||||||
|
void setTitle(const QString &title) { m_title = title; }
|
||||||
|
|
||||||
|
void updateNow();
|
||||||
|
QDateTime lastUpdate() const;
|
||||||
|
|
||||||
|
void saveRules();
|
||||||
|
|
||||||
|
const AdBlockRule *allow(const QString &urlString) const;
|
||||||
|
const AdBlockRule *block(const QString &urlString) const;
|
||||||
|
QList<const AdBlockRule*> pageRules() const { return m_pageRules; }
|
||||||
|
|
||||||
|
QList<AdBlockRule> allRules() const;
|
||||||
|
void addRule(const AdBlockRule &rule);
|
||||||
|
void removeRule(int offset);
|
||||||
|
void replaceRule(const AdBlockRule &rule, int offset);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void rulesDownloaded();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void populateCache();
|
||||||
|
QString rulesFileName() const;
|
||||||
|
void parseUrl(const QUrl &url);
|
||||||
|
void loadRules();
|
||||||
|
|
||||||
|
QString m_title;
|
||||||
|
bool m_enabled;
|
||||||
|
|
||||||
|
QNetworkReply *m_downloading;
|
||||||
|
QList<AdBlockRule> m_rules;
|
||||||
|
|
||||||
|
// sorted list
|
||||||
|
QList<const AdBlockRule*> m_networkExceptionRules;
|
||||||
|
QList<const AdBlockRule*> m_networkBlockRules;
|
||||||
|
QList<const AdBlockRule*> m_pageRules;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ADBLOCKSUBSCRIPTION_H
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
#include "autofillmodel.h"
|
#include "autofillmodel.h"
|
||||||
#include "bookmarkstoolbar.h"
|
#include "bookmarkstoolbar.h"
|
||||||
#include "locationbar.h"
|
#include "locationbar.h"
|
||||||
|
#include "clickablelabel.h"
|
||||||
|
#include "adblockmanager.h"
|
||||||
|
|
||||||
void QupZilla::postLaunch()
|
void QupZilla::postLaunch()
|
||||||
{
|
{
|
||||||
|
@ -73,7 +75,6 @@ void QupZilla::postLaunch()
|
||||||
if (m_tabWidget->count() == 0) //Something went really wrong .. add one tab
|
if (m_tabWidget->count() == 0) //Something went really wrong .. add one tab
|
||||||
m_tabWidget->addView(m_homepage);
|
m_tabWidget->addView(m_homepage);
|
||||||
|
|
||||||
QApplication::restoreOverrideCursor();
|
|
||||||
setUpdatesEnabled(true);
|
setUpdatesEnabled(true);
|
||||||
emit startingCompleted();
|
emit startingCompleted();
|
||||||
}
|
}
|
||||||
|
@ -148,10 +149,12 @@ void QupZilla::setupUi()
|
||||||
m_privateBrowsing->setPixmap(QPixmap(":/icons/locationbar/privatebrowsing.png"));
|
m_privateBrowsing->setPixmap(QPixmap(":/icons/locationbar/privatebrowsing.png"));
|
||||||
m_privateBrowsing->setVisible(false);
|
m_privateBrowsing->setVisible(false);
|
||||||
m_privateBrowsing->setToolTip(tr("Private Browsing Enabled"));
|
m_privateBrowsing->setToolTip(tr("Private Browsing Enabled"));
|
||||||
m_allowFlashIcon = new QLabel(this);
|
m_adblockIcon = new ClickableLabel(this);
|
||||||
m_allowFlashIcon->setPixmap(QPixmap(":/icons/menu/flash.png"));
|
m_adblockIcon->setPixmap(QPixmap(":/icons/other/adblock.png"));
|
||||||
m_allowFlashIcon->setVisible(false);
|
m_adblockIcon->setMaximumHeight(16);
|
||||||
m_allowFlashIcon->setToolTip(tr("Flash Plugin Enabled"));
|
m_adblockIcon->setVisible(false);
|
||||||
|
m_adblockIcon->setCursor(Qt::PointingHandCursor);
|
||||||
|
m_adblockIcon->setToolTip(tr("Click to show AdBlock options"));
|
||||||
m_ipLabel = new QLabel(this);
|
m_ipLabel = new QLabel(this);
|
||||||
m_ipLabel->setStyleSheet("padding-right: 5px;");
|
m_ipLabel->setStyleSheet("padding-right: 5px;");
|
||||||
m_ipLabel->setToolTip(tr("IP Address of current page"));
|
m_ipLabel->setToolTip(tr("IP Address of current page"));
|
||||||
|
@ -159,7 +162,7 @@ void QupZilla::setupUi()
|
||||||
statusBar()->insertPermanentWidget(0, m_progressBar);
|
statusBar()->insertPermanentWidget(0, m_progressBar);
|
||||||
statusBar()->insertPermanentWidget(1, m_ipLabel);
|
statusBar()->insertPermanentWidget(1, m_ipLabel);
|
||||||
statusBar()->insertPermanentWidget(2, m_privateBrowsing);
|
statusBar()->insertPermanentWidget(2, m_privateBrowsing);
|
||||||
statusBar()->insertPermanentWidget(3, m_allowFlashIcon);
|
statusBar()->insertPermanentWidget(3, m_adblockIcon);
|
||||||
|
|
||||||
m_bookmarksToolbar = new BookmarksToolbar(this);
|
m_bookmarksToolbar = new BookmarksToolbar(this);
|
||||||
addToolBar(m_bookmarksToolbar);
|
addToolBar(m_bookmarksToolbar);
|
||||||
|
@ -285,6 +288,7 @@ void QupZilla::setupMenu()
|
||||||
connect(m_buttonReload, SIGNAL(triggered()), this, SLOT(reload()));
|
connect(m_buttonReload, SIGNAL(triggered()), this, SLOT(reload()));
|
||||||
connect(m_buttonHome, SIGNAL(triggered()), this, SLOT(goHome()));
|
connect(m_buttonHome, SIGNAL(triggered()), this, SLOT(goHome()));
|
||||||
connect(m_actionExitFullscreen, SIGNAL(triggered(bool)), this, SLOT(fullScreen(bool)));
|
connect(m_actionExitFullscreen, SIGNAL(triggered(bool)), this, SLOT(fullScreen(bool)));
|
||||||
|
connect(m_adblockIcon, SIGNAL(clicked(QPoint)), AdBlockManager::instance(), SLOT(showDialog()));
|
||||||
|
|
||||||
//Make shortcuts available even in fullscreen (menu hidden)
|
//Make shortcuts available even in fullscreen (menu hidden)
|
||||||
QList<QAction*> actions = menuBar()->actions();
|
QList<QAction*> actions = menuBar()->actions();
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#include "bookmarksmodel.h"
|
#include "bookmarksmodel.h"
|
||||||
#include "downloadmanager.h"
|
#include "downloadmanager.h"
|
||||||
#include "autofillmodel.h"
|
#include "autofillmodel.h"
|
||||||
|
#include "adblockmanager.h"
|
||||||
|
|
||||||
MainApplication::MainApplication(int &argc, char **argv)
|
MainApplication::MainApplication(int &argc, char **argv)
|
||||||
: QtSingleApplication("QupZillaWebBrowser", argc, argv)
|
: QtSingleApplication("QupZillaWebBrowser", argc, argv)
|
||||||
|
@ -53,12 +54,12 @@ MainApplication::MainApplication(int &argc, char **argv)
|
||||||
,m_isChanged(false)
|
,m_isChanged(false)
|
||||||
,m_isExited(false)
|
,m_isExited(false)
|
||||||
{
|
{
|
||||||
|
setOverrideCursor(Qt::WaitCursor);
|
||||||
#if defined(Q_WS_X11) & !defined(DEVELOPING)
|
#if defined(Q_WS_X11) & !defined(DEVELOPING)
|
||||||
DATADIR = "/usr/share/qupzilla/";
|
DATADIR = "/usr/share/qupzilla/";
|
||||||
#else
|
#else
|
||||||
DATADIR = qApp->applicationDirPath()+"/";
|
DATADIR = qApp->applicationDirPath()+"/";
|
||||||
#endif
|
#endif
|
||||||
setOverrideCursor(Qt::WaitCursor);
|
|
||||||
setWindowIcon(QIcon(":/icons/qupzilla.png"));
|
setWindowIcon(QIcon(":/icons/qupzilla.png"));
|
||||||
bool noAddons = false;
|
bool noAddons = false;
|
||||||
QUrl startUrl("");
|
QUrl startUrl("");
|
||||||
|
@ -122,6 +123,7 @@ MainApplication::MainApplication(int &argc, char **argv)
|
||||||
QupZilla* qupzilla = new QupZilla(true, startUrl);
|
QupZilla* qupzilla = new QupZilla(true, startUrl);
|
||||||
m_mainWindows.append(qupzilla);
|
m_mainWindows.append(qupzilla);
|
||||||
connect(qupzilla, SIGNAL(message(MainApplication::MessageType,bool)), this, SLOT(sendMessages(MainApplication::MessageType,bool)));
|
connect(qupzilla, SIGNAL(message(MainApplication::MessageType,bool)), this, SLOT(sendMessages(MainApplication::MessageType,bool)));
|
||||||
|
qApp->processEvents();
|
||||||
qupzilla->show();
|
qupzilla->show();
|
||||||
|
|
||||||
AutoSaver* saver = new AutoSaver();
|
AutoSaver* saver = new AutoSaver();
|
||||||
|
@ -136,6 +138,7 @@ MainApplication::MainApplication(int &argc, char **argv)
|
||||||
networkManager()->loadCertExceptions();
|
networkManager()->loadCertExceptions();
|
||||||
plugins()->loadPlugins();
|
plugins()->loadPlugins();
|
||||||
loadSettings();
|
loadSettings();
|
||||||
|
QApplication::restoreOverrideCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainApplication::loadSettings()
|
void MainApplication::loadSettings()
|
||||||
|
@ -314,6 +317,7 @@ void MainApplication::quitApplication()
|
||||||
cookieJar()->saveCookies();
|
cookieJar()->saveCookies();
|
||||||
m_networkmanager->saveCertExceptions();
|
m_networkmanager->saveCertExceptions();
|
||||||
m_plugins->c2f_saveSettings();
|
m_plugins->c2f_saveSettings();
|
||||||
|
AdBlockManager::instance()->save();
|
||||||
|
|
||||||
quit();
|
quit();
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,8 @@
|
||||||
#include "pluginproxy.h"
|
#include "pluginproxy.h"
|
||||||
#include "qtwin.h"
|
#include "qtwin.h"
|
||||||
#include "ui_closedialog.h"
|
#include "ui_closedialog.h"
|
||||||
|
#include "adblockmanager.h"
|
||||||
|
#include "clickablelabel.h"
|
||||||
|
|
||||||
const QString QupZilla::VERSION = "0.9.9";
|
const QString QupZilla::VERSION = "0.9.9";
|
||||||
const QString QupZilla::BUILDTIME = QLocale(QLocale::English).toDateTime(__DATE__" "__TIME__, "MMM dd yyyy hh:mm:ss").toString("MM/dd/yyyy hh:ss");
|
const QString QupZilla::BUILDTIME = QLocale(QLocale::English).toDateTime(__DATE__" "__TIME__, "MMM dd yyyy hh:mm:ss").toString("MM/dd/yyyy hh:ss");
|
||||||
|
@ -93,7 +95,7 @@ void QupZilla::loadSettings()
|
||||||
settings.beginGroup("Web-Browser-Settings");
|
settings.beginGroup("Web-Browser-Settings");
|
||||||
bool allowFlash = settings.value("allowFlash",true).toBool();
|
bool allowFlash = settings.value("allowFlash",true).toBool();
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
m_allowFlashIcon->setVisible(allowFlash);
|
m_adblockIcon->setVisible(allowFlash);
|
||||||
|
|
||||||
//Browser Window settings
|
//Browser Window settings
|
||||||
settings.beginGroup("Browser-View-Settings");
|
settings.beginGroup("Browser-View-Settings");
|
||||||
|
@ -156,7 +158,7 @@ void QupZilla::receiveMessage(MainApplication::MessageType mes, bool state)
|
||||||
{
|
{
|
||||||
switch (mes) {
|
switch (mes) {
|
||||||
case MainApplication::ShowFlashIcon:
|
case MainApplication::ShowFlashIcon:
|
||||||
m_allowFlashIcon->setVisible(state);
|
m_adblockIcon->setVisible(state);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MainApplication::CheckPrivateBrowsing:
|
case MainApplication::CheckPrivateBrowsing:
|
||||||
|
@ -368,6 +370,7 @@ void QupZilla::aboutToShowToolsMenu()
|
||||||
m_menuTools->addSeparator();
|
m_menuTools->addSeparator();
|
||||||
m_menuTools->addAction(tr("Download Manager"), this, SLOT(showDownloadManager()))->setShortcut(QKeySequence("Ctrl+Y"));
|
m_menuTools->addAction(tr("Download Manager"), this, SLOT(showDownloadManager()))->setShortcut(QKeySequence("Ctrl+Y"));
|
||||||
m_menuTools->addAction(tr("Cookies Manager"), this, SLOT(showCookieManager()));
|
m_menuTools->addAction(tr("Cookies Manager"), this, SLOT(showCookieManager()));
|
||||||
|
m_menuTools->addAction(tr("AdBlock"), AdBlockManager::instance(), SLOT(showDialog()));
|
||||||
m_menuTools->addAction(QIcon(":/icons/menu/rss.png"), tr("RSS Reader"), this, SLOT(showRSSManager()));
|
m_menuTools->addAction(QIcon(":/icons/menu/rss.png"), tr("RSS Reader"), this, SLOT(showRSSManager()));
|
||||||
m_menuTools->addAction(QIcon::fromTheme("edit-clear"), tr("Clear Recent History"), this, SLOT(showClearPrivateData()));
|
m_menuTools->addAction(QIcon::fromTheme("edit-clear"), tr("Clear Recent History"), this, SLOT(showClearPrivateData()));
|
||||||
m_actionPrivateBrowsing = new QAction(tr("Private Browsing"), this);
|
m_actionPrivateBrowsing = new QAction(tr("Private Browsing"), this);
|
||||||
|
@ -523,12 +526,12 @@ void QupZilla::showDownloadManager()
|
||||||
|
|
||||||
void QupZilla::showPreferences()
|
void QupZilla::showPreferences()
|
||||||
{
|
{
|
||||||
bool flashIconVisibility = m_allowFlashIcon->isVisible();
|
bool flashIconVisibility = m_adblockIcon->isVisible();
|
||||||
Preferences prefs(this, this);
|
Preferences prefs(this, this);
|
||||||
prefs.exec();
|
prefs.exec();
|
||||||
|
|
||||||
if (flashIconVisibility != m_allowFlashIcon->isVisible())
|
if (flashIconVisibility != m_adblockIcon->isVisible())
|
||||||
emit message(MainApplication::ShowFlashIcon, m_allowFlashIcon->isVisible());
|
emit message(MainApplication::ShowFlashIcon, m_adblockIcon->isVisible());
|
||||||
}
|
}
|
||||||
|
|
||||||
void QupZilla::showSource()
|
void QupZilla::showSource()
|
||||||
|
@ -750,7 +753,7 @@ QupZilla::~QupZilla()
|
||||||
{
|
{
|
||||||
delete m_tabWidget;
|
delete m_tabWidget;
|
||||||
delete m_privateBrowsing;
|
delete m_privateBrowsing;
|
||||||
delete m_allowFlashIcon;
|
delete m_adblockIcon;
|
||||||
delete m_menuBack;
|
delete m_menuBack;
|
||||||
delete m_menuForward;
|
delete m_menuForward;
|
||||||
delete m_locationBar;
|
delete m_locationBar;
|
||||||
|
|
|
@ -213,7 +213,7 @@ private:
|
||||||
QAction* m_actionReload;
|
QAction* m_actionReload;
|
||||||
|
|
||||||
QLabel* m_privateBrowsing;
|
QLabel* m_privateBrowsing;
|
||||||
QLabel* m_allowFlashIcon;
|
ClickableLabel* m_adblockIcon;
|
||||||
QPointer<QWebInspector> m_webInspector;
|
QPointer<QWebInspector> m_webInspector;
|
||||||
QPointer<QDockWidget> m_webInspectorDock;
|
QPointer<QDockWidget> m_webInspectorDock;
|
||||||
|
|
||||||
|
|
|
@ -69,5 +69,6 @@
|
||||||
<file>icons/preferences/document-properties.png</file>
|
<file>icons/preferences/document-properties.png</file>
|
||||||
<file>icons/preferences/stock_keyring.png</file>
|
<file>icons/preferences/stock_keyring.png</file>
|
||||||
<file>icons/other/list-add.png</file>
|
<file>icons/other/list-add.png</file>
|
||||||
|
<file>icons/other/adblock.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
BIN
src/data/icons/other/adblock.png
Normal file
BIN
src/data/icons/other/adblock.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
|
@ -35,6 +35,7 @@ HistoryManager::HistoryManager(QupZilla* mainClass, QWidget* parent) :
|
||||||
connect(ui->close, SIGNAL(clicked(QAbstractButton*)), this, SLOT(hide()));
|
connect(ui->close, SIGNAL(clicked(QAbstractButton*)), this, SLOT(hide()));
|
||||||
connect(ui->deleteB, SIGNAL(clicked()), this, SLOT(deleteItem()));
|
connect(ui->deleteB, SIGNAL(clicked()), this, SLOT(deleteItem()));
|
||||||
connect(ui->clearAll, SIGNAL(clicked()), this, SLOT(clearHistory()));
|
connect(ui->clearAll, SIGNAL(clicked()), this, SLOT(clearHistory()));
|
||||||
|
// connect(ui->search, SIGNAL(textChanged(QString)), ui->historyTree, SLOT(filterStringWithoutTopItems(QString)));
|
||||||
connect(ui->search, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(search()));
|
connect(ui->search, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(search()));
|
||||||
connect(ui->historyTree, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenuRequested(const QPoint &)));
|
connect(ui->historyTree, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenuRequested(const QPoint &)));
|
||||||
connect(ui->historyTree, SIGNAL(itemControlClicked(QTreeWidgetItem*)), this, SLOT(itemControlClicked(QTreeWidgetItem*)));
|
connect(ui->historyTree, SIGNAL(itemControlClicked(QTreeWidgetItem*)), this, SLOT(itemControlClicked(QTreeWidgetItem*)));
|
||||||
|
|
|
@ -21,9 +21,13 @@
|
||||||
#include "networkmanagerproxy.h"
|
#include "networkmanagerproxy.h"
|
||||||
#include "mainapplication.h"
|
#include "mainapplication.h"
|
||||||
#include "webpage.h"
|
#include "webpage.h"
|
||||||
|
#include "pluginproxy.h"
|
||||||
|
#include "adblockmanager.h"
|
||||||
|
#include "adblocknetwork.h"
|
||||||
|
|
||||||
NetworkManager::NetworkManager(QupZilla* mainClass, QObject* parent) :
|
NetworkManager::NetworkManager(QupZilla* mainClass, QObject* parent) :
|
||||||
NetworkManagerProxy(mainClass, parent)
|
NetworkManagerProxy(mainClass, parent)
|
||||||
|
,m_adblockNetwork(0)
|
||||||
,p_QupZilla(mainClass)
|
,p_QupZilla(mainClass)
|
||||||
,m_ignoreAllWarnings(false)
|
,m_ignoreAllWarnings(false)
|
||||||
{
|
{
|
||||||
|
@ -181,9 +185,20 @@ QNetworkReply* NetworkManager::createRequest(QNetworkAccessManager::Operation op
|
||||||
|
|
||||||
QNetworkRequest req = request;
|
QNetworkRequest req = request;
|
||||||
req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
|
req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
|
||||||
QNetworkReply* reply = QNetworkAccessManager::createRequest(op, req, outgoingData);
|
|
||||||
|
|
||||||
//emit requestCreated(op, request, reply);
|
|
||||||
|
// if (QNetworkReply* repl = mApp->plugins()->createNetworkRequest(op, request, outgoingData))
|
||||||
|
// return repl;
|
||||||
|
// Adblock
|
||||||
|
if (op == QNetworkAccessManager::GetOperation) {
|
||||||
|
if (!m_adblockNetwork)
|
||||||
|
m_adblockNetwork = AdBlockManager::instance()->network();
|
||||||
|
QNetworkReply* reply = m_adblockNetwork->block(req);
|
||||||
|
if (reply)
|
||||||
|
return reply;
|
||||||
|
}
|
||||||
|
|
||||||
|
QNetworkReply* reply = QNetworkAccessManager::createRequest(op, req, outgoingData);
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include "networkmanagerproxy.h"
|
#include "networkmanagerproxy.h"
|
||||||
|
|
||||||
class QupZilla;
|
class QupZilla;
|
||||||
|
class AdBlockNetwork;
|
||||||
class NetworkManager : public NetworkManagerProxy
|
class NetworkManager : public NetworkManagerProxy
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -56,6 +57,7 @@ public slots:
|
||||||
void setSSLConfiguration(QNetworkReply* reply);
|
void setSSLConfiguration(QNetworkReply* reply);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
AdBlockNetwork* m_adblockNetwork;
|
||||||
QupZilla* p_QupZilla;
|
QupZilla* p_QupZilla;
|
||||||
QList<QSslCertificate> m_certExceptions;
|
QList<QSslCertificate> m_certExceptions;
|
||||||
QNetworkDiskCache* m_diskCache;
|
QNetworkDiskCache* m_diskCache;
|
||||||
|
|
|
@ -53,6 +53,8 @@ public:
|
||||||
virtual void formSent(const QNetworkRequest &request, const QByteArray &outgoingData) { Q_UNUSED(request) Q_UNUSED(outgoingData)}
|
virtual void formSent(const QNetworkRequest &request, const QByteArray &outgoingData) { Q_UNUSED(request) Q_UNUSED(outgoingData)}
|
||||||
virtual void pageLoaded(QWebView* view) { Q_UNUSED(view) }
|
virtual void pageLoaded(QWebView* view) { Q_UNUSED(view) }
|
||||||
virtual void downloadRequested(QWidget* requestWidget) { Q_UNUSED(requestWidget) }
|
virtual void downloadRequested(QWidget* requestWidget) { Q_UNUSED(requestWidget) }
|
||||||
|
virtual QNetworkReply* createNetworkRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice* outgoingData)
|
||||||
|
{ Q_UNUSED(op) Q_UNUSED(request) Q_UNUSED(outgoingData) return 0; }
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_INTERFACE(PluginInterface, "Qupzilla.Browser.PluginInterface/1.0")
|
Q_DECLARE_INTERFACE(PluginInterface, "Qupzilla.Browser.PluginInterface/1.0")
|
||||||
|
|
|
@ -37,7 +37,7 @@ void PluginProxy::populateWebViewMenu(QMenu* menu, QWebView* view, QWebHitTestRe
|
||||||
iPlugin->populateWebViewMenu(menu, view, r);
|
iPlugin->populateWebViewMenu(menu, view, r);
|
||||||
|
|
||||||
if (menu->actions().count() == count)
|
if (menu->actions().count() == count)
|
||||||
menu->removeAction(menu->actions().at(count));
|
menu->removeAction(menu->actions().at(count-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PluginProxy::populateToolsMenu(QMenu* menu)
|
void PluginProxy::populateToolsMenu(QMenu* menu)
|
||||||
|
@ -68,6 +68,17 @@ void PluginProxy::populateHelpMenu(QMenu* menu)
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QNetworkReply* PluginProxy::createNetworkRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *outgoingData)
|
||||||
|
{
|
||||||
|
QNetworkReply* reply = 0;
|
||||||
|
foreach(PluginInterface* iPlugin, loadedPlugins) {
|
||||||
|
reply = iPlugin->createNetworkRequest(op, request, outgoingData);
|
||||||
|
if (reply)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return reply;
|
||||||
|
}
|
||||||
|
|
||||||
void PluginProxy::c2f_loadSettings()
|
void PluginProxy::c2f_loadSettings()
|
||||||
{
|
{
|
||||||
QSettings settings(mApp->getActiveProfil()+"settings.ini", QSettings::IniFormat);
|
QSettings settings(mApp->getActiveProfil()+"settings.ini", QSettings::IniFormat);
|
||||||
|
|
|
@ -32,6 +32,7 @@ public:
|
||||||
void populateWebViewMenu(QMenu* menu, QWebView* view, QWebHitTestResult r);
|
void populateWebViewMenu(QMenu* menu, QWebView* view, QWebHitTestResult r);
|
||||||
void populateToolsMenu(QMenu* menu);
|
void populateToolsMenu(QMenu* menu);
|
||||||
void populateHelpMenu(QMenu* menu);
|
void populateHelpMenu(QMenu* menu);
|
||||||
|
QNetworkReply* createNetworkRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice* outgoingData);
|
||||||
|
|
||||||
// CLick2Flash
|
// CLick2Flash
|
||||||
void c2f_loadSettings();
|
void c2f_loadSettings();
|
||||||
|
|
|
@ -77,6 +77,7 @@ PluginInterface* Plugins::getPlugin(QString pluginFileName)
|
||||||
return 0;
|
return 0;
|
||||||
QPluginLoader loader(path);
|
QPluginLoader loader(path);
|
||||||
QObject* plugin = loader.instance();
|
QObject* plugin = loader.instance();
|
||||||
|
|
||||||
if (plugin) {
|
if (plugin) {
|
||||||
PluginInterface* iPlugin = qobject_cast<PluginInterface*>(plugin);
|
PluginInterface* iPlugin = qobject_cast<PluginInterface*>(plugin);
|
||||||
return iPlugin;
|
return iPlugin;
|
||||||
|
|
|
@ -29,3 +29,55 @@ void TreeWidget::mousePressEvent(QMouseEvent* event)
|
||||||
|
|
||||||
QTreeWidget::mousePressEvent(event);
|
QTreeWidget::mousePressEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<QTreeWidgetItem*> allTreeItems;
|
||||||
|
void iterateAllItems(QTreeWidgetItem* parent, QTreeWidget* treeWidget, bool includeTopLevelItems = true)
|
||||||
|
{
|
||||||
|
int count = parent ? parent->childCount() : treeWidget->topLevelItemCount();
|
||||||
|
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
QTreeWidgetItem *item =
|
||||||
|
parent ? parent->child(i) : treeWidget->topLevelItem(i);
|
||||||
|
|
||||||
|
if (includeTopLevelItems)
|
||||||
|
allTreeItems.append(item);
|
||||||
|
else if (item->childCount() == 0)
|
||||||
|
allTreeItems.append(item);
|
||||||
|
|
||||||
|
iterateAllItems(item, treeWidget, includeTopLevelItems);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<QTreeWidgetItem*> TreeWidget::allItems(bool includeTopLevelItems)
|
||||||
|
{
|
||||||
|
allTreeItems.clear();
|
||||||
|
iterateAllItems(0, this, includeTopLevelItems);
|
||||||
|
return allTreeItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TreeWidget::filterStringWithoutTopItems(QString string)
|
||||||
|
{
|
||||||
|
QList<QTreeWidgetItem*> _allItems = allItems(false);
|
||||||
|
|
||||||
|
if (string.isEmpty()) {
|
||||||
|
foreach (QTreeWidgetItem* item, _allItems)
|
||||||
|
item->setHidden(false);
|
||||||
|
} else {
|
||||||
|
foreach (QTreeWidgetItem* item, _allItems)
|
||||||
|
item->setHidden(!item->text(0).contains(string));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TreeWidget::filterStringWithTopItems(QString string)
|
||||||
|
{
|
||||||
|
QList<QTreeWidgetItem*> _allItems = allItems();
|
||||||
|
|
||||||
|
if (string.isEmpty()) {
|
||||||
|
foreach (QTreeWidgetItem* item, _allItems)
|
||||||
|
item->setHidden(false);
|
||||||
|
} else {
|
||||||
|
foreach (QTreeWidgetItem* item, _allItems)
|
||||||
|
item->setHidden(!item->text(0).contains(string));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -27,11 +27,14 @@ class TreeWidget : public QTreeWidget
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit TreeWidget(QWidget* parent = 0);
|
explicit TreeWidget(QWidget* parent = 0);
|
||||||
|
QList<QTreeWidgetItem*> allItems(bool includeTopLevelItems = true);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void itemControlClicked(QTreeWidgetItem* item);
|
void itemControlClicked(QTreeWidgetItem* item);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void filterStringWithTopItems(QString string);
|
||||||
|
void filterStringWithoutTopItems(QString string);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void mousePressEvent(QMouseEvent* event);
|
void mousePressEvent(QMouseEvent* event);
|
||||||
|
|
|
@ -27,6 +27,7 @@ WebPage::WebPage(WebView* parent, QupZilla* mainClass)
|
||||||
: QWebPage(parent)
|
: QWebPage(parent)
|
||||||
,p_QupZilla(mainClass)
|
,p_QupZilla(mainClass)
|
||||||
,m_view(parent)
|
,m_view(parent)
|
||||||
|
// ,m_isOpeningNextWindowAsNewTab(false)
|
||||||
{
|
{
|
||||||
setForwardUnsupportedContent(true);
|
setForwardUnsupportedContent(true);
|
||||||
setPluginFactory(new WebPluginFactory(this));
|
setPluginFactory(new WebPluginFactory(this));
|
||||||
|
@ -54,7 +55,6 @@ void WebPage::handleUnsupportedContent(QNetworkReply* reply)
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
qDebug() << reply->errorString();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
qDebug() << "WebPage::UnsupportedContent error" << reply->errorString();
|
qDebug() << "WebPage::UnsupportedContent error" << reply->errorString();
|
||||||
|
@ -88,7 +88,8 @@ bool WebPage::acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest &r
|
||||||
|
|
||||||
bool accept = QWebPage::acceptNavigationRequest(frame, request, type);
|
bool accept = QWebPage::acceptNavigationRequest(frame, request, type);
|
||||||
if (accept && openIn == TabWidget::NewTab) {
|
if (accept && openIn == TabWidget::NewTab) {
|
||||||
//p_QupZilla->tabWidget()->addView(request.url(),tr("New tab"), openIn);
|
// m_isOpeningNextWindowAsNewTab = true;
|
||||||
|
// p_QupZilla->tabWidget()->addView(request.url(),tr("New tab"), openIn);
|
||||||
}
|
}
|
||||||
return accept;
|
return accept;
|
||||||
}
|
}
|
||||||
|
@ -110,6 +111,13 @@ void WebPage::populateNetworkRequest(QNetworkRequest &request)
|
||||||
|
|
||||||
QWebPage* WebPage::createWindow(QWebPage::WebWindowType type)
|
QWebPage* WebPage::createWindow(QWebPage::WebWindowType type)
|
||||||
{
|
{
|
||||||
|
// if (m_isOpeningNextWindowAsNewTab)
|
||||||
|
// return 0;
|
||||||
|
// m_isOpeningNextWindowAsNewTab = false;
|
||||||
|
// qDebug() << type;
|
||||||
|
// QWebView* view = new QWebView();
|
||||||
|
// view->show();
|
||||||
|
// return view->page();
|
||||||
Q_UNUSED(type);
|
Q_UNUSED(type);
|
||||||
int index = p_QupZilla->tabWidget()->addView();
|
int index = p_QupZilla->tabWidget()->addView();
|
||||||
return p_QupZilla->weView(index)->page();
|
return p_QupZilla->weView(index)->page();
|
||||||
|
|
|
@ -59,6 +59,7 @@ protected:
|
||||||
QWebPage::NavigationType m_lastRequestType;
|
QWebPage::NavigationType m_lastRequestType;
|
||||||
WebView* m_view;
|
WebView* m_view;
|
||||||
QSslCertificate m_SslCert;
|
QSslCertificate m_SslCert;
|
||||||
|
// bool m_isOpeningNextWindowAsNewTab;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WEBPAGE_H
|
#endif // WEBPAGE_H
|
||||||
|
|
Loading…
Reference in New Issue
Block a user