From 5a96e19ce972ddbd548bfde276eaaaf0e5c17211 Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Sun, 7 Apr 2013 18:32:43 +0200 Subject: [PATCH] Copy custom icons when copying/moving entries/groups to another database. --- src/core/Group.cpp | 21 +++++++++++++++++++++ src/core/Group.h | 1 + src/core/Metadata.cpp | 11 +++++++++++ src/core/Metadata.h | 1 + src/gui/group/GroupModel.cpp | 19 +++++++++++++++++++ 5 files changed, 53 insertions(+) diff --git a/src/core/Group.cpp b/src/core/Group.cpp index b53fa4d00..989c9e1cc 100644 --- a/src/core/Group.cpp +++ b/src/core/Group.cpp @@ -436,6 +436,27 @@ QList Group::groupsRecursive(bool includeSelf) const return groupList; } +QSet Group::customIconsRecursive() const +{ + QSet result; + + if (!iconUuid().isNull()) { + result.insert(iconUuid()); + } + + Q_FOREACH (Entry* entry, entriesRecursive(true)) { + if (!entry->iconUuid().isNull()) { + result.insert(entry->iconUuid()); + } + } + + Q_FOREACH (Group* group, m_children) { + result.unite(group->customIconsRecursive()); + } + + return result; +} + Group* Group::clone() const { // TODO: what to do about custom icons? diff --git a/src/core/Group.h b/src/core/Group.h index eb46f8507..c7e4f4000 100644 --- a/src/core/Group.h +++ b/src/core/Group.h @@ -99,6 +99,7 @@ public: const QList& entries() const; QList entriesRecursive(bool includeHistoryItems = false) const; QList groupsRecursive(bool includeSelf) const; + QSet customIconsRecursive() const; Group* clone() const; QList search(const QString& searchTerm, Qt::CaseSensitivity caseSensitivity, diff --git a/src/core/Metadata.cpp b/src/core/Metadata.cpp index 9e150bd9f..105ad14d2 100644 --- a/src/core/Metadata.cpp +++ b/src/core/Metadata.cpp @@ -348,6 +348,17 @@ void Metadata::removeCustomIcon(const Uuid& uuid) Q_EMIT modified(); } +void Metadata::copyCustomIcons(const QSet& iconList, const Metadata* otherMetadata) +{ + Q_FOREACH (const Uuid& uuid, iconList) { + Q_ASSERT(otherMetadata->containsCustomIcon(uuid)); + + if (!containsCustomIcon(uuid)) { + addCustomIcon(uuid, otherMetadata->customIcon(uuid)); + } + } +} + void Metadata::setRecycleBinEnabled(bool value) { set(m_recycleBinEnabled, value); diff --git a/src/core/Metadata.h b/src/core/Metadata.h index 520143430..8e9e8a7db 100644 --- a/src/core/Metadata.h +++ b/src/core/Metadata.h @@ -91,6 +91,7 @@ public: // void setAutoEnableVisualHiding(bool value); void addCustomIcon(const Uuid& uuid, const QImage& icon); void removeCustomIcon(const Uuid& uuid); + void copyCustomIcons(const QSet& iconList, const Metadata* otherMetadata); void setRecycleBinEnabled(bool value); void setRecycleBin(Group* group); void setRecycleBinChanged(const QDateTime& value); diff --git a/src/gui/group/GroupModel.cpp b/src/gui/group/GroupModel.cpp index fb7608031..db63079ce 100644 --- a/src/gui/group/GroupModel.cpp +++ b/src/gui/group/GroupModel.cpp @@ -23,6 +23,7 @@ #include "core/Database.h" #include "core/DatabaseIcons.h" #include "core/Group.h" +#include "core/Metadata.h" #include "core/Tools.h" GroupModel::GroupModel(Database* db, QObject* parent) @@ -262,6 +263,14 @@ bool GroupModel::dropMimeData(const QMimeData* data, Qt::DropAction action, group = dragGroup->clone(); } + Database* sourceDb = dragGroup->database(); + Database* targetDb = parentGroup->database(); + + if (sourceDb != targetDb) { + QSet customIcons = group->customIconsRecursive(); + targetDb->metadata()->copyCustomIcons(customIcons, sourceDb->metadata()); + } + group->setParent(parentGroup, row); } else { @@ -292,6 +301,16 @@ bool GroupModel::dropMimeData(const QMimeData* data, Qt::DropAction action, entry = dragEntry->clone(); } + Database* sourceDb = dragEntry->group()->database(); + Database* targetDb = parentGroup->database(); + Uuid customIcon = entry->iconUuid(); + + if (sourceDb != targetDb && !customIcon.isNull() + && !targetDb->metadata()->containsCustomIcon(customIcon)) { + targetDb->metadata()->addCustomIcon(customIcon, + sourceDb->metadata()->customIcon(customIcon)); + } + entry->setGroup(parentGroup); } }