aboutsummaryrefslogtreecommitdiff
path: root/lib/web/webprofile.h
blob: b58fad7348f7656ba1e5da0aa0a34f707f0a6843 (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
/*
 * 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
 */

#ifndef SMOLBOTE_WEBENGINEPROFILE_H
#define SMOLBOTE_WEBENGINEPROFILE_H

#include <QHash>
#include <QUrl>
#include <QString>
#include <QWebEngineProfile>
#include <QVector>
#include <QNetworkCookie>
#include <QMap>
#include <QWebEngineSettings>

class WebProfile : public QWebEngineProfile
{
    Q_OBJECT

    Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
    Q_PROPERTY(QString search READ search WRITE setSearch NOTIFY searchChanged)
    Q_PROPERTY(QUrl homepage READ homepage WRITE setHomepage NOTIFY homepageChanged)
    Q_PROPERTY(QUrl newtab READ newtab WRITE setNewtab NOTIFY newtabChanged)

    // QWebEngineProfile should-be properties
    Q_PROPERTY(QString cachePath READ cachePath WRITE setCachePath NOTIFY propertyChanged)
    Q_PROPERTY(QString persistentStoragePath READ persistentStoragePath WRITE setPersistentStoragePath NOTIFY propertyChanged)
    Q_PROPERTY(int persistentCookiesPolicy READ persistentCookiesPolicy WRITE setPersistentCookiesPolicy NOTIFY propertyChanged)

    Q_PROPERTY(QString httpAcceptLanguage READ httpAcceptLanguage WRITE setHttpAcceptLanguage NOTIFY propertyChanged)
    Q_PROPERTY(int httpCacheMaximumSize READ httpCacheMaximumSize WRITE setHttpCacheMaximumSize NOTIFY propertyChanged)
    Q_PROPERTY(int httpCacheType READ httpCacheType WRITE setHttpCacheType NOTIFY propertyChanged)
    Q_PROPERTY(QString httpUserAgent READ httpUserAgent WRITE setHttpUserAgent NOTIFY propertyChanged)

    Q_PROPERTY(bool spellCheckEnabled READ isSpellCheckEnabled WRITE setSpellCheckEnabled NOTIFY propertyChanged)

public:
    // off-the-record constructor
    explicit WebProfile(const QString &name, QObject *parent = nullptr);
    // default constructor
    explicit WebProfile(const QString &storageName, const QString &name, QObject *parent = nullptr);

    ~WebProfile() = default;

    static void setDefaultProfile(WebProfile *profile)
    {
        Q_CHECK_PTR(profile);
        WebProfile::profile = profile;
    }
    static WebProfile *defaultProfile()
    {
        Q_CHECK_PTR(WebProfile::profile);
        return WebProfile::profile;
    }

    const QString name() const;
    void setName(const QString &name);

    const QVector<QNetworkCookie> cookies() const
    {
        return qAsConst(m_cookies);
    }

    // search url
    QString search() const;
    void setSearch(const QString &url);

    // homepage url
    QUrl homepage() const;
    void setHomepage(const QUrl &url);

    // new tab url
    QUrl newtab() const;
    void setNewtab(const QUrl &url);

    void setCachePath(const QString &path);
    void setPersistentStoragePath(const QString &path);
    void setPersistentCookiesPolicy(int policy);

    void setHttpAcceptLanguage(const QString &httpAcceptLanguage);
    void setHttpCacheMaximumSize(int maxSize);
    void setHttpCacheType(int type);
    void setHttpUserAgent(const QString &userAgent);

    void setSpellCheckEnabled(bool enable);

signals:
    void nameChanged(const QString &name);
    void searchChanged(const QString &url);
    void homepageChanged(const QUrl &url);
    void newtabChanged(const QUrl &url);

    void propertyChanged(const QString &name, const QVariant &value);
    void attributeChanged(const QWebEngineSettings::WebAttribute attribute, const bool value);

private:
    static WebProfile *profile;

    QString m_name;
    QString m_search = QString("about:blank");
    QUrl m_homepage = QUrl("about:blank");
    QUrl m_newtab = QUrl("about:blank");

    QVector<QNetworkCookie> m_cookies;
};

#endif // SMOLBOTE_WEBENGINEPROFILE_H