aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/configuration/configuration.h7
-rw-r--r--lib/web/profilemanager.cpp13
-rw-r--r--lib/web/webprofile.cpp14
-rw-r--r--lib/web/webprofile.h9
4 files changed, 43 insertions, 0 deletions
diff --git a/lib/configuration/configuration.h b/lib/configuration/configuration.h
index d4770ae..1524536 100644
--- a/lib/configuration/configuration.h
+++ b/lib/configuration/configuration.h
@@ -56,6 +56,13 @@ public:
return std::optional<QString>(QString::fromStdString(this->value<std::string>(path).value()));
//return std::optional<QString>(vm[path].as<const char*>());
+ } else if constexpr(std::is_same_v<T, QStringList>) {
+ QStringList r;
+ for(const std::string &item : this->value<std::vector<std::string>>(path).value()) {
+ r.append(QString::fromStdString(item));
+ }
+ return std::optional<QStringList>(r);
+
} else if constexpr(std::is_same_v<T, std::string>) {
if(vm[path].value().type() == typeid(int)) {
diff --git a/lib/web/profilemanager.cpp b/lib/web/profilemanager.cpp
index 74ddc75..17435e8 100644
--- a/lib/web/profilemanager.cpp
+++ b/lib/web/profilemanager.cpp
@@ -73,6 +73,19 @@ WebProfile *ProfileManager::loadProfile(const QString &path)
this->m_profiles.at(id)->settings.setValue("attributes/" + QString::number(attr), value);
});
+ // headers
+ ptr->settings.beginGroup("headers");
+ for(const QString &key : ptr->settings.childKeys()) {
+ ptr->profile->setHttpHeader(key.toLatin1(), ptr->settings.value(key).toString().toLatin1());
+ }
+ ptr->settings.endGroup();
+ connect(ptr->profile, &WebProfile::headerChanged, ptr->profile, [this, id](const QString &name, const QString &value) {
+ this->m_profiles.at(id)->settings.setValue("headers/" + name, value);
+ });
+ connect(ptr->profile, &WebProfile::headerRemoved, ptr->profile, [this, id](const QString &name) {
+ this->m_profiles.at(id)->settings.remove("headers/" + name);
+ });
+
m_profiles[id] = std::move(ptr);
return m_profiles.at(id)->profile;
}
diff --git a/lib/web/webprofile.cpp b/lib/web/webprofile.cpp
index bd84d38..16c12b7 100644
--- a/lib/web/webprofile.cpp
+++ b/lib/web/webprofile.cpp
@@ -135,6 +135,20 @@ void WebProfile::setHttpUserAgent(const QString &userAgent)
emit propertyChanged("httpUserAgent", userAgent);
}
+void WebProfile::setHttpHeader(const QString& name, const QString& value)
+{
+ m_headers[name.toLatin1()] = value.toLatin1();
+ emit headerChanged(name, value);
+}
+
+void WebProfile::removeHttpHeader(const QString& name)
+{
+ if(m_headers.contains(name.toLatin1())) {
+ m_headers.remove(name.toLatin1());
+ emit headerRemoved(name);
+ }
+}
+
void WebProfile::setSpellCheckEnabled(bool enable)
{
QWebEngineProfile::setSpellCheckEnabled(enable);
diff --git a/lib/web/webprofile.h b/lib/web/webprofile.h
index b58fad7..269989b 100644
--- a/lib/web/webprofile.h
+++ b/lib/web/webprofile.h
@@ -65,6 +65,10 @@ public:
{
return qAsConst(m_cookies);
}
+ const QMap<QByteArray, QByteArray> headers() const
+ {
+ return qAsConst(m_headers);
+ }
// search url
QString search() const;
@@ -86,6 +90,8 @@ public:
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 setSpellCheckEnabled(bool enable);
@@ -97,6 +103,8 @@ signals:
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);
private:
static WebProfile *profile;
@@ -107,6 +115,7 @@ private:
QUrl m_newtab = QUrl("about:blank");
QVector<QNetworkCookie> m_cookies;
+ QMap<QByteArray, QByteArray> m_headers;
};
#endif // SMOLBOTE_WEBENGINEPROFILE_H