From e9c6cdefff00daffb8b07e72c47f8e8f845ba436 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Tue, 15 Dec 2020 11:51:08 +0200 Subject: Move src/webengine to lib/webengine --- src/webengine/webprofile.cpp | 138 ------------------------------------------- 1 file changed, 138 deletions(-) delete mode 100644 src/webengine/webprofile.cpp (limited to 'src/webengine/webprofile.cpp') diff --git a/src/webengine/webprofile.cpp b/src/webengine/webprofile.cpp deleted file mode 100644 index f1e71fb..0000000 --- a/src/webengine/webprofile.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* - * 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/gitea/aqua/smolbote - * - * SPDX-License-Identifier: GPL-3.0 - */ - -#include "webprofile.h" -#include "urlinterceptor.h" -#include -#include -#include -#include -#include - -static WebProfile *s_profile = nullptr; - -void WebProfile::setDefaultProfile(WebProfile *profile) -{ - s_profile = profile; -} -WebProfile *WebProfile::defaultProfile() -{ - return s_profile; -} - -QSettings *WebProfile::load(const QString &path, const QString &search, const QUrl &homepage, const QUrl &newtab) -{ - auto *settings = new QSettings(path, QSettings::IniFormat); - - if(!settings->contains("search")) { - settings->setValue("search", search); - } - if(!settings->contains("homepage")) { - settings->setValue("homepage", homepage); - } - if(!settings->contains("newtab")) { - settings->setValue("newtab", newtab); - } - - return settings; -} - -WebProfile *WebProfile::load(const QString &id, QSettings *settings, bool isOffTheRecord) -{ - WebProfile *profile = nullptr; - - if(settings->value("otr", isOffTheRecord).toBool()) { - profile = new WebProfile(id, nullptr); - } else { - profile = new WebProfile(id, id, nullptr); - } - - profile->m_name = settings->value("name", id).toString(); - connect(profile, &WebProfile::nameChanged, profile, [settings](const QString &name) { settings->setValue("name", name); }); - profile->m_search = settings->value("search", "").toString(); - connect(profile, &WebProfile::searchChanged, settings, [settings](const QString &url) { settings->setValue("search", url); }); - profile->m_homepage = settings->value("homepage", "").toUrl(); - connect(profile, &WebProfile::homepageChanged, settings, [settings](const QUrl &url) { settings->setValue("homepage", url); }); - profile->m_newtab = settings->value("newtab", "").toUrl(); - connect(profile, &WebProfile::newtabChanged, settings, [settings](const QUrl &url) { settings->setValue("newtab", url); }); - - { - settings->beginGroup("properties"); - const auto keys = settings->childKeys(); - for(const QString &key : keys) { - profile->setProperty(qUtf8Printable(key), settings->value(key)); - } - settings->endGroup(); // properties - connect(profile, &WebProfile::propertyChanged, [settings](const QString &property, const QVariant &value) { - settings->setValue("properties/" + property, value); - }); - } - { - settings->beginGroup("attributes"); - const auto keys = settings->childKeys(); - auto *s = profile->settings(); - for(const QString &key : keys) { - auto attribute = static_cast(key.toInt()); - s->setAttribute(attribute, settings->value(key).toBool()); - } - settings->endGroup(); - connect(profile, &WebProfile::attributeChanged, [settings](const QWebEngineSettings::WebAttribute attr, const bool value) { - settings->setValue("attributes/" + QString::number(attr), value); - }); - } - { - // headers - settings->beginGroup("headers"); - const auto keys = settings->childKeys(); - for(const QString &key : keys) { - profile->setHttpHeader(key.toLatin1(), settings->value(key).toString().toLatin1()); - } - settings->endGroup(); - connect(profile, &WebProfile::headerChanged, [settings](const QString &name, const QString &value) { - settings->setValue("headers/" + name, value); - }); - connect(profile, &WebProfile::headerRemoved, [settings](const QString &name) { - settings->remove("headers/" + name); - }); - } - return profile; -} - -// off-the-record constructor -WebProfile::WebProfile(const QString &id, QObject *parent) - : QWebEngineProfile(parent) - , m_id(id) -{ - QWebEngineProfile::setUrlRequestInterceptor(new UrlRequestInterceptor(this)); - connect(this->cookieStore(), &QWebEngineCookieStore::cookieAdded, this, [this](const QNetworkCookie &cookie) { - spdlog::debug("[{}]: +cookie {}", qUtf8Printable(m_name), qUtf8Printable(cookie.name())); - m_cookies.append(cookie); - }); - connect(this->cookieStore(), &QWebEngineCookieStore::cookieRemoved, this, [this](const QNetworkCookie &cookie) { - spdlog::debug("[{}]: -cookie {}", qUtf8Printable(m_name), qUtf8Printable(cookie.name())); - m_cookies.removeOne(cookie); - }); - cookieStore()->loadAllCookies(); -} - -// default constructor -WebProfile::WebProfile(const QString &id, const QString &storageName, QObject *parent) - : QWebEngineProfile(storageName, parent) - , m_id(id) -{ - QWebEngineProfile::setUrlRequestInterceptor(new UrlRequestInterceptor(this)); - connect(this->cookieStore(), &QWebEngineCookieStore::cookieAdded, this, [this](const QNetworkCookie &cookie) { - spdlog::debug("[{}]: +cookie {}", qUtf8Printable(m_name), qUtf8Printable(cookie.name())); - m_cookies.append(cookie); - }); - connect(this->cookieStore(), &QWebEngineCookieStore::cookieRemoved, this, [this](const QNetworkCookie &cookie) { - spdlog::debug("[{}]: -cookie {}", qUtf8Printable(m_name), qUtf8Printable(cookie.name())); - m_cookies.removeOne(cookie); - }); - cookieStore()->loadAllCookies(); -} -- cgit v1.2.1