diff options
Diffstat (limited to 'src/browser.cpp')
-rw-r--r-- | src/browser.cpp | 68 |
1 files changed, 27 insertions, 41 deletions
diff --git a/src/browser.cpp b/src/browser.cpp index c3cbd2f..09fc2c8 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -98,46 +98,31 @@ const QList<QPair<QString, Profile *>> Browser::profileList() const return profiles; } -QPair<QString, Profile *> Browser::loadProfile(const QString &id, bool isOffTheRecord) +void Browser::loadProfiles(const QStringList &profilePaths) { Configuration conf; - const QString _id = [id]() { - // if id contains a separator, it should be a path - if(id.contains(QDir::separator())) { - return QFileInfo(id).baseName(); - } else { - return id; - } - }(); + for(const QString &path : profilePaths) { + const QString id = QFileInfo(path).baseName(); - auto *profile = m_profileManager->profile(/* id */ _id, /* path */ (_id == id) ? QString() : id, isOffTheRecord); - connect(profile, &WebProfile::downloadRequested, m_downloads.get(), &DownloadsWidget::addDownload); - - auto *interceptor = new UrlRequestInterceptor(profile, profile); - for(UrlFilter *filter : m_filters) { - interceptor->addFilter(filter); - } - const auto headers = conf.value<QStringList>("filter.header").value_or(QStringList()); - for(const QString &header : headers) { - const auto h = header.split(QLatin1Literal(":")); - if(h.length() == 2) - interceptor->addHttpHeader(h.at(0).toLatin1(), h.at(1).toLatin1()); - } - profile->setUrlRequestInterceptor(interceptor); + auto *profile = m_profileManager->add(id, path); + connect(profile, &WebProfile::downloadRequested, m_downloads.get(), &DownloadsWidget::addDownload); - spdlog::info("Added profile: {}{}", qUtf8Printable(_id), profile->isOffTheRecord() ? " (otr)" : ""); - return QPair<QString, WebProfile *>(_id, profile); -} + auto *interceptor = new UrlRequestInterceptor(profile, profile); + for(UrlFilter *filter : m_filters) { + interceptor->addFilter(filter); + } -void Browser::removeProfile(const QString &id) -{ - m_profileManager->deleteProfile(id); -} + const auto headers = conf.value<QStringList>("filter.header").value_or(QStringList()); + for(const QString &header : headers) { + const auto h = header.split(QLatin1Literal(":")); + if(h.length() == 2) + interceptor->addHttpHeader(h.at(0).toLatin1(), h.at(1).toLatin1()); + } + profile->setUrlRequestInterceptor(interceptor); -WebProfileManager *Browser::getProfileManager() -{ - return m_profileManager; + spdlog::info("Added profile\t{}{}\t{}", qUtf8Printable(id), profile->isOffTheRecord() ? "*" : "", qUtf8Printable(profile->name())); + } } QPluginLoader *Browser::addPlugin(const QString &path) @@ -202,19 +187,20 @@ void Browser::setup(QVector<QPluginLoader *> plugins) // load profiles m_profileManager = new WebProfileManager(this); - for(const QString &profilePath : Util::files(conf.value<QString>("profile.path").value(), { "*.profile" })) { - this->loadProfile(profilePath); - } + WebProfileManager::setInstance(m_profileManager); + loadProfiles(Util::files(conf.value<QString>("profile.path").value(), { "*.profile" })); // set default profile { const QString id = conf.value<QString>("profile.default").value(); auto *profile = m_profileManager->profile(id); if(profile == nullptr) { - profile = qobject_cast<WebProfile *>(loadProfile(id).second); + spdlog::error("Unknown default profile!"); + //profile = qobject_cast<WebProfile *>(loadProfile(id).second); + } else { + spdlog::info("Default profile\t{}{}\t{}", qUtf8Printable(id), profile->isOffTheRecord() ? "*" : "", qUtf8Printable(profile->name())); + WebProfile::setDefaultProfile(profile); } - - WebProfile::setDefaultProfile(profile); } // bookmarks @@ -231,7 +217,7 @@ void Browser::setup(QVector<QPluginLoader *> plugins) }); auto *openInCurrentTabWithProfile = menu->addMenu(tr("Open link in current tab with profile")); - m_profileManager->profileMenu(openInCurrentTabWithProfile, [url, subwindow](WebProfile *profile) { + profileMenu(openInCurrentTabWithProfile, [url, subwindow](WebProfile *profile) { subwindow->currentView()->setProfile(profile); subwindow->currentView()->load(url); }); @@ -241,7 +227,7 @@ void Browser::setup(QVector<QPluginLoader *> plugins) }); auto *openInNewTabWithProfile = menu->addMenu(tr("Open link in new tab with profile")); - m_profileManager->profileMenu(openInNewTabWithProfile, [url, subwindow](WebProfile *profile) { + profileMenu(openInNewTabWithProfile, [url, subwindow](WebProfile *profile) { subwindow->addTab(url, profile); }); |