Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/files.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ double-click to open, right-click for the menu, `Ctrl`/`Shift`+click to mark.
| folder | its contents, with sizes and dates; the header adds the folder's total size |
| image | the image, with its pixel size |
| video | plays muted; `Space` pauses (`Shift+Space` types a space), `Alt+M` toggles sound, the fullsize button opens mpv |
| audio (mp3, flac, wav, ogg, oga, opus, m4a, aac) | its cover, title and artist over its waveform, which fills in as it plays; `Space` plays and pauses, a click on the waveform seeks |
| PDF | every page, drawn as it scrolls into view; `Shift+↑` `Shift+↓` scroll |
| 3D model (glb, gltf, obj, stl, ply, fbx) | turns with a drag or `Shift`+arrows, zooms with the wheel; needs the optional `qt6-quick3d` and `assimp`. Converted outside the shell: past 8 MB that takes a moment, which the preview says. Past 128 MB, or for a point cloud such as a Gaussian splat (points, no faces), there is no preview, and it says why |
| Markdown | rendered |
| other text | syntax highlighted, with line numbers |
| anything else | its size |
Expand Down
2 changes: 1 addition & 1 deletion docs/wheel.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ A row with a keybinding shows its keys last; on the selected row, keys that do n
|---|---|
| anything | everything above |
| `workspace` | every open window; `workspace 2` the ones on 2 |
| `/` | files and folders under home and any folders you add |
| `/` | files and folders under home and any folders you add; a pasted full path that exists, however deep |
| `=` | a calculation; `Enter` copies the answer |
| `help` | the manual; `Enter` shows it on one screen |
| `wheely settings` | the wheel's settings |
Expand Down
25 changes: 20 additions & 5 deletions plugins/xpo.files/Files.qml
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,20 @@ Item {
readonly property int lineHeight: Math.round(Style.font.subtitle * 1.75)

readonly property int previewLimit: 262144
// What an entry previews as: "image", "video" or "". A handler of settledSel asks it of the entry,
// since it runs before the bindings below and would see the last entry's answer.
// What an entry previews as: "image", "video", "audio", "pdf", "model" or "". A handler of settledSel
// asks it of the entry, since it runs before the bindings below and would see the last entry's answer.
function media(e) {
return !e || e.isDir || e.missing ? ""
: FilesIndex.isImage(e.name) ? "image" : FilesIndex.isVideo(e.name) ? "video" : ""
: FilesIndex.isImage(e.name) ? "image" : FilesIndex.isVideo(e.name) ? "video"
: FilesIndex.isAudio(e.name) ? "audio" : FilesIndex.isPdf(e.name) ? "pdf" : FilesIndex.isModel(e.name) ? "model" : ""
}
readonly property bool showsImage: root.media(root.settledSel) === "image"
readonly property bool showsVideo: root.media(root.settledSel) === "video"
readonly property bool showsAudio: root.media(root.settledSel) === "audio"
// balsam converts a model in its own process, but the shell still loads what it makes, in a time
// that grows with its size: past 128 MB, no preview.
readonly property bool showsModel: root.media(root.settledSel) === "model" && root.settledSel.size <= 134217728
readonly property bool showsPdf: root.media(root.settledSel) === "pdf"
property string imageDims: ""
FilesProcess {
id: measurer
Expand All @@ -148,7 +154,7 @@ Item {
readonly property bool showsMarkdown: !root.showsDiff && !!root.settledSel && !root.settledSel.isDir
&& !root.settledSel.missing && FilesIndex.isMarkdown(root.settledSel.name)
readonly property string previewPath:
(root.settledSel && !root.settledSel.isDir && !root.settledSel.missing && !root.showsImage && !root.showsVideo
(root.settledSel && !root.settledSel.isDir && !root.settledSel.missing && !root.media(root.settledSel)
&& root.settledSel.size <= root.previewLimit) ? root.settledSel.path : ""
// Keep the full file for safe editing. The preview lays out three screens of folder rows, over two of code,
// and twice as many whenever scrolling nears their end.
Expand Down Expand Up @@ -258,7 +264,7 @@ Item {
}
}
// Read whether shown or not, so the heading can count its lines. Only changed files have
// a diff; the rest, images and videos, keep their usual preview.
// a diff; the rest, and media of every kind, keep their usual preview.
function readDiff() {
differ.cancel()
var e = root.settledSel
Expand Down Expand Up @@ -346,8 +352,17 @@ Item {
: root.showsCode || root.previewBody || root.showsDiff ? ""
: root.settledSel.missing ? "Deleted · Ctrl+D shows changes"
: (root.showsVideo && preview.videoStatus !== Loader.Error) ? ""
: (root.showsAudio && preview.audioStatus !== Loader.Error) ? ""
// Past 8 MB, converting a model takes long enough to say so until it shows.
: (root.showsModel && !preview.modelFailed && !(preview.modelLoading && root.settledSel.size > 8388608)) ? ""
: (root.showsImage && preview.imageStatus !== Image.Error) ? ""
: (root.showsPdf && !preview.pdfFailed) ? ""
: FilesIndex.humanSize(root.settledSel.size) + " · no preview"
+ (root.media(root.settledSel) !== "model" ? ""
: !root.showsModel ? "\nOver 128 MB, too large to preview"
: preview.modelLoading ? "\nLarge model, it takes a moment to load"
: preview.modelNeeds ? "\nInstall " + preview.modelNeeds + " to preview 3D models"
: preview.modelPoints ? "\nA point cloud, not a mesh" : "")

// Payloads may choose a start; otherwise use the stable home directory.
// A popped-out window is raised instead, and keeps its place unless sent elsewhere.
Expand Down
94 changes: 94 additions & 0 deletions plugins/xpo.files/FilesAudio.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import QtQuick
import QtMultimedia
import qs.Commons
import qs.Commons as Commons
import "FilesIndex.js" as FilesIndex

// A song: its cover, title and artist over its waveform, which fills in as it plays. Space plays it;
// it never starts on its own, so stepping through a folder of music stays quiet.
Item {
id: root
property string path: ""
property string cover: ""
property string wave: ""

function toggle() { if (player.playing) player.pause(); else player.play() }

MediaPlayer {
id: player
source: root.path ? FilesIndex.fileUrl(root.path) : ""
audioOutput: AudioOutput { volume: 0.7 }
}
Component.onDestruction: player.stop()

// ffmpeg draws both as PNG data URLs: the embedded cover, if any, and the waveform in the accent.
FilesProcess { id: coverer; onFinished: output => root.cover = output ? "data:image/png;base64," + output : "" }
FilesProcess { id: waver; onFinished: output => root.wave = output ? "data:image/png;base64," + output : "" }
Component.onCompleted: {
coverer.start(["sh", "-c", 'ffmpeg -v error -i "$1" -an -frames:v 1 -c:v png -f image2pipe - | base64 -w0', "sh", root.path])
waver.start(["sh", "-c", 'ffmpeg -v error -i "$1" -filter_complex "aformat=channel_layouts=mono,showwavespic=s=1600x240:scale=sqrt:colors=$2"'
+ ' -frames:v 1 -c:v png -f image2pipe - | base64 -w0', "sh", root.path, String(Commons.Color.accent)])
}

Column {
anchors.centerIn: parent
width: parent.width * 0.8
spacing: Style.spacing.md

Image {
anchors.horizontalCenter: parent.horizontalCenter
visible: !!root.cover
source: root.cover
width: Math.min(parent.width, root.height * 0.45)
height: width
fillMode: Image.PreserveAspectCrop
}
Text {
width: parent.width
horizontalAlignment: Text.AlignHCenter
elide: Text.ElideRight
text: player.metaData.stringValue(MediaMetaData.Title) || root.path.slice(root.path.lastIndexOf("/") + 1)
color: Commons.Color.menu.text
font.family: Style.font.menuFamily
font.pixelSize: Style.font.subtitle
}
Text {
width: parent.width
horizontalAlignment: Text.AlignHCenter
elide: Text.ElideRight
text: player.error !== MediaPlayer.NoError ? "Cannot play this file"
: player.metaData.stringValue(MediaMetaData.ContributingArtist) || player.metaData.stringValue(MediaMetaData.AlbumArtist)
color: Commons.Color.menu.text
opacity: 0.6
font.family: Style.font.menuFamily
font.pixelSize: Style.font.bodySmall
}

// The waveform dim, and again in full up to where it plays; a click seeks there.
Item {
width: parent.width
height: Style.space(120)
Image { anchors.fill: parent; source: root.wave; opacity: 0.3 }
Item {
width: parent.width * player.position / Math.max(1, player.duration)
height: parent.height
clip: true
Image { width: parent.parent.width; height: parent.height; source: root.wave }
}
MouseArea {
anchors.fill: parent
enabled: player.seekable
cursorShape: Qt.PointingHandCursor
onClicked: mouse => player.position = mouse.x / width * player.duration
}
}
Text {
anchors.horizontalCenter: parent.horizontalCenter
text: (player.playing ? "󰏤 " : "󰐊 ") + FilesIndex.clock(player.position) + " / " + FilesIndex.clock(player.duration)
color: Commons.Color.menu.text
opacity: 0.6
font.family: Style.font.menuFamily
font.pixelSize: Style.font.caption
}
}
}
1 change: 1 addition & 0 deletions plugins/xpo.files/FilesHints.qml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Item {
? [["↑↓", "select"], ["enter", "open"], ["←", "up"], ["shift+↑↓", "scroll"]]
: [["↑↓", "scroll"], ["enter", "open"], ["←", "list"]])
.concat(panel && root.panel.showsVideo ? [["space", "play/pause"], ["alt+m", "mute"]] : [])
.concat(panel && root.panel.showsAudio ? [["space", "play/pause"]] : [])
readonly property var paste: !panel || !root.panel.held ? []
: ["ctrl+v", (root.panel.held.move ? "move " : "copy ") + root.panel.held.name + " here"]
// A window closes like any other, so only the overlay offers esc.
Expand Down
25 changes: 19 additions & 6 deletions plugins/xpo.files/FilesIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,24 @@ function humanSize(bytes) {
return (u === 0 ? n : n.toFixed(n < 10 ? 1 : 0)) + units[u]
}

// A player's position: m:ss, or h:mm:ss from the first hour.
function clock(ms) {
var s = Math.floor(ms / 1000), m = Math.floor(s / 60), h = Math.floor(m / 60)
return (h ? h + ":" + String(m % 60).padStart(2, "0") : String(m))
+ ":" + String(s % 60).padStart(2, "0")
}

// Only formats available through this Qt installation.
var IMAGE = { png: 1, jpg: 1, jpeg: 1, gif: 1, webp: 1, bmp: 1,
svg: 1, ico: 1, icns: 1, tif: 1, tiff: 1, tga: 1 }

var VIDEO = { mp4: 1, m4v: 1, mkv: 1, webm: 1, mov: 1, avi: 1, mpg: 1, mpeg: 1,
ogv: 1, wmv: 1, flv: 1, "3gp": 1, "3g2": 1, m2ts: 1, vob: 1 }

var AUDIO = { mp3: 1, flac: 1, wav: 1, ogg: 1, oga: 1, opus: 1, m4a: 1, aac: 1 }

var MODEL = { glb: 1, gltf: 1, obj: 1, stl: 1, ply: 1, fbx: 1 }

// StyledText lays code out an order of magnitude faster than rich text. Drop the
// last newline, break lines as drawnText() does, and keep other whitespace as written,
// through entities StyledText cannot collapse. highlight.py applies the same rules.
Expand Down Expand Up @@ -382,15 +393,17 @@ function isMarkdown(name) {
return /\.(md|markdown|mdown|mkd)$/.test(n)
}

function isImage(name) {
// Whether a name, with more than its extension, ends in one of the table's extensions.
function hasExt(name, table) {
var cut = String(name).lastIndexOf(".")
return cut > 0 && IMAGE[String(name).slice(cut + 1).toLowerCase()] === 1
return cut > 0 && table[String(name).slice(cut + 1).toLowerCase()] === 1
}

function isVideo(name) {
var cut = String(name).lastIndexOf(".")
return cut > 0 && VIDEO[String(name).slice(cut + 1).toLowerCase()] === 1
}
function isImage(name) { return hasExt(name, IMAGE) }
function isVideo(name) { return hasExt(name, VIDEO) }
function isAudio(name) { return hasExt(name, AUDIO) }
function isPdf(name) { return hasExt(name, { pdf: 1 }) }
function isModel(name) { return hasExt(name, MODEL) }

// Normalize text files to a trailing newline on save.
function endLine(t) {
Expand Down
4 changes: 2 additions & 2 deletions plugins/xpo.files/FilesKeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ function onKey(panel, ops, preview, event) {
if (menu && (event.key === Qt.Key_Menu || (event.key === Qt.Key_F10 && (event.modifiers & Qt.ShiftModifier)))) {
menu.openHere(); event.accepted = true; return
}
if (event.key === Qt.Key_Space && panel.showsVideo && !event.modifiers) {
if (!event.isAutoRepeat) preview.toggleVideo()
if (event.key === Qt.Key_Space && (panel.showsVideo || panel.showsAudio) && !event.modifiers) {
if (!event.isAutoRepeat) preview.togglePlay()
event.accepted = true
return
}
Expand Down
86 changes: 86 additions & 0 deletions plugins/xpo.files/FilesModel.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import QtQuick
import QtQuick3D
import QtQuick3D.Helpers
import "FilesIndex.js" as FilesIndex

// A 3D model, scaled to a fixed size about its centre, turned by dragging and zoomed by scrolling.
// An import blocks its process until done, so Qt's balsam converts the model in a process of its own
// as assimp reads its bounds, and the shell only loads balsam's meshes. Loaded on its own so a shell
// without Qt Quick 3D only loses this preview.
View3D {
id: root
property string path: ""
property bool loading: true
// Without assimp, Qt has no importer for any model.
property bool noImporter: false
// Points with no faces, as a Gaussian splat: nothing for Qt Quick 3D to draw.
property bool pointCloud: false
property string scene: ""
property vector3d low
property vector3d high
readonly property bool failed: !root.loading && (!root.scene || model.status === Loader3D.Error)

function turn(dx, dy) {
origin.eulerRotation = Qt.vector3d(origin.eulerRotation.x + dx, origin.eulerRotation.y + dy, 0)
}

// Each conversion clears the last one's files. Its children die with it, as when the preview moves on.
// balsam's complaint, if any, is read with the rest. The shell decodes textures as it shows them, a
// 2048 px one in tens of milliseconds, so past 1024 px, more than a preview needs, they shrink here.
FilesProcess {
id: converter
onFinished: (output, code) => {
var qml = output.match(/^.*\.qml$/m)
var lo = output.match(/^Minimum point\s+\((\S+) (\S+) (\S+)\)/m), hi = output.match(/^Maximum point\s+\((\S+) (\S+) (\S+)\)/m)
root.noImporter = code === 127
root.pointCloud = output.indexOf("No meshes remaining") >= 0
if (!code && qml && lo && hi) {
root.low = Qt.vector3d(+lo[1], +lo[2], +lo[3])
root.high = Qt.vector3d(+hi[1], +hi[2], +hi[3])
root.scene = FilesIndex.fileUrl(qml[0])
}
root.loading = false
}
}
Component.onCompleted: converter.start(["sh", "-c", 'command -v assimp >/dev/null || exit 127; '
+ 'm=${XDG_CACHE_HOME:-$HOME/.cache}/wheely/models; rm -rf "$m" && mkdir -p "$m" && d=$(mktemp -d -p "$m") || exit 1; '
+ 'setpriv --pdeathsig TERM assimp info "$1" > "$d/info" & '
+ 'setpriv --pdeathsig TERM /usr/lib/qt6/bin/balsam -o "$d" "$1" 2>&1 >/dev/null || exit 1; '
+ '[ ! -d "$d/maps" ] || setpriv --pdeathsig TERM magick mogrify -resize "1024x1024>" -define png:compression-level=1 "$d"/maps/* 2>/dev/null; '
+ 'wait $! && ls "$d"/*.qml && cat "$d/info"',
"files", root.path])

environment: SceneEnvironment {
backgroundMode: SceneEnvironment.Color
clearColor: "black"
antialiasingMode: SceneEnvironment.MSAA
}

// Seen from a little above and to the side, close enough that the model fills most of the pane.
Node {
id: origin
eulerRotation: Qt.vector3d(-20, 30, 0)
PerspectiveCamera {
id: camera
z: 170
DirectionalLight { ambientColor: Qt.rgba(0.35, 0.35, 0.35, 1) }
}
}

// Made over several frames, so a scene of many parts doesn't hold up the shell either.
Loader3D {
id: model
source: root.scene
asynchronous: true
readonly property vector3d size: root.high.minus(root.low)
readonly property real fit: 100 / Math.max(size.x, size.y, size.z, 1e-6)
scale: Qt.vector3d(fit, fit, fit)
position: root.high.plus(root.low).times(-fit / 2)
}

OrbitCameraController {
anchors.fill: parent
origin: origin
camera: camera
}
}
49 changes: 49 additions & 0 deletions plugins/xpo.files/FilesPdf.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import QtQuick
import qs.Commons

// A PDF's pages in a column, each drawn by pdftoppm only once it scrolls near the view.
// Every page takes the first page's shape; a page of another shape is fitted inside it.
ListView {
id: root
property string path: ""
property int pages: 0
property real aspect: 1.414
property bool failed: false

clip: true
spacing: Style.spacing.md
boundsBehavior: Flickable.StopAtBounds
model: root.pages

function scrollBy(dy) {
root.contentY = Math.max(root.originY, Math.min(root.contentY + dy,
root.originY + root.contentHeight - root.height))
}

FilesProcess {
id: info
onFinished: output => {
var pages = output.match(/^Pages:\s+(\d+)/m), size = output.match(/^Page size:\s+([\d.]+) x ([\d.]+)/m)
if (size) root.aspect = size[2] / size[1]
root.pages = pages ? +pages[1] : 0
root.failed = !root.pages
}
}
Component.onCompleted: info.start(["pdfinfo", root.path])

delegate: Image {
id: page
required property int index
width: ListView.view.width
height: width * root.aspect
fillMode: Image.PreserveAspectFit
asynchronous: true
FilesProcess {
id: render
onFinished: output => page.source = output ? "data:image/png;base64," + output : ""
}
Component.onCompleted: render.start(["sh", "-c",
'pdftoppm -png -singlefile -f "$3" -l "$3" -scale-to-x "$2" -scale-to-y -1 "$1" | base64 -w0', "sh",
root.path, String(Math.ceil(width * Screen.devicePixelRatio)), String(index + 1)])
}
}
Loading