diff --git a/application/LaunchInteraction.cpp b/application/LaunchInteraction.cpp index 070c8249..c7ef942a 100644 --- a/application/LaunchInteraction.cpp +++ b/application/LaunchInteraction.cpp @@ -14,6 +14,7 @@ #include #include #include +#include LaunchController::LaunchController(QObject *parent) : QObject(parent) { @@ -76,8 +77,9 @@ void LaunchController::login() // we loop until the user succeeds in logging in or gives up bool tryagain = true; // the failure. the default failure. - QString failReason = tr("Your account is currently not logged in. Please enter " + const QString needLoginAgain = tr("Your account is currently not logged in. Please enter " "your password to log in again."); + QString failReason = needLoginAgain; while (tryagain) { @@ -94,7 +96,12 @@ void LaunchController::login() progDialog.exec(task.get()); if (!task->successful()) { - failReason = task->failReason(); + auto failReasonNew = task->failReason(); + if(failReasonNew == "Invalid token.") + { + failReason = needLoginAgain; + } + else failReason = failReasonNew; } } switch (m_session->status) @@ -108,6 +115,26 @@ void LaunchController::login() case AuthSession::RequiresPassword: { EditAccountDialog passDialog(failReason, m_parentWidget, EditAccountDialog::PasswordField); + auto username = m_session->username; + auto chopN = [](QString toChop, int N) -> QString + { + if(toChop.size() > N) + { + auto left = toChop.left(N); + left += QString("\u25CF").repeated(toChop.size() - N); + return left; + } + return toChop; + }; + + if(username.contains('@')) + { + auto parts = username.split('@'); + auto mailbox = chopN(parts[0],3); + QString domain = chopN(parts[1], 3); + username = mailbox + '@' + domain; + } + passDialog.setUsername(username); if (passDialog.exec() == QDialog::Accepted) { password = passDialog.password(); diff --git a/application/MainWindow.cpp b/application/MainWindow.cpp index 0747e442..d5fcc6f0 100644 --- a/application/MainWindow.cpp +++ b/application/MainWindow.cpp @@ -519,7 +519,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi repopulateAccountsMenu(); accountMenuButton = new QToolButton(this); - accountMenuButton->setText(tr("Accounts")); + accountMenuButton->setText(tr("Profiles")); accountMenuButton->setMenu(accountMenu); accountMenuButton->setPopupMode(QToolButton::InstantPopup); accountMenuButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); @@ -753,8 +753,6 @@ void MainWindow::repopulateAccountsMenu() QAction *action = new QAction(tr("No accounts added!"), this); action->setEnabled(false); accountMenu->addAction(action); - - accountMenu->addSeparator(); } else { @@ -764,9 +762,11 @@ void MainWindow::repopulateAccountsMenu() MojangAccountPtr account = accounts->at(i); // Styling hack + /* QAction *section = new QAction(account->username(), this); section->setEnabled(false); accountMenu->addAction(section); + */ for (auto profile : account->profiles()) { @@ -782,11 +782,11 @@ void MainWindow::repopulateAccountsMenu() accountMenu->addAction(action); connect(action, SIGNAL(triggered(bool)), SLOT(changeActiveAccount())); } - - accountMenu->addSeparator(); } } + accountMenu->addSeparator(); + QAction *action = new QAction(tr("No Default Account"), this); action->setCheckable(true); action->setIcon(MMC->getThemedIcon("noaccount")); @@ -838,12 +838,14 @@ void MainWindow::activeAccountChanged() if (profile != nullptr) { accountMenuButton->setIcon(SkinUtils::getFaceFromCache(profile->name)); + accountMenuButton->setText(profile->name); return; } } // Set the icon to the "no account" icon. accountMenuButton->setIcon(MMC->getThemedIcon("noaccount")); + accountMenuButton->setText(tr("Profiles")); } bool MainWindow::eventFilter(QObject *obj, QEvent *ev) diff --git a/application/dialogs/EditAccountDialog.cpp b/application/dialogs/EditAccountDialog.cpp index b78cebee..7c2ff981 100644 --- a/application/dialogs/EditAccountDialog.cpp +++ b/application/dialogs/EditAccountDialog.cpp @@ -26,8 +26,8 @@ EditAccountDialog::EditAccountDialog(const QString &text, QWidget *parent, int f ui->label->setText(text); ui->label->setVisible(!text.isEmpty()); - ui->userTextBox->setVisible(flags & UsernameField); - ui->passTextBox->setVisible(flags & PasswordField); + ui->userTextBox->setEnabled(flags & UsernameField); + ui->passTextBox->setEnabled(flags & PasswordField); } EditAccountDialog::~EditAccountDialog() @@ -40,11 +40,21 @@ void EditAccountDialog::on_label_linkActivated(const QString &link) QDesktopServices::openUrl(QUrl(link)); } +void EditAccountDialog::setUsername(const QString & user) const +{ + ui->userTextBox->setText(user); +} + QString EditAccountDialog::username() const { return ui->userTextBox->text(); } +void EditAccountDialog::setPassword(const QString & pass) const +{ + ui->passTextBox->setText(pass); +} + QString EditAccountDialog::password() const { return ui->passTextBox->text(); diff --git a/application/dialogs/EditAccountDialog.h b/application/dialogs/EditAccountDialog.h index df8b21bf..e1f6f401 100644 --- a/application/dialogs/EditAccountDialog.h +++ b/application/dialogs/EditAccountDialog.h @@ -31,14 +31,10 @@ public: int flags = UsernameField | PasswordField); ~EditAccountDialog(); - /*! - * Gets the text entered in the dialog's username field. - */ - QString username() const; + void setUsername(const QString & user) const; + void setPassword(const QString & pass) const; - /*! - * Gets the text entered in the dialog's password field. - */ + QString username() const; QString password() const; enum Flags diff --git a/application/dialogs/EditAccountDialog.ui b/application/dialogs/EditAccountDialog.ui index 5f727bd4..da24c124 100644 --- a/application/dialogs/EditAccountDialog.ui +++ b/application/dialogs/EditAccountDialog.ui @@ -11,7 +11,7 @@ - Edit Account + Login diff --git a/application/pages/global/AccountListPage.cpp b/application/pages/global/AccountListPage.cpp index 7be72aaa..7ca7e414 100644 --- a/application/pages/global/AccountListPage.cpp +++ b/application/pages/global/AccountListPage.cpp @@ -24,7 +24,6 @@ #include "net/URLConstants.h" #include "Env.h" -#include "dialogs/EditAccountDialog.h" #include "dialogs/ProgressDialog.h" #include "dialogs/AccountSelectDialog.h" #include "dialogs/LoginDialog.h"