Refactored adblock icon separated from main form.
This commit is contained in:
parent
83e5ffa15e
commit
281e903752
8 changed files with 39 additions and 46 deletions
|
@ -55,43 +55,33 @@
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
|
|
||||||
#if defined(USE_WEBENGINE)
|
|
||||||
#include "network-web/adblock/adblockicon.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
FormMain::FormMain(QWidget* parent, Qt::WindowFlags f)
|
FormMain::FormMain(QWidget* parent, Qt::WindowFlags f)
|
||||||
: QMainWindow(parent, f), m_ui(new Ui::FormMain) {
|
: QMainWindow(parent, f), m_ui(new Ui::FormMain) {
|
||||||
m_ui->setupUi(this);
|
m_ui->setupUi(this);
|
||||||
|
|
||||||
#if defined(USE_WEBENGINE)
|
qApp->setMainForm(this);
|
||||||
m_adblockIcon = new AdBlockIcon(this);
|
|
||||||
m_adblockIcon->setObjectName(QSL("m_adblockIconAction"));
|
|
||||||
m_ui->m_menuTools->addAction(m_adblockIcon);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
qApp->setMainForm(this);
|
|
||||||
// Add these actions to the list of actions of the main window.
|
// Add these actions to the list of actions of the main window.
|
||||||
// This allows to use actions via shortcuts
|
// This allows to use actions via shortcuts
|
||||||
// even if main menu is not visible.
|
// even if main menu is not visible.
|
||||||
addActions(allActions());
|
addActions(qApp->userActions());
|
||||||
|
|
||||||
#if defined(USE_WEBENGINE)
|
setStatusBar(m_statusBar = new StatusBar(this));
|
||||||
addAction(m_adblockIcon);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
m_statusBar = new StatusBar(this);
|
|
||||||
setStatusBar(m_statusBar);
|
|
||||||
// Prepare main window and tabs.
|
// Prepare main window and tabs.
|
||||||
prepareMenus();
|
prepareMenus();
|
||||||
|
|
||||||
// Prepare tabs.
|
// Prepare tabs.
|
||||||
//m_ui->m_tabWidget->initializeTabs();
|
//m_ui->m_tabWidget->initializeTabs();
|
||||||
tabWidget()->feedMessageViewer()->feedsToolBar()->loadSavedActions();
|
tabWidget()->feedMessageViewer()->feedsToolBar()->loadSavedActions();
|
||||||
tabWidget()->feedMessageViewer()->messagesToolBar()->loadSavedActions();
|
tabWidget()->feedMessageViewer()->messagesToolBar()->loadSavedActions();
|
||||||
// Establish connections.
|
|
||||||
|
// Establish connections.
|
||||||
createConnections();
|
createConnections();
|
||||||
updateMessageButtonsAvailability();
|
updateMessageButtonsAvailability();
|
||||||
updateFeedButtonsAvailability();
|
updateFeedButtonsAvailability();
|
||||||
|
|
||||||
// Setup some appearance of the window.
|
// Setup some appearance of the window.
|
||||||
setupIcons();
|
setupIcons();
|
||||||
loadSize();
|
loadSize();
|
||||||
|
@ -186,7 +176,6 @@ QList<QAction*> FormMain::allActions() const {
|
||||||
actions << m_ui->m_actionExpandCollapseItem;
|
actions << m_ui->m_actionExpandCollapseItem;
|
||||||
#if defined(USE_WEBENGINE)
|
#if defined(USE_WEBENGINE)
|
||||||
actions << m_ui->m_actionTabNewWebBrowser;
|
actions << m_ui->m_actionTabNewWebBrowser;
|
||||||
actions << m_adblockIcon;
|
|
||||||
#endif
|
#endif
|
||||||
actions << m_ui->m_actionTabsCloseAll;
|
actions << m_ui->m_actionTabsCloseAll;
|
||||||
actions << m_ui->m_actionTabsCloseAllExceptCurrent;
|
actions << m_ui->m_actionTabsCloseAllExceptCurrent;
|
||||||
|
|
|
@ -23,10 +23,6 @@
|
||||||
#include "ui_formmain.h"
|
#include "ui_formmain.h"
|
||||||
|
|
||||||
|
|
||||||
#if defined(USE_WEBENGINE)
|
|
||||||
class AdBlockIcon;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class StatusBar;
|
class StatusBar;
|
||||||
|
|
||||||
class FormMain : public QMainWindow {
|
class FormMain : public QMainWindow {
|
||||||
|
@ -59,12 +55,6 @@ class FormMain : public QMainWindow {
|
||||||
void loadSize();
|
void loadSize();
|
||||||
void saveSize();
|
void saveSize();
|
||||||
|
|
||||||
#if defined(USE_WEBENGINE)
|
|
||||||
AdBlockIcon* adblockIcon() const {
|
|
||||||
return m_adblockIcon;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
// Displays window on top or switches its visibility.
|
// Displays window on top or switches its visibility.
|
||||||
void display();
|
void display();
|
||||||
|
@ -112,10 +102,6 @@ class FormMain : public QMainWindow {
|
||||||
// Sets up proper icons for this widget.
|
// Sets up proper icons for this widget.
|
||||||
void setupIcons();
|
void setupIcons();
|
||||||
|
|
||||||
#if defined(USE_WEBENGINE)
|
|
||||||
AdBlockIcon* m_adblockIcon;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
QScopedPointer<Ui::FormMain> m_ui;
|
QScopedPointer<Ui::FormMain> m_ui;
|
||||||
QMenu* m_trayMenu;
|
QMenu* m_trayMenu;
|
||||||
StatusBar* m_statusBar;
|
StatusBar* m_statusBar;
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "gui/tabwidget.h"
|
#include "gui/tabwidget.h"
|
||||||
#include "gui/webbrowser.h"
|
#include "gui/webbrowser.h"
|
||||||
#include "network-web/adblock/adblockicon.h"
|
#include "network-web/adblock/adblockicon.h"
|
||||||
|
#include "network-web/adblock/adblockmanager.h"
|
||||||
|
|
||||||
#include <QWheelEvent>
|
#include <QWheelEvent>
|
||||||
|
|
||||||
|
@ -143,8 +144,10 @@ void WebViewer::clear() {
|
||||||
|
|
||||||
void WebViewer::contextMenuEvent(QContextMenuEvent* event) {
|
void WebViewer::contextMenuEvent(QContextMenuEvent* event) {
|
||||||
event->accept();
|
event->accept();
|
||||||
|
|
||||||
QMenu* menu = page()->createStandardContextMenu();
|
QMenu* menu = page()->createStandardContextMenu();
|
||||||
menu->addAction(qApp->mainForm()->adblockIcon());
|
menu->addAction(AdBlockManager::instance()->adblockIcon());
|
||||||
|
|
||||||
const QPoint pos = event->globalPos();
|
const QPoint pos = event->globalPos();
|
||||||
QPoint p(pos.x(), pos.y() + 1);
|
QPoint p(pos.x(), pos.y() + 1);
|
||||||
menu->popup(p);
|
menu->popup(p);
|
||||||
|
|
|
@ -85,6 +85,10 @@ FeedReader* Application::feedReader() {
|
||||||
QList<QAction*> Application::userActions() {
|
QList<QAction*> Application::userActions() {
|
||||||
if (m_mainForm != nullptr && m_userActions.isEmpty()) {
|
if (m_mainForm != nullptr && m_userActions.isEmpty()) {
|
||||||
m_userActions = m_mainForm->allActions();
|
m_userActions = m_mainForm->allActions();
|
||||||
|
|
||||||
|
#if defined(USE_WEBENGINE)
|
||||||
|
m_userActions.append(AdBlockManager::instance()->adblockIcon());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_userActions;
|
return m_userActions;
|
||||||
|
|
|
@ -32,16 +32,16 @@
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
|
|
||||||
AdBlockIcon::AdBlockIcon(QObject* parent)
|
AdBlockIcon::AdBlockIcon(AdBlockManager* parent)
|
||||||
: QAction(parent), m_flashTimer(0), m_timerTicks(0), m_enabled(AdBlockManager::instance()->isEnabled()) {
|
: QAction(parent), m_manager(parent), m_flashTimer(0), m_timerTicks(0), m_enabled(m_manager->isEnabled()) {
|
||||||
setToolTip(tr("AdBlock lets you block unwanted content on web pages"));
|
setToolTip(tr("AdBlock lets you block unwanted content on web pages"));
|
||||||
setText(QSL("AdBlock"));
|
setText(QSL("AdBlock"));
|
||||||
setMenu(new QMenu());
|
setMenu(new QMenu());
|
||||||
setIcon(m_enabled ? qApp->icons()->miscIcon(ADBLOCK_ICON_ACTIVE) : qApp->icons()->miscIcon(ADBLOCK_ICON_DISABLED));
|
setIcon(m_enabled ? qApp->icons()->miscIcon(ADBLOCK_ICON_ACTIVE) : qApp->icons()->miscIcon(ADBLOCK_ICON_DISABLED));
|
||||||
|
|
||||||
connect(AdBlockManager::instance(), SIGNAL(enabledChanged(bool)), this, SLOT(setEnabled(bool)));
|
connect(m_manager, SIGNAL(enabledChanged(bool)), this, SLOT(setEnabled(bool)));
|
||||||
connect(menu(), SIGNAL(aboutToShow()), this, SLOT(createMenu()));
|
connect(menu(), SIGNAL(aboutToShow()), this, SLOT(createMenu()));
|
||||||
connect(this, &QAction::triggered, AdBlockManager::instance(), &AdBlockManager::showDialog);
|
connect(this, &QAction::triggered, m_manager, &AdBlockManager::showDialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
AdBlockIcon::~AdBlockIcon() {
|
AdBlockIcon::~AdBlockIcon() {
|
||||||
|
@ -58,7 +58,7 @@ void AdBlockIcon::popupBlocked(const QString& ruleString, const QUrl& url) {
|
||||||
int index = ruleString.lastIndexOf(QLatin1String(" ("));
|
int index = ruleString.lastIndexOf(QLatin1String(" ("));
|
||||||
const QString subscriptionName = ruleString.left(index);
|
const QString subscriptionName = ruleString.left(index);
|
||||||
const QString filter = ruleString.mid(index + 2, ruleString.size() - index - 3);
|
const QString filter = ruleString.mid(index + 2, ruleString.size() - index - 3);
|
||||||
AdBlockSubscription* subscription = AdBlockManager::instance()->subscriptionByName(subscriptionName);
|
AdBlockSubscription* subscription = m_manager->subscriptionByName(subscriptionName);
|
||||||
|
|
||||||
if (filter.isEmpty() || !subscription) {
|
if (filter.isEmpty() || !subscription) {
|
||||||
return;
|
return;
|
||||||
|
@ -93,14 +93,13 @@ void AdBlockIcon::createMenu(QMenu* menu) {
|
||||||
}
|
}
|
||||||
|
|
||||||
menu->clear();
|
menu->clear();
|
||||||
AdBlockManager* manager = AdBlockManager::instance();
|
AdBlockCustomList* customList = m_manager->customList();
|
||||||
AdBlockCustomList* customList = manager->customList();
|
|
||||||
WebPage* page = qApp->mainForm()->tabWidget()->currentWidget()->webBrowser()->viewer()->page();
|
WebPage* page = qApp->mainForm()->tabWidget()->currentWidget()->webBrowser()->viewer()->page();
|
||||||
const QUrl pageUrl = page->url();
|
const QUrl pageUrl = page->url();
|
||||||
menu->addAction(tr("Show AdBlock &settings"), manager, SLOT(showDialog()));
|
menu->addAction(tr("Show AdBlock &settings"), m_manager, SLOT(showDialog()));
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
|
|
||||||
if (!pageUrl.host().isEmpty() && m_enabled && manager->canRunOnScheme(pageUrl.scheme())) {
|
if (!pageUrl.host().isEmpty() && m_enabled && m_manager->canRunOnScheme(pageUrl.scheme())) {
|
||||||
const QString host = page->url().host().contains(QLatin1String("www.")) ? pageUrl.host().mid(4) : pageUrl.host();
|
const QString host = page->url().host().contains(QLatin1String("www.")) ? pageUrl.host().mid(4) : pageUrl.host();
|
||||||
const QString hostFilter = QString("@@||%1^$document").arg(host);
|
const QString hostFilter = QString("@@||%1^$document").arg(host);
|
||||||
const QString pageFilter = QString("@@|%1|$document").arg(pageUrl.toString());
|
const QString pageFilter = QString("@@|%1|$document").arg(pageUrl.toString());
|
||||||
|
@ -132,8 +131,7 @@ void AdBlockIcon::toggleCustomFilter() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString filter = action->data().toString();
|
const QString filter = action->data().toString();
|
||||||
AdBlockManager* manager = AdBlockManager::instance();
|
AdBlockCustomList* customList = m_manager->customList();
|
||||||
AdBlockCustomList* customList = manager->customList();
|
|
||||||
|
|
||||||
if (customList->containsFilter(filter)) {
|
if (customList->containsFilter(filter)) {
|
||||||
customList->removeFilter(filter);
|
customList->removeFilter(filter);
|
||||||
|
|
|
@ -29,13 +29,14 @@ class QUrl;
|
||||||
class QAction;
|
class QAction;
|
||||||
class QTimer;
|
class QTimer;
|
||||||
|
|
||||||
|
class AdBlockManager;
|
||||||
class BrowserWindow;
|
class BrowserWindow;
|
||||||
|
|
||||||
class AdBlockIcon : public QAction {
|
class AdBlockIcon : public QAction {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AdBlockIcon(QObject* parent = 0);
|
explicit AdBlockIcon(AdBlockManager* parent = 0);
|
||||||
virtual ~AdBlockIcon();
|
virtual ~AdBlockIcon();
|
||||||
|
|
||||||
void popupBlocked(const QString& ruleString, const QUrl& url);
|
void popupBlocked(const QString& ruleString, const QUrl& url);
|
||||||
|
@ -52,6 +53,7 @@ class AdBlockIcon : public QAction {
|
||||||
void stopAnimation();
|
void stopAnimation();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
AdBlockManager* m_manager;
|
||||||
QVector<QPair<AdBlockRule*, QUrl>> m_blockedPopups;
|
QVector<QPair<AdBlockRule*, QUrl>> m_blockedPopups;
|
||||||
QTimer* m_flashTimer;
|
QTimer* m_flashTimer;
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#include "miscellaneous/settings.h"
|
#include "miscellaneous/settings.h"
|
||||||
#include "network-web/adblock/adblockdialog.h"
|
#include "network-web/adblock/adblockdialog.h"
|
||||||
#include "network-web/adblock/adblockmatcher.h"
|
#include "network-web/adblock/adblockmatcher.h"
|
||||||
|
#include "network-web/adblock/adblockicon.h"
|
||||||
#include "network-web/adblock/adblocksubscription.h"
|
#include "network-web/adblock/adblocksubscription.h"
|
||||||
#include "network-web/adblock/adblockurlinterceptor.h"
|
#include "network-web/adblock/adblockurlinterceptor.h"
|
||||||
#include "network-web/networkurlinterceptor.h"
|
#include "network-web/networkurlinterceptor.h"
|
||||||
|
@ -43,6 +43,10 @@ Q_GLOBAL_STATIC(AdBlockManager, qz_adblock_manager)
|
||||||
|
|
||||||
AdBlockManager::AdBlockManager(QObject* parent)
|
AdBlockManager::AdBlockManager(QObject* parent)
|
||||||
: QObject(parent), m_loaded(false), m_enabled(true), m_matcher(new AdBlockMatcher(this)), m_interceptor(new AdBlockUrlInterceptor(this)) {
|
: QObject(parent), m_loaded(false), m_enabled(true), m_matcher(new AdBlockMatcher(this)), m_interceptor(new AdBlockUrlInterceptor(this)) {
|
||||||
|
|
||||||
|
m_adblockIcon = new AdBlockIcon(this);
|
||||||
|
m_adblockIcon->setObjectName(QSL("m_adblockIconAction"));
|
||||||
|
|
||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ class AdBlockSubscription;
|
||||||
class AdBlockRule;
|
class AdBlockRule;
|
||||||
class AdBlockDialog;
|
class AdBlockDialog;
|
||||||
class AdBlockUrlInterceptor;
|
class AdBlockUrlInterceptor;
|
||||||
|
class AdBlockIcon;
|
||||||
|
|
||||||
class AdBlockManager : public QObject {
|
class AdBlockManager : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -66,6 +67,10 @@ class AdBlockManager : public QObject {
|
||||||
|
|
||||||
AdBlockCustomList* customList() const;
|
AdBlockCustomList* customList() const;
|
||||||
|
|
||||||
|
inline AdBlockIcon* adblockIcon() const {
|
||||||
|
return m_adblockIcon;
|
||||||
|
}
|
||||||
|
|
||||||
static QString storedListsPath();
|
static QString storedListsPath();
|
||||||
|
|
||||||
static AdBlockManager* instance();
|
static AdBlockManager* instance();
|
||||||
|
@ -85,6 +90,8 @@ class AdBlockManager : public QObject {
|
||||||
bool m_loaded;
|
bool m_loaded;
|
||||||
bool m_enabled;
|
bool m_enabled;
|
||||||
|
|
||||||
|
AdBlockIcon* m_adblockIcon;
|
||||||
|
|
||||||
QList<AdBlockSubscription*> m_subscriptions;
|
QList<AdBlockSubscription*> m_subscriptions;
|
||||||
AdBlockMatcher* m_matcher;
|
AdBlockMatcher* m_matcher;
|
||||||
QStringList m_disabledRules;
|
QStringList m_disabledRules;
|
||||||
|
|
Loading…
Add table
Reference in a new issue