From 18695d636d400ae7d4b340c3aab670d8c5b8a182 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Sun, 22 Jul 2018 18:41:15 +0300 Subject: [PATCH] Add input field to specify the device name on login --- src/LoginPage.cpp | 31 ++++++++++++++++++------------- src/LoginPage.h | 9 +++++---- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/LoginPage.cpp b/src/LoginPage.cpp index dbf9d470..c0880bdd 100644 --- a/src/LoginPage.cpp +++ b/src/LoginPage.cpp @@ -95,6 +95,9 @@ LoginPage::LoginPage(QWidget *parent) password_input_->setLabel(tr("Password")); password_input_->setEchoMode(QLineEdit::Password); + deviceName_ = new TextField(this); + deviceName_->setLabel(tr("Device name")); + serverInput_ = new TextField(this); serverInput_->setLabel("Homeserver address"); serverInput_->setPlaceholderText("matrix.org"); @@ -104,7 +107,8 @@ LoginPage::LoginPage(QWidget *parent) serverLayout_->addWidget(serverInput_, 0, Qt::AlignVCenter); form_layout_->addLayout(matrixidLayout_); - form_layout_->addWidget(password_input_, Qt::AlignHCenter, 0); + form_layout_->addWidget(password_input_); + form_layout_->addWidget(deviceName_, Qt::AlignHCenter, 0); form_layout_->addLayout(serverLayout_); button_layout_ = new QHBoxLayout(); @@ -145,6 +149,7 @@ LoginPage::LoginPage(QWidget *parent) connect(login_button_, SIGNAL(clicked()), this, SLOT(onLoginButtonClicked())); connect(matrixid_input_, SIGNAL(returnPressed()), login_button_, SLOT(click())); connect(password_input_, SIGNAL(returnPressed()), login_button_, SLOT(click())); + connect(deviceName_, SIGNAL(returnPressed()), login_button_, SLOT(click())); connect(serverInput_, SIGNAL(returnPressed()), login_button_, SLOT(click())); connect(matrixid_input_, SIGNAL(editingFinished()), this, SLOT(onMatrixIdEntered())); connect(serverInput_, SIGNAL(editingFinished()), this, SLOT(onServerAddressEntered())); @@ -269,19 +274,19 @@ LoginPage::onLoginButtonClicked() return loginError(tr("Empty password")); http::client()->set_server(serverInput_->text().toStdString()); - http::client()->login(user.localpart(), - password_input_->text().toStdString(), - initialDeviceName(), - [this](const mtx::responses::Login &res, mtx::http::RequestErr err) { - if (err) { - emit loginError( - QString::fromStdString(err->matrix_error.error)); - emit errorOccurred(); - return; - } + http::client()->login( + user.localpart(), + password_input_->text().toStdString(), + deviceName_->text().isEmpty() ? initialDeviceName() : deviceName_->text().toStdString(), + [this](const mtx::responses::Login &res, mtx::http::RequestErr err) { + if (err) { + emit loginError(QString::fromStdString(err->matrix_error.error)); + emit errorOccurred(); + return; + } - emit loginOk(res); - }); + emit loginOk(res); + }); emit loggingIn(); } diff --git a/src/LoginPage.h b/src/LoginPage.h index c52ccaa4..cf2d024b 100644 --- a/src/LoginPage.h +++ b/src/LoginPage.h @@ -86,13 +86,13 @@ private: std::string initialDeviceName() { #if defined(Q_OS_MAC) - return "nheko on macOS"; + return "Nheko on macOS"; #elif defined(Q_OS_LINUX) - return "nheko on Linux"; + return "Nheko on Linux"; #elif defined(Q_OS_WIN) - return "nheko on Windows"; + return "Nheko on Windows"; #else - return "nheko"; + return "Nheko"; #endif } @@ -120,5 +120,6 @@ private: TextField *matrixid_input_; TextField *password_input_; + TextField *deviceName_; TextField *serverInput_; };