/third_party/virtualbox/src/VBox/Frontends/VirtualBox/src/platform/x11/UIDesktopServices_x11.cpp

https://github.com/thalium/icebox · C++ · 72 lines · 36 code · 9 blank · 27 comment · 1 complexity · f9e3dc7dadd7c1b1542431651ef556e6 MD5 · raw file

  1. /* $Id: UIDesktopServices_x11.cpp $ */
  2. /** @file
  3. * VBox Qt GUI - Qt GUI - Utility Classes and Functions specific to X11..
  4. */
  5. /*
  6. * Copyright (C) 2010-2017 Oracle Corporation
  7. *
  8. * This file is part of VirtualBox Open Source Edition (OSE), as
  9. * available from http://www.virtualbox.org. This file is free software;
  10. * you can redistribute it and/or modify it under the terms of the GNU
  11. * General Public License (GPL) as published by the Free Software
  12. * Foundation, in version 2 as it comes in the "COPYING" file of the
  13. * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
  14. * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
  15. */
  16. #ifdef VBOX_WITH_PRECOMPILED_HEADERS
  17. # include <precomp.h>
  18. #else /* !VBOX_WITH_PRECOMPILED_HEADERS */
  19. /* VBox includes */
  20. # include "UIDesktopServices.h"
  21. /* Qt includes */
  22. # include <QCoreApplication>
  23. # include <QDesktopServices>
  24. # include <QDir>
  25. # include <QFile>
  26. # include <QTextStream>
  27. # include <QUrl>
  28. #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
  29. bool UIDesktopServices::createMachineShortcut(const QString & /* strSrcFile */, const QString &strDstPath, const QString &strName, const QString &strUuid)
  30. {
  31. QFile link(strDstPath + QDir::separator() + strName + ".desktop");
  32. if (link.open(QFile::WriteOnly | QFile::Truncate))
  33. {
  34. QTextStream out(&link);
  35. out.setCodec("UTF-8");
  36. /* Create a link which starts VirtualBox with the machine uuid. */
  37. out << "[Desktop Entry]" << endl
  38. << "Encoding=UTF-8" << endl
  39. << "Version=1.0" << endl
  40. << "Name=" << strName << endl
  41. << "Comment=Starts the VirtualBox machine " << strName << endl
  42. << "Type=Application" << endl
  43. << "Exec=" << QCoreApplication::applicationFilePath() << " --comment \"" << strName << "\" --startvm \"" << strUuid << "\"" << endl
  44. << "Icon=virtualbox-vbox.png" << endl;
  45. /* This would be a real file link entry, but then we could also simply
  46. * use a soft link (on most UNIX fs):
  47. out << "[Desktop Entry]" << endl
  48. << "Encoding=UTF-8" << endl
  49. << "Version=1.0" << endl
  50. << "Name=" << strName << endl
  51. << "Type=Link" << endl
  52. << "Icon=virtualbox-vbox.png" << endl
  53. */
  54. link.setPermissions(link.permissions() | QFile::ExeOwner);
  55. return true;
  56. }
  57. return false;
  58. }
  59. bool UIDesktopServices::openInFileManager(const QString &strFile)
  60. {
  61. QFileInfo fi(strFile);
  62. return QDesktopServices::openUrl(QUrl("file://" + QDir::toNativeSeparators(fi.absolutePath()), QUrl::TolerantMode));
  63. }