VirtualBox

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

Last change on this file since 76606 was 76606, checked in by vboxsync, 5 years ago

FE/Qt: Cleaning out old precompiled header experiment.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.6 KB
Line 
1/* $Id: UIDesktopServices_win.cpp 76606 2019-01-02 05:40:39Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - Qt GUI - Utility Classes and Functions specific to Windows..
4 */
5
6/*
7 * Copyright (C) 2010-2019 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/* VBox includes */
19#include "UIDesktopServices.h"
20
21/* Qt includes */
22#include <QDir>
23#include <QCoreApplication>
24#include <QUuid>
25
26/* System includes */
27#include <iprt/win/shlobj.h>
28
29
30bool UIDesktopServices::createMachineShortcut(const QString & /* strSrcFile */, const QString &strDstPath, const QString &strName, const QUuid &uUuid)
31{
32 IShellLink *pShl = NULL;
33 IPersistFile *pPPF = NULL;
34 QString strVBox = QDir::toNativeSeparators(QCoreApplication::applicationFilePath());
35 QFileInfo fi(strVBox);
36 QString strVBoxDir = QDir::toNativeSeparators(fi.absolutePath());
37 HRESULT rc = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)(&pShl));
38 if (FAILED(rc))
39 return false;
40 do
41 {
42 rc = pShl->SetPath(strVBox.utf16());
43 if (FAILED(rc))
44 break;
45 rc = pShl->SetWorkingDirectory(strVBoxDir.utf16());
46 if (FAILED(rc))
47 break;
48 QString strArgs = QString("--comment \"%1\" --startvm \"%2\"").arg(strName).arg(uUuid.toString());
49 rc = pShl->SetArguments(strArgs.utf16());
50 if (FAILED(rc))
51 break;
52 QString strDesc = QString("Starts the VirtualBox machine %1").arg(strName);
53 rc = pShl->SetDescription(strDesc.utf16());
54 if (FAILED(rc))
55 break;
56 rc = pShl->QueryInterface(IID_IPersistFile, (void**)&pPPF);
57 if (FAILED(rc))
58 break;
59 QString strLink = QString("%1\\%2.lnk").arg(strDstPath).arg(strName);
60 rc = pPPF->Save(strLink.utf16(), TRUE);
61 } while(0);
62 if (pPPF)
63 pPPF->Release();
64 if (pShl)
65 pShl->Release();
66 return SUCCEEDED(rc);
67}
68
69bool UIDesktopServices::openInFileManager(const QString &strFile)
70{
71 QFileInfo fi(strFile);
72 QString strTmp = QDir::toNativeSeparators(fi.absolutePath());
73
74 intptr_t rc = (intptr_t)ShellExecute(NULL, L"explore", strTmp.utf16(), NULL, NULL, SW_SHOWNORMAL);
75
76 return rc > 32 ? true : false;
77}
78
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use