mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-07-26 00:05:34 -04:00
keepassxc-browser
This commit is contained in:
parent
a7e6e4ef45
commit
06518c5736
43 changed files with 4422 additions and 42 deletions
109
src/browser/BrowserEntryConfig.cpp
Normal file
109
src/browser/BrowserEntryConfig.cpp
Normal file
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* Copyright (C) 2013 Francois Ferrand
|
||||
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "BrowserEntryConfig.h"
|
||||
#include <QtCore>
|
||||
#include "core/Entry.h"
|
||||
#include "core/EntryAttributes.h"
|
||||
|
||||
static const char KEEPASSBROWSER_NAME[] = "keepassxc-browser Settings"; //TODO: duplicated string (also in Service.cpp)
|
||||
|
||||
|
||||
BrowserEntryConfig::BrowserEntryConfig(QObject* parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
QStringList BrowserEntryConfig::allowedHosts() const
|
||||
{
|
||||
return m_allowedHosts.toList();
|
||||
}
|
||||
|
||||
void BrowserEntryConfig::setAllowedHosts(const QStringList& allowedHosts)
|
||||
{
|
||||
m_allowedHosts = allowedHosts.toSet();
|
||||
}
|
||||
|
||||
QStringList BrowserEntryConfig::deniedHosts() const
|
||||
{
|
||||
return m_deniedHosts.toList();
|
||||
}
|
||||
|
||||
void BrowserEntryConfig::setDeniedHosts(const QStringList& deniedHosts)
|
||||
{
|
||||
m_deniedHosts = deniedHosts.toSet();
|
||||
}
|
||||
|
||||
bool BrowserEntryConfig::isAllowed(const QString& host) const
|
||||
{
|
||||
return m_allowedHosts.contains(host);
|
||||
}
|
||||
|
||||
void BrowserEntryConfig::allow(const QString& host)
|
||||
{
|
||||
m_allowedHosts.insert(host);
|
||||
m_deniedHosts.remove(host);
|
||||
}
|
||||
|
||||
bool BrowserEntryConfig::isDenied(const QString& host) const
|
||||
{
|
||||
return m_deniedHosts.contains(host);
|
||||
}
|
||||
|
||||
void BrowserEntryConfig::deny(const QString& host)
|
||||
{
|
||||
m_deniedHosts.insert(host);
|
||||
m_allowedHosts.remove(host);
|
||||
}
|
||||
|
||||
QString BrowserEntryConfig::realm() const
|
||||
{
|
||||
return m_realm;
|
||||
}
|
||||
|
||||
void BrowserEntryConfig::setRealm(const QString& realm)
|
||||
{
|
||||
m_realm = realm;
|
||||
}
|
||||
|
||||
bool BrowserEntryConfig::load(const Entry* entry)
|
||||
{
|
||||
QString s = entry->attributes()->value(KEEPASSBROWSER_NAME);
|
||||
if (s.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QJsonDocument doc = QJsonDocument::fromJson(s.toUtf8());
|
||||
if (doc.isNull()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QVariantMap map = doc.object().toVariantMap();
|
||||
for (QVariantMap::const_iterator iter = map.cbegin(); iter != map.cend(); ++iter) {
|
||||
setProperty(iter.key().toLatin1(), iter.value());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void BrowserEntryConfig::save(Entry* entry)
|
||||
{
|
||||
QVariantMap v = qo2qv(this);
|
||||
QJsonObject o = QJsonObject::fromVariantMap(v);
|
||||
QByteArray json = QJsonDocument(o).toJson(QJsonDocument::Compact);
|
||||
entry->attributes()->set(KEEPASSBROWSER_NAME, json);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue