From 68c4669ce49aad21beff0e8ef0122a86d53b12e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Feber?= Date: Thu, 22 Jul 2021 22:29:01 +0200 Subject: [PATCH] Add PublicShare and Templates QStandardPaths These directories are common on desktop operating systems. "Public" is used for sharing files with other users and "Templates" lets you add new files to the file creation desktop menu (for example in a file manager). An example use in a Qt application would be KDE's KIO having default icons for both directories. This is where they point to: Windows: C:/Users/Public, C:/Users//AppData/Roaming/Microsoft/Windows/Templates macOS: ~/Public, ~/Templates Unix: ~/Public, ~/Templates Task-number: QTBUG-86106 Task-number: QTBUG-78092 Change-Id: Ifca60c7d2a6dc2109ec290e8fb109ee2d5ca4d38 Reviewed-by: Thiago Macieira --- src/corelib/io/qstandardpaths.cpp | 28 +++++++++++++++++++++++ src/corelib/io/qstandardpaths.h | 4 +++- src/corelib/io/qstandardpaths_android.cpp | 2 ++ src/corelib/io/qstandardpaths_haiku.cpp | 4 ++++ src/corelib/io/qstandardpaths_mac.mm | 9 ++++++++ src/corelib/io/qstandardpaths_unix.cpp | 12 ++++++++++ src/corelib/io/qstandardpaths_win.cpp | 6 ++++- 7 files changed, 63 insertions(+), 2 deletions(-) diff --git a/src/corelib/io/qstandardpaths.cpp b/src/corelib/io/qstandardpaths.cpp index b76eafcb894..e07cea451b2 100644 --- a/src/corelib/io/qstandardpaths.cpp +++ b/src/corelib/io/qstandardpaths.cpp @@ -153,6 +153,14 @@ QT_BEGIN_NAMESPACE 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. + \value PublicShareLocation Returns a directory location where user-specific publicly shared files + and directories can be stored. This is a generic value. Note that the returned path may be + empty if the system has no concept of a publicly shared location. + This enum value was added in Qt 6.3. + \value TemplatesLocation Returns a directory location where user-specific + template files can be stored. This is a generic value. Note that the returned path may be + empty if the system has no concept of a templates location. + This enum value was added in Qt 6.3. The following table gives examples of paths on different operating systems. The first path is the writable path (unless noted). Other, additional @@ -217,6 +225,12 @@ QT_BEGIN_NAMESPACE \row \li AppConfigLocation \li "~/Library/Preferences/" \li "C:/Users//AppData/Local/", "C:/ProgramData/" + \row \li PublicShareLocation + \li "~/Public" + \li "C:/Users/Public" + \row \li TemplatesLocation + \li "~/Templates" + \li "C:/Users//AppData/Roaming/Microsoft/Windows/Templates" \endtable \table @@ -259,6 +273,10 @@ QT_BEGIN_NAMESPACE \li "~/.local/share/", "/usr/local/share/", "/usr/share/" \row \li AppConfigLocation \li "~/.config/", "/etc/xdg/" + \row \li PublicShareLocation + \li "~/Public" + \row \li TemplatesLocation + \li "~/Templates" \endtable \table @@ -320,6 +338,12 @@ QT_BEGIN_NAMESPACE \row \li AppConfigLocation \li "/files/settings" \li "/Library/Preferences/" + \row \li PublicShareLocation + \li not supported + \li not supported + \row \li TemplatesLocation + \li not supported + \li not supported \endtable In the table above, \c is usually the organization name, the @@ -572,6 +596,10 @@ QString QStandardPaths::displayName(StandardLocation type) case AppDataLocation: case AppConfigLocation: return QCoreApplication::translate("QStandardPaths", "Application Configuration"); + case PublicShareLocation: + return QCoreApplication::translate("QStandardPaths", "Public"); + case TemplatesLocation: + return QCoreApplication::translate("QStandardPaths", "Templates"); } // not reached return QString(); diff --git a/src/corelib/io/qstandardpaths.h b/src/corelib/io/qstandardpaths.h index 2ee228beec3..145591f58d8 100644 --- a/src/corelib/io/qstandardpaths.h +++ b/src/corelib/io/qstandardpaths.h @@ -72,7 +72,9 @@ public: GenericCacheLocation, GenericConfigLocation, AppDataLocation, - AppConfigLocation + AppConfigLocation, + PublicShareLocation, + TemplatesLocation }; Q_ENUM(StandardLocation) diff --git a/src/corelib/io/qstandardpaths_android.cpp b/src/corelib/io/qstandardpaths_android.cpp index d5ece858182..28993a16dc9 100644 --- a/src/corelib/io/qstandardpaths_android.cpp +++ b/src/corelib/io/qstandardpaths_android.cpp @@ -200,6 +200,8 @@ QString QStandardPaths::writableLocation(StandardLocation type) return getFilesDir(); case QStandardPaths::ApplicationsLocation: case QStandardPaths::FontsLocation: + case QStandardPaths::PublicShareLocation: + case QStandardPaths::TemplatesLocation: default: break; } diff --git a/src/corelib/io/qstandardpaths_haiku.cpp b/src/corelib/io/qstandardpaths_haiku.cpp index 044d69fe45e..cac7767e6b2 100644 --- a/src/corelib/io/qstandardpaths_haiku.cpp +++ b/src/corelib/io/qstandardpaths_haiku.cpp @@ -137,6 +137,8 @@ QString QStandardPaths::writableLocation(StandardLocation type) case MusicLocation: case MoviesLocation: case DownloadLocation: + case PublicShareLocation: + case TemplatesLocation: case HomeLocation: return haikuStandardPath(B_USER_DIRECTORY); case FontsLocation: @@ -178,6 +180,8 @@ QStringList QStandardPaths::standardLocations(StandardLocation type) case MusicLocation: case MoviesLocation: case DownloadLocation: + case PublicShareLocation: + case TemplatesLocation: case HomeLocation: paths += haikuStandardPath(B_USER_NONPACKAGED_DIRECTORY); break; diff --git a/src/corelib/io/qstandardpaths_mac.mm b/src/corelib/io/qstandardpaths_mac.mm index a95e6a3bb12..8c102d6928f 100644 --- a/src/corelib/io/qstandardpaths_mac.mm +++ b/src/corelib/io/qstandardpaths_mac.mm @@ -85,6 +85,9 @@ static NSSearchPathDirectory searchPathDirectory(QStandardPaths::StandardLocatio return NSCachesDirectory; case QStandardPaths::DownloadLocation: return NSDownloadsDirectory; + case QStandardPaths::PublicShareLocation: + return NSSharedPublicDirectory; + case QStandardPaths::TemplatesLocation: default: return (NSSearchPathDirectory)0; } @@ -136,6 +139,12 @@ static QString baseWritableLocation(QStandardPaths::StandardLocation type, break; case QStandardPaths::ApplicationsLocation: break; + case QStandardPaths::PublicShareLocation: + path = pathForDirectory(NSDocumentDirectory, mask) + QLatin1String("/Public"); + break; + case QStandardPaths::TemplatesLocation: + path = pathForDirectory(NSDocumentDirectory, mask) + QLatin1String("/Templates"); + break; #endif case QStandardPaths::FontsLocation: path = pathForDirectory(NSLibraryDirectory, mask) + QLatin1String("/Fonts"); diff --git a/src/corelib/io/qstandardpaths_unix.cpp b/src/corelib/io/qstandardpaths_unix.cpp index fa35265257f..6acec9c034a 100644 --- a/src/corelib/io/qstandardpaths_unix.cpp +++ b/src/corelib/io/qstandardpaths_unix.cpp @@ -88,6 +88,10 @@ static QLatin1String xdg_key_name(QStandardPaths::StandardLocation type) return QLatin1String("VIDEOS"); case QStandardPaths::DownloadLocation: return QLatin1String("DOWNLOAD"); + case QStandardPaths::PublicShareLocation: + return QLatin1String("PUBLICSHARE"); + case QStandardPaths::TemplatesLocation: + return QLatin1String("TEMPLATES"); default: return QLatin1String(); } @@ -338,6 +342,14 @@ QString QStandardPaths::writableLocation(StandardLocation type) path = writableLocation(GenericDataLocation) + QLatin1String("/applications"); break; + case PublicShareLocation: + path = QDir::homePath() + QLatin1String("/Public"); + break; + + case TemplatesLocation: + path = QDir::homePath() + QLatin1String("/Templates"); + break; + default: break; } diff --git a/src/corelib/io/qstandardpaths_win.cpp b/src/corelib/io/qstandardpaths_win.cpp index 36541a4f81f..93034dd9b0b 100644 --- a/src/corelib/io/qstandardpaths_win.cpp +++ b/src/corelib/io/qstandardpaths_win.cpp @@ -144,8 +144,10 @@ static GUID writableSpecialFolderId(QStandardPaths::StandardLocation type) FOLDERID_LocalAppData, // GenericConfigLocation ("Local" path) FOLDERID_RoamingAppData,// AppDataLocation ("Roaming" path) FOLDERID_LocalAppData, // AppConfigLocation ("Local" path) + FOLDERID_Public, // PublicShareLocation + FOLDERID_Templates, // TemplatesLocation }; - static_assert(sizeof(folderIds) / sizeof(folderIds[0]) == size_t(QStandardPaths::AppConfigLocation + 1)); + static_assert(sizeof(folderIds) / sizeof(folderIds[0]) == size_t(QStandardPaths::TemplatesLocation + 1)); // folders for low integrity processes static const GUID folderIds_li[] = { @@ -166,6 +168,8 @@ static GUID writableSpecialFolderId(QStandardPaths::StandardLocation type) FOLDERID_LocalAppDataLow,// GenericConfigLocation ("Local" path) FOLDERID_RoamingAppData, // AppDataLocation ("Roaming" path) FOLDERID_LocalAppDataLow,// AppConfigLocation ("Local" path) + FOLDERID_Public, // PublicShareLocation + FOLDERID_Templates, // TemplatesLocation }; static_assert(sizeof(folderIds_li) == sizeof(folderIds));