VirtualBox

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

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

Fixed freeze during add/remove/add/remove sequence in clean MediaComboBox.
Fixed settings shortcuts update during removing all elements from MediaComboBox.
Some other minor update-bugs fixed.

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