[34401] | 1 | /* $Id: UIDesktopServices_x11.cpp 74878 2018-10-17 13:34:24Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
[52727] | 3 | * VBox Qt GUI - Qt GUI - Utility Classes and Functions specific to X11..
|
---|
[34401] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[69500] | 7 | * Copyright (C) 2010-2017 Oracle Corporation
|
---|
[34401] | 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 |
|
---|
[52730] | 18 | #ifdef VBOX_WITH_PRECOMPILED_HEADERS
|
---|
| 19 | # include <precomp.h>
|
---|
| 20 | #else /* !VBOX_WITH_PRECOMPILED_HEADERS */
|
---|
| 21 |
|
---|
[34401] | 22 | /* VBox includes */
|
---|
[52730] | 23 | # include "UIDesktopServices.h"
|
---|
[34401] | 24 |
|
---|
| 25 | /* Qt includes */
|
---|
[52730] | 26 | # include <QCoreApplication>
|
---|
| 27 | # include <QDesktopServices>
|
---|
| 28 | # include <QDir>
|
---|
| 29 | # include <QFile>
|
---|
| 30 | # include <QTextStream>
|
---|
| 31 | # include <QUrl>
|
---|
[34401] | 32 |
|
---|
[52730] | 33 | #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
|
---|
| 34 |
|
---|
| 35 |
|
---|
[74878] | 36 | bool UIDesktopServices::createMachineShortcut(const QString & /* strSrcFile */, const QString &strDstPath, const QString &strName, const QUuid &aUuid)
|
---|
[34401] | 37 | {
|
---|
| 38 | QFile link(strDstPath + QDir::separator() + strName + ".desktop");
|
---|
| 39 | if (link.open(QFile::WriteOnly | QFile::Truncate))
|
---|
| 40 | {
|
---|
| 41 | QTextStream out(&link);
|
---|
| 42 | out.setCodec("UTF-8");
|
---|
| 43 | /* Create a link which starts VirtualBox with the machine uuid. */
|
---|
| 44 | out << "[Desktop Entry]" << endl
|
---|
| 45 | << "Encoding=UTF-8" << endl
|
---|
| 46 | << "Version=1.0" << endl
|
---|
| 47 | << "Name=" << strName << endl
|
---|
| 48 | << "Comment=Starts the VirtualBox machine " << strName << endl
|
---|
| 49 | << "Type=Application" << endl
|
---|
[74878] | 50 | << "Exec=" << QCoreApplication::applicationFilePath() << " --comment \"" << strName << "\" --startvm \"" << aUuid.toString() << "\"" << endl
|
---|
[34863] | 51 | << "Icon=virtualbox-vbox.png" << endl;
|
---|
[34401] | 52 | /* This would be a real file link entry, but then we could also simply
|
---|
| 53 | * use a soft link (on most UNIX fs):
|
---|
| 54 | out << "[Desktop Entry]" << endl
|
---|
| 55 | << "Encoding=UTF-8" << endl
|
---|
| 56 | << "Version=1.0" << endl
|
---|
| 57 | << "Name=" << strName << endl
|
---|
| 58 | << "Type=Link" << endl
|
---|
[34863] | 59 | << "Icon=virtualbox-vbox.png" << endl
|
---|
[34401] | 60 | */
|
---|
[34886] | 61 | link.setPermissions(link.permissions() | QFile::ExeOwner);
|
---|
[34401] | 62 | return true;
|
---|
| 63 | }
|
---|
| 64 | return false;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | bool UIDesktopServices::openInFileManager(const QString &strFile)
|
---|
| 68 | {
|
---|
| 69 | QFileInfo fi(strFile);
|
---|
[34462] | 70 | return QDesktopServices::openUrl(QUrl("file://" + QDir::toNativeSeparators(fi.absolutePath()), QUrl::TolerantMode));
|
---|
[34401] | 71 | }
|
---|
| 72 |
|
---|