1 | /* $Id: UIWizardNewVMPageBasic1.cpp 85053 2020-07-03 11:33:19Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIWizardNewVMPageBasicNameType 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. */
|
---|
45 | struct osTypePattern
|
---|
46 | {
|
---|
47 | QRegExp pattern;
|
---|
48 | const char *pcstId;
|
---|
49 | };
|
---|
50 |
|
---|
51 | static 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 |
|
---|
181 | UIWizardNewVMPageNameType::UIWizardNewVMPageNameType(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 |
|
---|
196 | void UIWizardNewVMPageNameType::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 |
|
---|
216 | void UIWizardNewVMPageNameType::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 |
|
---|
224 | bool UIWizardNewVMPageNameType::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 |
|
---|
252 | void UIWizardNewVMPageNameType::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 |
|
---|
272 | bool UIWizardNewVMPageNameType::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 |
|
---|
283 | bool UIWizardNewVMPageNameType::createMachineFolder()
|
---|
284 | {
|
---|
285 | if (!m_pNameAndSystemEditor)
|
---|
286 | return false;
|
---|
287 | /* Cleanup previosly created folder if any: */
|
---|
288 | if (!cleanupMachineFolder())
|
---|
289 | {
|
---|
290 | msgCenter().cannotRemoveMachineFolder(m_strMachineFolder, thisImp());
|
---|
291 | return false;
|
---|
292 | }
|
---|
293 |
|
---|
294 | composeMachineFilePath();
|
---|
295 |
|
---|
296 | /* Check if the folder already exists and check if it has been created by this wizard */
|
---|
297 | if (QDir(m_strMachineFolder).exists())
|
---|
298 | {
|
---|
299 | /* Looks like we have already created this folder for this run of the wizard. Just return */
|
---|
300 | if (m_strCreatedFolder == m_strMachineFolder)
|
---|
301 | return true;
|
---|
302 | /* The folder is there but not because of this wizard. Avoid overwriting a existing machine's folder */
|
---|
303 | else
|
---|
304 | {
|
---|
305 | msgCenter().cannotRewriteMachineFolder(m_strMachineFolder, thisImp());
|
---|
306 | return false;
|
---|
307 | }
|
---|
308 | }
|
---|
309 |
|
---|
310 | /* Try to create new folder (and it's predecessors): */
|
---|
311 | bool fMachineFolderCreated = QDir().mkpath(m_strMachineFolder);
|
---|
312 | if (!fMachineFolderCreated)
|
---|
313 | {
|
---|
314 | msgCenter().cannotCreateMachineFolder(m_strMachineFolder, thisImp());
|
---|
315 | return false;
|
---|
316 | }
|
---|
317 | m_strCreatedFolder = m_strMachineFolder;
|
---|
318 | return true;
|
---|
319 | }
|
---|
320 |
|
---|
321 | bool UIWizardNewVMPageNameType::cleanupMachineFolder(bool fWizardCancel /* = false */)
|
---|
322 | {
|
---|
323 | /* Make sure folder was previosly created: */
|
---|
324 | if (m_strCreatedFolder.isEmpty())
|
---|
325 | return true;
|
---|
326 | /* Clean this folder if the machine folder has been changed by the user or we are cancelling the wizard: */
|
---|
327 | if (m_strCreatedFolder != m_strMachineFolder || fWizardCancel)
|
---|
328 | {
|
---|
329 | /* Try to cleanup folder (and it's predecessors): */
|
---|
330 | bool fMachineFolderRemoved = QDir().rmpath(m_strCreatedFolder);
|
---|
331 | /* Reset machine folder value: */
|
---|
332 | if (fMachineFolderRemoved)
|
---|
333 | m_strCreatedFolder = QString();
|
---|
334 | /* Return cleanup result: */
|
---|
335 | return fMachineFolderRemoved;
|
---|
336 | }
|
---|
337 | return true;
|
---|
338 | }
|
---|
339 |
|
---|
340 | QString UIWizardNewVMPageNameType::machineFilePath() const
|
---|
341 | {
|
---|
342 | return m_strMachineFilePath;
|
---|
343 | }
|
---|
344 |
|
---|
345 | void UIWizardNewVMPageNameType::setMachineFilePath(const QString &strMachineFilePath)
|
---|
346 | {
|
---|
347 | m_strMachineFilePath = strMachineFilePath;
|
---|
348 | }
|
---|
349 |
|
---|
350 | QString UIWizardNewVMPageNameType::machineFolder() const
|
---|
351 | {
|
---|
352 | return m_strMachineFolder;
|
---|
353 | }
|
---|
354 |
|
---|
355 | void UIWizardNewVMPageNameType::setMachineFolder(const QString &strMachineFolder)
|
---|
356 | {
|
---|
357 | m_strMachineFolder = strMachineFolder;
|
---|
358 | }
|
---|
359 |
|
---|
360 | QString UIWizardNewVMPageNameType::machineBaseName() const
|
---|
361 | {
|
---|
362 | return m_strMachineBaseName;
|
---|
363 | }
|
---|
364 |
|
---|
365 | void UIWizardNewVMPageNameType::setMachineBaseName(const QString &strMachineBaseName)
|
---|
366 | {
|
---|
367 | m_strMachineBaseName = strMachineBaseName;
|
---|
368 | }
|
---|
369 |
|
---|
370 | QString UIWizardNewVMPageNameType::guestOSFamiyId() const
|
---|
371 | {
|
---|
372 | if (!m_pNameAndSystemEditor)
|
---|
373 | return QString();
|
---|
374 | return m_pNameAndSystemEditor->familyId();
|
---|
375 | }
|
---|
376 |
|
---|
377 | QString UIWizardNewVMPageNameType::ISOFilePath() const
|
---|
378 | {
|
---|
379 | if (!m_pISOFilePathSelector)
|
---|
380 | return QString();
|
---|
381 | return m_pISOFilePathSelector->path();
|
---|
382 | }
|
---|
383 |
|
---|
384 | bool UIWizardNewVMPageNameType::isUnattendedEnabled() const
|
---|
385 | {
|
---|
386 | if (!m_pButtonUnattended)
|
---|
387 | return false;
|
---|
388 | return m_pButtonUnattended->isChecked();
|
---|
389 | }
|
---|
390 |
|
---|
391 | bool UIWizardNewVMPageNameType::startHeadless() const
|
---|
392 | {
|
---|
393 | if (!m_pStartHeadlessCheckBox)
|
---|
394 | return false;
|
---|
395 | return m_pStartHeadlessCheckBox->isChecked();
|
---|
396 | }
|
---|
397 |
|
---|
398 | const QString &UIWizardNewVMPageNameType::detectedOSTypeId() const
|
---|
399 | {
|
---|
400 | return m_strDetectedOSTypeId;
|
---|
401 | }
|
---|
402 |
|
---|
403 | UIWizardNewVMPageBasicNameType::UIWizardNewVMPageBasicNameType(const QString &strGroup)
|
---|
404 | : UIWizardNewVMPageNameType(strGroup)
|
---|
405 | {
|
---|
406 | prepare();
|
---|
407 | }
|
---|
408 |
|
---|
409 | void UIWizardNewVMPageBasicNameType::prepare()
|
---|
410 | {
|
---|
411 | QGridLayout *pMainLayout = new QGridLayout(this);
|
---|
412 | if (pMainLayout)
|
---|
413 | {
|
---|
414 | m_pLabel1 = new QIRichTextLabel(this);
|
---|
415 | if (m_pLabel1)
|
---|
416 | pMainLayout->addWidget(m_pLabel1, 0, 0, 1, 3);
|
---|
417 |
|
---|
418 | QButtonGroup *pButtonGroup = new QButtonGroup(this);
|
---|
419 | if (pButtonGroup)
|
---|
420 | {
|
---|
421 | m_pButtonSimple = new QRadioButton(this);
|
---|
422 | if (m_pButtonSimple)
|
---|
423 | {
|
---|
424 | m_pButtonSimple->setChecked(true);
|
---|
425 | pMainLayout->addWidget(m_pButtonSimple, 1, 0, 1, 3);
|
---|
426 | }
|
---|
427 | m_pButtonUnattended = new QRadioButton(this);
|
---|
428 | if (m_pButtonUnattended)
|
---|
429 | {
|
---|
430 | QStyleOptionButton options;
|
---|
431 | options.initFrom(m_pButtonUnattended);
|
---|
432 | const int iWidth = m_pButtonUnattended->style()->pixelMetric(QStyle::PM_ExclusiveIndicatorWidth,
|
---|
433 | &options, m_pButtonUnattended);
|
---|
434 | pMainLayout->setColumnMinimumWidth(0, iWidth);
|
---|
435 | pMainLayout->addWidget(m_pButtonUnattended, 2, 0, 1, 3);
|
---|
436 | }
|
---|
437 |
|
---|
438 | pButtonGroup->addButton(m_pButtonSimple);
|
---|
439 | pButtonGroup->addButton(m_pButtonUnattended);
|
---|
440 | connect(pButtonGroup, static_cast<void(QButtonGroup::*)(QAbstractButton*)>(&QButtonGroup::buttonClicked),
|
---|
441 | this, &UIWizardNewVMPageBasicNameType::sltUnattendedCheckBoxToggle);
|
---|
442 | }
|
---|
443 |
|
---|
444 | m_pISOSelectorLabel = new QLabel;
|
---|
445 | if (m_pISOSelectorLabel)
|
---|
446 | {
|
---|
447 | m_pISOSelectorLabel->setAlignment(Qt::AlignRight);
|
---|
448 | m_pISOSelectorLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
|
---|
449 | m_pISOSelectorLabel->setEnabled(false);
|
---|
450 | pMainLayout->addWidget(m_pISOSelectorLabel, 3, 1);
|
---|
451 | }
|
---|
452 | m_pISOFilePathSelector = new UIFilePathSelector;
|
---|
453 | if (m_pISOFilePathSelector)
|
---|
454 | {
|
---|
455 | m_pISOFilePathSelector->setResetEnabled(false);
|
---|
456 | m_pISOFilePathSelector->setMode(UIFilePathSelector::Mode_File_Open);
|
---|
457 | m_pISOFilePathSelector->setFileDialogFilters("*.iso *.ISO");
|
---|
458 | m_pISOFilePathSelector->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
|
---|
459 | m_pISOFilePathSelector->setEnabled(false);
|
---|
460 | connect(m_pISOFilePathSelector, &UIFilePathSelector::pathChanged, this, &UIWizardNewVMPageBasicNameType::sltISOPathChanged);
|
---|
461 | pMainLayout->addWidget(m_pISOFilePathSelector, 3, 2);
|
---|
462 | }
|
---|
463 |
|
---|
464 | m_pStartHeadlessLabel = new QLabel;
|
---|
465 | if (m_pStartHeadlessLabel)
|
---|
466 | {
|
---|
467 | m_pStartHeadlessLabel->setAlignment(Qt::AlignRight);
|
---|
468 | m_pStartHeadlessLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
|
---|
469 | m_pStartHeadlessLabel->setEnabled(false);
|
---|
470 | pMainLayout->addWidget(m_pStartHeadlessLabel, 4, 1);
|
---|
471 | }
|
---|
472 | m_pStartHeadlessCheckBox = new QCheckBox;
|
---|
473 | if (m_pStartHeadlessCheckBox)
|
---|
474 | {
|
---|
475 | m_pStartHeadlessCheckBox->setEnabled(false);
|
---|
476 | pMainLayout->addWidget(m_pStartHeadlessCheckBox, 4, 2);
|
---|
477 | }
|
---|
478 |
|
---|
479 | m_pLabel2 = new QIRichTextLabel(this);
|
---|
480 | if (m_pLabel2)
|
---|
481 | pMainLayout->addWidget(m_pLabel2, 5, 0, 1, 3);
|
---|
482 |
|
---|
483 | m_pNameAndSystemEditor = new UINameAndSystemEditor(this, true, true, true);
|
---|
484 | if (m_pNameAndSystemEditor)
|
---|
485 | {
|
---|
486 | connect(m_pNameAndSystemEditor, &UINameAndSystemEditor::sigNameChanged, this, &UIWizardNewVMPageBasicNameType::sltNameChanged);
|
---|
487 | connect(m_pNameAndSystemEditor, &UINameAndSystemEditor::sigPathChanged, this, &UIWizardNewVMPageBasicNameType::sltPathChanged);
|
---|
488 | connect(m_pNameAndSystemEditor, &UINameAndSystemEditor::sigOsTypeChanged, this, &UIWizardNewVMPageBasicNameType::sltOsTypeChanged);
|
---|
489 | pMainLayout->addWidget(m_pNameAndSystemEditor, 6, 1, 1, 2);
|
---|
490 | }
|
---|
491 |
|
---|
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 | }
|
---|
505 |
|
---|
506 | int UIWizardNewVMPageBasicNameType::nextId() const
|
---|
507 | {
|
---|
508 | UIWizardNewVM *pWizard = qobject_cast<UIWizardNewVM*>(wizard());
|
---|
509 | if (!pWizard || !pWizard->isUnattendedInstallEnabled())
|
---|
510 | return UIWizardNewVM::PageHardware;
|
---|
511 | return UIWizardNewVM::PageUserNameHostname;
|
---|
512 | }
|
---|
513 |
|
---|
514 | void UIWizardNewVMPageBasicNameType::setTypeByISODetectedOSType(const QString &strDetectedOSType)
|
---|
515 | {
|
---|
516 | if (!strDetectedOSType.isEmpty())
|
---|
517 | onNameChanged(strDetectedOSType);
|
---|
518 | }
|
---|
519 |
|
---|
520 | bool UIWizardNewVMPageBasicNameType::isComplete() const
|
---|
521 | {
|
---|
522 | if (m_pNameAndSystemEditor->name().isEmpty())
|
---|
523 | return false;
|
---|
524 | return checkISOFile();
|
---|
525 | }
|
---|
526 |
|
---|
527 | void UIWizardNewVMPageBasicNameType::sltNameChanged(const QString &strNewName)
|
---|
528 | {
|
---|
529 | onNameChanged(strNewName);
|
---|
530 | composeMachineFilePath();
|
---|
531 | }
|
---|
532 |
|
---|
533 | void UIWizardNewVMPageBasicNameType::sltPathChanged(const QString &strNewPath)
|
---|
534 | {
|
---|
535 | Q_UNUSED(strNewPath);
|
---|
536 | composeMachineFilePath();
|
---|
537 | }
|
---|
538 |
|
---|
539 | void UIWizardNewVMPageBasicNameType::sltOsTypeChanged()
|
---|
540 | {
|
---|
541 | /* Call to base-class: */
|
---|
542 | onOsTypeChanged();
|
---|
543 | }
|
---|
544 |
|
---|
545 | void UIWizardNewVMPageBasicNameType::sltISOPathChanged(const QString &strPath)
|
---|
546 | {
|
---|
547 | determineOSType(strPath);
|
---|
548 | setTypeByISODetectedOSType(m_strDetectedOSTypeId);
|
---|
549 | emit completeChanged();
|
---|
550 | }
|
---|
551 |
|
---|
552 | void UIWizardNewVMPageBasicNameType::sltUnattendedCheckBoxToggle()
|
---|
553 | {
|
---|
554 | const bool fEnabled = m_pButtonUnattended->isChecked();
|
---|
555 | if (m_pISOSelectorLabel)
|
---|
556 | m_pISOSelectorLabel->setEnabled(fEnabled);
|
---|
557 | if (m_pISOFilePathSelector)
|
---|
558 | m_pISOFilePathSelector->setEnabled(fEnabled);
|
---|
559 | if (m_pStartHeadlessLabel)
|
---|
560 | m_pStartHeadlessLabel->setEnabled(fEnabled);
|
---|
561 | if (m_pStartHeadlessCheckBox)
|
---|
562 | m_pStartHeadlessCheckBox->setEnabled(fEnabled);
|
---|
563 | // if (m_pStatusLabel)
|
---|
564 | // m_pStatusLabel->setEnabled(fEnabled);
|
---|
565 | emit completeChanged();
|
---|
566 | }
|
---|
567 |
|
---|
568 |
|
---|
569 | void UIWizardNewVMPageBasicNameType::retranslateUi()
|
---|
570 | {
|
---|
571 | /* Translate page: */
|
---|
572 | setTitle(UIWizardNewVM::tr("Name and operating system"));
|
---|
573 |
|
---|
574 | if (m_pLabel1)
|
---|
575 | m_pLabel1->setText(UIWizardNewVM::tr("Please choose whether you want to leave newly created VM empty or use operating "
|
---|
576 | "system image medium for unattended installation. You can additionally specify "
|
---|
577 | "whether newly created machine should be started in headless mode if you are sure "
|
---|
578 | "your interference will not be necessary."));
|
---|
579 |
|
---|
580 | if (m_pButtonSimple)
|
---|
581 | {
|
---|
582 | m_pButtonSimple->setText(UIWizardNewVM::tr("Leave Empty"));
|
---|
583 | m_pButtonSimple->setToolTip(UIWizardNewVM::tr("When checked, no guest OS will be installed after this wizard is closed"));
|
---|
584 | }
|
---|
585 | if (m_pButtonUnattended)
|
---|
586 | {
|
---|
587 | m_pButtonUnattended->setText(UIWizardNewVM::tr("Unattended Install"));
|
---|
588 | m_pButtonUnattended->setToolTip(UIWizardNewVM::tr("When checked, an unattended guest OS will be initialized after this wizard is closed"));
|
---|
589 | }
|
---|
590 |
|
---|
591 | if (m_pISOSelectorLabel)
|
---|
592 | m_pISOSelectorLabel->setText(UIWizardNewVM::tr("Image:"));
|
---|
593 |
|
---|
594 | if (m_pStartHeadlessLabel)
|
---|
595 | m_pStartHeadlessLabel->setText(UIWizardNewVM::tr("Options:"));
|
---|
596 | if (m_pStartHeadlessCheckBox)
|
---|
597 | {
|
---|
598 | m_pStartHeadlessCheckBox->setText(UIWizardNewVM::tr("Start VM Headless"));
|
---|
599 | m_pStartHeadlessCheckBox->setToolTip(UIWizardNewVM::tr("When checked, the unattended install will start the virtual machine headless"));
|
---|
600 | }
|
---|
601 |
|
---|
602 | if (m_pLabel2)
|
---|
603 | m_pLabel2->setText(UIWizardNewVM::tr("Please choose a descriptive name and destination folder for the new virtual machine "
|
---|
604 | "and select the type of operating system you intend to install on it. "
|
---|
605 | "The name you choose will be used throughout VirtualBox "
|
---|
606 | "to identify this machine."));
|
---|
607 |
|
---|
608 | if ( m_pNameAndSystemEditor
|
---|
609 | && m_pISOSelectorLabel
|
---|
610 | && m_pStartHeadlessLabel)
|
---|
611 | {
|
---|
612 | int iMinWidthHint = 0;
|
---|
613 | iMinWidthHint = qMax(iMinWidthHint, m_pISOSelectorLabel->minimumSizeHint().width());
|
---|
614 | iMinWidthHint = qMax(iMinWidthHint, m_pStartHeadlessLabel->minimumSizeHint().width());
|
---|
615 | m_pNameAndSystemEditor->setMinimumLayoutIndent(iMinWidthHint);
|
---|
616 | }
|
---|
617 | }
|
---|
618 |
|
---|
619 | void UIWizardNewVMPageBasicNameType::initializePage()
|
---|
620 | {
|
---|
621 | /* Translate page: */
|
---|
622 | retranslateUi();
|
---|
623 | if (m_pNameAndSystemEditor)
|
---|
624 | m_pNameAndSystemEditor->setFocus();
|
---|
625 | }
|
---|
626 |
|
---|
627 | void UIWizardNewVMPageBasicNameType::cleanupPage()
|
---|
628 | {
|
---|
629 | /* Cleanup: */
|
---|
630 | cleanupMachineFolder();
|
---|
631 | /* Call to base-class: */
|
---|
632 | UIWizardPage::cleanupPage();
|
---|
633 | }
|
---|
634 |
|
---|
635 | bool UIWizardNewVMPageBasicNameType::validatePage()
|
---|
636 | {
|
---|
637 | /* Try to create machine folder: */
|
---|
638 | return createMachineFolder();
|
---|
639 | }
|
---|