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:
parent
5032c504fb
commit
653e7aa429
@ -28,7 +28,6 @@
|
||||
#include "scripts.h"
|
||||
#include "networkmanager.h"
|
||||
#include "locationbar.h"
|
||||
#include "siteinfopermissionitem.h"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
@ -124,15 +123,8 @@ SiteInfo::SiteInfo(WebView *view)
|
||||
}
|
||||
});
|
||||
|
||||
// Permissions
|
||||
for (auto &attribute : mApp->siteSettingsManager()->getSupportedAttribute()) {
|
||||
addPermissionOption(attribute);
|
||||
}
|
||||
for (auto &feature : mApp->siteSettingsManager()->getSupportedFeatures()) {
|
||||
addPermissionOption(feature);
|
||||
}
|
||||
|
||||
|
||||
/* Permissions */
|
||||
addSiteSettings();
|
||||
|
||||
connect(ui->saveButton, SIGNAL(clicked(QAbstractButton*)), this, SLOT(saveImage()));
|
||||
connect(ui->listWidget, SIGNAL(currentRowChanged(int)), ui->stackedWidget, SLOT(setCurrentIndex(int)));
|
||||
@ -337,34 +329,30 @@ SiteInfo::~SiteInfo()
|
||||
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* optionItem = new SiteInfoPermissionItem(option, perm, this);
|
||||
auto* optionItem = new SiteInfoPermissionItem(perm, this);
|
||||
|
||||
ui->listPermissions->setItemWidget(listItem, optionItem);
|
||||
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* listItem = new QListWidgetItem(ui->listPermissions);
|
||||
auto* optionItem = new SiteInfoPermissionItem(feature, perm, this);
|
||||
|
||||
ui->listPermissions->setItemWidget(listItem, optionItem);
|
||||
listItem->setSizeHint(optionItem->sizeHint());
|
||||
}
|
||||
|
||||
void SiteInfo::addPermissionOption(const QWebEngineSettings::WebAttribute attribute)
|
||||
{
|
||||
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());
|
||||
auto siteSettings = mApp->siteSettingsManager()->getSiteSettings(m_baseUrl);
|
||||
// Attributes
|
||||
for (const auto &attribute : mApp->siteSettingsManager()->getSupportedAttribute()) {
|
||||
SiteInfoPermissionItem *item = addPermissionOption(siteSettings.attributes[attribute]);
|
||||
item->setAttribute(attribute);
|
||||
}
|
||||
// Permissions
|
||||
for (const auto &feature : mApp->siteSettingsManager()->getSupportedFeatures()) {
|
||||
SiteInfoPermissionItem *item = addPermissionOption(siteSettings.features[feature]);
|
||||
item->setFeature(feature);
|
||||
}
|
||||
}
|
||||
|
||||
void SiteInfo::saveSiteSettings()
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include "qzcommon.h"
|
||||
#include "sitesettingsmanager.h"
|
||||
#include "siteinfopermissionitem.h"
|
||||
|
||||
#include <QUrl>
|
||||
#include <QDialog>
|
||||
@ -58,9 +59,8 @@ private:
|
||||
void showLoadingText();
|
||||
void showPixmap(QPixmap pixmap);
|
||||
|
||||
void addPermissionOption(const SiteSettingsManager::PageOptions option);
|
||||
void addPermissionOption(const QWebEnginePage::Feature feature);
|
||||
void addPermissionOption(const QWebEngineSettings::WebAttribute attribute);
|
||||
void addSiteSettings();
|
||||
SiteInfoPermissionItem* addPermissionOption(SiteSettingsManager::Permission perm);
|
||||
|
||||
Ui::SiteInfo* ui;
|
||||
CertificateInfoWidget* m_certWidget;
|
||||
|
@ -22,42 +22,14 @@
|
||||
#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)
|
||||
, m_option(a_option)
|
||||
, m_type(Browser)
|
||||
, m_ui(new Ui::SiteInfoPermissionItem())
|
||||
, m_hasOptionAsk(true)
|
||||
, m_hasOptionDefault(true)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
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()
|
||||
@ -94,7 +66,7 @@ void SiteInfoPermissionItem::setHasOptionDefault(bool 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->radioAsk->setChecked(false);
|
||||
@ -118,26 +90,6 @@ void SiteInfoPermissionItem::setPermission(SiteSettingsManager::Permission permi
|
||||
qWarning() << "Unknown permission" << permission;
|
||||
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
|
||||
@ -162,14 +114,36 @@ SiteSettingsManager::Permission SiteInfoPermissionItem::permission() const
|
||||
|
||||
QString SiteInfoPermissionItem::sqlColumn()
|
||||
{
|
||||
switch (m_type) {
|
||||
case Browser:
|
||||
return mApp->siteSettingsManager()->optionToSqlColumn(m_option);
|
||||
case Attribute:
|
||||
return mApp->siteSettingsManager()->webAttributeToSqlColumn(m_attribute);
|
||||
case Feature:
|
||||
return mApp->siteSettingsManager()->featureToSqlColumn(m_feature);
|
||||
default:
|
||||
return QL1S();
|
||||
}
|
||||
return m_sqlColumn;
|
||||
}
|
||||
|
||||
void SiteInfoPermissionItem::setDefaultPermission(SiteSettingsManager::Permission permission)
|
||||
{
|
||||
if (permission == SiteSettingsManager::Default) {
|
||||
permission = SiteSettingsManager::Ask;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
@ -36,16 +36,7 @@ class SiteInfoPermissionItem : public QWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum Type {
|
||||
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);
|
||||
explicit SiteInfoPermissionItem(const SiteSettingsManager::Permission &a_permission, QWidget* parent = nullptr);
|
||||
~SiteInfoPermissionItem();
|
||||
|
||||
bool hasOptionAsk() const;
|
||||
@ -54,17 +45,20 @@ public:
|
||||
SiteSettingsManager::Permission permission() const;
|
||||
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 setHasOptionDefault(bool hasDefault);
|
||||
void setPermission(SiteSettingsManager::Permission permission);
|
||||
|
||||
private:
|
||||
void setPermission(const SiteSettingsManager::Permission permission);
|
||||
void setDefaultPermission(SiteSettingsManager::Permission permission);
|
||||
|
||||
bool m_hasOptionAsk;
|
||||
bool m_hasOptionDefault;
|
||||
SiteSettingsManager::PageOptions m_option;
|
||||
QWebEngineSettings::WebAttribute m_attribute;
|
||||
QWebEnginePage::Feature m_feature;
|
||||
Type m_type;
|
||||
QString m_sqlColumn;
|
||||
|
||||
private:
|
||||
QScopedPointer<Ui::SiteInfoPermissionItem> m_ui;
|
||||
|
@ -62,6 +62,29 @@ SiteSettingsManager::SiteSettingsManager ( QObject* parent )
|
||||
supportedFeatures.append(QWebEnginePage::MouseLock);
|
||||
supportedFeatures.append(QWebEnginePage::DesktopVideoCapture);
|
||||
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
|
||||
@ -99,7 +122,7 @@ void SiteSettingsManager::loadSettings()
|
||||
|
||||
|
||||
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());
|
||||
}
|
||||
settings.endGroup();
|
||||
@ -502,3 +525,31 @@ QList<QWebEnginePage::Feature> SiteSettingsManager::getSupportedFeatures() const
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
@ -49,8 +49,8 @@ public:
|
||||
{
|
||||
Permission AllowCookies;
|
||||
int ZoomLevel;
|
||||
QHash<QWebEngineSettings::WebAttribute, Permission> attributes; /* Enable disable soem feature eg. Javascript, Images etc */
|
||||
QHash<QWebEnginePage::Feature, Permission> features; /* HTML permissions */
|
||||
QMap<QWebEngineSettings::WebAttribute, Permission> attributes; /* Enable disable soem feature eg. Javascript, Images etc */
|
||||
QMap<QWebEnginePage::Feature, Permission> features; /* HTML permissions */
|
||||
QString server;
|
||||
};
|
||||
|
||||
@ -95,6 +95,8 @@ public:
|
||||
QList<QWebEngineSettings::WebAttribute> getSupportedAttribute() const;
|
||||
QList<QWebEnginePage::Feature> getSupportedFeatures() const;
|
||||
|
||||
SiteSettings getSiteSettings(QUrl &url);
|
||||
|
||||
private:
|
||||
|
||||
Permission testAttribute(const QWebEngineSettings::WebAttribute attribute) const;
|
||||
@ -104,7 +106,9 @@ private:
|
||||
QList<QWebEngineSettings::WebAttribute> supportedAttribute;
|
||||
QList<QWebEnginePage::Feature> supportedFeatures;
|
||||
QMap<QWebEnginePage::Feature, Permission> defaultFeatures;
|
||||
|
||||
QString attributesSql;
|
||||
QString everythingSql;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user