diff options
author | David Faure <david.faure@kdab.com> | 2015-01-06 11:44:22 +0100 |
---|---|---|
committer | David Faure <david.faure@kdab.com> | 2015-01-09 12:15:59 +0100 |
commit | 4c980aedc17c1da8f7160989fbb845ea72b36f44 (patch) | |
tree | 31ad4926d76d3a92585cd473a2ea5e01bc1e6f82 /src/corelib | |
parent | 3b9629e8bdbf23bb793c88f967b2cfe2b8256278 (diff) |
QStandardPaths: add AppConfigLocation.
ConfigLocation was erroneously inconsistent, by adding the org name
and app name on Windows (unintentionally) and not on Unix (while having
subdirs in ~/.config is actually common practice for some XDG desktops)
Therefore this adds AppConfigLocation, which always has the org name
and app name (while GenericConfigLocation never does).
[ChangeLog][QtCore][QStandardPaths] Added QStandardPaths::AppConfigLocation,
for application-specific configuration directory. ConfigLocation was inconsistent.
Task-number: QTBUG-38872
Task-number: QTBUG-38845
Change-Id: I80fb98f296436261f3996c9df87571c29b06ab35
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/io/qstandardpaths.cpp | 16 | ||||
-rw-r--r-- | src/corelib/io/qstandardpaths.h | 1 | ||||
-rw-r--r-- | src/corelib/io/qstandardpaths_android.cpp | 1 | ||||
-rw-r--r-- | src/corelib/io/qstandardpaths_blackberry.cpp | 1 | ||||
-rw-r--r-- | src/corelib/io/qstandardpaths_ios.mm | 1 | ||||
-rw-r--r-- | src/corelib/io/qstandardpaths_mac.mm | 10 | ||||
-rw-r--r-- | src/corelib/io/qstandardpaths_unix.cpp | 31 | ||||
-rw-r--r-- | src/corelib/io/qstandardpaths_win.cpp | 2 | ||||
-rw-r--r-- | src/corelib/io/qstandardpaths_winrt.cpp | 1 |
9 files changed, 52 insertions, 12 deletions
diff --git a/src/corelib/io/qstandardpaths.cpp b/src/corelib/io/qstandardpaths.cpp index b41aee55d2..2e16c6d1ae 100644 --- a/src/corelib/io/qstandardpaths.cpp +++ b/src/corelib/io/qstandardpaths.cpp @@ -142,6 +142,10 @@ QT_BEGIN_NAMESPACE \value AppLocalDataLocation Returns the local settings path on the Windows operating system. On all other platforms, it returns the same value as AppDataLocation. This enum value was added in Qt 5.4. + \value AppConfigLocation Returns a directory location where user-specific + configuration files should be written. This is an application-specific directory, + and the returned path is never empty. + This enum value was added in Qt 5.5. The following table gives examples of paths on different operating systems. The first path is the writable path (unless noted). Other, additional @@ -206,6 +210,9 @@ QT_BEGIN_NAMESPACE \row \li AppLocalDataLocation \li "~/Library/Application Support/<APPNAME>", "/Library/Application Support/<APPNAME>". "<APPDIR>/../Resources" \li "C:/Users/<USER>/AppData/Local/<APPNAME>", "C:/ProgramData/<APPNAME>", "<APPDIR>", "<APPDIR>/data" + \row \li AppConfigLocation + \li "~/Library/Preferences/<APPNAME>" + \li "C:/Users/<USER>/AppData/Local/<APPNAME>", "C:/ProgramData/<APPNAME>" \endtable \table @@ -267,6 +274,9 @@ QT_BEGIN_NAMESPACE \row \li AppLocalDataLocation \li "<APPROOT>/data", "<APPROOT>/app/native/assets" \li "~/.local/share/<APPNAME>", "/usr/local/share/<APPNAME>", "/usr/share/<APPNAME>" + \row \li AppConfigLocation + \li "<APPROOT>/data/Settings" + \li "~/.config/<APPNAME>", "/etc/xdg/<APPNAME>" \endtable \table @@ -307,6 +317,8 @@ QT_BEGIN_NAMESPACE \li "<APPROOT>/cache" (there is no shared cache) \row \li AppDataLocation \li "<APPROOT>/files", "<USER>/<APPNAME>/files" + \row \li AppConfigLocation + \li "<APPROOT>/files/settings" \endtable In the table above, \c <APPNAME> is usually the organization name, the @@ -565,6 +577,8 @@ QString QStandardPaths::displayName(StandardLocation type) case AppDataLocation: case AppLocalDataLocation: return QCoreApplication::translate("QStandardPaths", "Application Data"); + case AppConfigLocation: + return QCoreApplication::translate("QStandardPaths", "Application Configuration"); } // not reached return QString(); @@ -585,7 +599,7 @@ QString QStandardPaths::displayName(StandardLocation type) This affects the locations into which test programs might write files: GenericDataLocation, DataLocation, ConfigLocation, GenericConfigLocation, - GenericCacheLocation, CacheLocation. + AppConfigLocation, GenericCacheLocation, CacheLocation. Other locations are not affected. On Unix, \c XDG_DATA_HOME is set to \e ~/.qttest/share, \c XDG_CONFIG_HOME is diff --git a/src/corelib/io/qstandardpaths.h b/src/corelib/io/qstandardpaths.h index e305450240..60e53fe117 100644 --- a/src/corelib/io/qstandardpaths.h +++ b/src/corelib/io/qstandardpaths.h @@ -64,6 +64,7 @@ public: GenericCacheLocation, GenericConfigLocation, AppDataLocation, + AppConfigLocation, AppLocalDataLocation = DataLocation }; diff --git a/src/corelib/io/qstandardpaths_android.cpp b/src/corelib/io/qstandardpaths_android.cpp index 958b4ea486..b887e107e7 100644 --- a/src/corelib/io/qstandardpaths_android.cpp +++ b/src/corelib/io/qstandardpaths_android.cpp @@ -233,6 +233,7 @@ QString QStandardPaths::writableLocation(StandardLocation type) return getExternalStoragePublicDirectory("DIRECTORY_DOWNLOADS"); case QStandardPaths::GenericConfigLocation: case QStandardPaths::ConfigLocation: + case QStandardPaths::AppConfigLocation: return getFilesDir() + testDir() + QLatin1String("/settings"); case QStandardPaths::GenericDataLocation: return getExternalStorageDirectory() + testDir(); diff --git a/src/corelib/io/qstandardpaths_blackberry.cpp b/src/corelib/io/qstandardpaths_blackberry.cpp index 02d7c110ae..473da7542c 100644 --- a/src/corelib/io/qstandardpaths_blackberry.cpp +++ b/src/corelib/io/qstandardpaths_blackberry.cpp @@ -69,6 +69,7 @@ QString QStandardPaths::writableLocation(StandardLocation type) return QDir::homePath() + testModeInsert() + QLatin1String("/Cache"); case ConfigLocation: case GenericConfigLocation: + case AppConfigLocation: return QDir::homePath() + testModeInsert() + QLatin1String("/Settings"); case GenericDataLocation: return sharedRoot + testModeInsert() + QLatin1String("/misc"); diff --git a/src/corelib/io/qstandardpaths_ios.mm b/src/corelib/io/qstandardpaths_ios.mm index 9b500f4623..449c66fe0c 100644 --- a/src/corelib/io/qstandardpaths_ios.mm +++ b/src/corelib/io/qstandardpaths_ios.mm @@ -103,6 +103,7 @@ QString QStandardPaths::writableLocation(StandardLocation type) break; case ConfigLocation: case GenericConfigLocation: + case AppConfigLocation: location = pathForDirectory(NSDocumentDirectory); break; case DownloadLocation: diff --git a/src/corelib/io/qstandardpaths_mac.mm b/src/corelib/io/qstandardpaths_mac.mm index 01d1c01f78..4cd71d7d52 100644 --- a/src/corelib/io/qstandardpaths_mac.mm +++ b/src/corelib/io/qstandardpaths_mac.mm @@ -53,6 +53,7 @@ OSType translateLocation(QStandardPaths::StandardLocation type) switch (type) { case QStandardPaths::ConfigLocation: case QStandardPaths::GenericConfigLocation: + case QStandardPaths::AppConfigLocation: return kPreferencesFolderType; case QStandardPaths::DesktopLocation: return kDesktopFolderType; @@ -129,7 +130,8 @@ static QString macLocation(QStandardPaths::StandardLocation type, short domain) QString path = getFullPath(ref); - if (type == QStandardPaths::AppDataLocation || type == QStandardPaths::AppLocalDataLocation || type == QStandardPaths::CacheLocation) + if (type == QStandardPaths::AppDataLocation || type == QStandardPaths::AppLocalDataLocation || + type == QStandardPaths::CacheLocation || type == QStandardPaths::AppConfigLocation) appendOrganizationAndApp(path); return path; } @@ -155,7 +157,11 @@ QString QStandardPaths::writableLocation(StandardLocation type) return path; case GenericConfigLocation: case ConfigLocation: - return qttestDir + QLatin1String("/Preferences"); + case AppConfigLocation: + path = qttestDir + QLatin1String("/Preferences"); + if (type == AppConfigLocation) + appendOrganizationAndApp(path); + return path; default: break; } diff --git a/src/corelib/io/qstandardpaths_unix.cpp b/src/corelib/io/qstandardpaths_unix.cpp index 2ad6dfa121..94dcbaff9a 100644 --- a/src/corelib/io/qstandardpaths_unix.cpp +++ b/src/corelib/io/qstandardpaths_unix.cpp @@ -97,6 +97,7 @@ QString QStandardPaths::writableLocation(StandardLocation type) } case ConfigLocation: case GenericConfigLocation: + case AppConfigLocation: { // http://standards.freedesktop.org/basedir-spec/latest/ QString xdgConfigHome = QFile::decodeName(qgetenv("XDG_CONFIG_HOME")); @@ -104,6 +105,8 @@ QString QStandardPaths::writableLocation(StandardLocation type) xdgConfigHome = QDir::homePath() + QLatin1String("/.qttest/config"); if (xdgConfigHome.isEmpty()) xdgConfigHome = QDir::homePath() + QLatin1String("/.config"); + if (type == AppConfigLocation) + appendOrganizationAndApp(xdgConfigHome); return xdgConfigHome; } case RuntimeLocation: @@ -278,21 +281,31 @@ static QStringList xdgDataDirs() return dirs; } +static QStringList xdgConfigDirs() +{ + QStringList dirs; + // http://standards.freedesktop.org/basedir-spec/latest/ + const QString xdgConfigDirs = QFile::decodeName(qgetenv("XDG_CONFIG_DIRS")); + if (xdgConfigDirs.isEmpty()) + dirs.append(QString::fromLatin1("/etc/xdg")); + else + dirs = xdgConfigDirs.split(QLatin1Char(':')); + return dirs; +} + QStringList QStandardPaths::standardLocations(StandardLocation type) { QStringList dirs; switch (type) { case ConfigLocation: case GenericConfigLocation: - { - // http://standards.freedesktop.org/basedir-spec/latest/ - const QString xdgConfigDirs = QFile::decodeName(qgetenv("XDG_CONFIG_DIRS")); - if (xdgConfigDirs.isEmpty()) - dirs.append(QString::fromLatin1("/etc/xdg")); - else - dirs = xdgConfigDirs.split(QLatin1Char(':')); - } - break; + dirs = xdgConfigDirs(); + break; + case AppConfigLocation: + dirs = xdgConfigDirs(); + for (int i = 0; i < dirs.count(); ++i) + appendOrganizationAndApp(dirs[i]); + break; case GenericDataLocation: dirs = xdgDataDirs(); break; diff --git a/src/corelib/io/qstandardpaths_win.cpp b/src/corelib/io/qstandardpaths_win.cpp index 5e56db3797..8fe4be0d5c 100644 --- a/src/corelib/io/qstandardpaths_win.cpp +++ b/src/corelib/io/qstandardpaths_win.cpp @@ -98,6 +98,7 @@ QString QStandardPaths::writableLocation(StandardLocation type) switch (type) { case ConfigLocation: // same as AppLocalDataLocation, on Windows case GenericConfigLocation: // same as GenericDataLocation on Windows + case AppConfigLocation: case AppDataLocation: case AppLocalDataLocation: case GenericDataLocation: @@ -195,6 +196,7 @@ QStringList QStandardPaths::standardLocations(StandardLocation type) switch (type) { case ConfigLocation: // same as AppLocalDataLocation, on Windows (oversight, but too late to fix it) case GenericConfigLocation: // same as GenericDataLocation, on Windows + case AppConfigLocation: // same as AppLocalDataLocation, that one on purpose case AppDataLocation: case AppLocalDataLocation: case GenericDataLocation: diff --git a/src/corelib/io/qstandardpaths_winrt.cpp b/src/corelib/io/qstandardpaths_winrt.cpp index 5c09b4814d..6aa31bf296 100644 --- a/src/corelib/io/qstandardpaths_winrt.cpp +++ b/src/corelib/io/qstandardpaths_winrt.cpp @@ -67,6 +67,7 @@ QString QStandardPaths::writableLocation(StandardLocation type) switch (type) { case ConfigLocation: // same as AppLocalDataLocation, on Windows case GenericConfigLocation: // same as GenericDataLocation, on Windows + case AppConfigLocation: case AppDataLocation: case AppLocalDataLocation: case GenericDataLocation: { |