From a05c0de53bec5ea59ce0b53b56c64d8b251aba16 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Fri, 16 May 2025 20:33:40 -0700 Subject: [PATCH] core/qmlglobal: add dataPath(), statePath() and cachePath() --- src/core/paths.cpp | 12 ++++++++++++ src/core/qmlglobal.cpp | 12 ++++++++++++ src/core/qmlglobal.hpp | 6 ++++++ 3 files changed, 30 insertions(+) diff --git a/src/core/paths.cpp b/src/core/paths.cpp index 037052d3..57cd0f4d 100644 --- a/src/core/paths.cpp +++ b/src/core/paths.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include "instanceinfo.hpp" @@ -232,7 +233,18 @@ QDir QsPaths::shellDataDir() { QDir QsPaths::shellStateDir() { if (this->shellStateState == DirState::Unknown) { +#if QT_VERSION < QT_VERSION_CHECK(6, 7, 0) + QDir dir; + if (qEnvironmentVariableIsSet("XDG_STATE_HOME")) { + dir = QDir(qEnvironmentVariable("XDG_STATE_HOME")); + } else { + auto home = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); + dir = QDir(home.filePath(".local/state")); + } +#else auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::StateLocation)); +#endif + dir = QDir(dir.filePath("by-shell")); dir = QDir(dir.filePath(this->shellId)); this->mShellStateDir = dir; diff --git a/src/core/qmlglobal.cpp b/src/core/qmlglobal.cpp index c0a14197..7903bf41 100644 --- a/src/core/qmlglobal.cpp +++ b/src/core/qmlglobal.cpp @@ -202,6 +202,18 @@ QString QuickshellGlobal::cacheDir() const { // NOLINT return QsPaths::instance()->shellCacheDir().path(); } +QString QuickshellGlobal::dataPath(const QString& path) const { + return this->dataDir() % '/' % path; +} + +QString QuickshellGlobal::statePath(const QString& path) const { + return this->stateDir() % '/' % path; +} + +QString QuickshellGlobal::cachePath(const QString& path) const { + return this->cacheDir() % '/' % path; +} + QVariant QuickshellGlobal::env(const QString& variable) { // NOLINT auto vstr = variable.toStdString(); if (!qEnvironmentVariableIsSet(vstr.data())) return QVariant::fromValue(nullptr); diff --git a/src/core/qmlglobal.hpp b/src/core/qmlglobal.hpp index 4c87bc82..5ccec3b2 100644 --- a/src/core/qmlglobal.hpp +++ b/src/core/qmlglobal.hpp @@ -155,6 +155,12 @@ public: /// Setting the `fallback` parameter of `iconPath` will attempt to load the fallback /// icon if the requested one could not be loaded. Q_INVOKABLE static QString iconPath(const QString& icon, const QString& fallback); + /// Equivalent to `${Quickshell.dataDir}/${path}` + Q_INVOKABLE [[nodiscard]] QString dataPath(const QString& path) const; + /// Equivalent to `${Quickshell.stateDir}/${path}` + Q_INVOKABLE [[nodiscard]] QString statePath(const QString& path) const; + /// Equivalent to `${Quickshell.cacheDir}/${path}` + Q_INVOKABLE [[nodiscard]] QString cachePath(const QString& path) const; [[nodiscard]] QString shellRoot() const;