diff options
Diffstat (limited to 'src/browser.cpp')
-rw-r--r-- | src/browser.cpp | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/src/browser.cpp b/src/browser.cpp index 3a23eeb..6e1e2ba 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -15,7 +15,7 @@ #include "configuration.h" #include "downloadswidget.h" #include "mainwindow/mainwindow.h" -#include "profilemanager.h" +#include "webprofilemanager.h" #include "subwindow/subwindow.h" #include "util.h" #include "webengine/urlinterceptor.h" @@ -94,13 +94,18 @@ const QList<QPair<QString, Profile *>> Browser::profileList() const QPair<QString, Profile *> Browser::loadProfile(const QString &id, bool isOffTheRecord) { - WebProfile *profile = nullptr; - if(QFile::exists(id)) { - profile = m_profileManager->loadProfile(id); - } else { - profile = m_profileManager->createProfile(id, isOffTheRecord); - } + 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; + } + }(); + + 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); @@ -113,7 +118,7 @@ QPair<QString, Profile *> Browser::loadProfile(const QString &id, bool isOffTheR } profile->setRequestInterceptor(interceptor); - return QPair<QString, WebProfile *>(m_profileManager->id(profile), profile); + return QPair<QString, WebProfile *>(_id, profile); } void Browser::removeProfile(const QString &id) @@ -133,7 +138,7 @@ Configuration *Browser::getConfiguration() const return m_config.get(); } -ProfileManager *Browser::getProfileManager() +WebProfileManager *Browser::getProfileManager() { return m_profileManager; } @@ -192,7 +197,7 @@ void Browser::setup(QVector<QPluginLoader *> plugins) // cookie request filter // load profiles - m_profileManager = new ProfileManager(m_config->section("profile"), this); + m_profileManager = new WebProfileManager(m_config->section("profile"), this); for(const QString &profilePath : Util::files(m_config->value<QString>("profile.path").value(), { "*.profile" })) { this->loadProfile(profilePath); } @@ -220,22 +225,20 @@ void Browser::setup(QVector<QPluginLoader *> plugins) subwindow->currentView()->load(url); }); - auto *openInCurrentTabWithProfile = m_profileManager->createProfileMenu([url, subwindow](WebProfile *profile) { + auto *openInCurrentTabWithProfile = menu->addMenu(tr("Open link in current tab with profile")); + m_profileManager->profileMenu(openInCurrentTabWithProfile, [url, subwindow](WebProfile *profile) { subwindow->currentView()->setProfile(profile); subwindow->currentView()->load(url); - }, nullptr); - openInCurrentTabWithProfile->setTitle(tr("Open link in current tab with profile")); - menu->addMenu(openInCurrentTabWithProfile); + }); menu->addAction(tr("Open link in new tab"), subwindow, [url, subwindow]() { subwindow->addTab(url); }); - auto *openInNewTabWithProfile = m_profileManager->createProfileMenu([url, subwindow](WebProfile *profile) { + auto *openInNewTabWithProfile = menu->addMenu(tr("Open link in new tab with profile")); + m_profileManager->profileMenu(openInNewTabWithProfile, [url, subwindow](WebProfile *profile) { subwindow->addTab(url, profile); - }, nullptr); - openInNewTabWithProfile->setTitle(tr("Open link in new tab with profile")); - menu->addMenu(openInNewTabWithProfile); + }); menu->exec(pos); }); |