aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-06-08 15:00:22 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-06-08 15:00:22 +0200
commit99917ab581314f9517569401bc79e150e4ce0881 (patch)
treebed6fa884a0925e104f9e15c399c1b5e91683a2b /lib
parentImprove plugin loading (diff)
downloadsmolbote-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')
-rw-r--r--lib/configuration/configuration.h3
-rw-r--r--lib/web/webprofile.cpp46
-rw-r--r--lib/web/webprofile.h6
3 files changed, 34 insertions, 21 deletions
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<T, QString>) {
- return std::optional<QString>(vm[path].as<const char*>());
+ return std::optional<QString>(QString::fromStdString(this->value<std::string>(path).value()));
+ //return std::optional<QString>(vm[path].as<const char*>());
} else if constexpr(std::is_same_v<T, std::string>) {
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;
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<QString, QString> &defaults, const QString &path);
+WebProfile* loadProfile(const QString &name, const QHash<QString, QString> &defaults, const QString &path = QString());
//WebProfile *saveProfile(WebProfile *profile, const QString &path);
#endif // SMOLBOTE_WEBENGINEPROFILE_H