Cockatrice/cockatrice/src/interface/widgets/dialogs/dlg_register.cpp
BruebachL 2b7b4e8168
Some checks are pending
CodeQL / Analyze (cpp) (push) Waiting to run
CodeQL / Analyze (actions) (push) Waiting to run
Build Desktop / Configure (push) Waiting to run
Build Desktop / Debian 13 (push) Blocked by required conditions
Build Desktop / Debian 12 (push) Blocked by required conditions
Build Desktop / Fedora 44 (push) Blocked by required conditions
Build Desktop / Fedora 43 (push) Blocked by required conditions
Build Desktop / Servatrice_Debian 12 (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 (push) Blocked by required conditions
Build Desktop / Ubuntu 24.04 (push) Blocked by required conditions
Build Desktop / Arch (push) Blocked by required conditions
Build Desktop / macOS 13 Intel (push) Blocked by required conditions
Build Desktop / macOS 14 (push) Blocked by required conditions
Build Desktop / macOS 15 (push) Blocked by required conditions
Build Desktop / macOS 26 Debug (push) Blocked by required conditions
Build Desktop / Windows 10 (push) Blocked by required conditions
Build Docker / Servatrice (arm) (push) Waiting to run
Build Docker / Servatrice (x86) (push) Waiting to run
Build Docker / Publish multi-platform Servatrice image (push) Blocked by required conditions
[App] Add onboarding wizard (#7064)
* [App] Add onboarding wizard

Took 10 minutes

Took 3 minutes

Took 7 minutes

Took 9 minutes

Took 2 minutes

Took 1 minute


Took 7 minutes

* Adjust CI

Took 14 minutes

Took 56 seconds

Took 2 seconds

Took 3 seconds

* Adjust CI again

Took 14 minutes

Took 2 seconds

* Comments and fixes

Took 9 seconds


Took 1 minute

* Rebase.

Took 5 minutes

Took 50 seconds

Took 15 seconds

* Comments.

Took 7 minutes

* CI lol

Took 3 minutes

* CI again lol

Took 4 minutes

* Drop some settings, add some new ones.

Took 19 minutes

* Resize when expanding section

Took 4 minutes

Took 3 minutes

Took 7 minutes

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
2026-08-24 23:05:58 +02:00

551 lines
26 KiB
C++

#include "dlg_register.h"
#include "../../../client/settings/cache_settings.h"
#include "../server/handle_public_servers.h"
#include "../server/user/user_info_connection.h"
#include <QComboBox>
#include <QDialogButtonBox>
#include <QGridLayout>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QMessageBox>
#include <QPushButton>
#include <QRadioButton>
#include <QVBoxLayout>
#include <libcockatrice/settings/servers_settings.h>
#include <libcockatrice/utility/string_limits.h>
DlgRegister::DlgRegister(QWidget *parent) : QDialog(parent)
{
// ── Server picker ──────────────────────────────────────────────────
previousHostButton = new QRadioButton(tr("Known Hosts"), this);
previousHosts = new QComboBox(this);
btnDeleteServer = new QPushButton(this);
btnDeleteServer->setIcon(QPixmap("theme:icons/remove_row"));
btnDeleteServer->setToolTip(tr("Delete the currently selected saved server"));
btnDeleteServer->setFixedWidth(30);
connect(btnDeleteServer, &QPushButton::clicked, this, &DlgRegister::actRemoveSavedServer);
hps = new HandlePublicServers(this);
btnRefreshServers = new QPushButton(this);
btnRefreshServers->setIcon(QPixmap("theme:icons/sync"));
btnRefreshServers->setToolTip(tr("Refresh the server list with known public servers"));
btnRefreshServers->setFixedWidth(30);
connect(hps, &HandlePublicServers::sigPublicServersDownloadedSuccessfully, this, [this] { rebuildComboBoxList(); });
connect(hps, &HandlePublicServers::sigPublicServersDownloadedUnsuccessfully, this,
&DlgRegister::rebuildComboBoxList);
connect(btnRefreshServers, &QPushButton::released, this, &DlgRegister::downloadThePublicServers);
newHostButton = new QRadioButton(tr("New Host"), this);
auto *serverPickerRow = new QHBoxLayout;
serverPickerRow->addWidget(previousHosts);
serverPickerRow->addWidget(btnDeleteServer);
serverPickerRow->addWidget(btnRefreshServers);
auto *serverGroupLayout = new QVBoxLayout;
serverGroupLayout->addWidget(previousHostButton);
serverGroupLayout->addLayout(serverPickerRow);
serverGroupLayout->addWidget(newHostButton);
auto *serverGroupBox = new QGroupBox(tr("Server"));
serverGroupBox->setLayout(serverGroupLayout);
// ── Registration fields ────────────────────────────────────────────
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"
"Your email will be used to verify your account."));
infoLabel->setWordWrap(true);
hostLabel = new QLabel(tr("&Host:"));
hostEdit = new QLineEdit(servers.getHostname());
hostEdit->setMaxLength(MAX_NAME_LENGTH);
hostLabel->setBuddy(hostEdit);
portLabel = new QLabel(tr("&Port:"));
portEdit = new QLineEdit(servers.getPort());
portEdit->setValidator(new QIntValidator(0, 0xffff, portEdit));
portLabel->setBuddy(portEdit);
playernameLabel = new QLabel(tr("Player &name:"));
playernameEdit = new QLineEdit(servers.getPlayerName());
playernameEdit->setMaxLength(MAX_NAME_LENGTH);
playernameLabel->setBuddy(playernameEdit);
passwordLabel = new QLabel(tr("P&assword:"));
passwordEdit = new QLineEdit();
passwordEdit->setMaxLength(MAX_NAME_LENGTH);
passwordLabel->setBuddy(passwordEdit);
passwordEdit->setEchoMode(QLineEdit::Password);
passwordConfirmationLabel = new QLabel(tr("Password (again):"));
passwordConfirmationEdit = new QLineEdit();
passwordConfirmationEdit->setMaxLength(MAX_NAME_LENGTH);
passwordConfirmationLabel->setBuddy(passwordConfirmationEdit);
passwordConfirmationEdit->setEchoMode(QLineEdit::Password);
emailLabel = new QLabel(tr("Email:"));
emailEdit = new QLineEdit();
emailEdit->setMaxLength(MAX_NAME_LENGTH);
emailLabel->setBuddy(emailEdit);
emailConfirmationLabel = new QLabel(tr("Email (again):"));
emailConfirmationEdit = new QLineEdit();
emailConfirmationEdit->setMaxLength(MAX_NAME_LENGTH);
emailConfirmationLabel->setBuddy(emailConfirmationEdit);
countryLabel = new QLabel(tr("Country:"));
countryEdit = new QComboBox();
countryLabel->setBuddy(countryEdit);
countryEdit->insertItem(0, tr("Undefined"));
countryEdit->addItem(QPixmap("theme:countries/ad"), "ad");
countryEdit->addItem(QPixmap("theme:countries/ae"), "ae");
countryEdit->addItem(QPixmap("theme:countries/af"), "af");
countryEdit->addItem(QPixmap("theme:countries/ag"), "ag");
countryEdit->addItem(QPixmap("theme:countries/ai"), "ai");
countryEdit->addItem(QPixmap("theme:countries/al"), "al");
countryEdit->addItem(QPixmap("theme:countries/am"), "am");
countryEdit->addItem(QPixmap("theme:countries/ao"), "ao");
countryEdit->addItem(QPixmap("theme:countries/aq"), "aq");
countryEdit->addItem(QPixmap("theme:countries/ar"), "ar");
countryEdit->addItem(QPixmap("theme:countries/as"), "as");
countryEdit->addItem(QPixmap("theme:countries/at"), "at");
countryEdit->addItem(QPixmap("theme:countries/au"), "au");
countryEdit->addItem(QPixmap("theme:countries/aw"), "aw");
countryEdit->addItem(QPixmap("theme:countries/ax"), "ax");
countryEdit->addItem(QPixmap("theme:countries/az"), "az");
countryEdit->addItem(QPixmap("theme:countries/ba"), "ba");
countryEdit->addItem(QPixmap("theme:countries/bb"), "bb");
countryEdit->addItem(QPixmap("theme:countries/bd"), "bd");
countryEdit->addItem(QPixmap("theme:countries/be"), "be");
countryEdit->addItem(QPixmap("theme:countries/bf"), "bf");
countryEdit->addItem(QPixmap("theme:countries/bg"), "bg");
countryEdit->addItem(QPixmap("theme:countries/bh"), "bh");
countryEdit->addItem(QPixmap("theme:countries/bi"), "bi");
countryEdit->addItem(QPixmap("theme:countries/bj"), "bj");
countryEdit->addItem(QPixmap("theme:countries/bl"), "bl");
countryEdit->addItem(QPixmap("theme:countries/bm"), "bm");
countryEdit->addItem(QPixmap("theme:countries/bn"), "bn");
countryEdit->addItem(QPixmap("theme:countries/bo"), "bo");
countryEdit->addItem(QPixmap("theme:countries/bq"), "bq");
countryEdit->addItem(QPixmap("theme:countries/br"), "br");
countryEdit->addItem(QPixmap("theme:countries/bs"), "bs");
countryEdit->addItem(QPixmap("theme:countries/bt"), "bt");
countryEdit->addItem(QPixmap("theme:countries/bv"), "bv");
countryEdit->addItem(QPixmap("theme:countries/bw"), "bw");
countryEdit->addItem(QPixmap("theme:countries/by"), "by");
countryEdit->addItem(QPixmap("theme:countries/bz"), "bz");
countryEdit->addItem(QPixmap("theme:countries/ca"), "ca");
countryEdit->addItem(QPixmap("theme:countries/cc"), "cc");
countryEdit->addItem(QPixmap("theme:countries/cd"), "cd");
countryEdit->addItem(QPixmap("theme:countries/cf"), "cf");
countryEdit->addItem(QPixmap("theme:countries/cg"), "cg");
countryEdit->addItem(QPixmap("theme:countries/ch"), "ch");
countryEdit->addItem(QPixmap("theme:countries/ci"), "ci");
countryEdit->addItem(QPixmap("theme:countries/ck"), "ck");
countryEdit->addItem(QPixmap("theme:countries/cl"), "cl");
countryEdit->addItem(QPixmap("theme:countries/cm"), "cm");
countryEdit->addItem(QPixmap("theme:countries/cn"), "cn");
countryEdit->addItem(QPixmap("theme:countries/co"), "co");
countryEdit->addItem(QPixmap("theme:countries/cr"), "cr");
countryEdit->addItem(QPixmap("theme:countries/cu"), "cu");
countryEdit->addItem(QPixmap("theme:countries/cv"), "cv");
countryEdit->addItem(QPixmap("theme:countries/cw"), "cw");
countryEdit->addItem(QPixmap("theme:countries/cx"), "cx");
countryEdit->addItem(QPixmap("theme:countries/cy"), "cy");
countryEdit->addItem(QPixmap("theme:countries/cz"), "cz");
countryEdit->addItem(QPixmap("theme:countries/de"), "de");
countryEdit->addItem(QPixmap("theme:countries/dj"), "dj");
countryEdit->addItem(QPixmap("theme:countries/dk"), "dk");
countryEdit->addItem(QPixmap("theme:countries/dm"), "dm");
countryEdit->addItem(QPixmap("theme:countries/do"), "do");
countryEdit->addItem(QPixmap("theme:countries/dz"), "dz");
countryEdit->addItem(QPixmap("theme:countries/ec"), "ec");
countryEdit->addItem(QPixmap("theme:countries/ee"), "ee");
countryEdit->addItem(QPixmap("theme:countries/eg"), "eg");
countryEdit->addItem(QPixmap("theme:countries/eh"), "eh");
countryEdit->addItem(QPixmap("theme:countries/er"), "er");
countryEdit->addItem(QPixmap("theme:countries/es"), "es");
countryEdit->addItem(QPixmap("theme:countries/et"), "et");
countryEdit->addItem(QPixmap("theme:countries/eu"), "eu");
countryEdit->addItem(QPixmap("theme:countries/fi"), "fi");
countryEdit->addItem(QPixmap("theme:countries/fj"), "fj");
countryEdit->addItem(QPixmap("theme:countries/fk"), "fk");
countryEdit->addItem(QPixmap("theme:countries/fm"), "fm");
countryEdit->addItem(QPixmap("theme:countries/fo"), "fo");
countryEdit->addItem(QPixmap("theme:countries/fr"), "fr");
countryEdit->addItem(QPixmap("theme:countries/ga"), "ga");
countryEdit->addItem(QPixmap("theme:countries/gb"), "gb");
countryEdit->addItem(QPixmap("theme:countries/gd"), "gd");
countryEdit->addItem(QPixmap("theme:countries/ge"), "ge");
countryEdit->addItem(QPixmap("theme:countries/gf"), "gf");
countryEdit->addItem(QPixmap("theme:countries/gg"), "gg");
countryEdit->addItem(QPixmap("theme:countries/gh"), "gh");
countryEdit->addItem(QPixmap("theme:countries/gi"), "gi");
countryEdit->addItem(QPixmap("theme:countries/gl"), "gl");
countryEdit->addItem(QPixmap("theme:countries/gm"), "gm");
countryEdit->addItem(QPixmap("theme:countries/gn"), "gn");
countryEdit->addItem(QPixmap("theme:countries/gp"), "gp");
countryEdit->addItem(QPixmap("theme:countries/gq"), "gq");
countryEdit->addItem(QPixmap("theme:countries/gr"), "gr");
countryEdit->addItem(QPixmap("theme:countries/gs"), "gs");
countryEdit->addItem(QPixmap("theme:countries/gt"), "gt");
countryEdit->addItem(QPixmap("theme:countries/gu"), "gu");
countryEdit->addItem(QPixmap("theme:countries/gw"), "gw");
countryEdit->addItem(QPixmap("theme:countries/gy"), "gy");
countryEdit->addItem(QPixmap("theme:countries/hk"), "hk");
countryEdit->addItem(QPixmap("theme:countries/hm"), "hm");
countryEdit->addItem(QPixmap("theme:countries/hn"), "hn");
countryEdit->addItem(QPixmap("theme:countries/hr"), "hr");
countryEdit->addItem(QPixmap("theme:countries/ht"), "ht");
countryEdit->addItem(QPixmap("theme:countries/hu"), "hu");
countryEdit->addItem(QPixmap("theme:countries/id"), "id");
countryEdit->addItem(QPixmap("theme:countries/ie"), "ie");
countryEdit->addItem(QPixmap("theme:countries/il"), "il");
countryEdit->addItem(QPixmap("theme:countries/im"), "im");
countryEdit->addItem(QPixmap("theme:countries/in"), "in");
countryEdit->addItem(QPixmap("theme:countries/io"), "io");
countryEdit->addItem(QPixmap("theme:countries/iq"), "iq");
countryEdit->addItem(QPixmap("theme:countries/ir"), "ir");
countryEdit->addItem(QPixmap("theme:countries/is"), "is");
countryEdit->addItem(QPixmap("theme:countries/it"), "it");
countryEdit->addItem(QPixmap("theme:countries/je"), "je");
countryEdit->addItem(QPixmap("theme:countries/jm"), "jm");
countryEdit->addItem(QPixmap("theme:countries/jo"), "jo");
countryEdit->addItem(QPixmap("theme:countries/jp"), "jp");
countryEdit->addItem(QPixmap("theme:countries/ke"), "ke");
countryEdit->addItem(QPixmap("theme:countries/kg"), "kg");
countryEdit->addItem(QPixmap("theme:countries/kh"), "kh");
countryEdit->addItem(QPixmap("theme:countries/ki"), "ki");
countryEdit->addItem(QPixmap("theme:countries/km"), "km");
countryEdit->addItem(QPixmap("theme:countries/kn"), "kn");
countryEdit->addItem(QPixmap("theme:countries/kp"), "kp");
countryEdit->addItem(QPixmap("theme:countries/kr"), "kr");
countryEdit->addItem(QPixmap("theme:countries/kw"), "kw");
countryEdit->addItem(QPixmap("theme:countries/ky"), "ky");
countryEdit->addItem(QPixmap("theme:countries/kz"), "kz");
countryEdit->addItem(QPixmap("theme:countries/la"), "la");
countryEdit->addItem(QPixmap("theme:countries/lb"), "lb");
countryEdit->addItem(QPixmap("theme:countries/lc"), "lc");
countryEdit->addItem(QPixmap("theme:countries/li"), "li");
countryEdit->addItem(QPixmap("theme:countries/lk"), "lk");
countryEdit->addItem(QPixmap("theme:countries/lr"), "lr");
countryEdit->addItem(QPixmap("theme:countries/ls"), "ls");
countryEdit->addItem(QPixmap("theme:countries/lt"), "lt");
countryEdit->addItem(QPixmap("theme:countries/lu"), "lu");
countryEdit->addItem(QPixmap("theme:countries/lv"), "lv");
countryEdit->addItem(QPixmap("theme:countries/ly"), "ly");
countryEdit->addItem(QPixmap("theme:countries/ma"), "ma");
countryEdit->addItem(QPixmap("theme:countries/mc"), "mc");
countryEdit->addItem(QPixmap("theme:countries/md"), "md");
countryEdit->addItem(QPixmap("theme:countries/me"), "me");
countryEdit->addItem(QPixmap("theme:countries/mf"), "mf");
countryEdit->addItem(QPixmap("theme:countries/mg"), "mg");
countryEdit->addItem(QPixmap("theme:countries/mh"), "mh");
countryEdit->addItem(QPixmap("theme:countries/mk"), "mk");
countryEdit->addItem(QPixmap("theme:countries/ml"), "ml");
countryEdit->addItem(QPixmap("theme:countries/mm"), "mm");
countryEdit->addItem(QPixmap("theme:countries/mn"), "mn");
countryEdit->addItem(QPixmap("theme:countries/mo"), "mo");
countryEdit->addItem(QPixmap("theme:countries/mp"), "mp");
countryEdit->addItem(QPixmap("theme:countries/mq"), "mq");
countryEdit->addItem(QPixmap("theme:countries/mr"), "mr");
countryEdit->addItem(QPixmap("theme:countries/ms"), "ms");
countryEdit->addItem(QPixmap("theme:countries/mt"), "mt");
countryEdit->addItem(QPixmap("theme:countries/mu"), "mu");
countryEdit->addItem(QPixmap("theme:countries/mv"), "mv");
countryEdit->addItem(QPixmap("theme:countries/mw"), "mw");
countryEdit->addItem(QPixmap("theme:countries/mx"), "mx");
countryEdit->addItem(QPixmap("theme:countries/my"), "my");
countryEdit->addItem(QPixmap("theme:countries/mz"), "mz");
countryEdit->addItem(QPixmap("theme:countries/na"), "na");
countryEdit->addItem(QPixmap("theme:countries/nc"), "nc");
countryEdit->addItem(QPixmap("theme:countries/ne"), "ne");
countryEdit->addItem(QPixmap("theme:countries/nf"), "nf");
countryEdit->addItem(QPixmap("theme:countries/ng"), "ng");
countryEdit->addItem(QPixmap("theme:countries/ni"), "ni");
countryEdit->addItem(QPixmap("theme:countries/nl"), "nl");
countryEdit->addItem(QPixmap("theme:countries/no"), "no");
countryEdit->addItem(QPixmap("theme:countries/np"), "np");
countryEdit->addItem(QPixmap("theme:countries/nr"), "nr");
countryEdit->addItem(QPixmap("theme:countries/nu"), "nu");
countryEdit->addItem(QPixmap("theme:countries/nz"), "nz");
countryEdit->addItem(QPixmap("theme:countries/om"), "om");
countryEdit->addItem(QPixmap("theme:countries/pa"), "pa");
countryEdit->addItem(QPixmap("theme:countries/pe"), "pe");
countryEdit->addItem(QPixmap("theme:countries/pf"), "pf");
countryEdit->addItem(QPixmap("theme:countries/pg"), "pg");
countryEdit->addItem(QPixmap("theme:countries/ph"), "ph");
countryEdit->addItem(QPixmap("theme:countries/pk"), "pk");
countryEdit->addItem(QPixmap("theme:countries/pl"), "pl");
countryEdit->addItem(QPixmap("theme:countries/pm"), "pm");
countryEdit->addItem(QPixmap("theme:countries/pn"), "pn");
countryEdit->addItem(QPixmap("theme:countries/pr"), "pr");
countryEdit->addItem(QPixmap("theme:countries/ps"), "ps");
countryEdit->addItem(QPixmap("theme:countries/pt"), "pt");
countryEdit->addItem(QPixmap("theme:countries/pw"), "pw");
countryEdit->addItem(QPixmap("theme:countries/py"), "py");
countryEdit->addItem(QPixmap("theme:countries/qa"), "qa");
countryEdit->addItem(QPixmap("theme:countries/re"), "re");
countryEdit->addItem(QPixmap("theme:countries/ro"), "ro");
countryEdit->addItem(QPixmap("theme:countries/rs"), "rs");
countryEdit->addItem(QPixmap("theme:countries/ru"), "ru");
countryEdit->addItem(QPixmap("theme:countries/rw"), "rw");
countryEdit->addItem(QPixmap("theme:countries/sa"), "sa");
countryEdit->addItem(QPixmap("theme:countries/sb"), "sb");
countryEdit->addItem(QPixmap("theme:countries/sc"), "sc");
countryEdit->addItem(QPixmap("theme:countries/sd"), "sd");
countryEdit->addItem(QPixmap("theme:countries/se"), "se");
countryEdit->addItem(QPixmap("theme:countries/sg"), "sg");
countryEdit->addItem(QPixmap("theme:countries/sh"), "sh");
countryEdit->addItem(QPixmap("theme:countries/si"), "si");
countryEdit->addItem(QPixmap("theme:countries/sj"), "sj");
countryEdit->addItem(QPixmap("theme:countries/sk"), "sk");
countryEdit->addItem(QPixmap("theme:countries/sl"), "sl");
countryEdit->addItem(QPixmap("theme:countries/sm"), "sm");
countryEdit->addItem(QPixmap("theme:countries/sn"), "sn");
countryEdit->addItem(QPixmap("theme:countries/so"), "so");
countryEdit->addItem(QPixmap("theme:countries/sr"), "sr");
countryEdit->addItem(QPixmap("theme:countries/ss"), "ss");
countryEdit->addItem(QPixmap("theme:countries/st"), "st");
countryEdit->addItem(QPixmap("theme:countries/sv"), "sv");
countryEdit->addItem(QPixmap("theme:countries/sx"), "sx");
countryEdit->addItem(QPixmap("theme:countries/sy"), "sy");
countryEdit->addItem(QPixmap("theme:countries/sz"), "sz");
countryEdit->addItem(QPixmap("theme:countries/tc"), "tc");
countryEdit->addItem(QPixmap("theme:countries/td"), "td");
countryEdit->addItem(QPixmap("theme:countries/tf"), "tf");
countryEdit->addItem(QPixmap("theme:countries/tg"), "tg");
countryEdit->addItem(QPixmap("theme:countries/th"), "th");
countryEdit->addItem(QPixmap("theme:countries/tj"), "tj");
countryEdit->addItem(QPixmap("theme:countries/tk"), "tk");
countryEdit->addItem(QPixmap("theme:countries/tl"), "tl");
countryEdit->addItem(QPixmap("theme:countries/tm"), "tm");
countryEdit->addItem(QPixmap("theme:countries/tn"), "tn");
countryEdit->addItem(QPixmap("theme:countries/to"), "to");
countryEdit->addItem(QPixmap("theme:countries/tr"), "tr");
countryEdit->addItem(QPixmap("theme:countries/tt"), "tt");
countryEdit->addItem(QPixmap("theme:countries/tv"), "tv");
countryEdit->addItem(QPixmap("theme:countries/tw"), "tw");
countryEdit->addItem(QPixmap("theme:countries/tz"), "tz");
countryEdit->addItem(QPixmap("theme:countries/ua"), "ua");
countryEdit->addItem(QPixmap("theme:countries/ug"), "ug");
countryEdit->addItem(QPixmap("theme:countries/um"), "um");
countryEdit->addItem(QPixmap("theme:countries/us"), "us");
countryEdit->addItem(QPixmap("theme:countries/uy"), "uy");
countryEdit->addItem(QPixmap("theme:countries/uz"), "uz");
countryEdit->addItem(QPixmap("theme:countries/va"), "va");
countryEdit->addItem(QPixmap("theme:countries/vc"), "vc");
countryEdit->addItem(QPixmap("theme:countries/ve"), "ve");
countryEdit->addItem(QPixmap("theme:countries/vg"), "vg");
countryEdit->addItem(QPixmap("theme:countries/vi"), "vi");
countryEdit->addItem(QPixmap("theme:countries/vn"), "vn");
countryEdit->addItem(QPixmap("theme:countries/vu"), "vu");
countryEdit->addItem(QPixmap("theme:countries/wf"), "wf");
countryEdit->addItem(QPixmap("theme:countries/ws"), "ws");
countryEdit->addItem(QPixmap("theme:countries/xk"), "xk");
countryEdit->addItem(QPixmap("theme:countries/ye"), "ye");
countryEdit->addItem(QPixmap("theme:countries/yt"), "yt");
countryEdit->addItem(QPixmap("theme:countries/za"), "za");
countryEdit->addItem(QPixmap("theme:countries/zm"), "zm");
countryEdit->addItem(QPixmap("theme:countries/zw"), "zw");
countryEdit->setCurrentIndex(0);
QStringList countries = SettingsCache::instance().getCountries();
for (const QString &c : countries) {
countryEdit->addItem(QPixmap("theme:countries/" + c.toLower()), c);
}
realnameLabel = new QLabel(tr("Real name:"));
realnameEdit = new QLineEdit();
realnameEdit->setMaxLength(MAX_NAME_LENGTH);
realnameLabel->setBuddy(realnameEdit);
// ── Layout ─────────────────────────────────────────────────────────
auto *grid = new QGridLayout;
grid->addWidget(serverGroupBox, 0, 0, 1, 2);
grid->addWidget(infoLabel, 1, 0, 1, 2);
grid->addWidget(hostLabel, 2, 0);
grid->addWidget(hostEdit, 2, 1);
grid->addWidget(portLabel, 3, 0);
grid->addWidget(portEdit, 3, 1);
grid->addWidget(playernameLabel, 4, 0);
grid->addWidget(playernameEdit, 4, 1);
grid->addWidget(passwordLabel, 5, 0);
grid->addWidget(passwordEdit, 5, 1);
grid->addWidget(passwordConfirmationLabel, 6, 0);
grid->addWidget(passwordConfirmationEdit, 6, 1);
grid->addWidget(emailLabel, 7, 0);
grid->addWidget(emailEdit, 7, 1);
grid->addWidget(emailConfirmationLabel, 8, 0);
grid->addWidget(emailConfirmationEdit, 8, 1);
grid->addWidget(countryLabel, 10, 0);
grid->addWidget(countryEdit, 10, 1);
grid->addWidget(realnameLabel, 11, 0);
grid->addWidget(realnameEdit, 11, 1);
auto *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttonBox, &QDialogButtonBox::accepted, this, &DlgRegister::actOk);
connect(buttonBox, &QDialogButtonBox::rejected, this, &DlgRegister::reject);
auto *mainLayout = new QVBoxLayout;
mainLayout->addLayout(grid);
mainLayout->addWidget(buttonBox);
setLayout(mainLayout);
setWindowTitle(tr("Register to server"));
setMinimumWidth(360);
connect(previousHostButton, &QRadioButton::toggled, this, &DlgRegister::previousHostSelected);
connect(newHostButton, &QRadioButton::toggled, this, &DlgRegister::newHostSelected);
connect(previousHosts, &QComboBox::currentTextChanged, this, &DlgRegister::updateDisplayInfo);
previousHostButton->setChecked(true);
preRebuildComboBoxList();
}
DlgRegister::~DlgRegister() = default;
void DlgRegister::downloadThePublicServers()
{
btnRefreshServers->setDisabled(true);
previousHosts->clear();
previousHosts->addItem(placeHolderText);
hps->downloadPublicServers();
}
void DlgRegister::preRebuildComboBoxList()
{
UserConnection_Information uci;
savedHostList = uci.getServerInfo();
if (savedHostList.size() == 1) {
downloadThePublicServers();
} else {
rebuildComboBoxList();
}
}
void DlgRegister::rebuildComboBoxList(int failure)
{
Q_UNUSED(failure);
previousHosts->clear();
UserConnection_Information uci;
savedHostList = uci.getServerInfo();
auto &servers = SettingsCache::instance().servers();
QString previousHostName = servers.getPrevioushostName();
for (const auto &pair : savedHostList) {
const auto &tmp = pair.second;
QString saveName = tmp.getSaveName();
if (saveName.size()) {
previousHosts->addItem(saveName);
if (saveName.compare(previousHostName) == 0) {
previousHosts->setCurrentIndex(previousHosts->count() - 1);
}
}
}
btnRefreshServers->setDisabled(false);
}
void DlgRegister::previousHostSelected(bool state)
{
if (state) {
previousHosts->setDisabled(false);
btnRefreshServers->setDisabled(false);
hostEdit->setDisabled(true);
portEdit->setDisabled(true);
}
}
void DlgRegister::newHostSelected(bool state)
{
if (state) {
previousHosts->setDisabled(true);
btnRefreshServers->setDisabled(true);
hostEdit->setDisabled(false);
hostEdit->clear();
hostEdit->setPlaceholderText(tr("Server URL"));
portEdit->setDisabled(false);
portEdit->clear();
portEdit->setPlaceholderText(tr("Communication Port"));
playernameEdit->setDisabled(false);
playernameEdit->clear();
} else {
// Rebuild the list so the previously selected host's details are
// repopulated (mirrors DlgConnect::newHostSelected).
preRebuildComboBoxList();
}
}
void DlgRegister::updateDisplayInfo(const QString &saveName)
{
if (saveName.isEmpty() || saveName == placeHolderText) {
return;
}
UserConnection_Information uci;
QStringList _data = uci.getServerInfo(saveName);
if (_data.size() < 7) {
return;
}
hostEdit->setText(_data.at(1));
portEdit->setText(_data.at(2));
playernameEdit->setText(_data.at(3));
}
void DlgRegister::actOk()
{
if (passwordEdit->text().length() < 8) {
QMessageBox::critical(this, tr("Registration Warning"), tr("Your password is too short."));
return;
} else if (passwordEdit->text() != passwordConfirmationEdit->text()) {
QMessageBox::critical(this, tr("Registration Warning"), tr("Your passwords do not match, please try again."));
return;
} else if (emailConfirmationEdit->text() != emailEdit->text()) {
QMessageBox::critical(this, tr("Registration Warning"),
tr("Your email addresses do not match, please try again."));
return;
}
if (playernameEdit->text().isEmpty()) {
QMessageBox::critical(this, tr("Registration Warning"), tr("The player name can't be empty."));
return;
}
ServersSettings &servers = SettingsCache::instance().servers();
if (newHostButton->isChecked()) {
// Persist the new host so it shows up in the Connect dialog later.
// The password is never stored: the account is not verified yet.
const QString host = hostEdit->text().trimmed();
if (!host.isEmpty()) {
servers.addNewServer(host, host, portEdit->text().trimmed(), playernameEdit->text().trimmed(), QString(),
false);
servers.setPrevioushostName(host);
}
} else {
const QString saveName = previousHosts->currentText();
if (!saveName.isEmpty() && saveName != placeHolderText) {
servers.setPrevioushostName(saveName);
}
}
accept();
}
void DlgRegister::actRemoveSavedServer()
{
SettingsCache::instance().servers().removeServer(hostEdit->text());
previousHosts->removeItem(previousHosts->currentIndex());
}