/* * 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 #include #include #include 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"); { const auto keys = config.childKeys(); for(const QString &key : keys) { #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"); { const auto keys = config.childKeys(); auto *settings = profile->settings(); for(const QString &key : keys) { #ifdef QT_DEBUG qDebug("- set attribute %s to %s", qUtf8Printable(key), qUtf8Printable(config.value(key).toString())); #endif auto attribute = static_cast(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 &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;