From c7c3ee19ee66ab5f3ad57c16f546e35674093c0d Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Fri, 7 Apr 2017 19:25:06 +0300 Subject: [PATCH] Use QLabel to display registration errors --- Makefile | 6 +++--- include/RegisterPage.h | 5 +++++ src/LoginPage.cc | 2 +- src/MainWindow.cc | 5 +++-- src/RegisterPage.cc | 33 ++++++++++++++++++--------------- 5 files changed, 30 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index 7f97e93..eb8a666 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,13 @@ -run: build +run: debug ./build/nheko debug: @cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=Debug - @make -C build + @make -C build -j2 release-debug: @cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=RelWithDebInfo - @make -C build + @make -C build -j2 clean: rm -rf build diff --git a/include/RegisterPage.h b/include/RegisterPage.h index f1c3848..421cbd8 100644 --- a/include/RegisterPage.h +++ b/include/RegisterPage.h @@ -43,6 +43,10 @@ signals: // responsible for the actual registering on the remote Matrix 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: void onBackButtonClicked(); void onRegisterButtonClicked(); @@ -55,6 +59,7 @@ private: QHBoxLayout *button_layout_; QLabel *logo_; + QLabel *error_label_; FlatButton *back_button_; RaisedButton *register_button_; diff --git a/src/LoginPage.cc b/src/LoginPage.cc index 68927c3..54eda38 100644 --- a/src/LoginPage.cc +++ b/src/LoginPage.cc @@ -55,7 +55,7 @@ LoginPage::LoginPage(QWidget *parent) form_layout_ = new QVBoxLayout(); form_layout_->setSpacing(20); - form_layout_->setContentsMargins(0, 00, 0, 30); + form_layout_->setContentsMargins(0, 0, 0, 30); form_widget_->setLayout(form_layout_); form_wrapper_->addStretch(1); diff --git a/src/MainWindow.cc b/src/MainWindow.cc index 82976f2..3989e09 100644 --- a/src/MainWindow.cc +++ b/src/MainWindow.cc @@ -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) { - qDebug() << "About to register to Matrix"; - qDebug() << "Username: " << username << " Password: " << password << " Server: " << server; + Q_UNUSED(password); + + qDebug() << "Registering" << username << "at" << server; } void MainWindow::showWelcomePage() diff --git a/src/RegisterPage.cc b/src/RegisterPage.cc index fcb43b8..bad6eeb 100644 --- a/src/RegisterPage.cc +++ b/src/RegisterPage.cc @@ -56,7 +56,7 @@ RegisterPage::RegisterPage(QWidget *parent) form_layout_ = new QVBoxLayout(); form_layout_->setSpacing(20); - form_layout_->setContentsMargins(0, 00, 0, 60); + form_layout_->setContentsMargins(0, 0, 0, 40); form_widget_->setLayout(form_layout_); form_wrapper_->addStretch(1); @@ -92,7 +92,10 @@ RegisterPage::RegisterPage(QWidget *parent) button_layout_ = new QHBoxLayout(); 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_->setBackgroundColor(QColor("#171919")); @@ -110,9 +113,10 @@ RegisterPage::RegisterPage(QWidget *parent) top_layout_->addStretch(1); top_layout_->addLayout(logo_layout_); top_layout_->addLayout(form_wrapper_); - top_layout_->addStretch(2); + top_layout_->addStretch(1); top_layout_->addLayout(button_layout_); top_layout_->addStretch(1); + top_layout_->addWidget(error_label_, 0, Qt::AlignHCenter); connect(back_button_, SIGNAL(clicked()), this, SLOT(onBackButtonClicked())); connect(register_button_, SIGNAL(clicked()), this, SLOT(onRegisterButtonClicked())); @@ -134,24 +138,23 @@ void RegisterPage::onBackButtonClicked() emit backButtonClicked(); } +void RegisterPage::registerError(const QString &msg) +{ + error_label_->setText(msg); +} + void RegisterPage::onRegisterButtonClicked() { + error_label_->setText(""); + if (!username_input_->hasAcceptableInput()) { - QString text("Invalid username"); - QPoint point = username_input_->mapToGlobal(username_input_->rect().topRight()); - QToolTip::showText(point, text); + registerError("Invalid username"); } else if (!password_input_->hasAcceptableInput()) { - QString text("Password is not long enough"); - QPoint point = password_input_->mapToGlobal(password_input_->rect().topRight()); - QToolTip::showText(point, text); + registerError("Password is not long enough (min 8 chars)"); } else if (password_input_->text() != password_confirmation_->text()) { - QString text("Passwords don't match"); - QPoint point = password_confirmation_->mapToGlobal(password_confirmation_->rect().topRight()); - QToolTip::showText(point, text); + registerError("Passwords don't match"); } else if (!server_input_->hasAcceptableInput()) { - QString text("Invalid server name"); - QPoint point = server_input_->mapToGlobal(server_input_->rect().topRight()); - QToolTip::showText(point, text); + registerError("Invalid server name"); } else { QString username = username_input_->text(); QString password = password_input_->text();