mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +01:00
Add implementation of default permissions dialog
Still work in progress Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
parent
5eff4dc0e5
commit
ab0ff451c2
@ -854,6 +854,7 @@ void MainApplication::saveSettings()
|
|||||||
m_searchEnginesManager->saveSettings();
|
m_searchEnginesManager->saveSettings();
|
||||||
m_plugins->shutdown();
|
m_plugins->shutdown();
|
||||||
m_networkManager->shutdown();
|
m_networkManager->shutdown();
|
||||||
|
m_siteSettingsManager->saveSettings();
|
||||||
|
|
||||||
qzSettings->saveSettings();
|
qzSettings->saveSettings();
|
||||||
QFile::remove(DataPaths::currentProfilePath() + QLatin1String("/WebpageIcons.db"));
|
QFile::remove(DataPaths::currentProfilePath() + QLatin1String("/WebpageIcons.db"));
|
||||||
|
@ -35,8 +35,44 @@ SiteSettingsManager::~SiteSettingsManager() noexcept
|
|||||||
void SiteSettingsManager::loadSettings()
|
void SiteSettingsManager::loadSettings()
|
||||||
{
|
{
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings.beginGroup("Web-Browser-Settings");
|
// settings.beginGroup("Web-Browser-Settings");
|
||||||
// m_isSaving = settings.value("allowPerDomainZoom", true).toBool();
|
// m_isSaving = settings.value("allowPerDomainZoom", true).toBool();
|
||||||
|
// settings.endGroup();
|
||||||
|
|
||||||
|
settings.beginGroup("Site-Settings");
|
||||||
|
/* These are handled by already existing parts of Falkon */
|
||||||
|
// m_defaults[poAllowJavascript] = settings.value("allowJavascript", Default).toInt();
|
||||||
|
// m_defaults[poAllowImages] = settings.value("allowImages", Default).toInt();
|
||||||
|
// m_defaults[poAllowCookies] = settings.value("allowCookies", Default).toInt();
|
||||||
|
// m_defaults[poZoomLevel] = settings.value("defaultZoomLevel", Default).toInt(); // fail
|
||||||
|
m_defaults[poAllowNotifications] = intToPermission(settings.value("allowNotifications", Default).toInt());
|
||||||
|
m_defaults[poAllowGeolocation] = intToPermission(settings.value("allowGealocation", Default).toInt());
|
||||||
|
m_defaults[poAllowMediaAudioCapture] = intToPermission(settings.value("allowMicrophone", Default).toInt());
|
||||||
|
m_defaults[poAllowMediaVideoCapture] = intToPermission(settings.value("allowCamera", Default).toInt());
|
||||||
|
m_defaults[poAllowMediaAudioVideoCapture] = intToPermission(settings.value("allowCameraAndMicrophone", Default).toInt());
|
||||||
|
m_defaults[poAllowMouseLock] = intToPermission(settings.value("allowMouseLock", Default).toInt());
|
||||||
|
m_defaults[poAllowDesktopVideoCapture] = intToPermission(settings.value("allowDesktopVideoCapture", Default).toInt());
|
||||||
|
m_defaults[poAllowDesktopAudioVideoCapture] = intToPermission(settings.value("allowDesktopAudioVideoCapture", Default).toInt());
|
||||||
|
settings.endGroup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SiteSettingsManager::saveSettings()
|
||||||
|
{
|
||||||
|
Settings settings;
|
||||||
|
settings.beginGroup("Site-Settings");
|
||||||
|
/* These are handled by already existing parts of Falkon */
|
||||||
|
// settings.setValue("allowJavascript", m_defaults[poAllowJavascript]);
|
||||||
|
// settings.setValue("allowIbutmages", m_defaults[poAllowImages]);
|
||||||
|
// settings.setValue("allowCookies", m_defaults[poAllowCookies]);
|
||||||
|
// settings.setValue("defaultZoomLevel", m_defaults[poZoomLevel]);
|
||||||
|
settings.setValue("allowNotifications", m_defaults[poAllowNotifications]);
|
||||||
|
settings.setValue("allowGealocation", m_defaults[poAllowGeolocation]);
|
||||||
|
settings.setValue("allowMicrophone", m_defaults[poAllowMediaAudioCapture]);
|
||||||
|
settings.setValue("allowCamera", m_defaults[poAllowMediaVideoCapture]);
|
||||||
|
settings.setValue("allowCameraAndMicrophone", m_defaults[poAllowMediaAudioVideoCapture]);
|
||||||
|
settings.setValue("allowMouseLock", m_defaults[poAllowMouseLock]);
|
||||||
|
settings.setValue("allowDesktopVideoCapture", m_defaults[poAllowDesktopVideoCapture]);
|
||||||
|
settings.setValue("allowDesktopAudioVideoCapture", m_defaults[poAllowDesktopAudioVideoCapture]);
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,16 +165,7 @@ SiteSettingsManager::Permission SiteSettingsManager::getPermission(const SiteSet
|
|||||||
if (query.next()) {
|
if (query.next()) {
|
||||||
int allow_option = query.value(column).toInt();
|
int allow_option = query.value(column).toInt();
|
||||||
|
|
||||||
switch (allow_option) {
|
return intToPermission(allow_option);
|
||||||
case Allow:
|
|
||||||
return Allow;
|
|
||||||
case Deny:
|
|
||||||
return Deny;
|
|
||||||
case Ask:
|
|
||||||
return Ask;
|
|
||||||
default:
|
|
||||||
return Default;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Default;
|
return Default;
|
||||||
@ -205,6 +232,33 @@ SiteSettingsManager::Permission SiteSettingsManager::getDefaultPermission(const
|
|||||||
case poAllowImages:
|
case poAllowImages:
|
||||||
return testAttribute(QWebEngineSettings::AutoLoadImages);
|
return testAttribute(QWebEngineSettings::AutoLoadImages);
|
||||||
|
|
||||||
|
case poAllowNotifications:
|
||||||
|
return m_defaults[poAllowNotifications];
|
||||||
|
|
||||||
|
case poAllowGeolocation:
|
||||||
|
return m_defaults[poAllowGeolocation];
|
||||||
|
|
||||||
|
case poAllowMediaAudioCapture:
|
||||||
|
return m_defaults[poAllowMediaAudioCapture];
|
||||||
|
|
||||||
|
case poAllowMediaVideoCapture:
|
||||||
|
return m_defaults[poAllowMediaVideoCapture];
|
||||||
|
|
||||||
|
case poAllowMediaAudioVideoCapture:
|
||||||
|
return m_defaults[poAllowMediaAudioVideoCapture];
|
||||||
|
|
||||||
|
case poAllowMouseLock:
|
||||||
|
return m_defaults[poAllowMouseLock];
|
||||||
|
|
||||||
|
case poAllowDesktopVideoCapture:
|
||||||
|
return m_defaults[poAllowDesktopVideoCapture];
|
||||||
|
|
||||||
|
case poAllowDesktopAudioVideoCapture:
|
||||||
|
return m_defaults[poAllowDesktopAudioVideoCapture];
|
||||||
|
|
||||||
|
// so far not implemented
|
||||||
|
case poZoomLevel:
|
||||||
|
case poAllowCookies:
|
||||||
default:
|
default:
|
||||||
Q_UNREACHABLE();
|
Q_UNREACHABLE();
|
||||||
qWarning() << "Unknown option" << option;
|
qWarning() << "Unknown option" << option;
|
||||||
@ -212,6 +266,68 @@ SiteSettingsManager::Permission SiteSettingsManager::getDefaultPermission(const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SiteSettingsManager::Permission SiteSettingsManager::getDefaultPermission(const QWebEnginePage::Feature& feature)
|
||||||
|
{
|
||||||
|
auto option = optionFromWebEngineFeature(feature);
|
||||||
|
return getDefaultPermission(option);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SiteSettingsManager::setDefaultPermission(const SiteSettingsManager::PageOptions& option, const int& value)
|
||||||
|
{
|
||||||
|
switch (option) {
|
||||||
|
case poAllowNotifications:
|
||||||
|
case poAllowGeolocation:
|
||||||
|
case poAllowMediaAudioCapture:
|
||||||
|
case poAllowMediaVideoCapture:
|
||||||
|
case poAllowMediaAudioVideoCapture:
|
||||||
|
case poAllowMouseLock:
|
||||||
|
case poAllowDesktopVideoCapture:
|
||||||
|
case poAllowDesktopAudioVideoCapture:
|
||||||
|
setDefaultPermission(option, intToPermission(value));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case poZoomLevel:
|
||||||
|
case poAllowCookies:
|
||||||
|
case poAllowJavascript:
|
||||||
|
case poAllowImages:
|
||||||
|
default:
|
||||||
|
Q_UNREACHABLE();
|
||||||
|
qWarning() << "Unknown option" << option;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SiteSettingsManager::setDefaultPermission(const SiteSettingsManager::PageOptions& option, const SiteSettingsManager::Permission& permission)
|
||||||
|
{
|
||||||
|
switch (option) {
|
||||||
|
case poZoomLevel:
|
||||||
|
case poAllowCookies:
|
||||||
|
case poAllowJavascript:
|
||||||
|
case poAllowImages:
|
||||||
|
qWarning() << "So far not implemented" << option;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case poAllowNotifications:
|
||||||
|
case poAllowGeolocation:
|
||||||
|
case poAllowMediaAudioCapture:
|
||||||
|
case poAllowMediaVideoCapture:
|
||||||
|
case poAllowMediaAudioVideoCapture:
|
||||||
|
case poAllowMouseLock:
|
||||||
|
case poAllowDesktopVideoCapture:
|
||||||
|
case poAllowDesktopAudioVideoCapture:
|
||||||
|
m_defaults[option] = permission;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Q_UNREACHABLE();
|
||||||
|
qWarning() << "Unknown option" << option;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SiteSettingsManager::setDefaultPermission(const QWebEnginePage::Feature& feature, const SiteSettingsManager::Permission& value)
|
||||||
|
{
|
||||||
|
auto option = optionFromWebEngineFeature(feature);
|
||||||
|
setDefaultPermission(option, value);
|
||||||
|
}
|
||||||
|
|
||||||
bool SiteSettingsManager::getDefaultOptionValue(const SiteSettingsManager::PageOptions& option)
|
bool SiteSettingsManager::getDefaultOptionValue(const SiteSettingsManager::PageOptions& option)
|
||||||
{
|
{
|
||||||
switch (option) {
|
switch (option) {
|
||||||
@ -283,3 +399,17 @@ SiteSettingsManager::Permission SiteSettingsManager::testAttribute(const QWebEng
|
|||||||
return Deny;
|
return Deny;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SiteSettingsManager::Permission SiteSettingsManager::intToPermission(const int permission) const
|
||||||
|
{
|
||||||
|
switch (permission) {
|
||||||
|
case Allow:
|
||||||
|
return Allow;
|
||||||
|
case Deny:
|
||||||
|
return Deny;
|
||||||
|
case Ask:
|
||||||
|
return Ask;
|
||||||
|
default:
|
||||||
|
return Default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -82,6 +82,7 @@ public:
|
|||||||
~SiteSettingsManager();
|
~SiteSettingsManager();
|
||||||
|
|
||||||
void loadSettings();
|
void loadSettings();
|
||||||
|
void saveSettings();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get settings which should be applied to webpage before loading.
|
* @brief Get settings which should be applied to webpage before loading.
|
||||||
@ -100,14 +101,22 @@ public:
|
|||||||
void setOption(const PageOptions option, const QUrl &url, const int value);
|
void setOption(const PageOptions option, const QUrl &url, const int value);
|
||||||
void setOption(const QWebEnginePage::Feature &feature, const QUrl &url, const Permission &value);
|
void setOption(const QWebEnginePage::Feature &feature, const QUrl &url, const Permission &value);
|
||||||
|
|
||||||
|
Permission getDefaultPermission(const PageOptions &option);
|
||||||
|
Permission getDefaultPermission(const QWebEnginePage::Feature &feature);
|
||||||
|
void setDefaultPermission(const PageOptions &option, const Permission &permission);
|
||||||
|
void setDefaultPermission(const QWebEnginePage::Feature &feature, const Permission &value);
|
||||||
|
void setDefaultPermission(const PageOptions &option, const int &value);
|
||||||
|
|
||||||
QString sqlColumnFromWebEngineFeature(const QWebEnginePage::Feature &feature);
|
QString sqlColumnFromWebEngineFeature(const QWebEnginePage::Feature &feature);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString optionToSqlColumn(const PageOptions &option);
|
QString optionToSqlColumn(const PageOptions &option);
|
||||||
bool getDefaultOptionValue(const PageOptions &option);
|
bool getDefaultOptionValue(const PageOptions &option);
|
||||||
Permission getDefaultPermission(const PageOptions &option);
|
|
||||||
PageOptions optionFromWebEngineFeature(const QWebEnginePage::Feature &feature) const;
|
PageOptions optionFromWebEngineFeature(const QWebEnginePage::Feature &feature) const;
|
||||||
Permission testAttribute(const QWebEngineSettings::WebAttribute attribute) const;
|
Permission testAttribute(const QWebEngineSettings::WebAttribute attribute) const;
|
||||||
|
Permission intToPermission(const int permission) const;
|
||||||
|
|
||||||
|
QMap<PageOptions, Permission> m_defaults;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,14 +42,7 @@ HTML5PermissionsDialog::HTML5PermissionsDialog(QWidget* parent)
|
|||||||
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &HTML5PermissionsDialog::saveSettings);
|
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &HTML5PermissionsDialog::saveSettings);
|
||||||
|
|
||||||
showFeaturePermissions(currentFeature());
|
showFeaturePermissions(currentFeature());
|
||||||
|
showDefaultPermissions();
|
||||||
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()
|
HTML5PermissionsDialog::~HTML5PermissionsDialog()
|
||||||
@ -175,4 +168,24 @@ void HTML5PermissionsDialog::saveSettings()
|
|||||||
qDebug() << query.lastError();
|
qDebug() << query.lastError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 8; ++i) {
|
||||||
|
auto* item = static_cast<HTML5PermissionsItem*>(ui->listWidgetDefaults->itemWidget(ui->listWidgetDefaults->item(i)));
|
||||||
|
const auto feature = item->getFeature();
|
||||||
|
const auto permission = item->getPermission();
|
||||||
|
mApp->siteSettingsManager()->setDefaultPermission(feature, permission);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HTML5PermissionsDialog::showDefaultPermissions()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 8; ++i) {
|
||||||
|
const auto feature = indexToFeature(i);
|
||||||
|
const auto permission = mApp->siteSettingsManager()->getDefaultPermission(feature);
|
||||||
|
|
||||||
|
auto* listItem = new QListWidgetItem(ui->listWidgetDefaults);
|
||||||
|
auto* permItem = new HTML5PermissionsItem(feature, permission, this);
|
||||||
|
ui->listWidgetDefaults->setItemWidget(listItem, permItem);
|
||||||
|
listItem->setSizeHint(permItem->sizeHint());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,8 @@ private Q_SLOTS:
|
|||||||
void removeEntry();
|
void removeEntry();
|
||||||
void featureIndexChanged();
|
void featureIndexChanged();
|
||||||
|
|
||||||
|
void showDefaultPermissions();
|
||||||
|
|
||||||
void saveSettings();
|
void saveSettings();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -109,6 +109,7 @@ void HTML5PermissionsItem::setCombo()
|
|||||||
ui->comboBox->setCurrentIndex(1);
|
ui->comboBox->setCurrentIndex(1);
|
||||||
break;
|
break;
|
||||||
case SiteSettingsManager::Ask:
|
case SiteSettingsManager::Ask:
|
||||||
|
case SiteSettingsManager::Default:
|
||||||
ui->comboBox->setCurrentIndex(2);
|
ui->comboBox->setCurrentIndex(2);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user