Commit 26c86617 authored by Isa's avatar Isa Committed by Andreas Traczyk

ux: add name registration to settings

Change-Id: I7ea11b56984b4aad989d145bb92328cb676c85b4
parent 9316d47f
......@@ -19,23 +19,29 @@
#include "regnamedialog.h"
#include "ui_regnamedialog.h"
#include <QTimer>
RegNameDialog::RegNameDialog(const QString& newRegName, QWidget* parent)
:ui(new Ui::RegNameDialog),
QDialog(parent)
:QDialog(parent),
ui(new Ui::RegNameDialog),
registeredName_(newRegName),
gif(new QMovie(":/images/ajax-loader.gif"))
{
ui->setupUi(this);
ui->stackedWidget->setCurrentWidget(ui->startPage);
ui->registeredName->setText(newRegName);
connect(ui->confirmBtn, &QPushButton::clicked, [this]() {
accept();
}
);
connect(ui->startPageConfirmBtn, &QPushButton::clicked, this, &RegNameDialog::startNameRegistration);
connect(ui->cancelBtn, &QPushButton::clicked, [this]() {
connect(ui->startPageCancelBtn, &QPushButton::clicked, [this]() {
reject();
}
);
ui->registeredName->setTextInteractionFlags(Qt::TextSelectableByMouse);
// get name registration result
connect(LRCInstance::editableAccountModel(), &lrc::api::NewAccountModel::nameRegistrationEnded,
this, &RegNameDialog::nameRegistrationResultSlot);
}
RegNameDialog::~RegNameDialog()
......@@ -44,3 +50,34 @@ RegNameDialog::~RegNameDialog()
delete ui;
}
void
RegNameDialog::startNameRegistration()
{
LRCInstance::editableAccountModel()->registerName(LRCInstance::getCurrAccId(),
"", registeredName_.toStdString());
startSpinner();
}
void
RegNameDialog::nameRegistrationResultSlot(const std::string& accountId,
lrc::api::account::RegisterNameStatus status, const std::string& registerdName)
{
gif->stop();
if(status == lrc::api::account::RegisterNameStatus::SUCCESS) {
ui->stackedWidget->setCurrentWidget(ui->nameRegisteredPage);
QTimer::singleShot(1000, this, &RegNameDialog::accept);
} else {
ui->stackedWidget->setCurrentWidget(ui->nameNotRegisteredPage);
QTimer::singleShot(1000, this, &RegNameDialog::reject);
}
}
void
RegNameDialog::startSpinner()
{
ui->stackedWidget->setCurrentWidget(ui->loadingPage);
ui->spinnerLabel->setMovie(gif);
gif->start();
}
\ No newline at end of file
......@@ -18,20 +18,33 @@
#pragma once
#include <QDialog>
#include <QMovie>
#include "lrcinstance.h"
#include "api/newaccountmodel.h"
namespace Ui {
class RegNameDialog;
}
class RegNameDialog : public QDialog
{
Q_OBJECT
RegNameDialog(const RegNameDialog& cpy);
class RegNameDialog : public QDialog
{
Q_OBJECT
RegNameDialog(const RegNameDialog& cpy);
public:
RegNameDialog(const QString& newRegName = "", QWidget* parent = nullptr);
~RegNameDialog();
~RegNameDialog();
private slots:
void nameRegistrationResultSlot(const std::string& accountId,
lrc::api::account::RegisterNameStatus status, const std::string& registerdName);
void startNameRegistration();
private:
Ui::RegNameDialog* ui;
QString registeredName_;
QMovie* gif;
void startSpinner();
};
\ No newline at end of file
This diff is collapsed.
......@@ -247,8 +247,6 @@ SettingsWidget::updateAccountInfoDisplayed()
ui->currentRegisteredID->setText(QString::fromStdString(LRCInstance::getCurrentAccountInfo().registeredName));
ui->currentRingID->setText(QString::fromStdString(LRCInstance::getCurrentAccountInfo().profileInfo.uri));
ui->currentRegisteredID->setReadOnly(true);
// if no registered name is found for account
if (LRCInstance::getCurrentAccountInfo().registeredName.empty()) {
ui->currentRegisteredID->setReadOnly(false);
......@@ -367,8 +365,7 @@ SettingsWidget::validateRegNameForm(const QString& regName)
QRegularExpression regExp(" ");
if (regName.size() > 2 && !regName.contains(regExp)) {
return true;
}
else {
} else {
return false;
}
}
......@@ -444,7 +441,6 @@ void SettingsWidget::setRegNameUi(RegName stat)
ui->regNameButton->setEnabled(true);
connect(ui->regNameButton, &QPushButton::clicked, this, &SettingsWidget::regNameRegisteredSlot);
break;
case RegName::SEARCHING:
......@@ -455,11 +451,12 @@ void SettingsWidget::setRegNameUi(RegName stat)
connect(gif, SIGNAL(frameChanged(int)), this, SLOT(setButtonIconSlot(int)));
gif->start();
ui->regNameButton->setEnabled(false);
break;
}
}
void SettingsWidget::setButtonIconSlot(int frame)
void
SettingsWidget::setButtonIconSlot(int frame)
{
Q_UNUSED(frame);
ui->regNameButton->setIcon(QIcon(gif->currentPixmap()));
......@@ -471,10 +468,13 @@ SettingsWidget::regNameRegisteredSlot()
if (!regNameBtn_) { return; }
RegNameDialog regNameDialog(registeredName_, this);
if (regNameDialog.exec() == QDialog::Accepted) { // if user confirms regName choice
if (regNameDialog.exec() == QDialog::Accepted) {
ui->currentRegisteredID->setReadOnly(true);
}
else {
ui->currentRegisteredID->setText(registeredName_);
lrc::api::account::ConfProperties_t accountProperties = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), accountProperties);
} else {
ui->currentRegisteredID->setText("");
registeredName_ = "";
}
......@@ -695,7 +695,7 @@ SettingsWidget::setConnections()
this, &SettingsWidget::updateAndShowDevicesSlot);
// account settings setters {
connect(ui->accountEnableCheckBox, &QAbstractButton::clicked, this, &SettingsWidget::setAccEnableSlot);
connect(ui->accountEnableCheckBox, &QCheckBox::clicked, this, &SettingsWidget::setAccEnableSlot);
connect(ui->displayNameLineEdit, &QLineEdit::textChanged, [this](const QString& displayName) {
LRCInstance::setCurrAccDisplayName(displayName.toStdString());
......@@ -965,4 +965,4 @@ void
SettingsWidget::stopVideo()
{
Video::PreviewManager::instance().stopPreview();
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment