Warning, /network/neochat/src/qml/StartChatPage.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2019 Black Hat <bhat@encom.eu.org>
0002 // SPDX-FileCopyrightText: 2020 Carl Schwan <carl@carlschwan.eu>
0003 // SPDX-License-Identifier: GPL-3.0-only
0004 
0005 import QtQuick
0006 import QtQuick.Controls as QQC2
0007 import QtQuick.Layouts
0008 
0009 import org.kde.kirigami as Kirigami
0010 import org.kde.kirigamiaddons.delegates as Delegates
0011 import org.kde.kirigamiaddons.labs.components as KirigamiComponents
0012 
0013 import org.kde.neochat
0014 
0015 Kirigami.ScrollablePage {
0016     id: root
0017 
0018     property NeoChatConnection connection
0019 
0020     title: i18n("Start a Chat")
0021 
0022     header: QQC2.Control {
0023         padding: Kirigami.Units.largeSpacing
0024         contentItem: RowLayout {
0025             Kirigami.SearchField {
0026                 id: identifierField
0027 
0028                 property bool isUserID: text.match(/@(.+):(.+)/g)
0029 
0030                 Layout.fillWidth: true
0031 
0032                 placeholderText: i18n("Find a user...")
0033 
0034                 onAccepted: userDictListModel.search()
0035             }
0036 
0037             QQC2.Button {
0038                 visible: identifierField.isUserID
0039 
0040                 text: i18n("Chat")
0041                 highlighted: true
0042 
0043                 onClicked: {
0044                     connection.requestDirectChat(identifierField.text);
0045                     applicationWindow().pageStack.layers.pop();
0046                 }
0047             }
0048         }
0049     }
0050 
0051     ListView {
0052         id: userDictListView
0053 
0054         clip: true
0055 
0056         spacing: Kirigami.Units.smallSpacing
0057 
0058         model: UserDirectoryListModel {
0059             id: userDictListModel
0060 
0061             connection: root.connection
0062             keyword: identifierField.text
0063         }
0064 
0065         delegate: Delegates.RoundedItemDelegate {
0066             id: delegate
0067 
0068             required property string userID
0069             required property string avatar
0070             required property string name
0071             required property var directChats
0072 
0073             text: name
0074 
0075             contentItem: RowLayout {
0076                 KirigamiComponents.Avatar {
0077                     Layout.preferredWidth: Kirigami.Units.iconSizes.medium
0078                     Layout.preferredHeight: Kirigami.Units.iconSizes.medium
0079                     source: delegate.avatar ? ("image://mxc/" + delegate.avatar) : ""
0080                     name: delegate.name
0081                 }
0082 
0083                 Delegates.SubtitleContentItem {
0084                     itemDelegate: delegate
0085                     subtitle: delegate.userID
0086                     Layout.fillWidth: true
0087                     labelItem.textFormat: Text.PlainText
0088                 }
0089 
0090                 QQC2.Button {
0091                     id: joinChatButton
0092 
0093                     visible: delegate.directChats && delegate.directChats.length > 0
0094                     text: i18n("Join existing chat")
0095                     display: QQC2.Button.IconOnly
0096 
0097                     icon.name: "document-send"
0098                     onClicked: {
0099                         connection.requestDirectChat(delegate.userID);
0100                         applicationWindow().pageStack.layers.pop();
0101                     }
0102 
0103                     Layout.alignment: Qt.AlignRight
0104 
0105                     QQC2.ToolTip.text: text
0106                     QQC2.ToolTip.visible: hovered
0107                     QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0108                 }
0109 
0110                 QQC2.Button {
0111                     icon.name: "irc-join-channel"
0112                     // We wants to make sure an user can't start more than one
0113                     // chat with someone.
0114                     visible: !joinChatButton.visible
0115                     text: i18n("Create new chat")
0116                     display: QQC2.Button.IconOnly
0117 
0118                     onClicked: {
0119                         connection.requestDirectChat(delegate.userID);
0120                         applicationWindow().pageStack.layers.pop();
0121                     }
0122 
0123                     Layout.alignment: Qt.AlignRight
0124 
0125                     QQC2.ToolTip.text: text
0126                     QQC2.ToolTip.visible: hovered
0127                     QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0128                 }
0129             }
0130         }
0131 
0132         Kirigami.PlaceholderMessage {
0133             anchors.centerIn: parent
0134             visible: userDictListView.count < 1
0135             text: i18n("No users available")
0136         }
0137     }
0138 }