aboutsummaryrefslogtreecommitdiff
path: root/plugins/ProfileEditor/forms/profileview.cpp
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-10-07 13:20:54 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-10-07 18:19:19 +0200
commit2a5ea0269a1f9511c51d661a6c7d7bdc7d0176fa (patch)
tree7649cf4c1c20bbe8c801d642148992eea314d3ec /plugins/ProfileEditor/forms/profileview.cpp
parentAdd hint on enabling plugins to makepkg (diff)
downloadsmolbote-2a5ea0269a1f9511c51d661a6c7d7bdc7d0176fa.tar.xz
Expand HTTP header settings #4
- add doc/Usage/Filter.asciidoc to explain the usage of the filter headers - add HTTP headers to Profile (section "headers") - Use request interceptor to apply filter headers, then profile headers - add insert/delete actions to ProfileEditor
Diffstat (limited to 'plugins/ProfileEditor/forms/profileview.cpp')
-rw-r--r--plugins/ProfileEditor/forms/profileview.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/plugins/ProfileEditor/forms/profileview.cpp b/plugins/ProfileEditor/forms/profileview.cpp
index ccb4ae5..4a89af6 100644
--- a/plugins/ProfileEditor/forms/profileview.cpp
+++ b/plugins/ProfileEditor/forms/profileview.cpp
@@ -13,6 +13,7 @@
#include <QWebEngineSettings>
#include <QWebEngineCookieStore>
#include <QDateTime>
+#include "newhttpheaderdialog.h"
inline void connectSetting(QCheckBox *checkBox, WebProfile *profile, QWebEngineSettings::WebAttribute attr)
{
@@ -86,6 +87,28 @@ ProfileView::ProfileView(WebProfile *profile, QWidget *parent)
ui->storagePath_lineEdit->setText(m_profile->persistentStoragePath());
ui->cachePath_lineEdit->setText(m_profile->cachePath());
+ // headers tab
+ for(auto i = m_profile->headers().constBegin(); i != m_profile->headers().constEnd(); ++i) {
+ //ui->httpHeaders->addItem();
+ headerChanged(i.key(), i.value());
+ }
+ connect(m_profile, &WebProfile::headerChanged, this, &ProfileView::headerChanged);
+ connect(m_profile, &WebProfile::headerRemoved, this, &ProfileView::headerRemoved);
+ connect(ui->headers_insert, &QPushButton::clicked, m_profile, [this]() {
+ auto *dlg = new NewHttpHeaderDialog(this);
+ if(dlg->exec() == QDialog::Accepted) {
+ m_profile->setHttpHeader(dlg->header(), dlg->value());
+ }
+ delete dlg;
+ });
+ connect(ui->headers_delete, &QPushButton::clicked, m_profile, [this]() {
+ for(auto &list : ui->httpHeaders->selectedRanges()) {
+ for(int i = list.bottomRow(); i >= list.topRow(); --i) {
+ m_profile->removeHttpHeader(ui->httpHeaders->item(i, 0)->text());
+ }
+ }
+ });
+
// settings tab
connectSetting(ui->autoloadImages, m_profile, QWebEngineSettings::AutoLoadImages);
connectSetting(ui->autoloadIcons, m_profile, QWebEngineSettings::AutoLoadIconsForPage);
@@ -157,6 +180,29 @@ void ProfileView::loadCookies(QWebEngineCookieStore *store)
connect(ui->cookies_deleteAll, &QPushButton::clicked, store, &QWebEngineCookieStore::deleteAllCookies);
}
+void ProfileView::headerChanged(const QString &name, const QString &value)
+{
+ const auto items = ui->httpHeaders->findItems(name, Qt::MatchExactly);
+ if(!items.isEmpty()) {
+ QTableWidgetItem *valueItem = ui->httpHeaders->item(items.constFirst()->row(), 1);
+ valueItem->setText(value);
+ } else {
+ // new header
+ const int index = ui->httpHeaders->rowCount();
+ ui->httpHeaders->setRowCount(index + 1);
+ ui->httpHeaders->setItem(index, 0, new QTableWidgetItem(name));
+ ui->httpHeaders->setItem(index, 1, new QTableWidgetItem(value));
+ }
+}
+
+void ProfileView::headerRemoved(const QString& name)
+{
+ const auto items = ui->httpHeaders->findItems(name, Qt::MatchExactly);
+ if(!items.isEmpty()) {
+ ui->httpHeaders->removeRow(items.constFirst()->row());
+ }
+}
+
void ProfileView::cookieAdded(const QNetworkCookie &cookie)
{
auto index = ui->cookies->rowCount();