VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/wizards/editors/UIWizardNewVMEditors.cpp

Last change on this file was 103950, checked in by vboxsync, 2 months ago

FE/Qt. bugref:10622. Using new UITranslationEventListener in wizard classes. part 3.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.4 KB
Line 
1/* $Id: UIWizardNewVMEditors.cpp 103950 2024-03-20 11:41:04Z 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 <QCheckBox>
30#include <QLabel>
31#include <QVBoxLayout>
32
33/* GUI includes: */
34#include "QILineEdit.h"
35#include "UIBaseMemoryEditor.h"
36#include "UICommon.h"
37#include "UIFilePathSelector.h"
38#include "UIHostnameDomainNameEditor.h"
39#include "UITranslationEventListener.h"
40#include "UIUserNamePasswordEditor.h"
41#include "UIVirtualCPUEditor.h"
42#include "UIWizardNewVM.h"
43#include "UIWizardNewVMEditors.h"
44#include "UIWizardNewVMUnattendedPage.h"
45
46/* Other VBox includes: */
47#include "iprt/assert.h"
48
49
50/*********************************************************************************************************************************
51* UIUserNamePasswordGroupBox implementation. *
52*********************************************************************************************************************************/
53
54UIUserNamePasswordGroupBox::UIUserNamePasswordGroupBox(QWidget *pParent /* = 0 */)
55 : QGroupBox(pParent)
56 , m_pUserNamePasswordEditor(0)
57{
58 prepare();
59}
60
61void UIUserNamePasswordGroupBox::prepare()
62{
63 QVBoxLayout *pUserNameContainerLayout = new QVBoxLayout(this);
64 m_pUserNamePasswordEditor = new UIUserNamePasswordEditor;
65 AssertReturnVoid(m_pUserNamePasswordEditor);
66 m_pUserNamePasswordEditor->setLabelsVisible(true);
67 m_pUserNamePasswordEditor->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
68 pUserNameContainerLayout->addWidget(m_pUserNamePasswordEditor);
69
70 connect(m_pUserNamePasswordEditor, &UIUserNamePasswordEditor::sigPasswordChanged,
71 this, &UIUserNamePasswordGroupBox::sigPasswordChanged);
72 connect(m_pUserNamePasswordEditor, &UIUserNamePasswordEditor::sigUserNameChanged,
73 this, &UIUserNamePasswordGroupBox::sigUserNameChanged);
74 sltRetranslateUI();
75 connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
76 this, &UIUserNamePasswordGroupBox::sltRetranslateUI);
77}
78
79void UIUserNamePasswordGroupBox::sltRetranslateUI()
80{
81 setTitle(UIWizardNewVM::tr("Username and Password"));
82}
83
84QString UIUserNamePasswordGroupBox::userName() const
85{
86 if (m_pUserNamePasswordEditor)
87 return m_pUserNamePasswordEditor->userName();
88 return QString();
89}
90
91void UIUserNamePasswordGroupBox::setUserName(const QString &strUserName)
92{
93 if (m_pUserNamePasswordEditor)
94 m_pUserNamePasswordEditor->setUserName(strUserName);
95}
96
97QString UIUserNamePasswordGroupBox::password() const
98{
99 if (m_pUserNamePasswordEditor)
100 return m_pUserNamePasswordEditor->password();
101 return QString();
102}
103
104void UIUserNamePasswordGroupBox::setPassword(const QString &strPassword)
105{
106 if (m_pUserNamePasswordEditor)
107 m_pUserNamePasswordEditor->setPassword(strPassword);
108}
109
110bool UIUserNamePasswordGroupBox::isComplete()
111{
112 if (m_pUserNamePasswordEditor)
113 return m_pUserNamePasswordEditor->isComplete();
114 return false;
115}
116
117void UIUserNamePasswordGroupBox::setLabelsVisible(bool fVisible)
118{
119 if (m_pUserNamePasswordEditor)
120 m_pUserNamePasswordEditor->setLabelsVisible(fVisible);
121}
122
123
124/*********************************************************************************************************************************
125* UIGAInstallationGroupBox implementation. *
126*********************************************************************************************************************************/
127
128UIGAInstallationGroupBox::UIGAInstallationGroupBox(QWidget *pParent /* = 0 */)
129 : QGroupBox(pParent)
130 , m_pGAISOPathLabel(0)
131 , m_pGAISOFilePathSelector(0)
132
133{
134 prepare();
135}
136
137void UIGAInstallationGroupBox::prepare()
138{
139 setCheckable(true);
140
141 QHBoxLayout *pGAInstallationISOLayout = new QHBoxLayout(this);
142 AssertReturnVoid(pGAInstallationISOLayout);
143 m_pGAISOPathLabel = new QLabel;
144 AssertReturnVoid(m_pGAISOPathLabel);
145 m_pGAISOPathLabel->setAlignment(Qt::AlignRight);
146 m_pGAISOPathLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
147
148 pGAInstallationISOLayout->addWidget(m_pGAISOPathLabel);
149
150 m_pGAISOFilePathSelector = new UIFilePathSelector;
151 AssertReturnVoid(m_pGAISOFilePathSelector);
152
153 m_pGAISOFilePathSelector->setResetEnabled(false);
154 m_pGAISOFilePathSelector->setMode(UIFilePathSelector::Mode_File_Open);
155 m_pGAISOFilePathSelector->setFileDialogFilters("ISO Images(*.iso *.ISO)");
156 m_pGAISOFilePathSelector->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
157 m_pGAISOFilePathSelector->setInitialPath(uiCommon().defaultFolderPathForType(UIMediumDeviceType_DVD));
158 m_pGAISOFilePathSelector->setRecentMediaListType(UIMediumDeviceType_DVD);
159 if (m_pGAISOPathLabel)
160 m_pGAISOPathLabel->setBuddy(m_pGAISOFilePathSelector);
161
162 pGAInstallationISOLayout->addWidget(m_pGAISOFilePathSelector);
163
164 connect(m_pGAISOFilePathSelector, &UIFilePathSelector::pathChanged,
165 this, &UIGAInstallationGroupBox::sigPathChanged);
166 connect(this, &UIGAInstallationGroupBox::toggled,
167 this, &UIGAInstallationGroupBox::sltToggleWidgetsEnabled);
168 sltRetranslateUI();
169 connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
170 this, &UIGAInstallationGroupBox::sltRetranslateUI);
171}
172
173void UIGAInstallationGroupBox::sltRetranslateUI()
174{
175 if (m_pGAISOFilePathSelector)
176 m_pGAISOFilePathSelector->setToolTip(UIWizardNewVM::tr("Selects an installation medium (ISO file) for the Guest Additions."));
177 if (m_pGAISOPathLabel)
178 m_pGAISOPathLabel->setText(UIWizardNewVM::tr("Guest &Additions ISO:"));
179 setTitle(UIWizardNewVM::tr("Gu&est Additions"));
180 setToolTip(UIWizardNewVM::tr("When checked, the guest additions will be installed after the guest OS install."));
181}
182
183QString UIGAInstallationGroupBox::path() const
184{
185 if (m_pGAISOFilePathSelector)
186 return m_pGAISOFilePathSelector->path();
187 return QString();
188}
189
190void UIGAInstallationGroupBox::setPath(const QString &strPath, bool fRefreshText /* = true */)
191{
192 if (m_pGAISOFilePathSelector)
193 m_pGAISOFilePathSelector->setPath(strPath, fRefreshText);
194}
195
196void UIGAInstallationGroupBox::mark()
197{
198 bool fError = !UIWizardNewVMUnattendedCommon::checkGAISOFile(path());
199 if (m_pGAISOFilePathSelector)
200 m_pGAISOFilePathSelector->mark(fError, UIWizardNewVM::tr("Invalid Guest Additions installation media"));
201}
202
203bool UIGAInstallationGroupBox::isComplete() const
204{
205 if (!isChecked())
206 return true;
207 return UIWizardNewVMUnattendedCommon::checkGAISOFile(path());
208}
209
210void UIGAInstallationGroupBox::sltToggleWidgetsEnabled(bool fEnabled)
211{
212 if (m_pGAISOPathLabel)
213 m_pGAISOPathLabel->setEnabled(fEnabled);
214
215 if (m_pGAISOFilePathSelector)
216 m_pGAISOFilePathSelector->setEnabled(fEnabled);
217}
218
219
220/*********************************************************************************************************************************
221* UIAdditionalUnattendedOptions implementation. *
222*********************************************************************************************************************************/
223
224UIAdditionalUnattendedOptions::UIAdditionalUnattendedOptions(QWidget *pParent /* = 0 */)
225 : QGroupBox(pParent)
226 , m_pProductKeyLabel(0)
227 , m_pProductKeyLineEdit(0)
228 , m_pHostnameDomainNameEditor(0)
229 , m_pStartHeadlessCheckBox(0)
230{
231 prepare();
232}
233
234void UIAdditionalUnattendedOptions::prepare()
235{
236 m_pMainLayout = new QGridLayout(this);
237 m_pMainLayout->setColumnStretch(0, 0);
238 m_pMainLayout->setColumnStretch(1, 1);
239 m_pProductKeyLabel = new QLabel;
240 if (m_pProductKeyLabel)
241 {
242 m_pProductKeyLabel->setAlignment(Qt::AlignRight);
243 m_pProductKeyLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
244 m_pMainLayout->addWidget(m_pProductKeyLabel, 0, 0);
245 }
246 m_pProductKeyLineEdit = new QILineEdit;
247 if (m_pProductKeyLineEdit)
248 {
249 m_pProductKeyLineEdit->setInputMask(">NNNNN-NNNNN-NNNNN-NNNNN-NNNNN;#");
250 if (m_pProductKeyLabel)
251 m_pProductKeyLabel->setBuddy(m_pProductKeyLineEdit);
252 m_pMainLayout->addWidget(m_pProductKeyLineEdit, 0, 1, 1, 2);
253 }
254
255 m_pHostnameDomainNameEditor = new UIHostnameDomainNameEditor;
256 if (m_pHostnameDomainNameEditor)
257 m_pMainLayout->addWidget(m_pHostnameDomainNameEditor, 1, 0, 2, 3);
258
259 m_pStartHeadlessCheckBox = new QCheckBox;
260 if (m_pStartHeadlessCheckBox)
261 m_pMainLayout->addWidget(m_pStartHeadlessCheckBox, 3, 1);
262
263 if (m_pHostnameDomainNameEditor)
264 connect(m_pHostnameDomainNameEditor, &UIHostnameDomainNameEditor::sigHostnameDomainNameChanged,
265 this, &UIAdditionalUnattendedOptions::sigHostnameDomainNameChanged);
266 if (m_pProductKeyLineEdit)
267 connect(m_pProductKeyLineEdit, &QILineEdit::textChanged,
268 this, &UIAdditionalUnattendedOptions::sigProductKeyChanged);
269 if (m_pStartHeadlessCheckBox)
270 connect(m_pStartHeadlessCheckBox, &QCheckBox::toggled,
271 this, &UIAdditionalUnattendedOptions::sigStartHeadlessChanged);
272
273 sltRetranslateUI();
274 connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
275 this, &UIAdditionalUnattendedOptions::sltRetranslateUI);
276}
277
278void UIAdditionalUnattendedOptions::sltRetranslateUI()
279{
280 setTitle(UIWizardNewVM::tr("Additional Options"));
281
282 if (m_pProductKeyLabel)
283 m_pProductKeyLabel->setText(UIWizardNewVM::tr("&Product Key:"));
284
285 if (m_pStartHeadlessCheckBox)
286 {
287 m_pStartHeadlessCheckBox->setText(UIWizardNewVM::tr("&Install in Background"));
288 m_pStartHeadlessCheckBox->setToolTip(UIWizardNewVM::tr("When checked, headless boot (with no GUI) will be enabled for "
289 "unattended guest OS installation of newly created virtual machine."));
290 }
291
292 int iMaxWidth = 0;
293 if (m_pProductKeyLabel)
294 iMaxWidth = qMax(m_pProductKeyLabel->minimumSizeHint().width(), iMaxWidth);
295 if (m_pHostnameDomainNameEditor)
296 iMaxWidth = qMax(m_pHostnameDomainNameEditor->firstColumnWidth(), iMaxWidth);
297 if (iMaxWidth > 0)
298 {
299 m_pMainLayout->setColumnMinimumWidth(0, iMaxWidth);
300 m_pHostnameDomainNameEditor->setFirstColumnWidth(iMaxWidth);
301 }
302 if (m_pProductKeyLineEdit)
303 m_pProductKeyLineEdit->setToolTip(UIWizardNewVM::tr("Holds the product key."));
304}
305
306QString UIAdditionalUnattendedOptions::hostname() const
307{
308 if (m_pHostnameDomainNameEditor)
309 return m_pHostnameDomainNameEditor->hostname();
310 return QString();
311}
312
313void UIAdditionalUnattendedOptions::setHostname(const QString &strHostname)
314{
315 if (m_pHostnameDomainNameEditor)
316 return m_pHostnameDomainNameEditor->setHostname(strHostname);
317}
318
319QString UIAdditionalUnattendedOptions::domainName() const
320{
321 if (m_pHostnameDomainNameEditor)
322 return m_pHostnameDomainNameEditor->domainName();
323 return QString();
324}
325
326void UIAdditionalUnattendedOptions::setDomainName(const QString &strDomainName)
327{
328 if (m_pHostnameDomainNameEditor)
329 return m_pHostnameDomainNameEditor->setDomainName(strDomainName);
330}
331
332QString UIAdditionalUnattendedOptions::hostnameDomainName() const
333{
334 if (m_pHostnameDomainNameEditor)
335 return m_pHostnameDomainNameEditor->hostnameDomainName();
336 return QString();
337}
338
339bool UIAdditionalUnattendedOptions::isComplete() const
340{
341 return isHostnameComplete();
342}
343
344bool UIAdditionalUnattendedOptions::isHostnameComplete() const
345{
346 if (m_pHostnameDomainNameEditor)
347 return m_pHostnameDomainNameEditor->isComplete();
348 return false;
349}
350
351
352void UIAdditionalUnattendedOptions::mark()
353{
354 if (m_pHostnameDomainNameEditor)
355 m_pHostnameDomainNameEditor->mark();
356}
357
358void UIAdditionalUnattendedOptions::disableEnableProductKeyWidgets(bool fEnabled)
359{
360 if (m_pProductKeyLabel)
361 m_pProductKeyLabel->setEnabled(fEnabled);
362 if (m_pProductKeyLineEdit)
363 m_pProductKeyLineEdit->setEnabled(fEnabled);
364}
365
366/*********************************************************************************************************************************
367* UINewVMHardwareContainer implementation. *
368*********************************************************************************************************************************/
369
370UINewVMHardwareContainer::UINewVMHardwareContainer(QWidget *pParent /* = 0 */)
371 : QWidget(pParent)
372 , m_pBaseMemoryEditor(0)
373 , m_pVirtualCPUEditor(0)
374 , m_pEFICheckBox(0)
375{
376 prepare();
377}
378
379void UINewVMHardwareContainer::setMemorySize(int iSize)
380{
381 if (m_pBaseMemoryEditor)
382 m_pBaseMemoryEditor->setValue(iSize);
383}
384
385void UINewVMHardwareContainer::setCPUCount(int iCount)
386{
387 if (m_pVirtualCPUEditor)
388 m_pVirtualCPUEditor->setValue(iCount);
389}
390
391void UINewVMHardwareContainer::setEFIEnabled(bool fEnabled)
392{
393 if (m_pEFICheckBox)
394 m_pEFICheckBox->setChecked(fEnabled);
395}
396
397void UINewVMHardwareContainer::prepare()
398{
399 QGridLayout *pHardwareLayout = new QGridLayout(this);
400 pHardwareLayout->setContentsMargins(0, 0, 0, 0);
401
402 m_pBaseMemoryEditor = new UIBaseMemoryEditor;
403 m_pVirtualCPUEditor = new UIVirtualCPUEditor;
404 m_pEFICheckBox = new QCheckBox;
405 pHardwareLayout->addWidget(m_pBaseMemoryEditor, 0, 0, 1, 4);
406 pHardwareLayout->addWidget(m_pVirtualCPUEditor, 1, 0, 1, 4);
407 pHardwareLayout->addWidget(m_pEFICheckBox, 2, 0, 1, 1);
408
409
410 if (m_pBaseMemoryEditor)
411 connect(m_pBaseMemoryEditor, &UIBaseMemoryEditor::sigValueChanged,
412 this, &UINewVMHardwareContainer::sigMemorySizeChanged);
413 if (m_pVirtualCPUEditor)
414 connect(m_pVirtualCPUEditor, &UIVirtualCPUEditor::sigValueChanged,
415 this, &UINewVMHardwareContainer::sigCPUCountChanged);
416 if (m_pEFICheckBox)
417 connect(m_pEFICheckBox, &QCheckBox::toggled,
418 this, &UINewVMHardwareContainer::sigEFIEnabledChanged);
419
420 sltRetranslateUI();
421 connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
422 this, &UINewVMHardwareContainer::sltRetranslateUI);
423}
424
425void UINewVMHardwareContainer::sltRetranslateUI()
426{
427 if (m_pEFICheckBox)
428 {
429 m_pEFICheckBox->setText(UIWizardNewVM::tr("&Enable EFI (special OSes only)"));
430 m_pEFICheckBox->setToolTip(UIWizardNewVM::tr("When checked, the guest will support the Extended Firmware Interface (EFI), "
431 "which is required to boot certain guest OSes. Non-EFI aware OSes will not "
432 "be able to boot if this option is activated."));
433 }
434}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use