diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-07-20 12:10:16 +1000 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-07-20 12:10:16 +1000 |
| commit | 0f0471fa6085d988a0a16bae9ced6b3a4e44b57d (patch) | |
| tree | 1f35c54c32af69ab22a1feb0097f8e9e2cf5f873 /widgets/filedialog/FolderContents.qml | |
| parent | filedialog: navigation (diff) | |
| download | caelestia-shell-0f0471fa6085d988a0a16bae9ced6b3a4e44b57d.tar.gz caelestia-shell-0f0471fa6085d988a0a16bae9ced6b3a4e44b57d.tar.bz2 caelestia-shell-0f0471fa6085d988a0a16bae9ced6b3a4e44b57d.zip | |
filedialog: better mime detection
Required file
Also show folders first
Diffstat (limited to 'widgets/filedialog/FolderContents.qml')
| -rw-r--r-- | widgets/filedialog/FolderContents.qml | 36 |
1 files changed, 14 insertions, 22 deletions
diff --git a/widgets/filedialog/FolderContents.qml b/widgets/filedialog/FolderContents.qml index f8e10d9..c6129df 100644 --- a/widgets/filedialog/FolderContents.qml +++ b/widgets/filedialog/FolderContents.qml @@ -15,13 +15,13 @@ GridView { required property var dialog - property var mimes: ({}) - clip: true focus: true + currentIndex: -1 Keys.onEscapePressed: root.currentIndex = -1 model: FolderListModel { + showDirsFirst: true folder: { let url = "file://"; if (root.dialog.cwd[0] === "Home") @@ -77,18 +77,22 @@ GridView { asynchronous: true implicitSize: Sizes.itemWidth - Appearance.padding.normal * 2 - source: { - const mime = root.mimes[item.fileSuffix]; - - if (mime?.startsWith("image-")) - return item.fileUrl; - - return Quickshell.iconPath(item.fileIsDir ? "inode-directory" : root.mimes[item.fileSuffix] ?? "application-x-zerosize", "image-missing"); - } + source: Quickshell.iconPath(item.fileIsDir ? "inode-directory" : "application-x-zerosize") onStatusChanged: { if (status === Image.Error) source = Quickshell.iconPath("error"); } + + Process { + running: !item.fileIsDir + command: ["file", "--mime", "-b", item.filePath] + stdout: StdioCollector { + onStreamFinished: { + const mime = text.split(";")[0].replace("/", "-"); + icon.source = mime.startsWith("image-") ? item.fileUrl : Quickshell.iconPath(mime, "image-missing"); + } + } + } } StyledText { @@ -115,16 +119,4 @@ GridView { } } } - - FileView { - path: "/etc/mime.types" - onLoaded: { - root.mimes = text().split("\n").filter(l => !l.startsWith("#")).reduce((mimes, line) => { - const [type, ext] = line.split(/\s+/); - if (ext) - mimes[ext] = type.replace("/", "-"); - return mimes; - }, {}); - } - } } |