VirtualBox

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

Last change on this file since 68479 was 68479, checked in by vboxsync, 7 years ago

FE/Qt: UIWizardNewVMPageBasic1.cpp: actually use at least 3 letters

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 18.0 KB
Line 
1/* $Id: UIWizardNewVMPageBasic1.cpp 68479 2017-08-21 09:02:51Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIWizardNewVMPageBasic1 class implementation.
4 */
5
6/*
7 * Copyright (C) 2006-2016 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#ifdef VBOX_WITH_PRECOMPILED_HEADERS
19# include <precomp.h>
20#else /* !VBOX_WITH_PRECOMPILED_HEADERS */
21
22/* Qt includes: */
23# include <QDir>
24# include <QVBoxLayout>
25# include <QHBoxLayout>
26# include <QLineEdit>
27
28/* GUI includes: */
29# include "UIWizardNewVMPageBasic1.h"
30# include "UIWizardNewVM.h"
31# include "UIMessageCenter.h"
32# include "UINameAndSystemEditor.h"
33# include "QIRichTextLabel.h"
34
35/* COM includes: */
36# include "CSystemProperties.h"
37
38#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
39
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)|(NT4)", Qt::CaseInsensitive), "WindowsNT4" },
60 /* Note: Do not automatically set WindowsXP_64 on 64-bit hosts, as Windows XP 64-bit
61 * is extremely rare -- most users never heard of it even. So always default to 32-bit. */
62 { QRegExp("((Wi.*XP)|(XP)).*", Qt::CaseInsensitive), "WindowsXP" },
63 { QRegExp("((Wi.*2003)|(W2K3)|(Win2K3)).*64", Qt::CaseInsensitive), "Windows2003_64" },
64 { QRegExp("((Wi.*2003)|(W2K3)|(Win2K3)).*32", Qt::CaseInsensitive), "Windows2003" },
65 { QRegExp("((Wi.*Vis)|(Vista)).*64", Qt::CaseInsensitive), "WindowsVista_64" },
66 { QRegExp("((Wi.*Vis)|(Vista)).*32", Qt::CaseInsensitive), "WindowsVista" },
67 { QRegExp( "(Wi.*2016)|(W2K16)|(Win2K16)", Qt::CaseInsensitive), "Windows2016_64" },
68 { QRegExp( "(Wi.*2012)|(W2K12)|(Win2K12)", Qt::CaseInsensitive), "Windows2012_64" },
69 { QRegExp("((Wi.*2008)|(W2K8)|(Win2k8)).*64", Qt::CaseInsensitive), "Windows2008_64" },
70 { QRegExp("((Wi.*2008)|(W2K8)|(Win2K8)).*32", Qt::CaseInsensitive), "Windows2008" },
71 { QRegExp( "(Wi.*2000)|(W2K)|(Win2K)", Qt::CaseInsensitive), "Windows2000" },
72 { QRegExp( "(Wi.*7.*64)|(W7.*64)", Qt::CaseInsensitive), "Windows7_64" },
73 { QRegExp( "(Wi.*7.*32)|(W7.*32)", Qt::CaseInsensitive), "Windows7" },
74 { QRegExp( "(Wi.*8.*1.*64)|(W8.*64)", Qt::CaseInsensitive), "Windows81_64" },
75 { QRegExp( "(Wi.*8.*1.*32)|(W8.*32)", Qt::CaseInsensitive), "Windows81" },
76 { QRegExp( "(Wi.*8.*64)|(W8.*64)", Qt::CaseInsensitive), "Windows8_64" },
77 { QRegExp( "(Wi.*8.*32)|(W8.*32)", Qt::CaseInsensitive), "Windows8" },
78 { QRegExp( "(Wi.*10.*64)|(W10.*64)", Qt::CaseInsensitive), "Windows10_64" },
79 { QRegExp( "(Wi.*10.*32)|(W10.*32)", Qt::CaseInsensitive), "Windows10" },
80 { QRegExp( "Wi.*3.*1", Qt::CaseInsensitive), "Windows31" },
81 /* Set Windows 7 as default for "Windows". */
82 { QRegExp( "Wi.*64", Qt::CaseInsensitive), "Windows7_64" },
83 { QRegExp( "Wi.*32", Qt::CaseInsensitive), "Windows7" },
84
85 /* Solaris: */
86 { QRegExp("Sol.*11", Qt::CaseInsensitive), "Solaris11_64" },
87 { QRegExp("((Op.*Sol)|(os20[01][0-9])|(Sol.*10)|(India)|(Neva)).*64", Qt::CaseInsensitive), "OpenSolaris_64" },
88 { QRegExp("((Op.*Sol)|(os20[01][0-9])|(Sol.*10)|(India)|(Neva)).*32", Qt::CaseInsensitive), "OpenSolaris" },
89 { QRegExp("Sol.*64", Qt::CaseInsensitive), "Solaris_64" },
90 { QRegExp("Sol.*32", Qt::CaseInsensitive), "Solaris" },
91
92 /* OS/2: */
93 { QRegExp( "OS[/|!-]{,1}2.*W.*4.?5", Qt::CaseInsensitive), "OS2Warp45" },
94 { QRegExp( "OS[/|!-]{,1}2.*W.*4", Qt::CaseInsensitive), "OS2Warp4" },
95 { QRegExp( "OS[/|!-]{,1}2.*W", Qt::CaseInsensitive), "OS2Warp3" },
96 { QRegExp("(OS[/|!-]{,1}2.*e)|(eCS.*)", Qt::CaseInsensitive), "OS2eCS" },
97 { QRegExp( "OS[/|!-]{,1}2", Qt::CaseInsensitive), "OS2" },
98 { QRegExp( "eComS.*", Qt::CaseInsensitive), "OS2eCS" },
99
100 /* Other: Must come before Ubuntu/Maverick and before Linux??? */
101 { QRegExp("QN", Qt::CaseInsensitive), "QNX" },
102
103 /* Mac OS X: Must come before Ubuntu/Maverick and before Linux: */
104 { QRegExp("((mac.*10[.,]{0,1}4)|(os.*x.*10[.,]{0,1}4)|(mac.*ti)|(os.*x.*ti)|(Tig)).64", Qt::CaseInsensitive), "MacOS_64" },
105 { QRegExp("((mac.*10[.,]{0,1}4)|(os.*x.*10[.,]{0,1}4)|(mac.*ti)|(os.*x.*ti)|(Tig)).32", Qt::CaseInsensitive), "MacOS" },
106 { QRegExp("((mac.*10[.,]{0,1}5)|(os.*x.*10[.,]{0,1}5)|(mac.*leo)|(os.*x.*leo)|(Leop)).*64", Qt::CaseInsensitive), "MacOS_64" },
107 { QRegExp("((mac.*10[.,]{0,1}5)|(os.*x.*10[.,]{0,1}5)|(mac.*leo)|(os.*x.*leo)|(Leop)).*32", Qt::CaseInsensitive), "MacOS" },
108 { QRegExp("((mac.*10[.,]{0,1}6)|(os.*x.*10[.,]{0,1}6)|(mac.*SL)|(os.*x.*SL)|(Snow L)).*64", Qt::CaseInsensitive), "MacOS106_64" },
109 { QRegExp("((mac.*10[.,]{0,1}6)|(os.*x.*10[.,]{0,1}6)|(mac.*SL)|(os.*x.*SL)|(Snow L)).*32", Qt::CaseInsensitive), "MacOS106" },
110 { QRegExp( "(mac.*10[.,]{0,1}7)|(os.*x.*10[.,]{0,1}7)|(mac.*ML)|(os.*x.*ML)|(Mount)", Qt::CaseInsensitive), "MacOS108_64" },
111 { QRegExp( "(mac.*10[.,]{0,1}8)|(os.*x.*10[.,]{0,1}8)|(Lion)", Qt::CaseInsensitive), "MacOS107_64" },
112 { QRegExp( "(mac.*10[.,]{0,1}9)|(os.*x.*10[.,]{0,1}9)|(mac.*mav)|(os.*x.*mav)|(Mavericks)", Qt::CaseInsensitive), "MacOS109_64" },
113 { QRegExp( "(mac.*yos)|(os.*x.*yos)|(Yosemite)", Qt::CaseInsensitive), "MacOS1010_64" },
114 { QRegExp( "(mac.*cap)|(os.*x.*capit)|(Capitan)", Qt::CaseInsensitive), "MacOS1011_64" },
115 { QRegExp( "(mac.*hig)|(os.*x.*high.*sierr)|(High Sierra)", Qt::CaseInsensitive), "MacOS1013_64" },
116 { QRegExp( "(mac.*sie)|(os.*x.*sierr)|(Sierra)", Qt::CaseInsensitive), "MacOS1012_64" },
117 { QRegExp("((Mac)|(Tig)|(Leop)|(Yose)|(os[ ]*x)).*64", Qt::CaseInsensitive), "MacOS_64" },
118 { QRegExp("((Mac)|(Tig)|(Leop)|(Yose)|(os[ ]*x)).*32", Qt::CaseInsensitive), "MacOS" },
119
120 /* Code names for Linux distributions: */
121 { 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" },
122 { 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" },
123 { 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" },
124 { 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" },
125 { QRegExp("((sarge)|(etch)|(lenny)|(squeeze)|(wheezy)|(jessie)|(stretch)|(buster)|(sid)).*64", Qt::CaseInsensitive), "Debian_64" },
126 { QRegExp("((sarge)|(etch)|(lenny)|(squeeze)|(wheezy)|(jessie)|(stretch)|(buster)|(sid)).*32", Qt::CaseInsensitive), "Debian" },
127 { QRegExp("((moonshine)|(werewolf)|(sulphur)|(cambridge)|(leonidas)|(constantine)|(goddard)|(laughlin)|(lovelock)|(verne)|(beefy)|(spherical)).*64", Qt::CaseInsensitive), "Fedora_64" },
128 { QRegExp("((moonshine)|(werewolf)|(sulphur)|(cambridge)|(leonidas)|(constantine)|(goddard)|(laughlin)|(lovelock)|(verne)|(beefy)|(spherical)).*32", Qt::CaseInsensitive), "Fedora" },
129
130 /* Regular names of Linux distributions: */
131 { QRegExp("Arc.*64", Qt::CaseInsensitive), "ArchLinux_64" },
132 { QRegExp("Arc.*32", Qt::CaseInsensitive), "ArchLinux" },
133 { QRegExp("Deb.*64", Qt::CaseInsensitive), "Debian_64" },
134 { QRegExp("Deb.*32", Qt::CaseInsensitive), "Debian" },
135 { QRegExp("((SU)|(Nov)|(SLE)).*64", Qt::CaseInsensitive), "OpenSUSE_64" },
136 { QRegExp("((SU)|(Nov)|(SLE)).*32", Qt::CaseInsensitive), "OpenSUSE" },
137 { QRegExp("Fe.*64", Qt::CaseInsensitive), "Fedora_64" },
138 { QRegExp("Fe.*32", Qt::CaseInsensitive), "Fedora" },
139 { QRegExp("((Gen)|(Sab)).*64", Qt::CaseInsensitive), "Gentoo_64" },
140 { QRegExp("((Gen)|(Sab)).*32", Qt::CaseInsensitive), "Gentoo" },
141 { QRegExp("((Man)|(Mag)).*64", Qt::CaseInsensitive), "Mandriva_64" },
142 { QRegExp("((Man)|(Mag)).*32", Qt::CaseInsensitive), "Mandriva" },
143 { QRegExp("((Red)|(rhel)|(cen)).*64", Qt::CaseInsensitive), "RedHat_64" },
144 { QRegExp("((Red)|(rhel)|(cen)).*32", Qt::CaseInsensitive), "RedHat" },
145 { QRegExp("Tur.*64", Qt::CaseInsensitive), "Turbolinux_64" },
146 { QRegExp("Tur.*32", Qt::CaseInsensitive), "Turbolinux" },
147 { QRegExp("(Ub)|(Min).*64", Qt::CaseInsensitive), "Ubuntu_64" },
148 { QRegExp("(Ub)|(Min).*32", Qt::CaseInsensitive), "Ubuntu" },
149 { QRegExp("Xa.*64", Qt::CaseInsensitive), "Xandros_64" },
150 { QRegExp("Xa.*32", Qt::CaseInsensitive), "Xandros" },
151 { QRegExp("((Or)|(oel)|(ol)).*64", Qt::CaseInsensitive), "Oracle_64" },
152 { QRegExp("((Or)|(oel)|(ol)).*32", Qt::CaseInsensitive), "Oracle" },
153 { QRegExp("Knoppix", Qt::CaseInsensitive), "Linux26" },
154 { QRegExp("Dsl", Qt::CaseInsensitive), "Linux24" },
155 { QRegExp("((Lin)|(lnx)).*2.?2", Qt::CaseInsensitive), "Linux22" },
156 { QRegExp("((Lin)|(lnx)).*2.?4.*64", Qt::CaseInsensitive), "Linux24_64" },
157 { QRegExp("((Lin)|(lnx)).*2.?4.*32", Qt::CaseInsensitive), "Linux24" },
158 { QRegExp("((((Lin)|(lnx)).*2.?6)|(LFS)).*64", Qt::CaseInsensitive), "Linux26_64" },
159 { QRegExp("((((Lin)|(lnx)).*2.?6)|(LFS)).*32", Qt::CaseInsensitive), "Linux26" },
160 { QRegExp("((Lin)|(lnx)).*64", Qt::CaseInsensitive), "Linux26_64" },
161 { QRegExp("((Lin)|(lnx)).*32", Qt::CaseInsensitive), "Linux26" },
162
163 /* Other: */
164 { QRegExp("L4", Qt::CaseInsensitive), "L4" },
165 { QRegExp("((Fr.*B)|(fbsd)).*64", Qt::CaseInsensitive), "FreeBSD_64" },
166 { QRegExp("((Fr.*B)|(fbsd)).*32", Qt::CaseInsensitive), "FreeBSD" },
167 { QRegExp("Op.*B.*64", Qt::CaseInsensitive), "OpenBSD_64" },
168 { QRegExp("Op.*B.*32", Qt::CaseInsensitive), "OpenBSD" },
169 { QRegExp("Ne.*B.*64", Qt::CaseInsensitive), "NetBSD_64" },
170 { QRegExp("Ne.*B.*32", Qt::CaseInsensitive), "NetBSD" },
171 { QRegExp("Net", Qt::CaseInsensitive), "Netware" },
172 { QRegExp("Rocki", Qt::CaseInsensitive), "JRockitVE" },
173 { QRegExp("bs[23]{0,1}-", Qt::CaseInsensitive), "VBoxBS_64" }, /* bootsector tests */
174 { QRegExp("Ot", Qt::CaseInsensitive), "Other" },
175};
176
177UIWizardNewVMPage1::UIWizardNewVMPage1(const QString &strGroup)
178 : m_strGroup(strGroup)
179{
180 CHost host = vboxGlobal().host();
181 m_fSupportsHWVirtEx = host.GetProcessorFeature(KProcessorFeature_HWVirtEx);
182 m_fSupportsLongMode = host.GetProcessorFeature(KProcessorFeature_LongMode);
183}
184
185void UIWizardNewVMPage1::onNameChanged(QString strNewName)
186{
187 /* Do not forget about achitecture bits, if not yet specified: */
188 if (!strNewName.contains("32") && !strNewName.contains("64"))
189 strNewName += ARCH_BITS == 64 && m_fSupportsHWVirtEx && m_fSupportsLongMode ? "64" : "32";
190
191 /* Search for a matching OS type based on the string the user typed already. */
192 for (size_t i = 0; i < RT_ELEMENTS(gs_OSTypePattern); ++i)
193 if (strNewName.contains(gs_OSTypePattern[i].pattern))
194 {
195 m_pNameAndSystemEditor->blockSignals(true);
196 m_pNameAndSystemEditor->setType(vboxGlobal().vmGuestOSType(gs_OSTypePattern[i].pcstId));
197 m_pNameAndSystemEditor->blockSignals(false);
198 break;
199 }
200}
201
202void UIWizardNewVMPage1::onOsTypeChanged()
203{
204 /* If the user manually edited the OS type, we didn't want our automatic OS type guessing anymore.
205 * So simply disconnect the text-edit signal. */
206 m_pNameAndSystemEditor->disconnect(SIGNAL(sigNameChanged(const QString &)), thisImp(), SLOT(sltNameChanged(const QString &)));
207}
208
209bool UIWizardNewVMPage1::machineFolderCreated()
210{
211 return !m_strMachineFolder.isEmpty();
212}
213
214bool UIWizardNewVMPage1::createMachineFolder()
215{
216 /* Cleanup previosly created folder if any: */
217 if (machineFolderCreated() && !cleanupMachineFolder())
218 {
219 msgCenter().cannotRemoveMachineFolder(m_strMachineFolder, thisImp());
220 return false;
221 }
222
223 /* Get VBox: */
224 CVirtualBox vbox = vboxGlobal().virtualBox();
225 /* Get default machine folder: */
226 const QString strDefaultMachineFolder = vbox.GetSystemProperties().GetDefaultMachineFolder();
227 /* Compose machine filename: */
228 const QString strMachineFilePath = vbox.ComposeMachineFilename(m_pNameAndSystemEditor->name(),
229 m_strGroup,
230 QString(),
231 strDefaultMachineFolder);
232 /* Compose machine folder/basename: */
233 const QFileInfo fileInfo(strMachineFilePath);
234 const QString strMachineFolder = fileInfo.absolutePath();
235 const QString strMachineBaseName = fileInfo.completeBaseName();
236
237 /* Make sure that folder doesn't exists: */
238 if (QDir(strMachineFolder).exists())
239 {
240 msgCenter().cannotRewriteMachineFolder(strMachineFolder, thisImp());
241 return false;
242 }
243
244 /* Try to create new folder (and it's predecessors): */
245 bool fMachineFolderCreated = QDir().mkpath(strMachineFolder);
246 if (!fMachineFolderCreated)
247 {
248 msgCenter().cannotCreateMachineFolder(strMachineFolder, thisImp());
249 return false;
250 }
251
252 /* Initialize fields: */
253 m_strMachineFolder = strMachineFolder;
254 m_strMachineBaseName = strMachineBaseName;
255 return true;
256}
257
258bool UIWizardNewVMPage1::cleanupMachineFolder()
259{
260 /* Make sure folder was previosly created: */
261 if (m_strMachineFolder.isEmpty())
262 return false;
263 /* Try to cleanup folder (and it's predecessors): */
264 bool fMachineFolderRemoved = QDir().rmpath(m_strMachineFolder);
265 /* Reset machine folder value: */
266 if (fMachineFolderRemoved)
267 m_strMachineFolder = QString();
268 /* Return cleanup result: */
269 return fMachineFolderRemoved;
270}
271
272UIWizardNewVMPageBasic1::UIWizardNewVMPageBasic1(const QString &strGroup)
273 : UIWizardNewVMPage1(strGroup)
274{
275 /* Create widgets: */
276 QVBoxLayout *pMainLayout = new QVBoxLayout(this);
277 {
278 m_pLabel = new QIRichTextLabel(this);
279 m_pNameAndSystemEditor = new UINameAndSystemEditor(this);
280 pMainLayout->addWidget(m_pLabel);
281 pMainLayout->addWidget(m_pNameAndSystemEditor);
282 pMainLayout->addStretch();
283 }
284
285 /* Setup connections: */
286 connect(m_pNameAndSystemEditor, SIGNAL(sigNameChanged(const QString &)), this, SLOT(sltNameChanged(const QString &)));
287 connect(m_pNameAndSystemEditor, SIGNAL(sigOsTypeChanged()), this, SLOT(sltOsTypeChanged()));
288
289 /* Register fields: */
290 registerField("name*", m_pNameAndSystemEditor, "name", SIGNAL(sigNameChanged(const QString &)));
291 registerField("type", m_pNameAndSystemEditor, "type", SIGNAL(sigOsTypeChanged()));
292 registerField("machineFolder", this, "machineFolder");
293 registerField("machineBaseName", this, "machineBaseName");
294}
295
296void UIWizardNewVMPageBasic1::sltNameChanged(const QString &strNewName)
297{
298 /* Call to base-class: */
299 onNameChanged(strNewName);
300}
301
302void UIWizardNewVMPageBasic1::sltOsTypeChanged()
303{
304 /* Call to base-class: */
305 onOsTypeChanged();
306}
307
308void UIWizardNewVMPageBasic1::retranslateUi()
309{
310 /* Translate page: */
311 setTitle(UIWizardNewVM::tr("Name and operating system"));
312
313 /* Translate widgets: */
314 m_pLabel->setText(UIWizardNewVM::tr("Please choose a descriptive name for the new virtual machine "
315 "and select the type of operating system you intend to install on it. "
316 "The name you choose will be used throughout VirtualBox "
317 "to identify this machine."));
318}
319
320void UIWizardNewVMPageBasic1::initializePage()
321{
322 /* Translate page: */
323 retranslateUi();
324}
325
326void UIWizardNewVMPageBasic1::cleanupPage()
327{
328 /* Cleanup: */
329 cleanupMachineFolder();
330 /* Call to base-class: */
331 UIWizardPage::cleanupPage();
332}
333
334bool UIWizardNewVMPageBasic1::validatePage()
335{
336 /* Try to create machine folder: */
337 return createMachineFolder();
338}
339
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