VirtualBox

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

最後變更 在這個檔案從6000是 5999,由 vboxsync 提交於 17 年 前

The Giant CDDL Dual-License Header Change.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 93.4 KB
 
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.alldomusa.eu.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#elif defined Q_OS_MACX
871 cbAudioDriver->insertItem (vboxGlobal().toString (CEnums::CoreAudioDriver));
872#endif
873
874 /* Network Page */
875
876 loadInterfacesList();
877
878 /*
879 * update the Ok button state for pages with validation
880 * (validityChanged() connected to enableNext() will do the job)
881 */
882 wvalGeneral->revalidate();
883 wvalHDD->revalidate();
884 wvalDVD->revalidate();
885 wvalFloppy->revalidate();
886
887 /* VRDP Page */
888
889 cbVRDPAuthType->insertItem (vboxGlobal().toString (CEnums::VRDPAuthNull));
890 cbVRDPAuthType->insertItem (vboxGlobal().toString (CEnums::VRDPAuthExternal));
891 cbVRDPAuthType->insertItem (vboxGlobal().toString (CEnums::VRDPAuthGuest));
892}
893
894/**
895 * Returns a path to the given page of this settings dialog. See ::path() for
896 * details.
897 */
898QString VBoxVMSettingsDlg::pagePath (QWidget *aPage)
899{
900 QListViewItem *li = listView->
901 findItem (QString::number (widgetStack->id (aPage)), 1);
902 return ::path (li);
903}
904
905bool VBoxVMSettingsDlg::eventFilter (QObject *object, QEvent *event)
906{
907 if (!object->isWidgetType())
908 return QDialog::eventFilter (object, event);
909
910 QWidget *widget = static_cast <QWidget *> (object);
911 if (widget->topLevelWidget() != this)
912 return QDialog::eventFilter (object, event);
913
914 switch (event->type())
915 {
916 case QEvent::Enter:
917 case QEvent::Leave:
918 {
919 if (event->type() == QEvent::Enter)
920 whatsThisCandidate = widget;
921 else
922 whatsThisCandidate = NULL;
923 whatsThisTimer->start (100, true /* sshot */);
924 break;
925 }
926 case QEvent::FocusIn:
927 {
928 updateWhatsThis (true /* gotFocus */);
929 tblBootOrder->processFocusIn (widget);
930 break;
931 }
932 default:
933 break;
934 }
935
936 return QDialog::eventFilter (object, event);
937}
938
939void VBoxVMSettingsDlg::showEvent (QShowEvent *e)
940{
941 QDialog::showEvent (e);
942
943 /* one may think that QWidget::polish() is the right place to do things
944 * below, but apparently, by the time when QWidget::polish() is called,
945 * the widget style & layout are not fully done, at least the minimum
946 * size hint is not properly calculated. Since this is sometimes necessary,
947 * we provide our own "polish" implementation. */
948
949 if (polished)
950 return;
951
952 polished = true;
953
954 /* update geometry for the dynamically added usb-page to ensure proper
955 * sizeHint calculation by the Qt layout manager */
956 wstUSBFilters->updateGeometry();
957 /* let our toplevel widget calculate its sizeHint properly */
958 QApplication::sendPostedEvents (0, 0);
959
960 layout()->activate();
961
962 /* resize to the miminum possible size */
963 resize (minimumSize());
964
965 VBoxGlobal::centerWidget (this, parentWidget());
966}
967
968void VBoxVMSettingsDlg::updateShortcuts()
969{
970 /* setup necessary combobox item */
971 cbHDA->setCurrentItem (uuidHDA);
972 cbHDB->setCurrentItem (uuidHDB);
973 cbHDD->setCurrentItem (uuidHDD);
974 cbISODVD->setCurrentItem (uuidISODVD);
975 cbISOFloppy->setCurrentItem (uuidISOFloppy);
976 /* check if the enumeration process has been started yet */
977 if (!vboxGlobal().isMediaEnumerationStarted())
978 vboxGlobal().startEnumeratingMedia();
979 else
980 {
981 cbHDA->refresh();
982 cbHDB->refresh();
983 cbHDD->refresh();
984 cbISODVD->refresh();
985 cbISOFloppy->refresh();
986 }
987}
988
989void VBoxVMSettingsDlg::loadInterfacesList()
990{
991#if defined Q_WS_WIN
992 /* clear inner list */
993 mInterfaceList.clear();
994 /* load current inner list */
995 CHostNetworkInterfaceEnumerator en =
996 vboxGlobal().virtualBox().GetHost().GetNetworkInterfaces().Enumerate();
997 while (en.HasMore())
998 mInterfaceList += en.GetNext().GetName();
999 /* save current list item name */
1000 QString currentListItemName = lbHostInterface->currentText();
1001 /* load current list items */
1002 lbHostInterface->clear();
1003 if (mInterfaceList.count())
1004 lbHostInterface->insertStringList (mInterfaceList);
1005 else
1006 lbHostInterface->insertItem (mNoInterfaces);
1007 /* select current list item */
1008 int index = lbHostInterface->index (
1009 lbHostInterface->findItem (currentListItemName));
1010 if (index == -1)
1011 index = 0;
1012 lbHostInterface->setCurrentItem (index);
1013 lbHostInterface->setSelected (index, true);
1014 /* enable/disable interface delete button */
1015 pbHostRemove->setEnabled (!mInterfaceList.isEmpty());
1016#endif
1017}
1018
1019void VBoxVMSettingsDlg::hostInterfaceAdd()
1020{
1021#if defined Q_WS_WIN
1022
1023 /* allow the started helper process to make itself the foreground window */
1024 AllowSetForegroundWindow (ASFW_ANY);
1025
1026 /* search for the max available interface index */
1027 int ifaceNumber = 0;
1028 QString ifaceName = tr ("VirtualBox Host Interface %1");
1029 QRegExp regExp (QString ("^") + ifaceName.arg ("([0-9]+)") + QString ("$"));
1030 for (uint index = 0; index < lbHostInterface->count(); ++ index)
1031 {
1032 QString iface = lbHostInterface->text (index);
1033 int pos = regExp.search (iface);
1034 if (pos != -1)
1035 ifaceNumber = regExp.cap (1).toInt() > ifaceNumber ?
1036 regExp.cap (1).toInt() : ifaceNumber;
1037 }
1038
1039 /* creating add host interface dialog */
1040 VBoxAddNIDialog dlg (this, ifaceName.arg (++ ifaceNumber));
1041 if (dlg.exec() != QDialog::Accepted)
1042 return;
1043 QString iName = dlg.getName();
1044
1045 /* create interface */
1046 CHost host = vboxGlobal().virtualBox().GetHost();
1047 CHostNetworkInterface iFace;
1048 CProgress progress = host.CreateHostNetworkInterface (iName, iFace);
1049 if (host.isOk())
1050 {
1051 vboxProblem().showModalProgressDialog (progress, iName, this);
1052 if (progress.GetResultCode() == 0)
1053 {
1054 /* add&select newly created interface */
1055 delete lbHostInterface->findItem (mNoInterfaces);
1056 lbHostInterface->insertItem (iName);
1057 mInterfaceList += iName;
1058 lbHostInterface->setCurrentItem (lbHostInterface->count() - 1);
1059 lbHostInterface->setSelected (lbHostInterface->count() - 1, true);
1060 for (int index = 0; index < tbwNetwork->count(); ++ index)
1061 networkPageUpdate (tbwNetwork->page (index));
1062 /* enable interface delete button */
1063 pbHostRemove->setEnabled (true);
1064 }
1065 else
1066 vboxProblem().cannotCreateHostInterface (progress, iName, this);
1067 }
1068 else
1069 vboxProblem().cannotCreateHostInterface (host, iName, this);
1070
1071 /* allow the started helper process to make itself the foreground window */
1072 AllowSetForegroundWindow (ASFW_ANY);
1073
1074#endif
1075}
1076
1077void VBoxVMSettingsDlg::hostInterfaceRemove()
1078{
1079#if defined Q_WS_WIN
1080
1081 /* allow the started helper process to make itself the foreground window */
1082 AllowSetForegroundWindow (ASFW_ANY);
1083
1084 /* check interface name */
1085 QString iName = lbHostInterface->currentText();
1086 if (iName.isEmpty())
1087 return;
1088
1089 /* asking user about deleting selected network interface */
1090 int delNetIface = vboxProblem().message (this, VBoxProblemReporter::Question,
1091 tr ("<p>Do you want to remove the selected host network interface "
1092 "<nobr><b>%1</b>?</nobr></p>"
1093 "<p><b>Note:</b> This interface may be in use by one or more "
1094 "network adapters of this or another VM. After it is removed, these "
1095 "adapters will no longer work until you correct their settings by "
1096 "either choosing a different interface name or a different adapter "
1097 "attachment type.</p>").arg (iName),
1098 0, /* autoConfirmId */
1099 QIMessageBox::Ok | QIMessageBox::Default,
1100 QIMessageBox::Cancel | QIMessageBox::Escape);
1101 if (delNetIface == QIMessageBox::Cancel)
1102 return;
1103
1104 CHost host = vboxGlobal().virtualBox().GetHost();
1105 CHostNetworkInterface iFace = host.GetNetworkInterfaces().FindByName (iName);
1106 if (host.isOk())
1107 {
1108 /* delete interface */
1109 CProgress progress = host.RemoveHostNetworkInterface (iFace.GetId(), iFace);
1110 if (host.isOk())
1111 {
1112 vboxProblem().showModalProgressDialog (progress, iName, this);
1113 if (progress.GetResultCode() == 0)
1114 {
1115 if (lbHostInterface->count() == 1)
1116 {
1117 lbHostInterface->insertItem (mNoInterfaces);
1118 /* disable interface delete button */
1119 pbHostRemove->setEnabled (false);
1120 }
1121 delete lbHostInterface->findItem (iName);
1122 lbHostInterface->setSelected (lbHostInterface->currentItem(), true);
1123 mInterfaceList.erase (mInterfaceList.find (iName));
1124 for (int index = 0; index < tbwNetwork->count(); ++ index)
1125 networkPageUpdate (tbwNetwork->page (index));
1126 }
1127 else
1128 vboxProblem().cannotRemoveHostInterface (progress, iFace, this);
1129 }
1130 }
1131
1132 if (!host.isOk())
1133 vboxProblem().cannotRemoveHostInterface (host, iFace, this);
1134#endif
1135}
1136
1137void VBoxVMSettingsDlg::networkPageUpdate (QWidget *aWidget)
1138{
1139 if (!aWidget) return;
1140#if defined Q_WS_WIN
1141 VBoxVMNetworkSettings *set = static_cast<VBoxVMNetworkSettings*> (aWidget);
1142 set->loadList (mInterfaceList, mNoInterfaces);
1143 set->revalidate();
1144#endif
1145}
1146
1147
1148void VBoxVMSettingsDlg::onMediaEnumerationDone()
1149{
1150 mAllowResetFirstRunFlag = true;
1151}
1152
1153
1154void VBoxVMSettingsDlg::resetFirstRunFlag()
1155{
1156 if (mAllowResetFirstRunFlag)
1157 mResetFirstRunFlag = true;
1158}
1159
1160
1161void VBoxVMSettingsDlg::hdaMediaChanged()
1162{
1163 resetFirstRunFlag();
1164 uuidHDA = grbHDA->isChecked() ? cbHDA->getId() : QUuid();
1165 txHDA->setText (getHdInfo (grbHDA, uuidHDA));
1166 /* revailidate */
1167 wvalHDD->revalidate();
1168}
1169
1170
1171void VBoxVMSettingsDlg::hdbMediaChanged()
1172{
1173 resetFirstRunFlag();
1174 uuidHDB = grbHDB->isChecked() ? cbHDB->getId() : QUuid();
1175 txHDB->setText (getHdInfo (grbHDB, uuidHDB));
1176 /* revailidate */
1177 wvalHDD->revalidate();
1178}
1179
1180
1181void VBoxVMSettingsDlg::hddMediaChanged()
1182{
1183 resetFirstRunFlag();
1184 uuidHDD = grbHDD->isChecked() ? cbHDD->getId() : QUuid();
1185 txHDD->setText (getHdInfo (grbHDD, uuidHDD));
1186 /* revailidate */
1187 wvalHDD->revalidate();
1188}
1189
1190
1191void VBoxVMSettingsDlg::cdMediaChanged()
1192{
1193 resetFirstRunFlag();
1194 uuidISODVD = bgDVD->isChecked() ? cbISODVD->getId() : QUuid();
1195 /* revailidate */
1196 wvalDVD->revalidate();
1197}
1198
1199
1200void VBoxVMSettingsDlg::fdMediaChanged()
1201{
1202 resetFirstRunFlag();
1203 uuidISOFloppy = bgFloppy->isChecked() ? cbISOFloppy->getId() : QUuid();
1204 /* revailidate */
1205 wvalFloppy->revalidate();
1206}
1207
1208
1209QString VBoxVMSettingsDlg::getHdInfo (QGroupBox *aGroupBox, QUuid aId)
1210{
1211 QString notAttached = tr ("<not attached>", "hard disk");
1212 if (aId.isNull())
1213 return notAttached;
1214 return aGroupBox->isChecked() ?
1215 vboxGlobal().details (vboxGlobal().virtualBox().GetHardDisk (aId), true) :
1216 notAttached;
1217}
1218
1219void VBoxVMSettingsDlg::updateWhatsThis (bool gotFocus /* = false */)
1220{
1221 QString text;
1222
1223 QWidget *widget = NULL;
1224 if (!gotFocus)
1225 {
1226 if (whatsThisCandidate != NULL && whatsThisCandidate != this)
1227 widget = whatsThisCandidate;
1228 }
1229 else
1230 {
1231 widget = focusData()->focusWidget();
1232 }
1233 /* if the given widget lacks the whats'this text, look at its parent */
1234 while (widget && widget != this)
1235 {
1236 text = QWhatsThis::textFor (widget);
1237 if (!text.isEmpty())
1238 break;
1239 widget = widget->parentWidget();
1240 }
1241
1242 if (text.isEmpty() && !warningString.isEmpty())
1243 text = warningString;
1244 if (text.isEmpty())
1245 text = QWhatsThis::textFor (this);
1246
1247 whatsThisLabel->setText (text);
1248}
1249
1250void VBoxVMSettingsDlg::setWarning (const QString &warning)
1251{
1252 warningString = warning;
1253 if (!warning.isEmpty())
1254 warningString = QString ("<font color=red>%1</font>").arg (warning);
1255
1256 if (!warningString.isEmpty())
1257 whatsThisLabel->setText (warningString);
1258 else
1259 updateWhatsThis (true);
1260}
1261
1262/**
1263 * Sets up this dialog.
1264 *
1265 * If @a aCategory is non-null, it should be one of values from the hidden
1266 * '[cat]' column of #listView (see VBoxVMSettingsDlg.ui in qdesigner)
1267 * prepended with the '#' sign. In this case, the specified category page
1268 * will be activated when the dialog is open.
1269 *
1270 * If @a aWidget is non-null, it should be a name of one of widgets
1271 * from the given category page. In this case, the specified widget
1272 * will get focus when the dialog is open.
1273 *
1274 * @note Calling this method after the dialog is open has no sense.
1275 *
1276 * @param aCategory Category to select when the dialog is open or null.
1277 * @param aWidget Category to select when the dialog is open or null.
1278 */
1279void VBoxVMSettingsDlg::setup (const QString &aCategory, const QString &aControl)
1280{
1281 if (!aCategory.isNull())
1282 {
1283 /* search for a list view item corresponding to the category */
1284 QListViewItem *item = listView->findItem (aCategory, listView_Link);
1285 if (item)
1286 {
1287 listView->setSelected (item, true);
1288
1289 /* search for a widget with the given name */
1290 if (!aControl.isNull())
1291 {
1292 QObject *obj = widgetStack->visibleWidget()->child (aControl);
1293 if (obj && obj->isWidgetType())
1294 {
1295 QWidget *w = static_cast <QWidget *> (obj);
1296 QWidgetList parents;
1297 QWidget *p = w;
1298 while ((p = p->parentWidget()) != NULL)
1299 {
1300 if (!strcmp (p->className(), "QTabWidget"))
1301 {
1302 /* the tab contents widget is two steps down
1303 * (QTabWidget -> QWidgetStack -> QWidget) */
1304 QWidget *c = parents.last();
1305 if (c)
1306 c = parents.prev();
1307 if (c)
1308 static_cast <QTabWidget *> (p)->showPage (c);
1309 }
1310 parents.append (p);
1311 }
1312
1313 w->setFocus();
1314 }
1315 }
1316 }
1317 }
1318}
1319
1320void VBoxVMSettingsDlg::listView_currentChanged (QListViewItem *item)
1321{
1322 Assert (item);
1323 int id = item->text (1).toInt();
1324 Assert (id >= 0);
1325 titleLabel->setText (::path (item));
1326 widgetStack->raiseWidget (id);
1327}
1328
1329
1330void VBoxVMSettingsDlg::enableOk (const QIWidgetValidator *wval)
1331{
1332 Q_UNUSED (wval);
1333
1334 /* reset the warning text; interested parties will set it during
1335 * validation */
1336 setWarning (QString::null);
1337
1338 QString wvalWarning;
1339
1340 /* detect the overall validity */
1341 bool newValid = true;
1342 {
1343 QObjectList *l = this->queryList ("QIWidgetValidator");
1344 QObjectListIt it (*l);
1345 QObject *obj;
1346 while ((obj = it.current()) != 0)
1347 {
1348 QIWidgetValidator *wval = (QIWidgetValidator *) obj;
1349 newValid = wval->isValid();
1350 if (!newValid)
1351 {
1352 wvalWarning = wval->warningText();
1353 break;
1354 }
1355 ++ it;
1356 }
1357 delete l;
1358 }
1359
1360 if (warningString.isNull() && !wvalWarning.isNull())
1361 {
1362 /* try to set the generic error message when invalid but no specific
1363 * message is provided */
1364 setWarning (wvalWarning);
1365 }
1366
1367 if (valid != newValid)
1368 {
1369 valid = newValid;
1370 buttonOk->setEnabled (valid);
1371 warningLabel->setHidden (valid);
1372 warningPixmap->setHidden (valid);
1373 }
1374}
1375
1376
1377void VBoxVMSettingsDlg::revalidate (QIWidgetValidator *wval)
1378{
1379 /* do individual validations for pages */
1380 QWidget *pg = wval->widget();
1381 bool valid = wval->isOtherValid();
1382
1383 QString warningText;
1384 QString pageTitle = pagePath (pg);
1385
1386 if (pg == pageHDD)
1387 {
1388 CVirtualBox vbox = vboxGlobal().virtualBox();
1389 valid = true;
1390
1391 QValueList <QUuid> uuids;
1392
1393 if (valid && grbHDA->isChecked())
1394 {
1395 if (uuidHDA.isNull())
1396 {
1397 valid = false;
1398 warningText = tr ("Primary Master hard disk is not selected");
1399 }
1400 else uuids << uuidHDA;
1401 }
1402
1403 if (valid && grbHDB->isChecked())
1404 {
1405 if (uuidHDB.isNull())
1406 {
1407 valid = false;
1408 warningText = tr ("Primary Slave hard disk is not selected");
1409 }
1410 else
1411 {
1412 bool found = uuids.findIndex (uuidHDB) >= 0;
1413 if (found)
1414 {
1415 CHardDisk hd = vbox.GetHardDisk (uuidHDB);
1416 valid = hd.GetType() == CEnums::ImmutableHardDisk;
1417 }
1418 if (valid)
1419 uuids << uuidHDB;
1420 else
1421 warningText = tr ("Primary Slave hard disk is already attached "
1422 "to a different slot");
1423 }
1424 }
1425
1426 if (valid && grbHDD->isChecked())
1427 {
1428 if (uuidHDD.isNull())
1429 {
1430 valid = false;
1431 warningText = tr ("Secondary Slave hard disk is not selected");
1432 }
1433 else
1434 {
1435 bool found = uuids.findIndex (uuidHDD) >= 0;
1436 if (found)
1437 {
1438 CHardDisk hd = vbox.GetHardDisk (uuidHDD);
1439 valid = hd.GetType() == CEnums::ImmutableHardDisk;
1440 }
1441 if (valid)
1442 uuids << uuidHDB;
1443 else
1444 warningText = tr ("Secondary Slave hard disk is already attached "
1445 "to a different slot");
1446 }
1447 }
1448
1449 cbHDA->setEnabled (grbHDA->isChecked());
1450 cbHDB->setEnabled (grbHDB->isChecked());
1451 cbHDD->setEnabled (grbHDD->isChecked());
1452 tbHDA->setEnabled (grbHDA->isChecked());
1453 tbHDB->setEnabled (grbHDB->isChecked());
1454 tbHDD->setEnabled (grbHDD->isChecked());
1455 }
1456 else if (pg == pageDVD)
1457 {
1458 if (!bgDVD->isChecked())
1459 rbHostDVD->setChecked(false), rbISODVD->setChecked(false);
1460 else if (!rbHostDVD->isChecked() && !rbISODVD->isChecked())
1461 rbHostDVD->setChecked(true);
1462
1463 valid = !(rbISODVD->isChecked() && uuidISODVD.isNull());
1464
1465 cbHostDVD->setEnabled (rbHostDVD->isChecked());
1466 cbPassthrough->setEnabled (rbHostDVD->isChecked());
1467
1468 cbISODVD->setEnabled (rbISODVD->isChecked());
1469 tbISODVD->setEnabled (rbISODVD->isChecked());
1470
1471 if (!valid)
1472 warningText = tr ("CD/DVD image file is not selected");
1473 }
1474 else if (pg == pageFloppy)
1475 {
1476 if (!bgFloppy->isChecked())
1477 rbHostFloppy->setChecked(false), rbISOFloppy->setChecked(false);
1478 else if (!rbHostFloppy->isChecked() && !rbISOFloppy->isChecked())
1479 rbHostFloppy->setChecked(true);
1480
1481 valid = !(rbISOFloppy->isChecked() && uuidISOFloppy.isNull());
1482
1483 cbHostFloppy->setEnabled (rbHostFloppy->isChecked());
1484
1485 cbISOFloppy->setEnabled (rbISOFloppy->isChecked());
1486 tbISOFloppy->setEnabled (rbISOFloppy->isChecked());
1487
1488 if (!valid)
1489 warningText = tr ("Floppy image file is not selected");
1490 }
1491 else if (pg == pageNetwork)
1492 {
1493 QWidget *tab = NULL;
1494 for (int index = 0; index < tbwNetwork->count(); ++ index)
1495 {
1496 tab = tbwNetwork->page (index);
1497 VBoxVMNetworkSettings *page =
1498 static_cast <VBoxVMNetworkSettings *> (tab);
1499 valid = page->isPageValid (mInterfaceList);
1500 if (!valid) break;
1501 }
1502 if (!valid)
1503 {
1504 Assert (tab);
1505 warningText = tr ("Incorrect host network interface is selected");
1506 pageTitle += ": " + tbwNetwork->tabLabel (tab);
1507 }
1508 }
1509 else if (pg == pageSerial)
1510 {
1511 valid = true;
1512 QValueList <QString> ports;
1513 QValueList <QString> paths;
1514
1515 int index = 0;
1516 for (; index < tbwSerialPorts->count(); ++ index)
1517 {
1518 QWidget *tab = tbwSerialPorts->page (index);
1519 VBoxVMSerialPortSettings *page =
1520 static_cast <VBoxVMSerialPortSettings *> (tab);
1521
1522 /* check the predefined port number unicity */
1523 if (page->mSerialPortBox->isChecked() && !page->isUserDefined())
1524 {
1525 QString port = page->mPortNumCombo->currentText();
1526 valid = !ports.contains (port);
1527 if (!valid)
1528 {
1529 warningText = tr ("Duplicate port number is selected ");
1530 pageTitle += ": " + tbwSerialPorts->tabLabel (tab);
1531 break;
1532 }
1533 ports << port;
1534 }
1535 /* check the port path emptiness & unicity */
1536 CEnums::PortMode mode =
1537 vboxGlobal().toPortMode (page->mHostModeCombo->currentText());
1538 if (mode != CEnums::DisconnectedPort)
1539 {
1540 QString path = page->mPortPathLine->text();
1541 valid = !path.isEmpty() && !paths.contains (path);
1542 if (!valid)
1543 {
1544 warningText = path.isEmpty() ?
1545 tr ("Port path is not specified ") :
1546 tr ("Duplicate port path is entered ");
1547 pageTitle += ": " + tbwSerialPorts->tabLabel (tab);
1548 break;
1549 }
1550 paths << path;
1551 }
1552 }
1553 }
1554 else if (pg == pageParallel)
1555 {
1556 valid = true;
1557 QValueList <QString> ports;
1558 QValueList <QString> paths;
1559
1560 int index = 0;
1561 for (; index < tbwParallelPorts->count(); ++ index)
1562 {
1563 QWidget *tab = tbwParallelPorts->page (index);
1564 VBoxVMParallelPortSettings *page =
1565 static_cast <VBoxVMParallelPortSettings *> (tab);
1566
1567 /* check the predefined port number unicity */
1568 if (page->mParallelPortBox->isChecked() && !page->isUserDefined())
1569 {
1570 QString port = page->mPortNumCombo->currentText();
1571 valid = !ports.contains (port);
1572 if (!valid)
1573 {
1574 warningText = tr ("Duplicate port number is selected ");
1575 pageTitle += ": " + tbwParallelPorts->tabLabel (tab);
1576 break;
1577 }
1578 ports << port;
1579 }
1580 /* check the port path emptiness & unicity */
1581 if (page->mParallelPortBox->isChecked())
1582 {
1583 QString path = page->mPortPathLine->text();
1584 valid = !path.isEmpty() && !paths.contains (path);
1585 if (!valid)
1586 {
1587 warningText = path.isEmpty() ?
1588 tr ("Port path is not specified ") :
1589 tr ("Duplicate port path is entered ");
1590 pageTitle += ": " + tbwParallelPorts->tabLabel (tab);
1591 break;
1592 }
1593 paths << path;
1594 }
1595 }
1596 }
1597
1598 if (!valid)
1599 setWarning (tr ("%1 on the <b>%2</b> page.")
1600 .arg (warningText, pageTitle));
1601
1602 wval->setOtherValid (valid);
1603}
1604
1605
1606void VBoxVMSettingsDlg::getFromMachine (const CMachine &machine)
1607{
1608 cmachine = machine;
1609
1610 setCaption (machine.GetName() + tr (" - Settings"));
1611
1612 CVirtualBox vbox = vboxGlobal().virtualBox();
1613 CBIOSSettings biosSettings = cmachine.GetBIOSSettings();
1614
1615 /* name */
1616 leName->setText (machine.GetName());
1617
1618 /* OS type */
1619 QString typeId = machine.GetOSTypeId();
1620 cbOS->setCurrentItem (vboxGlobal().vmGuestOSTypeIndex (typeId));
1621 cbOS_activated (cbOS->currentItem());
1622
1623 /* RAM size */
1624 slRAM->setValue (machine.GetMemorySize());
1625
1626 /* VRAM size */
1627 slVRAM->setValue (machine.GetVRAMSize());
1628
1629 /* Boot-order */
1630 tblBootOrder->getFromMachine (machine);
1631
1632 /* ACPI */
1633 chbEnableACPI->setChecked (biosSettings.GetACPIEnabled());
1634
1635 /* IO APIC */
1636 chbEnableIOAPIC->setChecked (biosSettings.GetIOAPICEnabled());
1637
1638 /* VT-x/AMD-V */
1639 machine.GetHWVirtExEnabled() == CEnums::False ? chbVTX->setChecked (false) :
1640 machine.GetHWVirtExEnabled() == CEnums::True ? chbVTX->setChecked (true) :
1641 chbVTX->setNoChange();
1642
1643 /* Saved state folder */
1644 leSnapshotFolder->setText (machine.GetSnapshotFolder());
1645
1646 /* Description */
1647 teDescription->setText (machine.GetDescription());
1648
1649 /* Shared clipboard mode */
1650 cbSharedClipboard->setCurrentItem (machine.GetClipboardMode());
1651
1652 /* IDE controller type */
1653 cbIdeController->setCurrentText (vboxGlobal().toString (biosSettings.GetIDEControllerType()));
1654
1655 /* other features */
1656 QString saveRtimeImages = cmachine.GetExtraData (VBoxDefs::GUI_SaveMountedAtRuntime);
1657 chbRememberMedia->setChecked (saveRtimeImages != "no");
1658
1659 /* hard disk images */
1660 {
1661 struct
1662 {
1663 CEnums::DiskControllerType ctl;
1664 LONG dev;
1665 struct {
1666 QGroupBox *grb;
1667 QComboBox *cbb;
1668 QLabel *tx;
1669 QUuid *uuid;
1670 } data;
1671 }
1672 diskSet[] =
1673 {
1674 { CEnums::IDE0Controller, 0, {grbHDA, cbHDA, txHDA, &uuidHDA} },
1675 { CEnums::IDE0Controller, 1, {grbHDB, cbHDB, txHDB, &uuidHDB} },
1676 { CEnums::IDE1Controller, 1, {grbHDD, cbHDD, txHDD, &uuidHDD} },
1677 };
1678
1679 grbHDA->setChecked (false);
1680 grbHDB->setChecked (false);
1681 grbHDD->setChecked (false);
1682
1683 CHardDiskAttachmentEnumerator en =
1684 machine.GetHardDiskAttachments().Enumerate();
1685 while (en.HasMore())
1686 {
1687 CHardDiskAttachment hda = en.GetNext();
1688 for (uint i = 0; i < SIZEOF_ARRAY (diskSet); i++)
1689 {
1690 if (diskSet [i].ctl == hda.GetController() &&
1691 diskSet [i].dev == hda.GetDeviceNumber())
1692 {
1693 CHardDisk hd = hda.GetHardDisk();
1694 CHardDisk root = hd.GetRoot();
1695 QString src = root.GetLocation();
1696 if (hd.GetStorageType() == CEnums::VirtualDiskImage)
1697 {
1698 QFileInfo fi (src);
1699 src = fi.fileName() + " (" +
1700 QDir::convertSeparators (fi.dirPath (true)) + ")";
1701 }
1702 diskSet [i].data.grb->setChecked (true);
1703 diskSet [i].data.tx->setText (vboxGlobal().details (hd));
1704 *(diskSet [i].data.uuid) = QUuid (root.GetId());
1705 }
1706 }
1707 }
1708 }
1709
1710 /* floppy image */
1711 {
1712 /* read out the host floppy drive list and prepare the combobox */
1713 CHostFloppyDriveCollection coll =
1714 vboxGlobal().virtualBox().GetHost().GetFloppyDrives();
1715 hostFloppies.resize (coll.GetCount());
1716 cbHostFloppy->clear();
1717 int id = 0;
1718 CHostFloppyDriveEnumerator en = coll.Enumerate();
1719 while (en.HasMore())
1720 {
1721 CHostFloppyDrive hostFloppy = en.GetNext();
1722 /** @todo set icon? */
1723 QString name = hostFloppy.GetName();
1724 QString description = hostFloppy.GetDescription();
1725 QString fullName = description.isEmpty() ?
1726 name :
1727 QString ("%1 (%2)").arg (description, name);
1728 cbHostFloppy->insertItem (fullName, id);
1729 hostFloppies [id] = hostFloppy;
1730 ++ id;
1731 }
1732
1733 CFloppyDrive floppy = machine.GetFloppyDrive();
1734 switch (floppy.GetState())
1735 {
1736 case CEnums::HostDriveCaptured:
1737 {
1738 CHostFloppyDrive drv = floppy.GetHostDrive();
1739 QString name = drv.GetName();
1740 QString description = drv.GetDescription();
1741 QString fullName = description.isEmpty() ?
1742 name :
1743 QString ("%1 (%2)").arg (description, name);
1744 if (coll.FindByName (name).isNull())
1745 {
1746 /*
1747 * if the floppy drive is not currently available,
1748 * add it to the end of the list with a special mark
1749 */
1750 cbHostFloppy->insertItem ("* " + fullName);
1751 cbHostFloppy->setCurrentItem (cbHostFloppy->count() - 1);
1752 }
1753 else
1754 {
1755 /* this will select the correct item from the prepared list */
1756 cbHostFloppy->setCurrentText (fullName);
1757 }
1758 rbHostFloppy->setChecked (true);
1759 break;
1760 }
1761 case CEnums::ImageMounted:
1762 {
1763 CFloppyImage img = floppy.GetImage();
1764 QString src = img.GetFilePath();
1765 AssertMsg (!src.isNull(), ("Image file must not be null"));
1766 QFileInfo fi (src);
1767 rbISOFloppy->setChecked (true);
1768 uuidISOFloppy = QUuid (img.GetId());
1769 break;
1770 }
1771 case CEnums::NotMounted:
1772 {
1773 bgFloppy->setChecked(false);
1774 break;
1775 }
1776 default:
1777 AssertMsgFailed (("invalid floppy state: %d\n", floppy.GetState()));
1778 }
1779 }
1780
1781 /* CD/DVD-ROM image */
1782 {
1783 /* read out the host DVD drive list and prepare the combobox */
1784 CHostDVDDriveCollection coll =
1785 vboxGlobal().virtualBox().GetHost().GetDVDDrives();
1786 hostDVDs.resize (coll.GetCount());
1787 cbHostDVD->clear();
1788 int id = 0;
1789 CHostDVDDriveEnumerator en = coll.Enumerate();
1790 while (en.HasMore())
1791 {
1792 CHostDVDDrive hostDVD = en.GetNext();
1793 /// @todo (r=dmik) set icon?
1794 QString name = hostDVD.GetName();
1795 QString description = hostDVD.GetDescription();
1796 QString fullName = description.isEmpty() ?
1797 name :
1798 QString ("%1 (%2)").arg (description, name);
1799 cbHostDVD->insertItem (fullName, id);
1800 hostDVDs [id] = hostDVD;
1801 ++ id;
1802 }
1803
1804 CDVDDrive dvd = machine.GetDVDDrive();
1805 switch (dvd.GetState())
1806 {
1807 case CEnums::HostDriveCaptured:
1808 {
1809 CHostDVDDrive drv = dvd.GetHostDrive();
1810 QString name = drv.GetName();
1811 QString description = drv.GetDescription();
1812 QString fullName = description.isEmpty() ?
1813 name :
1814 QString ("%1 (%2)").arg (description, name);
1815 if (coll.FindByName (name).isNull())
1816 {
1817 /*
1818 * if the DVD drive is not currently available,
1819 * add it to the end of the list with a special mark
1820 */
1821 cbHostDVD->insertItem ("* " + fullName);
1822 cbHostDVD->setCurrentItem (cbHostDVD->count() - 1);
1823 }
1824 else
1825 {
1826 /* this will select the correct item from the prepared list */
1827 cbHostDVD->setCurrentText (fullName);
1828 }
1829 rbHostDVD->setChecked (true);
1830 cbPassthrough->setChecked (dvd.GetPassthrough());
1831 break;
1832 }
1833 case CEnums::ImageMounted:
1834 {
1835 CDVDImage img = dvd.GetImage();
1836 QString src = img.GetFilePath();
1837 AssertMsg (!src.isNull(), ("Image file must not be null"));
1838 QFileInfo fi (src);
1839 rbISODVD->setChecked (true);
1840 uuidISODVD = QUuid (img.GetId());
1841 break;
1842 }
1843 case CEnums::NotMounted:
1844 {
1845 bgDVD->setChecked(false);
1846 break;
1847 }
1848 default:
1849 AssertMsgFailed (("invalid DVD state: %d\n", dvd.GetState()));
1850 }
1851 }
1852
1853 /* audio */
1854 {
1855 CAudioAdapter audio = machine.GetAudioAdapter();
1856 grbAudio->setChecked (audio.GetEnabled());
1857 cbAudioDriver->setCurrentText (vboxGlobal().toString (audio.GetAudioDriver()));
1858 }
1859
1860 /* network */
1861 {
1862 ulong count = vbox.GetSystemProperties().GetNetworkAdapterCount();
1863 for (ulong slot = 0; slot < count; ++ slot)
1864 {
1865 CNetworkAdapter adapter = machine.GetNetworkAdapter (slot);
1866 addNetworkAdapter (adapter);
1867 }
1868 }
1869
1870 /* serial ports */
1871 {
1872 ulong count = vbox.GetSystemProperties().GetSerialPortCount();
1873 for (ulong slot = 0; slot < count; ++ slot)
1874 {
1875 CSerialPort port = machine.GetSerialPort (slot);
1876 addSerialPort (port);
1877 }
1878 }
1879
1880 /* parallel ports */
1881 {
1882 ulong count = vbox.GetSystemProperties().GetParallelPortCount();
1883 for (ulong slot = 0; slot < count; ++ slot)
1884 {
1885 CParallelPort port = machine.GetParallelPort (slot);
1886 addParallelPort (port);
1887 }
1888 }
1889
1890 /* USB */
1891 {
1892 CUSBController ctl = machine.GetUSBController();
1893
1894 if (ctl.isNull())
1895 {
1896 /* disable the USB controller category if the USB controller is
1897 * not available (i.e. in VirtualBox OSE) */
1898
1899 QListViewItem *usbItem = listView->findItem ("#usb", listView_Link);
1900 Assert (usbItem);
1901 if (usbItem)
1902 usbItem->setVisible (false);
1903
1904 /* disable validators if any */
1905 pageUSB->setEnabled (false);
1906
1907 /* Show an error message (if there is any).
1908 * Note that we don't use the generic cannotLoadMachineSettings()
1909 * call here because we want this message to be suppressable. */
1910 vboxProblem().cannotAccessUSB (machine);
1911 }
1912 else
1913 {
1914 cbEnableUSBController->setChecked (ctl.GetEnabled());
1915 cbEnableUSBEhci->setChecked (ctl.GetEnabledEhci());
1916 usbAdapterToggled (cbEnableUSBController->isChecked());
1917
1918 CUSBDeviceFilterEnumerator en = ctl.GetDeviceFilters().Enumerate();
1919 while (en.HasMore())
1920 addUSBFilter (en.GetNext(), false /* isNew */);
1921
1922 lvUSBFilters->setCurrentItem (lvUSBFilters->firstChild());
1923 /* silly Qt -- doesn't emit currentChanged after adding the
1924 * first item to an empty list */
1925 lvUSBFilters_currentChanged (lvUSBFilters->firstChild());
1926 }
1927 }
1928
1929 /* vrdp */
1930 {
1931 CVRDPServer vrdp = machine.GetVRDPServer();
1932
1933 if (vrdp.isNull())
1934 {
1935 /* disable the VRDP category if VRDP is
1936 * not available (i.e. in VirtualBox OSE) */
1937
1938 QListViewItem *vrdpItem = listView->findItem ("#vrdp", listView_Link);
1939 Assert (vrdpItem);
1940 if (vrdpItem)
1941 vrdpItem->setVisible (false);
1942
1943 /* disable validators if any */
1944 pageVRDP->setEnabled (false);
1945
1946 /* if machine has something to say, show the message */
1947 vboxProblem().cannotLoadMachineSettings (machine, false /* strict */);
1948 }
1949 else
1950 {
1951 grbVRDP->setChecked (vrdp.GetEnabled());
1952 leVRDPPort->setText (QString::number (vrdp.GetPort()));
1953 cbVRDPAuthType->setCurrentText (vboxGlobal().toString (vrdp.GetAuthType()));
1954 leVRDPTimeout->setText (QString::number (vrdp.GetAuthTimeout()));
1955 }
1956 }
1957
1958 /* shared folders */
1959 {
1960 mSharedFolders->getFromMachine (machine);
1961 }
1962
1963 /* request for media shortcuts update */
1964 cbHDA->setBelongsTo (machine.GetId());
1965 cbHDB->setBelongsTo (machine.GetId());
1966 cbHDD->setBelongsTo (machine.GetId());
1967 updateShortcuts();
1968
1969 /* revalidate pages with custom validation */
1970 wvalHDD->revalidate();
1971 wvalDVD->revalidate();
1972 wvalFloppy->revalidate();
1973 wvalVRDP->revalidate();
1974
1975 /* finally set the reset First Run Wizard flag to "false" to make sure
1976 * user will see this dialog if he hasn't change the boot-order
1977 * and/or mounted images configuration */
1978 mResetFirstRunFlag = false;
1979}
1980
1981
1982COMResult VBoxVMSettingsDlg::putBackToMachine()
1983{
1984 CVirtualBox vbox = vboxGlobal().virtualBox();
1985 CBIOSSettings biosSettings = cmachine.GetBIOSSettings();
1986
1987 /* name */
1988 cmachine.SetName (leName->text());
1989
1990 /* OS type */
1991 CGuestOSType type = vboxGlobal().vmGuestOSType (cbOS->currentItem());
1992 AssertMsg (!type.isNull(), ("vmGuestOSType() must return non-null type"));
1993 cmachine.SetOSTypeId (type.GetId());
1994
1995 /* RAM size */
1996 cmachine.SetMemorySize (slRAM->value());
1997
1998 /* VRAM size */
1999 cmachine.SetVRAMSize (slVRAM->value());
2000
2001 /* boot order */
2002 tblBootOrder->putBackToMachine (cmachine);
2003
2004 /* ACPI */
2005 biosSettings.SetACPIEnabled (chbEnableACPI->isChecked());
2006
2007 /* IO APIC */
2008 biosSettings.SetIOAPICEnabled (chbEnableIOAPIC->isChecked());
2009
2010 /* VT-x/AMD-V */
2011 cmachine.SetHWVirtExEnabled (
2012 chbVTX->state() == QButton::Off ? CEnums::False :
2013 chbVTX->state() == QButton::On ? CEnums::True : CEnums::Default);
2014
2015 /* Saved state folder */
2016 if (leSnapshotFolder->isModified())
2017 {
2018 cmachine.SetSnapshotFolder (leSnapshotFolder->text());
2019 if (!cmachine.isOk())
2020 vboxProblem()
2021 .cannotSetSnapshotFolder (cmachine,
2022 QDir::convertSeparators (leSnapshotFolder->text()));
2023 }
2024
2025 /* Description */
2026 cmachine.SetDescription (teDescription->text());
2027
2028 /* Shared clipboard mode */
2029 cmachine.SetClipboardMode ((CEnums::ClipboardMode)cbSharedClipboard->currentItem());
2030
2031 /* IDE controller type */
2032 biosSettings.SetIDEControllerType (vboxGlobal().toIDEControllerType (cbIdeController->currentText()));
2033
2034 /* other features */
2035 cmachine.SetExtraData (VBoxDefs::GUI_SaveMountedAtRuntime,
2036 chbRememberMedia->isChecked() ? "yes" : "no");
2037
2038 /* hard disk images */
2039 {
2040 struct
2041 {
2042 CEnums::DiskControllerType ctl;
2043 LONG dev;
2044 struct {
2045 QGroupBox *grb;
2046 QUuid *uuid;
2047 } data;
2048 }
2049 diskSet[] =
2050 {
2051 { CEnums::IDE0Controller, 0, {grbHDA, &uuidHDA} },
2052 { CEnums::IDE0Controller, 1, {grbHDB, &uuidHDB} },
2053 { CEnums::IDE1Controller, 1, {grbHDD, &uuidHDD} }
2054 };
2055
2056 /*
2057 * first, detach all disks (to ensure we can reattach them to different
2058 * controllers / devices, when appropriate)
2059 */
2060 CHardDiskAttachmentEnumerator en =
2061 cmachine.GetHardDiskAttachments().Enumerate();
2062 while (en.HasMore())
2063 {
2064 CHardDiskAttachment hda = en.GetNext();
2065 for (uint i = 0; i < SIZEOF_ARRAY (diskSet); i++)
2066 {
2067 if (diskSet [i].ctl == hda.GetController() &&
2068 diskSet [i].dev == hda.GetDeviceNumber())
2069 {
2070 cmachine.DetachHardDisk (diskSet [i].ctl, diskSet [i].dev);
2071 if (!cmachine.isOk())
2072 vboxProblem().cannotDetachHardDisk (
2073 this, cmachine, diskSet [i].ctl, diskSet [i].dev);
2074 }
2075 }
2076 }
2077
2078 /* now, attach new disks */
2079 for (uint i = 0; i < SIZEOF_ARRAY (diskSet); i++)
2080 {
2081 QUuid *newId = diskSet [i].data.uuid;
2082 if (diskSet [i].data.grb->isChecked() && !(*newId).isNull())
2083 {
2084 cmachine.AttachHardDisk (*newId, diskSet [i].ctl, diskSet [i].dev);
2085 if (!cmachine.isOk())
2086 vboxProblem().cannotAttachHardDisk (
2087 this, cmachine, *newId, diskSet [i].ctl, diskSet [i].dev);
2088 }
2089 }
2090 }
2091
2092 /* floppy image */
2093 {
2094 CFloppyDrive floppy = cmachine.GetFloppyDrive();
2095 if (!bgFloppy->isChecked())
2096 {
2097 floppy.Unmount();
2098 }
2099 else if (rbHostFloppy->isChecked())
2100 {
2101 int id = cbHostFloppy->currentItem();
2102 Assert (id >= 0);
2103 if (id < (int) hostFloppies.count())
2104 floppy.CaptureHostDrive (hostFloppies [id]);
2105 /*
2106 * otherwise the selected drive is not yet available, leave it
2107 * as is
2108 */
2109 }
2110 else if (rbISOFloppy->isChecked())
2111 {
2112 Assert (!uuidISOFloppy.isNull());
2113 floppy.MountImage (uuidISOFloppy);
2114 }
2115 }
2116
2117 /* CD/DVD-ROM image */
2118 {
2119 CDVDDrive dvd = cmachine.GetDVDDrive();
2120 if (!bgDVD->isChecked())
2121 {
2122 dvd.SetPassthrough (false);
2123 dvd.Unmount();
2124 }
2125 else if (rbHostDVD->isChecked())
2126 {
2127 dvd.SetPassthrough (cbPassthrough->isChecked());
2128 int id = cbHostDVD->currentItem();
2129 Assert (id >= 0);
2130 if (id < (int) hostDVDs.count())
2131 dvd.CaptureHostDrive (hostDVDs [id]);
2132 /*
2133 * otherwise the selected drive is not yet available, leave it
2134 * as is
2135 */
2136 }
2137 else if (rbISODVD->isChecked())
2138 {
2139 dvd.SetPassthrough (false);
2140 Assert (!uuidISODVD.isNull());
2141 dvd.MountImage (uuidISODVD);
2142 }
2143 }
2144
2145 /* Clear the "GUI_FirstRun" extra data key in case if the boot order
2146 * and/or disk configuration were changed */
2147 if (mResetFirstRunFlag)
2148 cmachine.SetExtraData (VBoxDefs::GUI_FirstRun, QString::null);
2149
2150 /* audio */
2151 {
2152 CAudioAdapter audio = cmachine.GetAudioAdapter();
2153 audio.SetAudioDriver (vboxGlobal().toAudioDriverType (cbAudioDriver->currentText()));
2154 audio.SetEnabled (grbAudio->isChecked());
2155 AssertWrapperOk (audio);
2156 }
2157
2158 /* network */
2159 {
2160 for (int index = 0; index < tbwNetwork->count(); index++)
2161 {
2162 VBoxVMNetworkSettings *page =
2163 (VBoxVMNetworkSettings *) tbwNetwork->page (index);
2164 Assert (page);
2165 page->putBackToAdapter();
2166 }
2167 }
2168
2169 /* serial ports */
2170 {
2171 for (int index = 0; index < tbwSerialPorts->count(); index++)
2172 {
2173 VBoxVMSerialPortSettings *page =
2174 (VBoxVMSerialPortSettings *) tbwSerialPorts->page (index);
2175 Assert (page);
2176 page->putBackToPort();
2177 }
2178 }
2179
2180 /* parallel ports */
2181 {
2182 for (int index = 0; index < tbwParallelPorts->count(); index++)
2183 {
2184 VBoxVMParallelPortSettings *page =
2185 (VBoxVMParallelPortSettings *) tbwParallelPorts->page (index);
2186 Assert (page);
2187 page->putBackToPort();
2188 }
2189 }
2190
2191 /* usb */
2192 {
2193 CUSBController ctl = cmachine.GetUSBController();
2194
2195 if (!ctl.isNull())
2196 {
2197 /* the USB controller may be unavailable (i.e. in VirtualBox OSE) */
2198
2199 ctl.SetEnabled (cbEnableUSBController->isChecked());
2200 ctl.SetEnabledEhci (cbEnableUSBEhci->isChecked());
2201
2202 /*
2203 * first, remove all old filters (only if the list is changed,
2204 * not only individual properties of filters)
2205 */
2206 if (mUSBFilterListModified)
2207 for (ulong count = ctl.GetDeviceFilters().GetCount(); count; -- count)
2208 ctl.RemoveDeviceFilter (0);
2209
2210 /* then add all new filters */
2211 for (QListViewItem *item = lvUSBFilters->firstChild(); item;
2212 item = item->nextSibling())
2213 {
2214 USBListItem *uli = static_cast <USBListItem *> (item);
2215 VBoxUSBFilterSettings *settings =
2216 static_cast <VBoxUSBFilterSettings *>
2217 (wstUSBFilters->widget (uli->mId));
2218 Assert (settings);
2219
2220 COMResult res = settings->putBackToFilter();
2221 if (!res.isOk())
2222 return res;
2223
2224 CUSBDeviceFilter filter = settings->filter();
2225 filter.SetActive (uli->isOn());
2226
2227 if (mUSBFilterListModified)
2228 ctl.InsertDeviceFilter (~0, filter);
2229 }
2230 }
2231
2232 mUSBFilterListModified = false;
2233 }
2234
2235 /* vrdp */
2236 {
2237 CVRDPServer vrdp = cmachine.GetVRDPServer();
2238
2239 if (!vrdp.isNull())
2240 {
2241 /* VRDP may be unavailable (i.e. in VirtualBox OSE) */
2242 vrdp.SetEnabled (grbVRDP->isChecked());
2243 vrdp.SetPort (leVRDPPort->text().toULong());
2244 vrdp.SetAuthType (vboxGlobal().toVRDPAuthType (cbVRDPAuthType->currentText()));
2245 vrdp.SetAuthTimeout (leVRDPTimeout->text().toULong());
2246 }
2247 }
2248
2249 /* shared folders */
2250 {
2251 mSharedFolders->putBackToMachine();
2252 }
2253
2254 return COMResult();
2255}
2256
2257
2258void VBoxVMSettingsDlg::showImageManagerHDA() { showVDImageManager (&uuidHDA, cbHDA); }
2259void VBoxVMSettingsDlg::showImageManagerHDB() { showVDImageManager (&uuidHDB, cbHDB); }
2260void VBoxVMSettingsDlg::showImageManagerHDD() { showVDImageManager (&uuidHDD, cbHDD); }
2261void VBoxVMSettingsDlg::showImageManagerISODVD() { showVDImageManager (&uuidISODVD, cbISODVD); }
2262void VBoxVMSettingsDlg::showImageManagerISOFloppy() { showVDImageManager(&uuidISOFloppy, cbISOFloppy); }
2263
2264void VBoxVMSettingsDlg::showVDImageManager (QUuid *id, VBoxMediaComboBox *cbb, QLabel*)
2265{
2266 VBoxDefs::DiskType type = VBoxDefs::InvalidType;
2267 if (cbb == cbISODVD)
2268 type = VBoxDefs::CD;
2269 else if (cbb == cbISOFloppy)
2270 type = VBoxDefs::FD;
2271 else
2272 type = VBoxDefs::HD;
2273
2274 VBoxDiskImageManagerDlg dlg (this, "VBoxDiskImageManagerDlg",
2275 WType_Dialog | WShowModal);
2276 QUuid machineId = cmachine.GetId();
2277 QUuid hdId = type == VBoxDefs::HD ? cbb->getId() : QUuid();
2278 QUuid cdId = type == VBoxDefs::CD ? cbb->getId() : QUuid();
2279 QUuid fdId = type == VBoxDefs::FD ? cbb->getId() : QUuid();
2280 dlg.setup (type, true, &machineId, true /* aRefresh */, cmachine,
2281 hdId, cdId, fdId);
2282 if (dlg.exec() == VBoxDiskImageManagerDlg::Accepted)
2283 {
2284 *id = dlg.getSelectedUuid();
2285 resetFirstRunFlag();
2286 }
2287 else
2288 {
2289 *id = cbb->getId();
2290 }
2291
2292 cbb->setCurrentItem (*id);
2293 cbb->setFocus();
2294
2295 /* revalidate pages with custom validation */
2296 wvalHDD->revalidate();
2297 wvalDVD->revalidate();
2298 wvalFloppy->revalidate();
2299}
2300
2301void VBoxVMSettingsDlg::addNetworkAdapter (const CNetworkAdapter &aAdapter)
2302{
2303 VBoxVMNetworkSettings *page = new VBoxVMNetworkSettings();
2304 page->loadList (mInterfaceList, mNoInterfaces);
2305 page->getFromAdapter (aAdapter);
2306 QString pageTitle = QString (tr ("Adapter %1", "network"))
2307 .arg (aAdapter.GetSlot());
2308 tbwNetwork->addTab (page, pageTitle);
2309
2310 /* fix the tab order so that main dialog's buttons are always the last */
2311 setTabOrder (page->leTAPTerminate, buttonHelp);
2312 setTabOrder (buttonHelp, buttonOk);
2313 setTabOrder (buttonOk, buttonCancel);
2314
2315 /* setup validation */
2316 QIWidgetValidator *wval =
2317 new QIWidgetValidator (QString ("%1: %2")
2318 .arg (pagePath (pageNetwork), pageTitle),
2319 pageNetwork, this);
2320 connect (page->grbEnabled, SIGNAL (toggled (bool)), wval, SLOT (revalidate()));
2321 connect (page->cbNetworkAttachment, SIGNAL (activated (const QString &)),
2322 wval, SLOT (revalidate()));
2323 connect (wval, SIGNAL (validityChanged (const QIWidgetValidator *)),
2324 this, SLOT (enableOk (const QIWidgetValidator *)));
2325 connect (wval, SIGNAL (isValidRequested (QIWidgetValidator *)),
2326 this, SLOT (revalidate( QIWidgetValidator *)));
2327
2328 page->setValidator (wval);
2329 page->revalidate();
2330
2331#ifdef Q_WS_WIN
2332
2333 /* fix focus order (make sure the Host Interface list UI goes after the
2334 * last network adapter UI item) */
2335
2336 setTabOrder (page->chbCableConnected, lbHostInterface);
2337 setTabOrder (lbHostInterface, pbHostAdd);
2338 setTabOrder (pbHostAdd, pbHostRemove);
2339
2340#endif
2341}
2342
2343void VBoxVMSettingsDlg::addSerialPort (const CSerialPort &aPort)
2344{
2345 VBoxVMSerialPortSettings *page = new VBoxVMSerialPortSettings();
2346 page->getFromPort (aPort);
2347 QString pageTitle = QString (tr ("Port %1", "serial ports"))
2348 .arg (aPort.GetSlot());
2349 tbwSerialPorts->addTab (page, pageTitle);
2350
2351 /* fix the tab order so that main dialog's buttons are always the last */
2352 setTabOrder (page->mPortPathLine, buttonHelp);
2353 setTabOrder (buttonHelp, buttonOk);
2354 setTabOrder (buttonOk, buttonCancel);
2355
2356 /* setup validation */
2357 QIWidgetValidator *wval =
2358 new QIWidgetValidator (QString ("%1: %2")
2359 .arg (pagePath (pageSerial), pageTitle),
2360 pageSerial, this);
2361 connect (page->mSerialPortBox, SIGNAL (toggled (bool)),
2362 wval, SLOT (revalidate()));
2363 connect (page->mIRQLine, SIGNAL (textChanged (const QString &)),
2364 wval, SLOT (revalidate()));
2365 connect (page->mIOPortLine, SIGNAL (textChanged (const QString &)),
2366 wval, SLOT (revalidate()));
2367 connect (page->mHostModeCombo, SIGNAL (activated (const QString &)),
2368 wval, SLOT (revalidate()));
2369 connect (wval, SIGNAL (validityChanged (const QIWidgetValidator *)),
2370 this, SLOT (enableOk (const QIWidgetValidator *)));
2371 connect (wval, SIGNAL (isValidRequested (QIWidgetValidator *)),
2372 this, SLOT (revalidate (QIWidgetValidator *)));
2373
2374 wval->revalidate();
2375}
2376
2377void VBoxVMSettingsDlg::addParallelPort (const CParallelPort &aPort)
2378{
2379 VBoxVMParallelPortSettings *page = new VBoxVMParallelPortSettings();
2380 page->getFromPort (aPort);
2381 QString pageTitle = QString (tr ("Port %1", "parallel ports"))
2382 .arg (aPort.GetSlot());
2383 tbwParallelPorts->addTab (page, pageTitle);
2384
2385 /* fix the tab order so that main dialog's buttons are always the last */
2386 setTabOrder (page->mPortPathLine, buttonHelp);
2387 setTabOrder (buttonHelp, buttonOk);
2388 setTabOrder (buttonOk, buttonCancel);
2389
2390 /* setup validation */
2391 QIWidgetValidator *wval =
2392 new QIWidgetValidator (QString ("%1: %2")
2393 .arg (pagePath (pageParallel), pageTitle),
2394 pageParallel, this);
2395 connect (page->mParallelPortBox, SIGNAL (toggled (bool)),
2396 wval, SLOT (revalidate()));
2397 connect (page->mIRQLine, SIGNAL (textChanged (const QString &)),
2398 wval, SLOT (revalidate()));
2399 connect (page->mIOPortLine, SIGNAL (textChanged (const QString &)),
2400 wval, SLOT (revalidate()));
2401 connect (wval, SIGNAL (validityChanged (const QIWidgetValidator *)),
2402 this, SLOT (enableOk (const QIWidgetValidator *)));
2403 connect (wval, SIGNAL (isValidRequested (QIWidgetValidator *)),
2404 this, SLOT (revalidate (QIWidgetValidator *)));
2405
2406 wval->revalidate();
2407}
2408
2409void VBoxVMSettingsDlg::slRAM_valueChanged( int val )
2410{
2411 leRAM->setText( QString().setNum( val ) );
2412}
2413
2414void VBoxVMSettingsDlg::leRAM_textChanged( const QString &text )
2415{
2416 slRAM->setValue( text.toInt() );
2417}
2418
2419void VBoxVMSettingsDlg::slVRAM_valueChanged( int val )
2420{
2421 leVRAM->setText( QString().setNum( val ) );
2422}
2423
2424void VBoxVMSettingsDlg::leVRAM_textChanged( const QString &text )
2425{
2426 slVRAM->setValue( text.toInt() );
2427}
2428
2429void VBoxVMSettingsDlg::cbOS_activated (int item)
2430{
2431 Q_UNUSED (item);
2432/// @todo (dmik) remove?
2433// CGuestOSType type = vboxGlobal().vmGuestOSType (item);
2434// txRAMBest->setText (tr ("<qt>Best&nbsp;%1&nbsp;MB<qt>")
2435// .arg (type.GetRecommendedRAM()));
2436// txVRAMBest->setText (tr ("<qt>Best&nbsp;%1&nbsp;MB</qt>")
2437// .arg (type.GetRecommendedVRAM()));
2438 txRAMBest->setText (QString::null);
2439 txVRAMBest->setText (QString::null);
2440}
2441
2442void VBoxVMSettingsDlg::tbResetSavedStateFolder_clicked()
2443{
2444 /*
2445 * do this instead of le->setText (QString::null) to cause
2446 * isModified() return true
2447 */
2448 leSnapshotFolder->selectAll();
2449 leSnapshotFolder->del();
2450}
2451
2452void VBoxVMSettingsDlg::tbSelectSavedStateFolder_clicked()
2453{
2454 QString settingsFolder = VBoxGlobal::getFirstExistingDir (leSnapshotFolder->text());
2455 if (settingsFolder.isNull())
2456 settingsFolder = QFileInfo (cmachine.GetSettingsFilePath()).dirPath (true);
2457
2458 QString folder = vboxGlobal().getExistingDirectory (settingsFolder, this);
2459 if (folder.isNull())
2460 return;
2461
2462 folder = QDir::convertSeparators (folder);
2463 /* remove trailing slash if any */
2464 folder.remove (QRegExp ("[\\\\/]$"));
2465
2466 /*
2467 * do this instead of le->setText (folder) to cause
2468 * isModified() return true
2469 */
2470 leSnapshotFolder->selectAll();
2471 leSnapshotFolder->insert (folder);
2472}
2473
2474// USB Filter stuff
2475////////////////////////////////////////////////////////////////////////////////
2476
2477void VBoxVMSettingsDlg::usbAdapterToggled (bool aOn)
2478{
2479 if (!aOn)
2480 cbEnableUSBEhci->setChecked (aOn);
2481 grbUSBFilters->setEnabled (aOn);
2482}
2483
2484void VBoxVMSettingsDlg::addUSBFilter (const CUSBDeviceFilter &aFilter, bool isNew)
2485{
2486 QListViewItem *currentItem = isNew
2487 ? lvUSBFilters->currentItem()
2488 : lvUSBFilters->lastItem();
2489
2490 VBoxUSBFilterSettings *settings = new VBoxUSBFilterSettings (wstUSBFilters);
2491 settings->setup (VBoxUSBFilterSettings::MachineType);
2492 settings->getFromFilter (aFilter);
2493
2494 USBListItem *item = new USBListItem (lvUSBFilters, currentItem);
2495 item->setOn (aFilter.GetActive());
2496 item->setText (lvUSBFilters_Name, aFilter.GetName());
2497
2498 item->mId = wstUSBFilters->addWidget (settings);
2499
2500 /* fix the tab order so that main dialog's buttons are always the last */
2501 setTabOrder (settings->focusProxy(), buttonHelp);
2502 setTabOrder (buttonHelp, buttonOk);
2503 setTabOrder (buttonOk, buttonCancel);
2504
2505 if (isNew)
2506 {
2507 lvUSBFilters->setSelected (item, true);
2508 lvUSBFilters_currentChanged (item);
2509 settings->leUSBFilterName->setFocus();
2510 }
2511
2512 connect (settings->leUSBFilterName, SIGNAL (textChanged (const QString &)),
2513 this, SLOT (lvUSBFilters_setCurrentText (const QString &)));
2514
2515 /* setup validation */
2516
2517 QIWidgetValidator *wval =
2518 new QIWidgetValidator (pagePath (pageUSB), settings, settings);
2519 connect (wval, SIGNAL (validityChanged (const QIWidgetValidator *)),
2520 this, SLOT (enableOk (const QIWidgetValidator *)));
2521
2522 wval->revalidate();
2523}
2524
2525void VBoxVMSettingsDlg::lvUSBFilters_currentChanged (QListViewItem *item)
2526{
2527 if (item && lvUSBFilters->selectedItem() != item)
2528 lvUSBFilters->setSelected (item, true);
2529
2530 tbRemoveUSBFilter->setEnabled (!!item);
2531
2532 tbUSBFilterUp->setEnabled (!!item && item->itemAbove());
2533 tbUSBFilterDown->setEnabled (!!item && item->itemBelow());
2534
2535 if (item)
2536 {
2537 USBListItem *uli = static_cast <USBListItem *> (item);
2538 wstUSBFilters->raiseWidget (uli->mId);
2539 }
2540 else
2541 {
2542 /* raise the disabled widget */
2543 wstUSBFilters->raiseWidget (0);
2544 }
2545}
2546
2547void VBoxVMSettingsDlg::lvUSBFilters_setCurrentText (const QString &aText)
2548{
2549 QListViewItem *item = lvUSBFilters->currentItem();
2550 Assert (item);
2551
2552 item->setText (lvUSBFilters_Name, aText);
2553}
2554
2555void VBoxVMSettingsDlg::tbAddUSBFilter_clicked()
2556{
2557 /* search for the max available filter index */
2558 int maxFilterIndex = 0;
2559 QString usbFilterName = tr ("New Filter %1", "usb");
2560 QRegExp regExp (QString ("^") + usbFilterName.arg ("([0-9]+)") + QString ("$"));
2561 QListViewItemIterator iterator (lvUSBFilters);
2562 while (*iterator)
2563 {
2564 QString filterName = (*iterator)->text (lvUSBFilters_Name);
2565 int pos = regExp.search (filterName);
2566 if (pos != -1)
2567 maxFilterIndex = regExp.cap (1).toInt() > maxFilterIndex ?
2568 regExp.cap (1).toInt() : maxFilterIndex;
2569 ++ iterator;
2570 }
2571
2572 /* creating new usb filter */
2573 CUSBDeviceFilter filter = cmachine.GetUSBController()
2574 .CreateDeviceFilter (usbFilterName.arg (maxFilterIndex + 1));
2575
2576 filter.SetActive (true);
2577 addUSBFilter (filter, true /* isNew */);
2578
2579 mUSBFilterListModified = true;
2580}
2581
2582void VBoxVMSettingsDlg::tbAddUSBFilterFrom_clicked()
2583{
2584 usbDevicesMenu->exec (QCursor::pos());
2585}
2586
2587void VBoxVMSettingsDlg::menuAddUSBFilterFrom_activated (int aIndex)
2588{
2589 CUSBDevice usb = usbDevicesMenu->getUSB (aIndex);
2590 /* if null then some other item but a USB device is selected */
2591 if (usb.isNull())
2592 return;
2593
2594 CUSBDeviceFilter filter = cmachine.GetUSBController()
2595 .CreateDeviceFilter (vboxGlobal().details (usb));
2596
2597 filter.SetVendorId (QString().sprintf ("%04hX", usb.GetVendorId()));
2598 filter.SetProductId (QString().sprintf ("%04hX", usb.GetProductId()));
2599 filter.SetRevision (QString().sprintf ("%04hX", usb.GetRevision()));
2600 /* The port property depends on the host computer rather than on the USB
2601 * device itself; for this reason only a few people will want to use it in
2602 * the filter since the same device plugged into a different socket will
2603 * not match the filter in this case. */
2604#if 0
2605 /// @todo set it anyway if Alt is currently pressed
2606 filter.SetPort (QString().sprintf ("%04hX", usb.GetPort()));
2607#endif
2608 filter.SetManufacturer (usb.GetManufacturer());
2609 filter.SetProduct (usb.GetProduct());
2610 filter.SetSerialNumber (usb.GetSerialNumber());
2611 filter.SetRemote (usb.GetRemote() ? "yes" : "no");
2612
2613 filter.SetActive (true);
2614 addUSBFilter (filter, true /* isNew */);
2615
2616 mUSBFilterListModified = true;
2617}
2618
2619void VBoxVMSettingsDlg::tbRemoveUSBFilter_clicked()
2620{
2621 QListViewItem *item = lvUSBFilters->currentItem();
2622 Assert (item);
2623
2624 USBListItem *uli = static_cast <USBListItem *> (item);
2625 QWidget *settings = wstUSBFilters->widget (uli->mId);
2626 Assert (settings);
2627 wstUSBFilters->removeWidget (settings);
2628 delete settings;
2629
2630 delete item;
2631
2632 lvUSBFilters->setSelected (lvUSBFilters->currentItem(), true);
2633 mUSBFilterListModified = true;
2634}
2635
2636void VBoxVMSettingsDlg::tbUSBFilterUp_clicked()
2637{
2638 QListViewItem *item = lvUSBFilters->currentItem();
2639 Assert (item);
2640
2641 QListViewItem *itemAbove = item->itemAbove();
2642 Assert (itemAbove);
2643 itemAbove = itemAbove->itemAbove();
2644
2645 if (!itemAbove)
2646 {
2647 /* overcome Qt stupidity */
2648 item->itemAbove()->moveItem (item);
2649 }
2650 else
2651 item->moveItem (itemAbove);
2652
2653 lvUSBFilters_currentChanged (item);
2654 mUSBFilterListModified = true;
2655}
2656
2657void VBoxVMSettingsDlg::tbUSBFilterDown_clicked()
2658{
2659 QListViewItem *item = lvUSBFilters->currentItem();
2660 Assert (item);
2661
2662 QListViewItem *itemBelow = item->itemBelow();
2663 Assert (itemBelow);
2664
2665 item->moveItem (itemBelow);
2666
2667 lvUSBFilters_currentChanged (item);
2668 mUSBFilterListModified = true;
2669}
2670
2671#include "VBoxVMSettingsDlg.ui.moc"
2672
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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