Allow removing multiple entries.

This commit is contained in:
Felix Geyer 2013-10-08 21:36:01 +02:00
parent 8778df5789
commit 551637f0c2
3 changed files with 49 additions and 14 deletions

View file

@ -228,27 +228,61 @@ void DatabaseWidget::cloneEntry()
m_entryView->setCurrentEntry(entry); m_entryView->setCurrentEntry(entry);
} }
void DatabaseWidget::deleteEntry() void DatabaseWidget::deleteEntries()
{ {
Entry* currentEntry = m_entryView->currentEntry(); const QModelIndexList selected = m_entryView->selectionModel()->selectedRows();
if (!currentEntry) {
if (selected.isEmpty()) {
Q_ASSERT(false); Q_ASSERT(false);
return; return;
} }
bool inRecylceBin = Tools::hasChild(m_db->metadata()->recycleBin(), currentEntry); // get all entry pointers as the indexes change when removing multiple entries
QList<Entry*> 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()) { if (inRecylceBin || !m_db->metadata()->recycleBinEnabled()) {
QMessageBox::StandardButton result = QMessageBox::question( QMessageBox::StandardButton result;
this, tr("Delete entry?"),
tr("Do you really want to delete the entry \"%1\" for good?") if (selected.size() == 1) {
.arg(currentEntry->title()), result = QMessageBox::question(
QMessageBox::Yes | QMessageBox::No); 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) { if (result == QMessageBox::Yes) {
delete currentEntry; Q_FOREACH (Entry* entry, selectedEntries) {
delete entry;
}
} }
} }
else { 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);
}
} }
} }

View file

@ -85,7 +85,7 @@ Q_SIGNALS:
public Q_SLOTS: public Q_SLOTS:
void createEntry(); void createEntry();
void cloneEntry(); void cloneEntry();
void deleteEntry(); void deleteEntries();
void copyUsername(); void copyUsername();
void copyPassword(); void copyPassword();
void copyAttribute(QAction* action); void copyAttribute(QAction* action);

View file

@ -162,7 +162,7 @@ MainWindow::MainWindow()
m_actionMultiplexer.connect(m_ui->actionEntryEdit, SIGNAL(triggered()), m_actionMultiplexer.connect(m_ui->actionEntryEdit, SIGNAL(triggered()),
SLOT(switchToEntryEdit())); SLOT(switchToEntryEdit()));
m_actionMultiplexer.connect(m_ui->actionEntryDelete, SIGNAL(triggered()), m_actionMultiplexer.connect(m_ui->actionEntryDelete, SIGNAL(triggered()),
SLOT(deleteEntry())); SLOT(deleteEntries()));
m_actionMultiplexer.connect(m_ui->actionEntryCopyUsername, SIGNAL(triggered()), m_actionMultiplexer.connect(m_ui->actionEntryCopyUsername, SIGNAL(triggered()),
SLOT(copyUsername())); SLOT(copyUsername()));
m_actionMultiplexer.connect(m_ui->actionEntryCopyPassword, SIGNAL(triggered()), m_actionMultiplexer.connect(m_ui->actionEntryCopyPassword, SIGNAL(triggered()),
@ -262,12 +262,13 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode)
case DatabaseWidget::ViewMode: { case DatabaseWidget::ViewMode: {
bool inSearch = dbWidget->isInSearchMode(); bool inSearch = dbWidget->isInSearchMode();
bool singleEntrySelected = dbWidget->entryView()->isSingleEntrySelected(); bool singleEntrySelected = dbWidget->entryView()->isSingleEntrySelected();
bool entriesSelected = !dbWidget->entryView()->selectionModel()->selectedRows().isEmpty();
bool groupSelected = dbWidget->groupView()->currentGroup(); bool groupSelected = dbWidget->groupView()->currentGroup();
m_ui->actionEntryNew->setEnabled(!inSearch); m_ui->actionEntryNew->setEnabled(!inSearch);
m_ui->actionEntryClone->setEnabled(singleEntrySelected && !inSearch); m_ui->actionEntryClone->setEnabled(singleEntrySelected && !inSearch);
m_ui->actionEntryEdit->setEnabled(singleEntrySelected); m_ui->actionEntryEdit->setEnabled(singleEntrySelected);
m_ui->actionEntryDelete->setEnabled(singleEntrySelected); m_ui->actionEntryDelete->setEnabled(entriesSelected);
m_ui->actionEntryCopyUsername->setEnabled(singleEntrySelected); m_ui->actionEntryCopyUsername->setEnabled(singleEntrySelected);
m_ui->actionEntryCopyPassword->setEnabled(singleEntrySelected); m_ui->actionEntryCopyPassword->setEnabled(singleEntrySelected);
m_ui->menuEntryCopyAttribute->setEnabled(singleEntrySelected); m_ui->menuEntryCopyAttribute->setEnabled(singleEntrySelected);