~ubuntu-branches/ubuntu/raring/virtualbox-ose/raring

« back to all changes in this revision

Viewing changes to src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsDisplay.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-01-30 23:27:25 UTC
  • mfrom: (0.3.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20110130232725-2ouajjd2ggdet0zd
Tags: 4.0.2-dfsg-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Add Apport hook.
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Drop *-source packages.
* Drop ubuntu-01-fix-build-gcc45.patch, fixed upstream.
* Drop ubuntu-02-as-needed.patch, added to the Debian package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: VBoxVMSettingsDisplay.cpp $ */
2
 
/** @file
3
 
 *
4
 
 * VBox frontends: Qt4 GUI ("VirtualBox"):
5
 
 * VBoxVMSettingsDisplay class implementation
6
 
 */
7
 
 
8
 
/*
9
 
 * Copyright (C) 2008-2010 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
 
#include "QIWidgetValidator.h"
21
 
#include "VBoxVMSettingsDisplay.h"
22
 
#include "VBoxGlobal.h"
23
 
#include "VBoxProblemReporter.h"
24
 
 
25
 
#include <QDesktopWidget>
26
 
 
27
 
/**
28
 
 *  Calculates a suitable page step size for the given max value. The returned
29
 
 *  size is so that there will be no more than 32 pages. The minimum returned
30
 
 *  page size is 4.
31
 
 */
32
 
static int calcPageStep (int aMax)
33
 
{
34
 
    /* reasonable max. number of page steps is 32 */
35
 
    uint page = ((uint) aMax + 31) / 32;
36
 
    /* make it a power of 2 */
37
 
    uint p = page, p2 = 0x1;
38
 
    while ((p >>= 1))
39
 
        p2 <<= 1;
40
 
    if (page != p2)
41
 
        p2 <<= 1;
42
 
    if (p2 < 4)
43
 
        p2 = 4;
44
 
    return (int) p2;
45
 
}
46
 
 
47
 
VBoxVMSettingsDisplay::VBoxVMSettingsDisplay()
48
 
{
49
 
    /* Apply UI decorations */
50
 
    Ui::VBoxVMSettingsDisplay::setupUi (this);
51
 
 
52
 
    /* Setup constants */
53
 
    CSystemProperties sys = vboxGlobal().virtualBox().GetSystemProperties();
54
 
    m_minVRAM = sys.GetMinGuestVRAM();
55
 
    m_maxVRAM = sys.GetMaxGuestVRAM();
56
 
    m_maxVRAMVisible = m_maxVRAM;
57
 
    const uint MinMonitors = 1;
58
 
#if (QT_VERSION >= 0x040600)
59
 
    const uint cHostScreens = QApplication::desktop()->screenCount();
60
 
#else /* (QT_VERSION >= 0x040600) */
61
 
    const uint cHostScreens = QApplication::desktop()->numScreens();
62
 
#endif /* !(QT_VERSION >= 0x040600) */
63
 
    const uint MaxMonitors = sys.GetMaxGuestMonitors();
64
 
 
65
 
    /* Setup validators */
66
 
    mLeMemory->setValidator (new QIntValidator (m_minVRAM, m_maxVRAMVisible, this));
67
 
    mLeMonitors->setValidator (new QIntValidator (MinMonitors, MaxMonitors, this));
68
 
    mLeVRDPPort->setValidator (new QRegExpValidator (QRegExp ("(([0-9]{1,5}(\\-[0-9]{1,5}){0,1}),)*([0-9]{1,5}(\\-[0-9]{1,5}){0,1})"), this));
69
 
    mLeVRDPTimeout->setValidator (new QIntValidator (this));
70
 
 
71
 
    /* Setup connections */
72
 
    connect (mSlMemory, SIGNAL (valueChanged (int)), this, SLOT (valueChangedVRAM (int)));
73
 
    connect (mLeMemory, SIGNAL (textChanged (const QString&)), this, SLOT (textChangedVRAM (const QString&)));
74
 
    connect (mSlMonitors, SIGNAL (valueChanged (int)), this, SLOT (valueChangedMonitors (int)));
75
 
    connect (mLeMonitors, SIGNAL (textChanged (const QString&)), this, SLOT (textChangedMonitors (const QString&)));
76
 
 
77
 
    /* Setup initial values */
78
 
    mSlMemory->setPageStep (calcPageStep (m_maxVRAMVisible));
79
 
    mSlMemory->setSingleStep (mSlMemory->pageStep() / 4);
80
 
    mSlMemory->setTickInterval (mSlMemory->pageStep());
81
 
    mSlMonitors->setPageStep (1);
82
 
    mSlMonitors->setSingleStep (1);
83
 
    mSlMonitors->setTickInterval (1);
84
 
    /* Setup the scale so that ticks are at page step boundaries */
85
 
    mSlMemory->setMinimum ((m_minVRAM / mSlMemory->pageStep()) * mSlMemory->pageStep());
86
 
    mSlMemory->setMaximum (m_maxVRAMVisible);
87
 
    mSlMemory->setSnappingEnabled (true);
88
 
    quint64 needMBytes = VBoxGlobal::requiredVideoMemory (&mMachine) / _1M;
89
 
    mSlMemory->setErrorHint (0, 1);
90
 
    mSlMemory->setWarningHint (1, needMBytes);
91
 
    mSlMemory->setOptimalHint (needMBytes, m_maxVRAMVisible);
92
 
    mSlMonitors->setMinimum (MinMonitors);
93
 
    mSlMonitors->setMaximum (MaxMonitors);
94
 
    mSlMonitors->setErrorHint (0, MinMonitors);
95
 
    mSlMonitors->setOptimalHint (MinMonitors, cHostScreens);
96
 
    mSlMonitors->setWarningHint (cHostScreens, MaxMonitors);
97
 
    /* Limit min/max. size of QLineEdit */
98
 
    mLeMemory->setFixedWidthByText (QString().fill ('8', 4));
99
 
    mLeMonitors->setFixedWidthByText (QString().fill ('8', 4));
100
 
    /* Ensure value and validation is updated */
101
 
    valueChangedVRAM (mSlMemory->value());
102
 
    valueChangedMonitors (mSlMonitors->value());
103
 
    /* Setup VRDP widget */
104
 
    mCbVRDPMethod->insertItem (0, ""); /* KVRDPAuthType_Null */
105
 
    mCbVRDPMethod->insertItem (1, ""); /* KVRDPAuthType_External */
106
 
    mCbVRDPMethod->insertItem (2, ""); /* KVRDPAuthType_Guest */
107
 
    /* Initially disabled */
108
 
    mCbVRDP->setChecked (false);
109
 
 
110
 
    mCb3D->setEnabled (false);
111
 
 
112
 
#ifndef VBOX_WITH_VIDEOHWACCEL
113
 
    mCb2DVideo->setVisible (false);
114
 
#endif
115
 
 
116
 
    /* Applying language settings */
117
 
    retranslateUi();
118
 
}
119
 
 
120
 
#ifdef VBOX_WITH_VIDEOHWACCEL
121
 
bool VBoxVMSettingsDisplay::isAcceleration2DVideoSelected() const
122
 
{
123
 
    return mCb2DVideo->isChecked();
124
 
}
125
 
#endif
126
 
 
127
 
void VBoxVMSettingsDisplay::getFrom (const CMachine &aMachine)
128
 
{
129
 
    mMachine = aMachine;
130
 
 
131
 
    int currentSize = mMachine.GetVRAMSize();
132
 
    m_initialVRAM = RT_MIN(currentSize, m_maxVRAM);
133
 
 
134
 
    /* must come _before_ setting the initial memory value */
135
 
    checkMultiMonitorReqs();
136
 
 
137
 
    /* Memory Size */
138
 
    mSlMemory->setValue (currentSize);
139
 
 
140
 
    /* Monitors Count */
141
 
    mSlMonitors->setValue (mMachine.GetMonitorCount());
142
 
 
143
 
    /* 3D Acceleration */
144
 
    bool isAccelerationSupported = vboxGlobal().virtualBox().GetHost()
145
 
                                   .GetAcceleration3DAvailable();
146
 
    mCb3D->setEnabled (isAccelerationSupported);
147
 
    mCb3D->setChecked (mMachine.GetAccelerate3DEnabled());
148
 
 
149
 
#ifdef VBOX_WITH_VIDEOHWACCEL
150
 
    mCb2DVideo->setEnabled (VBoxGlobal::isAcceleration2DVideoAvailable());
151
 
    mCb2DVideo->setChecked (   mMachine.GetAccelerate2DVideoEnabled()
152
 
                            && VBoxGlobal::isAcceleration2DVideoAvailable());
153
 
#endif
154
 
 
155
 
    /* VRDP Settings */
156
 
    CVRDPServer vrdp = mMachine.GetVRDPServer();
157
 
    if (!vrdp.isNull())
158
 
    {
159
 
        mCbVRDP->setChecked (vrdp.GetEnabled());
160
 
        mLeVRDPPort->setText (vrdp.GetPorts());
161
 
        mCbVRDPMethod->setCurrentIndex (mCbVRDPMethod->
162
 
                                        findText (vboxGlobal().toString (vrdp.GetAuthType())));
163
 
        mLeVRDPTimeout->setText (QString::number (vrdp.GetAuthTimeout()));
164
 
        mCbMultipleConn->setChecked(vrdp.GetAllowMultiConnection());
165
 
    }
166
 
    else
167
 
    {
168
 
        vboxProblem().cannotLoadMachineSettings (mMachine, false /* strict */);
169
 
        mTwDisplay->setTabEnabled (1, false);
170
 
    }
171
 
}
172
 
 
173
 
void VBoxVMSettingsDisplay::putBackTo()
174
 
{
175
 
    /* Memory Size */
176
 
    mMachine.SetVRAMSize (mSlMemory->value());
177
 
 
178
 
    /* Monitors Count */
179
 
    mMachine.SetMonitorCount (mSlMonitors->value());
180
 
 
181
 
    /* 3D Acceleration */
182
 
    mMachine.SetAccelerate3DEnabled (mCb3D->isChecked());
183
 
 
184
 
#ifdef VBOX_WITH_VIDEOHWACCEL
185
 
    /* 2D Video Acceleration */
186
 
    mMachine.SetAccelerate2DVideoEnabled (mCb2DVideo->isChecked());
187
 
#endif
188
 
 
189
 
    /* VRDP Settings */
190
 
    CVRDPServer vrdp = mMachine.GetVRDPServer();
191
 
    if (!vrdp.isNull())
192
 
    {
193
 
        vrdp.SetEnabled (mCbVRDP->isChecked());
194
 
        vrdp.SetPorts (mLeVRDPPort->text());
195
 
        vrdp.SetAuthType (vboxGlobal().toVRDPAuthType (mCbVRDPMethod->currentText()));
196
 
        vrdp.SetAuthTimeout (mLeVRDPTimeout->text().toULong());
197
 
        vrdp.SetAllowMultiConnection(mCbMultipleConn->isChecked());
198
 
    }
199
 
}
200
 
 
201
 
void VBoxVMSettingsDisplay::setValidator (QIWidgetValidator *aVal)
202
 
{
203
 
    mValidator = aVal;
204
 
    connect (mCb3D, SIGNAL (stateChanged (int)),
205
 
             mValidator, SLOT (revalidate()));
206
 
#ifdef VBOX_WITH_VIDEOHWACCEL
207
 
    connect (mCb2DVideo, SIGNAL (stateChanged (int)),
208
 
             mValidator, SLOT (revalidate()));
209
 
#endif
210
 
    connect (mCbVRDP, SIGNAL (toggled (bool)),
211
 
             mValidator, SLOT (revalidate()));
212
 
    connect (mLeVRDPPort, SIGNAL (textChanged (const QString&)),
213
 
             mValidator, SLOT (revalidate()));
214
 
    connect (mLeVRDPTimeout, SIGNAL (textChanged (const QString&)),
215
 
             mValidator, SLOT (revalidate()));
216
 
}
217
 
 
218
 
bool VBoxVMSettingsDisplay::revalidate (QString &aWarning, QString & /* aTitle */)
219
 
{
220
 
    /* Video RAM amount test */
221
 
    quint64 needBytes = VBoxGlobal::requiredVideoMemory (&mMachine, mSlMonitors->value());
222
 
    if ((quint64) mSlMemory->value() * _1M < needBytes)
223
 
    {
224
 
        aWarning = tr (
225
 
            "you have assigned less than <b>%1</b> of video memory which is "
226
 
            "the minimum amount required to switch the virtual machine to "
227
 
            "fullscreen or seamless mode.")
228
 
            .arg (vboxGlobal().formatSize (needBytes, 0, VBoxDefs::FormatSize_RoundUp));
229
 
        return true;
230
 
    }
231
 
#ifdef VBOX_WITH_VIDEOHWACCEL
232
 
    if (mCb2DVideo->isChecked())
233
 
    {
234
 
        quint64 needBytesWith2D = needBytes + VBoxGlobal::required2DOffscreenVideoMemory();
235
 
        if ((quint64) mSlMemory->value() * _1M < needBytesWith2D)
236
 
        {
237
 
            aWarning = tr (
238
 
                "you have assigned less than <b>%1</b> of video memory which is "
239
 
                "the minimum amount required for HD Video to be played efficiently.")
240
 
                .arg (vboxGlobal().formatSize (needBytesWith2D, 0, VBoxDefs::FormatSize_RoundUp));
241
 
            return true;
242
 
        }
243
 
    }
244
 
#endif
245
 
 
246
 
    /* 3D Acceleration support test */
247
 
    // TODO : W8 for NaN //
248
 
 
249
 
    return true;
250
 
}
251
 
 
252
 
void VBoxVMSettingsDisplay::setOrderAfter (QWidget *aWidget)
253
 
{
254
 
    setTabOrder (aWidget, mTwDisplay->focusProxy());
255
 
    setTabOrder (mTwDisplay->focusProxy(), mSlMemory);
256
 
    setTabOrder (mSlMemory, mLeMemory);
257
 
    setTabOrder (mLeMemory, mSlMonitors);
258
 
    setTabOrder (mSlMonitors, mLeMonitors);
259
 
    setTabOrder (mLeMonitors, mCb3D);
260
 
#ifdef VBOX_WITH_VIDEOHWACCEL
261
 
    setTabOrder (mCb3D, mCb2DVideo);
262
 
    setTabOrder (mCb2DVideo, mCbVRDP);
263
 
#else
264
 
    setTabOrder (mCb3D, mCbVRDP);
265
 
#endif
266
 
    setTabOrder (mCbVRDP, mLeVRDPPort);
267
 
    setTabOrder (mLeVRDPPort, mCbVRDPMethod);
268
 
    setTabOrder (mCbVRDPMethod, mLeVRDPTimeout);
269
 
    setTabOrder (mLeVRDPTimeout, mCbMultipleConn);
270
 
}
271
 
 
272
 
void VBoxVMSettingsDisplay::retranslateUi()
273
 
{
274
 
    /* Translate uic generated strings */
275
 
    Ui::VBoxVMSettingsDisplay::retranslateUi (this);
276
 
 
277
 
    CSystemProperties sys = vboxGlobal().virtualBox().GetSystemProperties();
278
 
    mLbMemoryMin->setText (tr ("<qt>%1&nbsp;MB</qt>").arg (m_minVRAM));
279
 
    mLbMemoryMax->setText (tr ("<qt>%1&nbsp;MB</qt>").arg (m_maxVRAMVisible));
280
 
    mLbMonitorsMin->setText (tr ("<qt>%1</qt>").arg (1));
281
 
    mLbMonitorsMax->setText (tr ("<qt>%1</qt>").arg (sys.GetMaxGuestMonitors()));
282
 
 
283
 
    mCbVRDPMethod->setItemText (0,
284
 
        vboxGlobal().toString (KVRDPAuthType_Null));
285
 
    mCbVRDPMethod->setItemText (1,
286
 
        vboxGlobal().toString (KVRDPAuthType_External));
287
 
    mCbVRDPMethod->setItemText (2,
288
 
        vboxGlobal().toString (KVRDPAuthType_Guest));
289
 
}
290
 
 
291
 
void VBoxVMSettingsDisplay::valueChangedVRAM (int aVal)
292
 
{
293
 
    mLeMemory->setText (QString().setNum (aVal));
294
 
}
295
 
 
296
 
void VBoxVMSettingsDisplay::textChangedVRAM (const QString &aText)
297
 
{
298
 
    mSlMemory->setValue (aText.toInt());
299
 
}
300
 
 
301
 
void VBoxVMSettingsDisplay::valueChangedMonitors (int aVal)
302
 
{
303
 
    mLeMonitors->setText (QString().setNum (aVal));
304
 
    checkMultiMonitorReqs();
305
 
}
306
 
 
307
 
void VBoxVMSettingsDisplay::textChangedMonitors (const QString &aText)
308
 
{
309
 
    mSlMonitors->setValue (aText.toInt());
310
 
}
311
 
 
312
 
void VBoxVMSettingsDisplay::checkMultiMonitorReqs()
313
 
{
314
 
    int cVal = mSlMonitors->value();
315
 
#ifdef VBOX_WITH_VIDEOHWACCEL
316
 
    mCb2DVideo->setEnabled(VBoxGlobal::isAcceleration2DVideoAvailable());
317
 
#endif /* VBOX_WITH_VIDEOHWACCEL */
318
 
    mCb3D->setEnabled(vboxGlobal().virtualBox().GetHost().GetAcceleration3DAvailable());
319
 
 
320
 
    /* The memory requirements have changed too. */
321
 
    quint64 needMBytes = VBoxGlobal::requiredVideoMemory (&mMachine, cVal) / _1M;
322
 
    /* Limit the maximum memory to save careless users from setting useless big values */
323
 
    m_maxVRAMVisible = cVal * 32;
324
 
    if (m_maxVRAMVisible < 128)
325
 
        m_maxVRAMVisible = 128;
326
 
    if (m_maxVRAMVisible < m_initialVRAM)
327
 
        m_maxVRAMVisible = m_initialVRAM;
328
 
    mSlMemory->setWarningHint (1, needMBytes);
329
 
    mSlMemory->setPageStep (calcPageStep (m_maxVRAMVisible));
330
 
    mSlMemory->setMaximum (m_maxVRAMVisible);
331
 
    mSlMemory->setOptimalHint (needMBytes, m_maxVRAMVisible);
332
 
    mLeMemory->setValidator (new QIntValidator (m_minVRAM, m_maxVRAMVisible, this));
333
 
    mLbMemoryMax->setText (tr ("<qt>%1&nbsp;MB</qt>").arg (m_maxVRAMVisible));
334
 
    /* ... or just call retranslateUi()? */
335
 
}
336