3
* VBox frontends: Qt4 GUI ("VirtualBox"):
4
* VBoxVMSettingsFD class implementation
8
* Copyright (C) 2006-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.
23
#include "VBoxVMSettingsFD.h"
24
#include "VBoxGlobal.h"
25
#include "VBoxProblemReporter.h"
26
#include "QIWidgetValidator.h"
27
#include "VBoxMediaManagerDlg.h"
31
VBoxVMSettingsFD::VBoxVMSettingsFD()
35
/* Apply UI decorations */
36
Ui::VBoxVMSettingsFD::setupUi (this);
38
/* Setup connections */
39
connect (mGbFD, SIGNAL (toggled (bool)), this, SLOT (onGbChange (bool)));
40
connect (mRbHostFD, SIGNAL (toggled (bool)), this, SLOT (onRbChange()));
41
connect (mRbIsoFD, SIGNAL (toggled (bool)), this, SLOT (onRbChange()));
42
connect (mCbIsoFD, SIGNAL (activated (int)), this, SLOT (onCbChange()));
43
connect (mTbIsoFD, SIGNAL (clicked()), this, SLOT (showMediaManager()));
46
mTbIsoFD->setIcon (VBoxGlobal::iconSet (":/select_file_16px.png",
47
":/select_file_dis_16px.png"));
50
mCbIsoFD->setType (VBoxDefs::MediaType_Floppy);
52
mLastSelected = mRbHostFD;
53
/* Applying language settings */
57
void VBoxVMSettingsFD::getFrom (const CMachine &aMachine)
61
/* Read out the host floppy drive list and prepare the combobox */
62
CHostFloppyDriveVector coll =
63
vboxGlobal().virtualBox().GetHost().GetFloppyDrives();
64
mHostFDs.resize (coll.size());
67
for (int id = 0; id < coll.size(); ++id)
69
CHostFloppyDrive hostFloppy = coll[id];
70
/** @todo set icon? */
71
QString name = hostFloppy.GetName();
72
QString description = hostFloppy.GetDescription();
73
QString fullName = description.isEmpty() ?
75
QString ("%1 (%2)").arg (description, name);
76
mCbHostFD->insertItem (id, fullName);
77
mHostFDs [id] = hostFloppy;
80
CFloppyDrive floppy = aMachine.GetFloppyDrive();
81
switch (floppy.GetState())
83
case KDriveState_HostDriveCaptured:
85
CHostFloppyDrive drv = floppy.GetHostDrive();
86
QString name = drv.GetName();
87
QString description = drv.GetDescription();
88
QString fullName = description.isEmpty() ?
90
QString ("%1 (%2)").arg (description, name);
91
if (vboxGlobal().virtualBox().GetHost().FindHostFloppyDrive (name).isNull())
93
/* If the floppy drive is not currently available, add it to
94
* the end of the list with a special mark */
95
mCbHostFD->insertItem (mCbHostFD->count(), "* " + fullName);
96
mCbHostFD->setCurrentIndex (mCbHostFD->count() - 1);
100
/* This will select the correct item from the prepared list. */
101
mCbHostFD->setCurrentIndex (mCbHostFD->findText (fullName));
103
mRbHostFD->setChecked (true);
104
mRbHostFD->setAutoExclusive (true);
105
mRbIsoFD->setAutoExclusive (true);
108
case KDriveState_ImageMounted:
110
CFloppyImage img = floppy.GetImage();
111
QString src = img.GetLocation();
112
AssertMsg (!src.isNull(), ("Image file must not be null"));
114
mRbIsoFD->setChecked (true);
115
mUuidIsoFD = QString (img.GetId());
116
mRbHostFD->setAutoExclusive (true);
117
mRbIsoFD->setAutoExclusive (true);
120
case KDriveState_NotMounted:
122
mGbFD->setChecked (false);
123
mRbHostFD->setAutoExclusive (false);
124
mRbIsoFD->setAutoExclusive (false);
128
AssertMsgFailed (("invalid floppy state: %d\n", floppy.GetState()));
131
mCbIsoFD->setMachineId (mMachine.GetId());
132
mCbIsoFD->setCurrentItem (mUuidIsoFD);
133
if (!vboxGlobal().isMediaEnumerationStarted())
134
vboxGlobal().startEnumeratingMedia();
139
mValidator->revalidate();
142
void VBoxVMSettingsFD::putBackTo()
144
CFloppyDrive floppy = mMachine.GetFloppyDrive();
145
if (!mGbFD->isChecked())
149
else if (mRbHostFD->isChecked())
151
int id = mCbHostFD->currentIndex();
153
if (id < (int) mHostFDs.count())
154
floppy.CaptureHostDrive (mHostFDs [id]);
156
else if (mRbIsoFD->isChecked())
158
Assert (!mUuidIsoFD.isNull());
159
floppy.MountImage (mUuidIsoFD);
163
void VBoxVMSettingsFD::setValidator (QIWidgetValidator *aVal)
168
bool VBoxVMSettingsFD::revalidate (QString &aWarning, QString &)
170
if (mRbHostFD->isChecked() && mCbHostFD->currentText().isNull())
171
aWarning = tr ("Host floppy drive is not selected");
172
else if (mRbIsoFD->isChecked() && mUuidIsoFD.isNull())
173
aWarning = tr ("Floppy image file is not selected");
175
return aWarning.isNull();
178
void VBoxVMSettingsFD::setOrderAfter (QWidget *aWidget)
180
setTabOrder (aWidget, mGbFD);
181
setTabOrder (mGbFD, mRbHostFD);
182
setTabOrder (mRbHostFD, mCbHostFD);
183
setTabOrder (mCbHostFD, mRbIsoFD);
184
setTabOrder (mRbIsoFD, mCbIsoFD);
185
setTabOrder (mCbIsoFD, mTbIsoFD);
188
void VBoxVMSettingsFD::retranslateUi()
190
/* Translate uic generated strings */
191
Ui::VBoxVMSettingsFD::retranslateUi (this);
194
void VBoxVMSettingsFD::onGbChange (bool aSwitchedOn)
196
/* Toggle auto-exclusiveness on/off to let the buttons be unchecked both in
197
* case of group-box is not checked and exclusively checked in case of
198
* group-box is checked. */
199
mRbHostFD->setAutoExclusive (aSwitchedOn);
200
mRbIsoFD->setAutoExclusive (aSwitchedOn);
202
/* Toggle both buttons off when the group box unchecked. */
205
mLastSelected = mRbIsoFD->isChecked() ? mRbIsoFD : mRbHostFD;
207
mRbHostFD->blockSignals (true);
208
mRbIsoFD->blockSignals (true);
209
mRbHostFD->setChecked (false);
210
mRbIsoFD->setChecked (false);
211
mRbHostFD->blockSignals (false);
212
mRbIsoFD->blockSignals (false);
214
/* Toggle last checked button on when the group box checked. */
215
else if (!mRbHostFD->isChecked() && !mRbIsoFD->isChecked())
217
mLastSelected->blockSignals (true);
218
mLastSelected->setChecked (true);
219
mLastSelected->blockSignals (false);
222
mMountFDChild->setEnabled (aSwitchedOn);
227
void VBoxVMSettingsFD::onRbChange()
229
/* Check the 'host' group. */
230
mCbHostFD->setEnabled (mRbHostFD->isChecked());
232
/* Check the 'iso' group. */
233
mCbIsoFD->setEnabled (mRbIsoFD->isChecked());
234
mTbIsoFD->setEnabled (mRbIsoFD->isChecked());
239
void VBoxVMSettingsFD::onCbChange()
241
mUuidIsoFD = mGbFD->isChecked() ? mCbIsoFD->id() : QString::null;
244
mValidator->revalidate();
247
void VBoxVMSettingsFD::showMediaManager()
249
QString oldId = mUuidIsoFD;
250
VBoxMediaManagerDlg dlg (this);
252
dlg.setup (VBoxDefs::MediaType_Floppy, true /* aDoSelect */,
253
false /* aRefresh */, mMachine, mCbIsoFD->id());
255
QString newId = dlg.exec() == QDialog::Accepted ?
256
dlg.selectedId() : mCbIsoFD->id();
260
mCbIsoFD->setCurrentItem (mUuidIsoFD);
264
mCbIsoFD->setFocus();
266
mValidator->revalidate();