Warning, /network/neochat/src/qml/ManualRoomDialog.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-FileCopyrightText: 2023 James Graham <james.h.graham@protonmail.com> 0002 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0003 0004 import QtQuick 0005 import QtQuick.Layouts 0006 0007 import org.kde.kirigami as Kirigami 0008 import org.kde.kirigamiaddons.formcard as FormCard 0009 0010 import org.kde.neochat 0011 0012 Kirigami.Dialog { 0013 id: root 0014 0015 /** 0016 * @brief The connection for the current user. 0017 */ 0018 required property NeoChatConnection connection 0019 0020 /** 0021 * @brief Signal emitted when a valid room id or alias is entered. 0022 */ 0023 signal roomSelected(string roomId, 0024 string displayName, 0025 url avatarUrl, 0026 string alias, 0027 string topic, 0028 int memberCount, 0029 bool isJoined) 0030 0031 title: i18nc("@title", "Room ID or Alias") 0032 0033 width: Math.min(applicationWindow().width, Kirigami.Units.gridUnit * 24) 0034 leftPadding: 0 0035 rightPadding: 0 0036 topPadding: 0 0037 bottomPadding: 0 0038 0039 standardButtons: Kirigami.Dialog.Cancel 0040 customFooterActions: [ 0041 Kirigami.Action { 0042 enabled: roomIdAliasText.isValidText 0043 text: i18n("OK") 0044 icon.name: "dialog-ok" 0045 onTriggered: { 0046 // We don't necessarily have all the info so fill out the best we can. 0047 let roomId = roomIdAliasText.isAlias() ? "" : roomIdAliasText.text; 0048 let displayName = ""; 0049 let avatarUrl = ""; 0050 let alias = roomIdAliasText.isAlias() ? roomIdAliasText.text : ""; 0051 let topic = ""; 0052 let memberCount = -1; 0053 let isJoined = false; 0054 if (roomIdAliasText.room) { 0055 roomId = roomIdAliasText.room.id; 0056 displayName = roomIdAliasText.room.displayName; 0057 avatarUrl = roomIdAliasText.room.avatarUrl.toString().length > 0 ? connection.makeMediaUrl(roomIdAliasText.room.avatarUrl) : "" 0058 alias = roomIdAliasText.room.canonicalAlias; 0059 topic = roomIdAliasText.room.topic; 0060 memberCount = roomIdAliasText.room.joinedCount; 0061 isJoined = true; 0062 } 0063 root.roomSelected(roomId, displayName, avatarUrl, alias, topic, memberCount, isJoined); 0064 root.close(); 0065 } 0066 } 0067 ] 0068 0069 contentItem: ColumnLayout { 0070 spacing: 0 0071 FormCard.FormTextFieldDelegate { 0072 id: roomIdAliasText 0073 property bool isValidText: text.match(/(#|!)(.+):(.+)/g) 0074 property bool correctStart: text.startsWith("#") || text.startsWith("!") 0075 property NeoChatRoom room: { 0076 if (!acceptableInput) { 0077 return null; 0078 } 0079 if (isAlias()) { 0080 return root.connection.roomByAlias(text); 0081 } else { 0082 return root.connection.room(text); 0083 } 0084 } 0085 0086 label: i18n("Room ID or Alias:") 0087 statusMessage: { 0088 if (text.length > 0 && !correctStart) { 0089 return i18n("Must start with # for an alias or ! for an ID"); 0090 } 0091 if (timer.running) { 0092 return ""; 0093 } 0094 if (text.length > 0 && !isValidText) { 0095 return i18n("The input is not a valid room ID or alias"); 0096 } 0097 return correctStart ? "" : i18n("Must start with # for an alias or ! for an ID"); 0098 } 0099 status: text.length > 0 ? Kirigami.MessageType.Error : Kirigami.MessageType.Information 0100 0101 onTextEdited: timer.restart() 0102 0103 function isAlias() { 0104 return roomIdAliasText.text.startsWith("#"); 0105 } 0106 0107 Timer { 0108 id: timer 0109 interval: 1000 0110 } 0111 } 0112 } 0113 0114 onVisibleChanged: { 0115 roomIdAliasText.forceActiveFocus() 0116 timer.restart() 0117 } 0118 }