mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-25 11:22:58 +00:00
optimize QStandardPaths getters
Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
parent
5b7672d90e
commit
cf5aec3cbc
1 changed files with 19 additions and 22 deletions
|
@ -78,7 +78,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
|
||||||
case CacheLocation:
|
case CacheLocation:
|
||||||
case GenericCacheLocation: {
|
case GenericCacheLocation: {
|
||||||
// http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html
|
// http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html
|
||||||
QString xdgCacheHome = QFile::decodeName(qgetenv("XDG_CACHE_HOME"));
|
static QString xdgCacheHome = QFile::decodeName(qgetenv("XDG_CACHE_HOME"));
|
||||||
if (xdgCacheHome.isEmpty()) {
|
if (xdgCacheHome.isEmpty()) {
|
||||||
xdgCacheHome = QDir::homePath() + QLatin1String("/.cache");
|
xdgCacheHome = QDir::homePath() + QLatin1String("/.cache");
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
|
||||||
}
|
}
|
||||||
case DataLocation:
|
case DataLocation:
|
||||||
case GenericDataLocation: {
|
case GenericDataLocation: {
|
||||||
QString xdgDataHome = QFile::decodeName(qgetenv("XDG_DATA_HOME"));
|
static QString xdgDataHome = QFile::decodeName(qgetenv("XDG_DATA_HOME"));
|
||||||
if (xdgDataHome.isEmpty()) {
|
if (xdgDataHome.isEmpty()) {
|
||||||
xdgDataHome = QDir::homePath() + QLatin1String("/.local/share");
|
xdgDataHome = QDir::homePath() + QLatin1String("/.local/share");
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
|
||||||
case ConfigLocation:
|
case ConfigLocation:
|
||||||
case GenericConfigLocation: {
|
case GenericConfigLocation: {
|
||||||
// http://standards.freedesktop.org/basedir-spec/latest/
|
// http://standards.freedesktop.org/basedir-spec/latest/
|
||||||
QString xdgConfigHome = QFile::decodeName(qgetenv("XDG_CONFIG_HOME"));
|
static QString xdgConfigHome = QFile::decodeName(qgetenv("XDG_CONFIG_HOME"));
|
||||||
if (xdgConfigHome.isEmpty()) {
|
if (xdgConfigHome.isEmpty()) {
|
||||||
xdgConfigHome = QDir::homePath() + QLatin1String("/.config");
|
xdgConfigHome = QDir::homePath() + QLatin1String("/.config");
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
|
||||||
case RuntimeLocation: {
|
case RuntimeLocation: {
|
||||||
const uid_t myUid = geteuid();
|
const uid_t myUid = geteuid();
|
||||||
// http://standards.freedesktop.org/basedir-spec/latest/
|
// http://standards.freedesktop.org/basedir-spec/latest/
|
||||||
QString xdgRuntimeDir = QFile::decodeName(qgetenv("XDG_RUNTIME_DIR"));
|
static QString xdgRuntimeDir = QFile::decodeName(qgetenv("XDG_RUNTIME_DIR"));
|
||||||
if (xdgRuntimeDir.isEmpty()) {
|
if (xdgRuntimeDir.isEmpty()) {
|
||||||
const QString userName = QFileSystemEngine::resolveUserName(myUid);
|
const QString userName = QFileSystemEngine::resolveUserName(myUid);
|
||||||
xdgRuntimeDir = QDir::tempPath() + QLatin1String("/runtime-") + userName;
|
xdgRuntimeDir = QDir::tempPath() + QLatin1String("/runtime-") + userName;
|
||||||
|
@ -143,7 +143,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://www.freedesktop.org/wiki/Software/xdg-user-dirs
|
// http://www.freedesktop.org/wiki/Software/xdg-user-dirs
|
||||||
QString xdgConfigHome = QFile::decodeName(qgetenv("XDG_CONFIG_HOME"));
|
static QString xdgConfigHome = QFile::decodeName(qgetenv("XDG_CONFIG_HOME"));
|
||||||
if (xdgConfigHome.isEmpty()) {
|
if (xdgConfigHome.isEmpty()) {
|
||||||
xdgConfigHome = QDir::homePath() + QLatin1String("/.config");
|
xdgConfigHome = QDir::homePath() + QLatin1String("/.config");
|
||||||
}
|
}
|
||||||
|
@ -169,44 +169,41 @@ QString QStandardPaths::writableLocation(StandardLocation type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString key;
|
QString value;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case DesktopLocation: {
|
case DesktopLocation: {
|
||||||
key = QLatin1String("DESKTOP");
|
value = lines.value(QLatin1String("DESKTOP"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DocumentsLocation: {
|
case DocumentsLocation: {
|
||||||
key = QLatin1String("DOCUMENTS");
|
value = lines.value(QLatin1String("DOCUMENTS"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PicturesLocation: {
|
case PicturesLocation: {
|
||||||
key = QLatin1String("PICTURES");
|
value = lines.value(QLatin1String("PICTURES"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MusicLocation: {
|
case MusicLocation: {
|
||||||
key = QLatin1String("MUSIC");
|
value = lines.value(QLatin1String("MUSIC"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MoviesLocation: {
|
case MoviesLocation: {
|
||||||
key = QLatin1String("VIDEOS");
|
value = lines.value(QLatin1String("VIDEOS"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DownloadLocation: {
|
case DownloadLocation: {
|
||||||
key = QLatin1String("DOWNLOAD");
|
value = lines.value(QLatin1String("DOWNLOAD"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!key.isEmpty()) {
|
if (!value.isEmpty()) {
|
||||||
QString value = lines.value(key);
|
// value can start with $HOME
|
||||||
if (!value.isEmpty()) {
|
if (value.startsWith(QLatin1String("$HOME"))) {
|
||||||
// value can start with $HOME
|
value = QDir::homePath() + value.mid(5);
|
||||||
if (value.startsWith(QLatin1String("$HOME"))) {
|
|
||||||
value = QDir::homePath() + value.mid(5);
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,7 +213,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
|
||||||
static QStringList xdgDataDirs()
|
static QStringList xdgDataDirs()
|
||||||
{
|
{
|
||||||
// http://standards.freedesktop.org/basedir-spec/latest/
|
// http://standards.freedesktop.org/basedir-spec/latest/
|
||||||
QString xdgDataDirsEnv = QFile::decodeName(qgetenv("XDG_DATA_DIRS"));
|
static const QString xdgDataDirsEnv = QFile::decodeName(qgetenv("XDG_DATA_DIRS"));
|
||||||
if (xdgDataDirsEnv.isEmpty()) {
|
if (xdgDataDirsEnv.isEmpty()) {
|
||||||
QStringList dirs;
|
QStringList dirs;
|
||||||
dirs.append(QString::fromLatin1("/usr/local/share"));
|
dirs.append(QString::fromLatin1("/usr/local/share"));
|
||||||
|
@ -233,7 +230,7 @@ QStringList QStandardPaths::standardLocations(StandardLocation type)
|
||||||
case ConfigLocation:
|
case ConfigLocation:
|
||||||
case GenericConfigLocation: {
|
case GenericConfigLocation: {
|
||||||
// http://standards.freedesktop.org/basedir-spec/latest/
|
// http://standards.freedesktop.org/basedir-spec/latest/
|
||||||
const QString xdgConfigDirs = QFile::decodeName(qgetenv("XDG_CONFIG_DIRS"));
|
static const QString xdgConfigDirs = QFile::decodeName(qgetenv("XDG_CONFIG_DIRS"));
|
||||||
if (xdgConfigDirs.isEmpty()) {
|
if (xdgConfigDirs.isEmpty()) {
|
||||||
dirs.append(QString::fromLatin1("/etc/xdg"));
|
dirs.append(QString::fromLatin1("/etc/xdg"));
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue