Skip to content

Commit

Permalink
Allow selecting from all entries if no match found on autotype shortcut
Browse files Browse the repository at this point in the history
Fixes keepassxreboot#429

If the global autotype shortcut is triggered on a window, but no
applicable match can be found, populate the AutoTypeSelectDialog
with all available entry-sequence pairs. The user can then filter
this list with the filter box implemented in keepassxreboot#2955 to narrow down
the matches and select with arrow keys and enter or mouse.
  • Loading branch information
kneitinger committed Sep 19, 2019
1 parent c19703c commit d985592
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/autotype/AutoType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,28 +294,36 @@ void AutoType::performGlobalAutoType(const QList<QSharedPointer<Database>>& dbLi
return;
}

QList<AutoTypeMatch> matchList;
QList<AutoTypeMatch> windowMatchList;
QList<AutoTypeMatch> allSequenceList;

for (const auto& db : dbList) {
const QList<Entry*> dbEntries = db->rootGroup()->entriesRecursive();
for (Entry* entry : dbEntries) {
// Find unique entry:sequence pairs that match the focused window
const QSet<QString> sequences = autoTypeSequences(entry, m_windowTitleForGlobal).toSet();
for (const QString& sequence : sequences) {
if (!sequence.isEmpty()) {
matchList << AutoTypeMatch(entry, sequence);
windowMatchList << AutoTypeMatch(entry, sequence);
}
}
// Find all unique entry:sequence pairs
const QSet<QString> allSequences = autoTypeSequences(entry).toSet();
for (const QString& sequence : allSequences) {
if (!sequence.isEmpty()) {
allSequenceList << AutoTypeMatch(entry, sequence);
}
}
}
}

if (matchList.isEmpty()) {
// allSequenceList being empty implies that windowMatchList is also empty
if (allSequenceList.isEmpty()) {
if (qobject_cast<QApplication*>(QCoreApplication::instance())) {
auto* msgBox = new QMessageBox();
msgBox->setAttribute(Qt::WA_DeleteOnClose);
msgBox->setWindowTitle(tr("Auto-Type - KeePassXC"));
msgBox->setText(tr("Couldn't find an entry that matches the window title:")
.append("\n\n")
.append(m_windowTitleForGlobal));
msgBox->setText(tr("Could not find auto-type sequences in any entries"));
msgBox->setIcon(QMessageBox::Information);
msgBox->setStandardButtons(QMessageBox::Ok);
msgBox->show();
Expand All @@ -325,8 +333,8 @@ void AutoType::performGlobalAutoType(const QList<QSharedPointer<Database>>& dbLi

m_inGlobalAutoTypeDialog.unlock();
emit autotypeRejected();
} else if ((matchList.size() == 1) && !config()->get("security/autotypeask").toBool()) {
executeAutoTypeActions(matchList.first().entry, nullptr, matchList.first().sequence, m_windowForGlobal);
} else if ((windowMatchList.size() == 1) && !config()->get("security/autotypeask").toBool()) {
executeAutoTypeActions(windowMatchList.first().entry, nullptr, windowMatchList.first().sequence, m_windowForGlobal);
m_inGlobalAutoTypeDialog.unlock();
} else {
auto* selectDialog = new AutoTypeSelectDialog();
Expand All @@ -335,7 +343,11 @@ void AutoType::performGlobalAutoType(const QList<QSharedPointer<Database>>& dbLi
connect(selectDialog, SIGNAL(matchActivated(AutoTypeMatch)), SLOT(performAutoTypeFromGlobal(AutoTypeMatch)));
connect(selectDialog, SIGNAL(rejected()), SLOT(autoTypeRejectedFromGlobal()));

selectDialog->setMatchList(matchList);
if (!windowMatchList.isEmpty()) {
selectDialog->setMatchList(windowMatchList);
} else {
selectDialog->setMatchList(allSequenceList);
}
#ifdef Q_OS_MACOS
m_plugin->raiseOwnWindow();
Tools::wait(200);
Expand Down

0 comments on commit d985592

Please sign in to comment.