diff --git a/src/config/configfile.cpp b/src/config/configfile.cpp index fd749873..b7aeda83 100644 --- a/src/config/configfile.cpp +++ b/src/config/configfile.cpp @@ -50,7 +50,7 @@ ConfigFile::ConfigFile(char *argv0, bool readonly) : noWriteAccess(readonly) myConfigState = OK; // !!!! Revisionsnummer der Configdefaults !!!!! - configRev = 86; + configRev = 87; //standard defaults logOnOffDefault = "1"; @@ -237,6 +237,7 @@ ConfigFile::ConfigFile(char *argv0, bool readonly) : noWriteAccess(readonly) configList.push_back(ConfigInfo("ChatCleanerUseIpv6", CONFIG_TYPE_INT, "0")); configList.push_back(ConfigInfo("MyName", CONFIG_TYPE_STRING, "Human Player")); configList.push_back(ConfigInfo("MyAvatar", CONFIG_TYPE_STRING, "")); + configList.push_back(ConfigInfo("MyRememberedNameDuringGuestLogin", CONFIG_TYPE_STRING, "")); configList.push_back(ConfigInfo("Opponent1Name", CONFIG_TYPE_STRING, "Player 1")); configList.push_back(ConfigInfo("Opponent1Avatar", CONFIG_TYPE_STRING, "")); configList.push_back(ConfigInfo("Opponent2Name", CONFIG_TYPE_STRING, "Player 2")); diff --git a/src/gui/qt/internetgamelogindialog/internetgamelogindialogimpl.cpp b/src/gui/qt/internetgamelogindialog/internetgamelogindialogimpl.cpp index 5fcc2a95..f4506877 100644 --- a/src/gui/qt/internetgamelogindialog/internetgamelogindialogimpl.cpp +++ b/src/gui/qt/internetgamelogindialog/internetgamelogindialogimpl.cpp @@ -4,114 +4,123 @@ #include internetGameLoginDialogImpl::internetGameLoginDialogImpl(QWidget *parent, ConfigFile *c) : - QDialog(parent), myConfig(c){ + QDialog(parent), myConfig(c){ setupUi(this); - - connect(groupBox_reguser, SIGNAL(toggled(bool)), this, SLOT(regUserToggled(bool))); - connect(checkBox_guest, SIGNAL(toggled(bool)), this, SLOT(guestUserToggled(bool))); - connect(lineEdit_password, SIGNAL(textEdited(QString)), this, SLOT(okButtonCheck())); - connect(lineEdit_username, SIGNAL(textEdited(QString)), this, SLOT(okButtonCheck())); + + connect(groupBox_reguser, SIGNAL(toggled(bool)), this, SLOT(regUserToggled(bool))); + connect(checkBox_guest, SIGNAL(toggled(bool)), this, SLOT(guestUserToggled(bool))); + connect(lineEdit_password, SIGNAL(textEdited(QString)), this, SLOT(okButtonCheck())); + connect(lineEdit_username, SIGNAL(textEdited(QString)), this, SLOT(okButtonCheck())); } void internetGameLoginDialogImpl::regUserToggled(bool b) { - - checkBox_guest->setChecked(!b); - if(b) { + checkBox_guest->setChecked(!b); + + if(b) { + if(QString::fromUtf8(myConfig->readConfigString("MyRememberedNameDuringGuestLogin").c_str()).isEmpty()) { lineEdit_username->setText(QString::fromUtf8(myConfig->readConfigString("MyName").c_str())); - if(myConfig->readConfigInt("InternetSavePassword")) { - checkBox_rememberPassword->setChecked(true); - lineEdit_password->setText(QString::fromUtf8(QByteArray::fromBase64(myConfig->readConfigString("InternetLoginPassword").c_str()))); - } - else { - checkBox_rememberPassword->setChecked(false); - lineEdit_password->clear(); - } } + else { + lineEdit_username->setText(QString::fromUtf8(myConfig->readConfigString("MyRememberedNameDuringGuestLogin").c_str())); + } + if(myConfig->readConfigInt("InternetSavePassword")) { + checkBox_rememberPassword->setChecked(true); + lineEdit_password->setText(QString::fromUtf8(QByteArray::fromBase64(myConfig->readConfigString("InternetLoginPassword").c_str()))); + } + else { + checkBox_rememberPassword->setChecked(false); + lineEdit_password->clear(); + } + } - okButtonCheck(); + okButtonCheck(); } void internetGameLoginDialogImpl::guestUserToggled(bool b) { - groupBox_reguser->setChecked(!b); - - if(b) { - checkBox_rememberPassword->setChecked(false); - lineEdit_password->clear(); - lineEdit_username->clear(); - } + groupBox_reguser->setChecked(!b); - okButtonCheck(); + if(b) { + myConfig->writeConfigString("MyRememberedNameDuringGuestLogin", lineEdit_username->text().toUtf8().constData()); + checkBox_rememberPassword->setChecked(false); + lineEdit_password->clear(); + lineEdit_username->clear(); + + myConfig->writeBuffer(); + } + + okButtonCheck(); } void internetGameLoginDialogImpl::exec() { - if(myConfig->readConfigInt("InternetLoginMode") == 0) { - groupBox_reguser->setChecked(true); - lineEdit_username->setText(QString::fromUtf8(myConfig->readConfigString("MyName").c_str())); - if(myConfig->readConfigInt("InternetSavePassword")) { - checkBox_rememberPassword->setChecked(true); - lineEdit_password->setText(QString::fromUtf8(QByteArray::fromBase64(myConfig->readConfigString("InternetLoginPassword").c_str()))); - } - else { - checkBox_rememberPassword->setChecked(false); - lineEdit_password->clear(); - } - } - else { - checkBox_guest->setChecked(true); - } - - okButtonCheck(); - - if(groupBox_reguser->isChecked() && !checkBox_rememberPassword->isChecked() && lineEdit_password->text().isEmpty()) { - lineEdit_password->setFocus(); - } - - QDialog::exec(); + if(myConfig->readConfigInt("InternetLoginMode") == 0) { + groupBox_reguser->setChecked(true); + lineEdit_username->setText(QString::fromUtf8(myConfig->readConfigString("MyName").c_str())); + if(myConfig->readConfigInt("InternetSavePassword")) { + checkBox_rememberPassword->setChecked(true); + lineEdit_password->setText(QString::fromUtf8(QByteArray::fromBase64(myConfig->readConfigString("InternetLoginPassword").c_str()))); + } + else { + checkBox_rememberPassword->setChecked(false); + lineEdit_password->clear(); + } + } + else { + checkBox_guest->setChecked(true); + } + + okButtonCheck(); + + if(groupBox_reguser->isChecked() && !checkBox_rememberPassword->isChecked() && lineEdit_password->text().isEmpty()) { + lineEdit_password->setFocus(); + } + + QDialog::exec(); } void internetGameLoginDialogImpl::accept() { - if(groupBox_reguser->isChecked()) { - myConfig->writeConfigInt("InternetLoginMode", 0); - myConfig->writeConfigString("MyName", lineEdit_username->text().toUtf8().constData()); - if(checkBox_rememberPassword->isChecked()) { - myConfig->writeConfigInt("InternetSavePassword", 1); - myConfig->writeConfigString("InternetLoginPassword", lineEdit_password->text().toUtf8().toBase64().constData()); - } - else { - myConfig->writeConfigInt("InternetSavePassword", 0); - } - } - else if(checkBox_guest->isChecked()) { - myConfig->writeConfigInt("InternetLoginMode", 1); - // Generate a valid guest name. - QString guestName; - int guestId; - Tools::getRandNumber(1, 99999, 1, &guestId, false); - guestName.sprintf("Guest%05d", guestId); - myConfig->writeConfigString("MyName", guestName.toUtf8().constData()); - } - - myConfig->writeBuffer(); - - QDialog::accept(); + if(groupBox_reguser->isChecked()) { + myConfig->writeConfigInt("InternetLoginMode", 0); + myConfig->writeConfigString("MyName", lineEdit_username->text().toUtf8().constData()); + if(checkBox_rememberPassword->isChecked()) { + myConfig->writeConfigInt("InternetSavePassword", 1); + myConfig->writeConfigString("InternetLoginPassword", lineEdit_password->text().toUtf8().toBase64().constData()); + } + else { + myConfig->writeConfigInt("InternetSavePassword", 0); + } + + } + else if(checkBox_guest->isChecked()) { + myConfig->writeConfigInt("InternetLoginMode", 1); + // Generate a valid guest name. + QString guestName; + int guestId; + Tools::getRandNumber(1, 99999, 1, &guestId, false); + guestName.sprintf("Guest%05d", guestId); + myConfig->writeConfigString("MyName", guestName.toUtf8().constData()); + } + + myConfig->writeBuffer(); + + QDialog::accept(); } void internetGameLoginDialogImpl::okButtonCheck() { - - if(groupBox_reguser->isChecked()) { - if(!lineEdit_password->text().isEmpty() && !lineEdit_username->text().isEmpty()) { - pushButton_login->setEnabled(true); - } - else { - pushButton_login->setEnabled(false); - } - } - else { - pushButton_login->setEnabled(true); - } + + if(groupBox_reguser->isChecked()) { + if(!lineEdit_password->text().isEmpty() && !lineEdit_username->text().isEmpty()) { + pushButton_login->setEnabled(true); + } + else { + pushButton_login->setEnabled(false); + } + } + else { + pushButton_login->setEnabled(true); + } }