From 99917ab581314f9517569401bc79e150e4ce0881 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Fri, 8 Jun 2018 15:00:22 +0200 Subject: Better profile loading First load all profiles from profile.path, and then the profile.default if missing, after which set the default profile. Profile names and whether they're otr can be set by .profile name=string and otr=bool. --- lib/configuration/configuration.h | 3 ++- lib/web/webprofile.cpp | 46 ++++++++++++++++++++++++--------------- lib/web/webprofile.h | 6 ++--- 3 files changed, 34 insertions(+), 21 deletions(-) (limited to 'lib') diff --git a/lib/configuration/configuration.h b/lib/configuration/configuration.h index 1df6bb5..59c837c 100644 --- a/lib/configuration/configuration.h +++ b/lib/configuration/configuration.h @@ -49,7 +49,8 @@ public: } if constexpr(std::is_same_v) { - return std::optional(vm[path].as()); + return std::optional(QString::fromStdString(this->value(path).value())); + //return std::optional(vm[path].as()); } else if constexpr(std::is_same_v) { diff --git a/lib/web/webprofile.cpp b/lib/web/webprofile.cpp index b40a98c..67671a0 100644 --- a/lib/web/webprofile.cpp +++ b/lib/web/webprofile.cpp @@ -14,23 +14,33 @@ WebProfile *WebProfile::profile = nullptr; -void loadProfile(WebProfile *profile, const QHash &defaults, const QString &path) +WebProfile* loadProfile(const QString &name, const QHash &defaults, const QString &path) { - Q_CHECK_PTR(profile); - - profile->setSearch(defaults.value("profile.search")); - profile->setHomepage(QUrl::fromUserInput(defaults.value("profile.homepage"))); - profile->setNewtab(QUrl::fromUserInput(defaults.value("profile.newtab"))); - - // return if there is no config file - if(!QFileInfo::exists(path)) - return; - + WebProfile *profile = nullptr; #ifdef QT_DEBUG - qDebug("+ Reading config for profile '%s': %s", qUtf8Printable(profile->name()), qUtf8Printable(path)); + qDebug("+ Reading config for profile '%s': %s", qUtf8Printable(name), qUtf8Printable(path)); #endif QSettings config(path, QSettings::IniFormat); + if(name.isEmpty()) { + // a default otr profile + profile = new WebProfile(QObject::tr("Off-the-record"), nullptr); + + } else if(config.value("otr").toBool()) { + // a named otr profile + profile = new WebProfile(config.value("name", name).toString(), nullptr); + + } else { + // a named profile + profile = new WebProfile(name, config.value("name", name).toString(), nullptr); + } + + Q_CHECK_PTR(profile); + + profile->setSearch(config.value("search", defaults.value("profile.search")).toString()); + profile->setHomepage(config.value("homepage", defaults.value("profile.homepage")).toUrl()); + profile->setNewtab(config.value("newtab", defaults.value("profile.newtab")).toUrl()); + config.beginGroup("properties"); { const auto keys = config.childKeys(); @@ -56,20 +66,22 @@ void loadProfile(WebProfile *profile, const QHash &defaults, c } } config.endGroup(); + + return profile; } -WebProfile::WebProfile(QObject *parent) +WebProfile::WebProfile(const QString &name, QObject *parent) : QWebEngineProfile(parent) { - m_name = tr("Off-the-record"); + m_name = name; #ifdef QT_DEBUG - qDebug("Creating off-the-record profile"); + qDebug("Creating otr profile %s", qUtf8Printable(m_name)); #endif } -WebProfile::WebProfile(const QString &name, QObject *parent) - : QWebEngineProfile(name, parent) +WebProfile::WebProfile(const QString &storageName, const QString &name, QObject *parent) + : QWebEngineProfile(storageName, parent) { m_name = name; diff --git a/lib/web/webprofile.h b/lib/web/webprofile.h index 31c5b44..a421359 100644 --- a/lib/web/webprofile.h +++ b/lib/web/webprofile.h @@ -34,9 +34,9 @@ class WebProfile : public QWebEngineProfile public: // off-the-record constructor - explicit WebProfile(QObject *parent = nullptr); - // default constructor explicit WebProfile(const QString &name, QObject *parent = nullptr); + // default constructor + explicit WebProfile(const QString &storageName, const QString &name, QObject *parent = nullptr); ~WebProfile() = default; @@ -108,7 +108,7 @@ private: QUrl m_newtab = QUrl("about:blank"); }; -void loadProfile(WebProfile *profile, const QHash &defaults, const QString &path); +WebProfile* loadProfile(const QString &name, const QHash &defaults, const QString &path = QString()); //WebProfile *saveProfile(WebProfile *profile, const QString &path); #endif // SMOLBOTE_WEBENGINEPROFILE_H -- cgit v1.2.1