/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsGeneral.cpp

https://gitlab.com/ufo/virtualbox-ose-3-1-8 · C++ · 184 lines · 102 code · 37 blank · 45 comment · 7 complexity · 9f5e78c8fbc9064adb7fa1f454edeff6 MD5 · raw file

  1. /** @file
  2. *
  3. * VBox frontends: Qt4 GUI ("VirtualBox"):
  4. * VBoxVMSettingsGeneral class implementation
  5. */
  6. /*
  7. * Copyright (C) 2006-2008 Sun Microsystems, Inc.
  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. * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
  18. * Clara, CA 95054 USA or visit http://www.sun.com if you need
  19. * additional information or have any questions.
  20. */
  21. #include "VBoxVMSettingsGeneral.h"
  22. #include "VBoxGlobal.h"
  23. #include "VBoxProblemReporter.h"
  24. #include "QIWidgetValidator.h"
  25. #include <QDir>
  26. VBoxVMSettingsGeneral::VBoxVMSettingsGeneral()
  27. : mValidator (0)
  28. {
  29. /* Apply UI decorations */
  30. Ui::VBoxVMSettingsGeneral::setupUi (this);
  31. /* Setup validators */
  32. mLeName->setValidator (new QRegExpValidator (QRegExp (".+"), this));
  33. /* Shared Clipboard mode */
  34. mCbClipboard->addItem (""); /* KClipboardMode_Disabled */
  35. mCbClipboard->addItem (""); /* KClipboardMode_HostToGuest */
  36. mCbClipboard->addItem (""); /* KClipboardMode_GuestToHost */
  37. mCbClipboard->addItem (""); /* KClipboardMode_Bidirectional */
  38. #ifdef Q_WS_MAC
  39. mTeDescription->setMinimumHeight (150);
  40. #endif /* Q_WS_MAC */
  41. /* Applying language settings */
  42. retranslateUi();
  43. }
  44. bool VBoxVMSettingsGeneral::is64BitOSTypeSelected() const
  45. {
  46. return mOSTypeSelector->type().GetIs64Bit();
  47. }
  48. #ifdef VBOX_WITH_VIDEOHWACCEL
  49. bool VBoxVMSettingsGeneral::isWindowsOSTypeSelected() const
  50. {
  51. return mOSTypeSelector->type().GetFamilyId() == "Windows";
  52. }
  53. #endif
  54. void VBoxVMSettingsGeneral::getFrom (const CMachine &aMachine)
  55. {
  56. mMachine = aMachine;
  57. /* Name */
  58. mLeName->setText (aMachine.GetName());
  59. /* OS type */
  60. mOSTypeSelector->setType (vboxGlobal().vmGuestOSType (aMachine.GetOSTypeId()));
  61. /* Remember mediums mounted at runtime */
  62. QString saveRtimeImages = mMachine.GetExtraData (VBoxDefs::GUI_SaveMountedAtRuntime);
  63. mCbSaveMounted->setChecked (saveRtimeImages != "no");
  64. /* Show Mini ToolBar in fullscreen/seamless */
  65. QString showMiniToolBar = mMachine.GetExtraData (VBoxDefs::GUI_ShowMiniToolBar);
  66. mCbShowToolBar->setChecked (showMiniToolBar != "no");
  67. /* Show Mini ToolBar at top */
  68. QString miniToolBarAlignment = mMachine.GetExtraData (VBoxDefs::GUI_MiniToolBarAlignment);
  69. mCbToolBarAlignment->setChecked (miniToolBarAlignment == "top");
  70. mCbToolBarAlignment->setEnabled (mCbShowToolBar->isChecked());
  71. /* Snapshot folder */
  72. mPsSnapshot->setPath (aMachine.GetSnapshotFolder());
  73. mPsSnapshot->setHomeDir (QFileInfo (mMachine.GetSettingsFilePath()).absolutePath());
  74. /* Shared clipboard mode */
  75. mCbClipboard->setCurrentIndex (aMachine.GetClipboardMode());
  76. /* Description */
  77. mTeDescription->setPlainText (aMachine.GetDescription());
  78. if (mValidator)
  79. mValidator->revalidate();
  80. }
  81. void VBoxVMSettingsGeneral::putBackTo()
  82. {
  83. /* Name */
  84. mMachine.SetName (mLeName->text());
  85. /* OS type */
  86. AssertMsg (!mOSTypeSelector->type().isNull(), ("mOSTypeSelector must return non-null type"));
  87. mMachine.SetOSTypeId (mOSTypeSelector->type().GetId());
  88. /* Remember mediums mounted at runtime */
  89. mMachine.SetExtraData (VBoxDefs::GUI_SaveMountedAtRuntime,
  90. mCbSaveMounted->isChecked() ? "yes" : "no");
  91. /* Show Mini ToolBar in fullscreen/seamless */
  92. mMachine.SetExtraData (VBoxDefs::GUI_ShowMiniToolBar,
  93. mCbShowToolBar->isChecked() ? "yes" : "no");
  94. /* Show Mini ToolBar at top */
  95. mMachine.SetExtraData (VBoxDefs::GUI_MiniToolBarAlignment,
  96. mCbToolBarAlignment->isChecked() ? "top" : "bottom");
  97. /* Saved state folder */
  98. if (mPsSnapshot->isModified())
  99. {
  100. mMachine.SetSnapshotFolder (mPsSnapshot->path());
  101. if (!mMachine.isOk())
  102. vboxProblem().cannotSetSnapshotFolder (mMachine,
  103. QDir::toNativeSeparators (mPsSnapshot->path()));
  104. }
  105. /* Shared clipboard mode */
  106. mMachine.SetClipboardMode ((KClipboardMode) mCbClipboard->currentIndex());
  107. /* Description (set empty to null to avoid an empty <Description> node
  108. * in the settings file) */
  109. mMachine.SetDescription (mTeDescription->toPlainText().isEmpty() ?
  110. QString::null : mTeDescription->toPlainText());
  111. }
  112. void VBoxVMSettingsGeneral::setValidator (QIWidgetValidator *aVal)
  113. {
  114. mValidator = aVal;
  115. connect (mOSTypeSelector, SIGNAL (osTypeChanged()), mValidator, SLOT (revalidate()));
  116. }
  117. void VBoxVMSettingsGeneral::setOrderAfter (QWidget *aWidget)
  118. {
  119. /* Setup Tab order */
  120. setTabOrder (aWidget, mTwGeneral->focusProxy());
  121. setTabOrder (mTwGeneral->focusProxy(), mLeName);
  122. setTabOrder (mLeName, mOSTypeSelector);
  123. setTabOrder (mOSTypeSelector, mPsSnapshot);
  124. setTabOrder (mPsSnapshot, mCbClipboard);
  125. setTabOrder (mCbClipboard, mCbSaveMounted);
  126. setTabOrder (mCbSaveMounted, mTeDescription);
  127. }
  128. void VBoxVMSettingsGeneral::retranslateUi()
  129. {
  130. /* Translate uic generated strings */
  131. Ui::VBoxVMSettingsGeneral::retranslateUi (this);
  132. /* Path selector */
  133. mPsSnapshot->setWhatsThis (tr ("Displays the path where snapshots of this "
  134. "virtual machine will be stored. Be aware that "
  135. "snapshots can take quite a lot of disk "
  136. "space."));
  137. /* Shared Clipboard mode */
  138. mCbClipboard->setItemText (0, vboxGlobal().toString (KClipboardMode_Disabled));
  139. mCbClipboard->setItemText (1, vboxGlobal().toString (KClipboardMode_HostToGuest));
  140. mCbClipboard->setItemText (2, vboxGlobal().toString (KClipboardMode_GuestToHost));
  141. mCbClipboard->setItemText (3, vboxGlobal().toString (KClipboardMode_Bidirectional));
  142. }
  143. void VBoxVMSettingsGeneral::showEvent (QShowEvent *aEvent)
  144. {
  145. QCoreApplication::sendPostedEvents();
  146. VBoxSettingsPage::showEvent (aEvent);
  147. }