From 75c16d1cbba7226fea7ada2a85a5b320bcdb06f9 Mon Sep 17 00:00:00 2001 From: Vladimir Svyatski Date: Fri, 21 Apr 2017 17:33:06 +0300 Subject: [PATCH] Add requested source code changes --- src/core/Database.cpp | 16 ++++++++++++++++ src/core/Database.h | 1 + src/gui/DatabaseWidget.cpp | 31 +++++++++---------------------- src/gui/DatabaseWidget.h | 2 +- src/gui/MainWindow.cpp | 10 +++++----- src/gui/MainWindow.ui | 4 ++-- 6 files changed, 34 insertions(+), 30 deletions(-) diff --git a/src/core/Database.cpp b/src/core/Database.cpp index 4aa9e3f5b..5b5a707f9 100644 --- a/src/core/Database.cpp +++ b/src/core/Database.cpp @@ -308,6 +308,22 @@ void Database::recycleGroup(Group* group) } } +void Database::emptyRecycleBin() +{ + if (m_metadata->recycleBinEnabled() && m_metadata->recycleBin()) { + // destroying direct entries of the recycle bin + QList subEntries = m_metadata->recycleBin()->entries(); + for (Entry* entry : subEntries) { + delete entry; + } + // destroying direct subgroups of the recycle bin + QList subGroups = m_metadata->recycleBin()->children(); + for (Group* group : subGroups) { + delete group; + } + } +} + void Database::merge(const Database* other) { m_rootGroup->merge(other->rootGroup()); diff --git a/src/core/Database.h b/src/core/Database.h index 16c149608..7728d14c8 100644 --- a/src/core/Database.h +++ b/src/core/Database.h @@ -108,6 +108,7 @@ public: bool verifyKey(const CompositeKey& key) const; void recycleEntry(Entry* entry); void recycleGroup(Group* group); + void emptyRecycleBin(); void setEmitModified(bool value); void copyAttributesFrom(const Database* other); void merge(const Database* other); diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index 342f37f09..115c560f0 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -1273,32 +1273,19 @@ bool DatabaseWidget::isRecycleBinSelected() const return m_groupView->currentGroup() && m_groupView->currentGroup() == m_db->metadata()->recycleBin(); } -void DatabaseWidget::emptyTrash() +void DatabaseWidget::emptyRecycleBin() { - Group* currentGroup = m_groupView->currentGroup(); - if (!currentGroup) { - Q_ASSERT(false); + if(!isRecycleBinSelected()) { return; } - if (currentGroup == m_db->metadata()->recycleBin()) { - QMessageBox::StandardButton result = MessageBox::question( - this, tr("Empty recycle bin?"), - tr("Are you sure you want to permanently delete everytning from your recycle bin?"), - QMessageBox::Yes | QMessageBox::No); + QMessageBox::StandardButton result = MessageBox::question( + this, tr("Empty recycle bin?"), + tr("Are you sure you want to permanently delete everything from your recycle bin?"), + QMessageBox::Yes | QMessageBox::No); - if (result == QMessageBox::Yes) { - // destroying direct entries of the recycle bin - QList subEntries = currentGroup->entries(); - for (Entry* entry : subEntries) { - delete entry; - } - // destroying direct subgroups of the recycle bin - QList subGroups = currentGroup->children(); - for (Group* group : subGroups) { - delete group; - } - refreshSearch(); - } + if (result == QMessageBox::Yes) { + m_db->emptyRecycleBin(); + refreshSearch(); } } diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h index 5751aedb4..3add336f0 100644 --- a/src/gui/DatabaseWidget.h +++ b/src/gui/DatabaseWidget.h @@ -153,7 +153,7 @@ public slots: void switchToImportKeepass1(const QString& fileName); void databaseModified(); void databaseSaved(); - void emptyTrash(); + void emptyRecycleBin(); // Search related slots void search(const QString& searchtext); diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 72a0f4c31..6883f8a7e 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -197,7 +197,7 @@ MainWindow::MainWindow() m_ui->actionGroupNew->setIcon(filePath()->icon("actions", "group-new", false)); m_ui->actionGroupEdit->setIcon(filePath()->icon("actions", "group-edit", false)); m_ui->actionGroupDelete->setIcon(filePath()->icon("actions", "group-delete", false)); - m_ui->actionGroupEmptyTrash->setIcon(filePath()->icon("actions", "group-empty-trash", false)); + m_ui->actionGroupEmptyRecycleBin->setIcon(filePath()->icon("actions", "group-empty-trash", false)); m_ui->actionSettings->setIcon(filePath()->icon("actions", "configure")); m_ui->actionSettings->setMenuRole(QAction::PreferencesRole); @@ -296,8 +296,8 @@ MainWindow::MainWindow() SLOT(switchToGroupEdit())); m_actionMultiplexer.connect(m_ui->actionGroupDelete, SIGNAL(triggered()), SLOT(deleteGroup())); - m_actionMultiplexer.connect(m_ui->actionGroupEmptyTrash, SIGNAL(triggered()), - SLOT(emptyTrash())); + m_actionMultiplexer.connect(m_ui->actionGroupEmptyRecycleBin, SIGNAL(triggered()), + SLOT(emptyRecycleBin())); connect(m_ui->actionSettings, SIGNAL(triggered()), SLOT(switchToSettings())); connect(m_ui->actionPasswordGenerator, SIGNAL(toggled(bool)), SLOT(switchToPasswordGen(bool))); @@ -433,8 +433,8 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode) m_ui->actionGroupNew->setEnabled(groupSelected); m_ui->actionGroupEdit->setEnabled(groupSelected); m_ui->actionGroupDelete->setEnabled(groupSelected && dbWidget->canDeleteCurrentGroup()); - m_ui->actionGroupEmptyTrash->setVisible(recycleBinSelected); - m_ui->actionGroupEmptyTrash->setEnabled(recycleBinSelected); + m_ui->actionGroupEmptyRecycleBin->setVisible(recycleBinSelected); + m_ui->actionGroupEmptyRecycleBin->setEnabled(recycleBinSelected); m_ui->actionChangeMasterKey->setEnabled(true); m_ui->actionChangeDatabaseSettings->setEnabled(true); m_ui->actionDatabaseSave->setEnabled(true); diff --git a/src/gui/MainWindow.ui b/src/gui/MainWindow.ui index adacff5cb..384586e8d 100644 --- a/src/gui/MainWindow.ui +++ b/src/gui/MainWindow.ui @@ -238,7 +238,7 @@ - + @@ -523,7 +523,7 @@ Re&pair database - + Empty recycle bin