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

Add data cache in HTML5PermDialog

Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
Juraj Oravec 2022-08-16 09:10:08 +02:00
parent f8da0b0048
commit 81eaf7c32f
Signed by: SGOrava
GPG Key ID: 13660A3F1D9F093B
2 changed files with 43 additions and 21 deletions

View File

@ -52,6 +52,7 @@ void HTML5PermissionsDialog::showFeaturePermissions(QWebEnginePage::Feature feat
{ {
ui->treeWidget->clear(); ui->treeWidget->clear();
if (m_data[feature].length() == 0) {
QString column = mApp->siteSettingsManager()->sqlColumnFromWebEngineFeature(feature); QString column = mApp->siteSettingsManager()->sqlColumnFromWebEngineFeature(feature);
QSqlQuery query(SqlDatabase::instance()->database()); QSqlQuery query(SqlDatabase::instance()->database());
query.prepare(QSL("SELECT id, server, %1 FROM site_settings WHERE %1 != ?").arg(column)); query.prepare(QSL("SELECT id, server, %1 FROM site_settings WHERE %1 != ?").arg(column));
@ -59,23 +60,19 @@ void HTML5PermissionsDialog::showFeaturePermissions(QWebEnginePage::Feature feat
query.exec(); query.exec();
while (query.next()) { while (query.next()) {
int id = query.value(0).toInt(); SiteData siteData;
if (m_removed.contains(feature) && m_removed[feature].contains(id)) { siteData.id = query.value(0).toInt();
continue; siteData.host = query.value(1).toString();
siteData.perm = static_cast<SiteSettingsManager::Permission>(query.value(2).toInt());
m_data[feature].append(siteData);
createEntry(siteData);
} }
auto* item = new QTreeWidgetItem(ui->treeWidget);
item->setText(0, query.value(1).toString());
auto perm = static_cast<SiteSettingsManager::Permission>(query.value(2).toInt());
if (perm == SiteSettingsManager::Allow) {
item->setText(1, tr("Allow"));
} }
else { else {
item->setText(1, tr("Deny")); for (auto siteData : m_data[feature]) {
createEntry(siteData);
} }
item->setData(0, Qt::UserRole + 10, id);
ui->treeWidget->addTopLevelItem(item);
} }
} }
@ -84,6 +81,24 @@ void HTML5PermissionsDialog::featureIndexChanged()
showFeaturePermissions(currentFeature()); showFeaturePermissions(currentFeature());
} }
void HTML5PermissionsDialog::createEntry(HTML5PermissionsDialog::SiteData& siteData)
{
if (m_removed.contains(currentFeature()) && m_removed[currentFeature()].contains(siteData.id)) {
return;
}
auto* item = new QTreeWidgetItem(ui->treeWidget);
item->setText(0, siteData.host);
if (siteData.perm == SiteSettingsManager::Allow) {
item->setText(1, tr("Allow"));
}
else {
item->setText(1, tr("Deny"));
}
item->setData(0, Qt::UserRole + 10, siteData.id);
ui->treeWidget->addTopLevelItem(item);
}
void HTML5PermissionsDialog::removeEntry() void HTML5PermissionsDialog::removeEntry()
{ {
QTreeWidgetItem* item = ui->treeWidget->currentItem(); QTreeWidgetItem* item = ui->treeWidget->currentItem();

View File

@ -18,6 +18,7 @@
#ifndef HTML5PERMISSIONSDIALOG_H #ifndef HTML5PERMISSIONSDIALOG_H
#define HTML5PERMISSIONSDIALOG_H #define HTML5PERMISSIONSDIALOG_H
#include "sitesettingsmanager.h"
#include <QDialog> #include <QDialog>
#include <QStringList> #include <QStringList>
#include <QWebEnginePage> #include <QWebEnginePage>
@ -44,13 +45,19 @@ private Q_SLOTS:
void saveSettings(); void saveSettings();
private: private:
enum Role { Allow, Deny }; struct SiteData {
SiteSettingsManager::Permission perm;
int id;
QString host;
};
void createEntry(SiteData &siteData);
QWebEnginePage::Feature currentFeature() const; QWebEnginePage::Feature currentFeature() const;
QWebEnginePage::Feature indexToFeature(const int index) const; QWebEnginePage::Feature indexToFeature(const int index) const;
Ui::HTML5PermissionsDialog* ui; Ui::HTML5PermissionsDialog* ui;
QHash<QWebEnginePage::Feature, QList<SiteData>> m_data;
QHash<QWebEnginePage::Feature, QVariantList> m_removed; QHash<QWebEnginePage::Feature, QVariantList> m_removed;
}; };