VirtualBox

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

Last change on this file since 1 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 58.3 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.215389.xyz. 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 /* revailidate */
678 wvalHDD->revalidate();
679}
680
681
682void VBoxVMSettingsDlg::hdbMediaChanged()
683{
684 uuidHDB = grbHDB->isChecked() ? cbHDB->getId() : QUuid();
685 txHDB->setText (getHdInfo (grbHDB, uuidHDB));
686 /* revailidate */
687 wvalHDD->revalidate();
688}
689
690
691void VBoxVMSettingsDlg::hddMediaChanged()
692{
693 uuidHDD = grbHDD->isChecked() ? cbHDD->getId() : QUuid();
694 txHDD->setText (getHdInfo (grbHDD, uuidHDD));
695 /* revailidate */
696 wvalHDD->revalidate();
697}
698
699
700void VBoxVMSettingsDlg::cdMediaChanged()
701{
702 uuidISODVD = bgDVD->isChecked() ? cbISODVD->getId() : QUuid();
703 /* revailidate */
704 wvalDVD->revalidate();
705}
706
707
708void VBoxVMSettingsDlg::fdMediaChanged()
709{
710 uuidISOFloppy = bgFloppy->isChecked() ? cbISOFloppy->getId() : QUuid();
711 /* revailidate */
712 wvalFloppy->revalidate();
713}
714
715
716QString VBoxVMSettingsDlg::getHdInfo (QGroupBox *aGroupBox, QUuid aId)
717{
718 QString notAttached = tr ("<not attached>", "hard disk");
719 if (aId.isNull())
720 return notAttached;
721 return aGroupBox->isChecked() ?
722 vboxGlobal().details (vboxGlobal().virtualBox().GetHardDisk (aId), true) :
723 notAttached;
724}
725
726void VBoxVMSettingsDlg::updateWhatsThis (bool gotFocus /* = false */)
727{
728 QString text;
729
730 QWidget *widget = NULL;
731 if (!gotFocus)
732 {
733 if (whatsThisCandidate != NULL && whatsThisCandidate != this)
734 widget = whatsThisCandidate;
735 }
736 else
737 {
738 widget = focusData()->focusWidget();
739 }
740 /* if the given widget lacks the whats'this text, look at its parent */
741 while (widget && widget != this)
742 {
743 text = QWhatsThis::textFor (widget);
744 if (!text.isEmpty())
745 break;
746 widget = widget->parentWidget();
747 }
748
749 if (text.isEmpty() && !warningString.isEmpty())
750 text = warningString;
751 if (text.isEmpty())
752 text = QWhatsThis::textFor (this);
753
754 whatsThisLabel->setText (text);
755}
756
757void VBoxVMSettingsDlg::setWarning (const QString &warning)
758{
759 warningString = warning;
760 if (!warning.isEmpty())
761 warningString = QString ("<font color=red>%1</font>").arg (warning);
762
763 if (!warningString.isEmpty())
764 whatsThisLabel->setText (warningString);
765 else
766 updateWhatsThis (true);
767}
768
769/**
770 * Sets up this dialog.
771 *
772 * @note Calling this method after the dialog is open has no sense.
773 *
774 * @param category
775 * Category to select when the dialog is open. Must be one of
776 * values from the hidden '[cat]' column of #listView
777 * (see VBoxVMSettingsDlg.ui in qdesigner) prepended with the '#'
778 * sign.
779 */
780void VBoxVMSettingsDlg::setup (const QString &category)
781{
782 if (category)
783 {
784 QListViewItem *item = listView->findItem (category, listView_Link);
785 if (item)
786 listView->setSelected (item, true);
787 }
788}
789
790void VBoxVMSettingsDlg::listView_currentChanged (QListViewItem *item)
791{
792 Assert (item);
793 int id = item->text (1).toInt();
794 Assert (id >= 0);
795 titleLabel->setText (::path (item));
796 widgetStack->raiseWidget (id);
797}
798
799
800void VBoxVMSettingsDlg::enableOk( const QIWidgetValidator *wval )
801{
802 Q_UNUSED (wval);
803
804 /* detect the overall validity */
805 bool newValid = true;
806 {
807 QObjectList *l = this->queryList ("QIWidgetValidator");
808 QObjectListIt it (*l);
809 QObject *obj;
810 while ((obj = it.current()) != 0)
811 {
812 newValid &= ((QIWidgetValidator *) obj)->isValid();
813 ++it;
814 }
815 delete l;
816 }
817
818 if (valid != newValid)
819 {
820 valid = newValid;
821 buttonOk->setEnabled (valid);
822 if (valid)
823 setWarning(0);
824 warningLabel->setHidden(valid);
825 warningPixmap->setHidden(valid);
826 }
827}
828
829
830void VBoxVMSettingsDlg::revalidate( QIWidgetValidator *wval )
831{
832 /* do individual validations for pages */
833 QWidget *pg = wval->widget();
834 bool valid = wval->isOtherValid();
835
836 if (pg == pageHDD)
837 {
838 CVirtualBox vbox = vboxGlobal().virtualBox();
839 valid = true;
840
841 QValueList <QUuid> uuids;
842
843 if (valid && grbHDA->isChecked())
844 {
845 if (uuidHDA.isNull())
846 {
847 valid = false;
848 setWarning (tr ("Primary Master hard disk is not selected."));
849 }
850 else uuids << uuidHDA;
851 }
852
853 if (valid && grbHDB->isChecked())
854 {
855 if (uuidHDB.isNull())
856 {
857 valid = false;
858 setWarning (tr ("Primary Slave hard disk is not selected."));
859 }
860 else
861 {
862 bool found = uuids.findIndex (uuidHDB) >= 0;
863 if (found)
864 {
865 CHardDisk hd = vbox.GetHardDisk (uuidHDB);
866 valid = hd.GetType() == CEnums::ImmutableHardDisk;
867 }
868 if (valid)
869 uuids << uuidHDB;
870 else
871 setWarning (tr ("Primary Slave hard disk is already attached "
872 "to a different slot."));
873 }
874 }
875
876 if (valid && grbHDD->isChecked())
877 {
878 if (uuidHDD.isNull())
879 {
880 valid = false;
881 setWarning (tr ("Secondary Slave hard disk is not selected."));
882 }
883 else
884 {
885 bool found = uuids.findIndex (uuidHDD) >= 0;
886 if (found)
887 {
888 CHardDisk hd = vbox.GetHardDisk (uuidHDD);
889 valid = hd.GetType() == CEnums::ImmutableHardDisk;
890 }
891 if (valid)
892 uuids << uuidHDB;
893 else
894 setWarning (tr ("Secondary Slave hard disk is already attached "
895 "to a different slot."));
896 }
897 }
898
899 cbHDA->setEnabled (grbHDA->isChecked());
900 cbHDB->setEnabled (grbHDB->isChecked());
901 cbHDD->setEnabled (grbHDD->isChecked());
902 tbHDA->setEnabled (grbHDA->isChecked());
903 tbHDB->setEnabled (grbHDB->isChecked());
904 tbHDD->setEnabled (grbHDD->isChecked());
905 }
906 else if (pg == pageDVD)
907 {
908 if (!bgDVD->isChecked())
909 rbHostDVD->setChecked(false), rbISODVD->setChecked(false);
910 else if (!rbHostDVD->isChecked() && !rbISODVD->isChecked())
911 rbHostDVD->setChecked(true);
912
913 valid = !(rbISODVD->isChecked() && uuidISODVD.isNull());
914
915 cbHostDVD->setEnabled (rbHostDVD->isChecked());
916
917 cbISODVD->setEnabled (rbISODVD->isChecked());
918 tbISODVD->setEnabled (rbISODVD->isChecked());
919
920 if (!valid)
921 setWarning (tr ("CD/DVD drive image file is not selected."));
922 }
923 else if (pg == pageFloppy)
924 {
925 if (!bgFloppy->isChecked())
926 rbHostFloppy->setChecked(false), rbISOFloppy->setChecked(false);
927 else if (!rbHostFloppy->isChecked() && !rbISOFloppy->isChecked())
928 rbHostFloppy->setChecked(true);
929
930 valid = !(rbISOFloppy->isChecked() && uuidISOFloppy.isNull());
931
932 cbHostFloppy->setEnabled (rbHostFloppy->isChecked());
933
934 cbISOFloppy->setEnabled (rbISOFloppy->isChecked());
935 tbISOFloppy->setEnabled (rbISOFloppy->isChecked());
936
937 if (!valid)
938 setWarning (tr ("Floppy drive image file is not selected."));
939 }
940 else if (pg == pageNetwork)
941 {
942 int slot = -1;
943 for (int index = 0; index < tbwNetwork->count(); index++)
944 {
945 QWidget* pTab = tbwNetwork->page (index);
946 Assert(pTab);
947 VBoxVMNetworkSettings* pNetSet = static_cast <VBoxVMNetworkSettings*>(pTab);
948 if (!pNetSet->grbEnabled->isChecked())
949 {
950 pNetSet->cbNetworkAttachment->setCurrentItem (0);
951 pNetSet->cbNetworkAttachment_activated (pNetSet->cbNetworkAttachment->currentText());
952 }
953
954 CEnums::NetworkAttachmentType type =
955 vboxGlobal().toNetworkAttachmentType (pNetSet->cbNetworkAttachment->currentText());
956 valid = (slot == -1) &&
957 !(type == CEnums::HostInterfaceNetworkAttachment &&
958 !pNetSet->checkNetworkInterface (pNetSet->lbHostInterface->currentText()));
959 if (slot == -1 && !valid)
960 slot = index;
961 }
962 if (!valid)
963 setWarning (tr ("Incorrect host network interface is selected for Adapter %1.")
964 .arg (slot));
965 }
966
967 wval->setOtherValid (valid);
968}
969
970
971void VBoxVMSettingsDlg::getFromMachine (const CMachine &machine)
972{
973 cmachine = machine;
974
975 setCaption (machine.GetName() + tr (" - Settings"));
976
977 CVirtualBox vbox = vboxGlobal().virtualBox();
978 CBIOSSettings biosSettings = cmachine.GetBIOSSettings();
979
980 /* name */
981 leName->setText (machine.GetName());
982
983 /* OS type */
984 CGuestOSType type = machine.GetOSType();
985 cbOS->setCurrentItem (vboxGlobal().vmGuestOSTypeIndex(type));
986 cbOS_activated (cbOS->currentItem());
987
988 /* RAM size */
989 slRAM->setValue (machine.GetMemorySize());
990
991 /* VRAM size */
992 slVRAM->setValue (machine.GetVRAMSize());
993
994 /* boot order */
995 bootDevicesInUse.clear();
996 for (int i = 0; i < tblBootOrder->numRows(); i ++)
997 {
998 QTableItem *item = tblBootOrder->item (i, 0);
999 item->setText (vboxGlobal().toString (machine.GetBootOrder (i + 1)));
1000 }
1001
1002 /* ACPI */
1003 chbEnableACPI->setChecked (biosSettings.GetACPIEnabled());
1004
1005 /* IO APIC */
1006 chbEnableIOAPIC->setChecked (biosSettings.GetIOAPICEnabled());
1007
1008 /* Saved state folder */
1009 leSnapshotFolder->setText (machine.GetSnapshotFolder());
1010
1011 /* hard disk images */
1012 {
1013 struct
1014 {
1015 CEnums::DiskControllerType ctl;
1016 LONG dev;
1017 struct {
1018 QGroupBox *grb;
1019 QComboBox *cbb;
1020 QLabel *tx;
1021 QUuid *uuid;
1022 } data;
1023 }
1024 diskSet[] =
1025 {
1026 { CEnums::IDE0Controller, 0, {grbHDA, cbHDA, txHDA, &uuidHDA} },
1027 { CEnums::IDE0Controller, 1, {grbHDB, cbHDB, txHDB, &uuidHDB} },
1028 { CEnums::IDE1Controller, 1, {grbHDD, cbHDD, txHDD, &uuidHDD} },
1029 };
1030
1031 grbHDA->setChecked (false);
1032 grbHDB->setChecked (false);
1033 grbHDD->setChecked (false);
1034
1035 CHardDiskAttachmentEnumerator en =
1036 machine.GetHardDiskAttachments().Enumerate();
1037 while (en.HasMore())
1038 {
1039 CHardDiskAttachment hda = en.GetNext();
1040 for (uint i = 0; i < SIZEOF_ARRAY (diskSet); i++)
1041 {
1042 if (diskSet [i].ctl == hda.GetController() &&
1043 diskSet [i].dev == hda.GetDeviceNumber())
1044 {
1045 CHardDisk hd = hda.GetHardDisk();
1046 CHardDisk root = hd.GetRoot();
1047 QString src = root.GetLocation();
1048 if (hd.GetStorageType() == CEnums::VirtualDiskImage)
1049 {
1050 QFileInfo fi (src);
1051 src = fi.fileName() + " (" +
1052 QDir::convertSeparators (fi.dirPath (true)) + ")";
1053 }
1054 diskSet [i].data.grb->setChecked (true);
1055 diskSet [i].data.tx->setText (vboxGlobal().details (hd));
1056 *(diskSet [i].data.uuid) = QUuid (root.GetId());
1057 }
1058 }
1059 }
1060 }
1061
1062 /* floppy image */
1063 {
1064 /* read out the host floppy drive list and prepare the combobox */
1065 CHostFloppyDriveCollection coll =
1066 vboxGlobal().virtualBox().GetHost().GetFloppyDrives();
1067 hostFloppies.resize (coll.GetCount());
1068 cbHostFloppy->clear();
1069 int id = 0;
1070 CHostFloppyDriveEnumerator en = coll.Enumerate();
1071 while (en.HasMore())
1072 {
1073 CHostFloppyDrive hostFloppy = en.GetNext();
1074 /** @todo set icon? */
1075 cbHostFloppy->insertItem (hostFloppy.GetName(), id);
1076 hostFloppies [id] = hostFloppy;
1077 ++ id;
1078 }
1079
1080 CFloppyDrive floppy = machine.GetFloppyDrive();
1081 switch (floppy.GetState())
1082 {
1083 case CEnums::HostDriveCaptured:
1084 {
1085 CHostFloppyDrive drv = floppy.GetHostDrive();
1086 QString name = drv.GetName();
1087 if (coll.FindByName (name).isNull())
1088 {
1089 /*
1090 * if the floppy drive is not currently available,
1091 * add it to the end of the list with a special mark
1092 */
1093 cbHostFloppy->insertItem ("* " + name);
1094 cbHostFloppy->setCurrentItem (cbHostFloppy->count() - 1);
1095 }
1096 else
1097 {
1098 /* this will select the correct item from the prepared list */
1099 cbHostFloppy->setCurrentText (name);
1100 }
1101 rbHostFloppy->setChecked (true);
1102 break;
1103 }
1104 case CEnums::ImageMounted:
1105 {
1106 CFloppyImage img = floppy.GetImage();
1107 QString src = img.GetFilePath();
1108 AssertMsg (!src.isNull(), ("Image file must not be null"));
1109 QFileInfo fi (src);
1110 rbISOFloppy->setChecked (true);
1111 uuidISOFloppy = QUuid (img.GetId());
1112 break;
1113 }
1114 case CEnums::NotMounted:
1115 {
1116 bgFloppy->setChecked(false);
1117 break;
1118 }
1119 default:
1120 AssertMsgFailed (("invalid floppy state: %d\n", floppy.GetState()));
1121 }
1122 }
1123
1124 /* CD/DVD-ROM image */
1125 {
1126 /* read out the host DVD drive list and prepare the combobox */
1127 CHostDVDDriveCollection coll =
1128 vboxGlobal().virtualBox().GetHost().GetDVDDrives();
1129 hostDVDs.resize (coll.GetCount());
1130 cbHostDVD->clear();
1131 int id = 0;
1132 CHostDVDDriveEnumerator en = coll.Enumerate();
1133 while (en.HasMore())
1134 {
1135 CHostDVDDrive hostDVD = en.GetNext();
1136 /// @todo (r=dmik) set icon?
1137 cbHostDVD->insertItem (hostDVD.GetName(), id);
1138 hostDVDs [id] = hostDVD;
1139 ++ id;
1140 }
1141
1142 CDVDDrive dvd = machine.GetDVDDrive();
1143 switch (dvd.GetState())
1144 {
1145 case CEnums::HostDriveCaptured:
1146 {
1147 CHostDVDDrive drv = dvd.GetHostDrive();
1148 QString name = drv.GetName();
1149 if (coll.FindByName (name).isNull())
1150 {
1151 /*
1152 * if the DVD drive is not currently available,
1153 * add it to the end of the list with a special mark
1154 */
1155 cbHostDVD->insertItem ("* " + name);
1156 cbHostDVD->setCurrentItem (cbHostDVD->count() - 1);
1157 }
1158 else
1159 {
1160 /* this will select the correct item from the prepared list */
1161 cbHostDVD->setCurrentText (name);
1162 }
1163 rbHostDVD->setChecked (true);
1164 break;
1165 }
1166 case CEnums::ImageMounted:
1167 {
1168 CDVDImage img = dvd.GetImage();
1169 QString src = img.GetFilePath();
1170 AssertMsg (!src.isNull(), ("Image file must not be null"));
1171 QFileInfo fi (src);
1172 rbISODVD->setChecked (true);
1173 uuidISODVD = QUuid (img.GetId());
1174 break;
1175 }
1176 case CEnums::NotMounted:
1177 {
1178 bgDVD->setChecked(false);
1179 break;
1180 }
1181 default:
1182 AssertMsgFailed (("invalid DVD state: %d\n", dvd.GetState()));
1183 }
1184 }
1185
1186 /* audio */
1187 {
1188 CAudioAdapter audio = machine.GetAudioAdapter();
1189 grbAudio->setChecked (audio.GetEnabled());
1190 cbAudioDriver->setCurrentText (vboxGlobal().toString (audio.GetAudioDriver()));
1191 }
1192
1193 /* network */
1194 {
1195 ulong count = vbox.GetSystemProperties().GetNetworkAdapterCount();
1196 for (ulong slot = 0; slot < count; slot ++)
1197 {
1198 CNetworkAdapter adapter = machine.GetNetworkAdapter (slot);
1199 addNetworkAdapter (adapter, false);
1200 }
1201 }
1202
1203 /* usb */
1204 {
1205 CUSBController ctl = machine.GetUSBController();
1206
1207 QListViewItem *usbListItem = listView->findItem ("USB", 0, Qt::Contains);
1208 if (usbListItem && ctl.isNull())
1209 usbListItem->setVisible (false);
1210
1211 cbEnableUSBController->setChecked (ctl.GetEnabled());
1212
1213 CUSBDeviceFilterEnumerator en = ctl.GetDeviceFilters().Enumerate();
1214 while (en.HasMore())
1215 addUSBFilter (en.GetNext(), false /* isNew */);
1216
1217 lvUSBFilters->setCurrentItem (lvUSBFilters->firstChild());
1218 /*
1219 * silly, silly Qt -- doesn't emit currentChanged after adding the
1220 * first item to an empty list
1221 */
1222 lvUSBFilters_currentChanged (lvUSBFilters->firstChild());
1223 }
1224
1225 /* request for media shortcuts update */
1226 cbHDA->setBelongsTo(machine.GetId());
1227 cbHDB->setBelongsTo(machine.GetId());
1228 cbHDD->setBelongsTo(machine.GetId());
1229 updateShortcuts (VBoxDefs::InvalidType);
1230
1231 /* revalidate pages with custom validation */
1232 wvalHDD->revalidate();
1233 wvalDVD->revalidate();
1234 wvalFloppy->revalidate();
1235}
1236
1237
1238COMResult VBoxVMSettingsDlg::putBackToMachine()
1239{
1240 CVirtualBox vbox = vboxGlobal().virtualBox();
1241 CBIOSSettings biosSettings = cmachine.GetBIOSSettings();
1242
1243 /* name */
1244 cmachine.SetName (leName->text());
1245
1246 /* OS type */
1247 CGuestOSType type = vboxGlobal().vmGuestOSType (cbOS->currentItem());
1248 AssertMsg (!type.isNull(), ("vmGuestOSType() must return non-null type"));
1249 cmachine.SetOSType (type);
1250
1251 /* RAM size */
1252 cmachine.SetMemorySize (slRAM->value());
1253
1254 /* VRAM size */
1255 cmachine.SetVRAMSize (slVRAM->value());
1256
1257 /* boot order */
1258 for (int i = 0; i < tblBootOrder->numRows(); i ++)
1259 {
1260 QTableItem *item = tblBootOrder->item (i, 0);
1261 cmachine.SetBootOrder (i + 1, vboxGlobal().toDeviceType (item->text()));
1262 }
1263
1264 /* ACPI */
1265 biosSettings.SetACPIEnabled (chbEnableACPI->isChecked());
1266
1267 /* IO APIC */
1268 biosSettings.SetIOAPICEnabled (chbEnableIOAPIC->isChecked());
1269
1270 /* Saved state folder */
1271 if (leSnapshotFolder->isModified())
1272 cmachine.SetSnapshotFolder (leSnapshotFolder->text());
1273
1274 /* hard disk images */
1275 {
1276 struct
1277 {
1278 CEnums::DiskControllerType ctl;
1279 LONG dev;
1280 struct {
1281 QGroupBox *grb;
1282 QUuid *uuid;
1283 } data;
1284 }
1285 diskSet[] =
1286 {
1287 { CEnums::IDE0Controller, 0, {grbHDA, &uuidHDA} },
1288 { CEnums::IDE0Controller, 1, {grbHDB, &uuidHDB} },
1289 { CEnums::IDE1Controller, 1, {grbHDD, &uuidHDD} }
1290 };
1291
1292 /*
1293 * first, detach all disks (to ensure we can reattach them to different
1294 * controllers / devices, when appropriate)
1295 */
1296 CHardDiskAttachmentEnumerator en =
1297 cmachine.GetHardDiskAttachments().Enumerate();
1298 while (en.HasMore())
1299 {
1300 CHardDiskAttachment hda = en.GetNext();
1301 for (uint i = 0; i < SIZEOF_ARRAY (diskSet); i++)
1302 {
1303 if (diskSet [i].ctl == hda.GetController() &&
1304 diskSet [i].dev == hda.GetDeviceNumber())
1305 {
1306 cmachine.DetachHardDisk (diskSet [i].ctl, diskSet [i].dev);
1307 if (!cmachine.isOk())
1308 vboxProblem().cannotDetachHardDisk (
1309 this, cmachine, diskSet [i].ctl, diskSet [i].dev);
1310 }
1311 }
1312 }
1313
1314 /* now, attach new disks */
1315 for (uint i = 0; i < SIZEOF_ARRAY (diskSet); i++)
1316 {
1317 QUuid *newId = diskSet [i].data.uuid;
1318 if (diskSet [i].data.grb->isChecked() && !(*newId).isNull())
1319 {
1320 cmachine.AttachHardDisk (*newId, diskSet [i].ctl, diskSet [i].dev);
1321 if (!cmachine.isOk())
1322 vboxProblem().cannotAttachHardDisk (
1323 this, cmachine, *newId, diskSet [i].ctl, diskSet [i].dev);
1324 }
1325 }
1326 }
1327
1328 /* floppy image */
1329 {
1330 CFloppyDrive floppy = cmachine.GetFloppyDrive();
1331 if (!bgFloppy->isChecked())
1332 {
1333 floppy.Unmount();
1334 }
1335 else if (rbHostFloppy->isChecked())
1336 {
1337 int id = cbHostFloppy->currentItem();
1338 Assert (id >= 0);
1339 if (id < (int) hostFloppies.count())
1340 floppy.CaptureHostDrive (hostFloppies [id]);
1341 /*
1342 * otherwise the selected drive is not yet available, leave it
1343 * as is
1344 */
1345 }
1346 else if (rbISOFloppy->isChecked())
1347 {
1348 Assert (!uuidISOFloppy.isNull());
1349 floppy.MountImage (uuidISOFloppy);
1350 }
1351 }
1352
1353 /* CD/DVD-ROM image */
1354 {
1355 CDVDDrive dvd = cmachine.GetDVDDrive();
1356 if (!bgDVD->isChecked())
1357 {
1358 dvd.Unmount();
1359 }
1360 else if (rbHostDVD->isChecked())
1361 {
1362 int id = cbHostDVD->currentItem();
1363 Assert (id >= 0);
1364 if (id < (int) hostDVDs.count())
1365 dvd.CaptureHostDrive (hostDVDs [id]);
1366 /*
1367 * otherwise the selected drive is not yet available, leave it
1368 * as is
1369 */
1370 }
1371 else if (rbISODVD->isChecked())
1372 {
1373 Assert (!uuidISODVD.isNull());
1374 dvd.MountImage (uuidISODVD);
1375 }
1376 }
1377
1378 /* audio */
1379 {
1380 CAudioAdapter audio = cmachine.GetAudioAdapter();
1381 audio.SetAudioDriver (vboxGlobal().toAudioDriverType (cbAudioDriver->currentText()));
1382 audio.SetEnabled (grbAudio->isChecked());
1383 AssertWrapperOk (audio);
1384 }
1385
1386 /* network */
1387 {
1388 for (int index = 0; index < tbwNetwork->count(); index++)
1389 {
1390 VBoxVMNetworkSettings *page =
1391 (VBoxVMNetworkSettings *) tbwNetwork->page (index);
1392 Assert (page);
1393 page->putBackToAdapter();
1394 }
1395 }
1396
1397 /* usb */
1398 {
1399 CUSBController ctl = cmachine.GetUSBController();
1400
1401 ctl.SetEnabled (cbEnableUSBController->isChecked());
1402
1403 /*
1404 * first, remove all old filters (only if the list is changed,
1405 * not only individual properties of filters)
1406 */
1407 if (mUSBFilterListModified)
1408 for (ulong count = ctl.GetDeviceFilters().GetCount(); count; -- count)
1409 ctl.RemoveDeviceFilter (0);
1410
1411 /* then add all new filters */
1412 for (QListViewItem *item = lvUSBFilters->firstChild(); item;
1413 item = item->nextSibling())
1414 {
1415 USBListItem *uli = static_cast <USBListItem *> (item);
1416 VBoxUSBFilterSettings *settings =
1417 static_cast <VBoxUSBFilterSettings *>
1418 (wstUSBFilters->widget (uli->mId));
1419 Assert (settings);
1420
1421 COMResult res = settings->putBackToFilter();
1422 if (!res.isOk())
1423 return res;
1424
1425 CUSBDeviceFilter filter = settings->filter();
1426 filter.SetActive (uli->isOn());
1427
1428 if (mUSBFilterListModified)
1429 ctl.InsertDeviceFilter (~0, filter);
1430 }
1431
1432 mUSBFilterListModified = false;
1433 }
1434
1435 return COMResult();
1436}
1437
1438
1439void VBoxVMSettingsDlg::showImageManagerHDA() { showVDImageManager (&uuidHDA, cbHDA); }
1440void VBoxVMSettingsDlg::showImageManagerHDB() { showVDImageManager (&uuidHDB, cbHDB); }
1441void VBoxVMSettingsDlg::showImageManagerHDD() { showVDImageManager (&uuidHDD, cbHDD); }
1442void VBoxVMSettingsDlg::showImageManagerISODVD() { showVDImageManager (&uuidISODVD, cbISODVD); }
1443void VBoxVMSettingsDlg::showImageManagerISOFloppy() { showVDImageManager(&uuidISOFloppy, cbISOFloppy); }
1444
1445void VBoxVMSettingsDlg::showVDImageManager (QUuid *id, VBoxMediaComboBox *cbb, QLabel*)
1446{
1447 VBoxDefs::DiskType type = VBoxDefs::InvalidType;
1448 if (cbb == cbISODVD)
1449 type = VBoxDefs::CD;
1450 else if (cbb == cbISOFloppy)
1451 type = VBoxDefs::FD;
1452 else
1453 type = VBoxDefs::HD;
1454
1455 VBoxDiskImageManagerDlg dlg (this, "VBoxDiskImageManagerDlg",
1456 WType_Dialog | WShowModal);
1457 QUuid machineId = cmachine.GetId();
1458 dlg.setup (type, true, &machineId, (const VBoxMediaList*)0, cmachine);
1459 if (dlg.exec() == VBoxDiskImageManagerDlg::Accepted)
1460 *id = dlg.getSelectedUuid();
1461 updateShortcuts (type, &dlg);
1462 cbb->setFocus();
1463}
1464
1465void VBoxVMSettingsDlg::addNetworkAdapter (const CNetworkAdapter &adapter,
1466 bool /* select */)
1467{
1468 VBoxVMNetworkSettings *page = new VBoxVMNetworkSettings ();
1469 page->getFromAdapter (adapter);
1470 tbwNetwork->addTab(page, QString("Adapter %1").arg(adapter.GetSlot()));
1471
1472 /* fix the tab order so that main dialog's buttons are always the last */
1473 setTabOrder (page->leTAPTerminate, buttonHelp);
1474 setTabOrder (buttonHelp, buttonOk);
1475 setTabOrder (buttonOk, buttonCancel);
1476
1477 /* setup validation */
1478 QIWidgetValidator *wval = new QIWidgetValidator (pageNetwork, this);
1479 connect (page->cbNetworkAttachment, SIGNAL (activated (const QString &)),
1480 wval, SLOT (revalidate()));
1481
1482 connect (page->lbHostInterface, SIGNAL ( selectionChanged () ),
1483 wval, SLOT (revalidate()));
1484 connect (page->lbHostInterface, SIGNAL ( currentChanged ( QListBoxItem * ) ),
1485 wval, SLOT (revalidate()));
1486 connect (page->lbHostInterface, SIGNAL ( highlighted ( QListBoxItem * ) ),
1487 wval, SLOT (revalidate()));
1488 connect (page->grbEnabled, SIGNAL (toggled (bool)),
1489 wval, SLOT (revalidate()));
1490
1491 connect (wval, SIGNAL (validityChanged (const QIWidgetValidator *)),
1492 this, SLOT (enableOk (const QIWidgetValidator *)));
1493 connect (wval, SIGNAL (isValidRequested (QIWidgetValidator *)),
1494 this, SLOT (revalidate( QIWidgetValidator *)));
1495
1496 wval->revalidate();
1497}
1498
1499void VBoxVMSettingsDlg::slRAM_valueChanged( int val )
1500{
1501 leRAM->setText( QString().setNum( val ) );
1502}
1503
1504void VBoxVMSettingsDlg::leRAM_textChanged( const QString &text )
1505{
1506 slRAM->setValue( text.toInt() );
1507}
1508
1509void VBoxVMSettingsDlg::slVRAM_valueChanged( int val )
1510{
1511 leVRAM->setText( QString().setNum( val ) );
1512}
1513
1514void VBoxVMSettingsDlg::leVRAM_textChanged( const QString &text )
1515{
1516 slVRAM->setValue( text.toInt() );
1517}
1518
1519void VBoxVMSettingsDlg::cbOS_activated (int item)
1520{
1521 Q_UNUSED (item);
1522/// @todo (dmik) remove?
1523// CGuestOSType type = vboxGlobal().vmGuestOSType (item);
1524// txRAMBest->setText (tr ("<qt>Best&nbsp;%1&nbsp;MB<qt>")
1525// .arg (type.GetRecommendedRAM()));
1526// txVRAMBest->setText (tr ("<qt>Best&nbsp;%1&nbsp;MB</qt>")
1527// .arg (type.GetRecommendedVRAM()));
1528 txRAMBest->setText (QString::null);
1529 txVRAMBest->setText (QString::null);
1530}
1531
1532void VBoxVMSettingsDlg::tbResetSavedStateFolder_clicked()
1533{
1534 /*
1535 * do this instead of le->setText (QString::null) to cause
1536 * isModified() return true
1537 */
1538 leSnapshotFolder->selectAll();
1539 leSnapshotFolder->del();
1540}
1541
1542void VBoxVMSettingsDlg::tbSelectSavedStateFolder_clicked()
1543{
1544 QString settingsFolder =
1545 QFileInfo (cmachine.GetSettingsFilePath()).dirPath (true);
1546
1547 QFileDialog dlg (settingsFolder, QString::null, this);
1548 dlg.setMode (QFileDialog::DirectoryOnly);
1549
1550 if (!leSnapshotFolder->text().isEmpty())
1551 {
1552 /* set the first parent directory that exists as the current */
1553 QDir dir (settingsFolder);
1554 QFileInfo fld (dir, leSnapshotFolder->text());
1555 do
1556 {
1557 QString dp = fld.dirPath (false);
1558 fld = QFileInfo (dp);
1559 }
1560 while (!fld.exists() && !QDir (fld.absFilePath()).isRoot());
1561
1562 if (fld.exists())
1563 dlg.setDir (fld.absFilePath());
1564 }
1565
1566 if (dlg.exec() == QDialog::Accepted)
1567 {
1568 QString folder = QDir::convertSeparators (dlg.selectedFile());
1569 /* remove trailing slash */
1570 folder.truncate (folder.length() - 1);
1571
1572 /*
1573 * do this instead of le->setText (folder) to cause
1574 * isModified() return true
1575 */
1576 leSnapshotFolder->selectAll();
1577 leSnapshotFolder->insert (folder);
1578 }
1579}
1580
1581// USB Filter stuff
1582////////////////////////////////////////////////////////////////////////////////
1583
1584void VBoxVMSettingsDlg::addUSBFilter (const CUSBDeviceFilter &aFilter, bool isNew)
1585{
1586 QListViewItem *currentItem = isNew
1587 ? lvUSBFilters->currentItem()
1588 : lvUSBFilters->lastItem();
1589
1590 VBoxUSBFilterSettings *settings = new VBoxUSBFilterSettings (wstUSBFilters);
1591 settings->getFromFilter (aFilter);
1592
1593 USBListItem *item = new USBListItem (lvUSBFilters, currentItem);
1594 item->setOn (aFilter.GetActive());
1595 item->setText (lvUSBFilters_Name, aFilter.GetName());
1596
1597 item->mId = wstUSBFilters->addWidget (settings);
1598
1599 /* fix the tab order so that main dialog's buttons are always the last */
1600 setTabOrder (settings->focusProxy(), buttonHelp);
1601 setTabOrder (buttonHelp, buttonOk);
1602 setTabOrder (buttonOk, buttonCancel);
1603
1604 if (isNew)
1605 {
1606 lvUSBFilters->setSelected (item, true);
1607 lvUSBFilters_currentChanged (item);
1608 settings->leUSBFilterName->setFocus();
1609 }
1610
1611 connect (settings->leUSBFilterName, SIGNAL (textChanged (const QString &)),
1612 this, SLOT (lvUSBFilters_setCurrentText (const QString &)));
1613
1614 /* setup validation */
1615
1616 QIWidgetValidator *wval = new QIWidgetValidator (settings, settings);
1617 connect (wval, SIGNAL (validityChanged (const QIWidgetValidator *)),
1618 this, SLOT (enableOk (const QIWidgetValidator *)));
1619
1620 wval->revalidate();
1621}
1622
1623void VBoxVMSettingsDlg::lvUSBFilters_currentChanged (QListViewItem *item)
1624{
1625 if (item && lvUSBFilters->selectedItem() != item)
1626 lvUSBFilters->setSelected (item, true);
1627
1628 tbRemoveUSBFilter->setEnabled (!!item);
1629
1630 tbUSBFilterUp->setEnabled (!!item && item->itemAbove());
1631 tbUSBFilterDown->setEnabled (!!item && item->itemBelow());
1632
1633 if (item)
1634 {
1635 USBListItem *uli = static_cast <USBListItem *> (item);
1636 wstUSBFilters->raiseWidget (uli->mId);
1637 }
1638 else
1639 {
1640 /* raise the disabled widget */
1641 wstUSBFilters->raiseWidget (0);
1642 }
1643}
1644
1645void VBoxVMSettingsDlg::lvUSBFilters_setCurrentText (const QString &aText)
1646{
1647 QListViewItem *item = lvUSBFilters->currentItem();
1648 Assert (item);
1649
1650 item->setText (lvUSBFilters_Name, aText);
1651}
1652
1653void VBoxVMSettingsDlg::tbAddUSBFilter_clicked()
1654{
1655 CUSBDeviceFilter filter = cmachine.GetUSBController()
1656 .CreateDeviceFilter (tr ("New Filter %1", "usb")
1657 .arg (++ mLastUSBFilterNum));
1658
1659 filter.SetActive (true);
1660 addUSBFilter (filter, true /* isNew */);
1661
1662 mUSBFilterListModified = true;
1663}
1664
1665void VBoxVMSettingsDlg::tbRemoveUSBFilter_clicked()
1666{
1667 QListViewItem *item = lvUSBFilters->currentItem();
1668 Assert (item);
1669
1670 USBListItem *uli = static_cast <USBListItem *> (item);
1671 QWidget *settings = wstUSBFilters->widget (uli->mId);
1672 Assert (settings);
1673 wstUSBFilters->removeWidget (settings);
1674 delete settings;
1675
1676 delete item;
1677
1678 lvUSBFilters->setSelected (lvUSBFilters->currentItem(), true);
1679 mUSBFilterListModified = true;
1680}
1681
1682void VBoxVMSettingsDlg::tbUSBFilterUp_clicked()
1683{
1684 QListViewItem *item = lvUSBFilters->currentItem();
1685 Assert (item);
1686
1687 QListViewItem *itemAbove = item->itemAbove();
1688 Assert (itemAbove);
1689 itemAbove = itemAbove->itemAbove();
1690
1691 if (!itemAbove)
1692 {
1693 /* overcome Qt stupidity */
1694 item->itemAbove()->moveItem (item);
1695 }
1696 else
1697 item->moveItem (itemAbove);
1698
1699 lvUSBFilters_currentChanged (item);
1700 mUSBFilterListModified = true;
1701}
1702
1703void VBoxVMSettingsDlg::tbUSBFilterDown_clicked()
1704{
1705 QListViewItem *item = lvUSBFilters->currentItem();
1706 Assert (item);
1707
1708 QListViewItem *itemBelow = item->itemBelow();
1709 Assert (itemBelow);
1710
1711 item->moveItem (itemBelow);
1712
1713 lvUSBFilters_currentChanged (item);
1714 mUSBFilterListModified = true;
1715}
1716
1717#include "VBoxVMSettingsDlg.ui.moc"
1718
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