summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/CMakeLists.txt7
-rw-r--r--src/plugins/pluginloader.cpp17
-rw-r--r--src/plugins/pluginloader.h25
-rw-r--r--src/plugins/rplugininterface.hpp23
-rw-r--r--src/plugins/rview.hpp25
-rw-r--r--src/plugins/test/pluginloader.cpp40
6 files changed, 137 insertions, 0 deletions
diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt
new file mode 100644
index 00000000..01b13ae1
--- /dev/null
+++ b/src/plugins/CMakeLists.txt
@@ -0,0 +1,7 @@
+add_library(pluginloader STATIC pluginloader.cpp pluginloader.h)
+target_link_libraries(pluginloader PUBLIC Qt6::Core Qt6::Widgets)
+
+if(TESTING)
+ add_executable(load_plugin test/pluginloader.cpp)
+ target_link_libraries(load_plugin GTest::gtest GTest::gtest_main Qt6::Core)
+endif()
diff --git a/src/plugins/pluginloader.cpp b/src/plugins/pluginloader.cpp
new file mode 100644
index 00000000..ad5dbc14
--- /dev/null
+++ b/src/plugins/pluginloader.cpp
@@ -0,0 +1,17 @@
+/* ============================================================
+ * The rekonq project
+ * ============================================================
+ * SPDX-License-Identifier: GPL-3.0-only
+ * Copyright (C) 2022 aqua <aqua@iserlohn-fortress.net>
+ * ============================================================
+ * Description: rekonq plugin loader
+ * ============================================================ */
+
+#include "pluginloader.h"
+#include <QJsonArray>
+
+PluginLoader::PluginLoader(const QString &fileName, QObject *parent) : QPluginLoader(fileName, parent)
+{
+ const auto metadata = metaData()["MetaData"].toObject();
+ for (const auto &value : metadata["schemes"].toArray()) { m_schemes.append(value.toString()); }
+}
diff --git a/src/plugins/pluginloader.h b/src/plugins/pluginloader.h
new file mode 100644
index 00000000..f764da9f
--- /dev/null
+++ b/src/plugins/pluginloader.h
@@ -0,0 +1,25 @@
+/* ============================================================
+ * The rekonq project
+ * ============================================================
+ * SPDX-License-Identifier: GPL-3.0-only
+ * Copyright (C) 2022 aqua <aqua@iserlohn-fortress.net>
+ * ============================================================
+ * Description: rekonq plugin loader
+ * ============================================================ */
+
+#pragma once
+
+#include "rplugininterface.hpp"
+#include <QPluginLoader>
+
+class PluginLoader : public QPluginLoader {
+
+public:
+ explicit PluginLoader(const QString &path, QObject *parent = nullptr);
+ [[nodiscard]] bool hasScheme(const QString &scheme) { return m_schemes.contains(scheme); }
+
+ [[nodiscard]] RekonqPluginInterface *interface() { return qobject_cast<RekonqPluginInterface *>(instance()); }
+
+private:
+ QStringList m_schemes;
+};
diff --git a/src/plugins/rplugininterface.hpp b/src/plugins/rplugininterface.hpp
new file mode 100644
index 00000000..16186591
--- /dev/null
+++ b/src/plugins/rplugininterface.hpp
@@ -0,0 +1,23 @@
+/* ============================================================
+ * The rekonq project
+ * ============================================================
+ * SPDX-License-Identifier: GPL-3.0-only
+ * Copyright (C) 2022 aqua <aqua@iserlohn-fortress.net>
+ * ============================================================
+ * Description: rekonq plugin interface
+ * ============================================================ */
+
+#pragma once
+
+#include "rview.hpp"
+#include <QtPlugin>
+
+class RekonqPluginInterface : public QObject {
+ Q_OBJECT
+
+public:
+ virtual rView *view(const QUrl &url) = 0;
+};
+
+#define RekonqPluginInterface_iid "rekonq.3.RekongPluginInterface"
+Q_DECLARE_INTERFACE(RekonqPluginInterface, RekonqPluginInterface_iid)
diff --git a/src/plugins/rview.hpp b/src/plugins/rview.hpp
new file mode 100644
index 00000000..71bf5ddf
--- /dev/null
+++ b/src/plugins/rview.hpp
@@ -0,0 +1,25 @@
+/* ============================================================
+ * The rekonq project
+ * ============================================================
+ * SPDX-License-Identifier: GPL-3.0-only
+ * Copyright (C) 2022 aqua <aqua@iserlohn-fortress.net>
+ * ============================================================
+ * Description: View Interface
+ * ============================================================ */
+
+#pragma once
+
+#include <QUrl>
+#include <QWidget>
+
+class rView : public QWidget {
+ Q_OBJECT
+
+public:
+ explicit rView(const QUrl &url = QUrl(), QWidget *parent = nullptr) : QWidget(parent) {}
+
+signals:
+ void iconChanged(const QIcon &);
+ void urlChanged(const QUrl &);
+ void titleChanged(const QString &);
+};
diff --git a/src/plugins/test/pluginloader.cpp b/src/plugins/test/pluginloader.cpp
new file mode 100644
index 00000000..83b30c40
--- /dev/null
+++ b/src/plugins/test/pluginloader.cpp
@@ -0,0 +1,40 @@
+#include <QJsonArray>
+#include <QPluginLoader>
+#include <gtest/gtest.h>
+#include <iostream>
+
+char *pluginPath;
+
+class PluginLoaderTest : public ::testing::Test {
+
+protected:
+ void SetUp() override { loader = new QPluginLoader; }
+ void TearDown() override { delete loader; }
+
+ QPluginLoader *loader = nullptr;
+};
+
+TEST_F(PluginLoaderTest, InterfaceTest)
+{
+ // Ensure plugin loads
+ loader->setFileName(pluginPath);
+ EXPECT_TRUE(loader->load()) << "For plugin: " << pluginPath << '\n' << qUtf8Printable(loader->errorString());
+
+ // Ensure plugin has metadata
+ const auto metadata = loader->metaData()["MetaData"].toObject();
+ EXPECT_TRUE(metadata.contains("name"));
+ EXPECT_FALSE(metadata["name"].toString().isEmpty());
+ EXPECT_TRUE(metadata.contains("schemes"));
+ EXPECT_FALSE(metadata["schemes"].toArray().isEmpty());
+}
+
+int main(int argc, char **argv)
+{
+ ::testing::InitGoogleTest(&argc, argv);
+ if (argc != 2) {
+ std::cerr << "Usage: " << argv[0] << " [path to plugin]" << std::endl;
+ return -1;
+ }
+ pluginPath = argv[1];
+ return RUN_ALL_TESTS();
+}