- Timestamp:
- Aug 26, 2009, 11:45:41 PM (16 years ago)
- Location:
- trunk/src/gui/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gui/util/qdesktopservices.cpp
r2 r132 52 52 #elif defined(Q_WS_WIN) 53 53 #include "qdesktopservices_win.cpp" 54 #elif defined(Q_WS_PM) 55 #include "qdesktopservices_pm.cpp" 54 56 #elif defined(Q_WS_MAC) 55 57 #include "qdesktopservices_mac.cpp" -
trunk/src/gui/util/qdesktopservices_pm.cpp
r95 r132 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** Contact: Qt Software Information (qt-info@nokia.com) 5 ** 6 ** Copyright (C) 2009 netlabs.org. OS/2 parts. 5 7 ** 6 8 ** This file is part of the QtGui module of the Qt Toolkit. … … 48 50 #include <qcoreapplication.h> 49 51 50 #include <windows.h>51 #include <shlobj.h>52 #if !defined(Q_OS_WINCE)53 # include <intshcut.h>54 #else55 # include <qguifunctions_wince.h>56 # if !defined(STANDARDSHELL_UI_MODEL)57 # include <winx.h>58 # endif59 #endif60 61 52 #ifndef QT_NO_DESKTOPSERVICES 62 53 63 54 QT_BEGIN_NAMESPACE 64 65 //#undef UNICODE66 55 67 56 static bool openDocument(const QUrl &file) … … 70 59 return false; 71 60 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 }); 78 return (returnValue > 32); //ShellExecute returns a value greater than 32 if successful 79 } 80 81 static QString expandEnvStrings(const QString &command) 82 { 83 84 #if defined(Q_OS_WINCE) 85 return command; 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); 92 else 93 return command; 94 #endif 61 // @todo implement 62 return false; 95 63 } 96 64 97 65 static bool launchWebBrowser(const QUrl &url) 98 66 { 99 if (url.scheme() == QLatin1String("mailto")) { 100 //Retrieve the commandline for the default mail client 101 //the key used below is the command line for the mailto: shell command 102 DWORD bufferSize = 2 * MAX_PATH; 103 long returnValue = -1; 104 QString command; 105 106 HKEY handle; 107 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); 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 }); 127 RegCloseKey(handle); 128 129 if(returnValue) 130 return false; 131 command = expandEnvStrings(command); 132 command = command.trimmed(); 133 //Make sure the path for the process is in quotes 134 int index = -1 ; 135 if (command[0]!= QLatin1Char('\"')) { 136 index = command.indexOf(QLatin1String(".exe "), 0, Qt::CaseInsensitive); 137 command.insert(index+4, QLatin1Char('\"')); 138 command.insert(0, QLatin1Char('\"')); 139 } 140 //pass the url as the parameter 141 index = command.lastIndexOf(QLatin1String("%1")); 142 if (index != -1){ 143 command.replace(index, 2, url.toString()); 144 } 145 //start the process 146 PROCESS_INFORMATION pi; 147 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 }); 161 162 if (!returnValue) 163 return false; 164 165 CloseHandle(pi.hProcess); 166 CloseHandle(pi.hThread); 167 return true; 168 } 169 170 if (!url.isValid()) 171 return false; 172 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 }); 179 return (returnValue > 32); 67 // @todo implement 68 return false; 180 69 } 181 70 182 71 QString QDesktopServices::storageLocation(StandardLocation type) 183 72 { 184 #if !defined(QT_NO_SETTINGS) 185 QSettings settings(QSettings::UserScope, QLatin1String("Microsoft"), QLatin1String("Windows")); 186 settings.beginGroup(QLatin1String("CurrentVersion/Explorer/Shell Folders")); 187 switch (type) { 188 case CacheLocation: 189 // Although Microsoft has a Cache key it is a pointer to IE's cache, not a cache 190 // location for everyone. Most applications seem to be using a 191 // cache directory located in their AppData directory 192 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 228 case QDesktopServices::HomeLocation: 229 return QDir::homePath(); break; 230 231 case QDesktopServices::TempLocation: 232 return QDir::tempPath(); break; 233 234 default: 235 break; 236 } 237 #endif 73 // @todo implement 238 74 return QString(); 239 75 }
Note:
See TracChangeset
for help on using the changeset viewer.