From dea65b637ca2369524b9b1864eff3b2457fb37b7 Mon Sep 17 00:00:00 2001 From: Vladimir Svyatski Date: Fri, 21 Apr 2017 13:49:32 +0300 Subject: [PATCH] Add context menu entry to clean the Recycle Bin in databases This implements the feature request (issue) #503. --- .../16x16/actions/group-empty-trash.png | Bin 0 -> 1115 bytes src/gui/DatabaseWidget.cpp | 35 ++++++++++++++++++ src/gui/DatabaseWidget.h | 2 + src/gui/MainWindow.cpp | 6 +++ src/gui/MainWindow.ui | 12 +++++- 5 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 share/icons/application/16x16/actions/group-empty-trash.png diff --git a/share/icons/application/16x16/actions/group-empty-trash.png b/share/icons/application/16x16/actions/group-empty-trash.png new file mode 100644 index 0000000000000000000000000000000000000000..aa9d7321f94a42ed44418c86e8a26a585de0ed7c GIT binary patch literal 1115 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4mJh`2Kmqb6B!s7SkfJR9T^zbpD<_bdda}R zAX(xXQ4*Y=R#Ki=l*-_klAn~S;F+74o*I;zm{M7IGS!BGf%&bci(^Q|Ee1!1eg7H% z|Nqax7=46+;m9G%2 zcg_3v=jSno*QXi&e}BoqgfNCF=7_nOw)jdd6-oJzUl|ylz52%R_wyTu-(SBmy#36; zz{UKZfrFi$frE#O;rsXZKX2}yG5hEBHM#%)d}Lta$Z2r=e0DeAuT5Ul^Y*3e`1^#r znd5MD8&i578{f2gp4EJIX*a6ga34O;UoR0M`OiRO<_yCP9}WNQ-=?tQ%lYHK_cAaZ zImE#7i;L;gb@}@AAD`dY9OjAVWD{g$WK+$oYpbvSZ+N1hJ}uzM&odu>%j+|r-XG5+ z?KdYmLGW{O%Hzo&*s|WTawu$IoOGvNV$0K`l701|Nf*Kd6MlSt%Y67Rd%xt9r%xoG zq%4t`wC9Gzj-RX&dbX+Q79XZge0cKxe4hLDHOVY5!3OmF|8KM-)5ze&$1Fpc+Q0K3 zo>rG*+xCCIgq&SM@{fPh`yXC)4{W<$9wE7IZ&E_Vx!?T{-*&6>@YMhR%MLN2{y!5h zNNerFFMt}bP?SJ_1@^_wkiJKDpYW|)(aQ;Vk<7`Qd@AGAIHY+@@ zZ!`D#FH!fG{dWVSLc@#$*P11K7Hs%&{=;W|<-_4@c5VIpBP8$D|6*GbDIsz5rzFeI zO357-HzinZ{%7$0&3;5coPkB)2J8R-e^XOfb~VkElsJ^X&tT5Zzip0=4ULV=8Ct@| z{D)`v@0X0*Uw8Jvp;Ihhm`<4T6fiR|alB!YTX0fbzCO9)!#C^0%k}q5#O+}@_WS*R zo;Nx)e{BJmI@r+ET6>VQ*(-kXAKk2`Td)W?(8k@ zfB604KY5<}a%;eeq986IB_%oO$#s3xt>tGX8y8I4@hh~8Q>4I0M~0`z!QS}KuQMOs zeywerZr=arUs3Ys+P3oN(G82b9jh3bIFcAvD=;%l^D`gb9{;FE=l>mxAFVkJJ0rUq zJ9|IhzianimatedHide(); } } + +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 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(); + } + } +} diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h index d98cb0722..5751aedb4 100644 --- a/src/gui/DatabaseWidget.h +++ b/src/gui/DatabaseWidget.h @@ -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); diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 814501f6a..72a0f4c31 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -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); diff --git a/src/gui/MainWindow.ui b/src/gui/MainWindow.ui index c44bee9e7..adacff5cb 100644 --- a/src/gui/MainWindow.ui +++ b/src/gui/MainWindow.ui @@ -162,7 +162,7 @@ 0 0 800 - 29 + 21 @@ -235,8 +235,10 @@ &Groups + + @@ -521,6 +523,14 @@ Re&pair database + + + Empty recycle bin + + + false + +