1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

Asdd UI for default HTML5 permission settings

- It is a dummy UI, may change in the future.

Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
Juraj Oravec 2022-08-21 00:43:37 +02:00
parent 0c462f0a1c
commit 5eff4dc0e5
Signed by: SGOrava
GPG Key ID: 13660A3F1D9F093B
8 changed files with 429 additions and 120 deletions

View File

@ -244,6 +244,7 @@ set(SRCS ${SRCS}
tools/headerview.cpp
tools/horizontallistwidget.cpp
tools/html5permissions/html5permissionsdialog.cpp
tools/html5permissions/html5permissionsitem.cpp
tools/html5permissions/html5permissionsmanager.cpp
tools/html5permissions/html5permissionsnotification.cpp
tools/iconprovider.cpp
@ -475,6 +476,7 @@ set(SRCS ${SRCS}
tools/headerview.h
tools/horizontallistwidget.h
tools/html5permissions/html5permissionsdialog.h
tools/html5permissions/html5permissionsitem.h
tools/html5permissions/html5permissionsmanager.h
tools/html5permissions/html5permissionsnotification.h
tools/iconprovider.h
@ -562,6 +564,7 @@ qt_wrap_ui(SRCS
tools/certificateinfowidget.ui
tools/docktitlebarwidget.ui
tools/html5permissions/html5permissionsdialog.ui
tools/html5permissions/html5permissionsitem.ui
tools/html5permissions/html5permissionsnotification.ui
webengine/jsalert.ui
webengine/jsconfirm.ui

View File

@ -21,7 +21,6 @@
#include "settings.h"
#include "sqldatabase.h"
#include <QUrl>
#include <qwebenginesettings.h>
SiteSettingsManager::SiteSettingsManager ( QObject* parent )
: QObject(parent)
@ -191,11 +190,28 @@ QString SiteSettingsManager::optionToSqlColumn(const SiteSettingsManager::PageOp
return QSL("allow_desktop_audio_video_capture");
default:
Q_UNREACHABLE();
qWarning() << "Unknown option" << option;
return QLatin1String("");
}
}
SiteSettingsManager::Permission SiteSettingsManager::getDefaultPermission(const SiteSettingsManager::PageOptions& option)
{
switch (option) {
case poAllowJavascript:
return testAttribute(QWebEngineSettings::JavascriptEnabled);
case poAllowImages:
return testAttribute(QWebEngineSettings::AutoLoadImages);
default:
Q_UNREACHABLE();
qWarning() << "Unknown option" << option;
return Deny;
}
}
bool SiteSettingsManager::getDefaultOptionValue(const SiteSettingsManager::PageOptions& option)
{
switch (option) {
@ -213,12 +229,13 @@ bool SiteSettingsManager::getDefaultOptionValue(const SiteSettingsManager::PageO
return false;
default:
Q_UNREACHABLE();
qWarning() << "Unknown option" << option;
return false;
}
}
SiteSettingsManager::PageOptions SiteSettingsManager::optionFromWebEngineFeature(const QWebEnginePage::Feature& feature)
SiteSettingsManager::PageOptions SiteSettingsManager::optionFromWebEngineFeature(const QWebEnginePage::Feature& feature) const
{
switch (feature) {
case QWebEnginePage::Notifications:
@ -246,6 +263,7 @@ SiteSettingsManager::PageOptions SiteSettingsManager::optionFromWebEngineFeature
return poAllowDesktopAudioVideoCapture;
default:
Q_UNREACHABLE();
qWarning() << "Unknown feature" << feature;
return poAllowNotifications;
}
@ -255,3 +273,13 @@ QString SiteSettingsManager::sqlColumnFromWebEngineFeature(const QWebEnginePage:
{
return optionToSqlColumn(optionFromWebEngineFeature(feature));
}
SiteSettingsManager::Permission SiteSettingsManager::testAttribute(const QWebEngineSettings::WebAttribute attribute) const
{
if (mApp->webSettings()->testAttribute(attribute)) {
return Allow;
}
else {
return Deny;
}
}

View File

@ -20,6 +20,7 @@
#include "qzcommon.h"
#include <QWebEnginePage>
#include <QWebEngineSettings>
class QUrl;
@ -42,6 +43,7 @@ public:
Deny = 2,
Ask = 3,
};
Q_ENUM(Permission);
enum PageOptions {
poAllowJavascript,
@ -57,6 +59,7 @@ public:
poAllowDesktopVideoCapture,
poAllowDesktopAudioVideoCapture,
};
Q_ENUM(PageOptions);
struct SiteSettings
{
@ -102,7 +105,9 @@ public:
private:
QString optionToSqlColumn(const PageOptions &option);
bool getDefaultOptionValue(const PageOptions &option);
PageOptions optionFromWebEngineFeature(const QWebEnginePage::Feature &feature);
Permission getDefaultPermission(const PageOptions &option);
PageOptions optionFromWebEngineFeature(const QWebEnginePage::Feature &feature) const;
Permission testAttribute(const QWebEngineSettings::WebAttribute attribute) const;
};

View File

@ -19,6 +19,7 @@
#include "ui_html5permissionsdialog.h"
#include "settings.h"
#include "mainapplication.h"
#include "html5permissionsitem.h"
#include "html5permissionsmanager.h"
#include "sitesettingsmanager.h"
@ -41,6 +42,14 @@ HTML5PermissionsDialog::HTML5PermissionsDialog(QWidget* parent)
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &HTML5PermissionsDialog::saveSettings);
showFeaturePermissions(currentFeature());
for (int i = 0; i < 8; ++i) {
// Create permission item
auto* listItem = new QListWidgetItem(ui->listWidgetDefaults);
auto* permItem = new HTML5PermissionsItem(indexToFeature(i), SiteSettingsManager::Ask, this);
ui->listWidgetDefaults->setItemWidget(listItem, permItem);
listItem->setSizeHint(permItem->sizeHint());
}
}
HTML5PermissionsDialog::~HTML5PermissionsDialog()

View File

@ -6,14 +6,24 @@
<rect>
<x>0</x>
<y>0</y>
<width>483</width>
<height>332</height>
<width>586</width>
<height>387</height>
</rect>
</property>
<property name="windowTitle">
<string>HTML5 Permissions</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Site permissions</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="1">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
@ -24,7 +34,7 @@
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
<height>183</height>
</size>
</property>
</spacer>
@ -38,16 +48,6 @@
</item>
</layout>
</item>
<item row="2" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QTreeWidget" name="treeWidget">
<property name="indentation">
@ -71,7 +71,7 @@
</column>
</widget>
</item>
<item row="0" column="0" colspan="2">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
@ -131,7 +131,7 @@
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<width>81</width>
<height>20</height>
</size>
</property>
@ -141,6 +141,30 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Defaults</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListWidget" name="listWidgetDefaults"/>
</item>
</layout>
</widget>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>

View File

@ -0,0 +1,129 @@
/* ============================================================
* Falkon - Qt web browser
* Copyright (C) 2022 Juraj Oravec <jurajoravec@mailo.com>
*
* 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 <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "html5permissionsitem.h"
#include "ui_html5permissionsitem.h"
HTML5PermissionsItem::HTML5PermissionsItem(const QWebEnginePage::Feature& feature, const SiteSettingsManager::Permission& permission, QWidget* parent)
: QWidget(parent)
, ui(new Ui::HTML5PermissionsItem())
, m_feature(feature)
, m_permission(permission)
{
ui->setupUi(this);
setLabel();
setCombo();
connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(permissionIndexChanged()));
}
HTML5PermissionsItem::~HTML5PermissionsItem() noexcept
{
delete ui;
}
void HTML5PermissionsItem::permissionIndexChanged()
{
switch (ui->comboBox->currentIndex()) {
case 0:
m_permission = SiteSettingsManager::Allow;
break;
case 1:
m_permission = SiteSettingsManager::Deny;
break;
case 2:
m_permission = SiteSettingsManager::Ask;
break;
default:
Q_UNREACHABLE();
qWarning() << "Unknown permission index" << ui->comboBox->currentIndex();
break;
}
}
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:
Q_UNREACHABLE();
qWarning() << "Unknown feature" << m_feature;
break;
}
}
void HTML5PermissionsItem::setCombo()
{
switch (m_permission) {
case SiteSettingsManager::Allow:
ui->comboBox->setCurrentIndex(0);
break;
case SiteSettingsManager::Deny:
ui->comboBox->setCurrentIndex(1);
break;
case SiteSettingsManager::Ask:
ui->comboBox->setCurrentIndex(2);
break;
default:
Q_UNREACHABLE();
qWarning() << "Unknown permission" << m_permission;
break;
}
}
QWebEnginePage::Feature HTML5PermissionsItem::getFeature() const
{
return m_feature;
}
SiteSettingsManager::Permission HTML5PermissionsItem::getPermission() const
{
return m_permission;
}

View File

@ -0,0 +1,54 @@
/* ============================================================
* Falkon - Qt web browser
* Copyright (C) 2022 Juraj Oravec <jurajoravec@mailo.com>
*
* 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 <http://www.gnu.org/licenses/>.
* ============================================================ */
#ifndef HTML5PERMISSIONSITEM_H
#define HTML5PERMISSIONSITEM_H
#include "qzcommon.h"
#include "sitesettingsmanager.h"
#include <QWebEnginePage>
#include <QWebEngineSettings>
namespace Ui
{
class HTML5PermissionsItem;
}
class FALKON_EXPORT HTML5PermissionsItem : public QWidget
{
Q_OBJECT
public:
explicit HTML5PermissionsItem(const QWebEnginePage::Feature &feature, const SiteSettingsManager::Permission &permission, QWidget* parent = nullptr);
~HTML5PermissionsItem();
QWebEnginePage::Feature getFeature() const;
SiteSettingsManager::Permission getPermission() const;
private Q_SLOTS:
void permissionIndexChanged();
private:
void setLabel();
void setCombo();
Ui::HTML5PermissionsItem* ui;
QWebEnginePage::Feature m_feature;
SiteSettingsManager::Permission m_permission;
};
#endif // HTML5PERMISSIONSITEM_H

View File

@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>HTML5PermissionsItem</class>
<widget class="QWidget" name="HTML5PermissionsItem">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>319</width>
<height>38</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QComboBox" name="comboBox">
<item>
<property name="text">
<string>Allow</string>
</property>
</item>
<item>
<property name="text">
<string>Deny</string>
</property>
</item>
<item>
<property name="text">
<string>Ask</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>