VirtualBox

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

Last change on this file since 47053 was 47053, checked in by vboxsync, 12 years ago

FE/Qt: Grok Win2k* VM names to Win2k* guest types in the VM creation wizard.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 12.7 KB
Line 
1/* $Id: UIWizardNewVMPageBasic1.cpp 47053 2013-07-09 12:20:06Z vboxsync $ */
2/** @file
3 *
4 * VBox frontends: Qt4 GUI ("VirtualBox"):
5 * UIWizardNewVMPageBasic1 class implementation
6 */
7
8/*
9 * Copyright (C) 2006-2012 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20/* Qt includes: */
21#include <QDir>
22#include <QVBoxLayout>
23#include <QHBoxLayout>
24#include <QLineEdit>
25
26/* GUI includes: */
27#include "UIWizardNewVMPageBasic1.h"
28#include "UIWizardNewVM.h"
29#include "UIMessageCenter.h"
30#include "UINameAndSystemEditor.h"
31#include "QIRichTextLabel.h"
32
33/* COM includes: */
34#include "CSystemProperties.h"
35
36/* Defines some patterns to guess the right OS type. Should be in sync with
37 * VirtualBox-settings-common.xsd in Main. The list is sorted by priority. The
38 * first matching string found, will be used. */
39struct osTypePattern
40{
41 QRegExp pattern;
42 const char *pcstId;
43};
44
45static const osTypePattern gs_OSTypePattern[] =
46{
47 /* DOS: */
48 { QRegExp("DOS", Qt::CaseInsensitive), "DOS" },
49
50 /* Windows: */
51 { QRegExp("Wi.*98", Qt::CaseInsensitive), "Windows98" },
52 { QRegExp("Wi.*95", Qt::CaseInsensitive), "Windows95" },
53 { QRegExp("Wi.*Me", Qt::CaseInsensitive), "WindowsMe" },
54 { QRegExp("(Wi.*NT)|(NT4)", Qt::CaseInsensitive), "WindowsNT4" },
55 { QRegExp("((Wi.*XP)|(\\bXP\\b)).*64", Qt::CaseInsensitive), "WindowsXP_64" },
56 { QRegExp("(Wi.*XP)|(\\bXP\\b)", Qt::CaseInsensitive), "WindowsXP" },
57 { QRegExp("((Wi.*2003)|(W2K3)|(Win2K3)).*64", Qt::CaseInsensitive), "Windows2003_64" },
58 { QRegExp("(Wi.*2003)|(W2K3)|(Win2K3)", Qt::CaseInsensitive), "Windows2003" },
59 { QRegExp("((Wi.*V)|(Vista)).*64", Qt::CaseInsensitive), "WindowsVista_64" },
60 { QRegExp("(Wi.*V)|(Vista)", Qt::CaseInsensitive), "WindowsVista" },
61 { QRegExp("(Wi.*2012)|(W2K12)|(Win2K12)", Qt::CaseInsensitive), "Windows2012_64" },
62 { QRegExp("((Wi.*2008)|(W2K8)|(Win2k8)).*64", Qt::CaseInsensitive), "Windows2008_64" },
63 { QRegExp("(Wi.*2008)|(W2K8)|(Win2K8)", Qt::CaseInsensitive), "Windows2008" },
64 { QRegExp("(Wi.*2000)|(W2K)|(Win2K)", Qt::CaseInsensitive), "Windows2000" },
65 { QRegExp("(Wi.*7.*64)|(W7.*64)", Qt::CaseInsensitive), "Windows7_64" },
66 { QRegExp("(Wi.*7)|(W7)", Qt::CaseInsensitive), "Windows7" },
67 { QRegExp("(Wi.*8.*1.*64)|(W8.*64)", Qt::CaseInsensitive), "Windows81_64" },
68 { QRegExp("(Wi.*8.*1)|(W8)", Qt::CaseInsensitive), "Windows81" },
69 { QRegExp("(Wi.*8.*64)|(W8.*64)", Qt::CaseInsensitive), "Windows8_64" },
70 { QRegExp("(Wi.*8)|(W8)", Qt::CaseInsensitive), "Windows8" },
71 { QRegExp("Wi.*3", Qt::CaseInsensitive), "Windows31" },
72 { QRegExp("Wi", Qt::CaseInsensitive), "WindowsXP" },
73
74 /* Solaris: */
75 { QRegExp("So.*11", Qt::CaseInsensitive), "Solaris11_64" },
76 { QRegExp("((Op.*So)|(os20[01][0-9])|(So.*10)|(India)|(Neva)).*64", Qt::CaseInsensitive), "OpenSolaris_64" },
77 { QRegExp("(Op.*So)|(os20[01][0-9])|(So.*10)|(India)|(Neva)", Qt::CaseInsensitive), "OpenSolaris" },
78 { QRegExp("So.*64", Qt::CaseInsensitive), "Solaris_64" },
79 { QRegExp("So", Qt::CaseInsensitive), "Solaris" },
80
81 /* OS/2: */
82 { QRegExp("OS[/|!-]{,1}2.*W.*4.?5", Qt::CaseInsensitive), "OS2Warp45" },
83 { QRegExp("OS[/|!-]{,1}2.*W.*4", Qt::CaseInsensitive), "OS2Warp4" },
84 { QRegExp("OS[/|!-]{,1}2.*W", Qt::CaseInsensitive), "OS2Warp3" },
85 { QRegExp("(OS[/|!-]{,1}2.*e)|(eCS.*)", Qt::CaseInsensitive), "OS2eCS" },
86 { QRegExp("OS[/|!-]{,1}2", Qt::CaseInsensitive), "OS2" },
87
88 /* Code names for Linux distributions: */
89 { QRegExp("((edgy)|(feisty)|(gutsy)|(hardy)|(intrepid)|(jaunty)|(karmic)|(lucid)|(maverick)|(natty)|(oneiric)|(precise)|(quantal)|(raring)).*64", Qt::CaseInsensitive), "Ubuntu_64" },
90 { QRegExp("(edgy)|(feisty)|(gutsy)|(hardy)|(intrepid)|(jaunty)|(karmic)|(lucid)|(maverick)|(natty)|(oneiric)|(precise)|(quantal)|(raring)", Qt::CaseInsensitive), "Ubuntu" },
91 { QRegExp("((sarge)|(etch)|(lenny)|(squeeze)|(wheezy)|(jessie)|(sid)).*64", Qt::CaseInsensitive), "Debian_64" },
92 { QRegExp("(sarge)|(etch)|(lenny)|(squeeze)|(wheezy)|(jessie)|(sid)", Qt::CaseInsensitive), "Debian" },
93 { QRegExp("((moonshine)|(werewolf)|(sulphur)|(cambridge)|(leonidas)|(constantine)|(goddard)|(laughlin)|(lovelock)|(verne)|(beefy)|(spherical)).*64", Qt::CaseInsensitive), "Fedora_64" },
94 { QRegExp("(moonshine)|(werewolf)|(sulphur)|(cambridge)|(leonidas)|(constantine)|(goddard)|(laughlin)|(lovelock)|(verne)|(beefy)|(spherical)", Qt::CaseInsensitive), "Fedora" },
95
96 /* Regular names of Linux distributions: */
97 { QRegExp("Arc.*64", Qt::CaseInsensitive), "ArchLinux_64" },
98 { QRegExp("Arc", Qt::CaseInsensitive), "ArchLinux" },
99 { QRegExp("Deb.*64", Qt::CaseInsensitive), "Debian_64" },
100 { QRegExp("Deb", Qt::CaseInsensitive), "Debian" },
101 { QRegExp("((SU)|(Nov)|(SLE)).*64", Qt::CaseInsensitive), "OpenSUSE_64" },
102 { QRegExp("(SU)|(Nov)|(SLE)", Qt::CaseInsensitive), "OpenSUSE" },
103 { QRegExp("Fe.*64", Qt::CaseInsensitive), "Fedora_64" },
104 { QRegExp("Fe", Qt::CaseInsensitive), "Fedora" },
105 { QRegExp("((Gen)|(Sab)).*64", Qt::CaseInsensitive), "Gentoo_64" },
106 { QRegExp("(Gen)|(Sab)", Qt::CaseInsensitive), "Gentoo" },
107 { QRegExp("((Man)|(Mag)).*64", Qt::CaseInsensitive), "Mandriva_64" },
108 { QRegExp("((Man)|(Mag))", Qt::CaseInsensitive), "Mandriva" },
109 { QRegExp("((Red)|(rhel)|(cen)).*64", Qt::CaseInsensitive), "RedHat_64" },
110 { QRegExp("(Red)|(rhel)|(cen)", Qt::CaseInsensitive), "RedHat" },
111 { QRegExp("Tur.*64", Qt::CaseInsensitive), "Turbolinux_64" },
112 { QRegExp("Tur", Qt::CaseInsensitive), "Turbolinux" },
113 { QRegExp("Ub.*64", Qt::CaseInsensitive), "Ubuntu_64" },
114 { QRegExp("Ub", Qt::CaseInsensitive), "Ubuntu" },
115 { QRegExp("Xa.*64", Qt::CaseInsensitive), "Xandros_64" },
116 { QRegExp("Xa", Qt::CaseInsensitive), "Xandros" },
117 { QRegExp("((Or)|(oel)).*64", Qt::CaseInsensitive), "Oracle_64" },
118 { QRegExp("(Or)|(oel)", Qt::CaseInsensitive), "Oracle" },
119 { QRegExp("Knoppix", Qt::CaseInsensitive), "Linux26" },
120 { QRegExp("Dsl", Qt::CaseInsensitive), "Linux24" },
121 { QRegExp("((Li)|(lnx)).*2.?2", Qt::CaseInsensitive), "Linux22" },
122 { QRegExp("((Li)|(lnx)).*2.?4.*64", Qt::CaseInsensitive), "Linux24_64" },
123 { QRegExp("((Li)|(lnx)).*2.?4", Qt::CaseInsensitive), "Linux24" },
124 { QRegExp("((((Li)|(lnx)).*2.?6)|(LFS)).*64", Qt::CaseInsensitive), "Linux26_64" },
125 { QRegExp("(((Li)|(lnx)).*2.?6)|(LFS)", Qt::CaseInsensitive), "Linux26" },
126 { QRegExp("((Li)|(lnx)).*64", Qt::CaseInsensitive), "Linux26_64" },
127 { QRegExp("(Li)|(lnx)", Qt::CaseInsensitive), "Linux26" },
128
129 /* Other: */
130 { QRegExp("L4", Qt::CaseInsensitive), "L4" },
131 { QRegExp("((Fr.*B)|(fbsd)).*64", Qt::CaseInsensitive), "FreeBSD_64" },
132 { QRegExp("(Fr.*B)|(fbsd)", Qt::CaseInsensitive), "FreeBSD" },
133 { QRegExp("Op.*B.*64", Qt::CaseInsensitive), "OpenBSD_64" },
134 { QRegExp("Op.*B", Qt::CaseInsensitive), "OpenBSD" },
135 { QRegExp("Ne.*B.*64", Qt::CaseInsensitive), "NetBSD_64" },
136 { QRegExp("Ne.*B", Qt::CaseInsensitive), "NetBSD" },
137 { QRegExp("QN", Qt::CaseInsensitive), "QNX" },
138 { QRegExp("((Mac)|(Tig)|(Leop)|(osx)).*64", Qt::CaseInsensitive), "MacOS_64" },
139 { QRegExp("(Mac)|(Tig)|(Leop)|(osx)", Qt::CaseInsensitive), "MacOS" },
140 { QRegExp("Net", Qt::CaseInsensitive), "Netware" },
141 { QRegExp("Rocki", Qt::CaseInsensitive), "JRockitVE" },
142 { QRegExp("Ot", Qt::CaseInsensitive), "Other" },
143};
144
145UIWizardNewVMPage1::UIWizardNewVMPage1(const QString &strGroup)
146 : m_strGroup(strGroup)
147{
148}
149
150void UIWizardNewVMPage1::onNameChanged(const QString &strNewName)
151{
152 /* Search for a matching OS type based on the string the user typed already. */
153 for (size_t i = 0; i < RT_ELEMENTS(gs_OSTypePattern); ++i)
154 if (strNewName.contains(gs_OSTypePattern[i].pattern))
155 {
156 m_pNameAndSystemEditor->blockSignals(true);
157 m_pNameAndSystemEditor->setType(vboxGlobal().vmGuestOSType(gs_OSTypePattern[i].pcstId));
158 m_pNameAndSystemEditor->blockSignals(false);
159 break;
160 }
161}
162
163void UIWizardNewVMPage1::onOsTypeChanged()
164{
165 /* If the user manually edited the OS type, we didn't want our automatic OS type guessing anymore.
166 * So simply disconnect the text-edit signal. */
167 m_pNameAndSystemEditor->disconnect(SIGNAL(sigNameChanged(const QString &)), thisImp(), SLOT(sltNameChanged(const QString &)));
168}
169
170bool UIWizardNewVMPage1::machineFolderCreated()
171{
172 return !m_strMachineFolder.isEmpty();
173}
174
175bool UIWizardNewVMPage1::createMachineFolder()
176{
177 /* Cleanup previosly created folder if any: */
178 if (machineFolderCreated() && !cleanupMachineFolder())
179 {
180 msgCenter().cannotRemoveMachineFolder(m_strMachineFolder, thisImp());
181 return false;
182 }
183
184 /* Get VBox: */
185 CVirtualBox vbox = vboxGlobal().virtualBox();
186 /* Get default machines directory: */
187 QString strDefaultMachinesFolder = vbox.GetSystemProperties().GetDefaultMachineFolder();
188 /* Compose machine filename: */
189 QString strMachineFilename = vbox.ComposeMachineFilename(m_pNameAndSystemEditor->name(), m_strGroup, QString::null, strDefaultMachinesFolder);
190 /* Compose machine folder/basename: */
191 QFileInfo fileInfo(strMachineFilename);
192 QString strMachineFolder = fileInfo.absolutePath();
193 QString strMachineBaseName = fileInfo.completeBaseName();
194
195 /* Make sure that folder doesn't exists: */
196 if (QDir(strMachineFolder).exists())
197 {
198 msgCenter().cannotRewriteMachineFolder(strMachineFolder, thisImp());
199 return false;
200 }
201
202 /* Try to create new folder (and it's predecessors): */
203 bool fMachineFolderCreated = QDir().mkpath(strMachineFolder);
204 if (!fMachineFolderCreated)
205 {
206 msgCenter().cannotCreateMachineFolder(strMachineFolder, thisImp());
207 return false;
208 }
209
210 /* Initialize fields: */
211 m_strMachineFolder = strMachineFolder;
212 m_strMachineBaseName = strMachineBaseName;
213 return true;
214}
215
216bool UIWizardNewVMPage1::cleanupMachineFolder()
217{
218 /* Make sure folder was previosly created: */
219 if (m_strMachineFolder.isEmpty())
220 return false;
221 /* Try to cleanup folder (and it's predecessors): */
222 bool fMachineFolderRemoved = QDir().rmpath(m_strMachineFolder);
223 /* Reset machine folder value: */
224 if (fMachineFolderRemoved)
225 m_strMachineFolder = QString();
226 /* Return cleanup result: */
227 return fMachineFolderRemoved;
228}
229
230UIWizardNewVMPageBasic1::UIWizardNewVMPageBasic1(const QString &strGroup)
231 : UIWizardNewVMPage1(strGroup)
232{
233 /* Create widgets: */
234 QVBoxLayout *pMainLayout = new QVBoxLayout(this);
235 {
236 m_pLabel = new QIRichTextLabel(this);
237 m_pNameAndSystemEditor = new UINameAndSystemEditor(this);
238 pMainLayout->addWidget(m_pLabel);
239 pMainLayout->addWidget(m_pNameAndSystemEditor);
240 pMainLayout->addStretch();
241 }
242
243 /* Setup connections: */
244 connect(m_pNameAndSystemEditor, SIGNAL(sigNameChanged(const QString &)), this, SLOT(sltNameChanged(const QString &)));
245 connect(m_pNameAndSystemEditor, SIGNAL(sigOsTypeChanged()), this, SLOT(sltOsTypeChanged()));
246
247 /* Register fields: */
248 registerField("name*", m_pNameAndSystemEditor, "name", SIGNAL(sigNameChanged(const QString &)));
249 registerField("type", m_pNameAndSystemEditor, "type", SIGNAL(sigOsTypeChanged()));
250 registerField("machineFolder", this, "machineFolder");
251 registerField("machineBaseName", this, "machineBaseName");
252}
253
254void UIWizardNewVMPageBasic1::sltNameChanged(const QString &strNewName)
255{
256 /* Call to base-class: */
257 onNameChanged(strNewName);
258}
259
260void UIWizardNewVMPageBasic1::sltOsTypeChanged()
261{
262 /* Call to base-class: */
263 onOsTypeChanged();
264}
265
266void UIWizardNewVMPageBasic1::retranslateUi()
267{
268 /* Translate page: */
269 setTitle(UIWizardNewVM::tr("Name and operating system"));
270
271 /* Translate widgets: */
272 m_pLabel->setText(UIWizardNewVM::tr("Please choose a descriptive name for the new virtual machine "
273 "and select the type of operating system you intend to install on it. "
274 "The name you choose will be used throughout VirtualBox "
275 "to identify this machine."));
276}
277
278void UIWizardNewVMPageBasic1::initializePage()
279{
280 /* Translate page: */
281 retranslateUi();
282}
283
284void UIWizardNewVMPageBasic1::cleanupPage()
285{
286 /* Cleanup: */
287 cleanupMachineFolder();
288 /* Call to base-class: */
289 UIWizardPage::cleanupPage();
290}
291
292bool UIWizardNewVMPageBasic1::validatePage()
293{
294 /* Try to create machine folder: */
295 return createMachineFolder();
296}
297
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