diff --git a/src/core/Entry.cpp b/src/core/Entry.cpp index bd19e2a49..7848300a8 100644 --- a/src/core/Entry.cpp +++ b/src/core/Entry.cpp @@ -452,6 +452,16 @@ Entry* Entry::clone() const return entry; } +void Entry::copyDataFrom(const Entry* other) +{ + setUpdateTimeinfo(false); + m_data = other->m_data; + m_attributes->copyDataFrom(other->m_attributes); + m_attachments->copyDataFrom(other->m_attachments); + m_autoTypeAssociations->copyDataFrom(other->m_autoTypeAssociations); + setUpdateTimeinfo(true); +} + void Entry::beginUpdate() { Q_ASSERT(!m_tmpHistoryItem); diff --git a/src/core/Entry.h b/src/core/Entry.h index 909a036ef..d86775210 100644 --- a/src/core/Entry.h +++ b/src/core/Entry.h @@ -111,6 +111,7 @@ public: void removeHistoryItems(const QList& historyEntries); void truncateHistory(); Entry* clone() const; + void copyDataFrom(const Entry* other); QString resolvePlaceholders(const QString& str) const; /** diff --git a/tests/TestEntry.cpp b/tests/TestEntry.cpp index c7e143fdf..fdba1c81c 100644 --- a/tests/TestEntry.cpp +++ b/tests/TestEntry.cpp @@ -38,5 +38,40 @@ void TestEntry::testHistoryItemDeletion() delete entry; } +void TestEntry::testCopyDataFrom() +{ + Entry* entry = new Entry(); + + entry->setTitle("testtitle"); + entry->attributes()->set("attr1", "abc"); + entry->attributes()->set("attr2", "def"); + + entry->attachments()->set("test", "123"); + entry->attachments()->set("test2", "456"); + + AutoTypeAssociations::Association assoc; + assoc.window = "1"; + assoc.sequence = "2"; + entry->autoTypeAssociations()->add(assoc); + assoc.window = "3"; + assoc.sequence = "4"; + entry->autoTypeAssociations()->add(assoc); + + Entry* entry2 = new Entry(); + entry2->copyDataFrom(entry); + delete entry; + + QCOMPARE(entry2->title(), QString("testtitle")); + QCOMPARE(entry2->attributes()->value("attr1"), QString("abc")); + QCOMPARE(entry2->attributes()->value("attr2"), QString("def")); + + QCOMPARE(entry2->attachments()->keys().size(), 2); + QCOMPARE(entry2->attachments()->value("test"), QByteArray("123")); + QCOMPARE(entry2->attachments()->value("test2"), QByteArray("456")); + + QCOMPARE(entry2->autoTypeAssociations()->size(), 2); + QCOMPARE(entry2->autoTypeAssociations()->get(0).window, QString("1")); + QCOMPARE(entry2->autoTypeAssociations()->get(1).window, QString("3")); +} QTEST_GUILESS_MAIN(TestEntry) diff --git a/tests/TestEntry.h b/tests/TestEntry.h index e1f645092..d873f636c 100644 --- a/tests/TestEntry.h +++ b/tests/TestEntry.h @@ -28,6 +28,7 @@ class TestEntry : public QObject private Q_SLOTS: void testHistoryItemDeletion(); + void testCopyDataFrom(); }; #endif // KEEPASSX_TESTENTRY_H