aboutsummaryrefslogtreecommitdiff
path: root/src/browser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/browser.cpp')
-rw-r--r--src/browser.cpp115
1 files changed, 20 insertions, 95 deletions
diff --git a/src/browser.cpp b/src/browser.cpp
index 29a02b7..f2c7314 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -24,64 +24,6 @@
#include <QJsonArray>
#include <about/aboutdialog.h>
-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 = std::shared_ptr<QObject>(loader.instance());
-
- } else {
- qDebug("Loading pluing: %s [failed]", qUtf8Printable(path));
- qDebug("%s", qUtf8Printable(loader.errorString()));
- }
-
- return p;
-}
-
-inline QVector<Plugin> loadPlugins(const QString &path)
-{
- QVector<Plugin> list;
- QFileInfo location(path);
- if(!location.exists()) {
- qDebug("Plugin location doesn't exist.");
- return list;
- }
-
- if(location.isFile()) {
- // only load this one plugin
- auto p = loadPluginFromPath(location.absoluteFilePath());
- if(p.instance)
- list.append(p);
-
- } else if(location.isDir()) {
- // load all profiles from this directory
- const auto entries = QDir(location.absoluteFilePath()).entryInfoList(QDir::Files | QDir::Readable);
- for(const auto &f : entries) {
- auto p = loadPluginFromPath(f.absoluteFilePath());
- if(p.instance)
- list.append(p);
- }
-
- } else {
-#ifdef QT_DEBUG
- qDebug("Path is neither file nor folder: %s", qUtf8Printable(path));
-#endif
- }
-
- return list;
-}
-
Browser::Browser(int &argc, char *argv[])
: SingleApplication(argc, argv)
{
@@ -96,10 +38,7 @@ Browser::~Browser()
m_bookmarks->save();
qDeleteAll(m_windows);
- m_windows.clear();
-
- //qDeleteAll(m_plugins);
- m_plugins.clear();
+ m_windows.clear();
}
@@ -118,31 +57,27 @@ void Browser::setConfiguration(std::shared_ptr<Configuration> &config)
m_config = config;
}
-void Browser::setup(const QString &defaultProfile)
+void Browser::registerPlugin(const Plugin &plugin)
{
- Q_ASSERT_X(m_config, "Browser::setup", "Configuration not set");
-
- // load plugins first
- m_plugins.append(loadPlugins(QString::fromStdString(m_config->value<std::string>("plugins.path").value())));
+ if(plugin.instance->inherits("ProfileInterface")) {
+ auto *profileEditor = qobject_cast<ProfileInterface *>(plugin.instance);
+ Q_ASSERT_X(profileEditor != nullptr, "Browser::setup", "profile interface cast failed");
- // register commands
- for(const Plugin &p : qAsConst(m_plugins)) {
-
- if(p.instance->inherits("ProfileInterface")) {
- auto *profileEditor = qobject_cast<ProfileInterface *>(p.instance.get());
- Q_ASSERT_X(profileEditor != nullptr, "Browser::setup", "profile interface cast failed");
-
- connect(this, &Browser::registerProfile, [=](WebProfile *profile) {
- profileEditor->registerProfile(profile);
- });
- }
-
- auto *plugin = qobject_cast<PluginInterface *>(p.instance.get());
- if(plugin) {
- m_commands.unite(plugin->commands());
+ for(auto it = m_profiles.constBegin(); it != m_profiles.constEnd(); ++it) {
+ profileEditor->registerProfile(it.value());
}
+ connect(this, &Browser::registerProfile, [=](WebProfile *profile) {
+ profileEditor->registerProfile(profile);
+ });
}
+ m_plugins.append(plugin);
+}
+
+void Browser::setup(const QString &defaultProfile)
+{
+ Q_ASSERT_X(m_config, "Browser::setup", "Configuration not set");
+
// load profiles
{
const auto defaults = m_config->section("profile");
@@ -203,16 +138,6 @@ WebProfile *Browser::profile(const QString &name) const
return nullptr;
}
-int Browser::command(const QString &command)
-{
- if(m_commands.contains(command)) {
- return m_commands.value(command)();
- } else {
- qWarning("No such command: %s", qUtf8Printable(command));
- return -1;
- }
-}
-
void Browser::createSession(const QString &profileName, bool newWindow, const QStringList &urls)
{
if(m_windows.isEmpty()) {
@@ -249,7 +174,7 @@ MainWindow *Browser::createWindow()
bookmarksAction->setShortcut(QKeySequence(QString::fromStdString(m_config->value<std::string>("bookmarks.shortcut").value())));
connect(bookmarksAction, &QAction::triggered, window, [this, window]() {
bool wasVisible = m_bookmarks->isVisible();
- for(MainWindow *w : m_windows) {
+ for(MainWindow *w : qAsConst(m_windows)) {
w->removeDockWidget(m_bookmarks.get());
}
if(!wasVisible) {
@@ -262,7 +187,7 @@ MainWindow *Browser::createWindow()
downloadsAction->setShortcut(QKeySequence(QString::fromStdString(m_config->value<std::string>("downloads.shortcut").value())));
connect(downloadsAction, &QAction::triggered, window, [this, window]() {
bool wasVisible = m_downloads->isVisible();
- for(MainWindow *w : m_windows) {
+ for(MainWindow *w : qAsConst(m_windows)) {
w->removeDockWidget(m_downloads.get());
}
if(!wasVisible) {
@@ -273,7 +198,7 @@ MainWindow *Browser::createWindow()
for(const Plugin &p : qAsConst(m_plugins)) {
if(p.instance->inherits("ProfileInterface")) {
- auto *profileEditor = qobject_cast<ProfileInterface *>(p.instance.get());
+ auto *profileEditor = qobject_cast<ProfileInterface *>(p.instance);
auto *profileAction = new QAction(tr("Profile"), window);
profileAction->setShortcut(p.shortcut);
connect(profileAction, &QAction::triggered, window, [profileEditor]() {