From b27e55b0bbba9a1678159abe44280e173374f971 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sat, 16 Jun 2018 13:55:35 +0200 Subject: Sort .profile by time Remove ProfileInterface::setProfiles ProfileView: Add General tab ProfileView: some cleanup ProfileView: Add Cookies tab --- plugins/ProfileEditor/forms/profileview.cpp | 127 +++++++++++++++++----------- 1 file changed, 76 insertions(+), 51 deletions(-) (limited to 'plugins/ProfileEditor/forms/profileview.cpp') diff --git a/plugins/ProfileEditor/forms/profileview.cpp b/plugins/ProfileEditor/forms/profileview.cpp index 2d96d43..f2e74ad 100644 --- a/plugins/ProfileEditor/forms/profileview.cpp +++ b/plugins/ProfileEditor/forms/profileview.cpp @@ -8,16 +8,20 @@ #include "profileview.h" #include "ui_profileview.h" +#include #include +#include +#include inline void connectSetting(QCheckBox *checkBox, QWebEngineSettings *settings, QWebEngineSettings::WebAttribute attr) { + checkBox->setChecked(settings->testAttribute(attr)); QObject::connect(checkBox, &QCheckBox::clicked, [settings, attr](bool checked) { settings->setAttribute(attr, checked); }); } -ProfileView::ProfileView(QWebEngineProfile *profile, QWidget *parent) +ProfileView::ProfileView(WebProfile *profile, QWidget *parent) : QWidget(parent) , ui(new Ui::ProfileView) { @@ -25,28 +29,58 @@ ProfileView::ProfileView(QWebEngineProfile *profile, QWidget *parent) m_profile = profile; ui->setupUi(this); - loadProfile(); + // general tab + ui->name->setText(profile->name()); + ui->offTheRecord->setChecked(profile->isOffTheRecord()); + ui->configurationPath->setText(profile->configurationPath()); // http tab + ui->userAgent->setPlainText(m_profile->httpUserAgent()); connect(ui->userAgent, &QPlainTextEdit::textChanged, profile, [=]() { profile->setHttpUserAgent(ui->userAgent->toPlainText()); }); + + ui->acceptLanguage->setPlainText(m_profile->httpAcceptLanguage()); connect(ui->acceptLanguage, &QPlainTextEdit::textChanged, profile, [=]() { profile->setHttpAcceptLanguage(ui->acceptLanguage->toPlainText()); }); + + ui->cacheType->setCurrentIndex(m_profile->httpCacheType()); connect(ui->cacheType, QOverload::of(&QComboBox::currentIndexChanged), profile, [=](int index) { profile->setHttpCacheType(static_cast(index)); }); + + ui->cacheSize->setText(QString::number(m_profile->httpCacheMaximumSize())); connect(ui->cacheSize, &QLineEdit::textChanged, profile, [=](const QString &text) { profile->setHttpCacheMaximumSize(text.toInt()); }); + + ui->cookiePolicy->setCurrentIndex(m_profile->persistentCookiesPolicy()); connect(ui->cookiePolicy, QOverload::of(&QComboBox::currentIndexChanged), profile, [=](int index) { profile->setPersistentCookiesPolicy(static_cast(index)); }); + connect(ui->clearCache_pushButton, &QPushButton::clicked, profile, &QWebEngineProfile::clearHttpCache); connect(ui->clearHistory_pushButton, &QPushButton::clicked, profile, &QWebEngineProfile::clearAllVisitedLinks); - QWebEngineSettings *settings = m_profile->settings(); + ui->storagePath_lineEdit->setText(m_profile->persistentStoragePath()); + ui->cachePath_lineEdit->setText(m_profile->cachePath()); + + // settings tab + loadSettings(profile->settings()); + + // cookies tab + loadCookies(profile->cookieStore()); +} + +ProfileView::~ProfileView() +{ + delete ui; +} + +void ProfileView::loadSettings(QWebEngineSettings *settings) +{ + // settings connectSetting(ui->autoloadImages, settings, QWebEngineSettings::AutoLoadImages); connectSetting(ui->autoloadIcons, settings, QWebEngineSettings::AutoLoadIconsForPage); @@ -82,57 +116,48 @@ ProfileView::ProfileView(QWebEngineProfile *profile, QWidget *parent) connectSetting(ui->printElementBackgrounds, settings, QWebEngineSettings::PrintElementBackgrounds); } -ProfileView::~ProfileView() +void ProfileView::loadCookies(QWebEngineCookieStore *store) { - delete ui; -} + // + connect(store, &QWebEngineCookieStore::cookieAdded, this, &ProfileView::cookieAdded); + connect(store, &QWebEngineCookieStore::cookieRemoved, this, &ProfileView::cookieRemoved); + + connect(ui->cookies_reload, &QPushButton::clicked, store, [=]() { + ui->cookies->clearContents(); + ui->cookies->setRowCount(0); + store->loadAllCookies(); + }); -void ProfileView::loadProfile() -{ - if(m_profile->storageName().isEmpty()) - setWindowTitle(tr("Off-the-record")); - else - setWindowTitle(m_profile->storageName()); + connect(ui->cookies_delete, &QPushButton::clicked, store, [=]() { + auto index = ui->cookies->currentRow(); + auto cookie = ui->cookies->item(index, 0)->data(Qt::UserRole).value(); + store->deleteCookie(cookie); + }); - // http - ui->userAgent->setPlainText(m_profile->httpUserAgent()); - ui->acceptLanguage->setPlainText(m_profile->httpAcceptLanguage()); - ui->cacheType->setCurrentIndex(m_profile->httpCacheType()); - ui->cacheSize->setText(QString::number(m_profile->httpCacheMaximumSize())); +} - // path - ui->storagePath_lineEdit->setText(m_profile->persistentStoragePath()); - ui->cachePath_lineEdit->setText(m_profile->cachePath()); +void ProfileView::cookieAdded(const QNetworkCookie &cookie) +{ + auto index = ui->cookies->rowCount(); + ui->cookies->setRowCount(index + 1); + + auto *item = new QTableWidgetItem(QString(cookie.name())); + item->setData(Qt::UserRole, QVariant::fromValue(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())); + ui->cookies->setItem(index, 3, new QTableWidgetItem(cookie.expirationDate().toString(Qt::RFC2822Date))); +} - // settings - QWebEngineSettings *settings = m_profile->settings(); - ui->autoloadImages->setChecked(settings->testAttribute(QWebEngineSettings::AutoLoadImages)); - ui->javascriptEnabled->setChecked(settings->testAttribute(QWebEngineSettings::JavascriptEnabled)); - ui->javascriptCanOpenWindows->setChecked(settings->testAttribute(QWebEngineSettings::JavascriptCanOpenWindows)); - ui->javascriptCanAccessClipboard->setChecked(settings->testAttribute(QWebEngineSettings::JavascriptCanAccessClipboard)); - ui->linksIncludedInFocusChain->setChecked(settings->testAttribute(QWebEngineSettings::LinksIncludedInFocusChain)); - ui->localStorageEnabled->setChecked(settings->testAttribute(QWebEngineSettings::LocalStorageEnabled)); - ui->localContentCanAccessRemoteUrls->setChecked(settings->testAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls)); - ui->xssAuditingEnabled->setChecked(settings->testAttribute(QWebEngineSettings::XSSAuditingEnabled)); - ui->spatialNavigationEnabled->setChecked(settings->testAttribute(QWebEngineSettings::SpatialNavigationEnabled)); - ui->localContentCanAccessFileUrls->setChecked(settings->testAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls)); - ui->hyperlinkAuditingEnabled->setChecked(settings->testAttribute(QWebEngineSettings::HyperlinkAuditingEnabled)); - ui->scrollAnimatorEnabled->setChecked(settings->testAttribute(QWebEngineSettings::ScrollAnimatorEnabled)); - ui->errorPagesEnabled->setChecked(settings->testAttribute(QWebEngineSettings::ErrorPageEnabled)); - ui->ppapiPluginsEnabled->setChecked(settings->testAttribute(QWebEngineSettings::PluginsEnabled)); - ui->fullscreenSupportEnabled->setChecked(settings->testAttribute(QWebEngineSettings::FullScreenSupportEnabled)); - ui->screenCaptureEnabled->setChecked(settings->testAttribute(QWebEngineSettings::ScreenCaptureEnabled)); - ui->webglEnabled->setChecked(settings->testAttribute(QWebEngineSettings::WebGLEnabled)); - ui->canvasEnabled->setChecked(settings->testAttribute(QWebEngineSettings::Accelerated2dCanvasEnabled)); - ui->autoloadIcons->setChecked(settings->testAttribute(QWebEngineSettings::AutoLoadIconsForPage)); - ui->touchIconsEnabled->setChecked(settings->testAttribute(QWebEngineSettings::TouchIconsEnabled)); - ui->focusOnNavigationEnabled->setChecked(settings->testAttribute(QWebEngineSettings::FocusOnNavigationEnabled)); - ui->printElementBackgrounds->setChecked(settings->testAttribute(QWebEngineSettings::PrintElementBackgrounds)); - ui->allowRunningInsecureContent->setChecked(settings->testAttribute(QWebEngineSettings::AllowRunningInsecureContent)); - ui->allowGeolocationOnInsecureContent->setChecked(settings->testAttribute(QWebEngineSettings::AllowGeolocationOnInsecureOrigins)); - ui->javascriptCanActivateWindows->setChecked(settings->testAttribute(QWebEngineSettings::AllowWindowActivationFromJavaScript)); - ui->showScrollBars->setChecked(settings->testAttribute(QWebEngineSettings::ShowScrollBars)); - - // policy - ui->cookiePolicy->setCurrentIndex(m_profile->persistentCookiesPolicy()); +void ProfileView::cookieRemoved(const QNetworkCookie &cookie) +{ + for(int i = 0; i < ui->cookies->rowCount(); ++i) { + auto *item = ui->cookies->item(i, 0); + if(item->data(Qt::UserRole).value() == cookie) { + //qDebug("removing cookie on row %i", i); + ui->cookies->removeRow(i); + break; + } + } } + -- cgit v1.2.1