1 | /* $Id: UIWizardNewVMPageBasic4.cpp 87869 2021-02-25 09:34:33Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIWizardNewVMPageBasic4 class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2020 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | /* Qt includes: */
|
---|
19 | #include <QGridLayout>
|
---|
20 | #include <QMetaType>
|
---|
21 | #include <QRadioButton>
|
---|
22 | #include <QVBoxLayout>
|
---|
23 |
|
---|
24 | /* GUI includes: */
|
---|
25 | #include "QIRichTextLabel.h"
|
---|
26 | #include "QIToolButton.h"
|
---|
27 | #include "UIIconPool.h"
|
---|
28 | #include "UIMediaComboBox.h"
|
---|
29 | #include "UIMedium.h"
|
---|
30 | #include "UIMediumSelector.h"
|
---|
31 | #include "UIMessageCenter.h"
|
---|
32 | #include "UIWizardNewVD.h"
|
---|
33 | #include "UIWizardNewVM.h"
|
---|
34 | #include "UIWizardNewVMPageBasic4.h"
|
---|
35 |
|
---|
36 | UIWizardNewVMPage4::UIWizardNewVMPage4()
|
---|
37 | : m_fRecommendedNoDisk(false)
|
---|
38 | , m_pDiskSkip(0)
|
---|
39 | , m_pDiskCreate(0)
|
---|
40 | , m_pDiskPresent(0)
|
---|
41 | , m_pDiskSelector(0)
|
---|
42 | , m_pVMMButton(0)
|
---|
43 | {
|
---|
44 | }
|
---|
45 |
|
---|
46 | void UIWizardNewVMPage4::updateVirtualDiskSource()
|
---|
47 | {
|
---|
48 | if (!m_pDiskSelector || !m_pVMMButton)
|
---|
49 | return;
|
---|
50 |
|
---|
51 | /* Enable/disable controls: */
|
---|
52 | m_pDiskSelector->setEnabled(m_pDiskPresent->isChecked());
|
---|
53 | m_pVMMButton->setEnabled(m_pDiskPresent->isChecked());
|
---|
54 |
|
---|
55 | /* Fetch filed values: */
|
---|
56 | if (m_pDiskSkip->isChecked())
|
---|
57 | {
|
---|
58 | m_uVirtualDiskId = QUuid();
|
---|
59 | m_strVirtualDiskName = QString();
|
---|
60 | m_strVirtualDiskLocation = QString();
|
---|
61 | }
|
---|
62 | else if (m_pDiskPresent->isChecked())
|
---|
63 | {
|
---|
64 | m_uVirtualDiskId = m_pDiskSelector->id();
|
---|
65 | m_strVirtualDiskName = m_pDiskSelector->currentText();
|
---|
66 | m_strVirtualDiskLocation = m_pDiskSelector->location();
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | void UIWizardNewVMPage4::getWithFileOpenDialog()
|
---|
71 | {
|
---|
72 | /* Get opened medium id: */
|
---|
73 | QUuid uMediumId;
|
---|
74 |
|
---|
75 | int returnCode = uiCommon().openMediumSelectorDialog(thisImp(), UIMediumDeviceType_HardDisk,
|
---|
76 | uMediumId,
|
---|
77 | fieldImp("machineFolder").toString(),
|
---|
78 | fieldImp("machineBaseName").toString(),
|
---|
79 | fieldImp("type").value<CGuestOSType>().GetId(),
|
---|
80 | false /* don't show/enable the create action: */);
|
---|
81 |
|
---|
82 | if (returnCode == static_cast<int>(UIMediumSelector::ReturnCode_Accepted) && !uMediumId.isNull())
|
---|
83 | {
|
---|
84 | /* Update medium-combo if necessary: */
|
---|
85 | m_pDiskSelector->setCurrentItem(uMediumId);
|
---|
86 | /* Update hard disk source: */
|
---|
87 | updateVirtualDiskSource();
|
---|
88 | /* Focus on hard disk combo: */
|
---|
89 | m_pDiskSelector->setFocus();
|
---|
90 | }
|
---|
91 | }
|
---|
92 |
|
---|
93 | bool UIWizardNewVMPage4::getWithNewVirtualDiskWizard()
|
---|
94 | {
|
---|
95 | /* Create New Virtual Hard Drive wizard: */
|
---|
96 | UISafePointerWizardNewVD pWizard = new UIWizardNewVD(thisImp(),
|
---|
97 | fieldImp("machineBaseName").toString(),
|
---|
98 | fieldImp("machineFolder").toString(),
|
---|
99 | fieldImp("type").value<CGuestOSType>().GetRecommendedHDD(),
|
---|
100 | wizardImp()->mode());
|
---|
101 | pWizard->prepare();
|
---|
102 | bool fResult = false;
|
---|
103 | if (pWizard->exec() == QDialog::Accepted)
|
---|
104 | {
|
---|
105 | fResult = true;
|
---|
106 | m_virtualDisk = pWizard->virtualDisk();
|
---|
107 | m_pDiskSelector->setCurrentItem(m_virtualDisk.GetId());
|
---|
108 | m_pDiskPresent->click();
|
---|
109 | }
|
---|
110 | if (pWizard)
|
---|
111 | delete pWizard;
|
---|
112 | return fResult;
|
---|
113 | }
|
---|
114 |
|
---|
115 | void UIWizardNewVMPage4::ensureNewVirtualDiskDeleted()
|
---|
116 | {
|
---|
117 | /* Make sure virtual-disk valid: */
|
---|
118 | if (m_virtualDisk.isNull())
|
---|
119 | return;
|
---|
120 |
|
---|
121 | /* Remember virtual-disk attributes: */
|
---|
122 | QString strLocation = m_virtualDisk.GetLocation();
|
---|
123 | /* Prepare delete storage progress: */
|
---|
124 | CProgress progress = m_virtualDisk.DeleteStorage();
|
---|
125 | if (m_virtualDisk.isOk())
|
---|
126 | {
|
---|
127 | /* Show delete storage progress: */
|
---|
128 | msgCenter().showModalProgressDialog(progress, thisImp()->windowTitle(), ":/progress_media_delete_90px.png", thisImp());
|
---|
129 | if (!progress.isOk() || progress.GetResultCode() != 0)
|
---|
130 | msgCenter().cannotDeleteHardDiskStorage(progress, strLocation, thisImp());
|
---|
131 | }
|
---|
132 | else
|
---|
133 | msgCenter().cannotDeleteHardDiskStorage(m_virtualDisk, strLocation, thisImp());
|
---|
134 |
|
---|
135 | /* Detach virtual-disk anyway: */
|
---|
136 | m_virtualDisk.detach();
|
---|
137 | }
|
---|
138 |
|
---|
139 | void UIWizardNewVMPage4::retranslateWidgets()
|
---|
140 | {
|
---|
141 | if (m_pDiskSkip)
|
---|
142 | m_pDiskSkip->setText(UIWizardNewVM::tr("&Do not add a virtual hard disk"));
|
---|
143 | if (m_pDiskCreate)
|
---|
144 | m_pDiskCreate->setText(UIWizardNewVM::tr("&Create a virtual hard disk now"));
|
---|
145 | if (m_pDiskPresent)
|
---|
146 | m_pDiskPresent->setText(UIWizardNewVM::tr("&Use an existing virtual hard disk file"));
|
---|
147 | if (m_pVMMButton)
|
---|
148 | m_pVMMButton->setToolTip(UIWizardNewVM::tr("Choose a virtual hard disk file..."));
|
---|
149 | }
|
---|
150 |
|
---|
151 | QWidget *UIWizardNewVMPage4::createDiskWidgets()
|
---|
152 | {
|
---|
153 | QWidget *pDiskContainer = new QWidget;
|
---|
154 | QGridLayout *pDiskLayout = new QGridLayout(pDiskContainer);
|
---|
155 |
|
---|
156 | m_pDiskSkip = new QRadioButton;
|
---|
157 | m_pDiskCreate = new QRadioButton;
|
---|
158 | m_pDiskPresent = new QRadioButton;
|
---|
159 | QStyleOptionButton options;
|
---|
160 | options.initFrom(m_pDiskPresent);
|
---|
161 | int iWidth = m_pDiskPresent->style()->pixelMetric(QStyle::PM_ExclusiveIndicatorWidth, &options, m_pDiskPresent);
|
---|
162 | pDiskLayout->setColumnMinimumWidth(0, iWidth);
|
---|
163 | m_pDiskSelector = new UIMediaComboBox;
|
---|
164 | {
|
---|
165 | m_pDiskSelector->setType(UIMediumDeviceType_HardDisk);
|
---|
166 | m_pDiskSelector->repopulate();
|
---|
167 | }
|
---|
168 | m_pVMMButton = new QIToolButton;
|
---|
169 | {
|
---|
170 | m_pVMMButton->setAutoRaise(true);
|
---|
171 | m_pVMMButton->setIcon(UIIconPool::iconSet(":/select_file_16px.png", ":/select_file_disabled_16px.png"));
|
---|
172 | }
|
---|
173 | pDiskLayout->addWidget(m_pDiskSkip, 0, 0, 1, 3);
|
---|
174 | pDiskLayout->addWidget(m_pDiskCreate, 1, 0, 1, 3);
|
---|
175 | pDiskLayout->addWidget(m_pDiskPresent, 2, 0, 1, 3);
|
---|
176 | pDiskLayout->addWidget(m_pDiskSelector, 3, 1);
|
---|
177 | pDiskLayout->addWidget(m_pVMMButton, 3, 2);
|
---|
178 | return pDiskContainer;
|
---|
179 | }
|
---|
180 |
|
---|
181 | UIWizardNewVMPageBasic4::UIWizardNewVMPageBasic4()
|
---|
182 | : m_pLabel(0)
|
---|
183 | {
|
---|
184 | prepare();
|
---|
185 | qRegisterMetaType<CMedium>();
|
---|
186 | registerField("virtualDisk", this, "virtualDisk");
|
---|
187 | registerField("virtualDiskId", this, "virtualDiskId");
|
---|
188 | registerField("virtualDiskName", this, "virtualDiskName");
|
---|
189 | registerField("virtualDiskLocation", this, "virtualDiskLocation");
|
---|
190 | }
|
---|
191 |
|
---|
192 | int UIWizardNewVMPageBasic4::nextId() const
|
---|
193 | {
|
---|
194 | if (m_pDiskCreate->isChecked())
|
---|
195 | return UIWizardNewVM::Page5;
|
---|
196 | return UIWizardNewVM::Page8;
|
---|
197 | }
|
---|
198 |
|
---|
199 | void UIWizardNewVMPageBasic4::prepare()
|
---|
200 | {
|
---|
201 | QVBoxLayout *pMainLayout = new QVBoxLayout(this);
|
---|
202 |
|
---|
203 | m_pLabel = new QIRichTextLabel(this);
|
---|
204 | pMainLayout->addWidget(m_pLabel);
|
---|
205 | pMainLayout->addWidget(createDiskWidgets());
|
---|
206 |
|
---|
207 | pMainLayout->addStretch();
|
---|
208 | updateVirtualDiskSource();
|
---|
209 | createConnections();
|
---|
210 | }
|
---|
211 |
|
---|
212 | void UIWizardNewVMPageBasic4::createConnections()
|
---|
213 | {
|
---|
214 | connect(m_pDiskSkip, &QRadioButton::toggled,
|
---|
215 | this, &UIWizardNewVMPageBasic4::sltVirtualDiskSourceChanged);
|
---|
216 | connect(m_pDiskCreate, &QRadioButton::toggled,
|
---|
217 | this, &UIWizardNewVMPageBasic4::sltVirtualDiskSourceChanged);
|
---|
218 | connect(m_pDiskPresent, &QRadioButton::toggled,
|
---|
219 | this, &UIWizardNewVMPageBasic4::sltVirtualDiskSourceChanged);
|
---|
220 | connect(m_pDiskSelector, static_cast<void(UIMediaComboBox::*)(int)>(&UIMediaComboBox::currentIndexChanged),
|
---|
221 | this, &UIWizardNewVMPageBasic4::sltVirtualDiskSourceChanged);
|
---|
222 | connect(m_pVMMButton, &QIToolButton::clicked,
|
---|
223 | this, &UIWizardNewVMPageBasic4::sltGetWithFileOpenDialog);
|
---|
224 | }
|
---|
225 |
|
---|
226 | void UIWizardNewVMPageBasic4::sltVirtualDiskSourceChanged()
|
---|
227 | {
|
---|
228 | /* Call to base-class: */
|
---|
229 | updateVirtualDiskSource();
|
---|
230 |
|
---|
231 | /* Broadcast complete-change: */
|
---|
232 | emit completeChanged();
|
---|
233 | }
|
---|
234 |
|
---|
235 | void UIWizardNewVMPageBasic4::sltGetWithFileOpenDialog()
|
---|
236 | {
|
---|
237 | /* Call to base-class: */
|
---|
238 | getWithFileOpenDialog();
|
---|
239 | }
|
---|
240 |
|
---|
241 | void UIWizardNewVMPageBasic4::retranslateUi()
|
---|
242 | {
|
---|
243 | setTitle(UIWizardNewVM::tr("Virtual Hard disk"));
|
---|
244 |
|
---|
245 | QString strRecommendedHDD = field("type").value<CGuestOSType>().isNull() ? QString() :
|
---|
246 | UICommon::formatSize(field("type").value<CGuestOSType>().GetRecommendedHDD());
|
---|
247 | if (m_pLabel)
|
---|
248 | m_pLabel->setText(UIWizardNewVM::tr("<p>If you wish you can add a virtual hard disk to the new machine. "
|
---|
249 | "You can either create a new hard disk file or select one from the list "
|
---|
250 | "or from another location using the folder icon. "
|
---|
251 | "If you need a more complex storage set-up you can skip this step "
|
---|
252 | "and make the changes to the machine settings once the machine is created. "
|
---|
253 | "The recommended size of the hard disk is <b>%1</b>.</p>")
|
---|
254 | .arg(strRecommendedHDD));
|
---|
255 |
|
---|
256 | retranslateWidgets();
|
---|
257 | }
|
---|
258 |
|
---|
259 | void UIWizardNewVMPageBasic4::initializePage()
|
---|
260 | {
|
---|
261 | retranslateUi();
|
---|
262 |
|
---|
263 | if (!field("type").canConvert<CGuestOSType>())
|
---|
264 | return;
|
---|
265 |
|
---|
266 | CGuestOSType type = field("type").value<CGuestOSType>();
|
---|
267 |
|
---|
268 | if (type.GetRecommendedHDD() != 0)
|
---|
269 | {
|
---|
270 | if (m_pDiskCreate)
|
---|
271 | {
|
---|
272 | m_pDiskCreate->setFocus();
|
---|
273 | m_pDiskCreate->setChecked(true);
|
---|
274 | }
|
---|
275 | m_fRecommendedNoDisk = false;
|
---|
276 | }
|
---|
277 | else
|
---|
278 | {
|
---|
279 | if (m_pDiskSkip)
|
---|
280 | {
|
---|
281 | m_pDiskSkip->setFocus();
|
---|
282 | m_pDiskSkip->setChecked(true);
|
---|
283 | }
|
---|
284 | m_fRecommendedNoDisk = true;
|
---|
285 | }
|
---|
286 | if (m_pDiskSelector)
|
---|
287 | m_pDiskSelector->setCurrentIndex(0);
|
---|
288 | }
|
---|
289 |
|
---|
290 | void UIWizardNewVMPageBasic4::cleanupPage()
|
---|
291 | {
|
---|
292 | /* Call to base-class: */
|
---|
293 | ensureNewVirtualDiskDeleted();
|
---|
294 | UIWizardPage::cleanupPage();
|
---|
295 | }
|
---|
296 |
|
---|
297 | bool UIWizardNewVMPageBasic4::isComplete() const
|
---|
298 | {
|
---|
299 | if (!m_pDiskSkip)
|
---|
300 | return false;
|
---|
301 | return m_pDiskSkip->isChecked() ||
|
---|
302 | !m_pDiskPresent->isChecked() ||
|
---|
303 | !uiCommon().medium(m_pDiskSelector->id()).isNull();
|
---|
304 | }
|
---|
305 |
|
---|
306 | // bool UIWizardNewVMPageBasic4::validatePage()
|
---|
307 | // {
|
---|
308 | // /* Initial result: */
|
---|
309 | // bool fResult = true;
|
---|
310 |
|
---|
311 | // /* Ensure unused virtual-disk is deleted: */
|
---|
312 | // if (m_pDiskSkip->isChecked() || m_pDiskCreate->isChecked() || (!m_virtualDisk.isNull() && m_uVirtualDiskId != m_virtualDisk.GetId()))
|
---|
313 | // ensureNewVirtualDiskDeleted();
|
---|
314 |
|
---|
315 | // if (m_pDiskSkip->isChecked())
|
---|
316 | // {
|
---|
317 | // /* Ask user about disk-less machine unless that's the recommendation: */
|
---|
318 | // if (!m_fRecommendedNoDisk)
|
---|
319 | // fResult = msgCenter().confirmHardDisklessMachine(thisImp());
|
---|
320 | // }
|
---|
321 | // else if (m_pDiskCreate->isChecked())
|
---|
322 | // {
|
---|
323 | // /* Show the New Virtual Hard Drive wizard: */
|
---|
324 | // fResult = getWithNewVirtualDiskWizard();
|
---|
325 | // }
|
---|
326 |
|
---|
327 | // if (fResult)
|
---|
328 | // {
|
---|
329 | // /* Lock finish button: */
|
---|
330 | // startProcessing();
|
---|
331 |
|
---|
332 | // /* Try to create VM: */
|
---|
333 | // fResult = qobject_cast<UIWizardNewVM*>(wizard())->createVM();
|
---|
334 |
|
---|
335 | // /* Unlock finish button: */
|
---|
336 | // endProcessing();
|
---|
337 | // }
|
---|
338 |
|
---|
339 | // /* Return result: */
|
---|
340 | // return fResult;
|
---|
341 | // }
|
---|