From aa8198eec380659fd3538e058b50c24b0f88743c Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sun, 1 Jul 2018 18:13:01 +0200 Subject: Code cleanup Clean up MainWindow Configuration is now a std::unique_ptr Connect downloads and request interceptor to all profiles --- src/browser.cpp | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) (limited to 'src/browser.cpp') diff --git a/src/browser.cpp b/src/browser.cpp index b793bb1..6ffcaaa 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -52,14 +52,16 @@ void Browser::about() dlg->exec(); } -void Browser::setConfiguration(std::shared_ptr &config) +void Browser::setConfiguration(std::unique_ptr &config) { Q_ASSERT(config); - m_config = config; + m_config = std::move(config); } void Browser::registerPlugin(const Plugin &plugin) { + Q_ASSERT(m_config); + if(plugin.instance->inherits("ProfileInterface")) { auto *profileEditor = qobject_cast(plugin.instance); Q_ASSERT_X(profileEditor != nullptr, "Browser::setup", "profile interface cast failed"); @@ -88,6 +90,21 @@ void Browser::setup(const QString &defaultProfile) { Q_ASSERT_X(m_config, "Browser::setup", "Configuration not set"); + auto stylesheet = m_config->value("browser.stylesheet"); + if(stylesheet) { + QFile f(stylesheet.value()); + if(f.open(QIODevice::ReadOnly)) { + setStyleSheet(f.readAll()); + f.close(); + } + } + + // downloads + m_downloads = std::make_unique(m_config->value("downloads.path").value()); + // url request filter + m_urlFilter = std::make_unique(m_config->value("filter.path").value()); + // cookie request filter + // load profiles { const auto defaults = m_config->section("profile"); @@ -98,6 +115,8 @@ void Browser::setup(const QString &defaultProfile) for(const QFileInfo &f : entries) { auto *profile = ProfileManager::loadProfile(f.absoluteFilePath(), defaults); + connect(profile, &WebProfile::downloadRequested, m_downloads.get(), &DownloadsWidget::addDownload); + profile->setRequestInterceptor(m_urlFilter.get()); emit registerProfile(profile); } } @@ -106,26 +125,18 @@ void Browser::setup(const QString &defaultProfile) if(ProfileManager::profile(defaultProfile) == nullptr) { // if this profile has not been added, it doesn't have a path 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)); } - // url request filter - m_urlFilter = std::make_shared(QString::fromStdString(m_config->value("filter.path").value())); - WebProfile::defaultProfile()->setRequestInterceptor(m_urlFilter.get()); - - // cookie request filter - // bookmarks m_bookmarks = std::make_shared(QString::fromStdString(m_config->value("bookmarks.path").value())); connect(m_bookmarks.get(), &BookmarksWidget::openUrl, this, [this](const QUrl &url) { m_windows.last()->createTab(url); }); - - // downloads - m_downloads = std::make_shared(QString::fromStdString(m_config->value("downloads.path").value())); - connect(WebProfile::defaultProfile(), &WebProfile::downloadRequested, m_downloads.get(), &DownloadsWidget::addDownload); } void Browser::createSession(const QJsonObject &object) @@ -152,7 +163,7 @@ void Browser::createSession(const QJsonObject &object) } } if(window == nullptr) - window = mainwindow->createSubWindow(profile); + window = mainwindow->createSubWindow(m_config, profile); const QJsonArray tabs = subwindow.value("tabs").toArray(); if(tabs.isEmpty()) -- cgit v1.2.1