VirtualBox

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

Last change on this file since 41587 was 41587, checked in by vboxsync, 13 years ago

FE/Qt: 6227: Decrease GUI build time: Rework COM wrappers generator to create one header per each COM interface. Update all GUI files to use newly generated headers.

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