diff --git a/src/core/Entry.cpp b/src/core/Entry.cpp index 3ab2839d8..ab6fd2a28 100644 --- a/src/core/Entry.cpp +++ b/src/core/Entry.cpp @@ -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) { diff --git a/src/core/Entry.h b/src/core/Entry.h index 2e42b50d4..6c739d78f 100644 --- a/src/core/Entry.h +++ b/src/core/Entry.h @@ -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) diff --git a/src/core/Group.cpp b/src/core/Group.cpp index e9f875cb5..0e652878c 100644 --- a/src/core/Group.cpp +++ b/src/core/Group.cpp @@ -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) { diff --git a/src/core/Group.h b/src/core/Group.h index a121922f5..f1d93825d 100644 --- a/src/core/Group.h +++ b/src/core/Group.h @@ -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) diff --git a/src/gui/group/GroupModel.cpp b/src/gui/group/GroupModel.cpp index 18b926dc2..436660f91 100644 --- a/src/gui/group/GroupModel.cpp +++ b/src/gui/group/GroupModel.cpp @@ -258,14 +258,16 @@ bool GroupModel::dropMimeData(const QMimeData* data, Group* group = dragGroup; if (sourceDb != targetDb) { - QSet 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);