VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/ui/VBoxVMSettingsDlg.ui.h@ 59

Last change on this file since 59 was 59, checked in by vboxsync, 18 years ago

FE/Qt [dsen]:

  • Replaced the "enumeration in progress" indication in the VDM list-views with progress bar list view items. Single media enumretaion events for individual media are handled again to make progress bars run.
  • Added static methods to VBoxDiskImageManagerDlg to compose tool tips for media. These methods are used in the VM settings dialog for media shortcut comboboxes.
  • Fixed: The Remove button is now disabled for hard disks with children.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 59.5 KB
Line 
1/**
2 *
3 * VBox frontends: Qt GUI ("VirtualBox"):
4 * "VM settings" dialog UI include (Qt Designer)
5 */
6
7/*
8 * Copyright (C) 2006 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 wish to add, delete or rename functions or slots use
27** Qt Designer which will update this file, preserving your code. Create an
28** init() function in place of a constructor, and a destroy() function in
29** place of a destructor.
30*****************************************************************************/
31
32
33/**
34 * Calculates a suitable page step size for the given max value.
35 * The returned size is so that there will be no more than 32 pages.
36 * The minimum returned page size is 4.
37 */
38static int calcPageStep (int aMax)
39{
40 /* reasonable max. number of page steps is 32 */
41 uint page = ((uint) aMax + 31) / 32;
42 /* make it a power of 2 */
43 uint p = page, p2 = 0x1;
44 while ((p >>= 1))
45 p2 <<= 1;
46 if (page != p2)
47 p2 <<= 1;
48 if (p2 < 4)
49 p2 = 4;
50 return (int) p2;
51}
52
53/**
54 * Simple QTableItem subclass to use QComboBox as the cell editor.
55 * This subclass (as opposed to QComboTableItem) allows to specify the
56 * EditType::WhenCurrent edit type of the cell (to let it look like a normal
57 * text cell when not in focus).
58 *
59 * Additionally, this subclass supports unicity of a group of values
60 * among a group of ComboTableItem items that refer to the same list of
61 * unique values currently being used.
62 */
63class ComboTableItem : public QObject, public QTableItem
64{
65 Q_OBJECT
66
67public:
68
69 ComboTableItem (QTable *aTable, EditType aEditType,
70 const QStringList &aList, const QStringList &aUnique,
71 QStringList *aUniqueInUse)
72 : QTableItem (aTable, aEditType)
73 , mList (aList), mUnique (aUnique), mUniqueInUse (aUniqueInUse), mComboBoxSelector(0)
74 {
75 setReplaceable (FALSE);
76 }
77
78 // reimplemented QTableItem members
79 QWidget *createEditor() const
80 {
81 mComboBoxSelector = new QComboBox (table()->viewport());
82 QStringList list = mList;
83 if (mUniqueInUse)
84 {
85 /* remove unique values currently in use */
86 for (QStringList::Iterator it = mUniqueInUse->begin();
87 it != mUniqueInUse->end(); ++ it)
88 {
89 if (*it != text())
90 list.remove (*it);
91 }
92 }
93 mComboBoxSelector->insertStringList (list);
94 mComboBoxSelector->setCurrentText (text());
95 QObject::connect (mComboBoxSelector, SIGNAL (highlighted (const QString &)),
96 this, SLOT (doValueChanged (const QString &)));
97 QObject::connect (mComboBoxSelector, SIGNAL (activated (const QString &)),
98 this, SLOT (focusClearing ()));
99
100 return mComboBoxSelector;
101 }
102
103 void setContentFromEditor (QWidget *aWidget)
104 {
105 if (aWidget->inherits ("QComboBox"))
106 {
107 QString text = ((QComboBox *) aWidget)->currentText();
108 setText (text);
109 }
110 else
111 QTableItem::setContentFromEditor (aWidget);
112 }
113 void setText (const QString &aText)
114 {
115 if (aText != text())
116 {
117 /* update the list of unique values currently in use */
118 if (mUniqueInUse)
119 {
120 QStringList::Iterator it = mUniqueInUse->find (text());
121 if (it != mUniqueInUse->end())
122 mUniqueInUse->remove (it);
123 if (mUnique.contains (aText))
124 (*mUniqueInUse) += aText;
125 }
126 QTableItem::setText (aText);
127 }
128 }
129
130 /*
131 * Function: rtti()
132 * Target: required for runtime information about ComboTableItem class
133 * used for static_cast from QTableItem
134 */
135 int rtti() const { return 1001; }
136
137 /*
138 * Function: getEditor()
139 * Target: returns pointer to stored combo-box
140 */
141 QComboBox* getEditor() { return mComboBoxSelector; }
142
143private slots:
144
145 /*
146 * QTable doesn't call endEdit() when item's EditType is WhenCurrent and
147 * the table widget loses focus or gets destroyed (assuming the user will
148 * hit Enter if he wants to keep the value), so we need to do it ourselves
149 */
150 void doValueChanged (const QString &text) { setText (text); }
151
152 /*
153 * Function: focusClearing()
154 * Target: required for removing focus from combo-box
155 */
156 void focusClearing() { mComboBoxSelector->clearFocus(); }
157
158private:
159
160 const QStringList mList;
161 const QStringList mUnique;
162 QStringList* mUniqueInUse;
163 mutable QComboBox* mComboBoxSelector;
164};
165
166
167/// @todo (dmik) remove?
168///**
169// * Returns the through position of the item in the list view.
170// */
171//static int pos (QListView *lv, QListViewItem *li)
172//{
173// QListViewItemIterator it (lv);
174// int p = -1, c = 0;
175// while (it.current() && p < 0)
176// {
177// if (it.current() == li)
178// p = c;
179// ++ it;
180// ++ c;
181// }
182// return p;
183//}
184
185class USBListItem : public QCheckListItem
186{
187public:
188
189 USBListItem (QListView *aParent, QListViewItem *aAfter)
190 : QCheckListItem (aParent, aAfter, QString::null, CheckBox)
191 , mId (-1) {}
192
193 int mId;
194};
195
196/**
197 * Returns the path to the item in the form of 'grandparent > parent > item'
198 * using the text of the first column of every item.
199 */
200static QString path (QListViewItem *li)
201{
202 static QString sep = ": ";
203 QString p;
204 QListViewItem *cur = li;
205 while (cur)
206 {
207 if (!p.isNull())
208 p = sep + p;
209 p = cur->text (0).simplifyWhiteSpace() + p;
210 cur = cur->parent();
211 }
212 return p;
213}
214
215enum
216{
217 /* listView column numbers */
218 listView_Category = 0,
219 listView_Id = 1,
220 listView_Link = 2,
221 /* lvUSBFilters column numbers */
222 lvUSBFilters_Name = 0,
223};
224
225void VBoxVMSettingsDlg::init()
226{
227 polished = false;
228
229 setIcon (QPixmap::fromMimeSource ("settings_16px.png"));
230
231 /* all pages are initially valid */
232 valid = true;
233 buttonOk->setEnabled( true );
234
235 /* disable unselecting items by clicking in the unused area of the list */
236 new QIListViewSelectionPreserver (this, listView);
237 /* hide the header and internal columns */
238 listView->header()->hide();
239 listView->setColumnWidthMode (listView_Id, QListView::Manual);
240 listView->setColumnWidthMode (listView_Link, QListView::Manual);
241 listView->hideColumn (listView_Id);
242 listView->hideColumn (listView_Link);
243 /* sort by the id column (to have pages in the desired order) */
244 listView->setSorting (listView_Id);
245 listView->sort();
246 /* disable further sorting (important for network adapters) */
247 listView->setSorting (-1);
248 /* set the first item selected */
249 listView->setSelected (listView->firstChild(), true);
250 listView_currentChanged (listView->firstChild());
251 /* setup status bar icon */
252 warningPixmap->setMaximumSize( 16, 16 );
253 warningPixmap->setPixmap( QMessageBox::standardIcon( QMessageBox::Warning ) );
254
255 /* page title font is derived from the system font */
256 QFont f = font();
257 f.setBold (true);
258 f.setPointSize (f.pointSize() + 2);
259 titleLabel->setFont (f);
260
261 /* setup the what's this label */
262 QApplication::setGlobalMouseTracking (true);
263 qApp->installEventFilter (this);
264 whatsThisTimer = new QTimer (this);
265 connect (whatsThisTimer, SIGNAL (timeout()), this, SLOT (updateWhatsThis()));
266 whatsThisCandidate = NULL;
267 whatsThisLabel->setTextFormat (Qt::RichText);
268 whatsThisLabel->setMinimumHeight (whatsThisLabel->frameWidth() * 2 +
269 4 /* seems that RichText adds some margin */ +
270 whatsThisLabel->fontMetrics().lineSpacing() * 3);
271
272 /*
273 * setup connections and set validation for pages
274 * ----------------------------------------------------------------------
275 */
276
277 /* General page */
278
279 CSystemProperties sysProps = vboxGlobal().virtualBox().GetSystemProperties();
280
281 const uint MinRAM = sysProps.GetMinGuestRAM();
282 const uint MaxRAM = sysProps.GetMaxGuestRAM();
283 const uint MinVRAM = sysProps.GetMinGuestVRAM();
284 const uint MaxVRAM = sysProps.GetMaxGuestVRAM();
285
286 leName->setValidator( new QRegExpValidator( QRegExp( ".+" ), this ) );
287
288 leRAM->setValidator (new QIntValidator (MinRAM, MaxRAM, this));
289 leVRAM->setValidator (new QIntValidator (MinVRAM, MaxVRAM, this));
290
291 wvalGeneral = new QIWidgetValidator( pageGeneral, this );
292 connect (wvalGeneral, SIGNAL (validityChanged (const QIWidgetValidator *)),
293 this, SLOT(enableOk (const QIWidgetValidator *)));
294
295 tbSelectSavedStateFolder->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
296 "select_file_dis_16px.png"));
297 tbResetSavedStateFolder->setIconSet (VBoxGlobal::iconSet ("delete_16px.png",
298 "delete_dis_16px.png"));
299
300 /* HDD Images page */
301
302 QWhatsThis::add (static_cast <QWidget *> (grbHDA->child ("qt_groupbox_checkbox")),
303 tr ("When checked, attaches the specified virtual hard disk to the "
304 "Master slot of the Primary IDE controller."));
305 QWhatsThis::add (static_cast <QWidget *> (grbHDB->child ("qt_groupbox_checkbox")),
306 tr ("When checked, attaches the specified virtual hard disk to the "
307 "Slave slot of the Primary IDE controller."));
308 QWhatsThis::add (static_cast <QWidget *> (grbHDD->child ("qt_groupbox_checkbox")),
309 tr ("When checked, attaches the specified virtual hard disk to the "
310 "Slave slot of the Secondary IDE controller."));
311 cbHDA = new VBoxMediaComboBox (grbHDA, "cbHDA", VBoxDefs::HD);
312 cbHDB = new VBoxMediaComboBox (grbHDB, "cbHDB", VBoxDefs::HD);
313 cbHDD = new VBoxMediaComboBox (grbHDD, "cbHDD", VBoxDefs::HD);
314 hdaLayout->insertWidget (0, cbHDA);
315 hdbLayout->insertWidget (0, cbHDB);
316 hddLayout->insertWidget (0, cbHDD);
317 /* sometimes the weirdness of Qt just kills... */
318 setTabOrder (static_cast <QWidget *> (grbHDA->child ("qt_groupbox_checkbox")),
319 cbHDA);
320 setTabOrder (static_cast <QWidget *> (grbHDB->child ("qt_groupbox_checkbox")),
321 cbHDB);
322 setTabOrder (static_cast <QWidget *> (grbHDD->child ("qt_groupbox_checkbox")),
323 cbHDD);
324
325 QWhatsThis::add (cbHDB, tr ("Displays the virtual hard disk to attach to this IDE slot "
326 "and allows to quickly select a different hard disk."));
327 QWhatsThis::add (cbHDD, tr ("Displays the virtual hard disk to attach to this IDE slot "
328 "and allows to quickly select a different hard disk."));
329 QWhatsThis::add (cbHDA, tr ("Displays the virtual hard disk to attach to this IDE slot "
330 "and allows to quickly select a different hard disk."));
331 QWhatsThis::add (cbHDB, tr ("Displays the virtual hard disk to attach to this IDE slot "
332 "and allows to quickly select a different hard disk."));
333 QWhatsThis::add (cbHDD, tr ("Displays the virtual hard disk to attach to this IDE slot "
334 "and allows to quickly select a different hard disk."));
335
336 wvalHDD = new QIWidgetValidator( pageHDD, this );
337 connect (wvalHDD, SIGNAL (validityChanged (const QIWidgetValidator *)),
338 this, SLOT (enableOk (const QIWidgetValidator *)));
339 connect (wvalHDD, SIGNAL (isValidRequested (QIWidgetValidator *)),
340 this, SLOT (revalidate (QIWidgetValidator *)));
341
342 connect (grbHDA, SIGNAL (toggled (bool)), this, SLOT (hdaMediaChanged()));
343 connect (grbHDB, SIGNAL (toggled (bool)), this, SLOT (hdbMediaChanged()));
344 connect (grbHDD, SIGNAL (toggled (bool)), this, SLOT (hddMediaChanged()));
345 connect (cbHDA, SIGNAL (activated (int)), this, SLOT (hdaMediaChanged()));
346 connect (cbHDB, SIGNAL (activated (int)), this, SLOT (hdbMediaChanged()));
347 connect (cbHDD, SIGNAL (activated (int)), this, SLOT (hddMediaChanged()));
348 connect (tbHDA, SIGNAL (clicked()), this, SLOT (showImageManagerHDA()));
349 connect (tbHDB, SIGNAL (clicked()), this, SLOT (showImageManagerHDB()));
350 connect (tbHDD, SIGNAL (clicked()), this, SLOT (showImageManagerHDD()));
351
352 /* setup iconsets -- qdesigner is not capable... */
353 tbHDA->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
354 "select_file_dis_16px.png"));
355 tbHDB->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
356 "select_file_dis_16px.png"));
357 tbHDD->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
358 "select_file_dis_16px.png"));
359
360 /* CD/DVD-ROM Drive Page */
361
362 QWhatsThis::add (static_cast <QWidget *> (bgDVD->child ("qt_groupbox_checkbox")),
363 tr ("When checked, mounts the specified media to the CD/DVD drive of the "
364 "virtual machine. Note that the CD/DVD drive is always connected to the "
365 "Secondary Master IDE controller of the machine."));
366 cbISODVD = new VBoxMediaComboBox (bgDVD, "cbISODVD", VBoxDefs::CD);
367 cdLayout->insertWidget(0, cbISODVD);
368 QWhatsThis::add (cbISODVD, tr ("Displays the image file to mount to the virtual CD/DVD "
369 "drive and allows to quickly select a different image."));
370
371 wvalDVD = new QIWidgetValidator (pageDVD, this);
372 connect (wvalDVD, SIGNAL (validityChanged (const QIWidgetValidator *)),
373 this, SLOT (enableOk (const QIWidgetValidator *)));
374 connect (wvalDVD, SIGNAL (isValidRequested (QIWidgetValidator *)),
375 this, SLOT (revalidate( QIWidgetValidator *)));
376
377 connect (bgDVD, SIGNAL (toggled (bool)), this, SLOT (cdMediaChanged()));
378 connect (rbHostDVD, SIGNAL (stateChanged (int)), wvalDVD, SLOT (revalidate()));
379 connect (rbISODVD, SIGNAL (stateChanged (int)), wvalDVD, SLOT (revalidate()));
380 connect (cbISODVD, SIGNAL (activated (int)), this, SLOT (cdMediaChanged()));
381 connect (tbISODVD, SIGNAL (clicked()), this, SLOT (showImageManagerISODVD()));
382
383 /* setup iconsets -- qdesigner is not capable... */
384 tbISODVD->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
385 "select_file_dis_16px.png"));
386
387 /* Floppy Drive Page */
388
389 QWhatsThis::add (static_cast <QWidget *> (bgFloppy->child ("qt_groupbox_checkbox")),
390 tr ("When checked, mounts the specified media to the Floppy drive of the "
391 "virtual machine."));
392 cbISOFloppy = new VBoxMediaComboBox (bgFloppy, "cbISOFloppy", VBoxDefs::FD);
393 fdLayout->insertWidget(0, cbISOFloppy);
394 QWhatsThis::add (cbISOFloppy, tr ("Displays the image file to mount to the virtual Floppy "
395 "drive and allows to quickly select a different image."));
396
397 wvalFloppy = new QIWidgetValidator (pageFloppy, this);
398 connect (wvalFloppy, SIGNAL (validityChanged (const QIWidgetValidator *)),
399 this, SLOT (enableOk (const QIWidgetValidator *)));
400 connect (wvalFloppy, SIGNAL (isValidRequested (QIWidgetValidator *)),
401 this, SLOT (revalidate( QIWidgetValidator *)));
402
403 connect (bgFloppy, SIGNAL (toggled (bool)), this, SLOT (fdMediaChanged()));
404 connect (rbHostFloppy, SIGNAL (stateChanged (int)), wvalFloppy, SLOT (revalidate()));
405 connect (rbISOFloppy, SIGNAL (stateChanged (int)), wvalFloppy, SLOT (revalidate()));
406 connect (cbISOFloppy, SIGNAL (activated (int)), this, SLOT (fdMediaChanged()));
407 connect (tbISOFloppy, SIGNAL (clicked()), this, SLOT (showImageManagerISOFloppy()));
408
409 /* setup iconsets -- qdesigner is not capable... */
410 tbISOFloppy->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
411 "select_file_dis_16px.png"));
412
413 /* Audio Page */
414
415 QWhatsThis::add (static_cast <QWidget *> (grbAudio->child ("qt_groupbox_checkbox")),
416 tr ("When checked, the virtual PCI audio card is plugged into the "
417 "virtual machine that uses the specified driver to communicate "
418 "to the host audio card."));
419
420 /* Network Page */
421
422 QVBoxLayout* pageNetworkLayout = new QVBoxLayout (pageNetwork, 0, 10, "pageNetworkLayout");
423 tbwNetwork = new QTabWidget (pageNetwork, "tbwNetwork");
424 pageNetworkLayout->addWidget (tbwNetwork);
425
426 /* USB Page */
427
428 lvUSBFilters->header()->hide();
429 /* disable sorting */
430 lvUSBFilters->setSorting (-1);
431 /* disable unselecting items by clicking in the unused area of the list */
432 new QIListViewSelectionPreserver (this, lvUSBFilters);
433 /* create the widget stack for filter settings */
434 /// @todo (r=dmik) having a separate settings widget for every USB filter
435 // is not that smart if there are lots of USB filters. The reason for
436 // stacking here is that the stacked widget is used to temporarily store
437 // data of the associated USB filter until the dialog window is accepted.
438 // If we remove stacking, we will have to create a structure to store
439 // editable data of all USB filters while the dialog is open.
440 wstUSBFilters = new QWidgetStack (grbUSBFilters, "wstUSBFilters");
441 grbUSBFiltersLayout->addWidget (wstUSBFilters);
442 /* create a default (disabled) filter settings widget at index 0 */
443 wstUSBFilters->addWidget (new VBoxUSBFilterSettings (wstUSBFilters), 0);
444 lvUSBFilters_currentChanged (NULL);
445
446 /* setup iconsets -- qdesigner is not capable... */
447 tbAddUSBFilter->setIconSet (VBoxGlobal::iconSet ("usb_add_16px.png",
448 "usb_add_disabled_16px.png"));
449 tbRemoveUSBFilter->setIconSet (VBoxGlobal::iconSet ("usb_remove_16px.png",
450 "usb_remove_disabled_16px.png"));
451 tbUSBFilterUp->setIconSet (VBoxGlobal::iconSet ("usb_moveup_16px.png",
452 "usb_moveup_disabled_16px.png"));
453 tbUSBFilterDown->setIconSet (VBoxGlobal::iconSet ("usb_movedown_16px.png",
454 "usb_movedown_disabled_16px.png"));
455
456 mLastUSBFilterNum = 0;
457 mUSBFilterListModified = false;
458
459 /*
460 * set initial values
461 * ----------------------------------------------------------------------
462 */
463
464 /* General page */
465
466 cbOS->insertStringList (vboxGlobal().vmGuestOSTypeDescriptions());
467
468 slRAM->setPageStep (calcPageStep (MaxRAM));
469 slRAM->setLineStep (slRAM->pageStep() / 4);
470 slRAM->setTickInterval (slRAM->pageStep());
471 /* setup the scale so that ticks are at page step boundaries */
472 slRAM->setMinValue ((MinRAM / slRAM->pageStep()) * slRAM->pageStep());
473 slRAM->setMaxValue (MaxRAM);
474 txRAMMin->setText (tr ("<qt>%1&nbsp;MB</qt>").arg (MinRAM));
475 txRAMMax->setText (tr ("<qt>%1&nbsp;MB</qt>").arg (MaxRAM));
476 /* limit min/max. size of QLineEdit */
477 leRAM->setMaximumSize (leRAM->fontMetrics().width ("99999")
478 + leRAM->frameWidth() * 2,
479 leRAM->minimumSizeHint().height());
480 leRAM->setMinimumSize (leRAM->maximumSize());
481 /* ensure leRAM value and validation is updated */
482 slRAM_valueChanged (slRAM->value());
483
484 slVRAM->setPageStep (calcPageStep (MaxVRAM));
485 slVRAM->setLineStep (slVRAM->pageStep() / 4);
486 slVRAM->setTickInterval (slVRAM->pageStep());
487 /* setup the scale so that ticks are at page step boundaries */
488 slVRAM->setMinValue ((MinVRAM / slVRAM->pageStep()) * slVRAM->pageStep());
489 slVRAM->setMaxValue (MaxVRAM);
490 txVRAMMin->setText (tr ("<qt>%1&nbsp;MB</qt>").arg (MinVRAM));
491 txVRAMMax->setText (tr ("<qt>%1&nbsp;MB</qt>").arg (MaxVRAM));
492 /* limit min/max. size of QLineEdit */
493 leVRAM->setMaximumSize (leVRAM->fontMetrics().width ("99999")
494 + leVRAM->frameWidth() * 2,
495 leVRAM->minimumSizeHint().height());
496 leVRAM->setMinimumSize (leVRAM->maximumSize());
497 /* ensure leVRAM value and validation is updated */
498 slVRAM_valueChanged (slVRAM->value());
499
500 tblBootOrder->horizontalHeader()->hide();
501 tblBootOrder->setTopMargin (0);
502 tblBootOrder->verticalHeader()->hide();
503 tblBootOrder->setLeftMargin (0);
504 tblBootOrder->setNumCols (1);
505 tblBootOrder->setNumRows (sysProps.GetMaxBootPosition());
506 {
507 QStringList list = vboxGlobal().deviceTypeStrings();
508 QStringList unique;
509 unique
510 << vboxGlobal().toString (CEnums::FloppyDevice)
511 << vboxGlobal().toString (CEnums::DVDDevice)
512 << vboxGlobal().toString (CEnums::HardDiskDevice)
513 << vboxGlobal().toString (CEnums::NetworkDevice);
514 for (int i = 0; i < tblBootOrder->numRows(); i++)
515 {
516 ComboTableItem *item = new ComboTableItem (
517 tblBootOrder, QTableItem::OnTyping,
518 list, unique, &bootDevicesInUse);
519 tblBootOrder->setItem (i, 0, item);
520 }
521 }
522 connect (tblBootOrder, SIGNAL (clicked(int, int, int, const QPoint&)),
523 this, SLOT (bootItemActivate(int, int, int, const QPoint&)));
524
525 tblBootOrder->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Preferred);
526 tblBootOrder->setMinimumHeight (tblBootOrder->rowHeight(0) * 4 +
527 tblBootOrder->frameWidth() * 2);
528 tblBootOrder->setColumnStretchable (0, true);
529 tblBootOrder->verticalHeader()->setResizeEnabled (false);
530 tblBootOrder->verticalHeader()->setClickEnabled (false);
531// tblBootOrder->setFocusStyle (QTable::FollowStyle);
532
533 /* HDD Images page */
534
535 /* CD-ROM Drive Page */
536
537 /* Audio Page */
538
539 cbAudioDriver->insertItem (vboxGlobal().toString (CEnums::NullAudioDriver));
540#if defined Q_WS_WIN32
541 cbAudioDriver->insertItem (vboxGlobal().toString (CEnums::WINMMAudioDriver));
542#elif defined Q_WS_X11
543 cbAudioDriver->insertItem (vboxGlobal().toString (CEnums::OSSAudioDriver));
544#ifdef VBOX_WITH_ALSA
545 cbAudioDriver->insertItem (vboxGlobal().toString (CEnums::ALSAAudioDriver));
546#endif
547#endif
548
549 /* Network Page */
550
551 /*
552 * update the Ok button state for pages with validation
553 * (validityChanged() connected to enableNext() will do the job)
554 */
555 wvalGeneral->revalidate();
556 wvalHDD->revalidate();
557 wvalDVD->revalidate();
558 wvalFloppy->revalidate();
559}
560
561bool VBoxVMSettingsDlg::eventFilter (QObject *object, QEvent *event)
562{
563 if (!object->isWidgetType())
564 return QDialog::eventFilter (object, event);
565
566 QWidget *widget = static_cast <QWidget *> (object);
567 if (widget->topLevelWidget() != this)
568 return QDialog::eventFilter (object, event);
569
570 switch (event->type())
571 {
572 case QEvent::Enter:
573 case QEvent::Leave:
574 {
575 if (event->type() == QEvent::Enter)
576 whatsThisCandidate = widget;
577 else
578 whatsThisCandidate = NULL;
579 whatsThisTimer->start (100, true /* sshot */);
580 break;
581 }
582 case QEvent::FocusIn:
583 {
584 updateWhatsThis (true /* gotFocus */);
585 break;
586 }
587 default:
588 break;
589 }
590
591 return QDialog::eventFilter (object, event);
592}
593
594void VBoxVMSettingsDlg::showEvent (QShowEvent *e)
595{
596 QDialog::showEvent (e);
597
598 /* one may think that QWidget::polish() is the right place to do things
599 * below, but apparently, by the time when QWidget::polish() is called,
600 * the widget style & layout are not fully done, at least the minimum
601 * size hint is not properly calculated. Since this is sometimes necessary,
602 * we provide our own "polish" implementation. */
603
604 if (polished)
605 return;
606
607 polished = true;
608
609 /* resize to the miminum possible size */
610 resize (minimumSize());
611
612 VBoxGlobal::centerWidget (this, parentWidget());
613}
614
615void VBoxVMSettingsDlg::bootItemActivate (int row, int col, int /* button */,
616 const QPoint &/* mousePos */)
617{
618 tblBootOrder->editCell(row, col);
619 QTableItem* tableItem = tblBootOrder->item(row, col);
620 if (tableItem->rtti() == 1001)
621 (static_cast<ComboTableItem*>(tableItem))->getEditor()->popup();
622}
623
624void VBoxVMSettingsDlg::updateShortcuts (VBoxDefs::DiskType aType,
625 VBoxDiskImageManagerDlg *aVdm)
626{
627 /* update request for selected item */
628 cbHDA->setRequiredItem (uuidHDA);
629 cbHDB->setRequiredItem (uuidHDB);
630 cbHDD->setRequiredItem (uuidHDD);
631 cbISODVD->setRequiredItem (uuidISODVD);
632 cbISOFloppy->setRequiredItem (uuidISOFloppy);
633
634 if (aVdm)
635 /* quick update from vdm data */
636 {
637 QStringList names, keys;
638 aVdm->uploadCurrentList (names, keys, cbHDA->getBelongsTo());
639
640 switch (aType)
641 {
642 case VBoxDefs::HD:
643 cbHDA->loadShortCuts (names, keys);
644 cbHDB->loadShortCuts (names, keys);
645 cbHDD->loadShortCuts (names, keys);
646 break;
647 case VBoxDefs::CD:
648 cbISODVD->loadShortCuts (names, keys);
649 break;
650 case VBoxDefs::FD:
651 cbISOFloppy->loadShortCuts (names, keys);
652 break;
653 default:
654 Assert (0);
655 break;
656 }
657 }
658 else
659 /* slow update through media-enumeration process */
660 {
661 /* request for refresh every combo-box */
662 cbHDA->setReadyForRefresh();
663 cbHDB->setReadyForRefresh();
664 cbHDD->setReadyForRefresh();
665 cbISODVD->setReadyForRefresh();
666 cbISOFloppy->setReadyForRefresh();
667 /* starting media-enumerating process */
668 vboxGlobal().startEnumeratingMedia();
669 }
670}
671
672
673void VBoxVMSettingsDlg::hdaMediaChanged()
674{
675 uuidHDA = grbHDA->isChecked() ? cbHDA->getId() : QUuid();
676 txHDA->setText (getHdInfo (grbHDA, uuidHDA));
677 /* tool-tip composing */
678 if (!uuidHDA.isNull())
679 {
680 CHardDisk hd = vboxGlobal().virtualBox().GetHardDisk (uuidHDA);
681 QToolTip::add (cbHDA, VBoxDiskImageManagerDlg::composeHdToolTip (hd));
682 }
683 /* revailidate */
684 wvalHDD->revalidate();
685}
686
687
688void VBoxVMSettingsDlg::hdbMediaChanged()
689{
690 uuidHDB = grbHDB->isChecked() ? cbHDB->getId() : QUuid();
691 txHDB->setText (getHdInfo (grbHDB, uuidHDB));
692 /* tool-tip composing */
693 if (!uuidHDB.isNull())
694 {
695 CHardDisk hd = vboxGlobal().virtualBox().GetHardDisk (uuidHDB);
696 QToolTip::add (cbHDB, VBoxDiskImageManagerDlg::composeHdToolTip (hd));
697 }
698 /* revailidate */
699 wvalHDD->revalidate();
700}
701
702
703void VBoxVMSettingsDlg::hddMediaChanged()
704{
705 uuidHDD = grbHDD->isChecked() ? cbHDD->getId() : QUuid();
706 txHDD->setText (getHdInfo (grbHDD, uuidHDD));
707 /* tool-tip composing */
708 if (!uuidHDD.isNull())
709 {
710 CHardDisk hd = vboxGlobal().virtualBox().GetHardDisk (uuidHDD);
711 QToolTip::add (cbHDD, VBoxDiskImageManagerDlg::composeHdToolTip (hd));
712 }
713 /* revailidate */
714 wvalHDD->revalidate();
715}
716
717
718void VBoxVMSettingsDlg::cdMediaChanged()
719{
720 uuidISODVD = bgDVD->isChecked() ? cbISODVD->getId() : QUuid();
721 /* tool-tip composing */
722 if (!uuidISODVD.isNull())
723 {
724 CDVDImage cd = vboxGlobal().virtualBox().GetDVDImage (uuidISODVD);
725 QToolTip::add (cbISODVD, VBoxDiskImageManagerDlg::composeCdToolTip (cd));
726 }
727 /* revailidate */
728 wvalDVD->revalidate();
729}
730
731
732void VBoxVMSettingsDlg::fdMediaChanged()
733{
734 uuidISOFloppy = bgFloppy->isChecked() ? cbISOFloppy->getId() : QUuid();
735 /* tool-tip composing */
736 if (!uuidISOFloppy.isNull())
737 {
738 CFloppyImage fd = vboxGlobal().virtualBox().GetFloppyImage (uuidISOFloppy);
739 QToolTip::add (cbISOFloppy, VBoxDiskImageManagerDlg::composeFdToolTip (fd));
740 }
741 /* revailidate */
742 wvalFloppy->revalidate();
743}
744
745
746QString VBoxVMSettingsDlg::getHdInfo (QGroupBox *aGroupBox, QUuid aId)
747{
748 QString notAttached = tr ("<not attached>", "hard disk");
749 if (aId.isNull())
750 return notAttached;
751 return aGroupBox->isChecked() ?
752 vboxGlobal().details (vboxGlobal().virtualBox().GetHardDisk (aId), true) :
753 notAttached;
754}
755
756void VBoxVMSettingsDlg::updateWhatsThis (bool gotFocus /* = false */)
757{
758 QString text;
759
760 QWidget *widget = NULL;
761 if (!gotFocus)
762 {
763 if (whatsThisCandidate != NULL && whatsThisCandidate != this)
764 widget = whatsThisCandidate;
765 }
766 else
767 {
768 widget = focusData()->focusWidget();
769 }
770 /* if the given widget lacks the whats'this text, look at its parent */
771 while (widget && widget != this)
772 {
773 text = QWhatsThis::textFor (widget);
774 if (!text.isEmpty())
775 break;
776 widget = widget->parentWidget();
777 }
778
779 if (text.isEmpty() && !warningString.isEmpty())
780 text = warningString;
781 if (text.isEmpty())
782 text = QWhatsThis::textFor (this);
783
784 whatsThisLabel->setText (text);
785}
786
787void VBoxVMSettingsDlg::setWarning (const QString &warning)
788{
789 warningString = warning;
790 if (!warning.isEmpty())
791 warningString = QString ("<font color=red>%1</font>").arg (warning);
792
793 if (!warningString.isEmpty())
794 whatsThisLabel->setText (warningString);
795 else
796 updateWhatsThis (true);
797}
798
799/**
800 * Sets up this dialog.
801 *
802 * @note Calling this method after the dialog is open has no sense.
803 *
804 * @param category
805 * Category to select when the dialog is open. Must be one of
806 * values from the hidden '[cat]' column of #listView
807 * (see VBoxVMSettingsDlg.ui in qdesigner) prepended with the '#'
808 * sign.
809 */
810void VBoxVMSettingsDlg::setup (const QString &category)
811{
812 if (category)
813 {
814 QListViewItem *item = listView->findItem (category, listView_Link);
815 if (item)
816 listView->setSelected (item, true);
817 }
818}
819
820void VBoxVMSettingsDlg::listView_currentChanged (QListViewItem *item)
821{
822 Assert (item);
823 int id = item->text (1).toInt();
824 Assert (id >= 0);
825 titleLabel->setText (::path (item));
826 widgetStack->raiseWidget (id);
827}
828
829
830void VBoxVMSettingsDlg::enableOk( const QIWidgetValidator *wval )
831{
832 Q_UNUSED (wval);
833
834 /* detect the overall validity */
835 bool newValid = true;
836 {
837 QObjectList *l = this->queryList ("QIWidgetValidator");
838 QObjectListIt it (*l);
839 QObject *obj;
840 while ((obj = it.current()) != 0)
841 {
842 newValid &= ((QIWidgetValidator *) obj)->isValid();
843 ++it;
844 }
845 delete l;
846 }
847
848 if (valid != newValid)
849 {
850 valid = newValid;
851 buttonOk->setEnabled (valid);
852 if (valid)
853 setWarning(0);
854 warningLabel->setHidden(valid);
855 warningPixmap->setHidden(valid);
856 }
857}
858
859
860void VBoxVMSettingsDlg::revalidate( QIWidgetValidator *wval )
861{
862 /* do individual validations for pages */
863 QWidget *pg = wval->widget();
864 bool valid = wval->isOtherValid();
865
866 if (pg == pageHDD)
867 {
868 CVirtualBox vbox = vboxGlobal().virtualBox();
869 valid = true;
870
871 QValueList <QUuid> uuids;
872
873 if (valid && grbHDA->isChecked())
874 {
875 if (uuidHDA.isNull())
876 {
877 valid = false;
878 setWarning (tr ("Primary Master hard disk is not selected."));
879 }
880 else uuids << uuidHDA;
881 }
882
883 if (valid && grbHDB->isChecked())
884 {
885 if (uuidHDB.isNull())
886 {
887 valid = false;
888 setWarning (tr ("Primary Slave hard disk is not selected."));
889 }
890 else
891 {
892 bool found = uuids.findIndex (uuidHDB) >= 0;
893 if (found)
894 {
895 CHardDisk hd = vbox.GetHardDisk (uuidHDB);
896 valid = hd.GetType() == CEnums::ImmutableHardDisk;
897 }
898 if (valid)
899 uuids << uuidHDB;
900 else
901 setWarning (tr ("Primary Slave hard disk is already attached "
902 "to a different slot."));
903 }
904 }
905
906 if (valid && grbHDD->isChecked())
907 {
908 if (uuidHDD.isNull())
909 {
910 valid = false;
911 setWarning (tr ("Secondary Slave hard disk is not selected."));
912 }
913 else
914 {
915 bool found = uuids.findIndex (uuidHDD) >= 0;
916 if (found)
917 {
918 CHardDisk hd = vbox.GetHardDisk (uuidHDD);
919 valid = hd.GetType() == CEnums::ImmutableHardDisk;
920 }
921 if (valid)
922 uuids << uuidHDB;
923 else
924 setWarning (tr ("Secondary Slave hard disk is already attached "
925 "to a different slot."));
926 }
927 }
928
929 cbHDA->setEnabled (grbHDA->isChecked());
930 cbHDB->setEnabled (grbHDB->isChecked());
931 cbHDD->setEnabled (grbHDD->isChecked());
932 tbHDA->setEnabled (grbHDA->isChecked());
933 tbHDB->setEnabled (grbHDB->isChecked());
934 tbHDD->setEnabled (grbHDD->isChecked());
935 }
936 else if (pg == pageDVD)
937 {
938 if (!bgDVD->isChecked())
939 rbHostDVD->setChecked(false), rbISODVD->setChecked(false);
940 else if (!rbHostDVD->isChecked() && !rbISODVD->isChecked())
941 rbHostDVD->setChecked(true);
942
943 valid = !(rbISODVD->isChecked() && uuidISODVD.isNull());
944
945 cbHostDVD->setEnabled (rbHostDVD->isChecked());
946
947 cbISODVD->setEnabled (rbISODVD->isChecked());
948 tbISODVD->setEnabled (rbISODVD->isChecked());
949
950 if (!valid)
951 setWarning (tr ("CD/DVD drive image file is not selected."));
952 }
953 else if (pg == pageFloppy)
954 {
955 if (!bgFloppy->isChecked())
956 rbHostFloppy->setChecked(false), rbISOFloppy->setChecked(false);
957 else if (!rbHostFloppy->isChecked() && !rbISOFloppy->isChecked())
958 rbHostFloppy->setChecked(true);
959
960 valid = !(rbISOFloppy->isChecked() && uuidISOFloppy.isNull());
961
962 cbHostFloppy->setEnabled (rbHostFloppy->isChecked());
963
964 cbISOFloppy->setEnabled (rbISOFloppy->isChecked());
965 tbISOFloppy->setEnabled (rbISOFloppy->isChecked());
966
967 if (!valid)
968 setWarning (tr ("Floppy drive image file is not selected."));
969 }
970 else if (pg == pageNetwork)
971 {
972 int slot = -1;
973 for (int index = 0; index < tbwNetwork->count(); index++)
974 {
975 QWidget* pTab = tbwNetwork->page (index);
976 Assert(pTab);
977 VBoxVMNetworkSettings* pNetSet = static_cast <VBoxVMNetworkSettings*>(pTab);
978 if (!pNetSet->grbEnabled->isChecked())
979 {
980 pNetSet->cbNetworkAttachment->setCurrentItem (0);
981 pNetSet->cbNetworkAttachment_activated (pNetSet->cbNetworkAttachment->currentText());
982 }
983
984 CEnums::NetworkAttachmentType type =
985 vboxGlobal().toNetworkAttachmentType (pNetSet->cbNetworkAttachment->currentText());
986 valid = (slot == -1) &&
987 !(type == CEnums::HostInterfaceNetworkAttachment &&
988 !pNetSet->checkNetworkInterface (pNetSet->lbHostInterface->currentText()));
989 if (slot == -1 && !valid)
990 slot = index;
991 }
992 if (!valid)
993 setWarning (tr ("Incorrect host network interface is selected for Adapter %1.")
994 .arg (slot));
995 }
996
997 wval->setOtherValid (valid);
998}
999
1000
1001void VBoxVMSettingsDlg::getFromMachine (const CMachine &machine)
1002{
1003 cmachine = machine;
1004
1005 setCaption (machine.GetName() + tr (" - Settings"));
1006
1007 CVirtualBox vbox = vboxGlobal().virtualBox();
1008 CBIOSSettings biosSettings = cmachine.GetBIOSSettings();
1009
1010 /* name */
1011 leName->setText (machine.GetName());
1012
1013 /* OS type */
1014 CGuestOSType type = machine.GetOSType();
1015 cbOS->setCurrentItem (vboxGlobal().vmGuestOSTypeIndex(type));
1016 cbOS_activated (cbOS->currentItem());
1017
1018 /* RAM size */
1019 slRAM->setValue (machine.GetMemorySize());
1020
1021 /* VRAM size */
1022 slVRAM->setValue (machine.GetVRAMSize());
1023
1024 /* boot order */
1025 bootDevicesInUse.clear();
1026 for (int i = 0; i < tblBootOrder->numRows(); i ++)
1027 {
1028 QTableItem *item = tblBootOrder->item (i, 0);
1029 item->setText (vboxGlobal().toString (machine.GetBootOrder (i + 1)));
1030 }
1031
1032 /* ACPI */
1033 chbEnableACPI->setChecked (biosSettings.GetACPIEnabled());
1034
1035 /* IO APIC */
1036 chbEnableIOAPIC->setChecked (biosSettings.GetIOAPICEnabled());
1037
1038 /* Saved state folder */
1039 leSnapshotFolder->setText (machine.GetSnapshotFolder());
1040
1041 /* hard disk images */
1042 {
1043 struct
1044 {
1045 CEnums::DiskControllerType ctl;
1046 LONG dev;
1047 struct {
1048 QGroupBox *grb;
1049 QComboBox *cbb;
1050 QLabel *tx;
1051 QUuid *uuid;
1052 } data;
1053 }
1054 diskSet[] =
1055 {
1056 { CEnums::IDE0Controller, 0, {grbHDA, cbHDA, txHDA, &uuidHDA} },
1057 { CEnums::IDE0Controller, 1, {grbHDB, cbHDB, txHDB, &uuidHDB} },
1058 { CEnums::IDE1Controller, 1, {grbHDD, cbHDD, txHDD, &uuidHDD} },
1059 };
1060
1061 grbHDA->setChecked (false);
1062 grbHDB->setChecked (false);
1063 grbHDD->setChecked (false);
1064
1065 CHardDiskAttachmentEnumerator en =
1066 machine.GetHardDiskAttachments().Enumerate();
1067 while (en.HasMore())
1068 {
1069 CHardDiskAttachment hda = en.GetNext();
1070 for (uint i = 0; i < SIZEOF_ARRAY (diskSet); i++)
1071 {
1072 if (diskSet [i].ctl == hda.GetController() &&
1073 diskSet [i].dev == hda.GetDeviceNumber())
1074 {
1075 CHardDisk hd = hda.GetHardDisk();
1076 CHardDisk root = hd.GetRoot();
1077 QString src = root.GetLocation();
1078 if (hd.GetStorageType() == CEnums::VirtualDiskImage)
1079 {
1080 QFileInfo fi (src);
1081 src = fi.fileName() + " (" +
1082 QDir::convertSeparators (fi.dirPath (true)) + ")";
1083 }
1084 diskSet [i].data.grb->setChecked (true);
1085 diskSet [i].data.tx->setText (vboxGlobal().details (hd));
1086 *(diskSet [i].data.uuid) = QUuid (root.GetId());
1087 }
1088 }
1089 }
1090 }
1091
1092 /* floppy image */
1093 {
1094 /* read out the host floppy drive list and prepare the combobox */
1095 CHostFloppyDriveCollection coll =
1096 vboxGlobal().virtualBox().GetHost().GetFloppyDrives();
1097 hostFloppies.resize (coll.GetCount());
1098 cbHostFloppy->clear();
1099 int id = 0;
1100 CHostFloppyDriveEnumerator en = coll.Enumerate();
1101 while (en.HasMore())
1102 {
1103 CHostFloppyDrive hostFloppy = en.GetNext();
1104 /** @todo set icon? */
1105 cbHostFloppy->insertItem (hostFloppy.GetName(), id);
1106 hostFloppies [id] = hostFloppy;
1107 ++ id;
1108 }
1109
1110 CFloppyDrive floppy = machine.GetFloppyDrive();
1111 switch (floppy.GetState())
1112 {
1113 case CEnums::HostDriveCaptured:
1114 {
1115 CHostFloppyDrive drv = floppy.GetHostDrive();
1116 QString name = drv.GetName();
1117 if (coll.FindByName (name).isNull())
1118 {
1119 /*
1120 * if the floppy drive is not currently available,
1121 * add it to the end of the list with a special mark
1122 */
1123 cbHostFloppy->insertItem ("* " + name);
1124 cbHostFloppy->setCurrentItem (cbHostFloppy->count() - 1);
1125 }
1126 else
1127 {
1128 /* this will select the correct item from the prepared list */
1129 cbHostFloppy->setCurrentText (name);
1130 }
1131 rbHostFloppy->setChecked (true);
1132 break;
1133 }
1134 case CEnums::ImageMounted:
1135 {
1136 CFloppyImage img = floppy.GetImage();
1137 QString src = img.GetFilePath();
1138 AssertMsg (!src.isNull(), ("Image file must not be null"));
1139 QFileInfo fi (src);
1140 rbISOFloppy->setChecked (true);
1141 uuidISOFloppy = QUuid (img.GetId());
1142 break;
1143 }
1144 case CEnums::NotMounted:
1145 {
1146 bgFloppy->setChecked(false);
1147 break;
1148 }
1149 default:
1150 AssertMsgFailed (("invalid floppy state: %d\n", floppy.GetState()));
1151 }
1152 }
1153
1154 /* CD/DVD-ROM image */
1155 {
1156 /* read out the host DVD drive list and prepare the combobox */
1157 CHostDVDDriveCollection coll =
1158 vboxGlobal().virtualBox().GetHost().GetDVDDrives();
1159 hostDVDs.resize (coll.GetCount());
1160 cbHostDVD->clear();
1161 int id = 0;
1162 CHostDVDDriveEnumerator en = coll.Enumerate();
1163 while (en.HasMore())
1164 {
1165 CHostDVDDrive hostDVD = en.GetNext();
1166 /// @todo (r=dmik) set icon?
1167 cbHostDVD->insertItem (hostDVD.GetName(), id);
1168 hostDVDs [id] = hostDVD;
1169 ++ id;
1170 }
1171
1172 CDVDDrive dvd = machine.GetDVDDrive();
1173 switch (dvd.GetState())
1174 {
1175 case CEnums::HostDriveCaptured:
1176 {
1177 CHostDVDDrive drv = dvd.GetHostDrive();
1178 QString name = drv.GetName();
1179 if (coll.FindByName (name).isNull())
1180 {
1181 /*
1182 * if the DVD drive is not currently available,
1183 * add it to the end of the list with a special mark
1184 */
1185 cbHostDVD->insertItem ("* " + name);
1186 cbHostDVD->setCurrentItem (cbHostDVD->count() - 1);
1187 }
1188 else
1189 {
1190 /* this will select the correct item from the prepared list */
1191 cbHostDVD->setCurrentText (name);
1192 }
1193 rbHostDVD->setChecked (true);
1194 break;
1195 }
1196 case CEnums::ImageMounted:
1197 {
1198 CDVDImage img = dvd.GetImage();
1199 QString src = img.GetFilePath();
1200 AssertMsg (!src.isNull(), ("Image file must not be null"));
1201 QFileInfo fi (src);
1202 rbISODVD->setChecked (true);
1203 uuidISODVD = QUuid (img.GetId());
1204 break;
1205 }
1206 case CEnums::NotMounted:
1207 {
1208 bgDVD->setChecked(false);
1209 break;
1210 }
1211 default:
1212 AssertMsgFailed (("invalid DVD state: %d\n", dvd.GetState()));
1213 }
1214 }
1215
1216 /* audio */
1217 {
1218 CAudioAdapter audio = machine.GetAudioAdapter();
1219 grbAudio->setChecked (audio.GetEnabled());
1220 cbAudioDriver->setCurrentText (vboxGlobal().toString (audio.GetAudioDriver()));
1221 }
1222
1223 /* network */
1224 {
1225 ulong count = vbox.GetSystemProperties().GetNetworkAdapterCount();
1226 for (ulong slot = 0; slot < count; slot ++)
1227 {
1228 CNetworkAdapter adapter = machine.GetNetworkAdapter (slot);
1229 addNetworkAdapter (adapter, false);
1230 }
1231 }
1232
1233 /* usb */
1234 {
1235 CUSBController ctl = machine.GetUSBController();
1236
1237 QListViewItem *usbListItem = listView->findItem ("USB", 0, Qt::Contains);
1238 if (usbListItem && ctl.isNull())
1239 usbListItem->setVisible (false);
1240
1241 cbEnableUSBController->setChecked (ctl.GetEnabled());
1242
1243 CUSBDeviceFilterEnumerator en = ctl.GetDeviceFilters().Enumerate();
1244 while (en.HasMore())
1245 addUSBFilter (en.GetNext(), false /* isNew */);
1246
1247 lvUSBFilters->setCurrentItem (lvUSBFilters->firstChild());
1248 /*
1249 * silly, silly Qt -- doesn't emit currentChanged after adding the
1250 * first item to an empty list
1251 */
1252 lvUSBFilters_currentChanged (lvUSBFilters->firstChild());
1253 }
1254
1255 /* request for media shortcuts update */
1256 cbHDA->setBelongsTo(machine.GetId());
1257 cbHDB->setBelongsTo(machine.GetId());
1258 cbHDD->setBelongsTo(machine.GetId());
1259 updateShortcuts (VBoxDefs::InvalidType);
1260
1261 /* revalidate pages with custom validation */
1262 wvalHDD->revalidate();
1263 wvalDVD->revalidate();
1264 wvalFloppy->revalidate();
1265}
1266
1267
1268COMResult VBoxVMSettingsDlg::putBackToMachine()
1269{
1270 CVirtualBox vbox = vboxGlobal().virtualBox();
1271 CBIOSSettings biosSettings = cmachine.GetBIOSSettings();
1272
1273 /* name */
1274 cmachine.SetName (leName->text());
1275
1276 /* OS type */
1277 CGuestOSType type = vboxGlobal().vmGuestOSType (cbOS->currentItem());
1278 AssertMsg (!type.isNull(), ("vmGuestOSType() must return non-null type"));
1279 cmachine.SetOSType (type);
1280
1281 /* RAM size */
1282 cmachine.SetMemorySize (slRAM->value());
1283
1284 /* VRAM size */
1285 cmachine.SetVRAMSize (slVRAM->value());
1286
1287 /* boot order */
1288 for (int i = 0; i < tblBootOrder->numRows(); i ++)
1289 {
1290 QTableItem *item = tblBootOrder->item (i, 0);
1291 cmachine.SetBootOrder (i + 1, vboxGlobal().toDeviceType (item->text()));
1292 }
1293
1294 /* ACPI */
1295 biosSettings.SetACPIEnabled (chbEnableACPI->isChecked());
1296
1297 /* IO APIC */
1298 biosSettings.SetIOAPICEnabled (chbEnableIOAPIC->isChecked());
1299
1300 /* Saved state folder */
1301 if (leSnapshotFolder->isModified())
1302 cmachine.SetSnapshotFolder (leSnapshotFolder->text());
1303
1304 /* hard disk images */
1305 {
1306 struct
1307 {
1308 CEnums::DiskControllerType ctl;
1309 LONG dev;
1310 struct {
1311 QGroupBox *grb;
1312 QUuid *uuid;
1313 } data;
1314 }
1315 diskSet[] =
1316 {
1317 { CEnums::IDE0Controller, 0, {grbHDA, &uuidHDA} },
1318 { CEnums::IDE0Controller, 1, {grbHDB, &uuidHDB} },
1319 { CEnums::IDE1Controller, 1, {grbHDD, &uuidHDD} }
1320 };
1321
1322 /*
1323 * first, detach all disks (to ensure we can reattach them to different
1324 * controllers / devices, when appropriate)
1325 */
1326 CHardDiskAttachmentEnumerator en =
1327 cmachine.GetHardDiskAttachments().Enumerate();
1328 while (en.HasMore())
1329 {
1330 CHardDiskAttachment hda = en.GetNext();
1331 for (uint i = 0; i < SIZEOF_ARRAY (diskSet); i++)
1332 {
1333 if (diskSet [i].ctl == hda.GetController() &&
1334 diskSet [i].dev == hda.GetDeviceNumber())
1335 {
1336 cmachine.DetachHardDisk (diskSet [i].ctl, diskSet [i].dev);
1337 if (!cmachine.isOk())
1338 vboxProblem().cannotDetachHardDisk (
1339 this, cmachine, diskSet [i].ctl, diskSet [i].dev);
1340 }
1341 }
1342 }
1343
1344 /* now, attach new disks */
1345 for (uint i = 0; i < SIZEOF_ARRAY (diskSet); i++)
1346 {
1347 QUuid *newId = diskSet [i].data.uuid;
1348 if (diskSet [i].data.grb->isChecked() && !(*newId).isNull())
1349 {
1350 cmachine.AttachHardDisk (*newId, diskSet [i].ctl, diskSet [i].dev);
1351 if (!cmachine.isOk())
1352 vboxProblem().cannotAttachHardDisk (
1353 this, cmachine, *newId, diskSet [i].ctl, diskSet [i].dev);
1354 }
1355 }
1356 }
1357
1358 /* floppy image */
1359 {
1360 CFloppyDrive floppy = cmachine.GetFloppyDrive();
1361 if (!bgFloppy->isChecked())
1362 {
1363 floppy.Unmount();
1364 }
1365 else if (rbHostFloppy->isChecked())
1366 {
1367 int id = cbHostFloppy->currentItem();
1368 Assert (id >= 0);
1369 if (id < (int) hostFloppies.count())
1370 floppy.CaptureHostDrive (hostFloppies [id]);
1371 /*
1372 * otherwise the selected drive is not yet available, leave it
1373 * as is
1374 */
1375 }
1376 else if (rbISOFloppy->isChecked())
1377 {
1378 Assert (!uuidISOFloppy.isNull());
1379 floppy.MountImage (uuidISOFloppy);
1380 }
1381 }
1382
1383 /* CD/DVD-ROM image */
1384 {
1385 CDVDDrive dvd = cmachine.GetDVDDrive();
1386 if (!bgDVD->isChecked())
1387 {
1388 dvd.Unmount();
1389 }
1390 else if (rbHostDVD->isChecked())
1391 {
1392 int id = cbHostDVD->currentItem();
1393 Assert (id >= 0);
1394 if (id < (int) hostDVDs.count())
1395 dvd.CaptureHostDrive (hostDVDs [id]);
1396 /*
1397 * otherwise the selected drive is not yet available, leave it
1398 * as is
1399 */
1400 }
1401 else if (rbISODVD->isChecked())
1402 {
1403 Assert (!uuidISODVD.isNull());
1404 dvd.MountImage (uuidISODVD);
1405 }
1406 }
1407
1408 /* audio */
1409 {
1410 CAudioAdapter audio = cmachine.GetAudioAdapter();
1411 audio.SetAudioDriver (vboxGlobal().toAudioDriverType (cbAudioDriver->currentText()));
1412 audio.SetEnabled (grbAudio->isChecked());
1413 AssertWrapperOk (audio);
1414 }
1415
1416 /* network */
1417 {
1418 for (int index = 0; index < tbwNetwork->count(); index++)
1419 {
1420 VBoxVMNetworkSettings *page =
1421 (VBoxVMNetworkSettings *) tbwNetwork->page (index);
1422 Assert (page);
1423 page->putBackToAdapter();
1424 }
1425 }
1426
1427 /* usb */
1428 {
1429 CUSBController ctl = cmachine.GetUSBController();
1430
1431 ctl.SetEnabled (cbEnableUSBController->isChecked());
1432
1433 /*
1434 * first, remove all old filters (only if the list is changed,
1435 * not only individual properties of filters)
1436 */
1437 if (mUSBFilterListModified)
1438 for (ulong count = ctl.GetDeviceFilters().GetCount(); count; -- count)
1439 ctl.RemoveDeviceFilter (0);
1440
1441 /* then add all new filters */
1442 for (QListViewItem *item = lvUSBFilters->firstChild(); item;
1443 item = item->nextSibling())
1444 {
1445 USBListItem *uli = static_cast <USBListItem *> (item);
1446 VBoxUSBFilterSettings *settings =
1447 static_cast <VBoxUSBFilterSettings *>
1448 (wstUSBFilters->widget (uli->mId));
1449 Assert (settings);
1450
1451 COMResult res = settings->putBackToFilter();
1452 if (!res.isOk())
1453 return res;
1454
1455 CUSBDeviceFilter filter = settings->filter();
1456 filter.SetActive (uli->isOn());
1457
1458 if (mUSBFilterListModified)
1459 ctl.InsertDeviceFilter (~0, filter);
1460 }
1461
1462 mUSBFilterListModified = false;
1463 }
1464
1465 return COMResult();
1466}
1467
1468
1469void VBoxVMSettingsDlg::showImageManagerHDA() { showVDImageManager (&uuidHDA, cbHDA); }
1470void VBoxVMSettingsDlg::showImageManagerHDB() { showVDImageManager (&uuidHDB, cbHDB); }
1471void VBoxVMSettingsDlg::showImageManagerHDD() { showVDImageManager (&uuidHDD, cbHDD); }
1472void VBoxVMSettingsDlg::showImageManagerISODVD() { showVDImageManager (&uuidISODVD, cbISODVD); }
1473void VBoxVMSettingsDlg::showImageManagerISOFloppy() { showVDImageManager(&uuidISOFloppy, cbISOFloppy); }
1474
1475void VBoxVMSettingsDlg::showVDImageManager (QUuid *id, VBoxMediaComboBox *cbb, QLabel*)
1476{
1477 VBoxDefs::DiskType type = VBoxDefs::InvalidType;
1478 if (cbb == cbISODVD)
1479 type = VBoxDefs::CD;
1480 else if (cbb == cbISOFloppy)
1481 type = VBoxDefs::FD;
1482 else
1483 type = VBoxDefs::HD;
1484
1485 VBoxDiskImageManagerDlg dlg (this, "VBoxDiskImageManagerDlg",
1486 WType_Dialog | WShowModal);
1487 QUuid machineId = cmachine.GetId();
1488 dlg.setup (type, true, &machineId, (const VBoxMediaList*)0, cmachine);
1489 if (dlg.exec() == VBoxDiskImageManagerDlg::Accepted)
1490 *id = dlg.getSelectedUuid();
1491 updateShortcuts (type, &dlg);
1492 cbb->setFocus();
1493}
1494
1495void VBoxVMSettingsDlg::addNetworkAdapter (const CNetworkAdapter &adapter,
1496 bool /* select */)
1497{
1498 VBoxVMNetworkSettings *page = new VBoxVMNetworkSettings ();
1499 page->getFromAdapter (adapter);
1500 tbwNetwork->addTab(page, QString("Adapter %1").arg(adapter.GetSlot()));
1501
1502 /* fix the tab order so that main dialog's buttons are always the last */
1503 setTabOrder (page->leTAPTerminate, buttonHelp);
1504 setTabOrder (buttonHelp, buttonOk);
1505 setTabOrder (buttonOk, buttonCancel);
1506
1507 /* setup validation */
1508 QIWidgetValidator *wval = new QIWidgetValidator (pageNetwork, this);
1509 connect (page->cbNetworkAttachment, SIGNAL (activated (const QString &)),
1510 wval, SLOT (revalidate()));
1511
1512 connect (page->lbHostInterface, SIGNAL ( selectionChanged () ),
1513 wval, SLOT (revalidate()));
1514 connect (page->lbHostInterface, SIGNAL ( currentChanged ( QListBoxItem * ) ),
1515 wval, SLOT (revalidate()));
1516 connect (page->lbHostInterface, SIGNAL ( highlighted ( QListBoxItem * ) ),
1517 wval, SLOT (revalidate()));
1518 connect (page->grbEnabled, SIGNAL (toggled (bool)),
1519 wval, SLOT (revalidate()));
1520
1521 connect (wval, SIGNAL (validityChanged (const QIWidgetValidator *)),
1522 this, SLOT (enableOk (const QIWidgetValidator *)));
1523 connect (wval, SIGNAL (isValidRequested (QIWidgetValidator *)),
1524 this, SLOT (revalidate( QIWidgetValidator *)));
1525
1526 wval->revalidate();
1527}
1528
1529void VBoxVMSettingsDlg::slRAM_valueChanged( int val )
1530{
1531 leRAM->setText( QString().setNum( val ) );
1532}
1533
1534void VBoxVMSettingsDlg::leRAM_textChanged( const QString &text )
1535{
1536 slRAM->setValue( text.toInt() );
1537}
1538
1539void VBoxVMSettingsDlg::slVRAM_valueChanged( int val )
1540{
1541 leVRAM->setText( QString().setNum( val ) );
1542}
1543
1544void VBoxVMSettingsDlg::leVRAM_textChanged( const QString &text )
1545{
1546 slVRAM->setValue( text.toInt() );
1547}
1548
1549void VBoxVMSettingsDlg::cbOS_activated (int item)
1550{
1551 Q_UNUSED (item);
1552/// @todo (dmik) remove?
1553// CGuestOSType type = vboxGlobal().vmGuestOSType (item);
1554// txRAMBest->setText (tr ("<qt>Best&nbsp;%1&nbsp;MB<qt>")
1555// .arg (type.GetRecommendedRAM()));
1556// txVRAMBest->setText (tr ("<qt>Best&nbsp;%1&nbsp;MB</qt>")
1557// .arg (type.GetRecommendedVRAM()));
1558 txRAMBest->setText (QString::null);
1559 txVRAMBest->setText (QString::null);
1560}
1561
1562void VBoxVMSettingsDlg::tbResetSavedStateFolder_clicked()
1563{
1564 /*
1565 * do this instead of le->setText (QString::null) to cause
1566 * isModified() return true
1567 */
1568 leSnapshotFolder->selectAll();
1569 leSnapshotFolder->del();
1570}
1571
1572void VBoxVMSettingsDlg::tbSelectSavedStateFolder_clicked()
1573{
1574 QString settingsFolder =
1575 QFileInfo (cmachine.GetSettingsFilePath()).dirPath (true);
1576
1577 QFileDialog dlg (settingsFolder, QString::null, this);
1578 dlg.setMode (QFileDialog::DirectoryOnly);
1579
1580 if (!leSnapshotFolder->text().isEmpty())
1581 {
1582 /* set the first parent directory that exists as the current */
1583 QDir dir (settingsFolder);
1584 QFileInfo fld (dir, leSnapshotFolder->text());
1585 do
1586 {
1587 QString dp = fld.dirPath (false);
1588 fld = QFileInfo (dp);
1589 }
1590 while (!fld.exists() && !QDir (fld.absFilePath()).isRoot());
1591
1592 if (fld.exists())
1593 dlg.setDir (fld.absFilePath());
1594 }
1595
1596 if (dlg.exec() == QDialog::Accepted)
1597 {
1598 QString folder = QDir::convertSeparators (dlg.selectedFile());
1599 /* remove trailing slash */
1600 folder.truncate (folder.length() - 1);
1601
1602 /*
1603 * do this instead of le->setText (folder) to cause
1604 * isModified() return true
1605 */
1606 leSnapshotFolder->selectAll();
1607 leSnapshotFolder->insert (folder);
1608 }
1609}
1610
1611// USB Filter stuff
1612////////////////////////////////////////////////////////////////////////////////
1613
1614void VBoxVMSettingsDlg::addUSBFilter (const CUSBDeviceFilter &aFilter, bool isNew)
1615{
1616 QListViewItem *currentItem = isNew
1617 ? lvUSBFilters->currentItem()
1618 : lvUSBFilters->lastItem();
1619
1620 VBoxUSBFilterSettings *settings = new VBoxUSBFilterSettings (wstUSBFilters);
1621 settings->getFromFilter (aFilter);
1622
1623 USBListItem *item = new USBListItem (lvUSBFilters, currentItem);
1624 item->setOn (aFilter.GetActive());
1625 item->setText (lvUSBFilters_Name, aFilter.GetName());
1626
1627 item->mId = wstUSBFilters->addWidget (settings);
1628
1629 /* fix the tab order so that main dialog's buttons are always the last */
1630 setTabOrder (settings->focusProxy(), buttonHelp);
1631 setTabOrder (buttonHelp, buttonOk);
1632 setTabOrder (buttonOk, buttonCancel);
1633
1634 if (isNew)
1635 {
1636 lvUSBFilters->setSelected (item, true);
1637 lvUSBFilters_currentChanged (item);
1638 settings->leUSBFilterName->setFocus();
1639 }
1640
1641 connect (settings->leUSBFilterName, SIGNAL (textChanged (const QString &)),
1642 this, SLOT (lvUSBFilters_setCurrentText (const QString &)));
1643
1644 /* setup validation */
1645
1646 QIWidgetValidator *wval = new QIWidgetValidator (settings, settings);
1647 connect (wval, SIGNAL (validityChanged (const QIWidgetValidator *)),
1648 this, SLOT (enableOk (const QIWidgetValidator *)));
1649
1650 wval->revalidate();
1651}
1652
1653void VBoxVMSettingsDlg::lvUSBFilters_currentChanged (QListViewItem *item)
1654{
1655 if (item && lvUSBFilters->selectedItem() != item)
1656 lvUSBFilters->setSelected (item, true);
1657
1658 tbRemoveUSBFilter->setEnabled (!!item);
1659
1660 tbUSBFilterUp->setEnabled (!!item && item->itemAbove());
1661 tbUSBFilterDown->setEnabled (!!item && item->itemBelow());
1662
1663 if (item)
1664 {
1665 USBListItem *uli = static_cast <USBListItem *> (item);
1666 wstUSBFilters->raiseWidget (uli->mId);
1667 }
1668 else
1669 {
1670 /* raise the disabled widget */
1671 wstUSBFilters->raiseWidget (0);
1672 }
1673}
1674
1675void VBoxVMSettingsDlg::lvUSBFilters_setCurrentText (const QString &aText)
1676{
1677 QListViewItem *item = lvUSBFilters->currentItem();
1678 Assert (item);
1679
1680 item->setText (lvUSBFilters_Name, aText);
1681}
1682
1683void VBoxVMSettingsDlg::tbAddUSBFilter_clicked()
1684{
1685 CUSBDeviceFilter filter = cmachine.GetUSBController()
1686 .CreateDeviceFilter (tr ("New Filter %1", "usb")
1687 .arg (++ mLastUSBFilterNum));
1688
1689 filter.SetActive (true);
1690 addUSBFilter (filter, true /* isNew */);
1691
1692 mUSBFilterListModified = true;
1693}
1694
1695void VBoxVMSettingsDlg::tbRemoveUSBFilter_clicked()
1696{
1697 QListViewItem *item = lvUSBFilters->currentItem();
1698 Assert (item);
1699
1700 USBListItem *uli = static_cast <USBListItem *> (item);
1701 QWidget *settings = wstUSBFilters->widget (uli->mId);
1702 Assert (settings);
1703 wstUSBFilters->removeWidget (settings);
1704 delete settings;
1705
1706 delete item;
1707
1708 lvUSBFilters->setSelected (lvUSBFilters->currentItem(), true);
1709 mUSBFilterListModified = true;
1710}
1711
1712void VBoxVMSettingsDlg::tbUSBFilterUp_clicked()
1713{
1714 QListViewItem *item = lvUSBFilters->currentItem();
1715 Assert (item);
1716
1717 QListViewItem *itemAbove = item->itemAbove();
1718 Assert (itemAbove);
1719 itemAbove = itemAbove->itemAbove();
1720
1721 if (!itemAbove)
1722 {
1723 /* overcome Qt stupidity */
1724 item->itemAbove()->moveItem (item);
1725 }
1726 else
1727 item->moveItem (itemAbove);
1728
1729 lvUSBFilters_currentChanged (item);
1730 mUSBFilterListModified = true;
1731}
1732
1733void VBoxVMSettingsDlg::tbUSBFilterDown_clicked()
1734{
1735 QListViewItem *item = lvUSBFilters->currentItem();
1736 Assert (item);
1737
1738 QListViewItem *itemBelow = item->itemBelow();
1739 Assert (itemBelow);
1740
1741 item->moveItem (itemBelow);
1742
1743 lvUSBFilters_currentChanged (item);
1744 mUSBFilterListModified = true;
1745}
1746
1747#include "VBoxVMSettingsDlg.ui.moc"
1748
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette