Commit 1a2b258b authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Port validators to QRegularExpression

* Use QRegularExpression[Validator] instead of QRegExp[Validator]
* Take the additional regular expression as string instead of as
regular expression
* Make the file statics local statics

GnuPG-bug-id: 5916
parent 29a4359f
......@@ -246,9 +246,9 @@ public:
QValidator *validator = nullptr;
if (attr == QLatin1String("EMAIL")) {
validator = regex.isEmpty() ? Validation::email() : Validation::email(QRegExp(regex));
validator = regex.isEmpty() ? Validation::email() : Validation::email(regex);
} else if (!regex.isEmpty()) {
validator = new QRegExpValidator(QRegExp(regex), nullptr);
validator = new QRegularExpressionValidator{QRegularExpression{regex}, nullptr};
}
QLineEdit *le = addRow(ui.gridLayout, label, preset, validator, readonly, required);
......
......@@ -62,7 +62,7 @@
#include <KMessageBox>
#include <QIcon>
#include <QRegExpValidator>
#include <QRegularExpressionValidator>
#include <QLineEdit>
#include <QMetaProperty>
#include <QDir>
......@@ -1515,13 +1515,13 @@ void EnterDetailsPage::updateForm()
QValidator *validator = nullptr;
if (attr == QLatin1String("EMAIL")) {
row = row_index_of(ui.emailLE, ui.gridLayout);
validator = regex.isEmpty() ? Validation::email() : Validation::email(QRegExp(regex));
validator = regex.isEmpty() ? Validation::email() : Validation::email(regex);
} else if (attr == QLatin1String("NAME") || attr == QLatin1String("CN")) {
if ((pgp() && attr == QLatin1String("CN")) || (!pgp() && attr == QLatin1String("NAME"))) {
continue;
}
if (pgp()) {
validator = regex.isEmpty() ? Validation::pgpName() : Validation::pgpName(QRegExp(regex));
validator = regex.isEmpty() ? Validation::pgpName() : Validation::pgpName(regex);
}
row = row_index_of(ui.nameLE, ui.gridLayout);
} else {
......@@ -1529,7 +1529,7 @@ void EnterDetailsPage::updateForm()
row = add_row(ui.gridLayout, &dynamicWidgets);
}
if (!validator && !regex.isEmpty()) {
validator = new QRegExpValidator(QRegExp(regex), nullptr);
validator = new QRegularExpressionValidator{QRegularExpression{regex}, nullptr};
}
QLineEdit *le = adjust_row(ui.gridLayout, row, label, preset, validator, readonly, required);
......
......@@ -17,15 +17,11 @@
#include "kleopatra_debug.h"
#include <QRegExp>
#include <QRegularExpression>
using namespace Kleo;
// these are modeled after gnupg/g10/keygen.c:ask_user_id:
static const QString name_rx = QStringLiteral("[^0-9<>][^<>@]{3,}");
static const QString comment_rx = QStringLiteral("[^()]*");
namespace
{
......@@ -51,28 +47,31 @@ QValidator *Validation::email(QObject *parent)
return new EMailValidator(parent);
}
QValidator *Validation::email(const QRegExp &addRX, QObject *parent)
QValidator *Validation::email(const QString &addRX, QObject *parent)
{
return new MultiValidator(email(), new QRegExpValidator(addRX, nullptr), parent);
return new MultiValidator{email(), new QRegularExpressionValidator{QRegularExpression{addRX}, nullptr}, parent};
}
QValidator *Validation::pgpName(QObject *parent)
{
return new QRegExpValidator(QRegExp(name_rx), parent);
// this regular expression is modeled after gnupg/g10/keygen.c:ask_user_id:
static const auto name_rx = QRegularExpression{QStringLiteral("[^0-9<>][^<>@]{3,}")};
return new QRegularExpressionValidator{name_rx, parent};
}
QValidator *Validation::pgpName(const QRegExp &addRX, QObject *parent)
QValidator *Validation::pgpName(const QString &addRX, QObject *parent)
{
return new MultiValidator(pgpName(), new QRegExpValidator(addRX, nullptr), parent);
return new MultiValidator{pgpName(), new QRegularExpressionValidator{QRegularExpression{addRX}, nullptr}, parent};
}
QValidator *Validation::pgpComment(QObject *parent)
{
return new QRegExpValidator(QRegExp(comment_rx), parent);
// this regular expression is modeled after gnupg/g10/keygen.c:ask_user_id:
static const auto comment_rx = QRegularExpression{QStringLiteral("[^()]*")};
return new QRegularExpressionValidator{comment_rx, parent};
}
QValidator *Validation::pgpComment(const QRegExp &addRX, QObject *parent)
QValidator *Validation::pgpComment(const QString &addRX, QObject *parent)
{
return new MultiValidator(pgpComment(), new QRegExpValidator(addRX, nullptr), parent);
return new MultiValidator{pgpComment(), new QRegularExpressionValidator{QRegularExpression{addRX}, nullptr}, parent};
}
......@@ -9,9 +9,9 @@
#pragma once
#include <QObject>
class QObject;
class QString;
class QValidator;
class QRegExp;
namespace Kleo
{
......@@ -22,9 +22,9 @@ QValidator *email(QObject *parent = nullptr);
QValidator *pgpName(QObject *parent = nullptr);
QValidator *pgpComment(QObject *parent = nullptr);
QValidator *email(const QRegExp &additionalRegExp, QObject *parent = nullptr);
QValidator *pgpName(const QRegExp &additionalRegExp, QObject *parent = nullptr);
QValidator *pgpComment(const QRegExp &additionalRegExp, QObject *parent = nullptr);
QValidator *email(const QString &additionalRegExp, QObject *parent = nullptr);
QValidator *pgpName(const QString &additionalRegExp, QObject *parent = nullptr);
QValidator *pgpComment(const QString &additionalRegExp, QObject *parent = nullptr);
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment