1 | /* $Id: UIWizardCloneVMEditors.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 <QComboBox>
|
---|
32 | #include <QDir>
|
---|
33 | #include <QLabel>
|
---|
34 | #include <QRadioButton>
|
---|
35 | #include <QGridLayout>
|
---|
36 |
|
---|
37 | /* GUI includes: */
|
---|
38 | #include "QILineEdit.h"
|
---|
39 | #include "UICommon.h"
|
---|
40 | #include "UIFilePathSelector.h"
|
---|
41 | #include "UIWizardCloneVM.h"
|
---|
42 | #include "UIWizardCloneVMEditors.h"
|
---|
43 |
|
---|
44 | /* Other VBox includes: */
|
---|
45 | #include "iprt/assert.h"
|
---|
46 | #include "COMEnums.h"
|
---|
47 | #include "CSystemProperties.h"
|
---|
48 |
|
---|
49 |
|
---|
50 | /*********************************************************************************************************************************
|
---|
51 | * UICloneVMNamePathEditor implementation. *
|
---|
52 | *********************************************************************************************************************************/
|
---|
53 |
|
---|
54 | UICloneVMNamePathEditor::UICloneVMNamePathEditor(const QString &strOriginalName, const QString &strDefaultPath, QWidget *pParent /* = 0 */)
|
---|
55 | :QIWithRetranslateUI<QGroupBox>(pParent)
|
---|
56 | , m_pContainerLayout(0)
|
---|
57 | , m_pNameLineEdit(0)
|
---|
58 | , m_pPathSelector(0)
|
---|
59 | , m_pNameLabel(0)
|
---|
60 | , m_pPathLabel(0)
|
---|
61 | , m_strOriginalName(strOriginalName)
|
---|
62 | , m_strDefaultPath(strDefaultPath)
|
---|
63 | {
|
---|
64 | prepare();
|
---|
65 | }
|
---|
66 |
|
---|
67 | bool UICloneVMNamePathEditor::isComplete(const QString &strMachineGroup)
|
---|
68 | {
|
---|
69 | AssertReturn(m_pNameLineEdit && m_pPathSelector, false);
|
---|
70 |
|
---|
71 | bool fInvalidName = m_pNameLineEdit->text().isEmpty();
|
---|
72 | m_pNameLineEdit->mark(fInvalidName, UIWizardCloneVM::tr("Clone name cannot be empty"));
|
---|
73 |
|
---|
74 | const QString &strPath = m_pPathSelector->path();
|
---|
75 | QDir dir(strPath);
|
---|
76 | bool fInvalidPath = strPath.isEmpty() || !dir.exists() || !dir.isReadable();
|
---|
77 | m_pPathSelector->mark(fInvalidPath, UIWizardCloneVM::tr("Path is invalid"));
|
---|
78 |
|
---|
79 | /* Check if there is already a machine folder for this name and path: */
|
---|
80 | bool fExists = false;
|
---|
81 | if (!fInvalidName)
|
---|
82 | {
|
---|
83 | CVirtualBox vbox = uiCommon().virtualBox();
|
---|
84 | QString strCloneFilePath =
|
---|
85 | vbox.ComposeMachineFilename(m_pNameLineEdit->text(), strMachineGroup, QString(), m_pPathSelector->path());
|
---|
86 | fExists = QDir(QDir::toNativeSeparators(QFileInfo(strCloneFilePath).absolutePath())).exists();
|
---|
87 | m_pNameLineEdit->mark(fExists, UIWizardCloneVM::tr("The clone name is not unique"));
|
---|
88 | }
|
---|
89 |
|
---|
90 | return !fInvalidName && !fInvalidPath && !fExists;
|
---|
91 | }
|
---|
92 |
|
---|
93 | QString UICloneVMNamePathEditor::cloneName() const
|
---|
94 | {
|
---|
95 | if (m_pNameLineEdit)
|
---|
96 | return m_pNameLineEdit->text();
|
---|
97 | return QString();
|
---|
98 | }
|
---|
99 |
|
---|
100 | void UICloneVMNamePathEditor::setCloneName(const QString &strName)
|
---|
101 | {
|
---|
102 | if (m_pNameLineEdit)
|
---|
103 | m_pNameLineEdit->setText(strName);
|
---|
104 | }
|
---|
105 |
|
---|
106 | QString UICloneVMNamePathEditor::clonePath() const
|
---|
107 | {
|
---|
108 | if (m_pPathSelector)
|
---|
109 | return m_pPathSelector->path();
|
---|
110 | return QString();
|
---|
111 | }
|
---|
112 |
|
---|
113 | void UICloneVMNamePathEditor::setClonePath(const QString &strPath)
|
---|
114 | {
|
---|
115 | if (m_pPathSelector)
|
---|
116 | m_pPathSelector->setPath(strPath);
|
---|
117 | }
|
---|
118 |
|
---|
119 | void UICloneVMNamePathEditor::setFirstColumnWidth(int iWidth)
|
---|
120 | {
|
---|
121 | if (m_pContainerLayout)
|
---|
122 | m_pContainerLayout->setColumnMinimumWidth(0, iWidth);
|
---|
123 | }
|
---|
124 |
|
---|
125 | int UICloneVMNamePathEditor::firstColumnWidth() const
|
---|
126 | {
|
---|
127 | int iMaxWidth = 0;
|
---|
128 | if (m_pNameLabel)
|
---|
129 | iMaxWidth = qMax(iMaxWidth, m_pNameLabel->minimumSizeHint().width());
|
---|
130 | if (m_pPathLabel)
|
---|
131 | iMaxWidth = qMax(iMaxWidth, m_pPathLabel->minimumSizeHint().width());
|
---|
132 | return iMaxWidth;
|
---|
133 | }
|
---|
134 |
|
---|
135 | void UICloneVMNamePathEditor::setLayoutContentsMargins(int iLeft, int iTop, int iRight, int iBottom)
|
---|
136 | {
|
---|
137 | if (m_pContainerLayout)
|
---|
138 | m_pContainerLayout->setContentsMargins(iLeft, iTop, iRight, iBottom);
|
---|
139 | }
|
---|
140 |
|
---|
141 | void UICloneVMNamePathEditor::prepare()
|
---|
142 | {
|
---|
143 | m_pContainerLayout = new QGridLayout(this);
|
---|
144 |
|
---|
145 |
|
---|
146 | m_pNameLabel = new QLabel;
|
---|
147 | if (m_pNameLabel)
|
---|
148 | {
|
---|
149 | m_pNameLabel->setAlignment(Qt::AlignRight);
|
---|
150 | m_pNameLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
|
---|
151 | m_pContainerLayout->addWidget(m_pNameLabel, 0, 0, 1, 1);
|
---|
152 | }
|
---|
153 |
|
---|
154 | m_pNameLineEdit = new UIMarkableLineEdit();
|
---|
155 | if (m_pNameLineEdit)
|
---|
156 | {
|
---|
157 | m_pContainerLayout->addWidget(m_pNameLineEdit, 0, 1, 1, 1);
|
---|
158 | m_pNameLineEdit->setText(UIWizardCloneVM::tr("%1 Clone").arg(m_strOriginalName));
|
---|
159 | connect(m_pNameLineEdit, &UIMarkableLineEdit::textChanged,
|
---|
160 | this, &UICloneVMNamePathEditor::sigCloneNameChanged);
|
---|
161 | if (m_pNameLabel)
|
---|
162 | m_pNameLabel->setBuddy(m_pNameLineEdit);
|
---|
163 | }
|
---|
164 |
|
---|
165 | m_pPathLabel = new QLabel(this);
|
---|
166 | if (m_pPathLabel)
|
---|
167 | {
|
---|
168 | m_pPathLabel->setAlignment(Qt::AlignRight);
|
---|
169 | m_pPathLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
|
---|
170 | m_pContainerLayout->addWidget(m_pPathLabel, 1, 0, 1, 1);
|
---|
171 | }
|
---|
172 |
|
---|
173 | m_pPathSelector = new UIFilePathSelector(this);
|
---|
174 | if (m_pPathSelector)
|
---|
175 | {
|
---|
176 | m_pContainerLayout->addWidget(m_pPathSelector, 1, 1, 1, 1);
|
---|
177 | m_pPathSelector->setPath(m_strDefaultPath);
|
---|
178 | connect(m_pPathSelector, &UIFilePathSelector::pathChanged,
|
---|
179 | this, &UICloneVMNamePathEditor::sigClonePathChanged);
|
---|
180 | if (m_pPathLabel)
|
---|
181 | m_pPathLabel->setBuddy(m_pPathSelector);
|
---|
182 |
|
---|
183 | }
|
---|
184 |
|
---|
185 | retranslateUi();
|
---|
186 | }
|
---|
187 |
|
---|
188 | void UICloneVMNamePathEditor::retranslateUi()
|
---|
189 | {
|
---|
190 | if (m_pNameLabel)
|
---|
191 | m_pNameLabel->setText(UIWizardCloneVM::tr("&Name:"));
|
---|
192 | if (m_pPathLabel)
|
---|
193 | m_pPathLabel->setText(UIWizardCloneVM::tr("&Path:"));
|
---|
194 | if (m_pNameLineEdit)
|
---|
195 | m_pNameLineEdit->setToolTip(UIWizardCloneVM::tr("Holds a name for the new virtual machine."));
|
---|
196 | if (m_pPathSelector)
|
---|
197 | m_pPathSelector->setToolTip(UIWizardCloneVM::tr("Specifies The location of the new virtual machine in host's storage."));
|
---|
198 | }
|
---|
199 |
|
---|
200 |
|
---|
201 | /*********************************************************************************************************************************
|
---|
202 | * UICloneVMAdditionalOptionsEditor implementation. *
|
---|
203 | *********************************************************************************************************************************/
|
---|
204 |
|
---|
205 |
|
---|
206 | UICloneVMAdditionalOptionsEditor::UICloneVMAdditionalOptionsEditor(QWidget *pParent /* = 0 */)
|
---|
207 | :QIWithRetranslateUI<QGroupBox>(pParent)
|
---|
208 | , m_pContainerLayout(0)
|
---|
209 | , m_pMACComboBoxLabel(0)
|
---|
210 | , m_pMACComboBox(0)
|
---|
211 | , m_pAdditionalOptionsLabel(0)
|
---|
212 | , m_pKeepDiskNamesCheckBox(0)
|
---|
213 | , m_pKeepHWUUIDsCheckBox(0)
|
---|
214 | {
|
---|
215 | prepare();
|
---|
216 | }
|
---|
217 |
|
---|
218 | void UICloneVMAdditionalOptionsEditor::setLayoutContentsMargins(int iLeft, int iTop, int iRight, int iBottom)
|
---|
219 | {
|
---|
220 | if (m_pContainerLayout)
|
---|
221 | m_pContainerLayout->setContentsMargins(iLeft, iTop, iRight, iBottom);
|
---|
222 | }
|
---|
223 |
|
---|
224 | void UICloneVMAdditionalOptionsEditor::setFirstColumnWidth(int iWidth)
|
---|
225 | {
|
---|
226 | if (m_pContainerLayout)
|
---|
227 | m_pContainerLayout->setColumnMinimumWidth(0, iWidth);
|
---|
228 | }
|
---|
229 |
|
---|
230 | int UICloneVMAdditionalOptionsEditor::firstColumnWidth() const
|
---|
231 | {
|
---|
232 | int iMaxWidth = 0;
|
---|
233 | if (m_pMACComboBoxLabel)
|
---|
234 | iMaxWidth = qMax(iMaxWidth, m_pMACComboBoxLabel->minimumSizeHint().width());
|
---|
235 | if (m_pAdditionalOptionsLabel)
|
---|
236 | iMaxWidth = qMax(iMaxWidth, m_pAdditionalOptionsLabel->minimumSizeHint().width());
|
---|
237 | return iMaxWidth;
|
---|
238 | }
|
---|
239 |
|
---|
240 | MACAddressClonePolicy UICloneVMAdditionalOptionsEditor::macAddressClonePolicy() const
|
---|
241 | {
|
---|
242 | return m_pMACComboBox->currentData().value<MACAddressClonePolicy>();
|
---|
243 | }
|
---|
244 |
|
---|
245 | void UICloneVMAdditionalOptionsEditor::setMACAddressClonePolicy(MACAddressClonePolicy enmMACAddressClonePolicy)
|
---|
246 | {
|
---|
247 | const int iIndex = m_pMACComboBox->findData(QVariant::fromValue(enmMACAddressClonePolicy));
|
---|
248 | AssertMsg(iIndex != -1, ("Data not found!"));
|
---|
249 | m_pMACComboBox->setCurrentIndex(iIndex);
|
---|
250 | }
|
---|
251 |
|
---|
252 | bool UICloneVMAdditionalOptionsEditor::keepHardwareUUIDs() const
|
---|
253 | {
|
---|
254 | if (m_pKeepHWUUIDsCheckBox)
|
---|
255 | return m_pKeepHWUUIDsCheckBox->isChecked();
|
---|
256 | return false;
|
---|
257 | }
|
---|
258 |
|
---|
259 | bool UICloneVMAdditionalOptionsEditor::keepDiskNames() const
|
---|
260 | {
|
---|
261 | if (m_pKeepDiskNamesCheckBox)
|
---|
262 | m_pKeepDiskNamesCheckBox->isChecked();
|
---|
263 | return false;
|
---|
264 | }
|
---|
265 |
|
---|
266 | void UICloneVMAdditionalOptionsEditor::prepare()
|
---|
267 | {
|
---|
268 | m_pContainerLayout = new QGridLayout(this);
|
---|
269 |
|
---|
270 | m_pMACComboBoxLabel = new QLabel;
|
---|
271 | if (m_pMACComboBoxLabel)
|
---|
272 | {
|
---|
273 | m_pMACComboBoxLabel->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter);
|
---|
274 | m_pContainerLayout->addWidget(m_pMACComboBoxLabel, 2, 0, 1, 1);
|
---|
275 | }
|
---|
276 |
|
---|
277 | m_pMACComboBox = new QComboBox;
|
---|
278 | if (m_pMACComboBox)
|
---|
279 | {
|
---|
280 | m_pContainerLayout->addWidget(m_pMACComboBox, 2, 1, 1, 1);
|
---|
281 | connect(m_pMACComboBox, &QComboBox::currentIndexChanged,
|
---|
282 | this, &UICloneVMAdditionalOptionsEditor::sltMACAddressClonePolicyChanged);
|
---|
283 | if (m_pMACComboBoxLabel)
|
---|
284 | m_pMACComboBoxLabel->setBuddy(m_pMACComboBox);
|
---|
285 | }
|
---|
286 | m_pMACComboBox->blockSignals(true);
|
---|
287 | populateMACAddressClonePolicies();
|
---|
288 | m_pMACComboBox->blockSignals(false);
|
---|
289 |
|
---|
290 | /* Load currently supported clone options: */
|
---|
291 | CSystemProperties comProperties = uiCommon().virtualBox().GetSystemProperties();
|
---|
292 | const QVector<KCloneOptions> supportedOptions = comProperties.GetSupportedCloneOptions();
|
---|
293 | /* Check whether we support additional clone options at all: */
|
---|
294 | int iVerticalPosition = 3;
|
---|
295 | const bool fSupportedKeepDiskNames = supportedOptions.contains(KCloneOptions_KeepDiskNames);
|
---|
296 | const bool fSupportedKeepHWUUIDs = supportedOptions.contains(KCloneOptions_KeepHwUUIDs);
|
---|
297 | if (fSupportedKeepDiskNames || fSupportedKeepHWUUIDs)
|
---|
298 | {
|
---|
299 | m_pAdditionalOptionsLabel = new QLabel;
|
---|
300 | if (m_pAdditionalOptionsLabel)
|
---|
301 | {
|
---|
302 | m_pAdditionalOptionsLabel->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter);
|
---|
303 | m_pContainerLayout->addWidget(m_pAdditionalOptionsLabel, iVerticalPosition, 0, 1, 1);
|
---|
304 | }
|
---|
305 | }
|
---|
306 | if (fSupportedKeepDiskNames)
|
---|
307 | {
|
---|
308 | m_pKeepDiskNamesCheckBox = new QCheckBox;
|
---|
309 | if (m_pKeepDiskNamesCheckBox)
|
---|
310 | {
|
---|
311 | m_pContainerLayout->addWidget(m_pKeepDiskNamesCheckBox, iVerticalPosition++, 1, 1, 1);
|
---|
312 | connect(m_pKeepDiskNamesCheckBox, &QCheckBox::toggled,
|
---|
313 | this, &UICloneVMAdditionalOptionsEditor::sigKeepDiskNamesToggled);
|
---|
314 | }
|
---|
315 | }
|
---|
316 | if (fSupportedKeepHWUUIDs)
|
---|
317 | {
|
---|
318 | m_pKeepHWUUIDsCheckBox = new QCheckBox;
|
---|
319 | if (m_pKeepHWUUIDsCheckBox)
|
---|
320 | {
|
---|
321 | m_pContainerLayout->addWidget(m_pKeepHWUUIDsCheckBox, iVerticalPosition++, 1, 1, 1);
|
---|
322 | connect(m_pKeepHWUUIDsCheckBox, &QCheckBox::toggled,
|
---|
323 | this, &UICloneVMAdditionalOptionsEditor::sigKeepHardwareUUIDsToggled);
|
---|
324 | }
|
---|
325 | }
|
---|
326 |
|
---|
327 |
|
---|
328 | retranslateUi();
|
---|
329 | }
|
---|
330 |
|
---|
331 | void UICloneVMAdditionalOptionsEditor::retranslateUi()
|
---|
332 | {
|
---|
333 | m_pMACComboBoxLabel->setText(UIWizardCloneVM::tr("MAC Address P&olicy:"));
|
---|
334 | m_pMACComboBox->setToolTip(UIWizardCloneVM::tr("Determines MAC address policy for clonning:"));
|
---|
335 | for (int i = 0; i < m_pMACComboBox->count(); ++i)
|
---|
336 | {
|
---|
337 | const MACAddressClonePolicy enmPolicy = m_pMACComboBox->itemData(i).value<MACAddressClonePolicy>();
|
---|
338 | switch (enmPolicy)
|
---|
339 | {
|
---|
340 | case MACAddressClonePolicy_KeepAllMACs:
|
---|
341 | {
|
---|
342 | m_pMACComboBox->setItemText(i, UIWizardCloneVM::tr("Include all network adapter MAC addresses"));
|
---|
343 | m_pMACComboBox->setItemData(i, UIWizardCloneVM::tr("Include all network adapter MAC addresses during "
|
---|
344 | "cloning."), Qt::ToolTipRole);
|
---|
345 | break;
|
---|
346 | }
|
---|
347 | case MACAddressClonePolicy_KeepNATMACs:
|
---|
348 | {
|
---|
349 | m_pMACComboBox->setItemText(i, UIWizardCloneVM::tr("Include only NAT network adapter MAC addresses"));
|
---|
350 | m_pMACComboBox->setItemData(i, UIWizardCloneVM::tr("Include only NAT network adapter MAC addresses during "
|
---|
351 | "cloning."), Qt::ToolTipRole);
|
---|
352 | break;
|
---|
353 | }
|
---|
354 | case MACAddressClonePolicy_StripAllMACs:
|
---|
355 | {
|
---|
356 | m_pMACComboBox->setItemText(i, UIWizardCloneVM::tr("Generate new MAC addresses for all network adapters"));
|
---|
357 | m_pMACComboBox->setItemData(i, UIWizardCloneVM::tr("Generate new MAC addresses for all network adapters during "
|
---|
358 | "cloning."), Qt::ToolTipRole);
|
---|
359 | break;
|
---|
360 | }
|
---|
361 | default:
|
---|
362 | break;
|
---|
363 | }
|
---|
364 | }
|
---|
365 |
|
---|
366 | if (m_pAdditionalOptionsLabel)
|
---|
367 | m_pAdditionalOptionsLabel->setText(UIWizardCloneVM::tr("Additional Options:"));
|
---|
368 | if (m_pKeepDiskNamesCheckBox)
|
---|
369 | {
|
---|
370 | m_pKeepDiskNamesCheckBox->setToolTip(UIWizardCloneVM::tr("When checked, disk names will be preserved during cloning."));
|
---|
371 | m_pKeepDiskNamesCheckBox->setText(UIWizardCloneVM::tr("Keep &Disk Names"));
|
---|
372 | }
|
---|
373 | if (m_pKeepHWUUIDsCheckBox)
|
---|
374 | {
|
---|
375 | m_pKeepHWUUIDsCheckBox->setToolTip(UIWizardCloneVM::tr("When checked, hardware UUIDs will be preserved during cloning."));
|
---|
376 | m_pKeepHWUUIDsCheckBox->setText(UIWizardCloneVM::tr("Keep Hard&ware UUIDs"));
|
---|
377 | }
|
---|
378 | }
|
---|
379 |
|
---|
380 | void UICloneVMAdditionalOptionsEditor::sltMACAddressClonePolicyChanged()
|
---|
381 | {
|
---|
382 | emit sigMACAddressClonePolicyChanged(macAddressClonePolicy());
|
---|
383 | updateMACAddressClonePolicyComboToolTip();
|
---|
384 | }
|
---|
385 |
|
---|
386 | void UICloneVMAdditionalOptionsEditor::updateMACAddressClonePolicyComboToolTip()
|
---|
387 | {
|
---|
388 | if (!m_pMACComboBox)
|
---|
389 | return;
|
---|
390 | const QString strCurrentToolTip = m_pMACComboBox->currentData(Qt::ToolTipRole).toString();
|
---|
391 | AssertMsg(!strCurrentToolTip.isEmpty(), ("Tool-tip data not found!"));
|
---|
392 | m_pMACComboBox->setToolTip(strCurrentToolTip);
|
---|
393 | }
|
---|
394 |
|
---|
395 | void UICloneVMAdditionalOptionsEditor::populateMACAddressClonePolicies()
|
---|
396 | {
|
---|
397 | AssertReturnVoid(m_pMACComboBox && m_pMACComboBox->count() == 0);
|
---|
398 |
|
---|
399 | /* Map known clone options to known MAC address export policies: */
|
---|
400 | QMap<KCloneOptions, MACAddressClonePolicy> knownOptions;
|
---|
401 | knownOptions[KCloneOptions_KeepAllMACs] = MACAddressClonePolicy_KeepAllMACs;
|
---|
402 | knownOptions[KCloneOptions_KeepNATMACs] = MACAddressClonePolicy_KeepNATMACs;
|
---|
403 |
|
---|
404 | /* Load currently supported clone options: */
|
---|
405 | CSystemProperties comProperties = uiCommon().virtualBox().GetSystemProperties();
|
---|
406 | const QVector<KCloneOptions> supportedOptions = comProperties.GetSupportedCloneOptions();
|
---|
407 |
|
---|
408 | /* Check which of supported options/policies are known: */
|
---|
409 | QList<MACAddressClonePolicy> supportedPolicies;
|
---|
410 | foreach (const KCloneOptions &enmOption, supportedOptions)
|
---|
411 | if (knownOptions.contains(enmOption))
|
---|
412 | supportedPolicies << knownOptions.value(enmOption);
|
---|
413 |
|
---|
414 | /* Add supported policies first: */
|
---|
415 | foreach (const MACAddressClonePolicy &enmPolicy, supportedPolicies)
|
---|
416 | m_pMACComboBox->addItem(QString(), QVariant::fromValue(enmPolicy));
|
---|
417 |
|
---|
418 | /* Add hardcoded policy finally: */
|
---|
419 | m_pMACComboBox->addItem(QString(), QVariant::fromValue(MACAddressClonePolicy_StripAllMACs));
|
---|
420 |
|
---|
421 | /* Set default: */
|
---|
422 | if (supportedPolicies.contains(MACAddressClonePolicy_KeepNATMACs))
|
---|
423 | setMACAddressClonePolicy(MACAddressClonePolicy_KeepNATMACs);
|
---|
424 | else
|
---|
425 | setMACAddressClonePolicy(MACAddressClonePolicy_StripAllMACs);
|
---|
426 | }
|
---|
427 |
|
---|
428 |
|
---|
429 | /*********************************************************************************************************************************
|
---|
430 | * UICloneVMAdditionalOptionsEditor implementation. *
|
---|
431 | *********************************************************************************************************************************/
|
---|
432 |
|
---|
433 | UICloneVMCloneTypeGroupBox::UICloneVMCloneTypeGroupBox(QWidget *pParent /* = 0 */)
|
---|
434 | :QIWithRetranslateUI<QGroupBox>(pParent)
|
---|
435 | , m_pButtonGroup(0)
|
---|
436 | , m_pFullCloneRadio(0)
|
---|
437 | , m_pLinkedCloneRadio(0)
|
---|
438 | {
|
---|
439 | prepare();
|
---|
440 | }
|
---|
441 |
|
---|
442 | bool UICloneVMCloneTypeGroupBox::isFullClone() const
|
---|
443 | {
|
---|
444 | if (m_pFullCloneRadio)
|
---|
445 | return m_pFullCloneRadio->isChecked();
|
---|
446 | return true;
|
---|
447 | }
|
---|
448 |
|
---|
449 | void UICloneVMCloneTypeGroupBox::prepare()
|
---|
450 | {
|
---|
451 | QVBoxLayout *pMainLayout = new QVBoxLayout(this);
|
---|
452 | AssertReturnVoid(pMainLayout);
|
---|
453 | /* Prepare clone-type options button-group: */
|
---|
454 | m_pButtonGroup = new QButtonGroup(this);
|
---|
455 | if (m_pButtonGroup)
|
---|
456 | {
|
---|
457 | /* Prepare full clone option radio-button: */
|
---|
458 | m_pFullCloneRadio = new QRadioButton(this);
|
---|
459 | if (m_pFullCloneRadio)
|
---|
460 | {
|
---|
461 | m_pFullCloneRadio->setChecked(true);
|
---|
462 | m_pButtonGroup->addButton(m_pFullCloneRadio);
|
---|
463 | pMainLayout->addWidget(m_pFullCloneRadio);
|
---|
464 | }
|
---|
465 |
|
---|
466 | /* Load currently supported clone options: */
|
---|
467 | CSystemProperties comProperties = uiCommon().virtualBox().GetSystemProperties();
|
---|
468 | const QVector<KCloneOptions> supportedOptions = comProperties.GetSupportedCloneOptions();
|
---|
469 | /* Check whether we support linked clone option at all: */
|
---|
470 | const bool fSupportedLinkedClone = supportedOptions.contains(KCloneOptions_Link);
|
---|
471 |
|
---|
472 | /* Prepare linked clone option radio-button: */
|
---|
473 | if (fSupportedLinkedClone)
|
---|
474 | {
|
---|
475 | m_pLinkedCloneRadio = new QRadioButton(this);
|
---|
476 | if (m_pLinkedCloneRadio)
|
---|
477 | {
|
---|
478 | m_pButtonGroup->addButton(m_pLinkedCloneRadio);
|
---|
479 | pMainLayout->addWidget(m_pLinkedCloneRadio);
|
---|
480 | }
|
---|
481 | }
|
---|
482 | }
|
---|
483 |
|
---|
484 | connect(m_pButtonGroup, &QButtonGroup::buttonClicked,
|
---|
485 | this, &UICloneVMCloneTypeGroupBox::sltButtonClicked);
|
---|
486 |
|
---|
487 | retranslateUi();
|
---|
488 | }
|
---|
489 |
|
---|
490 | void UICloneVMCloneTypeGroupBox::retranslateUi()
|
---|
491 | {
|
---|
492 | if (m_pFullCloneRadio)
|
---|
493 | {
|
---|
494 | m_pFullCloneRadio->setText(UIWizardCloneVM::tr("&Full clone"));
|
---|
495 | m_pFullCloneRadio->setToolTip(UIWizardCloneVM::tr("When chosen, all the virtual disks of the source vm are also cloned."));
|
---|
496 | }
|
---|
497 | if (m_pLinkedCloneRadio)
|
---|
498 | {
|
---|
499 | m_pLinkedCloneRadio->setText(UIWizardCloneVM::tr("&Linked clone"));
|
---|
500 | m_pLinkedCloneRadio->setToolTip(UIWizardCloneVM::tr("When chosen, the cloned vm will save space by sharing the source VM's disk images."));
|
---|
501 | }
|
---|
502 | }
|
---|
503 |
|
---|
504 | void UICloneVMCloneTypeGroupBox::sltButtonClicked(QAbstractButton *)
|
---|
505 | {
|
---|
506 | emit sigFullCloneSelected(m_pFullCloneRadio && m_pFullCloneRadio->isChecked());
|
---|
507 | }
|
---|
508 |
|
---|
509 |
|
---|
510 | /*********************************************************************************************************************************
|
---|
511 | * UICloneVMAdditionalOptionsEditor implementation. *
|
---|
512 | *********************************************************************************************************************************/
|
---|
513 |
|
---|
514 | UICloneVMCloneModeGroupBox::UICloneVMCloneModeGroupBox(bool fShowChildsOption, QWidget *pParent /* = 0 */)
|
---|
515 | :QIWithRetranslateUI<QGroupBox>(pParent)
|
---|
516 | , m_fShowChildsOption(fShowChildsOption)
|
---|
517 | , m_pMachineRadio(0)
|
---|
518 | , m_pMachineAndChildsRadio(0)
|
---|
519 | , m_pAllRadio(0)
|
---|
520 | {
|
---|
521 | prepare();
|
---|
522 | }
|
---|
523 |
|
---|
524 | void UICloneVMCloneModeGroupBox::prepare()
|
---|
525 | {
|
---|
526 | QVBoxLayout *pMainLayout = new QVBoxLayout(this);
|
---|
527 | AssertReturnVoid(pMainLayout);
|
---|
528 |
|
---|
529 | QButtonGroup *pButtonGroup = new QButtonGroup(this);
|
---|
530 | m_pMachineRadio = new QRadioButton(this);
|
---|
531 | if (m_pMachineRadio)
|
---|
532 | {
|
---|
533 | m_pMachineRadio->setChecked(true);
|
---|
534 | pButtonGroup->addButton(m_pMachineRadio);
|
---|
535 | }
|
---|
536 | m_pMachineAndChildsRadio = new QRadioButton(this);
|
---|
537 | if (m_pMachineAndChildsRadio)
|
---|
538 | {
|
---|
539 | if (!m_fShowChildsOption)
|
---|
540 | m_pMachineAndChildsRadio->hide();
|
---|
541 | pButtonGroup->addButton(m_pMachineAndChildsRadio);
|
---|
542 | }
|
---|
543 |
|
---|
544 | m_pAllRadio = new QRadioButton(this);
|
---|
545 | if (m_pAllRadio)
|
---|
546 | pButtonGroup->addButton(m_pAllRadio);
|
---|
547 |
|
---|
548 | pMainLayout->addWidget(m_pMachineRadio);
|
---|
549 | pMainLayout->addWidget(m_pMachineAndChildsRadio);
|
---|
550 | pMainLayout->addWidget(m_pAllRadio);
|
---|
551 | pMainLayout->addStretch();
|
---|
552 |
|
---|
553 | connect(pButtonGroup, &QButtonGroup::buttonClicked,
|
---|
554 | this, &UICloneVMCloneModeGroupBox::sltButtonClicked);
|
---|
555 |
|
---|
556 | retranslateUi();
|
---|
557 | }
|
---|
558 |
|
---|
559 | void UICloneVMCloneModeGroupBox::retranslateUi()
|
---|
560 | {
|
---|
561 | if (m_pMachineRadio)
|
---|
562 | {
|
---|
563 | m_pMachineRadio->setText(UIWizardCloneVM::tr("Current &machine state"));
|
---|
564 | m_pMachineRadio->setToolTip(UIWizardCloneVM::tr("When chosen, only the current state of the source vm is cloned."));
|
---|
565 | }
|
---|
566 | if (m_pMachineAndChildsRadio)
|
---|
567 | m_pMachineAndChildsRadio->setText(UIWizardCloneVM::tr("Current &snapshot tree branch"));
|
---|
568 | if (m_pAllRadio)
|
---|
569 | {
|
---|
570 | m_pAllRadio->setText(UIWizardCloneVM::tr("&Everything"));
|
---|
571 | m_pAllRadio->setToolTip(UIWizardCloneVM::tr("When chosen, all the saved states of the source vm are also cloned."));
|
---|
572 | }
|
---|
573 | }
|
---|
574 |
|
---|
575 |
|
---|
576 | void UICloneVMCloneModeGroupBox::sltButtonClicked()
|
---|
577 | {
|
---|
578 | emit sigCloneModeChanged(cloneMode());
|
---|
579 | }
|
---|
580 |
|
---|
581 | KCloneMode UICloneVMCloneModeGroupBox::cloneMode() const
|
---|
582 | {
|
---|
583 | KCloneMode enmCloneMode = KCloneMode_MachineState;
|
---|
584 | if (m_pMachineAndChildsRadio && m_pMachineAndChildsRadio->isChecked())
|
---|
585 | enmCloneMode = KCloneMode_MachineAndChildStates;
|
---|
586 | else if (m_pAllRadio && m_pAllRadio->isChecked())
|
---|
587 | enmCloneMode = KCloneMode_AllStates;
|
---|
588 | return enmCloneMode;
|
---|
589 | }
|
---|