aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-01-14 20:34:50 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2018-01-14 20:34:50 +0100
commit037b039bfbfeda2e9b7ebef7e38616575411c876 (patch)
tree6767f8edc0860b60b590dc30a37319a7c1c66a0d
parentMinor fixes (diff)
downloadsmolbote-037b039bfbfeda2e9b7ebef7e38616575411c876.tar.xz
Initial plugins testing
-rw-r--r--CMakeLists.txt9
-rw-r--r--plugins/ProfileEditor/CMakeLists.txt18
-rw-r--r--plugins/ProfileEditor/ProfileEditor.json5
-rw-r--r--plugins/ProfileEditor/profileeditorplugin.cpp27
-rw-r--r--plugins/ProfileEditor/profileeditorplugin.h29
-rw-r--r--plugins/interfaces.h39
-rw-r--r--src/browser.cpp17
-rw-r--r--src/browser.h4
-rw-r--r--src/mainwindow.cpp23
-rw-r--r--src/mainwindow.h2
10 files changed, 170 insertions, 3 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 12afb57..7cb59e2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -48,6 +48,8 @@ add_subdirectory(lib/bookmarks)
add_subdirectory(lib/downloads)
add_subdirectory(lib/navigation)
+add_subdirectory(plugins/ProfileEditor)
+
# configure a header file to pass version information
# if you don't have git, or are building this off the source tarball, define versions in version.h.in
execute_process(COMMAND "git" "describe" WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} OUTPUT_VARIABLE GitDescribe OUTPUT_STRIP_TRAILING_WHITESPACE)
@@ -102,11 +104,16 @@ set(SourceCode
"src/forms/cookiesform.cpp"
"src/forms/cookiesform.h"
"src/forms/cookiesform.ui"
+
+ # plugin interfaces
+ plugins/interfaces.h
)
add_executable(poi ${SourceCode})
-target_include_directories(poi PRIVATE src lib)
+target_include_directories(poi
+ PRIVATE src lib
+ PRIVATE plugins)
target_link_libraries(poi Qt5::Core Qt5::Widgets Qt5::Concurrent Qt5::WebEngineWidgets)
target_link_libraries(poi configuration)
diff --git a/plugins/ProfileEditor/CMakeLists.txt b/plugins/ProfileEditor/CMakeLists.txt
new file mode 100644
index 0000000..3eaa0f5
--- /dev/null
+++ b/plugins/ProfileEditor/CMakeLists.txt
@@ -0,0 +1,18 @@
+cmake_minimum_required(VERSION 3.1.0)
+
+find_package(Qt5Core REQUIRED)
+find_package(Qt5Widgets REQUIRED)
+find_package(Qt5WebEngineWidgets REQUIRED)
+
+set(CMAKE_AUTOMOC ON)
+
+add_library(ProfileEditorPlugin SHARED
+ profileeditorplugin.cpp
+ profileeditorplugin.h)
+
+target_include_directories(ProfileEditorPlugin
+ PUBLIC ..)
+
+target_link_libraries(ProfileEditorPlugin
+ PRIVATE Qt5::Widgets
+ PRIVATE Qt5::WebEngineWidgets)
diff --git a/plugins/ProfileEditor/ProfileEditor.json b/plugins/ProfileEditor/ProfileEditor.json
new file mode 100644
index 0000000..e371eee
--- /dev/null
+++ b/plugins/ProfileEditor/ProfileEditor.json
@@ -0,0 +1,5 @@
+{
+ "name": "Profile Editor",
+ "shortcut": "Ctrl+F2",
+ "author": "Aqua-sama <aqua@iserlohn-fortress.net"
+}
diff --git a/plugins/ProfileEditor/profileeditorplugin.cpp b/plugins/ProfileEditor/profileeditorplugin.cpp
new file mode 100644
index 0000000..1f4f16e
--- /dev/null
+++ b/plugins/ProfileEditor/profileeditorplugin.cpp
@@ -0,0 +1,27 @@
+/*
+ * 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: git://neueland.iserlohn-fortress.net/smolbote.git
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#include "profileeditorplugin.h"
+#include <QLabel>
+#include <QVBoxLayout>
+
+QWidget *ProfileEditorPlugin::createWidget(QWebEngineProfile *profile, QWidget *parent)
+{
+ QWidget *widget = new QWidget(parent);
+ widget->setWindowFlags(Qt::ToolTip);
+ widget->setVisible(false);
+ auto *layout = new QVBoxLayout(widget);
+ widget->setLayout(layout);
+
+ QLabel *storageName_label = new QLabel(profile->storageName(), widget);
+ if(storageName_label->text().isEmpty())
+ storageName_label->setText(tr("Off-the-record"));
+ layout->addWidget(storageName_label);
+
+ return widget;
+}
diff --git a/plugins/ProfileEditor/profileeditorplugin.h b/plugins/ProfileEditor/profileeditorplugin.h
new file mode 100644
index 0000000..3115ab2
--- /dev/null
+++ b/plugins/ProfileEditor/profileeditorplugin.h
@@ -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: git://neueland.iserlohn-fortress.net/smolbote.git
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#ifndef PROFILEEDITORPLUGIN_H
+#define PROFILEEDITORPLUGIN_H
+
+#include <QWebEngineProfile>
+#include <QWidget>
+#include <interfaces.h>
+
+class ProfileEditorPlugin : public QObject, public PluginInterface, public ProfileInterface
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID ProfileInterfaceIid FILE "ProfileEditor.json")
+ Q_INTERFACES(PluginInterface ProfileInterface)
+
+public:
+ // PluginInterface
+
+ // ProfileInterface
+ QWidget *createWidget(QWebEngineProfile *profile, QWidget *parent) override;
+};
+
+#endif //PROFILEEDITORPLUGIN_H
diff --git a/plugins/interfaces.h b/plugins/interfaces.h
new file mode 100644
index 0000000..a43964a
--- /dev/null
+++ b/plugins/interfaces.h
@@ -0,0 +1,39 @@
+/*
+ * 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: git://neueland.iserlohn-fortress.net/smolbote.git
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef INTERFACES_H
+#define INTERFACES_H
+
+#include <QtPlugin>
+
+class QString;
+class QAction;
+class QWidget;
+class QWebEngineProfile;
+
+class PluginInterface
+{
+public:
+ virtual ~PluginInterface() = default;
+};
+
+class ProfileInterface
+{
+public:
+ virtual ~ProfileInterface() = default;
+
+ virtual QWidget *createWidget(QWebEngineProfile *profile, QWidget *parent) = 0;
+};
+
+#define PluginInterfaceIid "net.iserlohn-fortress.smolbote.PluginInterface"
+Q_DECLARE_INTERFACE(PluginInterface, PluginInterfaceIid)
+
+#define ProfileInterfaceIid "net.iserlohn-fortress.smolbote.ProfileInterface"
+Q_DECLARE_INTERFACE(ProfileInterface, ProfileInterfaceIid)
+
+#endif //INTERFACES_H
diff --git a/src/browser.cpp b/src/browser.cpp
index 8b7f40f..542465b 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -13,6 +13,9 @@
#include <bookmarks/bookmarkswidget.h>
#include <downloads/downloadswidget.h>
+#include <QPluginLoader>
+#include <QtPlugin>
+
Browser::Browser(int &argc, char *argv[])
: SingleApplication(argc, argv)
{
@@ -34,12 +37,25 @@ Browser::~Browser()
}
qDebug("Waiting for threads to wind down: %s", QThreadPool::globalInstance()->waitForDone() ? "done" : "failed");
+
+ qDeleteAll(m_plugins);
}
void Browser::setConfiguration(std::shared_ptr<Configuration> &config)
{
m_config = config;
+ // plugin loader
+ QPluginLoader loader("plugins/ProfileEditor/libProfileEditorPlugin.so");
+ qDebug("Trying to load %s: %s", qUtf8Printable(loader.fileName()), loader.load() ? "ok" : "failed");
+ if(!loader.isLoaded()) {
+ qDebug("Error: %s", qUtf8Printable(loader.errorString()));
+ } else {
+ PluginInterface *plugin = qobject_cast<PluginInterface *>(loader.instance());
+ m_plugins.append(plugin);
+ //qDebug("author: %s", qUtf8Printable(loader.metaData()["MetaData"].toObject()["author"].toString()));
+ }
+
m_bookmarksManager = std::make_shared<BookmarksWidget>(QString::fromStdString(m_config->value<std::string>("bookmarks.path").value()));
m_downloadManager = std::make_shared<DownloadsWidget>(QString::fromStdString(m_config->value<std::string>("downloads.path").value()));
@@ -57,6 +73,7 @@ MainWindow *Browser::createWindow()
window->setBookmarksWidget(m_bookmarksManager);
window->setDownloadsWidget(m_downloadManager);
window->setProfile(m_defaultProfile);
+ window->addPlugins(m_plugins);
m_windows.append(window);
diff --git a/src/browser.h b/src/browser.h
index 9649948..236b0fb 100644
--- a/src/browser.h
+++ b/src/browser.h
@@ -15,6 +15,7 @@
#include <QVector>
#include <memory>
#include "webengine/cookieinterceptor.h"
+#include <interfaces.h>
class MainWindow;
class BookmarksWidget;
@@ -26,7 +27,7 @@ class Browser : public SingleApplication
public:
explicit Browser(int &argc, char *argv[]);
- ~Browser();
+ ~Browser() final;
Q_DISABLE_COPY(Browser)
void setConfiguration(std::shared_ptr<Configuration> &config);
@@ -43,6 +44,7 @@ private:
std::shared_ptr<Configuration> m_config;
QVector<MainWindow *> m_windows;
+ QVector<PluginInterface *> m_plugins;
QHash<QString, std::shared_ptr<WebEngineProfile>> m_profiles;
std::shared_ptr<WebEngineProfile> m_defaultProfile;
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index f57cab9..913885d 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -17,7 +17,6 @@
#include <bookmarks/bookmarkswidget.h>
#include <downloads/downloadswidget.h>
#include <navigation/urllineedit.h>
-#include <settings/configuration.h>
#include <settings/settingsdialog.h>
MainWindow::MainWindow(std::shared_ptr<Configuration> config, QWidget *parent)
@@ -308,3 +307,25 @@ void MainWindow::handleTitleUpdated(const QString &title)
setWindowTitle(t);
//setWindowTitle(browser->settings()->value("window.title").toString().replace("title", title).replace("profile", tabBar->profile()->name()));
}
+
+void MainWindow::addPlugins(QVector<PluginInterface *> &plugins) {
+ for(PluginInterface *plugin : plugins) {
+ ProfileInterface *profilePlugin = dynamic_cast<ProfileInterface *>(plugin);
+ QWidget *w = profilePlugin->createWidget(m_profile.get(), this);
+
+ QAction *profileAction = new QAction(this);
+ profileAction->setText("Profile Action");
+ ui->navigationToolBar->addAction(profileAction);
+ connect(profileAction, &QAction::triggered, this, [this, w]() {
+ w->setVisible(!w->isVisible());
+ if(w->isVisible()) {
+ w->adjustSize();
+ QPoint pos = ui->navigationToolBar->pos();
+ pos.setX(pos.x() + ui->navigationToolBar->width() - w->width());
+ pos.setY(pos.y() + ui->navigationToolBar->height());
+ w->move(mapToGlobal(pos));
+ w->show();
+ }
+ });
+ }
+}
diff --git a/src/mainwindow.h b/src/mainwindow.h
index c83778e..6d1e190 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -16,6 +16,7 @@
#include <QMainWindow>
#include <QUrl>
#include <memory>
+#include <interfaces.h>
namespace Ui
{
@@ -59,6 +60,7 @@ public slots:
void setBookmarksWidget(std::shared_ptr<BookmarksWidget> &widget);
void setDownloadsWidget(std::shared_ptr<DownloadsWidget> &widget);
+ void addPlugins(QVector<PluginInterface *> &plugins);
void toggleFullscreen();