Files
neochat/imports/NeoChat/Page/InviteUserPage.qml
Carl Schwan 28c965a40d Use a page for invitation instead of popup
This generally work better on a mobile device
2020-11-16 22:45:41 +00:00

135 lines
3.4 KiB
QML

/**
* SPDX-FileCopyrightText: 2019 Black Hat <bhat@encom.eu.org>
*
* SPDX-License-Identifier: GPL-3.0-only
*/
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import org.kde.kirigami 2.14 as Kirigami
import org.kde.neochat 1.0
Kirigami.ScrollablePage {
id: root
property var room
parent: applicationWindow().overlay
title: i18n("Invite a User")
actions {
main: Kirigami.Action {
icon.name: "dialog-close"
text: i18nc("@action", "Cancel")
onTriggered: applicationWindow().pageStack.pop()
}
}
header: RowLayout {
Layout.fillWidth: true
Layout.margins: Kirigami.Units.largeSpacing
Kirigami.SearchField {
id: identifierField
property bool isUserID: text.match(/@(.+):(.+)/g)
Layout.fillWidth: true
placeholderText: i18n("Find a user...")
onAccepted: userDictListModel.search()
}
Button {
visible: identifierField.isUserID
text: i18n("Add")
highlighted: true
onClicked: {
room.inviteToRoom(identifierField.text)
}
}
}
ListView {
Layout.fillWidth: true
Layout.fillHeight: true
id: userDictListView
clip: true
model: UserDirectoryListModel {
id: userDictListModel
connection: root.room.connection
keyword: identifierField.text
}
Kirigami.PlaceholderMessage {
anchors.centerIn: parent
visible: userDictListView.count < 1
text: i18n("No users available")
}
delegate: Kirigami.AbstractListItem {
id: delegate
property bool inRoom: room && room.containsUser(userID)
topPadding: Kirigami.Units.largeSpacing
bottomPadding: Kirigami.Units.largeSpacing
contentItem: RowLayout {
Kirigami.Avatar {
Layout.preferredWidth: height
Layout.fillHeight: true
source: avatar ? "image://mxc/" + avatar : ""
name: name
}
ColumnLayout {
Layout.fillWidth: true
Layout.fillHeight: true
spacing: 0
Kirigami.Heading {
Layout.fillWidth: true
Layout.fillHeight: true
level: 3
text: name
textFormat: Text.PlainText
elide: Text.ElideRight
wrapMode: Text.NoWrap
}
Label {
Layout.fillWidth: true
Layout.fillHeight: true
text: userID
textFormat: Text.PlainText
elide: Text.ElideRight
wrapMode: Text.NoWrap
}
}
ToolButton {
visible: !inRoom
icon.name: "document-send"
text: i18n("Send invitation")
onClicked: {
room.inviteToRoom(userID);
applicationWindow().pageStack.pop();
}
}
}
}
}
}