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
This commit is contained in:
Marco 2017-06-03 12:32:46 +02:00 committed by thez3ro
parent 7ceac05395
commit 8ca444aee0
No known key found for this signature in database
GPG Key ID: F628F9E41DD7C073
3 changed files with 46 additions and 31 deletions

View File

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

View File

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

View File

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