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, string displayName, url avatarUrl, string alias, string topic, int memberCount, bool isJoined) 0024 0025 title: i18nc("@title", "Room ID or Alias") 0026 0027 width: Math.min(applicationWindow().width, Kirigami.Units.gridUnit * 24) 0028 leftPadding: 0 0029 rightPadding: 0 0030 topPadding: 0 0031 bottomPadding: 0 0032 0033 standardButtons: Kirigami.Dialog.Cancel 0034 customFooterActions: [ 0035 Kirigami.Action { 0036 enabled: roomIdAliasText.isValidText 0037 text: i18n("OK") 0038 icon.name: "dialog-ok" 0039 onTriggered: { 0040 // We don't necessarily have all the info so fill out the best we can. 0041 let roomId = roomIdAliasText.isAlias() ? "" : roomIdAliasText.text; 0042 let displayName = ""; 0043 let avatarUrl = ""; 0044 let alias = roomIdAliasText.isAlias() ? roomIdAliasText.text : ""; 0045 let topic = ""; 0046 let memberCount = -1; 0047 let isJoined = false; 0048 if (roomIdAliasText.room) { 0049 roomId = roomIdAliasText.room.id; 0050 displayName = roomIdAliasText.room.displayName; 0051 avatarUrl = roomIdAliasText.room.avatarUrl.toString().length > 0 ? connection.makeMediaUrl(roomIdAliasText.room.avatarUrl) : ""; 0052 alias = roomIdAliasText.room.canonicalAlias; 0053 topic = roomIdAliasText.room.topic; 0054 memberCount = roomIdAliasText.room.joinedCount; 0055 isJoined = true; 0056 } 0057 root.roomSelected(roomId, displayName, avatarUrl, alias, topic, memberCount, isJoined); 0058 root.close(); 0059 } 0060 } 0061 ] 0062 0063 contentItem: ColumnLayout { 0064 spacing: 0 0065 FormCard.FormTextFieldDelegate { 0066 id: roomIdAliasText 0067 property bool isValidText: text.match(/(#|!)(.+):(.+)/g) 0068 property bool correctStart: text.startsWith("#") || text.startsWith("!") 0069 property NeoChatRoom room: { 0070 if (!acceptableInput) { 0071 return null; 0072 } 0073 if (isAlias()) { 0074 return root.connection.roomByAlias(text); 0075 } else { 0076 return root.connection.room(text); 0077 } 0078 } 0079 0080 label: i18n("Room ID or Alias:") 0081 statusMessage: { 0082 if (text.length > 0 && !correctStart) { 0083 return i18n("Must start with # for an alias or ! for an ID"); 0084 } 0085 if (timer.running) { 0086 return ""; 0087 } 0088 if (text.length > 0 && !isValidText) { 0089 return i18n("The input is not a valid room ID or alias"); 0090 } 0091 return correctStart ? "" : i18n("Must start with # for an alias or ! for an ID"); 0092 } 0093 status: text.length > 0 ? Kirigami.MessageType.Error : Kirigami.MessageType.Information 0094 0095 onTextEdited: timer.restart() 0096 0097 function isAlias() { 0098 return roomIdAliasText.text.startsWith("#"); 0099 } 0100 0101 Timer { 0102 id: timer 0103 interval: 1000 0104 } 0105 } 0106 } 0107 0108 onVisibleChanged: { 0109 roomIdAliasText.forceActiveFocus(); 0110 timer.restart(); 0111 } 0112 }