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();
|
||||
|
||||
QString column = mApp->siteSettingsManager()->sqlColumnFromWebEngineFeature(feature);
|
||||
QSqlQuery query(SqlDatabase::instance()->database());
|
||||
query.prepare(QSL("SELECT id, server, %1 FROM site_settings WHERE %1 != ?").arg(column));
|
||||
query.addBindValue(SiteSettingsManager::Default);
|
||||
query.exec();
|
||||
if (m_data[feature].length() == 0) {
|
||||
QString column = mApp->siteSettingsManager()->sqlColumnFromWebEngineFeature(feature);
|
||||
QSqlQuery query(SqlDatabase::instance()->database());
|
||||
query.prepare(QSL("SELECT id, server, %1 FROM site_settings WHERE %1 != ?").arg(column));
|
||||
query.addBindValue(SiteSettingsManager::Default);
|
||||
query.exec();
|
||||
|
||||
while (query.next()) {
|
||||
int id = query.value(0).toInt();
|
||||
if (m_removed.contains(feature) && m_removed[feature].contains(id)) {
|
||||
continue;
|
||||
}
|
||||
while (query.next()) {
|
||||
SiteData siteData;
|
||||
siteData.id = query.value(0).toInt();
|
||||
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);
|
||||
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"));
|
||||
createEntry(siteData);
|
||||
}
|
||||
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());
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
QTreeWidgetItem* item = ui->treeWidget->currentItem();
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#ifndef HTML5PERMISSIONSDIALOG_H
|
||||
#define HTML5PERMISSIONSDIALOG_H
|
||||
|
||||
#include "sitesettingsmanager.h"
|
||||
#include <QDialog>
|
||||
#include <QStringList>
|
||||
#include <QWebEnginePage>
|
||||
|
@ -44,13 +45,19 @@ private Q_SLOTS:
|
|||
void saveSettings();
|
||||
|
||||
private:
|
||||
enum Role { Allow, Deny };
|
||||
struct SiteData {
|
||||
SiteSettingsManager::Permission perm;
|
||||
int id;
|
||||
QString host;
|
||||
};
|
||||
void createEntry(SiteData &siteData);
|
||||
|
||||
QWebEnginePage::Feature currentFeature() const;
|
||||
QWebEnginePage::Feature indexToFeature(const int index) const;
|
||||
|
||||
Ui::HTML5PermissionsDialog* ui;
|
||||
|
||||
QHash<QWebEnginePage::Feature, QList<SiteData>> m_data;
|
||||
QHash<QWebEnginePage::Feature, QVariantList> m_removed;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user