summaryrefslogtreecommitdiffstats
path: root/src/gui/util/qdesktopservices_win.cpp
diff options
context:
space:
mode:
authorJens Bache-Wiig <jbache@trolltech.com>2009-09-16 11:59:20 (GMT)
committerJens Bache-Wiig <jbache@trolltech.com>2009-09-16 12:02:39 (GMT)
commit722d351de797135273a05ff0f4c63315bf37592d (patch)
treed2af3a105daf24ff1c29c620b6d143a3ee709492 /src/gui/util/qdesktopservices_win.cpp
parent16c4afe4592587a4bc48ae2170da748e0d149a64 (diff)
downloadQt-722d351de797135273a05ff0f4c63315bf37592d.zip
Qt-722d351de797135273a05ff0f4c63315bf37592d.tar.gz
Qt-722d351de797135273a05ff0f4c63315bf37592d.tar.bz2
Fix QDesktopServices::storageLocation() when registry keys are missing
We should not use the registry key when looking up the storage location as this is not really supported by Microsoft and not allways accessible. Instead we now use SHGetSpecialFolderPath. Note that we avoid SHGetKnownFolderPath as it is not available on all CE platforms though it is the reccommended function by Microsoft. Task-number: QTBUG-3241 Reviewed-by: prasanth
Diffstat (limited to 'src/gui/util/qdesktopservices_win.cpp')
-rw-r--r--src/gui/util/qdesktopservices_win.cpp66
1 files changed, 44 insertions, 22 deletions
diff --git a/src/gui/util/qdesktopservices_win.cpp b/src/gui/util/qdesktopservices_win.cpp
index 9ae3a15..bf29870 100644
--- a/src/gui/util/qdesktopservices_win.cpp
+++ b/src/gui/util/qdesktopservices_win.cpp
@@ -41,6 +41,7 @@
#include <qsettings.h>
#include <qdir.h>
+#include <qlibrary.h>
#include <qurl.h>
#include <qstringlist.h>
#include <qprocess.h>
@@ -168,50 +169,72 @@ static bool launchWebBrowser(const QUrl &url)
QString QDesktopServices::storageLocation(StandardLocation type)
{
-#if !defined(QT_NO_SETTINGS)
- QSettings settings(QSettings::UserScope, QLatin1String("Microsoft"), QLatin1String("Windows"));
- settings.beginGroup(QLatin1String("CurrentVersion/Explorer/Shell Folders"));
+ QString result;
+
+#ifndef Q_OS_WINCE
+ QLibrary library(QLatin1String("shell32"));
+#else
+ QLibrary library(QLatin1String("coredll"));
+#endif // Q_OS_WINCE
+ typedef BOOL (WINAPI*GetSpecialFolderPath)(HWND, LPWSTR, int, BOOL);
+ static GetSpecialFolderPath SHGetSpecialFolderPath =
+ (GetSpecialFolderPath)library.resolve("SHGetSpecialFolderPathW");
+ if (!SHGetSpecialFolderPath)
+ return QString();
+
+ wchar_t path[MAX_PATH];
+
switch (type) {
- case CacheLocation:
- // Although Microsoft has a Cache key it is a pointer to IE's cache, not a cache
- // location for everyone. Most applications seem to be using a
- // cache directory located in their AppData directory
- return storageLocation(DataLocation) + QLatin1String("\\cache");
case DataLocation:
- if (!settings.contains(QLatin1String("Local AppData")))
- break;
- return settings.value(QLatin1String("Local AppData")).toString()
- + QLatin1String("\\") + QCoreApplication::organizationName()
- + QLatin1String("\\") + QCoreApplication::applicationName();
+ if (SHGetSpecialFolderPath(0, path, CSIDL_LOCAL_APPDATA, FALSE))
+ result = QString::fromWCharArray(path);
+ if (!QCoreApplication::organizationName().isEmpty())
+ result = result + QLatin1String("\\") + QCoreApplication::organizationName();
+ if (!QCoreApplication::applicationName().isEmpty())
+ result = result + QLatin1String("\\") + QCoreApplication::applicationName();
break;
+
case DesktopLocation:
- return settings.value(QLatin1String("Desktop")).toString();
+ if (SHGetSpecialFolderPath(0, path, CSIDL_DESKTOPDIRECTORY, FALSE))
+ result = QString::fromWCharArray(path);
break;
case DocumentsLocation:
- return settings.value(QLatin1String("Personal")).toString();
+ if (SHGetSpecialFolderPath(0, path, CSIDL_PERSONAL, FALSE))
+ result = QString::fromWCharArray(path);
break;
case FontsLocation:
- return settings.value(QLatin1String("Fonts")).toString();
+ if (SHGetSpecialFolderPath(0, path, CSIDL_FONTS, FALSE))
+ result = QString::fromWCharArray(path);
break;
case ApplicationsLocation:
- return settings.value(QLatin1String("Programs")).toString();
+ if (SHGetSpecialFolderPath(0, path, CSIDL_PROGRAMS, FALSE))
+ result = QString::fromWCharArray(path);
break;
case MusicLocation:
- return settings.value(QLatin1String("My Music")).toString();
+ if (SHGetSpecialFolderPath(0, path, CSIDL_MYMUSIC, FALSE))
+ result = QString::fromWCharArray(path);
break;
case MoviesLocation:
- return settings.value(QLatin1String("My Video")).toString();
+ if (SHGetSpecialFolderPath(0, path, CSIDL_MYVIDEO, FALSE))
+ result = QString::fromWCharArray(path);
break;
case PicturesLocation:
- return settings.value(QLatin1String("My Pictures")).toString();
+ if (SHGetSpecialFolderPath(0, path, CSIDL_MYPICTURES, FALSE))
+ result = QString::fromWCharArray(path);
break;
+ case CacheLocation:
+ // Although Microsoft has a Cache key it is a pointer to IE's cache, not a cache
+ // location for everyone. Most applications seem to be using a
+ // cache directory located in their AppData directory
+ return storageLocation(DataLocation) + QLatin1String("\\cache");
+
case QDesktopServices::HomeLocation:
return QDir::homePath(); break;
@@ -221,8 +244,7 @@ QString QDesktopServices::storageLocation(StandardLocation type)
default:
break;
}
-#endif
- return QString();
+ return result;
}
QString QDesktopServices::displayName(StandardLocation type)