Commit 12f3461b authored by Laurent Montel's avatar Laurent Montel 😁

Remove code

parent f595c2db
/* ============================================================
*
* This file is a part of the rekonq project
*
* Copyright (C) 2010-2011 by Benjamin Poulain <ikipou at gmail dot com>
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ============================================================ */
#ifndef ADBLOCKRULEIMPL_H
#define ADBLOCKRULEIMPL_H
class QString;
class QNetworkRequest;
namespace MessageViewer
{
class AdBlockRuleImpl
{
public:
explicit AdBlockRuleImpl(const QString &) {}
virtual ~AdBlockRuleImpl() {}
virtual bool match(const QNetworkRequest &request, const QString &encodedUrl, const QString &encodedUrlLowerCase) const = 0;
// This are added just for debugging purposes
virtual QString ruleString() const = 0;
virtual QString ruleType() const = 0;
};
}
#endif // ADBLOCKRULEIMPL_H
/*
Copyright (c) 2013-2016 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "adblockaddsubscriptiondialog.h"
#include "adblockshowlistdialog.h"
#include "adblockutil.h"
#include <KLocalizedString>
#include <QComboBox>
#include <QLabel>
#include <QHBoxLayout>
#include <QDialogButtonBox>
#include <QPushButton>
#include <QVBoxLayout>
#include <QToolButton>
#include <QPointer>
using namespace MessageViewer;
AdBlockAddSubscriptionDialog::AdBlockAddSubscriptionDialog(const QStringList &excludeList, QWidget *parent)
: QDialog(parent)
{
setWindowTitle(i18n("Add subscription"));
QVBoxLayout *mainLayout = new QVBoxLayout;
setLayout(mainLayout);
QWidget *w = new QWidget;
QHBoxLayout *lay = new QHBoxLayout;
lay->setMargin(0);
QLabel *lab = new QLabel(i18n("Select List:"));
lab->setObjectName(QStringLiteral("listsubscriptionlabel"));
lay->addWidget(lab);
mListSubscription = new QComboBox;
mListSubscription->setObjectName(QStringLiteral("listsubscriptioncombobox"));
lay->addWidget(mListSubscription);
mShowList = new QToolButton;
mShowList->setToolTip(i18n("Show List"));
mShowList->setObjectName(QStringLiteral("showlisttoolbutton"));
mShowList->setIcon(QIcon::fromTheme(QStringLiteral("document-preview")));
lay->addWidget(mShowList);
connect(mShowList, &QToolButton::clicked, this, &AdBlockAddSubscriptionDialog::slotShowList);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
buttonBox->setObjectName(QStringLiteral("listsubscriptionbuttonBox"));
QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
okButton->setDefault(true);
okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
connect(buttonBox, &QDialogButtonBox::accepted, this, &AdBlockAddSubscriptionDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &AdBlockAddSubscriptionDialog::reject);
w->setLayout(lay);
mainLayout->addWidget(w);
mainLayout->addWidget(buttonBox);
initializeList(excludeList);
}
AdBlockAddSubscriptionDialog::~AdBlockAddSubscriptionDialog()
{
}
void AdBlockAddSubscriptionDialog::initializeList(const QStringList &excludeList)
{
QMapIterator<QString, QString> i(MessageViewer::AdBlockUtil::listSubscriptions());
while (i.hasNext()) {
i.next();
if (!excludeList.contains(i.key())) {
mListSubscription->addItem(i.key(), i.value());
}
}
}
void AdBlockAddSubscriptionDialog::selectedList(QString &name, QString &url)
{
name = mListSubscription->currentText();
url = mListSubscription->itemData(mListSubscription->currentIndex()).toString();
}
void AdBlockAddSubscriptionDialog::slotShowList()
{
const QString url = mListSubscription->itemData(mListSubscription->currentIndex()).toString();
if (!url.isEmpty()) {
QPointer<AdBlockShowListDialog> dlg = new AdBlockShowListDialog(false, this);
dlg->setListName(mListSubscription->currentText());
dlg->setAdBlockListPath(QString(), url);
dlg->exec();
delete dlg;
}
}
/*
Copyright (c) 2013-2016 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef ADBLOCKADDSUBSCRIPTIONDIALOG_H
#define ADBLOCKADDSUBSCRIPTIONDIALOG_H
#include <QDialog>
class QComboBox;
class QToolButton;
namespace MessageViewer
{
class AdBlockAddSubscriptionDialog : public QDialog
{
Q_OBJECT
public:
explicit AdBlockAddSubscriptionDialog(const QStringList &excludeList, QWidget *parent = Q_NULLPTR);
~AdBlockAddSubscriptionDialog();
void selectedList(QString &name, QString &url);
private Q_SLOTS:
void slotShowList();
private:
void initializeList(const QStringList &excludeList);
QComboBox *mListSubscription;
QToolButton *mShowList;
};
}
#endif // ADBLOCKADDSUBSCRIPTIONDIALOG_H
/*
Copyright (c) 2016 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "adblockautomaticruleslistwidget.h"
using namespace MessageViewer;
AdBlockAutomaticRulesListWidget::AdBlockAutomaticRulesListWidget(QWidget *parent)
: QListWidget(parent)
{
connect(this, &AdBlockAutomaticRulesListWidget::itemChanged, this, &AdBlockAutomaticRulesListWidget::slotItemChanged);
}
AdBlockAutomaticRulesListWidget::~AdBlockAutomaticRulesListWidget()
{
}
void AdBlockAutomaticRulesListWidget::slotItemChanged(QListWidgetItem *item)
{
updateItem(item);
}
void AdBlockAutomaticRulesListWidget::updateItem(QListWidgetItem *item)
{
const bool itemIsChecked = (item->checkState() & Qt::Checked);
QFont font = item->font();
const QString rule = item->text();
if (itemIsChecked) {
font.setItalic(false);
item->setFont(font);
if (rule.contains(QRegularExpression(QStringLiteral("^@@.*")))) {
item->setTextColor(Qt::magenta);
} else if (rule.contains(QRegularExpression(QStringLiteral("^\\[.*")))) {
item->setTextColor(Qt::red);
} else if (rule.contains(QRegularExpression(QStringLiteral(".*##.*")))) {
item->setTextColor(Qt::blue);
} else {
if (!defaultTextColor.isValid()) {
const QPalette palette = viewport()->palette();
defaultTextColor = palette.text().color();
}
item->setTextColor(defaultTextColor);
}
} else {
font.setItalic(true);
item->setFont(font);
item->setTextColor(Qt::gray);
}
}
void AdBlockAutomaticRulesListWidget::setDisabledRules(const QStringList &disabledRules)
{
mDisabledRules = disabledRules;
}
void AdBlockAutomaticRulesListWidget::setRules(const QString &rules)
{
clear();
const QStringList lst = rules.split(QLatin1Char('\n'), QString::SkipEmptyParts);
Q_FOREACH (const QString &rule, lst) {
createItem(rule);
}
}
void AdBlockAutomaticRulesListWidget::createItem(const QString &rule)
{
QListWidgetItem *subItem = new QListWidgetItem(this);
subItem->setText(rule);
if (rule.startsWith(QLatin1Char('!')) || rule.startsWith(QLatin1Char('['))) {
//Comment
subItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled);
subItem->setTextColor(Qt::gray);
} else {
subItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled);
const bool checkState = mDisabledRules.contains(rule);
subItem->setCheckState(checkState ? Qt::Unchecked : Qt::Checked);
updateItem(subItem);
}
}
QStringList AdBlockAutomaticRulesListWidget::disabledRules() const
{
QStringList currentDisabledRules;
for (int i = 0; i < count(); ++i) {
QListWidgetItem *row = item(i);
if (row->flags() & Qt::ItemIsUserCheckable) {
if (row->checkState() == Qt::Unchecked) {
currentDisabledRules << row->text();
}
}
}
return currentDisabledRules;
}
/*
Copyright (c) 2016 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef ADBLOCKAUTOMATICRULESLISTWIDGET_H
#define ADBLOCKAUTOMATICRULESLISTWIDGET_H
#include <QListWidget>
#include "messageviewer_export.h"
namespace MessageViewer
{
class MESSAGEVIEWER_EXPORT AdBlockAutomaticRulesListWidget : public QListWidget
{
Q_OBJECT
public:
explicit AdBlockAutomaticRulesListWidget(QWidget *parent = Q_NULLPTR);
~AdBlockAutomaticRulesListWidget();
void setRules(const QString &rules);
void setDisabledRules(const QStringList &disabledRules);
QStringList disabledRules() const;
private Q_SLOTS:
void slotItemChanged(QListWidgetItem *item);
private:
void updateItem(QListWidgetItem *item);
void createItem(const QString &rule);
QStringList mDisabledRules;
QColor defaultTextColor;
};
}
#endif // ADBLOCKAUTOMATICRULESLISTWIDGET_H
/*
Copyright (c) 2013-2016 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "adblocklistwidget.h"
#include <KLocalizedString>
#include <QPainter>
#include <QPaintEvent>
using namespace MessageViewer;
AdBlockListWidget::AdBlockListWidget(QWidget *parent)
: QListWidget(parent)
{
}
AdBlockListWidget::~AdBlockListWidget()
{
}
void AdBlockListWidget::changeEvent(QEvent *event)
{
if (event->type() == QEvent::PaletteChange) {
generalPaletteChanged();
}
QListWidget::changeEvent(event);
}
void AdBlockListWidget::generalPaletteChanged()
{
const QPalette palette = viewport()->palette();
QColor color = palette.text().color();
color.setAlpha(128);
mTextColor = color;
}
void AdBlockListWidget::paintEvent(QPaintEvent *event)
{
if (!model() || model()->rowCount() == 0) {
QPainter p(viewport());
QFont font = p.font();
font.setItalic(true);
p.setFont(font);
if (!mTextColor.isValid()) {
generalPaletteChanged();
}
p.setPen(mTextColor);
p.drawText(QRect(0, 0, width(), height()), Qt::AlignCenter, i18n("Not subscription added..."));
} else {
QListWidget::paintEvent(event);
}
}
/*
Copyright (c) 2013-2016 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef ADBLOCKLISTWIDGET_H
#define ADBLOCKLISTWIDGET_H
#include <QListWidget>
class QPaintEvent;
class QEvent;
namespace MessageViewer
{
class AdBlockListWidget : public QListWidget
{
Q_OBJECT
public:
explicit AdBlockListWidget(QWidget *parent = Q_NULLPTR);
~AdBlockListWidget();
private:
void generalPaletteChanged();
protected:
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
void changeEvent(QEvent *event) Q_DECL_OVERRIDE;
private:
QColor mTextColor;
};
}
#endif // ADBLOCKLISTWIDGET_H
/* ============================================================
*
* This file is a part of the rekonq project
* Copyright (c) 2013-2016 Montel Laurent <montel@kde.org>
* based on code from rekonq
* Copyright (C) 2010-2012 by Andrea Diamantini <adjam7 at gmail dot com>
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ============================================================ */
#ifndef AD_BLOCK_SETTINGS_WIDGET_H
#define AD_BLOCK_SETTINGS_WIDGET_H
#include "messageviewer_export.h"
// Qt Includes
#include <QWidget>
class QListWidgetItem;
namespace Ui
{
class adblock;
}
namespace MessageViewer
{
class MESSAGEVIEWER_EXPORT AdBlockSettingWidget : public QWidget
{
Q_OBJECT
public:
explicit AdBlockSettingWidget(QWidget *parent = Q_NULLPTR);
virtual ~AdBlockSettingWidget();
bool changed() const;
void save();
void doLoadFromGlobalSettings();
void doResetToDefaultsOther();
Q_SIGNALS:
void changed(bool);
void settingsChanged();
protected:
bool event(QEvent *event) Q_DECL_OVERRIDE;
private Q_SLOTS:
void hasChanged();
void slotInfoLinkActivated(const QString &);
void insertRule();
void removeRule();
void slotAddFilter();
void slotRemoveSubscription();
void slotUpdateButtons();
void slotShowList();
void slotImportFilters();
void slotExportFilters();
void slotUpdateManualButtons();
void slotEditFilter();
void slotManualFilterLineEditTextChanged(const QString &);
void slotAutomaticFilterDouble(QListWidgetItem *item);
void slotDeleteList(const QString &listName);
private:
void updateCheckBox();
void addManualFilter(const QString &text, const QStringList &excludeRules = QStringList());
void showAutomaticFilterList(QListWidgetItem *item);
enum List {
UrlList = Qt::UserRole + 1,
PathList = Qt::UserRole + 2,
LastUpdateList = Qt::UserRole + 3
};
Ui::adblock *mUi;
bool mChanged;
};
}
#endif // AD_BLOCK_SETTINGS_WIDGET_H
/*
Copyright (c) 2013-2016 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "adblockshowlistdialog.h"
#include "adblocksyntaxhighlighter.h"
#include "kpimtextedit/plaintexteditorwidget.h"
#include "kpimtextedit/plaintexteditor.h"
#include "messageviewer_debug.h"
#include "Libkdepim/ProgressIndicatorLabel"
#include <KLocalizedString>
#include <KIO/Job>
#include <QTemporaryFile>
#include <KSharedConfig>
#include <QUrl>
#include <QDialogButtonBox>
#include <KConfigGroup>
#include <QPushButton>
#include <QVBoxLayout>
using namespace MessageViewer;
AdBlockShowListDialog::AdBlockShowListDialog(bool showDeleteBrokenList, QWidget *parent)
: QDialog(parent),
mTemporaryFile(Q_NULLPTR),
mUser1Button(Q_NULLPTR)
{
setWindowTitle(i18n("Show adblock list"));