diff --git a/src/autotype/AutoType.cpp b/src/autotype/AutoType.cpp index 5c936bf13..5bd10115a 100644 --- a/src/autotype/AutoType.cpp +++ b/src/autotype/AutoType.cpp @@ -173,12 +173,10 @@ bool AutoType::registerGlobalShortcut(Qt::Key key, Qt::KeyboardModifiers modifie m_currentGlobalKey = key; m_currentGlobalModifiers = modifiers; return true; - } else { - return false; } - } else { - return true; + return false; } + return true; } void AutoType::unregisterGlobalShortcut() @@ -202,9 +200,13 @@ int AutoType::callEventFilter(void* event) */ void AutoType::executeAutoTypeActions(const Entry* entry, QWidget* hideWindow, const QString& sequence, WId window) { + Q_ASSERT(m_inAutoType); + if (!m_inAutoType) { + return; + } + // no edit to the sequence beyond this point if (!verifyAutoTypeSyntax(sequence)) { - m_inAutoType = false; // TODO: make this automatic return; } @@ -212,7 +214,6 @@ void AutoType::executeAutoTypeActions(const Entry* entry, QWidget* hideWindow, c ListDeleter actionsDeleter(&actions); if (!parseActions(sequence, entry, actions)) { - m_inAutoType = false; // TODO: make this automatic return; } @@ -241,8 +242,6 @@ void AutoType::executeAutoTypeActions(const Entry* entry, QWidget* hideWindow, c action->accept(m_executor); QCoreApplication::processEvents(QEventLoop::AllEvents, 10); } - - m_inAutoType = false; } /** @@ -256,13 +255,15 @@ void AutoType::performAutoType(const Entry* entry, QWidget* hideWindow) } QList sequences = autoTypeSequences(entry); - if(sequences.isEmpty()) { + if (sequences.isEmpty()) { return; } m_inAutoType = true; executeAutoTypeActions(entry, hideWindow, sequences.first()); + + m_inAutoType = false; } /** @@ -304,8 +305,8 @@ void AutoType::performGlobalAutoType(const QList& dbList) message.append(windowTitle); MessageBox::information(nullptr, tr("Auto-Type - KeePassXC"), message); } else if ((matchList.size() == 1) && !config()->get("security/autotypeask").toBool()) { - m_inAutoType = false; executeAutoTypeActions(matchList.first().entry, nullptr, matchList.first().sequence); + m_inAutoType = false; } else { m_windowFromGlobal = m_plugin->activeWindow(); AutoTypeSelectDialog* selectDialog = new AutoTypeSelectDialog(); @@ -329,9 +330,9 @@ void AutoType::performAutoTypeFromGlobal(AutoTypeMatch match) m_plugin->raiseWindow(m_windowFromGlobal); - m_inAutoType = false; - executeAutoTypeActions(match.entry, nullptr, match.sequence, m_windowFromGlobal); + + m_inAutoType = false; } /** @@ -542,6 +543,17 @@ QList AutoType::autoTypeSequences(const Entry* entry, const QString& wi return sequenceList; } + const Group* group = entry->group(); + do { + if (group->autoTypeEnabled() == Group::Disable) { + return sequenceList; + } else if (group->autoTypeEnabled() == Group::Enable) { + break; + } + group = group->parentGroup(); + + } while (group); + if (!windowTitle.isEmpty()) { const QList assocList = entry->autoTypeAssociations()->getAll(); for (const AutoTypeAssociations::Association& assoc : assocList) { @@ -572,17 +584,6 @@ QList AutoType::autoTypeSequences(const Entry* entry, const QString& wi sequenceList.append(entry->effectiveAutoTypeSequence()); } - const Group* group = entry->group(); - do { - if (group->autoTypeEnabled() == Group::Disable) { - return QList(); - } else if (group->autoTypeEnabled() == Group::Enable) { - return sequenceList; - } - group = group->parentGroup(); - - } while (group); - return sequenceList; } diff --git a/src/core/Entry.cpp b/src/core/Entry.cpp index e4c9e720e..8db955c93 100644 --- a/src/core/Entry.cpp +++ b/src/core/Entry.cpp @@ -226,18 +226,18 @@ QString Entry::defaultAutoTypeSequence() const */ QString Entry::effectiveAutoTypeSequence() const { - if (autoTypeEnabled() == false) { - return QString(); + if (!autoTypeEnabled()) { + return {}; } const Group* parent = group(); if (!parent) { - return QString(); + return {}; } QString sequence = parent->effectiveAutoTypeSequence(); if (sequence.isEmpty()) { - return QString(); + return {}; } if (!m_data.defaultAutoTypeSequence.isEmpty()) { diff --git a/src/gui/entry/AutoTypeMatchModel.cpp b/src/gui/entry/AutoTypeMatchModel.cpp index 3a48e1737..6a370dea5 100644 --- a/src/gui/entry/AutoTypeMatchModel.cpp +++ b/src/gui/entry/AutoTypeMatchModel.cpp @@ -55,7 +55,7 @@ void AutoTypeMatchModel::setMatchList(const QList& matches) QSet databases; - for (AutoTypeMatch match : asConst(m_matches)) { + for (AutoTypeMatch& match : m_matches) { databases.insert(match.entry->group()->database()); } @@ -81,9 +81,8 @@ int AutoTypeMatchModel::rowCount(const QModelIndex& parent) const { if (parent.isValid()) { return 0; - } else { - return m_matches.size(); } + return m_matches.size(); } int AutoTypeMatchModel::columnCount(const QModelIndex& parent) const @@ -96,7 +95,7 @@ int AutoTypeMatchModel::columnCount(const QModelIndex& parent) const QVariant AutoTypeMatchModel::data(const QModelIndex& index, int role) const { if (!index.isValid()) { - return QVariant(); + return {}; } AutoTypeMatch match = matchFromIndex(index); @@ -138,7 +137,7 @@ QVariant AutoTypeMatchModel::data(const QModelIndex& index, int role) const return font; } - return QVariant(); + return {}; } QVariant AutoTypeMatchModel::headerData(int section, Qt::Orientation orientation, int role) const @@ -156,12 +155,12 @@ QVariant AutoTypeMatchModel::headerData(int section, Qt::Orientation orientation } } - return QVariant(); + return {}; } void AutoTypeMatchModel::entryDataChanged(Entry* entry) { - for (int row = 0; row < m_matches.size(); row++) { + for (int row = 0; row < m_matches.size(); ++row) { AutoTypeMatch match = m_matches[row]; if (match.entry == entry) { emit dataChanged(index(row, 0), index(row, columnCount()-1)); @@ -172,13 +171,13 @@ void AutoTypeMatchModel::entryDataChanged(Entry* entry) void AutoTypeMatchModel::entryAboutToRemove(Entry* entry) { - for (int row = 0; row < m_matches.size(); row++) { + for (int row = 0; row < m_matches.size(); ++row) { AutoTypeMatch match = m_matches[row]; if (match.entry == entry) { beginRemoveRows(QModelIndex(), row, row); m_matches.removeAt(row); endRemoveRows(); - row--; + --row; } } } diff --git a/src/gui/entry/AutoTypeMatchModel.h b/src/gui/entry/AutoTypeMatchModel.h index 8d341f5f4..791dbc3df 100644 --- a/src/gui/entry/AutoTypeMatchModel.h +++ b/src/gui/entry/AutoTypeMatchModel.h @@ -50,7 +50,7 @@ public: void setMatchList(const QList& matches); -private Q_SLOTS: +private slots: void entryAboutToRemove(Entry* entry); void entryRemoved(); void entryDataChanged(Entry* entry); diff --git a/src/gui/entry/AutoTypeMatchView.cpp b/src/gui/entry/AutoTypeMatchView.cpp index 013d192fc..ad7d16ddc 100644 --- a/src/gui/entry/AutoTypeMatchView.cpp +++ b/src/gui/entry/AutoTypeMatchView.cpp @@ -61,7 +61,7 @@ void AutoTypeMatchView::setMatchList(const QList& matches) for (int i = 0; i < m_model->columnCount(); ++i) { resizeColumnToContents(i); if (columnWidth(i) > 250) { - setColumnWidth(i, 250); + setColumnWidth(i, 250); } } setFirstMatchActive(); @@ -84,20 +84,13 @@ void AutoTypeMatchView::emitMatchActivated(const QModelIndex& index) emit matchActivated(match); } -void AutoTypeMatchView::setModel(QAbstractItemModel* model) -{ - Q_UNUSED(model); - Q_ASSERT(false); -} - AutoTypeMatch AutoTypeMatchView::currentMatch() { QModelIndexList list = selectionModel()->selectedRows(); if (list.size() == 1) { return m_model->matchFromIndex(m_sortModel->mapToSource(list.first())); - } else { - return AutoTypeMatch(); } + return AutoTypeMatch(); } void AutoTypeMatchView::setCurrentMatch(AutoTypeMatch match) @@ -110,7 +103,6 @@ AutoTypeMatch AutoTypeMatchView::matchFromIndex(const QModelIndex& index) { if (index.isValid()) { return m_model->matchFromIndex(m_sortModel->mapToSource(index)); - } else { - return AutoTypeMatch(); } + return AutoTypeMatch(); } diff --git a/src/gui/entry/AutoTypeMatchView.h b/src/gui/entry/AutoTypeMatchView.h index 08c177005..14ad9ea2a 100644 --- a/src/gui/entry/AutoTypeMatchView.h +++ b/src/gui/entry/AutoTypeMatchView.h @@ -33,21 +33,20 @@ class AutoTypeMatchView : public QTreeView public: explicit AutoTypeMatchView(QWidget* parent = nullptr); - void setModel(QAbstractItemModel* model) override; AutoTypeMatch currentMatch(); void setCurrentMatch(AutoTypeMatch match); AutoTypeMatch matchFromIndex(const QModelIndex& index); void setMatchList(const QList& matches); void setFirstMatchActive(); -Q_SIGNALS: +signals: void matchActivated(AutoTypeMatch match); void matchSelectionChanged(); protected: void keyPressEvent(QKeyEvent* event) override; -private Q_SLOTS: +private slots: void emitMatchActivated(const QModelIndex& index); private: diff --git a/src/gui/entry/EditEntryWidget.cpp b/src/gui/entry/EditEntryWidget.cpp index 71366651f..bab5a0728 100644 --- a/src/gui/entry/EditEntryWidget.cpp +++ b/src/gui/entry/EditEntryWidget.cpp @@ -170,7 +170,6 @@ void EditEntryWidget::setupAutoType() m_autoTypeDefaultSequenceGroup->addButton(m_autoTypeUi->inheritSequenceButton); m_autoTypeDefaultSequenceGroup->addButton(m_autoTypeUi->customSequenceButton); - //m_autoTypeWindowSequenceGroup->addButton(m_autoTypeUi->customWindowSequenceButton); m_autoTypeAssocModel->setAutoTypeAssociations(m_autoTypeAssoc); m_autoTypeUi->assocView->setModel(m_autoTypeAssocModel); m_autoTypeUi->assocView->setColumnHidden(1, true); diff --git a/tests/TestAutoType.cpp b/tests/TestAutoType.cpp index 53f455ce6..7590bc613 100644 --- a/tests/TestAutoType.cpp +++ b/tests/TestAutoType.cpp @@ -310,7 +310,7 @@ void TestAutoType::testAutoTypeEffectiveSequences() QString sequenceDisabled("{TEST_DISABLED}"); QString sequenceOrphan("{TEST_ORPHAN}"); - Database* db = new Database(); + QScopedPointer db(new Database()); QPointer rootGroup = db->rootGroup(); // Group with autotype enabled and custom default sequence @@ -362,7 +362,7 @@ void TestAutoType::testAutoTypeEffectiveSequences() entry5->setAutoTypeEnabled(false); // Entry with no parent - QPointer entry6 = new Entry(); + QScopedPointer entry6(new Entry()); entry6->setDefaultAutoTypeSequence(sequenceOrphan); QCOMPARE(entry1->defaultAutoTypeSequence(), QString()); @@ -377,6 +377,4 @@ void TestAutoType::testAutoTypeEffectiveSequences() QCOMPARE(entry5->effectiveAutoTypeSequence(), QString()); QCOMPARE(entry6->defaultAutoTypeSequence(), sequenceOrphan); QCOMPARE(entry6->effectiveAutoTypeSequence(), QString()); - - delete db; } \ No newline at end of file