Skip to content

Commit

Permalink
Made DlgRegister a friend class of AbstractClient so that it can
Browse files Browse the repository at this point in the history
access user input in case registering to a server fails and the
user is sent back to the registration input dialogue again. This
saves the user the effort of re-typing everything, when presumably
only one thing is incorrect

Adds the feature requested from issue #4982

See #4983 for more information
  • Loading branch information
candyapplecorn committed Jan 13, 2024
1 parent 9d0c4be commit ddf8487
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 21 deletions.
2 changes: 2 additions & 0 deletions cockatrice/src/abstractclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Event_ConnectionClosed;
class Event_ServerShutdown;
class Event_ReplayAdded;
class FeatureSet;
class DlgRegister;

enum ClientStatus
{
Expand All @@ -45,6 +46,7 @@ enum ClientStatus

class AbstractClient : public QObject
{
friend class DlgRegister;
Q_OBJECT
signals:
void statusChanged(ClientStatus _status);
Expand Down
24 changes: 10 additions & 14 deletions cockatrice/src/dlg_register.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "dlg_register.h"

#include "abstractclient.h"
#include "pb/serverinfo_user.pb.h"
#include "settingscache.h"
#include "stringsizes.h"
Expand All @@ -12,13 +13,7 @@
#include <QLabel>
#include <QMessageBox>

DlgRegister::DlgRegister(QWidget *parent,
const QString &initialEmail,
const QString &initialUsername,
const QString &initialPassword,
const QString &initialRealName,
const QString &initialCountry)
: QDialog(parent)
DlgRegister::DlgRegister(QWidget *parent, AbstractClient *abstractClient) : QDialog(parent)

{
ServersSettings &servers = SettingsCache::instance().servers();
Expand All @@ -37,29 +32,30 @@ DlgRegister::DlgRegister(QWidget *parent,
portLabel->setBuddy(portEdit);

playernameLabel = new QLabel(tr("Player &name:"));
playernameEdit = new QLineEdit(servers.getPlayerName().isEmpty() ? initialUsername : servers.getPlayerName());
playernameEdit =
new QLineEdit(servers.getPlayerName().isEmpty() ? abstractClient->getUserName() : servers.getPlayerName());
playernameEdit->setMaxLength(MAX_NAME_LENGTH);
playernameLabel->setBuddy(playernameEdit);

passwordLabel = new QLabel(tr("P&assword:"));
passwordEdit = new QLineEdit(initialPassword);
passwordEdit = new QLineEdit(abstractClient->password);
passwordEdit->setMaxLength(MAX_NAME_LENGTH);
passwordLabel->setBuddy(passwordEdit);
passwordEdit->setEchoMode(QLineEdit::Password);

passwordConfirmationLabel = new QLabel(tr("Password (again):"));
passwordConfirmationEdit = new QLineEdit(initialPassword);
passwordConfirmationEdit = new QLineEdit(abstractClient->password);
passwordConfirmationEdit->setMaxLength(MAX_NAME_LENGTH);
passwordConfirmationLabel->setBuddy(passwordConfirmationEdit);
passwordConfirmationEdit->setEchoMode(QLineEdit::Password);

emailLabel = new QLabel(tr("Email:"));
emailEdit = new QLineEdit(initialEmail);
emailEdit = new QLineEdit(abstractClient->email);
emailEdit->setMaxLength(MAX_NAME_LENGTH);
emailLabel->setBuddy(emailEdit);

emailConfirmationLabel = new QLabel(tr("Email (again):"));
emailConfirmationEdit = new QLineEdit(initialEmail);
emailConfirmationEdit = new QLineEdit(abstractClient->email);
emailConfirmationEdit->setMaxLength(MAX_NAME_LENGTH);
emailConfirmationLabel->setBuddy(emailConfirmationEdit);

Expand Down Expand Up @@ -319,7 +315,7 @@ DlgRegister::DlgRegister(QWidget *parent,
countryEdit->addItem(QPixmap("theme:countries/zm"), "zm");
countryEdit->addItem(QPixmap("theme:countries/zw"), "zw");

int initialCountryIndex = countryEdit->findText(initialCountry);
int initialCountryIndex = countryEdit->findText(abstractClient->country);
if (initialCountryIndex != -1) {
countryEdit->setCurrentIndex(initialCountryIndex);
} else {
Expand All @@ -331,7 +327,7 @@ DlgRegister::DlgRegister(QWidget *parent,
countryEdit->addItem(QPixmap("theme:countries/" + c.toLower()), c);

realnameLabel = new QLabel(tr("Real name:"));
realnameEdit = new QLineEdit();
realnameEdit = new QLineEdit(abstractClient->realName);
realnameEdit->setMaxLength(MAX_NAME_LENGTH);
realnameLabel->setBuddy(realnameEdit);

Expand Down
8 changes: 2 additions & 6 deletions cockatrice/src/dlg_register.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@
class QLabel;
class QPushButton;
class QCheckBox;
class AbstractClient;

class DlgRegister : public QDialog
{
Q_OBJECT
public:
DlgRegister(QWidget *parent = nullptr,
const QString &initialEmail = QString(),
const QString &initialUsername = QString(),
const QString &initialPassword = QString(),
const QString &initialRealName = QString(),
const QString &initialCountry = QString());
DlgRegister(QWidget *parent = nullptr, AbstractClient *abstractClient = nullptr);
QString getHost() const
{
return hostEdit->text();
Expand Down
1 change: 1 addition & 0 deletions cockatrice/src/remoteclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <QWebSocket>

class QTimer;
class DlgRegister;

class RemoteClient : public AbstractClient
{
Expand Down
2 changes: 1 addition & 1 deletion cockatrice/src/window_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ void MainWindow::actConnect()

void MainWindow::actRegister()
{
DlgRegister dlg(this, dlg.getEmail(), dlg.getPlayerName(), dlg.getPassword(), dlg.getRealName(), dlg.getCountry());
DlgRegister dlg(this, client);
if (dlg.exec()) {
client->registerToServer(dlg.getHost(), static_cast<unsigned int>(dlg.getPort()), dlg.getPlayerName(),
dlg.getPassword(), dlg.getEmail(), dlg.getCountry(), dlg.getRealName());
Expand Down

0 comments on commit ddf8487

Please sign in to comment.