Add ability to delete groups via gui.
This commit is contained in:
committed by
Felix Geyer
parent
19bacd6737
commit
8467e7756d
@@ -197,16 +197,21 @@ bool Database::hasKey()
|
||||
return m_hasKey;
|
||||
}
|
||||
|
||||
void Database::createRecycleBin()
|
||||
{
|
||||
Group* recycleBin = new Group();
|
||||
recycleBin->setUuid(Uuid::random());
|
||||
recycleBin->setName(tr("Recycle Bin"));
|
||||
recycleBin->setIcon(43);
|
||||
recycleBin->setParent(rootGroup());
|
||||
m_metadata->setRecycleBin(recycleBin);
|
||||
}
|
||||
|
||||
void Database::recycleEntry(Entry* entry)
|
||||
{
|
||||
if (m_metadata->recycleBinEnabled()) {
|
||||
if (!m_metadata->recycleBin()) {
|
||||
Group* recycleBin = new Group();
|
||||
recycleBin->setUuid(Uuid::random());
|
||||
recycleBin->setName(tr("Recycle Bin"));
|
||||
recycleBin->setIcon(43);
|
||||
recycleBin->setParent(rootGroup());
|
||||
m_metadata->setRecycleBin(recycleBin);
|
||||
createRecycleBin();
|
||||
}
|
||||
entry->setGroup(metadata()->recycleBin());
|
||||
}
|
||||
@@ -214,3 +219,16 @@ void Database::recycleEntry(Entry* entry)
|
||||
delete entry;
|
||||
}
|
||||
}
|
||||
|
||||
void Database::recycleGroup(Group* group)
|
||||
{
|
||||
if (m_metadata->recycleBinEnabled()) {
|
||||
if (!m_metadata->recycleBin()) {
|
||||
createRecycleBin();
|
||||
}
|
||||
group->setParent(metadata()->recycleBin());
|
||||
}
|
||||
else {
|
||||
delete group;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,6 +86,7 @@ public:
|
||||
void updateKey(quint64 rounds);
|
||||
bool hasKey();
|
||||
void recycleEntry(Entry* entry);
|
||||
void recycleGroup(Group* group);
|
||||
|
||||
Q_SIGNALS:
|
||||
void groupDataChanged(Group* group);
|
||||
@@ -99,6 +100,8 @@ private:
|
||||
Entry* recFindEntry(const Uuid& uuid, Group* group);
|
||||
Group* recFindGroup(const Uuid& uuid, Group* group);
|
||||
|
||||
void createRecycleBin();
|
||||
|
||||
Metadata* m_metadata;
|
||||
Group* m_rootGroup;
|
||||
QList<DeletedObject> m_deletedObjects;
|
||||
|
||||
@@ -44,6 +44,11 @@ Entry::~Entry()
|
||||
{
|
||||
if (m_group) {
|
||||
m_group->removeEntry(this);
|
||||
|
||||
DeletedObject delEntry;
|
||||
delEntry.deletionTime = QDateTime::currentDateTimeUtc();
|
||||
delEntry.uuid = m_uuid;
|
||||
m_group->addDeletedObject(delEntry);
|
||||
}
|
||||
|
||||
qDeleteAll(m_history);
|
||||
@@ -356,7 +361,14 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
group->addEntry(this);
|
||||
m_group = group;
|
||||
QObject::setParent(group);
|
||||
|
||||
@@ -35,11 +35,30 @@ Group::Group()
|
||||
m_searchingEnabled = Inherit;
|
||||
|
||||
m_updateTimeinfo = true;
|
||||
m_emitSignals = true;
|
||||
}
|
||||
|
||||
Group::~Group()
|
||||
{
|
||||
cleanupParent();
|
||||
m_emitSignals = false;
|
||||
if (m_db && m_parent) {
|
||||
|
||||
QList<Entry*> entries = m_entries;
|
||||
Q_FOREACH (Entry* entry, entries) {
|
||||
delete entry;
|
||||
}
|
||||
|
||||
QList<Group*> children = m_children;
|
||||
Q_FOREACH (Group* group, children) {
|
||||
delete group;
|
||||
}
|
||||
|
||||
DeletedObject delGroup;
|
||||
delGroup.deletionTime = QDateTime::currentDateTimeUtc();
|
||||
delGroup.uuid = m_uuid;
|
||||
m_db->addDeletedObject(delGroup);
|
||||
}
|
||||
}
|
||||
|
||||
template <class P, class V> bool Group::set(P& property, const V& value) {
|
||||
@@ -66,6 +85,11 @@ void Group::setUpdateTimeinfo(bool value) {
|
||||
m_updateTimeinfo = value;
|
||||
}
|
||||
|
||||
bool Group::emitSignals()
|
||||
{
|
||||
return m_emitSignals;
|
||||
}
|
||||
|
||||
Uuid Group::uuid() const
|
||||
{
|
||||
return m_uuid;
|
||||
@@ -255,6 +279,7 @@ void Group::setParent(Group* parent, int index)
|
||||
m_parent = parent;
|
||||
|
||||
if (m_db != parent->m_db) {
|
||||
recCreateDelObjects();
|
||||
recSetDatabase(parent->m_db);
|
||||
}
|
||||
|
||||
@@ -342,19 +367,19 @@ void Group::addEntry(Entry *entry)
|
||||
|
||||
void Group::removeEntry(Entry* entry)
|
||||
{
|
||||
Q_EMIT entryAboutToRemove(entry);
|
||||
if (m_emitSignals) {
|
||||
Q_EMIT entryAboutToRemove(entry);
|
||||
}
|
||||
|
||||
entry->disconnect(this);
|
||||
if (m_db) {
|
||||
entry->disconnect(m_db);
|
||||
DeletedObject delObject;
|
||||
delObject.deletionTime = QDateTime::currentDateTimeUtc();
|
||||
delObject.uuid = entry->uuid();
|
||||
m_db->addDeletedObject(delObject);
|
||||
}
|
||||
m_entries.removeAll(entry);
|
||||
Q_EMIT modified();
|
||||
Q_EMIT entryRemoved();
|
||||
if (m_emitSignals) {
|
||||
Q_EMIT modified();
|
||||
Q_EMIT entryRemoved();
|
||||
}
|
||||
}
|
||||
|
||||
void Group::recSetDatabase(Database* db)
|
||||
@@ -392,9 +417,41 @@ void Group::recSetDatabase(Database* db)
|
||||
void Group::cleanupParent()
|
||||
{
|
||||
if (m_parent) {
|
||||
Q_EMIT aboutToRemove(this);
|
||||
if (m_parent->emitSignals()) {
|
||||
Q_EMIT aboutToRemove(this);
|
||||
}
|
||||
m_parent->m_children.removeAll(this);
|
||||
Q_EMIT modified();
|
||||
Q_EMIT removed();
|
||||
if (m_parent->emitSignals()) {
|
||||
Q_EMIT modified();
|
||||
Q_EMIT removed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Group::recCreateDelObjects()
|
||||
{
|
||||
if (m_db) {
|
||||
DeletedObject delGroup;
|
||||
delGroup.deletionTime = QDateTime::currentDateTimeUtc();
|
||||
delGroup.uuid = m_uuid;
|
||||
m_db->addDeletedObject(delGroup);
|
||||
|
||||
Q_FOREACH (Entry* entry, m_entries) {
|
||||
DeletedObject delEntry;
|
||||
delEntry.deletionTime = QDateTime::currentDateTimeUtc();
|
||||
delEntry.uuid = entry->uuid();
|
||||
m_db->addDeletedObject(delEntry);
|
||||
}
|
||||
|
||||
Q_FOREACH (Group* group, m_children) {
|
||||
group->recCreateDelObjects();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Group::addDeletedObject(const DeletedObject& delObj)
|
||||
{
|
||||
if (m_db) {
|
||||
m_db->addDeletedObject(delObj);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +75,9 @@ public:
|
||||
QList<Entry*> entries();
|
||||
const QList<Entry*>& entries() const;
|
||||
QList<Entry*> entriesRecursive(bool includeHistoryItems = false);
|
||||
bool emitSignals();
|
||||
void addDeletedObject(const DeletedObject& delObj);
|
||||
|
||||
|
||||
Q_SIGNALS:
|
||||
void dataChanged(Group* group);
|
||||
@@ -102,6 +105,7 @@ private:
|
||||
|
||||
void recSetDatabase(Database* db);
|
||||
void cleanupParent();
|
||||
void recCreateDelObjects();
|
||||
|
||||
QPointer<Database> m_db;
|
||||
Uuid m_uuid;
|
||||
@@ -122,6 +126,7 @@ private:
|
||||
QPixmapCache::Key m_pixmapCacheKey;
|
||||
|
||||
bool m_updateTimeinfo;
|
||||
bool m_emitSignals;
|
||||
|
||||
friend void Database::setRootGroup(Group* group);
|
||||
friend Entry::~Entry();
|
||||
|
||||
Reference in New Issue
Block a user