mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-27 00:09:53 -05:00
Move autoTypeSequence() and windowMatches() to the AutoType class.
This commit is contained in:
parent
4f0600421c
commit
92efb3d20b
@ -98,7 +98,7 @@ void AutoType::performAutoType(const Entry* entry, QWidget* hideWindow, const QS
|
||||
|
||||
QString sequence;
|
||||
if (customSequence.isEmpty()) {
|
||||
sequence = entry->resolvePlaceholders(entry->autoTypeSequence());
|
||||
sequence = entry->resolvePlaceholders(autoTypeSequence(entry));
|
||||
}
|
||||
else {
|
||||
sequence = customSequence;
|
||||
@ -154,7 +154,7 @@ void AutoType::performGlobalAutoType(const QList<Database*>& dbList)
|
||||
|
||||
Q_FOREACH (Database* db, dbList) {
|
||||
Q_FOREACH (Entry* entry, db->rootGroup()->entriesRecursive()) {
|
||||
QString sequence = entry->autoTypeSequence(windowTitle);
|
||||
QString sequence = autoTypeSequence(entry, windowTitle);
|
||||
if (!sequence.isEmpty()) {
|
||||
entryList << entry;
|
||||
sequenceHash.insert(entry, sequence);
|
||||
@ -436,3 +436,84 @@ QList<AutoTypeAction*> AutoType::createActionFromTemplate(const QString& tmpl, c
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
QString AutoType::autoTypeSequence(const Entry* entry, const QString& windowTitle)
|
||||
{
|
||||
if (!entry->autoTypeEnabled()) {
|
||||
return QString();
|
||||
}
|
||||
|
||||
bool enableSet = false;
|
||||
QString sequence;
|
||||
if (!windowTitle.isEmpty()) {
|
||||
bool match = false;
|
||||
Q_FOREACH (const AutoTypeAssociations::Association& assoc, entry->autoTypeAssociations()->getAll()) {
|
||||
if (windowMatches(windowTitle, assoc.window)) {
|
||||
if (!assoc.sequence.isEmpty()) {
|
||||
sequence = assoc.sequence;
|
||||
}
|
||||
else {
|
||||
sequence = entry->defaultAutoTypeSequence();
|
||||
}
|
||||
match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!match) {
|
||||
return QString();
|
||||
}
|
||||
}
|
||||
else {
|
||||
sequence = entry->defaultAutoTypeSequence();
|
||||
}
|
||||
|
||||
const Group* group = entry->group();
|
||||
do {
|
||||
if (!enableSet) {
|
||||
if (group->autoTypeEnabled() == Group::Disable) {
|
||||
return QString();
|
||||
}
|
||||
else if (group->autoTypeEnabled() == Group::Enable) {
|
||||
enableSet = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (sequence.isEmpty()) {
|
||||
sequence = group->defaultAutoTypeSequence();
|
||||
}
|
||||
|
||||
group = group->parentGroup();
|
||||
} while (group && (!enableSet || sequence.isEmpty()));
|
||||
|
||||
if (sequence.isEmpty() && (!entry->username().isEmpty() || !entry->password().isEmpty())) {
|
||||
if (entry->username().isEmpty()) {
|
||||
sequence = "{PASSWORD}{ENTER}";
|
||||
}
|
||||
else if (entry->password().isEmpty()) {
|
||||
sequence = "{USERNAME}{ENTER}";
|
||||
}
|
||||
else {
|
||||
sequence = "{USERNAME}{TAB}{PASSWORD}{ENTER}";
|
||||
}
|
||||
}
|
||||
|
||||
return sequence;
|
||||
}
|
||||
|
||||
bool AutoType::windowMatches(const QString& windowTitle, const QString& windowPattern)
|
||||
{
|
||||
QRegExp regExp;
|
||||
regExp.setCaseSensitivity(Qt::CaseInsensitive);
|
||||
|
||||
if (windowPattern.startsWith("//") && windowPattern.endsWith("//") && windowPattern.size() >= 4) {
|
||||
regExp.setPatternSyntax(QRegExp::RegExp2);
|
||||
regExp.setPattern(windowPattern.mid(2, windowPattern.size() - 4));
|
||||
}
|
||||
else {
|
||||
regExp.setPatternSyntax(QRegExp::Wildcard);
|
||||
regExp.setPattern(windowPattern);
|
||||
}
|
||||
|
||||
return regExp.exactMatch(windowTitle);
|
||||
}
|
||||
|
@ -65,6 +65,8 @@ private:
|
||||
void loadPlugin(const QString& pluginPath);
|
||||
bool parseActions(const QString& sequence, const Entry* entry, QList<AutoTypeAction*>& actions);
|
||||
QList<AutoTypeAction*> createActionFromTemplate(const QString& tmpl, const Entry* entry);
|
||||
QString autoTypeSequence(const Entry* entry, const QString& windowTitle = QString());
|
||||
bool windowMatches(const QString& windowTitle, const QString& windowPattern);
|
||||
|
||||
bool m_inAutoType;
|
||||
Qt::Key m_currentGlobalKey;
|
||||
|
@ -176,70 +176,6 @@ const AutoTypeAssociations* Entry::autoTypeAssociations() const
|
||||
return m_autoTypeAssociations;
|
||||
}
|
||||
|
||||
QString Entry::autoTypeSequence(const QString& windowTitle) const
|
||||
{
|
||||
if (!m_data.autoTypeEnabled) {
|
||||
return QString();
|
||||
}
|
||||
|
||||
bool enableSet = false;
|
||||
QString sequence;
|
||||
if (!windowTitle.isEmpty()) {
|
||||
bool match = false;
|
||||
Q_FOREACH (const AutoTypeAssociations::Association& assoc, m_autoTypeAssociations->getAll()) {
|
||||
if (windowMatches(windowTitle, assoc.window)) {
|
||||
if (!assoc.sequence.isEmpty()) {
|
||||
sequence = assoc.sequence;
|
||||
}
|
||||
else {
|
||||
sequence = m_data.defaultAutoTypeSequence;
|
||||
}
|
||||
match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!match) {
|
||||
return QString();
|
||||
}
|
||||
}
|
||||
else {
|
||||
sequence = m_data.defaultAutoTypeSequence;
|
||||
}
|
||||
|
||||
Group* group = m_group;
|
||||
do {
|
||||
if (!enableSet) {
|
||||
if (group->autoTypeEnabled() == Group::Disable) {
|
||||
return QString();
|
||||
}
|
||||
else if (group->autoTypeEnabled() == Group::Enable) {
|
||||
enableSet = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (sequence.isEmpty()) {
|
||||
sequence = group->defaultAutoTypeSequence();
|
||||
}
|
||||
|
||||
group = group->parentGroup();
|
||||
} while (group && (!enableSet || sequence.isEmpty()));
|
||||
|
||||
if (sequence.isEmpty() && (!username().isEmpty() || !password().isEmpty())) {
|
||||
if (username().isEmpty()) {
|
||||
sequence = "{PASSWORD}{ENTER}";
|
||||
}
|
||||
else if (password().isEmpty()) {
|
||||
sequence = "{USERNAME}{ENTER}";
|
||||
}
|
||||
else {
|
||||
sequence = "{USERNAME}{TAB}{PASSWORD}{ENTER}";
|
||||
}
|
||||
}
|
||||
|
||||
return sequence;
|
||||
}
|
||||
|
||||
QString Entry::title() const
|
||||
{
|
||||
return m_attributes->value("Title");
|
||||
@ -546,6 +482,11 @@ Group* Entry::group()
|
||||
return m_group;
|
||||
}
|
||||
|
||||
const Group* Entry::group() const
|
||||
{
|
||||
return m_group;
|
||||
}
|
||||
|
||||
void Entry::setGroup(Group* group)
|
||||
{
|
||||
Q_ASSERT(group);
|
||||
@ -601,23 +542,6 @@ bool Entry::match(const QString& searchTerm, Qt::CaseSensitivity caseSensitivity
|
||||
notes().contains(searchTerm, caseSensitivity);
|
||||
}
|
||||
|
||||
bool Entry::windowMatches(const QString& windowTitle, const QString& windowPattern)
|
||||
{
|
||||
QRegExp regExp;
|
||||
regExp.setCaseSensitivity(Qt::CaseInsensitive);
|
||||
|
||||
if (windowPattern.startsWith("//") && windowPattern.endsWith("//") && windowPattern.size() >= 4) {
|
||||
regExp.setPatternSyntax(QRegExp::RegExp2);
|
||||
regExp.setPattern(windowPattern.mid(2, windowPattern.size() - 4));
|
||||
}
|
||||
else {
|
||||
regExp.setPatternSyntax(QRegExp::Wildcard);
|
||||
regExp.setPattern(windowPattern);
|
||||
}
|
||||
|
||||
return regExp.exactMatch(windowTitle);
|
||||
}
|
||||
|
||||
QString Entry::resolvePlaceholders(const QString& str) const
|
||||
{
|
||||
QString result = str;
|
||||
|
@ -73,7 +73,6 @@ public:
|
||||
QString defaultAutoTypeSequence() const;
|
||||
AutoTypeAssociations* autoTypeAssociations();
|
||||
const AutoTypeAssociations* autoTypeAssociations() const;
|
||||
QString autoTypeSequence(const QString& windowTitle = QString()) const;
|
||||
QString title() const;
|
||||
QString url() const;
|
||||
QString username() const;
|
||||
@ -122,6 +121,7 @@ public:
|
||||
void endUpdate();
|
||||
|
||||
Group* group();
|
||||
const Group* group() const;
|
||||
void setGroup(Group* group);
|
||||
|
||||
void setUpdateTimeinfo(bool value);
|
||||
@ -143,7 +143,6 @@ private Q_SLOTS:
|
||||
private:
|
||||
const Database* database() const;
|
||||
template <class T> inline bool set(T& property, const T& value);
|
||||
static bool windowMatches(const QString& windowTitle, const QString& windowPattern);
|
||||
|
||||
Uuid m_uuid;
|
||||
EntryData m_data;
|
||||
|
Loading…
Reference in New Issue
Block a user