aboutsummaryrefslogtreecommitdiff
path: root/src/browser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/browser.cpp')
-rw-r--r--src/browser.cpp79
1 files changed, 60 insertions, 19 deletions
diff --git a/src/browser.cpp b/src/browser.cpp
index 4547e08..7130096 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -24,6 +24,7 @@
#include "webprofile.h"
#include <QAction>
#include <QDir>
+#include <QFileDialog>
#include <QFileInfo>
#include <QFileInfoList>
#include <QJsonArray>
@@ -47,6 +48,9 @@ Browser::~Browser()
if(m_bookmarks)
m_bookmarks->save();
+ for(auto *info : m_plugins)
+ delete info;
+
qDeleteAll(m_windows);
m_windows.clear();
}
@@ -122,10 +126,30 @@ ProfileManager *Browser::getProfileManager()
return m_profileManager;
}
+QPluginLoader *Browser::addPlugin(const QString &path)
+{
+ if(path.isEmpty())
+ return nullptr;
+
+ auto *loader = new QPluginLoader(path, this);
+ loader->load();
+
+ auto *info = new PluginInfo(loader);
+ m_plugins.append(info);
+
+ for(MainWindow *window : m_windows) {
+ addPluginTo(info, window);
+ }
+
+ return loader;
+}
+
void Browser::setup(QVector<QPluginLoader *> plugins)
{
Q_ASSERT(m_config);
- m_plugins = plugins;
+ for(QPluginLoader *loader : plugins) {
+ m_plugins.append(new PluginInfo(loader));
+ }
auto stylesheet = m_config->value<QString>("browser.stylesheet");
if(stylesheet) {
@@ -242,25 +266,12 @@ MainWindow *Browser::createWindow()
}
});
- for(QPluginLoader *loader : qAsConst(m_plugins)) {
- auto *pluginMenu = window->ui->menuTools->addMenu(loader->metaData().value("MetaData").toObject().value("name").toString());
-
- auto *aboutAction = pluginMenu->addAction(tr("About"));
- connect(aboutAction, &QAction::triggered, this, [loader, window]() {
- auto *dlg = new AboutPluginDialog(loader, window);
- dlg->exec();
- });
-
- auto *runAction = pluginMenu->addAction(tr("Run"));
- runAction->setShortcut(QKeySequence::fromString(loader->metaData().value("MetaData").toObject().value("shortcut").toString()));
+ connect(window->ui->actionAddPlugin, &QAction::triggered, this, [this]() {
+ this->addPlugin(QFileDialog::getOpenFileName(nullptr, tr("Add Plugin"), QDir::homePath(), tr("Plugins (*.so)")));
+ });
- connect(runAction, &QAction::triggered, window, [loader, window]() {
- if(loader->isLoaded()) {
- const auto *interface = qobject_cast<PluginInterface *>(loader->instance());
- Q_CHECK_PTR(interface);
- interface->createWidget(window)->exec();
- }
- });
+ for(auto *info : m_plugins) {
+ addPluginTo(info, window);
}
m_windows.append(window);
@@ -270,3 +281,33 @@ MainWindow *Browser::createWindow()
return window;
}
+
+void Browser::addPluginTo(PluginInfo *info, MainWindow *window)
+{
+ QPluginLoader *loader = info->loader;
+ auto *pluginMenu = window->ui->menuTools->addMenu(loader->metaData().value("MetaData").toObject().value("name").toString());
+ info->menus.append(pluginMenu);
+
+ auto *aboutAction = pluginMenu->addAction(tr("About"));
+ connect(aboutAction, &QAction::triggered, this, [loader, window]() {
+ auto *dlg = new AboutPluginDialog(loader, window);
+ dlg->exec();
+ });
+
+ auto *runAction = pluginMenu->addAction(tr("Run"));
+ runAction->setShortcut(QKeySequence::fromString(loader->metaData().value("MetaData").toObject().value("shortcut").toString()));
+
+ connect(runAction, &QAction::triggered, window, [loader, window]() {
+ if(loader->isLoaded()) {
+ const auto *interface = qobject_cast<PluginInterface *>(loader->instance());
+ Q_CHECK_PTR(interface);
+ interface->createWidget(window)->exec();
+ }
+ });
+
+ auto *removeAction = pluginMenu->addAction(tr("Remove"));
+ connect(removeAction, &QAction::triggered, this, [this, info]() {;
+ m_plugins.removeOne(info);
+ delete info;
+ });
+}