mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
Make InputValidator class members static
This commit is contained in:
parent
7502f167ae
commit
b3bb0531de
6 changed files with 22 additions and 46 deletions
|
@ -15,8 +15,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MATRIXIDVALIDATOR_H
|
||||
#define MATRIXIDVALIDATOR_H
|
||||
#ifndef MATRIX_INPUT_VALIDATOR_H
|
||||
#define MATRIX_INPUT_VALIDATOR_H
|
||||
|
||||
#include <QRegExp>
|
||||
#include <QRegExpValidator>
|
||||
|
@ -24,26 +24,11 @@
|
|||
class InputValidator
|
||||
{
|
||||
public:
|
||||
InputValidator(QObject *parent = 0);
|
||||
|
||||
// Validators for the different types of input.
|
||||
QRegExpValidator *id_;
|
||||
QRegExpValidator *localpart_;
|
||||
QRegExpValidator *password_;
|
||||
QRegExpValidator *domain_;
|
||||
|
||||
private:
|
||||
// Regular expression used to validate the whole matrix id.
|
||||
const QRegExp matrix_id_;
|
||||
|
||||
// Regular expressino to validate the matrix localpart.
|
||||
const QRegExp matrix_localpart_;
|
||||
|
||||
// Regular expression to validate a password for a matrix account.
|
||||
const QRegExp matrix_password_;
|
||||
|
||||
// Regular expression to validate a domain name.
|
||||
const QRegExp server_domain_;
|
||||
static QRegExpValidator Id;
|
||||
static QRegExpValidator Localpart;
|
||||
static QRegExpValidator Password;
|
||||
static QRegExpValidator Domain;
|
||||
};
|
||||
|
||||
#endif // MATRIXIDVALIDATOR_H
|
||||
#endif // MATRIX_INPUT_VALIDATOR_H
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include <QWidget>
|
||||
|
||||
#include "FlatButton.h"
|
||||
#include "InputValidator.h"
|
||||
#include "LoginSettings.h"
|
||||
#include "MatrixClient.h"
|
||||
#include "OverlayModal.h"
|
||||
|
@ -84,8 +83,6 @@ private:
|
|||
LoginSettings *login_settings_;
|
||||
QString custom_domain_;
|
||||
|
||||
InputValidator *matrix_id_validator_;
|
||||
|
||||
// Matrix client API provider.
|
||||
QSharedPointer<MatrixClient> client_;
|
||||
};
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
|
||||
#include "Avatar.h"
|
||||
#include "FlatButton.h"
|
||||
#include "InputValidator.h"
|
||||
#include "MatrixClient.h"
|
||||
#include "RaisedButton.h"
|
||||
#include "TextField.h"
|
||||
|
@ -71,8 +70,6 @@ private:
|
|||
TextField *password_confirmation_;
|
||||
TextField *server_input_;
|
||||
|
||||
InputValidator *validator_;
|
||||
|
||||
// Matrix client API provider.
|
||||
QSharedPointer<MatrixClient> client_;
|
||||
};
|
||||
|
|
|
@ -17,14 +17,12 @@
|
|||
|
||||
#include "InputValidator.h"
|
||||
|
||||
InputValidator::InputValidator(QObject *parent)
|
||||
: matrix_id_("@[A-Za-z0-9._%+-]+:[A-Za-z0-9.-]{1,126}\\.[A-Za-z]{1,63}")
|
||||
, matrix_localpart_("[A-za-z0-9._%+-]{3,}")
|
||||
, matrix_password_(".{8,}")
|
||||
, server_domain_("(?!\\-)(?:[a-zA-Z\\d\\-]{0,62}[a-zA-Z\\d]\\.){1,126}(?!\\d+)[a-zA-Z\\d]{1,63}")
|
||||
{
|
||||
id_ = new QRegExpValidator(matrix_id_, parent);
|
||||
localpart_ = new QRegExpValidator(matrix_localpart_, parent);
|
||||
password_ = new QRegExpValidator(matrix_password_, parent);
|
||||
domain_ = new QRegExpValidator(server_domain_, parent);
|
||||
}
|
||||
const QRegExp MXID_REGEX("@[A-Za-z0-9._%+-]+:[A-Za-z0-9.-]{1,126}\\.[A-Za-z]{1,63}");
|
||||
const QRegExp LOCALPART_REGEX("[A-za-z0-9._%+-]{3,}");
|
||||
const QRegExp PASSWORD_REGEX(".{8,}");
|
||||
const QRegExp DOMAIN_REGEX("(?!\\-)(?:[a-zA-Z\\d\\-]{0,62}[a-zA-Z\\d]\\.){1,126}(?!\\d+)[a-zA-Z\\d]{1,63}");
|
||||
|
||||
QRegExpValidator InputValidator::Id(MXID_REGEX);
|
||||
QRegExpValidator InputValidator::Localpart(LOCALPART_REGEX);
|
||||
QRegExpValidator InputValidator::Password(PASSWORD_REGEX);
|
||||
QRegExpValidator InputValidator::Domain(DOMAIN_REGEX);
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include <QDebug>
|
||||
|
||||
#include "InputValidator.h"
|
||||
#include "LoginPage.h"
|
||||
|
||||
LoginPage::LoginPage(QSharedPointer<MatrixClient> client, QWidget *parent)
|
||||
|
@ -25,8 +26,6 @@ LoginPage::LoginPage(QSharedPointer<MatrixClient> client, QWidget *parent)
|
|||
, login_settings_{nullptr}
|
||||
, client_{client}
|
||||
{
|
||||
matrix_id_validator_ = new InputValidator(this);
|
||||
|
||||
top_layout_ = new QVBoxLayout();
|
||||
|
||||
top_bar_layout_ = new QHBoxLayout();
|
||||
|
@ -133,7 +132,7 @@ LoginPage::LoginPage(QSharedPointer<MatrixClient> client, QWidget *parent)
|
|||
connect(client_.data(), SIGNAL(loginError(QString)), this, SLOT(loginError(QString)));
|
||||
connect(advanced_settings_button_, SIGNAL(clicked()), this, SLOT(showSettingsModal()));
|
||||
|
||||
matrixid_input_->setValidator(matrix_id_validator_->id_);
|
||||
matrixid_input_->setValidator(&InputValidator::Id);
|
||||
}
|
||||
|
||||
void LoginPage::loginError(QString error)
|
||||
|
|
|
@ -18,11 +18,11 @@
|
|||
#include <QDebug>
|
||||
#include <QToolTip>
|
||||
|
||||
#include "InputValidator.h"
|
||||
#include "RegisterPage.h"
|
||||
|
||||
RegisterPage::RegisterPage(QSharedPointer<MatrixClient> client, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, validator_(new InputValidator(parent))
|
||||
, client_(client)
|
||||
{
|
||||
top_layout_ = new QVBoxLayout();
|
||||
|
@ -132,9 +132,9 @@ RegisterPage::RegisterPage(QSharedPointer<MatrixClient> client, QWidget *parent)
|
|||
connect(server_input_, SIGNAL(returnPressed()), register_button_, SLOT(click()));
|
||||
connect(client_.data(), SIGNAL(registerError(const QString &)), this, SLOT(registerError(const QString &)));
|
||||
|
||||
username_input_->setValidator(validator_->localpart_);
|
||||
password_input_->setValidator(validator_->password_);
|
||||
server_input_->setValidator(validator_->domain_);
|
||||
username_input_->setValidator(&InputValidator::Localpart);
|
||||
password_input_->setValidator(&InputValidator::Password);
|
||||
server_input_->setValidator(&InputValidator::Domain);
|
||||
|
||||
setLayout(top_layout_);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue