mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-28 00:39:43 -05:00
Added history limits enforcement
This commit is contained in:
parent
860a2131b3
commit
8c87a87da6
@ -337,6 +337,19 @@ void Entry::setExpiryTime(const QDateTime& dateTime)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Entry::getHistSize() {
|
||||||
|
int size = 0;
|
||||||
|
|
||||||
|
for(int i=0 ; i<m_history.size() ; i++) {
|
||||||
|
size += m_history[i]->getSize();
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Entry::getSize() {
|
||||||
|
return attributes()->attributesSize() + attachments()->attachmentsSize();
|
||||||
|
}
|
||||||
|
|
||||||
QList<Entry*> Entry::historyItems()
|
QList<Entry*> Entry::historyItems()
|
||||||
{
|
{
|
||||||
return m_history;
|
return m_history;
|
||||||
@ -353,9 +366,22 @@ void Entry::addHistoryItem(Entry* entry)
|
|||||||
Q_ASSERT(entry->uuid() == uuid());
|
Q_ASSERT(entry->uuid() == uuid());
|
||||||
|
|
||||||
m_history.append(entry);
|
m_history.append(entry);
|
||||||
|
truncateHistory();
|
||||||
Q_EMIT modified();
|
Q_EMIT modified();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Entry::truncateHistory() {
|
||||||
|
const Database *db = database();
|
||||||
|
if(db) {
|
||||||
|
while(m_history.size() > db->metadata()->historyMaxItems()) {
|
||||||
|
m_history.removeFirst();
|
||||||
|
}
|
||||||
|
while(getHistSize() > db->metadata()->historyMaxSize()) {
|
||||||
|
m_history.removeFirst();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Entry::beginUpdate()
|
void Entry::beginUpdate()
|
||||||
{
|
{
|
||||||
Q_ASSERT(!m_tmpHistoryItem);
|
Q_ASSERT(!m_tmpHistoryItem);
|
||||||
|
@ -108,10 +108,14 @@ public:
|
|||||||
void setNotes(const QString& notes);
|
void setNotes(const QString& notes);
|
||||||
void setExpires(const bool& value);
|
void setExpires(const bool& value);
|
||||||
void setExpiryTime(const QDateTime& dateTime);
|
void setExpiryTime(const QDateTime& dateTime);
|
||||||
|
int getHistSize();
|
||||||
|
int getSize();
|
||||||
|
|
||||||
QList<Entry*> historyItems();
|
QList<Entry*> historyItems();
|
||||||
const QList<Entry*>& historyItems() const;
|
const QList<Entry*>& historyItems() const;
|
||||||
void addHistoryItem(Entry* entry);
|
void addHistoryItem(Entry* entry);
|
||||||
|
void truncateHistory();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call before and after set*() methods to create a history item
|
* Call before and after set*() methods to create a history item
|
||||||
* if the entry has been changed.
|
* if the entry has been changed.
|
||||||
|
@ -32,6 +32,11 @@ QByteArray EntryAttachments::value(const QString& key) const
|
|||||||
return m_attachments.value(key);
|
return m_attachments.value(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int EntryAttachments::dataSize(const QString& key)
|
||||||
|
{
|
||||||
|
return m_attachments.value(key).size();
|
||||||
|
}
|
||||||
|
|
||||||
void EntryAttachments::set(const QString& key, const QByteArray& value)
|
void EntryAttachments::set(const QString& key, const QByteArray& value)
|
||||||
{
|
{
|
||||||
bool emitModified = false;
|
bool emitModified = false;
|
||||||
@ -87,6 +92,15 @@ void EntryAttachments::clear()
|
|||||||
Q_EMIT modified();
|
Q_EMIT modified();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int EntryAttachments::attachmentsSize() {
|
||||||
|
int size = 0;
|
||||||
|
|
||||||
|
Q_FOREACH (const QString& key, keys()) {
|
||||||
|
size += dataSize(key);
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
bool EntryAttachments::operator==(const EntryAttachments& other) const
|
bool EntryAttachments::operator==(const EntryAttachments& other) const
|
||||||
{
|
{
|
||||||
return m_attachments == other.m_attachments;
|
return m_attachments == other.m_attachments;
|
||||||
|
@ -29,9 +29,11 @@ public:
|
|||||||
explicit EntryAttachments(QObject* parent = 0);
|
explicit EntryAttachments(QObject* parent = 0);
|
||||||
QList<QString> keys() const;
|
QList<QString> keys() const;
|
||||||
QByteArray value(const QString& key) const;
|
QByteArray value(const QString& key) const;
|
||||||
|
int dataSize(const QString& key);
|
||||||
void set(const QString& key, const QByteArray& value);
|
void set(const QString& key, const QByteArray& value);
|
||||||
void remove(const QString& key);
|
void remove(const QString& key);
|
||||||
void clear();
|
void clear();
|
||||||
|
int attachmentsSize();
|
||||||
bool operator==(const EntryAttachments& other) const;
|
bool operator==(const EntryAttachments& other) const;
|
||||||
bool operator!=(const EntryAttachments& other) const;
|
bool operator!=(const EntryAttachments& other) const;
|
||||||
EntryAttachments& operator=(EntryAttachments& other);
|
EntryAttachments& operator=(EntryAttachments& other);
|
||||||
|
@ -36,6 +36,11 @@ QString EntryAttributes::value(const QString& key) const
|
|||||||
return m_attributes.value(key);
|
return m_attributes.value(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int EntryAttributes::valueSize(const QString& key)
|
||||||
|
{
|
||||||
|
return m_attributes.value(key).size() * sizeof(QChar);
|
||||||
|
}
|
||||||
|
|
||||||
bool EntryAttributes::isProtected(const QString& key) const
|
bool EntryAttributes::isProtected(const QString& key) const
|
||||||
{
|
{
|
||||||
return m_protectedAttributes.contains(key);
|
return m_protectedAttributes.contains(key);
|
||||||
@ -223,6 +228,15 @@ void EntryAttributes::clear()
|
|||||||
Q_EMIT modified();
|
Q_EMIT modified();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int EntryAttributes::attributesSize() {
|
||||||
|
int size = 0;
|
||||||
|
|
||||||
|
Q_FOREACH (const QString& key, keys()) {
|
||||||
|
size += valueSize(key);
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
bool EntryAttributes::isDefaultAttribute(const QString& key)
|
bool EntryAttributes::isDefaultAttribute(const QString& key)
|
||||||
{
|
{
|
||||||
return DEFAULT_ATTRIBUTES.contains(key);
|
return DEFAULT_ATTRIBUTES.contains(key);
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include <QtCore/QSet>
|
#include <QtCore/QSet>
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
#include <QtCore/QStringList>
|
#include <QtCore/QStringList>
|
||||||
|
#include <QtCore/QChar>
|
||||||
|
|
||||||
class EntryAttributes : public QObject
|
class EntryAttributes : public QObject
|
||||||
{
|
{
|
||||||
@ -31,6 +32,7 @@ public:
|
|||||||
explicit EntryAttributes(QObject* parent = 0);
|
explicit EntryAttributes(QObject* parent = 0);
|
||||||
QList<QString> keys() const;
|
QList<QString> keys() const;
|
||||||
QString value(const QString& key) const;
|
QString value(const QString& key) const;
|
||||||
|
int valueSize(const QString& key);
|
||||||
bool isProtected(const QString& key) const;
|
bool isProtected(const QString& key) const;
|
||||||
void set(const QString& key, const QString& value, bool protect = false);
|
void set(const QString& key, const QString& value, bool protect = false);
|
||||||
void remove(const QString& key);
|
void remove(const QString& key);
|
||||||
@ -38,10 +40,10 @@ public:
|
|||||||
void copyCustomKeysFrom(const EntryAttributes* other);
|
void copyCustomKeysFrom(const EntryAttributes* other);
|
||||||
bool areCustomKeysDifferent(const EntryAttributes* other);
|
bool areCustomKeysDifferent(const EntryAttributes* other);
|
||||||
void clear();
|
void clear();
|
||||||
|
int attributesSize();
|
||||||
EntryAttributes& operator=(const EntryAttributes& other);
|
EntryAttributes& operator=(const EntryAttributes& other);
|
||||||
bool operator==(const EntryAttributes& other) const;
|
bool operator==(const EntryAttributes& other) const;
|
||||||
bool operator!=(const EntryAttributes& other) const;
|
bool operator!=(const EntryAttributes& other) const;
|
||||||
|
|
||||||
static const QStringList DEFAULT_ATTRIBUTES;
|
static const QStringList DEFAULT_ATTRIBUTES;
|
||||||
static bool isDefaultAttribute(const QString& key);
|
static bool isDefaultAttribute(const QString& key);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user