From 9365cdce4117d2a4512b9f2aa139d91a792d11ee Mon Sep 17 00:00:00 2001 From: Juraj Oravec Date: Sun, 28 Aug 2022 03:30:18 +0200 Subject: [PATCH] Add mockup permissions UI into SiteInfo window Signed-off-by: Juraj Oravec --- src/lib/CMakeLists.txt | 3 + src/lib/other/siteinfo.cpp | 34 +++++ src/lib/other/siteinfo.h | 3 + src/lib/other/siteinfo.ui | 19 +++ src/lib/other/siteinfopermissionitem.cpp | 119 ++++++++++++++++++ src/lib/other/siteinfopermissionitem.h | 61 +++++++++ src/lib/other/siteinfopermissionitem.ui | 76 +++++++++++ src/lib/other/sitesettingsmanager.cpp | 38 ++++++ src/lib/other/sitesettingsmanager.h | 3 + .../html5permissions/html5permissionsitem.cpp | 39 +----- 10 files changed, 358 insertions(+), 37 deletions(-) create mode 100644 src/lib/other/siteinfopermissionitem.cpp create mode 100644 src/lib/other/siteinfopermissionitem.h create mode 100644 src/lib/other/siteinfopermissionitem.ui diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 53bfc58fb..5f1ad7465 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -149,6 +149,7 @@ set(SRCS ${SRCS} other/licenseviewer.cpp other/qzsettings.cpp other/siteinfo.cpp + other/siteinfopermissionitem.cpp other/siteinfowidget.cpp other/sitesettingsmanager.cpp other/statusbar.cpp @@ -381,6 +382,7 @@ set(SRCS ${SRCS} other/licenseviewer.h other/qzsettings.h other/siteinfo.h + other/siteinfopermissionitem.h other/siteinfowidget.h other/sitesettingsmanager.h other/statusbar.h @@ -547,6 +549,7 @@ qt_wrap_ui(SRCS other/iconchooser.ui other/protocolhandlerdialog.ui other/siteinfo.ui + other/siteinfopermissionitem.ui other/siteinfowidget.ui preferences/acceptlanguage.ui preferences/addacceptlanguage.ui diff --git a/src/lib/other/siteinfo.cpp b/src/lib/other/siteinfo.cpp index 2070255ee..6126da983 100644 --- a/src/lib/other/siteinfo.cpp +++ b/src/lib/other/siteinfo.cpp @@ -28,6 +28,7 @@ #include "scripts.h" #include "networkmanager.h" #include "locationbar.h" +#include "siteinfopermissionitem.h" #include #include @@ -37,6 +38,7 @@ #include #include #include +#include SiteInfo::SiteInfo(WebView *view) : QDialog(view) @@ -122,6 +124,18 @@ SiteInfo::SiteInfo(WebView *view) } }); + // Permissions + addPermissionOption(SiteSettingsManager::poAllowJavascript); + addPermissionOption(SiteSettingsManager::poAllowImages); + addPermissionOption(SiteSettingsManager::poAllowNotifications); + addPermissionOption(SiteSettingsManager::poAllowGeolocation); + addPermissionOption(SiteSettingsManager::poAllowMediaAudioCapture); + addPermissionOption(SiteSettingsManager::poAllowMediaVideoCapture); + addPermissionOption(SiteSettingsManager::poAllowMediaAudioVideoCapture); + addPermissionOption(SiteSettingsManager::poAllowMouseLock); + addPermissionOption(SiteSettingsManager::poAllowDesktopVideoCapture); + addPermissionOption(SiteSettingsManager::poAllowDesktopAudioVideoCapture); + connect(ui->saveButton, SIGNAL(clicked(QAbstractButton*)), this, SLOT(saveImage())); connect(ui->listWidget, SIGNAL(currentRowChanged(int)), ui->stackedWidget, SLOT(setCurrentIndex(int))); connect(ui->treeImages, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(showImagePreview(QTreeWidgetItem*))); @@ -323,3 +337,23 @@ SiteInfo::~SiteInfo() delete ui; delete m_certWidget; } + +void SiteInfo::addPermissionOption(const SiteSettingsManager::PageOptions option) +{ + auto perm = mApp->siteSettingsManager()->getPermission(SiteSettingsManager::poAllowJavascript, m_baseUrl); + auto* listItem = new QListWidgetItem(ui->listPermissions); + auto* optionItem = new SiteInfoPermissionItem(option, perm, this); + + switch (option) { + case SiteSettingsManager::poAllowJavascript: + case SiteSettingsManager::poAllowImages: + case SiteSettingsManager::poAllowCookies: + optionItem->setHasOptionAsk(false); + break; + default: + break; + } + + ui->listPermissions->setItemWidget(listItem, optionItem); + listItem->setSizeHint(optionItem->sizeHint()); +} diff --git a/src/lib/other/siteinfo.h b/src/lib/other/siteinfo.h index 99cf36162..e7fc680a6 100644 --- a/src/lib/other/siteinfo.h +++ b/src/lib/other/siteinfo.h @@ -19,6 +19,7 @@ #define SITEINFO_H #include "qzcommon.h" +#include "sitesettingsmanager.h" #include #include @@ -56,6 +57,8 @@ private: void showLoadingText(); void showPixmap(QPixmap pixmap); + void addPermissionOption(const SiteSettingsManager::PageOptions option); + Ui::SiteInfo* ui; CertificateInfoWidget* m_certWidget; WebView* m_view; diff --git a/src/lib/other/siteinfo.ui b/src/lib/other/siteinfo.ui index 878474f41..7ae45ef30 100644 --- a/src/lib/other/siteinfo.ui +++ b/src/lib/other/siteinfo.ui @@ -52,6 +52,11 @@ Media + + + Permissions + + @@ -281,6 +286,20 @@ + + + + + + true + + + QAbstractItemView::ScrollPerPixel + + + + + diff --git a/src/lib/other/siteinfopermissionitem.cpp b/src/lib/other/siteinfopermissionitem.cpp new file mode 100644 index 000000000..79de28a6b --- /dev/null +++ b/src/lib/other/siteinfopermissionitem.cpp @@ -0,0 +1,119 @@ +/* ============================================================ + * Falkon - Qt web browser + * Copyright (C) 2022 Juraj Oravec + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * ============================================================ */ + +#include "siteinfopermissionitem.h" +#include "ui_siteinfopermissionitem.h" +#include "mainapplication.h" +#include "sitesettingsmanager.h" + + +SiteInfoPermissionItem::SiteInfoPermissionItem(const SiteSettingsManager::PageOptions &a_option, const SiteSettingsManager::Permission &a_permission, QWidget* parent) +: QWidget(parent) +, m_option(a_option) +, m_ui(new Ui::SiteInfoPermissionItem()) +{ + m_ui->setupUi(this); + + setPermission(a_permission); + m_ui->label->setText(mApp->siteSettingsManager()->getOptionName(a_option)); +} + +SiteInfoPermissionItem::~SiteInfoPermissionItem() +{ +} + +bool SiteInfoPermissionItem::hasOptionAsk() const +{ + return m_hasOptionAsk; +} + +void SiteInfoPermissionItem::setHasOptionAsk(bool hasOptionAsk) +{ + if (m_hasOptionAsk == hasOptionAsk) { + return; + } + + m_hasOptionAsk = hasOptionAsk; + m_ui->radioAsk->setVisible(hasOptionAsk); +} + +bool SiteInfoPermissionItem::hasOptionDefault() const +{ + return m_hasOptionDefault; +} + +void SiteInfoPermissionItem::setHasOptionDefault(bool hasOptionDefault) +{ + if (m_hasOptionDefault == hasOptionDefault) { + return; + } + + m_hasOptionDefault = hasOptionDefault; + m_ui->radioDefault->setVisible(hasOptionDefault); +} + +void SiteInfoPermissionItem::setPermission(SiteSettingsManager::Permission permission) +{ + m_ui->radioAllow->setChecked(false); + m_ui->radioAsk->setChecked(false); + m_ui->radioDeny->setChecked(false); + m_ui->radioDefault->setChecked(false); + + switch (permission) { + case SiteSettingsManager::Allow: + m_ui->radioAllow->setChecked(true); + break; + case SiteSettingsManager::Ask: + m_ui->radioAsk->setChecked(true); + break; + case SiteSettingsManager::Deny: + m_ui->radioDeny->setChecked(true); + break; + case SiteSettingsManager::Default: + m_ui->radioDefault->setChecked(true); + break; + default: + qWarning() << "Unknown permission" << permission; + m_ui->radioDefault->setChecked(true); + } +} + +SiteSettingsManager::Permission SiteInfoPermissionItem::permission() const +{ + if (m_ui->radioAllow->isChecked()) { + return SiteSettingsManager::Allow; + } + else if (m_ui->radioAsk->isChecked()) { + return SiteSettingsManager::Ask; + } + else if (m_ui->radioDeny->isChecked()) { + return SiteSettingsManager::Deny; + } + else if (m_ui->radioDefault->isChecked()) { + return SiteSettingsManager::Default; + } + else { + qWarning() << "No permission is selected"; + return SiteSettingsManager::Default; + } +} + +SiteSettingsManager::PageOptions SiteInfoPermissionItem::option() const +{ + return m_option; +} diff --git a/src/lib/other/siteinfopermissionitem.h b/src/lib/other/siteinfopermissionitem.h new file mode 100644 index 000000000..0ce69fb6f --- /dev/null +++ b/src/lib/other/siteinfopermissionitem.h @@ -0,0 +1,61 @@ +/* ============================================================ + * Falkon - Qt web browser + * Copyright (C) 2022 Juraj Oravec + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * ============================================================ */ + +#ifndef SITEINFOPERMISSIONITEM_H +#define SITEINFOPERMISSIONITEM_H + +#include "sitesettingsmanager.h" +#include +#include + +namespace Ui +{ +class SiteInfoPermissionItem; +} + +/** + * @todo write docs + */ +class SiteInfoPermissionItem : public QWidget +{ + Q_OBJECT + +public: + explicit SiteInfoPermissionItem(const SiteSettingsManager::PageOptions &a_option, const SiteSettingsManager::Permission &a_permission, QWidget* parent = nullptr); + ~SiteInfoPermissionItem(); + + bool hasOptionAsk() const; + bool hasOptionDefault() const; + + SiteSettingsManager::Permission permission() const; + SiteSettingsManager::PageOptions option() const; + + void setHasOptionAsk(bool hasAsk); + void setHasOptionDefault(bool hasDefault); + void setPermission(SiteSettingsManager::Permission permission); + +private: + bool m_hasOptionAsk; + bool m_hasOptionDefault; + SiteSettingsManager::PageOptions m_option; + +private: + QScopedPointer m_ui; +}; + +#endif // SITEINFOPERMISSIONITEM_H diff --git a/src/lib/other/siteinfopermissionitem.ui b/src/lib/other/siteinfopermissionitem.ui new file mode 100644 index 000000000..053661887 --- /dev/null +++ b/src/lib/other/siteinfopermissionitem.ui @@ -0,0 +1,76 @@ + + + SiteInfoPermissionItem + + + + 0 + 0 + 556 + 66 + + + + + + + + 75 + true + + + + + + + + + + + + + Default + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Ask + + + + + + + Allow + + + + + + + Deny + + + + + + + + + + diff --git a/src/lib/other/sitesettingsmanager.cpp b/src/lib/other/sitesettingsmanager.cpp index b58dd020b..dfc81c29f 100644 --- a/src/lib/other/sitesettingsmanager.cpp +++ b/src/lib/other/sitesettingsmanager.cpp @@ -409,3 +409,41 @@ SiteSettingsManager::Permission SiteSettingsManager::intToPermission(const int p return Default; } } + +QString SiteSettingsManager::getOptionName(const SiteSettingsManager::PageOptions& option) +{ + switch (option) { + case poAllowJavascript: + return QSL("JavaScript"); + case poAllowImages: + return QSL("Autoload Images"); + case poZoomLevel: + return QSL("Zoom level"); + case poAllowCookies: + return QSL("Cookies"); + case poAllowNotifications: + return QSL("Notifications"); + case poAllowGeolocation: + return QSL("Location"); + case poAllowMediaAudioCapture: + return QSL("Microphone"); + case poAllowMediaVideoCapture: + return QSL("Camera"); + case poAllowMediaAudioVideoCapture: + return QSL("Microphone and Camera"); + case poAllowMouseLock: + return QSL("Hide mouse pointer"); + case poAllowDesktopVideoCapture: + return QSL("Screen capture"); + case poAllowDesktopAudioVideoCapture: + return QSL("Screen capture with audio"); + default: + qWarning() << "Unknown option" << option; + return QSL("Unknown");; + } +} + +QString SiteSettingsManager::getOptionName(const QWebEnginePage::Feature& feature) +{ + return getOptionName(optionFromWebEngineFeature(feature)); +} diff --git a/src/lib/other/sitesettingsmanager.h b/src/lib/other/sitesettingsmanager.h index 4a51507b0..72c3cacf3 100644 --- a/src/lib/other/sitesettingsmanager.h +++ b/src/lib/other/sitesettingsmanager.h @@ -109,6 +109,9 @@ public: QString sqlColumnFromWebEngineFeature(const QWebEnginePage::Feature &feature); + QString getOptionName(const SiteSettingsManager::PageOptions &option); + QString getOptionName(const QWebEnginePage::Feature &feature); + private: QString optionToSqlColumn(const PageOptions &option); bool getDefaultOptionValue(const PageOptions &option); diff --git a/src/lib/tools/html5permissions/html5permissionsitem.cpp b/src/lib/tools/html5permissions/html5permissionsitem.cpp index a2ba0c9c2..b2bf4449e 100644 --- a/src/lib/tools/html5permissions/html5permissionsitem.cpp +++ b/src/lib/tools/html5permissions/html5permissionsitem.cpp @@ -17,6 +17,7 @@ * ============================================================ */ #include "html5permissionsitem.h" #include "ui_html5permissionsitem.h" +#include "mainapplication.h" HTML5PermissionsItem::HTML5PermissionsItem(const QWebEnginePage::Feature& feature, const SiteSettingsManager::Permission& permission, QWidget* parent) @@ -58,43 +59,7 @@ void HTML5PermissionsItem::permissionIndexChanged() void HTML5PermissionsItem::setLabel() { - switch (m_feature) { - case QWebEnginePage::Notifications: - ui->label->setText("Notifications"); - break; - - case QWebEnginePage::Geolocation: - ui->label->setText("Location"); - break; - - case QWebEnginePage::MediaAudioCapture: - ui->label->setText("Microphone"); - break; - - case QWebEnginePage::MediaVideoCapture: - ui->label->setText("Camera"); - break; - - case QWebEnginePage::MediaAudioVideoCapture: - ui->label->setText("Microphone and Camera"); - break; - - case QWebEnginePage::MouseLock: - ui->label->setText("Hide mouse pointer"); - break; - - case QWebEnginePage::DesktopVideoCapture: - ui->label->setText("Screen capture"); - break; - - case QWebEnginePage::DesktopAudioVideoCapture: - ui->label->setText("Screen capture with audio"); - break; - - default: - qWarning() << "Unknown feature" << m_feature; - break; - } + ui->label->setText(mApp->siteSettingsManager()->getOptionName(m_feature)); } void HTML5PermissionsItem::setCombo()