diff --git a/src/autotype/AutoType.cpp b/src/autotype/AutoType.cpp index 9400f14c4..a33487449 100644 --- a/src/autotype/AutoType.cpp +++ b/src/autotype/AutoType.cpp @@ -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& 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 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); +} diff --git a/src/autotype/AutoType.h b/src/autotype/AutoType.h index 0dcbb0fff..81d625d83 100644 --- a/src/autotype/AutoType.h +++ b/src/autotype/AutoType.h @@ -65,6 +65,8 @@ private: void loadPlugin(const QString& pluginPath); bool parseActions(const QString& sequence, const Entry* entry, QList& actions); QList 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; diff --git a/src/core/Entry.cpp b/src/core/Entry.cpp index 2643f7bca..08186c0fc 100644 --- a/src/core/Entry.cpp +++ b/src/core/Entry.cpp @@ -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; diff --git a/src/core/Entry.h b/src/core/Entry.h index 9a292f359..c629e3629 100644 --- a/src/core/Entry.h +++ b/src/core/Entry.h @@ -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 inline bool set(T& property, const T& value); - static bool windowMatches(const QString& windowTitle, const QString& windowPattern); Uuid m_uuid; EntryData m_data;