[34401] | 1 | /* $Id: UIDesktopServices_nix.cpp 101571 2023-10-24 00:48:20Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
[52727] | 3 | * VBox Qt GUI - Qt GUI - Utility Classes and Functions specific to X11..
|
---|
[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 <QCoreApplication>
|
---|
| 33 | #include <QDesktopServices>
|
---|
| 34 | #include <QDir>
|
---|
| 35 | #include <QFile>
|
---|
| 36 | #include <QTextStream>
|
---|
| 37 | #include <QUrl>
|
---|
[34401] | 38 |
|
---|
[52730] | 39 |
|
---|
[74942] | 40 | bool UIDesktopServices::createMachineShortcut(const QString & /* strSrcFile */, const QString &strDstPath, const QString &strName, const QUuid &uUuid)
|
---|
[34401] | 41 | {
|
---|
| 42 | QFile link(strDstPath + QDir::separator() + strName + ".desktop");
|
---|
| 43 | if (link.open(QFile::WriteOnly | QFile::Truncate))
|
---|
| 44 | {
|
---|
[76731] | 45 | const QString strVBox = QDir::toNativeSeparators(QCoreApplication::applicationDirPath() + "/" + VBOX_GUI_VMRUNNER_IMAGE);
|
---|
[34401] | 46 | QTextStream out(&link);
|
---|
| 47 | /* Create a link which starts VirtualBox with the machine uuid. */
|
---|
[101571] | 48 | out << "[Desktop Entry]" << Qt::endl
|
---|
| 49 | << "Encoding=UTF-8" << Qt::endl
|
---|
| 50 | << "Version=1.0" << Qt::endl
|
---|
| 51 | << "Name=" << strName << Qt::endl
|
---|
| 52 | << "Comment=Starts the VirtualBox machine " << strName << Qt::endl
|
---|
| 53 | << "Type=Application" << Qt::endl
|
---|
| 54 | << "Exec=" << strVBox << " --comment \"" << strName << "\" --startvm \"" << uUuid.toString() << "\"" << Qt::endl
|
---|
| 55 | << "Icon=virtualbox-vbox.png" << Qt::endl;
|
---|
[34401] | 56 | /* This would be a real file link entry, but then we could also simply
|
---|
| 57 | * use a soft link (on most UNIX fs):
|
---|
[101571] | 58 | out << "[Desktop Entry]" << Qt::endl
|
---|
| 59 | << "Encoding=UTF-8" << Qt::endl
|
---|
| 60 | << "Version=1.0" << Qt::endl
|
---|
| 61 | << "Name=" << strName << Qt::endl
|
---|
| 62 | << "Type=Link" << Qt::endl
|
---|
| 63 | << "Icon=virtualbox-vbox.png" << Qt::endl
|
---|
[34401] | 64 | */
|
---|
[34886] | 65 | link.setPermissions(link.permissions() | QFile::ExeOwner);
|
---|
[94036] | 66 | /** @todo r=bird: check status here perhaps, might've run out of disk space or
|
---|
| 67 | * some such thing... */
|
---|
[34401] | 68 | return true;
|
---|
| 69 | }
|
---|
| 70 | return false;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | bool UIDesktopServices::openInFileManager(const QString &strFile)
|
---|
| 74 | {
|
---|
| 75 | QFileInfo fi(strFile);
|
---|
[34462] | 76 | return QDesktopServices::openUrl(QUrl("file://" + QDir::toNativeSeparators(fi.absolutePath()), QUrl::TolerantMode));
|
---|
[34401] | 77 | }
|
---|
| 78 |
|
---|