forked from quickshell/quickshell
		
	core/qmlglobal: add dataPath(), statePath() and cachePath()
This commit is contained in:
		
							parent
							
								
									c1c24c2998
								
							
						
					
					
						commit
						a05c0de53b
					
				
					 3 changed files with 30 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -11,6 +11,7 @@
 | 
			
		|||
#include <qloggingcategory.h>
 | 
			
		||||
#include <qstandardpaths.h>
 | 
			
		||||
#include <qtenvironmentvariables.h>
 | 
			
		||||
#include <qtversionchecks.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
 | 
			
		||||
#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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue