aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2020-02-17 21:16:03 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2020-04-21 20:14:55 +0300
commit2c88c38a05c6c426792531fc928bc5a3e526b29d (patch)
tree711e11ceeca37a0ab109b66f7c140d195550e7cb
parentstaging/adblock: implement FilterList::isUpToDate (diff)
downloadsmolbote-2c88c38a05c6c426792531fc928bc5a3e526b29d.tar.xz
staging/adblock: add AdblockPlusPlugin
-rw-r--r--staging/adblock/AdblockPlusPlugin.json4
-rw-r--r--staging/adblock/meson.build13
-rw-r--r--staging/adblock/plugin.cpp29
-rw-r--r--staging/adblock/plugin.h25
4 files changed, 71 insertions, 0 deletions
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 <aqua@iserlohn-fortress.net>"
+}
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 <QTextStream>
+
+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 <filterinterface.h>
+
+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
+