aboutsummaryrefslogtreecommitdiff
path: root/lib/web/webprofile.cpp
blob: 9b16a6175da59558889eab759c22e9c365627729 (plain)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 * 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;

WebProfile::WebProfile(const QString &name, const QString &configPath, QObject *parent)
    : QWebEngineProfile(parent)
{
    m_name = name;
    m_configPath = configPath;

#ifdef QT_DEBUG
    qDebug("Creating otr profile %s", qUtf8Printable(m_name));
#endif

    connect(this->cookieStore(), &QWebEngineCookieStore::cookieAdded, this, [this](const QNetworkCookie &cookie) {
        m_cookies.append(cookie);
    });
    connect(this->cookieStore(), &QWebEngineCookieStore::cookieRemoved, this, [this](const QNetworkCookie &cookie) {
        m_cookies.removeAll(cookie);
    });
}

WebProfile::WebProfile(const QString &storageName, const QString &name, const QString &configPath, QObject *parent)
    : QWebEngineProfile(storageName, parent)
{
    m_name = name;
    m_configPath = configPath;

#ifdef QT_DEBUG
    qDebug("Creating profile %s", qUtf8Printable(m_name));
#endif

    connect(this->cookieStore(), &QWebEngineCookieStore::cookieAdded, this, [this](const QNetworkCookie &cookie) {
        m_cookies.append(cookie);
    });
    connect(this->cookieStore(), &QWebEngineCookieStore::cookieRemoved, this, [this](const QNetworkCookie &cookie) {
        m_cookies.removeAll(cookie);
    });
}

QString WebProfile::search() const
{
    return m_search;
}

void WebProfile::setSearch(const QString &url)
{
    m_search = url;
    emit searchChanged(m_search);
}

QUrl WebProfile::homepage() const
{
    return m_homepage;
}

void WebProfile::setHomepage(const QUrl &url)
{
    m_homepage = url;
    emit homepageChanged(m_homepage);
}

QUrl WebProfile::newtab() const
{
    return m_newtab;
}

void WebProfile::setNewtab(const QUrl &url)
{
    m_newtab = url;
    emit newtabChanged(m_newtab);
}

void WebProfile::setCachePath(const QString &path)
{
    QWebEngineProfile::setCachePath(path);
    emit cachePathChanged(QWebEngineProfile::cachePath());
}

void WebProfile::setPersistentStoragePath(const QString &path)
{
    QWebEngineProfile::setPersistentStoragePath(path);
    emit persistentStoragePathChanged(QWebEngineProfile::persistentStoragePath());
}

void WebProfile::setHttpAcceptLanguage(const QString &httpAcceptLanguage)
{
    QWebEngineProfile::setHttpAcceptLanguage(httpAcceptLanguage);
    emit httpAcceptLanguageChanged(QWebEngineProfile::httpAcceptLanguage());
}

void WebProfile::setHttpCacheMaximumSize(int maxSize)
{
    QWebEngineProfile::setHttpCacheMaximumSize(maxSize);
    emit httpCacheMaximumSizeChanged(QWebEngineProfile::httpCacheMaximumSize());
}

void WebProfile::setHttpUserAgent(const QString &userAgent)
{
    QWebEngineProfile::setHttpUserAgent(userAgent);
    emit httpUserAgentChanged(QWebEngineProfile::httpUserAgent());
}

void WebProfile::setSpellCheckEnabled(bool enable)
{
    QWebEngineProfile::setSpellCheckEnabled(enable);
    emit spellCheckEnabledChanged(QWebEngineProfile::isSpellCheckEnabled());
}