diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-01-15 00:35:58 +0100 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-01-15 00:35:58 +0100 |
commit | 2660fff9e6191808aa83197639a663b73a27bbfa (patch) | |
tree | e01930c4202d87c5b74f701938a0004a952425a1 /plugins/ProfileEditor/forms | |
parent | Initial plugins testing (diff) | |
download | smolbote-2660fff9e6191808aa83197639a663b73a27bbfa.tar.xz |
Moved ProfileView to ProfileEditorPlugin
Diffstat (limited to 'plugins/ProfileEditor/forms')
-rw-r--r-- | plugins/ProfileEditor/forms/profileview.cpp | 119 | ||||
-rw-r--r-- | plugins/ProfileEditor/forms/profileview.h | 37 | ||||
-rw-r--r-- | plugins/ProfileEditor/forms/profileview.ui | 374 |
3 files changed, 530 insertions, 0 deletions
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 <QWebEngineSettings> + +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 <QDialog> +#include <QWebEngineProfile> + +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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>ProfileView</class> + <widget class="QWidget" name="ProfileView"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>640</width> + <height>480</height> + </rect> + </property> + <property name="windowTitle"> + <string>Profile</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QTabWidget" name="tabWidget"> + <property name="currentIndex"> + <number>0</number> + </property> + <widget class="QWidget" name="httpTab"> + <attribute name="title"> + <string>HTTP</string> + </attribute> + <layout class="QFormLayout" name="formLayout_2"> + <item row="0" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>User Agent</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QPlainTextEdit" name="userAgent"/> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label_4"> + <property name="text"> + <string>Accept Language</string> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="label_5"> + <property name="text"> + <string>Cache Type</string> + </property> + </widget> + </item> + <item row="3" column="0"> + <widget class="QLabel" name="label_6"> + <property name="text"> + <string>Cache Size</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QPlainTextEdit" name="acceptLanguage"/> + </item> + <item row="2" column="1"> + <widget class="QComboBox" name="cacheType"> + <item> + <property name="text"> + <string>Memory Cache</string> + </property> + </item> + <item> + <property name="text"> + <string>Disk Cache</string> + </property> + </item> + <item> + <property name="text"> + <string>Disabled</string> + </property> + </item> + </widget> + </item> + <item row="3" column="1"> + <widget class="QLineEdit" name="cacheSize"/> + </item> + <item row="6" column="0"> + <widget class="QLabel" name="storagePath_label"> + <property name="text"> + <string>Storage Path</string> + </property> + </widget> + </item> + <item row="6" column="1"> + <widget class="QLineEdit" name="storagePath_lineEdit"> + <property name="enabled"> + <bool>false</bool> + </property> + </widget> + </item> + <item row="4" column="0"> + <widget class="QLabel" name="cachePath_label"> + <property name="text"> + <string>Cache Path</string> + </property> + </widget> + </item> + <item row="4" column="1"> + <widget class="QLineEdit" name="cachePath_lineEdit"> + <property name="enabled"> + <bool>false</bool> + </property> + </widget> + </item> + <item row="5" column="1"> + <widget class="QPushButton" name="clearCache_pushButton"> + <property name="text"> + <string>Clear Cache</string> + </property> + </widget> + </item> + <item row="7" column="0"> + <widget class="QLabel" name="cookiePolicy_label"> + <property name="text"> + <string>Cookies</string> + </property> + </widget> + </item> + <item row="7" column="1"> + <widget class="QComboBox" name="cookiePolicy"> + <item> + <property name="text"> + <string>No Persistent Cookies</string> + </property> + </item> + <item> + <property name="text"> + <string>Allow Persistent Cookies</string> + </property> + </item> + <item> + <property name="text"> + <string>Force Persistent Cookies</string> + </property> + </item> + </widget> + </item> + <item row="8" column="1"> + <widget class="QPushButton" name="clearHistory_pushButton"> + <property name="text"> + <string>Clear History</string> + </property> + </widget> + </item> + </layout> + </widget> + <widget class="QWidget" name="settingsTab"> + <attribute name="title"> + <string>Settings</string> + </attribute> + <layout class="QVBoxLayout" name="settings_verticalLayout"> + <item> + <widget class="QScrollArea" name="scrollArea"> + <property name="widgetResizable"> + <bool>true</bool> + </property> + <widget class="QWidget" name="scrollAreaWidgetContents"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>584</width> + <height>724</height> + </rect> + </property> + <layout class="QVBoxLayout" name="verticalLayout_4"> + <item> + <widget class="QCheckBox" name="autoloadImages_checkBox"> + <property name="text"> + <string>Autoload images</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="autoloadIcons_checkBox"> + <property name="text"> + <string>Autoload icons</string> + </property> + </widget> + </item> + <item> + <widget class="Line" name="line"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="javascriptEnabled"> + <property name="text"> + <string>JavaScript enabled</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="javascriptCanOpenWindows"> + <property name="text"> + <string>JavaScript can open windows</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="javascriptCanAccessClipboard"> + <property name="text"> + <string>JavaScript can access clipboard</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="javascriptCanActivateWindows"> + <property name="text"> + <string>JavaScript can activate windows</string> + </property> + </widget> + </item> + <item> + <widget class="Line" name="line_2"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="checkBox_11"> + <property name="text"> + <string>CheckBox</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="checkBox_23"> + <property name="text"> + <string>CheckBox</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="checkBox_25"> + <property name="text"> + <string>CheckBox</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="checkBox_24"> + <property name="text"> + <string>CheckBox</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="checkBox_19"> + <property name="text"> + <string>CheckBox</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="checkBox_22"> + <property name="text"> + <string>CheckBox</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="checkBox_21"> + <property name="text"> + <string>CheckBox</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="checkBox_14"> + <property name="text"> + <string>CheckBox</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="checkBox_16"> + <property name="text"> + <string>CheckBox</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="checkBox_18"> + <property name="text"> + <string>CheckBox</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="checkBox_17"> + <property name="text"> + <string>CheckBox</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="checkBox_15"> + <property name="text"> + <string>CheckBox</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="checkBox_13"> + <property name="text"> + <string>CheckBox</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="checkBox_10"> + <property name="text"> + <string>CheckBox</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="checkBox_7"> + <property name="text"> + <string>CheckBox</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="checkBox_8"> + <property name="text"> + <string>CheckBox</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="checkBox_5"> + <property name="text"> + <string>CheckBox</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="checkBox_3"> + <property name="text"> + <string>CheckBox</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="checkBox"> + <property name="text"> + <string>CheckBox</string> + </property> + </widget> + </item> + </layout> + </widget> + </widget> + </item> + </layout> + </widget> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> |