mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-01-12 15:59:58 -05:00
Fix additional cases of incorrectly handling of a Group's LastModificationTime
Cases: - Entry is added to a Group - Entry is removed from a Group - The Group list is sorted
This commit is contained in:
parent
ca4ae86eb6
commit
22a1a82e5b
@ -77,11 +77,11 @@ Group::~Group()
|
|||||||
cleanupParent();
|
cleanupParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class P, class V> inline bool Group::set(P& property, const V& value)
|
template <class P, class V> inline bool Group::set(P& property, const V& value, bool preserveTimeinfo)
|
||||||
{
|
{
|
||||||
if (property != value) {
|
if (property != value) {
|
||||||
property = value;
|
property = value;
|
||||||
emitModified();
|
emitModifiedEx(preserveTimeinfo);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@ -440,6 +440,15 @@ const Group* Group::parentGroup() const
|
|||||||
return m_parent;
|
return m_parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Group::emitModifiedEx(bool preserveTimeinfo) {
|
||||||
|
bool prevUpdateTimeinfo = m_updateTimeinfo;
|
||||||
|
if (preserveTimeinfo) {
|
||||||
|
m_updateTimeinfo = false; // prevent update of LastModificationTime
|
||||||
|
}
|
||||||
|
emitModified();
|
||||||
|
m_updateTimeinfo = prevUpdateTimeinfo;
|
||||||
|
}
|
||||||
|
|
||||||
void Group::setParent(Group* parent, int index, bool trackPrevious)
|
void Group::setParent(Group* parent, int index, bool trackPrevious)
|
||||||
{
|
{
|
||||||
Q_ASSERT(parent);
|
Q_ASSERT(parent);
|
||||||
@ -496,11 +505,7 @@ void Group::setParent(Group* parent, int index, bool trackPrevious)
|
|||||||
m_data.timeInfo.setLocationChanged(Clock::currentDateTimeUtc());
|
m_data.timeInfo.setLocationChanged(Clock::currentDateTimeUtc());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool prevUpdateTimeInfo = m_updateTimeinfo;
|
emitModifiedEx(true);
|
||||||
m_updateTimeinfo = false; // prevent update of LastModificationTime
|
|
||||||
emitModified();
|
|
||||||
m_updateTimeinfo = prevUpdateTimeInfo;
|
|
||||||
|
|
||||||
|
|
||||||
if (!moveWithinDatabase) {
|
if (!moveWithinDatabase) {
|
||||||
emit groupAdded();
|
emit groupAdded();
|
||||||
@ -990,7 +995,7 @@ void Group::addEntry(Entry* entry)
|
|||||||
connect(entry, &Entry::modified, m_db, &Database::markAsModified);
|
connect(entry, &Entry::modified, m_db, &Database::markAsModified);
|
||||||
}
|
}
|
||||||
|
|
||||||
emitModified();
|
emitModifiedEx(true);
|
||||||
emit entryAdded(entry);
|
emit entryAdded(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1007,7 +1012,7 @@ void Group::removeEntry(Entry* entry)
|
|||||||
entry->disconnect(m_db);
|
entry->disconnect(m_db);
|
||||||
}
|
}
|
||||||
m_entries.removeAll(entry);
|
m_entries.removeAll(entry);
|
||||||
emitModified();
|
emitModifiedEx(true);
|
||||||
emit entryRemoved(entry);
|
emit entryRemoved(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1078,12 +1083,7 @@ void Group::cleanupParent()
|
|||||||
if (m_parent) {
|
if (m_parent) {
|
||||||
emit groupAboutToRemove(this);
|
emit groupAboutToRemove(this);
|
||||||
m_parent->m_children.removeAll(this);
|
m_parent->m_children.removeAll(this);
|
||||||
|
emitModifiedEx(true);
|
||||||
bool prevUpdateTimeinfo = m_updateTimeinfo;
|
|
||||||
m_updateTimeinfo = false; // prevent update of LastModificationTime
|
|
||||||
emitModified();
|
|
||||||
m_updateTimeinfo = prevUpdateTimeinfo;
|
|
||||||
|
|
||||||
emit groupRemoved();
|
emit groupRemoved();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1234,7 +1234,7 @@ void Group::sortChildrenRecursively(bool reverse)
|
|||||||
child->sortChildrenRecursively(reverse);
|
child->sortChildrenRecursively(reverse);
|
||||||
}
|
}
|
||||||
|
|
||||||
emitModified();
|
emitModifiedEx(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Group* Group::previousParentGroup() const
|
const Group* Group::previousParentGroup() const
|
||||||
@ -1252,10 +1252,7 @@ QUuid Group::previousParentGroupUuid() const
|
|||||||
|
|
||||||
void Group::setPreviousParentGroupUuid(const QUuid& uuid)
|
void Group::setPreviousParentGroupUuid(const QUuid& uuid)
|
||||||
{
|
{
|
||||||
bool prevUpdateTimeinfo = m_updateTimeinfo;
|
set(m_data.previousParentGroupUuid, uuid, true);
|
||||||
m_updateTimeinfo = false; // prevent update of LastModificationTime
|
|
||||||
set(m_data.previousParentGroupUuid, uuid);
|
|
||||||
m_updateTimeinfo = prevUpdateTimeinfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Group::setPreviousParentGroup(const Group* group)
|
void Group::setPreviousParentGroup(const Group* group)
|
||||||
|
@ -210,8 +210,9 @@ private slots:
|
|||||||
void updateTimeinfo();
|
void updateTimeinfo();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template <class P, class V> bool set(P& property, const V& value);
|
template <class P, class V> bool set(P& property, const V& value, bool preserveTimeinfo = false);
|
||||||
|
|
||||||
|
void emitModifiedEx(bool preserveTimeinfo);
|
||||||
void setParent(Database* db);
|
void setParent(Database* db);
|
||||||
|
|
||||||
void connectDatabaseSignalsRecursive(Database* db);
|
void connectDatabaseSignalsRecursive(Database* db);
|
||||||
|
@ -1367,4 +1367,17 @@ void TestGroup::testTimeinfoChanges()
|
|||||||
QCOMPARE(subgroup2->timeInfo().lastModificationTime(), startTime);
|
QCOMPARE(subgroup2->timeInfo().lastModificationTime(), startTime);
|
||||||
QCOMPARE(subgroup2->timeInfo().locationChanged(), Clock::currentDateTimeUtc());
|
QCOMPARE(subgroup2->timeInfo().locationChanged(), Clock::currentDateTimeUtc());
|
||||||
QCOMPARE(db2.rootGroup()->timeInfo(), startTimeinfo);
|
QCOMPARE(db2.rootGroup()->timeInfo(), startTimeinfo);
|
||||||
|
|
||||||
|
QScopedPointer<Entry> entry1(new Entry());
|
||||||
|
entry1->setGroup(subgroup1);
|
||||||
|
// adding/removing an entry should not affect the LastModificationTime
|
||||||
|
QCOMPARE(subgroup1->timeInfo().lastModificationTime(), startTime);
|
||||||
|
entry1.reset(); // delete
|
||||||
|
QCOMPARE(subgroup1->timeInfo().lastModificationTime(), startTime);
|
||||||
|
|
||||||
|
// sorting should not affect the LastModificationTime
|
||||||
|
root->sortChildrenRecursively(true);
|
||||||
|
root->sortChildrenRecursively(false);
|
||||||
|
QCOMPARE(root->timeInfo().lastModificationTime(), startTime);
|
||||||
|
QCOMPARE(subgroup1->timeInfo().lastModificationTime(), startTime);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user