diff options
Diffstat (limited to 'plugins/ProfileEditor/forms/profileview.cpp')
-rw-r--r-- | plugins/ProfileEditor/forms/profileview.cpp | 46 |
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(); |