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.
This commit is contained in:
Marco 2017-05-15 21:06:14 +02:00 committed by thez3ro
parent 7bb9ea201c
commit fbfc2e4d07
No known key found for this signature in database
GPG Key ID: F628F9E41DD7C073
2 changed files with 56 additions and 33 deletions

View File

@ -21,6 +21,7 @@
#include <QApplication>
#include <QPluginLoader>
#include <iostream>
#include <QtWidgets/QErrorMessage>
#include "config-keepassx.h"
@ -328,8 +329,33 @@ bool AutoType::parseActions(const QString& sequence, const Entry* entry, QList<A
m_autoTypeDelay = config()->get("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<AutoTypeAction*> 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) {

View File

@ -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);