VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/platform/win/UIDesktopServices_win.cpp

Last change on this file was 99802, checked in by vboxsync, 13 months ago

*: Adjustments necessary for dropping -Zc:wchar_t- on windows and instead let the C++ compiler use the native wchar_t type.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.0 KB
Line 
1/* $Id: UIDesktopServices_win.cpp 99802 2023-05-16 00:05:16Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - Qt GUI - Utility Classes and Functions specific to Windows..
4 */
5
6/*
7 * Copyright (C) 2010-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28/* VBox includes */
29#include "UIDesktopServices.h"
30
31/* Qt includes */
32#include <QDir>
33#include <QCoreApplication>
34#include <QUuid>
35
36/* System includes */
37#include <iprt/win/shlobj.h>
38
39
40bool UIDesktopServices::createMachineShortcut(const QString & /* strSrcFile */, const QString &strDstPath, const QString &strName, const QUuid &uUuid)
41{
42 IShellLink *pShl = NULL;
43 IPersistFile *pPPF = NULL;
44 const QString strVBox = QDir::toNativeSeparators(QCoreApplication::applicationDirPath() + "/" + VBOX_GUI_VMRUNNER_IMAGE);
45 QFileInfo fi(strVBox);
46 QString strVBoxDir = QDir::toNativeSeparators(fi.absolutePath());
47 HRESULT rc = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)(&pShl));
48 if (FAILED(rc))
49 return false;
50 do
51 {
52/** @todo Not really BSTR, so using PCWSTR, but whatever... */
53 rc = pShl->SetPath((PCWSTR)strVBox.utf16());
54 if (FAILED(rc))
55 break;
56 rc = pShl->SetWorkingDirectory((PCWSTR)strVBoxDir.utf16());
57 if (FAILED(rc))
58 break;
59 QString strArgs = QString("--comment \"%1\" --startvm \"%2\"").arg(strName).arg(uUuid.toString());
60 rc = pShl->SetArguments((PCWSTR)strArgs.utf16());
61 if (FAILED(rc))
62 break;
63 QString strDesc = QString("Starts the VirtualBox machine %1").arg(strName);
64 rc = pShl->SetDescription((PCWSTR)strDesc.utf16());
65 if (FAILED(rc))
66 break;
67 rc = pShl->QueryInterface(IID_IPersistFile, (void**)&pPPF);
68 if (FAILED(rc))
69 break;
70 QString strLink = QString("%1\\%2.lnk").arg(strDstPath).arg(strName);
71 rc = pPPF->Save((PCWSTR)strLink.utf16(), TRUE);
72 } while(0);
73 if (pPPF)
74 pPPF->Release();
75 if (pShl)
76 pShl->Release();
77 return SUCCEEDED(rc);
78}
79
80bool UIDesktopServices::openInFileManager(const QString &strFile)
81{
82 QFileInfo fi(strFile);
83 QString strTmp = QDir::toNativeSeparators(fi.absolutePath());
84
85 intptr_t rc = (intptr_t)ShellExecute(NULL, L"explore", (PCWSTR)strTmp.utf16(), NULL, NULL, SW_SHOWNORMAL);
86
87 return rc > 32 ? true : false;
88}
89
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use