Add modified signals for entries.

This commit is contained in:
Florian Geyer 2012-04-11 19:51:54 +02:00 committed by Felix Geyer
parent 73e1104442
commit 674909f635
4 changed files with 86 additions and 24 deletions

View File

@ -28,6 +28,7 @@ Entry::Entry()
{ {
m_group = 0; m_group = 0;
m_db = 0; m_db = 0;
m_updateTimeinfo = true;
m_iconNumber = 0; m_iconNumber = 0;
m_autoTypeEnabled = true; m_autoTypeEnabled = true;
@ -47,6 +48,25 @@ Entry::~Entry()
qDeleteAll(m_history); qDeleteAll(m_history);
} }
template <class T> bool Entry::set(T& property, const T& value) {
if (property != value) {
property = value;
if (m_updateTimeinfo) {
m_timeInfo.setLastModificationTime(QDateTime::currentDateTime());
m_timeInfo.setLastAccessTime(QDateTime::currentDateTime());
}
Q_EMIT modified();
return true;
}
else {
return false;
}
}
void Entry::setUpdateTimeinfo(bool value) {
m_updateTimeinfo = value;
}
Uuid Entry::uuid() const Uuid Entry::uuid() const
{ {
return m_uuid; return m_uuid;
@ -193,48 +213,52 @@ QString Entry::notes() const
void Entry::setUuid(const Uuid& uuid) void Entry::setUuid(const Uuid& uuid)
{ {
Q_ASSERT(!uuid.isNull()); Q_ASSERT(!uuid.isNull());
set(m_uuid, uuid);
m_uuid = uuid;
} }
void Entry::setIcon(int iconNumber) void Entry::setIcon(int iconNumber)
{ {
Q_ASSERT(iconNumber >= 0); Q_ASSERT(iconNumber >= 0);
if (m_iconNumber != iconNumber || !m_customIcon.isNull()) {
m_iconNumber = iconNumber; m_iconNumber = iconNumber;
m_customIcon = Uuid(); m_customIcon = Uuid();
m_pixmapCacheKey = QPixmapCache::Key(); m_pixmapCacheKey = QPixmapCache::Key();
Q_EMIT modified();
}
} }
void Entry::setIcon(const Uuid& uuid) void Entry::setIcon(const Uuid& uuid)
{ {
Q_ASSERT(!uuid.isNull()); Q_ASSERT(!uuid.isNull());
if (set(m_customIcon, uuid)) {
m_iconNumber = 0; m_iconNumber = 0;
m_customIcon = uuid;
m_pixmapCacheKey = QPixmapCache::Key(); m_pixmapCacheKey = QPixmapCache::Key();
}
} }
void Entry::setForegroundColor(const QColor& color) void Entry::setForegroundColor(const QColor& color)
{ {
m_foregroundColor = color; set(m_foregroundColor, color);
} }
void Entry::setBackgroundColor(const QColor& color) void Entry::setBackgroundColor(const QColor& color)
{ {
m_backgroundColor = color; set(m_backgroundColor, color);
} }
void Entry::setOverrideUrl(const QString& url) void Entry::setOverrideUrl(const QString& url)
{ {
m_overrideUrl = url; set(m_overrideUrl, url);
} }
void Entry::setTags(const QString& tags) void Entry::setTags(const QString& tags)
{ {
m_tags = tags; set(m_tags, tags);
} }
void Entry::setTimeInfo(const TimeInfo& timeInfo) void Entry::setTimeInfo(const TimeInfo& timeInfo)
@ -244,26 +268,29 @@ void Entry::setTimeInfo(const TimeInfo& timeInfo)
void Entry::setAutoTypeEnabled(bool enable) void Entry::setAutoTypeEnabled(bool enable)
{ {
m_autoTypeEnabled = enable; set(m_autoTypeEnabled, enable);
} }
void Entry::setAutoTypeObfuscation(int obfuscation) void Entry::setAutoTypeObfuscation(int obfuscation)
{ {
m_autoTypeObfuscation = obfuscation; set(m_autoTypeObfuscation, obfuscation);
} }
void Entry::setDefaultAutoTypeSequence(const QString& sequence) void Entry::setDefaultAutoTypeSequence(const QString& sequence)
{ {
m_defaultAutoTypeSequence = sequence; set(m_defaultAutoTypeSequence, sequence);
} }
void Entry::addAutoTypeAssociation(const AutoTypeAssociation& assoc) void Entry::addAutoTypeAssociation(const AutoTypeAssociation& assoc)
{ {
m_autoTypeAssociations << assoc; m_autoTypeAssociations << assoc;
Q_EMIT modified();
} }
void Entry::setAttribute(const QString& key, const QString& value, bool protect) void Entry::setAttribute(const QString& key, const QString& value, bool protect)
{ {
bool emitModified = false;
bool addAttribute = !m_attributes.contains(key); bool addAttribute = !m_attributes.contains(key);
bool defaultAttribute = isDefaultAttribute(key); bool defaultAttribute = isDefaultAttribute(key);
@ -271,13 +298,23 @@ void Entry::setAttribute(const QString& key, const QString& value, bool protect)
Q_EMIT attributeAboutToBeAdded(key); Q_EMIT attributeAboutToBeAdded(key);
} }
if (addAttribute || m_attributes.value(key) != value) {
m_attributes.insert(key, value); m_attributes.insert(key, value);
emitModified = true;
}
if (protect) { if (protect) {
if (!m_protectedAttributes.contains(key)) {
emitModified = true;
}
m_protectedAttributes.insert(key); m_protectedAttributes.insert(key);
} }
else { else if (m_protectedAttributes.remove(key)) {
m_protectedAttributes.remove(key); emitModified = true;
}
if (emitModified) {
Q_EMIT modified();
} }
if (defaultAttribute) { if (defaultAttribute) {
@ -306,23 +343,28 @@ void Entry::removeAttribute(const QString& key)
m_protectedAttributes.remove(key); m_protectedAttributes.remove(key);
Q_EMIT attributeRemoved(key); Q_EMIT attributeRemoved(key);
Q_EMIT modified();
} }
void Entry::setAttachment(const QString& key, const QByteArray& value, bool protect) void Entry::setAttachment(const QString& key, const QByteArray& value, bool protect)
{ {
bool emitModified = false;
bool addAttachment = !m_binaries.contains(key); bool addAttachment = !m_binaries.contains(key);
if (addAttachment) { if (addAttachment || m_binaries.value(key) != value) {
Q_EMIT attachmentAboutToBeAdded(key); Q_EMIT attachmentAboutToBeAdded(key);
}
m_binaries.insert(key, value); m_binaries.insert(key, value);
emitModified = true;
}
if (protect) { if (protect) {
if (!m_protectedAttachments.contains(key)) {
emitModified = true;
}
m_protectedAttachments.insert(key); m_protectedAttachments.insert(key);
} }
else { else if (m_protectedAttachments.remove(key)) {
m_protectedAttachments.remove(key); emitModified = true;
} }
if (addAttachment) { if (addAttachment) {
@ -331,6 +373,10 @@ void Entry::setAttachment(const QString& key, const QByteArray& value, bool prot
else { else {
Q_EMIT attachmentChanged(key); Q_EMIT attachmentChanged(key);
} }
if (emitModified) {
Q_EMIT modified();
}
} }
void Entry::removeAttachment(const QString& key) void Entry::removeAttachment(const QString& key)
@ -346,6 +392,7 @@ void Entry::removeAttachment(const QString& key)
m_protectedAttachments.remove(key); m_protectedAttachments.remove(key);
Q_EMIT attachmentRemoved(key); Q_EMIT attachmentRemoved(key);
Q_EMIT modified();
} }
void Entry::setTitle(const QString& title) void Entry::setTitle(const QString& title)
@ -388,6 +435,7 @@ void Entry::addHistoryItem(Entry* entry)
Q_ASSERT(!entry->parent()); Q_ASSERT(!entry->parent());
m_history.append(entry); m_history.append(entry);
Q_EMIT modified();
} }
Group* Entry::group() Group* Entry::group()

View File

@ -101,6 +101,8 @@ public:
Group* group(); Group* group();
void setGroup(Group* group); void setGroup(Group* group);
void setUpdateTimeinfo(bool value);
static bool isDefaultAttribute(const QString& key); static bool isDefaultAttribute(const QString& key);
Q_SIGNALS: Q_SIGNALS:
@ -121,6 +123,8 @@ Q_SIGNALS:
void attachmentAboutToBeRemoved(QString key); void attachmentAboutToBeRemoved(QString key);
void attachmentRemoved(QString key); void attachmentRemoved(QString key);
void modified();
private: private:
Uuid m_uuid; Uuid m_uuid;
int m_iconNumber; int m_iconNumber;
@ -144,6 +148,9 @@ private:
const Database* m_db; const Database* m_db;
QPixmapCache::Key m_pixmapCacheKey; QPixmapCache::Key m_pixmapCacheKey;
const static QStringList m_defaultAttibutes; const static QStringList m_defaultAttibutes;
bool m_updateTimeinfo;
template <class T> inline bool set(T& property, const T& value);
}; };
#endif // KEEPASSX_ENTRY_H #endif // KEEPASSX_ENTRY_H

View File

@ -304,7 +304,9 @@ void Group::addEntry(Entry *entry)
m_entries << entry; m_entries << entry;
connect(entry, SIGNAL(dataChanged(Entry*)), SIGNAL(entryDataChanged(Entry*))); connect(entry, SIGNAL(dataChanged(Entry*)), SIGNAL(entryDataChanged(Entry*)));
connect(entry, SIGNAL(modified()), this, SIGNAL(modified()));
Q_EMIT modified();
Q_EMIT entryAdded(); Q_EMIT entryAdded();
} }
@ -314,7 +316,7 @@ void Group::removeEntry(Entry* entry)
entry->disconnect(this); entry->disconnect(this);
m_entries.removeAll(entry); m_entries.removeAll(entry);
Q_EMIT modified();
Q_EMIT entryRemoved(); Q_EMIT entryRemoved();
} }

View File

@ -68,6 +68,10 @@ void KeePass2XmlReader::readDatabase(QIODevice* device, Database* db, KeePass2Ra
group->setUpdateTimeinfo(true); group->setUpdateTimeinfo(true);
} }
Q_FOREACH (Entry* entry, m_entries) {
entry->setUpdateTimeinfo(true);
}
delete m_tmpParent; delete m_tmpParent;
} }
@ -808,6 +812,7 @@ Entry* KeePass2XmlReader::getEntry(const Uuid& uuid)
} }
Entry* entry = new Entry(); Entry* entry = new Entry();
entry->setUpdateTimeinfo(false);
entry->setUuid(uuid); entry->setUuid(uuid);
entry->setGroup(m_tmpParent); entry->setGroup(m_tmpParent);
m_entries << entry; m_entries << entry;