From 2660fff9e6191808aa83197639a663b73a27bbfa Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Mon, 15 Jan 2018 00:35:58 +0100 Subject: Moved ProfileView to ProfileEditorPlugin --- plugins/ProfileEditor/forms/profileview.cpp | 119 +++++++++ plugins/ProfileEditor/forms/profileview.h | 37 +++ plugins/ProfileEditor/forms/profileview.ui | 374 ++++++++++++++++++++++++++++ 3 files changed, 530 insertions(+) create mode 100644 plugins/ProfileEditor/forms/profileview.cpp create mode 100644 plugins/ProfileEditor/forms/profileview.h create mode 100644 plugins/ProfileEditor/forms/profileview.ui (limited to 'plugins/ProfileEditor/forms') diff --git a/plugins/ProfileEditor/forms/profileview.cpp b/plugins/ProfileEditor/forms/profileview.cpp new file mode 100644 index 0000000..ef0fece --- /dev/null +++ b/plugins/ProfileEditor/forms/profileview.cpp @@ -0,0 +1,119 @@ +/* + * 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: git://neueland.iserlohn-fortress.net/smolbote.git + * + * SPDX-License-Identifier: GPL-3.0 + */ + +#include "profileview.h" +#include "ui_profileview.h" +#include + +inline void connectCheckBox(QCheckBox *checkBox, QWebEngineSettings *settings, QWebEngineSettings::WebAttribute attr) +{ + QObject::connect(checkBox, &QCheckBox::clicked, [settings, attr](bool checked){ + settings->setAttribute(attr, checked); + }); +} + + +ProfileView::ProfileView(QWebEngineProfile *profile, QWidget *parent) + : QDialog(parent) + , ui(new Ui::ProfileView) +{ + Q_CHECK_PTR(profile); + m_profile = profile; + ui->setupUi(this); + + QWebEngineSettings *settings = m_profile->settings(); + connectCheckBox(ui->autoloadImages_checkBox, settings, QWebEngineSettings::AutoLoadImages); + connectCheckBox(ui->autoloadIcons_checkBox, settings, QWebEngineSettings::AutoLoadIconsForPage); + + connectCheckBox(ui->javascriptEnabled, settings, QWebEngineSettings::JavascriptEnabled); + connectCheckBox(ui->javascriptCanAccessClipboard, settings, QWebEngineSettings::JavascriptCanAccessClipboard); + connectCheckBox(ui->javascriptCanOpenWindows, settings, QWebEngineSettings::JavascriptCanOpenWindows); + connectCheckBox(ui->javascriptCanActivateWindows, settings, QWebEngineSettings::AllowWindowActivationFromJavaScript); + + // actions + connect(ui->clearCache_pushButton, &QPushButton::clicked, [this]() { + this->m_profile->clearHttpCache(); + }); + connect(ui->clearHistory_pushButton, &QPushButton::clicked, [this]() { + this->m_profile->clearAllVisitedLinks(); + }); + + loadProfile(); +} + +ProfileView::~ProfileView() +{ + delete ui; +} + +void ProfileView::loadProfile() +{ + if(m_profile->storageName().isEmpty()) + setWindowTitle(tr("Off-the-record")); + else + setWindowTitle(m_profile->storageName()); + + // 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()); + + // settings + QWebEngineSettings *settings = m_profile->settings(); + ui->autoloadImages_checkBox->setChecked(settings->testAttribute(QWebEngineSettings::AutoLoadImages)); + ui->autoloadIcons_checkBox->setChecked(settings->testAttribute(QWebEngineSettings::AutoLoadIconsForPage)); + + ui->javascriptEnabled->setChecked(settings->testAttribute(QWebEngineSettings::JavascriptEnabled)); + ui->javascriptCanAccessClipboard->setChecked(settings->testAttribute(QWebEngineSettings::JavascriptCanAccessClipboard)); + ui->javascriptCanOpenWindows->setChecked(settings->testAttribute(QWebEngineSettings::JavascriptCanOpenWindows)); + ui->javascriptCanActivateWindows->setChecked(settings->testAttribute(QWebEngineSettings::AllowWindowActivationFromJavaScript)); + + // policy + ui->cookiePolicy->setCurrentIndex(m_profile->persistentCookiesPolicy()); +} + +void ProfileView::updateProfile() +{ + // http + m_profile->setHttpUserAgent(ui->userAgent->toPlainText()); + m_profile->setHttpAcceptLanguage(ui->acceptLanguage->toPlainText()); + switch(ui->cacheType->currentIndex()) { + case 0: + m_profile->setHttpCacheType(QWebEngineProfile::MemoryHttpCache); + break; + case 1: + m_profile->setHttpCacheType(QWebEngineProfile::DiskHttpCache); + break; + case 2: + m_profile->setHttpCacheType(QWebEngineProfile::NoCache); + break; + default: + break; + } + m_profile->setHttpCacheMaximumSize(ui->cacheSize->text().toInt()); + + // policy + switch(ui->cookiePolicy->currentIndex()) { + case 0: + m_profile->setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies); + break; + case 1: + m_profile->setPersistentCookiesPolicy(QWebEngineProfile::AllowPersistentCookies); + break; + case 2: + m_profile->setPersistentCookiesPolicy(QWebEngineProfile::ForcePersistentCookies); + break; + default: + break; + } +} diff --git a/plugins/ProfileEditor/forms/profileview.h b/plugins/ProfileEditor/forms/profileview.h new file mode 100644 index 0000000..580bee9 --- /dev/null +++ b/plugins/ProfileEditor/forms/profileview.h @@ -0,0 +1,37 @@ +/* + * 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: git://neueland.iserlohn-fortress.net/smolbote.git + * + * SPDX-License-Identifier: GPL-3.0 + */ + +#ifndef PROFILEDIALOG_H +#define PROFILEDIALOG_H + +#include +#include + +namespace Ui +{ +class ProfileView; +} + +class ProfileView : public QDialog +{ + Q_OBJECT + +public: + explicit ProfileView(QWebEngineProfile *profile, QWidget *parent = nullptr); + ~ProfileView() override; + +public slots: + void loadProfile(); + void updateProfile(); + +private: + Ui::ProfileView *ui; + QWebEngineProfile *m_profile; +}; + +#endif // PROFILEDIALOG_H diff --git a/plugins/ProfileEditor/forms/profileview.ui b/plugins/ProfileEditor/forms/profileview.ui new file mode 100644 index 0000000..1e6f94f --- /dev/null +++ b/plugins/ProfileEditor/forms/profileview.ui @@ -0,0 +1,374 @@ + + + ProfileView + + + + 0 + 0 + 640 + 480 + + + + Profile + + + + + + 0 + + + + HTTP + + + + + + User Agent + + + + + + + + + + Accept Language + + + + + + + Cache Type + + + + + + + Cache Size + + + + + + + + + + + Memory Cache + + + + + Disk Cache + + + + + Disabled + + + + + + + + + + + Storage Path + + + + + + + false + + + + + + + Cache Path + + + + + + + false + + + + + + + Clear Cache + + + + + + + Cookies + + + + + + + + No Persistent Cookies + + + + + Allow Persistent Cookies + + + + + Force Persistent Cookies + + + + + + + + Clear History + + + + + + + + Settings + + + + + + true + + + + + 0 + 0 + 584 + 724 + + + + + + + Autoload images + + + + + + + Autoload icons + + + + + + + Qt::Horizontal + + + + + + + JavaScript enabled + + + + + + + JavaScript can open windows + + + + + + + JavaScript can access clipboard + + + + + + + JavaScript can activate windows + + + + + + + Qt::Horizontal + + + + + + + CheckBox + + + + + + + CheckBox + + + + + + + CheckBox + + + + + + + CheckBox + + + + + + + CheckBox + + + + + + + CheckBox + + + + + + + CheckBox + + + + + + + CheckBox + + + + + + + CheckBox + + + + + + + CheckBox + + + + + + + CheckBox + + + + + + + CheckBox + + + + + + + CheckBox + + + + + + + CheckBox + + + + + + + CheckBox + + + + + + + CheckBox + + + + + + + CheckBox + + + + + + + CheckBox + + + + + + + CheckBox + + + + + + + + + + + + + + + + -- cgit v1.2.1