VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageBasic4.cpp@ 40870

Last change on this file since 40870 was 40870, checked in by vboxsync, 13 years ago

FE/Qt: 6123: Rework VirtualBox wizards to unify them at the common architecture required for an expert-mode support.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 9.8 KB
Line 
1/* $Id: UIWizardNewVMPageBasic4.cpp 40870 2012-04-11 15:44:29Z vboxsync $ */
2/** @file
3 *
4 * VBox frontends: Qt4 GUI ("VirtualBox"):
5 * UIWizardNewVMPageBasic4 class implementation
6 */
7
8/*
9 * Copyright (C) 2006-2012 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20/* Global includes: */
21#include <QMetaType>
22#include <QVBoxLayout>
23#include <QGridLayout>
24#include <QGroupBox>
25#include <QRadioButton>
26
27/* Local includes: */
28#include "UIWizardNewVMPageBasic4.h"
29#include "UIWizardNewVM.h"
30#include "UIIconPool.h"
31#include "UIMessageCenter.h"
32#include "VBoxDefs.h"
33#include "QIRichTextLabel.h"
34#include "VBoxMediaComboBox.h"
35#include "QIToolButton.h"
36#include "UIWizardNewVD.h"
37
38UIWizardNewVMPageBasic4::UIWizardNewVMPageBasic4()
39{
40 /* Create widgets: */
41 QVBoxLayout *pMainLayout = new QVBoxLayout(this);
42 m_pLabel1 = new QIRichTextLabel(this);
43 m_pLabel2 = new QIRichTextLabel(this);
44 m_pBootHDCnt = new QGroupBox(this);
45 m_pBootHDCnt->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
46 m_pBootHDCnt->setCheckable(true);
47 QGridLayout *pDiskLayout = new QGridLayout(m_pBootHDCnt);
48 m_pDiskCreate = new QRadioButton(m_pBootHDCnt);
49 m_pDiskPresent = new QRadioButton(m_pBootHDCnt);
50 QStyleOptionButton options;
51 options.initFrom(m_pDiskCreate);
52 int wid = m_pDiskCreate->style()->subElementRect(QStyle::SE_RadioButtonIndicator, &options, m_pDiskCreate).width() +
53 m_pDiskCreate->style()->pixelMetric(QStyle::PM_RadioButtonLabelSpacing, &options, m_pDiskCreate) -
54 pDiskLayout->spacing() - 1;
55 QSpacerItem *pSpacer = new QSpacerItem(wid, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
56 m_pDiskSelector = new VBoxMediaComboBox(m_pBootHDCnt);
57 m_pDiskSelector->setType(VBoxDefs::MediumType_HardDisk);
58 m_pDiskSelector->repopulate();
59 m_pVMMButton = new QIToolButton(m_pBootHDCnt);
60 m_pVMMButton->setAutoRaise(true);
61 m_pVMMButton->setIcon(UIIconPool::iconSet(":/select_file_16px.png", ":/select_file_dis_16px.png"));
62 pDiskLayout->addWidget(m_pDiskCreate, 0, 0, 1, 3);
63 pDiskLayout->addWidget(m_pDiskPresent, 1, 0, 1, 3);
64 pDiskLayout->addItem(pSpacer, 2, 0);
65 pDiskLayout->addWidget(m_pDiskSelector, 2, 1);
66 pDiskLayout->addWidget(m_pVMMButton, 2, 2);
67 pMainLayout->addWidget(m_pLabel1);
68 pMainLayout->addWidget(m_pLabel2);
69 pMainLayout->addWidget(m_pBootHDCnt);
70 pMainLayout->addStretch();
71
72 /* Setup connections: */
73 connect(m_pBootHDCnt, SIGNAL(toggled(bool)), this, SLOT(virtualDiskSourceChanged()));
74 connect(m_pDiskCreate, SIGNAL(toggled(bool)), this, SLOT(virtualDiskSourceChanged()));
75 connect(m_pDiskPresent, SIGNAL(toggled(bool)), this, SLOT(virtualDiskSourceChanged()));
76 connect(m_pDiskSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(virtualDiskSourceChanged()));
77 connect(m_pVMMButton, SIGNAL(clicked()), this, SLOT(getWithFileOpenDialog()));
78
79 /* Initialise connections: */
80 virtualDiskSourceChanged();
81
82 /* Register CMedium class: */
83 qRegisterMetaType<CMedium>();
84 /* Register fields: */
85 registerField("virtualDisk", this, "virtualDisk");
86 registerField("virtualDiskId", this, "virtualDiskId");
87 registerField("virtualDiskName", this, "virtualDiskName");
88 registerField("virtualDiskLocation", this, "virtualDiskLocation");
89}
90
91void UIWizardNewVMPageBasic4::ensureNewVirtualDiskDeleted()
92{
93 if (m_virtualDisk.isNull())
94 return;
95
96 QString strId = m_virtualDisk.GetId();
97
98 bool fSuccess = false;
99
100 CProgress progress = m_virtualDisk.DeleteStorage();
101 if (m_virtualDisk.isOk())
102 {
103 msgCenter().showModalProgressDialog(progress, windowTitle(), ":/progress_media_delete_90px.png", this, true);
104 if (progress.isOk() && progress.GetResultCode() == S_OK)
105 fSuccess = true;
106 }
107
108 if (fSuccess)
109 vboxGlobal().removeMedium(VBoxDefs::MediumType_HardDisk, strId);
110 else
111 msgCenter().cannotDeleteHardDiskStorage(this, m_virtualDisk, progress);
112
113 m_virtualDisk.detach();
114}
115
116void UIWizardNewVMPageBasic4::virtualDiskSourceChanged()
117{
118 m_pDiskCreate->setEnabled(m_pBootHDCnt->isChecked());
119 m_pDiskPresent->setEnabled(m_pBootHDCnt->isChecked());
120 m_pDiskSelector->setEnabled(m_pDiskPresent->isEnabled() && m_pDiskPresent->isChecked());
121 m_pVMMButton->setEnabled(m_pDiskPresent->isEnabled() && m_pDiskPresent->isChecked());
122
123 if (m_pBootHDCnt->isChecked() && m_pDiskPresent->isChecked())
124 {
125 m_strVirtualDiskId = m_pDiskSelector->id();
126 m_strVirtualDiskName = m_pDiskSelector->currentText();
127 m_strVirtualDiskLocation = m_pDiskSelector->location();
128 }
129 else
130 {
131 m_strVirtualDiskId.clear();
132 m_strVirtualDiskName.clear();
133 m_strVirtualDiskLocation.clear();
134 }
135
136 emit completeChanged();
137}
138
139void UIWizardNewVMPageBasic4::getWithFileOpenDialog()
140{
141 /* Get opened vboxMedium id: */
142 QString strMediumId = vboxGlobal().openMediumWithFileOpenDialog(VBoxDefs::MediumType_HardDisk, this);
143 if (!strMediumId.isNull())
144 {
145 /* Update medium-combo if necessary: */
146 m_pDiskSelector->setCurrentItem(strMediumId);
147 /* Update hard disk source: */
148 virtualDiskSourceChanged();
149 /* Focus on hard disk combo: */
150 m_pDiskSelector->setFocus();
151 }
152}
153
154void UIWizardNewVMPageBasic4::retranslateUi()
155{
156 /* Translate page: */
157 setTitle(UIWizardNewVM::tr("Virtual Hard Disk"));
158
159 /* Translate widgets: */
160 m_pLabel1->setText(UIWizardNewVM::tr("<p>If you wish you can now add a start-up disk to the new machine. "
161 "You can either create a new virtual disk or select one from the list "
162 "or from another location using the folder icon.</p>"
163 "<p>If you need a more complex virtual disk setup you can skip this step "
164 "and make the changes to the machine settings once the machine is created.</p>"));
165 QString strRecommendedHDD = field("type").value<CGuestOSType>().isNull() ? QString() :
166 VBoxGlobal::formatSize(field("type").value<CGuestOSType>().GetRecommendedHDD());
167 m_pLabel2->setText(UIWizardNewVM::tr("The recommended size of the start-up disk is <b>%1</b>.").arg(strRecommendedHDD));
168 m_pBootHDCnt->setTitle(UIWizardNewVM::tr("Start-up &Disk"));
169 m_pDiskCreate->setText(UIWizardNewVM::tr("&Create new hard disk"));
170 m_pDiskPresent->setText(UIWizardNewVM::tr("&Use existing hard disk"));
171 m_pVMMButton->setToolTip(UIWizardNewVM::tr("Choose a virtual hard disk file..."));
172}
173
174void UIWizardNewVMPageBasic4::initializePage()
175{
176 /* Translate page: */
177 retranslateUi();
178
179 /* Prepare initial choice: */
180 m_pBootHDCnt->setChecked(true);
181 m_pDiskSelector->setCurrentIndex(0);
182 m_pDiskCreate->setChecked(true);
183
184 /* 'Create new hard-disk' should have focus initially: */
185 m_pDiskCreate->setFocus();
186}
187
188void UIWizardNewVMPageBasic4::cleanupPage()
189{
190 /* Clean medium if present */
191 ensureNewVirtualDiskDeleted();
192 /* Clean fields of that page */
193 UIWizardPage::cleanupPage();
194}
195
196bool UIWizardNewVMPageBasic4::isComplete() const
197{
198 /* Check what virtualDisk feats the rules: */
199 return !m_pBootHDCnt->isChecked() ||
200 !m_pDiskPresent->isChecked() ||
201 !vboxGlobal().findMedium(m_pDiskSelector->id()).isNull();
202}
203
204bool UIWizardNewVMPageBasic4::validatePage()
205{
206 /* Ensure unused virtual-disk is deleted: */
207 if (!m_pBootHDCnt->isChecked() || m_pDiskCreate->isChecked() || (!m_virtualDisk.isNull() && m_strVirtualDiskId != m_virtualDisk.GetId()))
208 ensureNewVirtualDiskDeleted();
209
210 /* Ask user about disk-less machine: */
211 if (!m_pBootHDCnt->isChecked() && !msgCenter().confirmHardDisklessMachine(this))
212 return false;
213
214 /* Show the New Virtual Disk wizard: */
215 if (m_pBootHDCnt->isChecked() && m_pDiskCreate->isChecked() && !getWithNewVirtualDiskWizard())
216 return false;
217
218 return true;
219}
220
221bool UIWizardNewVMPageBasic4::getWithNewVirtualDiskWizard()
222{
223 UIWizardNewVD dlg(this, field("machineBaseName").toString(), field("machineFolder").toString(), field("type").value<CGuestOSType>().GetRecommendedHDD());
224 if (dlg.exec() == QDialog::Accepted)
225 {
226 m_virtualDisk = dlg.virtualDisk();
227 m_pDiskSelector->setCurrentItem(m_virtualDisk.GetId());
228 m_pDiskPresent->click();
229 return true;
230 }
231 return false;
232}
233
234CMedium UIWizardNewVMPageBasic4::virtualDisk() const
235{
236 return m_virtualDisk;
237}
238
239void UIWizardNewVMPageBasic4::setVirtualDisk(const CMedium &virtualDisk)
240{
241 m_virtualDisk = virtualDisk;
242}
243
244QString UIWizardNewVMPageBasic4::virtualDiskId() const
245{
246 return m_strVirtualDiskId;
247}
248
249void UIWizardNewVMPageBasic4::setVirtualDiskId(const QString &strVirtualDiskId)
250{
251 m_strVirtualDiskId = strVirtualDiskId;
252}
253
254QString UIWizardNewVMPageBasic4::virtualDiskName() const
255{
256 return m_strVirtualDiskName;
257}
258
259void UIWizardNewVMPageBasic4::setVirtualDiskName(const QString &strVirtualDiskName)
260{
261 m_strVirtualDiskName = strVirtualDiskName;
262}
263
264QString UIWizardNewVMPageBasic4::virtualDiskLocation() const
265{
266 return m_strVirtualDiskLocation;
267}
268
269void UIWizardNewVMPageBasic4::setVirtualDiskLocation(const QString &strVirtualDiskLocation)
270{
271 m_strVirtualDiskLocation = strVirtualDiskLocation;
272}
273
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