VirtualBox

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

Last change on this file since 14683 was 14664, checked in by vboxsync, 16 years ago

Main & FEs: 3002: GUI/Main enhancements for 64 bits guests implemented.

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