From ebb2d88bc0dda231b3b51ff22928a56450ad45f1 Mon Sep 17 00:00:00 2001 From: vuurvlieg Date: Mon, 25 Mar 2024 13:09:15 +0100 Subject: [PATCH] Restore previous drag & drop logic --- src/core/Entry.h | 6 +-- src/core/Group.h | 5 +- src/gui/MainWindow.cpp | 4 -- src/gui/MainWindow.h | 1 - src/gui/group/GroupModel.cpp | 93 +++++++----------------------------- 5 files changed, 20 insertions(+), 89 deletions(-) diff --git a/src/core/Entry.h b/src/core/Entry.h index 9f5e462e9..2e42b50d4 100644 --- a/src/core/Entry.h +++ b/src/core/Entry.h @@ -177,13 +177,11 @@ public: 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 + 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 - - CloneCopy = CloneNewUuid | CloneResetTimeInfo | CloneIncludeHistory, - CloneExactCopy = CloneIncludeHistory, - CloneDefault = CloneNewUuid | CloneResetTimeInfo, }; Q_DECLARE_FLAGS(CloneFlags, CloneFlag) diff --git a/src/core/Group.h b/src/core/Group.h index 1552aabd3..a121922f5 100644 --- a/src/core/Group.h +++ b/src/core/Group.h @@ -49,11 +49,8 @@ public: 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 - - CloneCopy = CloneNewUuid | CloneResetTimeInfo | CloneIncludeEntries, - CloneExactCopy = CloneIncludeEntries, - CloneDefault = CloneCopy, }; Q_DECLARE_FLAGS(CloneFlags, CloneFlag) diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 72417b781..c97e04936 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -708,10 +708,6 @@ QList MainWindow::getOpenDatabases() return dbWidgets; } -DatabaseWidget* MainWindow::currentDatabaseWidget() { - return m_ui->tabWidget->currentDatabaseWidget(); -} - void MainWindow::showErrorMessage(const QString& message) { m_ui->globalMessageWidget->showMessage(message, MessageWidget::Error); diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index 5c727e5a6..c47c0d205 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -52,7 +52,6 @@ public: ~MainWindow() override; QList getOpenDatabases(); - DatabaseWidget* currentDatabaseWidget(); void restoreConfigState(); void setAllowScreenCapture(bool state); diff --git a/src/gui/group/GroupModel.cpp b/src/gui/group/GroupModel.cpp index 3e36e3254..18b926dc2 100644 --- a/src/gui/group/GroupModel.cpp +++ b/src/gui/group/GroupModel.cpp @@ -25,7 +25,6 @@ #include "core/Tools.h" #include "gui/DatabaseIcons.h" #include "gui/Icons.h" -#include "gui/MainWindow.h" #include "keeshare/KeeShare.h" GroupModel::GroupModel(Database* db, QObject* parent) @@ -230,13 +229,6 @@ bool GroupModel::dropMimeData(const QMimeData* data, Group* parentGroup = groupFromIndex(parent); - auto showErrorMessage = [](const QString& errorMessage){ - auto dbWidget = getMainWindow()->currentDatabaseWidget(); - if(dbWidget) { - dbWidget->showErrorMessage(errorMessage); - } - }; - if (isGroup) { QUuid dbUuid; QUuid groupUuid; @@ -266,49 +258,17 @@ bool GroupModel::dropMimeData(const QMimeData* data, Group* group = dragGroup; if (sourceDb != targetDb) { + QSet customIcons = group->customIconsRecursive(); + targetDb->metadata()->copyCustomIcons(customIcons, sourceDb->metadata()); + + // Always clone the group across db's to reset UUIDs + group = dragGroup->clone(Entry::CloneDefault | Entry::CloneIncludeHistory); if (action == Qt::MoveAction) { - Group* binGroup = sourceDb->metadata()->recycleBin(); - if(binGroup && binGroup->uuid() == dragGroup->uuid()) { - showErrorMessage(tr("Move Error: %1 group cannot be moved").arg(tr("Recycle bin"))); - return true; - } - - // the move is complex when any group or entry is known in the other db - bool complexMove = false; - for (const Group* g: group->groupsRecursive(true)) { - if (targetDb->containsDeletedObject(g->uuid()) || targetDb->rootGroup()->findGroupByUuid(g->uuid())) { - complexMove = true; - break; - } - } - for (const Entry* e: group->entriesRecursive(false)) { - if (targetDb->containsDeletedObject(e->uuid()) || targetDb->rootGroup()->findEntryByUuid(e->uuid())) { - complexMove = true; - break; - } - } - // TODO: unable to handle complex moves until the Merger interface supports single group/entry merging. - if (complexMove) { - showErrorMessage(tr("Move Error: (sub-)group(s) and/or entry(s) already present in this database")); - return true; - } - - group = dragGroup->clone(Entry::CloneExactCopy, Group::CloneExactCopy); - } - - targetDb->metadata()->copyCustomIcons(dragGroup->customIconsRecursive(), sourceDb->metadata()); - } - - if (action == Qt::MoveAction) { - // delete the original group when moving a clone - if (group != dragGroup) { - QList delObjects(sourceDb->deletedObjects()); + // Remove the original group from the sourceDb delete dragGroup; - // prevent group(s)/entry(s) from ending up on the deleted object list by restoring the previous list. - sourceDb->setDeletedObjects(delObjects); } - } else { // Action == Qt::CopyAction - group = dragGroup->clone(Entry::CloneCopy, Group::CloneCopy); + } else if (action == Qt::CopyAction) { + group = dragGroup->clone(Entry::CloneCopy); } group->setParent(parentGroup, row); @@ -317,13 +277,11 @@ bool GroupModel::dropMimeData(const QMimeData* data, return false; } - int numEntries = 0, numEntriesNotMoved = 0; while (!stream.atEnd()) { QUuid dbUuid; QUuid entryUuid; stream >> dbUuid >> entryUuid; - ++numEntries; - + Database* db = Database::databaseByUuid(dbUuid); if (!db) { continue; @@ -340,39 +298,22 @@ 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); + } + + // Reset the UUID when moving across db boundary + entry = dragEntry->clone(Entry::CloneDefault | Entry::CloneIncludeHistory); if (action == Qt::MoveAction) { - // the move is complex when the entry is known in the other db - bool complexMove = targetDb->containsDeletedObject(entry->uuid()) - || targetDb->rootGroup()->findEntryByUuid(entry->uuid()); - // TODO: unable to handle complex moves until the Merger interface supports single group/entry merging. - if (complexMove) { - ++numEntriesNotMoved; - continue; - } - entry = dragEntry->clone(Entry::CloneExactCopy); - } - - targetDb->metadata()->copyCustomIcon(entry->iconUuid(), sourceDb->metadata()); - } - - if (action == Qt::MoveAction) { - // delete the original entry when moving a clone - if (entry != dragEntry) { - QList delObjects(sourceDb->deletedObjects()); delete dragEntry; - // prevent entry from ending up on the deleted object list by restoring the previous list. - sourceDb->setDeletedObjects(delObjects); } - } else { // Action == Qt::CopyAction + } else if (action == Qt::CopyAction) { entry = dragEntry->clone(Entry::CloneCopy); } entry->setGroup(parentGroup); } - - if (numEntriesNotMoved) { - showErrorMessage(tr("Move Error: %1 of %2 entry(s) already present in this database").arg(numEntriesNotMoved).arg(numEntries)); - } } return true;