aboutsummaryrefslogtreecommitdiff
path: root/src/webengine/webprofile.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/webengine/webprofile.h')
-rw-r--r--src/webengine/webprofile.h167
1 files changed, 125 insertions, 42 deletions
diff --git a/src/webengine/webprofile.h b/src/webengine/webprofile.h
index 66154af..180cc9d 100644
--- a/src/webengine/webprofile.h
+++ b/src/webengine/webprofile.h
@@ -9,7 +9,6 @@
#ifndef SMOLBOTE_WEBENGINEPROFILE_H
#define SMOLBOTE_WEBENGINEPROFILE_H
-#include <QHash>
#include <QMap>
#include <QNetworkCookie>
#include <QString>
@@ -17,14 +16,17 @@
#include <QVector>
#include <QWebEngineProfile>
#include <QWebEngineSettings>
+#include <QVariant>
+#include <QSettings>
-class WebProfileManager;
+class UrlRequestInterceptor;
class WebProfile : public QWebEngineProfile
{
- friend class WebProfileManager;
+ friend class UrlRequestInterceptor;
Q_OBJECT
+ Q_PROPERTY(QString id READ getId CONSTANT)
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)
@@ -42,72 +44,153 @@ class WebProfile : public QWebEngineProfile
Q_PROPERTY(bool spellCheckEnabled READ isSpellCheckEnabled WRITE setSpellCheckEnabled NOTIFY propertyChanged)
+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(QWebEngineSettings::WebAttribute attribute, bool value);
+ void headerChanged(const QString &name, const QString &value);
+ void headerRemoved(const QString &name);
+
public:
+ [[nodiscard]] static QSettings *load(const QString &path, const QString &search = QString(), const QUrl &homepage = QUrl(), const QUrl &newtab = QUrl());
+ [[nodiscard]] static WebProfile *load(const QString &id, QSettings *settings, bool isOffTheRecord = true);
+
+ WebProfile(const WebProfile &) = delete;
+ WebProfile& operator=(const WebProfile &) = delete;
+ WebProfile(WebProfile &&) = delete;
+ WebProfile& operator=(WebProfile &&) = delete;
+
static WebProfile *defaultProfile();
static void setDefaultProfile(WebProfile *profile);
- ~WebProfile() = default;
+ ~WebProfile() override = default;
- const QString name() const;
- void setName(const QString &name);
-
- const QVector<QNetworkCookie> cookies() const
+ [[nodiscard]] QString getId() const
{
- return qAsConst(m_cookies);
+ return m_id;
+ }
+ [[nodiscard]] QString name() const
+ {
+ return m_name;
}
- const QMap<QByteArray, QByteArray> headers() const
+ void setName(const QString &name)
{
- return qAsConst(m_headers);
+ m_name = name;
+ emit nameChanged(name);
}
- // search url
- QString search() const;
- void setSearch(const QString &url);
+ [[nodiscard]] QVector<QNetworkCookie> cookies() const
+ {
+ return qAsConst(m_cookies);
+ }
- // homepage url
- QUrl homepage() const;
- void setHomepage(const QUrl &url);
+ [[nodiscard]] QString search() const
+ {
+ return m_search;
+ }
+ void setSearch(const QString &url)
+ {
+ m_search = url;
+ emit searchChanged(m_search);
+ }
- // new tab url
- QUrl newtab() const;
- void setNewtab(const QUrl &url);
+ [[nodiscard]] QUrl homepage() const
+ {
+ return m_homepage;
+ }
+ void setHomepage(const QUrl &url)
+ {
+ m_homepage = url;
+ emit homepageChanged(m_homepage);
+ }
- void setCachePath(const QString &path);
- void setPersistentStoragePath(const QString &path);
- void setPersistentCookiesPolicy(int policy);
+ [[nodiscard]] QUrl newtab() const
+ {
+ return m_newtab;
+ }
+ void setNewtab(const QUrl &url)
+ {
+ m_newtab = url;
+ emit newtabChanged(m_newtab);
+ }
- void setHttpAcceptLanguage(const QString &httpAcceptLanguage);
- void setHttpCacheMaximumSize(int maxSize);
- void setHttpCacheType(int type);
- void setHttpUserAgent(const QString &userAgent);
- void setHttpHeader(const QString &name, const QString &value);
- void removeHttpHeader(const QString &name);
+ void setCachePath(const QString &path)
+ {
+ QWebEngineProfile::setCachePath(path);
+ emit propertyChanged("cachePath", path);
+ }
+ void setPersistentStoragePath(const QString &path)
+ {
+ QWebEngineProfile::setPersistentStoragePath(path);
+ emit propertyChanged("persistentStoragePath", path);
+ }
+ void setPersistentCookiesPolicy(int policy)
+ {
+ QWebEngineProfile::setPersistentCookiesPolicy(static_cast<QWebEngineProfile::PersistentCookiesPolicy>(policy));
+ emit propertyChanged("persistentCookiesPolicy", policy);
+ }
- void setSpellCheckEnabled(bool enable);
+ void setHttpAcceptLanguage(const QString &httpAcceptLanguage)
+ {
+ QWebEngineProfile::setHttpAcceptLanguage(httpAcceptLanguage);
+ emit propertyChanged("httpAcceptLanguage", httpAcceptLanguage);
+ }
+ void setHttpCacheMaximumSize(int maxSize)
+ {
+ QWebEngineProfile::setHttpCacheMaximumSize(maxSize);
+ emit propertyChanged("httpCacheMaximumSize", maxSize);
+ }
+ void setHttpCacheType(int type)
+ {
+ QWebEngineProfile::setHttpCacheType(static_cast<QWebEngineProfile::HttpCacheType>(type));
+ emit propertyChanged("httpCacheType", type);
+ }
+ void setHttpUserAgent(const QString &userAgent)
+ {
+ QWebEngineProfile::setHttpUserAgent(userAgent);
+ emit propertyChanged("httpUserAgent", userAgent);
+ }
+ void setHttpHeader(const QString &name, const QString &value)
+ {
+ m_headers[name.toLatin1()] = value.toLatin1();
+ emit headerChanged(name, value);
+ }
+ void removeHttpHeader(const QString &name)
+ {
+ if(m_headers.contains(name.toLatin1())) {
+ m_headers.remove(name.toLatin1());
+ emit headerRemoved(name);
+ }
+ }
-signals:
- void nameChanged(const QString &name);
- void searchChanged(const QString &url);
- void homepageChanged(const QUrl &url);
- void newtabChanged(const QUrl &url);
+ void setSpellCheckEnabled(bool enable)
+ {
+ QWebEngineProfile::setSpellCheckEnabled(enable);
+ emit propertyChanged("spellCheckEnabed", enable);
+ }
- void propertyChanged(const QString &name, const QVariant &value);
- void attributeChanged(const QWebEngineSettings::WebAttribute attribute, const bool value);
- void headerChanged(const QString &name, const QString &value);
- void headerRemoved(const QString &name);
+ void setUrlRequestInterceptor(QWebEngineUrlRequestInterceptor *interceptor)
+ {
+ m_filters.append(interceptor);
+ }
protected:
// off-the-record constructor
- explicit WebProfile(const QString &name, QObject *parent = nullptr);
+ explicit WebProfile(const QString &id, QObject *parent = nullptr);
// default constructor
- explicit WebProfile(const QString &storageName, const QString &name, QObject *parent = nullptr);
+ explicit WebProfile(const QString &id, const QString &storageName, QObject *parent = nullptr);
-private:
+ const QString m_id;
QString m_name;
QString m_search = QString("about:blank");
QUrl m_homepage = QUrl("about:blank");
QUrl m_newtab = QUrl("about:blank");
+ QVector<QWebEngineUrlRequestInterceptor*> m_filters;
QVector<QNetworkCookie> m_cookies;
QMap<QByteArray, QByteArray> m_headers;
};