VirtualBox

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

Last change on this file since 57340 was 57340, checked in by vboxsync, 9 years ago

FE/Qt: New VM wizard:

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