1 | /* $Id: UIWizardCloneVMNamePathPage.cpp 103957 2024-03-20 13:41:59Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIWizardCloneVMNamePathPage class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011-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 "QIRichTextLabel.h"
|
---|
34 | #include "UIGlobalSession.h"
|
---|
35 | #include "UIWizardCloneVM.h"
|
---|
36 | #include "UIWizardCloneVMNamePathPage.h"
|
---|
37 |
|
---|
38 | /* COM includes: */
|
---|
39 | #include "CVirtualBox.h"
|
---|
40 |
|
---|
41 | QString UIWizardCloneVMNamePathCommon::composeCloneFilePath(const QString &strCloneName, const QString &strGroup, const QString &strFolderPath)
|
---|
42 | {
|
---|
43 | CVirtualBox vbox = gpGlobalSession->virtualBox();
|
---|
44 | return QDir::toNativeSeparators(vbox.ComposeMachineFilename(strCloneName, strGroup, QString(), strFolderPath));
|
---|
45 | }
|
---|
46 |
|
---|
47 | UIWizardCloneVMNamePathPage::UIWizardCloneVMNamePathPage(const QString &strOriginalName, const QString &strDefaultPath, const QString &strGroup)
|
---|
48 | : m_pNamePathEditor(0)
|
---|
49 | , m_pAdditionalOptionsEditor(0)
|
---|
50 | , m_strOriginalName(strOriginalName)
|
---|
51 | , m_strGroup(strGroup)
|
---|
52 | {
|
---|
53 | prepare(strDefaultPath);
|
---|
54 | }
|
---|
55 |
|
---|
56 | void UIWizardCloneVMNamePathPage::sltRetranslateUI()
|
---|
57 | {
|
---|
58 | setTitle(UIWizardCloneVM::tr("New machine name and path"));
|
---|
59 |
|
---|
60 | if (m_pMainLabel)
|
---|
61 | m_pMainLabel->setText(UIWizardCloneVM::tr("<p>Please choose a name and optionally a folder for the new virtual machine. "
|
---|
62 | "The new machine will be a clone of the machine <b>%1</b>.</p>")
|
---|
63 | .arg(m_strOriginalName));
|
---|
64 |
|
---|
65 | int iMaxWidth = 0;
|
---|
66 | if (m_pNamePathEditor)
|
---|
67 | iMaxWidth = qMax(iMaxWidth, m_pNamePathEditor->firstColumnWidth());
|
---|
68 | if (m_pAdditionalOptionsEditor)
|
---|
69 | iMaxWidth = qMax(iMaxWidth, m_pAdditionalOptionsEditor->firstColumnWidth());
|
---|
70 |
|
---|
71 | if (m_pNamePathEditor)
|
---|
72 | m_pNamePathEditor->setFirstColumnWidth(iMaxWidth);
|
---|
73 | if (m_pAdditionalOptionsEditor)
|
---|
74 | m_pAdditionalOptionsEditor->setFirstColumnWidth(iMaxWidth);
|
---|
75 | }
|
---|
76 |
|
---|
77 | void UIWizardCloneVMNamePathPage::initializePage()
|
---|
78 | {
|
---|
79 | UIWizardCloneVM *pWizard = wizardWindow<UIWizardCloneVM>();
|
---|
80 | AssertReturnVoid(pWizard);
|
---|
81 | sltRetranslateUI();
|
---|
82 | if (m_pNamePathEditor)
|
---|
83 | {
|
---|
84 | m_pNamePathEditor->setFocus();
|
---|
85 | if (!m_userModifiedParameters.contains("CloneName"))
|
---|
86 | pWizard->setCloneName(m_pNamePathEditor->cloneName());
|
---|
87 | if (!m_userModifiedParameters.contains("CloneFilePath"))
|
---|
88 | pWizard->setCloneFilePath(UIWizardCloneVMNamePathCommon::composeCloneFilePath(m_pNamePathEditor->cloneName(),
|
---|
89 | m_strGroup, m_pNamePathEditor->clonePath()));
|
---|
90 |
|
---|
91 | }
|
---|
92 | if (m_pAdditionalOptionsEditor)
|
---|
93 | {
|
---|
94 | if (!m_userModifiedParameters.contains("MacAddressPolicy"))
|
---|
95 | pWizard->setMacAddressPolicy(m_pAdditionalOptionsEditor->macAddressClonePolicy());
|
---|
96 | if (!m_userModifiedParameters.contains("KeepDiskNames"))
|
---|
97 | pWizard->setKeepDiskNames(m_pAdditionalOptionsEditor->keepDiskNames());
|
---|
98 | if (!m_userModifiedParameters.contains("KeepHardwareUUIDs"))
|
---|
99 | pWizard->setKeepHardwareUUIDs(m_pAdditionalOptionsEditor->keepHardwareUUIDs());
|
---|
100 | }
|
---|
101 | }
|
---|
102 |
|
---|
103 | void UIWizardCloneVMNamePathPage::prepare(const QString &strDefaultClonePath)
|
---|
104 | {
|
---|
105 | QVBoxLayout *pMainLayout = new QVBoxLayout(this);
|
---|
106 |
|
---|
107 | AssertReturnVoid(pMainLayout);
|
---|
108 |
|
---|
109 | m_pMainLabel = new QIRichTextLabel(this);
|
---|
110 | if (m_pMainLabel)
|
---|
111 | pMainLayout->addWidget(m_pMainLabel);
|
---|
112 |
|
---|
113 | m_pNamePathEditor = new UICloneVMNamePathEditor(m_strOriginalName, strDefaultClonePath);
|
---|
114 | if (m_pNamePathEditor)
|
---|
115 | {
|
---|
116 | m_pNamePathEditor->setFlat(true);
|
---|
117 | m_pNamePathEditor->setLayoutContentsMargins(0, 0, 0, 0);
|
---|
118 | pMainLayout->addWidget(m_pNamePathEditor);
|
---|
119 | connect(m_pNamePathEditor, &UICloneVMNamePathEditor::sigCloneNameChanged,
|
---|
120 | this, &UIWizardCloneVMNamePathPage::sltCloneNameChanged);
|
---|
121 | connect(m_pNamePathEditor, &UICloneVMNamePathEditor::sigClonePathChanged,
|
---|
122 | this, &UIWizardCloneVMNamePathPage::sltClonePathChanged);
|
---|
123 | }
|
---|
124 |
|
---|
125 | m_pAdditionalOptionsEditor = new UICloneVMAdditionalOptionsEditor;
|
---|
126 | if (m_pAdditionalOptionsEditor)
|
---|
127 | {
|
---|
128 | m_pAdditionalOptionsEditor->setFlat(true);
|
---|
129 | pMainLayout->addWidget(m_pAdditionalOptionsEditor);
|
---|
130 | connect(m_pAdditionalOptionsEditor, &UICloneVMAdditionalOptionsEditor::sigMACAddressClonePolicyChanged,
|
---|
131 | this, &UIWizardCloneVMNamePathPage::sltMACAddressClonePolicyChanged);
|
---|
132 | connect(m_pAdditionalOptionsEditor, &UICloneVMAdditionalOptionsEditor::sigKeepDiskNamesToggled,
|
---|
133 | this, &UIWizardCloneVMNamePathPage::sltKeepDiskNamesToggled);
|
---|
134 | connect(m_pAdditionalOptionsEditor, &UICloneVMAdditionalOptionsEditor::sigKeepHardwareUUIDsToggled,
|
---|
135 | this, &UIWizardCloneVMNamePathPage::sltKeepHardwareUUIDsToggled);
|
---|
136 | }
|
---|
137 |
|
---|
138 | pMainLayout->addStretch();
|
---|
139 |
|
---|
140 | sltRetranslateUI();
|
---|
141 | }
|
---|
142 |
|
---|
143 | bool UIWizardCloneVMNamePathPage::isComplete() const
|
---|
144 | {
|
---|
145 | return m_pNamePathEditor && m_pNamePathEditor->isComplete(m_strGroup);
|
---|
146 | }
|
---|
147 |
|
---|
148 | void UIWizardCloneVMNamePathPage::sltCloneNameChanged(const QString &strCloneName)
|
---|
149 | {
|
---|
150 | UIWizardCloneVM *pWizard = wizardWindow<UIWizardCloneVM>();
|
---|
151 | AssertReturnVoid(pWizard);
|
---|
152 | AssertReturnVoid(m_pNamePathEditor);
|
---|
153 | m_userModifiedParameters << "CloneName";
|
---|
154 | m_userModifiedParameters << "CloneFilePath";
|
---|
155 | pWizard->setCloneName(strCloneName);
|
---|
156 | pWizard->setCloneFilePath(UIWizardCloneVMNamePathCommon::composeCloneFilePath(strCloneName, m_strGroup, m_pNamePathEditor->clonePath()));
|
---|
157 | emit completeChanged();
|
---|
158 | }
|
---|
159 |
|
---|
160 | void UIWizardCloneVMNamePathPage::sltClonePathChanged(const QString &strClonePath)
|
---|
161 | {
|
---|
162 | AssertReturnVoid(m_pNamePathEditor);
|
---|
163 | AssertReturnVoid(wizardWindow<UIWizardCloneVM>());
|
---|
164 | m_userModifiedParameters << "CloneFilePath";
|
---|
165 | wizardWindow<UIWizardCloneVM>()->setCloneFilePath(UIWizardCloneVMNamePathCommon::composeCloneFilePath(m_pNamePathEditor->cloneName(), m_strGroup, strClonePath));
|
---|
166 | emit completeChanged();
|
---|
167 | }
|
---|
168 |
|
---|
169 | void UIWizardCloneVMNamePathPage::sltMACAddressClonePolicyChanged(MACAddressClonePolicy enmMACAddressClonePolicy)
|
---|
170 | {
|
---|
171 | AssertReturnVoid(wizardWindow<UIWizardCloneVM>());
|
---|
172 | m_userModifiedParameters << "MacAddressPolicy";
|
---|
173 | wizardWindow<UIWizardCloneVM>()->setMacAddressPolicy(enmMACAddressClonePolicy);
|
---|
174 | emit completeChanged();
|
---|
175 | }
|
---|
176 |
|
---|
177 | void UIWizardCloneVMNamePathPage::sltKeepDiskNamesToggled(bool fKeepDiskNames)
|
---|
178 | {
|
---|
179 | AssertReturnVoid(wizardWindow<UIWizardCloneVM>());
|
---|
180 | m_userModifiedParameters << "KeepDiskNames";
|
---|
181 | wizardWindow<UIWizardCloneVM>()->setKeepDiskNames(fKeepDiskNames);
|
---|
182 | emit completeChanged();
|
---|
183 | }
|
---|
184 |
|
---|
185 | void UIWizardCloneVMNamePathPage::sltKeepHardwareUUIDsToggled(bool fKeepHardwareUUIDs)
|
---|
186 | {
|
---|
187 | AssertReturnVoid(wizardWindow<UIWizardCloneVM>());
|
---|
188 | m_userModifiedParameters << "KeepHardwareUUIDs";
|
---|
189 | wizardWindow<UIWizardCloneVM>()->setKeepHardwareUUIDs(fKeepHardwareUUIDs);
|
---|
190 | emit completeChanged();
|
---|
191 | }
|
---|