~ubuntu-branches/ubuntu/trusty/virtualbox-lts-xenial/trusty-updates

« back to all changes in this revision

Viewing changes to src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsGeneral.cpp

  • Committer: Package Import Robot
  • Author(s): Gianfranco Costamagna
  • Date: 2016-02-23 14:28:26 UTC
  • Revision ID: package-import@ubuntu.com-20160223142826-bdu69el2z6wa2a44
Tags: upstream-4.3.36-dfsg
ImportĀ upstreamĀ versionĀ 4.3.36-dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: UIMachineSettingsGeneral.cpp $ */
 
2
/** @file
 
3
 *
 
4
 * VBox frontends: Qt4 GUI ("VirtualBox"):
 
5
 * UIMachineSettingsGeneral class implementation
 
6
 */
 
7
 
 
8
/*
 
9
 * Copyright (C) 2006-2012 Oracle Corporation
 
10
 *
 
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.
 
18
 */
 
19
 
 
20
/* Qt includes: */
 
21
#include <QDir>
 
22
#include <QLineEdit>
 
23
 
 
24
/* GUI includes: */
 
25
#include "UIMachineSettingsGeneral.h"
 
26
#include "UIMessageCenter.h"
 
27
#include "QIWidgetValidator.h"
 
28
#include "UIConverter.h"
 
29
 
 
30
UIMachineSettingsGeneral::UIMachineSettingsGeneral()
 
31
    : m_fHWVirtExEnabled(false)
 
32
{
 
33
    /* Apply UI decorations */
 
34
    Ui::UIMachineSettingsGeneral::setupUi (this);
 
35
 
 
36
    /* Setup validators */
 
37
    m_pNameAndSystemEditor->nameEditor()->setValidator(new QRegExpValidator(QRegExp(".+"), this));
 
38
 
 
39
    /* Shared Clipboard mode */
 
40
    mCbClipboard->addItem (""); /* KClipboardMode_Disabled */
 
41
    mCbClipboard->addItem (""); /* KClipboardMode_HostToGuest */
 
42
    mCbClipboard->addItem (""); /* KClipboardMode_GuestToHost */
 
43
    mCbClipboard->addItem (""); /* KClipboardMode_Bidirectional */
 
44
 
 
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 */
 
50
 
 
51
#ifdef Q_WS_MAC
 
52
    mTeDescription->setMinimumHeight (150);
 
53
#endif /* Q_WS_MAC */
 
54
 
 
55
    /* Prepare validation: */
 
56
    prepareValidation();
 
57
 
 
58
    /* Applying language settings */
 
59
    retranslateUi();
 
60
}
 
61
 
 
62
CGuestOSType UIMachineSettingsGeneral::guestOSType() const
 
63
{
 
64
    return m_pNameAndSystemEditor->type();
 
65
}
 
66
 
 
67
void UIMachineSettingsGeneral::setHWVirtExEnabled(bool fEnabled)
 
68
{
 
69
    /* Make sure hardware virtualization extension has changed: */
 
70
    if (m_fHWVirtExEnabled == fEnabled)
 
71
        return;
 
72
 
 
73
    /* Update hardware virtualization extension value: */
 
74
    m_fHWVirtExEnabled = fEnabled;
 
75
 
 
76
    /* Revalidate: */
 
77
    revalidate();
 
78
}
 
79
 
 
80
bool UIMachineSettingsGeneral::is64BitOSTypeSelected() const
 
81
{
 
82
    return m_pNameAndSystemEditor->type().GetIs64Bit();
 
83
}
 
84
 
 
85
#ifdef VBOX_WITH_VIDEOHWACCEL
 
86
bool UIMachineSettingsGeneral::isWindowsOSTypeSelected() const
 
87
{
 
88
    return m_pNameAndSystemEditor->type().GetFamilyId() == "Windows";
 
89
}
 
90
#endif /* VBOX_WITH_VIDEOHWACCEL */
 
91
 
 
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)
 
95
{
 
96
    /* Fetch data to machine: */
 
97
    UISettingsPageMachine::fetchData(data);
 
98
 
 
99
    /* Clear cache initially: */
 
100
    m_cache.clear();
 
101
 
 
102
    /* Prepare general data: */
 
103
    UIDataSettingsMachineGeneral generalData;
 
104
 
 
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();
 
119
 
 
120
    /* Cache general data: */
 
121
    m_cache.cacheInitialData(generalData);
 
122
 
 
123
    /* Upload machine to data: */
 
124
    UISettingsPageMachine::uploadData(data);
 
125
}
 
126
 
 
127
/* Load data to corresponding widgets from cache,
 
128
 * this task SHOULD be performed in GUI thread only: */
 
129
void UIMachineSettingsGeneral::getFromCache()
 
130
{
 
131
    /* Get general data from cache: */
 
132
    const UIDataSettingsMachineGeneral &generalData = m_cache.base();
 
133
 
 
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);
 
145
 
 
146
    /* Polish page finally: */
 
147
    polishPage();
 
148
 
 
149
    /* Revalidate: */
 
150
    revalidate();
 
151
}
 
152
 
 
153
/* Save data from corresponding widgets to cache,
 
154
 * this task SHOULD be performed in GUI thread only: */
 
155
void UIMachineSettingsGeneral::putToCache()
 
156
{
 
157
    /* Prepare general data: */
 
158
    UIDataSettingsMachineGeneral generalData = m_cache.base();
 
159
 
 
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();
 
171
 
 
172
    /* Cache general data: */
 
173
    m_cache.cacheCurrentData(generalData);
 
174
}
 
175
 
 
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)
 
179
{
 
180
    /* Fetch data to machine: */
 
181
    UISettingsPageMachine::fetchData(data);
 
182
 
 
183
    /* Check if general data was changed: */
 
184
    if (m_cache.wasChanged())
 
185
    {
 
186
        /* Get general data from cache: */
 
187
        const UIDataSettingsMachineGeneral &generalData = m_cache.data();
 
188
 
 
189
        /* Store general data: */
 
190
        if (isMachineInValidMode())
 
191
        {
 
192
            /* Advanced tab: */
 
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);
 
200
        }
 
201
        if (isMachineOffline())
 
202
        {
 
203
            /* Basic tab: Must update long mode CPU feature bit when os type changes. */
 
204
            if (generalData.m_strGuestOsTypeId != m_cache.base().m_strGuestOsTypeId)
 
205
            {
 
206
                m_machine.SetOSTypeId(generalData.m_strGuestOsTypeId);
 
207
 
 
208
                CVirtualBox vbox = vboxGlobal().virtualBox();
 
209
                CGuestOSType newType = vbox.GetGuestOSType(generalData.m_strGuestOsTypeId);
 
210
                m_machine.SetCPUProperty(KCPUPropertyType_LongMode, newType.GetIs64Bit());
 
211
            }
 
212
 
 
213
            /* Advanced tab: */
 
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);
 
219
        }
 
220
    }
 
221
 
 
222
    /* Upload machine to data: */
 
223
    UISettingsPageMachine::uploadData(data);
 
224
}
 
225
 
 
226
bool UIMachineSettingsGeneral::validate(QList<UIValidationMessage> &messages)
 
227
{
 
228
    /* Pass by default: */
 
229
    bool fPass = true;
 
230
 
 
231
    /* Prepare message: */
 
232
    UIValidationMessage message;
 
233
    message.first = VBoxGlobal::removeAccelMark(mTwGeneral->tabText(0));
 
234
 
 
235
    /* VM name validation: */
 
236
    if (m_pNameAndSystemEditor->name().trimmed().isEmpty())
 
237
    {
 
238
        message.second << tr("No name specified for the virtual machine.");
 
239
        fPass = false;
 
240
    }
 
241
 
 
242
    /* OS type & VT-x/AMD-v correlation: */
 
243
    if (is64BitOSTypeSelected() && !m_fHWVirtExEnabled)
 
244
    {
 
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.");
 
248
    }
 
249
 
 
250
    /* Serialize message: */
 
251
    if (!message.second.isEmpty())
 
252
        messages << message;
 
253
 
 
254
    /* Return result: */
 
255
    return fPass;
 
256
}
 
257
 
 
258
void UIMachineSettingsGeneral::setOrderAfter (QWidget *aWidget)
 
259
{
 
260
    /* Basic tab-order */
 
261
    setTabOrder (aWidget, mTwGeneral->focusProxy());
 
262
    setTabOrder (mTwGeneral->focusProxy(), m_pNameAndSystemEditor);
 
263
 
 
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);
 
271
 
 
272
    /* Description tab-order */
 
273
    setTabOrder (mCbToolBarAlignment, mTeDescription);
 
274
}
 
275
 
 
276
void UIMachineSettingsGeneral::retranslateUi()
 
277
{
 
278
    /* Translate uic generated strings */
 
279
    Ui::UIMachineSettingsGeneral::retranslateUi (this);
 
280
 
 
281
    /* Path selector */
 
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 "
 
285
                                   "space."));
 
286
 
 
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));
 
292
 
 
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));
 
298
}
 
299
 
 
300
void UIMachineSettingsGeneral::prepareValidation()
 
301
{
 
302
    /* Prepare validation: */
 
303
    connect(m_pNameAndSystemEditor, SIGNAL(sigOsTypeChanged()), this, SLOT(revalidate()));
 
304
    connect(m_pNameAndSystemEditor, SIGNAL(sigNameChanged(const QString&)), this, SLOT(revalidate()));
 
305
}
 
306
 
 
307
void UIMachineSettingsGeneral::polishPage()
 
308
{
 
309
    /* Basic tab: */
 
310
    m_pNameAndSystemEditor->setEnabled(isMachineOffline());
 
311
    /* Advanced tab: */
 
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());
 
323
}
 
324