3
* VBox frontends: Qt4 GUI ("VirtualBox"):
4
* VBoxVMFirstRunWzd class implementation
8
* Copyright (C) 2008-2009 Sun Microsystems, Inc.
10
* This file is part of VirtualBox Open Source Edition (OSE), as
11
* available from http://www.virtualbox.org. This file is free software;
12
* you can redistribute it and/or modify it under the terms of the GNU
13
* General Public License (GPL) as published by the Free Software
14
* Foundation, in version 2 as it comes in the "COPYING" file of the
15
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
19
* Clara, CA 95054 USA or visit http://www.sun.com if you need
20
* additional information or have any questions.
24
#include "VBoxVMFirstRunWzd.h"
25
#include "VBoxGlobal.h"
26
#include "VBoxProblemReporter.h"
27
#include "VBoxMediaManagerDlg.h"
28
#include "QIWidgetValidator.h"
30
VBoxVMFirstRunWzd::VBoxVMFirstRunWzd (const CMachine &aMachine, QWidget *aParent)
31
: QIWithRetranslateUI <QIAbstractWizard> (aParent)
35
/* Apply UI decorations */
36
Ui::VBoxVMFirstRunWzd::setupUi (this);
38
/* Initialize wizard hdr */
39
initializeWizardHdr();
41
/* Hide unnecessary text labels */
42
CMediumAttachment hda = mMachine.GetMediumAttachment ("IDE Controller", 0, 0);
43
mTextWelcome1->setHidden (hda.isNull());
44
mTextType1->setHidden (hda.isNull());
45
mTextSource1->setHidden (hda.isNull());
46
mTextSummaryHdr1->setHidden (hda.isNull());
47
mTextSummaryFtr1->setHidden (hda.isNull());
48
mTextWelcome2->setHidden (!hda.isNull());
49
mTextType2->setHidden (!hda.isNull());
50
mTextSource2->setHidden (!hda.isNull());
51
mTextSummaryHdr2->setHidden (!hda.isNull());
52
mTextSummaryFtr2->setHidden (!hda.isNull());
55
mCbMedia->setMachineId (mMachine.GetId());
56
mTbVmm->setIcon (VBoxGlobal::iconSet (":/select_file_16px.png", ":/select_file_dis_16px.png"));
57
mValidator = new QIWidgetValidator (mPageMedia, this);
58
connect (mValidator, SIGNAL (validityChanged (const QIWidgetValidator *)),
59
this, SLOT (enableNext (const QIWidgetValidator *)));
60
connect (mValidator, SIGNAL (isValidRequested (QIWidgetValidator *)),
61
this, SLOT (revalidate (QIWidgetValidator *)));
62
connect (mRbCdType, SIGNAL (clicked()), this, SLOT (mediaTypeChanged()));
63
connect (mRbFdType, SIGNAL (clicked()), this, SLOT (mediaTypeChanged()));
64
connect (mTbVmm, SIGNAL (clicked()), this, SLOT (openMediaManager()));
65
mRbCdType->animateClick();
67
/* Revalidate updated page */
68
mValidator->revalidate();
70
/* Initialize wizard ftr */
71
initializeWizardFtr();
76
void VBoxVMFirstRunWzd::retranslateUi()
78
/* Translate uic generated strings */
79
Ui::VBoxVMFirstRunWzd::retranslateUi (this);
81
QWidget *page = mPageStack->currentWidget();
83
if (page == mPageSummary)
86
QString type = mRbCdType->isChecked() ? tr ("CD/DVD-ROM Device") : tr ("Floppy Device");
87
QString source = mCbMedia->currentText();
88
QString summary = QString ("<table>"
89
"<tr><td>%1: </td><td>%2</td></tr>"
90
"<tr><td>%3: </td><td>%4</td></tr>"
92
.arg (tr ("Type", "summary"), type)
93
.arg (tr ("Source", "summary"), source);
94
mTeSummary->setText (summary);
98
void VBoxVMFirstRunWzd::accept()
100
/* Composing default controller name */
101
KStorageBus ctrBus (mRbCdType->isChecked() ? KStorageBus_IDE : KStorageBus_Floppy);
102
LONG ctrPort = mRbCdType->isChecked() ? 1 : 0;
105
/* Search for the first controller of the given type */
106
QVector<CStorageController> ctrs = mMachine.GetStorageControllers();
107
foreach (CStorageController ctr, ctrs)
109
if (ctr.GetBus() == ctrBus)
111
ctrName = ctr.GetName();
115
Assert (!ctrName.isEmpty());
116
/* Mount medium to the predefined port/device */
117
mMachine.MountMedium (ctrName, ctrPort, ctrDevice, mCbMedia->id(), false /* force */);
119
QIAbstractWizard::accept();
121
vboxProblem().cannotRemountMedium (this, mMachine, vboxGlobal().findMedium (mCbMedia->id()), true /* mount? */, false /* retry? */);
124
void VBoxVMFirstRunWzd::revalidate (QIWidgetValidator *aValidator)
126
/* Do individual validations for pages */
127
QWidget *pg = aValidator->widget();
128
bool valid = aValidator->isOtherValid();
130
/* Allow to go to Summary only if non-null medium selected */
131
if (pg == mPageMedia)
132
valid = !vboxGlobal().findMedium (mCbMedia->id()).isNull();
134
aValidator->setOtherValid (valid);
137
void VBoxVMFirstRunWzd::mediaTypeChanged()
139
/* CD/DVD media type selected */
140
if (sender() == mRbCdType)
142
/* Switch media combo-box type to CD/DVD */
143
mCbMedia->setType (VBoxDefs::MediumType_DVD);
145
/* Floppy media type selected */
146
else if (sender() == mRbFdType)
148
/* Switch media combo-box type to Floppy */
149
mCbMedia->setType (VBoxDefs::MediumType_Floppy);
152
/* Update the media combo-box */
153
mCbMedia->repopulate();
155
/* Revalidate updated page */
156
mValidator->revalidate();
159
void VBoxVMFirstRunWzd::openMediaManager()
161
/* Create & open VMM */
162
VBoxMediaManagerDlg dlg (this);
163
dlg.setup (mCbMedia->type(), true /* aDoSelect */);
164
if (dlg.exec() == QDialog::Accepted)
165
mCbMedia->setCurrentItem (dlg.selectedId());
167
/* Revalidate updated page */
168
mValidator->revalidate();
171
void VBoxVMFirstRunWzd::enableNext (const QIWidgetValidator *aValidator)
173
nextButton (aValidator->widget())->setEnabled (aValidator->isValid());
176
void VBoxVMFirstRunWzd::onPageShow()
178
/* Make sure all is properly translated & composed */
181
QWidget *page = mPageStack->currentWidget();
183
if (page == mPageWelcome)
184
nextButton (page)->setFocus();
185
else if (page == mPageMedia)
186
mRbCdType->isChecked() ? mRbCdType->setFocus() :
187
mRbFdType->setFocus();
188
else if (page == mPageSummary)
189
mTeSummary->setFocus();
191
if (page == mPageSummary)
192
finishButton()->setDefault (true);
194
nextButton (page)->setDefault (true);