1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

SiteSettings: Add permission browse dialog

Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
Juraj Oravec 2024-04-24 00:28:11 +02:00
parent 9e1dd38b94
commit f8493f3517
Signed by: SGOrava
GPG Key ID: 13660A3F1D9F093B
11 changed files with 311 additions and 5 deletions

View File

@ -211,6 +211,7 @@ set(SRCS ${SRCS}
preferences/preferences.cpp
preferences/schememanager.cpp
preferences/sitesettingsattributesitem.cpp
preferences/sitesettingsbrowsedialog.cpp
preferences/sitesettingshtml5item.cpp
preferences/thememanager.cpp
preferences/useragentdialog.cpp
@ -444,6 +445,7 @@ set(SRCS ${SRCS}
preferences/preferences.h
preferences/schememanager.h
preferences/sitesettingsattributesitem.h
preferences/sitesettingsbrowsedialog.h
preferences/sitesettingshtml5item.h
preferences/thememanager.h
preferences/useragentdialog.h
@ -560,6 +562,7 @@ qt_wrap_ui(SRCS
preferences/preferences.ui
preferences/schememanager.ui
preferences/sitesettingsattributesitem.ui
preferences/sitesettingsbrowsedialog.ui
preferences/sitesettingshtml5item.ui
preferences/thememanager.ui
preferences/useragentdialog.ui

View File

@ -119,11 +119,11 @@ public:
SiteSettings getSiteSettings(QUrl &url);
void setSiteSettings(SiteSettings &siteSettings);
QString sqlTable();
Permission intToPermission(const int permission) const;
private:
void prepareSqls();
Permission intToPermission(const int permission) const;
QMap<QWebEnginePage::Feature, Permission> defaultFeatures;

View File

@ -1095,8 +1095,9 @@ void Preferences::saveSettings()
settings.setValue(QSL("Password"), ui->proxyPassword->text());
settings.endGroup();
//SiteSettings TODO
//SiteSettings
settings.beginGroup(QSL("Site-Settings"));
/* HTML5 Features */
for (int i = 0; i < ui->siteSettingsHtml5List->count(); ++i) {
auto *item = static_cast<SiteSettingsHtml5Item*>(ui->siteSettingsHtml5List->itemWidget(ui->siteSettingsHtml5List->item(i)));
settings.setValue(mApp->siteSettingsManager()->featureToSqlColumn(item->feature()), item->permission());

View File

@ -159,8 +159,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>793</width>
<height>626</height>
<width>783</width>
<height>651</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
@ -1024,7 +1024,7 @@
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>2</number>
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">

View File

@ -9,6 +9,7 @@
#include "mainapplication.h"
#include "sitesettingsmanager.h"
#include "sitesettingsbrowsedialog.h"
SiteSettingsAttributesItem::SiteSettingsAttributesItem(const QWebEngineSettings::WebAttribute a_attribute, QWidget* parent)
: QWidget(parent)
@ -17,12 +18,24 @@ SiteSettingsAttributesItem::SiteSettingsAttributesItem(const QWebEngineSettings:
{
m_ui->setupUi(this);
m_ui->label->setText(mApp->siteSettingsManager()->getOptionName(m_attribute));
connect(m_ui->browseButton, &QPushButton::clicked, this, &SiteSettingsAttributesItem::showBrowseDialog);
}
SiteSettingsAttributesItem::~SiteSettingsAttributesItem()
{
}
void SiteSettingsAttributesItem::showBrowseDialog()
{
QString sqlColumn = mApp->siteSettingsManager()->webAttributeToSqlColumn(m_attribute);
QString name = m_ui->label->text();
auto* dialog = new SiteSettingsBrowseDialog(name, sqlColumn, this);
dialog->hideAskButton();
dialog->open();
}
QWebEngineSettings::WebAttribute SiteSettingsAttributesItem::attribute() const
{
return m_attribute;

View File

@ -27,6 +27,9 @@ public:
QWebEngineSettings::WebAttribute attribute() const;
public Q_SLOTS:
void showBrowseDialog();
private:
QWebEngineSettings::WebAttribute m_attribute;

View File

@ -0,0 +1,92 @@
// Falkon - SiteSettings permission browser dialog
// SPDX-FileCopyrightText: 2024 Juraj Oravec <jurajoravec@mailo.com>
// SPDX-License-Identifier: GPL-3.0-or-later
#include "sitesettingsbrowsedialog.h"
#include "ui_sitesettingsbrowsedialog.h"
#include "mainapplication.h"
#include "sqldatabase.h"
const int rolePermission = Qt::UserRole + 10;
SiteSettingsBrowseDialog::SiteSettingsBrowseDialog(QString &name, QString &sqlColumn, QWidget* parent)
: QDialog(parent)
, m_ui(new Ui::SiteSettingsBrowseDialog)
, m_sqlColumn(sqlColumn)
{
m_ui->setupUi(this);
m_ui->nameLabel->setText(name);
loadItems();
m_ui->treeWidget->header()->resizeSections(QHeaderView::ResizeToContents);
connect(m_ui->askButton, &QPushButton::clicked, this, [=]() { setPermission(SiteSettingsManager::Ask); });
connect(m_ui->allowButton, &QPushButton::clicked, this, [=]() { setPermission(SiteSettingsManager::Allow); });
connect(m_ui->denyButton, &QPushButton::clicked, this, [=]() { setPermission(SiteSettingsManager::Deny); });
connect(m_ui->defaultButton, &QPushButton::clicked, this, [=]() { setPermission(SiteSettingsManager::Default); });
connect(m_ui->buttonBox, &QDialogButtonBox::accepted, this, &SiteSettingsBrowseDialog::storeChanges);
}
void SiteSettingsBrowseDialog::loadItems()
{
QSqlDatabase db = SqlDatabase::instance()->database();
QString sqlTable = mApp->siteSettingsManager()->sqlTable();
QSqlQuery query(SqlDatabase::instance()->database());
query.prepare(QSL("SELECT server, %2 FROM %1 WHERE %2!=?").arg(sqlTable, m_sqlColumn));
query.addBindValue(SiteSettingsManager::Default);
query.exec();
while (query.next()) {
QString server = query.value(0).toString();
auto permission = mApp->siteSettingsManager()->intToPermission(query.value(1).toInt());
QString permissionName = mApp->siteSettingsManager()->getPermissionName(permission);
auto* item = new QTreeWidgetItem(m_ui->treeWidget);
item->setText(0, server);
item->setText(1, permissionName);
item->setData(0, rolePermission, permission);
m_ui->treeWidget->addTopLevelItem(item);
}
}
void SiteSettingsBrowseDialog::storeChanges()
{
QUrl url;
for (QHash<QString, int>::iterator it = m_listModifications.begin(); it != m_listModifications.end(); ++it) {
url.setHost(it.key());
mApp->siteSettingsManager()->setOption(m_sqlColumn, url, it.value());
}
}
void SiteSettingsBrowseDialog::setPermission(const SiteSettingsManager::Permission permission)
{
QTreeWidgetItem* item = m_ui->treeWidget->currentItem();
if (!item) {
return;
}
const QString server = item->text(0);
auto itemPermission = static_cast<SiteSettingsManager::Permission>(item->data(0, Qt::UserRole + 10).toInt());
if (permission == itemPermission) {
m_listModifications.remove(server);
}
QString permissionName = mApp->siteSettingsManager()->getPermissionName(permission);
m_listModifications[server] = permission;
item->setText(1, permissionName);
}
void SiteSettingsBrowseDialog::hideAskButton()
{
m_ui->askButton->hide();
}
SiteSettingsBrowseDialog::~SiteSettingsBrowseDialog()
{
}

View File

@ -0,0 +1,40 @@
// Falkon - SiteSettings permission browser dialog
// SPDX-FileCopyrightText: 2024 Juraj Oravec <jurajoravec@mailo.com>
// SPDX-License-Identifier: GPL-3.0-or-later
#ifndef SITESETTINGSBROWSEDIALOG_H
#define SITESETTINGSBROWSEDIALOG_H
#include "sitesettingsmanager.h"
#include <QDialog>
#include <QScopedPointer>
namespace Ui
{
class SiteSettingsBrowseDialog;
}
class SiteSettingsBrowseDialog : public QDialog
{
Q_OBJECT
public:
SiteSettingsBrowseDialog(QString &name, QString &sqlColumn, QWidget* parent = nullptr);
~SiteSettingsBrowseDialog();
void setPermission(const SiteSettingsManager::Permission permission);
void hideAskButton();
public Q_SLOTS:
void storeChanges();
private:
void loadItems();
QScopedPointer<Ui::SiteSettingsBrowseDialog> m_ui;
QHash<QString, int> m_listModifications;
QString m_sqlColumn;
};
#endif // SITESETTINGSBROWSEDIALOG_H

View File

@ -0,0 +1,139 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SiteSettingsBrowseDialog</class>
<widget class="QDialog" name="SiteSettingsBrowseDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>483</width>
<height>332</height>
</rect>
</property>
<property name="windowTitle">
<string>Site Permissions</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QTreeWidget" name="treeWidget">
<property name="indentation">
<number>0</number>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
<property name="allColumnsShowFocus">
<bool>true</bool>
</property>
<column>
<property name="text">
<string>Site</string>
</property>
</column>
<column>
<property name="text">
<string>Behaviour</string>
</property>
</column>
</widget>
</item>
<item row="1" column="1">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QPushButton" name="askButton">
<property name="text">
<string>Ask</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="allowButton">
<property name="text">
<string>Allow</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="denyButton">
<property name="text">
<string>Deny</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="defaultButton">
<property name="text">
<string>Default</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</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="0" column="0">
<widget class="QLabel" name="nameLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>SiteSettingsBrowseDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>SiteSettingsBrowseDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -8,6 +8,7 @@
#include "mainapplication.h"
#include "sitesettingsmanager.h"
#include "sitesettingsbrowsedialog.h"
SiteSettingsHtml5Item::SiteSettingsHtml5Item(const QWebEnginePage::Feature a_feature, QWidget* parent)
: QWidget(parent)
@ -31,12 +32,23 @@ SiteSettingsHtml5Item::SiteSettingsHtml5Item(const QWebEnginePage::Feature a_fea
setPermission();
m_ui->label->setText(mApp->siteSettingsManager()->getOptionName(m_feature));
connect(m_ui->browseButton, &QPushButton::clicked, this, &SiteSettingsHtml5Item::showBrowseDialog);
}
SiteSettingsHtml5Item::~SiteSettingsHtml5Item()
{
}
void SiteSettingsHtml5Item::showBrowseDialog()
{
QString sqlColumn = mApp->siteSettingsManager()->featureToSqlColumn(m_feature);
QString name = m_ui->label->text();
auto* dialog = new SiteSettingsBrowseDialog(name, sqlColumn, this);
dialog->open();
}
QWebEnginePage::Feature SiteSettingsHtml5Item::feature() const
{
return m_feature;

View File

@ -30,6 +30,9 @@ public:
QWebEnginePage::Feature feature() const;
SiteSettingsManager::Permission permission() const;
public Q_SLOTS:
void showBrowseDialog();
private:
QWebEnginePage::Feature m_feature;