Extensive work on Adblock.
This commit is contained in:
parent
a4a637b789
commit
cc9c3680c1
18 changed files with 237 additions and 226 deletions
|
@ -431,8 +431,6 @@ set(APP_SOURCES
|
||||||
src/network-web/adblock/adblocktreewidget.cpp
|
src/network-web/adblock/adblocktreewidget.cpp
|
||||||
src/network-web/adblock/followredirectreply.cpp
|
src/network-web/adblock/followredirectreply.cpp
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# MAIN sources.
|
# MAIN sources.
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
)
|
)
|
||||||
|
@ -526,8 +524,6 @@ set(APP_HEADERS
|
||||||
src/network-web/adblock/adblockicon.h
|
src/network-web/adblock/adblockicon.h
|
||||||
src/network-web/adblock/adblockmanager.h
|
src/network-web/adblock/adblockmanager.h
|
||||||
src/network-web/adblock/adblockmatcher.h
|
src/network-web/adblock/adblockmatcher.h
|
||||||
src/network-web/adblock/adblockrule.h
|
|
||||||
src/network-web/adblock/adblocksearchtree.h
|
|
||||||
src/network-web/adblock/adblocksubscription.h
|
src/network-web/adblock/adblocksubscription.h
|
||||||
src/network-web/adblock/adblocktreewidget.h
|
src/network-web/adblock/adblocktreewidget.h
|
||||||
src/network-web/adblock/followredirectreply.h
|
src/network-web/adblock/followredirectreply.h
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.3 KiB |
BIN
resources/graphics/icons/mini-kfaenza/web-adblock-disabled.png
Normal file
BIN
resources/graphics/icons/mini-kfaenza/web-adblock-disabled.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.2 KiB |
Binary file not shown.
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 6.3 KiB |
|
@ -35,6 +35,7 @@
|
||||||
#include "gui/statusbar.h"
|
#include "gui/statusbar.h"
|
||||||
#include "gui/feedmessageviewer.h"
|
#include "gui/feedmessageviewer.h"
|
||||||
#include "gui/formupdate.h"
|
#include "gui/formupdate.h"
|
||||||
|
#include "gui/plaintoolbutton.h"
|
||||||
#include "gui/formimportexport.h"
|
#include "gui/formimportexport.h"
|
||||||
#include "gui/formbackupdatabasesettings.h"
|
#include "gui/formbackupdatabasesettings.h"
|
||||||
#include "gui/formrestoredatabasesettings.h"
|
#include "gui/formrestoredatabasesettings.h"
|
||||||
|
|
|
@ -39,8 +39,9 @@ void PlainToolButton::paintEvent(QPaintEvent *e) {
|
||||||
// Set padding.
|
// Set padding.
|
||||||
rect.adjust(m_padding, m_padding, -m_padding, -m_padding);
|
rect.adjust(m_padding, m_padding, -m_padding, -m_padding);
|
||||||
|
|
||||||
|
|
||||||
// Paint the icon.
|
// Paint the icon.
|
||||||
if (underMouse()) {
|
if (underMouse() || isChecked()) {
|
||||||
p.setOpacity(0.7);
|
p.setOpacity(0.7);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +54,11 @@ int PlainToolButton::padding() const {
|
||||||
|
|
||||||
void PlainToolButton::setPadding(int padding) {
|
void PlainToolButton::setPadding(int padding) {
|
||||||
m_padding = padding;
|
m_padding = padding;
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlainToolButton::setChecked(bool checked) {
|
||||||
|
QToolButton::setChecked(checked);
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,9 @@ class PlainToolButton : public QToolButton {
|
||||||
int padding() const;
|
int padding() const;
|
||||||
void setPadding(int padding);
|
void setPadding(int padding);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void setChecked(bool checked);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Custom look.
|
// Custom look.
|
||||||
void paintEvent(QPaintEvent *e);
|
void paintEvent(QPaintEvent *e);
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
#include "gui/formmain.h"
|
#include "gui/formmain.h"
|
||||||
#include "gui/tabwidget.h"
|
#include "gui/tabwidget.h"
|
||||||
|
#include "gui/plaintoolbutton.h"
|
||||||
|
#include "network-web/adblock/adblockicon.h"
|
||||||
#include "miscellaneous/iconfactory.h"
|
#include "miscellaneous/iconfactory.h"
|
||||||
|
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
|
@ -31,11 +33,10 @@ StatusBar::StatusBar(QWidget *parent) : QStatusBar(parent) {
|
||||||
setSizeGripEnabled(false);
|
setSizeGripEnabled(false);
|
||||||
setContentsMargins(0, 0, 0, 0);
|
setContentsMargins(0, 0, 0, 0);
|
||||||
|
|
||||||
adblockIcon_ = new AdBlockIcon(this);
|
m_adblockIcon = new AdBlockIcon(this);
|
||||||
|
|
||||||
// Initializations of widgets for status bar.
|
// Initializations of widgets for status bar.
|
||||||
m_fullscreenSwitcher = new QToolButton(this);
|
m_fullscreenSwitcher = new PlainToolButton(this);
|
||||||
m_fullscreenSwitcher->setAutoRaise(true);
|
|
||||||
m_fullscreenSwitcher->setCheckable(true);
|
m_fullscreenSwitcher->setCheckable(true);
|
||||||
m_fullscreenSwitcher->setIcon(qApp->icons()->fromTheme("view-fullscreen"));
|
m_fullscreenSwitcher->setIcon(qApp->icons()->fromTheme("view-fullscreen"));
|
||||||
m_fullscreenSwitcher->setText(tr("Fullscreen mode"));
|
m_fullscreenSwitcher->setText(tr("Fullscreen mode"));
|
||||||
|
@ -68,22 +69,18 @@ StatusBar::StatusBar(QWidget *parent) : QStatusBar(parent) {
|
||||||
addPermanentWidget(m_barProgressFeeds);
|
addPermanentWidget(m_barProgressFeeds);
|
||||||
addPermanentWidget(m_lblProgressDownload);
|
addPermanentWidget(m_lblProgressDownload);
|
||||||
addPermanentWidget(m_barProgressDownload);
|
addPermanentWidget(m_barProgressDownload);
|
||||||
|
addPermanentWidget(m_adblockIcon);
|
||||||
addPermanentWidget(m_fullscreenSwitcher);
|
addPermanentWidget(m_fullscreenSwitcher);
|
||||||
addPermanentWidget(adblockIcon_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
StatusBar::~StatusBar() {
|
StatusBar::~StatusBar() {
|
||||||
qDebug("Destroying StatusBar instance.");
|
qDebug("Destroying StatusBar instance.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void StatusBar::displayDownloadManager() {
|
|
||||||
qApp->mainForm()->tabWidget()->showDownloadManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool StatusBar::eventFilter(QObject *watched, QEvent *event) {
|
bool StatusBar::eventFilter(QObject *watched, QEvent *event) {
|
||||||
if (watched == m_lblProgressDownload || watched == m_barProgressDownload) {
|
if (watched == m_lblProgressDownload || watched == m_barProgressDownload) {
|
||||||
if (event->type() == QEvent::MouseButtonPress) {
|
if (event->type() == QEvent::MouseButtonPress) {
|
||||||
displayDownloadManager();
|
qApp->mainForm()->tabWidget()->showDownloadManager();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,12 +20,11 @@
|
||||||
|
|
||||||
#include <QStatusBar>
|
#include <QStatusBar>
|
||||||
|
|
||||||
#include <adblock/adblockicon.h>
|
|
||||||
|
|
||||||
|
|
||||||
class QProgressBar;
|
class QProgressBar;
|
||||||
class QToolButton;
|
class PlainToolButton;
|
||||||
class QLabel;
|
class QLabel;
|
||||||
|
class AdBlockIcon;
|
||||||
|
|
||||||
class StatusBar : public QStatusBar {
|
class StatusBar : public QStatusBar {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -35,11 +34,13 @@ class StatusBar : public QStatusBar {
|
||||||
explicit StatusBar(QWidget *parent = 0);
|
explicit StatusBar(QWidget *parent = 0);
|
||||||
virtual ~StatusBar();
|
virtual ~StatusBar();
|
||||||
|
|
||||||
inline QToolButton *fullscreenSwitcher() const {
|
inline PlainToolButton *fullscreenSwitcher() const {
|
||||||
return m_fullscreenSwitcher;
|
return m_fullscreenSwitcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
AdBlockIcon *adBlockIcon() { return adblockIcon_; }
|
inline AdBlockIcon *adBlockIcon() {
|
||||||
|
return m_adblockIcon;
|
||||||
|
}
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
// Progress bar operations
|
// Progress bar operations
|
||||||
|
@ -49,8 +50,6 @@ class StatusBar : public QStatusBar {
|
||||||
void showProgressDownload(int progress, const QString &tooltip);
|
void showProgressDownload(int progress, const QString &tooltip);
|
||||||
void clearProgressDownload();
|
void clearProgressDownload();
|
||||||
|
|
||||||
void displayDownloadManager();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool eventFilter(QObject *watched, QEvent *event);
|
bool eventFilter(QObject *watched, QEvent *event);
|
||||||
|
|
||||||
|
@ -59,8 +58,8 @@ class StatusBar : public QStatusBar {
|
||||||
QLabel *m_lblProgressFeeds;
|
QLabel *m_lblProgressFeeds;
|
||||||
QProgressBar *m_barProgressDownload;
|
QProgressBar *m_barProgressDownload;
|
||||||
QLabel *m_lblProgressDownload;
|
QLabel *m_lblProgressDownload;
|
||||||
QToolButton *m_fullscreenSwitcher;
|
PlainToolButton *m_fullscreenSwitcher;
|
||||||
AdBlockIcon* adblockIcon_;
|
AdBlockIcon* m_adblockIcon;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // STATUSBAR_H
|
#endif // STATUSBAR_H
|
||||||
|
|
|
@ -89,6 +89,10 @@ AdBlockDialog::AdBlockDialog(QWidget* parent)
|
||||||
buttonBox->setFocus();
|
buttonBox->setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AdBlockDialog::~AdBlockDialog() {
|
||||||
|
qDebug("Destroying AdBlockDialog instance.");
|
||||||
|
}
|
||||||
|
|
||||||
void AdBlockDialog::showRule(const AdBlockRule* rule) const
|
void AdBlockDialog::showRule(const AdBlockRule* rule) const
|
||||||
{
|
{
|
||||||
AdBlockSubscription* subscription = rule->subscription();
|
AdBlockSubscription* subscription = rule->subscription();
|
||||||
|
@ -210,7 +214,7 @@ void AdBlockDialog::load()
|
||||||
|
|
||||||
m_loaded = true;
|
m_loaded = true;
|
||||||
|
|
||||||
QTimer::singleShot(50, this, SLOT(loadSubscriptions()));
|
QTimer::singleShot(100, this, SLOT(loadSubscriptions()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockDialog::closeEvent(QCloseEvent* ev)
|
void AdBlockDialog::closeEvent(QCloseEvent* ev)
|
||||||
|
|
|
@ -46,44 +46,45 @@ class AdBlockRule;
|
||||||
|
|
||||||
class AdBlockDialog : public QWidget, public Ui_AdBlockDialog
|
class AdBlockDialog : public QWidget, public Ui_AdBlockDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AdBlockDialog(QWidget* parent = 0);
|
explicit AdBlockDialog(QWidget* parent = 0);
|
||||||
|
virtual ~AdBlockDialog();
|
||||||
|
|
||||||
void showRule(const AdBlockRule* rule) const;
|
void showRule(const AdBlockRule* rule) const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void addRule();
|
void addRule();
|
||||||
void removeRule();
|
void removeRule();
|
||||||
|
|
||||||
void addSubscription();
|
void addSubscription();
|
||||||
void removeSubscription();
|
void removeSubscription();
|
||||||
|
|
||||||
void currentChanged(int index);
|
void currentChanged(int index);
|
||||||
void filterString(const QString &string);
|
void filterString(const QString &string);
|
||||||
void enableAdBlock(bool state);
|
void enableAdBlock(bool state);
|
||||||
|
|
||||||
void aboutToShowMenu();
|
void aboutToShowMenu();
|
||||||
void learnAboutRules();
|
void learnAboutRules();
|
||||||
|
|
||||||
void loadSubscriptions();
|
void loadSubscriptions();
|
||||||
void load();
|
void load();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void closeEvent(QCloseEvent* ev);
|
void closeEvent(QCloseEvent* ev);
|
||||||
|
|
||||||
AdBlockManager* m_manager;
|
AdBlockManager* m_manager;
|
||||||
AdBlockTreeWidget* m_currentTreeWidget;
|
AdBlockTreeWidget* m_currentTreeWidget;
|
||||||
AdBlockSubscription* m_currentSubscription;
|
AdBlockSubscription* m_currentSubscription;
|
||||||
|
|
||||||
QAction* m_actionAddRule;
|
QAction* m_actionAddRule;
|
||||||
QAction* m_actionRemoveRule;
|
QAction* m_actionRemoveRule;
|
||||||
QAction* m_actionAddSubscription;
|
QAction* m_actionAddSubscription;
|
||||||
QAction* m_actionRemoveSubscription;
|
QAction* m_actionRemoveSubscription;
|
||||||
|
|
||||||
bool m_loaded;
|
bool m_loaded;
|
||||||
bool m_useLimitedEasyList;
|
bool m_useLimitedEasyList;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ADBLOCKDIALOG_H
|
#endif // ADBLOCKDIALOG_H
|
||||||
|
|
|
@ -57,7 +57,16 @@
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<property name="margin">
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item row="4" column="0" colspan="2">
|
<item row="4" column="0" colspan="2">
|
||||||
|
@ -67,10 +76,6 @@
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Options</string>
|
<string>Options</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
|
||||||
<iconset resource="../../QuiteRSS.qrc">
|
|
||||||
<normaloff>:/images/images/adblock.png</normaloff>:/images/images/adblock.png</iconset>
|
|
||||||
</property>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
@ -129,7 +134,7 @@
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="standardButtons">
|
<property name="standardButtons">
|
||||||
<set>QDialogButtonBox::Ok</set>
|
<set>QDialogButtonBox::Close</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -137,9 +142,7 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources>
|
<resources/>
|
||||||
<include location="../../QuiteRSS.qrc"/>
|
|
||||||
</resources>
|
|
||||||
<connections>
|
<connections>
|
||||||
<connection>
|
<connection>
|
||||||
<sender>adblockCheckBox</sender>
|
<sender>adblockCheckBox</sender>
|
||||||
|
@ -157,5 +160,21 @@
|
||||||
</hint>
|
</hint>
|
||||||
</hints>
|
</hints>
|
||||||
</connection>
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>clicked(QAbstractButton*)</signal>
|
||||||
|
<receiver>AdBlockDialog</receiver>
|
||||||
|
<slot>close()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>434</x>
|
||||||
|
<y>440</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>272</x>
|
||||||
|
<y>230</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
</connections>
|
</connections>
|
||||||
</ui>
|
</ui>
|
||||||
|
|
|
@ -32,16 +32,18 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* ============================================================ */
|
* ============================================================ */
|
||||||
#include "adblockicon.h"
|
#include "network-web/adblock/adblockicon.h"
|
||||||
#include "adblockrule.h"
|
|
||||||
#include "adblockmanager.h"
|
#include "network-web/adblock/adblockrule.h"
|
||||||
#include "adblocksubscription.h"
|
#include "network-web/adblock/adblockmanager.h"
|
||||||
#include "webpage.h"
|
#include "network-web/adblock/adblocksubscription.h"
|
||||||
|
#include "network-web/webpage.h"
|
||||||
|
#include "network-web/webbrowser.h"
|
||||||
|
|
||||||
#include "miscellaneous/application.h"
|
#include "miscellaneous/application.h"
|
||||||
|
#include "gui/plaintoolbutton.h"
|
||||||
#include "gui/formmain.h"
|
#include "gui/formmain.h"
|
||||||
#include "gui/tabwidget.h"
|
#include "gui/tabwidget.h"
|
||||||
#include "network-web/webbrowser.h"
|
|
||||||
|
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
@ -50,27 +52,13 @@
|
||||||
|
|
||||||
|
|
||||||
AdBlockIcon::AdBlockIcon(QWidget *window, QWidget *parent)
|
AdBlockIcon::AdBlockIcon(QWidget *window, QWidget *parent)
|
||||||
: QToolButton(parent)
|
: PlainToolButton(parent), m_window(window), m_menuAction(0), m_flashTimer(0), m_timerTicks(0), m_enabled(false) {
|
||||||
, m_window(window)
|
setToolTip(tr("Adblock lets you block unwanted content on web pages."));
|
||||||
, m_menuAction(0)
|
|
||||||
, m_flashTimer(0)
|
|
||||||
, m_timerTicks(0)
|
|
||||||
, m_enabled(false)
|
|
||||||
{
|
|
||||||
setFocusPolicy(Qt::NoFocus);
|
|
||||||
setStyleSheet("QToolButton { border: none; padding: 0px; }");
|
|
||||||
|
|
||||||
connect(this, SIGNAL(clicked(QPoint)), this, SLOT(showMenu(QPoint)));
|
connect(this, SIGNAL(clicked(QPoint)), this, SLOT(showMenu(QPoint)));
|
||||||
connect(AdBlockManager::instance(), SIGNAL(enabledChanged(bool)), this, SLOT(setEnabled(bool)));
|
connect(AdBlockManager::instance(), SIGNAL(enabledChanged(bool)), this, SLOT(setEnabled(bool)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockIcon::retranslateStrings()
|
|
||||||
{
|
|
||||||
setToolTip(tr("AdBlock lets you block unwanted content on web pages"));
|
|
||||||
|
|
||||||
AdBlockManager::instance()->customList()->retranslateStrings();
|
|
||||||
}
|
|
||||||
|
|
||||||
void AdBlockIcon::popupBlocked(const QString &ruleString, const QUrl &url)
|
void AdBlockIcon::popupBlocked(const QString &ruleString, const QUrl &url)
|
||||||
{
|
{
|
||||||
int index = ruleString.lastIndexOf(QLatin1String(" ("));
|
int index = ruleString.lastIndexOf(QLatin1String(" ("));
|
||||||
|
@ -117,24 +105,25 @@ QAction* AdBlockIcon::menuAction()
|
||||||
return m_menuAction;
|
return m_menuAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockIcon::createMenu(QMenu* menu)
|
void AdBlockIcon::createMenu(QMenu *menu)
|
||||||
{
|
{
|
||||||
if (!menu) {
|
if (menu == NULL) {
|
||||||
menu = qobject_cast<QMenu*>(sender());
|
menu = qobject_cast<QMenu*>(sender());
|
||||||
if (!menu) {
|
|
||||||
|
if (menu == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
menu->clear();
|
menu->clear();
|
||||||
|
|
||||||
AdBlockManager* manager = AdBlockManager::instance();
|
AdBlockManager *manager = AdBlockManager::instance();
|
||||||
AdBlockCustomList* customList = manager->customList();
|
AdBlockCustomList *customList = manager->customList();
|
||||||
|
|
||||||
WebPage* page = qApp->mainForm()->tabWidget()->widget(qApp->mainForm()->tabWidget()->currentIndex())->webBrowser()->view()->page();
|
WebPage* page = qApp->mainForm()->tabWidget()->widget(qApp->mainForm()->tabWidget()->currentIndex())->webBrowser()->view()->page();
|
||||||
const QUrl pageUrl = page->mainFrame()->url();
|
const QUrl pageUrl = page->mainFrame()->url();
|
||||||
|
|
||||||
menu->addAction(tr("Show AdBlock &Settings"), manager, SLOT(showDialog()));
|
menu->addAction(tr("Show Adblock &settings"), manager, SLOT(showDialog()));
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
|
|
||||||
if (!pageUrl.host().isEmpty() && m_enabled && manager->canRunOnScheme(pageUrl.scheme())) {
|
if (!pageUrl.host().isEmpty() && m_enabled && manager->canRunOnScheme(pageUrl.scheme())) {
|
||||||
|
@ -244,10 +233,10 @@ void AdBlockIcon::stopAnimation()
|
||||||
void AdBlockIcon::setEnabled(bool enabled)
|
void AdBlockIcon::setEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
setIcon(QIcon(":images/images/adblock.png"));
|
setIcon(qApp->icons()->fromTheme("web-adblock"));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
setIcon(QIcon(":images/images/adblock-disabled.png"));
|
setIcon(qApp->icons()->fromTheme("web-adblock-disabled"));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_enabled = enabled;
|
m_enabled = enabled;
|
||||||
|
|
|
@ -35,50 +35,49 @@
|
||||||
#ifndef ADBLOCKICON_H
|
#ifndef ADBLOCKICON_H
|
||||||
#define ADBLOCKICON_H
|
#define ADBLOCKICON_H
|
||||||
|
|
||||||
#include <QToolButton>
|
#include "gui/plaintoolbutton.h"
|
||||||
|
|
||||||
#include "adblockrule.h"
|
|
||||||
|
|
||||||
class QMenu;
|
class QMenu;
|
||||||
class QUrl;
|
class QUrl;
|
||||||
class MainWindow;
|
class AdBlockRule;
|
||||||
|
|
||||||
class AdBlockIcon : public QToolButton
|
class AdBlockIcon : public PlainToolButton {
|
||||||
{
|
Q_OBJECT
|
||||||
Q_OBJECT
|
public:
|
||||||
public:
|
// Constructors.
|
||||||
explicit AdBlockIcon(QWidget *window, QWidget *parent = 0);
|
explicit AdBlockIcon(QWidget *window, QWidget *parent = 0);
|
||||||
~AdBlockIcon();
|
virtual ~AdBlockIcon();
|
||||||
|
|
||||||
void retranslateStrings();
|
void popupBlocked(const QString &ruleString, const QUrl &url);
|
||||||
void popupBlocked(const QString &ruleString, const QUrl &url);
|
QAction *menuAction();
|
||||||
QAction* menuAction();
|
|
||||||
|
|
||||||
signals:
|
public slots:
|
||||||
void clicked(QPoint);
|
void setEnabled(bool enabled);
|
||||||
|
void createMenu(QMenu *menu = NULL);
|
||||||
|
|
||||||
public slots:
|
private slots:
|
||||||
void setEnabled(bool enabled);
|
void showMenu(const QPoint &pos);
|
||||||
void createMenu(QMenu* menu = 0);
|
void toggleCustomFilter();
|
||||||
|
|
||||||
private slots:
|
void animateIcon();
|
||||||
void showMenu(const QPoint &pos);
|
void stopAnimation();
|
||||||
void toggleCustomFilter();
|
|
||||||
|
|
||||||
void animateIcon();
|
protected:
|
||||||
void stopAnimation();
|
void mouseReleaseEvent(QMouseEvent *event);
|
||||||
|
|
||||||
private:
|
signals:
|
||||||
void mouseReleaseEvent(QMouseEvent* event);
|
void clicked(QPoint);
|
||||||
|
|
||||||
QWidget *m_window;
|
private:
|
||||||
QAction* m_menuAction;
|
QWidget *m_window;
|
||||||
|
QAction* m_menuAction;
|
||||||
|
|
||||||
QVector<QPair<AdBlockRule*, QUrl> > m_blockedPopups;
|
QVector<QPair<AdBlockRule*, QUrl> > m_blockedPopups;
|
||||||
QTimer* m_flashTimer;
|
QTimer* m_flashTimer;
|
||||||
|
|
||||||
int m_timerTicks;
|
int m_timerTicks;
|
||||||
bool m_enabled;
|
bool m_enabled;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ADBLOCKICON_H
|
#endif // ADBLOCKICON_H
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
#include "miscellaneous/application.h"
|
#include "miscellaneous/application.h"
|
||||||
#include "miscellaneous/settings.h"
|
#include "miscellaneous/settings.h"
|
||||||
#include "network-web/silentnetworkaccessmanager.h"
|
#include "network-web/silentnetworkaccessmanager.h"
|
||||||
|
#include "gui/formmain.h"
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
@ -445,8 +446,14 @@ AdBlockSubscription* AdBlockManager::subscriptionByName(const QString &name) con
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
AdBlockDialog* AdBlockManager::showDialog()
|
AdBlockDialog *AdBlockManager::showDialog() {
|
||||||
{
|
QPointer<AdBlockDialog> form_pointer = new AdBlockDialog();
|
||||||
|
form_pointer.data()->show();
|
||||||
|
form_pointer.data()->raise();
|
||||||
|
form_pointer.data()->activateWindow();
|
||||||
|
form_pointer.data()->setAttribute(Qt::WA_DeleteOnClose, true);
|
||||||
|
return form_pointer.data();
|
||||||
|
/*
|
||||||
if (!m_adBlockDialog) {
|
if (!m_adBlockDialog) {
|
||||||
m_adBlockDialog = new AdBlockDialog;
|
m_adBlockDialog = new AdBlockDialog;
|
||||||
}
|
}
|
||||||
|
@ -455,7 +462,7 @@ AdBlockDialog* AdBlockManager::showDialog()
|
||||||
m_adBlockDialog.data()->raise();
|
m_adBlockDialog.data()->raise();
|
||||||
m_adBlockDialog.data()->activateWindow();
|
m_adBlockDialog.data()->activateWindow();
|
||||||
|
|
||||||
return m_adBlockDialog.data();
|
return m_adBlockDialog.data();*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockManager::showRule()
|
void AdBlockManager::showRule()
|
||||||
|
|
|
@ -70,68 +70,67 @@ class AdBlockSubscription;
|
||||||
|
|
||||||
class AdBlockManager : public QObject
|
class AdBlockManager : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AdBlockManager(QObject* parent = 0);
|
AdBlockManager(QObject* parent = 0);
|
||||||
~AdBlockManager();
|
~AdBlockManager();
|
||||||
|
|
||||||
static AdBlockManager* instance();
|
static AdBlockManager* instance();
|
||||||
|
|
||||||
static QString filterCharsFromFilename(const QString &name);
|
static QString filterCharsFromFilename(const QString &name);
|
||||||
|
|
||||||
static QString ensureUniqueFilename(const QString &name, const QString &appendFormat = QString("(%1)"));
|
static QString ensureUniqueFilename(const QString &name, const QString &appendFormat = QString("(%1)"));
|
||||||
|
|
||||||
void load();
|
void load();
|
||||||
void save();
|
void save();
|
||||||
|
|
||||||
bool isEnabled() const;
|
bool isEnabled() const;
|
||||||
bool canRunOnScheme(const QString &scheme) const;
|
bool canRunOnScheme(const QString &scheme) const;
|
||||||
|
|
||||||
bool useLimitedEasyList() const;
|
bool useLimitedEasyList() const;
|
||||||
void setUseLimitedEasyList(bool useLimited);
|
void setUseLimitedEasyList(bool useLimited);
|
||||||
|
|
||||||
QString elementHidingRules() const;
|
QString elementHidingRules() const;
|
||||||
QString elementHidingRulesForDomain(const QUrl &url) const;
|
QString elementHidingRulesForDomain(const QUrl &url) const;
|
||||||
|
|
||||||
AdBlockSubscription* subscriptionByName(const QString &name) const;
|
AdBlockSubscription* subscriptionByName(const QString &name) const;
|
||||||
QList<AdBlockSubscription*> subscriptions() const;
|
QList<AdBlockSubscription*> subscriptions() const;
|
||||||
|
|
||||||
QNetworkReply* block(const QNetworkRequest &request);
|
QNetworkReply* block(const QNetworkRequest &request);
|
||||||
|
|
||||||
QStringList disabledRules() const;
|
QStringList disabledRules() const;
|
||||||
void addDisabledRule(const QString &filter);
|
void addDisabledRule(const QString &filter);
|
||||||
void removeDisabledRule(const QString &filter);
|
void removeDisabledRule(const QString &filter);
|
||||||
|
|
||||||
AdBlockSubscription* addSubscription(const QString &title, const QString &url);
|
AdBlockSubscription* addSubscription(const QString &title, const QString &url);
|
||||||
bool removeSubscription(AdBlockSubscription* subscription);
|
bool removeSubscription(AdBlockSubscription* subscription);
|
||||||
|
|
||||||
AdBlockCustomList* customList() const;
|
AdBlockCustomList* customList() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void enabledChanged(bool enabled);
|
void enabledChanged(bool enabled);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setEnabled(bool enabled);
|
void setEnabled(bool enabled);
|
||||||
void showRule();
|
void showRule();
|
||||||
|
void updateAllSubscriptions();
|
||||||
|
|
||||||
void updateAllSubscriptions();
|
AdBlockDialog *showDialog();
|
||||||
|
|
||||||
AdBlockDialog* showDialog();
|
private:
|
||||||
|
inline bool canBeBlocked(const QUrl &url) const;
|
||||||
|
|
||||||
private:
|
bool m_loaded;
|
||||||
inline bool canBeBlocked(const QUrl &url) const;
|
bool m_enabled;
|
||||||
|
bool m_useLimitedEasyList;
|
||||||
|
|
||||||
bool m_loaded;
|
QList<AdBlockSubscription*> m_subscriptions;
|
||||||
bool m_enabled;
|
static AdBlockManager* s_adBlockManager;
|
||||||
bool m_useLimitedEasyList;
|
AdBlockMatcher* m_matcher;
|
||||||
|
QStringList m_disabledRules;
|
||||||
|
|
||||||
QList<AdBlockSubscription*> m_subscriptions;
|
QPointer<AdBlockDialog> m_adBlockDialog;
|
||||||
static AdBlockManager* s_adBlockManager;
|
|
||||||
AdBlockMatcher* m_matcher;
|
|
||||||
QStringList m_disabledRules;
|
|
||||||
|
|
||||||
QPointer<AdBlockDialog> m_adBlockDialog;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ADBLOCKMANAGER_H
|
#endif // ADBLOCKMANAGER_H
|
||||||
|
|
|
@ -327,18 +327,12 @@ AdBlockSubscription::~AdBlockSubscription()
|
||||||
|
|
||||||
// AdBlockCustomList
|
// AdBlockCustomList
|
||||||
|
|
||||||
AdBlockCustomList::AdBlockCustomList(QObject* parent)
|
AdBlockCustomList::AdBlockCustomList(QObject* parent) : AdBlockSubscription(tr("Custom rules"), parent) {
|
||||||
: AdBlockSubscription(tr("Custom Rules"), parent)
|
setTitle(tr("Custom rules"));
|
||||||
{
|
|
||||||
// TODO
|
// TODO
|
||||||
setFilePath(qApp->homeFolderPath() + "/adblock/customlist.txt");
|
setFilePath(qApp->homeFolderPath() + "/adblock/customlist.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockCustomList::retranslateStrings()
|
|
||||||
{
|
|
||||||
setTitle(tr("Custom Rules"));
|
|
||||||
}
|
|
||||||
|
|
||||||
void AdBlockCustomList::loadSubscription(const QStringList &disabledRules)
|
void AdBlockCustomList::loadSubscription(const QStringList &disabledRules)
|
||||||
{
|
{
|
||||||
// DuckDuckGo ad whitelist rules
|
// DuckDuckGo ad whitelist rules
|
||||||
|
|
|
@ -77,82 +77,80 @@ class FollowRedirectReply;
|
||||||
|
|
||||||
class AdBlockSubscription : public QObject
|
class AdBlockSubscription : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit AdBlockSubscription(const QString &title, QObject* parent = 0);
|
explicit AdBlockSubscription(const QString &title, QObject* parent = 0);
|
||||||
~AdBlockSubscription();
|
~AdBlockSubscription();
|
||||||
|
|
||||||
QString title() const;
|
QString title() const;
|
||||||
void setTitle(const QString &title);
|
void setTitle(const QString &title);
|
||||||
|
|
||||||
QString filePath() const;
|
QString filePath() const;
|
||||||
void setFilePath(const QString &path);
|
void setFilePath(const QString &path);
|
||||||
|
|
||||||
QUrl url() const;
|
QUrl url() const;
|
||||||
void setUrl(const QUrl &url);
|
void setUrl(const QUrl &url);
|
||||||
|
|
||||||
virtual void loadSubscription(const QStringList &disabledRules);
|
virtual void loadSubscription(const QStringList &disabledRules);
|
||||||
virtual void saveSubscription();
|
virtual void saveSubscription();
|
||||||
|
|
||||||
const AdBlockRule* rule(int offset) const;
|
const AdBlockRule* rule(int offset) const;
|
||||||
QVector<AdBlockRule*> allRules() const;
|
QVector<AdBlockRule*> allRules() const;
|
||||||
|
|
||||||
const AdBlockRule* enableRule(int offset);
|
const AdBlockRule* enableRule(int offset);
|
||||||
const AdBlockRule* disableRule(int offset);
|
const AdBlockRule* disableRule(int offset);
|
||||||
|
|
||||||
virtual bool canEditRules() const;
|
virtual bool canEditRules() const;
|
||||||
virtual bool canBeRemoved() const;
|
virtual bool canBeRemoved() const;
|
||||||
|
|
||||||
virtual int addRule(AdBlockRule* rule);
|
virtual int addRule(AdBlockRule* rule);
|
||||||
virtual bool removeRule(int offset);
|
virtual bool removeRule(int offset);
|
||||||
virtual const AdBlockRule* replaceRule(AdBlockRule* rule, int offset);
|
virtual const AdBlockRule* replaceRule(AdBlockRule* rule, int offset);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateSubscription();
|
void updateSubscription();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void subscriptionChanged();
|
void subscriptionChanged();
|
||||||
void subscriptionUpdated();
|
void subscriptionUpdated();
|
||||||
void subscriptionError(const QString &message);
|
void subscriptionError(const QString &message);
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void subscriptionDownloaded();
|
void subscriptionDownloaded();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool saveDownloadedData(const QByteArray &data);
|
virtual bool saveDownloadedData(const QByteArray &data);
|
||||||
|
|
||||||
FollowRedirectReply* m_reply;
|
FollowRedirectReply* m_reply;
|
||||||
|
|
||||||
QVector<AdBlockRule*> m_rules;
|
QVector<AdBlockRule*> m_rules;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_title;
|
QString m_title;
|
||||||
QString m_filePath;
|
QString m_filePath;
|
||||||
|
|
||||||
QUrl m_url;
|
QUrl m_url;
|
||||||
bool m_updated;
|
bool m_updated;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AdBlockCustomList : public AdBlockSubscription
|
class AdBlockCustomList : public AdBlockSubscription
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit AdBlockCustomList(QObject* parent = 0);
|
explicit AdBlockCustomList(QObject* parent = 0);
|
||||||
|
|
||||||
void retranslateStrings();
|
void loadSubscription(const QStringList &disabledRules);
|
||||||
|
void saveSubscription();
|
||||||
|
|
||||||
void loadSubscription(const QStringList &disabledRules);
|
bool canEditRules() const;
|
||||||
void saveSubscription();
|
bool canBeRemoved() const;
|
||||||
|
|
||||||
bool canEditRules() const;
|
bool containsFilter(const QString &filter) const;
|
||||||
bool canBeRemoved() const;
|
bool removeFilter(const QString &filter);
|
||||||
|
|
||||||
bool containsFilter(const QString &filter) const;
|
int addRule(AdBlockRule* rule);
|
||||||
bool removeFilter(const QString &filter);
|
bool removeRule(int offset);
|
||||||
|
const AdBlockRule* replaceRule(AdBlockRule* rule, int offset);
|
||||||
int addRule(AdBlockRule* rule);
|
|
||||||
bool removeRule(int offset);
|
|
||||||
const AdBlockRule* replaceRule(AdBlockRule* rule, int offset);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ADBLOCKSUBSCRIPTION_H
|
#endif // ADBLOCKSUBSCRIPTION_H
|
||||||
|
|
Loading…
Add table
Reference in a new issue