Changeset 561 for trunk/src/gui/util/qdesktopservices_win.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/util/qdesktopservices_win.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 42 42 #include <qsettings.h> 43 43 #include <qdir.h> 44 #include <qlibrary.h> 44 45 #include <qurl.h> 45 46 #include <qstringlist.h> … … 48 49 #include <qcoreapplication.h> 49 50 50 #include < windows.h>51 #include <qt_windows.h> 51 52 #include <shlobj.h> 52 53 #if !defined(Q_OS_WINCE) … … 59 60 #endif 60 61 62 #if defined(Q_CC_MINGW) && !defined(CSIDL_MYMUSIC) 63 #define CSIDL_MYMUSIC 13 64 #define CSIDL_MYVIDEO 14 65 #endif 66 61 67 #ifndef QT_NO_DESKTOPSERVICES 62 68 63 69 QT_BEGIN_NAMESPACE 64 65 //#undef UNICODE66 70 67 71 static bool openDocument(const QUrl &file) … … 69 73 if (!file.isValid()) 70 74 return false; 71 72 quintptr returnValue; 73 QT_WA({ 74 returnValue = (quintptr)ShellExecute(0, 0, (TCHAR *)file.toString().utf16(), 0, 0, SW_SHOWNORMAL); 75 } , { 76 returnValue = (quintptr)ShellExecuteA(0, 0, file.toString().toLocal8Bit().constData(), 0, 0, SW_SHOWNORMAL); 77 }); 75 QString filePath = file.toLocalFile(); 76 if (filePath.isEmpty()) 77 filePath = file.toString(); 78 quintptr returnValue = (quintptr)ShellExecute(0, 0, (wchar_t*)filePath.utf16(), 0, 0, SW_SHOWNORMAL); 78 79 return (returnValue > 32); //ShellExecute returns a value greater than 32 if successful 79 80 } … … 81 82 static QString expandEnvStrings(const QString &command) 82 83 { 83 84 84 #if defined(Q_OS_WINCE) 85 85 return command; 86 86 #else 87 QByteArray path = command.toLocal8Bit(); 88 char commandValue[2 * MAX_PATH] = {0}; 89 DWORD returnValue = ExpandEnvironmentStringsA(path.data(), commandValue, MAX_PATH); 90 if (returnValue) 91 return QString::fromLocal8Bit(commandValue); 87 wchar_t buffer[MAX_PATH]; 88 if (ExpandEnvironmentStrings((wchar_t*)command.utf16(), buffer, MAX_PATH)) 89 return QString::fromWCharArray(buffer); 92 90 else 93 91 return command; … … 99 97 if (url.scheme() == QLatin1String("mailto")) { 100 98 //Retrieve the commandline for the default mail client 101 //the key used below is the command line for the mailto: shell command99 //the default key used below is the command line for the mailto: shell command 102 100 DWORD bufferSize = 2 * MAX_PATH; 103 101 long returnValue = -1; … … 106 104 HKEY handle; 107 105 LONG res; 108 QT_WA ({ 109 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, L"mailto\\Shell\\Open\\Command", 0, KEY_READ, &handle); 110 if (res != ERROR_SUCCESS) 111 return false; 112 113 wchar_t keyValue[2 * MAX_PATH] = {0}; 114 returnValue = RegQueryValueExW(handle, L"", 0, 0, reinterpret_cast<unsigned char*>(keyValue), &bufferSize); 106 wchar_t keyValue[2 * MAX_PATH] = {0}; 107 QString keyName(QLatin1String("mailto")); 108 109 //Check if user has set preference, otherwise use default. 110 res = RegOpenKeyExW(HKEY_CURRENT_USER, 111 L"Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\mailto\\UserChoice", 112 0, KEY_READ, &handle); 113 if (res == ERROR_SUCCESS) { 114 returnValue = RegQueryValueEx(handle, L"Progid", 0, 0, reinterpret_cast<unsigned char*>(keyValue), &bufferSize); 115 115 if (!returnValue) 116 command = QString::fromRawData((QChar*)keyValue, bufferSize); 117 }, { 118 res = RegOpenKeyExA(HKEY_CLASSES_ROOT, "mailto\\Shell\\Open\\Command", 0, KEY_READ, &handle); 119 if (res != ERROR_SUCCESS) 120 return false; 121 122 char keyValue[2 * MAX_PATH] = {0}; 123 returnValue = RegQueryValueExA(handle, "", 0, 0, reinterpret_cast<unsigned char*>(keyValue), &bufferSize); 124 if (!returnValue) 125 command = QString::fromLocal8Bit(keyValue); 126 }); 116 keyName = QString::fromUtf16((const ushort*)keyValue); 117 RegCloseKey(handle); 118 } 119 keyName += QLatin1String("\\Shell\\Open\\Command"); 120 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, (const wchar_t*)keyName.utf16(), 0, KEY_READ, &handle); 121 if (res != ERROR_SUCCESS) 122 return false; 123 124 bufferSize = 2 * MAX_PATH; 125 returnValue = RegQueryValueExW(handle, L"", 0, 0, reinterpret_cast<unsigned char*>(keyValue), &bufferSize); 126 if (!returnValue) 127 command = QString::fromRawData((QChar*)keyValue, bufferSize); 127 128 RegCloseKey(handle); 128 129 129 if (returnValue)130 if (returnValue) 130 131 return false; 132 131 133 command = expandEnvStrings(command); 132 134 command = command.trimmed(); … … 146 148 PROCESS_INFORMATION pi; 147 149 ZeroMemory(&pi, sizeof(pi)); 148 QT_WA ({ 149 STARTUPINFO si; 150 ZeroMemory(&si, sizeof(si)); 151 si.cb = sizeof(si); 152 153 returnValue = CreateProcess(NULL, (TCHAR*)command.utf16(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi); 154 }, { 155 STARTUPINFOA si; 156 ZeroMemory(&si, sizeof(si)); 157 si.cb = sizeof(si); 158 159 returnValue = CreateProcessA(NULL, command.toLocal8Bit().data(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi); 160 }); 150 STARTUPINFO si; 151 ZeroMemory(&si, sizeof(si)); 152 si.cb = sizeof(si); 153 154 returnValue = CreateProcess(NULL, (wchar_t*)command.utf16(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi); 161 155 162 156 if (!returnValue) … … 171 165 return false; 172 166 173 quintptr returnValue; 174 QT_WA ({ 175 returnValue = (quintptr)ShellExecute(0, 0, (TCHAR *) QString::fromUtf8(url.toEncoded().constData()).utf16(), 0, 0, SW_SHOWNORMAL); 176 } , { 177 returnValue = (quintptr)ShellExecuteA(0, 0, url.toEncoded().constData(), 0, 0, SW_SHOWNORMAL); 178 }); 167 if (url.scheme().isEmpty()) 168 return openDocument(url); 169 170 quintptr returnValue = (quintptr)ShellExecute(0, 0, (wchar_t *)QString::fromUtf8(url.toEncoded().constData()).utf16(), 171 0, 0, SW_SHOWNORMAL); 179 172 return (returnValue > 32); 180 173 } … … 182 175 QString QDesktopServices::storageLocation(StandardLocation type) 183 176 { 184 #if !defined(QT_NO_SETTINGS) 185 QSettings settings(QSettings::UserScope, QLatin1String("Microsoft"), QLatin1String("Windows")); 186 settings.beginGroup(QLatin1String("CurrentVersion/Explorer/Shell Folders")); 177 QString result; 178 179 #ifndef Q_OS_WINCE 180 QLibrary library(QLatin1String("shell32")); 181 #else 182 QLibrary library(QLatin1String("coredll")); 183 #endif // Q_OS_WINCE 184 typedef BOOL (WINAPI*GetSpecialFolderPath)(HWND, LPWSTR, int, BOOL); 185 static GetSpecialFolderPath SHGetSpecialFolderPath = 186 (GetSpecialFolderPath)library.resolve("SHGetSpecialFolderPathW"); 187 if (!SHGetSpecialFolderPath) 188 return QString(); 189 190 wchar_t path[MAX_PATH]; 191 187 192 switch (type) { 193 case DataLocation: 194 #if defined Q_WS_WINCE 195 if (SHGetSpecialFolderPath(0, path, CSIDL_APPDATA, FALSE)) 196 #else 197 if (SHGetSpecialFolderPath(0, path, CSIDL_LOCAL_APPDATA, FALSE)) 198 #endif 199 result = QString::fromWCharArray(path); 200 if (!QCoreApplication::organizationName().isEmpty()) 201 result = result + QLatin1String("\\") + QCoreApplication::organizationName(); 202 if (!QCoreApplication::applicationName().isEmpty()) 203 result = result + QLatin1String("\\") + QCoreApplication::applicationName(); 204 break; 205 206 case DesktopLocation: 207 if (SHGetSpecialFolderPath(0, path, CSIDL_DESKTOPDIRECTORY, FALSE)) 208 result = QString::fromWCharArray(path); 209 break; 210 211 case DocumentsLocation: 212 if (SHGetSpecialFolderPath(0, path, CSIDL_PERSONAL, FALSE)) 213 result = QString::fromWCharArray(path); 214 break; 215 216 case FontsLocation: 217 if (SHGetSpecialFolderPath(0, path, CSIDL_FONTS, FALSE)) 218 result = QString::fromWCharArray(path); 219 break; 220 221 case ApplicationsLocation: 222 if (SHGetSpecialFolderPath(0, path, CSIDL_PROGRAMS, FALSE)) 223 result = QString::fromWCharArray(path); 224 break; 225 226 case MusicLocation: 227 if (SHGetSpecialFolderPath(0, path, CSIDL_MYMUSIC, FALSE)) 228 result = QString::fromWCharArray(path); 229 break; 230 231 case MoviesLocation: 232 if (SHGetSpecialFolderPath(0, path, CSIDL_MYVIDEO, FALSE)) 233 result = QString::fromWCharArray(path); 234 break; 235 236 case PicturesLocation: 237 if (SHGetSpecialFolderPath(0, path, CSIDL_MYPICTURES, FALSE)) 238 result = QString::fromWCharArray(path); 239 break; 240 188 241 case CacheLocation: 189 242 // Although Microsoft has a Cache key it is a pointer to IE's cache, not a cache … … 191 244 // cache directory located in their AppData directory 192 245 return storageLocation(DataLocation) + QLatin1String("\\cache"); 193 case DataLocation:194 if (!settings.contains(QLatin1String("Local AppData")))195 break;196 return settings.value(QLatin1String("Local AppData")).toString()197 + QLatin1String("\\") + QCoreApplication::organizationName()198 + QLatin1String("\\") + QCoreApplication::applicationName();199 break;200 case DesktopLocation:201 return settings.value(QLatin1String("Desktop")).toString();202 break;203 204 case DocumentsLocation:205 return settings.value(QLatin1String("Personal")).toString();206 break;207 208 case FontsLocation:209 return settings.value(QLatin1String("Fonts")).toString();210 break;211 212 case ApplicationsLocation:213 return settings.value(QLatin1String("Programs")).toString();214 break;215 216 case MusicLocation:217 return settings.value(QLatin1String("My Music")).toString();218 break;219 220 case MoviesLocation:221 return settings.value(QLatin1String("My Video")).toString();222 break;223 224 case PicturesLocation:225 return settings.value(QLatin1String("My Pictures")).toString();226 break;227 246 228 247 case QDesktopServices::HomeLocation: … … 235 254 break; 236 255 } 237 #endif 238 return QString(); 256 return result; 239 257 } 240 258
Note:
See TracChangeset
for help on using the changeset viewer.