NOISSUE improve account UI

This commit is contained in:
Petr Mrázek 2015-08-14 02:27:01 +02:00
parent 8ed10c5b81
commit 0adb572a07
6 changed files with 52 additions and 18 deletions

View File

@ -14,6 +14,7 @@
#include <tasks/Task.h>
#include <auth/YggdrasilTask.h>
#include <launch/steps/TextPrint.h>
#include <QStringList>
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();

View File

@ -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)

View File

@ -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();

View File

@ -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

View File

@ -11,7 +11,7 @@
</rect>
</property>
<property name="windowTitle">
<string>Edit Account</string>
<string>Login</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>

View File

@ -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"