VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox4/ui/VBoxNewVMWzd.ui.h@ 7442

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

Main: Applied SATA changes from #2406. Increased XML settings version format from 1.2 to 1.3.pre.

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