From 3b611f42bf5c233ca66e406474896022b6ed78cc Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sat, 25 Aug 2018 20:07:54 +0200 Subject: Add BrowserInterface to simplify plugins a bit --- src/browser.cpp | 36 +++++++++++++++--------------------- src/browser.h | 6 +++--- 2 files changed, 18 insertions(+), 24 deletions(-) (limited to 'src') 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 &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(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(plugin.instance); - Q_CHECK_PTR(configEditor); - configEditor->setConfiguration(m_config.get()); - } + auto *p = qobject_cast(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 Browser::profiles() const +{ + const QMap profileList = ProfileManager::profileList(); + return QVector::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 &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 profiles() const override; public slots: void createSession(const QJsonObject &object); -- cgit v1.2.1