diff --git a/gui/logindialog.cpp b/gui/logindialog.cpp index 426757a9..842a4541 100644 --- a/gui/logindialog.cpp +++ b/gui/logindialog.cpp @@ -15,12 +15,18 @@ #include "logindialog.h" #include "ui_logindialog.h" +#include "keyring.h" LoginDialog::LoginDialog(QWidget *parent, const QString& loginErrMsg) : QDialog(parent), ui(new Ui::LoginDialog) { ui->setupUi(this); + //FIXME: translateable? + ui->usernameTextBox->lineEdit()->setPlaceholderText(QApplication::translate("LoginDialog", "Name", 0)); + + connect(ui->usernameTextBox, SIGNAL(currentTextChanged(QString)), this, SLOT(userTextChanged(QString))); + connect(ui->forgetButton, SIGNAL(clicked(bool)), this, SLOT(forgetCurrentUser())); if (loginErrMsg.isEmpty()) ui->loginErrorLabel->setVisible(false); @@ -33,6 +39,10 @@ LoginDialog::LoginDialog(QWidget *parent, const QString& loginErrMsg) : resize(minimumSizeHint()); layout()->setSizeConstraint(QLayout::SetFixedSize); + Keyring * k = Keyring::instance(); + QStringList accounts = k->getStoredAccounts("minecraft"); + ui->usernameTextBox->addItems(accounts); + } LoginDialog::~LoginDialog() @@ -42,10 +52,49 @@ LoginDialog::~LoginDialog() QString LoginDialog::getUsername() const { - return ui->usernameTextBox->text(); + return ui->usernameTextBox->currentText(); } QString LoginDialog::getPassword() const { return ui->passwordTextBox->text(); } + +void LoginDialog::forgetCurrentUser() +{ + Keyring * k = Keyring::instance(); + QString acct = ui->usernameTextBox->currentText(); + k->removeStoredAccount("minecraft", acct); + ui->passwordTextBox->clear(); + int index = ui->usernameTextBox->findText(acct); + if(index != -1) + ui->usernameTextBox->removeItem(index); +} + +void LoginDialog::userTextChanged ( const QString& user ) +{ + Keyring * k = Keyring::instance(); + QString acct = ui->usernameTextBox->currentText(); + QString passwd = k->getPassword("minecraft",acct); + ui->passwordTextBox->setText(passwd); +} + + +void LoginDialog::accept() +{ + bool saveName = ui->rememberUsernameCheckbox->isChecked(); + bool savePass = ui->rememberPasswordCheckbox->isChecked(); + if(saveName) + { + Keyring * k = Keyring::instance(); + if(savePass) + { + k->storePassword("minecraft",getUsername(),getPassword()); + } + else + { + k->storePassword("minecraft",getUsername(),QString()); + } + } + QDialog::accept(); +} diff --git a/gui/logindialog.h b/gui/logindialog.h index 1b70dcd5..5f4410f5 100644 --- a/gui/logindialog.h +++ b/gui/logindialog.h @@ -32,7 +32,11 @@ public: QString getUsername() const; QString getPassword() const; - + +public slots: + virtual void accept(); + virtual void userTextChanged(const QString& user); + virtual void forgetCurrentUser(); private: Ui::LoginDialog *ui; }; diff --git a/gui/logindialog.ui b/gui/logindialog.ui index ce41d2f5..0aaad52b 100644 --- a/gui/logindialog.ui +++ b/gui/logindialog.ui @@ -6,8 +6,8 @@ 0 0 - 365 - 145 + 476 + 168 @@ -31,9 +31,9 @@ - - - Username + + + true @@ -54,20 +54,23 @@ + + + + + 0 + 0 + + + + Forget + + + - - - - &Force Update - - - true - - - diff --git a/libsettings/include/keyring.h b/libsettings/include/keyring.h index 5774e287..299b14b0 100644 --- a/libsettings/include/keyring.h +++ b/libsettings/include/keyring.h @@ -72,6 +72,14 @@ public: */ virtual QStringList getStoredAccounts(QString service) = 0; + /** + * @brief Remove the specified account from storage + * @param service the service name + * @param username the account name + * @return + */ + virtual void removeStoredAccount(QString service, QString username) = 0; + protected: /// fall back to StubKeyring if false virtual bool isValid() { return false; } diff --git a/libsettings/src/stubkeyring.cpp b/libsettings/src/stubkeyring.cpp index 963f3dd9..cb03bf79 100644 --- a/libsettings/src/stubkeyring.cpp +++ b/libsettings/src/stubkeyring.cpp @@ -90,6 +90,12 @@ QStringList StubKeyring::getStoredAccounts(QString service) return out; } +void StubKeyring::removeStoredAccount ( QString service, QString username ) +{ + QString key = generateKey(service, username); + m_settings.remove(key); +} + StubKeyring::StubKeyring() : m_settings(QSettings::UserScope, "Orochimarufan", "Keyring") { diff --git a/libsettings/src/stubkeyring.h b/libsettings/src/stubkeyring.h index b5f04e4c..45791c85 100644 --- a/libsettings/src/stubkeyring.h +++ b/libsettings/src/stubkeyring.h @@ -29,7 +29,7 @@ public: virtual QString getPassword(QString service, QString username); virtual bool hasPassword(QString service, QString username); virtual QStringList getStoredAccounts(QString service); - + virtual void removeStoredAccount(QString service, QString username); private: friend class Keyring; explicit StubKeyring();