aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/Usage/Profile.asciidoc6
-rw-r--r--lib/web/meson.build15
-rw-r--r--lib/web/profilemanager.cpp171
-rw-r--r--lib/web/profilemanager.h79
-rw-r--r--lib/webprofile/meson.build12
-rw-r--r--lib/webprofile/webprofile.cpp (renamed from lib/web/webprofile.cpp)4
-rw-r--r--lib/webprofile/webprofile.h (renamed from lib/web/webprofile.h)8
-rw-r--r--lib/webprofile/webprofilemanager.cpp150
-rw-r--r--lib/webprofile/webprofilemanager.h78
-rw-r--r--linux/.config8
-rw-r--r--meson.build4
-rw-r--r--src/browser.cpp39
-rw-r--r--src/browser.h6
-rw-r--r--src/mainwindow/mainwindow.cpp2
-rw-r--r--src/mainwindow/menubar.cpp10
-rw-r--r--src/meson.build2
-rw-r--r--src/session/savesessiondialog.cpp2
-rw-r--r--src/session/session.cpp2
-rw-r--r--src/subwindow/subwindow.cpp27
-rw-r--r--src/webengine/webview.cpp11
20 files changed, 292 insertions, 344 deletions
diff --git a/doc/Usage/Profile.asciidoc b/doc/Usage/Profile.asciidoc
index 9b00dbc..79506fd 100644
--- a/doc/Usage/Profile.asciidoc
+++ b/doc/Usage/Profile.asciidoc
@@ -2,6 +2,12 @@
A Profile is a collection of settings, policies, scripts, cookies, cache and
history. Profiles can be used to isolate pages from each other.
+Off-the-record profiles only use in-memory cache and save no files to disk.
+
+Profiles can be either temporary or permanent. Temporary profiles are expire
+when the application is closed, whereas permanent profiles are kept between
+runs.
+
Each window has a default profile it uses when opening new tabs. This can be
changed from the window's menu. Additionally, tabs can have their profiles
individually changed from their context menu.
diff --git a/lib/web/meson.build b/lib/web/meson.build
deleted file mode 100644
index 54d94df..0000000
--- a/lib/web/meson.build
+++ /dev/null
@@ -1,15 +0,0 @@
-web_inc = include_directories('.')
-web_moc = qt5.preprocess(
- moc_headers: ['profilemanager.h', 'webprofile.h'],
- dependencies: dep_qt5
-)
-web_lib = static_library('web',
- ['profilemanager.cpp', 'webprofile.cpp', web_moc, interfaces_moc],
- dependencies: dep_qt5,
- include_directories: [include, web_inc]
-)
-
-dep_web = declare_dependency(
- include_directories: web_inc,
- link_with: web_lib
-)
diff --git a/lib/web/profilemanager.cpp b/lib/web/profilemanager.cpp
deleted file mode 100644
index 0bae251..0000000
--- a/lib/web/profilemanager.cpp
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * This file is part of smolbote. It's copyrighted by the contributors recorded
- * in the version control history of the file, available from its original
- * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote
- *
- * SPDX-License-Identifier: GPL-3.0
- */
-
-#include "profilemanager.h"
-#include "webprofile.h"
-#include <QFileInfo>
-#include <QWebEngineSettings>
-
-ProfileManager::ProfileManager(const QHash<QString, QString> &profileSection, QObject *parent)
- : QObject(parent)
- , defaults(profileSection)
-{
-}
-
-WebProfile *ProfileManager::createProfile(const QString& id, bool isOffTheRecord)
-{
- QDir profileDir(defaults.value("profile.path"));
- const QString path = profileDir.absoluteFilePath(id + ".profile");
- {
- QSettings init(path, QSettings::IniFormat);
- init.setValue("name", id);
- init.setValue("otr", isOffTheRecord);
- init.sync();
- }
- return loadProfile(path);
-}
-
-WebProfile *ProfileManager::loadProfile(const QString &path)
-{
- std::unique_ptr<ProfileData> ptr = std::make_unique<ProfileData>(path);
- const QString id = QFileInfo(path).baseName();
-
- if(ptr->settings.value("otr", true).toBool()) {
- ptr->profile = new WebProfile(ptr->settings.value("name", id).toString(), nullptr);
- } else {
- ptr->profile = new WebProfile(id, ptr->settings.value("name", id).toString(), nullptr);
- }
- Q_CHECK_PTR(ptr->profile);
- connect(ptr->profile, &WebProfile::nameChanged, ptr->profile, [this, id](const QString &name) {
- this->m_profiles.at(id)->settings.setValue("name", name);
- });
-
- ptr->profile->setSearch(ptr->settings.value("search", defaults.value("profile.search")).toString());
- connect(ptr->profile, &WebProfile::searchChanged, ptr->profile, [this, id](const QString &url) {
- this->m_profiles.at(id)->settings.setValue("search", url);
- });
-
- ptr->profile->setHomepage(ptr->settings.value("homepage", defaults.value("profile.homepage")).toUrl());
- connect(ptr->profile, &WebProfile::homepageChanged, ptr->profile, [this, id](const QUrl &url) {
- this->m_profiles.at(id)->settings.setValue("homepage", url);
- });
-
- ptr->profile->setNewtab(ptr->settings.value("newtab", defaults.value("profile.newtab")).toUrl());
- connect(ptr->profile, &WebProfile::newtabChanged, ptr->profile, [this, id](const QUrl &url) {
- this->m_profiles.at(id)->settings.setValue("newtab", url);
- });
-
- ptr->settings.beginGroup("properties");
- {
- const auto keys = ptr->settings.childKeys();
- for(const QString &key : keys) {
- ptr->profile->setProperty(qUtf8Printable(key), ptr->settings.value(key));
- }
- }
- ptr->settings.endGroup(); // properties
- connect(ptr->profile, &WebProfile::propertyChanged, ptr->profile, [this, id](const QString &property, const QVariant &value) {
- this->m_profiles.at(id)->settings.setValue("properties/" + property, value);
- });
-
- ptr->settings.beginGroup("attributes");
- {
- const auto keys = ptr->settings.childKeys();
- auto *settings = ptr->profile->settings();
- for(const QString &key : keys) {
- auto attribute = static_cast<QWebEngineSettings::WebAttribute>(key.toInt());
- settings->setAttribute(attribute, ptr->settings.value(key).toBool());
- }
- }
- ptr->settings.endGroup();
- connect(ptr->profile, &WebProfile::attributeChanged, ptr->profile, [this, id](const QWebEngineSettings::WebAttribute attr, const bool value) {
- this->m_profiles.at(id)->settings.setValue("attributes/" + QString::number(attr), value);
- });
-
- // headers
- ptr->settings.beginGroup("headers");
- for(const QString &key : ptr->settings.childKeys()) {
- ptr->profile->setHttpHeader(key.toLatin1(), ptr->settings.value(key).toString().toLatin1());
- }
- ptr->settings.endGroup();
- connect(ptr->profile, &WebProfile::headerChanged, ptr->profile, [this, id](const QString &name, const QString &value) {
- this->m_profiles.at(id)->settings.setValue("headers/" + name, value);
- });
- connect(ptr->profile, &WebProfile::headerRemoved, ptr->profile, [this, id](const QString &name) {
- this->m_profiles.at(id)->settings.remove("headers/" + name);
- });
-
- m_profiles[id] = std::move(ptr);
- return m_profiles.at(id)->profile;
-}
-
-void ProfileManager::deleteProfile(const QString &id)
-{
- if(m_profiles.count(id) > 0) {
- auto profileData = m_profiles.extract(id);
- profileData.mapped()->deleteSelf = true;
- }
-}
-
-void ProfileManager::profilePickerMenu(QMenu *menu, WebProfile *current, std::function<void(WebProfile *)> callback) const
-{
- auto *profileGroup = new QActionGroup(menu);
-
- for(const auto &profileData : m_profiles) {
- WebProfile *profile = profileData.second->profile;
-
- auto *action = menu->addAction(profile->name(), profile, [profile, callback]() {
- callback(profile);
- });
- action->setCheckable(true);
- profileGroup->addAction(action);
-
- if(profile == current)
- action->setChecked(true);
- }
-
- connect(menu, &QMenu::aboutToHide, profileGroup, &QActionGroup::deleteLater);
-}
-
-QMenu *ProfileManager::createProfileMenu(std::function<void(WebProfile *)> callback, QWidget *parent) const
-{
- auto *menu = new QMenu(parent);
- for(const auto &m_profile : m_profiles) {
- WebProfile *profile = m_profile.second->profile;
- QAction *action = menu->addAction(profile->name());
- connect(action, &QAction::triggered, profile, [profile, callback]() {
- callback(profile);
- });
- }
- return menu;
-}
-
-const QStringList ProfileManager::idList() const
-{
- QStringList ids;
- for(const auto &m_profile : m_profiles) {
- ids.append(m_profile.first);
- }
- return ids;
-}
-
-const QString ProfileManager::id(const WebProfile *profile) const
-{
- for(const auto &m_profile : m_profiles) {
- if(m_profile.second->profile == profile)
- return m_profile.first;
- }
- return QString();
-}
-
-WebProfile *ProfileManager::profile(const QString &id) const
-{
- if(m_profiles.count(id) > 0) {
- return m_profiles.at(id)->profile;
- }
- return nullptr;
-}
diff --git a/lib/web/profilemanager.h b/lib/web/profilemanager.h
deleted file mode 100644
index e0040a3..0000000
--- a/lib/web/profilemanager.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * This file is part of smolbote. It's copyrighted by the contributors recorded
- * in the version control history of the file, available from its original
- * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote
- *
- * SPDX-License-Identifier: GPL-3.0
- */
-
-#ifndef SMOLBOTE_PROFILEMANAGER_H
-#define SMOLBOTE_PROFILEMANAGER_H
-
-#include "webprofile.h"
-#include <QDir>
-#include <QFile>
-#include <QMap>
-#include <QMenu>
-#include <QObject>
-#include <QSettings>
-#include <functional>
-#include <map>
-#include <memory>
-
-class WebProfile;
-class ProfileManager : public QObject
-{
- Q_OBJECT
-public:
- explicit ProfileManager(const QHash<QString, QString> &profileSection, QObject *parent);
-
- WebProfile *createProfile(const QString &id, bool isOffTheRecord);
- WebProfile *loadProfile(const QString &path);
- void deleteProfile(const QString &id);
-
- void profilePickerMenu(QMenu *menu, WebProfile *current, std::function<void(WebProfile *)> callback) const;
- QMenu *createProfileMenu(std::function<void(WebProfile *)> callback, QWidget *parent = nullptr) const;
-
- const QStringList idList() const;
- const QString id(const WebProfile *profile) const;
- WebProfile *profile(const QString &id) const;
-
-private:
- struct ProfileData {
- explicit ProfileData(const QString &path = QString())
- : settings(path, QSettings::IniFormat)
- {
- this->path = path;
- }
-
- ~ProfileData()
- {
- if(!deleteSelf) {
-#ifdef QT_DEBUG
- qDebug("sync %s", qUtf8Printable(settings.fileName()));
-#endif
- this->settings.sync();
- } else {
- QFile::remove(path);
-
- if(!profile->isOffTheRecord()) {
- if(!profile->persistentStoragePath().isEmpty())
- QDir(profile->persistentStoragePath()).removeRecursively();
-
- if(!profile->cachePath().isEmpty())
- QDir(profile->cachePath()).removeRecursively();
- }
- }
- }
-
- WebProfile *profile = nullptr;
- bool deleteSelf = false;
- QSettings settings;
- QString path;
- };
-
- std::map<QString, std::unique_ptr<ProfileData>> m_profiles;
- const QHash<QString, QString> defaults;
-};
-
-#endif // SMOLBOTE_PROFILEMANAGER_H
diff --git a/lib/webprofile/meson.build b/lib/webprofile/meson.build
new file mode 100644
index 0000000..af4cfcb
--- /dev/null
+++ b/lib/webprofile/meson.build
@@ -0,0 +1,12 @@
+webprofile_lib = static_library('webprofile',
+ ['webprofilemanager.cpp', 'webprofile.cpp', interfaces_moc,
+ qt5.preprocess(moc_headers: ['webprofilemanager.h', 'webprofile.h'], dependencies: dep_qt5)],
+ dependencies: dep_qt5,
+ include_directories: [include]
+)
+
+dep_webprofile = declare_dependency(
+ include_directories: include_directories('.'),
+ link_with: webprofile_lib
+)
+
diff --git a/lib/web/webprofile.cpp b/lib/webprofile/webprofile.cpp
index 38aa7f0..ae6993e 100644
--- a/lib/web/webprofile.cpp
+++ b/lib/webprofile/webprofile.cpp
@@ -135,13 +135,13 @@ void WebProfile::setHttpUserAgent(const QString &userAgent)
emit propertyChanged("httpUserAgent", userAgent);
}
-void WebProfile::setHttpHeader(const QString& name, const QString& value)
+void WebProfile::setHttpHeader(const QString &name, const QString &value)
{
m_headers[name.toLatin1()] = value.toLatin1();
emit headerChanged(name, value);
}
-void WebProfile::removeHttpHeader(const QString& name)
+void WebProfile::removeHttpHeader(const QString &name)
{
if(m_headers.contains(name.toLatin1())) {
m_headers.remove(name.toLatin1());
diff --git a/lib/web/webprofile.h b/lib/webprofile/webprofile.h
index a3b5b12..37e3419 100644
--- a/lib/web/webprofile.h
+++ b/lib/webprofile/webprofile.h
@@ -10,12 +10,12 @@
#define SMOLBOTE_WEBENGINEPROFILE_H
#include <QHash>
-#include <QUrl>
+#include <QMap>
+#include <QNetworkCookie>
#include <QString>
-#include <QWebEngineProfile>
+#include <QUrl>
#include <QVector>
-#include <QNetworkCookie>
-#include <QMap>
+#include <QWebEngineProfile>
#include <QWebEngineSettings>
#include <profileinterface.h>
diff --git a/lib/webprofile/webprofilemanager.cpp b/lib/webprofile/webprofilemanager.cpp
new file mode 100644
index 0000000..d22b75c
--- /dev/null
+++ b/lib/webprofile/webprofilemanager.cpp
@@ -0,0 +1,150 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#include "webprofilemanager.h"
+#include "webprofile.h"
+#include <QFileInfo>
+#include <QWebEngineSettings>
+
+WebProfileManager::WebProfileManager(const QHash<QString, QString> &profileSection, QObject *parent)
+ : QObject(parent)
+ , defaults(profileSection)
+{
+}
+
+WebProfileManager::~WebProfileManager()
+{
+ for(Profile p : profiles) {
+ if(p.selfDestruct && p.settings != nullptr) {
+ if(!p.ptr->isOffTheRecord()) {
+ if(!p.ptr->persistentStoragePath().isEmpty())
+ QDir(p.ptr->persistentStoragePath()).removeRecursively();
+ if(!p.ptr->cachePath().isEmpty())
+ QDir(p.ptr->cachePath()).removeRecursively();
+ }
+ delete p.settings;
+ QFile::remove(p.settings->fileName());
+ } else if(p.settings != nullptr) {
+#ifdef QT_DEBUG
+ qDebug("sync %s", qUtf8Printable(p.settings->fileName()));
+#endif
+ p.settings->sync();
+ delete p.settings;
+ }
+ }
+}
+
+WebProfile *WebProfileManager::profile(const QString &id, const QString &path, bool isOffTheRecord)
+{
+ // Check if profile exists
+ if(profiles.contains(id))
+ return profiles.value(id).ptr;
+
+ Profile profile;
+
+ if(!path.isEmpty())
+ profile.settings = new QSettings(path, QSettings::IniFormat);
+
+ // QWebEngineCore cleans up profiles automatically, so no need to set parent
+ profile.ptr = [id, isOffTheRecord, profile]() {
+ if(isOffTheRecord)
+ return new WebProfile(/* name */ profile.value("name", id).toString(), /* parent */ nullptr);
+ else
+ return new WebProfile(/* storageName */ id, /* name */ profile.value("name", id).toString(), /* parent */ nullptr);
+ }();
+ if(profile.settings != nullptr)
+ profile.settings->setParent(profile.ptr);
+
+ connect(profile.ptr, &WebProfile::nameChanged, profile.settings, [profile](const QString &name) {
+ profile.settings->setValue("name", name);
+ });
+
+ profile.ptr->setSearch(profile.value("search", defaults.value("profile.search")).toString());
+ connect(profile.ptr, &WebProfile::searchChanged, profile.settings, [profile](const QString &url) {
+ profile.settings->setValue("search", url);
+ });
+
+ profile.ptr->setHomepage(profile.value("homepage", defaults.value("profile.homepage")).toUrl());
+ connect(profile.ptr, &WebProfile::homepageChanged, profile.settings, [profile](const QUrl &url) {
+ profile.settings->setValue("homepage", url);
+ });
+
+ profile.ptr->setNewtab(profile.value("newtab", defaults.value("profile.newtab")).toUrl());
+ connect(profile.ptr, &WebProfile::newtabChanged, profile.settings, [profile](const QUrl &url) {
+ profile.settings->setValue("newtab", url);
+ });
+
+ if(profile.settings != nullptr) {
+ profile.settings->beginGroup("properties");
+ {
+ const auto keys = profile.settings->childKeys();
+ for(const QString &key : keys) {
+ profile.ptr->setProperty(qUtf8Printable(key), profile.settings->value(key));
+ }
+ }
+ profile.settings->endGroup(); // properties
+ connect(profile.ptr, &WebProfile::propertyChanged, [profile](const QString &property, const QVariant &value) {
+ profile.settings->setValue("properties/" + property, value);
+ });
+
+ profile.settings->beginGroup("attributes");
+ {
+ const auto keys = profile.settings->childKeys();
+ auto *settings = profile.ptr->settings();
+ for(const QString &key : keys) {
+ auto attribute = static_cast<QWebEngineSettings::WebAttribute>(key.toInt());
+ settings->setAttribute(attribute, profile.settings->value(key).toBool());
+ }
+ }
+ profile.settings->endGroup();
+ connect(profile.ptr, &WebProfile::attributeChanged, [profile](const QWebEngineSettings::WebAttribute attr, const bool value) {
+ profile.settings->setValue("attributes/" + QString::number(attr), value);
+ });
+
+ // headers
+ profile.settings->beginGroup("headers");
+ for(const QString &key : profile.settings->childKeys()) {
+ profile.ptr->setHttpHeader(key.toLatin1(), profile.settings->value(key).toString().toLatin1());
+ }
+ profile.settings->endGroup();
+ connect(profile.ptr, &WebProfile::headerChanged, [profile](const QString &name, const QString &value) {
+ profile.settings->setValue("headers/" + name, value);
+ });
+ connect(profile.ptr, &WebProfile::headerRemoved, [profile](const QString &name) {
+ profile.settings->remove("headers/" + name);
+ });
+
+ } // profile.settings != nullptr
+
+ profiles[id] = profile;
+ return profile.ptr;
+}
+
+void WebProfileManager::deleteProfile(const QString &id)
+{
+ if(profiles.contains(id)) {
+ profiles[id].selfDestruct = true;
+ }
+}
+
+void WebProfileManager::profileMenu(QMenu *menu, std::function<void(WebProfile *)> callback, WebProfile *current, bool checkable) const
+{
+ auto *group = new QActionGroup(menu);
+ connect(menu, &QMenu::aboutToHide, group, &QActionGroup::deleteLater);
+
+ for(const auto &profile : profiles) {
+ auto *action = menu->addAction(profile.ptr->name(), profile.ptr, [profile, callback]() {
+ callback(profile.ptr);
+ });
+ action->setCheckable(checkable);
+ if(profile.ptr == current)
+ action->setChecked(true);
+ group->addAction(action);
+ }
+}
+
diff --git a/lib/webprofile/webprofilemanager.h b/lib/webprofile/webprofilemanager.h
new file mode 100644
index 0000000..822dc7d
--- /dev/null
+++ b/lib/webprofile/webprofilemanager.h
@@ -0,0 +1,78 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#ifndef SMOLBOTE_WEBPROFILEMANAGER_H
+#define SMOLBOTE_WEBPROFILEMANAGER_H
+
+#include "webprofile.h"
+#include <QDir>
+#include <QFile>
+#include <QMap>
+#include <QMenu>
+#include <QObject>
+#include <QSettings>
+#include <functional>
+
+class WebProfileManager : public QObject
+{
+ Q_OBJECT
+public:
+ explicit WebProfileManager(const QHash<QString, QString> &profileSection, QObject *parent);
+ ~WebProfileManager();
+
+ /** Create a profile with specified id
+ * param id The profile ID
+ * param path The path to the profile settings
+ * param isOffTheRecord Off-the-record toggle
+ * return WebProfile* The profile, or nullptr if one could not be created
+ */
+ WebProfile *profile(const QString &id, const QString &path = QString(), bool isOffTheRecord = true);
+
+ /** Set a profile for deletion
+ * param id The profile ID
+ * return void
+ */
+ void deleteProfile(const QString &id);
+
+ void profileMenu(QMenu *menu, std::function<void(WebProfile *)> callback, WebProfile *current = nullptr, bool checkable = false) const;
+
+ const QStringList idList() const
+ {
+ return profiles.keys();
+ }
+ QString id(WebProfile *profile) const
+ {
+ QMapIterator<QString, Profile> i(profiles);
+ while(i.hasNext()) {
+ i.next();
+ if(i.value().ptr == profile)
+ return i.key();
+ }
+ return QString();
+ }
+
+private:
+ struct Profile {
+ WebProfile *ptr = nullptr;
+ QSettings *settings = nullptr;
+ bool selfDestruct = false;
+
+ QVariant value(const QString &key, const QVariant &defaultValue) const
+ {
+ if(settings == nullptr)
+ return defaultValue;
+ else
+ return settings->value(key, defaultValue);
+ }
+ };
+
+ QMap<QString, Profile> profiles;
+ const QHash<QString, QString> defaults;
+};
+
+#endif // SMOLBOTE_PROFILEMANAGER_H
diff --git a/linux/.config b/linux/.config
index 3a2c718..b483d41 100644
--- a/linux/.config
+++ b/linux/.config
@@ -70,13 +70,7 @@ CONFIG_PROFILE_DEFAULT=""
CONFIG_PROFILE_DEFAULT_SEARCH="https://duckduckgo.com/?q=%1&ia=web"
CONFIG_PROFILE_DEFAULT_HOMEPAGE="about:blank"
CONFIG_PROFILE_DEFAULT_NEWTAB="about:blank"
-CONFIG_USEPLASMA=y
-
-#
-# KDE Integration
-#
-# CONFIG_PLASMA_BLUR is not set
-CONFIG_WALLET_FOLDER="smolbote"
+# CONFIG_USEPLASMA is not set
# CONFIG_USEBREAKPAD is not set
#
diff --git a/meson.build b/meson.build
index 1d333ca..be584ac 100644
--- a/meson.build
+++ b/meson.build
@@ -11,7 +11,7 @@ project('smolbote', 'cpp',
# Qt 5
qt5 = import('qt5')
-dep_qt5 = dependency('qt5', modules: ['Core', 'Network', 'Widgets', 'WebEngineWidgets', 'Test'])
+dep_qt5 = dependency('qt5', modules: ['Core', 'Network', 'Widgets', 'WebEngineWidgets', 'Concurrent', 'Test'])
# Boost
dep_boost = dependency('boost', modules: ['program_options'])
@@ -80,7 +80,7 @@ subdir('lib/bookmarks')
subdir('lib/configuration')
subdir('lib/downloads')
subdir('lib/urlfilter')
-subdir('lib/web')
+subdir('lib/webprofile')
subdir('3rd-party/SingleApplication')
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);
});
diff --git a/src/browser.h b/src/browser.h
index 8a40152..32011e0 100644
--- a/src/browser.h
+++ b/src/browser.h
@@ -24,7 +24,7 @@ class Configuration;
class BookmarksWidget;
class DownloadsWidget;
class MainWindow;
-class ProfileManager;
+class WebProfileManager;
class Browser : public SingleApplication, public BrowserInterface
{
Q_OBJECT
@@ -43,7 +43,7 @@ public:
const QString configuration(const QString &key) const override;
void setConfiguration(const QString &key, const QString &value) override;
- ProfileManager *getProfileManager();
+ WebProfileManager *getProfileManager();
const QList<QPair<QString, Profile *>> profileList() const override;
QPair<QString, Profile *> loadProfile(const QString &id, bool isOffTheRecord = true) override;
void removeProfile(const QString &id) override;
@@ -90,7 +90,7 @@ private:
std::unique_ptr<Configuration> m_config;
std::shared_ptr<BookmarksWidget> m_bookmarks;
std::unique_ptr<DownloadsWidget> m_downloads;
- ProfileManager *m_profileManager;
+ WebProfileManager *m_profileManager;
QVector<UrlFilter *> m_filters;
QVector<MainWindow *> m_windows;
diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp
index a5f1c90..71b594a 100644
--- a/src/mainwindow/mainwindow.cpp
+++ b/src/mainwindow/mainwindow.cpp
@@ -12,7 +12,7 @@
#include "config.h"
#include "configuration.h"
#include "menubar.h"
-#include "profilemanager.h"
+#include "webprofilemanager.h"
#include "session/session.h"
#include "session/sessiondialog.h"
#include "subwindow/subwindow.h"
diff --git a/src/mainwindow/menubar.cpp b/src/mainwindow/menubar.cpp
index 8e2180d..117641f 100644
--- a/src/mainwindow/menubar.cpp
+++ b/src/mainwindow/menubar.cpp
@@ -12,7 +12,7 @@
#include "configuration.h"
#include "downloadswidget.h"
#include "mainwindow.h"
-#include "profilemanager.h"
+#include "webprofilemanager.h"
#include "session/savesessiondialog.h"
#include "session/sessiondialog.h"
#include "subwindow/subwindow.h"
@@ -344,9 +344,9 @@ MenuBar::MenuBar(const Configuration *config, MainWindow *parent)
auto *_subwindow = parent->currentSubWindow();
if(_subwindow != nullptr) {
- browser->getProfileManager()->profilePickerMenu(subwindowProfile, _subwindow->profile(), [_subwindow](WebProfile *profile) {
+ browser->getProfileManager()->profileMenu(subwindowProfile, [_subwindow](WebProfile *profile) {
_subwindow->setProfile(profile);
- });
+ }, _subwindow->profile(), true);
}
});
}
@@ -391,9 +391,9 @@ MenuBar::MenuBar(const Configuration *config, MainWindow *parent)
pageProfile->clear();
if(parent->currentView != nullptr) {
- browser->getProfileManager()->profilePickerMenu(pageProfile, parent->currentView->profile(), [parent](WebProfile *profile) {
+ browser->getProfileManager()->profileMenu(pageProfile, [parent](WebProfile *profile) {
parent->currentView->setProfile(profile);
- });
+ }, parent->currentView->profile(), true);
}
});
diff --git a/src/meson.build b/src/meson.build
index fb338d8..ce4e216 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -14,7 +14,7 @@ poi_moc = qt5.preprocess(
poi = executable(get_option('poiName'), install: true,
cpp_args: ['-DQAPPLICATION_CLASS=QApplication'],
dependencies: [dep_qt5, dep_boost, dep_SingleApplication, dep_genheaders, dep_breakpad, dep_plasma,
- dep_about, dep_addressbar, dep_bookmarks, dep_configuration, dep_downloads, dep_urlfilter, dep_web],
+ dep_about, dep_addressbar, dep_bookmarks, dep_configuration, dep_downloads, dep_urlfilter, dep_webprofile],
include_directories: [include],
sources: ['main.cpp', 'builtins.cpp', 'crashhandler.cpp', poi_moc,
'browser.cpp',
diff --git a/src/session/savesessiondialog.cpp b/src/session/savesessiondialog.cpp
index 808ba45..9291215 100644
--- a/src/session/savesessiondialog.cpp
+++ b/src/session/savesessiondialog.cpp
@@ -9,7 +9,7 @@
#include "savesessiondialog.h"
#include "browser.h"
#include "mainwindow/mainwindow.h"
-#include "profilemanager.h"
+#include "webprofilemanager.h"
#include "subwindow/subwindow.h"
#include "ui_savesessiondialog.h"
#include "webengine/webview.h"
diff --git a/src/session/session.cpp b/src/session/session.cpp
index f7d372b..51575bf 100644
--- a/src/session/session.cpp
+++ b/src/session/session.cpp
@@ -10,7 +10,7 @@
#include "../webengine/webview.h"
#include "browser.h"
#include "mainwindow/mainwindow.h"
-#include "profilemanager.h"
+#include "webprofilemanager.h"
#include "subwindow/subwindow.h"
#include "webengine/webview.h"
#include <QJsonArray>
diff --git a/src/subwindow/subwindow.cpp b/src/subwindow/subwindow.cpp
index 76eddb3..31b49b9 100644
--- a/src/subwindow/subwindow.cpp
+++ b/src/subwindow/subwindow.cpp
@@ -20,7 +20,6 @@
#include <QTabBar>
#include <QToolButton>
#include "configuration.h"
-#include "profilemanager.h"
#include "webprofile.h"
SubWindow::SubWindow(const Configuration *config, QWidget *parent, Qt::WindowFlags flags)
@@ -35,32 +34,6 @@ SubWindow::SubWindow(const Configuration *config, QWidget *parent, Qt::WindowFla
m_profile = WebProfile::defaultProfile();
- // system menu
- {
- QMenu *menu = systemMenu();
- auto *firstAction = menu->actions().at(0);
-
- auto *profileName_action = new QAction(tr("Profile: %1").arg(m_profile->name()), menu);
- profileName_action->setEnabled(false);
- menu->insertAction(firstAction, profileName_action);
-
- auto *loadProfile_menu = new QMenu(tr("Load profile"), menu);
- menu->insertMenu(firstAction, loadProfile_menu);
-
- Browser *browser = qobject_cast<Browser *>(qApp);
- Q_CHECK_PTR(browser);
-
- auto *profileManager = dynamic_cast<Browser *>(qApp)->getProfileManager();
- loadProfile_menu->addActions(profileManager->createProfileMenu([this, profileName_action](WebProfile *profile) {
- this->setProfile(profile);
- profileName_action->setText(tr("Profile: %1").arg(profile->name()));
- },
- this)
- ->actions());
-
- menu->insertSeparator(firstAction);
- }
-
auto *fullScreen_shortcut = new QShortcut(QKeySequence(config->value<QString>("subwindow.shortcuts.fullscreen").value()), this);
connect(fullScreen_shortcut, &QShortcut::activated, this, [=]() {
auto *w = this->window();
diff --git a/src/webengine/webview.cpp b/src/webengine/webview.cpp
index 3861306..5e350eb 100644
--- a/src/webengine/webview.cpp
+++ b/src/webengine/webview.cpp
@@ -20,7 +20,7 @@
#include <QWebEngineContextMenuData>
#include <QWebEngineHistoryItem>
#include <QWidgetAction>
-#include "profilemanager.h"
+#include "webprofilemanager.h"
#include "webprofile.h"
#include "browser.h"
#include "wallet/wallet.h"
@@ -247,15 +247,12 @@ void WebView::contextMenuEvent(QContextMenuEvent *event)
createWindow(QWebEnginePage::WebBrowserTab)->load(ctxdata.linkUrl());
});
- auto *profileManager = dynamic_cast<Browser *>(qApp)->getProfileManager();
- QMenu *newTabMenu = profileManager->createProfileMenu([this, ctxdata](WebProfile *profile) {
+ auto *newTabMenu = menu->addMenu(tr("Open link in new tab with profile"));
+ dynamic_cast<Browser*>(qApp)->getProfileManager()->profileMenu(newTabMenu, [this, ctxdata](WebProfile *profile) {
auto *view = this->createWindow(QWebEnginePage::WebBrowserTab);
view->setProfile(profile);
view->load(ctxdata.linkUrl());
- },
- this);
- newTabMenu->setTitle(tr("Open link in new tab with profile"));
- menu->addMenu(newTabMenu);
+ });
connect(menu->addAction(tr("Open link in new window")), &QAction::triggered, this, [this, ctxdata]() {
createWindow(QWebEnginePage::WebBrowserWindow)->load(ctxdata.linkUrl());