VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/ui/VBoxNewVMWzd.ui.h@ 3232

Last change on this file since 3232 was 3232, checked in by vboxsync, 17 years ago

Make VT-x/AMD-V feature enabled by default for newly created OS/2-type VMs.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.3 KB
Line 
1/**
2 *
3 * VBox frontends: Qt GUI ("VirtualBox"):
4 * "New virtual machine" wizard UI include (Qt Designer)
5 */
6
7/*
8 * Copyright (C) 2006-2007 innotek GmbH
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License as published by the Free Software Foundation,
14 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
15 * distribution. VirtualBox OSE is distributed in the hope that it will
16 * be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * If you received this file as part of a commercial VirtualBox
19 * distribution, then only the terms of your commercial VirtualBox
20 * license agreement apply instead of the previous paragraph.
21 */
22
23/****************************************************************************
24** ui.h extension file, included from the uic-generated form implementation.
25**
26** If you want to add, delete, or rename functions or slots, use
27** Qt Designer to update this file, preserving your code.
28**
29** You should not define a constructor or destructor in this file.
30** Instead, write your code in functions called init() and destroy().
31** These will automatically be called by the form's constructor and
32** destructor.
33*****************************************************************************/
34
35/* defined in VBoxConsoleWnd.cpp */
36extern const char *GUI_FirstRun;
37
38/**
39 * Calculates a suitable page step size for the given max value.
40 * The returned size is so that there will be no more than 32 pages.
41 * The minimum returned page size is 4.
42 */
43static int calcPageStep (int aMax)
44{
45 /* reasonable max. number of page steps is 32 */
46 uint page = ((uint) aMax + 31) / 32;
47 /* make it a power of 2 */
48 uint p = page, p2 = 0x1;
49 while ((p >>= 1))
50 p2 <<= 1;
51 if (page != p2)
52 p2 <<= 1;
53 if (p2 < 4)
54 p2 = 4;
55 return (int) p2;
56}
57
58void VBoxNewVMWzd::init()
59{
60 /* disable help buttons */
61 helpButton()->setShown (false);
62
63 /*
64 * fix tab order to get the proper direction
65 * (originally the focus goes Next/Finish -> Back -> Cancel -> page)
66 */
67 QWidget::setTabOrder (backButton(), nextButton());
68 QWidget::setTabOrder (nextButton(), finishButton());
69 QWidget::setTabOrder (finishButton(), cancelButton());
70
71 /*
72 * setup connections and set validation for pages
73 * ----------------------------------------------------------------------
74 */
75
76 /* setup the label colors for nice scaling */
77 VBoxGlobal::adoptLabelPixmap (pmWelcome);
78 VBoxGlobal::adoptLabelPixmap (pmNameAndOS);
79 VBoxGlobal::adoptLabelPixmap (pmMemory);
80 VBoxGlobal::adoptLabelPixmap (pmHDD);
81 VBoxGlobal::adoptLabelPixmap (pmSummary);
82
83 /* Name and OS page */
84
85 leName->setValidator (new QRegExpValidator (QRegExp (".+" ), this));
86
87 wvalNameAndOS = new QIWidgetValidator (pageNameAndOS, this);
88 connect (wvalNameAndOS, SIGNAL (validityChanged (const QIWidgetValidator *)),
89 this, SLOT (enableNext (const QIWidgetValidator *)));
90
91 connect (cbOS, SIGNAL (activated (int)), this, SLOT (cbOS_activated (int)));
92
93 /* Memory page */
94
95 CSystemProperties sysProps = vboxGlobal().virtualBox().GetSystemProperties();
96
97 const uint MinRAM = sysProps.GetMinGuestRAM();
98 const uint MaxRAM = sysProps.GetMaxGuestRAM();
99
100 leRAM->setValidator (new QIntValidator (MinRAM, MaxRAM, this));
101
102 wvalMemory = new QIWidgetValidator (pageMemory, this);
103 connect (wvalMemory, SIGNAL (validityChanged (const QIWidgetValidator *)),
104 this, SLOT (enableNext (const QIWidgetValidator *)));
105
106 /* HDD Images page */
107 mediaCombo = new VBoxMediaComboBox (grbHDA, "mediaCombo", VBoxDefs::HD, true);
108 grbHDALayout->addMultiCellWidget (mediaCombo, 0, 0, 0, 2);
109 setTabOrder (mediaCombo, pbNewHD);
110 setTabOrder (pbNewHD, pbExistingHD);
111 connect (mediaCombo, SIGNAL (activated (int)),
112 this, SLOT (currentMediaChanged (int)));
113 if (!vboxGlobal().isMediaEnumerationStarted())
114 vboxGlobal().startEnumeratingMedia();
115 else
116 mediaCombo->refresh();
117
118 /// @todo (dmik) remove?
119 wvalHDD = new QIWidgetValidator (pageHDD, this);
120 connect (wvalHDD, SIGNAL (validityChanged (const QIWidgetValidator *)),
121 this, SLOT (enableNext (const QIWidgetValidator *)));
122 connect (wvalHDD, SIGNAL (isValidRequested (QIWidgetValidator *)),
123 this, SLOT (revalidate (QIWidgetValidator *)));
124
125 /* Summary page */
126
127 teSummary = new QITextEdit (pageSummary);
128 teSummary->setSizePolicy (QSizePolicy::Minimum, QSizePolicy::Minimum);
129 teSummary->setFrameShape (QTextEdit::NoFrame);
130 teSummary->setReadOnly (TRUE);
131 summaryLayout->insertWidget (1, teSummary);
132
133 /* filter out Enter keys in order to direct them to the default dlg button */
134 QIKeyFilter *ef = new QIKeyFilter (this, Key_Enter);
135 ef->watchOn (teSummary);
136
137 /*
138 * set initial values
139 * ----------------------------------------------------------------------
140 */
141
142 /* Name and OS page */
143
144 cbOS->insertStringList (vboxGlobal().vmGuestOSTypeDescriptions());
145 cbOS_activated (cbOS->currentItem());
146
147 /* Memory page */
148
149 slRAM->setPageStep (calcPageStep (MaxRAM));
150 slRAM->setLineStep (slRAM->pageStep() / 4);
151 slRAM->setTickInterval (slRAM->pageStep());
152 /* setup the scale so that ticks are at page step boundaries */
153 slRAM->setMinValue ((MinRAM / slRAM->pageStep()) * slRAM->pageStep());
154 slRAM->setMaxValue (MaxRAM);
155 txRAMMin->setText (tr ("<qt>%1&nbsp;MB</qt>").arg (MinRAM));
156 txRAMMax->setText (tr ("<qt>%1&nbsp;MB</qt>").arg (MaxRAM));
157 /*
158 * initial RAM value is set in cbOS_activated()
159 * limit min/max. size of QLineEdit
160 */
161 leRAM->setMaximumSize (leRAM->fontMetrics().width ("99999")
162 + leRAM->frameWidth() * 2,
163 leRAM->minimumSizeHint().height());
164 leRAM->setMinimumSize (leRAM->maximumSize());
165 /* ensure leRAM value and validation is updated */
166 slRAM_valueChanged (slRAM->value());
167
168 /* HDD Images page */
169
170 /* Summary page */
171
172 teSummary->setPaper (pageSummary->backgroundBrush());
173
174 /*
175 * update the next button state for pages with validation
176 * (validityChanged() connected to enableNext() will do the job)
177 */
178 wvalNameAndOS->revalidate();
179 wvalMemory->revalidate();
180 wvalHDD->revalidate();
181
182 /* the finish button on the Summary page is always enabled */
183 setFinishEnabled (pageSummary, true);
184
185 /* setup minimum width for the sizeHint to be calculated correctly */
186 int wid = widthSpacer->minimumSize().width();
187 txWelcome->setMinimumWidth (wid);
188 txNameAndOS->setMinimumWidth (wid);
189 textLabel1->setMinimumWidth (wid);
190 txRAMBest2->setMinimumWidth (wid);
191 textLabel1_3->setMinimumWidth (wid);
192 txVDIBest->setMinimumWidth (wid);
193 txSummaryHdr->setMinimumWidth (wid);
194 txSummaryFtr->setMinimumWidth (wid);
195}
196
197
198void VBoxNewVMWzd::destroy()
199{
200 ensureNewHardDiskDeleted();
201}
202
203void VBoxNewVMWzd::showEvent (QShowEvent *e)
204{
205 QDialog::showEvent (e);
206
207 /* one may think that QWidget::polish() is the right place to do things
208 * below, but apparently, by the time when QWidget::polish() is called,
209 * the widget style & layout are not fully done, at least the minimum
210 * size hint is not properly calculated. Since this is sometimes necessary,
211 * we provide our own "polish" implementation. */
212
213 layout()->activate();
214
215 /* resize to the miminum possible size */
216 resize (minimumSize());
217
218 VBoxGlobal::centerWidget (this, parentWidget());
219}
220
221void VBoxNewVMWzd::enableNext (const QIWidgetValidator *wval)
222{
223 setNextEnabled (wval->widget(), wval->isValid());
224}
225
226
227void VBoxNewVMWzd::revalidate (QIWidgetValidator *wval)
228{
229 /* do individual validations for pages */
230
231 bool valid = wval->isOtherValid();
232
233 if (wval == wvalHDD)
234 {
235 if (!chd.isNull() && mediaCombo->currentItem() != mediaCombo->count() - 1)
236 ensureNewHardDiskDeleted();
237 }
238
239 wval->setOtherValid( valid );
240}
241
242
243void VBoxNewVMWzd::showPage (QWidget *page)
244{
245 if (page == pageSummary)
246 {
247 /* compose summary */
248 QString summary = QString (tr (
249 "<tr><td>Name:</td><td>%1</td></tr>"
250 "<tr><td>OS Type:</td><td>%2</td></tr>"
251 "<tr><td>Base Memory:</td><td>%3&nbsp;MB</td></tr>"))
252 .arg (leName->text())
253 .arg (vboxGlobal().vmGuestOSType (cbOS->currentItem()).GetDescription())
254 .arg (slRAM->value());
255
256 if (mediaCombo->currentItem())
257 summary += QString (tr (
258 "<tr><td>Boot Hard Disk:</td><td>%4</td></tr>"))
259 .arg (mediaCombo->currentText());
260
261 teSummary->setText ("<table>" + summary + "</table>");
262
263 /* set Finish to default */
264 finishButton()->setDefault( true );
265 }
266 else
267 {
268 /* always set Next to default */
269 nextButton()->setDefault( true );
270 }
271
272 QWizard::showPage (page);
273
274 /*
275 * fix focus on the last page. when we go to the last page
276 * having the Next in focus the focus goes to the Cancel
277 * button because when the Next hides Finish is not yet shown.
278 */
279 if (page == pageSummary && focusWidget() == cancelButton())
280 finishButton()->setFocus();
281
282 /* setup focus for individual pages */
283 if (page == pageNameAndOS)
284 leName->setFocus();
285 else if (page == pageMemory)
286 slRAM->setFocus();
287 else if (page == pageHDD)
288 mediaCombo->setFocus();
289 else if (page == pageSummary)
290 teSummary->setFocus();
291
292 page->layout()->activate();
293}
294
295void VBoxNewVMWzd::accept()
296{
297 /*
298 * Try to create the machine when the Finish button is pressed.
299 * On failure, the wisard will remain open to give it another try.
300 */
301 if (constructMachine())
302 QWizard::accept();
303}
304
305bool VBoxNewVMWzd::constructMachine()
306{
307 CVirtualBox vbox = vboxGlobal().virtualBox();
308
309 /* create a machine with the default settings file location */
310 if (cmachine.isNull())
311 {
312 cmachine = vbox.CreateMachine (QString(), leName->text());
313 if (!vbox.isOk())
314 {
315 vboxProblem().cannotCreateMachine (vbox, this);
316 return false;
317 }
318 cmachine.SetExtraData (GUI_FirstRun, "yes");
319 }
320
321 /* name is set in CreateMachine() */
322
323 /* OS type */
324 CGuestOSType type = vboxGlobal().vmGuestOSType (cbOS->currentItem());
325 AssertMsg (!type.isNull(), ("vmGuestOSType() must return non-null type"));
326 cmachine.SetOSTypeId (type.GetId());
327
328 if (type.GetId() == "os2warp3" ||
329 type.GetId() == "os2warp4" ||
330 type.GetId() == "os2warp45")
331 cmachine.SetHWVirtExEnabled (CEnums::True);
332
333 /* RAM size */
334 cmachine.SetMemorySize (slRAM->value());
335
336 /* add one network adapter (NAT) by default */
337 {
338 CNetworkAdapter cadapter = cmachine.GetNetworkAdapter (0);
339 cadapter.SetEnabled (true);
340 cadapter.AttachToNAT();
341 cadapter.SetMACAddress (QString::null);
342 cadapter.SetCableConnected (true);
343 }
344
345 /* register the VM prior to attaching hard disks */
346 vbox.RegisterMachine (cmachine);
347 if (!vbox.isOk())
348 {
349 vboxProblem().cannotCreateMachine (vbox, cmachine, this);
350 return false;
351 }
352
353 /* Boot hard disk (Primary Master) */
354 if (!uuidHD.isNull())
355 {
356 bool ok = false;
357 QUuid id = cmachine.GetId();
358 CSession session = vboxGlobal().openSession (id);
359 if (!session.isNull())
360 {
361 CMachine m = session.GetMachine();
362 m.AttachHardDisk (uuidHD, CEnums::IDE0Controller, 0);
363 if (m.isOk())
364 {
365 m.SaveSettings();
366 if (m.isOk())
367 ok = true;
368 else
369 vboxProblem().cannotSaveMachineSettings (m, this);
370 }
371 else
372 vboxProblem().cannotAttachHardDisk (this, m, uuidHD,
373 CEnums::IDE0Controller, 0);
374 session.Close();
375 }
376 if (!ok)
377 {
378 /* unregister on failure */
379 vbox.UnregisterMachine (id);
380 if (vbox.isOk())
381 cmachine.DeleteSettings();
382 return false;
383 }
384 }
385
386 /* ensure we don't delete a newly created hard disk on success */
387 chd.detach();
388
389 return true;
390}
391
392void VBoxNewVMWzd::ensureNewHardDiskDeleted()
393{
394 if (!chd.isNull())
395 {
396 QUuid hdId = chd.GetId();
397 CVirtualBox vbox = vboxGlobal().virtualBox();
398 vbox.UnregisterHardDisk (chd.GetId());
399 if (!vbox.isOk())
400 vboxProblem().cannotUnregisterMedia (this, vbox, VBoxDefs::HD,
401 chd.GetLocation());
402 else
403 {
404 CVirtualDiskImage vdi = CUnknown (chd);
405 if (!vdi.isNull())
406 {
407 vdi.DeleteImage();
408 if (!vdi.isOk())
409 vboxProblem().cannotDeleteHardDiskImage (this, vdi);
410 }
411 }
412 chd.detach();
413 vboxGlobal().removeMedia (VBoxDefs::HD, hdId);
414 }
415}
416
417CMachine VBoxNewVMWzd::machine()
418{
419 return cmachine;
420}
421
422void VBoxNewVMWzd::showVDIManager()
423{
424 VBoxDiskImageManagerDlg dlg (this, "VBoxDiskImageManagerDlg", WType_Dialog | WShowModal);
425 dlg.setup (VBoxDefs::HD, true);
426 QUuid newId = dlg.exec() == VBoxDiskImageManagerDlg::Accepted ?
427 dlg.getSelectedUuid() : mediaCombo->getId();
428
429 if (uuidHD != newId)
430 {
431 ensureNewHardDiskDeleted();
432 uuidHD = newId;
433 mediaCombo->setCurrentItem (uuidHD);
434 }
435 mediaCombo->setFocus();
436 /* revailidate */
437 wvalHDD->revalidate();
438}
439
440void VBoxNewVMWzd::showNewVDIWizard()
441{
442 VBoxNewHDWzd dlg (this, "VBoxNewHDWzd");
443
444 CGuestOSType type = vboxGlobal().vmGuestOSType (cbOS->currentItem());
445
446 dlg.setRecommendedFileName (leName->text());
447 dlg.setRecommendedSize (type.GetRecommendedHDD());
448
449 if (dlg.exec() == QDialog::Accepted)
450 {
451 ensureNewHardDiskDeleted();
452 chd = dlg.hardDisk();
453 /* fetch uuid and name/path */
454 uuidHD = chd.GetId();
455 /* update media combobox */
456 VBoxMedia::Status status =
457 chd.GetAccessible() == TRUE ? VBoxMedia::Ok :
458 chd.isOk() ? VBoxMedia::Inaccessible :
459 VBoxMedia::Error;
460 vboxGlobal().addMedia (VBoxMedia (CUnknown (chd), VBoxDefs::HD, status));
461 mediaCombo->setCurrentItem (uuidHD);
462 mediaCombo->setFocus();
463 /* revailidate */
464 wvalHDD->revalidate();
465 }
466}
467
468void VBoxNewVMWzd::slRAM_valueChanged (int val)
469{
470 leRAM->setText (QString().setNum (val));
471}
472
473
474void VBoxNewVMWzd::leRAM_textChanged (const QString &text)
475{
476 slRAM->setValue (text.toInt());
477}
478
479void VBoxNewVMWzd::cbOS_activated (int item)
480{
481 CGuestOSType type = vboxGlobal().vmGuestOSType (item);
482 pmOS->setPixmap (vboxGlobal().vmGuestOSTypeIcon (type.GetId()));
483 txRAMBest->setText (QString::null);
484 txRAMBest2->setText (
485 tr ("The recommended base memory size is <b>%1</b> MB.")
486 .arg (type.GetRecommendedRAM()));
487 slRAM->setValue (type.GetRecommendedRAM());
488 txVDIBest->setText (
489 tr ("The recommended size of the boot hard disk is <b>%1</b> MB.")
490 .arg (type.GetRecommendedHDD()));
491}
492
493void VBoxNewVMWzd::currentMediaChanged (int)
494{
495 uuidHD = mediaCombo->getId();
496 /* revailidate */
497 wvalHDD->revalidate();
498}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette