[34401] | 1 | /* $Id: UIDesktopServices_win.cpp 99802 2023-05-16 00:05:16Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
[52727] | 3 | * VBox Qt GUI - Qt GUI - Utility Classes and Functions specific to Windows..
|
---|
[34401] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2010-2023 Oracle and/or its affiliates.
|
---|
[34401] | 8 | *
|
---|
[96407] | 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
|
---|
[34401] | 26 | */
|
---|
| 27 |
|
---|
| 28 | /* VBox includes */
|
---|
[76606] | 29 | #include "UIDesktopServices.h"
|
---|
[34401] | 30 |
|
---|
| 31 | /* Qt includes */
|
---|
[76606] | 32 | #include <QDir>
|
---|
| 33 | #include <QCoreApplication>
|
---|
| 34 | #include <QUuid>
|
---|
[34401] | 35 |
|
---|
| 36 | /* System includes */
|
---|
[76606] | 37 | #include <iprt/win/shlobj.h>
|
---|
[34401] | 38 |
|
---|
[52730] | 39 |
|
---|
[74942] | 40 | bool UIDesktopServices::createMachineShortcut(const QString & /* strSrcFile */, const QString &strDstPath, const QString &strName, const QUuid &uUuid)
|
---|
[34401] | 41 | {
|
---|
| 42 | IShellLink *pShl = NULL;
|
---|
| 43 | IPersistFile *pPPF = NULL;
|
---|
[76731] | 44 | const QString strVBox = QDir::toNativeSeparators(QCoreApplication::applicationDirPath() + "/" + VBOX_GUI_VMRUNNER_IMAGE);
|
---|
[34401] | 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 | {
|
---|
[99802] | 52 | /** @todo Not really BSTR, so using PCWSTR, but whatever... */
|
---|
| 53 | rc = pShl->SetPath((PCWSTR)strVBox.utf16());
|
---|
[34401] | 54 | if (FAILED(rc))
|
---|
| 55 | break;
|
---|
[99802] | 56 | rc = pShl->SetWorkingDirectory((PCWSTR)strVBoxDir.utf16());
|
---|
[34401] | 57 | if (FAILED(rc))
|
---|
| 58 | break;
|
---|
[74942] | 59 | QString strArgs = QString("--comment \"%1\" --startvm \"%2\"").arg(strName).arg(uUuid.toString());
|
---|
[99802] | 60 | rc = pShl->SetArguments((PCWSTR)strArgs.utf16());
|
---|
[34401] | 61 | if (FAILED(rc))
|
---|
| 62 | break;
|
---|
| 63 | QString strDesc = QString("Starts the VirtualBox machine %1").arg(strName);
|
---|
[99802] | 64 | rc = pShl->SetDescription((PCWSTR)strDesc.utf16());
|
---|
[34401] | 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);
|
---|
[99802] | 71 | rc = pPPF->Save((PCWSTR)strLink.utf16(), TRUE);
|
---|
[34401] | 72 | } while(0);
|
---|
| 73 | if (pPPF)
|
---|
| 74 | pPPF->Release();
|
---|
| 75 | if (pShl)
|
---|
| 76 | pShl->Release();
|
---|
[34415] | 77 | return SUCCEEDED(rc);
|
---|
[34401] | 78 | }
|
---|
| 79 |
|
---|
| 80 | bool UIDesktopServices::openInFileManager(const QString &strFile)
|
---|
| 81 | {
|
---|
| 82 | QFileInfo fi(strFile);
|
---|
| 83 | QString strTmp = QDir::toNativeSeparators(fi.absolutePath());
|
---|
| 84 |
|
---|
[99802] | 85 | intptr_t rc = (intptr_t)ShellExecute(NULL, L"explore", (PCWSTR)strTmp.utf16(), NULL, NULL, SW_SHOWNORMAL);
|
---|
[34401] | 86 |
|
---|
| 87 | return rc > 32 ? true : false;
|
---|
| 88 | }
|
---|
| 89 |
|
---|