mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 19:08:58 +03:00
Add settings panel for homeserver's domain
This commit is contained in:
parent
0834b246ad
commit
1f10403ace
7 changed files with 175 additions and 13 deletions
|
@ -86,6 +86,7 @@ set(SRC_FILES
|
||||||
src/InputValidator.cc
|
src/InputValidator.cc
|
||||||
src/Login.cc
|
src/Login.cc
|
||||||
src/LoginPage.cc
|
src/LoginPage.cc
|
||||||
|
src/LoginSettings.cc
|
||||||
src/MainWindow.cc
|
src/MainWindow.cc
|
||||||
src/MatrixClient.cc
|
src/MatrixClient.cc
|
||||||
src/Profile.cc
|
src/Profile.cc
|
||||||
|
@ -164,6 +165,7 @@ qt5_wrap_cpp(MOC_HEADERS
|
||||||
include/TimelineView.h
|
include/TimelineView.h
|
||||||
include/TimelineViewManager.h
|
include/TimelineViewManager.h
|
||||||
include/LoginPage.h
|
include/LoginPage.h
|
||||||
|
include/LoginSettings.h
|
||||||
include/MainWindow.h
|
include/MainWindow.h
|
||||||
include/MatrixClient.h
|
include/MatrixClient.h
|
||||||
include/RegisterPage.h
|
include/RegisterPage.h
|
||||||
|
|
|
@ -26,7 +26,9 @@
|
||||||
|
|
||||||
#include "FlatButton.h"
|
#include "FlatButton.h"
|
||||||
#include "InputValidator.h"
|
#include "InputValidator.h"
|
||||||
|
#include "LoginSettings.h"
|
||||||
#include "MatrixClient.h"
|
#include "MatrixClient.h"
|
||||||
|
#include "OverlayModal.h"
|
||||||
#include "RaisedButton.h"
|
#include "RaisedButton.h"
|
||||||
#include "TextField.h"
|
#include "TextField.h"
|
||||||
|
|
||||||
|
@ -53,10 +55,14 @@ private slots:
|
||||||
// Displays errors produced during the login.
|
// Displays errors produced during the login.
|
||||||
void loginError(QString error_message);
|
void loginError(QString error_message);
|
||||||
|
|
||||||
|
// Manipulate settings modal.
|
||||||
|
void showSettingsModal();
|
||||||
|
void closeSettingsModal(const QString &server);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVBoxLayout *top_layout_;
|
QVBoxLayout *top_layout_;
|
||||||
|
|
||||||
QHBoxLayout *back_layout_;
|
QHBoxLayout *top_bar_layout_;
|
||||||
QHBoxLayout *logo_layout_;
|
QHBoxLayout *logo_layout_;
|
||||||
QHBoxLayout *button_layout_;
|
QHBoxLayout *button_layout_;
|
||||||
|
|
||||||
|
@ -64,6 +70,7 @@ private:
|
||||||
QLabel *error_label_;
|
QLabel *error_label_;
|
||||||
|
|
||||||
FlatButton *back_button_;
|
FlatButton *back_button_;
|
||||||
|
FlatButton *advanced_settings_button_;
|
||||||
RaisedButton *login_button_;
|
RaisedButton *login_button_;
|
||||||
|
|
||||||
QWidget *form_widget_;
|
QWidget *form_widget_;
|
||||||
|
@ -73,6 +80,10 @@ private:
|
||||||
TextField *matrixid_input_;
|
TextField *matrixid_input_;
|
||||||
TextField *password_input_;
|
TextField *password_input_;
|
||||||
|
|
||||||
|
OverlayModal *settings_modal_;
|
||||||
|
LoginSettings *login_settings_;
|
||||||
|
QString custom_domain_;
|
||||||
|
|
||||||
InputValidator *matrix_id_validator_;
|
InputValidator *matrix_id_validator_;
|
||||||
|
|
||||||
// Matrix client API provider.
|
// Matrix client API provider.
|
||||||
|
|
40
include/LoginSettings.h
Normal file
40
include/LoginSettings.h
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LOGIN_SETTINGS_H
|
||||||
|
#define LOGIN_SETTINGS_H
|
||||||
|
|
||||||
|
#include <QFrame>
|
||||||
|
|
||||||
|
#include "FlatButton.h"
|
||||||
|
#include "TextField.h"
|
||||||
|
|
||||||
|
class LoginSettings : public QFrame
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit LoginSettings(QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void closing(const QString &server);
|
||||||
|
|
||||||
|
private:
|
||||||
|
TextField *input_;
|
||||||
|
FlatButton *submit_button_;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // LOGIN_SETTINGS_H
|
|
@ -50,6 +50,7 @@ private:
|
||||||
inline void OverlayModal::setDuration(int duration)
|
inline void OverlayModal::setDuration(int duration)
|
||||||
{
|
{
|
||||||
duration_ = duration;
|
duration_ = duration;
|
||||||
|
animation_->setDuration(duration_);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void OverlayModal::setColor(QColor color)
|
inline void OverlayModal::setColor(QColor color)
|
||||||
|
|
|
@ -21,28 +21,43 @@
|
||||||
|
|
||||||
LoginPage::LoginPage(QSharedPointer<MatrixClient> client, QWidget *parent)
|
LoginPage::LoginPage(QSharedPointer<MatrixClient> client, QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
, client_(client)
|
, settings_modal_{nullptr}
|
||||||
|
, login_settings_{nullptr}
|
||||||
|
, client_{client}
|
||||||
{
|
{
|
||||||
matrix_id_validator_ = new InputValidator(this);
|
matrix_id_validator_ = new InputValidator(this);
|
||||||
|
|
||||||
top_layout_ = new QVBoxLayout();
|
top_layout_ = new QVBoxLayout();
|
||||||
|
|
||||||
back_layout_ = new QHBoxLayout();
|
top_bar_layout_ = new QHBoxLayout();
|
||||||
back_layout_->setSpacing(0);
|
top_bar_layout_->setSpacing(0);
|
||||||
back_layout_->setContentsMargins(5, 5, -1, -1);
|
top_bar_layout_->setMargin(0);
|
||||||
|
|
||||||
back_button_ = new FlatButton(this);
|
back_button_ = new FlatButton(this);
|
||||||
back_button_->setMinimumSize(QSize(30, 30));
|
back_button_->setMinimumSize(QSize(30, 30));
|
||||||
|
back_button_->setForegroundColor("#333333");
|
||||||
back_button_->setCursor(QCursor(Qt::PointingHandCursor));
|
back_button_->setCursor(QCursor(Qt::PointingHandCursor));
|
||||||
|
|
||||||
|
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));
|
||||||
|
|
||||||
QIcon icon;
|
QIcon icon;
|
||||||
icon.addFile(":/icons/icons/left-angle.png", QSize(), QIcon::Normal, QIcon::Off);
|
icon.addFile(":/icons/icons/left-angle.png", QSize(), QIcon::Normal, QIcon::Off);
|
||||||
|
|
||||||
back_button_->setIcon(icon);
|
back_button_->setIcon(icon);
|
||||||
back_button_->setIconSize(QSize(24, 24));
|
back_button_->setIconSize(QSize(24, 24));
|
||||||
|
|
||||||
back_layout_->addWidget(back_button_, 0, Qt::AlignLeft | Qt::AlignVCenter);
|
QIcon advanced_settings_icon;
|
||||||
back_layout_->addStretch(1);
|
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);
|
||||||
|
|
||||||
logo_ = new QLabel(this);
|
logo_ = new QLabel(this);
|
||||||
logo_->setPixmap(QPixmap(":/logos/nheko-128.png"));
|
logo_->setPixmap(QPixmap(":/logos/nheko-128.png"));
|
||||||
|
@ -64,14 +79,14 @@ LoginPage::LoginPage(QSharedPointer<MatrixClient> client, QWidget *parent)
|
||||||
form_wrapper_->addWidget(form_widget_);
|
form_wrapper_->addWidget(form_widget_);
|
||||||
form_wrapper_->addStretch(1);
|
form_wrapper_->addStretch(1);
|
||||||
|
|
||||||
matrixid_input_ = new TextField();
|
matrixid_input_ = new TextField(this);
|
||||||
matrixid_input_->setTextColor("#333333");
|
matrixid_input_->setTextColor("#333333");
|
||||||
matrixid_input_->setLabel("Matrix ID");
|
matrixid_input_->setLabel("Matrix ID");
|
||||||
matrixid_input_->setInkColor("#555459");
|
matrixid_input_->setInkColor("#555459");
|
||||||
matrixid_input_->setBackgroundColor("#f9f9f9");
|
matrixid_input_->setBackgroundColor("#f9f9f9");
|
||||||
matrixid_input_->setPlaceholderText("e.g @joe:matrix.org");
|
matrixid_input_->setPlaceholderText("e.g @joe:matrix.org");
|
||||||
|
|
||||||
password_input_ = new TextField();
|
password_input_ = new TextField(this);
|
||||||
password_input_->setTextColor("#333333");
|
password_input_->setTextColor("#333333");
|
||||||
password_input_->setLabel("Password");
|
password_input_->setLabel("Password");
|
||||||
password_input_->setInkColor("#555459");
|
password_input_->setInkColor("#555459");
|
||||||
|
@ -83,7 +98,7 @@ LoginPage::LoginPage(QSharedPointer<MatrixClient> client, 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);
|
||||||
|
|
||||||
login_button_ = new RaisedButton("LOGIN", this);
|
login_button_ = new RaisedButton("LOGIN", this);
|
||||||
login_button_->setBackgroundColor(QColor("#333333"));
|
login_button_->setBackgroundColor(QColor("#333333"));
|
||||||
|
@ -100,7 +115,7 @@ LoginPage::LoginPage(QSharedPointer<MatrixClient> client, QWidget *parent)
|
||||||
error_label_ = new QLabel(this);
|
error_label_ = new QLabel(this);
|
||||||
error_label_->setStyleSheet("color: #E22826; font-size: 11pt;");
|
error_label_->setStyleSheet("color: #E22826; font-size: 11pt;");
|
||||||
|
|
||||||
top_layout_->addLayout(back_layout_);
|
top_layout_->addLayout(top_bar_layout_);
|
||||||
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_);
|
||||||
|
@ -116,6 +131,7 @@ LoginPage::LoginPage(QSharedPointer<MatrixClient> client, QWidget *parent)
|
||||||
connect(matrixid_input_, SIGNAL(returnPressed()), login_button_, SLOT(click()));
|
connect(matrixid_input_, SIGNAL(returnPressed()), login_button_, SLOT(click()));
|
||||||
connect(password_input_, SIGNAL(returnPressed()), login_button_, SLOT(click()));
|
connect(password_input_, SIGNAL(returnPressed()), login_button_, SLOT(click()));
|
||||||
connect(client_.data(), SIGNAL(loginError(QString)), this, SLOT(loginError(QString)));
|
connect(client_.data(), SIGNAL(loginError(QString)), this, SLOT(loginError(QString)));
|
||||||
|
connect(advanced_settings_button_, SIGNAL(clicked()), this, SLOT(showSettingsModal()));
|
||||||
|
|
||||||
matrixid_input_->setValidator(matrix_id_validator_->id_);
|
matrixid_input_->setValidator(matrix_id_validator_->id_);
|
||||||
}
|
}
|
||||||
|
@ -135,18 +151,49 @@ void LoginPage::onLoginButtonClicked()
|
||||||
loginError("Empty password");
|
loginError("Empty password");
|
||||||
} else {
|
} else {
|
||||||
QString user = matrixid_input_->text().split(":").at(0).split("@").at(1);
|
QString user = matrixid_input_->text().split(":").at(0).split("@").at(1);
|
||||||
QString home_server = matrixid_input_->text().split(":").at(1);
|
|
||||||
QString password = password_input_->text();
|
QString password = password_input_->text();
|
||||||
|
|
||||||
|
QString home_server = custom_domain_.isEmpty()
|
||||||
|
? matrixid_input_->text().split(":").at(1)
|
||||||
|
: custom_domain_;
|
||||||
|
|
||||||
client_->setServer(home_server);
|
client_->setServer(home_server);
|
||||||
client_->login(user, password);
|
client_->login(user, password);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
void LoginPage::reset()
|
void LoginPage::reset()
|
||||||
{
|
{
|
||||||
matrixid_input_->clear();
|
matrixid_input_->clear();
|
||||||
password_input_->clear();
|
password_input_->clear();
|
||||||
|
|
||||||
|
settings_modal_->deleteLater();
|
||||||
|
login_settings_->deleteLater();
|
||||||
|
|
||||||
|
login_settings_ = nullptr;
|
||||||
|
settings_modal_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoginPage::onBackButtonClicked()
|
void LoginPage::onBackButtonClicked()
|
||||||
|
|
61
src/LoginSettings.cc
Normal file
61
src/LoginSettings.cc
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
/*
|
||||||
|
* 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 <QLabel>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
|
#include "LoginSettings.h"
|
||||||
|
|
||||||
|
LoginSettings::LoginSettings(QWidget *parent)
|
||||||
|
: QFrame(parent)
|
||||||
|
{
|
||||||
|
setMaximumSize(400, 400);
|
||||||
|
setStyleSheet("background-color: #f9f9f9");
|
||||||
|
|
||||||
|
auto layout = new QVBoxLayout(this);
|
||||||
|
layout->setSpacing(30);
|
||||||
|
layout->setContentsMargins(20, 20, 20, 10);
|
||||||
|
|
||||||
|
input_ = new TextField(this);
|
||||||
|
input_->setTextColor("#555459");
|
||||||
|
input_->setLabel("Homeserver's domain");
|
||||||
|
input_->setInkColor("#333333");
|
||||||
|
input_->setBackgroundColor("#f9f9f9");
|
||||||
|
input_->setPlaceholderText("e.g matrix.domain.org:3434");
|
||||||
|
|
||||||
|
submit_button_ = new FlatButton("OK", this);
|
||||||
|
submit_button_->setBackgroundColor("black");
|
||||||
|
submit_button_->setForegroundColor("black");
|
||||||
|
submit_button_->setCursor(QCursor(Qt::PointingHandCursor));
|
||||||
|
submit_button_->setFontSize(15);
|
||||||
|
submit_button_->setFixedHeight(50);
|
||||||
|
submit_button_->setCornerRadius(3);
|
||||||
|
|
||||||
|
auto label = new QLabel("Advanced Settings", this);
|
||||||
|
label->setStyleSheet("color: #333333");
|
||||||
|
|
||||||
|
layout->addWidget(label);
|
||||||
|
layout->addWidget(input_);
|
||||||
|
layout->addWidget(submit_button_);
|
||||||
|
|
||||||
|
setLayout(layout);
|
||||||
|
|
||||||
|
connect(input_, SIGNAL(returnPressed()), submit_button_, SIGNAL(clicked()));
|
||||||
|
connect(submit_button_, &QPushButton::clicked, [=]() {
|
||||||
|
emit closing(input_->text());
|
||||||
|
});
|
||||||
|
}
|
|
@ -79,7 +79,7 @@ void MainWindow::removeOverlayProgressBar()
|
||||||
progress_modal_->fadeOut();
|
progress_modal_->fadeOut();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (progress_modal_ != nullptr)
|
if (spinner_ != nullptr)
|
||||||
spinner_->deleteLater();
|
spinner_->deleteLater();
|
||||||
|
|
||||||
progress_modal_ = nullptr;
|
progress_modal_ = nullptr;
|
||||||
|
|
Loading…
Reference in a new issue