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);
}
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<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()) {
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);
}
}
}

View File

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

View File

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