diff --git a/src/controller.cpp b/src/controller.cpp index 75d064260..59247d94b 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -178,10 +178,12 @@ void Controller::invokeLogin() } auto connection = new NeoChatConnection(account.homeserver()); - connect(connection, &NeoChatConnection::connected, this, [this, connection] { + m_connectionsLoading[accountId] = connection; + connect(connection, &NeoChatConnection::connected, this, [this, connection, accountId] { connection->loadState(); addConnection(connection); m_accountsLoading.removeAll(connection->userId()); + m_connectionsLoading.remove(accountId); Q_EMIT accountsLoadingChanged(); }); connect(connection, &NeoChatConnection::networkError, this, [this](const QString &error, const QString &, int, int) { @@ -330,3 +332,13 @@ void Controller::setTestMode(bool test) { testMode = test; } + +void Controller::removeConnection(const QString &userId) +{ + if (m_connectionsLoading.contains(userId) && m_connectionsLoading[userId]) { + auto connection = m_connectionsLoading[userId]; + m_accountsLoading.removeAll(userId); + Q_EMIT accountsLoadingChanged(); + SettingsGroup("Accounts"_ls).remove(userId); + } +} diff --git a/src/controller.h b/src/controller.h index 4e9b8eb27..a2481e3a6 100644 --- a/src/controller.h +++ b/src/controller.h @@ -96,6 +96,8 @@ public: static void setTestMode(bool testMode); + Q_INVOKABLE void removeConnection(const QString &userId); + private: explicit Controller(QObject *parent = nullptr); @@ -109,6 +111,7 @@ private: Quotient::AccountRegistry m_accountRegistry; QStringList m_accountsLoading; + QMap> m_connectionsLoading; QString m_endpoint; private Q_SLOTS: diff --git a/src/qml/WelcomePage.qml b/src/qml/WelcomePage.qml index 5e0e2e4dd..059a5772d 100644 --- a/src/qml/WelcomePage.qml +++ b/src/qml/WelcomePage.qml @@ -70,9 +70,45 @@ FormCard.FormCardPage { Repeater { id: loadingAccounts model: Controller.accountsLoading - delegate: FormCard.FormButtonDelegate { - text: i18nc("As in 'this account is still loading'", "%1 (loading)", modelData) - enabled: false + delegate: FormCard.AbstractFormDelegate { + id: loadingDelegate + + topPadding: Kirigami.Units.smallSpacing + bottomPadding: Kirigami.Units.smallSpacing + + background: null + contentItem: RowLayout { + spacing: 0 + + QQC2.Label { + Layout.fillWidth: true + text: i18nc("As in 'this account is still loading'", "%1 (loading)", modelData) + elide: Text.ElideRight + wrapMode: Text.Wrap + maximumLineCount: 2 + color: Kirigami.Theme.disabledTextColor + Accessible.ignored: true // base class sets this text on root already + } + + QQC2.ToolButton { + text: i18nc("@action:button", "Remove this account") + icon.name: "edit-delete-remove" + onClicked: Controller.removeConnection(modelData) + display: QQC2.Button.IconOnly + QQC2.ToolTip.text: text + QQC2.ToolTip.visible: hovered + QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay + enabled: true + Layout.preferredHeight: Kirigami.Units.gridUnit * 2 + } + + FormCard.FormArrow { + Layout.leftMargin: Kirigami.Units.smallSpacing + Layout.alignment: Qt.AlignRight | Qt.AlignVCenter + direction: Qt.RightArrow + visible: root.background.visible + } + } } } }