1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
/*
* This file is part of smolbote. It's copyrighted by the contributors recorded
* in the version control history of the file, available from its original
* location: https://neueland.iserlohn-fortress.net/smolbote.hg
*
* SPDX-License-Identifier: GPL-3.0
*/
#include "webprofile.h"
#include <QFileInfo>
#include <QSettings>
#include <QWebEngineCookieStore>
#include <QWebEngineSettings>
WebProfile *WebProfile::profile = nullptr;
void loadProfile(WebProfile *profile, const QString &path)
{
// return if there is no config file
if(!QFileInfo::exists(path))
return;
#ifdef QT_DEBUG
qDebug("Reading config for profile '%s': %s", qUtf8Printable(profile->name()), qUtf8Printable(path));
#endif
QSettings config(path, QSettings::IniFormat);
config.beginGroup("properties");
for(const QString &key : config.childKeys()) {
#ifdef QT_DEBUG
qDebug("set property %s to %s", qUtf8Printable(key), qUtf8Printable(config.value(key).toString()));
#endif
profile->setProperty(qUtf8Printable(key), config.value(key));
}
config.endGroup(); // properties
config.beginGroup("attributes");
auto *settings = profile->settings();
for(const QString &key : config.childKeys()) {
#ifdef QT_DEBUG
qDebug("set attribute %s to %s", qUtf8Printable(key), qUtf8Printable(config.value(key).toString()));
#endif
auto attribute = static_cast<QWebEngineSettings::WebAttribute>(key.toInt());
settings->setAttribute(attribute, config.value(key).toBool());
}
config.endGroup();
// config.beginGroup("http");
// setHttpUserAgent(config.value("userAgent", httpUserAgent()).toString());
// setHttpAcceptLanguage(config.value("accept-lang", httpAcceptLanguage()).toString());
// {
// QString cacheType = config.value("cacheType").toString();
// if(cacheType == "memory") {
// setHttpCacheType(QWebEngineProfile::MemoryHttpCache);
// } else if(cacheType == "disk") {
// setHttpCacheType(QWebEngineProfile::DiskHttpCache);
// } else if(cacheType == "disabled") {
// setHttpCacheType(QWebEngineProfile::NoCache);
// }
// }
// setHttpCacheMaximumSize(config.value("cacheSize", httpCacheMaximumSize()).toInt());
// config.endGroup(); // http
// config.beginGroup("policy");
// {
// QString cookies = config.value("cookies").toString();
// if(cookies == "disabled") {
// setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies);
// } else if(cookies == "allow") {
// setPersistentCookiesPolicy(QWebEngineProfile::AllowPersistentCookies);
// } else if(cookies == "force") {
// setPersistentCookiesPolicy(QWebEngineProfile::ForcePersistentCookies);
// }
// }
// config.endGroup(); // policy
}
WebProfile::WebProfile(const QHash<QString, QString> &defaults, QObject *parent)
: QWebEngineProfile(parent)
{
m_name = tr("Off-the-record");
#ifdef QT_DEBUG
qDebug("Creating off-the-record profile");
#endif
m_search = defaults.value("profile.search");
m_homepage = QUrl::fromUserInput(defaults.value("profile.homepage"));
m_newtab = QUrl::fromUserInput(defaults.value("profile.newtab"));
}
WebProfile::WebProfile(const QString &name, QObject *parent)
: QWebEngineProfile(name, parent)
{
m_name = name;
#ifdef QT_DEBUG
qDebug("Creating profile %s", qUtf8Printable(m_name));
#endif
}
WebProfile::~WebProfile() = default;
|