diff options
author | Jan Dalheimer <jan@dalheimer.de> | 2014-04-16 17:38:26 +0200 |
---|---|---|
committer | Jan Dalheimer <jan@dalheimer.de> | 2014-04-16 17:38:26 +0200 |
commit | 3ed5b1570bbd7a9b8060ffc5ee5ae7bc63975098 (patch) | |
tree | c2806dd68e876e4b0643738a20e19666cd4b69fd /gui/dialogs/LoginDialog.cpp | |
parent | 4674aad12500ddf94dc36cb2b479bbbd121ff088 (diff) | |
download | MultiMC-3ed5b1570bbd7a9b8060ffc5ee5ae7bc63975098.tar MultiMC-3ed5b1570bbd7a9b8060ffc5ee5ae7bc63975098.tar.gz MultiMC-3ed5b1570bbd7a9b8060ffc5ee5ae7bc63975098.tar.lz MultiMC-3ed5b1570bbd7a9b8060ffc5ee5ae7bc63975098.tar.xz MultiMC-3ed5b1570bbd7a9b8060ffc5ee5ae7bc63975098.zip |
LoginDialog changes
Diffstat (limited to 'gui/dialogs/LoginDialog.cpp')
-rw-r--r-- | gui/dialogs/LoginDialog.cpp | 90 |
1 files changed, 24 insertions, 66 deletions
diff --git a/gui/dialogs/LoginDialog.cpp b/gui/dialogs/LoginDialog.cpp index 5344ead8..483a096d 100644 --- a/gui/dialogs/LoginDialog.cpp +++ b/gui/dialogs/LoginDialog.cpp @@ -29,8 +29,6 @@ LoginDialog::LoginDialog(QWidget *parent) : QDialog(parent), ui(new Ui::LoginDia ui->progressBar->setVisible(false); ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); - setAttribute(Qt::WA_ShowModal); - connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); } @@ -43,14 +41,16 @@ LoginDialog::~LoginDialog() // Stage 1: User interaction void LoginDialog::accept() { - setResult(Accepted); - loop.quit(); -} - -void LoginDialog::reject() -{ - setResult(Rejected); - loop.quit(); + setUserInputsEnabled(false); + ui->progressBar->setVisible(true); + + m_account = MojangAccount::createFromUsername(ui->userTextBox->text()); + auto task = m_account->login(nullptr, ui->passTextBox->text()); + connect(task.get(), &Task::failed, this, &LoginDialog::onTaskFailed); + connect(task.get(), &Task::succeeded, this, &LoginDialog::onTaskSucceeded); + connect(task.get(), &Task::status, this, &LoginDialog::onTaskStatus); + connect(task.get(), &Task::progress, this, &LoginDialog::onTaskProgress); + task->start(); } void LoginDialog::setUserInputsEnabled(bool enable) @@ -61,92 +61,50 @@ void LoginDialog::setUserInputsEnabled(bool enable) } // Enable the OK button only when both textboxes contain something. -void LoginDialog::on_userTextBox_textEdited(QString newText) +void LoginDialog::on_userTextBox_textEdited(const QString &newText) { ui->buttonBox->button(QDialogButtonBox::Ok) ->setEnabled(!newText.isEmpty() && !ui->passTextBox->text().isEmpty()); } - -void LoginDialog::on_passTextBox_textEdited(QString newText) +void LoginDialog::on_passTextBox_textEdited(const QString &newText) { ui->buttonBox->button(QDialogButtonBox::Ok) ->setEnabled(!newText.isEmpty() && !ui->userTextBox->text().isEmpty()); } -// Stage 2: Task interaction -void LoginDialog::onTaskFailed(QString failure) +void LoginDialog::onTaskFailed(const QString &reason) { // Set message - ui->label->setText("<span style='color:red'>" + failure + "</span>"); + ui->label->setText("<span style='color:red'>" + reason + "</span>"); - // Return - setResult(Rejected); - loop.quit(); + setUserInputsEnabled(true); + ui->progressBar->setVisible(false); } void LoginDialog::onTaskSucceeded() { - setResult(Accepted); - loop.quit(); + QDialog::accept(); } -void LoginDialog::onTaskStatus(QString status) +void LoginDialog::onTaskStatus(const QString &status) { ui->label->setText(status); } -void LoginDialog::onTaskProgress(qint64 current, qint64 total) +void LoginDialog::onTaskProgress(qint64 value, qint64 max) { - ui->progressBar->setMaximum(total); - ui->progressBar->setValue(current); + ui->progressBar->setMaximum(max); + ui->progressBar->setValue(value); } // Public interface MojangAccountPtr LoginDialog::newAccount(QWidget *parent, QString msg) { LoginDialog dlg(parent); - dlg.show(); dlg.ui->label->setText(msg); - - while (1) + if (dlg.exec() == QDialog::Accepted) { - // Show dialog - dlg.loop.exec(); - - // Close if cancel was clicked - if (dlg.result() == Rejected) - return nullptr; - - // Read values - QString username(dlg.ui->userTextBox->text()); - QString password(dlg.ui->passTextBox->text()); - - // disable inputs - dlg.setUserInputsEnabled(false); - dlg.ui->progressBar->setVisible(true); - - // Start login process - MojangAccountPtr account = MojangAccount::createFromUsername(username); - auto task = account->login(nullptr, password); - - // show progess - connect(task.get(), &ProgressProvider::failed, &dlg, &LoginDialog::onTaskFailed); - connect(task.get(), &ProgressProvider::succeeded, &dlg, &LoginDialog::onTaskSucceeded); - connect(task.get(), &ProgressProvider::status, &dlg, &LoginDialog::onTaskStatus); - connect(task.get(), &ProgressProvider::progress, &dlg, &LoginDialog::onTaskProgress); - - // Start task - if (!task->isRunning()) - task->start(); - if (task->isRunning()) - dlg.loop.exec(); - - // Be done - if (dlg.result() == Accepted) - return account; - - // Otherwise, re-enable user inputs and begin anew - dlg.setUserInputsEnabled(true); - dlg.ui->progressBar->setVisible(false); + return dlg.m_account; } + return 0; } |