diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index d51dec94..52ec8928 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -228,27 +228,61 @@ void DatabaseWidget::cloneEntry() m_entryView->setCurrentEntry(entry); } -void DatabaseWidget::deleteEntry() +void DatabaseWidget::deleteEntries() { - Entry* currentEntry = m_entryView->currentEntry(); - if (!currentEntry) { + const QModelIndexList selected = m_entryView->selectionModel()->selectedRows(); + + if (selected.isEmpty()) { Q_ASSERT(false); return; } - bool inRecylceBin = Tools::hasChild(m_db->metadata()->recycleBin(), currentEntry); + // get all entry pointers as the indexes change when removing multiple entries + QList selectedEntries; + Q_FOREACH (const QModelIndex& index, selected) { + selectedEntries.append(m_entryView->entryFromIndex(index)); + } + + bool inRecylceBin = Tools::hasChild(m_db->metadata()->recycleBin(), selectedEntries.first()); if (inRecylceBin || !m_db->metadata()->recycleBinEnabled()) { - QMessageBox::StandardButton result = QMessageBox::question( - this, tr("Delete entry?"), - tr("Do you really want to delete the entry \"%1\" for good?") - .arg(currentEntry->title()), - QMessageBox::Yes | QMessageBox::No); + QMessageBox::StandardButton result; + + if (selected.size() == 1) { + result = QMessageBox::question( + this, tr("Delete entry?"), + tr("Do you really want to delete the entry \"%1\" for good?") + .arg(selectedEntries.first()->title()), + QMessageBox::Yes | QMessageBox::No); + } + else { + result = QMessageBox::question( + this, tr("Delete entries?"), + tr("Do you really want to delete %1 entries for good?") + .arg(selected.size()), + QMessageBox::Yes | QMessageBox::No); + } + if (result == QMessageBox::Yes) { - delete currentEntry; + Q_FOREACH (Entry* entry, selectedEntries) { + delete entry; + } } } else { - m_db->recycleEntry(currentEntry); + if (selected.size() > 1) { + QMessageBox::StandardButton result = QMessageBox::question( + this, tr("Move entries to recycle bin?"), + tr("Do you really want to move %1 entries to the recycle bin?") + .arg(selected.size()), + QMessageBox::Yes | QMessageBox::No); + if (result == QMessageBox::No) { + return; + } + } + + Q_FOREACH (Entry* entry, selectedEntries) { + m_db->recycleEntry(entry); + } } } diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h index c1e1a94c..e5bacd5d 100644 --- a/src/gui/DatabaseWidget.h +++ b/src/gui/DatabaseWidget.h @@ -85,7 +85,7 @@ Q_SIGNALS: public Q_SLOTS: void createEntry(); void cloneEntry(); - void deleteEntry(); + void deleteEntries(); void copyUsername(); void copyPassword(); void copyAttribute(QAction* action); diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index b9ac27e0..390b6875 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -162,7 +162,7 @@ MainWindow::MainWindow() m_actionMultiplexer.connect(m_ui->actionEntryEdit, SIGNAL(triggered()), SLOT(switchToEntryEdit())); m_actionMultiplexer.connect(m_ui->actionEntryDelete, SIGNAL(triggered()), - SLOT(deleteEntry())); + SLOT(deleteEntries())); m_actionMultiplexer.connect(m_ui->actionEntryCopyUsername, SIGNAL(triggered()), SLOT(copyUsername())); m_actionMultiplexer.connect(m_ui->actionEntryCopyPassword, SIGNAL(triggered()), @@ -262,12 +262,13 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode) case DatabaseWidget::ViewMode: { bool inSearch = dbWidget->isInSearchMode(); bool singleEntrySelected = dbWidget->entryView()->isSingleEntrySelected(); + bool entriesSelected = !dbWidget->entryView()->selectionModel()->selectedRows().isEmpty(); bool groupSelected = dbWidget->groupView()->currentGroup(); m_ui->actionEntryNew->setEnabled(!inSearch); m_ui->actionEntryClone->setEnabled(singleEntrySelected && !inSearch); m_ui->actionEntryEdit->setEnabled(singleEntrySelected); - m_ui->actionEntryDelete->setEnabled(singleEntrySelected); + m_ui->actionEntryDelete->setEnabled(entriesSelected); m_ui->actionEntryCopyUsername->setEnabled(singleEntrySelected); m_ui->actionEntryCopyPassword->setEnabled(singleEntrySelected); m_ui->menuEntryCopyAttribute->setEnabled(singleEntrySelected);