// 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 QtMultimedia import org.kde.kirigami as Kirigami import koutnet.app // two sources, one presentation. A LAN transfer has already put the file on this ColumnLayout { id: root // the LAN side: a local path, no scheme. property string filePath: "" // the Matrix side: an already-usable URL, mxc:// or otherwise. property string mediaUrl: "" property string chatId: "" property string eventId: "" property string downloadedUrl: "" property bool downloading: false property string downloadError: "" // A music row's only outward act: the window's single player takes the // track. Five rows of audio used to mean five players; what the row needs // to draw itself honestly is what the global player holds right now. signal musicActivated(string chatId, string source, string title) // the seek the global player carries, routed upward because a row cannot // see the window's player: only the track that is active here offers one. signal musicSeek(int positionMs) property string activeChatId: "" property string activeSource: "" property bool musicPlaying: false property int musicPositionMs: 0 property int musicDurationMs: 0 // The homeserver's own shorthand for "this is a file of mine, ask me for // it": not a url a decoder opens, but one the QML network manager fetches // with the session's own credentials. readonly property bool mxcUrl: /^mxc:/i.test(root.mediaUrl) // A url anything can fetch as it stands, used where there is no file to // cache it in: an https:// one, or the geo: point below. readonly property bool directUrl: !root.mxcUrl // One attempt at the download path, so a url that cannot be fetched at all // does not ask for itself in a loop every time the row scrolls past. property bool downloadAttempted: false function startDownload() { if (root.mediaUrl.length > 0 && !root.downloadedUrl && !root.downloading && !root.downloadAttempted) { root.downloadAttempted = true root.downloading = true // the address and the name go with the event id: a forwarded // attachment has no event of its own in this room, so the media is // fetched by what the row says it is. matrixRooms.downloadAttachment(root.chatId, root.eventId, root.mediaUrl, root.fileName) } } // A tap on a picture and a request from the desktop are the two things that // need a file rather than a picture. Both use the local copy when there is // one and ask for it when there is not; openAfter says which one waits. property string openAfter: "" function openViewer() { if (root.sourceUrl.length > 0) { root.imageActivated(root.sourceUrl) return } root.openAfter = "viewer" root.startDownload() } // The video's tap: the recording is claimed for the page's one player, whose // surface this tile is. A remote recording is fetched first, then claimed. function openVideo() { root.downloadError = "" root.videoClaimRequested(root.eventId, root.playbackSource, root.fileName, videoSurface) if (root.playbackSource.length === 0) root.startDownload() } // The desktop knows nothing about a homeserver's shorthand, and what it does function openExternally() { if (root.filePath.length > 0) { root.fileActivated(FsUtils.toSourceUrl(root.filePath)) return } if (root.downloadedUrl.length > 0) { root.fileActivated(root.downloadedUrl) return } root.openAfter = "desktop" root.startDownload() } // What to do when this row appears: start the watchdog and the cache timer, // and nothing else. A timeline builds rows as it scrolls, so anything // fetched here is fetched again for every picture crossing the viewport. function loadImage() { imageWatchdog.stop() cacheWarm.stop() if (!root.showsImage) return imageWatchdog.start() cacheWarm.start() } onMediaUrlChanged: { thumbnailFailed = false posterFailed = false downloadedUrl = "" downloadError = "" downloading = false openAfter = "" downloadAttempted = false Qt.callLater(loadImage) } onIsImageChanged: Qt.callLater(loadImage) onThumbnailUrlChanged: thumbnailFailed = false onMediaKindChanged: Qt.callLater(loadImage) onFilePathChanged: { refreshPoster() // A local copy arrived while this row holds the player: the player is // told what to play. Every claim path is idempotent at the page. if (root.claimedHere && root.playbackSource.length > 0) root.videoClaimRequested(root.eventId, root.playbackSource, root.fileName, videoSurface) } onDownloadedUrlChanged: { refreshPoster() // The download the tap started has put a file on the disk: if this // row holds the page's player, the player is told what to play. if (root.claimedHere && root.playbackSource.length > 0) root.videoClaimRequested(root.eventId, root.playbackSource, root.fileName, videoSurface) } // A direct load that neither finished nor failed is the one case a timeout // catches: the network manager neither errors nor answers. Timer { id: imageWatchdog interval: 8000 onTriggered: { if (root.showsImage && preview.status !== Image.Ready && !root.downloadedUrl) root.startDownload() } } // Fetches the full-size copy into the cache so the next pass draws from a // file. Delayed: a row flashing past during a fast scroll is gone by then. Timer { id: cacheWarm interval: 600 onTriggered: { if (root.showsImage && !root.downloadedUrl && !root.downloadAttempted) root.startDownload() } } Connections { target: matrixRooms function onAttachmentReady(chatId, eventId, localUrl) { if (chatId !== root.chatId || eventId !== root.eventId || !root.downloading) return root.downloadedUrl = String(localUrl) root.downloading = false cacheWarm.stop() if (root.openAfter === "viewer") root.imageActivated(root.sourceUrl) else if (root.openAfter === "desktop") root.fileActivated(root.sourceUrl) else if (root.openAfter === "music") root.musicActivated(root.chatId, root.sourceUrl, root.musicTitle) root.openAfter = "" } function onAttachmentFailed(chatId, eventId, error) { if (chatId !== root.chatId || eventId !== root.eventId) return root.downloading = false root.openAfter = "" root.downloadError = error // A failed attempt is not a spent one: a second ask is a person // saying the first did not work, and nothing here retries on its // own. root.downloadAttempted = false } } // "", "image", "video", "audio" or "file". Empty for a LAN attachment, // which says what it is with isImage instead. property string mediaKind: "" property string fileName: "" property bool isImage: false // what the sender said the picture measures, reserving the right shape // before it arrives; zero falls back to the decoder. property int mediaWidth: 0 property int mediaHeight: 0 property int mediaDurationMs: 0 property real maxImageWidth: Kirigami.Units.gridUnit * 18 readonly property bool isSticker: root.mediaKind === "sticker" // The widest the picture is ever decoded at, fixed rather than following property int decodeCapWidth: 0 // The ceiling a recording's tile may reach: a little more than a // photograph's, since the picture is the whole message here and the // transport adds no width. Still bounded by the row. property real videoMaxWidth: root.maxImageWidth signal imageActivated(string source) signal fileActivated(string source) // The page's one player is claimed by message id, with the local source, // the name the float reads, and the surface this tile draws into - which // belongs to the delegate and cannot outlive the row. signal videoClaimRequested(string msgId, string source, string name, Item surface) // Pause/play and the seek, said upward: the decoder is the page's, the // row only reports what its reader did with the controls. signal videoToggleRequested(string msgId) signal videoSeekRequested(int positionMs) // The transport's hand-off: the player page takes the local copy of the // recording when a fullscreen is asked for. signal videoActivated(string source) // What the row's media is doing, said upward so the page can keep the signal musicRowState(string msgId, bool onScreen) signal videoRowState(string msgId, bool onScreen) // The one recording the page's player holds, said by the page. Every row // that is not it draws its poster and keeps its hands off the player. property string videoClaimMsgId: "" // What the page's player is doing with that recording, for the transport // this row draws while it holds the claim. property bool videoPlaying: false property int videoPositionMs: 0 property int videoDurationMs: 0 // Whether the page's player is playing this row's recording. readonly property bool claimedHere: root.eventId.length > 0 && root.eventId === root.videoClaimMsgId // Whether this row is within the viewport, said by the delegate the list // attaches to. A row scrolled past keeps its controls alive through the // page's float. property bool rowOnScreen: true // The music row reports itself only while it is the track the player // holds - an idle row's position is nobody's business. function reportMusicState() { if (root.activeHere) root.musicRowState(root.eventId, root.rowOnScreen) } // The video row likewise, while it holds the decoder. function reportVideoState() { if (root.claimedHere) root.videoRowState(root.eventId, root.rowOnScreen) } onRowOnScreenChanged: { reportMusicState() reportVideoState() } onActiveHereChanged: reportMusicState() onClaimedHereChanged: { // A row handed the claim - fresh from the view or reused - offers the // player its surface again; the page keeps the position it had. if (root.claimedHere) { root.videoClaimRequested(root.eventId, root.playbackSource, root.fileName, videoSurface) root.reportVideoState() } } Component.onDestruction: { // A row that leaves the list without a farewell would leave the float // standing over a row that no longer exists. if (root.activeHere) root.musicRowState(root.eventId, false) // A claimed row that leaves the list hands its picture back to nothing: // the player keeps playing and the float takes the controls. if (root.claimedHere) root.videoRowState(root.eventId, false) } // The frame the video tile draws. A local copy is framed by the poster // service; a remote recording draws the server's own preview. Empty means // no frame yet, and the tile has a fallback. property string generatedPoster: "" property bool posterFailed: false readonly property string posterSource: { if (root.hasLocalCopy && root.generatedPoster.length > 0) return FsUtils.toSourceUrl(root.generatedPoster) // TDLib calls a video-note preview a "thumbnail", but the file is a // small MP4, not a still. Handing that to Image makes the decoder fail // on every recycled row; the black tile and play chip are the honest // fallback until a real frame is generated locally. const preview = root.thumbnailUrl.split("?")[0].toLowerCase() if (!root.hasLocalCopy && !root.posterFailed && root.thumbnailUrl.length > 0 && !/\.(mp4|webm|mkv|avi|mov|m4v|3gp)$/.test(preview)) return root.thumbnailUrl return "" } // Asks for a frame of the local copy and takes it when it lands; an answer // already on disk comes back instantly. function refreshPoster() { if (!root.showsVideo) return const localPath = root.filePath.length > 0 ? root.filePath : FsUtils.toLocalPath(root.downloadedUrl) if (localPath.length === 0) { root.generatedPoster = "" return } root.generatedPoster = videoPoster.posterFor(localPath) } Component.onCompleted: { refreshPoster() // A fresh row the player already holds offers its surface straight away; // the player keeps the position it had. if (root.claimedHere && root.playbackSource.length > 0) root.videoClaimRequested(root.eventId, root.playbackSource, root.fileName, videoSurface) } Connections { target: videoPoster function onPosterReady(videoPath, posterPath) { if (posterPath.length === 0) return const localPath = root.filePath.length > 0 ? root.filePath : FsUtils.toLocalPath(root.downloadedUrl) if (localPath.length > 0 && localPath === videoPath) root.generatedPoster = posterPath } } // What the image and the player are pointed at. A local copy wins over the // server's address, so a scroll does not fetch the same photograph again. readonly property string sourceUrl: root.filePath.length > 0 ? FsUtils.toSourceUrl(root.filePath) : (root.downloadedUrl.length > 0 ? root.downloadedUrl : root.mediaUrl) // The homeserver's scaled copy of this picture. Empty for an encrypted room, // whose files the server cannot read and therefore cannot scale. property string thumbnailUrl: "" // Set once the scaled copy has been refused, so the row asks for the full // address instead of the same missing thumbnail on every pass. property bool thumbnailFailed: false // What the timeline draws: the local copy, else the server's scaled copy, // else the full address. The small one is what keeps a scroll going through // photographs several times a row's width. readonly property string previewUrl: root.hasLocalCopy ? root.sourceUrl : (!root.thumbnailFailed && root.thumbnailUrl.length > 0 ? root.thumbnailUrl : root.sourceUrl) // What a player is pointed at, which is different: a decoder is given a readonly property string playbackSource: root.filePath.length > 0 ? FsUtils.toSourceUrl(root.filePath) : (root.downloadedUrl.length > 0 ? root.downloadedUrl : "") // Whether the row has a local copy to point anything at: a file that came // over the LAN, or one this session has fetched from the homeserver. readonly property bool hasLocalCopy: root.filePath.length > 0 || root.downloadedUrl.length > 0 || root.mediaUrl.indexOf("file:") === 0 readonly property bool showsImage: (root.mediaUrl.length > 0 || root.filePath.length > 0) && (root.isImage || root.mediaKind === "image" || root.mediaKind === "sticker") readonly property bool showsVideo: (root.mediaUrl.length > 0 || root.filePath.length > 0) && root.mediaKind === "video" readonly property bool showsAudio: (root.mediaUrl.length > 0 || root.filePath.length > 0) && root.mediaKind === "audio" // A geo: point: opened in a map rather than downloaded. It is not a // homeserver's shorthand, so it reaches sourceUrl as it stands. readonly property bool showsLocation: root.mediaUrl.length > 0 && root.mediaKind === "location" // an attachment event whose media this session cannot reach, said in words // rather than drawn as a broken frame. Asked of the event's own address, // not sourceUrl, which is empty throughout a download. readonly property bool unreachable: root.mediaUrl.length === 0 && root.filePath.length === 0 // mm:ss, and hh:mm:ss once there is an hour to show. function clockOf(ms) { if (!ms || ms <= 0) return "" const total = Math.round(ms / 1000) const s = total % 60 const m = Math.floor(total / 60) % 60 const h = Math.floor(total / 3600) const pad = (n) => (n < 10 ? "0" + n : "" + n) return h > 0 ? h + ":" + pad(m) + ":" + pad(s) : m + ":" + pad(s) } // The label a music row shows: the file name with the extension cut off, // or the address it came by, since a row with no word at all looks broken // rather than anonymous. readonly property string musicTitle: { const base = root.fileName.length > 0 ? root.fileName : (root.filePath.length > 0 ? root.filePath.section('/', -1) : "") const dot = base.lastIndexOf('.') return (dot > 0 ? base.substring(0, dot) : base).trim() || i18nc("@info an audio attachment with no name", "Audio") } // Whether the player is holding this row's track right now. Two strings, // not one: the same file can live in two conversations, and a play button // lighting up for both would promise something the player is not doing. readonly property bool activeHere: root.chatId === root.activeChatId && root.activeSource.length > 0 && root.sourceUrl === root.activeSource spacing: Kirigami.Units.smallSpacing Image { id: preview // the declared size wins over the decoded one: the decoded one is not readonly property real naturalWidth: root.mediaWidth > 0 ? root.mediaWidth : root.maxImageWidth readonly property real naturalHeight: root.mediaWidth > 0 && root.mediaHeight > 0 ? root.mediaHeight : root.maxImageWidth // Sized off the cap and not its own width: a height that reads back the // width the layout just gave it is the binding loop this is written around. readonly property real shownWidth: Math.min(root.maxImageWidth, preview.naturalWidth) Layout.preferredWidth: preview.shownWidth Layout.preferredHeight: Math.min( root.isSticker ? Kirigami.Units.gridUnit * 10 : Kirigami.Units.gridUnit * 20, Math.round(preview.shownWidth * (preview.naturalHeight / preview.naturalWidth))) // Tall pictures get cropped by the viewer rather than by pushing three // messages off the screen. Layout.maximumHeight: root.isSticker ? Kirigami.Units.gridUnit * 10 : Kirigami.Units.gridUnit * 20 visible: root.showsImage || root.isSticker source: (root.showsImage || root.isSticker) ? root.previewUrl : "" fillMode: Image.PreserveAspectFit // This is a scrolling thumbnail, not a transformed texture. Mipmap // generation allocates extra levels and makes delegate recycling more // expensive without improving this 1:1-ish preview. mipmap: false asynchronous: true // A room picture can be twelve megapixels, and decoding one at full // size for a thumbnail is the difference a stutter is made of. sourceSize.width: root.isSticker ? Math.round(Kirigami.Units.gridUnit * 10) : (root.decodeCapWidth > 0 ? root.decodeCapWidth : Math.round(root.maxImageWidth)) Component.onCompleted: root.loadImage() // A failed direct load is the only signal that this url needs the // download path: the image reports no error and no size when the // network manager cannot hand it out. onStatusChanged: { if (status !== Image.Error || root.downloadedUrl) return // A thumbnail the server does not have is not a broken attachment: // the picture is still at its own address, and retrying on every // pass would ask for ever. if (root.thumbnailUrl.length > 0 && !root.thumbnailFailed) { root.thumbnailFailed = true return } imageWatchdog.stop() root.startDownload() } // A failed first URL can leave Image.Error latched while TDLib has just // supplied the completed local file. The source is authoritative; the // error label below must not survive a successful local replacement. onSourceChanged: root.downloadError = "" Accessible.role: Accessible.Graphic Accessible.name: root.fileName QQC2.BusyIndicator { anchors.centerIn: parent // Spinning while the file is fetched, but only while there is // nothing to show: a drawn picture needs no spinner because the // full-size copy was asked for behind it. running: preview.status === Image.Loading || (root.showsImage && root.downloading && preview.status !== Image.Ready) visible: running } HoverHandler { cursorShape: Qt.PointingHandCursor } TapHandler { onTapped: root.openViewer() } } // A video's face: a frame from the file itself, so a recording is recognized Rectangle { id: videoTile // The tile's shape: the recording's own aspect, or a 16:9 guess, fitted // into the video ceiling and the row's height cap. Fitted, not just // capped, so a vertical recording fills its height. readonly property real videoAspect: root.mediaWidth > 0 && root.mediaHeight > 0 ? root.mediaWidth / root.mediaHeight : 16.0 / 9.0 readonly property real tileWidth: Math.min(root.videoMaxWidth, Kirigami.Units.gridUnit * 20 * videoAspect) readonly property real tileHeight: Math.round(tileWidth / videoAspect) Layout.preferredWidth: tileWidth Layout.preferredHeight: tileHeight visible: root.showsVideo radius: Kirigami.Units.cornerRadius clip: true // Black rather than the theme's background, like the player page's // cinema surface: a letterboxed frame on a light plate reads as a fault. color: "black" Image { id: poster anchors.fill: parent source: root.posterSource visible: !root.claimedHere && status === Image.Ready fillMode: Image.PreserveAspectCrop mipmap: false asynchronous: true // Never decode a full-resolution video frame for a small timeline // tile. Telegram videos can have 4K posters; decoding those for // every recycled delegate causes both stalls and large RSS spikes. sourceSize: Qt.size(Math.max(1, videoTile.tileWidth * 2), Math.max(1, videoTile.tileHeight * 2)) onStatusChanged: { if (status !== Image.Error || root.hasLocalCopy) return // The homeserver has no preview for this one; not retried on // every pass, so the tile falls back to its plate and chip. root.posterFailed = true } } // What the row's own decoder hands over once the recording started here. // It lives on the tile so the tile keeps its shape while the picture changes. VideoOutput { id: videoSurface anchors.fill: parent visible: root.claimedHere fillMode: VideoOutput.PreserveAspectFit } // The chip says this tile is a play button: a native round button, // drawn by the theme, hovering and pressing like every other button. // Its tap starts the recording the same as a tap on the tile. QQC2.RoundButton { anchors.centerIn: parent width: Kirigami.Units.gridUnit * 3 height: width visible: !root.claimedHere icon.name: "media-playback-start" icon.width: Kirigami.Units.iconSizes.smallMedium icon.height: Kirigami.Units.iconSizes.smallMedium HoverHandler { cursorShape: Qt.PointingHandCursor } onClicked: root.openVideo() Accessible.role: Accessible.Button Accessible.name: i18nc("@action:button play the attached recording", "Play") } QQC2.BusyIndicator { anchors.centerIn: parent running: root.downloading && root.claimedHere && root.playbackSource.length === 0 visible: running } // The length, said the way Telegram says it: a small chip over the // frame's corner, for the recordings whose events measured them. Rectangle { anchors.right: parent.right anchors.bottom: parent.bottom anchors.margins: Kirigami.Units.smallSpacing radius: height / 2 color: Qt.rgba(0, 0, 0, 0.55) visible: !root.claimedHere && root.mediaDurationMs > 0 implicitWidth: durationLabel.implicitWidth + Kirigami.Units.smallSpacing * 2 implicitHeight: durationLabel.implicitHeight QQC2.Label { id: durationLabel anchors.centerIn: parent text: root.clockOf(root.mediaDurationMs) color: "white" font: Kirigami.Theme.smallFont } } // The desktop still opens a recording: the small button the row's // other kinds carry, tucked into the tile's corner. QQC2.ToolButton { anchors.top: parent.top anchors.right: parent.right anchors.margins: Kirigami.Units.smallSpacing display: QQC2.AbstractButton.IconOnly icon.name: "document-open" visible: !root.claimedHere text: i18nc("@action:button open the attachment outside this window", "Open") QQC2.ToolTip.visible: hovered QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay QQC2.ToolTip.text: text onClicked: root.openExternally() } HoverHandler { cursorShape: Qt.PointingHandCursor } TapHandler { onTapped: { // The claimed row's tap is the transport's own pause and play; // an unclaimed tile asks the page's player for the recording. if (root.claimedHere) root.videoToggleRequested(root.eventId) else root.openVideo() } } Accessible.role: Accessible.Graphic Accessible.name: root.fileName } // The decoder exists only once a video is asked for. The tile above is the ColumnLayout { // The transport sits under the tile and takes the tile's width, never // more: one picture with its controls beneath it. Layout.preferredWidth: videoTile.width Layout.maximumWidth: videoTile.width visible: root.claimedHere spacing: Kirigami.Units.smallSpacing QQC2.Label { visible: root.downloadError.length > 0 text: root.downloadError wrapMode: Text.Wrap Layout.fillWidth: true } RowLayout { Layout.fillWidth: true 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 attached recording", "Pause") : i18nc("@action:button play the attached recording", "Play") QQC2.ToolTip.visible: hovered QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay QQC2.ToolTip.text: text onClicked: root.videoToggleRequested(root.eventId) } 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.videoDurationMs > 0 ? root.videoDurationMs : root.mediaDurationMs) // Following the position while the handle is held fights // whoever is holding it. value: pressed ? value : root.videoPositionMs onMoved: root.videoSeekRequested(value) } QQC2.Label { text: root.clockOf(root.videoDurationMs > 0 ? root.videoDurationMs : root.mediaDurationMs) textFormat: Text.PlainText font: Kirigami.Theme.smallFont color: AppPalette.disabledText } QQC2.ToolButton { display: QQC2.AbstractButton.IconOnly icon.name: "view-fullscreen" text: i18nc("@action:button hand the recording to the window's player page", "Open in player") QQC2.ToolTip.visible: hovered QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay QQC2.ToolTip.text: text // A recording still on the server has no file to hand over // yet; the download the tile started puts one there. enabled: root.playbackSource.length > 0 onClicked: root.videoActivated(root.playbackSource) } } } // The music row: a play button, the name, and the seek the global player // carries - Telegram's shape, so a voice note and an album track read alike. RowLayout { id: musicRow Layout.fillWidth: true Layout.maximumWidth: root.maxImageWidth visible: root.showsAudio spacing: Kirigami.Units.smallSpacing QQC2.ToolButton { display: QQC2.AbstractButton.IconOnly icon.name: root.activeHere && root.musicPlaying ? "media-playback-pause" : "media-playback-start" text: root.activeHere && root.musicPlaying ? i18nc("@action:button pause the track this row started", "Pause") : i18nc("@action:button play the attached audio in the window's player", "Play") QQC2.ToolTip.visible: hovered QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay QQC2.ToolTip.text: text enabled: !root.downloading onClicked: { if (!root.hasLocalCopy) { // a remote track is fetched first, like a picture: the // download hands the request back and the row plays the local copy. root.downloadError = "" root.openAfter = "music" root.startDownload() return } root.musicActivated(root.chatId, root.sourceUrl, root.musicTitle) } } ColumnLayout { Layout.fillWidth: true spacing: 0 QQC2.Label { Layout.fillWidth: true text: root.musicTitle textFormat: Text.PlainText elide: Text.ElideRight font.pointSize: Kirigami.Theme.defaultFont.pointSize * 0.95 } // Progress only while this row's track is the one playing: a bar // standing still on every other audio row is noise. QQC2.Slider { Layout.fillWidth: true visible: root.activeHere from: 0 to: Math.max(1, root.musicDurationMs > 0 ? root.musicDurationMs : 1) value: pressed ? value : root.musicPositionMs onMoved: root.musicSeek(value) } } QQC2.Label { visible: root.activeHere || root.mediaDurationMs > 0 text: root.clockOf(root.activeHere && root.musicDurationMs > 0 ? root.musicDurationMs : root.mediaDurationMs) textFormat: Text.PlainText font: Kirigami.Theme.smallFont color: AppPalette.disabledText } QQC2.ToolButton { display: QQC2.AbstractButton.IconOnly icon.name: "document-open" text: i18nc("@action:button open the attachment outside this window", "Open") QQC2.ToolTip.visible: hovered QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay QQC2.ToolTip.text: text onClicked: root.openExternally() } } QQC2.ItemDelegate { Layout.fillWidth: true visible: !root.showsImage && !root.showsVideo && !root.showsAudio && !root.showsLocation && !root.unreachable text: root.fileName icon.name: "document-open" onClicked: root.openExternally() } // A shared location: a row that opens the geo: uri in whatever maps handler // the platform has, rather than trying to draw a map inside the timeline. RowLayout { Layout.fillWidth: true visible: root.showsLocation spacing: Kirigami.Units.smallSpacing QQC2.Label { Layout.fillWidth: true text: root.fileName.length > 0 ? i18nc("@info shared location caption", "Location: %1", root.fileName) : i18nc("@info shared location with no caption", "Shared location") textFormat: Text.PlainText wrapMode: Text.WordWrap font: Kirigami.Theme.smallFont } QQC2.ToolButton { display: QQC2.AbstractButton.IconOnly icon.name: "map-symbolic" text: i18nc("@action:button open a shared location in a map", "Open in map") QQC2.ToolTip.visible: hovered QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay QQC2.ToolTip.text: text onClicked: Qt.openUrlExternally(root.sourceUrl) } } // An image whose url the network would not serve and would not download QQC2.Label { Layout.fillWidth: true // A Telegram file becomes a file:// mediaUrl when TDLib finishes the visible: (root.showsImage || root.isSticker) && !root.hasLocalCopy && root.downloadError.length > 0 text: i18nc("@info:status an attachment could not be fetched", "%1 could not be loaded.", root.fileName) textFormat: Text.PlainText wrapMode: Text.WordWrap color: AppPalette.negativeText } QQC2.Label { Layout.fillWidth: true visible: root.unreachable text: i18nc("@info:status %1 is the attachment's name", "%1 cannot be opened from here.", root.fileName) textFormat: Text.PlainText wrapMode: Text.WordWrap font: Kirigami.Theme.smallFont color: AppPalette.disabledText } }