VirtualBox

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

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

FE/Qt: ​​​​​​​​​bugref:6769: Rework for New VM wizard (part 01): 1. Use the normalized machine base-name instead of user's machine name; 2. Small cleanup simplifying further changes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 17.7 KB
Line 
1/* $Id: UIWizardNewVMPageBasic1.cpp 60837 2016-05-04 15:29:56Z 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("((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" },
119 { 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" },
120 { QRegExp("((edgy)|(feisty)|(gutsy)|(hardy)|(intrepid)|(jaunty)|(karmic)|(lucid)|(maverick)|(natty)|(oneiric)|(precise)|(quantal)|(raring)|(saucy)|(trusty)|(utopic)|(vivid)|(wily)|(xenial)).*64", Qt::CaseInsensitive), "Ubuntu_64" },
121 { QRegExp("((edgy)|(feisty)|(gutsy)|(hardy)|(intrepid)|(jaunty)|(karmic)|(lucid)|(maverick)|(natty)|(oneiric)|(precise)|(quantal)|(raring)|(saucy)|(trusty)|(utopic)|(vivid)|(wily)|(xenial)).*32", Qt::CaseInsensitive), "Ubuntu" },
122 { QRegExp("((sarge)|(etch)|(lenny)|(squeeze)|(wheezy)|(jessie)|(sid)).*64", Qt::CaseInsensitive), "Debian_64" },
123 { QRegExp("((sarge)|(etch)|(lenny)|(squeeze)|(wheezy)|(jessie)|(sid)).*32", Qt::CaseInsensitive), "Debian" },
124 { QRegExp("((moonshine)|(werewolf)|(sulphur)|(cambridge)|(leonidas)|(constantine)|(goddard)|(laughlin)|(lovelock)|(verne)|(beefy)|(spherical)).*64", Qt::CaseInsensitive), "Fedora_64" },
125 { QRegExp("((moonshine)|(werewolf)|(sulphur)|(cambridge)|(leonidas)|(constantine)|(goddard)|(laughlin)|(lovelock)|(verne)|(beefy)|(spherical)).*32", Qt::CaseInsensitive), "Fedora" },
126
127 /* Regular names of Linux distributions: */
128 { QRegExp("Arc.*64", Qt::CaseInsensitive), "ArchLinux_64" },
129 { QRegExp("Arc.*32", Qt::CaseInsensitive), "ArchLinux" },
130 { QRegExp("Deb.*64", Qt::CaseInsensitive), "Debian_64" },
131 { QRegExp("Deb.*32", Qt::CaseInsensitive), "Debian" },
132 { QRegExp("((SU)|(Nov)|(SLE)).*64", Qt::CaseInsensitive), "OpenSUSE_64" },
133 { QRegExp("((SU)|(Nov)|(SLE)).*32", Qt::CaseInsensitive), "OpenSUSE" },
134 { QRegExp("Fe.*64", Qt::CaseInsensitive), "Fedora_64" },
135 { QRegExp("Fe.*32", Qt::CaseInsensitive), "Fedora" },
136 { QRegExp("((Gen)|(Sab)).*64", Qt::CaseInsensitive), "Gentoo_64" },
137 { QRegExp("((Gen)|(Sab)).*32", Qt::CaseInsensitive), "Gentoo" },
138 { QRegExp("((Man)|(Mag)).*64", Qt::CaseInsensitive), "Mandriva_64" },
139 { QRegExp("((Man)|(Mag)).*32", Qt::CaseInsensitive), "Mandriva" },
140 { QRegExp("((Red)|(rhel)|(cen)).*64", Qt::CaseInsensitive), "RedHat_64" },
141 { QRegExp("((Red)|(rhel)|(cen)).*32", Qt::CaseInsensitive), "RedHat" },
142 { QRegExp("Tur.*64", Qt::CaseInsensitive), "Turbolinux_64" },
143 { QRegExp("Tur.*32", Qt::CaseInsensitive), "Turbolinux" },
144 { QRegExp("(Ub)|(Min).*64", Qt::CaseInsensitive), "Ubuntu_64" },
145 { QRegExp("(Ub)|(Min).*32", Qt::CaseInsensitive), "Ubuntu" },
146 { QRegExp("Xa.*64", Qt::CaseInsensitive), "Xandros_64" },
147 { QRegExp("Xa.*32", Qt::CaseInsensitive), "Xandros" },
148 { QRegExp("((Or)|(oel)|(ol)).*64", Qt::CaseInsensitive), "Oracle_64" },
149 { QRegExp("((Or)|(oel)|(ol)).*32", Qt::CaseInsensitive), "Oracle" },
150 { QRegExp("Knoppix", Qt::CaseInsensitive), "Linux26" },
151 { QRegExp("Dsl", Qt::CaseInsensitive), "Linux24" },
152 { QRegExp("((Lin)|(lnx)).*2.?2", Qt::CaseInsensitive), "Linux22" },
153 { QRegExp("((Lin)|(lnx)).*2.?4.*64", Qt::CaseInsensitive), "Linux24_64" },
154 { QRegExp("((Lin)|(lnx)).*2.?4.*32", Qt::CaseInsensitive), "Linux24" },
155 { QRegExp("((((Lin)|(lnx)).*2.?6)|(LFS)).*64", Qt::CaseInsensitive), "Linux26_64" },
156 { QRegExp("((((Lin)|(lnx)).*2.?6)|(LFS)).*32", Qt::CaseInsensitive), "Linux26" },
157 { QRegExp("((Lin)|(lnx)).*64", Qt::CaseInsensitive), "Linux26_64" },
158 { QRegExp("((Lin)|(lnx)).*32", Qt::CaseInsensitive), "Linux26" },
159
160 /* Other: */
161 { QRegExp("L4", Qt::CaseInsensitive), "L4" },
162 { QRegExp("((Fr.*B)|(fbsd)).*64", Qt::CaseInsensitive), "FreeBSD_64" },
163 { QRegExp("((Fr.*B)|(fbsd)).*32", Qt::CaseInsensitive), "FreeBSD" },
164 { QRegExp("Op.*B.*64", Qt::CaseInsensitive), "OpenBSD_64" },
165 { QRegExp("Op.*B.*32", Qt::CaseInsensitive), "OpenBSD" },
166 { QRegExp("Ne.*B.*64", Qt::CaseInsensitive), "NetBSD_64" },
167 { QRegExp("Ne.*B.*32", Qt::CaseInsensitive), "NetBSD" },
168 { QRegExp("Net", Qt::CaseInsensitive), "Netware" },
169 { QRegExp("Rocki", Qt::CaseInsensitive), "JRockitVE" },
170 { QRegExp("bs[23]{0,1}-", Qt::CaseInsensitive), "VBoxBS_64" }, /* bootsector tests */
171 { QRegExp("Ot", Qt::CaseInsensitive), "Other" },
172};
173
174UIWizardNewVMPage1::UIWizardNewVMPage1(const QString &strGroup)
175 : m_strGroup(strGroup)
176{
177 CHost host = vboxGlobal().host();
178 m_fSupportsHWVirtEx = host.GetProcessorFeature(KProcessorFeature_HWVirtEx);
179 m_fSupportsLongMode = host.GetProcessorFeature(KProcessorFeature_LongMode);
180}
181
182void UIWizardNewVMPage1::onNameChanged(QString strNewName)
183{
184 /* Do not forget about achitecture bits, if not yet specified: */
185 if (!strNewName.contains("32") && !strNewName.contains("64"))
186 strNewName += ARCH_BITS == 64 && m_fSupportsHWVirtEx && m_fSupportsLongMode ? "64" : "32";
187
188 /* Search for a matching OS type based on the string the user typed already. */
189 for (size_t i = 0; i < RT_ELEMENTS(gs_OSTypePattern); ++i)
190 if (strNewName.contains(gs_OSTypePattern[i].pattern))
191 {
192 m_pNameAndSystemEditor->blockSignals(true);
193 m_pNameAndSystemEditor->setType(vboxGlobal().vmGuestOSType(gs_OSTypePattern[i].pcstId));
194 m_pNameAndSystemEditor->blockSignals(false);
195 break;
196 }
197}
198
199void UIWizardNewVMPage1::onOsTypeChanged()
200{
201 /* If the user manually edited the OS type, we didn't want our automatic OS type guessing anymore.
202 * So simply disconnect the text-edit signal. */
203 m_pNameAndSystemEditor->disconnect(SIGNAL(sigNameChanged(const QString &)), thisImp(), SLOT(sltNameChanged(const QString &)));
204}
205
206bool UIWizardNewVMPage1::machineFolderCreated()
207{
208 return !m_strMachineFolder.isEmpty();
209}
210
211bool UIWizardNewVMPage1::createMachineFolder()
212{
213 /* Cleanup previosly created folder if any: */
214 if (machineFolderCreated() && !cleanupMachineFolder())
215 {
216 msgCenter().cannotRemoveMachineFolder(m_strMachineFolder, thisImp());
217 return false;
218 }
219
220 /* Get VBox: */
221 CVirtualBox vbox = vboxGlobal().virtualBox();
222 /* Get default machine folder: */
223 const QString strDefaultMachineFolder = vbox.GetSystemProperties().GetDefaultMachineFolder();
224 /* Compose machine filename: */
225 const QString strMachineFilePath = vbox.ComposeMachineFilename(m_pNameAndSystemEditor->name(),
226 m_strGroup,
227 QString(),
228 strDefaultMachineFolder);
229 /* Compose machine folder/basename: */
230 const QFileInfo fileInfo(strMachineFilePath);
231 const QString strMachineFolder = fileInfo.absolutePath();
232 const QString strMachineBaseName = fileInfo.completeBaseName();
233
234 /* Make sure that folder doesn't exists: */
235 if (QDir(strMachineFolder).exists())
236 {
237 msgCenter().cannotRewriteMachineFolder(strMachineFolder, thisImp());
238 return false;
239 }
240
241 /* Try to create new folder (and it's predecessors): */
242 bool fMachineFolderCreated = QDir().mkpath(strMachineFolder);
243 if (!fMachineFolderCreated)
244 {
245 msgCenter().cannotCreateMachineFolder(strMachineFolder, thisImp());
246 return false;
247 }
248
249 /* Initialize fields: */
250 m_strMachineFolder = strMachineFolder;
251 m_strMachineBaseName = strMachineBaseName;
252 return true;
253}
254
255bool UIWizardNewVMPage1::cleanupMachineFolder()
256{
257 /* Make sure folder was previosly created: */
258 if (m_strMachineFolder.isEmpty())
259 return false;
260 /* Try to cleanup folder (and it's predecessors): */
261 bool fMachineFolderRemoved = QDir().rmpath(m_strMachineFolder);
262 /* Reset machine folder value: */
263 if (fMachineFolderRemoved)
264 m_strMachineFolder = QString();
265 /* Return cleanup result: */
266 return fMachineFolderRemoved;
267}
268
269UIWizardNewVMPageBasic1::UIWizardNewVMPageBasic1(const QString &strGroup)
270 : UIWizardNewVMPage1(strGroup)
271{
272 /* Create widgets: */
273 QVBoxLayout *pMainLayout = new QVBoxLayout(this);
274 {
275 m_pLabel = new QIRichTextLabel(this);
276 m_pNameAndSystemEditor = new UINameAndSystemEditor(this);
277 pMainLayout->addWidget(m_pLabel);
278 pMainLayout->addWidget(m_pNameAndSystemEditor);
279 pMainLayout->addStretch();
280 }
281
282 /* Setup connections: */
283 connect(m_pNameAndSystemEditor, SIGNAL(sigNameChanged(const QString &)), this, SLOT(sltNameChanged(const QString &)));
284 connect(m_pNameAndSystemEditor, SIGNAL(sigOsTypeChanged()), this, SLOT(sltOsTypeChanged()));
285
286 /* Register fields: */
287 registerField("name*", m_pNameAndSystemEditor, "name", SIGNAL(sigNameChanged(const QString &)));
288 registerField("type", m_pNameAndSystemEditor, "type", SIGNAL(sigOsTypeChanged()));
289 registerField("machineFolder", this, "machineFolder");
290 registerField("machineBaseName", this, "machineBaseName");
291}
292
293void UIWizardNewVMPageBasic1::sltNameChanged(const QString &strNewName)
294{
295 /* Call to base-class: */
296 onNameChanged(strNewName);
297}
298
299void UIWizardNewVMPageBasic1::sltOsTypeChanged()
300{
301 /* Call to base-class: */
302 onOsTypeChanged();
303}
304
305void UIWizardNewVMPageBasic1::retranslateUi()
306{
307 /* Translate page: */
308 setTitle(UIWizardNewVM::tr("Name and operating system"));
309
310 /* Translate widgets: */
311 m_pLabel->setText(UIWizardNewVM::tr("Please choose a descriptive name for the new virtual machine "
312 "and select the type of operating system you intend to install on it. "
313 "The name you choose will be used throughout VirtualBox "
314 "to identify this machine."));
315}
316
317void UIWizardNewVMPageBasic1::initializePage()
318{
319 /* Translate page: */
320 retranslateUi();
321}
322
323void UIWizardNewVMPageBasic1::cleanupPage()
324{
325 /* Cleanup: */
326 cleanupMachineFolder();
327 /* Call to base-class: */
328 UIWizardPage::cleanupPage();
329}
330
331bool UIWizardNewVMPageBasic1::validatePage()
332{
333 /* Try to create machine folder: */
334 return createMachineFolder();
335}
336
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