Commit eb8de1d3 authored by Laurent Montel's avatar Laurent Montel 😁

Don't use messageviewer code (prepare to remove qtwebkit support in messageviewer)

parent 742016cd
......@@ -6,7 +6,15 @@ set(adblocklibprivate_widget_SRCS
widgets/adblockblockableitemswidget.cpp
widgets/adblockcreatefilterdialog.cpp
widgets/adblockpluginurlinterceptorconfigurewidget.cpp
widgets/adblockaddsubscriptiondialog.cpp
widgets/adblockautomaticruleslistwidget.cpp
widgets/adblocklistwidget.cpp
widgets/adblocksettingwidget.cpp
widgets/adblockshowlistdialog.cpp
widgets/adblocksyntaxhighlighter.cpp
widgets/adblockutil.cpp
)
set(adblocklibprivate_SRCS
adblockmanager.cpp
adblocksearchtree.cpp
......@@ -17,14 +25,14 @@ set(adblocklibprivate_SRCS
adblocksubscription.cpp
${adblocklibprivate_widget_SRCS}
${messageviewer_adblock_lib_common_SRCS}
)
ki18n_wrap_ui(adblocklibprivate_SRCS widgets/adblockcreatefilterwidget.ui)
)
ki18n_wrap_ui(adblocklibprivate_SRCS widgets/adblockcreatefilterwidget.ui widgets/settings_adblock.ui)
add_library(adblocklibprivate ${adblocklibprivate_SRCS})
generate_export_header(adblocklibprivate BASE_NAME adblocklib)
target_link_libraries(adblocklibprivate
PRIVATE
PRIVATE
Qt5::Core
Qt5::WebEngine
Qt5::WebEngineWidgets
......@@ -32,15 +40,20 @@ PRIVATE
KF5::ItemViews
KF5::ConfigCore
KF5::PimCommon
KF5::MessageViewer
KF5::KIOWidgets
KF5::WebEngineViewer
)
KF5::TextWidgets
KF5::PimTextEdit
KF5::Libkdepim
)
set_target_properties(adblocklibprivate
PROPERTIES VERSION ${KDEPIMADDONS_LIB_VERSION} SOVERSION ${KDEPIMADDONS_LIB_SOVERSION}
)
)
install(TARGETS adblocklibprivate ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} LIBRARY NAMELINK_SKIP)
add_subdirectory(autotests)
if(BUILD_TESTING)
add_subdirectory(autotests)
add_subdirectory(tests)
endif()
......@@ -17,7 +17,7 @@
#include "adblockpluginurlinterceptorconfigurewidgettest.h"
#include "../widgets/adblockpluginurlinterceptorconfigurewidget.h"
#include <AdBlockSettingWidget>
#include "../widgets/adblocksettingwidget.h"
#include <QTest>
AdblockPluginUrlInterceptorConfigureWidgetTest::AdblockPluginUrlInterceptorConfigureWidgetTest(QObject *parent)
......@@ -35,7 +35,7 @@ void AdblockPluginUrlInterceptorConfigureWidgetTest::shouldHaveDefaultValue()
{
AdBlock::AdblockPluginUrlInterceptorConfigureWidget w;
MessageViewer::AdBlockSettingWidget *configurewidget = w.findChild<MessageViewer::AdBlockSettingWidget *>(QStringLiteral("configurewidget"));
AdBlock::AdBlockSettingWidget *configurewidget = w.findChild<AdBlock::AdBlockSettingWidget *>(QStringLiteral("configurewidget"));
QVERIFY(configurewidget);
}
......
set(adblocksettings_gui_SRCS adblocksettings_gui.cpp)
add_executable(adblocksettings_gui ${adblocksettings_gui_SRCS})
target_link_libraries(adblocksettings_gui
adblocklibprivate
KF5::ItemViews
KF5::I18n
KF5::CoreAddons
)
set(adblocksettingsdialog_gui_SRCS adblocksettingsdialog_gui.cpp)
add_executable(adblocksettingsdialog_gui ${adblocksettingsdialog_gui_SRCS})
target_link_libraries(adblocksettingsdialog_gui
adblocklibprivate
KF5::ItemViews
KF5::I18n
KF5::CoreAddons
)
set(adblockautomaticruleslistwidget_gui_SRCS adblockautomaticruleslistwidget_gui.cpp)
add_executable(adblockautomaticruleslistwidget_gui ${adblockautomaticruleslistwidget_gui_SRCS})
target_link_libraries(adblockautomaticruleslistwidget_gui
adblocklibprivate
KF5::ItemViews
KF5::I18n
KF5::CoreAddons
)
/*
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_gui.h"
#include "../widgets/adblockautomaticruleslistwidget.h"
#include <KAboutData>
#include <KLocalizedString>
#include <QCommandLineParser>
#include <QHBoxLayout>
#include <QApplication>
#include <QStandardPaths>
#include <QFileDialog>
AdBlockAutomaticRulesListWidgetTest::AdBlockAutomaticRulesListWidgetTest(const QString &fileName, QWidget *parent)
: QWidget(parent)
{
QVBoxLayout *lay = new QVBoxLayout(this);
QFile localFile(fileName);
QString adblockList;
if (localFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
adblockList = QString::fromLatin1(localFile.readAll());
}
AdBlock::AdBlockAutomaticRulesListWidget *list = new AdBlock::AdBlockAutomaticRulesListWidget(this);
list->setRules(adblockList);
lay->addWidget(list);
}
AdBlockAutomaticRulesListWidgetTest::~AdBlockAutomaticRulesListWidgetTest()
{
}
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QStandardPaths::setTestModeEnabled(true);
KAboutData aboutData(QStringLiteral("AdBlockAutomaticRulesListWidget_gui"), i18n("AdBlockAutomaticRulesListWidget_Gui"), QStringLiteral("1.0"));
aboutData.setShortDescription(i18n("Test for AdBlockAutomaticRulesListWidget"));
QCommandLineParser parser;
KAboutData::setApplicationData(aboutData);
parser.addVersionOption();
parser.addHelpOption();
parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("+[url]"), i18n("URL of adblock file list")));
aboutData.setupCommandLine(&parser);
parser.process(app);
aboutData.processCommandLine(&parser);
QString fileName;
if (parser.positionalArguments().count()) {
fileName = parser.positionalArguments().at(0);
} else {
fileName = QFileDialog::getOpenFileName(0, QString(), QString(), i18n("Adblock File (*)"));
}
if (fileName.isEmpty()) {
return 0;
}
AdBlockAutomaticRulesListWidgetTest *w = new AdBlockAutomaticRulesListWidgetTest(fileName);
w->resize(800, 600);
w->show();
app.exec();
delete w;
return 0;
}
/*
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 TEST_ADBLOCKAUTOMATICRULESLISTWIDGET_GUI_H
#define TEST_ADBLOCKAUTOMATICRULESLISTWIDGET_GUI_H
#include <QWidget>
class AdBlockAutomaticRulesListWidgetTest : public QWidget
{
Q_OBJECT
public:
explicit AdBlockAutomaticRulesListWidgetTest(const QString &fileName, QWidget *parent = Q_NULLPTR);
~AdBlockAutomaticRulesListWidgetTest();
};
#endif
/*
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 <QApplication>
#include <KAboutData>
#include <KLocalizedString>
#include <QCommandLineParser>
#include <QStandardPaths>
#include "../widgets/adblocksettingwidget.h"
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QStandardPaths::setTestModeEnabled(true);
KAboutData aboutData(QStringLiteral("adblocksettings_gui"), i18n("adblocksettingstest_Gui"), QStringLiteral("1.0"));
aboutData.setShortDescription(i18n("Test for adblocksettings"));
QCommandLineParser parser;
KAboutData::setApplicationData(aboutData);
parser.addVersionOption();
parser.addHelpOption();
aboutData.setupCommandLine(&parser);
parser.process(app);
aboutData.processCommandLine(&parser);
AdBlock::AdBlockSettingWidget *w = new AdBlock::AdBlockSettingWidget;
w->show();
return app.exec();
}
/*
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 <QDialog>
#include <QApplication>
#include <KAboutData>
#include <QVBoxLayout>
#include <QPushButton>
#include <KLocalizedString>
#include <QCommandLineParser>
#include <QDialogButtonBox>
#include <QStandardPaths>
#include "../widgets/adblocksettingwidget.h"
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QStandardPaths::setTestModeEnabled(true);
KAboutData aboutData(QStringLiteral("adblocksettings_gui"), i18n("adblocksettingstest_Gui"), QStringLiteral("1.0"));
aboutData.setShortDescription(i18n("Test for adblocksettings"));
QCommandLineParser parser;
KAboutData::setApplicationData(aboutData);
parser.addVersionOption();
parser.addHelpOption();
aboutData.setupCommandLine(&parser);
parser.process(app);
aboutData.processCommandLine(&parser);
AdBlock::AdBlockSettingWidget *w = new AdBlock::AdBlockSettingWidget;
QDialog dlg;
QVBoxLayout *layout = new QVBoxLayout;
dlg.setLayout(layout);
layout->addWidget(w);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
okButton->setDefault(true);
okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
QObject::connect(buttonBox, &QDialogButtonBox::accepted, &dlg, &QDialog::accept);
QObject::connect(buttonBox, &QDialogButtonBox::rejected, &dlg, &QDialog::reject);
layout->addWidget(buttonBox);
w->doLoadFromGlobalSettings();
if (dlg.exec()) {
w->save();
}
return 0;
}
/*
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 AdBlock;
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(AdBlock::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 AdBlock
{
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 AdBlock;
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;
}