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:
parent
f8da0b0048
commit
81eaf7c32f
|
@ -52,30 +52,27 @@ void HTML5PermissionsDialog::showFeaturePermissions(QWebEnginePage::Feature feat
|
||||||
{
|
{
|
||||||
ui->treeWidget->clear();
|
ui->treeWidget->clear();
|
||||||
|
|
||||||
QString column = mApp->siteSettingsManager()->sqlColumnFromWebEngineFeature(feature);
|
if (m_data[feature].length() == 0) {
|
||||||
QSqlQuery query(SqlDatabase::instance()->database());
|
QString column = mApp->siteSettingsManager()->sqlColumnFromWebEngineFeature(feature);
|
||||||
query.prepare(QSL("SELECT id, server, %1 FROM site_settings WHERE %1 != ?").arg(column));
|
QSqlQuery query(SqlDatabase::instance()->database());
|
||||||
query.addBindValue(SiteSettingsManager::Default);
|
query.prepare(QSL("SELECT id, server, %1 FROM site_settings WHERE %1 != ?").arg(column));
|
||||||
query.exec();
|
query.addBindValue(SiteSettingsManager::Default);
|
||||||
|
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);
|
||||||
|
|
||||||
auto* item = new QTreeWidgetItem(ui->treeWidget);
|
createEntry(siteData);
|
||||||
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 {
|
}
|
||||||
item->setText(1, tr("Deny"));
|
else {
|
||||||
|
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();
|
||||||
|
|
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user