Skip to content

Commit b61fc91

Browse files
committed
core/qmlglobal: add dataPath(), statePath() and cachePath()
1 parent 6f3275b commit b61fc91

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

src/core/paths.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <qloggingcategory.h>
1212
#include <qstandardpaths.h>
1313
#include <qtenvironmentvariables.h>
14+
#include <qtversionchecks.h>
1415
#include <unistd.h>
1516

1617
#include "instanceinfo.hpp"
@@ -232,7 +233,18 @@ QDir QsPaths::shellDataDir() {
232233

233234
QDir QsPaths::shellStateDir() {
234235
if (this->shellStateState == DirState::Unknown) {
236+
#if QT_VERSION < QT_VERSION_CHECK(6, 7, 0)
237+
QDir dir;
238+
if (qEnvironmentVariableIsSet("XDG_STATE_HOME")) {
239+
dir = QDir(qEnvironmentVariable("XDG_STATE_HOME"));
240+
} else {
241+
auto home = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
242+
dir = QDir(home.filePath(".local/state"));
243+
}
244+
#else
235245
auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::StateLocation));
246+
#endif
247+
236248
dir = QDir(dir.filePath("by-shell"));
237249
dir = QDir(dir.filePath(this->shellId));
238250
this->mShellStateDir = dir;

src/core/qmlglobal.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,18 @@ QString QuickshellGlobal::cacheDir() const { // NOLINT
202202
return QsPaths::instance()->shellCacheDir().path();
203203
}
204204

205+
QString QuickshellGlobal::dataPath(const QString& path) const {
206+
return this->dataDir() % '/' % path;
207+
}
208+
209+
QString QuickshellGlobal::statePath(const QString& path) const {
210+
return this->stateDir() % '/' % path;
211+
}
212+
213+
QString QuickshellGlobal::cachePath(const QString& path) const {
214+
return this->cacheDir() % '/' % path;
215+
}
216+
205217
QVariant QuickshellGlobal::env(const QString& variable) { // NOLINT
206218
auto vstr = variable.toStdString();
207219
if (!qEnvironmentVariableIsSet(vstr.data())) return QVariant::fromValue(nullptr);

src/core/qmlglobal.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ class QuickshellGlobal: public QObject {
155155
/// Setting the `fallback` parameter of `iconPath` will attempt to load the fallback
156156
/// icon if the requested one could not be loaded.
157157
Q_INVOKABLE static QString iconPath(const QString& icon, const QString& fallback);
158+
/// Equivalent to `${Quickshell.dataDir}/${path}`
159+
Q_INVOKABLE [[nodiscard]] QString dataPath(const QString& path) const;
160+
/// Equivalent to `${Quickshell.stateDir}/${path}`
161+
Q_INVOKABLE [[nodiscard]] QString statePath(const QString& path) const;
162+
/// Equivalent to `${Quickshell.cacheDir}/${path}`
163+
Q_INVOKABLE [[nodiscard]] QString cachePath(const QString& path) const;
158164

159165
[[nodiscard]] QString shellRoot() const;
160166

0 commit comments

Comments
 (0)