From 8c2682c9437ab7b225a51f289a818cb642256e8c Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Wed, 14 Feb 2024 17:38:46 +0100 Subject: [PATCH] Allow dropping connections from the welcome page This is the last piece required to make sure that we can recover from broken connections, e.g., when the access token is invalid. (cherry picked from commit b02bdd22dd14c46bfef985cbdb730fdaed323857) --- src/controller.cpp | 14 +++++++++++++- src/controller.h | 3 +++ src/qml/WelcomePage.qml | 42 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/controller.cpp b/src/controller.cpp index c060cef89..c088bc93a 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) { @@ -378,3 +380,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 80c8cc8e7..c46d2e5c5 100644 --- a/src/controller.h +++ b/src/controller.h @@ -110,6 +110,8 @@ public: static void setTestMode(bool testMode); + Q_INVOKABLE void removeConnection(const QString &userId); + private: explicit Controller(QObject *parent = nullptr); @@ -123,6 +125,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 942a15aec..935bba3ca 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 + } + } } } }