VirtualBox

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

Last change on this file since 6383 was 6383, checked in by vboxsync, 17 years ago

FE/Qt: Please do it like this.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 96.2 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-2007 innotek 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 (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19/****************************************************************************
20** ui.h extension file, included from the uic-generated form implementation.
21**
22** If you wish to add, delete or rename functions or slots use
23** Qt Designer which will update this file, preserving your code. Create an
24** init() function in place of a constructor, and a destroy() function in
25** place of a destructor.
26*****************************************************************************/
27
28
29/**
30 * QDialog class reimplementation to use for adding network interface.
31 * It has one line-edit field for entering network interface's name and
32 * common dialog's ok/cancel buttons.
33 */
34class VBoxAddNIDialog : public QDialog
35{
36 Q_OBJECT
37
38public:
39
40 VBoxAddNIDialog (QWidget *aParent, const QString &aIfaceName) :
41 QDialog (aParent, "VBoxAddNIDialog", true /* modal */),
42 mLeName (0)
43 {
44 setCaption (tr ("Add Host Interface"));
45 QVBoxLayout *mainLayout = new QVBoxLayout (this, 10, 10, "mainLayout");
46
47 /* Setup Input layout */
48 QHBoxLayout *inputLayout = new QHBoxLayout (mainLayout, 10, "inputLayout");
49 QLabel *lbName = new QLabel (tr ("Interface Name"), this);
50 mLeName = new QLineEdit (aIfaceName, this);
51 QWhatsThis::add (mLeName, tr ("Descriptive name of the new network interface"));
52 inputLayout->addWidget (lbName);
53 inputLayout->addWidget (mLeName);
54 connect (mLeName, SIGNAL (textChanged (const QString &)),
55 this, SLOT (validate()));
56
57 /* Setup Button layout */
58 QHBoxLayout *buttonLayout = new QHBoxLayout (mainLayout, 10, "buttonLayout");
59 mBtOk = new QPushButton (tr ("&OK"), this, "mBtOk");
60 QSpacerItem *spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
61 QPushButton *btCancel = new QPushButton (tr ("Cancel"), this, "btCancel");
62 connect (mBtOk, SIGNAL (clicked()), this, SLOT (accept()));
63 connect (btCancel, SIGNAL (clicked()), this, SLOT (reject()));
64 buttonLayout->addWidget (mBtOk);
65 buttonLayout->addItem (spacer);
66 buttonLayout->addWidget (btCancel);
67
68 /* resize to fit the aIfaceName in one string */
69 int requiredWidth = mLeName->fontMetrics().width (aIfaceName) +
70 mLeName->frameWidth() * 2 +
71 mLeName->lineWidth() * 2 +
72 inputLayout->spacing() +
73 lbName->fontMetrics().width (lbName->text()) +
74 lbName->frameWidth() * 2 +
75 lbName->lineWidth() * 2 +
76 mainLayout->margin() * 2;
77 resize (requiredWidth, minimumHeight());
78
79 /* Validate interface name field */
80 validate();
81 }
82
83 ~VBoxAddNIDialog() {}
84
85 QString getName() { return mLeName->text(); }
86
87private slots:
88
89 void validate()
90 {
91 mBtOk->setEnabled (!mLeName->text().isEmpty());
92 }
93
94private:
95
96 void showEvent (QShowEvent *aEvent)
97 {
98 setFixedHeight (height());
99 QDialog::showEvent (aEvent);
100 }
101
102 QPushButton *mBtOk;
103 QLineEdit *mLeName;
104};
105
106
107/**
108 * Calculates a suitable page step size for the given max value.
109 * The returned size is so that there will be no more than 32 pages.
110 * The minimum returned page size is 4.
111 */
112static int calcPageStep (int aMax)
113{
114 /* reasonable max. number of page steps is 32 */
115 uint page = ((uint) aMax + 31) / 32;
116 /* make it a power of 2 */
117 uint p = page, p2 = 0x1;
118 while ((p >>= 1))
119 p2 <<= 1;
120 if (page != p2)
121 p2 <<= 1;
122 if (p2 < 4)
123 p2 = 4;
124 return (int) p2;
125}
126
127
128/**
129 * QListView class reimplementation to use as boot items table.
130 * It has one unsorted column without header with automated width
131 * resize management.
132 * Keymapping handlers for ctrl-up & ctrl-down are translated into
133 * boot-items up/down moving.
134 */
135class BootItemsTable : public QListView
136{
137 Q_OBJECT
138
139public:
140
141 BootItemsTable (QWidget *aParent, const char *aName)
142 : QListView (aParent, aName)
143 {
144 addColumn (QString::null);
145 header()->hide();
146 setSorting (-1);
147 setColumnWidthMode (0, Maximum);
148 setResizeMode (AllColumns);
149 QWhatsThis::add (this, tr ("Defines the boot device order. "
150 "Use checkboxes to the left to enable or disable "
151 "individual boot devices. Move items up and down to "
152 "change the device order."));
153 setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Preferred);
154 connect (this, SIGNAL (pressed (QListViewItem*)),
155 this, SLOT (processPressed (QListViewItem*)));
156 }
157
158 ~BootItemsTable() {}
159
160 void emitItemToggled() { emit itemToggled(); }
161
162signals:
163
164 void moveItemUp();
165 void moveItemDown();
166 void itemToggled();
167
168private slots:
169
170 void processPressed (QListViewItem *aItem)
171 {
172 if (!aItem)
173 setSelected (currentItem(), true);
174 }
175
176 void keyPressEvent (QKeyEvent *aEvent)
177 {
178 if (aEvent->state() == Qt::ControlButton)
179 {
180 switch (aEvent->key())
181 {
182 case Qt::Key_Up:
183 emit moveItemUp();
184 return;
185 case Qt::Key_Down:
186 emit moveItemDown();
187 return;
188 default:
189 break;
190 }
191 }
192 QListView::keyPressEvent (aEvent);
193 }
194};
195
196
197/**
198 * QWidget class reimplementation to use as boot items widget.
199 * It contains BootItemsTable and two tool-buttons for moving
200 * boot-items up/down.
201 * This widget handles saving/loading CMachine information related
202 * to boot sequience.
203 */
204class BootItemsList : public QWidget
205{
206 Q_OBJECT
207
208 class BootItem : public QCheckListItem
209 {
210 public:
211
212 BootItem (BootItemsTable *aParent, QListViewItem *aAfter,
213 const QString &aName, Type aType)
214 : QCheckListItem (aParent, aAfter, aName, aType) {}
215
216 private:
217
218 void stateChange (bool)
219 {
220 BootItemsTable *table = static_cast<BootItemsTable*> (listView());
221 table->emitItemToggled();
222 }
223 };
224
225public:
226
227 BootItemsList (QWidget *aParent, const char *aName)
228 : QWidget (aParent, aName), mBootTable (0)
229 {
230 /* Setup main widget layout */
231 QHBoxLayout *mainLayout = new QHBoxLayout (this, 0, 6, "mainLayout");
232
233 /* Setup settings layout */
234 mBootTable = new BootItemsTable (this, "mBootTable");
235 connect (mBootTable, SIGNAL (currentChanged (QListViewItem*)),
236 this, SLOT (processCurrentChanged (QListViewItem*)));
237 mainLayout->addWidget (mBootTable);
238
239 /* Setup button's layout */
240 QVBoxLayout *buttonLayout = new QVBoxLayout (mainLayout, 0, "buttonLayout");
241 mBtnUp = new QToolButton (this, "mBtnUp");
242 mBtnDown = new QToolButton (this, "mBtnDown");
243 mBtnUp->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
244 mBtnDown->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
245 QWhatsThis::add (mBtnUp, tr ("Moves the selected boot device up."));
246 QWhatsThis::add (mBtnDown, tr ("Moves the selected boot device down."));
247 QToolTip::add (mBtnUp, tr ("Move Up (Ctrl-Up)"));
248 QToolTip::add (mBtnDown, tr ("Move Down (Ctrl-Down)"));
249 mBtnUp->setAutoRaise (true);
250 mBtnDown->setAutoRaise (true);
251 mBtnUp->setFocusPolicy (QWidget::StrongFocus);
252 mBtnDown->setFocusPolicy (QWidget::StrongFocus);
253 mBtnUp->setIconSet (VBoxGlobal::iconSet ("list_moveup_16px.png",
254 "list_moveup_disabled_16px.png"));
255 mBtnDown->setIconSet (VBoxGlobal::iconSet ("list_movedown_16px.png",
256 "list_movedown_disabled_16px.png"));
257 QSpacerItem *spacer = new QSpacerItem (0, 0, QSizePolicy::Minimum,
258 QSizePolicy::Minimum);
259 connect (mBtnUp, SIGNAL (clicked()), this, SLOT (moveItemUp()));
260 connect (mBtnDown, SIGNAL (clicked()), this, SLOT (moveItemDown()));
261 connect (mBootTable, SIGNAL (moveItemUp()), this, SLOT (moveItemUp()));
262 connect (mBootTable, SIGNAL (moveItemDown()), this, SLOT (moveItemDown()));
263 connect (mBootTable, SIGNAL (itemToggled()), this, SLOT (onItemToggled()));
264 buttonLayout->addWidget (mBtnUp);
265 buttonLayout->addWidget (mBtnDown);
266 buttonLayout->addItem (spacer);
267
268 /* Setup focus proxy for BootItemsList */
269 setFocusProxy (mBootTable);
270 }
271
272 ~BootItemsList() {}
273
274 void fixTabStops()
275 {
276 /* fix focus order for BootItemsList */
277 setTabOrder (mBootTable, mBtnUp);
278 setTabOrder (mBtnUp, mBtnDown);
279 }
280
281 void getFromMachine (const CMachine &aMachine)
282 {
283 /* Load boot-items of current VM */
284 QStringList uniqueList;
285 int minimumWidth = 0;
286 for (int i = 1; i <= 4; ++ i)
287 {
288 CEnums::DeviceType type = aMachine.GetBootOrder (i);
289 if (type != CEnums::NoDevice)
290 {
291 QString name = vboxGlobal().toString (type);
292 QCheckListItem *item = new BootItem (mBootTable,
293 mBootTable->lastItem(), name, QCheckListItem::CheckBox);
294 item->setOn (true);
295 uniqueList << name;
296 int width = item->width (mBootTable->fontMetrics(), mBootTable, 0);
297 if (width > minimumWidth) minimumWidth = width;
298 }
299 }
300 /* Load other unique boot-items */
301 for (int i = CEnums::FloppyDevice; i < CEnums::USBDevice; ++ i)
302 {
303 QString name = vboxGlobal().toString ((CEnums::DeviceType) i);
304 if (!uniqueList.contains (name))
305 {
306 QCheckListItem *item = new BootItem (mBootTable,
307 mBootTable->lastItem(), name, QCheckListItem::CheckBox);
308 uniqueList << name;
309 int width = item->width (mBootTable->fontMetrics(), mBootTable, 0);
310 if (width > minimumWidth) minimumWidth = width;
311 }
312 }
313 processCurrentChanged (mBootTable->firstChild());
314 mBootTable->setFixedWidth (minimumWidth +
315 4 /* viewport margin */);
316 mBootTable->setFixedHeight (mBootTable->childCount() *
317 mBootTable->firstChild()->totalHeight() +
318 4 /* viewport margin */);
319 }
320
321 void putBackToMachine (CMachine &aMachine)
322 {
323 QCheckListItem *item = 0;
324 /* Search for checked items */
325 int index = 1;
326 item = static_cast<QCheckListItem*> (mBootTable->firstChild());
327 while (item)
328 {
329 if (item->isOn())
330 {
331 CEnums::DeviceType type =
332 vboxGlobal().toDeviceType (item->text (0));
333 aMachine.SetBootOrder (index++, type);
334 }
335 item = static_cast<QCheckListItem*> (item->nextSibling());
336 }
337 /* Search for non-checked items */
338 item = static_cast<QCheckListItem*> (mBootTable->firstChild());
339 while (item)
340 {
341 if (!item->isOn())
342 aMachine.SetBootOrder (index++, CEnums::NoDevice);
343 item = static_cast<QCheckListItem*> (item->nextSibling());
344 }
345 }
346
347 void processFocusIn (QWidget *aWidget)
348 {
349 if (aWidget == mBootTable)
350 {
351 mBootTable->setSelected (mBootTable->currentItem(), true);
352 processCurrentChanged (mBootTable->currentItem());
353 }
354 else if (aWidget != mBtnUp && aWidget != mBtnDown)
355 {
356 mBootTable->setSelected (mBootTable->currentItem(), false);
357 processCurrentChanged (mBootTable->currentItem());
358 }
359 }
360
361signals:
362
363 void bootSequenceChanged();
364
365private slots:
366
367 void moveItemUp()
368 {
369 QListViewItem *item = mBootTable->currentItem();
370 Assert (item);
371 QListViewItem *itemAbove = item->itemAbove();
372 if (!itemAbove) return;
373 itemAbove->moveItem (item);
374 processCurrentChanged (item);
375 emit bootSequenceChanged();
376 }
377
378 void moveItemDown()
379 {
380 QListViewItem *item = mBootTable->currentItem();
381 Assert (item);
382 QListViewItem *itemBelow = item->itemBelow();
383 if (!itemBelow) return;
384 item->moveItem (itemBelow);
385 processCurrentChanged (item);
386 emit bootSequenceChanged();
387 }
388
389 void onItemToggled()
390 {
391 emit bootSequenceChanged();
392 }
393
394 void processCurrentChanged (QListViewItem *aItem)
395 {
396 bool upEnabled = aItem && aItem->isSelected() && aItem->itemAbove();
397 bool downEnabled = aItem && aItem->isSelected() && aItem->itemBelow();
398 if ((mBtnUp->hasFocus() && !upEnabled) ||
399 (mBtnDown->hasFocus() && !downEnabled))
400 mBootTable->setFocus();
401 mBtnUp->setEnabled (upEnabled);
402 mBtnDown->setEnabled (downEnabled);
403 }
404
405private:
406
407 BootItemsTable *mBootTable;
408 QToolButton *mBtnUp;
409 QToolButton *mBtnDown;
410};
411
412
413/// @todo (dmik) remove?
414///**
415// * Returns the through position of the item in the list view.
416// */
417//static int pos (QListView *lv, QListViewItem *li)
418//{
419// QListViewItemIterator it (lv);
420// int p = -1, c = 0;
421// while (it.current() && p < 0)
422// {
423// if (it.current() == li)
424// p = c;
425// ++ it;
426// ++ c;
427// }
428// return p;
429//}
430
431class USBListItem : public QCheckListItem
432{
433public:
434
435 USBListItem (QListView *aParent, QListViewItem *aAfter)
436 : QCheckListItem (aParent, aAfter, QString::null, CheckBox)
437 , mId (-1) {}
438
439 int mId;
440};
441
442/**
443 * Returns the path to the item in the form of 'grandparent > parent > item'
444 * using the text of the first column of every item.
445 */
446static QString path (QListViewItem *li)
447{
448 static QString sep = ": ";
449 QString p;
450 QListViewItem *cur = li;
451 while (cur)
452 {
453 if (!p.isNull())
454 p = sep + p;
455 p = cur->text (0).simplifyWhiteSpace() + p;
456 cur = cur->parent();
457 }
458 return p;
459}
460
461enum
462{
463 /* listView column numbers */
464 listView_Category = 0,
465 listView_Id = 1,
466 listView_Link = 2,
467 /* lvUSBFilters column numbers */
468 lvUSBFilters_Name = 0,
469};
470
471
472void VBoxVMSettingsDlg::init()
473{
474 polished = false;
475
476 /* disallow resetting First Run Wizard flag until media enumeration
477 * process is finished and all data is finally loaded into ui */
478 mAllowResetFirstRunFlag = false;
479 connect (&vboxGlobal(), SIGNAL (mediaEnumFinished (const VBoxMediaList &)),
480 this, SLOT (onMediaEnumerationDone()));
481
482 setIcon (QPixmap::fromMimeSource ("settings_16px.png"));
483
484 /* all pages are initially valid */
485 valid = true;
486 buttonOk->setEnabled( true );
487
488 /* disable unselecting items by clicking in the unused area of the list */
489 new QIListViewSelectionPreserver (this, listView);
490 /* hide the header and internal columns */
491 listView->header()->hide();
492 listView->setColumnWidthMode (listView_Id, QListView::Manual);
493 listView->setColumnWidthMode (listView_Link, QListView::Manual);
494 listView->hideColumn (listView_Id);
495 listView->hideColumn (listView_Link);
496 /* sort by the id column (to have pages in the desired order) */
497 listView->setSorting (listView_Id);
498 listView->sort();
499 /* disable further sorting (important for network adapters) */
500 listView->setSorting (-1);
501 /* set the first item selected */
502 listView->setSelected (listView->firstChild(), true);
503 listView_currentChanged (listView->firstChild());
504 /* setup status bar icon */
505 warningPixmap->setMaximumSize( 16, 16 );
506 warningPixmap->setPixmap( QMessageBox::standardIcon( QMessageBox::Warning ) );
507
508 /* page title font is derived from the system font */
509 QFont f = font();
510 f.setBold (true);
511 f.setPointSize (f.pointSize() + 2);
512 titleLabel->setFont (f);
513
514 /* setup the what's this label */
515 QApplication::setGlobalMouseTracking (true);
516 qApp->installEventFilter (this);
517 whatsThisTimer = new QTimer (this);
518 connect (whatsThisTimer, SIGNAL (timeout()), this, SLOT (updateWhatsThis()));
519 whatsThisCandidate = NULL;
520
521 whatsThisLabel = new QIRichLabel (this, "whatsThisLabel");
522 VBoxVMSettingsDlgLayout->addWidget (whatsThisLabel, 2, 1);
523
524#ifndef DEBUG
525 /* Enforce rich text format to avoid jumping margins (margins of plain
526 * text labels seem to be smaller). We don't do it in the DEBUG builds to
527 * be able to immediately catch badly formatted text (i.e. text that
528 * contains HTML tags but doesn't start with <qt> so that Qt isn't able to
529 * recognize it as rich text and draws all tags as is instead of doing
530 * formatting). We want to catch this text because this is how it will look
531 * in the whatsthis balloon where we cannot enforce rich text. */
532 whatsThisLabel->setTextFormat (Qt::RichText);
533#endif
534
535 whatsThisLabel->setMaxHeightMode (true);
536 whatsThisLabel->setFocusPolicy (QWidget::NoFocus);
537 whatsThisLabel->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Fixed);
538 whatsThisLabel->setBackgroundMode (QLabel::PaletteMidlight);
539 whatsThisLabel->setFrameShape (QLabel::Box);
540 whatsThisLabel->setFrameShadow (QLabel::Sunken);
541 whatsThisLabel->setMargin (7);
542 whatsThisLabel->setScaledContents (FALSE);
543 whatsThisLabel->setAlignment (int (QLabel::WordBreak |
544 QLabel::AlignJustify |
545 QLabel::AlignTop));
546
547 whatsThisLabel->setFixedHeight (whatsThisLabel->frameWidth() * 2 +
548 6 /* seems that RichText adds some margin */ +
549 whatsThisLabel->fontMetrics().lineSpacing() * 4);
550 whatsThisLabel->setMinimumWidth (whatsThisLabel->frameWidth() * 2 +
551 6 /* seems that RichText adds some margin */ +
552 whatsThisLabel->fontMetrics().width ('m') * 40);
553
554 /*
555 * setup connections and set validation for pages
556 * ----------------------------------------------------------------------
557 */
558
559 /* General page */
560
561 CSystemProperties sysProps = vboxGlobal().virtualBox().GetSystemProperties();
562
563 const uint MinRAM = sysProps.GetMinGuestRAM();
564 const uint MaxRAM = sysProps.GetMaxGuestRAM();
565 const uint MinVRAM = sysProps.GetMinGuestVRAM();
566 const uint MaxVRAM = sysProps.GetMaxGuestVRAM();
567
568 leName->setValidator (new QRegExpValidator (QRegExp (".+"), this));
569
570 leRAM->setValidator (new QIntValidator (MinRAM, MaxRAM, this));
571 leVRAM->setValidator (new QIntValidator (MinVRAM, MaxVRAM, this));
572
573 wvalGeneral = new QIWidgetValidator (pagePath (pageGeneral), pageGeneral, this);
574 connect (wvalGeneral, SIGNAL (validityChanged (const QIWidgetValidator *)),
575 this, SLOT(enableOk (const QIWidgetValidator *)));
576
577 tbSelectSavedStateFolder->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
578 "select_file_dis_16px.png"));
579 tbResetSavedStateFolder->setIconSet (VBoxGlobal::iconSet ("eraser_16px.png",
580 "eraser_disabled_16px.png"));
581
582 teDescription->setTextFormat (Qt::PlainText);
583
584 /* HDD Images page */
585
586 QWhatsThis::add (static_cast <QWidget *> (grbHDA->child ("qt_groupbox_checkbox")),
587 tr ("When checked, attaches the specified virtual hard disk to the "
588 "Master slot of the Primary IDE controller."));
589 QWhatsThis::add (static_cast <QWidget *> (grbHDB->child ("qt_groupbox_checkbox")),
590 tr ("When checked, attaches the specified virtual hard disk to the "
591 "Slave slot of the Primary IDE controller."));
592 QWhatsThis::add (static_cast <QWidget *> (grbHDD->child ("qt_groupbox_checkbox")),
593 tr ("When checked, attaches the specified virtual hard disk to the "
594 "Slave slot of the Secondary IDE controller."));
595 cbHDA = new VBoxMediaComboBox (grbHDA, "cbHDA", VBoxDefs::HD);
596 cbHDB = new VBoxMediaComboBox (grbHDB, "cbHDB", VBoxDefs::HD);
597 cbHDD = new VBoxMediaComboBox (grbHDD, "cbHDD", VBoxDefs::HD);
598 hdaLayout->insertWidget (0, cbHDA);
599 hdbLayout->insertWidget (0, cbHDB);
600 hddLayout->insertWidget (0, cbHDD);
601 /* sometimes the weirdness of Qt just kills... */
602 setTabOrder (static_cast <QWidget *> (grbHDA->child ("qt_groupbox_checkbox")),
603 cbHDA);
604 setTabOrder (static_cast <QWidget *> (grbHDB->child ("qt_groupbox_checkbox")),
605 cbHDB);
606 setTabOrder (static_cast <QWidget *> (grbHDD->child ("qt_groupbox_checkbox")),
607 cbHDD);
608
609 QWhatsThis::add (cbHDB, tr ("Displays the virtual hard disk to attach to this IDE slot "
610 "and allows to quickly select a different hard disk."));
611 QWhatsThis::add (cbHDD, tr ("Displays the virtual hard disk to attach to this IDE slot "
612 "and allows to quickly select a different hard disk."));
613 QWhatsThis::add (cbHDA, tr ("Displays the virtual hard disk to attach to this IDE slot "
614 "and allows to quickly select a different hard disk."));
615 QWhatsThis::add (cbHDB, tr ("Displays the virtual hard disk to attach to this IDE slot "
616 "and allows to quickly select a different hard disk."));
617 QWhatsThis::add (cbHDD, tr ("Displays the virtual hard disk to attach to this IDE slot "
618 "and allows to quickly select a different hard disk."));
619
620 wvalHDD = new QIWidgetValidator (pagePath (pageHDD), pageHDD, this);
621 connect (wvalHDD, SIGNAL (validityChanged (const QIWidgetValidator *)),
622 this, SLOT (enableOk (const QIWidgetValidator *)));
623 connect (wvalHDD, SIGNAL (isValidRequested (QIWidgetValidator *)),
624 this, SLOT (revalidate (QIWidgetValidator *)));
625
626 connect (grbHDA, SIGNAL (toggled (bool)), this, SLOT (hdaMediaChanged()));
627 connect (grbHDB, SIGNAL (toggled (bool)), this, SLOT (hdbMediaChanged()));
628 connect (grbHDD, SIGNAL (toggled (bool)), this, SLOT (hddMediaChanged()));
629 connect (cbHDA, SIGNAL (activated (int)), this, SLOT (hdaMediaChanged()));
630 connect (cbHDB, SIGNAL (activated (int)), this, SLOT (hdbMediaChanged()));
631 connect (cbHDD, SIGNAL (activated (int)), this, SLOT (hddMediaChanged()));
632 connect (tbHDA, SIGNAL (clicked()), this, SLOT (showImageManagerHDA()));
633 connect (tbHDB, SIGNAL (clicked()), this, SLOT (showImageManagerHDB()));
634 connect (tbHDD, SIGNAL (clicked()), this, SLOT (showImageManagerHDD()));
635
636 /* setup iconsets -- qdesigner is not capable... */
637 tbHDA->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
638 "select_file_dis_16px.png"));
639 tbHDB->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
640 "select_file_dis_16px.png"));
641 tbHDD->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
642 "select_file_dis_16px.png"));
643
644 /* CD/DVD-ROM Drive Page */
645
646 QWhatsThis::add (static_cast <QWidget *> (bgDVD->child ("qt_groupbox_checkbox")),
647 tr ("When checked, mounts the specified media to the CD/DVD drive of the "
648 "virtual machine. Note that the CD/DVD drive is always connected to the "
649 "Secondary Master IDE controller of the machine."));
650 cbISODVD = new VBoxMediaComboBox (bgDVD, "cbISODVD", VBoxDefs::CD);
651 cdLayout->insertWidget(0, cbISODVD);
652 QWhatsThis::add (cbISODVD, tr ("Displays the image file to mount to the virtual CD/DVD "
653 "drive and allows to quickly select a different image."));
654
655 wvalDVD = new QIWidgetValidator (pagePath (pageDVD), pageDVD, this);
656 connect (wvalDVD, SIGNAL (validityChanged (const QIWidgetValidator *)),
657 this, SLOT (enableOk (const QIWidgetValidator *)));
658 connect (wvalDVD, SIGNAL (isValidRequested (QIWidgetValidator *)),
659 this, SLOT (revalidate( QIWidgetValidator *)));
660
661 connect (bgDVD, SIGNAL (toggled (bool)), this, SLOT (cdMediaChanged()));
662 connect (rbHostDVD, SIGNAL (stateChanged (int)), wvalDVD, SLOT (revalidate()));
663 connect (rbISODVD, SIGNAL (stateChanged (int)), wvalDVD, SLOT (revalidate()));
664 connect (cbISODVD, SIGNAL (activated (int)), this, SLOT (cdMediaChanged()));
665 connect (tbISODVD, SIGNAL (clicked()), this, SLOT (showImageManagerISODVD()));
666
667 /* setup iconsets -- qdesigner is not capable... */
668 tbISODVD->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
669 "select_file_dis_16px.png"));
670
671 /* Floppy Drive Page */
672
673 QWhatsThis::add (static_cast <QWidget *> (bgFloppy->child ("qt_groupbox_checkbox")),
674 tr ("When checked, mounts the specified media to the Floppy drive of the "
675 "virtual machine."));
676 cbISOFloppy = new VBoxMediaComboBox (bgFloppy, "cbISOFloppy", VBoxDefs::FD);
677 fdLayout->insertWidget(0, cbISOFloppy);
678 QWhatsThis::add (cbISOFloppy, tr ("Displays the image file to mount to the virtual Floppy "
679 "drive and allows to quickly select a different image."));
680
681 wvalFloppy = new QIWidgetValidator (pagePath (pageFloppy), pageFloppy, this);
682 connect (wvalFloppy, SIGNAL (validityChanged (const QIWidgetValidator *)),
683 this, SLOT (enableOk (const QIWidgetValidator *)));
684 connect (wvalFloppy, SIGNAL (isValidRequested (QIWidgetValidator *)),
685 this, SLOT (revalidate( QIWidgetValidator *)));
686
687 connect (bgFloppy, SIGNAL (toggled (bool)), this, SLOT (fdMediaChanged()));
688 connect (rbHostFloppy, SIGNAL (stateChanged (int)), wvalFloppy, SLOT (revalidate()));
689 connect (rbISOFloppy, SIGNAL (stateChanged (int)), wvalFloppy, SLOT (revalidate()));
690 connect (cbISOFloppy, SIGNAL (activated (int)), this, SLOT (fdMediaChanged()));
691 connect (tbISOFloppy, SIGNAL (clicked()), this, SLOT (showImageManagerISOFloppy()));
692
693 /* setup iconsets -- qdesigner is not capable... */
694 tbISOFloppy->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
695 "select_file_dis_16px.png"));
696
697 /* Audio Page */
698
699 QWhatsThis::add (static_cast <QWidget *> (grbAudio->child ("qt_groupbox_checkbox")),
700 tr ("When checked, the virtual PCI audio card is plugged into the "
701 "virtual machine that uses the specified driver to communicate "
702 "to the host audio card."));
703
704 /* Network Page */
705
706#ifndef Q_WS_WIN
707 gbInterfaceList->setHidden (true);
708#endif
709 /* setup tab widget */
710 mNoInterfaces = tr ("<No suitable interfaces>");
711 /* setup iconsets */
712 pbHostAdd->setIconSet (VBoxGlobal::iconSet ("add_host_iface_16px.png",
713 "add_host_iface_disabled_16px.png"));
714 pbHostRemove->setIconSet (VBoxGlobal::iconSet ("remove_host_iface_16px.png",
715 "remove_host_iface_disabled_16px.png"));
716 /* setup languages */
717 QToolTip::add (pbHostAdd, tr ("Add"));
718 QToolTip::add (pbHostRemove, tr ("Remove"));
719
720 /* Serial Port Page */
721
722 /* Parallel Port Page (currently disabled) */
723 QListViewItem *item = listView->findItem ("#parallelPorts", listView_Link);
724 if (item) item->setVisible (false);
725
726 /* USB Page */
727
728 connect (cbEnableUSBController, SIGNAL (toggled (bool)),
729 this, SLOT (usbAdapterToggled (bool)));
730
731 lvUSBFilters->header()->hide();
732 /* disable sorting */
733 lvUSBFilters->setSorting (-1);
734 /* disable unselecting items by clicking in the unused area of the list */
735 new QIListViewSelectionPreserver (this, lvUSBFilters);
736 /* create the widget stack for filter settings */
737 /// @todo (r=dmik) having a separate settings widget for every USB filter
738 // is not that smart if there are lots of USB filters. The reason for
739 // stacking here is that the stacked widget is used to temporarily store
740 // data of the associated USB filter until the dialog window is accepted.
741 // If we remove stacking, we will have to create a structure to store
742 // editable data of all USB filters while the dialog is open.
743 wstUSBFilters = new QWidgetStack (grbUSBFilters, "wstUSBFilters");
744 grbUSBFiltersLayout->addWidget (wstUSBFilters);
745 /* create a default (disabled) filter settings widget at index 0 */
746 VBoxUSBFilterSettings *settings = new VBoxUSBFilterSettings (wstUSBFilters);
747 settings->setup (VBoxUSBFilterSettings::MachineType);
748 wstUSBFilters->addWidget (settings, 0);
749 lvUSBFilters_currentChanged (NULL);
750
751 /* setup iconsets -- qdesigner is not capable... */
752 tbAddUSBFilter->setIconSet (VBoxGlobal::iconSet ("usb_new_16px.png",
753 "usb_new_disabled_16px.png"));
754 tbAddUSBFilterFrom->setIconSet (VBoxGlobal::iconSet ("usb_add_16px.png",
755 "usb_add_disabled_16px.png"));
756 tbRemoveUSBFilter->setIconSet (VBoxGlobal::iconSet ("usb_remove_16px.png",
757 "usb_remove_disabled_16px.png"));
758 tbUSBFilterUp->setIconSet (VBoxGlobal::iconSet ("usb_moveup_16px.png",
759 "usb_moveup_disabled_16px.png"));
760 tbUSBFilterDown->setIconSet (VBoxGlobal::iconSet ("usb_movedown_16px.png",
761 "usb_movedown_disabled_16px.png"));
762 usbDevicesMenu = new VBoxUSBMenu (this);
763 connect (usbDevicesMenu, SIGNAL(activated(int)), this, SLOT(menuAddUSBFilterFrom_activated(int)));
764 mUSBFilterListModified = false;
765
766 /* VRDP Page */
767
768 QWhatsThis::add (static_cast <QWidget *> (grbVRDP->child ("qt_groupbox_checkbox")),
769 tr ("When checked, the VM will act as a Remote Desktop "
770 "Protocol (RDP) server, allowing remote clients to connect "
771 "and operate the VM (when it is running) "
772 "using a standard RDP client."));
773
774 leVRDPPort->setValidator (new QIntValidator (0, 0xFFFF, this));
775 leVRDPTimeout->setValidator (new QIntValidator (this));
776 wvalVRDP = new QIWidgetValidator (pagePath (pageVRDP), pageVRDP, this);
777 connect (wvalVRDP, SIGNAL (validityChanged (const QIWidgetValidator *)),
778 this, SLOT (enableOk (const QIWidgetValidator *)));
779 connect (wvalVRDP, SIGNAL (isValidRequested (QIWidgetValidator *)),
780 this, SLOT (revalidate( QIWidgetValidator *)));
781
782 connect (grbVRDP, SIGNAL (toggled (bool)), wvalFloppy, SLOT (revalidate()));
783 connect (leVRDPPort, SIGNAL (textChanged (const QString&)), wvalFloppy, SLOT (revalidate()));
784 connect (leVRDPTimeout, SIGNAL (textChanged (const QString&)), wvalFloppy, SLOT (revalidate()));
785
786 /* Shared Folders Page */
787
788 QVBoxLayout* pageFoldersLayout = new QVBoxLayout (pageFolders, 0, 10, "pageFoldersLayout");
789 mSharedFolders = new VBoxSharedFoldersSettings (pageFolders, "sharedFolders");
790 mSharedFolders->setDialogType (VBoxSharedFoldersSettings::MachineType);
791 pageFoldersLayout->addWidget (mSharedFolders);
792
793 /*
794 * set initial values
795 * ----------------------------------------------------------------------
796 */
797
798 /* General page */
799
800 cbOS->insertStringList (vboxGlobal().vmGuestOSTypeDescriptions());
801
802 slRAM->setPageStep (calcPageStep (MaxRAM));
803 slRAM->setLineStep (slRAM->pageStep() / 4);
804 slRAM->setTickInterval (slRAM->pageStep());
805 /* setup the scale so that ticks are at page step boundaries */
806 slRAM->setMinValue ((MinRAM / slRAM->pageStep()) * slRAM->pageStep());
807 slRAM->setMaxValue (MaxRAM);
808 txRAMMin->setText (tr ("<qt>%1&nbsp;MB</qt>").arg (MinRAM));
809 txRAMMax->setText (tr ("<qt>%1&nbsp;MB</qt>").arg (MaxRAM));
810 /* limit min/max. size of QLineEdit */
811 leRAM->setMaximumSize (leRAM->fontMetrics().width ("99999")
812 + leRAM->frameWidth() * 2,
813 leRAM->minimumSizeHint().height());
814 leRAM->setMinimumSize (leRAM->maximumSize());
815 /* ensure leRAM value and validation is updated */
816 slRAM_valueChanged (slRAM->value());
817
818 slVRAM->setPageStep (calcPageStep (MaxVRAM));
819 slVRAM->setLineStep (slVRAM->pageStep() / 4);
820 slVRAM->setTickInterval (slVRAM->pageStep());
821 /* setup the scale so that ticks are at page step boundaries */
822 slVRAM->setMinValue ((MinVRAM / slVRAM->pageStep()) * slVRAM->pageStep());
823 slVRAM->setMaxValue (MaxVRAM);
824 txVRAMMin->setText (tr ("<qt>%1&nbsp;MB</qt>").arg (MinVRAM));
825 txVRAMMax->setText (tr ("<qt>%1&nbsp;MB</qt>").arg (MaxVRAM));
826 /* limit min/max. size of QLineEdit */
827 leVRAM->setMaximumSize (leVRAM->fontMetrics().width ("99999")
828 + leVRAM->frameWidth() * 2,
829 leVRAM->minimumSizeHint().height());
830 leVRAM->setMinimumSize (leVRAM->maximumSize());
831 /* ensure leVRAM value and validation is updated */
832 slVRAM_valueChanged (slVRAM->value());
833
834 /* Boot-order table */
835 tblBootOrder = new BootItemsList (groupBox12, "tblBootOrder");
836 connect (tblBootOrder, SIGNAL (bootSequenceChanged()),
837 this, SLOT (resetFirstRunFlag()));
838
839 /* Fixing focus order for BootItemsList */
840 setTabOrder (tbwGeneral, tblBootOrder);
841 setTabOrder (tblBootOrder->focusProxy(), chbEnableACPI);
842 groupBox12Layout->addWidget (tblBootOrder);
843 tblBootOrder->fixTabStops();
844 /* Shared Clipboard mode */
845 cbSharedClipboard->insertItem (vboxGlobal().toString (CEnums::ClipDisabled));
846 cbSharedClipboard->insertItem (vboxGlobal().toString (CEnums::ClipHostToGuest));
847 cbSharedClipboard->insertItem (vboxGlobal().toString (CEnums::ClipGuestToHost));
848 cbSharedClipboard->insertItem (vboxGlobal().toString (CEnums::ClipBidirectional));
849 /* IDE Controller Type */
850 cbIdeController->insertItem (vboxGlobal().toString (CEnums::IDEControllerPIIX3));
851 cbIdeController->insertItem (vboxGlobal().toString (CEnums::IDEControllerPIIX4));
852
853 /* HDD Images page */
854
855 /* CD-ROM Drive Page */
856
857 /* Audio Page */
858
859 cbAudioDriver->insertItem (vboxGlobal().toString (CEnums::NullAudioDriver));
860#if defined Q_WS_WIN32
861 cbAudioDriver->insertItem (vboxGlobal().toString (CEnums::DSOUNDAudioDriver));
862# ifdef VBOX_WITH_WINMM
863 cbAudioDriver->insertItem (vboxGlobal().toString (CEnums::WINMMAudioDriver));
864# endif
865#elif defined Q_OS_LINUX
866 cbAudioDriver->insertItem (vboxGlobal().toString (CEnums::OSSAudioDriver));
867# ifdef VBOX_WITH_ALSA
868 cbAudioDriver->insertItem (vboxGlobal().toString (CEnums::ALSAAudioDriver));
869# endif
870# ifdef VBOX_WITH_PULSE
871 cbAudioDriver->insertItem (vboxGlobal().toString (CEnums::PulseAudioDriver));
872# endif
873#elif defined Q_OS_MACX
874 cbAudioDriver->insertItem (vboxGlobal().toString (CEnums::CoreAudioDriver));
875#endif
876
877 /* Network Page */
878
879 loadInterfacesList();
880 loadNetworksList();
881
882 /*
883 * update the Ok button state for pages with validation
884 * (validityChanged() connected to enableNext() will do the job)
885 */
886 wvalGeneral->revalidate();
887 wvalHDD->revalidate();
888 wvalDVD->revalidate();
889 wvalFloppy->revalidate();
890
891 /* VRDP Page */
892
893 cbVRDPAuthType->insertItem (vboxGlobal().toString (CEnums::VRDPAuthNull));
894 cbVRDPAuthType->insertItem (vboxGlobal().toString (CEnums::VRDPAuthExternal));
895 cbVRDPAuthType->insertItem (vboxGlobal().toString (CEnums::VRDPAuthGuest));
896}
897
898/**
899 * Returns a path to the given page of this settings dialog. See ::path() for
900 * details.
901 */
902QString VBoxVMSettingsDlg::pagePath (QWidget *aPage)
903{
904 QListViewItem *li = listView->
905 findItem (QString::number (widgetStack->id (aPage)), 1);
906 return ::path (li);
907}
908
909bool VBoxVMSettingsDlg::eventFilter (QObject *object, QEvent *event)
910{
911 if (!object->isWidgetType())
912 return QDialog::eventFilter (object, event);
913
914 QWidget *widget = static_cast <QWidget *> (object);
915 if (widget->topLevelWidget() != this)
916 return QDialog::eventFilter (object, event);
917
918 switch (event->type())
919 {
920 case QEvent::Enter:
921 case QEvent::Leave:
922 {
923 if (event->type() == QEvent::Enter)
924 whatsThisCandidate = widget;
925 else
926 whatsThisCandidate = NULL;
927 whatsThisTimer->start (100, true /* sshot */);
928 break;
929 }
930 case QEvent::FocusIn:
931 {
932 updateWhatsThis (true /* gotFocus */);
933 tblBootOrder->processFocusIn (widget);
934 break;
935 }
936 default:
937 break;
938 }
939
940 return QDialog::eventFilter (object, event);
941}
942
943void VBoxVMSettingsDlg::showEvent (QShowEvent *e)
944{
945 QDialog::showEvent (e);
946
947 /* one may think that QWidget::polish() is the right place to do things
948 * below, but apparently, by the time when QWidget::polish() is called,
949 * the widget style & layout are not fully done, at least the minimum
950 * size hint is not properly calculated. Since this is sometimes necessary,
951 * we provide our own "polish" implementation. */
952
953 if (polished)
954 return;
955
956 polished = true;
957
958 /* update geometry for the dynamically added usb-page to ensure proper
959 * sizeHint calculation by the Qt layout manager */
960 wstUSBFilters->updateGeometry();
961 /* let our toplevel widget calculate its sizeHint properly */
962 QApplication::sendPostedEvents (0, 0);
963
964 layout()->activate();
965
966 /* resize to the miminum possible size */
967 resize (minimumSize());
968
969 VBoxGlobal::centerWidget (this, parentWidget());
970}
971
972void VBoxVMSettingsDlg::updateShortcuts()
973{
974 /* setup necessary combobox item */
975 cbHDA->setCurrentItem (uuidHDA);
976 cbHDB->setCurrentItem (uuidHDB);
977 cbHDD->setCurrentItem (uuidHDD);
978 cbISODVD->setCurrentItem (uuidISODVD);
979 cbISOFloppy->setCurrentItem (uuidISOFloppy);
980 /* check if the enumeration process has been started yet */
981 if (!vboxGlobal().isMediaEnumerationStarted())
982 vboxGlobal().startEnumeratingMedia();
983 else
984 {
985 cbHDA->refresh();
986 cbHDB->refresh();
987 cbHDD->refresh();
988 cbISODVD->refresh();
989 cbISOFloppy->refresh();
990 }
991}
992
993void VBoxVMSettingsDlg::loadInterfacesList()
994{
995#if defined Q_WS_WIN
996 /* clear inner list */
997 mInterfaceList.clear();
998 /* load current inner list */
999 CHostNetworkInterfaceEnumerator en =
1000 vboxGlobal().virtualBox().GetHost().GetNetworkInterfaces().Enumerate();
1001 while (en.HasMore())
1002 mInterfaceList += en.GetNext().GetName();
1003 /* save current list item name */
1004 QString currentListItemName = lbHostInterface->currentText();
1005 /* load current list items */
1006 lbHostInterface->clear();
1007 if (mInterfaceList.count())
1008 lbHostInterface->insertStringList (mInterfaceList);
1009 else
1010 lbHostInterface->insertItem (mNoInterfaces);
1011 /* select current list item */
1012 int index = lbHostInterface->index (
1013 lbHostInterface->findItem (currentListItemName));
1014 if (index == -1)
1015 index = 0;
1016 lbHostInterface->setCurrentItem (index);
1017 lbHostInterface->setSelected (index, true);
1018 /* enable/disable interface delete button */
1019 pbHostRemove->setEnabled (!mInterfaceList.isEmpty());
1020#endif
1021}
1022
1023void VBoxVMSettingsDlg::loadNetworksList()
1024{
1025 /* clear inner list */
1026 mNetworksList.clear();
1027 /* loading internal networks list */
1028 CVirtualBox vbox = vboxGlobal().virtualBox();
1029 ulong count = vbox.GetSystemProperties().GetNetworkAdapterCount();
1030 CMachineEnumerator en = vbox.GetMachines().Enumerate();
1031 while (en.HasMore())
1032 {
1033 CMachine machine = en.GetNext();
1034 for (ulong slot = 0; slot < count; ++ slot)
1035 {
1036 CNetworkAdapter adapter = machine.GetNetworkAdapter (slot);
1037 if (adapter.GetAttachmentType() == CEnums::InternalNetworkAttachment &&
1038 !mNetworksList.contains (adapter.GetInternalNetwork()))
1039 mNetworksList << adapter.GetInternalNetwork();
1040 }
1041 }
1042 mLockNetworkListUpdate = false;
1043}
1044
1045void VBoxVMSettingsDlg::hostInterfaceAdd()
1046{
1047#if defined Q_WS_WIN
1048
1049 /* allow the started helper process to make itself the foreground window */
1050 AllowSetForegroundWindow (ASFW_ANY);
1051
1052 /* search for the max available interface index */
1053 int ifaceNumber = 0;
1054 QString ifaceName = tr ("VirtualBox Host Interface %1");
1055 QRegExp regExp (QString ("^") + ifaceName.arg ("([0-9]+)") + QString ("$"));
1056 for (uint index = 0; index < lbHostInterface->count(); ++ index)
1057 {
1058 QString iface = lbHostInterface->text (index);
1059 int pos = regExp.search (iface);
1060 if (pos != -1)
1061 ifaceNumber = regExp.cap (1).toInt() > ifaceNumber ?
1062 regExp.cap (1).toInt() : ifaceNumber;
1063 }
1064
1065 /* creating add host interface dialog */
1066 VBoxAddNIDialog dlg (this, ifaceName.arg (++ ifaceNumber));
1067 if (dlg.exec() != QDialog::Accepted)
1068 return;
1069 QString iName = dlg.getName();
1070
1071 /* create interface */
1072 CHost host = vboxGlobal().virtualBox().GetHost();
1073 CHostNetworkInterface iFace;
1074 CProgress progress = host.CreateHostNetworkInterface (iName, iFace);
1075 if (host.isOk())
1076 {
1077 vboxProblem().showModalProgressDialog (progress, iName, this);
1078 if (progress.GetResultCode() == 0)
1079 {
1080 /* add&select newly created interface */
1081 delete lbHostInterface->findItem (mNoInterfaces);
1082 lbHostInterface->insertItem (iName);
1083 mInterfaceList += iName;
1084 lbHostInterface->setCurrentItem (lbHostInterface->count() - 1);
1085 lbHostInterface->setSelected (lbHostInterface->count() - 1, true);
1086 for (int index = 0; index < tbwNetwork->count(); ++ index)
1087 networkPageUpdate (tbwNetwork->page (index));
1088 /* enable interface delete button */
1089 pbHostRemove->setEnabled (true);
1090 }
1091 else
1092 vboxProblem().cannotCreateHostInterface (progress, iName, this);
1093 }
1094 else
1095 vboxProblem().cannotCreateHostInterface (host, iName, this);
1096
1097 /* allow the started helper process to make itself the foreground window */
1098 AllowSetForegroundWindow (ASFW_ANY);
1099
1100#endif
1101}
1102
1103void VBoxVMSettingsDlg::hostInterfaceRemove()
1104{
1105#if defined Q_WS_WIN
1106
1107 /* allow the started helper process to make itself the foreground window */
1108 AllowSetForegroundWindow (ASFW_ANY);
1109
1110 /* check interface name */
1111 QString iName = lbHostInterface->currentText();
1112 if (iName.isEmpty())
1113 return;
1114
1115 /* asking user about deleting selected network interface */
1116 int delNetIface = vboxProblem().message (this, VBoxProblemReporter::Question,
1117 tr ("<p>Do you want to remove the selected host network interface "
1118 "<nobr><b>%1</b>?</nobr></p>"
1119 "<p><b>Note:</b> This interface may be in use by one or more "
1120 "network adapters of this or another VM. After it is removed, these "
1121 "adapters will no longer work until you correct their settings by "
1122 "either choosing a different interface name or a different adapter "
1123 "attachment type.</p>").arg (iName),
1124 0, /* autoConfirmId */
1125 QIMessageBox::Ok | QIMessageBox::Default,
1126 QIMessageBox::Cancel | QIMessageBox::Escape);
1127 if (delNetIface == QIMessageBox::Cancel)
1128 return;
1129
1130 CHost host = vboxGlobal().virtualBox().GetHost();
1131 CHostNetworkInterface iFace = host.GetNetworkInterfaces().FindByName (iName);
1132 if (host.isOk())
1133 {
1134 /* delete interface */
1135 CProgress progress = host.RemoveHostNetworkInterface (iFace.GetId(), iFace);
1136 if (host.isOk())
1137 {
1138 vboxProblem().showModalProgressDialog (progress, iName, this);
1139 if (progress.GetResultCode() == 0)
1140 {
1141 if (lbHostInterface->count() == 1)
1142 {
1143 lbHostInterface->insertItem (mNoInterfaces);
1144 /* disable interface delete button */
1145 pbHostRemove->setEnabled (false);
1146 }
1147 delete lbHostInterface->findItem (iName);
1148 lbHostInterface->setSelected (lbHostInterface->currentItem(), true);
1149 mInterfaceList.erase (mInterfaceList.find (iName));
1150 for (int index = 0; index < tbwNetwork->count(); ++ index)
1151 networkPageUpdate (tbwNetwork->page (index));
1152 }
1153 else
1154 vboxProblem().cannotRemoveHostInterface (progress, iFace, this);
1155 }
1156 }
1157
1158 if (!host.isOk())
1159 vboxProblem().cannotRemoveHostInterface (host, iFace, this);
1160#endif
1161}
1162
1163void VBoxVMSettingsDlg::networkPageUpdate (QWidget *aWidget)
1164{
1165 if (!aWidget) return;
1166#if defined Q_WS_WIN
1167 VBoxVMNetworkSettings *set = static_cast<VBoxVMNetworkSettings*> (aWidget);
1168 set->loadInterfaceList (mInterfaceList, mNoInterfaces);
1169 set->revalidate();
1170#endif
1171}
1172
1173
1174void VBoxVMSettingsDlg::onMediaEnumerationDone()
1175{
1176 mAllowResetFirstRunFlag = true;
1177}
1178
1179
1180void VBoxVMSettingsDlg::resetFirstRunFlag()
1181{
1182 if (mAllowResetFirstRunFlag)
1183 mResetFirstRunFlag = true;
1184}
1185
1186
1187void VBoxVMSettingsDlg::hdaMediaChanged()
1188{
1189 resetFirstRunFlag();
1190 uuidHDA = grbHDA->isChecked() ? cbHDA->getId() : QUuid();
1191 txHDA->setText (getHdInfo (grbHDA, uuidHDA));
1192 /* revailidate */
1193 wvalHDD->revalidate();
1194}
1195
1196
1197void VBoxVMSettingsDlg::hdbMediaChanged()
1198{
1199 resetFirstRunFlag();
1200 uuidHDB = grbHDB->isChecked() ? cbHDB->getId() : QUuid();
1201 txHDB->setText (getHdInfo (grbHDB, uuidHDB));
1202 /* revailidate */
1203 wvalHDD->revalidate();
1204}
1205
1206
1207void VBoxVMSettingsDlg::hddMediaChanged()
1208{
1209 resetFirstRunFlag();
1210 uuidHDD = grbHDD->isChecked() ? cbHDD->getId() : QUuid();
1211 txHDD->setText (getHdInfo (grbHDD, uuidHDD));
1212 /* revailidate */
1213 wvalHDD->revalidate();
1214}
1215
1216
1217void VBoxVMSettingsDlg::cdMediaChanged()
1218{
1219 resetFirstRunFlag();
1220 uuidISODVD = bgDVD->isChecked() ? cbISODVD->getId() : QUuid();
1221 /* revailidate */
1222 wvalDVD->revalidate();
1223}
1224
1225
1226void VBoxVMSettingsDlg::fdMediaChanged()
1227{
1228 resetFirstRunFlag();
1229 uuidISOFloppy = bgFloppy->isChecked() ? cbISOFloppy->getId() : QUuid();
1230 /* revailidate */
1231 wvalFloppy->revalidate();
1232}
1233
1234
1235QString VBoxVMSettingsDlg::getHdInfo (QGroupBox *aGroupBox, QUuid aId)
1236{
1237 QString notAttached = tr ("<not attached>", "hard disk");
1238 if (aId.isNull())
1239 return notAttached;
1240 return aGroupBox->isChecked() ?
1241 vboxGlobal().details (vboxGlobal().virtualBox().GetHardDisk (aId), true) :
1242 notAttached;
1243}
1244
1245void VBoxVMSettingsDlg::updateWhatsThis (bool gotFocus /* = false */)
1246{
1247 QString text;
1248
1249 QWidget *widget = NULL;
1250 if (!gotFocus)
1251 {
1252 if (whatsThisCandidate != NULL && whatsThisCandidate != this)
1253 widget = whatsThisCandidate;
1254 }
1255 else
1256 {
1257 widget = focusData()->focusWidget();
1258 }
1259 /* if the given widget lacks the whats'this text, look at its parent */
1260 while (widget && widget != this)
1261 {
1262 text = QWhatsThis::textFor (widget);
1263 if (!text.isEmpty())
1264 break;
1265 widget = widget->parentWidget();
1266 }
1267
1268 if (text.isEmpty() && !warningString.isEmpty())
1269 text = warningString;
1270 if (text.isEmpty())
1271 text = QWhatsThis::textFor (this);
1272
1273 whatsThisLabel->setText (text);
1274}
1275
1276void VBoxVMSettingsDlg::setWarning (const QString &warning)
1277{
1278 warningString = warning;
1279 if (!warning.isEmpty())
1280 warningString = QString ("<font color=red>%1</font>").arg (warning);
1281
1282 if (!warningString.isEmpty())
1283 whatsThisLabel->setText (warningString);
1284 else
1285 updateWhatsThis (true);
1286}
1287
1288/**
1289 * Sets up this dialog.
1290 *
1291 * If @a aCategory is non-null, it should be one of values from the hidden
1292 * '[cat]' column of #listView (see VBoxVMSettingsDlg.ui in qdesigner)
1293 * prepended with the '#' sign. In this case, the specified category page
1294 * will be activated when the dialog is open.
1295 *
1296 * If @a aWidget is non-null, it should be a name of one of widgets
1297 * from the given category page. In this case, the specified widget
1298 * will get focus when the dialog is open.
1299 *
1300 * @note Calling this method after the dialog is open has no sense.
1301 *
1302 * @param aCategory Category to select when the dialog is open or null.
1303 * @param aWidget Category to select when the dialog is open or null.
1304 */
1305void VBoxVMSettingsDlg::setup (const QString &aCategory, const QString &aControl)
1306{
1307 if (!aCategory.isNull())
1308 {
1309 /* search for a list view item corresponding to the category */
1310 QListViewItem *item = listView->findItem (aCategory, listView_Link);
1311 if (item)
1312 {
1313 listView->setSelected (item, true);
1314
1315 /* search for a widget with the given name */
1316 if (!aControl.isNull())
1317 {
1318 QObject *obj = widgetStack->visibleWidget()->child (aControl);
1319 if (obj && obj->isWidgetType())
1320 {
1321 QWidget *w = static_cast <QWidget *> (obj);
1322 QWidgetList parents;
1323 QWidget *p = w;
1324 while ((p = p->parentWidget()) != NULL)
1325 {
1326 if (!strcmp (p->className(), "QTabWidget"))
1327 {
1328 /* the tab contents widget is two steps down
1329 * (QTabWidget -> QWidgetStack -> QWidget) */
1330 QWidget *c = parents.last();
1331 if (c)
1332 c = parents.prev();
1333 if (c)
1334 static_cast <QTabWidget *> (p)->showPage (c);
1335 }
1336 parents.append (p);
1337 }
1338
1339 w->setFocus();
1340 }
1341 }
1342 }
1343 }
1344}
1345
1346void VBoxVMSettingsDlg::listView_currentChanged (QListViewItem *item)
1347{
1348 Assert (item);
1349 int id = item->text (1).toInt();
1350 Assert (id >= 0);
1351 titleLabel->setText (::path (item));
1352 widgetStack->raiseWidget (id);
1353}
1354
1355
1356void VBoxVMSettingsDlg::enableOk (const QIWidgetValidator *wval)
1357{
1358 Q_UNUSED (wval);
1359
1360 /* reset the warning text; interested parties will set it during
1361 * validation */
1362 setWarning (QString::null);
1363
1364 QString wvalWarning;
1365
1366 /* detect the overall validity */
1367 bool newValid = true;
1368 {
1369 QObjectList *l = this->queryList ("QIWidgetValidator");
1370 QObjectListIt it (*l);
1371 QObject *obj;
1372 while ((obj = it.current()) != 0)
1373 {
1374 QIWidgetValidator *wval = (QIWidgetValidator *) obj;
1375 newValid = wval->isValid();
1376 if (!newValid)
1377 {
1378 wvalWarning = wval->warningText();
1379 break;
1380 }
1381 ++ it;
1382 }
1383 delete l;
1384 }
1385
1386 if (warningString.isNull() && !wvalWarning.isNull())
1387 {
1388 /* try to set the generic error message when invalid but no specific
1389 * message is provided */
1390 setWarning (wvalWarning);
1391 }
1392
1393 if (valid != newValid)
1394 {
1395 valid = newValid;
1396 buttonOk->setEnabled (valid);
1397 warningLabel->setHidden (valid);
1398 warningPixmap->setHidden (valid);
1399 }
1400}
1401
1402
1403void VBoxVMSettingsDlg::revalidate (QIWidgetValidator *wval)
1404{
1405 /* do individual validations for pages */
1406 QWidget *pg = wval->widget();
1407 bool valid = wval->isOtherValid();
1408
1409 QString warningText;
1410 QString pageTitle = pagePath (pg);
1411
1412 if (pg == pageHDD)
1413 {
1414 CVirtualBox vbox = vboxGlobal().virtualBox();
1415 valid = true;
1416
1417 QValueList <QUuid> uuids;
1418
1419 if (valid && grbHDA->isChecked())
1420 {
1421 if (uuidHDA.isNull())
1422 {
1423 valid = false;
1424 warningText = tr ("Primary Master hard disk is not selected");
1425 }
1426 else uuids << uuidHDA;
1427 }
1428
1429 if (valid && grbHDB->isChecked())
1430 {
1431 if (uuidHDB.isNull())
1432 {
1433 valid = false;
1434 warningText = tr ("Primary Slave hard disk is not selected");
1435 }
1436 else
1437 {
1438 bool found = uuids.findIndex (uuidHDB) >= 0;
1439 if (found)
1440 {
1441 CHardDisk hd = vbox.GetHardDisk (uuidHDB);
1442 valid = hd.GetType() == CEnums::ImmutableHardDisk;
1443 }
1444 if (valid)
1445 uuids << uuidHDB;
1446 else
1447 warningText = tr ("Primary Slave hard disk is already attached "
1448 "to a different slot");
1449 }
1450 }
1451
1452 if (valid && grbHDD->isChecked())
1453 {
1454 if (uuidHDD.isNull())
1455 {
1456 valid = false;
1457 warningText = tr ("Secondary Slave hard disk is not selected");
1458 }
1459 else
1460 {
1461 bool found = uuids.findIndex (uuidHDD) >= 0;
1462 if (found)
1463 {
1464 CHardDisk hd = vbox.GetHardDisk (uuidHDD);
1465 valid = hd.GetType() == CEnums::ImmutableHardDisk;
1466 }
1467 if (valid)
1468 uuids << uuidHDB;
1469 else
1470 warningText = tr ("Secondary Slave hard disk is already attached "
1471 "to a different slot");
1472 }
1473 }
1474
1475 cbHDA->setEnabled (grbHDA->isChecked());
1476 cbHDB->setEnabled (grbHDB->isChecked());
1477 cbHDD->setEnabled (grbHDD->isChecked());
1478 tbHDA->setEnabled (grbHDA->isChecked());
1479 tbHDB->setEnabled (grbHDB->isChecked());
1480 tbHDD->setEnabled (grbHDD->isChecked());
1481 }
1482 else if (pg == pageDVD)
1483 {
1484 if (!bgDVD->isChecked())
1485 rbHostDVD->setChecked(false), rbISODVD->setChecked(false);
1486 else if (!rbHostDVD->isChecked() && !rbISODVD->isChecked())
1487 rbHostDVD->setChecked(true);
1488
1489 valid = !(rbISODVD->isChecked() && uuidISODVD.isNull());
1490
1491 cbHostDVD->setEnabled (rbHostDVD->isChecked());
1492 cbPassthrough->setEnabled (rbHostDVD->isChecked());
1493
1494 cbISODVD->setEnabled (rbISODVD->isChecked());
1495 tbISODVD->setEnabled (rbISODVD->isChecked());
1496
1497 if (!valid)
1498 warningText = tr ("CD/DVD image file is not selected");
1499 }
1500 else if (pg == pageFloppy)
1501 {
1502 if (!bgFloppy->isChecked())
1503 rbHostFloppy->setChecked(false), rbISOFloppy->setChecked(false);
1504 else if (!rbHostFloppy->isChecked() && !rbISOFloppy->isChecked())
1505 rbHostFloppy->setChecked(true);
1506
1507 valid = !(rbISOFloppy->isChecked() && uuidISOFloppy.isNull());
1508
1509 cbHostFloppy->setEnabled (rbHostFloppy->isChecked());
1510
1511 cbISOFloppy->setEnabled (rbISOFloppy->isChecked());
1512 tbISOFloppy->setEnabled (rbISOFloppy->isChecked());
1513
1514 if (!valid)
1515 warningText = tr ("Floppy image file is not selected");
1516 }
1517 else if (pg == pageNetwork)
1518 {
1519 QWidget *tab = NULL;
1520 VBoxVMNetworkSettings::CheckPageResult error =
1521 VBoxVMNetworkSettings::CheckPage_Ok;
1522 for (int index = 0; index < tbwNetwork->count(); ++ index)
1523 {
1524 tab = tbwNetwork->page (index);
1525 VBoxVMNetworkSettings *page =
1526 static_cast <VBoxVMNetworkSettings *> (tab);
1527 error = page->checkPage (mInterfaceList);
1528 valid = !error;
1529 if (!valid) break;
1530 }
1531 if (!valid)
1532 {
1533 Assert (tab);
1534 warningText =
1535 error == VBoxVMNetworkSettings::CheckPage_InvalidInterface ?
1536 tr ("Incorrect host network interface is selected") :
1537 error == VBoxVMNetworkSettings::CheckPage_NoNetworkName ?
1538 tr ("Internal network name is not set") :
1539 QString::null;
1540 pageTitle += ": " + tbwNetwork->tabLabel (tab);
1541 }
1542 }
1543 else if (pg == pageSerial)
1544 {
1545 valid = true;
1546 QValueList <QString> ports;
1547 QValueList <QString> paths;
1548
1549 int index = 0;
1550 for (; index < tbwSerialPorts->count(); ++ index)
1551 {
1552 QWidget *tab = tbwSerialPorts->page (index);
1553 VBoxVMSerialPortSettings *page =
1554 static_cast <VBoxVMSerialPortSettings *> (tab);
1555
1556 /* check the predefined port number unicity */
1557 if (page->mSerialPortBox->isChecked() && !page->isUserDefined())
1558 {
1559 QString port = page->mPortNumCombo->currentText();
1560 valid = !ports.contains (port);
1561 if (!valid)
1562 {
1563 warningText = tr ("Duplicate port number is selected ");
1564 pageTitle += ": " + tbwSerialPorts->tabLabel (tab);
1565 break;
1566 }
1567 ports << port;
1568 }
1569 /* check the port path emptiness & unicity */
1570 CEnums::PortMode mode =
1571 vboxGlobal().toPortMode (page->mHostModeCombo->currentText());
1572 if (mode != CEnums::DisconnectedPort)
1573 {
1574 QString path = page->mPortPathLine->text();
1575 valid = !path.isEmpty() && !paths.contains (path);
1576 if (!valid)
1577 {
1578 warningText = path.isEmpty() ?
1579 tr ("Port path is not specified ") :
1580 tr ("Duplicate port path is entered ");
1581 pageTitle += ": " + tbwSerialPorts->tabLabel (tab);
1582 break;
1583 }
1584 paths << path;
1585 }
1586 }
1587 }
1588 else if (pg == pageParallel)
1589 {
1590 valid = true;
1591 QValueList <QString> ports;
1592 QValueList <QString> paths;
1593
1594 int index = 0;
1595 for (; index < tbwParallelPorts->count(); ++ index)
1596 {
1597 QWidget *tab = tbwParallelPorts->page (index);
1598 VBoxVMParallelPortSettings *page =
1599 static_cast <VBoxVMParallelPortSettings *> (tab);
1600
1601 /* check the predefined port number unicity */
1602 if (page->mParallelPortBox->isChecked() && !page->isUserDefined())
1603 {
1604 QString port = page->mPortNumCombo->currentText();
1605 valid = !ports.contains (port);
1606 if (!valid)
1607 {
1608 warningText = tr ("Duplicate port number is selected ");
1609 pageTitle += ": " + tbwParallelPorts->tabLabel (tab);
1610 break;
1611 }
1612 ports << port;
1613 }
1614 /* check the port path emptiness & unicity */
1615 if (page->mParallelPortBox->isChecked())
1616 {
1617 QString path = page->mPortPathLine->text();
1618 valid = !path.isEmpty() && !paths.contains (path);
1619 if (!valid)
1620 {
1621 warningText = path.isEmpty() ?
1622 tr ("Port path is not specified ") :
1623 tr ("Duplicate port path is entered ");
1624 pageTitle += ": " + tbwParallelPorts->tabLabel (tab);
1625 break;
1626 }
1627 paths << path;
1628 }
1629 }
1630 }
1631
1632 if (!valid)
1633 setWarning (tr ("%1 on the <b>%2</b> page.")
1634 .arg (warningText, pageTitle));
1635
1636 wval->setOtherValid (valid);
1637}
1638
1639
1640void VBoxVMSettingsDlg::getFromMachine (const CMachine &machine)
1641{
1642 cmachine = machine;
1643
1644 setCaption (machine.GetName() + tr (" - Settings"));
1645
1646 CVirtualBox vbox = vboxGlobal().virtualBox();
1647 CBIOSSettings biosSettings = cmachine.GetBIOSSettings();
1648
1649 /* name */
1650 leName->setText (machine.GetName());
1651
1652 /* OS type */
1653 QString typeId = machine.GetOSTypeId();
1654 cbOS->setCurrentItem (vboxGlobal().vmGuestOSTypeIndex (typeId));
1655 cbOS_activated (cbOS->currentItem());
1656
1657 /* RAM size */
1658 slRAM->setValue (machine.GetMemorySize());
1659
1660 /* VRAM size */
1661 slVRAM->setValue (machine.GetVRAMSize());
1662
1663 /* Boot-order */
1664 tblBootOrder->getFromMachine (machine);
1665
1666 /* ACPI */
1667 chbEnableACPI->setChecked (biosSettings.GetACPIEnabled());
1668
1669 /* IO APIC */
1670 chbEnableIOAPIC->setChecked (biosSettings.GetIOAPICEnabled());
1671
1672 /* VT-x/AMD-V */
1673 machine.GetHWVirtExEnabled() == CEnums::False ? chbVTX->setChecked (false) :
1674 machine.GetHWVirtExEnabled() == CEnums::True ? chbVTX->setChecked (true) :
1675 chbVTX->setNoChange();
1676
1677 /* Saved state folder */
1678 leSnapshotFolder->setText (machine.GetSnapshotFolder());
1679
1680 /* Description */
1681 teDescription->setText (machine.GetDescription());
1682
1683 /* Shared clipboard mode */
1684 cbSharedClipboard->setCurrentItem (machine.GetClipboardMode());
1685
1686 /* IDE controller type */
1687 cbIdeController->setCurrentText (vboxGlobal().toString (biosSettings.GetIDEControllerType()));
1688
1689 /* other features */
1690 QString saveRtimeImages = cmachine.GetExtraData (VBoxDefs::GUI_SaveMountedAtRuntime);
1691 chbRememberMedia->setChecked (saveRtimeImages != "no");
1692
1693 /* hard disk images */
1694 {
1695 struct
1696 {
1697 CEnums::DiskControllerType ctl;
1698 LONG dev;
1699 struct {
1700 QGroupBox *grb;
1701 QComboBox *cbb;
1702 QLabel *tx;
1703 QUuid *uuid;
1704 } data;
1705 }
1706 diskSet[] =
1707 {
1708 { CEnums::IDE0Controller, 0, {grbHDA, cbHDA, txHDA, &uuidHDA} },
1709 { CEnums::IDE0Controller, 1, {grbHDB, cbHDB, txHDB, &uuidHDB} },
1710 { CEnums::IDE1Controller, 1, {grbHDD, cbHDD, txHDD, &uuidHDD} },
1711 };
1712
1713 grbHDA->setChecked (false);
1714 grbHDB->setChecked (false);
1715 grbHDD->setChecked (false);
1716
1717 CHardDiskAttachmentEnumerator en =
1718 machine.GetHardDiskAttachments().Enumerate();
1719 while (en.HasMore())
1720 {
1721 CHardDiskAttachment hda = en.GetNext();
1722 for (uint i = 0; i < SIZEOF_ARRAY (diskSet); i++)
1723 {
1724 if (diskSet [i].ctl == hda.GetController() &&
1725 diskSet [i].dev == hda.GetDeviceNumber())
1726 {
1727 CHardDisk hd = hda.GetHardDisk();
1728 CHardDisk root = hd.GetRoot();
1729 QString src = root.GetLocation();
1730 if (hd.GetStorageType() == CEnums::VirtualDiskImage)
1731 {
1732 QFileInfo fi (src);
1733 src = fi.fileName() + " (" +
1734 QDir::convertSeparators (fi.dirPath (true)) + ")";
1735 }
1736 diskSet [i].data.grb->setChecked (true);
1737 diskSet [i].data.tx->setText (vboxGlobal().details (hd));
1738 *(diskSet [i].data.uuid) = QUuid (root.GetId());
1739 }
1740 }
1741 }
1742 }
1743
1744 /* floppy image */
1745 {
1746 /* read out the host floppy drive list and prepare the combobox */
1747 CHostFloppyDriveCollection coll =
1748 vboxGlobal().virtualBox().GetHost().GetFloppyDrives();
1749 hostFloppies.resize (coll.GetCount());
1750 cbHostFloppy->clear();
1751 int id = 0;
1752 CHostFloppyDriveEnumerator en = coll.Enumerate();
1753 while (en.HasMore())
1754 {
1755 CHostFloppyDrive hostFloppy = en.GetNext();
1756 /** @todo set icon? */
1757 QString name = hostFloppy.GetName();
1758 QString description = hostFloppy.GetDescription();
1759 QString fullName = description.isEmpty() ?
1760 name :
1761 QString ("%1 (%2)").arg (description, name);
1762 cbHostFloppy->insertItem (fullName, id);
1763 hostFloppies [id] = hostFloppy;
1764 ++ id;
1765 }
1766
1767 CFloppyDrive floppy = machine.GetFloppyDrive();
1768 switch (floppy.GetState())
1769 {
1770 case CEnums::HostDriveCaptured:
1771 {
1772 CHostFloppyDrive drv = floppy.GetHostDrive();
1773 QString name = drv.GetName();
1774 QString description = drv.GetDescription();
1775 QString fullName = description.isEmpty() ?
1776 name :
1777 QString ("%1 (%2)").arg (description, name);
1778 if (coll.FindByName (name).isNull())
1779 {
1780 /*
1781 * if the floppy drive is not currently available,
1782 * add it to the end of the list with a special mark
1783 */
1784 cbHostFloppy->insertItem ("* " + fullName);
1785 cbHostFloppy->setCurrentItem (cbHostFloppy->count() - 1);
1786 }
1787 else
1788 {
1789 /* this will select the correct item from the prepared list */
1790 cbHostFloppy->setCurrentText (fullName);
1791 }
1792 rbHostFloppy->setChecked (true);
1793 break;
1794 }
1795 case CEnums::ImageMounted:
1796 {
1797 CFloppyImage img = floppy.GetImage();
1798 QString src = img.GetFilePath();
1799 AssertMsg (!src.isNull(), ("Image file must not be null"));
1800 QFileInfo fi (src);
1801 rbISOFloppy->setChecked (true);
1802 uuidISOFloppy = QUuid (img.GetId());
1803 break;
1804 }
1805 case CEnums::NotMounted:
1806 {
1807 bgFloppy->setChecked(false);
1808 break;
1809 }
1810 default:
1811 AssertMsgFailed (("invalid floppy state: %d\n", floppy.GetState()));
1812 }
1813 }
1814
1815 /* CD/DVD-ROM image */
1816 {
1817 /* read out the host DVD drive list and prepare the combobox */
1818 CHostDVDDriveCollection coll =
1819 vboxGlobal().virtualBox().GetHost().GetDVDDrives();
1820 hostDVDs.resize (coll.GetCount());
1821 cbHostDVD->clear();
1822 int id = 0;
1823 CHostDVDDriveEnumerator en = coll.Enumerate();
1824 while (en.HasMore())
1825 {
1826 CHostDVDDrive hostDVD = en.GetNext();
1827 /// @todo (r=dmik) set icon?
1828 QString name = hostDVD.GetName();
1829 QString description = hostDVD.GetDescription();
1830 QString fullName = description.isEmpty() ?
1831 name :
1832 QString ("%1 (%2)").arg (description, name);
1833 cbHostDVD->insertItem (fullName, id);
1834 hostDVDs [id] = hostDVD;
1835 ++ id;
1836 }
1837
1838 CDVDDrive dvd = machine.GetDVDDrive();
1839 switch (dvd.GetState())
1840 {
1841 case CEnums::HostDriveCaptured:
1842 {
1843 CHostDVDDrive drv = dvd.GetHostDrive();
1844 QString name = drv.GetName();
1845 QString description = drv.GetDescription();
1846 QString fullName = description.isEmpty() ?
1847 name :
1848 QString ("%1 (%2)").arg (description, name);
1849 if (coll.FindByName (name).isNull())
1850 {
1851 /*
1852 * if the DVD drive is not currently available,
1853 * add it to the end of the list with a special mark
1854 */
1855 cbHostDVD->insertItem ("* " + fullName);
1856 cbHostDVD->setCurrentItem (cbHostDVD->count() - 1);
1857 }
1858 else
1859 {
1860 /* this will select the correct item from the prepared list */
1861 cbHostDVD->setCurrentText (fullName);
1862 }
1863 rbHostDVD->setChecked (true);
1864 cbPassthrough->setChecked (dvd.GetPassthrough());
1865 break;
1866 }
1867 case CEnums::ImageMounted:
1868 {
1869 CDVDImage img = dvd.GetImage();
1870 QString src = img.GetFilePath();
1871 AssertMsg (!src.isNull(), ("Image file must not be null"));
1872 QFileInfo fi (src);
1873 rbISODVD->setChecked (true);
1874 uuidISODVD = QUuid (img.GetId());
1875 break;
1876 }
1877 case CEnums::NotMounted:
1878 {
1879 bgDVD->setChecked(false);
1880 break;
1881 }
1882 default:
1883 AssertMsgFailed (("invalid DVD state: %d\n", dvd.GetState()));
1884 }
1885 }
1886
1887 /* audio */
1888 {
1889 CAudioAdapter audio = machine.GetAudioAdapter();
1890 grbAudio->setChecked (audio.GetEnabled());
1891 cbAudioDriver->setCurrentText (vboxGlobal().toString (audio.GetAudioDriver()));
1892 }
1893
1894 /* network */
1895 {
1896 ulong count = vbox.GetSystemProperties().GetNetworkAdapterCount();
1897 for (ulong slot = 0; slot < count; ++ slot)
1898 {
1899 CNetworkAdapter adapter = machine.GetNetworkAdapter (slot);
1900 addNetworkAdapter (adapter);
1901 }
1902 }
1903
1904 /* serial ports */
1905 {
1906 ulong count = vbox.GetSystemProperties().GetSerialPortCount();
1907 for (ulong slot = 0; slot < count; ++ slot)
1908 {
1909 CSerialPort port = machine.GetSerialPort (slot);
1910 addSerialPort (port);
1911 }
1912 }
1913
1914 /* parallel ports */
1915 {
1916 ulong count = vbox.GetSystemProperties().GetParallelPortCount();
1917 for (ulong slot = 0; slot < count; ++ slot)
1918 {
1919 CParallelPort port = machine.GetParallelPort (slot);
1920 addParallelPort (port);
1921 }
1922 }
1923
1924 /* USB */
1925 {
1926 CUSBController ctl = machine.GetUSBController();
1927
1928 if (ctl.isNull())
1929 {
1930 /* disable the USB controller category if the USB controller is
1931 * not available (i.e. in VirtualBox OSE) */
1932
1933 QListViewItem *usbItem = listView->findItem ("#usb", listView_Link);
1934 Assert (usbItem);
1935 if (usbItem)
1936 usbItem->setVisible (false);
1937
1938 /* disable validators if any */
1939 pageUSB->setEnabled (false);
1940
1941 /* Show an error message (if there is any).
1942 * Note that we don't use the generic cannotLoadMachineSettings()
1943 * call here because we want this message to be suppressable. */
1944 vboxProblem().cannotAccessUSB (machine);
1945 }
1946 else
1947 {
1948 cbEnableUSBController->setChecked (ctl.GetEnabled());
1949 cbEnableUSBEhci->setChecked (ctl.GetEnabledEhci());
1950 usbAdapterToggled (cbEnableUSBController->isChecked());
1951
1952 CUSBDeviceFilterEnumerator en = ctl.GetDeviceFilters().Enumerate();
1953 while (en.HasMore())
1954 addUSBFilter (en.GetNext(), false /* isNew */);
1955
1956 lvUSBFilters->setCurrentItem (lvUSBFilters->firstChild());
1957 /* silly Qt -- doesn't emit currentChanged after adding the
1958 * first item to an empty list */
1959 lvUSBFilters_currentChanged (lvUSBFilters->firstChild());
1960 }
1961 }
1962
1963 /* vrdp */
1964 {
1965 CVRDPServer vrdp = machine.GetVRDPServer();
1966
1967 if (vrdp.isNull())
1968 {
1969 /* disable the VRDP category if VRDP is
1970 * not available (i.e. in VirtualBox OSE) */
1971
1972 QListViewItem *vrdpItem = listView->findItem ("#vrdp", listView_Link);
1973 Assert (vrdpItem);
1974 if (vrdpItem)
1975 vrdpItem->setVisible (false);
1976
1977 /* disable validators if any */
1978 pageVRDP->setEnabled (false);
1979
1980 /* if machine has something to say, show the message */
1981 vboxProblem().cannotLoadMachineSettings (machine, false /* strict */);
1982 }
1983 else
1984 {
1985 grbVRDP->setChecked (vrdp.GetEnabled());
1986 leVRDPPort->setText (QString::number (vrdp.GetPort()));
1987 cbVRDPAuthType->setCurrentText (vboxGlobal().toString (vrdp.GetAuthType()));
1988 leVRDPTimeout->setText (QString::number (vrdp.GetAuthTimeout()));
1989 }
1990 }
1991
1992 /* shared folders */
1993 {
1994 mSharedFolders->getFromMachine (machine);
1995 }
1996
1997 /* request for media shortcuts update */
1998 cbHDA->setBelongsTo (machine.GetId());
1999 cbHDB->setBelongsTo (machine.GetId());
2000 cbHDD->setBelongsTo (machine.GetId());
2001 updateShortcuts();
2002
2003 /* revalidate pages with custom validation */
2004 wvalHDD->revalidate();
2005 wvalDVD->revalidate();
2006 wvalFloppy->revalidate();
2007 wvalVRDP->revalidate();
2008
2009 /* finally set the reset First Run Wizard flag to "false" to make sure
2010 * user will see this dialog if he hasn't change the boot-order
2011 * and/or mounted images configuration */
2012 mResetFirstRunFlag = false;
2013}
2014
2015
2016COMResult VBoxVMSettingsDlg::putBackToMachine()
2017{
2018 CVirtualBox vbox = vboxGlobal().virtualBox();
2019 CBIOSSettings biosSettings = cmachine.GetBIOSSettings();
2020
2021 /* name */
2022 cmachine.SetName (leName->text());
2023
2024 /* OS type */
2025 CGuestOSType type = vboxGlobal().vmGuestOSType (cbOS->currentItem());
2026 AssertMsg (!type.isNull(), ("vmGuestOSType() must return non-null type"));
2027 cmachine.SetOSTypeId (type.GetId());
2028
2029 /* RAM size */
2030 cmachine.SetMemorySize (slRAM->value());
2031
2032 /* VRAM size */
2033 cmachine.SetVRAMSize (slVRAM->value());
2034
2035 /* boot order */
2036 tblBootOrder->putBackToMachine (cmachine);
2037
2038 /* ACPI */
2039 biosSettings.SetACPIEnabled (chbEnableACPI->isChecked());
2040
2041 /* IO APIC */
2042 biosSettings.SetIOAPICEnabled (chbEnableIOAPIC->isChecked());
2043
2044 /* VT-x/AMD-V */
2045 cmachine.SetHWVirtExEnabled (
2046 chbVTX->state() == QButton::Off ? CEnums::False :
2047 chbVTX->state() == QButton::On ? CEnums::True : CEnums::Default);
2048
2049 /* Saved state folder */
2050 if (leSnapshotFolder->isModified())
2051 {
2052 cmachine.SetSnapshotFolder (leSnapshotFolder->text());
2053 if (!cmachine.isOk())
2054 vboxProblem()
2055 .cannotSetSnapshotFolder (cmachine,
2056 QDir::convertSeparators (leSnapshotFolder->text()));
2057 }
2058
2059 /* Description (set empty to null to avoid an empty <Description> node
2060 * in the settings file) */
2061 cmachine.SetDescription (teDescription->text().isEmpty() ? QString::null :
2062 teDescription->text());
2063
2064 /* Shared clipboard mode */
2065 cmachine.SetClipboardMode ((CEnums::ClipboardMode)cbSharedClipboard->currentItem());
2066
2067 /* IDE controller type */
2068 biosSettings.SetIDEControllerType (vboxGlobal().toIDEControllerType (cbIdeController->currentText()));
2069
2070 /* other features */
2071 cmachine.SetExtraData (VBoxDefs::GUI_SaveMountedAtRuntime,
2072 chbRememberMedia->isChecked() ? "yes" : "no");
2073
2074 /* hard disk images */
2075 {
2076 struct
2077 {
2078 CEnums::DiskControllerType ctl;
2079 LONG dev;
2080 struct {
2081 QGroupBox *grb;
2082 QUuid *uuid;
2083 } data;
2084 }
2085 diskSet[] =
2086 {
2087 { CEnums::IDE0Controller, 0, {grbHDA, &uuidHDA} },
2088 { CEnums::IDE0Controller, 1, {grbHDB, &uuidHDB} },
2089 { CEnums::IDE1Controller, 1, {grbHDD, &uuidHDD} }
2090 };
2091
2092 /*
2093 * first, detach all disks (to ensure we can reattach them to different
2094 * controllers / devices, when appropriate)
2095 */
2096 CHardDiskAttachmentEnumerator en =
2097 cmachine.GetHardDiskAttachments().Enumerate();
2098 while (en.HasMore())
2099 {
2100 CHardDiskAttachment hda = en.GetNext();
2101 for (uint i = 0; i < SIZEOF_ARRAY (diskSet); i++)
2102 {
2103 if (diskSet [i].ctl == hda.GetController() &&
2104 diskSet [i].dev == hda.GetDeviceNumber())
2105 {
2106 cmachine.DetachHardDisk (diskSet [i].ctl, diskSet [i].dev);
2107 if (!cmachine.isOk())
2108 vboxProblem().cannotDetachHardDisk (
2109 this, cmachine, diskSet [i].ctl, diskSet [i].dev);
2110 }
2111 }
2112 }
2113
2114 /* now, attach new disks */
2115 for (uint i = 0; i < SIZEOF_ARRAY (diskSet); i++)
2116 {
2117 QUuid *newId = diskSet [i].data.uuid;
2118 if (diskSet [i].data.grb->isChecked() && !(*newId).isNull())
2119 {
2120 cmachine.AttachHardDisk (*newId, diskSet [i].ctl, diskSet [i].dev);
2121 if (!cmachine.isOk())
2122 vboxProblem().cannotAttachHardDisk (
2123 this, cmachine, *newId, diskSet [i].ctl, diskSet [i].dev);
2124 }
2125 }
2126 }
2127
2128 /* floppy image */
2129 {
2130 CFloppyDrive floppy = cmachine.GetFloppyDrive();
2131 if (!bgFloppy->isChecked())
2132 {
2133 floppy.Unmount();
2134 }
2135 else if (rbHostFloppy->isChecked())
2136 {
2137 int id = cbHostFloppy->currentItem();
2138 Assert (id >= 0);
2139 if (id < (int) hostFloppies.count())
2140 floppy.CaptureHostDrive (hostFloppies [id]);
2141 /*
2142 * otherwise the selected drive is not yet available, leave it
2143 * as is
2144 */
2145 }
2146 else if (rbISOFloppy->isChecked())
2147 {
2148 Assert (!uuidISOFloppy.isNull());
2149 floppy.MountImage (uuidISOFloppy);
2150 }
2151 }
2152
2153 /* CD/DVD-ROM image */
2154 {
2155 CDVDDrive dvd = cmachine.GetDVDDrive();
2156 if (!bgDVD->isChecked())
2157 {
2158 dvd.SetPassthrough (false);
2159 dvd.Unmount();
2160 }
2161 else if (rbHostDVD->isChecked())
2162 {
2163 dvd.SetPassthrough (cbPassthrough->isChecked());
2164 int id = cbHostDVD->currentItem();
2165 Assert (id >= 0);
2166 if (id < (int) hostDVDs.count())
2167 dvd.CaptureHostDrive (hostDVDs [id]);
2168 /*
2169 * otherwise the selected drive is not yet available, leave it
2170 * as is
2171 */
2172 }
2173 else if (rbISODVD->isChecked())
2174 {
2175 dvd.SetPassthrough (false);
2176 Assert (!uuidISODVD.isNull());
2177 dvd.MountImage (uuidISODVD);
2178 }
2179 }
2180
2181 /* Clear the "GUI_FirstRun" extra data key in case if the boot order
2182 * and/or disk configuration were changed */
2183 if (mResetFirstRunFlag)
2184 cmachine.SetExtraData (VBoxDefs::GUI_FirstRun, QString::null);
2185
2186 /* audio */
2187 {
2188 CAudioAdapter audio = cmachine.GetAudioAdapter();
2189 audio.SetAudioDriver (vboxGlobal().toAudioDriverType (cbAudioDriver->currentText()));
2190 audio.SetEnabled (grbAudio->isChecked());
2191 AssertWrapperOk (audio);
2192 }
2193
2194 /* network */
2195 {
2196 for (int index = 0; index < tbwNetwork->count(); index++)
2197 {
2198 VBoxVMNetworkSettings *page =
2199 (VBoxVMNetworkSettings *) tbwNetwork->page (index);
2200 Assert (page);
2201 page->putBackToAdapter();
2202 }
2203 }
2204
2205 /* serial ports */
2206 {
2207 for (int index = 0; index < tbwSerialPorts->count(); index++)
2208 {
2209 VBoxVMSerialPortSettings *page =
2210 (VBoxVMSerialPortSettings *) tbwSerialPorts->page (index);
2211 Assert (page);
2212 page->putBackToPort();
2213 }
2214 }
2215
2216 /* parallel ports */
2217 {
2218 for (int index = 0; index < tbwParallelPorts->count(); index++)
2219 {
2220 VBoxVMParallelPortSettings *page =
2221 (VBoxVMParallelPortSettings *) tbwParallelPorts->page (index);
2222 Assert (page);
2223 page->putBackToPort();
2224 }
2225 }
2226
2227 /* usb */
2228 {
2229 CUSBController ctl = cmachine.GetUSBController();
2230
2231 if (!ctl.isNull())
2232 {
2233 /* the USB controller may be unavailable (i.e. in VirtualBox OSE) */
2234
2235 ctl.SetEnabled (cbEnableUSBController->isChecked());
2236 ctl.SetEnabledEhci (cbEnableUSBEhci->isChecked());
2237
2238 /*
2239 * first, remove all old filters (only if the list is changed,
2240 * not only individual properties of filters)
2241 */
2242 if (mUSBFilterListModified)
2243 for (ulong count = ctl.GetDeviceFilters().GetCount(); count; -- count)
2244 ctl.RemoveDeviceFilter (0);
2245
2246 /* then add all new filters */
2247 for (QListViewItem *item = lvUSBFilters->firstChild(); item;
2248 item = item->nextSibling())
2249 {
2250 USBListItem *uli = static_cast <USBListItem *> (item);
2251 VBoxUSBFilterSettings *settings =
2252 static_cast <VBoxUSBFilterSettings *>
2253 (wstUSBFilters->widget (uli->mId));
2254 Assert (settings);
2255
2256 COMResult res = settings->putBackToFilter();
2257 if (!res.isOk())
2258 return res;
2259
2260 CUSBDeviceFilter filter = settings->filter();
2261 filter.SetActive (uli->isOn());
2262
2263 if (mUSBFilterListModified)
2264 ctl.InsertDeviceFilter (~0, filter);
2265 }
2266 }
2267
2268 mUSBFilterListModified = false;
2269 }
2270
2271 /* vrdp */
2272 {
2273 CVRDPServer vrdp = cmachine.GetVRDPServer();
2274
2275 if (!vrdp.isNull())
2276 {
2277 /* VRDP may be unavailable (i.e. in VirtualBox OSE) */
2278 vrdp.SetEnabled (grbVRDP->isChecked());
2279 vrdp.SetPort (leVRDPPort->text().toULong());
2280 vrdp.SetAuthType (vboxGlobal().toVRDPAuthType (cbVRDPAuthType->currentText()));
2281 vrdp.SetAuthTimeout (leVRDPTimeout->text().toULong());
2282 }
2283 }
2284
2285 /* shared folders */
2286 {
2287 mSharedFolders->putBackToMachine();
2288 }
2289
2290 return COMResult();
2291}
2292
2293
2294void VBoxVMSettingsDlg::showImageManagerHDA() { showVDImageManager (&uuidHDA, cbHDA); }
2295void VBoxVMSettingsDlg::showImageManagerHDB() { showVDImageManager (&uuidHDB, cbHDB); }
2296void VBoxVMSettingsDlg::showImageManagerHDD() { showVDImageManager (&uuidHDD, cbHDD); }
2297void VBoxVMSettingsDlg::showImageManagerISODVD() { showVDImageManager (&uuidISODVD, cbISODVD); }
2298void VBoxVMSettingsDlg::showImageManagerISOFloppy() { showVDImageManager(&uuidISOFloppy, cbISOFloppy); }
2299
2300void VBoxVMSettingsDlg::showVDImageManager (QUuid *id, VBoxMediaComboBox *cbb, QLabel*)
2301{
2302 VBoxDefs::DiskType type = VBoxDefs::InvalidType;
2303 if (cbb == cbISODVD)
2304 type = VBoxDefs::CD;
2305 else if (cbb == cbISOFloppy)
2306 type = VBoxDefs::FD;
2307 else
2308 type = VBoxDefs::HD;
2309
2310 VBoxDiskImageManagerDlg dlg (this, "VBoxDiskImageManagerDlg",
2311 WType_Dialog | WShowModal);
2312 QUuid machineId = cmachine.GetId();
2313 QUuid hdId = type == VBoxDefs::HD ? cbb->getId() : QUuid();
2314 QUuid cdId = type == VBoxDefs::CD ? cbb->getId() : QUuid();
2315 QUuid fdId = type == VBoxDefs::FD ? cbb->getId() : QUuid();
2316 dlg.setup (type, true, &machineId, true /* aRefresh */, cmachine,
2317 hdId, cdId, fdId);
2318 if (dlg.exec() == VBoxDiskImageManagerDlg::Accepted)
2319 {
2320 *id = dlg.getSelectedUuid();
2321 resetFirstRunFlag();
2322 }
2323 else
2324 {
2325 *id = cbb->getId();
2326 }
2327
2328 cbb->setCurrentItem (*id);
2329 cbb->setFocus();
2330
2331 /* revalidate pages with custom validation */
2332 wvalHDD->revalidate();
2333 wvalDVD->revalidate();
2334 wvalFloppy->revalidate();
2335}
2336
2337void VBoxVMSettingsDlg::addNetworkAdapter (const CNetworkAdapter &aAdapter)
2338{
2339 VBoxVMNetworkSettings *page = new VBoxVMNetworkSettings();
2340 page->loadInterfaceList (mInterfaceList, mNoInterfaces);
2341 page->loadNetworksList (mNetworksList);
2342 page->getFromAdapter (aAdapter);
2343 QString pageTitle = QString (tr ("Adapter %1", "network"))
2344 .arg (aAdapter.GetSlot());
2345 tbwNetwork->addTab (page, pageTitle);
2346
2347 /* fix the tab order so that main dialog's buttons are always the last */
2348 setTabOrder (page->leTAPTerminate, buttonHelp);
2349 setTabOrder (buttonHelp, buttonOk);
2350 setTabOrder (buttonOk, buttonCancel);
2351
2352 /* setup validation */
2353 QIWidgetValidator *wval =
2354 new QIWidgetValidator (QString ("%1: %2")
2355 .arg (pagePath (pageNetwork), pageTitle),
2356 pageNetwork, this);
2357 connect (page->grbEnabled, SIGNAL (toggled (bool)), wval, SLOT (revalidate()));
2358 connect (page->cbNetworkAttachment, SIGNAL (activated (const QString &)),
2359 wval, SLOT (revalidate()));
2360 connect (page->cbInternalNetworkName, SIGNAL (activated (const QString &)),
2361 wval, SLOT (revalidate()));
2362 connect (page->cbInternalNetworkName, SIGNAL (textChanged (const QString &)),
2363 this, SLOT (updateNetworksList()));
2364 connect (page->cbInternalNetworkName, SIGNAL (textChanged (const QString &)),
2365 wval, SLOT (revalidate()));
2366 connect (wval, SIGNAL (validityChanged (const QIWidgetValidator *)),
2367 this, SLOT (enableOk (const QIWidgetValidator *)));
2368 connect (wval, SIGNAL (isValidRequested (QIWidgetValidator *)),
2369 this, SLOT (revalidate( QIWidgetValidator *)));
2370
2371 page->setValidator (wval);
2372 page->revalidate();
2373
2374#ifdef Q_WS_WIN
2375
2376 /* fix focus order (make sure the Host Interface list UI goes after the
2377 * last network adapter UI item) */
2378
2379 setTabOrder (page->chbCableConnected, lbHostInterface);
2380 setTabOrder (lbHostInterface, pbHostAdd);
2381 setTabOrder (pbHostAdd, pbHostRemove);
2382
2383#endif
2384}
2385
2386void VBoxVMSettingsDlg::updateNetworksList()
2387{
2388 if (mLockNetworkListUpdate)
2389 return;
2390 mLockNetworkListUpdate = true;
2391
2392 QStringList curList (mNetworksList);
2393 for (int index = 0; index < tbwNetwork->count(); ++ index)
2394 {
2395 VBoxVMNetworkSettings *pg = tbwNetwork->page (index) ?
2396 static_cast <VBoxVMNetworkSettings*> (tbwNetwork->page (index)) : 0;
2397 if (pg)
2398 {
2399 QString curText = pg->cbInternalNetworkName->currentText();
2400 if (!curText.isEmpty() && !curList.contains (curText))
2401 curList << curText;
2402 }
2403 }
2404
2405 for (int index = 0; index < tbwNetwork->count(); ++ index)
2406 {
2407 VBoxVMNetworkSettings *pg = tbwNetwork->page (index) ?
2408 static_cast <VBoxVMNetworkSettings*> (tbwNetwork->page (index)) : 0;
2409 pg->loadNetworksList (curList);
2410 }
2411
2412 mLockNetworkListUpdate = false;
2413}
2414
2415void VBoxVMSettingsDlg::addSerialPort (const CSerialPort &aPort)
2416{
2417 VBoxVMSerialPortSettings *page = new VBoxVMSerialPortSettings();
2418 page->getFromPort (aPort);
2419 QString pageTitle = QString (tr ("Port %1", "serial ports"))
2420 .arg (aPort.GetSlot());
2421 tbwSerialPorts->addTab (page, pageTitle);
2422
2423 /* fix the tab order so that main dialog's buttons are always the last */
2424 setTabOrder (page->mPortPathLine, buttonHelp);
2425 setTabOrder (buttonHelp, buttonOk);
2426 setTabOrder (buttonOk, buttonCancel);
2427
2428 /* setup validation */
2429 QIWidgetValidator *wval =
2430 new QIWidgetValidator (QString ("%1: %2")
2431 .arg (pagePath (pageSerial), pageTitle),
2432 pageSerial, this);
2433 connect (page->mSerialPortBox, SIGNAL (toggled (bool)),
2434 wval, SLOT (revalidate()));
2435 connect (page->mIRQLine, SIGNAL (textChanged (const QString &)),
2436 wval, SLOT (revalidate()));
2437 connect (page->mIOPortLine, SIGNAL (textChanged (const QString &)),
2438 wval, SLOT (revalidate()));
2439 connect (page->mHostModeCombo, SIGNAL (activated (const QString &)),
2440 wval, SLOT (revalidate()));
2441 connect (wval, SIGNAL (validityChanged (const QIWidgetValidator *)),
2442 this, SLOT (enableOk (const QIWidgetValidator *)));
2443 connect (wval, SIGNAL (isValidRequested (QIWidgetValidator *)),
2444 this, SLOT (revalidate (QIWidgetValidator *)));
2445
2446 wval->revalidate();
2447}
2448
2449void VBoxVMSettingsDlg::addParallelPort (const CParallelPort &aPort)
2450{
2451 VBoxVMParallelPortSettings *page = new VBoxVMParallelPortSettings();
2452 page->getFromPort (aPort);
2453 QString pageTitle = QString (tr ("Port %1", "parallel ports"))
2454 .arg (aPort.GetSlot());
2455 tbwParallelPorts->addTab (page, pageTitle);
2456
2457 /* fix the tab order so that main dialog's buttons are always the last */
2458 setTabOrder (page->mPortPathLine, buttonHelp);
2459 setTabOrder (buttonHelp, buttonOk);
2460 setTabOrder (buttonOk, buttonCancel);
2461
2462 /* setup validation */
2463 QIWidgetValidator *wval =
2464 new QIWidgetValidator (QString ("%1: %2")
2465 .arg (pagePath (pageParallel), pageTitle),
2466 pageParallel, this);
2467 connect (page->mParallelPortBox, SIGNAL (toggled (bool)),
2468 wval, SLOT (revalidate()));
2469 connect (page->mIRQLine, SIGNAL (textChanged (const QString &)),
2470 wval, SLOT (revalidate()));
2471 connect (page->mIOPortLine, SIGNAL (textChanged (const QString &)),
2472 wval, SLOT (revalidate()));
2473 connect (wval, SIGNAL (validityChanged (const QIWidgetValidator *)),
2474 this, SLOT (enableOk (const QIWidgetValidator *)));
2475 connect (wval, SIGNAL (isValidRequested (QIWidgetValidator *)),
2476 this, SLOT (revalidate (QIWidgetValidator *)));
2477
2478 wval->revalidate();
2479}
2480
2481void VBoxVMSettingsDlg::slRAM_valueChanged( int val )
2482{
2483 leRAM->setText( QString().setNum( val ) );
2484}
2485
2486void VBoxVMSettingsDlg::leRAM_textChanged( const QString &text )
2487{
2488 slRAM->setValue( text.toInt() );
2489}
2490
2491void VBoxVMSettingsDlg::slVRAM_valueChanged( int val )
2492{
2493 leVRAM->setText( QString().setNum( val ) );
2494}
2495
2496void VBoxVMSettingsDlg::leVRAM_textChanged( const QString &text )
2497{
2498 slVRAM->setValue( text.toInt() );
2499}
2500
2501void VBoxVMSettingsDlg::cbOS_activated (int item)
2502{
2503 Q_UNUSED (item);
2504/// @todo (dmik) remove?
2505// CGuestOSType type = vboxGlobal().vmGuestOSType (item);
2506// txRAMBest->setText (tr ("<qt>Best&nbsp;%1&nbsp;MB<qt>")
2507// .arg (type.GetRecommendedRAM()));
2508// txVRAMBest->setText (tr ("<qt>Best&nbsp;%1&nbsp;MB</qt>")
2509// .arg (type.GetRecommendedVRAM()));
2510 txRAMBest->setText (QString::null);
2511 txVRAMBest->setText (QString::null);
2512}
2513
2514void VBoxVMSettingsDlg::tbResetSavedStateFolder_clicked()
2515{
2516 /*
2517 * do this instead of le->setText (QString::null) to cause
2518 * isModified() return true
2519 */
2520 leSnapshotFolder->selectAll();
2521 leSnapshotFolder->del();
2522}
2523
2524void VBoxVMSettingsDlg::tbSelectSavedStateFolder_clicked()
2525{
2526 QString settingsFolder = VBoxGlobal::getFirstExistingDir (leSnapshotFolder->text());
2527 if (settingsFolder.isNull())
2528 settingsFolder = QFileInfo (cmachine.GetSettingsFilePath()).dirPath (true);
2529
2530 QString folder = vboxGlobal().getExistingDirectory (settingsFolder, this);
2531 if (folder.isNull())
2532 return;
2533
2534 folder = QDir::convertSeparators (folder);
2535 /* remove trailing slash if any */
2536 folder.remove (QRegExp ("[\\\\/]$"));
2537
2538 /*
2539 * do this instead of le->setText (folder) to cause
2540 * isModified() return true
2541 */
2542 leSnapshotFolder->selectAll();
2543 leSnapshotFolder->insert (folder);
2544}
2545
2546// USB Filter stuff
2547////////////////////////////////////////////////////////////////////////////////
2548
2549void VBoxVMSettingsDlg::usbAdapterToggled (bool aOn)
2550{
2551 if (!aOn)
2552 cbEnableUSBEhci->setChecked (aOn);
2553 grbUSBFilters->setEnabled (aOn);
2554}
2555
2556void VBoxVMSettingsDlg::addUSBFilter (const CUSBDeviceFilter &aFilter, bool isNew)
2557{
2558 QListViewItem *currentItem = isNew
2559 ? lvUSBFilters->currentItem()
2560 : lvUSBFilters->lastItem();
2561
2562 VBoxUSBFilterSettings *settings = new VBoxUSBFilterSettings (wstUSBFilters);
2563 settings->setup (VBoxUSBFilterSettings::MachineType);
2564 settings->getFromFilter (aFilter);
2565
2566 USBListItem *item = new USBListItem (lvUSBFilters, currentItem);
2567 item->setOn (aFilter.GetActive());
2568 item->setText (lvUSBFilters_Name, aFilter.GetName());
2569
2570 item->mId = wstUSBFilters->addWidget (settings);
2571
2572 /* fix the tab order so that main dialog's buttons are always the last */
2573 setTabOrder (settings->focusProxy(), buttonHelp);
2574 setTabOrder (buttonHelp, buttonOk);
2575 setTabOrder (buttonOk, buttonCancel);
2576
2577 if (isNew)
2578 {
2579 lvUSBFilters->setSelected (item, true);
2580 lvUSBFilters_currentChanged (item);
2581 settings->leUSBFilterName->setFocus();
2582 }
2583
2584 connect (settings->leUSBFilterName, SIGNAL (textChanged (const QString &)),
2585 this, SLOT (lvUSBFilters_setCurrentText (const QString &)));
2586
2587 /* setup validation */
2588
2589 QIWidgetValidator *wval =
2590 new QIWidgetValidator (pagePath (pageUSB), settings, settings);
2591 connect (wval, SIGNAL (validityChanged (const QIWidgetValidator *)),
2592 this, SLOT (enableOk (const QIWidgetValidator *)));
2593
2594 wval->revalidate();
2595}
2596
2597void VBoxVMSettingsDlg::lvUSBFilters_currentChanged (QListViewItem *item)
2598{
2599 if (item && lvUSBFilters->selectedItem() != item)
2600 lvUSBFilters->setSelected (item, true);
2601
2602 tbRemoveUSBFilter->setEnabled (!!item);
2603
2604 tbUSBFilterUp->setEnabled (!!item && item->itemAbove());
2605 tbUSBFilterDown->setEnabled (!!item && item->itemBelow());
2606
2607 if (item)
2608 {
2609 USBListItem *uli = static_cast <USBListItem *> (item);
2610 wstUSBFilters->raiseWidget (uli->mId);
2611 }
2612 else
2613 {
2614 /* raise the disabled widget */
2615 wstUSBFilters->raiseWidget (0);
2616 }
2617}
2618
2619void VBoxVMSettingsDlg::lvUSBFilters_setCurrentText (const QString &aText)
2620{
2621 QListViewItem *item = lvUSBFilters->currentItem();
2622 Assert (item);
2623
2624 item->setText (lvUSBFilters_Name, aText);
2625}
2626
2627void VBoxVMSettingsDlg::tbAddUSBFilter_clicked()
2628{
2629 /* search for the max available filter index */
2630 int maxFilterIndex = 0;
2631 QString usbFilterName = tr ("New Filter %1", "usb");
2632 QRegExp regExp (QString ("^") + usbFilterName.arg ("([0-9]+)") + QString ("$"));
2633 QListViewItemIterator iterator (lvUSBFilters);
2634 while (*iterator)
2635 {
2636 QString filterName = (*iterator)->text (lvUSBFilters_Name);
2637 int pos = regExp.search (filterName);
2638 if (pos != -1)
2639 maxFilterIndex = regExp.cap (1).toInt() > maxFilterIndex ?
2640 regExp.cap (1).toInt() : maxFilterIndex;
2641 ++ iterator;
2642 }
2643
2644 /* creating new usb filter */
2645 CUSBDeviceFilter filter = cmachine.GetUSBController()
2646 .CreateDeviceFilter (usbFilterName.arg (maxFilterIndex + 1));
2647
2648 filter.SetActive (true);
2649 addUSBFilter (filter, true /* isNew */);
2650
2651 mUSBFilterListModified = true;
2652}
2653
2654void VBoxVMSettingsDlg::tbAddUSBFilterFrom_clicked()
2655{
2656 usbDevicesMenu->exec (QCursor::pos());
2657}
2658
2659void VBoxVMSettingsDlg::menuAddUSBFilterFrom_activated (int aIndex)
2660{
2661 CUSBDevice usb = usbDevicesMenu->getUSB (aIndex);
2662 /* if null then some other item but a USB device is selected */
2663 if (usb.isNull())
2664 return;
2665
2666 CUSBDeviceFilter filter = cmachine.GetUSBController()
2667 .CreateDeviceFilter (vboxGlobal().details (usb));
2668
2669 filter.SetVendorId (QString().sprintf ("%04hX", usb.GetVendorId()));
2670 filter.SetProductId (QString().sprintf ("%04hX", usb.GetProductId()));
2671 filter.SetRevision (QString().sprintf ("%04hX", usb.GetRevision()));
2672 /* The port property depends on the host computer rather than on the USB
2673 * device itself; for this reason only a few people will want to use it in
2674 * the filter since the same device plugged into a different socket will
2675 * not match the filter in this case. */
2676#if 0
2677 /// @todo set it anyway if Alt is currently pressed
2678 filter.SetPort (QString().sprintf ("%04hX", usb.GetPort()));
2679#endif
2680 filter.SetManufacturer (usb.GetManufacturer());
2681 filter.SetProduct (usb.GetProduct());
2682 filter.SetSerialNumber (usb.GetSerialNumber());
2683 filter.SetRemote (usb.GetRemote() ? "yes" : "no");
2684
2685 filter.SetActive (true);
2686 addUSBFilter (filter, true /* isNew */);
2687
2688 mUSBFilterListModified = true;
2689}
2690
2691void VBoxVMSettingsDlg::tbRemoveUSBFilter_clicked()
2692{
2693 QListViewItem *item = lvUSBFilters->currentItem();
2694 Assert (item);
2695
2696 USBListItem *uli = static_cast <USBListItem *> (item);
2697 QWidget *settings = wstUSBFilters->widget (uli->mId);
2698 Assert (settings);
2699 wstUSBFilters->removeWidget (settings);
2700 delete settings;
2701
2702 delete item;
2703
2704 lvUSBFilters->setSelected (lvUSBFilters->currentItem(), true);
2705 mUSBFilterListModified = true;
2706}
2707
2708void VBoxVMSettingsDlg::tbUSBFilterUp_clicked()
2709{
2710 QListViewItem *item = lvUSBFilters->currentItem();
2711 Assert (item);
2712
2713 QListViewItem *itemAbove = item->itemAbove();
2714 Assert (itemAbove);
2715 itemAbove = itemAbove->itemAbove();
2716
2717 if (!itemAbove)
2718 {
2719 /* overcome Qt stupidity */
2720 item->itemAbove()->moveItem (item);
2721 }
2722 else
2723 item->moveItem (itemAbove);
2724
2725 lvUSBFilters_currentChanged (item);
2726 mUSBFilterListModified = true;
2727}
2728
2729void VBoxVMSettingsDlg::tbUSBFilterDown_clicked()
2730{
2731 QListViewItem *item = lvUSBFilters->currentItem();
2732 Assert (item);
2733
2734 QListViewItem *itemBelow = item->itemBelow();
2735 Assert (itemBelow);
2736
2737 item->moveItem (itemBelow);
2738
2739 lvUSBFilters_currentChanged (item);
2740 mUSBFilterListModified = true;
2741}
2742
2743#include "VBoxVMSettingsDlg.ui.moc"
2744
Note: See TracBrowser for help on using the repository browser.

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