From 742ef8fa79e896e72213cea2411181148cd90ef1 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Sun, 23 Mar 2014 22:42:10 +0100 Subject: Implement DownloadLocation retrieving using SHGetKnownFolderPath MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch implements the TODO concerning the retrieval of DownloadLocation using SHGetKnownFolderPath [ChangeLog][QtCore][Windows] Now QStandardPaths::DownloadLocation returns the proper path for Windows Vista and up Task-number: QTBUG-35194 Change-Id: Ifc7686e23de76dbfd7826a75e4bf99aa5b9268b0 Reviewed-by: Jan Arve Sæther --- src/corelib/io/qstandardpaths_win.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/corelib') diff --git a/src/corelib/io/qstandardpaths_win.cpp b/src/corelib/io/qstandardpaths_win.cpp index a0344a0206..62da5ea245 100644 --- a/src/corelib/io/qstandardpaths_win.cpp +++ b/src/corelib/io/qstandardpaths_win.cpp @@ -49,6 +49,10 @@ #include #endif +#if !defined(Q_OS_WINCE) +const GUID qCLSID_FOLDERID_Downloads = { 0x374de290, 0x123f, 0x4565, { 0x91, 0x64, 0x39, 0xc4, 0x92, 0x5e, 0x46, 0x7b } }; +#endif + #include #include #if !defined(Q_OS_WINCE) @@ -68,6 +72,10 @@ QT_BEGIN_NAMESPACE +#if !defined(Q_OS_WINCE) +typedef HRESULT (WINAPI *GetKnownFolderPath)(REFKNOWNFOLDERID, DWORD, HANDLE, LPWSTR*); +#endif + static QString convertCharArray(const wchar_t *path) { return QDir::fromNativeSeparators(QString::fromWCharArray(path)); @@ -77,6 +85,10 @@ QString QStandardPaths::writableLocation(StandardLocation type) { QString result; +#if !defined(Q_OS_WINCE) + static GetKnownFolderPath SHGetKnownFolderPath = (GetKnownFolderPath)QSystemLibrary::resolve(QLatin1String("shell32"), "SHGetKnownFolderPath"); +#endif + wchar_t path[MAX_PATH]; switch (type) { @@ -107,7 +119,18 @@ QString QStandardPaths::writableLocation(StandardLocation type) result = convertCharArray(path); break; - case DownloadLocation: // TODO implement with SHGetKnownFolderPath(FOLDERID_Downloads) (starting from Vista) + case DownloadLocation: +#if !defined(Q_OS_WINCE) + if (SHGetKnownFolderPath) { + LPWSTR path; + if (SHGetKnownFolderPath(qCLSID_FOLDERID_Downloads, 0, 0, &path) == S_OK) { + result = convertCharArray(path); + CoTaskMemFree(path); + } + break; + } +#endif + // fall through case DocumentsLocation: if (SHGetSpecialFolderPath(0, path, CSIDL_PERSONAL, FALSE)) result = convertCharArray(path); -- cgit v1.2.3