mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +01:00
Added AdBlock icon at the right corner of status bar which shows actual
status of AdBlock as well as shows blocked content on page
This commit is contained in:
parent
77b31b8f85
commit
d7f7f7843f
@ -46,27 +46,23 @@
|
|||||||
#include "adblockmanager.h"
|
#include "adblockmanager.h"
|
||||||
#include "adblocksubscription.h"
|
#include "adblocksubscription.h"
|
||||||
#include "ui_adblockdialog.h"
|
#include "ui_adblockdialog.h"
|
||||||
|
#include "mainapplication.h"
|
||||||
|
|
||||||
AdBlockDialog::AdBlockDialog(QWidget *parent)
|
AdBlockDialog::AdBlockDialog(QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
, m_itemChangingBlock(false)
|
, m_itemChangingBlock(false)
|
||||||
|
, m_manager(AdBlockManager::instance())
|
||||||
{
|
{
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
// m_adBlockModel = new AdBlockModel(this);
|
adblockCheckBox->setChecked(m_manager->isEnabled());
|
||||||
// m_proxyModel = new TreeSortFilterProxyModel(this);
|
connect(adblockCheckBox, SIGNAL(toggled(bool)), m_manager, SLOT(setEnabled(bool)));
|
||||||
// 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(addButton, SIGNAL(clicked()), this, SLOT(addCustomRule()));
|
||||||
connect(reloadButton, SIGNAL(clicked()), this, SLOT(updateSubscription()));
|
connect(reloadButton, SIGNAL(clicked()), this, SLOT(updateSubscription()));
|
||||||
connect(search, SIGNAL(textChanged(QString)), treeWidget, SLOT(filterStringWithoutTopItems(QString)));
|
connect(search, SIGNAL(textChanged(QString)), treeWidget, SLOT(filterStringWithoutTopItems(QString)));
|
||||||
connect(manager->subscription(), SIGNAL(changed()), this, SLOT(refreshAfterUpdate()));
|
connect(m_manager->subscription(), SIGNAL(changed()), this, SLOT(refreshAfterUpdate()));
|
||||||
|
|
||||||
QTimer::singleShot(0, this, SLOT(firstRefresh()));
|
// QTimer::singleShot(0, this, SLOT(firstRefresh()));
|
||||||
|
firstRefresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockDialog::firstRefresh()
|
void AdBlockDialog::firstRefresh()
|
||||||
@ -86,7 +82,6 @@ void AdBlockDialog::refresh()
|
|||||||
m_itemChangingBlock = true;
|
m_itemChangingBlock = true;
|
||||||
treeWidget->setUpdatesEnabled(false);
|
treeWidget->setUpdatesEnabled(false);
|
||||||
treeWidget->clear();
|
treeWidget->clear();
|
||||||
AdBlockManager *manager = AdBlockManager::instance();
|
|
||||||
|
|
||||||
QFont boldFont;
|
QFont boldFont;
|
||||||
boldFont.setBold(true);
|
boldFont.setBold(true);
|
||||||
@ -104,7 +99,7 @@ void AdBlockDialog::refresh()
|
|||||||
treeWidget->addTopLevelItem(m_easyListItem);
|
treeWidget->addTopLevelItem(m_easyListItem);
|
||||||
|
|
||||||
bool customRulesStarted = false;
|
bool customRulesStarted = false;
|
||||||
QList<AdBlockRule> allRules = manager->subscription()->allRules();
|
QList<AdBlockRule> allRules = m_manager->subscription()->allRules();
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
foreach (const AdBlockRule rule, allRules) {
|
foreach (const AdBlockRule rule, allRules) {
|
||||||
@ -143,7 +138,7 @@ void AdBlockDialog::itemChanged(QTreeWidgetItem *item)
|
|||||||
item->setText(0, item->text(0).prepend("!"));
|
item->setText(0, item->text(0).prepend("!"));
|
||||||
|
|
||||||
AdBlockRule rul(item->text(0));
|
AdBlockRule rul(item->text(0));
|
||||||
AdBlockManager::instance()->subscription()->replaceRule(rul, offset);
|
m_manager->subscription()->replaceRule(rul, offset);
|
||||||
|
|
||||||
} else if (item->checkState(0) == Qt::Checked && item->text(0).startsWith("!")) { //Enable rule
|
} else if (item->checkState(0) == Qt::Checked && item->text(0).startsWith("!")) { //Enable rule
|
||||||
int offset = item->whatsThis(0).toInt();
|
int offset = item->whatsThis(0).toInt();
|
||||||
@ -152,13 +147,13 @@ void AdBlockDialog::itemChanged(QTreeWidgetItem *item)
|
|||||||
item->setText(0, newText);
|
item->setText(0, newText);
|
||||||
|
|
||||||
AdBlockRule rul(newText);
|
AdBlockRule rul(newText);
|
||||||
AdBlockManager::instance()->subscription()->replaceRule(rul, offset);
|
m_manager->subscription()->replaceRule(rul, offset);
|
||||||
|
|
||||||
} else { //Custom rule has been changed
|
} else { //Custom rule has been changed
|
||||||
int offset = item->whatsThis(0).toInt();
|
int offset = item->whatsThis(0).toInt();
|
||||||
|
|
||||||
AdBlockRule rul(item->text(0));
|
AdBlockRule rul(item->text(0));
|
||||||
AdBlockManager::instance()->subscription()->replaceRule(rul, offset);
|
m_manager->subscription()->replaceRule(rul, offset);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,8 +167,7 @@ void AdBlockDialog::addCustomRule()
|
|||||||
if (newRule.isEmpty())
|
if (newRule.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
AdBlockManager *manager = AdBlockManager::instance();
|
AdBlockSubscription *subscription = m_manager->subscription();
|
||||||
AdBlockSubscription *subscription = manager->subscription();
|
|
||||||
subscription->addRule(AdBlockRule(newRule));
|
subscription->addRule(AdBlockRule(newRule));
|
||||||
m_itemChangingBlock = true;
|
m_itemChangingBlock = true;
|
||||||
QTreeWidgetItem* item = new QTreeWidgetItem(m_customListItem);
|
QTreeWidgetItem* item = new QTreeWidgetItem(m_customListItem);
|
||||||
@ -186,6 +180,6 @@ void AdBlockDialog::addCustomRule()
|
|||||||
|
|
||||||
void AdBlockDialog::updateSubscription()
|
void AdBlockDialog::updateSubscription()
|
||||||
{
|
{
|
||||||
AdBlockSubscription *subscription = AdBlockManager::instance()->subscription();
|
AdBlockSubscription *subscription = m_manager->subscription();
|
||||||
subscription->updateNow();
|
subscription->updateNow();
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,7 @@
|
|||||||
#include "ui_adblockdialog.h"
|
#include "ui_adblockdialog.h"
|
||||||
|
|
||||||
class AdBlockModel;
|
class AdBlockModel;
|
||||||
|
class AdBlockManager;
|
||||||
class TreeSortFilterProxyModel;
|
class TreeSortFilterProxyModel;
|
||||||
class AdBlockDialog : public QDialog, public Ui_AdBlockDialog
|
class AdBlockDialog : public QDialog, public Ui_AdBlockDialog
|
||||||
{
|
{
|
||||||
@ -82,6 +83,7 @@ private:
|
|||||||
bool m_itemChangingBlock;
|
bool m_itemChangingBlock;
|
||||||
QTreeWidgetItem* m_customListItem;
|
QTreeWidgetItem* m_customListItem;
|
||||||
QTreeWidgetItem* m_easyListItem;
|
QTreeWidgetItem* m_easyListItem;
|
||||||
|
AdBlockManager* m_manager;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
66
src/adblock/adblockicon.cpp
Normal file
66
src/adblock/adblockicon.cpp
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/* ============================================================
|
||||||
|
* 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/>.
|
||||||
|
* ============================================================ */
|
||||||
|
#include "adblockicon.h"
|
||||||
|
#include "adblockmanager.h"
|
||||||
|
#include "qupzilla.h"
|
||||||
|
#include "webpage.h"
|
||||||
|
|
||||||
|
AdBlockIcon::AdBlockIcon(QupZilla *mainClass, QWidget *parent)
|
||||||
|
:ClickableLabel(parent)
|
||||||
|
,p_QupZilla(mainClass)
|
||||||
|
{
|
||||||
|
setPixmap(QPixmap(":/icons/other/adblock.png"));
|
||||||
|
setMaximumHeight(16);
|
||||||
|
setCursor(Qt::PointingHandCursor);
|
||||||
|
setToolTip(tr("AdBlock let you block any unwanted content on pages"));
|
||||||
|
|
||||||
|
connect(this, SIGNAL(clicked(QPoint)), this, SLOT(showMenu(QPoint)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void AdBlockIcon::showMenu(const QPoint &pos)
|
||||||
|
{
|
||||||
|
AdBlockManager* manager = AdBlockManager::instance();
|
||||||
|
|
||||||
|
QMenu menu;
|
||||||
|
menu.addAction(tr("Show AdBlock Settings"), manager, SLOT(showDialog()));
|
||||||
|
menu.addSeparator();
|
||||||
|
QList<WebPage::AdBlockedEntry> entries = p_QupZilla->weView()->webPage()->adBlockedEntries();
|
||||||
|
if (entries.isEmpty())
|
||||||
|
menu.addAction(tr("No content blocked"))->setEnabled(false);
|
||||||
|
else {
|
||||||
|
menu.addAction(tr("Blocked URL (AdBlock Rule) - click to edit rule"))->setEnabled(false);
|
||||||
|
foreach (WebPage::AdBlockedEntry entry, entries) {
|
||||||
|
QString address = entry.url.toString().right(55);
|
||||||
|
menu.addAction(tr("%1 with (%2)").arg(address, entry.rule), manager, SLOT(showRule()))->setData(entry.rule);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
menu.addSeparator();
|
||||||
|
menu.addAction(tr("Learn About Writing Rules"), this, SLOT(learnAboutRules()));
|
||||||
|
|
||||||
|
menu.exec(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AdBlockIcon::learnAboutRules()
|
||||||
|
{
|
||||||
|
p_QupZilla->tabWidget()->addView(QUrl("http://adblockplus.org/en/filters"), tr("New tab"), TabWidget::NewSelectedTab);
|
||||||
|
}
|
||||||
|
|
||||||
|
AdBlockIcon::~AdBlockIcon()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
47
src/adblock/adblockicon.h
Normal file
47
src/adblock/adblockicon.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/* ============================================================
|
||||||
|
* 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/>.
|
||||||
|
* ============================================================ */
|
||||||
|
#ifndef ADBLOCKICON_H
|
||||||
|
#define ADBLOCKICON_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QMenu>
|
||||||
|
|
||||||
|
#include "clickablelabel.h"
|
||||||
|
|
||||||
|
class QupZilla;
|
||||||
|
class AdBlockIcon : public ClickableLabel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit AdBlockIcon(QupZilla* mainClass, QWidget* parent = 0);
|
||||||
|
~AdBlockIcon();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void showMenu(const QPoint &pos);
|
||||||
|
void learnAboutRules();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QupZilla* p_QupZilla;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ADBLOCKICON_H
|
@ -65,10 +65,9 @@ AdBlockManager::AdBlockManager(QObject* parent)
|
|||||||
|
|
||||||
AdBlockManager* AdBlockManager::instance()
|
AdBlockManager* AdBlockManager::instance()
|
||||||
{
|
{
|
||||||
if (!s_adBlockManager) {
|
if (!s_adBlockManager)
|
||||||
qDebug() << "creating adblock manager";
|
|
||||||
s_adBlockManager = new AdBlockManager(mApp->networkManager());
|
s_adBlockManager = new AdBlockManager(mApp->networkManager());
|
||||||
}
|
|
||||||
return s_adBlockManager;
|
return s_adBlockManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,6 +77,7 @@ void AdBlockManager::setEnabled(bool enabled)
|
|||||||
return;
|
return;
|
||||||
m_enabled = enabled;
|
m_enabled = enabled;
|
||||||
emit rulesChanged();
|
emit rulesChanged();
|
||||||
|
mApp->sendMessages(MainApplication::SetAdBlockIconEnabled, enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
AdBlockNetwork* AdBlockManager::network()
|
AdBlockNetwork* AdBlockManager::network()
|
||||||
@ -132,6 +132,14 @@ AdBlockDialog* AdBlockManager::showDialog()
|
|||||||
return m_adBlockDialog;
|
return m_adBlockDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AdBlockManager::showRule()
|
||||||
|
{
|
||||||
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
||||||
|
AdBlockDialog* dialog = showDialog();
|
||||||
|
dialog->search->setText(action->data().toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
AdBlockManager::~AdBlockManager()
|
AdBlockManager::~AdBlockManager()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,8 @@ public:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setEnabled(bool enabled);
|
void setEnabled(bool enabled);
|
||||||
AdBlockDialog *showDialog();
|
AdBlockDialog* showDialog();
|
||||||
|
void showRule();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static AdBlockManager* s_adBlockManager;
|
static AdBlockManager* s_adBlockManager;
|
||||||
@ -86,8 +87,8 @@ private:
|
|||||||
bool m_loaded;
|
bool m_loaded;
|
||||||
bool m_enabled;
|
bool m_enabled;
|
||||||
QPointer<AdBlockDialog> m_adBlockDialog;
|
QPointer<AdBlockDialog> m_adBlockDialog;
|
||||||
AdBlockNetwork *m_adBlockNetwork;
|
AdBlockNetwork* m_adBlockNetwork;
|
||||||
AdBlockPage *m_adBlockPage;
|
AdBlockPage* m_adBlockPage;
|
||||||
AdBlockSubscription* m_subscription;
|
AdBlockSubscription* m_subscription;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -48,19 +48,20 @@
|
|||||||
#include "adblockmanager.h"
|
#include "adblockmanager.h"
|
||||||
#include "adblocksubscription.h"
|
#include "adblocksubscription.h"
|
||||||
#include "mainapplication.h"
|
#include "mainapplication.h"
|
||||||
|
#include "webpage.h"
|
||||||
|
|
||||||
AdBlockNetwork::AdBlockNetwork(QObject *parent)
|
AdBlockNetwork::AdBlockNetwork(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QNetworkReply *AdBlockNetwork::block(const QNetworkRequest &request)
|
QNetworkReply* AdBlockNetwork::block(const QNetworkRequest &request)
|
||||||
{
|
{
|
||||||
QUrl url = request.url();
|
QUrl url = request.url();
|
||||||
if (url.scheme() == "data")
|
if (url.scheme() == "data")
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
AdBlockManager *manager = AdBlockManager::instance();
|
AdBlockManager* manager = AdBlockManager::instance();
|
||||||
if (!manager->isEnabled())
|
if (!manager->isEnabled())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -71,11 +72,16 @@ QNetworkReply *AdBlockNetwork::block(const QNetworkRequest &request)
|
|||||||
if (subscription->allow(urlString))
|
if (subscription->allow(urlString))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (const AdBlockRule *rule = subscription->block(urlString))
|
if (const AdBlockRule* rule = subscription->block(urlString))
|
||||||
blockedRule = rule;
|
blockedRule = rule;
|
||||||
|
|
||||||
if (blockedRule) {
|
if (blockedRule) {
|
||||||
AdBlockBlockedNetworkReply *reply = new AdBlockBlockedNetworkReply(request, blockedRule, this);
|
QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100));
|
||||||
|
WebPage* webPage = (WebPage*)(v.value<void*>());
|
||||||
|
if (webPage)
|
||||||
|
webPage->addAdBlockRule(blockedRule->filter(), request.url());
|
||||||
|
|
||||||
|
AdBlockBlockedNetworkReply* reply = new AdBlockBlockedNetworkReply(request, blockedRule, this);
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -47,7 +47,7 @@
|
|||||||
#include "networkmanager.h"
|
#include "networkmanager.h"
|
||||||
// #define ADBLOCKSUBSCRIPTION_DEBUG
|
// #define ADBLOCKSUBSCRIPTION_DEBUG
|
||||||
|
|
||||||
AdBlockSubscription::AdBlockSubscription(QObject *parent)
|
AdBlockSubscription::AdBlockSubscription(QObject* parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_downloading(0)
|
, m_downloading(0)
|
||||||
{
|
{
|
||||||
@ -88,14 +88,14 @@ void AdBlockSubscription::updateNow()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
QNetworkRequest request(QUrl("https://easylist-downloads.adblockplus.org/easylist.txt"));
|
QNetworkRequest request(QUrl("https://easylist-downloads.adblockplus.org/easylist.txt"));
|
||||||
QNetworkReply *reply = mApp->networkManager()->get(request);
|
QNetworkReply* reply = mApp->networkManager()->get(request);
|
||||||
m_downloading = reply;
|
m_downloading = reply;
|
||||||
connect(reply, SIGNAL(finished()), this, SLOT(rulesDownloaded()));
|
connect(reply, SIGNAL(finished()), this, SLOT(rulesDownloaded()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockSubscription::rulesDownloaded()
|
void AdBlockSubscription::rulesDownloaded()
|
||||||
{
|
{
|
||||||
QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
|
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
|
||||||
if (!reply)
|
if (!reply)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ void AdBlockSubscription::rulesDownloaded()
|
|||||||
|
|
||||||
QString fileName = mApp->getActiveProfil()+"adblocklist.txt";
|
QString fileName = mApp->getActiveProfil()+"adblocklist.txt";
|
||||||
QFile file(fileName);
|
QFile file(fileName);
|
||||||
if (!file.open(QFile::ReadWrite)) {
|
if (!file.open(QFile::WriteOnly)) {
|
||||||
qWarning() << "AdBlockSubscription::" << __FUNCTION__ << "Unable to open adblock file for writing:" << fileName;
|
qWarning() << "AdBlockSubscription::" << __FUNCTION__ << "Unable to open adblock file for writing:" << fileName;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -155,7 +155,7 @@ void AdBlockSubscription::saveRules()
|
|||||||
|
|
||||||
const AdBlockRule* AdBlockSubscription::allow(const QString &urlString) const
|
const AdBlockRule* AdBlockSubscription::allow(const QString &urlString) const
|
||||||
{
|
{
|
||||||
foreach (const AdBlockRule *rule, m_networkExceptionRules) {
|
foreach (const AdBlockRule* rule, m_networkExceptionRules) {
|
||||||
if (rule->networkMatch(urlString))
|
if (rule->networkMatch(urlString))
|
||||||
return rule;
|
return rule;
|
||||||
}
|
}
|
||||||
@ -208,7 +208,7 @@ void AdBlockSubscription::populateCache()
|
|||||||
m_pageRules.clear();
|
m_pageRules.clear();
|
||||||
|
|
||||||
for (int i = 0; i < m_rules.count(); ++i) {
|
for (int i = 0; i < m_rules.count(); ++i) {
|
||||||
const AdBlockRule *rule = &m_rules.at(i);
|
const AdBlockRule* rule = &m_rules.at(i);
|
||||||
if (!rule->isEnabled())
|
if (!rule->isEnabled())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -77,8 +77,8 @@ public:
|
|||||||
|
|
||||||
void saveRules();
|
void saveRules();
|
||||||
|
|
||||||
const AdBlockRule *allow(const QString &urlString) const;
|
const AdBlockRule* allow(const QString &urlString) const;
|
||||||
const AdBlockRule *block(const QString &urlString) const;
|
const AdBlockRule* block(const QString &urlString) const;
|
||||||
QList<const AdBlockRule*> pageRules() const { return m_pageRules; }
|
QList<const AdBlockRule*> pageRules() const { return m_pageRules; }
|
||||||
|
|
||||||
QList<AdBlockRule> allRules() const;
|
QList<AdBlockRule> allRules() const;
|
||||||
@ -98,7 +98,7 @@ private:
|
|||||||
QString m_title;
|
QString m_title;
|
||||||
bool m_enabled;
|
bool m_enabled;
|
||||||
|
|
||||||
QNetworkReply *m_downloading;
|
QNetworkReply* m_downloading;
|
||||||
QList<AdBlockRule> m_rules;
|
QList<AdBlockRule> m_rules;
|
||||||
|
|
||||||
// sorted list
|
// sorted list
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#include "bookmarkstoolbar.h"
|
#include "bookmarkstoolbar.h"
|
||||||
#include "locationbar.h"
|
#include "locationbar.h"
|
||||||
#include "clickablelabel.h"
|
#include "clickablelabel.h"
|
||||||
#include "adblockmanager.h"
|
#include "adblockicon.h"
|
||||||
|
|
||||||
void QupZilla::postLaunch()
|
void QupZilla::postLaunch()
|
||||||
{
|
{
|
||||||
@ -149,12 +149,7 @@ 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_adblockIcon = new ClickableLabel(this);
|
m_adblockIcon = new AdBlockIcon(this);
|
||||||
m_adblockIcon->setPixmap(QPixmap(":/icons/other/adblock.png"));
|
|
||||||
m_adblockIcon->setMaximumHeight(16);
|
|
||||||
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"));
|
||||||
@ -288,7 +283,6 @@ 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();
|
||||||
|
@ -50,7 +50,7 @@ public:
|
|||||||
QString DATADIR;
|
QString DATADIR;
|
||||||
explicit MainApplication(int &argc, char **argv);
|
explicit MainApplication(int &argc, char **argv);
|
||||||
|
|
||||||
enum MessageType{ ShowFlashIcon, CheckPrivateBrowsing };
|
enum MessageType{ SetAdBlockIconEnabled, CheckPrivateBrowsing };
|
||||||
|
|
||||||
void loadSettings();
|
void loadSettings();
|
||||||
bool restoreStateSlot(QupZilla* window);
|
bool restoreStateSlot(QupZilla* window);
|
||||||
|
@ -91,11 +91,6 @@ void QupZilla::loadSettings()
|
|||||||
|
|
||||||
QWebSettings* websettings=mApp->webSettings();
|
QWebSettings* websettings=mApp->webSettings();
|
||||||
websettings->setAttribute(QWebSettings::JavascriptCanAccessClipboard, true);
|
websettings->setAttribute(QWebSettings::JavascriptCanAccessClipboard, true);
|
||||||
//Web browsing settings
|
|
||||||
settings.beginGroup("Web-Browser-Settings");
|
|
||||||
bool allowFlash = settings.value("allowFlash",true).toBool();
|
|
||||||
settings.endGroup();
|
|
||||||
m_adblockIcon->setVisible(allowFlash);
|
|
||||||
|
|
||||||
//Browser Window settings
|
//Browser Window settings
|
||||||
settings.beginGroup("Browser-View-Settings");
|
settings.beginGroup("Browser-View-Settings");
|
||||||
@ -111,6 +106,9 @@ void QupZilla::loadSettings()
|
|||||||
bool showMenuBar = settings.value("showMenubar",true).toBool();
|
bool showMenuBar = settings.value("showMenubar",true).toBool();
|
||||||
bool makeTransparent = settings.value("useTransparentBackground",false).toBool();
|
bool makeTransparent = settings.value("useTransparentBackground",false).toBool();
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
bool adBlockEnabled = settings.value("AdBlock/enabled", true).toBool();
|
||||||
|
|
||||||
|
m_adblockIcon->setEnabled(adBlockEnabled);
|
||||||
|
|
||||||
statusBar()->setVisible(showStatusBar);
|
statusBar()->setVisible(showStatusBar);
|
||||||
m_actionShowStatusbar->setChecked(showStatusBar);
|
m_actionShowStatusbar->setChecked(showStatusBar);
|
||||||
@ -157,8 +155,8 @@ void QupZilla::loadSettings()
|
|||||||
void QupZilla::receiveMessage(MainApplication::MessageType mes, bool state)
|
void QupZilla::receiveMessage(MainApplication::MessageType mes, bool state)
|
||||||
{
|
{
|
||||||
switch (mes) {
|
switch (mes) {
|
||||||
case MainApplication::ShowFlashIcon:
|
case MainApplication::SetAdBlockIconEnabled:
|
||||||
m_adblockIcon->setVisible(state);
|
m_adblockIcon->setEnabled(state);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MainApplication::CheckPrivateBrowsing:
|
case MainApplication::CheckPrivateBrowsing:
|
||||||
@ -526,12 +524,8 @@ void QupZilla::showDownloadManager()
|
|||||||
|
|
||||||
void QupZilla::showPreferences()
|
void QupZilla::showPreferences()
|
||||||
{
|
{
|
||||||
bool flashIconVisibility = m_adblockIcon->isVisible();
|
|
||||||
Preferences prefs(this, this);
|
Preferences prefs(this, this);
|
||||||
prefs.exec();
|
prefs.exec();
|
||||||
|
|
||||||
if (flashIconVisibility != m_adblockIcon->isVisible())
|
|
||||||
emit message(MainApplication::ShowFlashIcon, m_adblockIcon->isVisible());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QupZilla::showSource()
|
void QupZilla::showSource()
|
||||||
|
@ -186,17 +186,14 @@ QNetworkReply* NetworkManager::createRequest(QNetworkAccessManager::Operation op
|
|||||||
QNetworkRequest req = request;
|
QNetworkRequest req = request;
|
||||||
req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
|
req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
|
||||||
|
|
||||||
|
|
||||||
// if (QNetworkReply* repl = mApp->plugins()->createNetworkRequest(op, request, outgoingData))
|
|
||||||
// return repl;
|
|
||||||
// Adblock
|
// Adblock
|
||||||
if (op == QNetworkAccessManager::GetOperation) {
|
if (op == QNetworkAccessManager::GetOperation) {
|
||||||
if (!m_adblockNetwork)
|
if (!m_adblockNetwork)
|
||||||
m_adblockNetwork = AdBlockManager::instance()->network();
|
m_adblockNetwork = AdBlockManager::instance()->network();
|
||||||
QNetworkReply* reply = m_adblockNetwork->block(req);
|
QNetworkReply* reply = m_adblockNetwork->block(req);
|
||||||
if (reply)
|
if (reply)
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
QNetworkReply* reply = QNetworkAccessManager::createRequest(op, req, outgoingData);
|
QNetworkReply* reply = QNetworkAccessManager::createRequest(op, req, outgoingData);
|
||||||
return reply;
|
return reply;
|
||||||
|
@ -123,6 +123,15 @@ QWebPage* WebPage::createWindow(QWebPage::WebWindowType type)
|
|||||||
return p_QupZilla->weView(index)->page();
|
return p_QupZilla->weView(index)->page();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebPage::addAdBlockRule(const QString &filter, const QUrl &url)
|
||||||
|
{
|
||||||
|
AdBlockedEntry entry;
|
||||||
|
entry.rule = filter;
|
||||||
|
entry.url = url;
|
||||||
|
|
||||||
|
m_adBlockedEntries.append(entry);
|
||||||
|
}
|
||||||
|
|
||||||
bool WebPage::extension(Extension extension, const ExtensionOption* option, ExtensionReturn* output)
|
bool WebPage::extension(Extension extension, const ExtensionOption* option, ExtensionReturn* output)
|
||||||
{
|
{
|
||||||
if (extension == ChooseMultipleFilesExtension)
|
if (extension == ChooseMultipleFilesExtension)
|
||||||
|
@ -36,6 +36,11 @@ class WebPage : public QWebPage
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
struct AdBlockedEntry {
|
||||||
|
QString rule;
|
||||||
|
QUrl url;
|
||||||
|
};
|
||||||
|
|
||||||
WebPage(WebView* parent, QupZilla* mainClass);
|
WebPage(WebView* parent, QupZilla* mainClass);
|
||||||
void populateNetworkRequest(QNetworkRequest &request);
|
void populateNetworkRequest(QNetworkRequest &request);
|
||||||
~WebPage();
|
~WebPage();
|
||||||
@ -46,10 +51,13 @@ public:
|
|||||||
bool supportsExtension(Extension extension) const { return (extension == ErrorPageExtension); }
|
bool supportsExtension(Extension extension) const { return (extension == ErrorPageExtension); }
|
||||||
bool extension(Extension extension, const ExtensionOption* option, ExtensionReturn* output);
|
bool extension(Extension extension, const ExtensionOption* option, ExtensionReturn* output);
|
||||||
|
|
||||||
|
void addAdBlockRule(const QString &filter, const QUrl &url);
|
||||||
|
QList<AdBlockedEntry> adBlockedEntries() { return m_adBlockedEntries; }
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
QWebPage* createWindow(QWebPage::WebWindowType type);
|
QWebPage* createWindow(QWebPage::WebWindowType type);
|
||||||
void handleUnsupportedContent(QNetworkReply* url);
|
void handleUnsupportedContent(QNetworkReply* url);
|
||||||
void clearSSLCert() { m_SslCert = 0; }
|
void clearSSLCert() { m_SslCert = 0; m_adBlockedEntries.clear(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest &request, NavigationType type);
|
bool acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest &request, NavigationType type);
|
||||||
@ -59,6 +67,7 @@ protected:
|
|||||||
QWebPage::NavigationType m_lastRequestType;
|
QWebPage::NavigationType m_lastRequestType;
|
||||||
WebView* m_view;
|
WebView* m_view;
|
||||||
QSslCertificate m_SslCert;
|
QSslCertificate m_SslCert;
|
||||||
|
QList<AdBlockedEntry> m_adBlockedEntries;
|
||||||
// bool m_isOpeningNextWindowAsNewTab;
|
// bool m_isOpeningNextWindowAsNewTab;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -95,7 +95,8 @@ void WebView::urlChanged(const QUrl &url)
|
|||||||
emit showUrl(url);
|
emit showUrl(url);
|
||||||
p_QupZilla->refreshHistory();
|
p_QupZilla->refreshHistory();
|
||||||
}
|
}
|
||||||
emit changed();
|
if (m_lastUrl != url)
|
||||||
|
emit changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebView::linkClicked(const QUrl &url)
|
void WebView::linkClicked(const QUrl &url)
|
||||||
|
Loading…
Reference in New Issue
Block a user