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
......@@ -9,10 +9,22 @@
<rect>
<x>0</x>
<y>0</y>
<width>420</width>
<height>182</height>
<width>480</width>
<height>200</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>480</width>
<height>200</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>480</width>
<height>200</height>
</size>
</property>
<property name="windowTitle">
<string>Set Registered Name</string>
</property>
......@@ -22,96 +34,605 @@
<property name="modal">
<bool>true</bool>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>20</x>
<y>20</y>
<width>381</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Are you sure you would like to register this name?</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>30</x>
<y>50</y>
<width>351</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Once associated to this account, it cannot be changed.</string>
</property>
</widget>
<widget class="QPushButton" name="confirmBtn">
<property name="geometry">
<rect>
<x>70</x>
<y>140</y>
<width>151</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Confirm Registration</string>
</property>
</widget>
<widget class="QPushButton" name="cancelBtn">
<property name="geometry">
<rect>
<x>260</x>
<y>140</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Cancel</string>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>10</x>
<y>90</y>
<width>231</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>Your new registered name would be:</string>
</property>
</widget>
<widget class="QLabel" name="registeredName">
<property name="enabled">
<bool>true</bool>
</property>
<widget class="QStackedWidget" name="stackedWidget">
<property name="geometry">
<rect>
<x>246</x>
<y>90</y>
<width>161</width>
<height>21</height>
<x>0</x>
<y>0</y>
<width>481</width>
<height>191</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
<property name="maximumSize">
<size>
<width>700</width>
<height>700</height>
</size>
</property>
<property name="text">
<string/>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="startPage">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<spacer name="verticalSpacer_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Are you sure you would like to register this name?</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Once associated to this account, it cannot be changed.</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Your new registered name would be:</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<property name="topMargin">
<number>6</number>
</property>
<item>
<spacer name="horizontalSpacer_10">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="registeredName">
<property name="enabled">
<bool>true</bool>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string/>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_11">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="bottomMargin">
<number>10</number>
</property>
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="startPageConfirmBtn">
<property name="minimumSize">
<size>
<width>150</width>
<height>37</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background: rgb(250, 250, 250); border: none; padding: 10px;</string>
</property>
<property name="text">
<string>Confirm Registration</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_8">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="startPageCancelBtn">
<property name="minimumSize">
<size>
<width>150</width>
<height>37</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background: rgb(250, 250, 250); border: none; padding: 10px;</string>
</property>
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_9">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_6">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="loadingPage">
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<spacer name="verticalSpacer_15">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_15">
<item>
<spacer name="horizontalSpacer_32">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="spinnerLabel">
<property name="minimumSize">
<size>
<width>40</width>
<height>40</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>40</width>
<height>40</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_33">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_16">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="nameRegisteredPage">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<spacer name="horizontalSpacer_12">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_4">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>The name has been successfully registered!</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_13">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="nameNotRegisteredPage">
<layout class="QVBoxLayout" name="verticalLayout_3">