VirtualBox

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

Last change on this file since 98103 was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.9 KB
Line 
1/* $Id: UIDesktopServices_win.cpp 98103 2023-01-17 14:15:46Z 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 rc = pShl->SetPath(strVBox.utf16());
53 if (FAILED(rc))
54 break;
55 rc = pShl->SetWorkingDirectory(strVBoxDir.utf16());
56 if (FAILED(rc))
57 break;
58 QString strArgs = QString("--comment \"%1\" --startvm \"%2\"").arg(strName).arg(uUuid.toString());
59 rc = pShl->SetArguments(strArgs.utf16());
60 if (FAILED(rc))
61 break;
62 QString strDesc = QString("Starts the VirtualBox machine %1").arg(strName);
63 rc = pShl->SetDescription(strDesc.utf16());
64 if (FAILED(rc))
65 break;
66 rc = pShl->QueryInterface(IID_IPersistFile, (void**)&pPPF);
67 if (FAILED(rc))
68 break;
69 QString strLink = QString("%1\\%2.lnk").arg(strDstPath).arg(strName);
70 rc = pPPF->Save(strLink.utf16(), TRUE);
71 } while(0);
72 if (pPPF)
73 pPPF->Release();
74 if (pShl)
75 pShl->Release();
76 return SUCCEEDED(rc);
77}
78
79bool UIDesktopServices::openInFileManager(const QString &strFile)
80{
81 QFileInfo fi(strFile);
82 QString strTmp = QDir::toNativeSeparators(fi.absolutePath());
83
84 intptr_t rc = (intptr_t)ShellExecute(NULL, L"explore", strTmp.utf16(), NULL, NULL, SW_SHOWNORMAL);
85
86 return rc > 32 ? true : false;
87}
88
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use