1 | /* $Id: UIWizardNewVMUnattendedPage.cpp 103957 2024-03-20 13:41:59Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIWizardNewVMUnattendedPage 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 <QFileInfo>
|
---|
30 | #include <QGridLayout>
|
---|
31 |
|
---|
32 | /* GUI includes: */
|
---|
33 | #include "QIRichTextLabel.h"
|
---|
34 | #include "UIWizardNewVMEditors.h"
|
---|
35 | #include "UIWizardNewVMUnattendedPage.h"
|
---|
36 | #include "UIWizardNewVM.h"
|
---|
37 |
|
---|
38 | bool UIWizardNewVMUnattendedCommon::checkGAISOFile(const QString &strPath)
|
---|
39 | {
|
---|
40 | if (strPath.isNull() || strPath.isEmpty())
|
---|
41 | return false;
|
---|
42 | QFileInfo fileInfo(strPath);
|
---|
43 | if (!fileInfo.exists() || !fileInfo.isReadable())
|
---|
44 | return false;
|
---|
45 | return true;
|
---|
46 | }
|
---|
47 |
|
---|
48 | UIWizardNewVMUnattendedPage::UIWizardNewVMUnattendedPage()
|
---|
49 | : m_pLabel(0)
|
---|
50 | , m_pAdditionalOptionsContainer(0)
|
---|
51 | , m_pGAInstallationISOContainer(0)
|
---|
52 | , m_pUserNamePasswordGroupBox(0)
|
---|
53 | {
|
---|
54 | prepare();
|
---|
55 | }
|
---|
56 |
|
---|
57 | void UIWizardNewVMUnattendedPage::prepare()
|
---|
58 | {
|
---|
59 | QGridLayout *pMainLayout = new QGridLayout(this);
|
---|
60 |
|
---|
61 | m_pLabel = new QIRichTextLabel(this);
|
---|
62 | if (m_pLabel)
|
---|
63 | pMainLayout->addWidget(m_pLabel, 0, 0, 1, 2);
|
---|
64 |
|
---|
65 | m_pUserNamePasswordGroupBox = new UIUserNamePasswordGroupBox;
|
---|
66 | AssertReturnVoid(m_pUserNamePasswordGroupBox);
|
---|
67 | pMainLayout->addWidget(m_pUserNamePasswordGroupBox, 1, 0, 1, 1);
|
---|
68 |
|
---|
69 | m_pAdditionalOptionsContainer = new UIAdditionalUnattendedOptions;
|
---|
70 | AssertReturnVoid(m_pAdditionalOptionsContainer);
|
---|
71 | pMainLayout->addWidget(m_pAdditionalOptionsContainer, 1, 1, 1, 1);
|
---|
72 |
|
---|
73 | m_pGAInstallationISOContainer = new UIGAInstallationGroupBox;
|
---|
74 | AssertReturnVoid(m_pGAInstallationISOContainer);
|
---|
75 | pMainLayout->addWidget(m_pGAInstallationISOContainer, 2, 0, 1, 2);
|
---|
76 |
|
---|
77 | pMainLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Fixed, QSizePolicy::Expanding), 4, 0, 1, 2);
|
---|
78 |
|
---|
79 | createConnections();
|
---|
80 | }
|
---|
81 |
|
---|
82 | void UIWizardNewVMUnattendedPage::createConnections()
|
---|
83 | {
|
---|
84 | if (m_pUserNamePasswordGroupBox)
|
---|
85 | {
|
---|
86 | connect(m_pUserNamePasswordGroupBox, &UIUserNamePasswordGroupBox::sigPasswordChanged,
|
---|
87 | this, &UIWizardNewVMUnattendedPage::sltPasswordChanged);
|
---|
88 | connect(m_pUserNamePasswordGroupBox, &UIUserNamePasswordGroupBox::sigUserNameChanged,
|
---|
89 | this, &UIWizardNewVMUnattendedPage::sltUserNameChanged);
|
---|
90 | }
|
---|
91 | if (m_pGAInstallationISOContainer)
|
---|
92 | {
|
---|
93 | connect(m_pGAInstallationISOContainer, &UIGAInstallationGroupBox::toggled,
|
---|
94 | this, &UIWizardNewVMUnattendedPage::sltInstallGACheckBoxToggle);
|
---|
95 | connect(m_pGAInstallationISOContainer, &UIGAInstallationGroupBox::sigPathChanged,
|
---|
96 | this, &UIWizardNewVMUnattendedPage::sltGAISOPathChanged);
|
---|
97 | }
|
---|
98 |
|
---|
99 | if (m_pAdditionalOptionsContainer)
|
---|
100 | {
|
---|
101 | connect(m_pAdditionalOptionsContainer, &UIAdditionalUnattendedOptions::sigHostnameDomainNameChanged,
|
---|
102 | this, &UIWizardNewVMUnattendedPage::sltHostnameDomainNameChanged);
|
---|
103 | connect(m_pAdditionalOptionsContainer, &UIAdditionalUnattendedOptions::sigProductKeyChanged,
|
---|
104 | this, &UIWizardNewVMUnattendedPage::sltProductKeyChanged);
|
---|
105 | connect(m_pAdditionalOptionsContainer, &UIAdditionalUnattendedOptions::sigStartHeadlessChanged,
|
---|
106 | this, &UIWizardNewVMUnattendedPage::sltStartHeadlessChanged);
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 |
|
---|
111 | void UIWizardNewVMUnattendedPage::sltRetranslateUI()
|
---|
112 | {
|
---|
113 | setTitle(UIWizardNewVM::tr("Unattended Guest OS Install Setup"));
|
---|
114 | if (m_pLabel)
|
---|
115 | m_pLabel->setText(UIWizardNewVM::tr("You can configure the unattended guest OS install by modifying username, password, "
|
---|
116 | "and hostname. Additionally you can enable guest additions install. "
|
---|
117 | "For Microsoft Windows guests it is possible to provide a product key."));
|
---|
118 | if (m_pUserNamePasswordGroupBox)
|
---|
119 | m_pUserNamePasswordGroupBox->setTitle(UIWizardNewVM::tr("Username and Password"));
|
---|
120 | }
|
---|
121 |
|
---|
122 |
|
---|
123 | void UIWizardNewVMUnattendedPage::initializePage()
|
---|
124 | {
|
---|
125 | if (m_pAdditionalOptionsContainer)
|
---|
126 | m_pAdditionalOptionsContainer->disableEnableProductKeyWidgets(isProductKeyWidgetEnabled());
|
---|
127 | sltRetranslateUI();
|
---|
128 |
|
---|
129 | UIWizardNewVM *pWizard = wizardWindow<UIWizardNewVM>();
|
---|
130 | AssertReturnVoid(pWizard);
|
---|
131 | /* Initialize user/password if they are not modified by the user: */
|
---|
132 | if (m_pUserNamePasswordGroupBox)
|
---|
133 | {
|
---|
134 | m_pUserNamePasswordGroupBox->blockSignals(true);
|
---|
135 | if (!m_userModifiedParameters.contains("UserName"))
|
---|
136 | m_pUserNamePasswordGroupBox->setUserName(pWizard->userName());
|
---|
137 | if (!m_userModifiedParameters.contains("Password"))
|
---|
138 | m_pUserNamePasswordGroupBox->setPassword(pWizard->password());
|
---|
139 | m_pUserNamePasswordGroupBox->blockSignals(false);
|
---|
140 | }
|
---|
141 | if (m_pAdditionalOptionsContainer)
|
---|
142 | {
|
---|
143 | m_pAdditionalOptionsContainer->blockSignals(true);
|
---|
144 |
|
---|
145 | if (!m_userModifiedParameters.contains("HostnameDomainName"))
|
---|
146 | {
|
---|
147 | m_pAdditionalOptionsContainer->setHostname(pWizard->machineBaseName());
|
---|
148 | m_pAdditionalOptionsContainer->setDomainName("myguest.virtualbox.org");
|
---|
149 | /* Initialize unattended hostname here since we cannot get the efault value from CUnattended this early (unlike username etc): */
|
---|
150 | if (m_pAdditionalOptionsContainer->isHostnameComplete())
|
---|
151 | pWizard->setHostnameDomainName(m_pAdditionalOptionsContainer->hostnameDomainName());
|
---|
152 | }
|
---|
153 | m_pAdditionalOptionsContainer->blockSignals(false);
|
---|
154 | }
|
---|
155 | if (m_pGAInstallationISOContainer && !m_userModifiedParameters.contains("InstallGuestAdditions"))
|
---|
156 | {
|
---|
157 | m_pGAInstallationISOContainer->blockSignals(true);
|
---|
158 | m_pGAInstallationISOContainer->setChecked(pWizard->installGuestAdditions());
|
---|
159 | m_pGAInstallationISOContainer->blockSignals(false);
|
---|
160 | }
|
---|
161 |
|
---|
162 | if (m_pGAInstallationISOContainer && !m_userModifiedParameters.contains("GuestAdditionsISOPath"))
|
---|
163 | {
|
---|
164 | m_pGAInstallationISOContainer->blockSignals(true);
|
---|
165 | m_pGAInstallationISOContainer->setPath(pWizard->guestAdditionsISOPath());
|
---|
166 | m_pGAInstallationISOContainer->blockSignals(false);
|
---|
167 | }
|
---|
168 | }
|
---|
169 |
|
---|
170 | bool UIWizardNewVMUnattendedPage::isComplete() const
|
---|
171 | {
|
---|
172 | markWidgets();
|
---|
173 | UIWizardNewVM *pWizard = wizardWindow<UIWizardNewVM>();
|
---|
174 | if (pWizard && pWizard->installGuestAdditions() &&
|
---|
175 | m_pGAInstallationISOContainer &&
|
---|
176 | !UIWizardNewVMUnattendedCommon::checkGAISOFile(m_pGAInstallationISOContainer->path()))
|
---|
177 | return false;
|
---|
178 | if (m_pUserNamePasswordGroupBox && !m_pUserNamePasswordGroupBox->isComplete())
|
---|
179 | return false;
|
---|
180 | if (m_pAdditionalOptionsContainer && !m_pAdditionalOptionsContainer->isComplete())
|
---|
181 | return false;
|
---|
182 | return true;
|
---|
183 | }
|
---|
184 |
|
---|
185 | void UIWizardNewVMUnattendedPage::sltInstallGACheckBoxToggle(bool fEnabled)
|
---|
186 | {
|
---|
187 | wizardWindow<UIWizardNewVM>()->setInstallGuestAdditions(fEnabled);
|
---|
188 | m_userModifiedParameters << "InstallGuestAdditions";
|
---|
189 | emit completeChanged();
|
---|
190 | }
|
---|
191 |
|
---|
192 | void UIWizardNewVMUnattendedPage::sltGAISOPathChanged(const QString &strPath)
|
---|
193 | {
|
---|
194 | wizardWindow<UIWizardNewVM>()->setGuestAdditionsISOPath(strPath);
|
---|
195 | m_userModifiedParameters << "GuestAdditionsISOPath";
|
---|
196 | emit completeChanged();
|
---|
197 | }
|
---|
198 |
|
---|
199 | void UIWizardNewVMUnattendedPage::sltPasswordChanged(const QString &strPassword)
|
---|
200 | {
|
---|
201 | wizardWindow<UIWizardNewVM>()->setPassword(strPassword);
|
---|
202 | m_userModifiedParameters << "Password";
|
---|
203 | emit completeChanged();
|
---|
204 | }
|
---|
205 |
|
---|
206 | void UIWizardNewVMUnattendedPage::sltUserNameChanged(const QString &strUserName)
|
---|
207 | {
|
---|
208 | wizardWindow<UIWizardNewVM>()->setUserName(strUserName);
|
---|
209 | m_userModifiedParameters << "UserName";
|
---|
210 | emit completeChanged();
|
---|
211 | }
|
---|
212 |
|
---|
213 | bool UIWizardNewVMUnattendedPage::isProductKeyWidgetEnabled() const
|
---|
214 | {
|
---|
215 | UIWizardNewVM *pWizard = wizardWindow<UIWizardNewVM>();
|
---|
216 | if (!pWizard || !pWizard->isUnattendedEnabled() || !pWizard->isGuestOSTypeWindows())
|
---|
217 | return false;
|
---|
218 | return true;
|
---|
219 | }
|
---|
220 |
|
---|
221 | void UIWizardNewVMUnattendedPage::sltHostnameDomainNameChanged(const QString &strHostnameDomainName, bool fIsComplete)
|
---|
222 | {
|
---|
223 | AssertReturnVoid(wizardWindow<UIWizardNewVM>());
|
---|
224 | emit completeChanged();
|
---|
225 |
|
---|
226 | if (fIsComplete)
|
---|
227 | {
|
---|
228 | wizardWindow<UIWizardNewVM>()->setHostnameDomainName(strHostnameDomainName);
|
---|
229 | m_userModifiedParameters << "HostnameDomainName";
|
---|
230 | }
|
---|
231 | }
|
---|
232 |
|
---|
233 | void UIWizardNewVMUnattendedPage::sltProductKeyChanged(const QString &strProductKey)
|
---|
234 | {
|
---|
235 | AssertReturnVoid(wizardWindow<UIWizardNewVM>());
|
---|
236 | m_userModifiedParameters << "ProductKey";
|
---|
237 | wizardWindow<UIWizardNewVM>()->setProductKey(strProductKey);
|
---|
238 | }
|
---|
239 |
|
---|
240 | void UIWizardNewVMUnattendedPage::sltStartHeadlessChanged(bool fStartHeadless)
|
---|
241 | {
|
---|
242 | m_userModifiedParameters << "StartHeadless";
|
---|
243 | wizardWindow<UIWizardNewVM>()->setStartHeadless(fStartHeadless);
|
---|
244 | }
|
---|
245 |
|
---|
246 | void UIWizardNewVMUnattendedPage::markWidgets() const
|
---|
247 | {
|
---|
248 | AssertReturnVoid(wizardWindow<UIWizardNewVM>());
|
---|
249 | UIWizardNewVM *pWizard = wizardWindow<UIWizardNewVM>();
|
---|
250 | if (pWizard && pWizard->installGuestAdditions() && m_pGAInstallationISOContainer)
|
---|
251 | m_pGAInstallationISOContainer->mark();
|
---|
252 | }
|
---|
253 |
|
---|
254 | void UIWizardNewVMUnattendedPage::sltSelectedWindowsImageChanged(ulong uImageIndex)
|
---|
255 | {
|
---|
256 | AssertReturnVoid(wizardWindow<UIWizardNewVM>());
|
---|
257 | wizardWindow<UIWizardNewVM>()->setSelectedWindowImageIndex(uImageIndex);
|
---|
258 | }
|
---|