From 2a5ea0269a1f9511c51d661a6c7d7bdc7d0176fa Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sun, 7 Oct 2018 13:20:54 +0200 Subject: 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 --- .../ProfileEditor/forms/newhttpheaderdialog.cpp | 32 +++++++++ plugins/ProfileEditor/forms/newhttpheaderdialog.h | 33 +++++++++ plugins/ProfileEditor/forms/newhttpheaderdialog.ui | 84 ++++++++++++++++++++++ plugins/ProfileEditor/forms/profileview.cpp | 46 ++++++++++++ plugins/ProfileEditor/forms/profileview.h | 3 + plugins/ProfileEditor/forms/profileview.ui | 68 +++++++++++++++++- 6 files changed, 264 insertions(+), 2 deletions(-) create mode 100644 plugins/ProfileEditor/forms/newhttpheaderdialog.cpp create mode 100644 plugins/ProfileEditor/forms/newhttpheaderdialog.h create mode 100644 plugins/ProfileEditor/forms/newhttpheaderdialog.ui (limited to 'plugins/ProfileEditor/forms') diff --git a/plugins/ProfileEditor/forms/newhttpheaderdialog.cpp b/plugins/ProfileEditor/forms/newhttpheaderdialog.cpp new file mode 100644 index 0000000..3978c4e --- /dev/null +++ b/plugins/ProfileEditor/forms/newhttpheaderdialog.cpp @@ -0,0 +1,32 @@ +/* + * 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 + */ + +#include "newhttpheaderdialog.h" +#include "ui_newhttpheaderdialog.h" + +NewHttpHeaderDialog::NewHttpHeaderDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::NewHttpHeaderDialog) +{ + ui->setupUi(this); +} + +NewHttpHeaderDialog::~NewHttpHeaderDialog() +{ + delete ui; +} + +QString NewHttpHeaderDialog::header() const +{ + return ui->header->text(); +} + +QString NewHttpHeaderDialog::value() const +{ + return ui->value->text(); +} diff --git a/plugins/ProfileEditor/forms/newhttpheaderdialog.h b/plugins/ProfileEditor/forms/newhttpheaderdialog.h new file mode 100644 index 0000000..53a2a80 --- /dev/null +++ b/plugins/ProfileEditor/forms/newhttpheaderdialog.h @@ -0,0 +1,33 @@ +/* + * 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 NEWHTTPHEADERDIALOG_H +#define NEWHTTPHEADERDIALOG_H + +#include + +namespace Ui { +class NewHttpHeaderDialog; +} + +class NewHttpHeaderDialog : public QDialog +{ + Q_OBJECT + +public: + explicit NewHttpHeaderDialog(QWidget *parent = nullptr); + ~NewHttpHeaderDialog(); + + QString header() const; + QString value() const; + +private: + Ui::NewHttpHeaderDialog *ui; +}; + +#endif // NEWHTTPHEADERDIALOG_H diff --git a/plugins/ProfileEditor/forms/newhttpheaderdialog.ui b/plugins/ProfileEditor/forms/newhttpheaderdialog.ui new file mode 100644 index 0000000..a457ba6 --- /dev/null +++ b/plugins/ProfileEditor/forms/newhttpheaderdialog.ui @@ -0,0 +1,84 @@ + + + NewHttpHeaderDialog + + + + 0 + 0 + 320 + 108 + + + + Dialog + + + + + + Header + + + + + + + + + + Value + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + NewHttpHeaderDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + NewHttpHeaderDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + 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 #include #include +#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(); diff --git a/plugins/ProfileEditor/forms/profileview.h b/plugins/ProfileEditor/forms/profileview.h index 5ff472b..d05b0f1 100644 --- a/plugins/ProfileEditor/forms/profileview.h +++ b/plugins/ProfileEditor/forms/profileview.h @@ -33,6 +33,9 @@ public: private slots: void loadCookies(QWebEngineCookieStore *store); + void headerChanged(const QString &name, const QString &value); + void headerRemoved(const QString &name); + void cookieAdded(const QNetworkCookie &cookie); void cookieRemoved(const QNetworkCookie &cookie); diff --git a/plugins/ProfileEditor/forms/profileview.ui b/plugins/ProfileEditor/forms/profileview.ui index 74b6d5d..630e53d 100644 --- a/plugins/ProfileEditor/forms/profileview.ui +++ b/plugins/ProfileEditor/forms/profileview.ui @@ -234,6 +234,70 @@ + + + Headers + + + + + + 200 + + + 100 + + + true + + + false + + + + Name + + + + + Value + + + + + + + + + + Insert + + + + + + + Delete + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Settings @@ -249,8 +313,8 @@ 0 0 - 276 - 855 + 584 + 797 -- cgit v1.2.1