Much improved validation of custom parameters.
This commit is contained in:
parent
e718e31458
commit
048f0f6945
@ -833,6 +833,9 @@
|
|||||||
<bold>true</bold>
|
<bold>true</bold>
|
||||||
</font>
|
</font>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Your custom parameters will be ignored entirely, if you don't fix them!</string>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Invalid parameter entered!</string>
|
<string>Invalid parameter entered!</string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -60,43 +60,39 @@
|
|||||||
class StringValidator : public QValidator
|
class StringValidator : public QValidator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
StringValidator(QLabel *notifier) : m_notifier(notifier) { m_notifier->hide(); }
|
StringValidator(QLabel *notifier)
|
||||||
|
:
|
||||||
|
m_notifier(notifier)
|
||||||
|
{
|
||||||
|
m_notifier->hide();
|
||||||
|
}
|
||||||
|
|
||||||
virtual State validate(QString &input, int &pos) const
|
virtual State validate(QString &input, int &pos) const
|
||||||
{
|
{
|
||||||
bool invalid = false;
|
bool invalid = false;
|
||||||
|
|
||||||
invalid = invalid || (input.contains(" -B") || input.startsWith("-B"));
|
invalid = invalid || checkParam(input, "B");
|
||||||
invalid = invalid || (input.contains(" -o") || input.startsWith("-o"));
|
invalid = invalid || checkParam(input, "o");
|
||||||
invalid = invalid || (input.contains(" -h") || input.startsWith("-h"));
|
invalid = invalid || checkParam(input, "h");
|
||||||
invalid = invalid || (input.contains(" -p") || input.startsWith("-p"));
|
invalid = invalid || checkParam(input, "p");
|
||||||
|
invalid = invalid || checkParam(input, "q");
|
||||||
|
|
||||||
invalid = invalid || input.contains("--fps", Qt::CaseInsensitive);
|
invalid = invalid || checkParam(input, "fps");
|
||||||
invalid = invalid || input.contains("--frames", Qt::CaseInsensitive);
|
invalid = invalid || checkParam(input, "frames");
|
||||||
invalid = invalid || input.contains("--preset", Qt::CaseInsensitive);
|
invalid = invalid || checkParam(input, "preset");
|
||||||
invalid = invalid || input.contains("--tune", Qt::CaseInsensitive);
|
invalid = invalid || checkParam(input, "tune");
|
||||||
invalid = invalid || input.contains("--profile", Qt::CaseInsensitive);
|
invalid = invalid || checkParam(input, "profile");
|
||||||
invalid = invalid || input.contains("--stdin", Qt::CaseInsensitive);
|
invalid = invalid || checkParam(input, "stdin");
|
||||||
invalid = invalid || input.contains("--crf", Qt::CaseInsensitive);
|
invalid = invalid || checkParam(input, "crf");
|
||||||
invalid = invalid || input.contains("--bitrate", Qt::CaseInsensitive);
|
invalid = invalid || checkParam(input, "bitrate");
|
||||||
invalid = invalid || input.contains("--qp", Qt::CaseInsensitive);
|
invalid = invalid || checkParam(input, "qp");
|
||||||
invalid = invalid || input.contains("--pass", Qt::CaseInsensitive);
|
invalid = invalid || checkParam(input, "pass");
|
||||||
invalid = invalid || input.contains("--stats", Qt::CaseInsensitive);
|
invalid = invalid || checkParam(input, "stats");
|
||||||
invalid = invalid || input.contains("--output", Qt::CaseInsensitive);
|
invalid = invalid || checkParam(input, "output");
|
||||||
invalid = invalid || input.contains("--help", Qt::CaseInsensitive);
|
invalid = invalid || checkParam(input, "help");
|
||||||
invalid = invalid || input.contains("--quiet", Qt::CaseInsensitive);
|
invalid = invalid || checkParam(input, "quiet");
|
||||||
|
|
||||||
if(invalid)
|
return invalid ? QValidator::Intermediate : QValidator::Acceptable;
|
||||||
{
|
|
||||||
MessageBeep(MB_ICONWARNING);
|
|
||||||
if(m_notifier->isHidden())
|
|
||||||
{
|
|
||||||
m_notifier->show();
|
|
||||||
QTimer::singleShot(1000, m_notifier, SLOT(hide()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return invalid ? QValidator::Invalid : QValidator::Acceptable;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void fixup(QString &input) const
|
virtual void fixup(QString &input) const
|
||||||
@ -106,6 +102,46 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
QLabel *const m_notifier;
|
QLabel *const m_notifier;
|
||||||
|
|
||||||
|
bool checkParam(const QString &input, const QString ¶m) const
|
||||||
|
{
|
||||||
|
bool flag = false;
|
||||||
|
if(param.length() > 1)
|
||||||
|
{
|
||||||
|
flag = flag || input.contains(QString("--%1 ").arg(param), Qt::CaseInsensitive);
|
||||||
|
flag = flag || input.contains(QString("--%1*").arg(param), Qt::CaseInsensitive);
|
||||||
|
flag = flag || input.contains(QString("--%1?").arg(param), Qt::CaseInsensitive);
|
||||||
|
flag = flag || input.contains(QString("--%1<").arg(param), Qt::CaseInsensitive);
|
||||||
|
flag = flag || input.contains(QString("--%1>").arg(param), Qt::CaseInsensitive);
|
||||||
|
flag = flag || input.contains(QString("--%1/").arg(param), Qt::CaseInsensitive);
|
||||||
|
flag = flag || input.contains(QString("--%1\"").arg(param), Qt::CaseInsensitive);
|
||||||
|
flag = flag || input.contains(QString("--%1\\").arg(param), Qt::CaseInsensitive);
|
||||||
|
flag = flag || input.endsWith(QString("--%1").arg(param), Qt::CaseInsensitive);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
flag = flag || input.contains(QString(" -%1").arg(param));
|
||||||
|
flag = flag || input.contains(QString("*-%1").arg(param));
|
||||||
|
flag = flag || input.contains(QString("?-%1").arg(param));
|
||||||
|
flag = flag || input.contains(QString("<-%1").arg(param));
|
||||||
|
flag = flag || input.contains(QString(">-%1").arg(param));
|
||||||
|
flag = flag || input.contains(QString("/-%1").arg(param));
|
||||||
|
flag = flag || input.contains(QString("\"-%1").arg(param));
|
||||||
|
flag = flag || input.contains(QString("\\-%1").arg(param));
|
||||||
|
flag = flag || input.startsWith(QString("-%1").arg(param));
|
||||||
|
}
|
||||||
|
if(flag)
|
||||||
|
{
|
||||||
|
MessageBeep(MB_ICONWARNING);
|
||||||
|
m_notifier->setText(tr("Invalid parameter entered: %1").arg((param.length() > 1) ? QString("--%1").arg(param) : QString("-%1").arg(param)));
|
||||||
|
if(m_notifier->isHidden()) m_notifier->show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(m_notifier->isVisible()) m_notifier->hide();
|
||||||
|
}
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
@ -204,6 +240,8 @@ void AddJobDialog::showEvent(QShowEvent *event)
|
|||||||
generateOutputFileName(QDir::fromNativeSeparators(editSource->text()));
|
generateOutputFileName(QDir::fromNativeSeparators(editSource->text()));
|
||||||
buttonAccept->setFocus();
|
buttonAccept->setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
labelNotification->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AddJobDialog::eventFilter(QObject *o, QEvent *e)
|
bool AddJobDialog::eventFilter(QObject *o, QEvent *e)
|
||||||
@ -241,37 +279,40 @@ void AddJobDialog::accept(void)
|
|||||||
|
|
||||||
if(editOutput->text().trimmed().isEmpty())
|
if(editOutput->text().trimmed().isEmpty())
|
||||||
{
|
{
|
||||||
QMessageBox::warning(this, tr("Not Selected!"), tr("Please select a valid output file first!"));
|
QMessageBox::warning(this, tr("Not Selected!"), tr("<nobr>Please select a valid output file first!</nobr>"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QFileInfo sourceFile = QFileInfo(editSource->text());
|
QFileInfo sourceFile = QFileInfo(editSource->text());
|
||||||
if(!(sourceFile.exists() && sourceFile.isFile()))
|
if(!(sourceFile.exists() && sourceFile.isFile()))
|
||||||
{
|
{
|
||||||
QMessageBox::warning(this, tr("Not Found!"), tr("The selected source file could not be found!"));
|
QMessageBox::warning(this, tr("Not Found!"), tr("<nobr>The selected source file could not be found!</nobr>"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QFileInfo outputDir = QFileInfo(QFileInfo(editOutput->text()).path());
|
QFileInfo outputDir = QFileInfo(QFileInfo(editOutput->text()).path());
|
||||||
if(!(outputDir.exists() && outputDir.isDir() && outputDir.isWritable()))
|
if(!(outputDir.exists() && outputDir.isDir() && outputDir.isWritable()))
|
||||||
{
|
{
|
||||||
QMessageBox::warning(this, tr("Not Writable!"), tr("Output directory does not exist or is not writable!"));
|
QMessageBox::warning(this, tr("Not Writable!"), tr("<nobr>Output directory does not exist or is not writable!</nobr>"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QFileInfo outputFile = QFileInfo(editOutput->text());
|
QFileInfo outputFile = QFileInfo(editOutput->text());
|
||||||
if(outputFile.exists() && outputFile.isFile())
|
if(outputFile.exists() && outputFile.isFile())
|
||||||
{
|
{
|
||||||
if(QMessageBox::question(this, tr("Already Exists!"), tr("Output file already exists! Overwrite?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes)
|
int ret = QMessageBox::question(this, tr("Already Exists!"), tr("<nobr>Output file already exists! Overwrite?</nobr>"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
|
||||||
{
|
if(ret != QMessageBox::Yes) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if(outputFile.exists() && (!outputFile.isFile()))
|
if(outputFile.exists() && (!outputFile.isFile()))
|
||||||
{
|
{
|
||||||
QMessageBox::warning(this, tr("Not a File!"), tr("Selected output files does not appear to be a file!"));
|
QMessageBox::warning(this, tr("Not a File!"), tr("<nobr>Selected output files does not appear to be a file!</nobr>"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if(!editCustomParams->hasAcceptableInput())
|
||||||
|
{
|
||||||
|
int ret = QMessageBox::warning(this, tr("Invalid Params"), tr("<nobr>Your custom parameters are invalid and will be discarded!</nobr>"), QMessageBox::Ignore | QMessageBox::Cancel, QMessageBox::Cancel);
|
||||||
|
if(ret != QMessageBox::Ignore) return;
|
||||||
|
}
|
||||||
|
|
||||||
//Save directories
|
//Save directories
|
||||||
const QString appDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
|
const QString appDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
|
||||||
@ -603,7 +644,7 @@ void AddJobDialog::saveOptions(OptionsModel *options)
|
|||||||
options->setPreset(cbxPreset->model()->data(cbxPreset->model()->index(cbxPreset->currentIndex(), 0)).toString());
|
options->setPreset(cbxPreset->model()->data(cbxPreset->model()->index(cbxPreset->currentIndex(), 0)).toString());
|
||||||
options->setTune(cbxTuning->model()->data(cbxTuning->model()->index(cbxTuning->currentIndex(), 0)).toString());
|
options->setTune(cbxTuning->model()->data(cbxTuning->model()->index(cbxTuning->currentIndex(), 0)).toString());
|
||||||
options->setProfile(cbxProfile->model()->data(cbxProfile->model()->index(cbxProfile->currentIndex(), 0)).toString());
|
options->setProfile(cbxProfile->model()->data(cbxProfile->model()->index(cbxProfile->currentIndex(), 0)).toString());
|
||||||
options->setCustom(editCustomParams->text().simplified());
|
options->setCustom(editCustomParams->hasAcceptableInput() ? editCustomParams->text().simplified() : QString());
|
||||||
}
|
}
|
||||||
|
|
||||||
QString AddJobDialog::makeFileFilter(void)
|
QString AddJobDialog::makeFileFilter(void)
|
||||||
|
Loading…
Reference in New Issue
Block a user