diff options
Diffstat (limited to 'gui')
-rw-r--r-- | gui/logindialog.cpp | 76 | ||||
-rw-r--r-- | gui/logindialog.h | 4 |
2 files changed, 76 insertions, 4 deletions
diff --git a/gui/logindialog.cpp b/gui/logindialog.cpp index 31220e74..3b44c440 100644 --- a/gui/logindialog.cpp +++ b/gui/logindialog.cpp @@ -16,12 +16,15 @@ #include "logindialog.h" #include "ui_logindialog.h" #include "keyring.h" +#include <QDebug> LoginDialog::LoginDialog(QWidget *parent, const QString& loginErrMsg) : QDialog(parent), ui(new Ui::LoginDialog) { ui->setupUi(this); + + blockToggles = false; //FIXME: translateable? ui->usernameTextBox->lineEdit()->setPlaceholderText(QApplication::translate("LoginDialog", "Name", 0)); @@ -50,6 +53,9 @@ LoginDialog::LoginDialog(QWidget *parent, const QString& loginErrMsg) : { ui->passwordTextBox->setFocus(Qt::OtherFocusReason); } + + connect(ui->rememberUsernameCheckbox,SIGNAL(toggled(bool)), SLOT(usernameToggled(bool))); + connect(ui->rememberPasswordCheckbox,SIGNAL(toggled(bool)), SLOT(passwordToggled(bool))); } LoginDialog::~LoginDialog() @@ -76,14 +82,71 @@ void LoginDialog::forgetCurrentUser() int index = ui->usernameTextBox->findText(acct); if(index != -1) ui->usernameTextBox->removeItem(index); + if(!ui->usernameTextBox->count()) + { + blockToggles = true; + ui->rememberUsernameCheckbox->setChecked(false); + ui->rememberPasswordCheckbox->setChecked(false); + blockToggles = false; + } +} + +void LoginDialog::passwordToggled ( bool state ) +{ + // if toggled off + if(blockToggles) + return; + blockToggles = true; + if(!state) + { + qDebug() << "password disabled"; + } + else + { + if(!ui->rememberUsernameCheckbox->isChecked()) + { + ui->rememberUsernameCheckbox->setChecked(true); + } + qDebug() << "password enabled"; + } + blockToggles = false; +} + +void LoginDialog::usernameToggled ( bool state ) +{ + // if toggled off + if(blockToggles) + return; + blockToggles = true; + if(!state) + { + if(ui->rememberPasswordCheckbox->isChecked()) + { + ui->rememberPasswordCheckbox->setChecked(false); + } + qDebug() << "username disabled"; + } + else + { + qDebug() << "username enabled"; + } + blockToggles = false; } + void LoginDialog::userTextChanged ( const QString& user ) { + blockToggles = true; Keyring * k = Keyring::instance(); - QString acct = ui->usernameTextBox->currentText(); - QString passwd = k->getPassword("minecraft",acct); - ui->passwordTextBox->setText(passwd); + QStringList sl = k->getStoredAccounts("minecraft"); + if(sl.contains(user)) + { + ui->rememberUsernameCheckbox->setChecked(true); + QString passwd = k->getPassword("minecraft",user); + ui->rememberPasswordCheckbox->setChecked(!passwd.isEmpty()); + ui->passwordTextBox->setText(passwd); + } + blockToggles = false; } @@ -91,9 +154,9 @@ void LoginDialog::accept() { bool saveName = ui->rememberUsernameCheckbox->isChecked(); bool savePass = ui->rememberPasswordCheckbox->isChecked(); + Keyring * k = Keyring::instance(); if(saveName) { - Keyring * k = Keyring::instance(); if(savePass) { k->storePassword("minecraft",getUsername(),getPassword()); @@ -103,5 +166,10 @@ void LoginDialog::accept() k->storePassword("minecraft",getUsername(),QString()); } } + else + { + QString acct = ui->usernameTextBox->currentText(); + k->removeStoredAccount("minecraft", acct); + } QDialog::accept(); } diff --git a/gui/logindialog.h b/gui/logindialog.h index 5f4410f5..3bb45753 100644 --- a/gui/logindialog.h +++ b/gui/logindialog.h @@ -37,8 +37,12 @@ public slots: virtual void accept(); virtual void userTextChanged(const QString& user); virtual void forgetCurrentUser(); +private slots: + void usernameToggled ( bool ); + void passwordToggled ( bool ); private: Ui::LoginDialog *ui; + bool blockToggles; }; #endif // LOGINDIALOG_H |