VirtualBox

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

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

FE/Qt: Latest fixes to VDM and media enumeration process (better cooperation between media cobmoboxes, modal and modeless VDMs during the enumeration).

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