aboutsummaryrefslogtreecommitdiff
path: root/src
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
parentMainWindow: fix load session action (diff)
downloadsmolbote-3b611f42bf5c233ca66e406474896022b6ed78cc.tar.xz
Add BrowserInterface to simplify plugins a bit
Diffstat (limited to 'src')
-rw-r--r--src/browser.cpp36
-rw-r--r--src/browser.h6
2 files changed, 18 insertions, 24 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;
diff --git a/src/browser.h b/src/browser.h
index 99da8a7..340a16d 100644
--- a/src/browser.h
+++ b/src/browser.h
@@ -24,7 +24,7 @@ class DownloadsWidget;
class UrlRequestInterceptor;
class MainWindow;
class WebProfile;
-class Browser : public SingleApplication
+class Browser : public SingleApplication, public BrowserInterface
{
Q_OBJECT
@@ -37,6 +37,7 @@ public slots:
public:
void setConfiguration(std::unique_ptr<Configuration> &config);
+ Configuration *getConfiguration() const override;
void registerPlugin(const Plugin &plugin);
void setup(const QString &defaultProfile);
@@ -46,8 +47,7 @@ public:
return m_bookmarks;
}
-signals:
- void registerProfile(WebProfile *profile);
+ const QVector<WebProfile *> profiles() const override;
public slots:
void createSession(const QJsonObject &object);