aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt7
-rw-r--r--src/browser.cpp73
-rw-r--r--src/browser.h22
-rw-r--r--src/main.cpp37
-rw-r--r--src/plugin.h42
5 files changed, 84 insertions, 97 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e8f2794..a44a44f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -47,8 +47,10 @@ set(srclist
webengine/webview.cpp
webengine/webview.h
- # plugin interfaces
- plugin.h
+ # interfaces
+ ${PROJECT_SOURCE_DIR}/include/plugininterface.h
+ ${PROJECT_SOURCE_DIR}/include/profileinterface.h
+ ${PROJECT_SOURCE_DIR}/include/browserinterface.h
)
# if you are using a custom build location for breakpad:
@@ -64,6 +66,7 @@ endif()
target_include_directories(${poi_exe}
PRIVATE ${Boost_INCLUDE_DIRS}
+ PRIVATE ${PROJECT_SOURCE_DIR}/include
PRIVATE ${PROJECT_SOURCE_DIR}/lib
PRIVATE ${PROJECT_SOURCE_DIR}/plugins
)
diff --git a/src/browser.cpp b/src/browser.cpp
index 97020bc..0ad1071 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -28,6 +28,8 @@
#include <web/profilemanager.h>
#include <web/webprofile.h>
#include "webengine/filter.h"
+#include <QPluginLoader>
+#include <plugininterface.h>
Browser::Browser(int &argc, char *argv[], bool allowSecondary)
: SingleApplication(argc, argv, allowSecondary, SingleApplication::User | SingleApplication::SecondaryNotification | SingleApplication::ExcludeAppVersion)
@@ -49,23 +51,48 @@ Browser::~Browser()
void Browser::about()
{
auto *dlg = new AboutDialog;
- for(const Plugin &plugin : qAsConst(m_plugins)) {
- dlg->addPlugin(plugin.name, plugin.author, plugin.shortcut.toString());
+ for(const QPluginLoader *loader : qAsConst(m_plugins)) {
+ const auto meta = loader->metaData().value("MetaData").toObject();
+ dlg->addPlugin(meta.value("name").toString(), meta.value("author").toString(), meta.value("shortcut").toString());
}
dlg->exec();
}
-QPair<QString, WebProfile *> Browser::loadProfile(const QString &id)
+const QStringList Browser::configurationOptions() const
+{
+ QStringList options;
+ for(const auto &option : m_config->options()) {
+ options.append(QString::fromStdString(option->long_name()));
+ }
+ return options;
+}
+
+const QString Browser::configuration(const QString& key) const
+{
+ return m_config->value<QString>(qUtf8Printable(key)).value_or(QString());
+}
+
+void Browser::setConfiguration(const QString& key, const QString& value)
+{
+ m_config->setValue(qUtf8Printable(key), value);
+}
+
+const QList<QPair<QString, Profile *>> Browser::profileList() const
+{
+ QList<QPair<QString, Profile *>> profiles;
+ for(const QString &id : m_profileManager->idList()) {
+ profiles.append(qMakePair(id, m_profileManager->profile(id)));
+ }
+ return profiles;
+}
+
+QPair<QString, Profile *> Browser::loadProfile(const QString &id, bool isOffTheRecord)
{
WebProfile *profile = nullptr;
if(QFile::exists(id)) {
- //qDebug("id %s exists", qUtf8Printable(id));
profile = m_profileManager->loadProfile(id);
} else {
- QDir profileDir(m_config->value<QString>("profile.path").value());
- //qDebug("id %s --> %s", qUtf8Printable(id), qUtf8Printable(profileDir.absoluteFilePath(id + ".profile")));
- profile = m_profileManager->loadProfile(profileDir.absoluteFilePath(id + ".profile"));
- profile->setName(id);
+ profile = m_profileManager->createProfile(id, isOffTheRecord);
}
connect(profile, &WebProfile::downloadRequested, m_downloads.get(), &DownloadsWidget::addDownload);
auto *interceptor = new UrlRequestInterceptor(m_urlFilter.get(), profile, profile);
@@ -74,6 +101,11 @@ QPair<QString, WebProfile *> Browser::loadProfile(const QString &id)
return QPair<QString, WebProfile *>(m_profileManager->id(profile), profile);
}
+void Browser::removeProfile(const QString &id)
+{
+ m_profileManager->deleteProfile(id);
+}
+
void Browser::setConfiguration(std::unique_ptr<Configuration> &config)
{
Q_ASSERT(config);
@@ -91,20 +123,10 @@ ProfileManager *Browser::getProfileManager()
return m_profileManager;
}
-void Browser::registerPlugin(const Plugin &plugin)
-{
- Q_ASSERT(m_config);
-
- auto *p = qobject_cast<PluginInterface *>(plugin.instance);
- if(p != nullptr) {
- p->setBrowserInterface(this);
- m_plugins.append(plugin);
- }
-}
-
-void Browser::setup()
+void Browser::setup(QVector<QPluginLoader *> plugins)
{
Q_ASSERT(m_config);
+ m_plugins = plugins;
auto stylesheet = m_config->value<QString>("browser.stylesheet");
if(stylesheet) {
@@ -132,7 +154,7 @@ void Browser::setup()
const QString id = m_config->value<QString>("profile.default").value();
auto *profile = m_profileManager->profile(id);
if(profile == nullptr) {
- profile = this->loadProfile(id).second;
+ profile = qobject_cast<WebProfile *>(loadProfile(id).second);
}
WebProfile::setDefaultProfile(profile);
@@ -225,13 +247,12 @@ MainWindow *Browser::createWindow()
});
window->addAction(MainWindow::ToolsMenu, downloadsAction);
- for(const Plugin &p : qAsConst(m_plugins)) {
- auto *plugin = qobject_cast<PluginInterface *>(p.instance);
+ for(QPluginLoader *loader : qAsConst(m_plugins)) {
+ const auto *plugin = qobject_cast<PluginInterface *>(loader->instance());
Q_CHECK_PTR(plugin);
- auto *pluginAction = new QAction(p.name, window);
- pluginAction->setShortcut(p.shortcut);
-
+ auto *pluginAction = new QAction(loader->metaData().value("MetaData").toObject().value("name").toString(), window);
+ pluginAction->setShortcut(QKeySequence::fromString(loader->metaData().value("MetaData").toObject().value("shortcut").toString()));
connect(pluginAction, &QAction::triggered, window, [=]() {
plugin->createWidget(window)->exec();
});
diff --git a/src/browser.h b/src/browser.h
index 6731f59..35b4149 100644
--- a/src/browser.h
+++ b/src/browser.h
@@ -10,10 +10,10 @@
#define SMOLBOTE_BROWSER_H
#include <singleapplication.h>
+#include <browserinterface.h>
#include <QJsonObject>
#include <QVector>
#include <functional>
-#include <interfaces.h>
#include <memory>
#include "session.h"
@@ -22,7 +22,8 @@ class BookmarksWidget;
class DownloadsWidget;
class Filter;
class MainWindow;
-class WebProfile;
+class ProfileManager;
+class QPluginLoader;
class Browser : public SingleApplication, public BrowserInterface
{
Q_OBJECT
@@ -36,16 +37,19 @@ public slots:
public:
// interface
- Configuration *getConfiguration() const override;
+ Configuration *getConfiguration() const;
+ const QStringList configurationOptions() const override;
+ const QString configuration(const QString &key) const override;
+ void setConfiguration(const QString &key, const QString &value) override;
- ProfileManager *getProfileManager() override;
- QPair<QString, WebProfile *> loadProfile(const QString &id) override;
+ ProfileManager *getProfileManager();
+ const QList<QPair<QString, Profile *>> profileList() const override;
+ QPair<QString, Profile *> loadProfile(const QString &id, bool isOffTheRecord = true) override;
+ void removeProfile(const QString &id) override;
void setConfiguration(std::unique_ptr<Configuration> &config);
- void registerPlugin(const Plugin &plugin);
-
- void setup();
+ void setup(QVector<QPluginLoader *> plugins);
QJsonObject session() const {
return Session::session(m_windows);
@@ -65,7 +69,7 @@ private:
std::unique_ptr<Filter> m_urlFilter;
QVector<MainWindow *> m_windows;
- QVector<Plugin> m_plugins;
+ QVector<QPluginLoader *> m_plugins;
};
#endif // SMOLBOTE_BROWSER_H
diff --git a/src/main.cpp b/src/main.cpp
index 6940856..e0ba7eb 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -7,7 +7,6 @@
*/
#include "browser.h"
-#include "plugin.h"
#include "session.h"
#include "util.h"
#include "version.h"
@@ -17,6 +16,8 @@
#include <configuration/configuration.h>
#include <iostream>
#include <memory>
+#include <QPluginLoader>
+#include <plugininterface.h>
#ifdef _WIN32
#include <cstdio>
#include <windows.h>
@@ -102,19 +103,23 @@ int main(int argc, char **argv)
return 0;
}
- QVector<Plugin> plugins;
+ QVector<QPluginLoader *> plugins;
+ CommandHash_t pluginCommands;
+
for(const QString &path : Util::files(config->value<QString>("plugins.path").value())) {
- plugins.append(loadPluginFromPath(path));
- }
- QMap<QString, std::function<int()>> pluginCommands;
- for(const auto &plugin : plugins) {
- auto *pluginInterface = qobject_cast<PluginInterface *>(plugin.instance);
- Q_CHECK_PTR(pluginInterface);
-
- QHashIterator<QString, std::function<int()>> i(pluginInterface->commands());
- while(i.hasNext()) {
- i.next();
- pluginCommands.insert(i.key(), i.value());
+ QPluginLoader *loader = new QPluginLoader(path);
+ const bool loaded = loader->load();
+#ifdef QT_DEBUG
+ qDebug("Loading plugin %s %s", qUtf8Printable(path), loaded ? "[ok]" : "[failed]");
+#endif
+
+ if(loader->load()) {
+ plugins.append(loader);
+ auto *plugin = qobject_cast<PluginInterface *>(loader->instance());
+ pluginCommands.unite(plugin->commands());
+ } else {
+ qDebug("%s", qUtf8Printable(loader->errorString()));
+ delete loader;
}
}
@@ -187,11 +192,7 @@ int main(int argc, char **argv)
auto profile = config->value<QString>("profile.default");
app.setConfiguration(config);
- app.setup();
-
- for(const Plugin &plugin : plugins) {
- app.registerPlugin(plugin);
- }
+ app.setup(plugins);
QStringList urls;
if(arguments) {
diff --git a/src/plugin.h b/src/plugin.h
deleted file mode 100644
index 045d047..0000000
--- a/src/plugin.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote
- *
- * SPDX-License-Identifier: GPL-3.0
- */
-
-#ifndef SMOLBOTE_PLUGIN_H
-#define SMOLBOTE_PLUGIN_H
-
-#include <interfaces.h>
-#include <QPluginLoader>
-#include <QFileInfo>
-#include <QDir>
-
-inline Plugin loadPluginFromPath(const QString &path)
-{
- Plugin p;
- QPluginLoader loader(path);
-
- if(loader.load()) {
-#ifdef QT_DEBUG
- qDebug("Loading plugin: %s [ok]", qUtf8Printable(path));
-#endif
-
- auto meta = loader.metaData().value("MetaData").toObject();
- p.name = meta.value("name").toString();
- p.author = meta.value("author").toString();
- p.shortcut = QKeySequence::fromString(meta.value("shortcut").toString());
-
- p.instance = loader.instance();
-
- } else {
- qDebug("Loading pluing: %s [failed]", qUtf8Printable(path));
- qDebug("%s", qUtf8Printable(loader.errorString()));
- }
-
- return p;
-}
-
-#endif // SMOLBOTE_PLUGIN_H