From 9abf7a9690163737d3e70b3b52d814135858d0d5 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sat, 29 Sep 2018 14:56:39 +0200 Subject: ProfileManager: move initial profile loading to ProfileManager --- src/browser.cpp | 58 ++++++++++++++++++++++----------------------------------- 1 file changed, 22 insertions(+), 36 deletions(-) (limited to 'src/browser.cpp') diff --git a/src/browser.cpp b/src/browser.cpp index 6cdfdab..e93123c 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -16,16 +16,16 @@ #include #include #include +#include #include +#include #include #include #include #include #include -#include #include -#include -#include +#include Browser::Browser(int &argc, char *argv[], bool allowSecondary) : SingleApplication(argc, argv, allowSecondary, SingleApplication::User | SingleApplication::SecondaryNotification | SingleApplication::ExcludeAppVersion) @@ -55,11 +55,11 @@ void Browser::about() QPair Browser::loadProfile(const QString &id) { - WebProfile *profile = profileManager->loadProfile(id); + WebProfile *profile = m_profileManager->loadProfile(id); connect(profile, &WebProfile::downloadRequested, m_downloads.get(), &DownloadsWidget::addDownload); profile->setRequestInterceptor(m_urlFilter.get()); - return QPair(profileManager->id(profile), profile); + return QPair(m_profileManager->id(profile), profile); } void Browser::setConfiguration(std::unique_ptr &config) @@ -76,27 +76,24 @@ Configuration *Browser::getConfiguration() const ProfileManager *Browser::getProfileManager() { - return ProfileManager::instance(); + return m_profileManager; } void Browser::registerPlugin(const Plugin &plugin) { Q_ASSERT(m_config); - auto *p = qobject_cast(plugin.instance); - Q_CHECK_PTR(p); - p->setBrowserInterface(this); - - m_plugins.append(plugin); + if(p != nullptr) { + p->setBrowserInterface(this); + m_plugins.append(plugin); + } } void Browser::setup(const QString &defaultProfile) { Q_ASSERT(m_config); - ProfileManager::setInstance(new ProfileManager(m_config->section("profile"), this)); - auto stylesheet = m_config->value("browser.stylesheet"); if(stylesheet) { QFile f(stylesheet.value()); @@ -113,25 +110,15 @@ void Browser::setup(const QString &defaultProfile) // cookie request filter // load profiles - { - const auto defaults = m_config->section("profile"); - const QDir profilesDir(m_config->value("profile.path").value()); - - if(profilesDir.exists()) { - const auto entries = profilesDir.entryInfoList({ "*.profile" }, QDir::Files | QDir::Readable, QDir::Time); - - for(const QFileInfo &f : entries) { - loadProfile(f.absoluteFilePath()); - } - } - - // set default profile - if(profileManager->profile(defaultProfile) == nullptr) { - // if this profile has not been added, it doesn't have a path - loadProfile(QString()); - } - WebProfile::setDefaultProfile(profileManager->profile(defaultProfile)); + m_profileManager = new ProfileManager(m_config->section("profile"), defaultProfile, this); + // connect profiles + for(const QString &id : m_profileManager->idList()) { + auto *profile = m_profileManager->profile(id); + connect(profile, &WebProfile::downloadRequested, m_downloads.get(), &DownloadsWidget::addDownload); + profile->setRequestInterceptor(m_urlFilter.get()); } + // set default profile + WebProfile::setDefaultProfile(m_profileManager->profile(defaultProfile)); // bookmarks m_bookmarks = std::make_shared(QString::fromStdString(m_config->value("bookmarks.path").value())); @@ -142,7 +129,7 @@ void Browser::setup(const QString &defaultProfile) auto *timer = new QTimer(this); connect(timer, &QTimer::timeout, m_bookmarks.get(), &BookmarksWidget::save); // 5min * 60sec * 1000ms - timer->start(5*60*1000); + timer->start(5 * 60 * 1000); } void Browser::createSession(const QJsonObject &object) @@ -158,7 +145,7 @@ void Browser::createSession(const QJsonObject &object) for(const QJsonValue &s : subwindows) { const QJsonObject subwindow = s.toObject(); const QString profileId = subwindow.value("profile").toString(); - WebProfile *profile = profileManager->profile(profileId); + WebProfile *profile = m_profileManager->profile(profileId); if(profile == nullptr) profile = WebProfile::defaultProfile(); Q_CHECK_PTR(profile); @@ -180,7 +167,7 @@ void Browser::createSession(const QJsonObject &object) for(const QJsonValue &t : subwindow.value("tabs").toArray()) { const QJsonObject tab = t.toObject(); const QUrl url = QUrl::fromUserInput(tab.value("url").toString()); - WebProfile *p = profileManager->profile(tab.value("profile").toString()); + WebProfile *p = m_profileManager->profile(tab.value("profile").toString()); window->addTab(url, p); } } @@ -190,7 +177,7 @@ void Browser::createSession(const QJsonObject &object) MainWindow *Browser::createWindow() { // the window will delete itself when it closes, so we don't need to delete it - MainWindow *window = new MainWindow(m_config); + auto *window = new MainWindow(m_config); connect(window->addressBar, &AddressBar::complete, m_bookmarks.get(), &BookmarksWidget::search); connect(window, &MainWindow::createBookmark, m_bookmarks.get(), &BookmarksWidget::addBookmark); @@ -231,7 +218,6 @@ MainWindow *Browser::createWindow() plugin->createWidget(window)->exec(); }); window->addAction(MainWindow::ToolsMenu, pluginAction); - } m_windows.append(window); -- cgit v1.2.1