diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2019-11-22 19:34:09 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2019-11-22 20:05:31 +0200 |
commit | 62c3898d8e18a872700948c46a61592b315e79de (patch) | |
tree | 81f03b3012c07510202065f03aaec8cd1f9591fb | |
parent | Configuration: only try reading it when cfg file can be opened (diff) | |
download | smolbote-62c3898d8e18a872700948c46a61592b315e79de.tar.xz |
WebProfile refactoring
- Remove WebProfileManager::Profile::value
- Make WebProfile constructors protected, and WebProfileManager friend
class
-rw-r--r-- | src/webengine/webprofile.cpp | 13 | ||||
-rw-r--r-- | src/webengine/webprofile.h | 28 | ||||
-rw-r--r-- | src/webengine/webprofilemanager.cpp | 21 | ||||
-rw-r--r-- | src/webengine/webprofilemanager.h | 15 | ||||
-rw-r--r-- | test/cli/cli.cpp (renamed from src/cli/cli.cpp) | 0 | ||||
-rw-r--r-- | test/cli/meson.build (renamed from src/cli/meson.build) | 0 |
6 files changed, 34 insertions, 43 deletions
diff --git a/src/webengine/webprofile.cpp b/src/webengine/webprofile.cpp index 843b78e..2cea409 100644 --- a/src/webengine/webprofile.cpp +++ b/src/webengine/webprofile.cpp @@ -12,7 +12,18 @@ #include <QWebEngineCookieStore> #include <QWebEngineSettings> -WebProfile *WebProfile::profile = nullptr; +static WebProfile *s_profile = nullptr; + +void WebProfile::setDefaultProfile(WebProfile *profile) +{ + Q_CHECK_PTR(profile); + s_profile = profile; +} +WebProfile *WebProfile::defaultProfile() +{ + Q_CHECK_PTR(s_profile); + return s_profile; +} WebProfile::WebProfile(const QString &name, QObject *parent) : Profile(parent) diff --git a/src/webengine/webprofile.h b/src/webengine/webprofile.h index 37e3419..1ec2b88 100644 --- a/src/webengine/webprofile.h +++ b/src/webengine/webprofile.h @@ -19,29 +19,19 @@ #include <QWebEngineSettings> #include <profileinterface.h> +class WebProfileManager; class WebProfile : public Profile { + friend class WebProfileManager; + Q_OBJECT public: - // off-the-record constructor - explicit WebProfile(const QString &name, QObject *parent = nullptr); - // default constructor - explicit WebProfile(const QString &storageName, const QString &name, QObject *parent = nullptr); + static WebProfile *defaultProfile(); + static void setDefaultProfile(WebProfile *profile); ~WebProfile() = default; - static void setDefaultProfile(WebProfile *profile) - { - Q_CHECK_PTR(profile); - WebProfile::profile = profile; - } - static WebProfile *defaultProfile() - { - Q_CHECK_PTR(WebProfile::profile); - return WebProfile::profile; - } - const QString name() const; void setName(const QString &name); @@ -79,9 +69,13 @@ public: void setSpellCheckEnabled(bool enable); -private: - static WebProfile *profile; +protected: + // off-the-record constructor + explicit WebProfile(const QString &name, QObject *parent = nullptr); + // default constructor + explicit WebProfile(const QString &storageName, const QString &name, QObject *parent = nullptr); +private: QString m_name; QString m_search = QString("about:blank"); QUrl m_homepage = QUrl("about:blank"); diff --git a/src/webengine/webprofilemanager.cpp b/src/webengine/webprofilemanager.cpp index 3f3d5ba..2fe6222 100644 --- a/src/webengine/webprofilemanager.cpp +++ b/src/webengine/webprofilemanager.cpp @@ -7,10 +7,10 @@ */ #include "webprofilemanager.h" +#include "configuration.h" #include "webprofile.h" #include <QFileInfo> #include <QWebEngineSettings> -#include "configuration.h" WebProfileManager::WebProfileManager(QObject *parent) : QObject(parent) @@ -48,32 +48,34 @@ WebProfile *WebProfileManager::profile(const QString &id, const QString &path, b if(!path.isEmpty()) profile.settings = new QSettings(path, QSettings::IniFormat); + else + profile.settings = new QSettings; // QWebEngineCore cleans up profiles automatically, so no need to set parent profile.ptr = [id, isOffTheRecord, profile]() { - if(profile.value("otr", isOffTheRecord).toBool()) - return new WebProfile(/* name */ profile.value("name", id).toString(), /* parent */ nullptr); + if(profile.settings->value("otr", isOffTheRecord).toBool()) + return new WebProfile(/* name */ profile.settings->value("name", id).toString(), /* parent */ nullptr); else - return new WebProfile(/* storageName */ id, /* name */ profile.value("name", id).toString(), /* parent */ nullptr); + return new WebProfile(/* storageName */ id, /* name */ profile.settings->value("name", id).toString(), /* parent */ nullptr); }(); - if(profile.settings != nullptr) - profile.settings->setParent(profile.ptr); + + 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", conf.value<QString>("profile.search").value()).toString()); + profile.ptr->setSearch(profile.settings->value("search", conf.value<QString>("profile.search").value()).toString()); connect(profile.ptr, &WebProfile::searchChanged, profile.settings, [profile](const QString &url) { profile.settings->setValue("search", url); }); - profile.ptr->setHomepage(profile.value("homepage", conf.value<QString>("profile.homepage").value()).toUrl()); + profile.ptr->setHomepage(profile.settings->value("homepage", conf.value<QString>("profile.homepage").value()).toUrl()); connect(profile.ptr, &WebProfile::homepageChanged, profile.settings, [profile](const QUrl &url) { profile.settings->setValue("homepage", url); }); - profile.ptr->setNewtab(profile.value("newtab", conf.value<QString>("profile.newtab").value()).toUrl()); + profile.ptr->setNewtab(profile.settings->value("newtab", conf.value<QString>("profile.newtab").value()).toUrl()); connect(profile.ptr, &WebProfile::newtabChanged, profile.settings, [profile](const QUrl &url) { profile.settings->setValue("newtab", url); }); @@ -146,4 +148,3 @@ void WebProfileManager::profileMenu(QMenu *menu, const std::function<void(WebPro group->addAction(action); } } - diff --git a/src/webengine/webprofilemanager.h b/src/webengine/webprofilemanager.h index 3e82936..2d9cd29 100644 --- a/src/webengine/webprofilemanager.h +++ b/src/webengine/webprofilemanager.h @@ -18,13 +18,6 @@ #include <QSettings> #include <functional> -struct ProfileDefault_t -{ - QString search; - QString homepage; - QString newtab; -}; - class WebProfileManager : public QObject { Q_OBJECT @@ -68,14 +61,6 @@ private: 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; diff --git a/src/cli/cli.cpp b/test/cli/cli.cpp index 322c365..322c365 100644 --- a/src/cli/cli.cpp +++ b/test/cli/cli.cpp diff --git a/src/cli/meson.build b/test/cli/meson.build index 298e1db..298e1db 100644 --- a/src/cli/meson.build +++ b/test/cli/meson.build |