VirtualBox

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

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

InnoTek -> innotek: all the headers and comments.

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