internal: refactor Paths util
This commit is contained in:
parent
7b35c23bd0
commit
1de24676bb
15 changed files with 39 additions and 36 deletions
|
|
@ -97,7 +97,7 @@ Item {
|
||||||
model: FileSystemModel {
|
model: FileSystemModel {
|
||||||
path: {
|
path: {
|
||||||
if (root.dialog.cwd[0] === "Home")
|
if (root.dialog.cwd[0] === "Home")
|
||||||
return `${Paths.strip(Paths.home)}/${root.dialog.cwd.slice(1).join("/")}`;
|
return `${Paths.home}/${root.dialog.cwd.slice(1).join("/")}`;
|
||||||
else
|
else
|
||||||
return root.dialog.cwd.join("/");
|
return root.dialog.cwd.join("/");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ Item {
|
||||||
id: cachingImage
|
id: cachingImage
|
||||||
|
|
||||||
CachingImage {
|
CachingImage {
|
||||||
path: Paths.strip(root.source)
|
path: Paths.toLocalFile(root.source)
|
||||||
fillMode: Image.PreserveAspectFit
|
fillMode: Image.PreserveAspectFit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,6 @@ Image {
|
||||||
id: manager
|
id: manager
|
||||||
|
|
||||||
item: root
|
item: root
|
||||||
cacheDir: Paths.imagecache
|
cacheDir: Qt.resolvedUrl(Paths.imagecache)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ Singleton {
|
||||||
property alias paths: adapter.paths
|
property alias paths: adapter.paths
|
||||||
|
|
||||||
FileView {
|
FileView {
|
||||||
path: `${Paths.stringify(Paths.config)}/shell.json`
|
path: `${Paths.config}/shell.json`
|
||||||
watchChanges: true
|
watchChanges: true
|
||||||
onFileChanged: reload()
|
onFileChanged: reload()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import qs.utils
|
||||||
import Quickshell.Io
|
import Quickshell.Io
|
||||||
|
|
||||||
JsonObject {
|
JsonObject {
|
||||||
property string wallpaperDir: Paths.strip(`${Paths.pictures}/Wallpapers`)
|
property string wallpaperDir: `${Paths.pictures}/Wallpapers`
|
||||||
property string sessionGif: "root:/assets/kurukuru.gif"
|
property string sessionGif: "root:/assets/kurukuru.gif"
|
||||||
property string mediaGif: "root:/assets/bongocat.gif"
|
property string mediaGif: "root:/assets/bongocat.gif"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -526,7 +526,7 @@ Item {
|
||||||
|
|
||||||
playing: Players.active?.isPlaying ?? false
|
playing: Players.active?.isPlaying ?? false
|
||||||
speed: BeatDetector.bpm / 300
|
speed: BeatDetector.bpm / 300
|
||||||
source: Paths.expandTilde(Config.paths.mediaGif)
|
source: Paths.absolutePath(Config.paths.mediaGif)
|
||||||
asynchronous: true
|
asynchronous: true
|
||||||
fillMode: AnimatedImage.PreserveAspectFit
|
fillMode: AnimatedImage.PreserveAspectFit
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -209,7 +209,7 @@ Item {
|
||||||
|
|
||||||
playing: Players.active?.isPlaying ?? false
|
playing: Players.active?.isPlaying ?? false
|
||||||
speed: BeatDetector.bpm / 300
|
speed: BeatDetector.bpm / 300
|
||||||
source: Paths.expandTilde(Config.paths.mediaGif)
|
source: Paths.absolutePath(Config.paths.mediaGif)
|
||||||
asynchronous: true
|
asynchronous: true
|
||||||
fillMode: AnimatedImage.PreserveAspectFit
|
fillMode: AnimatedImage.PreserveAspectFit
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ Row {
|
||||||
id: pfp
|
id: pfp
|
||||||
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
path: `${Paths.stringify(Paths.home)}/.face`
|
path: `${Paths.home}/.face`
|
||||||
}
|
}
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ ColumnLayout {
|
||||||
id: pfp
|
id: pfp
|
||||||
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
path: `${Paths.stringify(Paths.home)}/.face`
|
path: `${Paths.home}/.face`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ Column {
|
||||||
playing: visible
|
playing: visible
|
||||||
asynchronous: true
|
asynchronous: true
|
||||||
speed: 0.7
|
speed: 0.7
|
||||||
source: Paths.expandTilde(Config.paths.sessionGif)
|
source: Paths.absolutePath(Config.paths.sessionGif)
|
||||||
}
|
}
|
||||||
|
|
||||||
SessionButton {
|
SessionButton {
|
||||||
|
|
|
||||||
|
|
@ -337,3 +337,12 @@ qreal CUtils::findAverageLuminance(const QImage& image, int rescaleSize) const {
|
||||||
|
|
||||||
return count == 0 ? 0.0 : totalLuminance / count;
|
return count == 0 ? 0.0 : totalLuminance / count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString CUtils::toLocalFile(const QUrl& url) const {
|
||||||
|
if (!url.isLocalFile()) {
|
||||||
|
qWarning() << "CUtils::toLocalFile: given url is not a local file" << url;
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return url.toLocalFile();
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,8 @@ public:
|
||||||
Q_INVOKABLE void getAverageLuminance(const QString& path, QJSValue callback);
|
Q_INVOKABLE void getAverageLuminance(const QString& path, QJSValue callback);
|
||||||
Q_INVOKABLE void getAverageLuminance(const QString& path, int rescaleSize, QJSValue callback);
|
Q_INVOKABLE void getAverageLuminance(const QString& path, int rescaleSize, QJSValue callback);
|
||||||
|
|
||||||
|
Q_INVOKABLE QString toLocalFile(const QUrl& url) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QColor findDominantColour(const QImage& image, int rescaleSize) const;
|
QColor findDominantColour(const QImage& image, int rescaleSize) const;
|
||||||
qreal findAverageLuminance(const QImage& image, int rescaleSize) const;
|
qreal findAverageLuminance(const QImage& image, int rescaleSize) const;
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ Singleton {
|
||||||
}
|
}
|
||||||
|
|
||||||
FileView {
|
FileView {
|
||||||
path: `${Paths.stringify(Paths.state)}/scheme.json`
|
path: `${Paths.state}/scheme.json`
|
||||||
watchChanges: true
|
watchChanges: true
|
||||||
onFileChanged: reload()
|
onFileChanged: reload()
|
||||||
onLoaded: root.load(text(), false)
|
onLoaded: root.load(text(), false)
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import QtQuick
|
||||||
Searcher {
|
Searcher {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
readonly property string currentNamePath: Paths.strip(`${Paths.state}/wallpaper/path.txt`)
|
readonly property string currentNamePath: `${Paths.state}/wallpaper/path.txt`
|
||||||
readonly property list<string> smartArg: Config.services.smartScheme ? [] : ["--no-smart"]
|
readonly property list<string> smartArg: Config.services.smartScheme ? [] : ["--no-smart"]
|
||||||
|
|
||||||
property bool showPreview: false
|
property bool showPreview: false
|
||||||
|
|
@ -74,7 +74,7 @@ Searcher {
|
||||||
id: wallpapers
|
id: wallpapers
|
||||||
|
|
||||||
recursive: true
|
recursive: true
|
||||||
path: Paths.expandTilde(Paths.wallsdir)
|
path: Paths.wallsdir
|
||||||
filter: FileSystemModel.Images
|
filter: FileSystemModel.Images
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,42 +1,34 @@
|
||||||
pragma Singleton
|
pragma Singleton
|
||||||
|
|
||||||
import qs.config
|
import qs.config
|
||||||
|
import Caelestia
|
||||||
import Quickshell
|
import Quickshell
|
||||||
import Qt.labs.platform
|
|
||||||
|
|
||||||
Singleton {
|
Singleton {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
readonly property url home: StandardPaths.standardLocations(StandardPaths.HomeLocation)[0]
|
readonly property string home: Quickshell.env("HOME")
|
||||||
readonly property url pictures: StandardPaths.standardLocations(StandardPaths.PicturesLocation)[0]
|
readonly property string pictures: Quickshell.env("XDG_PICTURES_DIR") || `${home}/Pictures`
|
||||||
|
|
||||||
readonly property url data: `${StandardPaths.standardLocations(StandardPaths.GenericDataLocation)[0]}/caelestia`
|
readonly property string data: `${Quickshell.env("XDG_DATA_HOME") || `${home}/.local/share`}/caelestia`
|
||||||
readonly property url state: `${StandardPaths.standardLocations(StandardPaths.GenericStateLocation)[0]}/caelestia`
|
readonly property string state: `${Quickshell.env("XDG_STATE_HOME") || `${home}/.local/state`}/caelestia`
|
||||||
readonly property url cache: `${StandardPaths.standardLocations(StandardPaths.GenericCacheLocation)[0]}/caelestia`
|
readonly property string cache: `${Quickshell.env("XDG_CACHE_HOME") || `${home}/.cache`}/caelestia`
|
||||||
readonly property url config: `${StandardPaths.standardLocations(StandardPaths.GenericConfigLocation)[0]}/caelestia`
|
readonly property string config: `${Quickshell.env("XDG_CONFIG_HOME") || `${home}/.config`}/caelestia`
|
||||||
|
|
||||||
readonly property url imagecache: `${cache}/imagecache`
|
readonly property string imagecache: `${cache}/imagecache`
|
||||||
readonly property string wallsdir: Quickshell.env("CAELESTIA_WALLPAPERS_DIR") || Config.paths.wallpaperDir
|
readonly property string wallsdir: Quickshell.env("CAELESTIA_WALLPAPERS_DIR") || absolutePath(Config.paths.wallpaperDir)
|
||||||
readonly property string libdir: Quickshell.env("CAELESTIA_LIB_DIR") || "/usr/lib/caelestia"
|
readonly property string libdir: Quickshell.env("CAELESTIA_LIB_DIR") || "/usr/lib/caelestia"
|
||||||
|
|
||||||
function stringify(path: url): string {
|
function toLocalFile(path: url): string {
|
||||||
let str = path.toString();
|
path = Qt.resolvedUrl(path);
|
||||||
if (str.startsWith("root:/"))
|
return path.toString() ? CUtils.toLocalFile(path) : "";
|
||||||
str = `file://${Quickshell.shellDir}/${str.slice(6)}`;
|
|
||||||
else if (str.startsWith("/"))
|
|
||||||
str = `file://${str}`;
|
|
||||||
return new URL(str).pathname;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function expandTilde(path: string): string {
|
function absolutePath(path: string): string {
|
||||||
return strip(path.replace("~", stringify(root.home)));
|
return toLocalFile(path.replace("~", home));
|
||||||
}
|
}
|
||||||
|
|
||||||
function shortenHome(path: string): string {
|
function shortenHome(path: string): string {
|
||||||
return path.replace(strip(root.home), "~");
|
return path.replace(home, "~");
|
||||||
}
|
|
||||||
|
|
||||||
function strip(path: url): string {
|
|
||||||
return stringify(path).replace("file://", "");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue