From 411617cc8ba09f30339801c10dda6937b601242a Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Sun, 22 Apr 2012 00:29:39 +0200 Subject: [PATCH] Add convenience function Database::addDeletedObject(const Uuid&). Drop Group::addDeletedObject() and make Entry call the Database function instead. --- src/core/Database.cpp | 9 +++++++++ src/core/Database.h | 1 + src/core/Entry.cpp | 12 ++++-------- src/core/Group.cpp | 22 +++++++--------------- src/core/Group.h | 2 +- 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/core/Database.cpp b/src/core/Database.cpp index f567b4047..91dd0ade6 100644 --- a/src/core/Database.cpp +++ b/src/core/Database.cpp @@ -121,6 +121,15 @@ void Database::addDeletedObject(const DeletedObject& delObj) m_deletedObjects.append(delObj); } +void Database::addDeletedObject(const Uuid& uuid) +{ + DeletedObject delObj; + delObj.deletionTime = QDateTime::currentDateTimeUtc(); + delObj.uuid = uuid; + + addDeletedObject(delObj); +} + Uuid Database::cipher() const { return m_cipher; diff --git a/src/core/Database.h b/src/core/Database.h index 6475626a0..ecbbc9c88 100644 --- a/src/core/Database.h +++ b/src/core/Database.h @@ -67,6 +67,7 @@ public: Group* resolveGroup(const Uuid& uuid); QList deletedObjects(); void addDeletedObject(const DeletedObject& delObj); + void addDeletedObject(const Uuid& uuid); Uuid cipher() const; Database::CompressionAlgorithm compressionAlgo() const; diff --git a/src/core/Entry.cpp b/src/core/Entry.cpp index b86910ced..1e63d4fb0 100644 --- a/src/core/Entry.cpp +++ b/src/core/Entry.cpp @@ -45,10 +45,9 @@ Entry::~Entry() if (m_group) { m_group->removeEntry(this); - DeletedObject delEntry; - delEntry.deletionTime = QDateTime::currentDateTimeUtc(); - delEntry.uuid = m_uuid; - m_group->addDeletedObject(delEntry); + if (m_group->database()) { + m_group->database()->addDeletedObject(m_uuid); + } } qDeleteAll(m_history); @@ -362,10 +361,7 @@ void Entry::setGroup(Group* group) if (m_group) { m_group->removeEntry(this); if (m_group->database() != group->database()) { - DeletedObject delEntry; - delEntry.deletionTime = QDateTime::currentDateTimeUtc(); - delEntry.uuid = m_uuid; - m_group->addDeletedObject(delEntry); + m_group->database()->addDeletedObject(m_uuid); } } diff --git a/src/core/Group.cpp b/src/core/Group.cpp index 267670dd4..4c330e4cb 100644 --- a/src/core/Group.cpp +++ b/src/core/Group.cpp @@ -300,6 +300,11 @@ void Group::setParent(Database* db) QObject::setParent(db); } +Database* Group::database() +{ + return m_db; +} + const Database* Group::database() const { return m_db; @@ -418,16 +423,10 @@ void Group::cleanupParent() void Group::recCreateDelObjects() { if (m_db) { - DeletedObject delGroup; - delGroup.deletionTime = QDateTime::currentDateTimeUtc(); - delGroup.uuid = m_uuid; - m_db->addDeletedObject(delGroup); + m_db->addDeletedObject(m_uuid); Q_FOREACH (Entry* entry, m_entries) { - DeletedObject delEntry; - delEntry.deletionTime = QDateTime::currentDateTimeUtc(); - delEntry.uuid = entry->uuid(); - m_db->addDeletedObject(delEntry); + m_db->addDeletedObject(entry->uuid()); } Q_FOREACH (Group* group, m_children) { @@ -435,10 +434,3 @@ void Group::recCreateDelObjects() } } } - -void Group::addDeletedObject(const DeletedObject& delObj) -{ - if (m_db) { - m_db->addDeletedObject(delObj); - } -} diff --git a/src/core/Group.h b/src/core/Group.h index b3f2b6887..77290bc96 100644 --- a/src/core/Group.h +++ b/src/core/Group.h @@ -69,13 +69,13 @@ public: const Group* parentGroup() const; void setParent(Group* parent, int index = -1); + Database* database(); const Database* database() const; QList children(); const QList& children() const; QList entries(); const QList& entries() const; QList entriesRecursive(bool includeHistoryItems = false); - void addDeletedObject(const DeletedObject& delObj); Q_SIGNALS: