aboutsummaryrefslogtreecommitdiff
path: root/src/browser.cpp
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-08-25 20:07:54 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-08-25 20:07:54 +0200
commit3b611f42bf5c233ca66e406474896022b6ed78cc (patch)
treecbf30d20220f91c5eccaf8d89a2aac1989241b08 /src/browser.cpp
parentMainWindow: fix load session action (diff)
downloadsmolbote-3b611f42bf5c233ca66e406474896022b6ed78cc.tar.xz
Add BrowserInterface to simplify plugins a bit
Diffstat (limited to 'src/browser.cpp')
-rw-r--r--src/browser.cpp36
1 files changed, 15 insertions, 21 deletions
diff --git a/src/browser.cpp b/src/browser.cpp
index 375796c..e248a3f 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -58,30 +58,20 @@ void Browser::setConfiguration(std::unique_ptr<Configuration> &config)
m_config = std::move(config);
}
-void Browser::registerPlugin(const Plugin &plugin)
+Configuration *Browser::getConfiguration() const
{
Q_ASSERT(m_config);
+ return m_config.get();
+}
- if(plugin.instance->inherits("ProfileInterface")) {
- auto *profileEditor = qobject_cast<ProfileInterface *>(plugin.instance);
- Q_ASSERT_X(profileEditor != nullptr, "Browser::setup", "profile interface cast failed");
-
- ProfileIterator it(ProfileManager::profileList());
- while(it.hasNext()) {
- it.next();
- profileEditor->registerProfile(it.value());
- }
- connect(this, &Browser::registerProfile, [=](WebProfile *profile) {
- profileEditor->registerProfile(profile);
- });
- }
+void Browser::registerPlugin(const Plugin &plugin)
+{
+ Q_ASSERT(m_config);
- if(plugin.instance->inherits("ConfigurationInterface")) {
- auto *configEditor = qobject_cast<ConfigurationInterface *>(plugin.instance);
- Q_CHECK_PTR(configEditor);
- configEditor->setConfiguration(m_config.get());
- }
+ auto *p = qobject_cast<PluginInterface *>(plugin.instance);
+ Q_CHECK_PTR(p);
+ p->setBrowserInterface(this);
m_plugins.append(plugin);
}
@@ -117,7 +107,6 @@ void Browser::setup(const QString &defaultProfile)
auto *profile = ProfileManager::loadProfile(f.absoluteFilePath(), defaults);
connect(profile, &WebProfile::downloadRequested, m_downloads.get(), &DownloadsWidget::addDownload);
profile->setRequestInterceptor(m_urlFilter.get());
- emit registerProfile(profile);
}
}
@@ -127,7 +116,6 @@ void Browser::setup(const QString &defaultProfile)
auto *profile = ProfileManager::loadProfile(QString(), defaults);
connect(profile, &WebProfile::downloadRequested, m_downloads.get(), &DownloadsWidget::addDownload);
profile->setRequestInterceptor(m_urlFilter.get());
- emit registerProfile(profile);
}
WebProfile::setDefaultProfile(ProfileManager::profile(defaultProfile));
}
@@ -139,6 +127,12 @@ void Browser::setup(const QString &defaultProfile)
});
}
+const QVector<WebProfile *> Browser::profiles() const
+{
+ const QMap<QString, WebProfile *> profileList = ProfileManager::profileList();
+ return QVector<WebProfile *>::fromList(profileList.values());
+}
+
void Browser::createSession(const QJsonObject &object)
{
MainWindow *mainwindow = nullptr;