Implement DownloadLocation retrieving using SHGetKnownFolderPath

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 <jan-arve.saether@digia.com>
bb10
Samuel Gaist 2014-03-23 22:42:10 +01:00 committed by The Qt Project
parent d48db922d4
commit 742ef8fa79
1 changed files with 24 additions and 1 deletions

View File

@ -49,6 +49,10 @@
#include <qcoreapplication.h>
#endif
#if !defined(Q_OS_WINCE)
const GUID qCLSID_FOLDERID_Downloads = { 0x374de290, 0x123f, 0x4565, { 0x91, 0x64, 0x39, 0xc4, 0x92, 0x5e, 0x46, 0x7b } };
#endif
#include <qt_windows.h>
#include <shlobj.h>
#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);