From e1a8a55a585dfe3d3326cec1211884cb4acf5153 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Sun, 7 Sep 2014 23:27:47 +0200 Subject: 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 Reviewed-by: Friedemann Kleint --- src/gui/util/qdesktopservices_win.cpp | 39 +++++++++++++++++++++-------------- 1 file 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) -- cgit v1.2.3