From 5e6920c427b30232e47039d26cbaec7173c837d2 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sat, 8 Sep 2018 15:41:10 +0200 Subject: Save WebProfile config when changed --- lib/web/profilemanager.cpp | 15 ++++++++++++--- lib/web/webprofile.cpp | 23 +++++++++++++++++------ lib/web/webprofile.h | 33 +++++++++++++-------------------- 3 files changed, 42 insertions(+), 29 deletions(-) (limited to 'lib') diff --git a/lib/web/profilemanager.cpp b/lib/web/profilemanager.cpp index b747bf6..960a03a 100644 --- a/lib/web/profilemanager.cpp +++ b/lib/web/profilemanager.cpp @@ -41,19 +41,22 @@ WebProfile *ProfileManager::loadProfile(const QString &path) ptr->profile = new WebProfile(id, ptr->settings.value("name", id).toString(), nullptr); } Q_CHECK_PTR(ptr->profile); + connect(ptr->profile, &WebProfile::nameChanged, [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->settings, [this, id](const QString &url) { + connect(ptr->profile, &WebProfile::searchChanged, [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->settings, [this, id](const QUrl &url) { + connect(ptr->profile, &WebProfile::homepageChanged, [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->settings, [this, id](const QUrl &url) { + connect(ptr->profile, &WebProfile::newtabChanged, [this, id](const QUrl &url) { this->m_profiles.at(id)->settings.setValue("newtab", url); }); @@ -65,6 +68,9 @@ WebProfile *ProfileManager::loadProfile(const QString &path) } } ptr->settings.endGroup(); // properties + connect(ptr->profile, &WebProfile::propertyChanged, [this, id](const QString &property, const QVariant &value) { + this->m_profiles.at(id)->settings.setValue("properties/" + property, value); + }); ptr->settings.beginGroup("attributes"); { @@ -76,6 +82,9 @@ WebProfile *ProfileManager::loadProfile(const QString &path) } } ptr->settings.endGroup(); + connect(ptr->profile, &WebProfile::attributeChanged, [this, id](const QWebEngineSettings::WebAttribute attr, const bool value) { + this->m_profiles.at(id)->settings.setValue("attributes/" + QString::number(attr), value); + }); m_profiles[id] = std::move(ptr); return m_profiles.at(id)->profile; diff --git a/lib/web/webprofile.cpp b/lib/web/webprofile.cpp index d42bb26..4d31376 100644 --- a/lib/web/webprofile.cpp +++ b/lib/web/webprofile.cpp @@ -48,6 +48,17 @@ WebProfile::WebProfile(const QString &storageName, const QString &name, QObject }); } +const QString WebProfile::name() const +{ + return m_name; +} + +void WebProfile::setName(const QString &name) +{ + m_name = name; + emit nameChanged(name); +} + QString WebProfile::search() const { return m_search; @@ -84,35 +95,35 @@ void WebProfile::setNewtab(const QUrl &url) void WebProfile::setCachePath(const QString &path) { QWebEngineProfile::setCachePath(path); - emit cachePathChanged(QWebEngineProfile::cachePath()); + emit propertyChanged("cachePath", path); } void WebProfile::setPersistentStoragePath(const QString &path) { QWebEngineProfile::setPersistentStoragePath(path); - emit persistentStoragePathChanged(QWebEngineProfile::persistentStoragePath()); + emit propertyChanged("persistentStoragePath", path); } void WebProfile::setHttpAcceptLanguage(const QString &httpAcceptLanguage) { QWebEngineProfile::setHttpAcceptLanguage(httpAcceptLanguage); - emit httpAcceptLanguageChanged(QWebEngineProfile::httpAcceptLanguage()); + emit propertyChanged("httpAcceptLanguage", httpAcceptLanguage); } void WebProfile::setHttpCacheMaximumSize(int maxSize) { QWebEngineProfile::setHttpCacheMaximumSize(maxSize); - emit httpCacheMaximumSizeChanged(QWebEngineProfile::httpCacheMaximumSize()); + emit propertyChanged("httpCacheMaximumSize", maxSize); } void WebProfile::setHttpUserAgent(const QString &userAgent) { QWebEngineProfile::setHttpUserAgent(userAgent); - emit httpUserAgentChanged(QWebEngineProfile::httpUserAgent()); + emit propertyChanged("httpUserAgent", userAgent); } void WebProfile::setSpellCheckEnabled(bool enable) { QWebEngineProfile::setSpellCheckEnabled(enable); - emit spellCheckEnabledChanged(QWebEngineProfile::isSpellCheckEnabled()); + emit propertyChanged("spellCheckEnabed", enable); } diff --git a/lib/web/webprofile.h b/lib/web/webprofile.h index 260ff36..2282afe 100644 --- a/lib/web/webprofile.h +++ b/lib/web/webprofile.h @@ -16,24 +16,26 @@ #include #include #include +#include class WebProfile : public QWebEngineProfile { Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) Q_PROPERTY(QString search READ search WRITE setSearch NOTIFY searchChanged) Q_PROPERTY(QUrl homepage READ homepage WRITE setHomepage NOTIFY homepageChanged) Q_PROPERTY(QUrl newtab READ newtab WRITE setNewtab NOTIFY newtabChanged) // QWebEngineProfile should-be properties - Q_PROPERTY(QString cachePath READ cachePath WRITE setCachePath NOTIFY cachePathChanged) - Q_PROPERTY(QString persistentStoragePath READ persistentStoragePath WRITE setPersistentStoragePath NOTIFY persistentStoragePathChanged) + Q_PROPERTY(QString cachePath READ cachePath WRITE setCachePath NOTIFY propertyChanged) + Q_PROPERTY(QString persistentStoragePath READ persistentStoragePath WRITE setPersistentStoragePath NOTIFY propertyChanged) - Q_PROPERTY(QString httpAcceptLanguage READ httpAcceptLanguage WRITE setHttpAcceptLanguage NOTIFY httpAcceptLanguageChanged) - Q_PROPERTY(int httpCacheMaximumSize READ httpCacheMaximumSize WRITE setHttpCacheMaximumSize NOTIFY httpCacheMaximumSizeChanged) - Q_PROPERTY(QString httpUserAgent READ httpUserAgent WRITE setHttpUserAgent NOTIFY httpUserAgentChanged) + Q_PROPERTY(QString httpAcceptLanguage READ httpAcceptLanguage WRITE setHttpAcceptLanguage NOTIFY propertyChanged) + Q_PROPERTY(int httpCacheMaximumSize READ httpCacheMaximumSize WRITE setHttpCacheMaximumSize NOTIFY propertyChanged) + Q_PROPERTY(QString httpUserAgent READ httpUserAgent WRITE setHttpUserAgent NOTIFY propertyChanged) - Q_PROPERTY(bool spellCheckEnabled READ isSpellCheckEnabled WRITE setSpellCheckEnabled NOTIFY spellCheckEnabledChanged) + Q_PROPERTY(bool spellCheckEnabled READ isSpellCheckEnabled WRITE setSpellCheckEnabled NOTIFY propertyChanged) public: // off-the-record constructor @@ -54,10 +56,8 @@ public: return WebProfile::profile; } - QString name() const - { - return m_name; - } + const QString name() const; + void setName(const QString &name); const QVector cookies() const { @@ -86,18 +86,13 @@ public: void setSpellCheckEnabled(bool enable); signals: + void nameChanged(const QString &name); void searchChanged(const QString &url); void homepageChanged(const QUrl &url); void newtabChanged(const QUrl &url); - void cachePathChanged(const QString &path); - void persistentStoragePathChanged(const QString &path); - - void httpAcceptLanguageChanged(const QString &httpAcceptLanguage); - void httpCacheMaximumSizeChanged(int maxSize); - void httpUserAgentChanged(const QString &userAgent); - - void spellCheckEnabledChanged(bool enable); + void propertyChanged(const QString &name, const QVariant &value); + void attributeChanged(const QWebEngineSettings::WebAttribute attribute, const bool value); private: static WebProfile *profile; @@ -110,6 +105,4 @@ private: QVector m_cookies; }; -//WebProfile *saveProfile(WebProfile *profile, const QString &path); - #endif // SMOLBOTE_WEBENGINEPROFILE_H -- cgit v1.2.1