aboutsummaryrefslogtreecommitdiff
path: root/src
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 /src
parentMinor fixes (diff)
downloadsmolbote-037b039bfbfeda2e9b7ebef7e38616575411c876.tar.xz
Initial plugins testing
Diffstat (limited to 'src')
-rw-r--r--src/browser.cpp17
-rw-r--r--src/browser.h4
-rw-r--r--src/mainwindow.cpp23
-rw-r--r--src/mainwindow.h2
4 files changed, 44 insertions, 2 deletions
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();