UINewVMWzd.cpp revision 0ffcd9709275503d939296f40cbaab6e4dd638cd
/* $Id$ */
/** @file
*
* VBox frontends: Qt4 GUI ("VirtualBox"):
* UINewVMWzd class implementation
*/
/*
* Copyright (C) 2006-2010 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/* Global includes */
#include <QDir>
/* Local includes */
#include "UIIconPool.h"
#include "UINewHDWzd.h"
#include "UINewVMWzd.h"
#include "QIFileDialog.h"
#include "VBoxProblemReporter.h"
#include "UIMachineSettingsStorage.h"
/* Globals */
struct osTypePattern
{
const char *pcstId;
};
/* Defines some patterns to guess the right OS type. Should be in sync with
* VirtualBox-settings-common.xsd in Main. The list is sorted by priority. The
* first matching string found, will be used. */
static const osTypePattern gs_OSTypePattern[] =
{
/* Windows */
/* Solaris */
{ QRegExp("((Op.*So)|(os20[01][0-9])|(So.*1[01])|(India)|(Neva)).*64", Qt::CaseInsensitive), "OpenSolaris_64" },
{ QRegExp("(Op.*So)|(os20[01][0-9])|(So.*1[01])|(India)|(Neva)", Qt::CaseInsensitive), "OpenSolaris" },
/* OS/2 */
/* Code names for Linux distributions */
{ QRegExp("((edgy)|(feisty)|(gutsy)|(hardy)|(intrepid)|(jaunty)|(karmic)|(lucid)|(maverick)|(natty)).*64", Qt::CaseInsensitive), "Ubuntu_64" },
{ QRegExp("(edgy)|(feisty)|(gutsy)|(hardy)|(intrepid)|(jaunty)|(karmic)|(lucid)|(maverick)|(natty)", Qt::CaseInsensitive), "Ubuntu" },
{ QRegExp("((sarge)|(etch)|(lenny)|(squeeze)|(wheezy)|(sid)).*64", Qt::CaseInsensitive), "Debian_64" },
{ QRegExp("((moonshine)|(werewolf)|(sulphur)|(cambridge)|(leonidas)|(constantine)|(goddard)|(laughlin)).*64", Qt::CaseInsensitive), "Fedora_64" },
{ QRegExp("(moonshine)|(werewolf)|(sulphur)|(cambridge)|(leonidas)|(constantine)|(goddard)|(laughlin)", Qt::CaseInsensitive), "Fedora" },
/* Regular names of Linux distributions */
/* Other */
};
{
/* Create & add pages */
addPage(new UINewVMWzdPage1);
addPage(new UINewVMWzdPage2);
addPage(new UINewVMWzdPage3);
addPage(new UINewVMWzdPage4);
addPage(new UINewVMWzdPage5);
/* Initial translate */
/* Initial translate all pages */
/* Resize to 'golden ratio' */
#ifdef Q_WS_MAC
/* Assign background image */
assignBackground(":/vmw_new_welcome_bg.png");
#else /* Q_WS_MAC */
/* Assign watermark */
assignWatermark(":/vmw_new_welcome.png");
#endif /* Q_WS_MAC */
}
{
/* Use 'machine' field value from page 5 */
}
void UINewVMWzd::retranslateUi()
{
/* Wizard title */
}
{
/* Decorate page */
}
void UINewVMWzdPage1::retranslateUi()
{
/* Translate uic generated strings */
/* Wizard page 1 title */
"to create a new virtual machine for VirtualBox.</p><p>%1</p>")
.arg(standardHelpText()));
}
void UINewVMWzdPage1::initializePage()
{
/* Fill and translate */
}
{
/* Decorate page */
/* Register 'name' & 'type' fields */
this, SLOT(sltOsTypeChanged()));
/* Setup contents */
}
{
/* Search for a matching OS type based on the string the user typed
* already. */
{
m_pTypeSelector->blockSignals(true);
m_pTypeSelector->blockSignals(false);
break;
}
}
void UINewVMWzdPage2::sltOsTypeChanged()
{
/* If the user manually edited the OS type, we didn't want our automatic OS
* type guessing anymore. So simply disconnect the text edit signal. */
}
void UINewVMWzdPage2::retranslateUi()
{
/* Translate uic generated strings */
/* Wizard page 2 title */
}
void UINewVMWzdPage2::initializePage()
{
/* Fill and translate */
/* 'Name' field should have focus initially */
}
void UINewVMWzdPage2::cleanupPage()
{
}
bool UINewVMWzdPage2::validatePage()
{
return createMachineFolder();
}
bool UINewVMWzdPage2::createMachineFolder()
{
/* Cleanup old folder if present: */
/* Get VBox: */
/* Get default machines directory: */
/* Compose machine filename name: */
QString strMachineFilename = vbox.ComposeMachineFilename(field("name").toString(), strDefaultMachinesFolder);
/* Get machine directory: */
/* Try to create this machine directory (and it's predecessors): */
/* Initialize machine dir value: */
/* Return creation result: */
return fMachineFolderCreated;
}
bool UINewVMWzdPage2::cleanupMachineFolder()
{
/* Return if machine folder was NOT set: */
if (m_strMachineFolder.isEmpty())
return false;
/* Try to cleanup this machine directory (and it's predecessors): */
/* Reset machine dir value: */
/* Return cleanup result: */
return fMachineFolderRemoved;
}
{
return m_strMachineFolder;
}
{
}
{
/* Decorate page */
/* Register 'ram' field */
/* Setup contents */
m_pRamEditor->setValidator(new QIntValidator(m_pRamSlider->minRAM(), m_pRamSlider->maxRAM(), this));
/* Setup page connections */
connect(m_pRamEditor, SIGNAL(textChanged(const QString &)), this, SLOT(ramEditorTextChanged(const QString &)));
/* Initialise page connections */
}
void UINewVMWzdPage3::retranslateUi()
{
/* Translate uic generated strings */
/* Wizard page 3 title */
/* Translate recommended 'ram' field value */
m_pPage3Text2->setText(tr("The recommended base memory size is <b>%1</b> MB.").arg(strRecommendedRAM));
/* Translate minimum & maximum 'ram' field values */
m_pRamMin->setText(QString("%1 %2").arg(m_pRamSlider->minRAM()).arg(VBoxGlobal::tr("MB", "size suffix MBytes=1024 KBytes")));
m_pRamMax->setText(QString("%1 %2").arg(m_pRamSlider->maxRAM()).arg(VBoxGlobal::tr("MB", "size suffix MBytes=1024 KBytes")));
}
void UINewVMWzdPage3::initializePage()
{
/* Fill and translate */
/* Assign recommended 'ram' field value */
/* 'Ram' field should have focus initially */
m_pRamSlider->setFocus();
}
bool UINewVMWzdPage3::isComplete() const
{
/* Check what 'ram' field value feats the bounds */
}
{
/* Update 'ram' field editor connected to slider */
}
{
/* Update 'ram' field slider connected to editor */
}
{
/* Decorate page */
/* Register CMedium class */
/* Register all related 'hardDisk*' fields */
/* Insert shifting spacer */
int wid = m_pDiskCreate->style()->subElementRect(QStyle::SE_RadioButtonIndicator, &options, m_pDiskCreate).width() +
/* Initialise medium-combo-box */
/* Setup medium-manager button */
":/select_file_dis_16px.png"));
/* Setup page connections */
/* Initialise page connections */
}
void UINewVMWzdPage4::retranslateUi()
{
/* Translate uic generated strings */
/* Wizard page 4 title */
/* Translate recommended 'hdd' field value */
m_pPage4Text2->setText (tr ("The recommended size of the boot hard disk is <b>%1</b>.").arg (strRecommendedHDD));
}
void UINewVMWzdPage4::initializePage()
{
/* Fill and translate */
/* Prepare initial choice */
m_pBootHDCnt->setChecked(true);
m_pDiskCreate->setChecked(true);
/* 'Create new hard-disk' should have focus initially */
}
void UINewVMWzdPage4::cleanupPage()
{
/* Clean medium if present */
/* Clean fields of that page */
}
bool UINewVMWzdPage4::isComplete() const
{
/* Check what 'hardDisk' field value feats the rules */
return !m_pBootHDCnt->isChecked() ||
!m_pDiskPresent->isChecked() ||
}
bool UINewVMWzdPage4::validatePage()
{
/* Ensure unused hard-disk is deleted */
if (!m_pBootHDCnt->isChecked() || m_pDiskCreate->isChecked() || (!m_HardDisk.isNull() && m_strHardDiskId != m_HardDisk.GetId()))
/* Ask user about disk-less machine */
return false;
/* Show the New Hard Disk wizard */
return false;
return true;
}
{
if (m_HardDisk.isNull())
return;
bool success = false;
if (m_HardDisk.isOk())
{
vboxProblem().showModalProgressDialog(progress, windowTitle(), ":/progress_media_delete_90px.png", this, true);
success = true;
}
if (success)
else
m_HardDisk.detach();
}
void UINewVMWzdPage4::hardDiskSourceChanged()
{
{
}
else
{
}
}
void UINewVMWzdPage4::getWithFileOpenDialog()
{
/* Get opened vboxMedium id: */
QString strMediumId = vboxGlobal().openMediumWithFileOpenDialog(VBoxDefs::MediumType_HardDisk, this);
if (!strMediumId.isNull())
{
/* Update medium-combo if necessary: */
/* Update hard disk source: */
/* Focus on hard disk combo: */
}
}
{
UINewHDWzd dlg(this);
{
m_pDiskPresent->click();
return true;
}
return false;
}
{
return m_HardDisk;
}
{
}
{
return m_strHardDiskId;
}
{
}
{
return m_strHardDiskName;
}
{
}
{
return m_strHardDiskLocation;
}
{
}
: m_iIDECount(0)
, m_iSATACount(0)
, m_iSCSICount(0)
, m_iFloppyCount(0)
, m_iSASCount(0)
{
/* Decorate page */
/* Register CMachine class */
/* Register 'machine' field */
/* Disable the background painting of the summary widget */
/* Make the summary field read-only */
m_pSummaryText->setReadOnly (true);
}
void UINewVMWzdPage5::retranslateUi()
{
/* Translate uic generated strings */
/* Wizard page 5 title */
/* Compose common summary */
(
"<tr><td><nobr>%1: </nobr></td><td>%2</td></tr>"
"<tr><td><nobr>%3: </nobr></td><td>%4</td></tr>"
"<tr><td><nobr>%5: </nobr></td><td>%6 %7</td></tr>"
)
;
/* Feat summary to 3 lines */
/* Add hard-disk info */
{
"<tr><td><nobr>%8: </nobr></td><td><nobr>%9</nobr></td></tr>")
/* Extend summary to 4 lines */
}
"you press it, a new virtual machine will be created. </p><p>Note "
"that you can alter these and all other setting of the created "
"virtual machine at any time using the <b>Settings</b> dialog "
"accessible through the menu of the main window.</p>")
.arg(VBoxGlobal::replaceHtmlEntities(VBoxGlobal::removeAccelMark(wizard()->buttonText(QWizard::FinishButton)))));
}
void UINewVMWzdPage5::initializePage()
{
/* Fill and translate */
/* Summary should have focus initially */
}
bool UINewVMWzdPage5::validatePage()
{
/* Try to construct machine */
return constructMachine();
}
bool UINewVMWzdPage5::constructMachine()
{
/* OS type */
/* Create a machine with the default settings file location */
{
false); // forceOverwrite
{
return false;
}
/* The FirstRun wizard is to be shown only when we don't attach any hard disk or attach a new (empty) one.
* Selecting an existing hard disk will cancel the wizard. */
}
/* RAM size */
/* VRAM size - select maximum between recommended and minimum for fullscreen */
/* Selecting recommended chipset type */
/* Selecting recommended Audio Controller */
/* Enabling audio by default */
/* Enable the OHCI and EHCI controller by default for new VMs. (new in 2.2) */
if ( !usbController.isNull()
{
usbController.SetEnabled(true);
/*
* USB 2.0 is only available if the proper ExtPack is installed.
*
* Note. Configuring EHCI here and providing messages about
* the missing extpack isn't exactly clean, but it is a
* necessary evil to patch over legacy compatability issues
* introduced by the new distribution model.
*/
static const char *s_pszUsbExtPackName = "Oracle VM VirtualBox Extension Pack";
usbController.SetEnabledEhci(true);
}
/* Create recommended DVD storage controller */
/* Set recommended DVD storage controller type */
/* Create recommended HD storage controller if it's not the same as the DVD controller */
{
/* Set the port count to 1 if SATA is used. */
}
else
{
/* The HD controller is the same as DVD */
}
/* Turn on PAE, if recommended */
/* Set recommended firmware type */
/* Set recommended human interface device types */
if (type.GetRecommendedUsbHid())
{
if (!usbController.isNull())
usbController.SetEnabled(true);
}
if (type.GetRecommendedUsbTablet())
{
if (!usbController.isNull())
usbController.SetEnabled(true);
}
/* Set HPET flag */
/* Set UTC flags */
/* Register the VM prior to attaching hard disks */
{
return false;
}
/* Attach default devices */
{
bool success = false;
{
/* Boot hard disk */
{
if (!m.isOk())
vboxProblem().cannotAttachDevice(m, VBoxDefs::MediumType_HardDisk, field("hardDiskLocation").toString(),
StorageSlot(ctrHdBus, 0, 0), this);
}
if (!m.isOk())
vboxProblem().cannotAttachDevice(m, VBoxDefs::MediumType_DVD, QString(), StorageSlot(ctrDvdBus, 1, 0), this);
if (m.isOk())
{
m.SaveSettings();
if (m.isOk())
success = true;
else
vboxProblem().cannotSaveMachineSettings(m, this);
}
}
if (!success)
{
/* Unregister on failure */
QVector<CMedium> aMedia = m_Machine.Unregister(KCleanupMode_UnregisterOnly); // @todo replace with DetachAllReturnHardDisksOnly once a progress dialog is in place below
{
progress.WaitForCompletion(-1); // @todo do this nicely with a progress dialog, this can delete lots of files
}
return false;
}
}
/* Ensure we don't try to delete a newly created hard disk on success */
return true;
}
{
switch (type)
{
case KStorageBus_IDE:
{
++m_iIDECount;
if (m_iIDECount > 1)
break;
}
case KStorageBus_SATA:
{
++m_iSATACount;
if (m_iSATACount > 1)
break;
}
case KStorageBus_SCSI:
{
++m_iSCSICount;
if (m_iSCSICount > 1)
break;
}
case KStorageBus_Floppy:
{
if (m_iFloppyCount > 1)
break;
}
case KStorageBus_SAS:
{
++m_iSASCount;
if (m_iSASCount > 1)
break;
}
default:
break;
}
return strControllerName;
}
{
return m_Machine;
}
{
}