diff --git a/src/core/Group.cpp b/src/core/Group.cpp index 8ed4a17cc..d6b90ba11 100644 --- a/src/core/Group.cpp +++ b/src/core/Group.cpp @@ -33,6 +33,8 @@ Group::Group() m_isExpanded = true; m_autoTypeEnabled = Inherit; m_searchingEnabled = Inherit; + + m_updateTimeinfo = true; } Group::~Group() @@ -40,6 +42,25 @@ Group::~Group() cleanupParent(); } +template bool Group::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 Group::setUpdateTimeinfo(bool value) { + m_updateTimeinfo = value; +} + Uuid Group::uuid() const { return m_uuid; @@ -125,43 +146,47 @@ Entry* Group::lastTopVisibleEntry() const void Group::setUuid(const Uuid& uuid) { - m_uuid = uuid; + set(m_uuid, uuid); } void Group::setName(const QString& name) { - m_name = name; - - Q_EMIT dataChanged(this); + if (set(m_name, name)) { + Q_EMIT dataChanged(this); + } } void Group::setNotes(const QString& notes) { - m_notes = notes; + set(m_notes, notes); } void Group::setIcon(int iconNumber) { Q_ASSERT(iconNumber >= 0); - m_iconNumber = iconNumber; - m_customIcon = Uuid(); + if (m_iconNumber != iconNumber || !m_customIcon.isNull()) { + m_iconNumber = iconNumber; + m_customIcon = Uuid(); - m_pixmapCacheKey = QPixmapCache::Key(); + m_pixmapCacheKey = QPixmapCache::Key(); - Q_EMIT dataChanged(this); + Q_EMIT modified(); + Q_EMIT dataChanged(this); + } } void Group::setIcon(const Uuid& uuid) { Q_ASSERT(!uuid.isNull()); - m_iconNumber = 0; - m_customIcon = uuid; + if (set(m_customIcon, uuid)) { + m_iconNumber = 0; - m_pixmapCacheKey = QPixmapCache::Key(); + m_pixmapCacheKey = QPixmapCache::Key(); - Q_EMIT dataChanged(this); + Q_EMIT dataChanged(this); + } } void Group::setTimeInfo(const TimeInfo& timeInfo) @@ -171,27 +196,27 @@ void Group::setTimeInfo(const TimeInfo& timeInfo) void Group::setExpanded(bool expanded) { - m_isExpanded = expanded; + set(m_isExpanded, expanded); } void Group::setDefaultAutoTypeSequence(const QString& sequence) { - m_defaultAutoTypeSequence = sequence; + set(m_defaultAutoTypeSequence, sequence); } void Group::setAutoTypeEnabled(TriState enable) { - m_autoTypeEnabled = enable; + set(m_autoTypeEnabled, enable); } void Group::setSearchingEnabled(TriState enable) { - m_searchingEnabled = enable; + set(m_searchingEnabled, enable); } void Group::setLastTopVisibleEntry(Entry* entry) { - m_lastTopVisibleEntry = entry; + set(m_lastTopVisibleEntry, entry); } Group* Group::parentGroup() @@ -215,6 +240,7 @@ void Group::setParent(Group* parent, int index) index = parent->children().size(); } + cleanupParent(); m_parent = parent; @@ -229,6 +255,7 @@ void Group::setParent(Group* parent, int index) parent->m_children.insert(index, this); + Q_EMIT modified(); Q_EMIT added(); } @@ -298,13 +325,14 @@ void Group::recSetDatabase(Database* db) disconnect(SIGNAL(removed()), m_db); disconnect(SIGNAL(aboutToAdd(Group*,int)), m_db); disconnect(SIGNAL(added()), m_db); + disconnect(SIGNAL(modified()), m_db); connect(this, SIGNAL(dataChanged(Group*)), db, SIGNAL(groupDataChanged(Group*))); - connect(this, SIGNAL(aboutToRemove(Group*)), db, SIGNAL(groupAboutToRemove(Group*))); connect(this, SIGNAL(removed()), db, SIGNAL(groupRemoved())); connect(this, SIGNAL(aboutToAdd(Group*,int)), db, SIGNAL(groupAboutToAdd(Group*,int))); connect(this, SIGNAL(added()), db, SIGNAL(groupAdded())); + connect(this, SIGNAL(modified()), db, SIGNAL(modified())); m_db = db; @@ -318,6 +346,7 @@ void Group::cleanupParent() if (m_parent) { Q_EMIT aboutToRemove(this); m_parent->m_children.removeAll(this); + Q_EMIT modified(); Q_EMIT removed(); } } diff --git a/src/core/Group.h b/src/core/Group.h index 18387edf2..af674bcee 100644 --- a/src/core/Group.h +++ b/src/core/Group.h @@ -63,6 +63,8 @@ public: void setSearchingEnabled(TriState enable); void setLastTopVisibleEntry(Entry* entry); + void setUpdateTimeinfo(bool value); + Group* parentGroup(); const Group* parentGroup() const; void setParent(Group* parent, int index = -1); @@ -88,7 +90,11 @@ Q_SIGNALS: void entryDataChanged(Entry* entry); + void modified(); + private: + template inline bool set(T& property, const T& value); + void addEntry(Entry* entry); void removeEntry(Entry* entry); void setParent(Database* db); @@ -114,6 +120,8 @@ private: QPointer m_parent; QPixmapCache::Key m_pixmapCacheKey; + bool m_updateTimeinfo; + friend void Database::setRootGroup(Group* group); friend Entry::~Entry(); friend void Entry::setGroup(Group *group); diff --git a/src/format/KeePass2XmlReader.cpp b/src/format/KeePass2XmlReader.cpp index 17a87bd22..d0135e8f4 100644 --- a/src/format/KeePass2XmlReader.cpp +++ b/src/format/KeePass2XmlReader.cpp @@ -64,6 +64,9 @@ void KeePass2XmlReader::readDatabase(QIODevice* device, Database* db, KeePass2Ra } m_meta->setUpdateDatetime(true); + Q_FOREACH (Group* group, m_groups) { + group->setUpdateTimeinfo(true); + } delete m_tmpParent; } @@ -785,6 +788,7 @@ Group* KeePass2XmlReader::getGroup(const Uuid& uuid) } Group* group = new Group(); + group->setUpdateTimeinfo(false); group->setUuid(uuid); group->setParent(m_tmpParent); m_groups << group;