From 8ca444aee005dd37284d83591a6f3c18f5c2ef66 Mon Sep 17 00:00:00 2001 From: Marco Date: Sat, 3 Jun 2017 12:32:46 +0200 Subject: [PATCH] add a method to perform the autotype sequence showing graphical dialogs Dialogs are show when the syntax of the autotype statement is wrong or contains long delays or statements which are repeated very often --- src/autotype/AutoType.cpp | 38 +++++++++++++++++++++++++++++++++++++- src/autotype/AutoType.h | 4 ++++ src/gui/DatabaseWidget.cpp | 35 +++++------------------------------ 3 files changed, 46 insertions(+), 31 deletions(-) diff --git a/src/autotype/AutoType.cpp b/src/autotype/AutoType.cpp index e4618f749..319814a3e 100644 --- a/src/autotype/AutoType.cpp +++ b/src/autotype/AutoType.cpp @@ -252,7 +252,8 @@ void AutoType::performAutoTypeFromGlobal(Entry* entry, const QString& sequence) m_plugin->raiseWindow(m_windowFromGlobal); m_inAutoType = false; - performAutoType(entry, nullptr, sequence, m_windowFromGlobal); + + performAutoTypeWithSyntaxCheckingDialog(entry, nullptr, sequence, m_windowFromGlobal); } void AutoType::resetInAutoType() @@ -714,3 +715,38 @@ bool AutoType::checkHighRepetition(const QString &string) highRepetition.setPatternSyntax(QRegExp::RegExp); return highRepetition.exactMatch(string); } + +void +AutoType::performAutoTypeWithSyntaxCheckingDialog(const Entry *entry, + QWidget *hideWindow, + const QString &customSequence, + WId window) +{ + if (!AutoType::checkSyntax(entry->effectiveAutoTypeSequence())) { + QMessageBox messageBox; + messageBox.critical(0, "AutoType", tr("The Syntax of your AutoType statement is incorrect!")); + return; + } + else if (AutoType::checkHighDelay(entry->effectiveAutoTypeSequence())) { + QMessageBox::StandardButton reply; + reply = QMessageBox::question(0, + "AutoType", + tr("This AutoType command contains a very long delay. Do you really want to execute it?")); + + if (reply == QMessageBox::No) { + return; + } + } + else if (AutoType::checkHighRepetition(entry->effectiveAutoTypeSequence())) { + QMessageBox::StandardButton reply; + reply = QMessageBox::question(0, + "AutoType", + tr("This AutoType command contains arguments which are repeated very often. Do you really want to execute it?")); + + if (reply == QMessageBox::No) { + return; + } + } + performAutoType(entry, hideWindow, customSequence, window); + +} diff --git a/src/autotype/AutoType.h b/src/autotype/AutoType.h index 92505b7de..90d12a7f6 100644 --- a/src/autotype/AutoType.h +++ b/src/autotype/AutoType.h @@ -45,6 +45,10 @@ public: static bool checkSyntax(const QString &string); static bool checkHighRepetition(const QString &string); static bool checkHighDelay(const QString &string); + void performAutoTypeWithSyntaxCheckingDialog(const Entry *entry, + QWidget *hideWindow = nullptr, + const QString &customSequence = QString(), + WId window = 0); inline bool isAvailable() { return m_plugin; diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index 3fe403fc7..3f5222e1d 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -584,32 +584,7 @@ void DatabaseWidget::performAutoType() return; } - if (!AutoType::checkSyntax(currentEntry->effectiveAutoTypeSequence())) { - QMessageBox messageBox; - messageBox.critical(0, "AutoType", tr("The Syntax of your AutoType statement is incorrect!")); - return; - } - else if (AutoType::checkHighDelay(currentEntry->effectiveAutoTypeSequence())) { - QMessageBox::StandardButton reply; - reply = QMessageBox::question(0, - "AutoType", - tr("This AutoType command contains a very long delay. Do you really want to execute it?")); - - if (reply == QMessageBox::No) { - return; - } - } - else if (AutoType::checkHighRepetition(currentEntry->effectiveAutoTypeSequence())) { - QMessageBox::StandardButton reply; - reply = QMessageBox::question(0, - "AutoType", - tr("This AutoType command contains arguments which are repeated very often. Do you really want to execute it?")); - - if (reply == QMessageBox::No) { - return; - } - } - autoType()->performAutoType(currentEntry, window()); + autoType()->performAutoTypeWithSyntaxCheckingDialog(currentEntry, window()); } void DatabaseWidget::openUrl() @@ -638,7 +613,7 @@ void DatabaseWidget::openUrlForEntry(Entry* entry) } return; } - + // otherwise ask user if (urlString.length() > 6) { QString cmdTruncated = urlString.mid(6); @@ -652,7 +627,7 @@ void DatabaseWidget::openUrlForEntry(Entry* entry) this ); msgbox.setDefaultButton(QMessageBox::No); - + QCheckBox* checkbox = new QCheckBox(tr("Remember my choice"), &msgbox); msgbox.setCheckBox(checkbox); bool remember = false; @@ -661,12 +636,12 @@ void DatabaseWidget::openUrlForEntry(Entry* entry) remember = true; } }); - + int result = msgbox.exec(); if (result == QMessageBox::Yes) { QProcess::startDetached(urlString.mid(6)); } - + if (remember) { entry->attributes()->set(EntryAttributes::RememberCmdExecAttr, result == QMessageBox::Yes ? "1" : "0");