Skip to content
Open
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: 2 additions & 1 deletion components/filedialog/FileDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ LazyLoader {

readonly property bool selectionValid: {
const file = folderContents.currentItem?.modelData;
return (file && !file.isDir && (filters.includes("*") || filters.includes(file.suffix))) ?? false;
const suffix = file?.suffix.toLowerCase();
return (file && !file.isDir && (filters.includes("*") || filters.some(f => f.toLowerCase() === suffix))) ?? false;
}

function accepted(path: string): void {
Expand Down
49 changes: 49 additions & 0 deletions components/images/ProfileImage.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
pragma ComponentBehavior: Bound

import QtQuick
import Caelestia

Item {
id: root

property string path
property string _format: CUtils.imageFormat(path)

readonly property int status: (loader.item as Image)?.status ?? Image.Null

function reload(): void {
_format = Qt.binding(() => CUtils.imageFormat(path));
loader.active = false;
loader.active = true;
}

Loader {
id: loader

anchors.fill: parent
sourceComponent: root._format === "gif" ? animatedComponent : cachingComponent
}

Component {
id: animatedComponent

AnimatedImage {
anchors.fill: parent
fillMode: AnimatedImage.PreserveAspectCrop
asynchronous: true
cache: false
playing: true
source: Qt.resolvedUrl(root.path)
}
}

Component {
id: cachingComponent

CachingImage {
anchors.fill: parent
cache: false
path: root.path
}
}
}
10 changes: 9 additions & 1 deletion modules/dashboard/dash/User.qml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Row {
visible: pfp.status !== Image.Ready
}

CachingImage {
ProfileImage {
id: pfp

anchors.fill: parent
Expand Down Expand Up @@ -100,6 +100,14 @@ Row {
}
}
}

Connections {
function onAccepted(): void {
Qt.callLater(pfp.reload);
}

target: root.facePicker
}
}

Column {
Expand Down
2 changes: 1 addition & 1 deletion modules/lock/Center.qml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ ColumnLayout {
visible: pfp.status !== Image.Ready
}

CachingImage {
ProfileImage {
id: pfp

anchors.fill: parent
Expand Down
14 changes: 14 additions & 0 deletions plugin/src/Caelestia/cutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <qdir.h>
#include <qfileinfo.h>
#include <qfuturewatcher.h>
#include <qimagereader.h>
#include <qloggingcategory.h>
#include <qqmlengine.h>

Expand Down Expand Up @@ -138,4 +139,17 @@ QString CUtils::toLocalFile(const QUrl& url) const {
return url.toLocalFile();
}

QString CUtils::imageFormat(const QUrl& url) const {
if (!url.isLocalFile()) {
qCWarning(lcCUtils) << "imageFormat: url" << url << "is not a local file";
return QString();
}

return imageFormat(url.toLocalFile());
}

QString CUtils::imageFormat(const QString& path) const {
return QString::fromLatin1(QImageReader::imageFormat(path));
}

} // namespace caelestia
2 changes: 2 additions & 0 deletions plugin/src/Caelestia/cutils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class CUtils : public QObject {
Q_INVOKABLE bool copyFile(const QUrl& source, const QUrl& target, bool overwrite = true) const;
Q_INVOKABLE bool deleteFile(const QUrl& path) const;
Q_INVOKABLE QString toLocalFile(const QUrl& url) const;
Q_INVOKABLE QString imageFormat(const QUrl& url) const;
Q_INVOKABLE QString imageFormat(const QString& path) const;
};

} // namespace caelestia
7 changes: 4 additions & 3 deletions utils/Images.qml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ pragma Singleton
import Quickshell

Singleton {
readonly property list<string> validImageTypes: ["jpeg", "png", "webp", "tiff", "svg"]
readonly property list<string> validImageExtensions: ["jpg", "jpeg", "png", "webp", "tif", "tiff", "svg"]
readonly property list<string> validImageTypes: ["jpeg", "png", "webp", "tiff", "svg", "gif"]
readonly property list<string> validImageExtensions: ["jpg", "jpeg", "png", "webp", "tif", "tiff", "svg", "gif"]

function isValidImageByName(name: string): bool {
return validImageExtensions.some(t => name.endsWith(`.${t}`));
const lowerName = name.toLowerCase();
return validImageExtensions.some(t => lowerName.endsWith(`.${t}`));
}
}