Save work.

This commit is contained in:
Martin Rotter 2017-07-19 21:55:01 +02:00
parent c2e1100ff6
commit e3635f5394
10 changed files with 353 additions and 399 deletions

View File

@ -20,6 +20,8 @@
#include "definitions/definitions.h"
#include <QComboBox>
AdBlockAddSubscriptionDialog::AdBlockAddSubscriptionDialog(QWidget* parent)
: QDialog(parent), m_ui(new Ui::AdBlockAddSubscriptionDialog) {
@ -33,7 +35,7 @@ AdBlockAddSubscriptionDialog::AdBlockAddSubscriptionDialog(QWidget* parent)
<< Subscription(QSL("IsraelList (Hebrew)"), QSL("http://secure.fanboy.co.nz/israelilist/IsraelList.txt"))
<< Subscription(QSL("NLBlock (Dutch)"), QSL("http://www.verzijlbergh.com/adblock/nlblock.txt"))
<< Subscription(QSL("Peter Lowe's list (English)"), QSL("http://pgl.yoyo.org/adservers/serverlist.php?hostformat=adblockplus&mimetype=plaintext"))
<< Subscription(QSL("PLgeneral (Polish))", QSL("http://www.niecko.pl/adblock/adblock.txt"))
<< Subscription(QSL("PLgeneral (Polish)"), QSL("http://www.niecko.pl/adblock/adblock.txt"))
<< Subscription(QSL("Schacks Adblock Plus liste (Danish)"), QSL("http://adblock.schack.dk/block.txt"))
<< Subscription(QSL("Xfiles (Italian)"), QSL("http://mozilla.gfsolone.com/filtri.txt"))
<< Subscription(QSL("EasyPrivacy (English)"), QSL("http://easylist-downloads.adblockplus.org/easyprivacy.txt"))
@ -47,7 +49,8 @@ AdBlockAddSubscriptionDialog::AdBlockAddSubscriptionDialog(QWidget* parent)
m_ui->comboBox->addItem(subscription.m_title);
}
connect(m_ui->comboBox, &QComboBox::currentIndexChanged, this, &AdBlockAddSubscriptionDialog::indexChanged);
connect(m_ui->comboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &AdBlockAddSubscriptionDialog::indexChanged);
indexChanged(0);
}
@ -62,7 +65,7 @@ QString AdBlockAddSubscriptionDialog::url() const {
void AdBlockAddSubscriptionDialog::indexChanged(int index) {
const Subscription subscription = m_knownSubscriptions.at(index);
// "Other..." entry
// "Other..." entry.
if (subscription.m_url.isEmpty()) {
m_ui->title->clear();
m_ui->url->clear();

View File

@ -41,7 +41,7 @@ AdBlockDialog::AdBlockDialog(QWidget* parent)
m_ui->adblockCheckBox->setChecked(m_manager->isEnabled());
QMenu* menu = new QMenu(buttonOptions);
QMenu* menu = new QMenu(m_ui->buttonOptions);
m_actionAddRule = menu->addAction(tr("Add Rule"), this, SLOT(addRule()));
m_actionRemoveRule = menu->addAction(tr("Remove Rule"), this, SLOT(removeRule()));
menu->addSeparator();
@ -54,10 +54,9 @@ AdBlockDialog::AdBlockDialog(QWidget* parent)
m_ui->buttonOptions->setMenu(menu);
connect(menu, SIGNAL(aboutToShow()), this, SLOT(aboutToShowMenu()));
connect(adblockCheckBox, SIGNAL(toggled(bool)), this, SLOT(enableAdBlock(bool)));
connect(search, SIGNAL(textChanged(QString)), this, SLOT(filterString(QString)));
connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(currentChanged(int)));
connect(buttonBox, SIGNAL(accepted()), this, SLOT(close()));
connect(m_ui->adblockCheckBox, SIGNAL(toggled(bool)), this, SLOT(enableAdBlock(bool)));
connect(m_ui->tabWidget, SIGNAL(currentChanged(int)), this, SLOT(currentChanged(int)));
connect(m_ui->buttonBox, SIGNAL(accepted()), this, SLOT(close()));
load();
@ -71,12 +70,12 @@ void AdBlockDialog::showRule(const AdBlockRule* rule) const {
return;
}
for (int i = 0; i < tabWidget->count(); ++i) {
AdBlockTreeWidget *treeWidget = qobject_cast<AdBlockTreeWidget*>(tabWidget->widget(i));
for (int i = 0; i < m_ui->tabWidget->count(); ++i) {
AdBlockTreeWidget *treeWidget = qobject_cast<AdBlockTreeWidget*>(m_ui->tabWidget->widget(i));
if (subscription == treeWidget->subscription()) {
treeWidget->showRule(rule);
tabWidget->setCurrentIndex(i);
m_ui->tabWidget->setCurrentIndex(i);
break;
}
}
@ -101,10 +100,10 @@ void AdBlockDialog::addSubscription() {
QString url = dialog.url();
if (AdBlockSubscription *subscription = m_manager->addSubscription(title, url)) {
AdBlockTreeWidget *tree = new AdBlockTreeWidget(subscription, tabWidget);
int index = tabWidget->insertTab(tabWidget->count() - 1, tree, subscription->title());
AdBlockTreeWidget *tree = new AdBlockTreeWidget(subscription, m_ui->tabWidget);
int index = m_ui->tabWidget->insertTab(m_ui->tabWidget->count() - 1, tree, subscription->title());
tabWidget->setCurrentIndex(index);
m_ui->tabWidget->setCurrentIndex(index);
}
}
@ -116,17 +115,11 @@ void AdBlockDialog::removeSubscription() {
void AdBlockDialog::currentChanged(int index) {
if (index != -1) {
m_currentTreeWidget = qobject_cast<AdBlockTreeWidget*>(tabWidget->widget(index));
m_currentTreeWidget = qobject_cast<AdBlockTreeWidget*>(m_ui->tabWidget->widget(index));
m_currentSubscription = m_currentTreeWidget->subscription();
}
}
void AdBlockDialog::filterString(const QString &string) {
if (m_currentTreeWidget && adblockCheckBox->isChecked()) {
m_currentTreeWidget->filterString(string);
}
}
void AdBlockDialog::enableAdBlock(bool state) {
m_manager->setEnabled(state);
@ -149,20 +142,20 @@ void AdBlockDialog::learnAboutRules() {
}
void AdBlockDialog::loadSubscriptions() {
for (int i = 0; i < tabWidget->count(); ++i) {
AdBlockTreeWidget* treeWidget = qobject_cast<AdBlockTreeWidget*>(tabWidget->widget(i));
for (int i = 0; i < m_ui->tabWidget->count(); ++i) {
AdBlockTreeWidget *treeWidget = qobject_cast<AdBlockTreeWidget*>(m_ui->tabWidget->widget(i));
treeWidget->refresh();
}
}
void AdBlockDialog::load() {
if (m_loaded || !adblockCheckBox->isChecked()) {
if (m_loaded || !m_ui->adblockCheckBox->isChecked()) {
return;
}
foreach (AdBlockSubscription* subscription, m_manager->subscriptions()) {
AdBlockTreeWidget* tree = new AdBlockTreeWidget(subscription, tabWidget);
tabWidget->addTab(tree, subscription->title());
AdBlockTreeWidget *tree = new AdBlockTreeWidget(subscription, m_ui->tabWidget);
m_ui->tabWidget->addTab(tree, subscription->title());
}
m_loaded = true;

View File

@ -45,7 +45,6 @@ class AdBlockDialog : public QWidget {
void removeSubscription();
void currentChanged(int index);
void filterString(const QString &string);
void enableAdBlock(bool state);
void aboutToShowMenu();

View File

@ -24,33 +24,6 @@
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLineEdit" name="search">
<property name="placeholderText">
<string>Search...</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>50</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QWidget" name="adblockWidget" native="true">
<property name="enabled">
@ -77,7 +50,7 @@
<string>Options</string>
</property>
<property name="icon">
<iconset resource="../data/icons.qrc">
<iconset>
<normaloff>:/icons/other/adblock.png</normaloff>:/icons/other/adblock.png</iconset>
</property>
</widget>
@ -139,9 +112,7 @@
</item>
</layout>
</widget>
<resources>
<include location="../data/icons.qrc"/>
</resources>
<resources/>
<connections>
<connection>
<sender>adblockCheckBox</sender>

View File

@ -20,10 +20,13 @@
#include "network-web/adblock/adblockrule.h"
#include "network-web/adblock/adblockmanager.h"
#include "network-web/adblock/adblocksubscription.h"
#include "miscellaneous/application.h"
#include "network-web/webpage.h"
#include <QMenu>
#include <QTimer>
AdBlockIcon::AdBlockIcon(BrowserWindow* window, QWidget* parent)
: ClickableLabel(parent), m_window(window), m_menuAction(0), m_flashTimer(0), m_timerTicks(0), m_enabled(false) {
setCursor(Qt::PointingHandCursor);
@ -55,7 +58,8 @@ void AdBlockIcon::popupBlocked(const QString &ruleString, const QUrl &url) {
pair.second = url;
m_blockedPopups.append(pair);
mApp->desktopNotifications()->showNotification(QPixmap(":html/adblock_big.png"), tr("Blocked popup window"), tr("AdBlock blocked unwanted popup window."));
qApp->showGuiMessage(tr("Blocked popup window"), tr("AdBlock blocked unwanted popup window."), QSystemTrayIcon::Information);
if (!m_flashTimer) {
m_flashTimer = new QTimer(this);
@ -68,7 +72,7 @@ void AdBlockIcon::popupBlocked(const QString &ruleString, const QUrl &url) {
m_flashTimer->setInterval(500);
m_flashTimer->start();
connect(m_flashTimer, SIGNAL(timeout()), this, SLOT(animateIcon()));
connect(m_flashTimer, &QTimer::timeout, this, &AdBlockIcon::animateIcon);
}
QAction *AdBlockIcon::menuAction() {

View File

@ -16,29 +16,25 @@
// You should have received a copy of the GNU General Public License
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
#include "adblocksearchtree.h"
#include "adblockrule.h"
#include "network-web/adblock/adblocksearchtree.h"
#include "network-web/adblock/adblockrule.h"
#include <QWebEngineUrlRequestInfo>
AdBlockSearchTree::AdBlockSearchTree()
: m_root(new Node)
{
AdBlockSearchTree::AdBlockSearchTree() : m_root(new Node) {
}
AdBlockSearchTree::~AdBlockSearchTree()
{
AdBlockSearchTree::~AdBlockSearchTree() {
deleteNode(m_root);
}
void AdBlockSearchTree::clear()
{
void AdBlockSearchTree::clear() {
deleteNode(m_root);
m_root = new Node;
}
bool AdBlockSearchTree::add(const AdBlockRule* rule)
{
bool AdBlockSearchTree::add(const AdBlockRule *rule) {
if (rule->m_type != AdBlockRule::StringContainsMatchRule) {
return false;
}
@ -47,7 +43,7 @@ bool AdBlockSearchTree::add(const AdBlockRule* rule)
int len = filter.size();
if (len <= 0) {
qDebug() << "AdBlockSearchTree: Inserting rule with filter len <= 0!";
qDebug("AdBlockSearchTree: Inserting rule with filter len <= 0!");
return false;
}
@ -56,11 +52,13 @@ bool AdBlockSearchTree::add(const AdBlockRule* rule)
for (int i = 0; i < len; ++i) {
const QChar c = filter.at(i);
Node *next = node->children.value(c);
if (!next) {
next = new Node;
next->c = c;
node->children[c] = next;
}
node = next;
}
@ -69,8 +67,7 @@ bool AdBlockSearchTree::add(const AdBlockRule* rule)
return true;
}
const AdBlockRule* AdBlockSearchTree::find(const QWebEngineUrlRequestInfo &request, const QString &domain, const QString &urlString) const
{
const AdBlockRule *AdBlockSearchTree::find(const QWebEngineUrlRequestInfo &request, const QString &domain, const QString &urlString) const {
int len = urlString.size();
if (len <= 0) {
@ -81,6 +78,7 @@ const AdBlockRule* AdBlockSearchTree::find(const QWebEngineUrlRequestInfo &reque
for (int i = 0; i < len; ++i) {
const AdBlockRule *rule = prefixSearch(request, domain, urlString, string++, len - i);
if (rule) {
return rule;
}
@ -89,8 +87,7 @@ const AdBlockRule* AdBlockSearchTree::find(const QWebEngineUrlRequestInfo &reque
return 0;
}
const AdBlockRule* AdBlockSearchTree::prefixSearch(const QWebEngineUrlRequestInfo &request, const QString &domain, const QString &urlString, const QChar* string, int len) const
{
const AdBlockRule *AdBlockSearchTree::prefixSearch(const QWebEngineUrlRequestInfo &request, const QString &domain, const QString &urlString, const QChar *string, int len) const {
if (len <= 0) {
return 0;
}
@ -98,6 +95,7 @@ const AdBlockRule* AdBlockSearchTree::prefixSearch(const QWebEngineUrlRequestInf
QChar c = string[0];
Node *node = m_root->children.value(c);
if (!node) {
return nullptr;
}
@ -110,6 +108,7 @@ const AdBlockRule* AdBlockSearchTree::prefixSearch(const QWebEngineUrlRequestInf
}
node = node->children.value(c);
if (!node) {
return nullptr;
}
@ -122,13 +121,13 @@ const AdBlockRule* AdBlockSearchTree::prefixSearch(const QWebEngineUrlRequestInf
return nullptr;
}
void AdBlockSearchTree::deleteNode(AdBlockSearchTree::Node* node)
{
void AdBlockSearchTree::deleteNode(AdBlockSearchTree::Node* node) {
if (!node) {
return;
}
QHashIterator<QChar, Node*> i(node->children);
while (i.hasNext()) {
i.next();
deleteNode(i.value());

View File

@ -22,17 +22,14 @@
#include <QChar>
#include <QHash>
#include "qzcommon.h"
class QWebEngineUrlRequestInfo;
class AdBlockRule;
class QUPZILLA_EXPORT AdBlockSearchTree
{
class AdBlockSearchTree {
public:
explicit AdBlockSearchTree();
~AdBlockSearchTree();
virtual ~AdBlockSearchTree();
void clear();

View File

@ -44,54 +44,44 @@
* SUCH DAMAGE.
*/
#include "adblocksubscription.h"
#include "adblockmanager.h"
#include "adblocksearchtree.h"
#include "mainapplication.h"
#include "networkmanager.h"
#include "datapaths.h"
#include "qztools.h"
#include "network-web/adblock/adblocksubscription.h"
#include "network-web/adblock/adblockmanager.h"
#include "network-web/adblock/adblocksearchtree.h"
#include "definitions/definitions.h"
#include "network-web/silentnetworkaccessmanager.h"
#include <QFile>
#include <QTimer>
#include <QNetworkReply>
#include <QSaveFile>
AdBlockSubscription::AdBlockSubscription(const QString &title, QObject* parent)
: QObject(parent)
, m_reply(0)
, m_title(title)
, m_updated(false)
{
: QObject(parent), m_reply(0), m_title(title), m_updated(false) {
}
QString AdBlockSubscription::title() const
{
QString AdBlockSubscription::title() const {
return m_title;
}
QString AdBlockSubscription::filePath() const
{
QString AdBlockSubscription::filePath() const {
return m_filePath;
}
void AdBlockSubscription::setFilePath(const QString &path)
{
void AdBlockSubscription::setFilePath(const QString &path) {
m_filePath = path;
}
QUrl AdBlockSubscription::url() const
{
QUrl AdBlockSubscription::url() const {
return m_url;
}
void AdBlockSubscription::setUrl(const QUrl &url)
{
void AdBlockSubscription::setUrl(const QUrl &url) {
m_url = url;
}
void AdBlockSubscription::loadSubscription(const QStringList &disabledRules)
{
void AdBlockSubscription::loadSubscription(const QStringList &disabledRules) {
QFile file(m_filePath);
if (!file.exists()) {
@ -100,7 +90,7 @@ void AdBlockSubscription::loadSubscription(const QStringList &disabledRules)
}
if (!file.open(QFile::ReadOnly)) {
qWarning() << "AdBlockSubscription::" << __FUNCTION__ << "Unable to open adblock file for reading" << m_filePath;
qWarning("Unable to open adblock file '%s' for reading.", qPrintable(m_filePath));
QTimer::singleShot(0, this, SLOT(updateSubscription()));
return;
}
@ -112,8 +102,8 @@ void AdBlockSubscription::loadSubscription(const QStringList &disabledRules)
textStream.readLine(1024);
QString header = textStream.readLine(1024);
if (!header.startsWith(QLatin1String("[Adblock")) || m_title.isEmpty()) {
qWarning() << "AdBlockSubscription::" << __FUNCTION__ << "invalid format of adblock file" << m_filePath;
if (!header.startsWith(QL1S("[Adblock")) || m_title.isEmpty()) {
qWarning("Invalid format of AdBlock file '%s'.", qPrintable(m_filePath));
QTimer::singleShot(0, this, SLOT(updateSubscription()));
return;
}
@ -130,23 +120,23 @@ void AdBlockSubscription::loadSubscription(const QStringList &disabledRules)
m_rules.append(rule);
}
// Initial update
// Initial update.
if (m_rules.isEmpty() && !m_updated) {
QTimer::singleShot(0, this, SLOT(updateSubscription()));
}
}
void AdBlockSubscription::saveSubscription()
{
void AdBlockSubscription::saveSubscription() {
}
void AdBlockSubscription::updateSubscription()
{
void AdBlockSubscription::updateSubscription() {
if (m_reply || !m_url.isValid()) {
return;
}
m_reply = mApp->networkManager()->get(QNetworkRequest(m_url));
SilentNetworkAccessManager *mgs = new SilentNetworkAccessManager(this);
m_reply = mgs->get(QNetworkRequest(m_url));
connect(m_reply, &QNetworkReply::finished, this, &AdBlockSubscription::subscriptionDownloaded);
}
@ -159,13 +149,11 @@ void AdBlockSubscription::subscriptionDownloaded()
bool error = false;
const QByteArray response = QString::fromUtf8(m_reply->readAll()).toUtf8();
if (m_reply->error() != QNetworkReply::NoError ||
!response.startsWith(QByteArray("[Adblock")) ||
!saveDownloadedData(response)
) {
if (m_reply->error() != QNetworkReply::NoError || !response.startsWith(QByteArray("[Adblock")) || !saveDownloadedData(response)) {
error = true;
}
m_reply->manager()->deleteLater();
m_reply->deleteLater();
m_reply = 0;

View File

@ -50,19 +50,19 @@
#include <QVector>
#include <QUrl>
#include "qzcommon.h"
#include "adblockrule.h"
#include "adblocksearchtree.h"
#include "network-web/adblock/adblockrule.h"
#include "network-web/adblock/adblocksearchtree.h"
class QUrl;
class QNetworkReply;
class QUPZILLA_EXPORT AdBlockSubscription : public QObject
{
class AdBlockSubscription : public QObject {
Q_OBJECT
public:
explicit AdBlockSubscription(const QString &title, QObject *parent = 0);
~AdBlockSubscription();
virtual ~AdBlockSubscription();
QString title() const;
@ -113,9 +113,9 @@ private:
bool m_updated;
};
class AdBlockCustomList : public AdBlockSubscription
{
class AdBlockCustomList : public AdBlockSubscription {
Q_OBJECT
public:
explicit AdBlockCustomList(QObject *parent = 0);