1 | /* $Id: UIWizardNewVDSizeLocationPage.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIWizardNewVDSizeLocationPage 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 <QDir>
|
---|
30 | #include <QVBoxLayout>
|
---|
31 |
|
---|
32 | /* GUI includes: */
|
---|
33 | #include "UIWizardNewVDSizeLocationPage.h"
|
---|
34 | #include "UIWizardNewVD.h"
|
---|
35 | #include "UICommon.h"
|
---|
36 | #include "UINotificationCenter.h"
|
---|
37 | #include "UIWizardDiskEditors.h"
|
---|
38 |
|
---|
39 | /* COM includes: */
|
---|
40 | #include "CSystemProperties.h"
|
---|
41 |
|
---|
42 | UIWizardNewVDSizeLocationPage::UIWizardNewVDSizeLocationPage(const QString &strDefaultName,
|
---|
43 | const QString &strDefaultPath, qulonglong uDefaultSize)
|
---|
44 | : m_pMediumSizePathGroup(0)
|
---|
45 | , m_uMediumSizeMin(_4M)
|
---|
46 | , m_uMediumSizeMax(uiCommon().virtualBox().GetSystemProperties().GetInfoVDSize())
|
---|
47 | , m_strDefaultName(strDefaultName.isEmpty() ? QString("NewVirtualDisk1") : strDefaultName)
|
---|
48 | , m_strDefaultPath(strDefaultPath)
|
---|
49 | , m_uDefaultSize(uDefaultSize)
|
---|
50 | {
|
---|
51 | prepare();
|
---|
52 | }
|
---|
53 |
|
---|
54 | void UIWizardNewVDSizeLocationPage::prepare()
|
---|
55 | {
|
---|
56 | QVBoxLayout *pMainLayout = new QVBoxLayout(this);
|
---|
57 | AssertReturnVoid(pMainLayout);
|
---|
58 | m_pMediumSizePathGroup = new UIMediumSizeAndPathGroupBox(false /* fExpertMode */, 0 /* parent */, _4M /* minimum size */);
|
---|
59 | connect(m_pMediumSizePathGroup, &UIMediumSizeAndPathGroupBox::sigMediumSizeChanged,
|
---|
60 | this, &UIWizardNewVDSizeLocationPage::sltMediumSizeChanged);
|
---|
61 | connect(m_pMediumSizePathGroup, &UIMediumSizeAndPathGroupBox::sigMediumPathChanged,
|
---|
62 | this, &UIWizardNewVDSizeLocationPage::sltMediumPathChanged);
|
---|
63 | connect(m_pMediumSizePathGroup, &UIMediumSizeAndPathGroupBox::sigMediumLocationButtonClicked,
|
---|
64 | this, &UIWizardNewVDSizeLocationPage::sltSelectLocationButtonClicked);
|
---|
65 | pMainLayout->addWidget(m_pMediumSizePathGroup);
|
---|
66 | pMainLayout->addStretch();
|
---|
67 | retranslateUi();
|
---|
68 | }
|
---|
69 |
|
---|
70 | void UIWizardNewVDSizeLocationPage::sltSelectLocationButtonClicked()
|
---|
71 | {
|
---|
72 | UIWizardNewVD *pWizard = wizardWindow<UIWizardNewVD>();
|
---|
73 | AssertReturnVoid(pWizard);
|
---|
74 | QString strSelectedPath =
|
---|
75 | UIWizardDiskEditors::openFileDialogForDiskFile(pWizard->mediumPath(), pWizard->mediumFormat(),
|
---|
76 | KDeviceType_HardDisk, pWizard);
|
---|
77 |
|
---|
78 | if (strSelectedPath.isEmpty())
|
---|
79 | return;
|
---|
80 | QString strMediumPath =
|
---|
81 | UIWizardDiskEditors::appendExtension(strSelectedPath,
|
---|
82 | UIWizardDiskEditors::defaultExtension(pWizard->mediumFormat(), KDeviceType_HardDisk));
|
---|
83 | QFileInfo mediumPath(strMediumPath);
|
---|
84 | m_pMediumSizePathGroup->setMediumFilePath(QDir::toNativeSeparators(mediumPath.absoluteFilePath()));
|
---|
85 | }
|
---|
86 |
|
---|
87 | void UIWizardNewVDSizeLocationPage::sltMediumSizeChanged(qulonglong uSize)
|
---|
88 | {
|
---|
89 | AssertReturnVoid(wizardWindow<UIWizardNewVD>());
|
---|
90 | m_userModifiedParameters << "MediumSize";
|
---|
91 | wizardWindow<UIWizardNewVD>()->setMediumSize(uSize);
|
---|
92 | emit completeChanged();
|
---|
93 | }
|
---|
94 |
|
---|
95 | void UIWizardNewVDSizeLocationPage::sltMediumPathChanged(const QString &strPath)
|
---|
96 | {
|
---|
97 | UIWizardNewVD *pWizard = wizardWindow<UIWizardNewVD>();
|
---|
98 | AssertReturnVoid(pWizard);
|
---|
99 | m_userModifiedParameters << "MediumPath";
|
---|
100 | QString strMediumPath =
|
---|
101 | UIWizardDiskEditors::appendExtension(strPath,
|
---|
102 | UIWizardDiskEditors::defaultExtension(pWizard->mediumFormat(), KDeviceType_HardDisk));
|
---|
103 | pWizard->setMediumPath(strMediumPath);
|
---|
104 | emit completeChanged();
|
---|
105 | }
|
---|
106 |
|
---|
107 | void UIWizardNewVDSizeLocationPage::retranslateUi()
|
---|
108 | {
|
---|
109 | setTitle(UIWizardNewVD::tr("File location and size"));
|
---|
110 | }
|
---|
111 |
|
---|
112 | void UIWizardNewVDSizeLocationPage::initializePage()
|
---|
113 | {
|
---|
114 | UIWizardNewVD *pWizard = wizardWindow<UIWizardNewVD>();
|
---|
115 | AssertReturnVoid(pWizard && m_pMediumSizePathGroup);
|
---|
116 |
|
---|
117 | QString strExtension = UIWizardDiskEditors::defaultExtension(pWizard->mediumFormat(), KDeviceType_HardDisk);
|
---|
118 | QString strMediumFilePath;
|
---|
119 | /* Initialize the medium file path with default name and path if user has not exclusively modified them yet: */
|
---|
120 | if (!m_userModifiedParameters.contains("MediumPath"))
|
---|
121 | strMediumFilePath =
|
---|
122 | UIWizardDiskEditors::constructMediumFilePath(UIWizardDiskEditors::appendExtension(m_strDefaultName,
|
---|
123 | strExtension), m_strDefaultPath);
|
---|
124 | /* Initialize the medium file path with file path and file name from the location editor. This part is to update the
|
---|
125 | * file extention correctly in case user has gone back and changed the file format after modifying medium file path: */
|
---|
126 | else
|
---|
127 | strMediumFilePath =
|
---|
128 | UIWizardDiskEditors::constructMediumFilePath(UIWizardDiskEditors::appendExtension(m_pMediumSizePathGroup->mediumName(),
|
---|
129 | strExtension), m_pMediumSizePathGroup->mediumPath());
|
---|
130 | m_pMediumSizePathGroup->blockSignals(true);
|
---|
131 | m_pMediumSizePathGroup->setMediumFilePath(strMediumFilePath);
|
---|
132 | m_pMediumSizePathGroup->blockSignals(false);
|
---|
133 | pWizard->setMediumPath(m_pMediumSizePathGroup->mediumFilePath());
|
---|
134 |
|
---|
135 | if (!m_userModifiedParameters.contains("MediumSize"))
|
---|
136 | {
|
---|
137 | m_pMediumSizePathGroup->blockSignals(true);
|
---|
138 | m_pMediumSizePathGroup->setMediumSize(m_uDefaultSize > m_uMediumSizeMin && m_uDefaultSize < m_uMediumSizeMax ? m_uDefaultSize : m_uMediumSizeMin);
|
---|
139 | m_pMediumSizePathGroup->blockSignals(false);
|
---|
140 | pWizard->setMediumSize(m_pMediumSizePathGroup->mediumSize());
|
---|
141 | }
|
---|
142 | retranslateUi();
|
---|
143 | }
|
---|
144 |
|
---|
145 | bool UIWizardNewVDSizeLocationPage::isComplete() const
|
---|
146 | {
|
---|
147 | UIWizardNewVD *pWizard = wizardWindow<UIWizardNewVD>();
|
---|
148 | AssertReturn(pWizard, false);
|
---|
149 | if (pWizard->mediumPath().isEmpty())
|
---|
150 | return false;
|
---|
151 | if (pWizard->mediumSize() > m_uMediumSizeMax || pWizard->mediumSize() < m_uMediumSizeMin)
|
---|
152 | return false;
|
---|
153 | return true;
|
---|
154 | }
|
---|
155 |
|
---|
156 | bool UIWizardNewVDSizeLocationPage::validatePage()
|
---|
157 | {
|
---|
158 | bool fResult = true;
|
---|
159 | UIWizardNewVD *pWizard = wizardWindow<UIWizardNewVD>();
|
---|
160 | AssertReturn(pWizard, false);
|
---|
161 | /* Make sure such file doesn't exist already: */
|
---|
162 | const QString strMediumPath(pWizard->mediumPath());
|
---|
163 | fResult = !QFileInfo(strMediumPath).exists();
|
---|
164 | if (!fResult)
|
---|
165 | {
|
---|
166 | UINotificationMessage::cannotOverwriteMediumStorage(strMediumPath, wizard()->notificationCenter());
|
---|
167 | return fResult;
|
---|
168 | }
|
---|
169 |
|
---|
170 | /* Make sure we are passing FAT size limitation: */
|
---|
171 | fResult = UIWizardDiskEditors::checkFATSizeLimitation(pWizard->mediumVariant(),
|
---|
172 | pWizard->mediumPath(),
|
---|
173 | pWizard->mediumSize());
|
---|
174 | if (!fResult)
|
---|
175 | {
|
---|
176 | UINotificationMessage::cannotCreateMediumStorageInFAT(strMediumPath, wizard()->notificationCenter());
|
---|
177 | return fResult;
|
---|
178 | }
|
---|
179 |
|
---|
180 | fResult = pWizard->createVirtualDisk();
|
---|
181 | return fResult;
|
---|
182 | }
|
---|