[users] Refactor constants

This commit is contained in:
Adriaan de Groot 2019-10-29 16:21:26 +01:00
parent 9cd1ef93bd
commit 8232ca626c
2 changed files with 8 additions and 10 deletions

View File

@ -45,6 +45,12 @@
#include <QRegExp> #include <QRegExp>
#include <QRegExpValidator> #include <QRegExpValidator>
static const QRegExp USERNAME_RX( "^[a-z_][a-z0-9_-]*[$]?$" );
static const QRegExp HOSTNAME_RX( "^[a-zA-Z0-9][-a-zA-Z0-9_]*$" );
static constexpr const int USERNAME_MAX_LENGTH = 31;
static constexpr const int HOSTNAME_MIN_LENGTH = 2;
static constexpr const int HOSTNAME_MAX_LENGTH = 63;
/** Add an error message and pixmap to a label. */ /** Add an error message and pixmap to a label. */
static inline void static inline void
labelError( QLabel* pix, QLabel* label, const QString& message ) labelError( QLabel* pix, QLabel* label, const QString& message )
@ -299,8 +305,7 @@ void
UsersPage::validateUsernameText( const QString& textRef ) UsersPage::validateUsernameText( const QString& textRef )
{ {
QString text( textRef ); QString text( textRef );
QRegExp rx( USERNAME_RX ); QRegExpValidator val( USERNAME_RX );
QRegExpValidator val( rx );
int pos = -1; int pos = -1;
if ( text.isEmpty() ) if ( text.isEmpty() )
@ -344,8 +349,7 @@ void
UsersPage::validateHostnameText( const QString& textRef ) UsersPage::validateHostnameText( const QString& textRef )
{ {
QString text = textRef; QString text = textRef;
QRegExp rx( HOSTNAME_RX ); QRegExpValidator val( HOSTNAME_RX );
QRegExpValidator val( rx );
int pos = -1; int pos = -1;
if ( text.isEmpty() ) if ( text.isEmpty() )

View File

@ -79,12 +79,6 @@ private:
PasswordCheckList m_passwordChecks; PasswordCheckList m_passwordChecks;
const QRegExp USERNAME_RX = QRegExp( "^[a-z_][a-z0-9_-]*[$]?$" );
const QRegExp HOSTNAME_RX = QRegExp( "^[a-zA-Z0-9][-a-zA-Z0-9_]*$" );
const int USERNAME_MAX_LENGTH = 31;
const int HOSTNAME_MIN_LENGTH = 2;
const int HOSTNAME_MAX_LENGTH = 63;
bool m_readyFullName; bool m_readyFullName;
bool m_readyUsername; bool m_readyUsername;
bool m_customUsername; bool m_customUsername;