Debian Codegraph @

resources/qml/dialogs/RoomDirectory.qml

raw
1 // SPDX-FileCopyrightText: Nheko Contributors
2 //
3 // SPDX-License-Identifier: GPL-3.0-or-later
4
5 import ".."
6 import "../ui"
7 import QtQuick 2.15
8 import QtQuick.Controls 2.3
9 import QtQuick.Layouts 1.3
10 import QtQuick.Window 2.15
11 import im.nheko 1.0
12
13 ApplicationWindow {
14 id: roomDirectoryWindow
15
16 visible: true
17 minimumWidth: 340
18 minimumHeight: 340
19 height: 420
20 width: 650
21 color: palette.window
22 modality: Qt.NonModal
23 flags: Qt.Dialog | Qt.WindowCloseButtonHint | Qt.WindowTitleHint
24 title: qsTr("Explore Public Rooms")
25
26 Shortcut {
27 sequence: StandardKey.Cancel
28 onActivated: roomDirectoryWindow.close()
29 }
30
31 ListView {
32 id: roomDirView
33
34 anchors.fill: parent
35 model: publicRooms
36
37 delegate: Rectangle {
38 id: roomDirDelegate
39
40 property color background: palette.window
41 property color importantText: palette.text
42 property color unimportantText: palette.buttonText
43 property int avatarSize: fontMetrics.height * 3.2
44
45 color: background
46 height: avatarSize + Nheko.paddingLarge
47 width: ListView.view.width
48
49 RowLayout {
50 spacing: Nheko.paddingMedium
51 anchors.fill: parent
52 anchors.margins: Nheko.paddingMedium
53 implicitHeight: textContent.implicitHeight
54
55 Avatar {
56 id: roomAvatar
57
58 Layout.alignment: Qt.AlignVCenter
59 Layout.rightMargin: Nheko.paddingMedium
60 Layout.preferredWidth: roomDirDelegate.avatarSize
61 Layout.preferredHeight: roomDirDelegate.avatarSize
62
63 url: model.avatarUrl.replace("mxc://", "image://MxcImage/")
64 roomid: model.roomid
65 displayName: model.name
66 }
67
68 GridLayout {
69 id: textContent
70 rows: 2
71 columns: 2
72
73 Layout.alignment: Qt.AlignLeft
74 Layout.preferredWidth: parent.width - roomAvatar.width
75
76 ElidedLabel {
77 Layout.row: 0
78 Layout.column: 0
79 Layout.fillWidth:true
80 color: roomDirDelegate.importantText
81 elideWidth: width
82 fullText: model.name
83 }
84
85 Label {
86 id: roomTopic
87
88 color: roomDirDelegate.unimportantText
89 Layout.row: 1
90 Layout.column: 0
91 font.pointSize: fontMetrics.font.pointSize*0.9
92 elide: Text.ElideRight
93 maximumLineCount: 2
94 Layout.fillWidth: true
95 text: model.topic
96 verticalAlignment: Text.AlignVCenter
97 wrapMode: Text.WordWrap
98 }
99
100 Label {
101 Layout.alignment: Qt.AlignHCenter
102 Layout.row: 0
103 Layout.column: 1
104 id: roomCount
105
106 color: roomDirDelegate.unimportantText
107 font.pointSize: fontMetrics.font.pointSize*0.9
108 text: model.numMembers.toString()
109 }
110
111 Button {
112 Layout.row: 1
113 Layout.column: 1
114 id: joinRoomButton
115 enabled: model.roomid !== ""
116 text: model.canJoin ? qsTr("Join") : qsTr("Open")
117 onClicked: {
118 if (model.canJoin)
119 publicRooms.joinRoom(model.index);
120 else
121 {
122 Rooms.setCurrentRoom(model.roomid);
123 roomDirectoryWindow.close();
124 }
125 }
126 }
127
128 }
129
130 }
131
132 }
133
134 footer: Item {
135 anchors.horizontalCenter: parent.horizontalCenter
136 width: parent.width
137 visible: !publicRooms.reachedEndOfPagination && publicRooms.loadingMoreRooms
138 // hacky but works
139 height: loadingSpinner.height + 2 * Nheko.paddingLarge
140 anchors.margins: Nheko.paddingLarge
141
142 Spinner {
143 id: loadingSpinner
144
145 anchors.centerIn: parent
146 anchors.margins: Nheko.paddingLarge
147 running: visible
148 foreground: palette.mid
149 }
150
151 }
152
153 }
154
155 header: RowLayout {
156 id: searchBarLayout
157
158 spacing: Nheko.paddingMedium
159 width: parent.width
160 implicitHeight: roomSearch.height
161
162 MatrixTextField {
163 id: roomSearch
164
165 focus: true
166 Layout.fillWidth: true
167 selectByMouse: true
168 font.pixelSize: fontMetrics.font.pixelSize
169 color: palette.text
170 placeholderText: qsTr("Search for public rooms")
171 onTextChanged: searchTimer.restart()
172
173 Component.onCompleted: forceActiveFocus()
174 }
175
176 MatrixTextField {
177 id: chooseServer
178
179 Layout.minimumWidth: 0.3 * header.width
180 Layout.maximumWidth: 0.3 * header.width
181 color: palette.text
182 placeholderText: qsTr("Choose custom homeserver")
183 onTextChanged: publicRooms.setMatrixServer(text)
184 }
185
186 Timer {
187 id: searchTimer
188
189 interval: 350
190 onTriggered: roomDirView.model.setSearchTerm(roomSearch.text)
191 }
192
193 }
194
195 footer: RowLayout {
196 spacing: Nheko.paddingMedium
197 width: parent.width
198
199 Button {
200 text: qsTr("Close")
201 onClicked: roomDirectoryWindow.close()
202 Layout.alignment: Qt.AlignRight
203 Layout.margins: Nheko.paddingMedium
204 }
205 }
206
207 }