diff options
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | plugins/ProfileEditor/forms/profileview.ui | 2 | ||||
-rw-r--r-- | plugins/ProfileEditor/profileeditorplugin.cpp | 5 | ||||
-rw-r--r-- | plugins/ProfileEditor/profileeditorplugin.h | 10 | ||||
-rw-r--r-- | plugins/interfaces.h | 10 | ||||
-rw-r--r-- | src/browser.cpp | 35 | ||||
-rw-r--r-- | src/browser.h | 2 |
7 files changed, 54 insertions, 12 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 856051b..c248210 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,7 +60,7 @@ add_subdirectory(lib/bookmarks) add_subdirectory(lib/downloads) add_subdirectory(lib/configuration) -#add_subdirectory(plugins/ProfileEditor) +add_subdirectory(plugins/ProfileEditor) # browser source code add_subdirectory(src) diff --git a/plugins/ProfileEditor/forms/profileview.ui b/plugins/ProfileEditor/forms/profileview.ui index 2e43bae..b55bda8 100644 --- a/plugins/ProfileEditor/forms/profileview.ui +++ b/plugins/ProfileEditor/forms/profileview.ui @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>ProfileView</class> - <widget class="QWidget" name="ProfileView"> + <widget class="QDialog" name="ProfileView"> <property name="geometry"> <rect> <x>0</x> diff --git a/plugins/ProfileEditor/profileeditorplugin.cpp b/plugins/ProfileEditor/profileeditorplugin.cpp index d048875..7a92e51 100644 --- a/plugins/ProfileEditor/profileeditorplugin.cpp +++ b/plugins/ProfileEditor/profileeditorplugin.cpp @@ -9,10 +9,9 @@ #include "profileeditorplugin.h" #include "forms/profileview.h" -QWidget *ProfileEditorPlugin::createWidget(QWebEngineProfile *profile, QWidget *parent) +QDialog *ProfileEditorPlugin::createWidget(QWebEngineProfile *profile, QWidget *parent) { auto *widget = new ProfileView(profile, parent); - widget->setWindowFlags(Qt::ToolTip); - widget->setVisible(false); + widget->setAttribute(Qt::WA_DeleteOnClose, true); return widget; } diff --git a/plugins/ProfileEditor/profileeditorplugin.h b/plugins/ProfileEditor/profileeditorplugin.h index 3999aba..899c51a 100644 --- a/plugins/ProfileEditor/profileeditorplugin.h +++ b/plugins/ProfileEditor/profileeditorplugin.h @@ -6,13 +6,13 @@ * SPDX-License-Identifier: GPL-3.0 */ -#ifndef PROFILEEDITORPLUGIN_H -#define PROFILEEDITORPLUGIN_H +#ifndef PROFILEEDITOR_PLUGIN_H +#define PROFILEEDITOR_PLUGIN_H #include <interfaces.h> class QWebEngineProfile; -class QWidget; +class QDialog; class ProfileEditorPlugin : public QObject, public PluginInterface, public ProfileInterface { Q_OBJECT @@ -23,7 +23,7 @@ public: // PluginInterface // ProfileInterface - QWidget *createWidget(QWebEngineProfile *profile, QWidget *parent) override; + QDialog *createWidget(QWebEngineProfile *profile, QWidget *parent) override; }; -#endif //PROFILEEDITORPLUGIN_H +#endif //PROFILEEDITOR_PLUGIN_H diff --git a/plugins/interfaces.h b/plugins/interfaces.h index 3bec574..46cf24a 100644 --- a/plugins/interfaces.h +++ b/plugins/interfaces.h @@ -10,12 +10,18 @@ #define INTERFACES_H #include <QtPlugin> +#include <memory> class QString; class QAction; -class QWidget; +class QDialog; class QWebEngineProfile; +struct Plugin +{ + std::shared_ptr<QObject> instance; +}; + class PluginInterface { public: @@ -27,7 +33,7 @@ class ProfileInterface public: virtual ~ProfileInterface() = default; - virtual QWidget *createWidget(QWebEngineProfile *profile, QWidget *parent) = 0; + virtual QDialog *createWidget(QWebEngineProfile *profile, QWidget *parent) = 0; }; #define PluginInterfaceIid "net.iserlohn-fortress.smolbote.PluginInterface" diff --git a/src/browser.cpp b/src/browser.cpp index 222174c..790abcb 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -17,6 +17,8 @@ #include <configuration/configuration.h> #include <downloads/downloadswidget.h> #include <version.h> +#include <QDir> +#include <QPluginLoader> Browser::Browser(int &argc, char *argv[]) : SingleApplication(argc, argv) @@ -30,8 +32,12 @@ Browser::~Browser() { if(m_bookmarks) m_bookmarks->save(); + qDeleteAll(m_windows); m_windows.clear(); + + //qDeleteAll(m_plugins); + m_plugins.clear(); } void Browser::setConfiguration(std::shared_ptr<Configuration> &config) @@ -44,6 +50,23 @@ void Browser::setup(const QString &defaultProfile) { Q_ASSERT_X(m_config, "Browser::setup", "Configuration not set"); + // plugins + QDir pluginsDir(QString::fromStdString(m_config->value<std::string>("plugins.path").value())); + if(pluginsDir.exists()) { + const QStringList entries = pluginsDir.entryList(QDir::Files | QDir::Readable); + for(const QString &name : entries) { + QPluginLoader loader(pluginsDir.absoluteFilePath(name)); + qDebug("Loading plugin %s: %s", qUtf8Printable(name), loader.load() ? "ok" : "failed"); + if(!loader.isLoaded()) { + qDebug("Error: %s", qUtf8Printable(loader.errorString())); + } else { + Plugin p; + p.instance = std::shared_ptr<QObject>(loader.instance()); + m_plugins.append(p); + } + } + } + // url request filter m_urlFilter = std::make_shared<UrlRequestInterceptor>(QString::fromStdString(m_config->value<std::string>("filter.path").value())); @@ -127,6 +150,18 @@ MainWindow *Browser::createWindow() }); window->addAction(MainWindow::ToolsMenu, downloadsAction); + for(Plugin p : m_plugins) { + auto *profileEditor = qobject_cast<ProfileInterface *>(p.instance.get()); + if(profileEditor) { + auto *profileAction = new QAction(tr("Profile"), window); + connect(profileAction, &QAction::triggered, window, [profileEditor]() { + //window->currentSubWindow() + profileEditor->createWidget(WebProfile::defaultProfile(), nullptr)->show(); + }); + window->addAction(MainWindow::ToolsMenu, profileAction); + } + } + m_windows.append(window); connect(window, &MainWindow::destroyed, this, [this, window]() { m_windows.removeOne(window); diff --git a/src/browser.h b/src/browser.h index c8e906d..3052279 100644 --- a/src/browser.h +++ b/src/browser.h @@ -13,6 +13,7 @@ #include <QJsonObject> #include <QVector> #include <memory> +#include <interfaces.h> class Configuration; class BookmarksWidget; @@ -42,6 +43,7 @@ private: std::shared_ptr<UrlRequestInterceptor> m_urlFilter; QVector<MainWindow *> m_windows; + QVector<Plugin> m_plugins; }; #endif // SMOLBOTE_BROWSER_H |