diff options
author | Frerich Raabe <raabe@froglogic.com> | 2015-10-21 17:21:47 +0200 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@theqtcompany.com> | 2015-12-08 13:06:13 +0000 |
commit | d129ccdb8aa63185ea939068d892b27c634e4842 (patch) | |
tree | 88c7a330a9851c7cacb804f4c55e1a8519d6e649 /src/libs/installer/createshortcutoperation.cpp | |
parent | 85ce71449b9ec80f636054ef447a21716cf5ab7a (diff) |
Implemented support for creating URL shortcuts on Windows
This makes it possible to use the CreateShortcut operation for creating
http: and ftp: links, too. This is useful for adding links to online
resources to the start menu.
The detection of hyperlinks is very simplistic at this point, but good
enough many purposes.
Change-Id: I80b5eea466a37891cb378eb5c603c08f065bd843
Reviewed-by: Karsten Heimrich <karsten.heimrich@theqtcompany.com>
Diffstat (limited to 'src/libs/installer/createshortcutoperation.cpp')
-rw-r--r-- | src/libs/installer/createshortcutoperation.cpp | 64 |
1 files changed, 43 insertions, 21 deletions
diff --git a/src/libs/installer/createshortcutoperation.cpp b/src/libs/installer/createshortcutoperation.cpp index 692b30aa4..9c48605ff 100644 --- a/src/libs/installer/createshortcutoperation.cpp +++ b/src/libs/installer/createshortcutoperation.cpp @@ -47,6 +47,7 @@ using namespace QInstaller; #ifdef Q_OS_WIN #include <qt_windows.h> #include <shlobj.h> +#include <Intshcut.h> #ifndef PIDLIST_ABSOLUTE typedef ITEMIDLIST *PIDLIST_ABSOLUTE; @@ -102,36 +103,57 @@ static bool createLink(const QString &fileName, const QString &linkName, QString const QString &iconId = QString()) { #ifdef Q_OS_WIN - bool success = QFile::link(fileName, linkName); + // CoInitialize cleanup object + DeCoInitializer _; - if (!success) - return success; + IUnknown *iunkn = NULL; - if (workingDir.isEmpty()) - workingDir = QFileInfo(fileName).absolutePath(); - workingDir = QDir::toNativeSeparators(workingDir); + if (fileName.toLower().startsWith(QLatin1String("http:")) + || fileName.toLower().startsWith(QLatin1String("ftp:"))) { + IUniformResourceLocator *iurl = NULL; + if (FAILED(CoCreateInstance(CLSID_InternetShortcut, NULL, CLSCTX_INPROC_SERVER, + IID_IUniformResourceLocator, (LPVOID*)&iurl))) { + return false; + } - // CoInitialize cleanup object - DeCoInitializer _; + if (FAILED(iurl->SetURL((wchar_t *)fileName.utf16(), IURL_SETURL_FL_GUESS_PROTOCOL))) { + iurl->Release(); + return false; + } + iunkn = iurl; + } else { + bool success = QFile::link(fileName, linkName); - IShellLink *psl = NULL; - if (FAILED(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl))) - return success; + if (!success) { + return success; + } + + if (workingDir.isEmpty()) + workingDir = QFileInfo(fileName).absolutePath(); + workingDir = QDir::toNativeSeparators(workingDir); + + IShellLink *psl = NULL; + if (FAILED(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, + IID_IShellLink, (LPVOID*)&psl))) { + return success; + } - // TODO: implement this server side, since there's not Qt equivalent to set working dir and arguments - psl->SetPath((wchar_t *)QDir::toNativeSeparators(fileName).utf16()); - psl->SetWorkingDirectory((wchar_t *)workingDir.utf16()); - if (!arguments.isNull()) - psl->SetArguments((wchar_t*)arguments.utf16()); - if (!iconPath.isNull()) - psl->SetIconLocation((wchar_t*)(iconPath.utf16()), iconId.toInt()); + // TODO: implement this server side, since there's not Qt equivalent to set working dir and arguments + psl->SetPath((wchar_t *)QDir::toNativeSeparators(fileName).utf16()); + psl->SetWorkingDirectory((wchar_t *)workingDir.utf16()); + if (!arguments.isNull()) + psl->SetArguments((wchar_t*)arguments.utf16()); + if (!iconPath.isNull()) + psl->SetIconLocation((wchar_t*)(iconPath.utf16()), iconId.toInt()); + iunkn = psl; + } IPersistFile *ppf = NULL; - if (SUCCEEDED(psl->QueryInterface(IID_IPersistFile, (void **)&ppf))) { + if (SUCCEEDED(iunkn->QueryInterface(IID_IPersistFile, (void **)&ppf))) { ppf->Save((wchar_t*)QDir::toNativeSeparators(linkName).utf16(), true); ppf->Release(); } - psl->Release(); + iunkn->Release(); PIDLIST_ABSOLUTE pidl; // Force start menu cache update if (SUCCEEDED(SHGetFolderLocation(0, CSIDL_STARTMENU, 0, 0, &pidl))) { @@ -143,7 +165,7 @@ static bool createLink(const QString &fileName, const QString &linkName, QString CoTaskMemFree(pidl); } - return success; + return true; #else Q_UNUSED(arguments) Q_UNUSED(workingDir) |