mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-01-26 22:36:59 -05:00
Merge pull request #1038 from frostasm/resolve-placeholders-in-window-association-title
AutoType: resolve placeholders for title in window associations
This commit is contained in:
commit
e95f36c725
@ -563,7 +563,8 @@ QString AutoType::autoTypeSequence(const Entry* entry, const QString& windowTitl
|
|||||||
bool match = false;
|
bool match = false;
|
||||||
const QList<AutoTypeAssociations::Association> assocList = entry->autoTypeAssociations()->getAll();
|
const QList<AutoTypeAssociations::Association> assocList = entry->autoTypeAssociations()->getAll();
|
||||||
for (const AutoTypeAssociations::Association& assoc : assocList) {
|
for (const AutoTypeAssociations::Association& assoc : assocList) {
|
||||||
if (windowMatches(windowTitle, assoc.window)) {
|
const QString window = entry->resolveMultiplePlaceholders(assoc.window);
|
||||||
|
if (windowMatches(windowTitle, window)) {
|
||||||
if (!assoc.sequence.isEmpty()) {
|
if (!assoc.sequence.isEmpty()) {
|
||||||
sequence = assoc.sequence;
|
sequence = assoc.sequence;
|
||||||
}
|
}
|
||||||
|
@ -17,9 +17,12 @@
|
|||||||
|
|
||||||
#include "AutoTypeAssociationsModel.h"
|
#include "AutoTypeAssociationsModel.h"
|
||||||
|
|
||||||
|
#include "core/Entry.h"
|
||||||
|
|
||||||
AutoTypeAssociationsModel::AutoTypeAssociationsModel(QObject* parent)
|
AutoTypeAssociationsModel::AutoTypeAssociationsModel(QObject* parent)
|
||||||
: QAbstractListModel(parent)
|
: QAbstractListModel(parent)
|
||||||
, m_autoTypeAssociations(nullptr)
|
, m_autoTypeAssociations(nullptr)
|
||||||
|
, m_entry(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,6 +49,11 @@ void AutoTypeAssociationsModel::setAutoTypeAssociations(AutoTypeAssociations* au
|
|||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AutoTypeAssociationsModel::setEntry(const Entry *entry)
|
||||||
|
{
|
||||||
|
m_entry = entry;
|
||||||
|
}
|
||||||
|
|
||||||
int AutoTypeAssociationsModel::rowCount(const QModelIndex& parent) const
|
int AutoTypeAssociationsModel::rowCount(const QModelIndex& parent) const
|
||||||
{
|
{
|
||||||
if (!m_autoTypeAssociations || parent.isValid()) {
|
if (!m_autoTypeAssociations || parent.isValid()) {
|
||||||
@ -86,7 +94,12 @@ QVariant AutoTypeAssociationsModel::data(const QModelIndex& index, int role) con
|
|||||||
|
|
||||||
if (role == Qt::DisplayRole) {
|
if (role == Qt::DisplayRole) {
|
||||||
if (index.column() == 0) {
|
if (index.column() == 0) {
|
||||||
return m_autoTypeAssociations->get(index.row()).window;
|
QString window = m_autoTypeAssociations->get(index.row()).window;
|
||||||
|
if (m_entry) {
|
||||||
|
window = m_entry->maskPasswordPlaceholders(window);
|
||||||
|
window = m_entry->resolveMultiplePlaceholders(window);
|
||||||
|
}
|
||||||
|
return window;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
QString sequence = m_autoTypeAssociations->get(index.row()).sequence;
|
QString sequence = m_autoTypeAssociations->get(index.row()).sequence;
|
||||||
|
@ -19,10 +19,11 @@
|
|||||||
#define KEEPASSX_AUTOTYPEASSOCIATIONSMODEL_H
|
#define KEEPASSX_AUTOTYPEASSOCIATIONSMODEL_H
|
||||||
|
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
|
#include <QPointer>
|
||||||
|
|
||||||
#include "core/AutoTypeAssociations.h"
|
#include "core/AutoTypeAssociations.h"
|
||||||
|
|
||||||
class EntryAttributes;
|
class Entry;
|
||||||
|
|
||||||
class AutoTypeAssociationsModel : public QAbstractListModel
|
class AutoTypeAssociationsModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
@ -31,6 +32,7 @@ class AutoTypeAssociationsModel : public QAbstractListModel
|
|||||||
public:
|
public:
|
||||||
explicit AutoTypeAssociationsModel(QObject* parent = nullptr);
|
explicit AutoTypeAssociationsModel(QObject* parent = nullptr);
|
||||||
void setAutoTypeAssociations(AutoTypeAssociations* autoTypeAssociations);
|
void setAutoTypeAssociations(AutoTypeAssociations* autoTypeAssociations);
|
||||||
|
void setEntry(const Entry* entry);
|
||||||
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||||
int columnCount(const QModelIndex& parent = QModelIndex()) const override;
|
int columnCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||||
@ -47,6 +49,7 @@ public slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
AutoTypeAssociations* m_autoTypeAssociations;
|
AutoTypeAssociations* m_autoTypeAssociations;
|
||||||
|
QPointer<const Entry> m_entry;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KEEPASSX_AUTOTYPEASSOCIATIONSMODEL_H
|
#endif // KEEPASSX_AUTOTYPEASSOCIATIONSMODEL_H
|
||||||
|
@ -378,6 +378,7 @@ void EditEntryWidget::setForms(const Entry* entry, bool restore)
|
|||||||
m_autoTypeUi->defaultWindowSequenceButton->setChecked(true);
|
m_autoTypeUi->defaultWindowSequenceButton->setChecked(true);
|
||||||
m_autoTypeUi->windowSequenceEdit->setText("");
|
m_autoTypeUi->windowSequenceEdit->setText("");
|
||||||
m_autoTypeAssoc->copyDataFrom(entry->autoTypeAssociations());
|
m_autoTypeAssoc->copyDataFrom(entry->autoTypeAssociations());
|
||||||
|
m_autoTypeAssocModel->setEntry(entry);
|
||||||
if (m_autoTypeAssoc->size() != 0) {
|
if (m_autoTypeAssoc->size() != 0) {
|
||||||
m_autoTypeUi->assocView->setCurrentIndex(m_autoTypeAssocModel->index(0, 0));
|
m_autoTypeUi->assocView->setCurrentIndex(m_autoTypeAssocModel->index(0, 0));
|
||||||
}
|
}
|
||||||
|
@ -96,6 +96,9 @@ void TestAutoType::init()
|
|||||||
m_entry4->setGroup(m_group);
|
m_entry4->setGroup(m_group);
|
||||||
m_entry4->setPassword("custom_attr");
|
m_entry4->setPassword("custom_attr");
|
||||||
m_entry4->attributes()->set("CUSTOM","Attribute",false);
|
m_entry4->attributes()->set("CUSTOM","Attribute",false);
|
||||||
|
m_entry4->attributes()->set("CustomAttrFirst","AttrValueFirst",false);
|
||||||
|
m_entry4->attributes()->set("CustomAttrSecond","AttrValueSecond",false);
|
||||||
|
m_entry4->attributes()->set("CustomAttrThird","AttrValueThird",false);
|
||||||
association.window = "//^CustomAttr1$//";
|
association.window = "//^CustomAttr1$//";
|
||||||
association.sequence = "{PASSWORD}:{S:CUSTOM}";
|
association.sequence = "{PASSWORD}:{S:CUSTOM}";
|
||||||
m_entry4->autoTypeAssociations()->add(association);
|
m_entry4->autoTypeAssociations()->add(association);
|
||||||
@ -105,7 +108,16 @@ void TestAutoType::init()
|
|||||||
association.window = "//^CustomAttr3$//";
|
association.window = "//^CustomAttr3$//";
|
||||||
association.sequence = "{PaSSworD}";
|
association.sequence = "{PaSSworD}";
|
||||||
m_entry4->autoTypeAssociations()->add(association);
|
m_entry4->autoTypeAssociations()->add(association);
|
||||||
|
association.window = "//^{S:CustomAttrFirst}$//";
|
||||||
|
association.sequence = "custom_attr_first";
|
||||||
|
m_entry4->autoTypeAssociations()->add(association);
|
||||||
|
association.window = "//{S:CustomAttrFirst}And{S:CustomAttrSecond}//";
|
||||||
|
association.sequence = "custom_attr_first_and_second";
|
||||||
|
m_entry4->autoTypeAssociations()->add(association);
|
||||||
|
association.window = "//{S:CustomAttrThird}//";
|
||||||
|
association.sequence = "custom_attr_third";
|
||||||
|
m_entry4->autoTypeAssociations()->add(association);
|
||||||
|
|
||||||
m_entry5 = new Entry();
|
m_entry5 = new Entry();
|
||||||
m_entry5->setGroup(m_group);
|
m_entry5->setGroup(m_group);
|
||||||
m_entry5->setPassword("example5");
|
m_entry5->setPassword("example5");
|
||||||
@ -253,4 +265,20 @@ void TestAutoType::testGlobalAutoTypeRegExp()
|
|||||||
m_autoType->performGlobalAutoType(m_dbList);
|
m_autoType->performGlobalAutoType(m_dbList);
|
||||||
QCOMPARE(m_test->actionChars(), QString("custom_attr"));
|
QCOMPARE(m_test->actionChars(), QString("custom_attr"));
|
||||||
m_test->clearActions();
|
m_test->clearActions();
|
||||||
|
|
||||||
|
// with resolve placeholders in window association title
|
||||||
|
m_test->setActiveWindowTitle("AttrValueFirst");
|
||||||
|
m_autoType->performGlobalAutoType(m_dbList);
|
||||||
|
QCOMPARE(m_test->actionChars(), QString("custom_attr_first"));
|
||||||
|
m_test->clearActions();
|
||||||
|
|
||||||
|
m_test->setActiveWindowTitle("lorem AttrValueFirstAndAttrValueSecond ipsum");
|
||||||
|
m_autoType->performGlobalAutoType(m_dbList);
|
||||||
|
QCOMPARE(m_test->actionChars(), QString("custom_attr_first_and_second"));
|
||||||
|
m_test->clearActions();
|
||||||
|
|
||||||
|
m_test->setActiveWindowTitle("lorem AttrValueThird ipsum");
|
||||||
|
m_autoType->performGlobalAutoType(m_dbList);
|
||||||
|
QCOMPARE(m_test->actionChars(), QString("custom_attr_third"));
|
||||||
|
m_test->clearActions();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user