VirtualBox

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

Last change on this file since 163 was 1, checked in by vboxsync, 55 years ago

import

  • 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);
102 mediaCombo->setUseEmptyItem (true);
103 mediaCombo->refresh();
104 grbHDALayout->addMultiCellWidget (mediaCombo, 0, 0, 0, 2);
105 setTabOrder (mediaCombo, pbNewHD);
106 setTabOrder (pbNewHD, pbExistingHD);
107 connect (mediaCombo, SIGNAL (activated (int)),
108 this, SLOT (currentMediaChanged (int)));
109
110 /// @todo (dmik) remove?
111 wvalHDD = new QIWidgetValidator (pageHDD, this);
112 connect (wvalHDD, SIGNAL (validityChanged (const QIWidgetValidator *)),
113 this, SLOT (enableNext (const QIWidgetValidator *)));
114 connect (wvalHDD, SIGNAL (isValidRequested (QIWidgetValidator *)),
115 this, SLOT (revalidate (QIWidgetValidator *)));
116
117 /*
118 * set initial values
119 * ----------------------------------------------------------------------
120 */
121
122 /* Name and OS page */
123
124 cbOS->insertStringList (vboxGlobal().vmGuestOSTypeDescriptions());
125 cbOS_activated (cbOS->currentItem());
126
127 /* Memory page */
128
129 slRAM->setPageStep (calcPageStep (MaxRAM));
130 slRAM->setLineStep (slRAM->pageStep() / 4);
131 slRAM->setTickInterval (slRAM->pageStep());
132 /* setup the scale so that ticks are at page step boundaries */
133 slRAM->setMinValue ((MinRAM / slRAM->pageStep()) * slRAM->pageStep());
134 slRAM->setMaxValue (MaxRAM);
135 txRAMMin->setText (tr ("<qt>%1&nbsp;MB</qt>").arg (MinRAM));
136 txRAMMax->setText (tr ("<qt>%1&nbsp;MB</qt>").arg (MaxRAM));
137 /*
138 * initial RAM value is set in cbOS_activated()
139 * limit min/max. size of QLineEdit
140 */
141 leRAM->setMaximumSize (leRAM->fontMetrics().width ("99999")
142 + leRAM->frameWidth() * 2,
143 leRAM->minimumSizeHint().height());
144 leRAM->setMinimumSize (leRAM->maximumSize());
145 /* ensure leRAM value and validation is updated */
146 slRAM_valueChanged (slRAM->value());
147
148 /* HDD Images page */
149
150 /* Summary page */
151
152 teSummary->setPaper (pageSummary->backgroundBrush());
153
154 /*
155 * update the next button state for pages with validation
156 * (validityChanged() connected to enableNext() will do the job)
157 */
158 wvalNameAndOS->revalidate();
159 wvalMemory->revalidate();
160 wvalHDD->revalidate();
161
162 /* the finish button on the Summary page is always enabled */
163 setFinishEnabled (pageSummary, true);
164
165 resize (sizeHint());
166}
167
168
169void VBoxNewVMWzd::destroy()
170{
171 ensureNewHardDiskDeleted();
172}
173
174void VBoxNewVMWzd::enableNext (const QIWidgetValidator *wval)
175{
176 setNextEnabled (wval->widget(), wval->isValid());
177}
178
179
180void VBoxNewVMWzd::revalidate (QIWidgetValidator *wval)
181{
182 /* do individual validations for pages */
183
184 bool valid = wval->isOtherValid();
185
186 if (wval == wvalHDD)
187 {
188 if (!chd.isNull() && mediaCombo->currentItem() != mediaCombo->count() - 1)
189 ensureNewHardDiskDeleted();
190 }
191
192 wval->setOtherValid( valid );
193}
194
195
196void VBoxNewVMWzd::showPage (QWidget *page)
197{
198 if (page == pageSummary)
199 {
200 /* compose summary */
201 QString summary = QString (tr (
202 "<tr><td>Name:</td><td>%1</td></tr>"
203 "<tr><td>OS Type:</td><td>%2</td></tr>"
204 "<tr><td>Base Memory:</td><td>%3&nbsp;MB</td></tr>"))
205 .arg (leName->text())
206 .arg (vboxGlobal().vmGuestOSType (cbOS->currentItem()).GetDescription())
207 .arg (slRAM->value());
208
209 if (mediaCombo->currentItem())
210 summary += QString (tr (
211 "<tr><td>Boot Hard Disk:</td><td>%4</td></tr>"))
212 .arg (mediaCombo->currentText());
213
214 teSummary->setText ("<table>" + summary + "</table>");
215
216 /* set Finish to default */
217 finishButton()->setDefault( true );
218 }
219 else
220 {
221 /* always set Next to default */
222 nextButton()->setDefault( true );
223 }
224
225 QWizard::showPage (page);
226
227 /*
228 * fix focus on the last page. when we go to the last page
229 * having the Next in focus the focus goes to the Cancel
230 * button because when the Next hides Finish is not yet shown.
231 */
232 if (page == pageSummary && focusWidget() == cancelButton())
233 finishButton()->setFocus();
234
235 /* setup focus for individual pages */
236 if (page == pageNameAndOS)
237 leName->setFocus();
238 else if (page == pageMemory)
239 slRAM->setFocus();
240 else if (page == pageHDD)
241 mediaCombo->setFocus();
242 else if (page == pageSummary)
243 teSummary->setFocus();
244}
245
246void VBoxNewVMWzd::accept()
247{
248 /*
249 * Try to create the machine when the Finish button is pressed.
250 * On failure, the wisard will remain open to give it another try.
251 */
252 if (constructMachine())
253 QWizard::accept();
254}
255
256bool VBoxNewVMWzd::constructMachine()
257{
258 CVirtualBox vbox = vboxGlobal().virtualBox();
259
260 /* create a machine with the default settings file location */
261 if (cmachine.isNull())
262 {
263 cmachine = vbox.CreateMachine (QString(), leName->text());
264 if (!vbox.isOk())
265 {
266 vboxProblem().cannotCreateMachine (vbox, this);
267 return false;
268 }
269 }
270
271 /* name is set in CreateMachine() */
272
273 /* OS type */
274 CGuestOSType type = vboxGlobal().vmGuestOSType (cbOS->currentItem());
275 AssertMsg (!type.isNull(), ("vmGuestOSType() must return non-null type"));
276 cmachine.SetOSType (type);
277
278 /* RAM size */
279 cmachine.SetMemorySize (slRAM->value());
280
281 /* add one network adapter (NAT) by default */
282 {
283 CNetworkAdapter cadapter = cmachine.GetNetworkAdapter (0);
284 cadapter.SetEnabled (true);
285 cadapter.AttachToNAT();
286 cadapter.SetMACAddress (QString::null);
287 cadapter.SetCableConnected (true);
288 }
289
290 /* register the VM prior to attaching hard disks */
291 vbox.RegisterMachine (cmachine);
292 if (!vbox.isOk())
293 {
294 vboxProblem().cannotCreateMachine (vbox, cmachine, this);
295 return false;
296 }
297
298 /* Boot hard disk (Primary Master) */
299 if (!uuidHD.isNull())
300 {
301 bool ok = false;
302 QUuid id = cmachine.GetId();
303 CSession session = vboxGlobal().openSession (id);
304 if (!session.isNull())
305 {
306 CMachine m = session.GetMachine();
307 m.AttachHardDisk (uuidHD, CEnums::IDE0Controller, 0);
308 if (m.isOk())
309 {
310 m.SaveSettings();
311 if (m.isOk())
312 ok = true;
313 else
314 vboxProblem().cannotSaveMachineSettings (m, this);
315 }
316 else
317 vboxProblem().cannotAttachHardDisk (this, m, uuidHD,
318 CEnums::IDE0Controller, 0);
319 session.Close();
320 }
321 if (!ok)
322 {
323 /* unregister on failure */
324 vbox.UnregisterMachine (id);
325 if (vbox.isOk())
326 cmachine.DeleteSettings();
327 return false;
328 }
329 }
330
331 /* ensure we don't delete a newly created hard disk on success */
332 chd.detach();
333
334 return true;
335}
336
337void VBoxNewVMWzd::ensureNewHardDiskDeleted()
338{
339 if (!chd.isNull())
340 {
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 mediaCombo->removeLastItem();
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 if (dlg.exec() == VBoxDiskImageManagerDlg::Accepted)
371 {
372 /* fetch uuid and name/path */
373 if (dlg.getSelectedUuid() != uuidHD)
374 {
375 ensureNewHardDiskDeleted();
376 uuidHD = dlg.getSelectedUuid();
377 }
378 /* refresh media combobox */
379 mediaCombo->setRequiredItem (uuidHD);
380 mediaCombo->refresh();
381 mediaCombo->setFocus();
382 /* revailidate */
383 wvalHDD->revalidate();
384 }
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 QFileInfo fi (chd.GetLocation());
404 mediaCombo->appendItem (fi.fileName() + " (" +
405 QDir::convertSeparators (fi.dirPath()) + ")", uuidHD);
406 mediaCombo->setCurrentItem (mediaCombo->count() - 1);
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.

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