From 5078da4e8467ba55841c0d48643769d62725b0af Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Mon, 1 Apr 2024 15:15:30 -0400 Subject: [PATCH] Disable the account switcher when there's only one account --- launcher/include/accountmanager.h | 5 +++++ launcher/src/accountmanager.cpp | 3 +++ launcher/ui/Pages/LoginPage.qml | 1 + 3 files changed, 9 insertions(+) diff --git a/launcher/include/accountmanager.h b/launcher/include/accountmanager.h index a6d4e0b..17d9f4a 100644 --- a/launcher/include/accountmanager.h +++ b/launcher/include/accountmanager.h @@ -14,6 +14,8 @@ class AccountManager : public QAbstractListModel QML_ELEMENT QML_UNCREATABLE("Use LauncherCore.accountManager") + Q_PROPERTY(int numAccounts READ numAccounts NOTIFY accountsChanged) + public: explicit AccountManager(LauncherCore &launcher, QObject *parent = nullptr); @@ -40,6 +42,9 @@ public: Q_INVOKABLE [[nodiscard]] bool hasAnyAccounts() const; Q_INVOKABLE [[nodiscard]] int numAccounts() const; +Q_SIGNALS: + void accountsChanged(); + private: void insertAccount(Account *account); diff --git a/launcher/src/accountmanager.cpp b/launcher/src/accountmanager.cpp index 408d2e6..756fa1f 100644 --- a/launcher/src/accountmanager.cpp +++ b/launcher/src/accountmanager.cpp @@ -24,6 +24,7 @@ void AccountManager::load() auto account = new Account(m_launcher, uuid, this); m_accounts.append(account); + Q_EMIT accountsChanged(); } } } @@ -105,6 +106,7 @@ void AccountManager::deleteAccount(Account *account) beginRemoveRows(QModelIndex(), row, row); m_accounts.removeAll(account); endRemoveRows(); + Q_EMIT accountsChanged(); } void AccountManager::insertAccount(Account *account) @@ -112,6 +114,7 @@ void AccountManager::insertAccount(Account *account) beginInsertRows(QModelIndex(), static_cast(m_accounts.size()), static_cast(m_accounts.size())); m_accounts.append(account); endInsertRows(); + Q_EMIT accountsChanged(); } bool AccountManager::hasAnyAccounts() const diff --git a/launcher/ui/Pages/LoginPage.qml b/launcher/ui/Pages/LoginPage.qml index 301d74d..7ab06e9 100644 --- a/launcher/ui/Pages/LoginPage.qml +++ b/launcher/ui/Pages/LoginPage.qml @@ -165,6 +165,7 @@ QQC2.Control { FormCard.FormButtonDelegate { id: currentAccountDelegate + enabled: LauncherCore.accountManager.numAccounts > 1 text: LauncherCore.currentProfile.account.name leading: Components.Avatar {