Fix moving a group/entry across dbs resets the CreationTime

This commit is contained in:
vuurvlieg 2024-03-28 12:26:33 +01:00
parent 9a7db370bf
commit ca4ae86eb6
5 changed files with 52 additions and 29 deletions

View File

@ -946,10 +946,15 @@ Entry* Entry::clone(CloneFlags flags) const
if (flags & CloneResetTimeInfo) {
QDateTime now = Clock::currentDateTimeUtc();
entry->m_data.timeInfo.setCreationTime(now);
entry->m_data.timeInfo.setLastAccessTime(now);
entry->m_data.timeInfo.setLocationChanged(now);
// preserve LastModificationTime
if (flags & CloneResetCreationTime) {
entry->m_data.timeInfo.setCreationTime(now);
}
if (flags & CloneResetLastAccessTime) {
entry->m_data.timeInfo.setLastAccessTime(now);
}
if (flags & CloneResetLocationChangedTime) {
entry->m_data.timeInfo.setLocationChanged(now);
}
}
if (flags & CloneRenameTitle) {

View File

@ -175,13 +175,18 @@ public:
{
CloneNoFlags = 0,
CloneNewUuid = 1, // generate a random uuid for the clone
CloneResetTimeInfo = 2, // set all TimeInfo attributes except LastModificationTime to the current time
CloneIncludeHistory = 4, // clone the history items
CloneResetCreationTime = 2, // set timeInfo.CreationTime to the current time
CloneResetLastAccessTime = 4, // set timeInfo.LastAccessTime to the current time
CloneResetLocationChangedTime = 8, // set timeInfo.LocationChangedTime to the current time
CloneIncludeHistory = 16, // clone the history items
CloneRenameTitle = 32, // add "-Clone" after the original title
CloneUserAsRef = 64, // Add the user as a reference to the original entry
ClonePassAsRef = 128, // Add the password as a reference to the original entry
CloneResetTimeInfo = CloneResetCreationTime | CloneResetLastAccessTime | CloneResetLocationChangedTime,
CloneExactCopy = CloneIncludeHistory,
CloneCopy = CloneExactCopy | CloneNewUuid | CloneResetTimeInfo,
CloneDefault = CloneNewUuid | CloneResetTimeInfo,
CloneCopy = CloneNewUuid | CloneResetTimeInfo | CloneIncludeHistory,
CloneRenameTitle = 8, // add "-Clone" after the original title
CloneUserAsRef = 16, // Add the user as a reference to the original entry
ClonePassAsRef = 32, // Add the password as a reference to the original entry
};
Q_DECLARE_FLAGS(CloneFlags, CloneFlag)

View File

@ -949,12 +949,16 @@ Group* Group::clone(Entry::CloneFlags entryFlags, Group::CloneFlags groupFlags)
clonedGroup->setUpdateTimeinfo(true);
if (groupFlags & Group::CloneResetTimeInfo) {
QDateTime now = Clock::currentDateTimeUtc();
clonedGroup->m_data.timeInfo.setCreationTime(now);
clonedGroup->m_data.timeInfo.setLastAccessTime(now);
clonedGroup->m_data.timeInfo.setLocationChanged(now);
// preserve LastModificationTime
if (groupFlags & Group::CloneResetCreationTime) {
clonedGroup->m_data.timeInfo.setCreationTime(now);
}
if (groupFlags & Group::CloneResetLastAccessTime) {
clonedGroup->m_data.timeInfo.setLastAccessTime(now);
}
if (groupFlags & Group::CloneResetLocationChangedTime) {
clonedGroup->m_data.timeInfo.setLocationChanged(now);
}
}
if (groupFlags & Group::CloneRenameTitle) {

View File

@ -47,10 +47,16 @@ public:
{
CloneNoFlags = 0,
CloneNewUuid = 1, // generate a random uuid for the clone
CloneResetTimeInfo = 2, // set all TimeInfo attributes except LastModificationTime to the current time
CloneIncludeEntries = 4, // clone the group entries
CloneDefault = CloneNewUuid | CloneResetTimeInfo | CloneIncludeEntries,
CloneRenameTitle = 8, // add "- Clone" after the original title
CloneResetCreationTime = 2, // set timeInfo.CreationTime to the current time
CloneResetLastAccessTime = 4, // set timeInfo.LastAccessTime to the current time
CloneResetLocationChangedTime = 8, // set timeInfo.LocationChangedTime to the current time
CloneIncludeEntries = 16, // clone the group entries
CloneRenameTitle = 32, // add "- Clone" after the original title
CloneResetTimeInfo = CloneResetCreationTime | CloneResetLastAccessTime | CloneResetLocationChangedTime,
CloneExactCopy = CloneIncludeEntries,
CloneCopy = CloneExactCopy | CloneNewUuid | CloneResetTimeInfo,
CloneDefault = CloneCopy,
};
Q_DECLARE_FLAGS(CloneFlags, CloneFlag)

View File

@ -258,14 +258,16 @@ bool GroupModel::dropMimeData(const QMimeData* data,
Group* group = dragGroup;
if (sourceDb != targetDb) {
QSet<QUuid> customIcons = group->customIconsRecursive();
targetDb->metadata()->copyCustomIcons(customIcons, sourceDb->metadata());
targetDb->metadata()->copyCustomIcons(group->customIconsRecursive(), sourceDb->metadata());
// Always clone the group across db's to reset UUIDs
group = dragGroup->clone(Entry::CloneDefault | Entry::CloneIncludeHistory);
if (action == Qt::MoveAction) {
// Remove the original group from the sourceDb
// For cross-db moves use a clone with new UUID but original CreationTime
group = dragGroup->clone(Entry::CloneFlags(Entry::CloneCopy & ~Entry::CloneResetCreationTime),
Group::CloneFlags(Group::CloneCopy & ~Group::CloneResetCreationTime));
// Remove the original from the sourceDb to allow this change to sync to other dbs
delete dragGroup;
} else {
group = dragGroup->clone(Entry::CloneCopy);
}
} else if (action == Qt::CopyAction) {
group = dragGroup->clone(Entry::CloneCopy);
@ -298,15 +300,16 @@ bool GroupModel::dropMimeData(const QMimeData* data,
Entry* entry = dragEntry;
if (sourceDb != targetDb) {
QUuid customIcon = entry->iconUuid();
if (!customIcon.isNull() && !targetDb->metadata()->hasCustomIcon(customIcon)) {
targetDb->metadata()->addCustomIcon(customIcon, sourceDb->metadata()->customIcon(customIcon).data);
}
targetDb->metadata()->copyCustomIcon(entry->iconUuid(), sourceDb->metadata());
// Reset the UUID when moving across db boundary
entry = dragEntry->clone(Entry::CloneDefault | Entry::CloneIncludeHistory);
if (action == Qt::MoveAction) {
// For cross-db moves use a clone with new UUID but original CreationTime
entry = dragEntry->clone(Entry::CloneFlags(Entry::CloneCopy & ~Entry::CloneResetCreationTime));
// Remove the original from the sourceDb to allow this change to sync to other dbs
delete dragEntry;
} else {
entry = dragEntry->clone(Entry::CloneCopy);
}
} else if (action == Qt::CopyAction) {
entry = dragEntry->clone(Entry::CloneCopy);