mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-04-20 23:56:39 -04:00
Restore previous drag & drop logic
This commit is contained in:
parent
9b6c36b517
commit
ebb2d88bc0
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -708,10 +708,6 @@ QList<DatabaseWidget*> 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);
|
||||
|
@ -52,7 +52,6 @@ public:
|
||||
~MainWindow() override;
|
||||
|
||||
QList<DatabaseWidget*> getOpenDatabases();
|
||||
DatabaseWidget* currentDatabaseWidget();
|
||||
void restoreConfigState();
|
||||
void setAllowScreenCapture(bool state);
|
||||
|
||||
|
@ -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<QUuid> 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<DeletedObject> 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<DeletedObject> 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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user