change inAutotype logic, preventing multiple autotype call

This commit is contained in:
thez3ro 2018-01-24 20:08:56 +01:00
parent ba4ef52e9e
commit a76c92ed9a
No known key found for this signature in database
GPG Key ID: F628F9E41DD7C073
8 changed files with 44 additions and 56 deletions

View File

@ -173,13 +173,11 @@ bool AutoType::registerGlobalShortcut(Qt::Key key, Qt::KeyboardModifiers modifie
m_currentGlobalKey = key;
m_currentGlobalModifiers = modifiers;
return true;
} else {
}
return false;
}
} else {
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<AutoTypeAction*> 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;
}
/**
@ -263,6 +262,8 @@ void AutoType::performAutoType(const Entry* entry, QWidget* hideWindow)
m_inAutoType = true;
executeAutoTypeActions(entry, hideWindow, sequences.first());
m_inAutoType = false;
}
/**
@ -304,8 +305,8 @@ void AutoType::performGlobalAutoType(const QList<Database*>& 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<QString> 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<AutoTypeAssociations::Association> assocList = entry->autoTypeAssociations()->getAll();
for (const AutoTypeAssociations::Association& assoc : assocList) {
@ -572,17 +584,6 @@ QList<QString> 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<QString>();
} else if (group->autoTypeEnabled() == Group::Enable) {
return sequenceList;
}
group = group->parentGroup();
} while (group);
return sequenceList;
}

View File

@ -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()) {

View File

@ -55,7 +55,7 @@ void AutoTypeMatchModel::setMatchList(const QList<AutoTypeMatch>& matches)
QSet<Database*> 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;
}
}
}

View File

@ -50,7 +50,7 @@ public:
void setMatchList(const QList<AutoTypeMatch>& matches);
private Q_SLOTS:
private slots:
void entryAboutToRemove(Entry* entry);
void entryRemoved();
void entryDataChanged(Entry* entry);

View File

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

View File

@ -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<AutoTypeMatch>& 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:

View File

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

View File

@ -310,7 +310,7 @@ void TestAutoType::testAutoTypeEffectiveSequences()
QString sequenceDisabled("{TEST_DISABLED}");
QString sequenceOrphan("{TEST_ORPHAN}");
Database* db = new Database();
QScopedPointer<Database> db(new Database());
QPointer<Group> 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<Entry> entry6 = new Entry();
QScopedPointer<Entry> 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;
}