Use QLabel to display registration errors

This commit is contained in:
Konstantinos Sideris 2017-04-07 19:25:06 +03:00
parent 73e73f46ea
commit c7c3ee19ee
5 changed files with 30 additions and 21 deletions

View file

@ -1,13 +1,13 @@
run: build run: debug
./build/nheko ./build/nheko
debug: debug:
@cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=Debug @cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=Debug
@make -C build @make -C build -j2
release-debug: release-debug:
@cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=RelWithDebInfo @cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=RelWithDebInfo
@make -C build @make -C build -j2
clean: clean:
rm -rf build rm -rf build

View file

@ -43,6 +43,10 @@ signals:
// responsible for the actual registering on the remote Matrix server. // responsible for the actual registering on the remote Matrix server.
void registerUser(const QString &username, const QString &password, const QString &server); void registerUser(const QString &username, const QString &password, const QString &server);
public slots:
// Display registration specific errors to the user.
void registerError(const QString &msg);
private slots: private slots:
void onBackButtonClicked(); void onBackButtonClicked();
void onRegisterButtonClicked(); void onRegisterButtonClicked();
@ -55,6 +59,7 @@ private:
QHBoxLayout *button_layout_; QHBoxLayout *button_layout_;
QLabel *logo_; QLabel *logo_;
QLabel *error_label_;
FlatButton *back_button_; FlatButton *back_button_;
RaisedButton *register_button_; RaisedButton *register_button_;

View file

@ -55,7 +55,7 @@ LoginPage::LoginPage(QWidget *parent)
form_layout_ = new QVBoxLayout(); form_layout_ = new QVBoxLayout();
form_layout_->setSpacing(20); form_layout_->setSpacing(20);
form_layout_->setContentsMargins(0, 00, 0, 30); form_layout_->setContentsMargins(0, 0, 0, 30);
form_widget_->setLayout(form_layout_); form_widget_->setLayout(form_layout_);
form_wrapper_->addStretch(1); form_wrapper_->addStretch(1);

View file

@ -88,8 +88,9 @@ void MainWindow::showChatPage(QString userid, QString homeserver, QString token)
void MainWindow::matrixRegister(const QString &username, const QString &password, const QString &server) void MainWindow::matrixRegister(const QString &username, const QString &password, const QString &server)
{ {
qDebug() << "About to register to Matrix"; Q_UNUSED(password);
qDebug() << "Username: " << username << " Password: " << password << " Server: " << server;
qDebug() << "Registering" << username << "at" << server;
} }
void MainWindow::showWelcomePage() void MainWindow::showWelcomePage()

View file

@ -56,7 +56,7 @@ RegisterPage::RegisterPage(QWidget *parent)
form_layout_ = new QVBoxLayout(); form_layout_ = new QVBoxLayout();
form_layout_->setSpacing(20); form_layout_->setSpacing(20);
form_layout_->setContentsMargins(0, 00, 0, 60); form_layout_->setContentsMargins(0, 0, 0, 40);
form_widget_->setLayout(form_layout_); form_widget_->setLayout(form_layout_);
form_wrapper_->addStretch(1); form_wrapper_->addStretch(1);
@ -92,7 +92,10 @@ RegisterPage::RegisterPage(QWidget *parent)
button_layout_ = new QHBoxLayout(); button_layout_ = new QHBoxLayout();
button_layout_->setSpacing(0); button_layout_->setSpacing(0);
button_layout_->setContentsMargins(0, 0, 0, 50); button_layout_->setContentsMargins(0, 0, 0, 30);
error_label_ = new QLabel(this);
error_label_->setStyleSheet("margin-bottom: 20px; color: #E22826; font-size: 11pt;");
register_button_ = new RaisedButton("REGISTER", this); register_button_ = new RaisedButton("REGISTER", this);
register_button_->setBackgroundColor(QColor("#171919")); register_button_->setBackgroundColor(QColor("#171919"));
@ -110,9 +113,10 @@ RegisterPage::RegisterPage(QWidget *parent)
top_layout_->addStretch(1); top_layout_->addStretch(1);
top_layout_->addLayout(logo_layout_); top_layout_->addLayout(logo_layout_);
top_layout_->addLayout(form_wrapper_); top_layout_->addLayout(form_wrapper_);
top_layout_->addStretch(2); top_layout_->addStretch(1);
top_layout_->addLayout(button_layout_); top_layout_->addLayout(button_layout_);
top_layout_->addStretch(1); top_layout_->addStretch(1);
top_layout_->addWidget(error_label_, 0, Qt::AlignHCenter);
connect(back_button_, SIGNAL(clicked()), this, SLOT(onBackButtonClicked())); connect(back_button_, SIGNAL(clicked()), this, SLOT(onBackButtonClicked()));
connect(register_button_, SIGNAL(clicked()), this, SLOT(onRegisterButtonClicked())); connect(register_button_, SIGNAL(clicked()), this, SLOT(onRegisterButtonClicked()));
@ -134,24 +138,23 @@ void RegisterPage::onBackButtonClicked()
emit backButtonClicked(); emit backButtonClicked();
} }
void RegisterPage::registerError(const QString &msg)
{
error_label_->setText(msg);
}
void RegisterPage::onRegisterButtonClicked() void RegisterPage::onRegisterButtonClicked()
{ {
error_label_->setText("");
if (!username_input_->hasAcceptableInput()) { if (!username_input_->hasAcceptableInput()) {
QString text("Invalid username"); registerError("Invalid username");
QPoint point = username_input_->mapToGlobal(username_input_->rect().topRight());
QToolTip::showText(point, text);
} else if (!password_input_->hasAcceptableInput()) { } else if (!password_input_->hasAcceptableInput()) {
QString text("Password is not long enough"); registerError("Password is not long enough (min 8 chars)");
QPoint point = password_input_->mapToGlobal(password_input_->rect().topRight());
QToolTip::showText(point, text);
} else if (password_input_->text() != password_confirmation_->text()) { } else if (password_input_->text() != password_confirmation_->text()) {
QString text("Passwords don't match"); registerError("Passwords don't match");
QPoint point = password_confirmation_->mapToGlobal(password_confirmation_->rect().topRight());
QToolTip::showText(point, text);
} else if (!server_input_->hasAcceptableInput()) { } else if (!server_input_->hasAcceptableInput()) {
QString text("Invalid server name"); registerError("Invalid server name");
QPoint point = server_input_->mapToGlobal(server_input_->rect().topRight());
QToolTip::showText(point, text);
} else { } else {
QString username = username_input_->text(); QString username = username_input_->text();
QString password = password_input_->text(); QString password = password_input_->text();