Add context menu entry to clean the Recycle Bin in databases

This implements the feature request (issue) #503.
This commit is contained in:
Vladimir Svyatski 2017-04-21 13:49:32 +03:00
parent b01953a5a3
commit dea65b637c
5 changed files with 54 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -1267,3 +1267,38 @@ void DatabaseWidget::hideMessage()
m_messageWidget->animatedHide();
}
}
bool DatabaseWidget::isRecycleBinSelected() const
{
return m_groupView->currentGroup() && m_groupView->currentGroup() == m_db->metadata()->recycleBin();
}
void DatabaseWidget::emptyTrash()
{
Group* currentGroup = m_groupView->currentGroup();
if (!currentGroup) {
Q_ASSERT(false);
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);
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;
}
refreshSearch();
}
}
}

View File

@ -102,6 +102,7 @@ public:
void closeUnlockDialog();
void blockAutoReload(bool block = true);
void refreshSearch();
bool isRecycleBinSelected() const;
signals:
void closeRequest();
@ -152,6 +153,7 @@ public slots:
void switchToImportKeepass1(const QString& fileName);
void databaseModified();
void databaseSaved();
void emptyTrash();
// Search related slots
void search(const QString& searchtext);

View File

@ -197,6 +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->actionSettings->setIcon(filePath()->icon("actions", "configure"));
m_ui->actionSettings->setMenuRole(QAction::PreferencesRole);
@ -295,6 +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()));
connect(m_ui->actionSettings, SIGNAL(triggered()), SLOT(switchToSettings()));
connect(m_ui->actionPasswordGenerator, SIGNAL(toggled(bool)), SLOT(switchToPasswordGen(bool)));
@ -413,6 +416,7 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode)
bool singleEntrySelected = dbWidget->numberOfSelectedEntries() == 1;
bool entriesSelected = dbWidget->numberOfSelectedEntries() > 0;
bool groupSelected = dbWidget->isGroupSelected();
bool recycleBinSelected = dbWidget->isRecycleBinSelected();
m_ui->actionEntryNew->setEnabled(!inSearch);
m_ui->actionEntryClone->setEnabled(singleEntrySelected);
@ -429,6 +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->actionChangeMasterKey->setEnabled(true);
m_ui->actionChangeDatabaseSettings->setEnabled(true);
m_ui->actionDatabaseSave->setEnabled(true);

View File

@ -162,7 +162,7 @@
<x>0</x>
<y>0</y>
<width>800</width>
<height>29</height>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
@ -235,8 +235,10 @@
<string>&amp;Groups</string>
</property>
<addaction name="actionGroupNew"/>
<addaction name="separator"/>
<addaction name="actionGroupEdit"/>
<addaction name="actionGroupDelete"/>
<addaction name="actionGroupEmptyTrash"/>
</widget>
<widget class="QMenu" name="menuTools">
<property name="title">
@ -521,6 +523,14 @@
<string>Re&amp;pair database</string>
</property>
</action>
<action name="actionGroupEmptyTrash">
<property name="text">
<string>Empty recycle bin</string>
</property>
<property name="visible">
<bool>false</bool>
</property>
</action>
</widget>
<customwidgets>
<customwidget>