moment/src/gui/Pages/AddChat/JoinRoom.qml

96 lines
2.4 KiB
QML
Raw Normal View History

2019-12-19 22:46:16 +11:00
// SPDX-License-Identifier: LGPL-3.0-or-later
2019-11-10 00:52:16 +11:00
import QtQuick 2.12
import QtQuick.Layouts 1.12
import "../../Base"
HBox {
id: addChatBox
clickButtonOnEnter: "apply"
2019-11-10 00:52:16 +11:00
onFocusChanged: roomField.item.forceActiveFocus()
2019-11-10 00:52:16 +11:00
buttonModel: [
{
name: "apply",
text: qsTr("Join"),
2019-12-13 23:30:36 +11:00
iconName: "room-join",
enabled: Boolean(roomField.item.text.trim()),
},
2019-11-10 00:52:16 +11:00
{ name: "cancel", text: qsTr("Cancel"), iconName: "cancel" },
]
buttonCallbacks: ({
apply: button => {
button.loading = true
errorMessage.text = ""
2019-11-10 00:52:16 +11:00
const args = [roomField.item.text.trim()]
2019-11-10 00:52:16 +11:00
py.callClientCoro(userId, "room_join", args, roomId => {
button.loading = false
errorMessage.text = ""
2019-11-10 00:52:16 +11:00
pageLoader.showRoom(userId, roomId)
}, (type, args) => {
button.loading = false
2019-11-10 05:20:53 +11:00
let txt = qsTr("Unknown error - %1: %2").arg(type).arg(args)
if (type === "ValueError")
txt = qsTr("Unrecognized alias, room ID or URL")
if (type === "MatrixNotFound")
txt = qsTr("Room not found")
if (type === "MatrixForbidden")
txt = qsTr("You do not have permission to join this room")
errorMessage.text = txt
2019-11-10 00:52:16 +11:00
})
},
cancel: button => {
roomField.item.text = ""
errorMessage.text = ""
2019-11-10 00:52:16 +11:00
pageLoader.showPrevious()
}
})
readonly property string userId: addChatPage.userId
2019-11-10 06:19:10 +11:00
CurrentUserAvatar {
Layout.alignment: Qt.AlignCenter
Layout.preferredWidth: 128
Layout.preferredHeight: Layout.preferredWidth
}
HLabeledItem {
2019-11-10 00:52:16 +11:00
id: roomField
2020-03-18 04:40:58 +11:00
label.text: qsTr("Alias, URL or room ID:")
2019-11-10 00:52:16 +11:00
Layout.fillWidth: true
HTextField {
width: parent.width
placeholderText: qsTr("#example:matrix.org")
error: Boolean(errorMessage.text)
}
2019-11-10 00:52:16 +11:00
}
HLabel {
id: errorMessage
wrapMode: Text.Wrap
horizontalAlignment: Text.AlignHCenter
color: theme.colors.errorText
visible: Layout.maximumHeight > 0
Layout.maximumHeight: text ? implicitHeight : 0
Behavior on Layout.maximumHeight { HNumberAnimation {} }
Layout.fillWidth: true
}
}