Improve InviteUserPage
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
// SPDX-FileCopyrightText: 2019 Black Hat <bhat@encom.eu.org>
|
// SPDX-FileCopyrightText: 2019 Black Hat <bhat@encom.eu.org>
|
||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
|
pragma ComponentBehavior: Bound
|
||||||
|
|
||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Controls as QQC2
|
import QtQuick.Controls as QQC2
|
||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
@@ -11,111 +13,77 @@ import org.kde.kirigamiaddons.labs.components as KirigamiComponents
|
|||||||
|
|
||||||
import org.kde.neochat
|
import org.kde.neochat
|
||||||
|
|
||||||
Kirigami.ScrollablePage {
|
SearchPage {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
property NeoChatRoom room
|
property NeoChatRoom room
|
||||||
|
|
||||||
title: i18n("Invite a User")
|
title: i18nc("@title:dialog", "Invite a User")
|
||||||
|
|
||||||
actions: [
|
searchFieldPlaceholder: i18nc("@info:placeholder", "Find a user…")
|
||||||
Kirigami.Action {
|
noResultPlaceholderMessage: i18nc("@info:placeholder", "No users found")
|
||||||
icon.name: "dialog-close"
|
|
||||||
text: i18nc("@action", "Cancel")
|
|
||||||
onTriggered: root.closeDialog()
|
|
||||||
}
|
|
||||||
]
|
|
||||||
header: RowLayout {
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.margins: Kirigami.Units.largeSpacing
|
|
||||||
|
|
||||||
Kirigami.SearchField {
|
headerTrailing: QQC2.Button {
|
||||||
id: identifierField
|
icon.name: "list-add"
|
||||||
property bool isUserId: text.match(/@(.+):(.+)/g)
|
display: QQC2.Button.IconOnly
|
||||||
Layout.fillWidth: true
|
enabled: root.model.searchText.match(/@(.+):(.+)/g) && !root.room.containsUser(root.model.searchText)
|
||||||
|
|
||||||
placeholderText: i18n("Find a user...")
|
text: i18nc("@action:button", "Invite this User")
|
||||||
onAccepted: userDictListModel.search()
|
|
||||||
}
|
|
||||||
|
|
||||||
QQC2.Button {
|
QQC2.ToolTip.visible: hovered
|
||||||
visible: identifierField.isUserId
|
QQC2.ToolTip.text: root.room.containsUser(root.model.searchText) ? i18nc("@info:tooltip", "User is either already a member or has been invited") : text
|
||||||
|
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
|
||||||
|
|
||||||
text: i18n("Add")
|
onClicked: root.room.inviteToRoom(root.model.searchText);
|
||||||
highlighted: true
|
|
||||||
|
|
||||||
onClicked: {
|
|
||||||
room.inviteToRoom(identifierField.text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ListView {
|
model: UserDirectoryListModel {
|
||||||
id: userDictListView
|
id: userDictListModel
|
||||||
|
|
||||||
clip: true
|
connection: root.room.connection
|
||||||
|
}
|
||||||
|
|
||||||
model: UserDirectoryListModel {
|
modelDelegate: Delegates.RoundedItemDelegate {
|
||||||
id: userDictListModel
|
id: delegate
|
||||||
|
|
||||||
connection: root.room.connection
|
required property string userId
|
||||||
searchText: identifierField.text
|
required property string displayName
|
||||||
}
|
required property url avatarUrl
|
||||||
|
|
||||||
Kirigami.PlaceholderMessage {
|
text: displayName
|
||||||
anchors.centerIn: parent
|
|
||||||
|
|
||||||
visible: userDictListView.count < 1
|
contentItem: RowLayout {
|
||||||
|
KirigamiComponents.Avatar {
|
||||||
|
Layout.preferredWidth: Kirigami.Units.iconSizes.medium
|
||||||
|
Layout.preferredHeight: Kirigami.Units.iconSizes.medium
|
||||||
|
source: delegate.avatarUrl
|
||||||
|
name: delegate.displayName
|
||||||
|
}
|
||||||
|
|
||||||
text: i18n("No users available")
|
Delegates.SubtitleContentItem {
|
||||||
}
|
itemDelegate: delegate
|
||||||
|
subtitle: delegate.userId
|
||||||
|
labelItem.textFormat: Text.PlainText
|
||||||
|
}
|
||||||
|
|
||||||
delegate: Delegates.RoundedItemDelegate {
|
QQC2.ToolButton {
|
||||||
id: delegate
|
id: inviteButton
|
||||||
|
|
||||||
required property string userId
|
readonly property bool inRoom: root.room && root.room.containsUser(delegate.userId)
|
||||||
required property string displayName
|
|
||||||
required property url avatarUrl
|
|
||||||
|
|
||||||
property bool inRoom: room && room.containsUser(userId)
|
icon.name: "document-send"
|
||||||
|
text: i18nc("@action:button", "Send invitation")
|
||||||
|
opacity: inRoom ? 0.5 : 1
|
||||||
|
enabled: !inRoom
|
||||||
|
|
||||||
text: displayName
|
onClicked: {
|
||||||
|
inviteButton.enabled = false;
|
||||||
contentItem: RowLayout {
|
root.room.inviteToRoom(delegate.userId);
|
||||||
KirigamiComponents.Avatar {
|
|
||||||
Layout.preferredWidth: Kirigami.Units.iconSizes.medium
|
|
||||||
Layout.preferredHeight: Kirigami.Units.iconSizes.medium
|
|
||||||
source: delegate.avatarUrl
|
|
||||||
name: delegate.displayName
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Delegates.SubtitleContentItem {
|
QQC2.ToolTip.text: !inRoom ? text : i18nc("@info:tooltip", "User is either already a member or has been invited")
|
||||||
itemDelegate: delegate
|
QQC2.ToolTip.visible: inviteButton.hovered
|
||||||
subtitle: delegate.userId
|
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
|
||||||
labelItem.textFormat: Text.PlainText
|
|
||||||
}
|
|
||||||
|
|
||||||
QQC2.ToolButton {
|
|
||||||
id: inviteButton
|
|
||||||
icon.name: "document-send"
|
|
||||||
text: i18n("Send invitation")
|
|
||||||
checkable: true
|
|
||||||
checked: inRoom
|
|
||||||
opacity: inRoom ? 0.5 : 1
|
|
||||||
|
|
||||||
onToggled: {
|
|
||||||
if (inRoom) {
|
|
||||||
checked = true;
|
|
||||||
} else {
|
|
||||||
room.inviteToRoom(delegate.userId);
|
|
||||||
applicationWindow().pageStack.layers.pop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QQC2.ToolTip.text: !inRoom ? text : i18n("User is either already a member or has been invited")
|
|
||||||
QQC2.ToolTip.visible: inviteButton.hovered
|
|
||||||
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user