From 272d20ce27bfde44fe0ea85d90fe178bb01198da Mon Sep 17 00:00:00 2001 From: David Faure Date: Thu, 3 Nov 2011 19:13:32 +0100 Subject: [PATCH] QStandardPaths: add DownloadLocation. Only properly implemented on unix (XDG), falls back to Document location on Mac and Windows, because not easily available with the current API being used by either one. Change-Id: Id269f0e3c4e3a68e19205de96c0b39980fde80ff Reviewed-by: Thiago Macieira --- src/corelib/io/qstandardpaths.cpp | 3 ++- src/corelib/io/qstandardpaths.h | 3 ++- src/corelib/io/qstandardpaths_mac.cpp | 2 ++ src/corelib/io/qstandardpaths_unix.cpp | 7 ++++++- src/corelib/io/qstandardpaths_win.cpp | 1 + .../auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp | 1 + 6 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/corelib/io/qstandardpaths.cpp b/src/corelib/io/qstandardpaths.cpp index 7deaceefc85..43ae5c07ab3 100644 --- a/src/corelib/io/qstandardpaths.cpp +++ b/src/corelib/io/qstandardpaths.cpp @@ -72,7 +72,7 @@ QT_BEGIN_NAMESPACE \value DocumentsLocation Returns the user's document. \value FontsLocation Returns the user's fonts. \value ApplicationsLocation Returns the user's applications. - \value MusicLocation Returns the users music. + \value MusicLocation Returns the user's music. \value MoviesLocation Returns the user's movies. \value PicturesLocation Returns the user's pictures. \value TempLocation Returns the system's temporary directory. @@ -89,6 +89,7 @@ QT_BEGIN_NAMESPACE files should be written. For instance unix local sockets. \value ConfigLocation Returns a directory location where user-specific configuration files should be written. + \value DownloadLocation Returns a directory for user's downloaded files. \sa writableLocation() standardLocations() displayName() locate() locateAll() diff --git a/src/corelib/io/qstandardpaths.h b/src/corelib/io/qstandardpaths.h index 1bef1be7f62..d91da9de2f8 100644 --- a/src/corelib/io/qstandardpaths.h +++ b/src/corelib/io/qstandardpaths.h @@ -72,7 +72,8 @@ public: CacheLocation, GenericDataLocation, RuntimeLocation, - ConfigLocation + ConfigLocation, + DownloadLocation }; static QString writableLocation(StandardLocation type); diff --git a/src/corelib/io/qstandardpaths_mac.cpp b/src/corelib/io/qstandardpaths_mac.cpp index 65c7f01fb47..84fc81494c9 100644 --- a/src/corelib/io/qstandardpaths_mac.cpp +++ b/src/corelib/io/qstandardpaths_mac.cpp @@ -60,6 +60,8 @@ OSType translateLocation(QStandardPaths::StandardLocation type) return kPreferencesFolderType; case QStandardPaths::DesktopLocation: return kDesktopFolderType; + case QStandardPaths::DownloadLocation: // needs NSSearchPathForDirectoriesInDomains with NSDownloadsDirectory + // which needs an objective-C *.mm file... case QStandardPaths::DocumentsLocation: return kDocumentsFolderType; case QStandardPaths::FontsLocation: diff --git a/src/corelib/io/qstandardpaths_unix.cpp b/src/corelib/io/qstandardpaths_unix.cpp index 059bf3bd10a..b1c5869f71c 100644 --- a/src/corelib/io/qstandardpaths_unix.cpp +++ b/src/corelib/io/qstandardpaths_unix.cpp @@ -173,6 +173,9 @@ QString QStandardPaths::writableLocation(StandardLocation type) case MoviesLocation: key = QLatin1String("VIDEOS"); break; + case DownloadLocation: + key = QLatin1String("DOWNLOAD"); + break; default: break; } @@ -210,7 +213,9 @@ QString QStandardPaths::writableLocation(StandardLocation type) case MoviesLocation: path = QDir::homePath() + QLatin1String("/Videos"); break; - + case DownloadLocation: + path = QDir::homePath() + QLatin1String("/Downloads"); + break; case ApplicationsLocation: path = writableLocation(GenericDataLocation) + QLatin1String("/applications"); break; diff --git a/src/corelib/io/qstandardpaths_win.cpp b/src/corelib/io/qstandardpaths_win.cpp index 5716ffc6a83..e9093649f32 100644 --- a/src/corelib/io/qstandardpaths_win.cpp +++ b/src/corelib/io/qstandardpaths_win.cpp @@ -123,6 +123,7 @@ QString QStandardPaths::writableLocation(StandardLocation type) result = convertCharArray(path); break; + case DownloadLocation: // TODO implement with SHGetKnownFolderPath(FOLDERID_Downloads) (starting from Vista) case DocumentsLocation: if (SHGetSpecialFolderPath(0, path, CSIDL_PERSONAL, FALSE)) result = convertCharArray(path); diff --git a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp index d8b22ae1346..5c2bb0bb694 100644 --- a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp +++ b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp @@ -266,6 +266,7 @@ void tst_qstandardpaths::testAllWritableLocations_data() QTest::newRow("TempLocation") << QStandardPaths::TempLocation; QTest::newRow("HomeLocation") << QStandardPaths::HomeLocation; QTest::newRow("DataLocation") << QStandardPaths::DataLocation; + QTest::newRow("DownloadLocation") << QStandardPaths::DownloadLocation; } void tst_qstandardpaths::testAllWritableLocations()