VirtualBox

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

Last change on this file since 87941 was 87941, checked in by vboxsync, 4 years ago

FE/Qt: bugref:9950. Some more polishing

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

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