From 576d78fb7f8aa09c6219f91864539d906662e17e Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 11 Jun 2021 22:18:35 +0300 Subject: [PATCH] UI Improvement: Display account type (#33) * Add account type column in accounts page * Show account type in account chooser * Allow set skin and delete skin only on mojang accounts * Rename Offline mode to Local --- api/logic/minecraft/auth/MojangAccount.cpp | 12 ++++++++++++ api/logic/minecraft/auth/MojangAccount.h | 4 ++++ api/logic/minecraft/auth/MojangAccountList.cpp | 8 +++++++- api/logic/minecraft/auth/MojangAccountList.h | 3 +++ application/MainWindow.cpp | 18 +++++++++--------- application/dialogs/LoginDialog.ui | 2 +- application/pages/global/AccountListPage.cpp | 7 +++++-- 7 files changed, 41 insertions(+), 13 deletions(-) diff --git a/api/logic/minecraft/auth/MojangAccount.cpp b/api/logic/minecraft/auth/MojangAccount.cpp index 894cfd4a..dd77d323 100644 --- a/api/logic/minecraft/auth/MojangAccount.cpp +++ b/api/logic/minecraft/auth/MojangAccount.cpp @@ -194,6 +194,18 @@ QString MojangAccount::authEndpoint() const return BuildConfig.AUTH_BASE_MOJANG; } +QString MojangAccount::displayLoginType() const +{ + if(m_loginType == "mojang") + return "Mojang"; + if(m_loginType == "dummy") + return "Local"; + if(m_loginType == "elyby") + return "Ely.by"; + + return "Unknown"; +} + std::shared_ptr MojangAccount::login(AuthSessionPtr session, QString password) { Q_ASSERT(m_currentTask.get() == nullptr); diff --git a/api/logic/minecraft/auth/MojangAccount.h b/api/logic/minecraft/auth/MojangAccount.h index b8e8a293..09498f8b 100644 --- a/api/logic/minecraft/auth/MojangAccount.h +++ b/api/logic/minecraft/auth/MojangAccount.h @@ -141,8 +141,12 @@ public: /* queries */ //! Returns whether the account is NotVerified, Verified or Online AccountStatus accountStatus() const; + //! Returns endpoint for authentication QString authEndpoint() const; + // ! Returns login type to display in account list or account chooser + QString displayLoginType() const; + signals: /** * This signal is emitted when the account changes diff --git a/api/logic/minecraft/auth/MojangAccountList.cpp b/api/logic/minecraft/auth/MojangAccountList.cpp index e584cb3b..9db87232 100644 --- a/api/logic/minecraft/auth/MojangAccountList.cpp +++ b/api/logic/minecraft/auth/MojangAccountList.cpp @@ -194,6 +194,9 @@ QVariant MojangAccountList::data(const QModelIndex &index, int role) const case NameColumn: return account->username(); + case TypeColumn: + return account->displayLoginType(); + default: return QVariant(); } @@ -229,6 +232,9 @@ QVariant MojangAccountList::headerData(int section, Qt::Orientation orientation, case NameColumn: return tr("Name"); + case TypeColumn: + return tr("Account type"); + default: return QVariant(); } @@ -256,7 +262,7 @@ int MojangAccountList::rowCount(const QModelIndex &) const int MojangAccountList::columnCount(const QModelIndex &) const { - return 2; + return 3; } Qt::ItemFlags MojangAccountList::flags(const QModelIndex &index) const diff --git a/api/logic/minecraft/auth/MojangAccountList.h b/api/logic/minecraft/auth/MojangAccountList.h index cc3a61a2..ab4da1d3 100644 --- a/api/logic/minecraft/auth/MojangAccountList.h +++ b/api/logic/minecraft/auth/MojangAccountList.h @@ -51,6 +51,9 @@ public: // Second column - Name NameColumn, + + // Third column - account type + TypeColumn, }; explicit MojangAccountList(QObject *parent = 0); diff --git a/application/MainWindow.cpp b/application/MainWindow.cpp index 1286007d..ff5a4c70 100644 --- a/application/MainWindow.cpp +++ b/application/MainWindow.cpp @@ -996,16 +996,15 @@ void MainWindow::updateToolsMenu() ui->actionLaunchInstanceOffline->setMenu(launchOfflineMenu); } -QString profileInUseFilter(const QString & profile, bool used) +QString formatProfile(const QString & profileName, const QString & loginType, bool used) { + QString textInBrackets = loginType; if(used) { - return profile + QObject::tr(" (in use)"); - } - else - { - return profile; + textInBrackets += ", in use"; } + return ((QString)"%1 (%2)").arg(profileName).arg(textInBrackets); + } void MainWindow::repopulateAccountsMenu() @@ -1023,7 +1022,7 @@ void MainWindow::repopulateAccountsMenu() // this can be called before accountMenuButton exists if (profile != nullptr && accountMenuButton) { - auto profileLabel = profileInUseFilter(profile->name, active_account->isInUse()); + auto profileLabel = formatProfile(profile->name, active_account->displayLoginType(), active_account->isInUse()); accountMenuButton->setText(profileLabel); } } @@ -1042,7 +1041,8 @@ void MainWindow::repopulateAccountsMenu() MojangAccountPtr account = accounts->at(i); for (auto profile : account->profiles()) { - auto profileLabel = profileInUseFilter(profile.name, account->isInUse()); + auto profileLabel = formatProfile(profile.name, account->displayLoginType(), account->isInUse()); + qDebug() << "AAA" << profileLabel; QAction *action = new QAction(profileLabel, this); action->setData(account->username()); action->setCheckable(true); @@ -1119,7 +1119,7 @@ void MainWindow::activeAccountChanged() const AccountProfile *profile = account->currentProfile(); if (profile != nullptr) { - auto profileLabel = profileInUseFilter(profile->name, account->isInUse()); + auto profileLabel = formatProfile(profile->name, account->displayLoginType(), account->isInUse()); accountMenuButton->setIcon(SkinUtils::getFaceFromCache(profile->id)); accountMenuButton->setText(profileLabel); return; diff --git a/application/dialogs/LoginDialog.ui b/application/dialogs/LoginDialog.ui index c065c827..b45ddf2b 100644 --- a/application/dialogs/LoginDialog.ui +++ b/application/dialogs/LoginDialog.ui @@ -75,7 +75,7 @@ - Offline (cracked) + Local (cracked) false diff --git a/application/pages/global/AccountListPage.cpp b/application/pages/global/AccountListPage.cpp index ff3736ed..f2cf8ad8 100644 --- a/application/pages/global/AccountListPage.cpp +++ b/application/pages/global/AccountListPage.cpp @@ -55,6 +55,7 @@ AccountListPage::AccountListPage(QWidget *parent) // Expand the account column ui->listView->header()->setSectionResizeMode(1, QHeaderView::Stretch); + ui->listView->header()->setSectionResizeMode(2, QHeaderView::Stretch); QItemSelectionModel *selectionModel = ui->listView->selectionModel(); @@ -142,9 +143,11 @@ void AccountListPage::updateButtonStates() ui->actionRemove->setEnabled(selection.size() > 0); ui->actionSetDefault->setEnabled(selection.size() > 0); - ui->actionUploadSkin->setEnabled(selection.size() > 0); - ui->actionDeleteSkin->setEnabled(selection.size() > 0); + bool enableSkins = selection.size() > 0 && selection.first().data(MojangAccountList::PointerRole).value()->loginType() == "mojang"; + ui->actionUploadSkin->setEnabled(enableSkins); + ui->actionDeleteSkin->setEnabled(enableSkins); + if(m_accounts->activeAccount().get() == nullptr) { ui->actionNoDefault->setEnabled(false); ui->actionNoDefault->setChecked(true);