// SPDX-FileCopyrightText: 2026 Matvey Shcherbinin // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL import QtQuick import QtQuick.Layouts import QtQuick.Controls as QQC2 import QtQuick.Dialogs import QtMultimedia import org.kde.kirigami as Kirigami import org.kde.kirigamiaddons.components as Components // not aliased: the viewer's model is list, and a // property type in a declaration cannot carry an import namespace. import org.kde.kirigamiaddons.labs.components import koutnet.app Kirigami.Page { id: root property string peerIp: "" property var peerInfo: null property var messagesModel: null property bool peerTyping: false property string selfDisplayName: "" property string selfAvatarSource: "" // The peer's TLS avatar, set by Main.qml from onPeerAvatar and handed to // the timeline so LAN rows fall back to it. property string peerAvatarSource: "" // What the window's one music player holds, so a row can say whether its // track is playing. The player itself lives in Main.qml. property string musicActiveChatId: "" property string musicActiveSource: "" // what the player says the track is called, for the float below the header. property string musicTitle: "" // what its metadata says about who performs it, when it says anything. property string musicPerformer: "" property bool musicPlaying: false property int musicPositionMs: 0 property int musicDurationMs: 0 // Where the active track's row stands; when it scrolls out of sight the // float takes over its controls, so a song does not stop because its row // was scrolled past. property string musicRowMsgId: "" property bool musicRowOnScreen: true // The queue and the repeat the float's transport buttons walk and cycle: // the window's player owns them, the float only shows where they stand. property int musicRepeatMode: 0 property int musicQueueIndex: -1 property int musicQueueSize: 0 // The page's one video recording: which message it belongs to, the name // the float reads, and whether its row is on screen. A video does not // outlive its chat. property string videoClaimMsgId: "" property string videoPlayingName: "" property bool videoRowOnScreen: true // What the player itself is doing - read off the player rather than // stored, so the transport and the float say exactly what it says. readonly property bool videoPlaying: videoPlayer.playbackState === MediaPlayer.PlayingState readonly property int videoPositionMs: videoPlayer.position readonly property int videoDurationMs: videoPlayer.duration // The page's one video decoder, kept like the music player so a recycled // row cannot stop the picture. A row claims it for its message id and // lends it the surface its tile draws into. MediaPlayer { id: videoPlayer audioOutput: AudioOutput {} } // A room chat (Matrix, later Rocket.Chat or Telegram groups) as opposed to // a LAN peer. They are deliberately not made to look alike: a room has a // name, a topic and members; a peer is a person. property bool isRoom: false // MatrixRoomBridge::roomInfo()'s map, or null. Keys used here: displayName, // topic, joinedCount, avatarUrl, encrypted. property var roomInfo: null signal sendRequested(string text, string replyExcerpt, string replyAuthor, string replyId) signal attachRequested(string localFilePath) signal attachmentsReady(var localPaths) // A hidden message (MSC2446): the composer flips the send path for it. signal spoilerRequested(string text) // A shared geo: point, from the composer's location form. signal locationRequested(real latitude, real longitude, string label) // A recorded voice clip (path + length) and an image sent as a sticker both // arrive here as local paths the bridge uploads. signal voiceCaptured(string filePath, int durationMs) signal stickerRequested(string localFilePath) property var pendingAttachments: [] function reviewAttachments(paths) { const clean = [] for (let i = 0; i < paths.length; ++i) { if (paths[i] && clean.indexOf(paths[i]) < 0) clean.push(paths[i]) } if (clean.length === 0) return root.pendingAttachments = clean attachmentReview.open() } function removePendingAttachment(index) { const next = root.pendingAttachments.slice() next.splice(index, 1) root.pendingAttachments = next if (next.length === 0) attachmentReview.close() } // A poll to create: question and the non-empty answer options. signal pollRequested(string question, var answers) signal callRequested() signal profileRequested() signal infoRequested() signal invitePeerRequested(string chatId) // The room's information panel: the window says whether it is out and how // wide it is, and the page answers with what the reader did to it. signal infoPanelCloseRequested() signal infoPanelWidthRequested(real width) // The room information page's own actions, forwarded up: the cards, the // dialogs and the bridge calls are the window's, not the panel's. signal memberActivated(string userId, Item anchorItem) signal leaveRequested(string chatId) signal verifySessionsRequested() signal encryptionRequested(string chatId) signal peerCardRequested(Item anchorItem) signal ownProfileRequested(Item anchorItem) signal newChatRequested() signal forwardRequested(int row) // The float player's stop: the window's player is what actually ends the // song, the page only asks it to. signal musicStopRequested() // The float's transport: a step along the queue, and the repeat cycle. signal musicSkipNext() signal musicSkipPrevious() signal musicRepeatCycle() // Raised after this page's own model has already been changed. The msgId // rather than the row: a row number means nothing on the other end of a socket. signal editCommitted(string msgId, string newText) signal deleteCommitted(string msgId) signal typingNotice() signal notifyRequested(string text) signal openChatRequested(string chatId) signal readReached() // An audio row asked for its track (or to move within it): the window's // player answers, wherever the reader has since navigated. signal musicActivated(string chatId, string source, string title) signal musicSeek(int positionMs) // A video tile's tap: the window opens its player page over everything, // which spans the window and takes a fullscreen on request. signal videoRequested(string source) // Files dropped on the conversation go the same way a chosen file does. signal filesDropped(var localPaths) readonly property bool hasChat: root.peerIp.length > 0 && root.messagesModel !== null readonly property bool isFavorites: root.peerInfo !== null && root.peerInfo.isFavorites === true readonly property alias atBottom: timeline.atBottom readonly property string selfReactionName: "me" property string viewerSource: "" property string viewerCaption: "" readonly property string roomName: root.roomInfo ? (root.roomInfo.displayName || "") : "" readonly property string roomTopic: root.roomInfo ? (root.roomInfo.topic || "") : "" readonly property int roomMemberCount: root.roomInfo ? (root.roomInfo.joinedCount || 0) : 0 // never the address. peerInfoFor() already substitutes a name for a peer // that has published none, so the fallback here is only for having no peer. title: root.isRoom ? (root.roomName.length > 0 ? root.roomName : i18nc("@title a room whose name has not been synced yet", "Room")) : (root.peerInfo ? (root.peerInfo.username || i18nc("@title a peer that has published no name of its own", "Unknown peer")) : i18nc("@title", "Chat")) padding: 0 // no peer column in compact mode, so the action that asks for one goes too. property bool compact: false // See the note on Kirigami.Theme in Main.qml. background: Rectangle { color: ThemePalette.surface opacity: appSettings.wallpaperPath.length > 0 ? 0 : 1 } // A room's name opens the room, a peer's name opens the peer: one // gesture, two different things behind it. function openHeaderProfile(anchorItem) { if (root.isRoom) root.infoRequested() else root.peerCardRequested(headerName) } titleDelegate: RowLayout { Layout.fillWidth: true spacing: Kirigami.Units.largeSpacing visible: root.peerInfo !== null || root.isRoom Components.Avatar { id: headerAvatar Layout.alignment: Qt.AlignVCenter implicitWidth: Kirigami.Units.iconSizes.medium implicitHeight: Kirigami.Units.iconSizes.medium name: root.isFavorites ? "" : root.title iconSource: root.isFavorites ? (AppPalette.dark ? "bookmarks-symbolic" : "bookmarks") : "" // A room usually has a picture; a LAN peer publishes a name and a // bio until an avatar frame lands and replaces the initials. source: root.isRoom && root.roomInfo ? (root.roomInfo.avatarUrl || "") : root.peerAvatarSource TapHandler { enabled: !root.isFavorites acceptedButtons: Qt.LeftButton onTapped: root.openHeaderProfile(headerAvatar) } } ColumnLayout { Layout.fillWidth: true spacing: 0 Kirigami.Heading { id: headerName Layout.fillWidth: true level: 4 elide: Text.ElideRight textFormat: Text.PlainText text: root.title HoverHandler { enabled: !root.isFavorites cursorShape: Qt.PointingHandCursor } // The name opens the same small panel as a face in the // timeline; the full room or peer view is an action in it. TapHandler { enabled: !root.isFavorites acceptedButtons: Qt.LeftButton onTapped: root.openHeaderProfile(headerName) } } // A room's second line is what the room is for; a peer's is whether // the person is there. RelativeTime.now makes the label age on its // own while the window sits open. QQC2.Label { Layout.fillWidth: true // the second line of the header goes in compact mode: when the // window is this short every line spent on furniture is a message. visible: !root.isFavorites && !root.compact && text.length > 0 elide: Text.ElideRight textFormat: Text.PlainText text: { if (root.isRoom) { if (root.roomTopic.length > 0) return root.roomTopic.replace(/\s+/g, " ") return root.roomMemberCount > 0 ? i18ncp("@info:status %1 is how many people are in a room", "%1 member", "%1 members", root.roomMemberCount) : "" } return root.peerInfo ? RelativeTime.presenceLabel(root.peerInfo.online === true, root.peerInfo.lastSeen || 0, RelativeTime.now) : "" } font: Kirigami.Theme.smallFont color: (!root.isRoom && root.peerInfo && root.peerInfo.online === true) ? AppPalette.positiveText : AppPalette.disabledText } } } actions: [ Kirigami.Action { text: root.isRoom ? i18nc("@action:button show the room's topic, address and members", "Room information") : i18nc("@action:button show who is on the other end of this conversation", "Details") icon.name: "documentinfo" // Shown at every width: in a narrow window the room's information // opens as a layer, and a button that vanished with the width // would leave the reader hunting for it. visible: root.hasChat && !root.isFavorites onTriggered: root.infoRequested() }, Kirigami.Action { text: i18nc("@action:button invite someone to this LAN group", "Invite") icon.name: "list-add-user" visible: root.hasChat && root.isRoom && chatTransport.transportName(root.peerIp) === "lan" onTriggered: root.invitePeerRequested(root.peerIp) }, Kirigami.Action { text: i18nc("@action:button start a voice call", "Call") icon.name: "call-start" // Compact mode keeps only what a message needs; a call still starts visible: root.hasChat && !root.isFavorites && !root.compact && chatTransport.supportsCalls(root.peerIp) onTriggered: root.callRequested() } ] // Copying goes through an off-screen editor because there is no clipboard // object in QML without pulling in a C++ helper for it. TextEdit { id: clipboardHelper visible: false function copyText(str) { text = str selectAll() copy() } } QQC2.Dialog { id: attachmentReview title: i18nc("@title:window review attachments before sending", "Send attachments") modal: true standardButtons: QQC2.Dialog.Cancel width: Math.min(root.width - Kirigami.Units.gridUnit * 2, Kirigami.Units.gridUnit * 32) contentItem: ColumnLayout { spacing: Kirigami.Units.smallSpacing QQC2.Label { Layout.fillWidth: true text: i18ncp("@info number of attachments waiting to be sent", "%1 attachment", "%1 attachments", root.pendingAttachments.length) wrapMode: Text.WordWrap } ListView { Layout.fillWidth: true Layout.preferredHeight: Math.min(contentHeight, Kirigami.Units.gridUnit * 14) model: root.pendingAttachments clip: true delegate: QQC2.ItemDelegate { width: ListView.view.width text: modelData.split("/").pop() icon.name: "mail-attachment" onClicked: root.removePendingAttachment(index) QQC2.ToolTip.visible: hovered QQC2.ToolTip.text: i18nc("@info click an attachment to remove it", "Click to remove") } } QQC2.Label { Layout.fillWidth: true text: i18nc("@info attachments can be removed by clicking them", "Click an item to remove it, or press Send to continue.") wrapMode: Text.WordWrap font: Kirigami.Theme.smallFont color: AppPalette.disabledText } QQC2.Button { Layout.alignment: Qt.AlignRight text: i18nc("@action:button send reviewed attachments", "Send") icon.name: "document-send" enabled: root.pendingAttachments.length > 0 onClicked: { root.attachmentsReady(root.pendingAttachments) root.pendingAttachments = [] attachmentReview.close() } } } } // A message carries one picture, but the component takes a model either way, // and the list has to be typed or the roles do not resolve. property list viewerItems: [ AlbumModelItem { type: AlbumModelItem.Image source: root.viewerSource caption: root.viewerCaption } ] AlbumMaximizeComponent { id: imageViewer // See the note on Kirigami.Theme in Main.qml: this is reparented into // the window overlay, which is a theme chain of its own. Kirigami.Theme.inherit: false model: root.viewerItems initialIndex: 0 showCaption: root.viewerCaption.length > 0 title: root.title subtitle: root.viewerCaption // the transfer already put the picture on this machine, so there is // nothing to download and "save as" just hands it to the desktop. onSaveItem: Qt.openUrlExternally(root.viewerSource) } // already a URL when it arrives: AttachmentBlock turns LAN attachments function showImage(source) { root.viewerSource = source const withoutQuery = source.split("?")[0] root.viewerCaption = decodeURIComponent(withoutQuery.substring(withoutQuery.lastIndexOf("/") + 1)) imageViewer.open() } // one menu for the whole list, so scrolling does not build one per message. Components.ConvergentContextMenu { id: messageMenu property int row: -1 property string body: "" property string author: "" property string msgId: "" readonly property var codeBlocks: TextHandler.codeBlocks(messageMenu.body) Kirigami.Action { text: i18nc("@action:inmenu", "Reply") icon.name: "mail-replied-symbolic" onTriggered: root.startReply(messageMenu.author, messageMenu.body, messageMenu.msgId) } Kirigami.Action { text: i18nc("@action:inmenu", "Copy") icon.name: "edit-copy" enabled: messageMenu.body.length > 0 onTriggered: { clipboardHelper.copyText(messageMenu.body) root.notifyRequested(i18nc("@info:status", "Message copied to the clipboard")) } } Kirigami.Action { text: i18ncp("@action:inmenu copy the code out of a message; the count is how many fenced blocks it has", "Copy the code", "Copy the code blocks", messageMenu.codeBlocks.length) icon.name: "edit-copy" visible: messageMenu.codeBlocks.length > 0 onTriggered: { clipboardHelper.copyText(messageMenu.codeBlocks.join("\n\n")) root.notifyRequested(i18nc("@info:status", "Code copied to the clipboard")) } } Kirigami.Action { text: i18nc("@action:inmenu add a reaction", "React") icon.name: "smiley-add" onTriggered: reactionPicker.openFor(messageMenu.row) } Kirigami.Action { text: i18nc("@action:inmenu forward this message", "Forward") icon.name: "mail-forward" onTriggered: root.forwardRequested(messageMenu.row) } Kirigami.Action { separator: true } Kirigami.Action { text: i18nc("@action:inmenu change what this message says", "Edit") icon.name: "document-edit" visible: root.canEditRow(messageMenu.row) onTriggered: root.startEdit(messageMenu.row, messageMenu.body) } Kirigami.Action { text: i18nc("@action:inmenu delete this message", "Delete") icon.name: "edit-delete" visible: chatTransport.supportsEdits(root.peerIp) onTriggered: deleteConfirm.open() } } // Asked about rather than done, because there is no undo behind it: the // entry is gone from the log as well as from the list. Kirigami.PromptDialog { id: deleteConfirm // See the note on Kirigami.Theme in Main.qml. Kirigami.Theme.inherit: false title: i18nc("@title:window", "Delete this message?") subtitle: i18nc("@info", "It will be removed from this conversation and from the other end of it. This cannot be undone.") standardButtons: Kirigami.Dialog.Cancel customFooterActions: [ Kirigami.Action { text: i18nc("@action:button confirm deleting a message", "Delete") icon.name: "edit-delete" onTriggered: { root.commitDelete(messageMenu.row) deleteConfirm.close() } } ] } // Only your own text can be changed, and a file has no text to change. // The transport has the last word: a backend without edits must not // offer a change that would never leave this window. function canEditRow(row) { if (!root.messagesModel || row < 0 || !chatTransport.supportsEdits(root.peerIp)) return false const idx = root.messagesModel.index(row, 0) return root.messagesModel.data(idx, ChatModel.IsOwnRole) === true && root.messagesModel.data(idx, ChatModel.IsFileRole) !== true } // Committing is the model's job first and the peer's second; nothing goes on // the wire for a message the model refused to change. function startEdit(row, body) { composer.startEdit(row, body) } function commitEdit(row, newText) { if (!root.messagesModel) return const msgId = root.messagesModel.msgIdForRow(row) if (root.messagesModel.editMessage(row, newText)) root.editCommitted(msgId, newText) } function commitDelete(row) { if (!root.messagesModel) return // Read before the row goes, or there is nothing left to read it from. const msgId = root.messagesModel.msgIdForRow(row) if (root.messagesModel.deleteMessage(row)) root.deleteCommitted(msgId) } // The user menu reports a mention here; the composer is the only place // that knows where the caret is and how a mention is written. function mentionUser(name, userId) { composer.insert("@" + (name || userId) + " ") composer.focusInput() } function startReply(author, excerpt, msgId) { composer.replyAuthor = author composer.replyExcerpt = excerpt composer.replyId = msgId composer.focusInput() } function pinMessage(msgId) { // Pinning is a Matrix room feature; a LAN peer has no room to pin to. if (chatTransport.transportName(root.peerIp) !== "matrix" || !root.messagesModel) return // Pass the event id directly: it is exact and cannot collide. matrixRooms.pinMessage(root.peerIp, msgId) } function clearReply() { composer.replyAuthor = "" composer.replyExcerpt = "" composer.replyId = "" } ReactionPicker { id: reactionPicker onChosen: (row, emoji) => { if (root.messagesModel) root.messagesModel.toggleReaction(row, emoji, root.selfReactionName) } } EmojiPopup { id: emojiPopup // Above the button that opened it, so the panel covers the // conversation rather than the list and the composer. Only a window // too narrow for a column of its own gets this shape; see panelDocked. anchorItem: composer.emojiButton onPicked: (emoji) => composer.insert(emoji) } // The emoji panel as a column of its own on the right, Telegram's shape EmojiSidePanel { id: emojiPanel parent: root anchors.top: parent.top anchors.bottom: parent.bottom anchors.right: parent.right // the room's panel, when it is on this side too, sits between the emoji // column and the window's edge anchors.rightMargin: root.infoPanelRightMargin // A one-column window has nowhere to put a third of itself: a panel readonly property bool docked: !root.compact && root.width >= emojiPanel.width + Kirigami.Units.gridUnit * 12 onPicked: (emoji) => { composer.insert(emoji) // The panel keeps the focus for its search field, so the field is // given it back here: the next emoji goes into it, not into a // search. composer.focusInput() } } // What the emoji panel takes off the conversation, and nothing while it is // closed. The timeline and the composer both stop where the column // starts, as they sit side by side rather than one over the other. readonly property real panelWidth: root.panelDocked ? emojiPanel.columnWidth : 0 readonly property bool panelDocked: emojiPanel.docked // The room's information as a column beside the conversation, as wide as // its stored width (the window owns it; see Main.qml), with a minimum // under which its page has nowhere left to draw. property bool infoPanelRequested: false property real infoPanelWidth: 0 // Which side the panel draws on: true left, false right - and right is // where it stands by default. A pinned KOutNet setting wins; "as the // code decides" is what the flag is for. readonly property bool infoPanelFlagLeft: false readonly property bool infoPanelOnLeft: appSettings.roomInfoSide === 1 ? true : appSettings.roomInfoSide === 2 ? false : infoPanelFlagLeft readonly property bool infoPanelFits: root.width >= root.infoPanelWidth + Kirigami.Units.gridUnit * 12 readonly property bool infoPanelVisible: root.infoPanelRequested && root.infoPanelFits && root.infoPanelWidth > 0 // What the conversation gives up on each side, which the timeline, the // composer and the floats subtract from the same edge the panel is on. readonly property real infoPanelLeftMargin: root.infoPanelVisible && root.infoPanelOnLeft ? root.infoPanelWidth : 0 readonly property real infoPanelRightMargin: root.infoPanelVisible && !root.infoPanelOnLeft ? root.infoPanelWidth : 0 // A window dragged out of the column takes the panel down with it: a // column the conversation no longer fits beside is the drop-down without // its sizing, left standing over the conversation. onPanelDockedChanged: if (!root.panelDocked) { emojiPanel.close() } // One panel at a time down the right edge: the room's information and the // emoji column are both full-height and open over the same conversation, // so each opener takes the other down. onInfoPanelRequestedChanged: if (infoPanelRequested) { emojiPanel.close() emojiPopup.close() } function openEmojiPanel() { // The room's panel gives way whichever shape the emoji take: a column // of its own or a pop-up over the composer. root.infoPanelCloseRequested() if (root.panelDocked) { if (!emojiPanel.visible) emojiPanel.toggle() return } emojiPopup.open() } // The room's information, reparented onto the page like the emoji panel, Item { id: infoPanelHost parent: root anchors.top: parent.top anchors.bottom: parent.bottom width: root.infoPanelVisible ? root.infoPanelWidth : 0 // one x for both sides: the panel is anchored by the edge it opens from x: root.infoPanelOnLeft ? 0 : parent.width - width visible: root.infoPanelVisible clip: true RoomInfoPage { id: roomInfoPanel anchors.fill: parent // an id only while the panel is out: a closed panel asks the bridge // for nothing, and opening it fills the same query back in. chatId: root.infoPanelVisible ? root.peerIp : "" onMemberActivated: (userId, anchorItem) => root.memberActivated(userId, anchorItem) onLeaveRequested: (chatId) => root.leaveRequested(chatId) onNotifyRequested: (text) => root.notifyRequested(text) onVerifySessionsRequested: root.verifySessionsRequested() onEncryptionRequested: (chatId) => root.encryptionRequested(chatId) } // The cross over the page, where the layer's Back button used to be: a QQC2.ToolButton { id: infoPanelCloseChip objectName: "roomInfoCloseChip" anchors.top: parent.top anchors.right: parent.right anchors.topMargin: roomInfoPanel.contentItem.y + Kirigami.Units.smallSpacing anchors.rightMargin: Kirigami.Units.smallSpacing + roomInfoPanel.scrollBarRoom z: 3 display: QQC2.AbstractButton.IconOnly icon.name: "window-close" text: i18nc("@action:button close the room information panel", "Close the room information") QQC2.ToolTip.visible: hovered QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay QQC2.ToolTip.text: text Accessible.name: text onClicked: root.infoPanelCloseRequested() } // The handle on the panel's inner edge, which moves this panel and Item { id: infoPanelResizeHandle property real widthAtGrab: 0 x: root.infoPanelOnLeft ? parent.width - width / 2 : -width / 2 y: 0 width: Kirigami.Units.smallSpacing * 3 height: parent.height Rectangle { anchors.horizontalCenter: parent.horizontalCenter width: 1 height: parent.height // a hairline, as the list's edge is drawn: the edge of a // column, not a rule through the window color: ThemePalette.accent opacity: panelEdgeDrag.active ? 0.8 : (panelEdgeHover.hovered ? 0.5 : 0.25) Behavior on opacity { NumberAnimation { duration: Kirigami.Units.longDuration easing.type: Easing.OutCubic } } } HoverHandler { id: panelEdgeHover cursorShape: Qt.SizeHorCursor } DragHandler { id: panelEdgeDrag // the handle follows the column, so the drag must not move it: // two writers for one x is a handle that fights its panel target: null cursorShape: Qt.SizeHorCursor yAxis.enabled: false grabPermissions: PointerHandler.CanTakeOverFromAnything onActiveChanged: if (active) infoPanelResizeHandle.widthAtGrab = root.infoPanelWidth onTranslationChanged: if (active) { // the left panel grows rightwards, the right one leftwards: // the hand moves the edge, not the panel const move = root.infoPanelOnLeft ? panelEdgeDrag.translation.x : -panelEdgeDrag.translation.x root.infoPanelWidthRequested( Math.round(infoPanelResizeHandle.widthAtGrab + move)) } } activeFocusOnTab: true Accessible.role: Accessible.Separator Accessible.name: i18nc("@info:whatsthis", "Width of the room information panel") Keys.onPressed: function (event) { // left and right move the edge, whichever side it is on: for a // panel on the right, growing means moving its edge left const direction = root.infoPanelOnLeft ? 1 : -1 const step = event.key === Qt.Key_Left ? -1 : (event.key === Qt.Key_Right ? 1 : 0) if (step === 0) return root.infoPanelWidthRequested( Math.round(root.infoPanelWidth + step * direction * Kirigami.Units.gridUnit)) event.accepted = true } } } FileDialog { id: fileDialog title: i18nc("@title:window", "Attach a file") onAccepted: root.reviewAttachments([FsUtils.toLocalPath(selectedFile)]) } // A sticker is any picture; the bridge uploads it and sends it as m.sticker. FileDialog { id: stickerDialog title: i18nc("@title:window", "Send a sticker") nameFilters: [i18nc("@item file type filter", "Images (*.png *.jpg *.jpeg *.gif *.webp)"), i18nc("@item file type filter", "All files (*)")] onAccepted: root.stickerRequested(FsUtils.toLocalPath(selectedFile)) } Kirigami.PlaceholderMessage { anchors.centerIn: parent width: parent.width - Kirigami.Units.gridUnit * 4 visible: !root.hasChat icon.name: "dialog-messages" text: i18nc("@info", "No conversation open") explanation: i18nc("@info", "Pick a chat from the list, or start a new one.") } MessageTimeline { id: timeline anchors.fill: parent anchors.leftMargin: root.infoPanelLeftMargin anchors.rightMargin: root.panelWidth + root.infoPanelRightMargin visible: root.hasChat messagesModel: root.messagesModel chatId: root.peerIp selfName: root.selfReactionName peerName: root.title selfDisplayName: root.selfDisplayName selfAvatarSource: root.selfAvatarSource peerAvatarSource: root.peerAvatarSource canEditMessages: chatTransport.supportsEdits(root.peerIp) musicActiveChatId: root.musicActiveChatId musicActiveSource: root.musicActiveSource musicPlaying: root.musicPlaying musicPositionMs: root.musicPositionMs musicDurationMs: root.musicDurationMs videoClaimMsgId: root.videoClaimMsgId videoPlaying: root.videoPlaying videoPositionMs: root.videoPositionMs videoDurationMs: root.videoDurationMs onAvatarActivated: (own, userId, anchorItem) => { if (own) root.ownProfileRequested(anchorItem) else if (root.isRoom && userId.length > 0) // a room member is not a peer: the message names the member by // id, and their card is the room's own, not the chat's. root.memberActivated(userId, anchorItem) else root.peerCardRequested(anchorItem) } onMentionRequested: (name, uid) => root.mentionUser(name, uid) onOpenChatRequested: (chatId) => root.openChatRequested(chatId) onCopyLinkRequested: (url) => { clipboardHelper.copyText(url) root.notifyRequested(i18nc("@info:status", "Link copied")) } onOlderHistoryRequested: { if (typeof telegramRooms !== "undefined" && root.peerIp.startsWith("tg:")) { var oldestId = "" if (root.messagesModel && typeof root.messagesModel.oldestMessageId === "function") oldestId = root.messagesModel.oldestMessageId() telegramRooms.requestOlderChatHistory(root.peerIp, oldestId) } } onReplyRequested: (row, author, excerpt, msgId) => root.startReply(author, excerpt, msgId) onPinRequested: (row, msgId) => root.pinMessage(msgId) onEditRequested: (row, body) => root.startEdit(row, body) onReactRequested: (row) => reactionPicker.openFor(row) onMenuRequested: (row, author, body, msgId) => { messageMenu.row = row messageMenu.author = author messageMenu.body = body messageMenu.msgId = msgId messageMenu.popup() } onReactionToggled: (row, emoji) => { if (root.messagesModel) root.messagesModel.toggleReaction(row, emoji, root.selfReactionName) } onImageActivated: (source) => root.showImage(source) onFileActivated: (source) => Qt.openUrlExternally(source) onVideoActivated: (source) => { // The player page takes over the decoding: the page's player // stands down, and the row returns to its poster. videoPlayer.stop() root.videoClaimMsgId = "" root.videoRequested(source) } // A row claimed the player: the claim moves, the picture gets the // row's surface, and the position is kept when the same recording asks // again, after a recycled item or a finished download. onVideoClaimRequested: (msgId, source, name, surface) => { if (root.videoClaimMsgId !== msgId) { root.videoClaimMsgId = msgId root.videoPlayingName = name videoPlayer.stop() videoPlayer.source = source.length > 0 ? source : "" } else if (source.length > 0 && String(videoPlayer.source).length === 0) { videoPlayer.source = source } if (surface) videoPlayer.videoOutput = surface if (source.length > 0 && String(videoPlayer.source) === source && videoPlayer.playbackState !== MediaPlayer.PlayingState) videoPlayer.play() } onVideoToggleRequested: (msgId) => { if (msgId !== root.videoClaimMsgId) return if (videoPlayer.playbackState === MediaPlayer.PlayingState) videoPlayer.pause() else videoPlayer.play() } onVideoSeekRequested: (positionMs) => { videoPlayer.position = positionMs } // The row said where its media stands; the floats act on it. onMusicRowState: (msgId, onScreen) => { root.musicRowMsgId = msgId root.musicRowOnScreen = onScreen } onVideoRowState: (msgId, onScreen) => { // Only the claimed recording's whereabouts matter to the float; // every other row's report is noise. if (msgId !== root.videoClaimMsgId) return root.videoRowOnScreen = onScreen } onMusicActivated: (chatId, source, title) => root.musicActivated(chatId, source, title) onMusicSeek: (positionMs) => root.musicSeek(positionMs) onReadReached: root.readReached() onFilesDropped: (localPaths) => root.reviewAttachments(localPaths) } // The player outside its own chat, Telegram's float: a card pinned below Kirigami.ShadowedRectangle { id: musicFloat anchors.top: parent.top anchors.topMargin: Kirigami.Units.smallSpacing * 2 anchors.left: parent.left anchors.leftMargin: Kirigami.Units.largeSpacing + root.infoPanelLeftMargin // the details panel owns the strip to its width; the float stops where // the timeline does, scrollbar included. anchors.right: parent.right anchors.rightMargin: root.panelWidth + Kirigami.Units.largeSpacing + root.infoPanelRightMargin + timeline.scrollBarRoom z: 2 radius: Kirigami.Units.cornerRadius color: ThemePalette.surface border.width: 1 border.color: Kirigami.ColorUtils.linearInterpolation(ThemePalette.surface, ThemePalette.text, 0.2) shadow.size: Kirigami.Units.largeSpacing shadow.color: Qt.rgba(0, 0, 0, 0.25) shadow.yOffset: 2 // The row spans the card and is centered in it, but keeps its own // height: nothing anchors back, so the card wraps its content instead // of the two sizing each other into a collapsed strip. height: musicFloatRow.implicitHeight + Kirigami.Units.largeSpacing // The song's own chat keeps the float away while the row is on screen, // and hands the controls over the moment it scrolls out of sight. visible: root.musicActiveChatId.length > 0 && (root.musicActiveChatId !== root.peerIp || !root.musicRowOnScreen) // The card taps as one button: in the track's own chat the tap returns MouseArea { anchors.fill: parent z: -1 onClicked: { if (root.musicActiveChatId === root.peerIp && root.musicRowMsgId.length > 0) { timeline.jumpToMessage(root.musicRowMsgId) return } root.musicActivated(root.musicActiveChatId, root.musicActiveSource, root.musicTitle) } } RowLayout { id: musicFloatRow anchors.left: parent.left anchors.right: parent.right anchors.verticalCenter: parent.verticalCenter anchors.margins: Kirigami.Units.smallSpacing spacing: Kirigami.Units.smallSpacing QQC2.ToolButton { display: QQC2.AbstractButton.IconOnly icon.name: root.musicPlaying ? "media-playback-pause" : "media-playback-start" text: root.musicPlaying ? i18nc("@action:button pause the song in the float player", "Pause") : i18nc("@action:button resume the song in the float player", "Play") QQC2.ToolTip.visible: hovered QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay QQC2.ToolTip.text: text onClicked: root.musicActivated(root.musicActiveChatId, root.musicActiveSource, root.musicTitle) } ColumnLayout { spacing: 0 QQC2.Label { Layout.maximumWidth: Kirigami.Units.gridUnit * 9 text: root.musicTitle textFormat: Text.PlainText elide: Text.ElideRight font.pointSize: Kirigami.Theme.defaultFont.pointSize * 0.95 } QQC2.Label { Layout.maximumWidth: Kirigami.Units.gridUnit * 9 visible: root.musicPerformer.length > 0 text: root.musicPerformer textFormat: Text.PlainText elide: Text.ElideRight font: Kirigami.Theme.smallFont color: AppPalette.disabledText } } // The seek the float has because it spans the chat: the one bar the // single player makes possible while the reader is elsewhere. QQC2.Slider { Layout.fillWidth: true from: 0 // never zero: a slider with an empty range cannot be moved, and // duration is zero until the header has been read. to: Math.max(1, root.musicDurationMs) value: pressed ? value : root.musicPositionMs onMoved: root.musicSeek(value) } QQC2.Label { font: Kirigami.Theme.smallFont color: AppPalette.disabledText // m:ss of what has played; a player that cannot say where it // is is a radio. text: { const total = Math.max(0, Math.round(root.musicPositionMs / 1000)) const pad = (n) => (n < 10 ? "0" + n : "" + n) return Math.floor(total / 60) + ":" + pad(total % 60) } } // The queue walked: a step back and a step along, wrapping only // under repeat-all, standing still at the ends otherwise. QQC2.ToolButton { display: QQC2.AbstractButton.IconOnly icon.name: "media-skip-backward" enabled: root.musicRepeatMode === 1 || root.musicQueueIndex > 0 text: i18nc("@action:button play the previous track of the queue", "Previous track") QQC2.ToolTip.visible: hovered QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay QQC2.ToolTip.text: text onClicked: root.musicSkipPrevious() } QQC2.ToolButton { display: QQC2.AbstractButton.IconOnly icon.name: "media-skip-forward" enabled: root.musicRepeatMode === 1 || root.musicQueueIndex + 1 < root.musicQueueSize text: i18nc("@action:button play the next track of the queue", "Next track") QQC2.ToolTip.visible: hovered QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay QQC2.ToolTip.text: text onClicked: root.musicSkipNext() } // The repeat, cycled: off, the whole queue, the one track. The // icon says which, so the button needs no menu. QQC2.ToolButton { display: QQC2.AbstractButton.IconOnly icon.name: root.musicRepeatMode === 2 ? "media-repeat-single" : root.musicRepeatMode === 1 ? "media-repeat-all" : "media-repeat-none" checked: root.musicRepeatMode !== 0 text: root.musicRepeatMode === 2 ? i18nc("@action:button repeat the current track only", "Repeat this track") : root.musicRepeatMode === 1 ? i18nc("@action:button repeat the whole queue", "Repeat the queue") : i18nc("@action:button turn repeat on", "Repeat") QQC2.ToolTip.visible: hovered QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay QQC2.ToolTip.text: text onClicked: root.musicRepeatCycle() } QQC2.ToolButton { display: QQC2.AbstractButton.IconOnly icon.name: "window-close" text: i18nc("@action:button stop the song and dismiss the float player", "Stop") QQC2.ToolTip.visible: hovered QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay QQC2.ToolTip.text: text onClicked: root.musicStopRequested() } } } // The recording that scrolled out of sight while it played: the same card // and controls, standing in for the row. The tap returns to the row; the // cross stops it for good, since a video has no life outside its row. Kirigami.ShadowedRectangle { id: videoFloat anchors.top: musicFloat.visible ? musicFloat.bottom : parent.top anchors.topMargin: Kirigami.Units.smallSpacing * 2 anchors.left: parent.left anchors.leftMargin: Kirigami.Units.largeSpacing + root.infoPanelLeftMargin anchors.right: parent.right anchors.rightMargin: root.panelWidth + Kirigami.Units.largeSpacing + root.infoPanelRightMargin + timeline.scrollBarRoom z: 2 radius: Kirigami.Units.cornerRadius color: ThemePalette.surface border.width: 1 border.color: Kirigami.ColorUtils.linearInterpolation(ThemePalette.surface, ThemePalette.text, 0.2) shadow.size: Kirigami.Units.largeSpacing shadow.color: Qt.rgba(0, 0, 0, 0.25) shadow.yOffset: 2 height: videoFloatRow.implicitHeight + Kirigami.Units.largeSpacing visible: root.videoClaimMsgId.length > 0 && root.videoPlaying && !root.videoRowOnScreen // The card's own tap, under the controls: a passive handler would take // the taps under the pause button too, and the click would both pause // and jump. MouseArea { anchors.fill: parent z: -1 onClicked: timeline.jumpToMessage(root.videoClaimMsgId) } RowLayout { id: videoFloatRow anchors.left: parent.left anchors.right: parent.right anchors.verticalCenter: parent.verticalCenter anchors.margins: Kirigami.Units.smallSpacing spacing: Kirigami.Units.smallSpacing QQC2.ToolButton { display: QQC2.AbstractButton.IconOnly icon.name: root.videoPlaying ? "media-playback-pause" : "media-playback-start" text: root.videoPlaying ? i18nc("@action:button pause the recording in the float player", "Pause") : i18nc("@action:button resume the recording in the float player", "Play") QQC2.ToolTip.visible: hovered QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay QQC2.ToolTip.text: text onClicked: { // the player is the page's own; no command slot between. if (root.videoPlaying) videoPlayer.pause() else videoPlayer.play() } } QQC2.Label { Layout.fillWidth: true text: root.videoPlayingName textFormat: Text.PlainText elide: Text.ElideRight font.pointSize: Kirigami.Theme.defaultFont.pointSize * 0.95 } QQC2.ToolButton { display: QQC2.AbstractButton.IconOnly icon.name: "window-close" text: i18nc("@action:button stop the recording and dismiss the float player", "Stop") QQC2.ToolTip.visible: hovered QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay QQC2.ToolTip.text: text onClicked: { videoPlayer.stop() root.videoClaimMsgId = "" } } } } // A pending edit left over from another conversation would land on whatever // row now has that number in this one. onPeerIpChanged: { root.clearReply() composer.cancelEdit() composer.cancelVoice() // the rows of the chat just left have said their piece, this chat's // have not. A recording does not outlive its chat: the player stands // down and the claim goes with the chat. root.musicRowMsgId = "" root.musicRowOnScreen = true videoPlayer.stop() videoPlayer.source = "" videoPlayer.videoOutput = null root.videoClaimMsgId = "" root.videoPlayingName = "" root.videoRowOnScreen = true } // The page gives its footer the full width whatever is in it, so the footer: Item { visible: root.hasChat implicitHeight: composer.implicitHeight Composer { id: composer // left and right, not left and a width: an anchored edge with // nothing across from it leaves the composer no width at all anchors.left: parent.left anchors.right: parent.right anchors.top: parent.top anchors.bottom: parent.bottom anchors.rightMargin: root.panelWidth + root.infoPanelRightMargin anchors.leftMargin: root.infoPanelLeftMargin peerTyping: root.peerTyping && !root.isFavorites peerName: root.title onSendRequested: (text, replyExcerpt, replyAuthor, replyId) => root.sendRequested(text, replyExcerpt, replyAuthor, replyId) onEditSubmitted: (row, text) => root.commitEdit(row, text) onAttachRequested: fileDialog.open() onEmojiRequested: root.openEmojiPanel() onSpoilerRequested: (text) => root.spoilerRequested(text) onLocationRequested: (lat, lon, label) => root.locationRequested(lat, lon, label) onVoiceCaptured: (path, ms) => root.voiceCaptured(path, ms) onStickerPickRequested: stickerDialog.open() onPollRequested: (question, answers) => root.pollRequested(question, answers) onReplyCancelled: root.clearReply() onTypingNotice: root.typingNotice() } } }