VirtualBox

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

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

2049: The first run wizard should not be run if an existing VDI is attached to a new VM:

Done :)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.4 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.215389.xyz. 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 if (uuidHD.isNull())
319 cmachine.SetExtraData (GUI_FirstRun, "yes");
320 }
321
322 /* name is set in CreateMachine() */
323
324 /* OS type */
325 CGuestOSType type = vboxGlobal().vmGuestOSType (cbOS->currentItem());
326 AssertMsg (!type.isNull(), ("vmGuestOSType() must return non-null type"));
327 cmachine.SetOSTypeId (type.GetId());
328
329 if (type.GetId() == "os2warp3" ||
330 type.GetId() == "os2warp4" ||
331 type.GetId() == "os2warp45")
332 cmachine.SetHWVirtExEnabled (CEnums::True);
333
334 /* RAM size */
335 cmachine.SetMemorySize (slRAM->value());
336
337 /* add one network adapter (NAT) by default */
338 {
339 CNetworkAdapter cadapter = cmachine.GetNetworkAdapter (0);
340 cadapter.SetEnabled (true);
341 cadapter.AttachToNAT();
342 cadapter.SetMACAddress (QString::null);
343 cadapter.SetCableConnected (true);
344 }
345
346 /* register the VM prior to attaching hard disks */
347 vbox.RegisterMachine (cmachine);
348 if (!vbox.isOk())
349 {
350 vboxProblem().cannotCreateMachine (vbox, cmachine, this);
351 return false;
352 }
353
354 /* Boot hard disk (Primary Master) */
355 if (!uuidHD.isNull())
356 {
357 bool ok = false;
358 QUuid id = cmachine.GetId();
359 CSession session = vboxGlobal().openSession (id);
360 if (!session.isNull())
361 {
362 CMachine m = session.GetMachine();
363 m.AttachHardDisk (uuidHD, CEnums::IDE0Controller, 0);
364 if (m.isOk())
365 {
366 m.SaveSettings();
367 if (m.isOk())
368 ok = true;
369 else
370 vboxProblem().cannotSaveMachineSettings (m, this);
371 }
372 else
373 vboxProblem().cannotAttachHardDisk (this, m, uuidHD,
374 CEnums::IDE0Controller, 0);
375 session.Close();
376 }
377 if (!ok)
378 {
379 /* unregister on failure */
380 vbox.UnregisterMachine (id);
381 if (vbox.isOk())
382 cmachine.DeleteSettings();
383 return false;
384 }
385 }
386
387 /* ensure we don't delete a newly created hard disk on success */
388 chd.detach();
389
390 return true;
391}
392
393void VBoxNewVMWzd::ensureNewHardDiskDeleted()
394{
395 if (!chd.isNull())
396 {
397 QUuid hdId = chd.GetId();
398 CVirtualBox vbox = vboxGlobal().virtualBox();
399 vbox.UnregisterHardDisk (chd.GetId());
400 if (!vbox.isOk())
401 vboxProblem().cannotUnregisterMedia (this, vbox, VBoxDefs::HD,
402 chd.GetLocation());
403 else
404 {
405 CVirtualDiskImage vdi = CUnknown (chd);
406 if (!vdi.isNull())
407 {
408 vdi.DeleteImage();
409 if (!vdi.isOk())
410 vboxProblem().cannotDeleteHardDiskImage (this, vdi);
411 }
412 }
413 chd.detach();
414 vboxGlobal().removeMedia (VBoxDefs::HD, hdId);
415 }
416}
417
418CMachine VBoxNewVMWzd::machine()
419{
420 return cmachine;
421}
422
423void VBoxNewVMWzd::showVDIManager()
424{
425 VBoxDiskImageManagerDlg dlg (this, "VBoxDiskImageManagerDlg", WType_Dialog | WShowModal);
426 dlg.setup (VBoxDefs::HD, true);
427 QUuid newId = dlg.exec() == VBoxDiskImageManagerDlg::Accepted ?
428 dlg.getSelectedUuid() : mediaCombo->getId();
429
430 if (uuidHD != newId)
431 {
432 ensureNewHardDiskDeleted();
433 uuidHD = newId;
434 mediaCombo->setCurrentItem (uuidHD);
435 }
436 mediaCombo->setFocus();
437 /* revailidate */
438 wvalHDD->revalidate();
439}
440
441void VBoxNewVMWzd::showNewVDIWizard()
442{
443 VBoxNewHDWzd dlg (this, "VBoxNewHDWzd");
444
445 CGuestOSType type = vboxGlobal().vmGuestOSType (cbOS->currentItem());
446
447 dlg.setRecommendedFileName (leName->text());
448 dlg.setRecommendedSize (type.GetRecommendedHDD());
449
450 if (dlg.exec() == QDialog::Accepted)
451 {
452 ensureNewHardDiskDeleted();
453 chd = dlg.hardDisk();
454 /* fetch uuid and name/path */
455 uuidHD = chd.GetId();
456 /* update media combobox */
457 VBoxMedia::Status status =
458 chd.GetAccessible() == TRUE ? VBoxMedia::Ok :
459 chd.isOk() ? VBoxMedia::Inaccessible :
460 VBoxMedia::Error;
461 vboxGlobal().addMedia (VBoxMedia (CUnknown (chd), VBoxDefs::HD, status));
462 mediaCombo->setCurrentItem (uuidHD);
463 mediaCombo->setFocus();
464 /* revailidate */
465 wvalHDD->revalidate();
466 }
467}
468
469void VBoxNewVMWzd::slRAM_valueChanged (int val)
470{
471 leRAM->setText (QString().setNum (val));
472}
473
474
475void VBoxNewVMWzd::leRAM_textChanged (const QString &text)
476{
477 slRAM->setValue (text.toInt());
478}
479
480void VBoxNewVMWzd::cbOS_activated (int item)
481{
482 CGuestOSType type = vboxGlobal().vmGuestOSType (item);
483 pmOS->setPixmap (vboxGlobal().vmGuestOSTypeIcon (type.GetId()));
484 txRAMBest->setText (QString::null);
485 txRAMBest2->setText (
486 tr ("The recommended base memory size is <b>%1</b> MB.")
487 .arg (type.GetRecommendedRAM()));
488 slRAM->setValue (type.GetRecommendedRAM());
489 txVDIBest->setText (
490 tr ("The recommended size of the boot hard disk is <b>%1</b> MB.")
491 .arg (type.GetRecommendedHDD()));
492}
493
494void VBoxNewVMWzd::currentMediaChanged (int)
495{
496 uuidHD = mediaCombo->getId();
497 /* revailidate */
498 wvalHDD->revalidate();
499}
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