2017-04-06 02:06:42 +03: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>
|
|
|
|
|
2017-05-14 16:36:30 +03:00
|
|
|
#include "InputValidator.h"
|
2017-04-06 02:06:42 +03:00
|
|
|
#include "LoginPage.h"
|
|
|
|
|
2017-04-11 17:45:47 +03:00
|
|
|
LoginPage::LoginPage(QSharedPointer<MatrixClient> client, QWidget *parent)
|
2017-04-06 02:06:42 +03:00
|
|
|
: QWidget(parent)
|
2017-05-09 13:25:43 +03:00
|
|
|
, settings_modal_{nullptr}
|
|
|
|
, login_settings_{nullptr}
|
|
|
|
, client_{client}
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
|
|
|
top_layout_ = new QVBoxLayout();
|
|
|
|
|
2017-05-09 13:25:43 +03:00
|
|
|
top_bar_layout_ = new QHBoxLayout();
|
|
|
|
top_bar_layout_->setSpacing(0);
|
|
|
|
top_bar_layout_->setMargin(0);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
|
|
|
back_button_ = new FlatButton(this);
|
|
|
|
back_button_->setMinimumSize(QSize(30, 30));
|
2017-05-09 13:25:43 +03:00
|
|
|
back_button_->setForegroundColor("#333333");
|
2017-04-06 02:06:42 +03:00
|
|
|
back_button_->setCursor(QCursor(Qt::PointingHandCursor));
|
|
|
|
|
2017-05-09 13:25:43 +03:00
|
|
|
advanced_settings_button_ = new FlatButton(this);
|
|
|
|
advanced_settings_button_->setMinimumSize(QSize(30, 30));
|
|
|
|
advanced_settings_button_->setForegroundColor("#333333");
|
|
|
|
advanced_settings_button_->setCursor(QCursor(Qt::PointingHandCursor));
|
|
|
|
|
2017-04-06 02:06:42 +03:00
|
|
|
QIcon icon;
|
|
|
|
icon.addFile(":/icons/icons/left-angle.png", QSize(), QIcon::Normal, QIcon::Off);
|
|
|
|
|
|
|
|
back_button_->setIcon(icon);
|
|
|
|
back_button_->setIconSize(QSize(24, 24));
|
|
|
|
|
2017-05-09 13:25:43 +03:00
|
|
|
QIcon advanced_settings_icon;
|
|
|
|
advanced_settings_icon.addFile(":/icons/icons/cog.png", QSize(), QIcon::Normal, QIcon::Off);
|
|
|
|
|
|
|
|
advanced_settings_button_->setIcon(advanced_settings_icon);
|
|
|
|
advanced_settings_button_->setIconSize(QSize(24, 24));
|
|
|
|
|
|
|
|
top_bar_layout_->addWidget(back_button_, 0, Qt::AlignLeft | Qt::AlignVCenter);
|
|
|
|
top_bar_layout_->addStretch(1);
|
|
|
|
top_bar_layout_->addWidget(advanced_settings_button_, 0, Qt::AlignRight | Qt::AlignVCenter);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
|
|
|
logo_ = new QLabel(this);
|
2017-04-21 17:16:29 +03:00
|
|
|
logo_->setPixmap(QPixmap(":/logos/nheko-128.png"));
|
|
|
|
|
|
|
|
logo_layout_ = new QHBoxLayout();
|
|
|
|
logo_layout_->setContentsMargins(0, 0, 0, 20);
|
2017-04-06 02:06:42 +03:00
|
|
|
logo_layout_->addWidget(logo_, 0, Qt::AlignHCenter);
|
|
|
|
|
|
|
|
form_wrapper_ = new QHBoxLayout();
|
|
|
|
form_widget_ = new QWidget();
|
|
|
|
form_widget_->setMinimumSize(QSize(350, 200));
|
|
|
|
|
|
|
|
form_layout_ = new QVBoxLayout();
|
|
|
|
form_layout_->setSpacing(20);
|
2017-04-07 19:25:06 +03:00
|
|
|
form_layout_->setContentsMargins(0, 0, 0, 30);
|
2017-04-06 02:06:42 +03:00
|
|
|
form_widget_->setLayout(form_layout_);
|
|
|
|
|
|
|
|
form_wrapper_->addStretch(1);
|
|
|
|
form_wrapper_->addWidget(form_widget_);
|
|
|
|
form_wrapper_->addStretch(1);
|
|
|
|
|
2017-05-09 13:25:43 +03:00
|
|
|
matrixid_input_ = new TextField(this);
|
2017-05-03 21:42:51 +03:00
|
|
|
matrixid_input_->setTextColor("#333333");
|
2017-04-10 01:47:15 +03:00
|
|
|
matrixid_input_->setLabel("Matrix ID");
|
2017-04-14 15:13:09 +03:00
|
|
|
matrixid_input_->setInkColor("#555459");
|
2017-04-10 01:47:15 +03:00
|
|
|
matrixid_input_->setBackgroundColor("#f9f9f9");
|
|
|
|
matrixid_input_->setPlaceholderText("e.g @joe:matrix.org");
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-05-09 13:25:43 +03:00
|
|
|
password_input_ = new TextField(this);
|
2017-05-03 21:42:51 +03:00
|
|
|
password_input_->setTextColor("#333333");
|
2017-04-06 02:06:42 +03:00
|
|
|
password_input_->setLabel("Password");
|
2017-04-14 15:13:09 +03:00
|
|
|
password_input_->setInkColor("#555459");
|
2017-04-06 02:06:42 +03:00
|
|
|
password_input_->setBackgroundColor("#f9f9f9");
|
|
|
|
password_input_->setEchoMode(QLineEdit::Password);
|
|
|
|
|
2017-04-10 01:47:15 +03:00
|
|
|
form_layout_->addWidget(matrixid_input_, Qt::AlignHCenter, 0);
|
2017-04-06 02:06:42 +03:00
|
|
|
form_layout_->addWidget(password_input_, Qt::AlignHCenter, 0);
|
|
|
|
|
|
|
|
button_layout_ = new QHBoxLayout();
|
|
|
|
button_layout_->setSpacing(0);
|
2017-05-09 13:25:43 +03:00
|
|
|
button_layout_->setContentsMargins(0, 0, 0, 30);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
|
|
|
login_button_ = new RaisedButton("LOGIN", this);
|
2017-04-21 17:16:29 +03:00
|
|
|
login_button_->setBackgroundColor(QColor("#333333"));
|
2017-04-14 17:10:18 +03:00
|
|
|
login_button_->setForegroundColor(QColor("white"));
|
2017-04-06 02:06:42 +03:00
|
|
|
login_button_->setMinimumSize(350, 65);
|
|
|
|
login_button_->setCursor(QCursor(Qt::PointingHandCursor));
|
|
|
|
login_button_->setFontSize(17);
|
|
|
|
login_button_->setCornerRadius(3);
|
|
|
|
|
|
|
|
button_layout_->addStretch(1);
|
|
|
|
button_layout_->addWidget(login_button_);
|
|
|
|
button_layout_->addStretch(1);
|
|
|
|
|
|
|
|
error_label_ = new QLabel(this);
|
|
|
|
error_label_->setStyleSheet("color: #E22826; font-size: 11pt;");
|
|
|
|
|
2017-05-09 13:25:43 +03:00
|
|
|
top_layout_->addLayout(top_bar_layout_);
|
2017-04-06 02:06:42 +03:00
|
|
|
top_layout_->addStretch(1);
|
|
|
|
top_layout_->addLayout(logo_layout_);
|
|
|
|
top_layout_->addLayout(form_wrapper_);
|
|
|
|
top_layout_->addStretch(1);
|
|
|
|
top_layout_->addLayout(button_layout_);
|
|
|
|
top_layout_->addWidget(error_label_, 0, Qt::AlignHCenter);
|
|
|
|
top_layout_->addStretch(1);
|
|
|
|
|
2017-04-11 17:45:47 +03:00
|
|
|
setLayout(top_layout_);
|
|
|
|
|
2017-04-06 02:06:42 +03:00
|
|
|
connect(back_button_, SIGNAL(clicked()), this, SLOT(onBackButtonClicked()));
|
|
|
|
connect(login_button_, SIGNAL(clicked()), this, SLOT(onLoginButtonClicked()));
|
2017-04-10 01:47:15 +03:00
|
|
|
connect(matrixid_input_, SIGNAL(returnPressed()), login_button_, SLOT(click()));
|
2017-04-06 02:06:42 +03:00
|
|
|
connect(password_input_, SIGNAL(returnPressed()), login_button_, SLOT(click()));
|
2017-04-11 17:45:47 +03:00
|
|
|
connect(client_.data(), SIGNAL(loginError(QString)), this, SLOT(loginError(QString)));
|
2017-05-09 13:25:43 +03:00
|
|
|
connect(advanced_settings_button_, SIGNAL(clicked()), this, SLOT(showSettingsModal()));
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-05-14 16:36:30 +03:00
|
|
|
matrixid_input_->setValidator(&InputValidator::Id);
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void LoginPage::loginError(QString error)
|
|
|
|
{
|
|
|
|
error_label_->setText(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoginPage::onLoginButtonClicked()
|
|
|
|
{
|
|
|
|
error_label_->setText("");
|
|
|
|
|
2017-04-10 01:47:15 +03:00
|
|
|
if (!matrixid_input_->hasAcceptableInput()) {
|
2017-04-06 02:06:42 +03:00
|
|
|
loginError("Invalid Matrix ID");
|
|
|
|
} else if (password_input_->text().isEmpty()) {
|
|
|
|
loginError("Empty password");
|
|
|
|
} else {
|
2017-04-10 01:47:15 +03:00
|
|
|
QString user = matrixid_input_->text().split(":").at(0).split("@").at(1);
|
2017-04-06 02:06:42 +03:00
|
|
|
QString password = password_input_->text();
|
|
|
|
|
2017-05-09 13:25:43 +03:00
|
|
|
QString home_server = custom_domain_.isEmpty()
|
|
|
|
? matrixid_input_->text().split(":").at(1)
|
|
|
|
: custom_domain_;
|
|
|
|
|
2017-04-11 17:45:47 +03:00
|
|
|
client_->setServer(home_server);
|
|
|
|
client_->login(user, password);
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-09 13:25:43 +03:00
|
|
|
void LoginPage::showSettingsModal()
|
|
|
|
{
|
|
|
|
if (login_settings_ == nullptr) {
|
|
|
|
login_settings_ = new LoginSettings(this);
|
|
|
|
connect(login_settings_, &LoginSettings::closing, this, &LoginPage::closeSettingsModal);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (settings_modal_ == nullptr) {
|
|
|
|
settings_modal_ = new OverlayModal(this, login_settings_);
|
|
|
|
settings_modal_->setDuration(100);
|
|
|
|
settings_modal_->setColor(QColor(55, 55, 55, 170));
|
|
|
|
}
|
|
|
|
|
|
|
|
settings_modal_->fadeIn();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoginPage::closeSettingsModal(const QString &server)
|
|
|
|
{
|
|
|
|
custom_domain_ = server;
|
|
|
|
settings_modal_->fadeOut();
|
|
|
|
}
|
|
|
|
|
2017-04-09 02:32:48 +03:00
|
|
|
void LoginPage::reset()
|
|
|
|
{
|
2017-04-10 01:47:15 +03:00
|
|
|
matrixid_input_->clear();
|
2017-04-09 02:32:48 +03:00
|
|
|
password_input_->clear();
|
2017-05-09 13:25:43 +03:00
|
|
|
|
2017-05-10 12:45:53 +03:00
|
|
|
if (settings_modal_ != nullptr) {
|
|
|
|
settings_modal_->deleteLater();
|
|
|
|
settings_modal_ = nullptr;
|
|
|
|
}
|
2017-05-09 13:25:43 +03:00
|
|
|
|
2017-05-10 12:45:53 +03:00
|
|
|
if (login_settings_ != nullptr) {
|
|
|
|
login_settings_->deleteLater();
|
|
|
|
login_settings_ = nullptr;
|
|
|
|
}
|
2017-04-09 02:32:48 +03:00
|
|
|
}
|
|
|
|
|
2017-04-06 02:06:42 +03:00
|
|
|
void LoginPage::onBackButtonClicked()
|
|
|
|
{
|
|
|
|
emit backButtonClicked();
|
|
|
|
}
|
|
|
|
|
|
|
|
LoginPage::~LoginPage()
|
|
|
|
{
|
|
|
|
}
|