VirtualBox

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

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

FE/Qt: Fix to r92017: Was misguided by own logic.

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