Add requested source code changes

This commit is contained in:
Vladimir Svyatski 2017-04-21 17:33:06 +03:00
parent dea65b637c
commit 75c16d1cbb
6 changed files with 34 additions and 30 deletions

View File

@ -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<Entry*> subEntries = m_metadata->recycleBin()->entries();
for (Entry* entry : subEntries) {
delete entry;
}
// destroying direct subgroups of the recycle bin
QList<Group*> subGroups = m_metadata->recycleBin()->children();
for (Group* group : subGroups) {
delete group;
}
}
}
void Database::merge(const Database* other)
{
m_rootGroup->merge(other->rootGroup());

View File

@ -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);

View File

@ -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?"),
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<Entry*> subEntries = currentGroup->entries();
for (Entry* entry : subEntries) {
delete entry;
}
// destroying direct subgroups of the recycle bin
QList<Group*> subGroups = currentGroup->children();
for (Group* group : subGroups) {
delete group;
}
m_db->emptyRecycleBin();
refreshSearch();
}
}
}

View File

@ -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);

View File

@ -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);

View File

@ -238,7 +238,7 @@
<addaction name="separator"/>
<addaction name="actionGroupEdit"/>
<addaction name="actionGroupDelete"/>
<addaction name="actionGroupEmptyTrash"/>
<addaction name="actionGroupEmptyRecycleBin"/>
</widget>
<widget class="QMenu" name="menuTools">
<property name="title">
@ -523,7 +523,7 @@
<string>Re&amp;pair database</string>
</property>
</action>
<action name="actionGroupEmptyTrash">
<action name="actionGroupEmptyRecycleBin">
<property name="text">
<string>Empty recycle bin</string>
</property>