Debian Codegraph @

resources/qml/dialogs/CreateDirect.qml

raw
1 // SPDX-FileCopyrightText: Nheko Contributors
2 //
3 // SPDX-License-Identifier: GPL-3.0-or-later
4
5 import ".."
6 import QtQuick
7 import QtQuick.Window
8 import QtQuick.Layouts
9 import QtQuick.Controls
10 import im.nheko
11
12 ApplicationWindow {
13 id: createDirectRoot
14 title: qsTr("Create Direct Chat")
15 property var profile
16 property bool otherUserHasE2ee: profile? profile.deviceList.rowCount() > 0 : true
17 minimumHeight: layout.implicitHeight + footer.implicitHeight + Nheko.paddingLarge*2
18 minimumWidth: Math.max(footer.implicitWidth, layout.implicitWidth)
19 modality: Qt.NonModal
20 flags: Qt.Dialog | Qt.WindowCloseButtonHint | Qt.WindowTitleHint
21
22 onVisibilityChanged: {
23 userID.forceActiveFocus();
24 }
25
26 Shortcut {
27 sequence: StandardKey.Cancel
28 onActivated: createDirectRoot.close()
29 }
30
31 ColumnLayout {
32 id: layout
33 anchors.fill: parent
34 anchors.margins: Nheko.paddingLarge
35 spacing: userID.height/4
36
37 GridLayout {
38 Layout.fillWidth: true
39 rows: 2
40 columns: 2
41 rowSpacing: Nheko.paddingSmall
42 columnSpacing: Nheko.paddingMedium
43
44 Avatar {
45 Layout.rowSpan: 2
46 Layout.preferredWidth: Nheko.avatarSize
47 Layout.preferredHeight: Nheko.avatarSize
48 Layout.alignment: Qt.AlignLeft
49 userid: profile? profile.userid : ""
50 url: profile? profile.avatarUrl.replace("mxc://", "image://MxcImage/") : null
51 displayName: profile? profile.displayName : ""
52 enabled: false
53 }
54 Label {
55 Layout.fillWidth: true
56 text: profile? profile.displayName : ""
57 color: TimelineManager.userColor(userID.text, palette.window)
58 font.pointSize: fontMetrics.font.pointSize
59 }
60
61 Label {
62 Layout.fillWidth: true
63 text: userID.text
64 color: palette.buttonText
65 font.pointSize: fontMetrics.font.pointSize * 0.9
66 }
67 }
68
69 MatrixTextField {
70 id: userID
71 property bool isValidMxid: text.match("@.+?:.{3,}")
72 Layout.fillWidth: true
73 focus: true
74 label: qsTr("User to invite")
75 placeholderText: qsTr("@user:server.tld")
76 onTextChanged: {
77 // we can't use "isValidMxid" here, since the property might only be reevaluated after this change handler.
78 if(text.match("@.+?:.{3,}")) {
79 profile = TimelineManager.getGlobalUserProfile(text);
80 } else
81 profile = null;
82 }
83 }
84
85 RowLayout {
86 Layout.fillWidth: true
87 Label {
88 Layout.fillWidth: true
89 Layout.alignment: Qt.AlignLeft
90 text: qsTr("Encryption")
91 color: palette.text
92 }
93 ToggleButton {
94 Layout.alignment: Qt.AlignRight
95 id: encryption
96 checked: otherUserHasE2ee
97 }
98 }
99
100 Item {Layout.fillHeight: true}
101 }
102 footer: DialogButtonBox {
103 standardButtons: DialogButtonBox.Cancel
104 Button {
105 text: "Start Direct Chat"
106 DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole
107 enabled: userID.isValidMxid && profile
108 }
109 onRejected: createDirectRoot.close();
110 onAccepted: {
111 profile.startChat(encryption.checked)
112 createDirectRoot.close()
113 }
114 }
115 }