diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-07-01 18:13:01 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-07-01 18:13:01 +0200 |
commit | aa8198eec380659fd3538e058b50c24b0f88743c (patch) | |
tree | b9ae32ac4192de87054a8892d4e654a45737a04e /src/browser.cpp | |
parent | Add browser.locale and browser.translation (diff) | |
download | smolbote-aa8198eec380659fd3538e058b50c24b0f88743c.tar.xz |
Code cleanup
Clean up MainWindow
Configuration is now a std::unique_ptr
Connect downloads and request interceptor to all profiles
Diffstat (limited to 'src/browser.cpp')
-rw-r--r-- | src/browser.cpp | 37 |
1 files changed, 24 insertions, 13 deletions
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<Configuration> &config) +void Browser::setConfiguration(std::unique_ptr<Configuration> &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<ProfileInterface *>(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<QString>("browser.stylesheet"); + if(stylesheet) { + QFile f(stylesheet.value()); + if(f.open(QIODevice::ReadOnly)) { + setStyleSheet(f.readAll()); + f.close(); + } + } + + // downloads + m_downloads = std::make_unique<DownloadsWidget>(m_config->value<QString>("downloads.path").value()); + // url request filter + m_urlFilter = std::make_unique<UrlRequestInterceptor>(m_config->value<QString>("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<UrlRequestInterceptor>(QString::fromStdString(m_config->value<std::string>("filter.path").value())); - WebProfile::defaultProfile()->setRequestInterceptor(m_urlFilter.get()); - - // cookie request filter - // bookmarks m_bookmarks = std::make_shared<BookmarksWidget>(QString::fromStdString(m_config->value<std::string>("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<DownloadsWidget>(QString::fromStdString(m_config->value<std::string>("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()) |