From fbfc2e4d070fe9475fa08e94d68e27ea7b7658fb Mon Sep 17 00:00:00 2001 From: Marco Date: Mon, 15 May 2017 21:06:14 +0200 Subject: [PATCH] create message boxes for saving editing autotypes statements, fix multiple messages problem on autotype execution You now get an error when you try to save incorrect autotype statements and warnings if you have high delays or much repetiton in your statement. Also you will now only get one warning if you want to perfom high delayed or often repeated statements. --- src/autotype/AutoType.cpp | 54 ++++++++++++++++--------------- src/gui/entry/EditEntryWidget.cpp | 35 ++++++++++++++++---- 2 files changed, 56 insertions(+), 33 deletions(-) diff --git a/src/autotype/AutoType.cpp b/src/autotype/AutoType.cpp index ac3be5b90..4ad83b086 100644 --- a/src/autotype/AutoType.cpp +++ b/src/autotype/AutoType.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include "config-keepassx.h" @@ -328,8 +329,33 @@ bool AutoType::parseActions(const QString& sequence, const Entry* entry, QListget("AutoTypeDelay").toInt(); - for (const QChar& ch : sequence) { - if (inTmpl) { + if (!AutoType::checkSyntax(sequence)) { + QMessageBox messageBox; + messageBox.critical(0, "AutoType", tr("The Syntax of your AutoType statement is incorrect!")); + return false; + } + else if (AutoType::checkHighDelay(sequence)) { + 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 false; + } + } + else if (AutoType::checkHighRepetition(sequence)) { + 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 false; + } + } + + for (const QChar &ch : sequence) { if (ch == '{') { qWarning("Syntax error in auto-type sequence."); return false; @@ -391,30 +417,6 @@ QList AutoType::createActionFromTemplate(const QString& tmpl, c if (num == 0) { return list; } - // some safety checks - else if (tmplName.compare("delay",Qt::CaseInsensitive)==0) { - if (num > 10000) { - 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 list; - } - } - } - else if (num > 100) { - 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 list; - } - - } } if (tmplName.compare("tab", Qt::CaseInsensitive) == 0) { diff --git a/src/gui/entry/EditEntryWidget.cpp b/src/gui/entry/EditEntryWidget.cpp index f1bdc8145..171590513 100644 --- a/src/gui/entry/EditEntryWidget.cpp +++ b/src/gui/entry/EditEntryWidget.cpp @@ -767,18 +767,39 @@ void EditEntryWidget::updateEntryData(Entry* entry) const } else { if (!AutoType::checkSyntax(m_autoTypeUi->sequenceEdit->text())) { - //@TODO handle wrong syntax - std::cout << "wrong syntax\n"; + //handle wrong syntax + QMessageBox messageBox; + messageBox.critical(0, + "AutoType", + tr("The Syntax of your AutoType statement is incorrect! It won't be saved!")); + } else if (AutoType::checkHighDelay(m_autoTypeUi->sequenceEdit->text())) { - //@TODO handle too long delay - std::cout << "too long delay\n"; + //handle too long delay + QMessageBox::StandardButton reply; + reply = QMessageBox::question(0, + "AutoType", + tr("This AutoType command contains a very long delay. Do you really want to save it?")); + + if (reply == QMessageBox::Yes) { + entry->setDefaultAutoTypeSequence(m_autoTypeUi->sequenceEdit->text()); + } } else if (AutoType::checkHighRepetition(m_autoTypeUi->sequenceEdit->text())) { - //@TODO handle too much repetition - std::cout << "too much repetition\n"; + //handle too much repetition + QMessageBox::StandardButton reply; + reply = QMessageBox::question(0, + "AutoType", + tr("This AutoType command contains arguments which are repeated very often. Do you really want to save it?")); + + if (reply == QMessageBox::Yes) { + entry->setDefaultAutoTypeSequence(m_autoTypeUi->sequenceEdit->text()); + } } - entry->setDefaultAutoTypeSequence(m_autoTypeUi->sequenceEdit->text()); + else { + entry->setDefaultAutoTypeSequence(m_autoTypeUi->sequenceEdit->text()); + } + } entry->autoTypeAssociations()->copyDataFrom(m_autoTypeAssoc);