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