@@ -62,6 +62,39 @@ namespace
62
62
}
63
63
}
64
64
65
+ void cloneIcon (Metadata* targetMetadata, const Database* sourceDb, const QUuid& iconUuid)
66
+ {
67
+ if (!iconUuid.isNull () && !targetMetadata->hasCustomIcon (iconUuid)) {
68
+ targetMetadata->addCustomIcon (iconUuid, sourceDb->metadata ()->customIcon (iconUuid));
69
+ }
70
+ }
71
+
72
+ void cloneEntries (Metadata* targetMetadata, const Group* sourceGroup, Group* targetGroup)
73
+ {
74
+ for (const Entry* sourceEntry : sourceGroup->entries ()) {
75
+ auto * targetEntry = sourceEntry->clone (Entry::CloneIncludeHistory);
76
+ const bool updateTimeinfoEntry = targetEntry->canUpdateTimeinfo ();
77
+ targetEntry->setUpdateTimeinfo (false );
78
+ targetEntry->setGroup (targetGroup);
79
+ targetEntry->setUpdateTimeinfo (updateTimeinfoEntry);
80
+ cloneIcon (targetMetadata, sourceEntry->database (), targetEntry->iconUuid ());
81
+ }
82
+ }
83
+
84
+ void cloneChildren (Metadata* targetMetadata, const Group* sourceRoot, Group* targetRoot)
85
+ {
86
+ for (const Group* sourceGroup : sourceRoot->children ()) {
87
+ auto * targetGroup = sourceGroup->clone (Entry::CloneNoFlags, Group::CloneNoFlags);
88
+ const bool updateTimeinfo = targetGroup->canUpdateTimeinfo ();
89
+ targetGroup->setUpdateTimeinfo (false );
90
+ targetGroup->setParent (targetRoot);
91
+ targetGroup->setUpdateTimeinfo (updateTimeinfo);
92
+ cloneIcon (targetMetadata, sourceRoot->database (), targetGroup->iconUuid ());
93
+ cloneEntries (targetMetadata, sourceGroup, targetGroup);
94
+ cloneChildren (targetMetadata, sourceGroup, targetGroup);
95
+ }
96
+ }
97
+
65
98
Database* extractIntoDatabase (const KeeShareSettings::Reference& reference, const Group* sourceRoot)
66
99
{
67
100
const auto * sourceDb = sourceRoot->database ();
@@ -75,18 +108,9 @@ namespace
75
108
targetRoot->setUpdateTimeinfo (false );
76
109
KeeShare::setReferenceTo (targetRoot, KeeShareSettings::Reference ());
77
110
targetRoot->setUpdateTimeinfo (updateTimeinfo);
78
- const auto sourceEntries = sourceRoot->entriesRecursive (false );
79
- for (const Entry* sourceEntry : sourceEntries) {
80
- auto * targetEntry = sourceEntry->clone (Entry::CloneIncludeHistory);
81
- const bool updateTimeinfoEntry = targetEntry->canUpdateTimeinfo ();
82
- targetEntry->setUpdateTimeinfo (false );
83
- targetEntry->setGroup (targetRoot);
84
- targetEntry->setUpdateTimeinfo (updateTimeinfoEntry);
85
- const auto iconUuid = targetEntry->iconUuid ();
86
- if (!iconUuid.isNull () && !targetMetadata->hasCustomIcon (iconUuid)) {
87
- targetMetadata->addCustomIcon (iconUuid, sourceEntry->database ()->metadata ()->customIcon (iconUuid));
88
- }
89
- }
111
+ cloneIcon (targetMetadata, sourceRoot->database (), targetRoot->iconUuid ());
112
+ cloneEntries (targetMetadata, sourceRoot, targetRoot);
113
+ cloneChildren (targetMetadata, sourceRoot, targetRoot);
90
114
91
115
auto key = QSharedPointer<CompositeKey>::create ();
92
116
key->addKey (QSharedPointer<PasswordKey>::create (reference.password ));
0 commit comments