summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qstandardpaths_unix.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/io/qstandardpaths_unix.cpp')
-rw-r--r--src/corelib/io/qstandardpaths_unix.cpp82
1 files changed, 42 insertions, 40 deletions
diff --git a/src/corelib/io/qstandardpaths_unix.cpp b/src/corelib/io/qstandardpaths_unix.cpp
index 6acec9c034..2750feda5d 100644
--- a/src/corelib/io/qstandardpaths_unix.cpp
+++ b/src/corelib/io/qstandardpaths_unix.cpp
@@ -58,15 +58,17 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
static void appendOrganizationAndApp(QString &path)
{
#ifndef QT_BOOTSTRAPPED
const QString org = QCoreApplication::organizationName();
if (!org.isEmpty())
- path += QLatin1Char('/') + org;
+ path += u'/' + org;
const QString appName = QCoreApplication::applicationName();
if (!appName.isEmpty())
- path += QLatin1Char('/') + appName;
+ path += u'/' + appName;
#else
Q_UNUSED(path);
#endif
@@ -77,23 +79,23 @@ static QLatin1String xdg_key_name(QStandardPaths::StandardLocation type)
{
switch (type) {
case QStandardPaths::DesktopLocation:
- return QLatin1String("DESKTOP");
+ return "DESKTOP"_L1;
case QStandardPaths::DocumentsLocation:
- return QLatin1String("DOCUMENTS");
+ return "DOCUMENTS"_L1;
case QStandardPaths::PicturesLocation:
- return QLatin1String("PICTURES");
+ return "PICTURES"_L1;
case QStandardPaths::MusicLocation:
- return QLatin1String("MUSIC");
+ return "MUSIC"_L1;
case QStandardPaths::MoviesLocation:
- return QLatin1String("VIDEOS");
+ return "VIDEOS"_L1;
case QStandardPaths::DownloadLocation:
- return QLatin1String("DOWNLOAD");
+ return "DOWNLOAD"_L1;
case QStandardPaths::PublicShareLocation:
- return QLatin1String("PUBLICSHARE");
+ return "PUBLICSHARE"_L1;
case QStandardPaths::TemplatesLocation:
- return QLatin1String("TEMPLATES");
+ return "TEMPLATES"_L1;
default:
- return QLatin1String();
+ return {};
}
}
#endif
@@ -217,9 +219,9 @@ QString QStandardPaths::writableLocation(StandardLocation type)
// http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html
QString xdgCacheHome = QFile::decodeName(qgetenv("XDG_CACHE_HOME"));
if (isTestModeEnabled())
- xdgCacheHome = QDir::homePath() + QLatin1String("/.qttest/cache");
+ xdgCacheHome = QDir::homePath() + "/.qttest/cache"_L1;
if (xdgCacheHome.isEmpty())
- xdgCacheHome = QDir::homePath() + QLatin1String("/.cache");
+ xdgCacheHome = QDir::homePath() + "/.cache"_L1;
if (type == QStandardPaths::CacheLocation)
appendOrganizationAndApp(xdgCacheHome);
return xdgCacheHome;
@@ -230,9 +232,9 @@ QString QStandardPaths::writableLocation(StandardLocation type)
{
QString xdgDataHome = QFile::decodeName(qgetenv("XDG_DATA_HOME"));
if (isTestModeEnabled())
- xdgDataHome = QDir::homePath() + QLatin1String("/.qttest/share");
+ xdgDataHome = QDir::homePath() + "/.qttest/share"_L1;
if (xdgDataHome.isEmpty())
- xdgDataHome = QDir::homePath() + QLatin1String("/.local/share");
+ xdgDataHome = QDir::homePath() + "/.local/share"_L1;
if (type == AppDataLocation || type == AppLocalDataLocation)
appendOrganizationAndApp(xdgDataHome);
return xdgDataHome;
@@ -244,9 +246,9 @@ QString QStandardPaths::writableLocation(StandardLocation type)
// http://standards.freedesktop.org/basedir-spec/latest/
QString xdgConfigHome = QFile::decodeName(qgetenv("XDG_CONFIG_HOME"));
if (isTestModeEnabled())
- xdgConfigHome = QDir::homePath() + QLatin1String("/.qttest/config");
+ xdgConfigHome = QDir::homePath() + "/.qttest/config"_L1;
if (xdgConfigHome.isEmpty())
- xdgConfigHome = QDir::homePath() + QLatin1String("/.config");
+ xdgConfigHome = QDir::homePath() + "/.config"_L1;
if (type == AppConfigLocation)
appendOrganizationAndApp(xdgConfigHome);
return xdgConfigHome;
@@ -259,7 +261,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
// environment variable not set or is set to something unsuitable
const uint myUid = uint(geteuid());
const QString userName = QFileSystemEngine::resolveUserName(myUid);
- xdgRuntimeDir = QDir::tempPath() + QLatin1String("/runtime-") + userName;
+ xdgRuntimeDir = QDir::tempPath() + "/runtime-"_L1 + userName;
if (!fromEnv) {
#ifndef Q_OS_WASM
@@ -281,13 +283,13 @@ QString QStandardPaths::writableLocation(StandardLocation type)
// http://www.freedesktop.org/wiki/Software/xdg-user-dirs
QString xdgConfigHome = QFile::decodeName(qgetenv("XDG_CONFIG_HOME"));
if (xdgConfigHome.isEmpty())
- xdgConfigHome = QDir::homePath() + QLatin1String("/.config");
- QFile file(xdgConfigHome + QLatin1String("/user-dirs.dirs"));
+ xdgConfigHome = QDir::homePath() + "/.config"_L1;
+ QFile file(xdgConfigHome + "/user-dirs.dirs"_L1);
const QLatin1String key = xdg_key_name(type);
if (!key.isEmpty() && !isTestModeEnabled() && file.open(QIODevice::ReadOnly)) {
QTextStream stream(&file);
// Only look for lines like: XDG_DESKTOP_DIR="$HOME/Desktop"
- QRegularExpression exp(QLatin1String("^XDG_(.*)_DIR=(.*)$"));
+ QRegularExpression exp("^XDG_(.*)_DIR=(.*)$"_L1);
QString result;
while (!stream.atEnd()) {
const QString &line = stream.readLine();
@@ -295,15 +297,15 @@ QString QStandardPaths::writableLocation(StandardLocation type)
if (match.hasMatch() && match.capturedView(1) == key) {
QStringView value = match.capturedView(2);
if (value.length() > 2
- && value.startsWith(QLatin1Char('\"'))
- && value.endsWith(QLatin1Char('\"')))
+ && value.startsWith(u'\"')
+ && value.endsWith(u'\"'))
value = value.mid(1, value.length() - 2);
// value can start with $HOME
- if (value.startsWith(QLatin1String("$HOME")))
+ if (value.startsWith("$HOME"_L1))
result = QDir::homePath() + value.mid(5);
else
result = value.toString();
- if (result.length() > 1 && result.endsWith(QLatin1Char('/')))
+ if (result.length() > 1 && result.endsWith(u'/'))
result.chop(1);
}
}
@@ -315,39 +317,39 @@ QString QStandardPaths::writableLocation(StandardLocation type)
QString path;
switch (type) {
case DesktopLocation:
- path = QDir::homePath() + QLatin1String("/Desktop");
+ path = QDir::homePath() + "/Desktop"_L1;
break;
case DocumentsLocation:
- path = QDir::homePath() + QLatin1String("/Documents");
+ path = QDir::homePath() + "/Documents"_L1;
break;
case PicturesLocation:
- path = QDir::homePath() + QLatin1String("/Pictures");
+ path = QDir::homePath() + "/Pictures"_L1;
break;
case FontsLocation:
- path = writableLocation(GenericDataLocation) + QLatin1String("/fonts");
+ path = writableLocation(GenericDataLocation) + "/fonts"_L1;
break;
case MusicLocation:
- path = QDir::homePath() + QLatin1String("/Music");
+ path = QDir::homePath() + "/Music"_L1;
break;
case MoviesLocation:
- path = QDir::homePath() + QLatin1String("/Videos");
+ path = QDir::homePath() + "/Videos"_L1;
break;
case DownloadLocation:
- path = QDir::homePath() + QLatin1String("/Downloads");
+ path = QDir::homePath() + "/Downloads"_L1;
break;
case ApplicationsLocation:
- path = writableLocation(GenericDataLocation) + QLatin1String("/applications");
+ path = writableLocation(GenericDataLocation) + "/applications"_L1;
break;
case PublicShareLocation:
- path = QDir::homePath() + QLatin1String("/Public");
+ path = QDir::homePath() + "/Public"_L1;
break;
case TemplatesLocation:
- path = QDir::homePath() + QLatin1String("/Templates");
+ path = QDir::homePath() + "/Templates"_L1;
break;
default:
@@ -368,7 +370,7 @@ static QStringList xdgDataDirs()
} else {
// Normalize paths, skip relative paths
for (const auto dir : qTokenize(xdgDataDirsEnv, u':')) {
- if (dir.startsWith(QLatin1Char('/')))
+ if (dir.startsWith(u'/'))
dirs.push_back(QDir::cleanPath(dir.toString()));
}
@@ -391,7 +393,7 @@ static QStringList xdgConfigDirs()
if (xdgConfigDirs.isEmpty())
dirs.append(QString::fromLatin1("/etc/xdg"));
else
- dirs = xdgConfigDirs.split(QLatin1Char(':'));
+ dirs = xdgConfigDirs.split(u':');
return dirs;
}
@@ -414,7 +416,7 @@ QStringList QStandardPaths::standardLocations(StandardLocation type)
case ApplicationsLocation:
dirs = xdgDataDirs();
for (int i = 0; i < dirs.count(); ++i)
- dirs[i].append(QLatin1String("/applications"));
+ dirs[i].append("/applications"_L1);
break;
case AppDataLocation:
case AppLocalDataLocation:
@@ -423,10 +425,10 @@ QStringList QStandardPaths::standardLocations(StandardLocation type)
appendOrganizationAndApp(dirs[i]);
break;
case FontsLocation:
- dirs += QDir::homePath() + QLatin1String("/.fonts");
+ dirs += QDir::homePath() + "/.fonts"_L1;
dirs += xdgDataDirs();
for (int i = 1; i < dirs.count(); ++i)
- dirs[i].append(QLatin1String("/fonts"));
+ dirs[i].append("/fonts"_L1);
break;
default:
break;