1 | /* $Id: UIDesktopServices_win.cpp 74942 2018-10-19 12:51:20Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - Qt GUI - Utility Classes and Functions specific to Windows..
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2017 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifdef VBOX_WITH_PRECOMPILED_HEADERS
|
---|
19 | # include <precomp.h>
|
---|
20 | #else /* !VBOX_WITH_PRECOMPILED_HEADERS */
|
---|
21 |
|
---|
22 | /* VBox includes */
|
---|
23 | # include "UIDesktopServices.h"
|
---|
24 |
|
---|
25 | /* Qt includes */
|
---|
26 | # include <QDir>
|
---|
27 | # include <QCoreApplication>
|
---|
28 | # include <QUuid>
|
---|
29 |
|
---|
30 | /* System includes */
|
---|
31 | # include <iprt/win/shlobj.h>
|
---|
32 |
|
---|
33 | #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
|
---|
34 |
|
---|
35 |
|
---|
36 | bool UIDesktopServices::createMachineShortcut(const QString & /* strSrcFile */, const QString &strDstPath, const QString &strName, const QUuid &uUuid)
|
---|
37 | {
|
---|
38 | IShellLink *pShl = NULL;
|
---|
39 | IPersistFile *pPPF = NULL;
|
---|
40 | QString strVBox = QDir::toNativeSeparators(QCoreApplication::applicationFilePath());
|
---|
41 | QFileInfo fi(strVBox);
|
---|
42 | QString strVBoxDir = QDir::toNativeSeparators(fi.absolutePath());
|
---|
43 | HRESULT rc = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)(&pShl));
|
---|
44 | if (FAILED(rc))
|
---|
45 | return false;
|
---|
46 | do
|
---|
47 | {
|
---|
48 | rc = pShl->SetPath(strVBox.utf16());
|
---|
49 | if (FAILED(rc))
|
---|
50 | break;
|
---|
51 | rc = pShl->SetWorkingDirectory(strVBoxDir.utf16());
|
---|
52 | if (FAILED(rc))
|
---|
53 | break;
|
---|
54 | QString strArgs = QString("--comment \"%1\" --startvm \"%2\"").arg(strName).arg(uUuid.toString());
|
---|
55 | rc = pShl->SetArguments(strArgs.utf16());
|
---|
56 | if (FAILED(rc))
|
---|
57 | break;
|
---|
58 | QString strDesc = QString("Starts the VirtualBox machine %1").arg(strName);
|
---|
59 | rc = pShl->SetDescription(strDesc.utf16());
|
---|
60 | if (FAILED(rc))
|
---|
61 | break;
|
---|
62 | rc = pShl->QueryInterface(IID_IPersistFile, (void**)&pPPF);
|
---|
63 | if (FAILED(rc))
|
---|
64 | break;
|
---|
65 | QString strLink = QString("%1\\%2.lnk").arg(strDstPath).arg(strName);
|
---|
66 | rc = pPPF->Save(strLink.utf16(), TRUE);
|
---|
67 | } while(0);
|
---|
68 | if (pPPF)
|
---|
69 | pPPF->Release();
|
---|
70 | if (pShl)
|
---|
71 | pShl->Release();
|
---|
72 | return SUCCEEDED(rc);
|
---|
73 | }
|
---|
74 |
|
---|
75 | bool UIDesktopServices::openInFileManager(const QString &strFile)
|
---|
76 | {
|
---|
77 | QFileInfo fi(strFile);
|
---|
78 | QString strTmp = QDir::toNativeSeparators(fi.absolutePath());
|
---|
79 |
|
---|
80 | intptr_t rc = (intptr_t)ShellExecute(NULL, L"explore", strTmp.utf16(), NULL, NULL, SW_SHOWNORMAL);
|
---|
81 |
|
---|
82 | return rc > 32 ? true : false;
|
---|
83 | }
|
---|
84 |
|
---|