Remove unused code.
This commit is contained in:
parent
7f752a854f
commit
f4c11d94e1
@ -51,6 +51,8 @@ class AdBlockDialog : public QDialog {
|
||||
void learnAboutRules();
|
||||
|
||||
void loadSubscriptions();
|
||||
|
||||
private:
|
||||
void load();
|
||||
|
||||
private:
|
||||
|
@ -29,11 +29,9 @@
|
||||
#include "network-web/webpage.h"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QTimer>
|
||||
|
||||
AdBlockIcon::AdBlockIcon(AdBlockManager* parent)
|
||||
: QAction(parent), m_manager(parent), m_flashTimer(nullptr), m_timerTicks(0) {
|
||||
: QAction(parent), m_manager(parent) {
|
||||
setToolTip(tr("AdBlock lets you block unwanted content on web pages"));
|
||||
setText(QSL("AdBlock"));
|
||||
setMenu(new QMenu());
|
||||
@ -48,46 +46,11 @@ AdBlockIcon::AdBlockIcon(AdBlockManager* parent)
|
||||
}
|
||||
|
||||
AdBlockIcon::~AdBlockIcon() {
|
||||
for (int i = 0; i < m_blockedPopups.count(); ++i) {
|
||||
delete m_blockedPopups.at(i).first;
|
||||
}
|
||||
|
||||
if (menu() != nullptr) {
|
||||
menu()->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
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 = m_manager->subscriptionByName(subscriptionName);
|
||||
|
||||
if (filter.isEmpty() || (subscription == nullptr)) {
|
||||
return;
|
||||
}
|
||||
|
||||
QPair<AdBlockRule*, QUrl> pair;
|
||||
|
||||
pair.first = new AdBlockRule(filter, subscription);
|
||||
pair.second = url;
|
||||
m_blockedPopups.append(pair);
|
||||
qApp->showGuiMessage(tr("Blocked popup window"), tr("AdBlock blocked unwanted popup window."), QSystemTrayIcon::Information);
|
||||
|
||||
if (m_flashTimer == nullptr) {
|
||||
m_flashTimer = new QTimer(this);
|
||||
}
|
||||
|
||||
if (m_flashTimer->isActive()) {
|
||||
stopAnimation();
|
||||
}
|
||||
|
||||
m_flashTimer->setInterval(500);
|
||||
m_flashTimer->start();
|
||||
|
||||
connect(m_flashTimer, &QTimer::timeout, this, &AdBlockIcon::animateIcon);
|
||||
}
|
||||
|
||||
void AdBlockIcon::createMenu(QMenu* menu) {
|
||||
if (menu == nullptr) {
|
||||
menu = qobject_cast<QMenu*>(sender());
|
||||
@ -98,27 +61,27 @@ void AdBlockIcon::createMenu(QMenu* menu) {
|
||||
}
|
||||
|
||||
menu->clear();
|
||||
AdBlockCustomList* customList = m_manager->customList();
|
||||
AdBlockCustomList* custom_list = m_manager->customList();
|
||||
WebPage* page = qApp->mainForm()->tabWidget()->currentWidget()->webBrowser()->viewer()->page();
|
||||
const QUrl pageUrl = page->url();
|
||||
const QUrl page_url = page->url();
|
||||
|
||||
menu->addAction(tr("Show AdBlock &settings"), m_manager, &AdBlockManager::showDialog);
|
||||
menu->addSeparator();
|
||||
|
||||
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();
|
||||
if (!page_url.host().isEmpty() && m_manager->isEnabled() && m_manager->canRunOnScheme(page_url.scheme())) {
|
||||
const QString host = page->url().host().contains(QLatin1String("www.")) ? page_url.host().mid(4) : page_url.host();
|
||||
const QString host_filter = QString("@@||%1^$document").arg(host);
|
||||
const QString page_filter = QString("@@|%1|$document").arg(pageUrl.toString());
|
||||
const QString page_filter = QString("@@|%1|$document").arg(page_url.toString());
|
||||
QAction* act = menu->addAction(tr("Disable on %1").arg(host));
|
||||
|
||||
act->setCheckable(true);
|
||||
act->setChecked(customList->containsFilter(host_filter));
|
||||
act->setChecked(custom_list->containsFilter(host_filter));
|
||||
act->setData(host_filter);
|
||||
connect(act, &QAction::triggered, this, &AdBlockIcon::toggleCustomFilter);
|
||||
|
||||
act = menu->addAction(tr("Disable only on this page"));
|
||||
act->setCheckable(true);
|
||||
act->setChecked(customList->containsFilter(page_filter));
|
||||
act->setChecked(custom_list->containsFilter(page_filter));
|
||||
act->setData(page_filter);
|
||||
connect(act, &QAction::triggered, this, &AdBlockIcon::toggleCustomFilter);
|
||||
|
||||
@ -153,29 +116,6 @@ void AdBlockIcon::toggleCustomFilter() {
|
||||
}
|
||||
}
|
||||
|
||||
void AdBlockIcon::animateIcon() {
|
||||
m_timerTicks++;
|
||||
|
||||
if (m_timerTicks > 10) {
|
||||
stopAnimation();
|
||||
return;
|
||||
}
|
||||
|
||||
if (icon().isNull()) {
|
||||
setIcon(qApp->icons()->miscIcon(ADBLOCK_ICON_ACTIVE));
|
||||
}
|
||||
else {
|
||||
setIcon(QIcon());
|
||||
}
|
||||
}
|
||||
|
||||
void AdBlockIcon::stopAnimation() {
|
||||
m_timerTicks = 0;
|
||||
m_flashTimer->stop();
|
||||
disconnect(m_flashTimer, &QTimer::timeout, this, &AdBlockIcon::animateIcon);
|
||||
setEnabled(m_enabled);
|
||||
}
|
||||
|
||||
void AdBlockIcon::setEnabled(bool enabled) {
|
||||
if (enabled) {
|
||||
setIcon(qApp->icons()->miscIcon(ADBLOCK_ICON_ACTIVE));
|
||||
@ -183,6 +123,4 @@ void AdBlockIcon::setEnabled(bool enabled) {
|
||||
else {
|
||||
setIcon(qApp->icons()->miscIcon(ADBLOCK_ICON_DISABLED));
|
||||
}
|
||||
|
||||
m_enabled = enabled;
|
||||
}
|
||||
|
@ -22,15 +22,8 @@
|
||||
|
||||
#include <QAction>
|
||||
|
||||
#include "network-web/adblock/adblockrule.h"
|
||||
|
||||
class QMenu;
|
||||
class QUrl;
|
||||
class QAction;
|
||||
class QTimer;
|
||||
|
||||
class AdBlockManager;
|
||||
class BrowserWindow;
|
||||
|
||||
class AdBlockIcon : public QAction {
|
||||
Q_OBJECT
|
||||
@ -39,25 +32,18 @@ class AdBlockIcon : public QAction {
|
||||
explicit AdBlockIcon(AdBlockManager* parent = nullptr);
|
||||
virtual ~AdBlockIcon();
|
||||
|
||||
void popupBlocked(const QString& ruleString, const QUrl& url);
|
||||
|
||||
public slots:
|
||||
void setEnabled(bool enabled);
|
||||
void createMenu(QMenu* menu = nullptr);
|
||||
|
||||
private slots:
|
||||
void showMenu(const QPoint& pos);
|
||||
void toggleCustomFilter();
|
||||
|
||||
void animateIcon();
|
||||
void stopAnimation();
|
||||
private:
|
||||
void createMenu(QMenu* menu = nullptr);
|
||||
|
||||
private:
|
||||
AdBlockManager* m_manager;
|
||||
QVector<QPair<AdBlockRule*, QUrl>> m_blockedPopups;
|
||||
QTimer* m_flashTimer;
|
||||
int m_timerTicks;
|
||||
bool m_enabled;
|
||||
};
|
||||
|
||||
#endif // ADBLOCKICON_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user