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.
This commit is contained in:
@@ -178,10 +178,12 @@ void Controller::invokeLogin()
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto connection = new NeoChatConnection(account.homeserver());
|
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();
|
connection->loadState();
|
||||||
addConnection(connection);
|
addConnection(connection);
|
||||||
m_accountsLoading.removeAll(connection->userId());
|
m_accountsLoading.removeAll(connection->userId());
|
||||||
|
m_connectionsLoading.remove(accountId);
|
||||||
Q_EMIT accountsLoadingChanged();
|
Q_EMIT accountsLoadingChanged();
|
||||||
});
|
});
|
||||||
connect(connection, &NeoChatConnection::networkError, this, [this](const QString &error, const QString &, int, int) {
|
connect(connection, &NeoChatConnection::networkError, this, [this](const QString &error, const QString &, int, int) {
|
||||||
@@ -330,3 +332,13 @@ void Controller::setTestMode(bool test)
|
|||||||
{
|
{
|
||||||
testMode = 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -96,6 +96,8 @@ public:
|
|||||||
|
|
||||||
static void setTestMode(bool testMode);
|
static void setTestMode(bool testMode);
|
||||||
|
|
||||||
|
Q_INVOKABLE void removeConnection(const QString &userId);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit Controller(QObject *parent = nullptr);
|
explicit Controller(QObject *parent = nullptr);
|
||||||
|
|
||||||
@@ -109,6 +111,7 @@ private:
|
|||||||
|
|
||||||
Quotient::AccountRegistry m_accountRegistry;
|
Quotient::AccountRegistry m_accountRegistry;
|
||||||
QStringList m_accountsLoading;
|
QStringList m_accountsLoading;
|
||||||
|
QMap<QString, QPointer<Quotient::Connection>> m_connectionsLoading;
|
||||||
QString m_endpoint;
|
QString m_endpoint;
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
|
|||||||
@@ -70,9 +70,45 @@ FormCard.FormCardPage {
|
|||||||
Repeater {
|
Repeater {
|
||||||
id: loadingAccounts
|
id: loadingAccounts
|
||||||
model: Controller.accountsLoading
|
model: Controller.accountsLoading
|
||||||
delegate: FormCard.FormButtonDelegate {
|
delegate: FormCard.AbstractFormDelegate {
|
||||||
text: i18nc("As in 'this account is still loading'", "%1 (loading)", modelData)
|
id: loadingDelegate
|
||||||
enabled: false
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user