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