VirtualBox

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

Last change on this file since 50741 was 50741, checked in by vboxsync, 11 years ago

FE/Qt: Added OS name hint for eComStation.

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