VirtualBox

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

最後變更 在這個檔案從13580是 13580,由 vboxsync 提交於 16 年 前

Ported s2 branch (r37120:38456).

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 15.0 KB
 
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.alldomusa.eu.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 /* create a machine with the default settings file location */
294 if (mMachine.isNull())
295 {
296 mMachine = vbox.CreateMachine (QString(), leName->text(), QUuid());
297 if (!vbox.isOk())
298 {
299 vboxProblem().cannotCreateMachine (vbox, this);
300 return false;
301 }
302
303 /* The FirstRun wizard is to be shown only when we don't attach any hard
304 * disk or attach a new (empty) one. Selecting an existing hard disk
305 * will cancel the wizard. */
306 if (mHDCombo->id().isNull() || !mHardDisk.isNull())
307 mMachine.SetExtraData (VBoxDefs::GUI_FirstRun, "yes");
308 }
309
310 /* name is set in CreateMachine() */
311
312 /* OS type */
313 CGuestOSType type = vboxGlobal().vmGuestOSType (cbOS->currentItem());
314 AssertMsg (!type.isNull(), ("vmGuestOSType() must return non-null type"));
315 QString typeId = type.GetId();
316 mMachine.SetOSTypeId (typeId);
317
318 if (typeId == "os2warp3" ||
319 typeId == "os2warp4" ||
320 typeId == "os2warp45" ||
321 typeId == "ecs")
322 mMachine.SetHWVirtExEnabled (KTSBool_True);
323
324 /* RAM size */
325 mMachine.SetMemorySize (slRAM->value());
326
327 /* add one network adapter (NAT) by default */
328 {
329 CNetworkAdapter cadapter = mMachine.GetNetworkAdapter (0);
330#ifdef VBOX_WITH_E1000
331 /* Default to e1k on solaris */
332 if (typeId == "solaris" ||
333 typeId == "opensolaris")
334 cadapter.SetAdapterType (KNetworkAdapterType_I82540EM);
335#endif /* VBOX_WITH_E1000 */
336 cadapter.SetEnabled (true);
337 cadapter.AttachToNAT();
338 cadapter.SetMACAddress (QString::null);
339 cadapter.SetCableConnected (true);
340
341 }
342
343 /* register the VM prior to attaching hard disks */
344 vbox.RegisterMachine (mMachine);
345 if (!vbox.isOk())
346 {
347 vboxProblem().cannotCreateMachine (vbox, mMachine, this);
348 return false;
349 }
350
351 /* Boot hard disk (IDE Primary Master) */
352 QUuid hardDiskId = mHDCombo->id();
353 if (!hardDiskId.isNull())
354 {
355 bool ok = false;
356 QUuid id = mMachine.GetId();
357 CSession session = vboxGlobal().openSession (id);
358 if (!session.isNull())
359 {
360 CMachine m = session.GetMachine();
361 m.AttachHardDisk2 (hardDiskId, KStorageBus_IDE, 0, 0);
362 if (m.isOk())
363 {
364 m.SaveSettings();
365 if (m.isOk())
366 ok = true;
367 else
368 vboxProblem().cannotSaveMachineSettings (m, this);
369 }
370 else
371 vboxProblem().cannotAttachHardDisk (this, m,
372 mHDCombo->location(),
373 KStorageBus_IDE, 0, 0);
374 session.Close();
375 }
376 if (!ok)
377 {
378 /* unregister on failure */
379 vbox.UnregisterMachine (id);
380 if (vbox.isOk())
381 mMachine.DeleteSettings();
382 return false;
383 }
384 }
385
386 /* ensure we don't try to delete a newly created hard disk on success */
387 mHardDisk.detach();
388
389 return true;
390}
391
392void VBoxNewVMWzd::ensureNewHardDiskDeleted()
393{
394 if (!mHardDisk.isNull())
395 {
396 /* remember ID as it may be lost after the deletion */
397 QUuid id = mHardDisk.GetId();
398
399 bool success = false;
400
401 CProgress progress = mHardDisk.DeleteStorage();
402 if (mHardDisk.isOk())
403 {
404 vboxProblem().showModalProgressDialog (progress, caption(),
405 parentWidget());
406 if (progress.isOk() && progress.GetResultCode() == S_OK)
407 success = true;
408 }
409
410 if (success)
411 vboxGlobal().removeMedium (VBoxDefs::MediaType_HardDisk, id);
412 else
413 vboxProblem().cannotDeleteHardDiskStorage (this, mHardDisk,
414 progress);
415 mHardDisk.detach();
416 }
417}
418
419CMachine VBoxNewVMWzd::machine()
420{
421 return mMachine;
422}
423
424void VBoxNewVMWzd::showHardDiskManager()
425{
426 VBoxMediaManagerDlg dlg (this, "VBoxMediaManagerDlg", WType_Dialog | WShowModal);
427 dlg.setup (VBoxDefs::MediaType_HardDisk, true);
428
429 if (dlg.exec() == VBoxMediaManagerDlg::Accepted)
430 {
431 QUuid newId = dlg.selectedId();
432 if (mHDCombo->id() != newId)
433 {
434 ensureNewHardDiskDeleted();
435 mHDCombo->setCurrentItem (newId);
436 }
437 }
438
439 mHDCombo->setFocus();
440}
441
442void VBoxNewVMWzd::showNewHardDiskWizard()
443{
444 VBoxNewHDWzd dlg (this, "VBoxNewHDWzd");
445
446 CGuestOSType type = vboxGlobal().vmGuestOSType (cbOS->currentItem());
447
448 dlg.setRecommendedFileName (leName->text());
449 dlg.setRecommendedSize (type.GetRecommendedHDD());
450
451 if (dlg.exec() == QDialog::Accepted)
452 {
453 ensureNewHardDiskDeleted();
454 mHardDisk = dlg.hardDisk();
455
456 mHDCombo->setCurrentItem (mHardDisk.GetId());
457 mHDCombo->setFocus();
458 }
459}
460
461void VBoxNewVMWzd::slRAM_valueChanged (int val)
462{
463 leRAM->setText (QString().setNum (val));
464}
465
466void VBoxNewVMWzd::leRAM_textChanged (const QString &text)
467{
468 slRAM->setValue (text.toInt());
469}
470
471void VBoxNewVMWzd::cbOS_activated (int item)
472{
473 CGuestOSType type = vboxGlobal().vmGuestOSType (item);
474 pmOS->setPixmap (vboxGlobal().vmGuestOSTypeIcon (type.GetId()));
475 txRAMBest->setText (QString::null);
476 txRAMBest2->setText (
477 tr ("The recommended base memory size is <b>%1</b> MB.")
478 .arg (type.GetRecommendedRAM()));
479 slRAM->setValue (type.GetRecommendedRAM());
480 txVDIBest->setText (
481 tr ("The recommended size of the boot hard disk is <b>%1</b> MB.")
482 .arg (type.GetRecommendedHDD()));
483}
484
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette