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

Rewrite permissions in SiteInfo window

Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
Juraj Oravec 2022-09-24 02:03:19 +02:00
parent 5032c504fb
commit 653e7aa429
Signed by: SGOrava
GPG Key ID: 13660A3F1D9F093B
6 changed files with 124 additions and 113 deletions

View File

@ -28,7 +28,6 @@
#include "scripts.h" #include "scripts.h"
#include "networkmanager.h" #include "networkmanager.h"
#include "locationbar.h" #include "locationbar.h"
#include "siteinfopermissionitem.h"
#include <QMenu> #include <QMenu>
#include <QMessageBox> #include <QMessageBox>
@ -124,15 +123,8 @@ SiteInfo::SiteInfo(WebView *view)
} }
}); });
// Permissions /* Permissions */
for (auto &attribute : mApp->siteSettingsManager()->getSupportedAttribute()) { addSiteSettings();
addPermissionOption(attribute);
}
for (auto &feature : mApp->siteSettingsManager()->getSupportedFeatures()) {
addPermissionOption(feature);
}
connect(ui->saveButton, SIGNAL(clicked(QAbstractButton*)), this, SLOT(saveImage())); connect(ui->saveButton, SIGNAL(clicked(QAbstractButton*)), this, SLOT(saveImage()));
connect(ui->listWidget, SIGNAL(currentRowChanged(int)), ui->stackedWidget, SLOT(setCurrentIndex(int))); connect(ui->listWidget, SIGNAL(currentRowChanged(int)), ui->stackedWidget, SLOT(setCurrentIndex(int)));
@ -337,34 +329,30 @@ SiteInfo::~SiteInfo()
delete m_certWidget; delete m_certWidget;
} }
void SiteInfo::addPermissionOption(const SiteSettingsManager::PageOptions option) SiteInfoPermissionItem* SiteInfo::addPermissionOption(SiteSettingsManager::Permission perm)
{ {
auto perm = mApp->siteSettingsManager()->getPermission(option, m_baseUrl);
auto* listItem = new QListWidgetItem(ui->listPermissions); auto* listItem = new QListWidgetItem(ui->listPermissions);
auto* optionItem = new SiteInfoPermissionItem(option, perm, this); auto* optionItem = new SiteInfoPermissionItem(perm, this);
ui->listPermissions->setItemWidget(listItem, optionItem); ui->listPermissions->setItemWidget(listItem, optionItem);
listItem->setSizeHint(optionItem->sizeHint()); listItem->setSizeHint(optionItem->sizeHint());
return optionItem;
} }
void SiteInfo::addPermissionOption(const QWebEnginePage::Feature feature) void SiteInfo::addSiteSettings()
{ {
auto perm = mApp->siteSettingsManager()->getPermission(feature, m_baseUrl); auto siteSettings = mApp->siteSettingsManager()->getSiteSettings(m_baseUrl);
auto* listItem = new QListWidgetItem(ui->listPermissions); // Attributes
auto* optionItem = new SiteInfoPermissionItem(feature, perm, this); for (const auto &attribute : mApp->siteSettingsManager()->getSupportedAttribute()) {
SiteInfoPermissionItem *item = addPermissionOption(siteSettings.attributes[attribute]);
ui->listPermissions->setItemWidget(listItem, optionItem); item->setAttribute(attribute);
listItem->setSizeHint(optionItem->sizeHint()); }
} // Permissions
for (const auto &feature : mApp->siteSettingsManager()->getSupportedFeatures()) {
void SiteInfo::addPermissionOption(const QWebEngineSettings::WebAttribute attribute) SiteInfoPermissionItem *item = addPermissionOption(siteSettings.features[feature]);
{ item->setFeature(feature);
auto perm = mApp->siteSettingsManager()->getPermission(attribute, m_baseUrl); }
auto* listItem = new QListWidgetItem(ui->listPermissions);
auto* optionItem = new SiteInfoPermissionItem(attribute, perm, this);
ui->listPermissions->setItemWidget(listItem, optionItem);
listItem->setSizeHint(optionItem->sizeHint());
} }
void SiteInfo::saveSiteSettings() void SiteInfo::saveSiteSettings()

View File

@ -20,6 +20,7 @@
#include "qzcommon.h" #include "qzcommon.h"
#include "sitesettingsmanager.h" #include "sitesettingsmanager.h"
#include "siteinfopermissionitem.h"
#include <QUrl> #include <QUrl>
#include <QDialog> #include <QDialog>
@ -58,9 +59,8 @@ private:
void showLoadingText(); void showLoadingText();
void showPixmap(QPixmap pixmap); void showPixmap(QPixmap pixmap);
void addPermissionOption(const SiteSettingsManager::PageOptions option); void addSiteSettings();
void addPermissionOption(const QWebEnginePage::Feature feature); SiteInfoPermissionItem* addPermissionOption(SiteSettingsManager::Permission perm);
void addPermissionOption(const QWebEngineSettings::WebAttribute attribute);
Ui::SiteInfo* ui; Ui::SiteInfo* ui;
CertificateInfoWidget* m_certWidget; CertificateInfoWidget* m_certWidget;

View File

@ -22,42 +22,14 @@
#include "sitesettingsmanager.h" #include "sitesettingsmanager.h"
SiteInfoPermissionItem::SiteInfoPermissionItem(const SiteSettingsManager::PageOptions &a_option, const SiteSettingsManager::Permission &a_permission, QWidget* parent) SiteInfoPermissionItem::SiteInfoPermissionItem(const SiteSettingsManager::Permission& a_permission, QWidget* parent)
: QWidget(parent) : QWidget(parent)
, m_option(a_option)
, m_type(Browser)
, m_ui(new Ui::SiteInfoPermissionItem()) , m_ui(new Ui::SiteInfoPermissionItem())
, m_hasOptionAsk(true)
, m_hasOptionDefault(true)
{ {
m_ui->setupUi(this); m_ui->setupUi(this);
setPermission(a_permission); setPermission(a_permission);
setHasOptionAsk(false);
m_ui->label->setText(mApp->siteSettingsManager()->getOptionName(a_option));
}
SiteInfoPermissionItem::SiteInfoPermissionItem(const QWebEnginePage::Feature& a_feature, const SiteSettingsManager::Permission& a_permission, QWidget* parent)
: QWidget(parent)
, m_feature(a_feature)
, m_type(Feature)
, m_ui(new Ui::SiteInfoPermissionItem())
{
m_ui->setupUi(this);
setPermission(a_permission);
m_ui->label->setText(mApp->siteSettingsManager()->getOptionName(a_feature));
}
SiteInfoPermissionItem::SiteInfoPermissionItem(const QWebEngineSettings::WebAttribute& a_attribute, const SiteSettingsManager::Permission& a_permission, QWidget* parent)
: QWidget(parent)
, m_attribute(a_attribute)
, m_type(Attribute)
, m_ui(new Ui::SiteInfoPermissionItem())
{
m_ui->setupUi(this);
setPermission(a_permission);
setHasOptionAsk(false);
m_ui->label->setText(mApp->siteSettingsManager()->getOptionName(a_attribute));
} }
SiteInfoPermissionItem::~SiteInfoPermissionItem() SiteInfoPermissionItem::~SiteInfoPermissionItem()
@ -94,7 +66,7 @@ void SiteInfoPermissionItem::setHasOptionDefault(bool hasOptionDefault)
m_ui->radioDefault->setVisible(hasOptionDefault); m_ui->radioDefault->setVisible(hasOptionDefault);
} }
void SiteInfoPermissionItem::setPermission(SiteSettingsManager::Permission permission) void SiteInfoPermissionItem::setPermission(const SiteSettingsManager::Permission permission)
{ {
m_ui->radioAllow->setChecked(false); m_ui->radioAllow->setChecked(false);
m_ui->radioAsk->setChecked(false); m_ui->radioAsk->setChecked(false);
@ -118,26 +90,6 @@ void SiteInfoPermissionItem::setPermission(SiteSettingsManager::Permission permi
qWarning() << "Unknown permission" << permission; qWarning() << "Unknown permission" << permission;
m_ui->radioDefault->setChecked(true); m_ui->radioDefault->setChecked(true);
} }
SiteSettingsManager::Permission defaultPermission;
switch (m_type) {
case Browser:
defaultPermission = mApp->siteSettingsManager()->getDefaultPermission(m_option);
break;
case Attribute:
defaultPermission = mApp->siteSettingsManager()->getDefaultPermission(m_attribute);
break;
case Feature:
defaultPermission = mApp->siteSettingsManager()->getDefaultPermission(m_feature);
break;
default:
defaultPermission = SiteSettingsManager::Default;
break;
}
if (defaultPermission == SiteSettingsManager::Default) {
defaultPermission = SiteSettingsManager::Ask;
}
m_ui->labelDefaultPermission->setText(mApp->siteSettingsManager()->getPermissionName(defaultPermission));
} }
SiteSettingsManager::Permission SiteInfoPermissionItem::permission() const SiteSettingsManager::Permission SiteInfoPermissionItem::permission() const
@ -162,14 +114,36 @@ SiteSettingsManager::Permission SiteInfoPermissionItem::permission() const
QString SiteInfoPermissionItem::sqlColumn() QString SiteInfoPermissionItem::sqlColumn()
{ {
switch (m_type) { return m_sqlColumn;
case Browser: }
return mApp->siteSettingsManager()->optionToSqlColumn(m_option);
case Attribute: void SiteInfoPermissionItem::setDefaultPermission(SiteSettingsManager::Permission permission)
return mApp->siteSettingsManager()->webAttributeToSqlColumn(m_attribute); {
case Feature: if (permission == SiteSettingsManager::Default) {
return mApp->siteSettingsManager()->featureToSqlColumn(m_feature); permission = SiteSettingsManager::Ask;
default: }
return QL1S(); m_ui->labelDefaultPermission->setText(mApp->siteSettingsManager()->getPermissionName(permission));
} }
void SiteInfoPermissionItem::setAttribute(const QWebEngineSettings::WebAttribute &attribute)
{
m_sqlColumn = mApp->siteSettingsManager()->webAttributeToSqlColumn(attribute);
m_ui->label->setText(mApp->siteSettingsManager()->getOptionName(attribute));
setDefaultPermission(mApp->siteSettingsManager()->getDefaultPermission(attribute));
setHasOptionAsk(false);
}
void SiteInfoPermissionItem::setFeature(const QWebEnginePage::Feature& feature)
{
m_sqlColumn = mApp->siteSettingsManager()->featureToSqlColumn(feature);
m_ui->label->setText(mApp->siteSettingsManager()->getOptionName(feature));
setDefaultPermission(mApp->siteSettingsManager()->getDefaultPermission(feature));
}
void SiteInfoPermissionItem::setOption(const SiteSettingsManager::PageOptions& option)
{
m_sqlColumn = mApp->siteSettingsManager()->optionToSqlColumn(option);
m_ui->label->setText(mApp->siteSettingsManager()->getOptionName(option));
setDefaultPermission(mApp->siteSettingsManager()->getDefaultPermission(option));
setHasOptionAsk(false);
} }

View File

@ -36,16 +36,7 @@ class SiteInfoPermissionItem : public QWidget
Q_OBJECT Q_OBJECT
public: public:
enum Type { explicit SiteInfoPermissionItem(const SiteSettingsManager::Permission &a_permission, QWidget* parent = nullptr);
Browser = 0,
Feature = 1,
Attribute = 2,
};
Q_ENUM(Type);
explicit SiteInfoPermissionItem(const SiteSettingsManager::PageOptions &a_option, const SiteSettingsManager::Permission &a_permission, QWidget* parent = nullptr);
explicit SiteInfoPermissionItem(const QWebEngineSettings::WebAttribute &a_attribute, const SiteSettingsManager::Permission &a_permission, QWidget* parent = nullptr);
explicit SiteInfoPermissionItem(const QWebEnginePage::Feature &a_feature, const SiteSettingsManager::Permission &a_permission, QWidget* parent = nullptr);
~SiteInfoPermissionItem(); ~SiteInfoPermissionItem();
bool hasOptionAsk() const; bool hasOptionAsk() const;
@ -54,17 +45,20 @@ public:
SiteSettingsManager::Permission permission() const; SiteSettingsManager::Permission permission() const;
QString sqlColumn(); QString sqlColumn();
void setAttribute(const QWebEngineSettings::WebAttribute& attribute);
void setFeature(const QWebEnginePage::Feature &feature);
void setOption(const SiteSettingsManager::PageOptions &option);
void setHasOptionAsk(bool hasAsk); void setHasOptionAsk(bool hasAsk);
void setHasOptionDefault(bool hasDefault); void setHasOptionDefault(bool hasDefault);
void setPermission(SiteSettingsManager::Permission permission);
private: private:
void setPermission(const SiteSettingsManager::Permission permission);
void setDefaultPermission(SiteSettingsManager::Permission permission);
bool m_hasOptionAsk; bool m_hasOptionAsk;
bool m_hasOptionDefault; bool m_hasOptionDefault;
SiteSettingsManager::PageOptions m_option; QString m_sqlColumn;
QWebEngineSettings::WebAttribute m_attribute;
QWebEnginePage::Feature m_feature;
Type m_type;
private: private:
QScopedPointer<Ui::SiteInfoPermissionItem> m_ui; QScopedPointer<Ui::SiteInfoPermissionItem> m_ui;

View File

@ -62,6 +62,29 @@ SiteSettingsManager::SiteSettingsManager ( QObject* parent )
supportedFeatures.append(QWebEnginePage::MouseLock); supportedFeatures.append(QWebEnginePage::MouseLock);
supportedFeatures.append(QWebEnginePage::DesktopVideoCapture); supportedFeatures.append(QWebEnginePage::DesktopVideoCapture);
supportedFeatures.append(QWebEnginePage::DesktopAudioVideoCapture); supportedFeatures.append(QWebEnginePage::DesktopAudioVideoCapture);
everythingSql = QSL("SELECT ");
for (int i = 0; i < supportedAttribute.size(); ++i) {
if (i > 0) {
everythingSql.append(QSL(", "));
}
everythingSql.append(webAttributeToSqlColumn(supportedAttribute[i]));
}
for (int i = 0; i < supportedFeatures.size(); ++i) {
everythingSql.append(QSL(", "));
everythingSql.append(featureToSqlColumn(supportedFeatures[i]));
}
everythingSql.append(QSL(", "));
everythingSql.append(optionToSqlColumn(poAllowCookies));
everythingSql.append(QSL(", "));
everythingSql.append(optionToSqlColumn(poZoomLevel));
everythingSql.append(QSL(" FROM site_settings WHERE server=?"));
} }
SiteSettingsManager::~SiteSettingsManager() noexcept SiteSettingsManager::~SiteSettingsManager() noexcept
@ -99,7 +122,7 @@ void SiteSettingsManager::loadSettings()
settings.beginGroup("Site-Settings-Default-Features"); settings.beginGroup("Site-Settings-Default-Features");
for (auto &feature : qAsConst(supportedFeatures)) { for (const auto &feature : qAsConst(supportedFeatures)) {
defaultFeatures[feature] = intToPermission(settings.value(featureToSqlColumn(feature), Ask).toInt()); defaultFeatures[feature] = intToPermission(settings.value(featureToSqlColumn(feature), Ask).toInt());
} }
settings.endGroup(); settings.endGroup();
@ -502,3 +525,31 @@ QList<QWebEnginePage::Feature> SiteSettingsManager::getSupportedFeatures() const
{ {
return supportedFeatures; return supportedFeatures;
} }
SiteSettingsManager::SiteSettings SiteSettingsManager::getSiteSettings(QUrl& url)
{
SiteSettings siteSettings;
int i;
QSqlQuery query(SqlDatabase::instance()->database());
query.prepare(everythingSql);
query.addBindValue(url.host());
query.exec();
if (query.next()) {
Permission perm;
for (i = 0; i < supportedAttribute.size(); ++i) {
perm = intToPermission(query.value(i).toInt());
siteSettings.attributes[supportedAttribute[i]] = perm;
}
for (i = 0; i < supportedFeatures.size(); ++i) {
perm = intToPermission(query.value(i + supportedAttribute.size()).toInt());
siteSettings.features[supportedFeatures[i]] = perm;
}
perm = intToPermission(query.value(supportedAttribute.size() + supportedFeatures.size()).toInt());
siteSettings.AllowCookies = perm;
siteSettings.ZoomLevel = query.value(supportedAttribute.size() + supportedFeatures.size() + 1).toInt();
}
return siteSettings;
}

View File

@ -49,8 +49,8 @@ public:
{ {
Permission AllowCookies; Permission AllowCookies;
int ZoomLevel; int ZoomLevel;
QHash<QWebEngineSettings::WebAttribute, Permission> attributes; /* Enable disable soem feature eg. Javascript, Images etc */ QMap<QWebEngineSettings::WebAttribute, Permission> attributes; /* Enable disable soem feature eg. Javascript, Images etc */
QHash<QWebEnginePage::Feature, Permission> features; /* HTML permissions */ QMap<QWebEnginePage::Feature, Permission> features; /* HTML permissions */
QString server; QString server;
}; };
@ -95,6 +95,8 @@ public:
QList<QWebEngineSettings::WebAttribute> getSupportedAttribute() const; QList<QWebEngineSettings::WebAttribute> getSupportedAttribute() const;
QList<QWebEnginePage::Feature> getSupportedFeatures() const; QList<QWebEnginePage::Feature> getSupportedFeatures() const;
SiteSettings getSiteSettings(QUrl &url);
private: private:
Permission testAttribute(const QWebEngineSettings::WebAttribute attribute) const; Permission testAttribute(const QWebEngineSettings::WebAttribute attribute) const;
@ -104,7 +106,9 @@ private:
QList<QWebEngineSettings::WebAttribute> supportedAttribute; QList<QWebEngineSettings::WebAttribute> supportedAttribute;
QList<QWebEnginePage::Feature> supportedFeatures; QList<QWebEnginePage::Feature> supportedFeatures;
QMap<QWebEnginePage::Feature, Permission> defaultFeatures; QMap<QWebEnginePage::Feature, Permission> defaultFeatures;
QString attributesSql; QString attributesSql;
QString everythingSql;
}; };