diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-06-08 15:00:22 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-06-08 15:00:22 +0200 |
commit | 99917ab581314f9517569401bc79e150e4ce0881 (patch) | |
tree | bed6fa884a0925e104f9e15c399c1b5e91683a2b /lib/web/webprofile.cpp | |
parent | Improve plugin loading (diff) | |
download | smolbote-99917ab581314f9517569401bc79e150e4ce0881.tar.xz |
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.
Diffstat (limited to 'lib/web/webprofile.cpp')
-rw-r--r-- | lib/web/webprofile.cpp | 46 |
1 files changed, 29 insertions, 17 deletions
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<QString, QString> &defaults, const QString &path) +WebProfile* loadProfile(const QString &name, const QHash<QString, QString> &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<QString, QString> &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; |