1
/* $Id: UIMachineSettingsGeneral.cpp $ */
4
* VBox frontends: Qt4 GUI ("VirtualBox"):
5
* UIMachineSettingsGeneral class implementation
9
* Copyright (C) 2006-2012 Oracle Corporation
11
* This file is part of VirtualBox Open Source Edition (OSE), as
12
* available from http://www.virtualbox.org. This file is free software;
13
* you can redistribute it and/or modify it under the terms of the GNU
14
* General Public License (GPL) as published by the Free Software
15
* Foundation, in version 2 as it comes in the "COPYING" file of the
16
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
25
#include "UIMachineSettingsGeneral.h"
26
#include "UIMessageCenter.h"
27
#include "QIWidgetValidator.h"
28
#include "UIConverter.h"
30
UIMachineSettingsGeneral::UIMachineSettingsGeneral()
31
: m_fHWVirtExEnabled(false)
33
/* Apply UI decorations */
34
Ui::UIMachineSettingsGeneral::setupUi (this);
36
/* Setup validators */
37
m_pNameAndSystemEditor->nameEditor()->setValidator(new QRegExpValidator(QRegExp(".+"), this));
39
/* Shared Clipboard mode */
40
mCbClipboard->addItem (""); /* KClipboardMode_Disabled */
41
mCbClipboard->addItem (""); /* KClipboardMode_HostToGuest */
42
mCbClipboard->addItem (""); /* KClipboardMode_GuestToHost */
43
mCbClipboard->addItem (""); /* KClipboardMode_Bidirectional */
45
/* Drag'n'drop mode */
46
mCbDragAndDrop->addItem (""); /* KDragAndDropMode_Disabled */
47
mCbDragAndDrop->addItem (""); /* KDragAndDropMode_HostToGuest */
48
mCbDragAndDrop->addItem (""); /* KDragAndDropMode_GuestToHost */
49
mCbDragAndDrop->addItem (""); /* KDragAndDropMode_Bidirectional */
52
mTeDescription->setMinimumHeight (150);
55
/* Prepare validation: */
58
/* Applying language settings */
62
CGuestOSType UIMachineSettingsGeneral::guestOSType() const
64
return m_pNameAndSystemEditor->type();
67
void UIMachineSettingsGeneral::setHWVirtExEnabled(bool fEnabled)
69
/* Make sure hardware virtualization extension has changed: */
70
if (m_fHWVirtExEnabled == fEnabled)
73
/* Update hardware virtualization extension value: */
74
m_fHWVirtExEnabled = fEnabled;
80
bool UIMachineSettingsGeneral::is64BitOSTypeSelected() const
82
return m_pNameAndSystemEditor->type().GetIs64Bit();
85
#ifdef VBOX_WITH_VIDEOHWACCEL
86
bool UIMachineSettingsGeneral::isWindowsOSTypeSelected() const
88
return m_pNameAndSystemEditor->type().GetFamilyId() == "Windows";
90
#endif /* VBOX_WITH_VIDEOHWACCEL */
92
/* Load data to cache from corresponding external object(s),
93
* this task COULD be performed in other than GUI thread: */
94
void UIMachineSettingsGeneral::loadToCacheFrom(QVariant &data)
96
/* Fetch data to machine: */
97
UISettingsPageMachine::fetchData(data);
99
/* Clear cache initially: */
102
/* Prepare general data: */
103
UIDataSettingsMachineGeneral generalData;
105
/* Gather general data: */
106
generalData.m_strName = m_machine.GetName();
107
generalData.m_strGuestOsTypeId = m_machine.GetOSTypeId();
108
QString strSaveMountedAtRuntime = m_machine.GetExtraData(GUI_SaveMountedAtRuntime);
109
generalData.m_fSaveMountedAtRuntime = strSaveMountedAtRuntime != "no";
110
QString strShowMiniToolBar = m_machine.GetExtraData(GUI_ShowMiniToolBar);
111
generalData.m_fShowMiniToolBar = strShowMiniToolBar != "no";
112
QString strMiniToolBarAlignment = m_machine.GetExtraData(GUI_MiniToolBarAlignment);
113
generalData.m_fMiniToolBarAtTop = strMiniToolBarAlignment == "top";
114
generalData.m_strSnapshotsFolder = m_machine.GetSnapshotFolder();
115
generalData.m_strSnapshotsHomeDir = QFileInfo(m_machine.GetSettingsFilePath()).absolutePath();
116
generalData.m_clipboardMode = m_machine.GetClipboardMode();
117
generalData.m_dragAndDropMode = m_machine.GetDragAndDropMode();
118
generalData.m_strDescription = m_machine.GetDescription();
120
/* Cache general data: */
121
m_cache.cacheInitialData(generalData);
123
/* Upload machine to data: */
124
UISettingsPageMachine::uploadData(data);
127
/* Load data to corresponding widgets from cache,
128
* this task SHOULD be performed in GUI thread only: */
129
void UIMachineSettingsGeneral::getFromCache()
131
/* Get general data from cache: */
132
const UIDataSettingsMachineGeneral &generalData = m_cache.base();
134
/* Load general data to page: */
135
m_pNameAndSystemEditor->setName(generalData.m_strName);
136
m_pNameAndSystemEditor->setType(vboxGlobal().vmGuestOSType(generalData.m_strGuestOsTypeId));
137
mCbSaveMounted->setChecked(generalData.m_fSaveMountedAtRuntime);
138
mCbShowToolBar->setChecked(generalData.m_fShowMiniToolBar);
139
mCbToolBarAlignment->setChecked(generalData.m_fMiniToolBarAtTop);
140
mPsSnapshot->setPath(generalData.m_strSnapshotsFolder);
141
mPsSnapshot->setHomeDir(generalData.m_strSnapshotsHomeDir);
142
mCbClipboard->setCurrentIndex(generalData.m_clipboardMode);
143
mCbDragAndDrop->setCurrentIndex(generalData.m_dragAndDropMode);
144
mTeDescription->setPlainText(generalData.m_strDescription);
146
/* Polish page finally: */
153
/* Save data from corresponding widgets to cache,
154
* this task SHOULD be performed in GUI thread only: */
155
void UIMachineSettingsGeneral::putToCache()
157
/* Prepare general data: */
158
UIDataSettingsMachineGeneral generalData = m_cache.base();
160
/* Gather general data: */
161
generalData.m_strName = m_pNameAndSystemEditor->name();
162
generalData.m_strGuestOsTypeId = m_pNameAndSystemEditor->type().GetId();
163
generalData.m_fSaveMountedAtRuntime = mCbSaveMounted->isChecked();
164
generalData.m_fShowMiniToolBar = mCbShowToolBar->isChecked();
165
generalData.m_fMiniToolBarAtTop = mCbToolBarAlignment->isChecked();
166
generalData.m_strSnapshotsFolder = mPsSnapshot->path();
167
generalData.m_clipboardMode = (KClipboardMode)mCbClipboard->currentIndex();
168
generalData.m_dragAndDropMode = (KDragAndDropMode)mCbDragAndDrop->currentIndex();
169
generalData.m_strDescription = mTeDescription->toPlainText().isEmpty() ?
170
QString::null : mTeDescription->toPlainText();
172
/* Cache general data: */
173
m_cache.cacheCurrentData(generalData);
176
/* Save data from cache to corresponding external object(s),
177
* this task COULD be performed in other than GUI thread: */
178
void UIMachineSettingsGeneral::saveFromCacheTo(QVariant &data)
180
/* Fetch data to machine: */
181
UISettingsPageMachine::fetchData(data);
183
/* Check if general data was changed: */
184
if (m_cache.wasChanged())
186
/* Get general data from cache: */
187
const UIDataSettingsMachineGeneral &generalData = m_cache.data();
189
/* Store general data: */
190
if (isMachineInValidMode())
193
m_machine.SetClipboardMode(generalData.m_clipboardMode);
194
m_machine.SetDragAndDropMode(generalData.m_dragAndDropMode);
195
m_machine.SetExtraData(GUI_SaveMountedAtRuntime, generalData.m_fSaveMountedAtRuntime ? "yes" : "no");
196
m_machine.SetExtraData(GUI_ShowMiniToolBar, generalData.m_fShowMiniToolBar ? "yes" : "no");
197
m_machine.SetExtraData(GUI_MiniToolBarAlignment, generalData.m_fMiniToolBarAtTop ? "top" : "bottom");
198
/* Description tab: */
199
m_machine.SetDescription(generalData.m_strDescription);
201
if (isMachineOffline())
203
/* Basic tab: Must update long mode CPU feature bit when os type changes. */
204
if (generalData.m_strGuestOsTypeId != m_cache.base().m_strGuestOsTypeId)
206
m_machine.SetOSTypeId(generalData.m_strGuestOsTypeId);
208
CVirtualBox vbox = vboxGlobal().virtualBox();
209
CGuestOSType newType = vbox.GetGuestOSType(generalData.m_strGuestOsTypeId);
210
m_machine.SetCPUProperty(KCPUPropertyType_LongMode, newType.GetIs64Bit());
214
m_machine.SetSnapshotFolder(generalData.m_strSnapshotsFolder);
215
/* Basic (again) tab: */
216
/* VM name must be last as otherwise its VM rename magic can collide with other settings in the config,
217
* especially with the snapshot folder: */
218
m_machine.SetName(generalData.m_strName);
222
/* Upload machine to data: */
223
UISettingsPageMachine::uploadData(data);
226
bool UIMachineSettingsGeneral::validate(QList<UIValidationMessage> &messages)
228
/* Pass by default: */
231
/* Prepare message: */
232
UIValidationMessage message;
233
message.first = VBoxGlobal::removeAccelMark(mTwGeneral->tabText(0));
235
/* VM name validation: */
236
if (m_pNameAndSystemEditor->name().trimmed().isEmpty())
238
message.second << tr("No name specified for the virtual machine.");
242
/* OS type & VT-x/AMD-v correlation: */
243
if (is64BitOSTypeSelected() && !m_fHWVirtExEnabled)
245
message.second << tr("The virtual machine operating system hint is set to a 64-bit type. "
246
"64-bit guest systems require hardware virtualization, "
247
"so this will be enabled automatically if you confirm the changes.");
250
/* Serialize message: */
251
if (!message.second.isEmpty())
258
void UIMachineSettingsGeneral::setOrderAfter (QWidget *aWidget)
260
/* Basic tab-order */
261
setTabOrder (aWidget, mTwGeneral->focusProxy());
262
setTabOrder (mTwGeneral->focusProxy(), m_pNameAndSystemEditor);
264
/* Advanced tab-order */
265
setTabOrder (m_pNameAndSystemEditor, mPsSnapshot);
266
setTabOrder (mPsSnapshot, mCbClipboard);
267
setTabOrder (mCbClipboard, mCbDragAndDrop);
268
setTabOrder (mCbDragAndDrop, mCbSaveMounted);
269
setTabOrder (mCbSaveMounted, mCbShowToolBar);
270
setTabOrder (mCbShowToolBar, mCbToolBarAlignment);
272
/* Description tab-order */
273
setTabOrder (mCbToolBarAlignment, mTeDescription);
276
void UIMachineSettingsGeneral::retranslateUi()
278
/* Translate uic generated strings */
279
Ui::UIMachineSettingsGeneral::retranslateUi (this);
282
mPsSnapshot->setWhatsThis (tr ("Holds the path where snapshots of this "
283
"virtual machine will be stored. Be aware that "
284
"snapshots can take quite a lot of disk "
287
/* Shared Clipboard mode */
288
mCbClipboard->setItemText (0, gpConverter->toString (KClipboardMode_Disabled));
289
mCbClipboard->setItemText (1, gpConverter->toString (KClipboardMode_HostToGuest));
290
mCbClipboard->setItemText (2, gpConverter->toString (KClipboardMode_GuestToHost));
291
mCbClipboard->setItemText (3, gpConverter->toString (KClipboardMode_Bidirectional));
293
/* Drag'n'drop mode */
294
mCbDragAndDrop->setItemText (0, gpConverter->toString (KDragAndDropMode_Disabled));
295
mCbDragAndDrop->setItemText (1, gpConverter->toString (KDragAndDropMode_HostToGuest));
296
mCbDragAndDrop->setItemText (2, gpConverter->toString (KDragAndDropMode_GuestToHost));
297
mCbDragAndDrop->setItemText (3, gpConverter->toString (KDragAndDropMode_Bidirectional));
300
void UIMachineSettingsGeneral::prepareValidation()
302
/* Prepare validation: */
303
connect(m_pNameAndSystemEditor, SIGNAL(sigOsTypeChanged()), this, SLOT(revalidate()));
304
connect(m_pNameAndSystemEditor, SIGNAL(sigNameChanged(const QString&)), this, SLOT(revalidate()));
307
void UIMachineSettingsGeneral::polishPage()
310
m_pNameAndSystemEditor->setEnabled(isMachineOffline());
312
mLbSnapshot->setEnabled(isMachineOffline());
313
mPsSnapshot->setEnabled(isMachineOffline());
314
mLbClipboard->setEnabled(isMachineInValidMode());
315
mCbClipboard->setEnabled(isMachineInValidMode());
316
mLbDragAndDrop->setEnabled(isMachineInValidMode());
317
mCbDragAndDrop->setEnabled(isMachineInValidMode());
318
mLbMedia->setEnabled(isMachineInValidMode());
319
mCbSaveMounted->setEnabled(isMachineInValidMode());
320
mLbToolBar->setEnabled(isMachineInValidMode());
321
mCbShowToolBar->setEnabled(isMachineInValidMode());
322
mCbToolBarAlignment->setEnabled(isMachineInValidMode() && mCbShowToolBar->isChecked());