VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageBasic1.cpp@ 85081

Last change on this file since 85081 was 85081, checked in by vboxsync, 5 years ago

FE/Qt: bugref:9515. First go at the expert mode page.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 28.8 KB
Line 
1/* $Id: UIWizardNewVMPageBasic1.cpp 85081 2020-07-07 12:03:00Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIWizardNewVMPageBasic1 class implementation.
4 */
5
6/*
7 * Copyright (C) 2006-2020 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/* Qt includes: */
19#include <QButtonGroup>
20#include <QCheckBox>
21#include <QDir>
22#include <QGridLayout>
23#include <QHBoxLayout>
24#include <QLabel>
25#include <QRadioButton>
26#include <QVBoxLayout>
27
28/* GUI includes: */
29#include "QIRichTextLabel.h"
30#include "UICommon.h"
31#include "UIFilePathSelector.h"
32#include "UIMessageCenter.h"
33#include "UINameAndSystemEditor.h"
34#include "UIWizardNewVMPageBasic1.h"
35#include "UIWizardNewVM.h"
36
37/* COM includes: */
38#include "CHost.h"
39#include "CSystemProperties.h"
40#include "CUnattended.h"
41
42/* Defines some patterns to guess the right OS type. Should be in sync with
43 * VirtualBox-settings-common.xsd in Main. The list is sorted by priority. The
44 * first matching string found, will be used. */
45struct osTypePattern
46{
47 QRegExp pattern;
48 const char *pcstId;
49};
50
51static const osTypePattern gs_OSTypePattern[] =
52{
53 /* DOS: */
54 { QRegExp("DOS", Qt::CaseInsensitive), "DOS" },
55
56 /* Windows: */
57 { QRegExp( "Wi.*98", Qt::CaseInsensitive), "Windows98" },
58 { QRegExp( "Wi.*95", Qt::CaseInsensitive), "Windows95" },
59 { QRegExp( "Wi.*Me", Qt::CaseInsensitive), "WindowsMe" },
60 { QRegExp( "(Wi.*NT)|(NT[-._v]*4)", Qt::CaseInsensitive), "WindowsNT4" },
61 { QRegExp( "NT[-._v]*3[.,]*[51x]", Qt::CaseInsensitive), "WindowsNT3x" },
62 /* Note: Do not automatically set WindowsXP_64 on 64-bit hosts, as Windows XP 64-bit
63 * is extremely rare -- most users never heard of it even. So always default to 32-bit. */
64 { QRegExp("((Wi.*XP)|(XP)).*", Qt::CaseInsensitive), "WindowsXP" },
65 { QRegExp("((Wi.*2003)|(W2K3)|(Win2K3)).*64", Qt::CaseInsensitive), "Windows2003_64" },
66 { QRegExp("((Wi.*2003)|(W2K3)|(Win2K3)).*32", Qt::CaseInsensitive), "Windows2003" },
67 { QRegExp("((Wi.*Vis)|(Vista)).*64", Qt::CaseInsensitive), "WindowsVista_64" },
68 { QRegExp("((Wi.*Vis)|(Vista)).*32", Qt::CaseInsensitive), "WindowsVista" },
69 { QRegExp( "(Wi.*2016)|(W2K16)|(Win2K16)", Qt::CaseInsensitive), "Windows2016_64" },
70 { QRegExp( "(Wi.*2012)|(W2K12)|(Win2K12)", Qt::CaseInsensitive), "Windows2012_64" },
71 { QRegExp("((Wi.*2008)|(W2K8)|(Win2k8)).*64", Qt::CaseInsensitive), "Windows2008_64" },
72 { QRegExp("((Wi.*2008)|(W2K8)|(Win2K8)).*32", Qt::CaseInsensitive), "Windows2008" },
73 { QRegExp( "(Wi.*2000)|(W2K)|(Win2K)", Qt::CaseInsensitive), "Windows2000" },
74 { QRegExp( "(Wi.*7.*64)|(W7.*64)", Qt::CaseInsensitive), "Windows7_64" },
75 { QRegExp( "(Wi.*7.*32)|(W7.*32)", Qt::CaseInsensitive), "Windows7" },
76 { QRegExp( "(Wi.*8.*1.*64)|(W8.*64)", Qt::CaseInsensitive), "Windows81_64" },
77 { QRegExp( "(Wi.*8.*1.*32)|(W8.*32)", Qt::CaseInsensitive), "Windows81" },
78 { QRegExp( "(Wi.*8.*64)|(W8.*64)", Qt::CaseInsensitive), "Windows8_64" },
79 { QRegExp( "(Wi.*8.*32)|(W8.*32)", Qt::CaseInsensitive), "Windows8" },
80 { QRegExp( "(Wi.*10.*64)|(W10.*64)", Qt::CaseInsensitive), "Windows10_64" },
81 { QRegExp( "(Wi.*10.*32)|(W10.*32)", Qt::CaseInsensitive), "Windows10" },
82 { QRegExp( "Wi.*3.*1", Qt::CaseInsensitive), "Windows31" },
83 /* Set Windows 7 as default for "Windows". */
84 { QRegExp( "Wi.*64", Qt::CaseInsensitive), "Windows7_64" },
85 { QRegExp( "Wi.*32", Qt::CaseInsensitive), "Windows7" },
86 /* ReactOS wants to be considered as Windows 2003 */
87 { QRegExp( "Reac.*", Qt::CaseInsensitive), "Windows2003" },
88
89 /* Solaris: */
90 { QRegExp("Sol.*11", Qt::CaseInsensitive), "Solaris11_64" },
91 { QRegExp("((Op.*Sol)|(os20[01][0-9])|(Sol.*10)|(India)|(Neva)).*64", Qt::CaseInsensitive), "OpenSolaris_64" },
92 { QRegExp("((Op.*Sol)|(os20[01][0-9])|(Sol.*10)|(India)|(Neva)).*32", Qt::CaseInsensitive), "OpenSolaris" },
93 { QRegExp("Sol.*64", Qt::CaseInsensitive), "Solaris_64" },
94 { QRegExp("Sol.*32", Qt::CaseInsensitive), "Solaris" },
95
96 /* OS/2: */
97 { QRegExp( "OS[/|!-]{,1}2.*W.*4.?5", Qt::CaseInsensitive), "OS2Warp45" },
98 { QRegExp( "OS[/|!-]{,1}2.*W.*4", Qt::CaseInsensitive), "OS2Warp4" },
99 { QRegExp( "OS[/|!-]{,1}2.*W", Qt::CaseInsensitive), "OS2Warp3" },
100 { QRegExp("(OS[/|!-]{,1}2.*e)|(eCS.*)", Qt::CaseInsensitive), "OS2eCS" },
101 { QRegExp( "OS[/|!-]{,1}2", Qt::CaseInsensitive), "OS2" },
102 { QRegExp( "eComS.*", Qt::CaseInsensitive), "OS2eCS" },
103
104 /* Other: Must come before Ubuntu/Maverick and before Linux??? */
105 { QRegExp("QN", Qt::CaseInsensitive), "QNX" },
106
107 /* Mac OS X: Must come before Ubuntu/Maverick and before Linux: */
108 { QRegExp("((mac.*10[.,]{0,1}4)|(os.*x.*10[.,]{0,1}4)|(mac.*ti)|(os.*x.*ti)|(Tig)).64", Qt::CaseInsensitive), "MacOS_64" },
109 { QRegExp("((mac.*10[.,]{0,1}4)|(os.*x.*10[.,]{0,1}4)|(mac.*ti)|(os.*x.*ti)|(Tig)).32", Qt::CaseInsensitive), "MacOS" },
110 { QRegExp("((mac.*10[.,]{0,1}5)|(os.*x.*10[.,]{0,1}5)|(mac.*leo)|(os.*x.*leo)|(Leop)).*64", Qt::CaseInsensitive), "MacOS_64" },
111 { QRegExp("((mac.*10[.,]{0,1}5)|(os.*x.*10[.,]{0,1}5)|(mac.*leo)|(os.*x.*leo)|(Leop)).*32", Qt::CaseInsensitive), "MacOS" },
112 { QRegExp("((mac.*10[.,]{0,1}6)|(os.*x.*10[.,]{0,1}6)|(mac.*SL)|(os.*x.*SL)|(Snow L)).*64", Qt::CaseInsensitive), "MacOS106_64" },
113 { QRegExp("((mac.*10[.,]{0,1}6)|(os.*x.*10[.,]{0,1}6)|(mac.*SL)|(os.*x.*SL)|(Snow L)).*32", Qt::CaseInsensitive), "MacOS106" },
114 { QRegExp( "(mac.*10[.,]{0,1}7)|(os.*x.*10[.,]{0,1}7)|(mac.*ML)|(os.*x.*ML)|(Mount)", Qt::CaseInsensitive), "MacOS108_64" },
115 { QRegExp( "(mac.*10[.,]{0,1}8)|(os.*x.*10[.,]{0,1}8)|(Lion)", Qt::CaseInsensitive), "MacOS107_64" },
116 { QRegExp( "(mac.*10[.,]{0,1}9)|(os.*x.*10[.,]{0,1}9)|(mac.*mav)|(os.*x.*mav)|(Mavericks)", Qt::CaseInsensitive), "MacOS109_64" },
117 { QRegExp( "(mac.*yos)|(os.*x.*yos)|(Yosemite)", Qt::CaseInsensitive), "MacOS1010_64" },
118 { QRegExp( "(mac.*cap)|(os.*x.*capit)|(Capitan)", Qt::CaseInsensitive), "MacOS1011_64" },
119 { QRegExp( "(mac.*hig)|(os.*x.*high.*sierr)|(High Sierra)", Qt::CaseInsensitive), "MacOS1013_64" },
120 { QRegExp( "(mac.*sie)|(os.*x.*sierr)|(Sierra)", Qt::CaseInsensitive), "MacOS1012_64" },
121 { QRegExp("((Mac)|(Tig)|(Leop)|(Yose)|(os[ ]*x)).*64", Qt::CaseInsensitive), "MacOS_64" },
122 { QRegExp("((Mac)|(Tig)|(Leop)|(Yose)|(os[ ]*x)).*32", Qt::CaseInsensitive), "MacOS" },
123
124 /* Code names for Linux distributions: */
125 { QRegExp("((bianca)|(cassandra)|(celena)|(daryna)|(elyssa)|(felicia)|(gloria)|(helena)|(isadora)|(julia)|(katya)|(lisa)|(maya)|(nadia)|(olivia)|(petra)|(qiana)|(rebecca)|(rafaela)|(rosa)).*64", Qt::CaseInsensitive), "Ubuntu_64" },
126 { QRegExp("((bianca)|(cassandra)|(celena)|(daryna)|(elyssa)|(felicia)|(gloria)|(helena)|(isadora)|(julia)|(katya)|(lisa)|(maya)|(nadia)|(olivia)|(petra)|(qiana)|(rebecca)|(rafaela)|(rosa)).*32", Qt::CaseInsensitive), "Ubuntu" },
127 { QRegExp("((edgy)|(feisty)|(gutsy)|(hardy)|(intrepid)|(jaunty)|(karmic)|(lucid)|(maverick)|(natty)|(oneiric)|(precise)|(quantal)|(raring)|(saucy)|(trusty)|(utopic)|(vivid)|(wily)|(xenial)|(yakkety)|(zesty)).*64", Qt::CaseInsensitive), "Ubuntu_64" },
128 { QRegExp("((edgy)|(feisty)|(gutsy)|(hardy)|(intrepid)|(jaunty)|(karmic)|(lucid)|(maverick)|(natty)|(oneiric)|(precise)|(quantal)|(raring)|(saucy)|(trusty)|(utopic)|(vivid)|(wily)|(xenial)|(yakkety)|(zesty)).*32", Qt::CaseInsensitive), "Ubuntu" },
129 { QRegExp("((sarge)|(etch)|(lenny)|(squeeze)|(wheezy)|(jessie)|(stretch)|(buster)|(sid)).*64", Qt::CaseInsensitive), "Debian_64" },
130 { QRegExp("((sarge)|(etch)|(lenny)|(squeeze)|(wheezy)|(jessie)|(stretch)|(buster)|(sid)).*32", Qt::CaseInsensitive), "Debian" },
131 { QRegExp("((moonshine)|(werewolf)|(sulphur)|(cambridge)|(leonidas)|(constantine)|(goddard)|(laughlin)|(lovelock)|(verne)|(beefy)|(spherical)).*64", Qt::CaseInsensitive), "Fedora_64" },
132 { QRegExp("((moonshine)|(werewolf)|(sulphur)|(cambridge)|(leonidas)|(constantine)|(goddard)|(laughlin)|(lovelock)|(verne)|(beefy)|(spherical)).*32", Qt::CaseInsensitive), "Fedora" },
133
134 /* Regular names of Linux distributions: */
135 { QRegExp("Arc.*64", Qt::CaseInsensitive), "ArchLinux_64" },
136 { QRegExp("Arc.*32", Qt::CaseInsensitive), "ArchLinux" },
137 { QRegExp("Deb.*64", Qt::CaseInsensitive), "Debian_64" },
138 { QRegExp("Deb.*32", Qt::CaseInsensitive), "Debian" },
139 { QRegExp("((SU)|(Nov)|(SLE)).*64", Qt::CaseInsensitive), "OpenSUSE_64" },
140 { QRegExp("((SU)|(Nov)|(SLE)).*32", Qt::CaseInsensitive), "OpenSUSE" },
141 { QRegExp("Fe.*64", Qt::CaseInsensitive), "Fedora_64" },
142 { QRegExp("Fe.*32", Qt::CaseInsensitive), "Fedora" },
143 { QRegExp("((Gen)|(Sab)).*64", Qt::CaseInsensitive), "Gentoo_64" },
144 { QRegExp("((Gen)|(Sab)).*32", Qt::CaseInsensitive), "Gentoo" },
145 { QRegExp("((Man)|(Mag)).*64", Qt::CaseInsensitive), "Mandriva_64" },
146 { QRegExp("((Man)|(Mag)).*32", Qt::CaseInsensitive), "Mandriva" },
147 { QRegExp("((Red)|(rhel)|(cen)).*64", Qt::CaseInsensitive), "RedHat_64" },
148 { QRegExp("((Red)|(rhel)|(cen)).*32", Qt::CaseInsensitive), "RedHat" },
149 { QRegExp("Tur.*64", Qt::CaseInsensitive), "Turbolinux_64" },
150 { QRegExp("Tur.*32", Qt::CaseInsensitive), "Turbolinux" },
151 { QRegExp("(Ub)|(Min).*64", Qt::CaseInsensitive), "Ubuntu_64" },
152 { QRegExp("(Ub)|(Min).*32", Qt::CaseInsensitive), "Ubuntu" },
153 { QRegExp("Xa.*64", Qt::CaseInsensitive), "Xandros_64" },
154 { QRegExp("Xa.*32", Qt::CaseInsensitive), "Xandros" },
155 { QRegExp("((Or)|(oel)|(ol)).*64", Qt::CaseInsensitive), "Oracle_64" },
156 { QRegExp("((Or)|(oel)|(ol)).*32", Qt::CaseInsensitive), "Oracle" },
157 { QRegExp("Knoppix", Qt::CaseInsensitive), "Linux26" },
158 { QRegExp("Dsl", Qt::CaseInsensitive), "Linux24" },
159 { QRegExp("((Lin)|(lnx)).*2.?2", Qt::CaseInsensitive), "Linux22" },
160 { QRegExp("((Lin)|(lnx)).*2.?4.*64", Qt::CaseInsensitive), "Linux24_64" },
161 { QRegExp("((Lin)|(lnx)).*2.?4.*32", Qt::CaseInsensitive), "Linux24" },
162 { QRegExp("((((Lin)|(lnx)).*2.?6)|(LFS)).*64", Qt::CaseInsensitive), "Linux26_64" },
163 { QRegExp("((((Lin)|(lnx)).*2.?6)|(LFS)).*32", Qt::CaseInsensitive), "Linux26" },
164 { QRegExp("((Lin)|(lnx)).*64", Qt::CaseInsensitive), "Linux26_64" },
165 { QRegExp("((Lin)|(lnx)).*32", Qt::CaseInsensitive), "Linux26" },
166
167 /* Other: */
168 { QRegExp("L4", Qt::CaseInsensitive), "L4" },
169 { QRegExp("((Fr.*B)|(fbsd)).*64", Qt::CaseInsensitive), "FreeBSD_64" },
170 { QRegExp("((Fr.*B)|(fbsd)).*32", Qt::CaseInsensitive), "FreeBSD" },
171 { QRegExp("Op.*B.*64", Qt::CaseInsensitive), "OpenBSD_64" },
172 { QRegExp("Op.*B.*32", Qt::CaseInsensitive), "OpenBSD" },
173 { QRegExp("Ne.*B.*64", Qt::CaseInsensitive), "NetBSD_64" },
174 { QRegExp("Ne.*B.*32", Qt::CaseInsensitive), "NetBSD" },
175 { QRegExp("Net", Qt::CaseInsensitive), "Netware" },
176 { QRegExp("Rocki", Qt::CaseInsensitive), "JRockitVE" },
177 { QRegExp("bs[23]{0,1}-", Qt::CaseInsensitive), "VBoxBS_64" }, /* bootsector tests */
178 { QRegExp("Ot", Qt::CaseInsensitive), "Other" },
179};
180
181UIWizardNewVMPage1::UIWizardNewVMPage1(const QString &strGroup)
182 : m_pButtonSimple(0)
183 , m_pButtonUnattended(0)
184 , m_pISOSelectorLabel(0)
185 , m_pISOFilePathSelector(0)
186 , m_pStartHeadlessLabel(0)
187 , m_pStartHeadlessCheckBox(0)
188 , m_pNameAndSystemEditor(0)
189 , m_strGroup(strGroup)
190{
191 CHost host = uiCommon().host();
192 m_fSupportsHWVirtEx = host.GetProcessorFeature(KProcessorFeature_HWVirtEx);
193 m_fSupportsLongMode = host.GetProcessorFeature(KProcessorFeature_LongMode);
194}
195
196void UIWizardNewVMPage1::onNameChanged(QString strNewName)
197{
198 /* Do not forget about achitecture bits, if not yet specified: */
199 if (!strNewName.contains("32") && !strNewName.contains("64"))
200 strNewName += ARCH_BITS == 64 && m_fSupportsHWVirtEx && m_fSupportsLongMode ? "64" : "32";
201
202 /* Search for a matching OS type based on the string the user typed already. */
203 for (size_t i = 0; i < RT_ELEMENTS(gs_OSTypePattern); ++i)
204 if (strNewName.contains(gs_OSTypePattern[i].pattern))
205 {
206 if (m_pNameAndSystemEditor)
207 {
208 m_pNameAndSystemEditor->blockSignals(true);
209 m_pNameAndSystemEditor->setType(uiCommon().vmGuestOSType(gs_OSTypePattern[i].pcstId));
210 m_pNameAndSystemEditor->blockSignals(false);
211 }
212 break;
213 }
214}
215
216void UIWizardNewVMPage1::onOsTypeChanged()
217{
218 /* If the user manually edited the OS type, we didn't want our automatic OS type guessing anymore.
219 * So simply disconnect the text-edit signal. */
220 if (m_pNameAndSystemEditor)
221 m_pNameAndSystemEditor->disconnect(SIGNAL(sigNameChanged(const QString &)), thisImp(), SLOT(sltNameChanged(const QString &)));
222}
223
224bool UIWizardNewVMPage1::determineOSType(const QString &strISOPath)
225{
226 QFileInfo isoFileInfo(strISOPath);
227 if (!isoFileInfo.exists())
228 {
229 m_strDetectedOSTypeId.clear();
230 // m_strDetectedOSVersion.clear();
231 // m_strDetectedOSFlavor.clear();
232 // m_strDetectedOSLanguages.clear();
233 // m_strDetectedOSHints.clear();
234 // updateStatusLabel();
235 return false;
236 }
237
238 CUnattended comUnatteded = uiCommon().virtualBox().CreateUnattendedInstaller();
239 comUnatteded.SetIsoPath(strISOPath);
240 comUnatteded.DetectIsoOS();
241
242 m_strDetectedOSTypeId = comUnatteded.GetDetectedOSTypeId();
243 // m_strDetectedOSVersion = comUnatteded.GetDetectedOSVersion();
244 // m_strDetectedOSFlavor = comUnatteded.GetDetectedOSFlavor();
245 // m_strDetectedOSLanguages = comUnatteded.GetDetectedOSLanguages();
246 // m_strDetectedOSHints = comUnatteded.GetDetectedOSHints();
247
248 //updateStatusLabel();
249 return true;
250}
251
252void UIWizardNewVMPage1::composeMachineFilePath()
253{
254 if (!m_pNameAndSystemEditor)
255 return;
256 if (m_pNameAndSystemEditor->name().isEmpty() || m_pNameAndSystemEditor->path().isEmpty())
257 return;
258 /* Get VBox: */
259 CVirtualBox vbox = uiCommon().virtualBox();
260
261 /* Compose machine filename: */
262 m_strMachineFilePath = vbox.ComposeMachineFilename(m_pNameAndSystemEditor->name(),
263 m_strGroup,
264 QString(),
265 m_pNameAndSystemEditor->path());
266 /* Compose machine folder/basename: */
267 const QFileInfo fileInfo(m_strMachineFilePath);
268 m_strMachineFolder = fileInfo.absolutePath();
269 m_strMachineBaseName = fileInfo.completeBaseName();
270}
271
272bool UIWizardNewVMPage1::checkISOFile() const
273{
274 if (m_pButtonUnattended && m_pButtonUnattended->isChecked())
275 {
276 QString strISOFilePath = m_pISOFilePathSelector ? m_pISOFilePathSelector->path() : QString();
277 if (!QFileInfo(strISOFilePath).exists())
278 return false;
279 }
280 return true;
281}
282
283void UIWizardNewVMPage1::createWidgets(QGridLayout *pGridLayout)
284{
285 if (pGridLayout)
286 {
287 m_pLabel1 = new QIRichTextLabel;
288 if (m_pLabel1)
289 pGridLayout->addWidget(m_pLabel1, 0, 0, 1, 3);
290
291 m_pButtonGroup = new QButtonGroup;
292 if (m_pButtonGroup)
293 {
294 m_pButtonSimple = new QRadioButton;
295 if (m_pButtonSimple)
296 {
297 m_pButtonSimple->setChecked(true);
298 pGridLayout->addWidget(m_pButtonSimple, 1, 0, 1, 3);
299 }
300 m_pButtonUnattended = new QRadioButton;
301 if (m_pButtonUnattended)
302 {
303 QStyleOptionButton options;
304 options.initFrom(m_pButtonUnattended);
305 const int iWidth = m_pButtonUnattended->style()->pixelMetric(QStyle::PM_ExclusiveIndicatorWidth,
306 &options, m_pButtonUnattended);
307 pGridLayout->setColumnMinimumWidth(0, iWidth);
308 pGridLayout->addWidget(m_pButtonUnattended, 2, 0, 1, 3);
309 }
310
311 m_pButtonGroup->addButton(m_pButtonSimple);
312 m_pButtonGroup->addButton(m_pButtonUnattended);
313 }
314
315 m_pISOSelectorLabel = new QLabel;
316 if (m_pISOSelectorLabel)
317 {
318 m_pISOSelectorLabel->setAlignment(Qt::AlignRight);
319 m_pISOSelectorLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
320 m_pISOSelectorLabel->setEnabled(false);
321 pGridLayout->addWidget(m_pISOSelectorLabel, 3, 1);
322 }
323 m_pISOFilePathSelector = new UIFilePathSelector;
324 if (m_pISOFilePathSelector)
325 {
326 m_pISOFilePathSelector->setResetEnabled(false);
327 m_pISOFilePathSelector->setMode(UIFilePathSelector::Mode_File_Open);
328 m_pISOFilePathSelector->setFileDialogFilters("*.iso *.ISO");
329 m_pISOFilePathSelector->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
330 m_pISOFilePathSelector->setEnabled(false);
331 pGridLayout->addWidget(m_pISOFilePathSelector, 3, 2);
332 }
333
334 m_pStartHeadlessLabel = new QLabel;
335 if (m_pStartHeadlessLabel)
336 {
337 m_pStartHeadlessLabel->setAlignment(Qt::AlignRight);
338 m_pStartHeadlessLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
339 m_pStartHeadlessLabel->setEnabled(false);
340 pGridLayout->addWidget(m_pStartHeadlessLabel, 4, 1);
341 }
342 m_pStartHeadlessCheckBox = new QCheckBox;
343 if (m_pStartHeadlessCheckBox)
344 {
345 m_pStartHeadlessCheckBox->setEnabled(false);
346 pGridLayout->addWidget(m_pStartHeadlessCheckBox, 4, 2);
347 }
348
349 m_pLabel2 = new QIRichTextLabel;
350 if (m_pLabel2)
351 pGridLayout->addWidget(m_pLabel2, 5, 0, 1, 3);
352
353 m_pNameAndSystemEditor = new UINameAndSystemEditor(0, true, true, true);
354 if (m_pNameAndSystemEditor)
355 {
356 pGridLayout->addWidget(m_pNameAndSystemEditor, 6, 1, 1, 2);
357 }
358 }
359}
360
361bool UIWizardNewVMPage1::createMachineFolder()
362{
363 if (!m_pNameAndSystemEditor)
364 return false;
365 /* Cleanup previosly created folder if any: */
366 if (!cleanupMachineFolder())
367 {
368 msgCenter().cannotRemoveMachineFolder(m_strMachineFolder, thisImp());
369 return false;
370 }
371
372 composeMachineFilePath();
373
374 /* Check if the folder already exists and check if it has been created by this wizard */
375 if (QDir(m_strMachineFolder).exists())
376 {
377 /* Looks like we have already created this folder for this run of the wizard. Just return */
378 if (m_strCreatedFolder == m_strMachineFolder)
379 return true;
380 /* The folder is there but not because of this wizard. Avoid overwriting a existing machine's folder */
381 else
382 {
383 msgCenter().cannotRewriteMachineFolder(m_strMachineFolder, thisImp());
384 return false;
385 }
386 }
387
388 /* Try to create new folder (and it's predecessors): */
389 bool fMachineFolderCreated = QDir().mkpath(m_strMachineFolder);
390 if (!fMachineFolderCreated)
391 {
392 msgCenter().cannotCreateMachineFolder(m_strMachineFolder, thisImp());
393 return false;
394 }
395 m_strCreatedFolder = m_strMachineFolder;
396 return true;
397}
398
399bool UIWizardNewVMPage1::cleanupMachineFolder(bool fWizardCancel /* = false */)
400{
401 /* Make sure folder was previosly created: */
402 if (m_strCreatedFolder.isEmpty())
403 return true;
404 /* Clean this folder if the machine folder has been changed by the user or we are cancelling the wizard: */
405 if (m_strCreatedFolder != m_strMachineFolder || fWizardCancel)
406 {
407 /* Try to cleanup folder (and it's predecessors): */
408 bool fMachineFolderRemoved = QDir().rmpath(m_strCreatedFolder);
409 /* Reset machine folder value: */
410 if (fMachineFolderRemoved)
411 m_strCreatedFolder = QString();
412 /* Return cleanup result: */
413 return fMachineFolderRemoved;
414 }
415 return true;
416}
417
418QString UIWizardNewVMPage1::machineFilePath() const
419{
420 return m_strMachineFilePath;
421}
422
423void UIWizardNewVMPage1::setMachineFilePath(const QString &strMachineFilePath)
424{
425 m_strMachineFilePath = strMachineFilePath;
426}
427
428QString UIWizardNewVMPage1::machineFolder() const
429{
430 return m_strMachineFolder;
431}
432
433void UIWizardNewVMPage1::setMachineFolder(const QString &strMachineFolder)
434{
435 m_strMachineFolder = strMachineFolder;
436}
437
438QString UIWizardNewVMPage1::machineBaseName() const
439{
440 return m_strMachineBaseName;
441}
442
443void UIWizardNewVMPage1::setMachineBaseName(const QString &strMachineBaseName)
444{
445 m_strMachineBaseName = strMachineBaseName;
446}
447
448QString UIWizardNewVMPage1::guestOSFamiyId() const
449{
450 if (!m_pNameAndSystemEditor)
451 return QString();
452 return m_pNameAndSystemEditor->familyId();
453}
454
455QString UIWizardNewVMPage1::ISOFilePath() const
456{
457 if (!m_pISOFilePathSelector)
458 return QString();
459 return m_pISOFilePathSelector->path();
460}
461
462bool UIWizardNewVMPage1::isUnattendedEnabled() const
463{
464 if (!m_pButtonUnattended)
465 return false;
466 return m_pButtonUnattended->isChecked();
467}
468
469bool UIWizardNewVMPage1::startHeadless() const
470{
471 if (!m_pStartHeadlessCheckBox)
472 return false;
473 return m_pStartHeadlessCheckBox->isChecked();
474}
475
476const QString &UIWizardNewVMPage1::detectedOSTypeId() const
477{
478 return m_strDetectedOSTypeId;
479}
480
481UIWizardNewVMPageBasic1::UIWizardNewVMPageBasic1(const QString &strGroup)
482 : UIWizardNewVMPage1(strGroup)
483{
484 prepare();
485}
486
487void UIWizardNewVMPageBasic1::prepare()
488{
489 QGridLayout *pMainLayout = new QGridLayout(this);;
490 createWidgets(pMainLayout);
491 createConnections();
492 /* Register fields: */
493 registerField("name*", m_pNameAndSystemEditor, "name", SIGNAL(sigNameChanged(const QString &)));
494 registerField("type", m_pNameAndSystemEditor, "type", SIGNAL(sigOsTypeChanged()));
495 registerField("machineFilePath", this, "machineFilePath");
496 registerField("machineFolder", this, "machineFolder");
497 registerField("machineBaseName", this, "machineBaseName");
498 registerField("guestOSFamiyId", this, "guestOSFamiyId");
499 registerField("ISOFilePath", this, "ISOFilePath");
500 registerField("isUnattendedEnabled", this, "isUnattendedEnabled");
501 registerField("startHeadless", this, "startHeadless");
502 registerField("detectedOSTypeId", this, "detectedOSTypeId");
503}
504
505void UIWizardNewVMPageBasic1::createConnections()
506{
507 connect(m_pButtonGroup, static_cast<void(QButtonGroup::*)(QAbstractButton*)>(&QButtonGroup::buttonClicked),
508 this, &UIWizardNewVMPageBasic1::sltUnattendedCheckBoxToggle);
509 connect(m_pISOFilePathSelector, &UIFilePathSelector::pathChanged, this, &UIWizardNewVMPageBasic1::sltISOPathChanged);
510 connect(m_pNameAndSystemEditor, &UINameAndSystemEditor::sigNameChanged, this, &UIWizardNewVMPageBasic1::sltNameChanged);
511 connect(m_pNameAndSystemEditor, &UINameAndSystemEditor::sigPathChanged, this, &UIWizardNewVMPageBasic1::sltPathChanged);
512 connect(m_pNameAndSystemEditor, &UINameAndSystemEditor::sigOsTypeChanged, this, &UIWizardNewVMPageBasic1::sltOsTypeChanged);
513}
514
515int UIWizardNewVMPageBasic1::nextId() const
516{
517 UIWizardNewVM *pWizard = qobject_cast<UIWizardNewVM*>(wizard());
518 if (!pWizard || !pWizard->isUnattendedInstallEnabled())
519 return UIWizardNewVM::Page3;
520 return UIWizardNewVM::Page2;
521}
522
523void UIWizardNewVMPageBasic1::setTypeByISODetectedOSType(const QString &strDetectedOSType)
524{
525 if (!strDetectedOSType.isEmpty())
526 onNameChanged(strDetectedOSType);
527}
528
529bool UIWizardNewVMPageBasic1::isComplete() const
530{
531 if (m_pNameAndSystemEditor->name().isEmpty())
532 return false;
533 return checkISOFile();
534}
535
536void UIWizardNewVMPageBasic1::sltNameChanged(const QString &strNewName)
537{
538 onNameChanged(strNewName);
539 composeMachineFilePath();
540}
541
542void UIWizardNewVMPageBasic1::sltPathChanged(const QString &strNewPath)
543{
544 Q_UNUSED(strNewPath);
545 composeMachineFilePath();
546}
547
548void UIWizardNewVMPageBasic1::sltOsTypeChanged()
549{
550 /* Call to base-class: */
551 onOsTypeChanged();
552}
553
554void UIWizardNewVMPageBasic1::sltISOPathChanged(const QString &strPath)
555{
556 determineOSType(strPath);
557 setTypeByISODetectedOSType(m_strDetectedOSTypeId);
558 emit completeChanged();
559}
560
561void UIWizardNewVMPageBasic1::sltUnattendedCheckBoxToggle()
562{
563 const bool fEnabled = m_pButtonUnattended->isChecked();
564 if (m_pISOSelectorLabel)
565 m_pISOSelectorLabel->setEnabled(fEnabled);
566 if (m_pISOFilePathSelector)
567 m_pISOFilePathSelector->setEnabled(fEnabled);
568 if (m_pStartHeadlessLabel)
569 m_pStartHeadlessLabel->setEnabled(fEnabled);
570 if (m_pStartHeadlessCheckBox)
571 m_pStartHeadlessCheckBox->setEnabled(fEnabled);
572 // if (m_pStatusLabel)
573 // m_pStatusLabel->setEnabled(fEnabled);
574 emit completeChanged();
575}
576
577
578void UIWizardNewVMPageBasic1::retranslateUi()
579{
580 /* Translate page: */
581 setTitle(UIWizardNewVM::tr("Virtual machine name and operating system"));
582
583 if (m_pLabel1)
584 m_pLabel1->setText(UIWizardNewVM::tr("Please choose whether you want to start an unattended guest os install "
585 "in which case you will have to select a valid installation medium. If not "
586 "your virtual disk will have an empty virtual hard disk. "
587 "Additionally you can choose to start the unattended install as a headless vm process."));
588
589 if (m_pButtonSimple)
590 {
591 m_pButtonSimple->setText(UIWizardNewVM::tr("Leave Disk Empty"));
592 m_pButtonSimple->setToolTip(UIWizardNewVM::tr("When checked, no guest OS will be installed after this wizard is closed"));
593 }
594 if (m_pButtonUnattended)
595 {
596 m_pButtonUnattended->setText(UIWizardNewVM::tr("Unattended Install"));
597 m_pButtonUnattended->setToolTip(UIWizardNewVM::tr("When checked, an unattended guest OS will be initialized after this wizard is closed"));
598 }
599
600 if (m_pISOSelectorLabel)
601 m_pISOSelectorLabel->setText(UIWizardNewVM::tr("Image:"));
602
603 if (m_pStartHeadlessLabel)
604 m_pStartHeadlessLabel->setText(UIWizardNewVM::tr("Options:"));
605 if (m_pStartHeadlessCheckBox)
606 {
607 m_pStartHeadlessCheckBox->setText(UIWizardNewVM::tr("Start VM Headless"));
608 m_pStartHeadlessCheckBox->setToolTip(UIWizardNewVM::tr("When checked, the unattended install will start the virtual machine headless"));
609 }
610
611 if (m_pLabel2)
612 m_pLabel2->setText(UIWizardNewVM::tr("Please choose a descriptive name and destination folder for the new virtual machine "
613 "and select the type of operating system you intend to install on it. "
614 "The name you choose will be used throughout VirtualBox "
615 "to identify this machine."));
616
617 if ( m_pNameAndSystemEditor
618 && m_pISOSelectorLabel
619 && m_pStartHeadlessLabel)
620 {
621 int iMinWidthHint = 0;
622 iMinWidthHint = qMax(iMinWidthHint, m_pISOSelectorLabel->minimumSizeHint().width());
623 iMinWidthHint = qMax(iMinWidthHint, m_pStartHeadlessLabel->minimumSizeHint().width());
624 m_pNameAndSystemEditor->setMinimumLayoutIndent(iMinWidthHint);
625 }
626}
627
628void UIWizardNewVMPageBasic1::initializePage()
629{
630 /* Translate page: */
631 retranslateUi();
632 if (m_pNameAndSystemEditor)
633 m_pNameAndSystemEditor->setFocus();
634}
635
636void UIWizardNewVMPageBasic1::cleanupPage()
637{
638 /* Cleanup: */
639 cleanupMachineFolder();
640 /* Call to base-class: */
641 UIWizardPage::cleanupPage();
642}
643
644bool UIWizardNewVMPageBasic1::validatePage()
645{
646 /* Try to create machine folder: */
647 return createMachineFolder();
648}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette