From eeafe7761479068fda7aec772f0dc36a8d5b1422 Mon Sep 17 00:00:00 2001 From: Louis-Bertrand Varin Date: Sun, 21 May 2017 13:51:16 -0400 Subject: [PATCH] Find entry by title. --- src/core/Group.cpp | 13 ++++++++++++- tests/TestGroup.cpp | 8 ++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/core/Group.cpp b/src/core/Group.cpp index 38acc2d60..0c83fa303 100644 --- a/src/core/Group.cpp +++ b/src/core/Group.cpp @@ -497,7 +497,18 @@ Entry* Group::findEntry(QString entryId) } } - return findEntryByPath(entryId); + Entry* entry = findEntryByPath(entryId); + if (entry) { + return entry; + } + + for (Entry* entry : entriesRecursive(false)) { + if (entry->title() == entryId) { + return entry; + } + } + + return nullptr; } Entry* Group::findEntryByUuid(const Uuid& uuid) diff --git a/tests/TestGroup.cpp b/tests/TestGroup.cpp index 4fb5e4b3b..a706badad 100644 --- a/tests/TestGroup.cpp +++ b/tests/TestGroup.cpp @@ -606,9 +606,17 @@ void TestGroup::testFindEntry() QVERIFY(entry != nullptr); QCOMPARE(entry->title(), QString("entry2")); + // Should also find the entry only by title. + entry = db->rootGroup()->findEntry(QString("entry2")); + QVERIFY(entry != nullptr); + QCOMPARE(entry->title(), QString("entry2")); + entry = db->rootGroup()->findEntry(QString("invalid/path/to/entry2")); QVERIFY(entry == nullptr); + entry = db->rootGroup()->findEntry(QString("entry27")); + QVERIFY(entry == nullptr); + // A valid UUID that does not exist in this database. entry = db->rootGroup()->findEntry(QString("febfb01ebcdf9dbd90a3f1579dc75281")); QVERIFY(entry == nullptr);