diff options
author | Samuel Gaist <samuel.gaist@edeltech.ch> | 2014-09-07 23:27:47 +0200 |
---|---|---|
committer | Samuel Gaist <samuel.gaist@edeltech.ch> | 2014-10-01 23:19:35 +0200 |
commit | e1a8a55a585dfe3d3326cec1211884cb4acf5153 (patch) | |
tree | 840caf22a5c53e8b5e2314b3521ae43f316f53d1 /src/gui | |
parent | 45de76f8e071edcf77bc3bd006f052fe5b3f01fc (diff) | |
download | qt4-tools-e1a8a55a585dfe3d3326cec1211884cb4acf5153.tar.gz |
Backport: use backslashes for UNCs path
ShellExecute fails to open a share folder due to using '/' instead of '\'.
Windows API doesn't support forward slashes for extended-length path.
Extended-length path are path that start with a "\\?\" prefix. For example,
"\\?\c:\very_long_path\foo\bar.txt", or in the case of a UNC path that
would be "\\?\very_long_path\foo\bar.txt". [1]
[1] http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx#maxpath
(cherry-picked and adapted from qtbase/18c916517f3004d34482c20ed66bf09ec274d385)
Task-number: QTBUG-13359
Change-Id: I2f38ecb76d87b87dc1d40bd48c94c78550a6ca1f
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/util/qdesktopservices_win.cpp | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/src/gui/util/qdesktopservices_win.cpp b/src/gui/util/qdesktopservices_win.cpp index 792474c453..1bf3654b61 100644 --- a/src/gui/util/qdesktopservices_win.cpp +++ b/src/gui/util/qdesktopservices_win.cpp @@ -65,15 +65,30 @@ QT_BEGIN_NAMESPACE -static bool openDocument(const QUrl &file) +static inline bool shellExecute(const QUrl &url) { - if (!file.isValid()) +#ifndef Q_OS_WINCE + if (!url.isValid()) + return false; + + const QString nativeFilePath = + url.isLocalFile() ? QDir::toNativeSeparators(url.toLocalFile()) : url.toString(); + const quintptr result = (quintptr)ShellExecute(0, 0, (wchar_t*)nativeFilePath.utf16(), 0, 0, SW_SHOWNORMAL); + // ShellExecute returns a value greater than 32 if successful + if (result <= 32) { + qWarning("ShellExecute '%s' failed (error %s).", qPrintable(url.toString()), qPrintable(QString::number(result))); return false; - QString filePath = file.toLocalFile(); - if (filePath.isEmpty()) - filePath = file.toString(); - quintptr returnValue = (quintptr)ShellExecute(0, 0, (wchar_t*)filePath.utf16(), 0, 0, SW_SHOWNORMAL); - return (returnValue > 32); //ShellExecute returns a value greater than 32 if successful + } + return true; +#else + Q_UNUSED(url); + return false; +#endif +} + +static bool openDocument(const QUrl &file) +{ + return shellExecute(file); } static QString expandEnvStrings(const QString &command) @@ -158,15 +173,7 @@ static bool launchWebBrowser(const QUrl &url) return true; } - if (!url.isValid()) - return false; - - if (url.scheme().isEmpty()) - return openDocument(url); - - quintptr returnValue = (quintptr)ShellExecute(0, 0, (wchar_t *)QString::fromUtf8(url.toEncoded().constData()).utf16(), - 0, 0, SW_SHOWNORMAL); - return (returnValue > 32); + return shellExecute(url); } QString QDesktopServices::storageLocation(StandardLocation type) |