From e81526f15e8c1e9c82b27009dbe512f78cf1dc0f Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sun, 24 Jun 2018 17:27:44 +0200 Subject: Add Session class --- lib/web/webprofile.cpp | 9 ++++++++- lib/web/webprofile.h | 11 ++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/web/webprofile.cpp b/lib/web/webprofile.cpp index 1124261..1613e52 100644 --- a/lib/web/webprofile.cpp +++ b/lib/web/webprofile.cpp @@ -13,8 +13,9 @@ #include WebProfile *WebProfile::profile = nullptr; +QMap WebProfile::profiles; -WebProfile* loadProfile(const QString &name, const QHash &defaults, const QString &path, QObject *parent) +WebProfile* WebProfile::loadProfile(const QString &name, const QHash &defaults, const QString &path, QObject *parent) { WebProfile *profile = nullptr; #ifdef QT_DEBUG @@ -36,6 +37,7 @@ WebProfile* loadProfile(const QString &name, const QHash &defa } Q_CHECK_PTR(profile); + profiles.insert(name, profile); profile->setSearch(config.value("search", defaults.value("profile.search")).toString()); profile->setHomepage(config.value("homepage", defaults.value("profile.homepage")).toUrl()); @@ -73,6 +75,10 @@ WebProfile* loadProfile(const QString &name, const QHash &defa WebProfile::WebProfile(const QString &name, const QString &configPath, QObject *parent) : QWebEngineProfile(parent) { + if(configPath.isEmpty()) + m_id = configPath; + else + m_id = QFileInfo(configPath).baseName(); m_name = name; m_configPath = configPath; @@ -91,6 +97,7 @@ WebProfile::WebProfile(const QString &name, const QString &configPath, QObject * WebProfile::WebProfile(const QString &storageName, const QString &name, const QString &configPath, QObject *parent) : QWebEngineProfile(storageName, parent) { + m_id = QFileInfo(configPath).baseName(); m_name = name; m_configPath = configPath; diff --git a/lib/web/webprofile.h b/lib/web/webprofile.h index 279e6bf..d41625c 100644 --- a/lib/web/webprofile.h +++ b/lib/web/webprofile.h @@ -15,6 +15,7 @@ #include #include #include +#include class WebProfile : public QWebEngineProfile { @@ -53,6 +54,13 @@ public: return WebProfile::profile; } + static WebProfile* loadProfile(const QString &name, const QHash &defaults, const QString &path = QString(), QObject *parent = nullptr); + + const QString id() const + { + return profiles.key(const_cast(this), ""); + } + QString name() const { return m_name; @@ -104,7 +112,9 @@ signals: private: static WebProfile *profile; + static QMap profiles; + QString m_id; QString m_configPath; QString m_name; QString m_search = QString("about:blank"); @@ -114,7 +124,6 @@ private: QVector m_cookies; }; -WebProfile* loadProfile(const QString &name, const QHash &defaults, const QString &path = QString(), QObject *parent = nullptr); //WebProfile *saveProfile(WebProfile *profile, const QString &path); #endif // SMOLBOTE_WEBENGINEPROFILE_H -- cgit v1.2.1