mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-08-25 06:39:54 -04:00
parent
8c87a87da6
commit
1a74feb253
6 changed files with 54 additions and 38 deletions
|
@ -337,17 +337,8 @@ void Entry::setExpiryTime(const QDateTime& dateTime)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Entry::getHistSize() {
|
int Entry::getSize(QList<QByteArray>* foundAttachements) {
|
||||||
int size = 0;
|
return attributes()->attributesSize() + attachments()->attachmentsSize(foundAttachements);
|
||||||
|
|
||||||
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()
|
||||||
|
@ -366,18 +357,49 @@ 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() {
|
void Entry::truncateHistory() {
|
||||||
const Database *db = database();
|
const Database *db = database();
|
||||||
if(db) {
|
if(db) {
|
||||||
while(m_history.size() > db->metadata()->historyMaxItems()) {
|
int histMaxItems = db->metadata()->historyMaxItems();
|
||||||
m_history.removeFirst();
|
if (histMaxItems > -1) {
|
||||||
|
int historyCount = 0;
|
||||||
|
QMutableListIterator<Entry*> i(m_history);
|
||||||
|
i.toBack();
|
||||||
|
while (i.hasPrevious()) {
|
||||||
|
historyCount++;
|
||||||
|
Entry* entry = i.previous();
|
||||||
|
if (historyCount > histMaxItems) {
|
||||||
|
delete entry;
|
||||||
|
i.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int histMaxSize = db->metadata()->historyMaxSize();
|
||||||
|
if (histMaxSize > -1) {
|
||||||
|
int size = 0;
|
||||||
|
QList<QByteArray>* foundAttachements = new QList<QByteArray>();
|
||||||
|
attachments()->attachmentsSize(foundAttachements);
|
||||||
|
|
||||||
|
QMutableListIterator<Entry*> i(m_history);
|
||||||
|
i.toBack();
|
||||||
|
while (i.hasPrevious()) {
|
||||||
|
Entry* entry = i.previous();
|
||||||
|
if (size > histMaxSize) {
|
||||||
|
delete entry;
|
||||||
|
i.remove();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
size += entry->getSize(foundAttachements);
|
||||||
|
if (size > histMaxSize) {
|
||||||
|
delete entry;
|
||||||
|
i.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
while(getHistSize() > db->metadata()->historyMaxSize()) {
|
|
||||||
m_history.removeFirst();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -399,10 +421,10 @@ void Entry::beginUpdate()
|
||||||
void Entry::endUpdate()
|
void Entry::endUpdate()
|
||||||
{
|
{
|
||||||
Q_ASSERT(m_tmpHistoryItem);
|
Q_ASSERT(m_tmpHistoryItem);
|
||||||
|
|
||||||
if (m_modifiedSinceBegin) {
|
if (m_modifiedSinceBegin) {
|
||||||
m_tmpHistoryItem->setUpdateTimeinfo(true);
|
m_tmpHistoryItem->setUpdateTimeinfo(true);
|
||||||
addHistoryItem(m_tmpHistoryItem);
|
addHistoryItem(m_tmpHistoryItem);
|
||||||
|
truncateHistory();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
delete m_tmpHistoryItem;
|
delete m_tmpHistoryItem;
|
||||||
|
|
|
@ -108,8 +108,7 @@ 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<QByteArray>* foundAttachements);
|
||||||
int getSize();
|
|
||||||
|
|
||||||
QList<Entry*> historyItems();
|
QList<Entry*> historyItems();
|
||||||
const QList<Entry*>& historyItems() const;
|
const QList<Entry*>& historyItems() const;
|
||||||
|
|
|
@ -32,11 +32,6 @@ 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;
|
||||||
|
@ -92,11 +87,16 @@ void EntryAttachments::clear()
|
||||||
Q_EMIT modified();
|
Q_EMIT modified();
|
||||||
}
|
}
|
||||||
|
|
||||||
int EntryAttachments::attachmentsSize() {
|
int EntryAttachments::attachmentsSize(QList<QByteArray>* foundAttachements) {
|
||||||
int size = 0;
|
int size = 0;
|
||||||
|
|
||||||
Q_FOREACH (const QString& key, keys()) {
|
QMapIterator<QString, QByteArray> i(m_attachments);
|
||||||
size += dataSize(key);
|
while (i.hasNext()) {
|
||||||
|
i.next();
|
||||||
|
if (!foundAttachements->contains(i.value())) {
|
||||||
|
foundAttachements->append(i.value());
|
||||||
|
size += i.value().size();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,11 +29,10 @@ 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();
|
int attachmentsSize(QList<QByteArray> *foundAttachements);
|
||||||
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,11 +36,6 @@ 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);
|
||||||
|
@ -231,8 +226,10 @@ void EntryAttributes::clear()
|
||||||
int EntryAttributes::attributesSize() {
|
int EntryAttributes::attributesSize() {
|
||||||
int size = 0;
|
int size = 0;
|
||||||
|
|
||||||
Q_FOREACH (const QString& key, keys()) {
|
QMapIterator<QString, QString> i(m_attributes);
|
||||||
size += valueSize(key);
|
while (i.hasNext()) {
|
||||||
|
i.next();
|
||||||
|
size += i.value().toUtf8().size();
|
||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
#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
|
||||||
{
|
{
|
||||||
|
@ -32,7 +31,6 @@ 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);
|
||||||
|
@ -44,6 +42,7 @@ public:
|
||||||
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…
Add table
Add a link
Reference in a new issue