1 | /* $Id: UIWizardCloneVD.cpp 104891 2024-06-12 12:41:04Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIWizardCloneVD 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 | /* GUI includes: */
|
---|
29 | #include "UICommon.h"
|
---|
30 | #include "UIGlobalSession.h"
|
---|
31 | #include "UIMedium.h"
|
---|
32 | #include "UIMediumEnumerator.h"
|
---|
33 | #include "UINotificationCenter.h"
|
---|
34 | #include "UIWizardCloneVD.h"
|
---|
35 | #include "UIWizardCloneVDFormatPage.h"
|
---|
36 | #include "UIWizardCloneVDVariantPage.h"
|
---|
37 | #include "UIWizardCloneVDPathSizePage.h"
|
---|
38 | #include "UIWizardCloneVDExpertPage.h"
|
---|
39 |
|
---|
40 | /* COM includes: */
|
---|
41 | #include "CMediumFormat.h"
|
---|
42 |
|
---|
43 | UIWizardCloneVD::UIWizardCloneVD(QWidget *pParent, const QUuid &uMediumId)
|
---|
44 | : UINativeWizard(pParent, WizardType_CloneVD)
|
---|
45 | , m_enmDeviceType(KDeviceType_Null)
|
---|
46 | , m_iMediumVariantPageIndex(-1)
|
---|
47 | {
|
---|
48 | #ifndef VBOX_WS_MAC
|
---|
49 | /* Assign watermark: */
|
---|
50 | setPixmapName(":/wizard_new_harddisk.png");
|
---|
51 | #else /* VBOX_WS_MAC */
|
---|
52 | /* Assign background image: */
|
---|
53 | setPixmapName(":/wizard_new_harddisk_bg.png");
|
---|
54 | #endif /* VBOX_WS_MAC */
|
---|
55 |
|
---|
56 | /* Init medium to be cloned: */
|
---|
57 | UIMedium uiMedium = gpMediumEnumerator->medium(uMediumId);
|
---|
58 | m_comSourceVirtualDisk = uiMedium.medium();
|
---|
59 |
|
---|
60 | /* Init device type: */
|
---|
61 | m_enmDeviceType = m_comSourceVirtualDisk.GetDeviceType();
|
---|
62 | }
|
---|
63 |
|
---|
64 | const CMedium &UIWizardCloneVD::sourceVirtualDisk() const
|
---|
65 | {
|
---|
66 | return m_comSourceVirtualDisk;
|
---|
67 | }
|
---|
68 |
|
---|
69 | KDeviceType UIWizardCloneVD::deviceType() const
|
---|
70 | {
|
---|
71 | return m_enmDeviceType;
|
---|
72 | }
|
---|
73 |
|
---|
74 | bool UIWizardCloneVD::copyVirtualDisk()
|
---|
75 | {
|
---|
76 | /* Check attributes: */
|
---|
77 | AssertReturn(!m_strMediumPath.isNull(), false);
|
---|
78 | AssertReturn(m_uMediumSize > 0, false);
|
---|
79 |
|
---|
80 | /* Get VBox object: */
|
---|
81 | CVirtualBox comVBox = gpGlobalSession->virtualBox();
|
---|
82 |
|
---|
83 | /* Create new virtual disk image: */
|
---|
84 | CMedium comVirtualDisk = comVBox.CreateMedium(m_comMediumFormat.GetName(), m_strMediumPath, KAccessMode_ReadWrite, m_enmDeviceType);
|
---|
85 | if (!comVBox.isOk())
|
---|
86 | {
|
---|
87 | UINotificationMessage::cannotCreateMediumStorage(comVBox, m_strMediumPath, notificationCenter());
|
---|
88 | return false;
|
---|
89 | }
|
---|
90 |
|
---|
91 | /* Compose medium-variant: */
|
---|
92 | QVector<KMediumVariant> variants(sizeof(qulonglong) * 8);
|
---|
93 | for (int i = 0; i < variants.size(); ++i)
|
---|
94 | {
|
---|
95 | qulonglong temp = m_uMediumVariant;
|
---|
96 | temp &= Q_UINT64_C(1) << i;
|
---|
97 | variants[i] = (KMediumVariant)temp;
|
---|
98 | }
|
---|
99 |
|
---|
100 | /* Copy medium: */
|
---|
101 | UINotificationProgressMediumCopy *pNotification = new UINotificationProgressMediumCopy(m_comSourceVirtualDisk,
|
---|
102 | comVirtualDisk,
|
---|
103 | variants);
|
---|
104 | connect(pNotification, &UINotificationProgressMediumCopy::sigMediumCopied,
|
---|
105 | &uiCommon(), &UICommon::sltHandleMediumCreated);
|
---|
106 | gpNotificationCenter->append(pNotification);
|
---|
107 |
|
---|
108 | /* Positive: */
|
---|
109 | return true;
|
---|
110 | }
|
---|
111 |
|
---|
112 | void UIWizardCloneVD::sltRetranslateUI()
|
---|
113 | {
|
---|
114 | /* Translate wizard: */
|
---|
115 | setWindowTitle(tr("Copy Virtual Disk"));
|
---|
116 | UINativeWizard::sltRetranslateUI();
|
---|
117 | }
|
---|
118 |
|
---|
119 | void UIWizardCloneVD::populatePages()
|
---|
120 | {
|
---|
121 | /* Create corresponding pages: */
|
---|
122 | switch (mode())
|
---|
123 | {
|
---|
124 | case WizardMode_Basic:
|
---|
125 |
|
---|
126 | {
|
---|
127 | addPage(new UIWizardCloneVDFormatPage(m_enmDeviceType));
|
---|
128 | m_iMediumVariantPageIndex = addPage(new UIWizardCloneVDVariantPage);
|
---|
129 | addPage(new UIWizardCloneVDPathSizePage(sourceDiskLogicalSize()));
|
---|
130 | break;
|
---|
131 | }
|
---|
132 | case WizardMode_Expert:
|
---|
133 | {
|
---|
134 | addPage(new UIWizardCloneVDExpertPage(m_enmDeviceType, sourceDiskLogicalSize()));
|
---|
135 | break;
|
---|
136 | }
|
---|
137 | default:
|
---|
138 | {
|
---|
139 | AssertMsgFailed(("Invalid mode: %d", mode()));
|
---|
140 | break;
|
---|
141 | }
|
---|
142 | }
|
---|
143 | }
|
---|
144 |
|
---|
145 | const CMediumFormat &UIWizardCloneVD::mediumFormat() const
|
---|
146 | {
|
---|
147 | return m_comMediumFormat;
|
---|
148 | }
|
---|
149 |
|
---|
150 | void UIWizardCloneVD::setMediumFormat(const CMediumFormat &comMediumFormat)
|
---|
151 | {
|
---|
152 | m_comMediumFormat = comMediumFormat;
|
---|
153 | if (mode() == WizardMode_Basic)
|
---|
154 | setMediumVariantPageVisibility();
|
---|
155 | }
|
---|
156 |
|
---|
157 | qulonglong UIWizardCloneVD::mediumVariant() const
|
---|
158 | {
|
---|
159 | return m_uMediumVariant;
|
---|
160 | }
|
---|
161 |
|
---|
162 | void UIWizardCloneVD::setMediumVariant(qulonglong uMediumVariant)
|
---|
163 | {
|
---|
164 | m_uMediumVariant = uMediumVariant;
|
---|
165 | }
|
---|
166 |
|
---|
167 | qulonglong UIWizardCloneVD::mediumSize() const
|
---|
168 | {
|
---|
169 | return m_uMediumSize;
|
---|
170 | }
|
---|
171 |
|
---|
172 | void UIWizardCloneVD::setMediumSize(qulonglong uMediumSize)
|
---|
173 | {
|
---|
174 | m_uMediumSize = uMediumSize;
|
---|
175 | }
|
---|
176 |
|
---|
177 | const QString &UIWizardCloneVD::mediumPath() const
|
---|
178 | {
|
---|
179 | return m_strMediumPath;
|
---|
180 | }
|
---|
181 |
|
---|
182 | void UIWizardCloneVD::setMediumPath(const QString &strPath)
|
---|
183 | {
|
---|
184 | m_strMediumPath = strPath;
|
---|
185 | }
|
---|
186 |
|
---|
187 | qulonglong UIWizardCloneVD::sourceDiskLogicalSize() const
|
---|
188 | {
|
---|
189 | if (m_comSourceVirtualDisk.isNull())
|
---|
190 | return 0;
|
---|
191 | return m_comSourceVirtualDisk.GetLogicalSize();
|
---|
192 | }
|
---|
193 |
|
---|
194 | QString UIWizardCloneVD::sourceDiskFilePath() const
|
---|
195 | {
|
---|
196 | if (m_comSourceVirtualDisk.isNull())
|
---|
197 | return QString();
|
---|
198 | return m_comSourceVirtualDisk.GetLocation();
|
---|
199 | }
|
---|
200 |
|
---|
201 | QString UIWizardCloneVD::sourceDiskName() const
|
---|
202 | {
|
---|
203 | if (m_comSourceVirtualDisk.isNull())
|
---|
204 | return QString();
|
---|
205 | return m_comSourceVirtualDisk.GetName();
|
---|
206 | }
|
---|
207 |
|
---|
208 | void UIWizardCloneVD::setMediumVariantPageVisibility()
|
---|
209 | {
|
---|
210 | AssertReturnVoid(!m_comMediumFormat.isNull());
|
---|
211 | ULONG uCapabilities = 0;
|
---|
212 | QVector<KMediumFormatCapabilities> capabilities;
|
---|
213 | capabilities = m_comMediumFormat.GetCapabilities();
|
---|
214 | for (int i = 0; i < capabilities.size(); i++)
|
---|
215 | uCapabilities |= capabilities[i];
|
---|
216 |
|
---|
217 | int cTest = 0;
|
---|
218 | if (uCapabilities & KMediumFormatCapabilities_CreateDynamic)
|
---|
219 | ++cTest;
|
---|
220 | if (uCapabilities & KMediumFormatCapabilities_CreateFixed)
|
---|
221 | ++cTest;
|
---|
222 | if (uCapabilities & KMediumFormatCapabilities_CreateSplit2G)
|
---|
223 | ++cTest;
|
---|
224 | setPageVisible(m_iMediumVariantPageIndex, cTest > 1);
|
---|
225 | }
|
---|