~ubuntu-branches/ubuntu/raring/virtualbox-ose/raring

« back to all changes in this revision

Viewing changes to src/VBox/Frontends/VirtualBox/src/VBoxVMSettingsFD.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2009-12-18 16:44:29 UTC
  • mfrom: (0.3.3 upstream) (0.4.6 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091218164429-jd34ccexpv5na11a
Tags: 3.1.2-dfsg-1ubuntu1
* Merge from Debian unstable (LP: #498219), remaining changes:
  - Disable update action
    - debian/patches/u01-disable-update-action.dpatch
  - VirtualBox should go in Accessories, not in System tools (LP: #288590)
    - debian/virtualbox-ose-qt.files/virtualbox-ose.desktop
  - Add Apport hook
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Add Launchpad integration
    - debian/control
    - debian/lpi-bug.xpm
    - debian/patches/u02-lp-integration.dpatch
* Fixes the following bugs:
  - Kernel module fails to build with Linux >= 2.6.32 (LP: #474625)
  - X.Org drivers need to be rebuilt against X-Server 1.7 (LP: #495935)
  - The *-source packages try to build the kernel modules even though the
    kernel headers aren't available (LP: #473334)
* Replace *-source packages with transitional packages for *-dkms.
* Adapt u01-disable-update-action.dpatch and u02-lp-integration.dpatch for
  new upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/** @file
2
 
 *
3
 
 * VBox frontends: Qt4 GUI ("VirtualBox"):
4
 
 * VBoxVMSettingsFD class implementation
5
 
 */
6
 
 
7
 
/*
8
 
 * Copyright (C) 2006-2009 Sun Microsystems, Inc.
9
 
 *
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.
17
 
 *
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.
21
 
 */
22
 
 
23
 
#include "VBoxVMSettingsFD.h"
24
 
#include "VBoxGlobal.h"
25
 
#include "VBoxProblemReporter.h"
26
 
#include "QIWidgetValidator.h"
27
 
#include "VBoxMediaManagerDlg.h"
28
 
 
29
 
#include <QFileInfo>
30
 
 
31
 
VBoxVMSettingsFD::VBoxVMSettingsFD()
32
 
    : mValidator (0)
33
 
    , mLastSelected (0)
34
 
{
35
 
    /* Apply UI decorations */
36
 
    Ui::VBoxVMSettingsFD::setupUi (this);
37
 
 
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()));
44
 
 
45
 
    /* Setup iconsets */
46
 
    mTbIsoFD->setIcon (VBoxGlobal::iconSet (":/select_file_16px.png",
47
 
                                            ":/select_file_dis_16px.png"));
48
 
 
49
 
    /* Setup dialog */
50
 
    mCbIsoFD->setType (VBoxDefs::MediaType_Floppy);
51
 
 
52
 
    mLastSelected = mRbHostFD;
53
 
    /* Applying language settings */
54
 
    retranslateUi();
55
 
}
56
 
 
57
 
void VBoxVMSettingsFD::getFrom (const CMachine &aMachine)
58
 
{
59
 
    mMachine = aMachine;
60
 
 
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());
65
 
    mCbHostFD->clear();
66
 
 
67
 
    for (int id = 0; id < coll.size(); ++id)
68
 
    {
69
 
        CHostFloppyDrive hostFloppy = coll[id];
70
 
        /** @todo set icon? */
71
 
        QString name = hostFloppy.GetName();
72
 
        QString description = hostFloppy.GetDescription();
73
 
        QString fullName = description.isEmpty() ?
74
 
            name :
75
 
            QString ("%1 (%2)").arg (description, name);
76
 
        mCbHostFD->insertItem (id, fullName);
77
 
        mHostFDs [id] = hostFloppy;
78
 
    }
79
 
 
80
 
    CFloppyDrive floppy = aMachine.GetFloppyDrive();
81
 
    switch (floppy.GetState())
82
 
    {
83
 
        case KDriveState_HostDriveCaptured:
84
 
        {
85
 
            CHostFloppyDrive drv = floppy.GetHostDrive();
86
 
            QString name = drv.GetName();
87
 
            QString description = drv.GetDescription();
88
 
            QString fullName = description.isEmpty() ?
89
 
                name :
90
 
                QString ("%1 (%2)").arg (description, name);
91
 
            if (vboxGlobal().virtualBox().GetHost().FindHostFloppyDrive (name).isNull())
92
 
            {
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);
97
 
            }
98
 
            else
99
 
            {
100
 
                /* This will select the correct item from the prepared list. */
101
 
                mCbHostFD->setCurrentIndex (mCbHostFD->findText (fullName));
102
 
            }
103
 
            mRbHostFD->setChecked (true);
104
 
            mRbHostFD->setAutoExclusive (true);
105
 
            mRbIsoFD->setAutoExclusive (true);
106
 
            break;
107
 
        }
108
 
        case KDriveState_ImageMounted:
109
 
        {
110
 
            CFloppyImage img = floppy.GetImage();
111
 
            QString src = img.GetLocation();
112
 
            AssertMsg (!src.isNull(), ("Image file must not be null"));
113
 
            QFileInfo fi (src);
114
 
            mRbIsoFD->setChecked (true);
115
 
            mUuidIsoFD = QString (img.GetId());
116
 
            mRbHostFD->setAutoExclusive (true);
117
 
            mRbIsoFD->setAutoExclusive (true);
118
 
            break;
119
 
        }
120
 
        case KDriveState_NotMounted:
121
 
        {
122
 
            mGbFD->setChecked (false);
123
 
            mRbHostFD->setAutoExclusive (false);
124
 
            mRbIsoFD->setAutoExclusive (false);
125
 
            break;
126
 
        }
127
 
        default:
128
 
            AssertMsgFailed (("invalid floppy state: %d\n", floppy.GetState()));
129
 
    }
130
 
 
131
 
    mCbIsoFD->setMachineId (mMachine.GetId());
132
 
    mCbIsoFD->setCurrentItem (mUuidIsoFD);
133
 
    if (!vboxGlobal().isMediaEnumerationStarted())
134
 
        vboxGlobal().startEnumeratingMedia();
135
 
    else
136
 
        mCbIsoFD->refresh();
137
 
 
138
 
    if (mValidator)
139
 
        mValidator->revalidate();
140
 
}
141
 
 
142
 
void VBoxVMSettingsFD::putBackTo()
143
 
{
144
 
    CFloppyDrive floppy = mMachine.GetFloppyDrive();
145
 
    if (!mGbFD->isChecked())
146
 
    {
147
 
        floppy.Unmount();
148
 
    }
149
 
    else if (mRbHostFD->isChecked())
150
 
    {
151
 
        int id = mCbHostFD->currentIndex();
152
 
        Assert (id >= 0);
153
 
        if (id < (int) mHostFDs.count())
154
 
            floppy.CaptureHostDrive (mHostFDs [id]);
155
 
    }
156
 
    else if (mRbIsoFD->isChecked())
157
 
    {
158
 
        Assert (!mUuidIsoFD.isNull());
159
 
        floppy.MountImage (mUuidIsoFD);
160
 
    }
161
 
}
162
 
 
163
 
void VBoxVMSettingsFD::setValidator (QIWidgetValidator *aVal)
164
 
{
165
 
    mValidator = aVal;
166
 
}
167
 
 
168
 
bool VBoxVMSettingsFD::revalidate (QString &aWarning, QString &)
169
 
{
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");
174
 
 
175
 
    return aWarning.isNull();
176
 
}
177
 
 
178
 
void VBoxVMSettingsFD::setOrderAfter (QWidget *aWidget)
179
 
{
180
 
    setTabOrder (aWidget, mGbFD);
181
 
    setTabOrder (mGbFD, mRbHostFD);
182
 
    setTabOrder (mRbHostFD, mCbHostFD);
183
 
    setTabOrder (mCbHostFD, mRbIsoFD);
184
 
    setTabOrder (mRbIsoFD, mCbIsoFD);
185
 
    setTabOrder (mCbIsoFD, mTbIsoFD);
186
 
}
187
 
 
188
 
void VBoxVMSettingsFD::retranslateUi()
189
 
{
190
 
    /* Translate uic generated strings */
191
 
    Ui::VBoxVMSettingsFD::retranslateUi (this);
192
 
}
193
 
 
194
 
void VBoxVMSettingsFD::onGbChange (bool aSwitchedOn)
195
 
{
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);
201
 
 
202
 
    /* Toggle both buttons off when the group box unchecked. */
203
 
    if (!aSwitchedOn)
204
 
    {
205
 
        mLastSelected = mRbIsoFD->isChecked() ? mRbIsoFD : mRbHostFD;
206
 
 
207
 
        mRbHostFD->blockSignals (true);
208
 
        mRbIsoFD->blockSignals (true);
209
 
        mRbHostFD->setChecked (false);
210
 
        mRbIsoFD->setChecked (false);
211
 
        mRbHostFD->blockSignals (false);
212
 
        mRbIsoFD->blockSignals (false);
213
 
    }
214
 
    /* Toggle last checked button on when the group box checked. */
215
 
    else if (!mRbHostFD->isChecked() && !mRbIsoFD->isChecked())
216
 
    {
217
 
        mLastSelected->blockSignals (true);
218
 
        mLastSelected->setChecked (true);
219
 
        mLastSelected->blockSignals (false);
220
 
    }
221
 
 
222
 
    mMountFDChild->setEnabled (aSwitchedOn);
223
 
 
224
 
    onRbChange();
225
 
}
226
 
 
227
 
void VBoxVMSettingsFD::onRbChange()
228
 
{
229
 
    /* Check the 'host' group. */
230
 
    mCbHostFD->setEnabled (mRbHostFD->isChecked());
231
 
 
232
 
    /* Check the 'iso' group. */
233
 
    mCbIsoFD->setEnabled (mRbIsoFD->isChecked());
234
 
    mTbIsoFD->setEnabled (mRbIsoFD->isChecked());
235
 
 
236
 
    onCbChange();
237
 
}
238
 
 
239
 
void VBoxVMSettingsFD::onCbChange()
240
 
{
241
 
    mUuidIsoFD = mGbFD->isChecked() ? mCbIsoFD->id() : QString::null;
242
 
    emit fdChanged();
243
 
    if (mValidator)
244
 
        mValidator->revalidate();
245
 
}
246
 
 
247
 
void VBoxVMSettingsFD::showMediaManager()
248
 
{
249
 
    QString oldId = mUuidIsoFD;
250
 
    VBoxMediaManagerDlg dlg (this);
251
 
 
252
 
    dlg.setup (VBoxDefs::MediaType_Floppy, true /* aDoSelect */,
253
 
               false /* aRefresh */, mMachine, mCbIsoFD->id());
254
 
 
255
 
    QString newId = dlg.exec() == QDialog::Accepted ?
256
 
                  dlg.selectedId() : mCbIsoFD->id();
257
 
    if (oldId != newId)
258
 
    {
259
 
        mUuidIsoFD = newId;
260
 
        mCbIsoFD->setCurrentItem (mUuidIsoFD);
261
 
        emit fdChanged();
262
 
    }
263
 
 
264
 
    mCbIsoFD->setFocus();
265
 
    if (mValidator)
266
 
        mValidator->revalidate();
267
 
}
268