Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remember user inputs after failed registration #4982 #4983

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 MainWindow;

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

class AbstractClient : public QObject
{
friend class MainWindow;
Q_OBJECT
signals:
void statusChanged(ClientStatus _status);
Expand Down
31 changes: 23 additions & 8 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,7 +13,14 @@
#include <QLabel>
#include <QMessageBox>

DlgRegister::DlgRegister(QWidget *parent) : QDialog(parent)
DlgRegister::DlgRegister(QWidget *parent,
QString username,
QString password,
QString email,
QString country,
QString realname)
: QDialog(parent)

{
ServersSettings &servers = SettingsCache::instance().servers();
infoLabel = new QLabel(tr("Enter your information and the information of the server you'd like to register to.\n"
Expand All @@ -30,29 +38,29 @@ DlgRegister::DlgRegister(QWidget *parent) : QDialog(parent)
portLabel->setBuddy(portEdit);

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

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

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

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

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

Expand Down Expand Up @@ -311,13 +319,20 @@ DlgRegister::DlgRegister(QWidget *parent) : QDialog(parent)
countryEdit->addItem(QPixmap("theme:countries/za"), "za");
countryEdit->addItem(QPixmap("theme:countries/zm"), "zm");
countryEdit->addItem(QPixmap("theme:countries/zw"), "zw");
countryEdit->setCurrentIndex(0);

int initialCountryIndex = countryEdit->findText(country);
if (initialCountryIndex != -1) {
countryEdit->setCurrentIndex(initialCountryIndex);
} else {
countryEdit->setCurrentIndex(0);
}

QStringList countries = SettingsCache::instance().getCountries();
foreach (QString c, countries)
countryEdit->addItem(QPixmap("theme:countries/" + c.toLower()), c);

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

Expand Down
8 changes: 7 additions & 1 deletion cockatrice/src/dlg_register.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@
class QLabel;
class QPushButton;
class QCheckBox;
class AbstractClient;

class DlgRegister : public QDialog
{
Q_OBJECT
public:
DlgRegister(QWidget *parent = nullptr);
DlgRegister(QWidget *parent = nullptr,
QString username = "",
QString password = "",
QString email = "",
QString country = "",
QString realname = "");
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
10 changes: 9 additions & 1 deletion cockatrice/src/window_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,15 @@ void MainWindow::actConnect()

void MainWindow::actRegister()
{
DlgRegister dlg(this);
// Note the pre-existing form data so that if the user is bounced back to the dialogue, they
// won't have to re-enter all the information again.
QString username = client->getUserName();
QString password = client->password;
QString email = client->email;
QString country = client->country;
QString realname = client->realName;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ebbit1q now MainWindow is the friend class instead of DlgRegister, and these variables are passed to the DlgRegister constructor


DlgRegister dlg(this, username, password, email, country, realname);
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
Loading