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