~ubuntu-branches/ubuntu/trusty/virtualbox-ose/trusty

« back to all changes in this revision

Viewing changes to src/VBox/Frontends/VirtualBox/src/wizards/firstrun/VBoxVMFirstRunWzd.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
 * VBoxVMFirstRunWzd class implementation
 
5
 */
 
6
 
 
7
/*
 
8
 * Copyright (C) 2008-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
/* Local includes */
 
24
#include "VBoxVMFirstRunWzd.h"
 
25
#include "VBoxGlobal.h"
 
26
#include "VBoxProblemReporter.h"
 
27
#include "VBoxMediaManagerDlg.h"
 
28
#include "QIWidgetValidator.h"
 
29
 
 
30
VBoxVMFirstRunWzd::VBoxVMFirstRunWzd (const CMachine &aMachine, QWidget *aParent)
 
31
    : QIWithRetranslateUI <QIAbstractWizard> (aParent)
 
32
    , mValidator (0)
 
33
    , mMachine (aMachine)
 
34
{
 
35
    /* Apply UI decorations */
 
36
    Ui::VBoxVMFirstRunWzd::setupUi (this);
 
37
 
 
38
    /* Initialize wizard hdr */
 
39
    initializeWizardHdr();
 
40
 
 
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());
 
53
 
 
54
    /* Media page */
 
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();
 
66
 
 
67
    /* Revalidate updated page */
 
68
    mValidator->revalidate();
 
69
 
 
70
    /* Initialize wizard ftr */
 
71
    initializeWizardFtr();
 
72
 
 
73
    retranslateUi();
 
74
}
 
75
 
 
76
void VBoxVMFirstRunWzd::retranslateUi()
 
77
{
 
78
    /* Translate uic generated strings */
 
79
    Ui::VBoxVMFirstRunWzd::retranslateUi (this);
 
80
 
 
81
    QWidget *page = mPageStack->currentWidget();
 
82
 
 
83
    if (page == mPageSummary)
 
84
    {
 
85
        /* Compose Summary */
 
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:&nbsp;</td><td>%2</td></tr>"
 
90
                                   "<tr><td>%3:&nbsp;</td><td>%4</td></tr>"
 
91
                                   "</table>")
 
92
                                   .arg (tr ("Type", "summary"), type)
 
93
                                   .arg (tr ("Source", "summary"), source);
 
94
        mTeSummary->setText (summary);
 
95
    }
 
96
}
 
97
 
 
98
void VBoxVMFirstRunWzd::accept()
 
99
{
 
100
    /* Composing default controller name */
 
101
    KStorageBus ctrBus (mRbCdType->isChecked() ? KStorageBus_IDE : KStorageBus_Floppy);
 
102
    LONG ctrPort = mRbCdType->isChecked() ? 1 : 0;
 
103
    LONG ctrDevice = 0;
 
104
    QString ctrName;
 
105
    /* Search for the first controller of the given type */
 
106
    QVector<CStorageController> ctrs = mMachine.GetStorageControllers();
 
107
    foreach (CStorageController ctr, ctrs)
 
108
    {
 
109
        if (ctr.GetBus() == ctrBus)
 
110
        {
 
111
            ctrName = ctr.GetName();
 
112
            break;
 
113
        }
 
114
    }
 
115
    Assert (!ctrName.isEmpty());
 
116
    /* Mount medium to the predefined port/device */
 
117
    mMachine.MountMedium (ctrName, ctrPort, ctrDevice, mCbMedia->id(), false /* force */);
 
118
    if (mMachine.isOk())
 
119
        QIAbstractWizard::accept();
 
120
    else
 
121
        vboxProblem().cannotRemountMedium (this, mMachine, vboxGlobal().findMedium (mCbMedia->id()), true /* mount? */, false /* retry? */);
 
122
}
 
123
 
 
124
void VBoxVMFirstRunWzd::revalidate (QIWidgetValidator *aValidator)
 
125
{
 
126
    /* Do individual validations for pages */
 
127
    QWidget *pg = aValidator->widget();
 
128
    bool valid = aValidator->isOtherValid();
 
129
 
 
130
    /* Allow to go to Summary only if non-null medium selected */
 
131
    if (pg == mPageMedia)
 
132
        valid = !vboxGlobal().findMedium (mCbMedia->id()).isNull();
 
133
 
 
134
    aValidator->setOtherValid (valid);
 
135
}
 
136
 
 
137
void VBoxVMFirstRunWzd::mediaTypeChanged()
 
138
{
 
139
    /* CD/DVD media type selected */
 
140
    if (sender() == mRbCdType)
 
141
    {
 
142
        /* Switch media combo-box type to CD/DVD */
 
143
        mCbMedia->setType (VBoxDefs::MediumType_DVD);
 
144
    }
 
145
    /* Floppy media type selected */
 
146
    else if (sender() == mRbFdType)
 
147
    {
 
148
        /* Switch media combo-box type to Floppy */
 
149
        mCbMedia->setType (VBoxDefs::MediumType_Floppy);
 
150
    }
 
151
 
 
152
    /* Update the media combo-box */
 
153
    mCbMedia->repopulate();
 
154
 
 
155
    /* Revalidate updated page */
 
156
    mValidator->revalidate();
 
157
}
 
158
 
 
159
void VBoxVMFirstRunWzd::openMediaManager()
 
160
{
 
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());
 
166
 
 
167
    /* Revalidate updated page */
 
168
    mValidator->revalidate();
 
169
}
 
170
 
 
171
void VBoxVMFirstRunWzd::enableNext (const QIWidgetValidator *aValidator)
 
172
{
 
173
    nextButton (aValidator->widget())->setEnabled (aValidator->isValid());
 
174
}
 
175
 
 
176
void VBoxVMFirstRunWzd::onPageShow()
 
177
{
 
178
    /* Make sure all is properly translated & composed */
 
179
    retranslateUi();
 
180
 
 
181
    QWidget *page = mPageStack->currentWidget();
 
182
 
 
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();
 
190
 
 
191
    if (page == mPageSummary)
 
192
        finishButton()->setDefault (true);
 
193
    else
 
194
        nextButton (page)->setDefault (true);
 
195
}
 
196