aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-05-15 14:26:47 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-05-15 14:26:47 +0200
commite412f035b054612d00fdbc39e13a958cf5492fec (patch)
tree438b806b4d1a53be6761dc91acedc988e489de01 /src
parentSet download tooltip image preview width to 400 (diff)
downloadsmolbote-e412f035b054612d00fdbc39e13a958cf5492fec.tar.xz
Profile editor plugin
Diffstat (limited to 'src')
-rw-r--r--src/browser.cpp35
-rw-r--r--src/browser.h2
2 files changed, 37 insertions, 0 deletions
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