19
#include "BrowserEntryConfig.h"
21
#include "core/Entry.h"
22
#include "core/Tools.h"
24
#include <QJsonDocument>
28
static const char KEEPASSXCBROWSER_NAME[] = "KeePassXC-Browser Settings";
30
BrowserEntryConfig::BrowserEntryConfig(QObject* parent)
35
QStringList BrowserEntryConfig::allowedHosts() const
37
return m_allowedHosts.toList();
40
void BrowserEntryConfig::setAllowedHosts(const QStringList& allowedHosts)
42
m_allowedHosts = allowedHosts.toSet();
45
QStringList BrowserEntryConfig::deniedHosts() const
47
return m_deniedHosts.toList();
50
void BrowserEntryConfig::setDeniedHosts(const QStringList& deniedHosts)
52
m_deniedHosts = deniedHosts.toSet();
55
bool BrowserEntryConfig::isAllowed(const QString& host) const
57
return m_allowedHosts.contains(host);
60
void BrowserEntryConfig::allow(const QString& host)
62
m_allowedHosts.insert(host);
63
m_deniedHosts.remove(host);
66
bool BrowserEntryConfig::isDenied(const QString& host) const
68
return m_deniedHosts.contains(host);
71
void BrowserEntryConfig::deny(const QString& host)
73
m_deniedHosts.insert(host);
74
m_allowedHosts.remove(host);
77
QString BrowserEntryConfig::realm() const
82
void BrowserEntryConfig::setRealm(const QString& realm)
87
bool BrowserEntryConfig::load(const Entry* entry)
89
QString s = entry->customData()->value(KEEPASSXCBROWSER_NAME);
94
QJsonDocument doc = QJsonDocument::fromJson(s.toUtf8());
99
QVariantMap map = doc.object().toVariantMap();
100
for (QVariantMap::const_iterator iter = map.cbegin(); iter != map.cend(); ++iter) {
101
setProperty(iter.key().toLatin1(), iter.value());
106
void BrowserEntryConfig::save(Entry* entry)
108
QVariantMap v = Tools::qo2qvm(this);
109
QJsonObject o = QJsonObject::fromVariantMap(v);
110
QByteArray json = QJsonDocument(o).toJson(QJsonDocument::Compact);
111
entry->customData()->set(KEEPASSXCBROWSER_NAME, json);