From 2c88c38a05c6c426792531fc928bc5a3e526b29d Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Mon, 17 Feb 2020 21:16:03 +0200 Subject: staging/adblock: add AdblockPlusPlugin --- staging/adblock/AdblockPlusPlugin.json | 4 ++++ staging/adblock/meson.build | 13 +++++++++++++ staging/adblock/plugin.cpp | 29 +++++++++++++++++++++++++++++ staging/adblock/plugin.h | 25 +++++++++++++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 staging/adblock/AdblockPlusPlugin.json create mode 100644 staging/adblock/plugin.cpp create mode 100644 staging/adblock/plugin.h diff --git a/staging/adblock/AdblockPlusPlugin.json b/staging/adblock/AdblockPlusPlugin.json new file mode 100644 index 0000000..053826a --- /dev/null +++ b/staging/adblock/AdblockPlusPlugin.json @@ -0,0 +1,4 @@ +{ + "name": "AdblockPlus Filter Plugin", + "author": "Aqua " +} diff --git a/staging/adblock/meson.build b/staging/adblock/meson.build index f797607..1b992e5 100644 --- a/staging/adblock/meson.build +++ b/staging/adblock/meson.build @@ -7,6 +7,19 @@ dep_adblockfilter = declare_dependency( ) ) +AdblockPlusFilterPlugin = shared_library('AdblockPlusPlugin', + [ 'plugin.cpp', + mod_qt5.preprocess( + include_directories: plugininterface_include, + moc_headers: 'plugin.h', + dependencies: [ dep_qt5 ] + ) + ], + dependencies: [ dep_qt5, dep_plugininterface, dep_adblockfilter ], + install: true, + install_dir: get_option('libdir')/'smolbote/plugins' +) + test('adblockfilter: parser', executable('adblockfilter-parsefilter', dependencies: [ dep_qt5, dep_gtest, dep_adblockfilter ], sources: [ 'test/parser.cpp' ] diff --git a/staging/adblock/plugin.cpp b/staging/adblock/plugin.cpp new file mode 100644 index 0000000..b4f1b56 --- /dev/null +++ b/staging/adblock/plugin.cpp @@ -0,0 +1,29 @@ +/* + * This file is part of smolbote. It's copyrighted by the contributors recorded + * in the version control history of the file, available from its original + * location: https://library.iserlohn-fortress.net/aqua/smolbote.git + * + * SPDX-License-Identifier: GPL-3.0 + */ + +#include "plugin.h" +#include "filterlist.h" +#include + +Filter* AdblockPlusFilterPlugin::load(QIODevice* from) const +{ + if(!from->isOpen()) + return nullptr; + + QTextStream stream(from); + auto *list = new AdblockPlus::FilterList; + const auto result = list->parse(stream); + + if(result.state != AdblockPlus::FilterList::Ok) { + delete list; + list = nullptr; + } + + return list; +} + diff --git a/staging/adblock/plugin.h b/staging/adblock/plugin.h new file mode 100644 index 0000000..1ca51aa --- /dev/null +++ b/staging/adblock/plugin.h @@ -0,0 +1,25 @@ +/* + * This file is part of smolbote. It's copyrighted by the contributors recorded + * in the version control history of the file, available from its original + * location: https://library.iserlohn-fortress.net/aqua/smolbote.git + * + * SPDX-License-Identifier: GPL-3.0 + */ + +#ifndef ADBLOCKPLUSFILTER_PLUGIN_H +#define ADBLOCKPLUSFILTER_PLUGIN_H + +#include + +class AdblockPlusFilterPlugin : public QObject, public FilterPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID FilterPluginIid FILE "AdblockPlusPlugin.json") + Q_INTERFACES(FilterPlugin) + +public: + Filter* load(QIODevice* from) const override; +}; + +#endif // ADBLOCKPLUSFILTER_PLUGIN_H + -- cgit v1.2.1