1 | /* $Id: UIWizardDiskEditors.cpp 101563 2023-10-23 23:36:38Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIUserNamePasswordEditor class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | /* Qt includes: */
|
---|
29 | #include <QButtonGroup>
|
---|
30 | #include <QCheckBox>
|
---|
31 | #include <QDir>
|
---|
32 | #include <QFileInfo>
|
---|
33 | #include <QLabel>
|
---|
34 | #include <QRadioButton>
|
---|
35 | #include <QVBoxLayout>
|
---|
36 |
|
---|
37 | /* GUI includes: */
|
---|
38 | #include "QILineEdit.h"
|
---|
39 | #include "QIToolButton.h"
|
---|
40 | #include "QIRichTextLabel.h"
|
---|
41 | #include "UICommon.h"
|
---|
42 | #include "UIConverter.h"
|
---|
43 | #include "UIFilePathSelector.h"
|
---|
44 | #include "UIHostnameDomainNameEditor.h"
|
---|
45 | #include "UIIconPool.h"
|
---|
46 | #include "UIMediumSizeEditor.h"
|
---|
47 | #include "UIUserNamePasswordEditor.h"
|
---|
48 | #include "UIWizardDiskEditors.h"
|
---|
49 | #include "UIWizardNewVMDiskPage.h"
|
---|
50 |
|
---|
51 | /* Other VBox includes: */
|
---|
52 | #include "iprt/assert.h"
|
---|
53 | #include "iprt/fs.h"
|
---|
54 | #include "CSystemProperties.h"
|
---|
55 |
|
---|
56 |
|
---|
57 | /*********************************************************************************************************************************
|
---|
58 | * UIWizardDiskEditors implementation. *
|
---|
59 | *********************************************************************************************************************************/
|
---|
60 |
|
---|
61 | QString UIWizardDiskEditors::appendExtension(const QString &strName, const QString &strExtension)
|
---|
62 | {
|
---|
63 | /* Convert passed name to native separators: */
|
---|
64 | QString strFileName = QDir::toNativeSeparators(strName);
|
---|
65 |
|
---|
66 | /* Remove all trailing dots to avoid multiple dots before extension: */
|
---|
67 | int iLen;
|
---|
68 | while (iLen = strFileName.length(), iLen > 0 && strFileName[iLen - 1] == '.')
|
---|
69 | strFileName.truncate(iLen - 1);
|
---|
70 |
|
---|
71 | /* Add passed extension if its not done yet: */
|
---|
72 | if (QFileInfo(strFileName).suffix().toLower() != strExtension)
|
---|
73 | strFileName += QString(".%1").arg(strExtension);
|
---|
74 |
|
---|
75 | /* Return result: */
|
---|
76 | return strFileName;
|
---|
77 | }
|
---|
78 |
|
---|
79 | QString UIWizardDiskEditors::constructMediumFilePath(const QString &strFileName, const QString &strPath)
|
---|
80 | {
|
---|
81 | /* Wrap file-info around received file name: */
|
---|
82 | QFileInfo fileInfo(strFileName);
|
---|
83 | /* If path-info is relative or there is no path-info at all: */
|
---|
84 | if (fileInfo.fileName() == strFileName || fileInfo.isRelative())
|
---|
85 | {
|
---|
86 | /* Resolve path on the basis of path we have: */
|
---|
87 | fileInfo = QFileInfo(strPath, strFileName);
|
---|
88 | }
|
---|
89 | /* Return full absolute hard disk file path: */
|
---|
90 | return QDir::toNativeSeparators(fileInfo.absoluteFilePath());
|
---|
91 | }
|
---|
92 |
|
---|
93 | bool UIWizardDiskEditors::checkFATSizeLimitation(const qulonglong uVariant, const QString &strMediumPath, const qulonglong uSize)
|
---|
94 | {
|
---|
95 | /* If the hard disk is split into 2GB parts then no need to make further checks: */
|
---|
96 | if (uVariant & KMediumVariant_VmdkSplit2G)
|
---|
97 | return true;
|
---|
98 | RTFSTYPE enmType;
|
---|
99 | int rc = RTFsQueryType(QFileInfo(strMediumPath).absolutePath().toLatin1().constData(), &enmType);
|
---|
100 | if (RT_SUCCESS(rc))
|
---|
101 | {
|
---|
102 | if (enmType == RTFSTYPE_FAT)
|
---|
103 | {
|
---|
104 | /* Limit the medium size to 4GB. minus 128 MB for file overhead: */
|
---|
105 | qulonglong fatLimit = _4G - _128M;
|
---|
106 | if (uSize >= fatLimit)
|
---|
107 | return false;
|
---|
108 | }
|
---|
109 | }
|
---|
110 | return true;
|
---|
111 | }
|
---|
112 |
|
---|
113 | QString UIWizardDiskEditors::openFileDialogForDiskFile(const QString &strInitialPath, const CMediumFormat &comMediumFormat,
|
---|
114 | KDeviceType enmDeviceType, QWidget *pParent)
|
---|
115 | {
|
---|
116 | QString strChosenFilePath;
|
---|
117 | QFileInfo initialPath(strInitialPath);
|
---|
118 | QDir folder = initialPath.path();
|
---|
119 | QString strFileName = initialPath.fileName();
|
---|
120 |
|
---|
121 | // /* Set the first parent folder that exists as the current: */
|
---|
122 | while (!folder.exists() && !folder.isRoot())
|
---|
123 | {
|
---|
124 | QFileInfo folderInfo(folder.absolutePath());
|
---|
125 | if (folder == QDir(folderInfo.absolutePath()))
|
---|
126 | break;
|
---|
127 | folder = folderInfo.absolutePath();
|
---|
128 | }
|
---|
129 | AssertReturn(folder.exists() && !folder.isRoot(), strChosenFilePath);
|
---|
130 |
|
---|
131 | QVector<QString> fileExtensions;
|
---|
132 | QVector<KDeviceType> deviceTypes;
|
---|
133 | comMediumFormat.DescribeFileExtensions(fileExtensions, deviceTypes);
|
---|
134 | QStringList validExtensionList;
|
---|
135 | for (int i = 0; i < fileExtensions.size(); ++i)
|
---|
136 | if (deviceTypes[i] == enmDeviceType)
|
---|
137 | validExtensionList << QString("*.%1").arg(fileExtensions[i]);
|
---|
138 | /* Compose full filter list: */
|
---|
139 | QString strBackendsList = QString("%1 (%2)").arg(comMediumFormat.GetName()).arg(validExtensionList.join(" "));
|
---|
140 |
|
---|
141 | strChosenFilePath = QIFileDialog::getSaveFileName(folder.absoluteFilePath(strFileName),
|
---|
142 | strBackendsList, pParent,
|
---|
143 | UICommon::tr("Please choose a location for new virtual hard disk file"));
|
---|
144 | return strChosenFilePath;
|
---|
145 | }
|
---|
146 |
|
---|
147 | QString UIWizardDiskEditors::defaultExtension(const CMediumFormat &mediumFormatRef, KDeviceType enmDeviceType)
|
---|
148 | {
|
---|
149 | if (!mediumFormatRef.isNull())
|
---|
150 | {
|
---|
151 | /* Load extension / device list: */
|
---|
152 | QVector<QString> fileExtensions;
|
---|
153 | QVector<KDeviceType> deviceTypes;
|
---|
154 | CMediumFormat mediumFormat(mediumFormatRef);
|
---|
155 | mediumFormat.DescribeFileExtensions(fileExtensions, deviceTypes);
|
---|
156 | for (int i = 0; i < fileExtensions.size(); ++i)
|
---|
157 | if (deviceTypes[i] == enmDeviceType)
|
---|
158 | return fileExtensions[i].toLower();
|
---|
159 | }
|
---|
160 | AssertMsgFailed(("Extension can't be NULL!\n"));
|
---|
161 | return QString();
|
---|
162 | }
|
---|
163 |
|
---|
164 | QString UIWizardDiskEditors::stripFormatExtension(const QString &strFileName, const QStringList &formatExtensions)
|
---|
165 | {
|
---|
166 | QString result(strFileName);
|
---|
167 | foreach (const QString &strExtension, formatExtensions)
|
---|
168 | {
|
---|
169 | if (strFileName.endsWith(strExtension, Qt::CaseInsensitive))
|
---|
170 | {
|
---|
171 | /* Add the dot to extenstion: */
|
---|
172 | QString strExtensionWithDot(strExtension);
|
---|
173 | strExtensionWithDot.prepend('.');
|
---|
174 | int iIndex = strFileName.lastIndexOf(strExtensionWithDot, -1, Qt::CaseInsensitive);
|
---|
175 | result.remove(iIndex, strExtensionWithDot.length());
|
---|
176 | }
|
---|
177 | }
|
---|
178 | return result;
|
---|
179 | }
|
---|
180 |
|
---|
181 |
|
---|
182 | /*********************************************************************************************************************************
|
---|
183 | * UIDiskVariantWidget implementation. *
|
---|
184 | *********************************************************************************************************************************/
|
---|
185 |
|
---|
186 |
|
---|
187 | UIDiskVariantWidget::UIDiskVariantWidget(QWidget *pParent /* = 0 */)
|
---|
188 | : QIWithRetranslateUI<QWidget>(pParent)
|
---|
189 | , m_pFixedCheckBox(0)
|
---|
190 | , m_pSplitBox(0)
|
---|
191 | {
|
---|
192 | prepare();
|
---|
193 | }
|
---|
194 |
|
---|
195 | void UIDiskVariantWidget::prepare()
|
---|
196 | {
|
---|
197 | QVBoxLayout *pVariantLayout = new QVBoxLayout(this);
|
---|
198 | AssertReturnVoid(pVariantLayout);
|
---|
199 | m_pFixedCheckBox = new QCheckBox;
|
---|
200 | m_pSplitBox = new QCheckBox;
|
---|
201 | connect(m_pFixedCheckBox, &QCheckBox::toggled, this, &UIDiskVariantWidget::sltVariantChanged);
|
---|
202 | connect(m_pSplitBox, &QCheckBox::toggled, this, &UIDiskVariantWidget::sltVariantChanged);
|
---|
203 | pVariantLayout->addWidget(m_pFixedCheckBox);
|
---|
204 | pVariantLayout->addWidget(m_pSplitBox);
|
---|
205 | pVariantLayout->addStretch();
|
---|
206 | retranslateUi();
|
---|
207 | }
|
---|
208 |
|
---|
209 | void UIDiskVariantWidget::retranslateUi()
|
---|
210 | {
|
---|
211 | if (m_pFixedCheckBox)
|
---|
212 | {
|
---|
213 | m_pFixedCheckBox->setText(tr("Pre-allocate &Full Size"));
|
---|
214 | m_pFixedCheckBox->setToolTip(tr("When checked, the virtual disk image is allocated with its full size during VM creation time"));
|
---|
215 | }
|
---|
216 | if (m_pSplitBox)
|
---|
217 | {
|
---|
218 | m_pSplitBox->setText(tr("&Split into 2GB parts"));
|
---|
219 | m_pSplitBox->setToolTip(tr("When checked, the virtual hard disk file is split into 2GB parts."));
|
---|
220 | }
|
---|
221 | }
|
---|
222 |
|
---|
223 | qulonglong UIDiskVariantWidget::mediumVariant() const
|
---|
224 | {
|
---|
225 | /* Initial value: */
|
---|
226 | qulonglong uMediumVariant = (qulonglong)KMediumVariant_Max;
|
---|
227 |
|
---|
228 | /* Exclusive options: */
|
---|
229 | if (m_pFixedCheckBox && m_pFixedCheckBox->isChecked())
|
---|
230 | uMediumVariant = (qulonglong)KMediumVariant_Fixed;
|
---|
231 | else
|
---|
232 | uMediumVariant = (qulonglong)KMediumVariant_Standard;
|
---|
233 |
|
---|
234 | /* Additional options: */
|
---|
235 | if (m_pSplitBox && m_pSplitBox->isChecked())
|
---|
236 | uMediumVariant |= (qulonglong)KMediumVariant_VmdkSplit2G;
|
---|
237 |
|
---|
238 | /* Return options: */
|
---|
239 | return uMediumVariant;
|
---|
240 | }
|
---|
241 |
|
---|
242 | void UIDiskVariantWidget::setMediumVariant(qulonglong uMediumVariant)
|
---|
243 | {
|
---|
244 | /* Exclusive options: */
|
---|
245 | if (uMediumVariant & (qulonglong)KMediumVariant_Fixed)
|
---|
246 | {
|
---|
247 | m_pFixedCheckBox->click();
|
---|
248 | m_pFixedCheckBox->setFocus();
|
---|
249 | }
|
---|
250 |
|
---|
251 | /* Additional options: */
|
---|
252 | m_pSplitBox->setChecked(uMediumVariant & (qulonglong)KMediumVariant_VmdkSplit2G);
|
---|
253 | }
|
---|
254 |
|
---|
255 | void UIDiskVariantWidget::updateMediumVariantWidgetsAfterFormatChange(const CMediumFormat &mediumFormat)
|
---|
256 | {
|
---|
257 | AssertReturnVoid(m_pFixedCheckBox && m_pSplitBox);
|
---|
258 | ULONG uCapabilities = 0;
|
---|
259 | QVector<KMediumFormatCapabilities> capabilities;
|
---|
260 | capabilities = mediumFormat.GetCapabilities();
|
---|
261 | for (int i = 0; i < capabilities.size(); i++)
|
---|
262 | uCapabilities |= capabilities[i];
|
---|
263 |
|
---|
264 | m_fIsCreateDynamicPossible = uCapabilities & KMediumFormatCapabilities_CreateDynamic;
|
---|
265 | m_fIsCreateFixedPossible = uCapabilities & KMediumFormatCapabilities_CreateFixed;
|
---|
266 | m_fIsCreateSplitPossible = uCapabilities & KMediumFormatCapabilities_CreateSplit2G;
|
---|
267 | m_pFixedCheckBox->setEnabled(true);
|
---|
268 | if (!m_fIsCreateDynamicPossible)
|
---|
269 | {
|
---|
270 | m_pFixedCheckBox->setChecked(true);
|
---|
271 | m_pFixedCheckBox->setEnabled(false);
|
---|
272 | }
|
---|
273 | if (!m_fIsCreateFixedPossible)
|
---|
274 | {
|
---|
275 | m_pFixedCheckBox->setChecked(false);
|
---|
276 | m_pFixedCheckBox->setEnabled(false);
|
---|
277 | }
|
---|
278 |
|
---|
279 | m_pSplitBox->setEnabled(m_fIsCreateSplitPossible);
|
---|
280 | if (!m_fIsCreateSplitPossible)
|
---|
281 | m_pSplitBox->setChecked(false);
|
---|
282 | emit sigMediumVariantChanged(mediumVariant());
|
---|
283 | }
|
---|
284 |
|
---|
285 | bool UIDiskVariantWidget::isComplete() const
|
---|
286 | {
|
---|
287 | /* Make sure medium variant is correct: */
|
---|
288 | return mediumVariant() != (qulonglong)KMediumVariant_Max;
|
---|
289 | }
|
---|
290 |
|
---|
291 | bool UIDiskVariantWidget::isCreateDynamicPossible() const
|
---|
292 | {
|
---|
293 | return m_fIsCreateDynamicPossible;
|
---|
294 | }
|
---|
295 |
|
---|
296 | bool UIDiskVariantWidget::isCreateFixedPossible() const
|
---|
297 | {
|
---|
298 | return m_fIsCreateFixedPossible;
|
---|
299 | }
|
---|
300 |
|
---|
301 | bool UIDiskVariantWidget::isCreateSplitPossible() const
|
---|
302 | {
|
---|
303 | return m_fIsCreateSplitPossible;
|
---|
304 | }
|
---|
305 |
|
---|
306 | void UIDiskVariantWidget::sltVariantChanged()
|
---|
307 | {
|
---|
308 | emit sigMediumVariantChanged(mediumVariant());
|
---|
309 | }
|
---|
310 |
|
---|
311 |
|
---|
312 | /*********************************************************************************************************************************
|
---|
313 | * UIMediumSizeAndPathGroupBox implementation. *
|
---|
314 | *********************************************************************************************************************************/
|
---|
315 |
|
---|
316 | UIMediumSizeAndPathGroupBox::UIMediumSizeAndPathGroupBox(bool fExpertMode, QWidget *pParent, qulonglong uMinimumMediumSize)
|
---|
317 | : QIWithRetranslateUI<QGroupBox>(pParent)
|
---|
318 | , m_pLocationEditor(0)
|
---|
319 | , m_pLocationOpenButton(0)
|
---|
320 | , m_pMediumSizeEditor(0)
|
---|
321 | , m_pLocationLabel(0)
|
---|
322 | , m_pSizeLabel(0)
|
---|
323 | , m_fExpertMode(fExpertMode)
|
---|
324 | {
|
---|
325 | prepare(uMinimumMediumSize);
|
---|
326 | }
|
---|
327 |
|
---|
328 | bool UIMediumSizeAndPathGroupBox::isComplete() const
|
---|
329 | {
|
---|
330 | if (QFileInfo(mediumFilePath()).exists())
|
---|
331 | {
|
---|
332 | m_pLocationEditor->mark(true, tr("Disk file name is not unique"));
|
---|
333 | return false;
|
---|
334 | }
|
---|
335 | m_pLocationEditor->mark(false);
|
---|
336 | return true;
|
---|
337 | }
|
---|
338 |
|
---|
339 | void UIMediumSizeAndPathGroupBox::prepare(qulonglong uMinimumMediumSize)
|
---|
340 | {
|
---|
341 | QVBoxLayout *pMainLayout = new QVBoxLayout(this);
|
---|
342 | /* Location widgets: */
|
---|
343 | if (!m_fExpertMode)
|
---|
344 | m_pLocationLabel = new QIRichTextLabel;
|
---|
345 | QHBoxLayout *pLocationLayout = new QHBoxLayout;
|
---|
346 | m_pLocationEditor = new QILineEdit;
|
---|
347 | m_pLocationOpenButton = new QIToolButton;
|
---|
348 | if (m_pLocationOpenButton)
|
---|
349 | {
|
---|
350 | m_pLocationOpenButton->setAutoRaise(true);
|
---|
351 | m_pLocationOpenButton->setIcon(UIIconPool::iconSet(":/select_file_16px.png", "select_file_disabled_16px.png"));
|
---|
352 | }
|
---|
353 | if (m_pLocationEditor)
|
---|
354 | m_pLocationEditor->setToolTip(tr("Holds the location of the virtual disk file."));
|
---|
355 | if (m_pLocationOpenButton)
|
---|
356 | m_pLocationEditor->setToolTip(tr("Opens file selection dialog so that a location for the disk file can be selected."));
|
---|
357 | pLocationLayout->addWidget(m_pLocationEditor);
|
---|
358 | pLocationLayout->addWidget(m_pLocationOpenButton);
|
---|
359 |
|
---|
360 | /* Size widgets: */
|
---|
361 | if (!m_fExpertMode)
|
---|
362 | m_pSizeLabel = new QIRichTextLabel;
|
---|
363 | m_pMediumSizeEditor = new UIMediumSizeEditor(0 /* parent */, uMinimumMediumSize);
|
---|
364 |
|
---|
365 | /* Add widgets to main layout: */
|
---|
366 | if (m_pLocationLabel)
|
---|
367 | pMainLayout->addWidget(m_pLocationLabel);
|
---|
368 | pMainLayout->addLayout(pLocationLayout);
|
---|
369 |
|
---|
370 | if (m_pSizeLabel)
|
---|
371 | pMainLayout->addWidget(m_pSizeLabel);
|
---|
372 | pMainLayout->addWidget(m_pMediumSizeEditor);
|
---|
373 |
|
---|
374 | connect(m_pMediumSizeEditor, &UIMediumSizeEditor::sigSizeChanged,
|
---|
375 | this, &UIMediumSizeAndPathGroupBox::sigMediumSizeChanged);
|
---|
376 |
|
---|
377 | connect(m_pLocationEditor, &QILineEdit::textChanged,
|
---|
378 | this, &UIMediumSizeAndPathGroupBox::sigMediumPathChanged);
|
---|
379 |
|
---|
380 | connect(m_pLocationOpenButton, &QIToolButton::clicked,
|
---|
381 | this, &UIMediumSizeAndPathGroupBox::sigMediumLocationButtonClicked);
|
---|
382 |
|
---|
383 | retranslateUi();
|
---|
384 | }
|
---|
385 | void UIMediumSizeAndPathGroupBox::retranslateUi()
|
---|
386 | {
|
---|
387 | if (m_fExpertMode)
|
---|
388 | setTitle(tr("Hard Disk File Location and Size"));
|
---|
389 | if (m_pLocationOpenButton)
|
---|
390 | m_pLocationOpenButton->setToolTip(tr("Specify a location for new virtual hard disk file..."));
|
---|
391 |
|
---|
392 | if (!m_fExpertMode && m_pLocationLabel)
|
---|
393 | m_pLocationLabel->setText(tr("Please type the name of the new virtual hard disk file into the box below or "
|
---|
394 | "click on the folder icon to select a different folder to create the file in."));
|
---|
395 | if (!m_fExpertMode && m_pSizeLabel)
|
---|
396 | m_pSizeLabel->setText(tr("Select the size of the virtual hard disk in megabytes. "
|
---|
397 | "This size is the limit on the amount of file data "
|
---|
398 | "that a virtual machine will be able to store on the hard disk."));
|
---|
399 | }
|
---|
400 |
|
---|
401 | QString UIMediumSizeAndPathGroupBox::mediumName() const
|
---|
402 | {
|
---|
403 | if (!m_pLocationEditor)
|
---|
404 | return QString();
|
---|
405 | return QFileInfo(m_pLocationEditor->text()).completeBaseName();
|
---|
406 | }
|
---|
407 |
|
---|
408 | QString UIMediumSizeAndPathGroupBox::mediumFilePath() const
|
---|
409 | {
|
---|
410 | if (!m_pLocationEditor)
|
---|
411 | return QString();
|
---|
412 | return m_pLocationEditor->text();
|
---|
413 | }
|
---|
414 |
|
---|
415 | void UIMediumSizeAndPathGroupBox::setMediumFilePath(const QString &strMediumPath)
|
---|
416 | {
|
---|
417 | if (!m_pLocationEditor)
|
---|
418 | return;
|
---|
419 | m_pLocationEditor->setText(strMediumPath);
|
---|
420 | }
|
---|
421 |
|
---|
422 | void UIMediumSizeAndPathGroupBox::updateMediumPath(const CMediumFormat &mediumFormat, const QStringList &formatExtensions,
|
---|
423 | KDeviceType enmDeviceType)
|
---|
424 | {
|
---|
425 | /* Compose virtual-disk extension: */
|
---|
426 | QString strDefaultExtension = UIWizardDiskEditors::defaultExtension(mediumFormat, enmDeviceType);
|
---|
427 | /* Update m_pLocationEditor's text if necessary: */
|
---|
428 | if (!m_pLocationEditor->text().isEmpty() && !strDefaultExtension.isEmpty())
|
---|
429 | {
|
---|
430 | QFileInfo fileInfo(m_pLocationEditor->text());
|
---|
431 | if (fileInfo.suffix() != strDefaultExtension)
|
---|
432 | {
|
---|
433 | QFileInfo newFileInfo(QDir(fileInfo.absolutePath()),
|
---|
434 | QString("%1.%2").
|
---|
435 | arg(UIWizardDiskEditors::stripFormatExtension(fileInfo.fileName(), formatExtensions)).
|
---|
436 | arg(strDefaultExtension));
|
---|
437 | setMediumFilePath(newFileInfo.absoluteFilePath());
|
---|
438 | }
|
---|
439 | }
|
---|
440 | }
|
---|
441 |
|
---|
442 | QString UIMediumSizeAndPathGroupBox::mediumPath() const
|
---|
443 | {
|
---|
444 | if (!m_pLocationEditor)
|
---|
445 | return QString();
|
---|
446 | return QDir::toNativeSeparators(QFileInfo(m_pLocationEditor->text()).absolutePath());
|
---|
447 | }
|
---|
448 |
|
---|
449 | qulonglong UIMediumSizeAndPathGroupBox::mediumSize() const
|
---|
450 | {
|
---|
451 | if (m_pMediumSizeEditor)
|
---|
452 | return m_pMediumSizeEditor->mediumSize();
|
---|
453 | return 0;
|
---|
454 | }
|
---|
455 |
|
---|
456 | void UIMediumSizeAndPathGroupBox::setMediumSize(qulonglong uSize)
|
---|
457 | {
|
---|
458 | if (m_pMediumSizeEditor)
|
---|
459 | return m_pMediumSizeEditor->setMediumSize(uSize);
|
---|
460 | }
|
---|
461 |
|
---|
462 | /*********************************************************************************************************************************
|
---|
463 | * UIDiskFormatBase implementation. *
|
---|
464 | *********************************************************************************************************************************/
|
---|
465 |
|
---|
466 | UIDiskFormatBase::UIDiskFormatBase(KDeviceType enmDeviceType, bool fExpertMode)
|
---|
467 | : m_enmDeviceType(enmDeviceType)
|
---|
468 | , m_fExpertMode(fExpertMode)
|
---|
469 | {
|
---|
470 | }
|
---|
471 |
|
---|
472 | UIDiskFormatBase::~UIDiskFormatBase()
|
---|
473 | {
|
---|
474 | }
|
---|
475 |
|
---|
476 | const CMediumFormat &UIDiskFormatBase::VDIMediumFormat() const
|
---|
477 | {
|
---|
478 | return m_comVDIMediumFormat;
|
---|
479 | }
|
---|
480 |
|
---|
481 | void UIDiskFormatBase::populateFormats(){
|
---|
482 | /* Enumerate medium formats in special order: */
|
---|
483 | CSystemProperties properties = uiCommon().virtualBox().GetSystemProperties();
|
---|
484 | const QVector<CMediumFormat> &formats = properties.GetMediumFormats();
|
---|
485 | QMap<QString, CMediumFormat> vdi, preferred, others;
|
---|
486 | foreach (const CMediumFormat &format, formats)
|
---|
487 | {
|
---|
488 | if (format.GetName() == "VDI")
|
---|
489 | {
|
---|
490 | vdi[format.GetId()] = format;
|
---|
491 | m_comVDIMediumFormat = format;
|
---|
492 | }
|
---|
493 | else
|
---|
494 | {
|
---|
495 | const QVector<KMediumFormatCapabilities> &capabilities = format.GetCapabilities();
|
---|
496 | if (capabilities.contains(KMediumFormatCapabilities_Preferred))
|
---|
497 | preferred[format.GetId()] = format;
|
---|
498 | else
|
---|
499 | others[format.GetId()] = format;
|
---|
500 | }
|
---|
501 | }
|
---|
502 |
|
---|
503 | /* Create buttons for VDI, preferred and others: */
|
---|
504 | foreach (const QString &strId, vdi.keys())
|
---|
505 | addFormat(vdi.value(strId), true);
|
---|
506 | foreach (const QString &strId, preferred.keys())
|
---|
507 | addFormat(preferred.value(strId), true);
|
---|
508 |
|
---|
509 | if (m_fExpertMode || m_enmDeviceType == KDeviceType_DVD || m_enmDeviceType == KDeviceType_Floppy)
|
---|
510 | {
|
---|
511 | foreach (const QString &strId, others.keys())
|
---|
512 | addFormat(others.value(strId));
|
---|
513 | }
|
---|
514 | }
|
---|
515 |
|
---|
516 | void UIDiskFormatBase::addFormat(CMediumFormat medFormat, bool fPreferred /* = false */)
|
---|
517 | {
|
---|
518 | AssertReturnVoid(!medFormat.isNull());
|
---|
519 | /* Check that medium format supports creation: */
|
---|
520 | ULONG uFormatCapabilities = 0;
|
---|
521 | QVector<KMediumFormatCapabilities> capabilities;
|
---|
522 | capabilities = medFormat.GetCapabilities();
|
---|
523 | for (int i = 0; i < capabilities.size(); i++)
|
---|
524 | uFormatCapabilities |= capabilities[i];
|
---|
525 |
|
---|
526 | if (!(uFormatCapabilities & KMediumFormatCapabilities_CreateFixed ||
|
---|
527 | uFormatCapabilities & KMediumFormatCapabilities_CreateDynamic))
|
---|
528 | return;
|
---|
529 |
|
---|
530 | /* Check that medium format supports creation of virtual hard-disks: */
|
---|
531 | QVector<QString> fileExtensions;
|
---|
532 | QVector<KDeviceType> deviceTypes;
|
---|
533 | medFormat.DescribeFileExtensions(fileExtensions, deviceTypes);
|
---|
534 | if (!deviceTypes.contains(m_enmDeviceType))
|
---|
535 | return;
|
---|
536 | m_formatList << Format(medFormat, UIWizardDiskEditors::defaultExtension(medFormat, m_enmDeviceType), fPreferred);
|
---|
537 | }
|
---|
538 |
|
---|
539 | QStringList UIDiskFormatBase::formatExtensions() const
|
---|
540 | {
|
---|
541 | QStringList extensionList;
|
---|
542 | foreach (const Format &format, m_formatList)
|
---|
543 | extensionList << format.m_strExtension;
|
---|
544 | return extensionList;
|
---|
545 | }
|
---|
546 |
|
---|
547 | bool UIDiskFormatBase::isExpertMode() const
|
---|
548 | {
|
---|
549 | return m_fExpertMode;
|
---|
550 | }
|
---|
551 |
|
---|
552 | /*********************************************************************************************************************************
|
---|
553 | * UIDiskFormatsGroupBox implementation. *
|
---|
554 | *********************************************************************************************************************************/
|
---|
555 |
|
---|
556 | UIDiskFormatsGroupBox::UIDiskFormatsGroupBox(bool fExpertMode, KDeviceType enmDeviceType, QWidget *pParent /* = 0 */)
|
---|
557 | : QIWithRetranslateUI<QWidget>(pParent)
|
---|
558 | , UIDiskFormatBase(enmDeviceType, fExpertMode)
|
---|
559 | , m_pFormatButtonGroup(0)
|
---|
560 | , m_pMainLayout(0)
|
---|
561 | {
|
---|
562 | prepare();
|
---|
563 | }
|
---|
564 |
|
---|
565 | CMediumFormat UIDiskFormatsGroupBox::mediumFormat() const
|
---|
566 | {
|
---|
567 | if (!m_pFormatButtonGroup)
|
---|
568 | return CMediumFormat();
|
---|
569 | int iIndex = m_pFormatButtonGroup->checkedId();
|
---|
570 | if (iIndex < 0 || iIndex >= m_formatList.size())
|
---|
571 | return CMediumFormat();
|
---|
572 | return m_formatList[iIndex].m_comFormat;
|
---|
573 | }
|
---|
574 |
|
---|
575 | void UIDiskFormatsGroupBox::setMediumFormat(const CMediumFormat &mediumFormat)
|
---|
576 | {
|
---|
577 | int iPosition = -1;
|
---|
578 | for (int i = 0; i < m_formatList.size(); ++i)
|
---|
579 | {
|
---|
580 | if (mediumFormat == m_formatList[i].m_comFormat)
|
---|
581 | iPosition = i;
|
---|
582 | }
|
---|
583 | if (iPosition >= 0)
|
---|
584 | {
|
---|
585 | m_pFormatButtonGroup->button(iPosition)->click();
|
---|
586 | m_pFormatButtonGroup->button(iPosition)->setFocus();
|
---|
587 | }
|
---|
588 | }
|
---|
589 |
|
---|
590 | void UIDiskFormatsGroupBox::prepare()
|
---|
591 | {
|
---|
592 | m_pMainLayout = new QVBoxLayout(this);
|
---|
593 | populateFormats();
|
---|
594 | createFormatWidgets();
|
---|
595 | retranslateUi();
|
---|
596 | }
|
---|
597 |
|
---|
598 | void UIDiskFormatsGroupBox::retranslateUi()
|
---|
599 | {
|
---|
600 | QList<QAbstractButton*> buttons = m_pFormatButtonGroup ? m_pFormatButtonGroup->buttons() : QList<QAbstractButton*>();
|
---|
601 | for (int i = 0; i < buttons.size(); ++i)
|
---|
602 | {
|
---|
603 | QAbstractButton *pButton = buttons[i];
|
---|
604 | const CMediumFormat &format = m_formatList[m_pFormatButtonGroup->id(pButton)].m_comFormat;
|
---|
605 | if (format.isNull())
|
---|
606 | continue;
|
---|
607 | UIMediumFormat enmFormat = gpConverter->fromInternalString<UIMediumFormat>(format.GetName());
|
---|
608 | pButton->setText(gpConverter->toString(enmFormat));
|
---|
609 | }
|
---|
610 | }
|
---|
611 |
|
---|
612 | void UIDiskFormatsGroupBox::createFormatWidgets()
|
---|
613 | {
|
---|
614 | AssertReturnVoid(m_pMainLayout);
|
---|
615 | AssertReturnVoid(!m_formatList.isEmpty());
|
---|
616 | m_pFormatButtonGroup = new QButtonGroup(this);
|
---|
617 | AssertReturnVoid(m_pFormatButtonGroup);
|
---|
618 |
|
---|
619 | for (int i = 0; i < m_formatList.size(); ++i)
|
---|
620 | {
|
---|
621 | QRadioButton *pFormatButton = new QRadioButton;
|
---|
622 | if (!pFormatButton)
|
---|
623 | continue;
|
---|
624 |
|
---|
625 | /* Make the preferred button font bold: */
|
---|
626 | if (m_formatList[i].m_fPreferred && isExpertMode())
|
---|
627 | {
|
---|
628 | QFont font = pFormatButton->font();
|
---|
629 | font.setBold(true);
|
---|
630 | pFormatButton->setFont(font);
|
---|
631 | }
|
---|
632 | m_pMainLayout->addWidget(pFormatButton);
|
---|
633 | m_pFormatButtonGroup->addButton(pFormatButton, i);
|
---|
634 | }
|
---|
635 |
|
---|
636 | setMediumFormat(m_formatList[0].m_comFormat);
|
---|
637 | connect(m_pFormatButtonGroup, &QButtonGroup::buttonClicked,
|
---|
638 | this, &UIDiskFormatsGroupBox::sigMediumFormatChanged);
|
---|
639 | }
|
---|
640 |
|
---|
641 |
|
---|
642 | /*********************************************************************************************************************************
|
---|
643 | * UIDiskFormatsGroupBox implementation. *
|
---|
644 | *********************************************************************************************************************************/
|
---|
645 |
|
---|
646 | UIDiskFormatsComboBox::UIDiskFormatsComboBox(bool fExpertMode, KDeviceType enmDeviceType, QWidget *pParent /* = 0 */)
|
---|
647 | : QIWithRetranslateUI<QIComboBox>(pParent)
|
---|
648 | , UIDiskFormatBase(enmDeviceType, fExpertMode)
|
---|
649 | {
|
---|
650 | prepare();
|
---|
651 | }
|
---|
652 |
|
---|
653 | void UIDiskFormatsComboBox::prepare()
|
---|
654 | {
|
---|
655 | populateFormats();
|
---|
656 | foreach (const Format &format, m_formatList)
|
---|
657 | {
|
---|
658 | addItem(format.m_comFormat.GetName());
|
---|
659 | }
|
---|
660 |
|
---|
661 | connect(this, &QIComboBox::currentIndexChanged,
|
---|
662 | this, &UIDiskFormatsComboBox::sigMediumFormatChanged);
|
---|
663 |
|
---|
664 | retranslateUi();
|
---|
665 | }
|
---|
666 |
|
---|
667 | CMediumFormat UIDiskFormatsComboBox::mediumFormat() const
|
---|
668 | {
|
---|
669 | int iIndex = currentIndex();
|
---|
670 | if (iIndex < 0 || iIndex >= m_formatList.size())
|
---|
671 | return CMediumFormat();
|
---|
672 | return m_formatList[iIndex].m_comFormat;
|
---|
673 | }
|
---|
674 |
|
---|
675 | void UIDiskFormatsComboBox::setMediumFormat(const CMediumFormat &mediumFormat)
|
---|
676 | {
|
---|
677 | int iPosition = -1;
|
---|
678 | for (int i = 0; i < m_formatList.size(); ++i)
|
---|
679 | {
|
---|
680 | if (mediumFormat == m_formatList[i].m_comFormat)
|
---|
681 | iPosition = i;
|
---|
682 | }
|
---|
683 | if (iPosition >= 0)
|
---|
684 | setCurrentIndex(iPosition);
|
---|
685 | }
|
---|
686 |
|
---|
687 | void UIDiskFormatsComboBox::retranslateUi()
|
---|
688 | {
|
---|
689 | for (int i = 0; i < count(); ++i)
|
---|
690 | {
|
---|
691 | if (i >= m_formatList.size())
|
---|
692 | break;
|
---|
693 | const CMediumFormat &format = m_formatList[i].m_comFormat;
|
---|
694 | if (format.isNull())
|
---|
695 | continue;
|
---|
696 | UIMediumFormat enmFormat = gpConverter->fromInternalString<UIMediumFormat>(format.GetName());
|
---|
697 | setItemText(i, gpConverter->toString(enmFormat));
|
---|
698 | }
|
---|
699 | }
|
---|