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

SiteSettings add Ask option for permission

Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
Juraj Oravec 2022-08-17 09:06:21 +02:00
parent b3e5c716dd
commit 0c462f0a1c
Signed by: SGOrava
GPG Key ID: 13660A3F1D9F093B
3 changed files with 26 additions and 27 deletions

View File

@ -114,21 +114,6 @@ void SiteSettingsManager::setOption(const QWebEnginePage::Feature& feature, cons
setOption(option, url, value);
}
bool SiteSettingsManager::getOption(const SiteSettingsManager::PageOptions option, const QUrl& url)
{
auto perm = getPermission(option, url);
if (perm == Allow) {
return true;
}
else if (perm == Deny) {
return false;
}
else {
return getDefaultOptionValue(option);
}
}
SiteSettingsManager::Permission SiteSettingsManager::getPermission(const SiteSettingsManager::PageOptions option, const QUrl& url)
{
QString column = optionToSqlColumn(option);
@ -145,12 +130,16 @@ SiteSettingsManager::Permission SiteSettingsManager::getPermission(const SiteSet
if (query.next()) {
int allow_option = query.value(column).toInt();
if (allow_option == 0) {
switch (allow_option) {
case Allow:
return Allow;
case Deny:
return Deny;
case Ask:
return Ask;
default:
return Default;
}
else {
return (allow_option == 1) ? Allow : Deny;
}
}
return Default;

View File

@ -40,6 +40,7 @@ public:
Default = 0,
Allow = 1,
Deny = 2,
Ask = 3,
};
enum PageOptions {
@ -90,7 +91,6 @@ public:
void setJavascript(const QUrl &url, const int value);
void setImages(const QUrl &url, const int value);
bool getOption(const PageOptions option, const QUrl &url);
Permission getPermission(const PageOptions option, const QUrl &url);
Permission getPermission(const QWebEnginePage::Feature &feature, const QUrl &url);

View File

@ -89,11 +89,20 @@ void HTML5PermissionsDialog::createEntry(const HTML5PermissionsDialog::SiteData&
auto* item = new QTreeWidgetItem(ui->treeWidget);
item->setText(0, siteData.host);
if (siteData.perm == SiteSettingsManager::Allow) {
switch (siteData.perm) {
case SiteSettingsManager::Allow:
item->setText(1, tr("Allow"));
}
else {
break;
case SiteSettingsManager::Deny:
item->setText(1, tr("Deny"));
break;
case SiteSettingsManager::Ask:
item->setText(1, tr("Ask"));
break;
default:
Q_UNREACHABLE();
item->setText(1, tr("Default"));
break;
}
item->setData(0, Qt::UserRole + 10, siteData.id);
ui->treeWidget->addTopLevelItem(item);
@ -149,7 +158,8 @@ void HTML5PermissionsDialog::saveSettings()
for (int i = 0; i < 8; ++i) {
const QWebEnginePage::Feature feature = indexToFeature(i);
const QString column = mApp->siteSettingsManager()->sqlColumnFromWebEngineFeature(feature);
query.prepare(QSL("UPDATE site_settings SET %1 = 0 WHERE id = ?").arg(column));
query.prepare(QSL("UPDATE site_settings SET %1 = ? WHERE id = ?").arg(column));
query.addBindValue(SiteSettingsManager::Default);
query.addBindValue(m_removed[feature]);
if (!query.execBatch()) {