VirtualBox

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

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

1764: Better default size in "Create VDI" wizard when called from "Create VM" wizard:

Rollback NewVM & NewHD Wizards QLabels to old *.ui version.

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