1 | /**
|
---|
2 | *
|
---|
3 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
4 | * "First Run Wizard" wizard UI include (Qt Designer)
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2007 InnoTek Systemberatung GmbH
|
---|
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 as published by the Free Software Foundation,
|
---|
14 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
15 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
16 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | *
|
---|
18 | * If you received this file as part of a commercial VirtualBox
|
---|
19 | * distribution, then only the terms of your commercial VirtualBox
|
---|
20 | * license agreement apply instead of the previous paragraph.
|
---|
21 | */
|
---|
22 |
|
---|
23 | /****************************************************************************
|
---|
24 | ** ui.h extension file, included from the uic-generated form implementation.
|
---|
25 | **
|
---|
26 | ** If you want to add, delete, or rename functions or slots, use
|
---|
27 | ** Qt Designer to update this file, preserving your code.
|
---|
28 | **
|
---|
29 | ** You should not define a constructor or destructor in this file.
|
---|
30 | ** Instead, write your code in functions called init() and destroy().
|
---|
31 | ** These will automatically be called by the form's constructor and
|
---|
32 | ** destructor.
|
---|
33 | *****************************************************************************/
|
---|
34 |
|
---|
35 | void VBoxVMFirstRunWzd::init()
|
---|
36 | {
|
---|
37 | /* initial wizard setup
|
---|
38 | * --------------------------------------------------------------------- */
|
---|
39 |
|
---|
40 | /* disable help buttons */
|
---|
41 | helpButton()->setShown (false);
|
---|
42 |
|
---|
43 | /* fix tab order to get the proper direction
|
---|
44 | * (originally the focus goes Next/Finish -> Back -> Cancel -> page) */
|
---|
45 | setTabOrder (backButton(), nextButton());
|
---|
46 | setTabOrder (nextButton(), finishButton());
|
---|
47 | setTabOrder (finishButton(), cancelButton());
|
---|
48 |
|
---|
49 | /* setup the label clolors for nice scaling */
|
---|
50 | VBoxGlobal::adoptLabelPixmap (pmWelcome);
|
---|
51 | VBoxGlobal::adoptLabelPixmap (pmType);
|
---|
52 | VBoxGlobal::adoptLabelPixmap (pmSummary);
|
---|
53 |
|
---|
54 | /* media page */
|
---|
55 | cbImage = new VBoxMediaComboBox (bgSource, "cbImage", VBoxDefs::CD);
|
---|
56 | ltVdm->insertWidget (0, cbImage);
|
---|
57 | tbVdm->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
|
---|
58 | "select_file_dis_16px.png"));
|
---|
59 | setTabOrder (cbImage, tbVdm);
|
---|
60 |
|
---|
61 | /* summary page */
|
---|
62 | teSummary = new QITextEdit (pageSummary);
|
---|
63 | teSummary->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Minimum);
|
---|
64 | teSummary->setFrameShape (QTextEdit::NoFrame);
|
---|
65 | teSummary->setReadOnly (TRUE);
|
---|
66 | teSummary->setPaper (pageSummary->backgroundBrush());
|
---|
67 | ltSummary->insertWidget (1, teSummary);
|
---|
68 |
|
---|
69 | /* setup connections and set validation for pages
|
---|
70 | * --------------------------------------------------------------------- */
|
---|
71 |
|
---|
72 | /* media page */
|
---|
73 | wvalType = new QIWidgetValidator (pageType, this);
|
---|
74 | connect (wvalType, SIGNAL (validityChanged (const QIWidgetValidator *)),
|
---|
75 | this, SLOT (enableNext (const QIWidgetValidator *)));
|
---|
76 | connect (wvalType, SIGNAL (isValidRequested (QIWidgetValidator *)),
|
---|
77 | this, SLOT (revalidate (QIWidgetValidator *)));
|
---|
78 |
|
---|
79 | /* filter out Enter keys in order to direct them to the default dlg button */
|
---|
80 | QIKeyFilter *ef = new QIKeyFilter (this, Key_Enter);
|
---|
81 | ef->watchOn (teSummary);
|
---|
82 |
|
---|
83 | /* set initial values
|
---|
84 | * --------------------------------------------------------------------- */
|
---|
85 |
|
---|
86 | /* the finish button on the Summary page is always enabled */
|
---|
87 | setFinishEnabled (pageSummary, true);
|
---|
88 |
|
---|
89 | /* setup minimum width for the sizeHint to be calculated correctly */
|
---|
90 | int wid = widthSpacer->minimumSize().width();
|
---|
91 | txWelcome->setMinimumWidth (wid);
|
---|
92 | txType->setMinimumWidth (wid);
|
---|
93 | txSource->setMinimumWidth (wid);
|
---|
94 | txSummaryHdr->setMinimumWidth (wid);
|
---|
95 | txSummaryFtr->setMinimumWidth (wid);
|
---|
96 |
|
---|
97 | /* media page */
|
---|
98 | rbCdType->animateClick();
|
---|
99 | rbHost->animateClick();
|
---|
100 | }
|
---|
101 |
|
---|
102 |
|
---|
103 | void VBoxVMFirstRunWzd::setup (CMachine &aMachine)
|
---|
104 | {
|
---|
105 | machine = aMachine;
|
---|
106 | }
|
---|
107 |
|
---|
108 |
|
---|
109 | void VBoxVMFirstRunWzd::showEvent (QShowEvent *aEvent)
|
---|
110 | {
|
---|
111 | QDialog::showEvent (aEvent);
|
---|
112 |
|
---|
113 | /* one may think that QWidget::polish() is the right place to do things
|
---|
114 | * below, but apparently, by the time when QWidget::polish() is called,
|
---|
115 | * the widget style & layout are not fully done, at least the minimum
|
---|
116 | * size hint is not properly calculated. Since this is sometimes necessary,
|
---|
117 | * we provide our own "polish" implementation. */
|
---|
118 |
|
---|
119 | layout()->activate();
|
---|
120 |
|
---|
121 | /* resize to the miminum possible size */
|
---|
122 | resize (minimumSize());
|
---|
123 |
|
---|
124 | VBoxGlobal::centerWidget (this, parentWidget());
|
---|
125 | }
|
---|
126 |
|
---|
127 |
|
---|
128 | void VBoxVMFirstRunWzd::showPage (QWidget *aPage)
|
---|
129 | {
|
---|
130 | if (aPage == pageSummary)
|
---|
131 | {
|
---|
132 | QString type =
|
---|
133 | rbCdType->isChecked() ? tr ("CD/DVD-ROM Device") :
|
---|
134 | rbFdType->isChecked() ? tr ("Floppy Device") :
|
---|
135 | QString::null;
|
---|
136 | QString source =
|
---|
137 | rbHost->isChecked() ? tr ("Host Drive %1").arg (cbHost->currentText()) :
|
---|
138 | rbImage->isChecked() ? cbImage->currentText() : QString::null;
|
---|
139 | QString summary =
|
---|
140 | QString (tr ("<table><tr><td>Type:</td><td>%1</td></tr>"
|
---|
141 | "<tr><td>Source:</td><td>%2</td></tr></table>"))
|
---|
142 | .arg (type).arg (source);
|
---|
143 | teSummary->setText (summary);
|
---|
144 | /* set Finish to default */
|
---|
145 | finishButton()->setDefault (true);
|
---|
146 | }
|
---|
147 | else
|
---|
148 | {
|
---|
149 | /* always set Next to default */
|
---|
150 | nextButton()->setDefault (true);
|
---|
151 | }
|
---|
152 |
|
---|
153 | QWizard::showPage (aPage);
|
---|
154 |
|
---|
155 | /* fix focus on the last page. when we go to the last page
|
---|
156 | * having the Next in focus the focus goes to the Cancel
|
---|
157 | * button because when the Next hides Finish is not yet shown. */
|
---|
158 | if (aPage == pageSummary && focusWidget() == cancelButton())
|
---|
159 | finishButton()->setFocus();
|
---|
160 |
|
---|
161 | /* setup focus for individual pages */
|
---|
162 | if (aPage == pageType)
|
---|
163 | bgType->setFocus();
|
---|
164 | else if (aPage == pageSummary)
|
---|
165 | teSummary->setFocus();
|
---|
166 |
|
---|
167 | aPage->layout()->activate();
|
---|
168 | }
|
---|
169 |
|
---|
170 |
|
---|
171 | void VBoxVMFirstRunWzd::accept()
|
---|
172 | {
|
---|
173 | /* CD/DVD Media selected */
|
---|
174 | if (rbCdType->isChecked())
|
---|
175 | {
|
---|
176 | if (rbHost->isChecked())
|
---|
177 | {
|
---|
178 | CHostDVDDrive hostDrive = hostDVDs [cbHost->currentItem()];
|
---|
179 | if (!hostDrive.isNull())
|
---|
180 | {
|
---|
181 | CDVDDrive virtualDrive = machine.GetDVDDrive();
|
---|
182 | virtualDrive.CaptureHostDrive (hostDrive);
|
---|
183 | }
|
---|
184 | }
|
---|
185 | else if (rbImage->isChecked())
|
---|
186 | {
|
---|
187 | CDVDDrive virtualDrive = machine.GetDVDDrive();
|
---|
188 | virtualDrive.MountImage (cbImage->getId());
|
---|
189 | }
|
---|
190 | }
|
---|
191 | /* Floppy Media selected */
|
---|
192 | else if (rbFdType->isChecked())
|
---|
193 | {
|
---|
194 | if (rbHost->isChecked())
|
---|
195 | {
|
---|
196 | CHostFloppyDrive hostDrive = hostFloppys [cbHost->currentItem()];
|
---|
197 | if (!hostDrive.isNull())
|
---|
198 | {
|
---|
199 | CFloppyDrive virtualDrive = machine.GetFloppyDrive();
|
---|
200 | virtualDrive.CaptureHostDrive (hostDrive);
|
---|
201 | }
|
---|
202 | }
|
---|
203 | else if (rbImage->isChecked())
|
---|
204 | {
|
---|
205 | CFloppyDrive virtualDrive = machine.GetFloppyDrive();
|
---|
206 | virtualDrive.MountImage (cbImage->getId());
|
---|
207 | }
|
---|
208 | }
|
---|
209 |
|
---|
210 | QWizard::accept();
|
---|
211 | }
|
---|
212 |
|
---|
213 |
|
---|
214 | void VBoxVMFirstRunWzd::enableNext (const QIWidgetValidator *aWval)
|
---|
215 | {
|
---|
216 | setNextEnabled (aWval->widget(), aWval->isValid());
|
---|
217 | }
|
---|
218 |
|
---|
219 |
|
---|
220 | void VBoxVMFirstRunWzd::revalidate (QIWidgetValidator *aWval)
|
---|
221 | {
|
---|
222 | /* do individual validations for pages */
|
---|
223 | QWidget *pg = aWval->widget();
|
---|
224 | bool valid = aWval->isOtherValid();
|
---|
225 |
|
---|
226 | if (pg == pageType)
|
---|
227 | {
|
---|
228 | valid = (rbHost->isChecked() && !cbHost->currentText().isEmpty()) ||
|
---|
229 | (rbImage->isChecked() && !cbImage->currentText().isEmpty());
|
---|
230 | }
|
---|
231 |
|
---|
232 | aWval->setOtherValid (valid);
|
---|
233 | }
|
---|
234 |
|
---|
235 |
|
---|
236 | void VBoxVMFirstRunWzd::mediaTypeChanged()
|
---|
237 | {
|
---|
238 | /* CD/DVD Media type selected */
|
---|
239 | cbHost->clear();
|
---|
240 | if (sender() == rbCdType)
|
---|
241 | {
|
---|
242 | /* Search for the host dvd-drives */
|
---|
243 | CHostDVDDriveCollection coll =
|
---|
244 | vboxGlobal().virtualBox().GetHost().GetDVDDrives();
|
---|
245 | hostDVDs.resize (coll.GetCount());
|
---|
246 | int id = 0;
|
---|
247 | CHostDVDDriveEnumerator en = coll.Enumerate();
|
---|
248 | while (en.HasMore())
|
---|
249 | {
|
---|
250 | CHostDVDDrive hostDVD = en.GetNext();
|
---|
251 | cbHost->insertItem (hostDVD.GetName(), id);
|
---|
252 | hostDVDs [id] = hostDVD;
|
---|
253 | ++ id;
|
---|
254 | }
|
---|
255 |
|
---|
256 | /* Switch media images type to CD */
|
---|
257 | cbImage->setType (VBoxDefs::CD);
|
---|
258 | }
|
---|
259 | /* Floppy Media type selected */
|
---|
260 | else if (sender() == rbFdType)
|
---|
261 | {
|
---|
262 | /* Search for the host floppy-drives */
|
---|
263 | CHostFloppyDriveCollection coll =
|
---|
264 | vboxGlobal().virtualBox().GetHost().GetFloppyDrives();
|
---|
265 | hostFloppys.resize (coll.GetCount());
|
---|
266 | int id = 0;
|
---|
267 | CHostFloppyDriveEnumerator en = coll.Enumerate();
|
---|
268 | while (en.HasMore())
|
---|
269 | {
|
---|
270 | CHostFloppyDrive hostFloppy = en.GetNext();
|
---|
271 | cbHost->insertItem (hostFloppy.GetName(), id);
|
---|
272 | hostFloppys [id] = hostFloppy;
|
---|
273 | ++ id;
|
---|
274 | }
|
---|
275 |
|
---|
276 | /* Switch media images type to FD */
|
---|
277 | cbImage->setType (VBoxDefs::FD);
|
---|
278 | }
|
---|
279 | /* Update media images list */
|
---|
280 | if (!vboxGlobal().isMediaEnumerationStarted())
|
---|
281 | vboxGlobal().startEnumeratingMedia();
|
---|
282 | else
|
---|
283 | cbImage->refresh();
|
---|
284 |
|
---|
285 | /* Revalidate updated page */
|
---|
286 | wvalType->revalidate();
|
---|
287 | }
|
---|
288 |
|
---|
289 |
|
---|
290 | void VBoxVMFirstRunWzd::mediaSourceChanged()
|
---|
291 | {
|
---|
292 | cbHost->setEnabled (sender() == rbHost);
|
---|
293 | cbImage->setEnabled (sender() == rbImage);
|
---|
294 | tbVdm->setEnabled (sender() == rbImage);
|
---|
295 |
|
---|
296 | /* Revalidate updated page */
|
---|
297 | wvalType->revalidate();
|
---|
298 | }
|
---|
299 |
|
---|
300 |
|
---|
301 | void VBoxVMFirstRunWzd::openVdm()
|
---|
302 | {
|
---|
303 | VBoxDiskImageManagerDlg vdm (this, "VBoxDiskImageManagerDlg",
|
---|
304 | WType_Dialog | WShowModal);
|
---|
305 | QUuid machineId = machine.GetId();
|
---|
306 | VBoxDefs::DiskType type = rbCdType->isChecked() ? VBoxDefs::CD :
|
---|
307 | rbFdType->isChecked() ? VBoxDefs::FD : VBoxDefs::InvalidType;
|
---|
308 | vdm.setup (type, true, &machineId);
|
---|
309 | if (vdm.exec() == VBoxDiskImageManagerDlg::Accepted)
|
---|
310 | {
|
---|
311 | cbImage->setCurrentItem (vdm.getSelectedUuid());
|
---|
312 |
|
---|
313 | /* Revalidate updated page */
|
---|
314 | wvalType->revalidate();
|
---|
315 | }
|
---|
316 | }
|
---|