1 | /* $Id: UIDesktopServices_nix.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - Qt GUI - Utility Classes and Functions specific to X11..
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2024 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 <QCoreApplication>
|
---|
33 | #include <QDesktopServices>
|
---|
34 | #include <QDir>
|
---|
35 | #include <QFile>
|
---|
36 | #include <QTextStream>
|
---|
37 | #include <QUrl>
|
---|
38 |
|
---|
39 |
|
---|
40 | bool UIDesktopServices::createMachineShortcut(const QString & /* strSrcFile */, const QString &strDstPath, const QString &strName, const QUuid &uUuid)
|
---|
41 | {
|
---|
42 | QFile link(strDstPath + QDir::separator() + strName + ".desktop");
|
---|
43 | if (link.open(QFile::WriteOnly | QFile::Truncate))
|
---|
44 | {
|
---|
45 | const QString strVBox = QDir::toNativeSeparators(QCoreApplication::applicationDirPath() + "/" + VBOX_GUI_VMRUNNER_IMAGE);
|
---|
46 | QTextStream out(&link);
|
---|
47 | /* Create a link which starts VirtualBox with the machine uuid. */
|
---|
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;
|
---|
56 | /* This would be a real file link entry, but then we could also simply
|
---|
57 | * use a soft link (on most UNIX fs):
|
---|
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
|
---|
64 | */
|
---|
65 | link.setPermissions(link.permissions() | QFile::ExeOwner);
|
---|
66 | /** @todo r=bird: check status here perhaps, might've run out of disk space or
|
---|
67 | * some such thing... */
|
---|
68 | return true;
|
---|
69 | }
|
---|
70 | return false;
|
---|
71 | }
|
---|
72 |
|
---|
73 | bool UIDesktopServices::openInFileManager(const QString &strFile)
|
---|
74 | {
|
---|
75 | QFileInfo fi(strFile);
|
---|
76 | return QDesktopServices::openUrl(QUrl("file://" + QDir::toNativeSeparators(fi.absolutePath()), QUrl::TolerantMode));
|
---|
77 | }
|
---|
78 |
|
---|