Implement KDBX 4.1 PreviousParentGroup flag

This commit is contained in:
Janek Bevendorff 2021-11-09 23:52:54 +01:00
parent ffaeac130f
commit cd9ef58e98
10 changed files with 200 additions and 18 deletions

View file

@ -1169,7 +1169,7 @@ const Group* Entry::group() const
return m_group;
}
void Entry::setGroup(Group* group)
void Entry::setGroup(Group* group, bool trackPrevious)
{
Q_ASSERT(group);
@ -1180,6 +1180,7 @@ void Entry::setGroup(Group* group)
if (m_group) {
m_group->removeEntry(this);
if (m_group->database() && m_group->database() != group->database()) {
setPreviousParentGroup(nullptr);
m_group->database()->addDeletedObject(m_uuid);
// copy custom icon to the new database
@ -1188,6 +1189,8 @@ void Entry::setGroup(Group* group)
group->database()->metadata()->addCustomIcon(iconUuid(),
m_group->database()->metadata()->customIcon(iconUuid()));
}
} else if (trackPrevious && m_group->database() && group != m_group) {
setPreviousParentGroup(m_group);
}
}
@ -1375,7 +1378,30 @@ QString Entry::resolveUrl(const QString& url) const
}
// No valid http URL's found
return QString("");
return {};
}
const Group* Entry::previousParentGroup() const
{
if (!database() || !database()->rootGroup()) {
return nullptr;
}
return database()->rootGroup()->findGroupByUuid(m_data.previousParentGroupUuid);
}
QUuid Entry::previousParentGroupUuid() const
{
return m_data.previousParentGroupUuid;
}
void Entry::setPreviousParentGroupUuid(const QUuid& uuid)
{
set(m_data.previousParentGroupUuid, uuid);
}
void Entry::setPreviousParentGroup(const Group* group)
{
setPreviousParentGroupUuid(group ? group->uuid() : QUuid());
}
bool EntryData::operator==(const EntryData& other) const
@ -1438,6 +1464,9 @@ bool EntryData::equals(const EntryData& other, CompareItemOptions options) const
if (::compare(excludeFromReports, other.excludeFromReports, options) != 0) {
return false;
}
if (::compare(previousParentGroupUuid, other.previousParentGroupUuid, options) != 0) {
return false;
}
return true;
}