VirtualBox

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

Last change on this file since 2866 was 2864, checked in by vboxsync, 18 years ago

1750: Add CDROM configuration to "Create VM" wizard:

First Run Wizard implemented.
This dialog allows user to select and temporarily mount the booting source for the VM to be started for the first time. The booting source could be:

  1. CD/DVD-ROM host drive.
  2. CD/DVD-ROM image file.
  3. Floppy host drive.
  4. Floppy image file.

It also allows user to invoke Virtual Disk Manager Dialog to add additional CD/FD images as booting sources.

The dialog will only be executed for the VM which has a GUI/FirstRun=”yes” extra data flag in it's configuration file. This flag currently will be auto-added only for the new VM created by the “New VM Wizard”. After the “First Run Wizard” will be proposed for the first time, the flag will be erased from the VM configuration file. This flag will also be erased from the configuration file in case of there is any other value rather than “yes” for it.

TODO: The flag should also be erased from the configuration file in case of user manually changes the boot sequence or the CD/FD/HD configuration through the VM Settings Dialog.

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

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