1 | /* $Id: UIDesktopServices_x11.cpp 76606 2019-01-02 05:40:39Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - Qt GUI - Utility Classes and Functions specific to X11..
|
---|
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 <QCoreApplication>
|
---|
23 | #include <QDesktopServices>
|
---|
24 | #include <QDir>
|
---|
25 | #include <QFile>
|
---|
26 | #include <QTextStream>
|
---|
27 | #include <QUrl>
|
---|
28 |
|
---|
29 |
|
---|
30 | bool UIDesktopServices::createMachineShortcut(const QString & /* strSrcFile */, const QString &strDstPath, const QString &strName, const QUuid &uUuid)
|
---|
31 | {
|
---|
32 | QFile link(strDstPath + QDir::separator() + strName + ".desktop");
|
---|
33 | if (link.open(QFile::WriteOnly | QFile::Truncate))
|
---|
34 | {
|
---|
35 | QTextStream out(&link);
|
---|
36 | out.setCodec("UTF-8");
|
---|
37 | /* Create a link which starts VirtualBox with the machine uuid. */
|
---|
38 | out << "[Desktop Entry]" << endl
|
---|
39 | << "Encoding=UTF-8" << endl
|
---|
40 | << "Version=1.0" << endl
|
---|
41 | << "Name=" << strName << endl
|
---|
42 | << "Comment=Starts the VirtualBox machine " << strName << endl
|
---|
43 | << "Type=Application" << endl
|
---|
44 | << "Exec=" << QCoreApplication::applicationFilePath() << " --comment \"" << strName << "\" --startvm \"" << uUuid.toString() << "\"" << endl
|
---|
45 | << "Icon=virtualbox-vbox.png" << endl;
|
---|
46 | /* This would be a real file link entry, but then we could also simply
|
---|
47 | * use a soft link (on most UNIX fs):
|
---|
48 | out << "[Desktop Entry]" << endl
|
---|
49 | << "Encoding=UTF-8" << endl
|
---|
50 | << "Version=1.0" << endl
|
---|
51 | << "Name=" << strName << endl
|
---|
52 | << "Type=Link" << endl
|
---|
53 | << "Icon=virtualbox-vbox.png" << endl
|
---|
54 | */
|
---|
55 | link.setPermissions(link.permissions() | QFile::ExeOwner);
|
---|
56 | return true;
|
---|
57 | }
|
---|
58 | return false;
|
---|
59 | }
|
---|
60 |
|
---|
61 | bool UIDesktopServices::openInFileManager(const QString &strFile)
|
---|
62 | {
|
---|
63 | QFileInfo fi(strFile);
|
---|
64 | return QDesktopServices::openUrl(QUrl("file://" + QDir::toNativeSeparators(fi.absolutePath()), QUrl::TolerantMode));
|
---|
65 | }
|
---|
66 |
|
---|