VirtualBox

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

Last change on this file since 69500 was 69500, checked in by vboxsync, 7 years ago

*: scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.7 KB
Line 
1/* $Id: UIDesktopServices_win.cpp 69500 2017-10-28 15:14:05Z 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
29/* System includes */
30# include <iprt/win/shlobj.h>
31
32#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
33
34
35bool UIDesktopServices::createMachineShortcut(const QString & /* strSrcFile */, const QString &strDstPath, const QString &strName, const QString &strUuid)
36{
37 IShellLink *pShl = NULL;
38 IPersistFile *pPPF = NULL;
39 QString strVBox = QDir::toNativeSeparators(QCoreApplication::applicationFilePath());
40 QFileInfo fi(strVBox);
41 QString strVBoxDir = QDir::toNativeSeparators(fi.absolutePath());
42 HRESULT rc = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)(&pShl));
43 if (FAILED(rc))
44 return false;
45 do
46 {
47 rc = pShl->SetPath(strVBox.utf16());
48 if (FAILED(rc))
49 break;
50 rc = pShl->SetWorkingDirectory(strVBoxDir.utf16());
51 if (FAILED(rc))
52 break;
53 QString strArgs = QString("--comment \"%1\" --startvm \"%2\"").arg(strName).arg(strUuid);
54 rc = pShl->SetArguments(strArgs.utf16());
55 if (FAILED(rc))
56 break;
57 QString strDesc = QString("Starts the VirtualBox machine %1").arg(strName);
58 rc = pShl->SetDescription(strDesc.utf16());
59 if (FAILED(rc))
60 break;
61 rc = pShl->QueryInterface(IID_IPersistFile, (void**)&pPPF);
62 if (FAILED(rc))
63 break;
64 QString strLink = QString("%1\\%2.lnk").arg(strDstPath).arg(strName);
65 rc = pPPF->Save(strLink.utf16(), TRUE);
66 } while(0);
67 if (pPPF)
68 pPPF->Release();
69 if (pShl)
70 pShl->Release();
71 return SUCCEEDED(rc);
72}
73
74bool UIDesktopServices::openInFileManager(const QString &strFile)
75{
76 QFileInfo fi(strFile);
77 QString strTmp = QDir::toNativeSeparators(fi.absolutePath());
78
79 intptr_t rc = (intptr_t)ShellExecute(NULL, L"explore", strTmp.utf16(), NULL, NULL, SW_SHOWNORMAL);
80
81 return rc > 32 ? true : false;
82}
83
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use