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