nheko/src/RegisterPage.cc

184 lines
6.0 KiB
C++
Raw Normal View History

2017-04-06 01:06:42 +02:00
/*
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QDebug>
#include <QToolTip>
#include "Config.h"
#include "InputValidator.h"
2017-04-06 01:06:42 +02:00
#include "RegisterPage.h"
RegisterPage::RegisterPage(QSharedPointer<MatrixClient> client, QWidget *parent)
2017-08-20 12:47:22 +02:00
: QWidget(parent)
, client_(client)
2017-04-06 01:06:42 +02:00
{
2017-05-21 15:36:06 +02:00
setStyleSheet("background-color: #f9f9f9");
2017-04-06 01:06:42 +02:00
top_layout_ = new QVBoxLayout();
back_layout_ = new QHBoxLayout();
back_layout_->setSpacing(0);
back_layout_->setContentsMargins(5, 5, -1, -1);
back_button_ = new FlatButton(this);
back_button_->setMinimumSize(QSize(30, 30));
QIcon icon;
icon.addFile(":/icons/icons/left-angle.png", QSize(), QIcon::Normal, QIcon::Off);
back_button_->setIcon(icon);
back_button_->setIconSize(QSize(24, 24));
back_layout_->addWidget(back_button_, 0, Qt::AlignLeft | Qt::AlignVCenter);
back_layout_->addStretch(1);
2017-04-21 16:16:29 +02:00
logo_ = new Avatar(this);
logo_->setImage(QImage(":/logos/nheko-128.png"));
logo_->setSize(80);
2017-04-06 01:06:42 +02:00
logo_layout_ = new QHBoxLayout();
2017-04-21 16:16:29 +02:00
logo_layout_->setMargin(0);
2017-04-06 01:06:42 +02:00
logo_layout_->addWidget(logo_, 0, Qt::AlignHCenter);
form_wrapper_ = new QHBoxLayout();
form_widget_ = new QWidget();
form_widget_->setMinimumSize(QSize(350, 300));
form_layout_ = new QVBoxLayout();
form_layout_->setSpacing(20);
form_layout_->setContentsMargins(0, 0, 0, 40);
2017-04-06 01:06:42 +02:00
form_widget_->setLayout(form_layout_);
form_wrapper_->addStretch(1);
form_wrapper_->addWidget(form_widget_);
form_wrapper_->addStretch(1);
username_input_ = new TextField();
2017-05-03 20:42:51 +02:00
username_input_->setTextColor("#333333");
2017-05-29 18:09:12 +02:00
username_input_->setLabel(tr("Username"));
2017-04-14 14:13:09 +02:00
username_input_->setInkColor("#555459");
2017-04-06 01:06:42 +02:00
username_input_->setBackgroundColor("#f9f9f9");
password_input_ = new TextField();
2017-05-03 20:42:51 +02:00
password_input_->setTextColor("#333333");
2017-05-29 18:09:12 +02:00
password_input_->setLabel(tr("Password"));
2017-04-14 14:13:09 +02:00
password_input_->setInkColor("#555459");
2017-04-06 01:06:42 +02:00
password_input_->setBackgroundColor("#f9f9f9");
password_input_->setEchoMode(QLineEdit::Password);
password_confirmation_ = new TextField();
2017-05-03 20:42:51 +02:00
password_confirmation_->setTextColor("#333333");
2017-05-29 18:09:12 +02:00
password_confirmation_->setLabel(tr("Password confirmation"));
2017-04-14 14:13:09 +02:00
password_confirmation_->setInkColor("#555459");
2017-04-06 01:06:42 +02:00
password_confirmation_->setBackgroundColor("#f9f9f9");
password_confirmation_->setEchoMode(QLineEdit::Password);
server_input_ = new TextField();
2017-05-03 20:42:51 +02:00
server_input_->setTextColor("#333333");
2017-05-29 18:09:12 +02:00
server_input_->setLabel(tr("Home Server"));
2017-04-14 14:13:09 +02:00
server_input_->setInkColor("#555459");
2017-04-06 01:06:42 +02:00
server_input_->setBackgroundColor("#f9f9f9");
form_layout_->addWidget(username_input_, Qt::AlignHCenter, 0);
form_layout_->addWidget(password_input_, Qt::AlignHCenter, 0);
form_layout_->addWidget(password_confirmation_, Qt::AlignHCenter, 0);
form_layout_->addWidget(server_input_, Qt::AlignHCenter, 0);
button_layout_ = new QHBoxLayout();
button_layout_->setSpacing(0);
2017-04-21 16:16:29 +02:00
button_layout_->setMargin(0);
QFont font;
font.setPixelSize(conf::fontSize);
error_label_ = new QLabel(this);
error_label_->setFont(font);
error_label_->setStyleSheet("color: #E22826");
2017-04-06 01:06:42 +02:00
2017-05-29 18:09:12 +02:00
register_button_ = new RaisedButton(tr("REGISTER"), this);
2017-04-21 16:16:29 +02:00
register_button_->setBackgroundColor(QColor("#333333"));
2017-04-14 16:10:18 +02:00
register_button_->setForegroundColor(QColor("white"));
2017-04-06 01:06:42 +02:00
register_button_->setMinimumSize(350, 65);
register_button_->setFontSize(conf::btn::fontSize);
register_button_->setCornerRadius(conf::btn::cornerRadius);
2017-04-06 01:06:42 +02:00
button_layout_->addStretch(1);
button_layout_->addWidget(register_button_);
button_layout_->addStretch(1);
top_layout_->addLayout(back_layout_);
top_layout_->addLayout(logo_layout_);
top_layout_->addLayout(form_wrapper_);
top_layout_->addStretch(1);
2017-04-06 01:06:42 +02:00
top_layout_->addLayout(button_layout_);
top_layout_->addStretch(1);
top_layout_->addWidget(error_label_, 0, Qt::AlignHCenter);
2017-04-06 01:06:42 +02:00
connect(back_button_, SIGNAL(clicked()), this, SLOT(onBackButtonClicked()));
connect(register_button_, SIGNAL(clicked()), this, SLOT(onRegisterButtonClicked()));
connect(username_input_, SIGNAL(returnPressed()), register_button_, SLOT(click()));
connect(password_input_, SIGNAL(returnPressed()), register_button_, SLOT(click()));
connect(password_confirmation_, SIGNAL(returnPressed()), register_button_, SLOT(click()));
connect(server_input_, SIGNAL(returnPressed()), register_button_, SLOT(click()));
connect(client_.data(), SIGNAL(registerError(const QString &)), this, SLOT(registerError(const QString &)));
2017-04-06 01:06:42 +02:00
username_input_->setValidator(&InputValidator::Localpart);
password_input_->setValidator(&InputValidator::Password);
server_input_->setValidator(&InputValidator::Domain);
2017-04-06 01:06:42 +02:00
setLayout(top_layout_);
}
2017-08-20 12:47:22 +02:00
void
RegisterPage::onBackButtonClicked()
2017-04-06 01:06:42 +02:00
{
emit backButtonClicked();
}
2017-08-20 12:47:22 +02:00
void
RegisterPage::registerError(const QString &msg)
{
error_label_->setText(msg);
}
2017-08-20 12:47:22 +02:00
void
RegisterPage::onRegisterButtonClicked()
2017-04-06 01:06:42 +02:00
{
error_label_->setText("");
2017-04-06 01:06:42 +02:00
if (!username_input_->hasAcceptableInput()) {
2017-05-29 18:09:12 +02:00
registerError(tr("Invalid username"));
2017-04-06 01:06:42 +02:00
} else if (!password_input_->hasAcceptableInput()) {
2017-05-29 18:09:12 +02:00
registerError(tr("Password is not long enough (min 8 chars)"));
2017-04-06 01:06:42 +02:00
} else if (password_input_->text() != password_confirmation_->text()) {
2017-05-29 18:09:12 +02:00
registerError(tr("Passwords don't match"));
2017-04-06 01:06:42 +02:00
} else if (!server_input_->hasAcceptableInput()) {
2017-05-29 18:09:12 +02:00
registerError(tr("Invalid server name"));
2017-04-06 01:06:42 +02:00
} else {
QString username = username_input_->text();
QString password = password_input_->text();
QString server = server_input_->text();
client_->registerUser(username, password, server);
2017-04-06 01:06:42 +02:00
}
}
RegisterPage::~RegisterPage()
{
}