aboutsummaryrefslogtreecommitdiff
path: root/plugins/ProfileEditor/forms/profileview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/ProfileEditor/forms/profileview.cpp')
-rw-r--r--plugins/ProfileEditor/forms/profileview.cpp153
1 files changed, 50 insertions, 103 deletions
diff --git a/plugins/ProfileEditor/forms/profileview.cpp b/plugins/ProfileEditor/forms/profileview.cpp
index 9a19cfc..992364c 100644
--- a/plugins/ProfileEditor/forms/profileview.cpp
+++ b/plugins/ProfileEditor/forms/profileview.cpp
@@ -1,29 +1,26 @@
/*
* 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
+ * location: https://neueland.iserlohn-fortress.net/cgit/smolbote
*
* SPDX-License-Identifier: GPL-3.0
*/
#include "profileview.h"
#include "ui_profileview.h"
-#include <profileinterface.h>
-#include <QWebEngineSettings>
-#include <QWebEngineCookieStore>
#include <QDateTime>
-#include "newhttpheaderdialog.h"
+#include <QWebEngineCookieStore>
+#include <QWebEngineSettings>
-inline void connectSetting(QCheckBox *checkBox, Profile *profile, QWebEngineSettings::WebAttribute attr)
+inline void connectSetting(QCheckBox *checkBox, QWebEngineProfile *profile, QWebEngineSettings::WebAttribute attr)
{
checkBox->setChecked(profile->settings()->testAttribute(attr));
QObject::connect(checkBox, &QCheckBox::clicked, [profile, attr](bool checked) {
profile->settings()->setAttribute(attr, checked);
- emit profile->attributeChanged(attr, checked);
});
}
-ProfileView::ProfileView(Profile *profile, QWidget *parent)
+ProfileView::ProfileView(const QString &name, QWebEngineProfile *profile, QSettings *settings, QWidget *parent)
: QWidget(parent)
, ui(new Ui::ProfileView)
{
@@ -32,52 +29,37 @@ ProfileView::ProfileView(Profile *profile, QWidget *parent)
ui->setupUi(this);
// general tab
- ui->name->setText(profile->name());
- connect(ui->name, &QLineEdit::editingFinished, profile, [=]() {
- profile->setName(ui->name->text());
- });
-
+ ui->name->setText(name);
ui->offTheRecord->setChecked(profile->isOffTheRecord());
- ui->homepage->setText(profile->homepage().toString());
- connect(ui->homepage, &QLineEdit::editingFinished, profile, [=]() {
- profile->setHomepage(QUrl::fromUserInput(ui->homepage->text()));
- });
-
- ui->newtab->setText(profile->newtab().toString());
- connect(ui->newtab, &QLineEdit::editingFinished, profile, [=]() {
- profile->setNewtab(QUrl::fromUserInput(ui->newtab->text()));
- });
-
- ui->search->setText(profile->search());
- connect(ui->search, &QLineEdit::editingFinished, profile, [=]() {
- profile->setSearch(ui->search->text());
- });
+ ui->settings_table->connect(settings);
// http tab
ui->userAgent->setPlainText(m_profile->httpUserAgent());
- connect(ui->userAgent, &QPlainTextEdit::textChanged, profile, [=]() {
+ connect(ui->userAgent, &QPlainTextEdit::textChanged, profile, [this, profile]() {
profile->setHttpUserAgent(ui->userAgent->toPlainText());
});
ui->acceptLanguage->setPlainText(m_profile->httpAcceptLanguage());
- connect(ui->acceptLanguage, &QPlainTextEdit::textChanged, profile, [=]() {
+ connect(ui->acceptLanguage, &QPlainTextEdit::textChanged, profile, [this, profile]() {
profile->setHttpAcceptLanguage(ui->acceptLanguage->toPlainText());
});
+ ui->headers_table->connect(settings, "headers");
+
ui->cacheType->setCurrentIndex(m_profile->httpCacheType());
- connect(ui->cacheType, QOverload<int>::of(&QComboBox::currentIndexChanged), profile, [=](int index) {
- profile->setHttpCacheType(index);
+ connect(ui->cacheType, QOverload<int>::of(&QComboBox::currentIndexChanged), profile, [profile](int index) {
+ profile->setHttpCacheType(static_cast<QWebEngineProfile::HttpCacheType>(index));
});
ui->cacheSize->setText(QString::number(m_profile->httpCacheMaximumSize()));
- connect(ui->cacheSize, &QLineEdit::textChanged, profile, [=](const QString &text) {
+ connect(ui->cacheSize, &QLineEdit::textChanged, profile, [profile](const QString &text) {
profile->setHttpCacheMaximumSize(text.toInt());
});
ui->cookiePolicy->setCurrentIndex(m_profile->persistentCookiesPolicy());
- connect(ui->cookiePolicy, QOverload<int>::of(&QComboBox::currentIndexChanged), profile, [=](int index) {
- profile->setPersistentCookiesPolicy(index);
+ connect(ui->cookiePolicy, QOverload<int>::of(&QComboBox::currentIndexChanged), profile, [profile](int index) {
+ profile->setPersistentCookiesPolicy(static_cast<QWebEngineProfile::PersistentCookiesPolicy>(index));
});
connect(ui->clearCache_pushButton, &QPushButton::clicked, profile, &QWebEngineProfile::clearHttpCache);
@@ -86,28 +68,13 @@ ProfileView::ProfileView(Profile *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());
+ if(profile->isOffTheRecord()) {
+ ui->cacheType->setEnabled(false);
+ ui->cacheSize->setEnabled(false);
+ ui->storagePath_lineEdit->setEnabled(false);
+ ui->cachePath_lineEdit->setEnabled(false);
+ ui->cookiePolicy->setEnabled(false);
}
- connect(m_profile, &Profile::headerChanged, this, &ProfileView::headerChanged);
- connect(m_profile, &Profile::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);
@@ -144,62 +111,39 @@ ProfileView::ProfileView(Profile *profile, QWidget *parent)
connectSetting(ui->printElementBackgrounds, m_profile, QWebEngineSettings::PrintElementBackgrounds);
// cookies tab
- loadCookies(profile->cookieStore());
- for(const auto &c : profile->cookies()) {
- cookieAdded(c);
+ for(const auto &data : profile->property("cookies").toList()) {
+ for(const auto &cookie : QNetworkCookie::parseCookies(data.toByteArray())) {
+ cookieAdded(cookie);
+ }
}
-}
-ProfileView::~ProfileView()
-{
- delete ui;
-}
+ connect(profile->cookieStore(), &QWebEngineCookieStore::cookieAdded, this, &ProfileView::cookieAdded);
+ connect(profile->cookieStore(), &QWebEngineCookieStore::cookieRemoved, this, &ProfileView::cookieRemoved);
-void ProfileView::loadCookies(QWebEngineCookieStore *store)
-{
- //
- connect(store, &QWebEngineCookieStore::cookieAdded, this, &ProfileView::cookieAdded);
- connect(store, &QWebEngineCookieStore::cookieRemoved, this, &ProfileView::cookieRemoved);
+ connect(ui->cookies_deleteSession, &QPushButton::clicked, profile->cookieStore(), &QWebEngineCookieStore::deleteSessionCookies);
+ connect(ui->cookies_deleteAll, &QPushButton::clicked, profile->cookieStore(), &QWebEngineCookieStore::deleteAllCookies);
- connect(ui->cookies_reload, &QPushButton::clicked, store, [=]() {
- ui->cookies->clearContents();
- ui->cookies->setRowCount(0);
- store->loadAllCookies();
- });
-
- connect(ui->cookies_delete, &QPushButton::clicked, store, [=]() {
+ connect(ui->cookies_delete, &QPushButton::clicked, [this, profile]() {
for(auto &list : ui->cookies->selectedRanges()) {
for(int i = list.bottomRow(); i >= list.topRow(); --i) {
auto cookie = ui->cookies->item(i, 0)->data(Qt::UserRole).value<QNetworkCookie>();
- store->deleteCookie(cookie);
+ profile->cookieStore()->deleteCookie(cookie);
}
}
});
- connect(ui->cookies_deleteSession, &QPushButton::clicked, store, &QWebEngineCookieStore::deleteSessionCookies);
- 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));
- }
+ connect(ui->cookies_reload, &QPushButton::clicked, [this, profile]() {
+ ui->cookies->clearContents();
+ ui->cookies->setRowCount(0);
+ qDebug("loadAllCookies called!");
+ profile->cookieStore()->loadAllCookies();
+ });
+
}
-void ProfileView::headerRemoved(const QString& name)
+ProfileView::~ProfileView()
{
- const auto items = ui->httpHeaders->findItems(name, Qt::MatchExactly);
- if(!items.isEmpty()) {
- ui->httpHeaders->removeRow(items.constFirst()->row());
- }
+ delete ui;
}
void ProfileView::cookieAdded(const QNetworkCookie &cookie)
@@ -212,21 +156,24 @@ void ProfileView::cookieAdded(const QNetworkCookie &cookie)
ui->cookies->setItem(index, 0, item);
ui->cookies->setItem(index, 1, new QTableWidgetItem(cookie.domain()));
ui->cookies->setItem(index, 2, new QTableWidgetItem(cookie.path()));
- if(cookie.isSessionCookie())
+ if(cookie.isSessionCookie()) {
ui->cookies->setItem(index, 3, new QTableWidgetItem(tr("session")));
- else
+ } else {
ui->cookies->setItem(index, 3, new QTableWidgetItem(cookie.expirationDate().toString(Qt::RFC2822Date)));
+ }
}
void ProfileView::cookieRemoved(const QNetworkCookie &cookie)
{
+ qDebug("cookieRemoved called");
+
for(int i = 0; i < ui->cookies->rowCount(); ++i) {
auto *item = ui->cookies->item(i, 0);
- if(item->data(Qt::UserRole).value<QNetworkCookie>() == cookie) {
- //qDebug("removing cookie on row %i", i);
+ if(item->data(Qt::UserRole).value<QNetworkCookie>().hasSameIdentifier(cookie)) {
+ qDebug("removing cookie on row %i", i);
ui->cookies->removeRow(i);
- break;
+ return;
}
+ qDebug("cookie on row %i doesn't have the same identifier", i);
}
}
-