VirtualBox

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

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

Updated the host DVD code on Linux to use hal for device detection

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 73.9 KB
Line 
1/**
2 *
3 * VBox frontends: Qt GUI ("VirtualBox"):
4 * "VM settings" dialog UI include (Qt Designer)
5 */
6
7/*
8 * Copyright (C) 2006 InnoTek Systemberatung GmbH
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.215389.xyz. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License as published by the Free Software Foundation,
14 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
15 * distribution. VirtualBox OSE is distributed in the hope that it will
16 * be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * If you received this file as part of a commercial VirtualBox
19 * distribution, then only the terms of your commercial VirtualBox
20 * license agreement apply instead of the previous paragraph.
21 */
22
23/****************************************************************************
24** ui.h extension file, included from the uic-generated form implementation.
25**
26** If you wish to add, delete or rename functions or slots use
27** Qt Designer which will update this file, preserving your code. Create an
28** init() function in place of a constructor, and a destroy() function in
29** place of a destructor.
30*****************************************************************************/
31
32
33extern const char *GUI_FirstRun;
34
35
36/**
37 * Calculates a suitable page step size for the given max value.
38 * The returned size is so that there will be no more than 32 pages.
39 * The minimum returned page size is 4.
40 */
41static int calcPageStep (int aMax)
42{
43 /* reasonable max. number of page steps is 32 */
44 uint page = ((uint) aMax + 31) / 32;
45 /* make it a power of 2 */
46 uint p = page, p2 = 0x1;
47 while ((p >>= 1))
48 p2 <<= 1;
49 if (page != p2)
50 p2 <<= 1;
51 if (p2 < 4)
52 p2 = 4;
53 return (int) p2;
54}
55
56
57/**
58 * QListView class reimplementation to use as boot items table.
59 * It has one unsorted column without header with automated width
60 * resize management.
61 * Keymapping handlers for ctrl-up & ctrl-down are translated into
62 * boot-items up/down moving.
63 */
64class BootItemsTable : public QListView
65{
66 Q_OBJECT
67
68public:
69
70 BootItemsTable (QWidget *aParent, const char *aName)
71 : QListView (aParent, aName)
72 {
73 addColumn (QString::null);
74 header()->hide();
75 setSorting (-1);
76 setColumnWidthMode (0, Maximum);
77 setResizeMode (AllColumns);
78 QWhatsThis::add (this, tr ("Defines the boot device order. "
79 "Use checkboxes to the left to enable or disable "
80 "individual boot devices. Move items up and down to "
81 "change the device order."));
82 setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Preferred);
83 connect (this, SIGNAL (pressed (QListViewItem*)),
84 this, SLOT (processPressed (QListViewItem*)));
85 }
86
87 ~BootItemsTable() {}
88
89 void emitItemToggled() { emit itemToggled(); }
90
91signals:
92
93 void moveItemUp();
94 void moveItemDown();
95 void itemToggled();
96
97private slots:
98
99 void processPressed (QListViewItem *aItem)
100 {
101 if (!aItem)
102 setSelected (currentItem(), true);
103 }
104
105 void keyPressEvent (QKeyEvent *aEvent)
106 {
107 if (aEvent->state() == Qt::ControlButton)
108 {
109 switch (aEvent->key())
110 {
111 case Qt::Key_Up:
112 emit moveItemUp();
113 return;
114 case Qt::Key_Down:
115 emit moveItemDown();
116 return;
117 default:
118 break;
119 }
120 }
121 QListView::keyPressEvent (aEvent);
122 }
123};
124
125
126/**
127 * QWidget class reimplementation to use as boot items widget.
128 * It contains BootItemsTable and two tool-buttons for moving
129 * boot-items up/down.
130 * This widget handles saving/loading CMachine information related
131 * to boot sequience.
132 */
133class BootItemsList : public QWidget
134{
135 Q_OBJECT
136
137 class BootItem : public QCheckListItem
138 {
139 public:
140
141 BootItem (BootItemsTable *aParent, QListViewItem *aAfter,
142 const QString &aName, Type aType)
143 : QCheckListItem (aParent, aAfter, aName, aType) {}
144
145 private:
146
147 void stateChange (bool)
148 {
149 BootItemsTable *table = static_cast<BootItemsTable*> (listView());
150 table->emitItemToggled();
151 }
152 };
153
154public:
155
156 BootItemsList (QWidget *aParent, const char *aName)
157 : QWidget (aParent, aName), mBootTable (0)
158 {
159 /* Setup main widget layout */
160 QHBoxLayout *mainLayout = new QHBoxLayout (this, 0, 6, "mainLayout");
161
162 /* Setup settings layout */
163 mBootTable = new BootItemsTable (this, "mBootTable");
164 connect (mBootTable, SIGNAL (currentChanged (QListViewItem*)),
165 this, SLOT (processCurrentChanged (QListViewItem*)));
166 mainLayout->addWidget (mBootTable);
167
168 /* Setup button's layout */
169 QVBoxLayout *buttonLayout = new QVBoxLayout (mainLayout, 0, "buttonLayout");
170 mBtnUp = new QToolButton (this, "mBtnUp");
171 mBtnDown = new QToolButton (this, "mBtnDown");
172 QWhatsThis::add (mBtnUp, tr ("Moves the selected boot device up."));
173 QWhatsThis::add (mBtnDown, tr ("Moves the selected boot device down."));
174 QToolTip::add (mBtnUp, tr ("Move Up (Ctrl-Up)"));
175 QToolTip::add (mBtnDown, tr ("Move Down (Ctrl-Down)"));
176 mBtnUp->setAutoRaise (true);
177 mBtnDown->setAutoRaise (true);
178 mBtnUp->setFocusPolicy (QWidget::StrongFocus);
179 mBtnDown->setFocusPolicy (QWidget::StrongFocus);
180 mBtnUp->setIconSet (VBoxGlobal::iconSet ("list_moveup_16px.png",
181 "list_moveup_disabled_16px.png"));
182 mBtnDown->setIconSet (VBoxGlobal::iconSet ("list_movedown_16px.png",
183 "list_movedown_disabled_16px.png"));
184 QSpacerItem *spacer = new QSpacerItem (0, 0, QSizePolicy::Minimum,
185 QSizePolicy::Expanding);
186 connect (mBtnUp, SIGNAL (clicked()), this, SLOT (moveItemUp()));
187 connect (mBtnDown, SIGNAL (clicked()), this, SLOT (moveItemDown()));
188 connect (mBootTable, SIGNAL (moveItemUp()), this, SLOT (moveItemUp()));
189 connect (mBootTable, SIGNAL (moveItemDown()), this, SLOT (moveItemDown()));
190 connect (mBootTable, SIGNAL (itemToggled()), this, SLOT (onItemToggled()));
191 buttonLayout->addWidget (mBtnUp);
192 buttonLayout->addWidget (mBtnDown);
193 buttonLayout->addItem (spacer);
194
195 /* Setup focus proxy for BootItemsList */
196 setFocusProxy (mBootTable);
197 }
198
199 ~BootItemsList() {}
200
201 void fixTabStops()
202 {
203 /* Fixing focus order for BootItemsList */
204 setTabOrder (mBootTable, mBtnUp);
205 setTabOrder (mBtnUp, mBtnDown);
206 }
207
208 void getFromMachine (const CMachine &aMachine)
209 {
210 /* Load boot-items of current VM */
211 QStringList uniqueList;
212 int minimumWidth = 0;
213 for (int i = 1; i <= 4; ++ i)
214 {
215 CEnums::DeviceType type = aMachine.GetBootOrder (i);
216 if (type != CEnums::NoDevice)
217 {
218 QString name = vboxGlobal().toString (type);
219 QCheckListItem *item = new BootItem (mBootTable,
220 mBootTable->lastItem(), name, QCheckListItem::CheckBox);
221 item->setOn (true);
222 uniqueList << name;
223 int width = item->width (mBootTable->fontMetrics(), mBootTable, 0);
224 if (width > minimumWidth) minimumWidth = width;
225 }
226 }
227 /* Load other unique boot-items */
228 for (int i = CEnums::FloppyDevice; i < CEnums::USBDevice; ++ i)
229 {
230 QString name = vboxGlobal().toString ((CEnums::DeviceType) i);
231 if (!uniqueList.contains (name))
232 {
233 QCheckListItem *item = new BootItem (mBootTable,
234 mBootTable->lastItem(), name, QCheckListItem::CheckBox);
235 uniqueList << name;
236 int width = item->width (mBootTable->fontMetrics(), mBootTable, 0);
237 if (width > minimumWidth) minimumWidth = width;
238 }
239 }
240 processCurrentChanged (mBootTable->firstChild());
241 mBootTable->setFixedWidth (minimumWidth +
242 4 /* viewport margin */);
243 mBootTable->setFixedHeight (mBootTable->childCount() *
244 mBootTable->firstChild()->totalHeight() +
245 4 /* viewport margin */);
246 }
247
248 void putBackToMachine (CMachine &aMachine)
249 {
250 QCheckListItem *item = 0;
251 /* Search for checked items */
252 int index = 1;
253 item = static_cast<QCheckListItem*> (mBootTable->firstChild());
254 while (item)
255 {
256 if (item->isOn())
257 {
258 CEnums::DeviceType type =
259 vboxGlobal().toDeviceType (item->text (0));
260 aMachine.SetBootOrder (index++, type);
261 }
262 item = static_cast<QCheckListItem*> (item->nextSibling());
263 }
264 /* Search for non-checked items */
265 item = static_cast<QCheckListItem*> (mBootTable->firstChild());
266 while (item)
267 {
268 if (!item->isOn())
269 aMachine.SetBootOrder (index++, CEnums::NoDevice);
270 item = static_cast<QCheckListItem*> (item->nextSibling());
271 }
272 }
273
274 void processFocusIn (QWidget *aWidget)
275 {
276 if (aWidget == mBootTable)
277 {
278 mBootTable->setSelected (mBootTable->currentItem(), true);
279 processCurrentChanged (mBootTable->currentItem());
280 }
281 else if (aWidget != mBtnUp && aWidget != mBtnDown)
282 {
283 mBootTable->setSelected (mBootTable->currentItem(), false);
284 processCurrentChanged (mBootTable->currentItem());
285 }
286 }
287
288signals:
289
290 void bootSequenceChanged();
291
292private slots:
293
294 void moveItemUp()
295 {
296 QListViewItem *item = mBootTable->currentItem();
297 Assert (item);
298 QListViewItem *itemAbove = item->itemAbove();
299 if (!itemAbove) return;
300 itemAbove->moveItem (item);
301 processCurrentChanged (item);
302 emit bootSequenceChanged();
303 }
304
305 void moveItemDown()
306 {
307 QListViewItem *item = mBootTable->currentItem();
308 Assert (item);
309 QListViewItem *itemBelow = item->itemBelow();
310 if (!itemBelow) return;
311 item->moveItem (itemBelow);
312 processCurrentChanged (item);
313 emit bootSequenceChanged();
314 }
315
316 void onItemToggled()
317 {
318 emit bootSequenceChanged();
319 }
320
321 void processCurrentChanged (QListViewItem *aItem)
322 {
323 bool upEnabled = aItem && aItem->isSelected() && aItem->itemAbove();
324 bool downEnabled = aItem && aItem->isSelected() && aItem->itemBelow();
325 if (mBtnUp->hasFocus() && !upEnabled ||
326 mBtnDown->hasFocus() && !downEnabled)
327 mBootTable->setFocus();
328 mBtnUp->setEnabled (upEnabled);
329 mBtnDown->setEnabled (downEnabled);
330 }
331
332private:
333
334 BootItemsTable *mBootTable;
335 QToolButton *mBtnUp;
336 QToolButton *mBtnDown;
337};
338
339
340/// @todo (dmik) remove?
341///**
342// * Returns the through position of the item in the list view.
343// */
344//static int pos (QListView *lv, QListViewItem *li)
345//{
346// QListViewItemIterator it (lv);
347// int p = -1, c = 0;
348// while (it.current() && p < 0)
349// {
350// if (it.current() == li)
351// p = c;
352// ++ it;
353// ++ c;
354// }
355// return p;
356//}
357
358class USBListItem : public QCheckListItem
359{
360public:
361
362 USBListItem (QListView *aParent, QListViewItem *aAfter)
363 : QCheckListItem (aParent, aAfter, QString::null, CheckBox)
364 , mId (-1) {}
365
366 int mId;
367};
368
369/**
370 * Returns the path to the item in the form of 'grandparent > parent > item'
371 * using the text of the first column of every item.
372 */
373static QString path (QListViewItem *li)
374{
375 static QString sep = ": ";
376 QString p;
377 QListViewItem *cur = li;
378 while (cur)
379 {
380 if (!p.isNull())
381 p = sep + p;
382 p = cur->text (0).simplifyWhiteSpace() + p;
383 cur = cur->parent();
384 }
385 return p;
386}
387
388enum
389{
390 /* listView column numbers */
391 listView_Category = 0,
392 listView_Id = 1,
393 listView_Link = 2,
394 /* lvUSBFilters column numbers */
395 lvUSBFilters_Name = 0,
396};
397
398void VBoxVMSettingsDlg::init()
399{
400 polished = false;
401
402 setIcon (QPixmap::fromMimeSource ("settings_16px.png"));
403
404 /* all pages are initially valid */
405 valid = true;
406 buttonOk->setEnabled( true );
407
408 /* disable unselecting items by clicking in the unused area of the list */
409 new QIListViewSelectionPreserver (this, listView);
410 /* hide the header and internal columns */
411 listView->header()->hide();
412 listView->setColumnWidthMode (listView_Id, QListView::Manual);
413 listView->setColumnWidthMode (listView_Link, QListView::Manual);
414 listView->hideColumn (listView_Id);
415 listView->hideColumn (listView_Link);
416 /* sort by the id column (to have pages in the desired order) */
417 listView->setSorting (listView_Id);
418 listView->sort();
419 /* disable further sorting (important for network adapters) */
420 listView->setSorting (-1);
421 /* set the first item selected */
422 listView->setSelected (listView->firstChild(), true);
423 listView_currentChanged (listView->firstChild());
424 /* setup status bar icon */
425 warningPixmap->setMaximumSize( 16, 16 );
426 warningPixmap->setPixmap( QMessageBox::standardIcon( QMessageBox::Warning ) );
427
428 /* page title font is derived from the system font */
429 QFont f = font();
430 f.setBold (true);
431 f.setPointSize (f.pointSize() + 2);
432 titleLabel->setFont (f);
433
434 /* setup the what's this label */
435 QApplication::setGlobalMouseTracking (true);
436 qApp->installEventFilter (this);
437 whatsThisTimer = new QTimer (this);
438 connect (whatsThisTimer, SIGNAL (timeout()), this, SLOT (updateWhatsThis()));
439 whatsThisCandidate = NULL;
440
441 whatsThisLabel = new QIRichLabel (this, "whatsThisLabel");
442 VBoxVMSettingsDlgLayout->addWidget (whatsThisLabel, 2, 1);
443
444#ifndef DEBUG
445 /* Enforce rich text format to avoid jumping margins (margins of plain
446 * text labels seem to be smaller). We don't do it in the DEBUG builds to
447 * be able to immediately catch badly formatted text (i.e. text that
448 * contains HTML tags but doesn't start with <qt> so that Qt isn't able to
449 * recognize it as rich text and draws all tags as is instead of doing
450 * formatting). We want to catch this text because this is how it will look
451 * in the whatsthis balloon where we cannot enforce rich text. */
452 whatsThisLabel->setTextFormat (Qt::RichText);
453#endif
454
455 whatsThisLabel->setMaxHeightMode (true);
456 whatsThisLabel->setFocusPolicy (QWidget::NoFocus);
457 whatsThisLabel->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Fixed);
458 whatsThisLabel->setBackgroundMode (QLabel::PaletteMidlight);
459 whatsThisLabel->setFrameShape (QLabel::Box);
460 whatsThisLabel->setFrameShadow (QLabel::Sunken);
461 whatsThisLabel->setMargin (7);
462 whatsThisLabel->setScaledContents (FALSE);
463 whatsThisLabel->setAlignment (int (QLabel::WordBreak |
464 QLabel::AlignJustify |
465 QLabel::AlignTop));
466
467 whatsThisLabel->setFixedHeight (whatsThisLabel->frameWidth() * 2 +
468 6 /* seems that RichText adds some margin */ +
469 whatsThisLabel->fontMetrics().lineSpacing() * 3);
470 whatsThisLabel->setMinimumWidth (whatsThisLabel->frameWidth() * 2 +
471 6 /* seems that RichText adds some margin */ +
472 whatsThisLabel->fontMetrics().width ('m') * 40);
473
474 /*
475 * setup connections and set validation for pages
476 * ----------------------------------------------------------------------
477 */
478
479 /* General page */
480
481 CSystemProperties sysProps = vboxGlobal().virtualBox().GetSystemProperties();
482
483 const uint MinRAM = sysProps.GetMinGuestRAM();
484 const uint MaxRAM = sysProps.GetMaxGuestRAM();
485 const uint MinVRAM = sysProps.GetMinGuestVRAM();
486 const uint MaxVRAM = sysProps.GetMaxGuestVRAM();
487
488 leName->setValidator( new QRegExpValidator( QRegExp( ".+" ), this ) );
489
490 leRAM->setValidator (new QIntValidator (MinRAM, MaxRAM, this));
491 leVRAM->setValidator (new QIntValidator (MinVRAM, MaxVRAM, this));
492
493 wvalGeneral = new QIWidgetValidator( pageGeneral, this );
494 connect (wvalGeneral, SIGNAL (validityChanged (const QIWidgetValidator *)),
495 this, SLOT(enableOk (const QIWidgetValidator *)));
496
497 tbSelectSavedStateFolder->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
498 "select_file_dis_16px.png"));
499 tbResetSavedStateFolder->setIconSet (VBoxGlobal::iconSet ("eraser_16px.png",
500 "eraser_disabled_16px.png"));
501
502 teDescription->setTextFormat (Qt::PlainText);
503
504 /* HDD Images page */
505
506 QWhatsThis::add (static_cast <QWidget *> (grbHDA->child ("qt_groupbox_checkbox")),
507 tr ("When checked, attaches the specified virtual hard disk to the "
508 "Master slot of the Primary IDE controller."));
509 QWhatsThis::add (static_cast <QWidget *> (grbHDB->child ("qt_groupbox_checkbox")),
510 tr ("When checked, attaches the specified virtual hard disk to the "
511 "Slave slot of the Primary IDE controller."));
512 QWhatsThis::add (static_cast <QWidget *> (grbHDD->child ("qt_groupbox_checkbox")),
513 tr ("When checked, attaches the specified virtual hard disk to the "
514 "Slave slot of the Secondary IDE controller."));
515 cbHDA = new VBoxMediaComboBox (grbHDA, "cbHDA", VBoxDefs::HD);
516 cbHDB = new VBoxMediaComboBox (grbHDB, "cbHDB", VBoxDefs::HD);
517 cbHDD = new VBoxMediaComboBox (grbHDD, "cbHDD", VBoxDefs::HD);
518 hdaLayout->insertWidget (0, cbHDA);
519 hdbLayout->insertWidget (0, cbHDB);
520 hddLayout->insertWidget (0, cbHDD);
521 /* sometimes the weirdness of Qt just kills... */
522 setTabOrder (static_cast <QWidget *> (grbHDA->child ("qt_groupbox_checkbox")),
523 cbHDA);
524 setTabOrder (static_cast <QWidget *> (grbHDB->child ("qt_groupbox_checkbox")),
525 cbHDB);
526 setTabOrder (static_cast <QWidget *> (grbHDD->child ("qt_groupbox_checkbox")),
527 cbHDD);
528
529 QWhatsThis::add (cbHDB, tr ("Displays the virtual hard disk to attach to this IDE slot "
530 "and allows to quickly select a different hard disk."));
531 QWhatsThis::add (cbHDD, tr ("Displays the virtual hard disk to attach to this IDE slot "
532 "and allows to quickly select a different hard disk."));
533 QWhatsThis::add (cbHDA, tr ("Displays the virtual hard disk to attach to this IDE slot "
534 "and allows to quickly select a different hard disk."));
535 QWhatsThis::add (cbHDB, tr ("Displays the virtual hard disk to attach to this IDE slot "
536 "and allows to quickly select a different hard disk."));
537 QWhatsThis::add (cbHDD, tr ("Displays the virtual hard disk to attach to this IDE slot "
538 "and allows to quickly select a different hard disk."));
539
540 wvalHDD = new QIWidgetValidator( pageHDD, this );
541 connect (wvalHDD, SIGNAL (validityChanged (const QIWidgetValidator *)),
542 this, SLOT (enableOk (const QIWidgetValidator *)));
543 connect (wvalHDD, SIGNAL (isValidRequested (QIWidgetValidator *)),
544 this, SLOT (revalidate (QIWidgetValidator *)));
545
546 connect (grbHDA, SIGNAL (toggled (bool)), this, SLOT (hdaMediaChanged()));
547 connect (grbHDB, SIGNAL (toggled (bool)), this, SLOT (hdbMediaChanged()));
548 connect (grbHDD, SIGNAL (toggled (bool)), this, SLOT (hddMediaChanged()));
549 connect (cbHDA, SIGNAL (activated (int)), this, SLOT (hdaMediaChanged()));
550 connect (cbHDB, SIGNAL (activated (int)), this, SLOT (hdbMediaChanged()));
551 connect (cbHDD, SIGNAL (activated (int)), this, SLOT (hddMediaChanged()));
552 connect (tbHDA, SIGNAL (clicked()), this, SLOT (showImageManagerHDA()));
553 connect (tbHDB, SIGNAL (clicked()), this, SLOT (showImageManagerHDB()));
554 connect (tbHDD, SIGNAL (clicked()), this, SLOT (showImageManagerHDD()));
555
556 /* setup iconsets -- qdesigner is not capable... */
557 tbHDA->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
558 "select_file_dis_16px.png"));
559 tbHDB->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
560 "select_file_dis_16px.png"));
561 tbHDD->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
562 "select_file_dis_16px.png"));
563
564 /* CD/DVD-ROM Drive Page */
565
566 QWhatsThis::add (static_cast <QWidget *> (bgDVD->child ("qt_groupbox_checkbox")),
567 tr ("When checked, mounts the specified media to the CD/DVD drive of the "
568 "virtual machine. Note that the CD/DVD drive is always connected to the "
569 "Secondary Master IDE controller of the machine."));
570 cbISODVD = new VBoxMediaComboBox (bgDVD, "cbISODVD", VBoxDefs::CD);
571 cdLayout->insertWidget(0, cbISODVD);
572 QWhatsThis::add (cbISODVD, tr ("Displays the image file to mount to the virtual CD/DVD "
573 "drive and allows to quickly select a different image."));
574
575 wvalDVD = new QIWidgetValidator (pageDVD, this);
576 connect (wvalDVD, SIGNAL (validityChanged (const QIWidgetValidator *)),
577 this, SLOT (enableOk (const QIWidgetValidator *)));
578 connect (wvalDVD, SIGNAL (isValidRequested (QIWidgetValidator *)),
579 this, SLOT (revalidate( QIWidgetValidator *)));
580
581 connect (bgDVD, SIGNAL (toggled (bool)), this, SLOT (cdMediaChanged()));
582 connect (rbHostDVD, SIGNAL (stateChanged (int)), wvalDVD, SLOT (revalidate()));
583 connect (rbISODVD, SIGNAL (stateChanged (int)), wvalDVD, SLOT (revalidate()));
584 connect (cbISODVD, SIGNAL (activated (int)), this, SLOT (cdMediaChanged()));
585 connect (tbISODVD, SIGNAL (clicked()), this, SLOT (showImageManagerISODVD()));
586
587 /* setup iconsets -- qdesigner is not capable... */
588 tbISODVD->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
589 "select_file_dis_16px.png"));
590
591 /* Floppy Drive Page */
592
593 QWhatsThis::add (static_cast <QWidget *> (bgFloppy->child ("qt_groupbox_checkbox")),
594 tr ("When checked, mounts the specified media to the Floppy drive of the "
595 "virtual machine."));
596 cbISOFloppy = new VBoxMediaComboBox (bgFloppy, "cbISOFloppy", VBoxDefs::FD);
597 fdLayout->insertWidget(0, cbISOFloppy);
598 QWhatsThis::add (cbISOFloppy, tr ("Displays the image file to mount to the virtual Floppy "
599 "drive and allows to quickly select a different image."));
600
601 wvalFloppy = new QIWidgetValidator (pageFloppy, this);
602 connect (wvalFloppy, SIGNAL (validityChanged (const QIWidgetValidator *)),
603 this, SLOT (enableOk (const QIWidgetValidator *)));
604 connect (wvalFloppy, SIGNAL (isValidRequested (QIWidgetValidator *)),
605 this, SLOT (revalidate( QIWidgetValidator *)));
606
607 connect (bgFloppy, SIGNAL (toggled (bool)), this, SLOT (fdMediaChanged()));
608 connect (rbHostFloppy, SIGNAL (stateChanged (int)), wvalFloppy, SLOT (revalidate()));
609 connect (rbISOFloppy, SIGNAL (stateChanged (int)), wvalFloppy, SLOT (revalidate()));
610 connect (cbISOFloppy, SIGNAL (activated (int)), this, SLOT (fdMediaChanged()));
611 connect (tbISOFloppy, SIGNAL (clicked()), this, SLOT (showImageManagerISOFloppy()));
612
613 /* setup iconsets -- qdesigner is not capable... */
614 tbISOFloppy->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
615 "select_file_dis_16px.png"));
616
617 /* Audio Page */
618
619 QWhatsThis::add (static_cast <QWidget *> (grbAudio->child ("qt_groupbox_checkbox")),
620 tr ("When checked, the virtual PCI audio card is plugged into the "
621 "virtual machine that uses the specified driver to communicate "
622 "to the host audio card."));
623
624 /* Network Page */
625
626 QVBoxLayout* pageNetworkLayout = new QVBoxLayout (pageNetwork, 0, 10, "pageNetworkLayout");
627 tbwNetwork = new QTabWidget (pageNetwork, "tbwNetwork");
628 pageNetworkLayout->addWidget (tbwNetwork);
629
630 /* USB Page */
631
632 lvUSBFilters->header()->hide();
633 /* disable sorting */
634 lvUSBFilters->setSorting (-1);
635 /* disable unselecting items by clicking in the unused area of the list */
636 new QIListViewSelectionPreserver (this, lvUSBFilters);
637 /* create the widget stack for filter settings */
638 /// @todo (r=dmik) having a separate settings widget for every USB filter
639 // is not that smart if there are lots of USB filters. The reason for
640 // stacking here is that the stacked widget is used to temporarily store
641 // data of the associated USB filter until the dialog window is accepted.
642 // If we remove stacking, we will have to create a structure to store
643 // editable data of all USB filters while the dialog is open.
644 wstUSBFilters = new QWidgetStack (grbUSBFilters, "wstUSBFilters");
645 grbUSBFiltersLayout->addWidget (wstUSBFilters);
646 /* create a default (disabled) filter settings widget at index 0 */
647 VBoxUSBFilterSettings *settings = new VBoxUSBFilterSettings (wstUSBFilters);
648 settings->setup (VBoxUSBFilterSettings::MachineType);
649 wstUSBFilters->addWidget (settings, 0);
650 lvUSBFilters_currentChanged (NULL);
651
652 /* setup iconsets -- qdesigner is not capable... */
653 tbAddUSBFilter->setIconSet (VBoxGlobal::iconSet ("usb_new_16px.png",
654 "usb_new_disabled_16px.png"));
655 tbAddUSBFilterFrom->setIconSet (VBoxGlobal::iconSet ("usb_add_16px.png",
656 "usb_add_disabled_16px.png"));
657 tbRemoveUSBFilter->setIconSet (VBoxGlobal::iconSet ("usb_remove_16px.png",
658 "usb_remove_disabled_16px.png"));
659 tbUSBFilterUp->setIconSet (VBoxGlobal::iconSet ("usb_moveup_16px.png",
660 "usb_moveup_disabled_16px.png"));
661 tbUSBFilterDown->setIconSet (VBoxGlobal::iconSet ("usb_movedown_16px.png",
662 "usb_movedown_disabled_16px.png"));
663 usbDevicesMenu = new VBoxUSBMenu (this);
664 connect (usbDevicesMenu, SIGNAL(activated(int)), this, SLOT(menuAddUSBFilterFrom_activated(int)));
665 mUSBFilterListModified = false;
666
667 /* VRDP Page */
668
669 QWhatsThis::add (static_cast <QWidget *> (grbVRDP->child ("qt_groupbox_checkbox")),
670 tr ("When checked, the VM will act as a Remote Desktop "
671 "Protocol (RDP) server, allowing remote clients to connect "
672 "and operate the VM (when it is running) "
673 "using a standard RDP client."));
674
675 ULONG maxPort = 65535;
676 leVRDPPort->setValidator (new QIntValidator (0, maxPort, this));
677 leVRDPTimeout->setValidator (new QIntValidator (0, maxPort, this));
678 wvalVRDP = new QIWidgetValidator (pageVRDP, this);
679 connect (wvalVRDP, SIGNAL (validityChanged (const QIWidgetValidator *)),
680 this, SLOT (enableOk (const QIWidgetValidator *)));
681 connect (wvalVRDP, SIGNAL (isValidRequested (QIWidgetValidator *)),
682 this, SLOT (revalidate( QIWidgetValidator *)));
683
684 connect (grbVRDP, SIGNAL (toggled (bool)), wvalFloppy, SLOT (revalidate()));
685 connect (leVRDPPort, SIGNAL (textChanged (const QString&)), wvalFloppy, SLOT (revalidate()));
686 connect (leVRDPTimeout, SIGNAL (textChanged (const QString&)), wvalFloppy, SLOT (revalidate()));
687
688 /* Shared Folders Page */
689
690 QVBoxLayout* pageFoldersLayout = new QVBoxLayout (pageFolders, 0, 10, "pageFoldersLayout");
691 mSharedFolders = new VBoxSharedFoldersSettings (pageFolders, "sharedFolders");
692 mSharedFolders->setDialogType (VBoxSharedFoldersSettings::MachineType);
693 pageFoldersLayout->addWidget (mSharedFolders);
694
695 /*
696 * set initial values
697 * ----------------------------------------------------------------------
698 */
699
700 /* General page */
701
702 cbOS->insertStringList (vboxGlobal().vmGuestOSTypeDescriptions());
703
704 slRAM->setPageStep (calcPageStep (MaxRAM));
705 slRAM->setLineStep (slRAM->pageStep() / 4);
706 slRAM->setTickInterval (slRAM->pageStep());
707 /* setup the scale so that ticks are at page step boundaries */
708 slRAM->setMinValue ((MinRAM / slRAM->pageStep()) * slRAM->pageStep());
709 slRAM->setMaxValue (MaxRAM);
710 txRAMMin->setText (tr ("<qt>%1&nbsp;MB</qt>").arg (MinRAM));
711 txRAMMax->setText (tr ("<qt>%1&nbsp;MB</qt>").arg (MaxRAM));
712 /* limit min/max. size of QLineEdit */
713 leRAM->setMaximumSize (leRAM->fontMetrics().width ("99999")
714 + leRAM->frameWidth() * 2,
715 leRAM->minimumSizeHint().height());
716 leRAM->setMinimumSize (leRAM->maximumSize());
717 /* ensure leRAM value and validation is updated */
718 slRAM_valueChanged (slRAM->value());
719
720 slVRAM->setPageStep (calcPageStep (MaxVRAM));
721 slVRAM->setLineStep (slVRAM->pageStep() / 4);
722 slVRAM->setTickInterval (slVRAM->pageStep());
723 /* setup the scale so that ticks are at page step boundaries */
724 slVRAM->setMinValue ((MinVRAM / slVRAM->pageStep()) * slVRAM->pageStep());
725 slVRAM->setMaxValue (MaxVRAM);
726 txVRAMMin->setText (tr ("<qt>%1&nbsp;MB</qt>").arg (MinVRAM));
727 txVRAMMax->setText (tr ("<qt>%1&nbsp;MB</qt>").arg (MaxVRAM));
728 /* limit min/max. size of QLineEdit */
729 leVRAM->setMaximumSize (leVRAM->fontMetrics().width ("99999")
730 + leVRAM->frameWidth() * 2,
731 leVRAM->minimumSizeHint().height());
732 leVRAM->setMinimumSize (leVRAM->maximumSize());
733 /* ensure leVRAM value and validation is updated */
734 slVRAM_valueChanged (slVRAM->value());
735
736 /* Boot-order table */
737 tblBootOrder = new BootItemsList (groupBox12, "tblBootOrder");
738 connect (tblBootOrder, SIGNAL (bootSequenceChanged()),
739 this, SLOT (bootSequenceChanged()));
740 /* Fixing focus order for BootItemsList */
741 setTabOrder (tbwGeneral, tblBootOrder);
742 setTabOrder (tblBootOrder->focusProxy(), chbEnableACPI);
743 groupBox12Layout->addWidget (tblBootOrder);
744 tblBootOrder->fixTabStops();
745 /* Shared Clipboard mode */
746 cbSharedClipboard->insertItem (vboxGlobal().toString (CEnums::ClipDisabled));
747 cbSharedClipboard->insertItem (vboxGlobal().toString (CEnums::ClipHostToGuest));
748 cbSharedClipboard->insertItem (vboxGlobal().toString (CEnums::ClipGuestToHost));
749 cbSharedClipboard->insertItem (vboxGlobal().toString (CEnums::ClipBidirectional));
750
751 /* HDD Images page */
752
753 /* CD-ROM Drive Page */
754
755 /* Audio Page */
756
757 cbAudioDriver->insertItem (vboxGlobal().toString (CEnums::NullAudioDriver));
758#if defined Q_WS_WIN32
759 cbAudioDriver->insertItem (vboxGlobal().toString (CEnums::DSOUNDAudioDriver));
760#ifdef VBOX_WITH_WINMM
761 cbAudioDriver->insertItem (vboxGlobal().toString (CEnums::WINMMAudioDriver));
762#endif
763#elif defined Q_OS_LINUX
764 cbAudioDriver->insertItem (vboxGlobal().toString (CEnums::OSSAudioDriver));
765#ifdef VBOX_WITH_ALSA
766 cbAudioDriver->insertItem (vboxGlobal().toString (CEnums::ALSAAudioDriver));
767#endif
768#elif defined Q_OS_MACX
769 cbAudioDriver->insertItem (vboxGlobal().toString (CEnums::CoreAudioDriver));
770#endif
771
772 /* Network Page */
773
774 updateInterfaces (0);
775
776 /*
777 * update the Ok button state for pages with validation
778 * (validityChanged() connected to enableNext() will do the job)
779 */
780 wvalGeneral->revalidate();
781 wvalHDD->revalidate();
782 wvalDVD->revalidate();
783 wvalFloppy->revalidate();
784
785 /* VRDP Page */
786
787 leVRDPPort->setAlignment (Qt::AlignRight);
788 cbVRDPAuthType->insertItem (vboxGlobal().toString (CEnums::VRDPAuthNull));
789 cbVRDPAuthType->insertItem (vboxGlobal().toString (CEnums::VRDPAuthExternal));
790 cbVRDPAuthType->insertItem (vboxGlobal().toString (CEnums::VRDPAuthGuest));
791 leVRDPTimeout->setAlignment (Qt::AlignRight);
792}
793
794bool VBoxVMSettingsDlg::eventFilter (QObject *object, QEvent *event)
795{
796 if (!object->isWidgetType())
797 return QDialog::eventFilter (object, event);
798
799 QWidget *widget = static_cast <QWidget *> (object);
800 if (widget->topLevelWidget() != this)
801 return QDialog::eventFilter (object, event);
802
803 switch (event->type())
804 {
805 case QEvent::Enter:
806 case QEvent::Leave:
807 {
808 if (event->type() == QEvent::Enter)
809 whatsThisCandidate = widget;
810 else
811 whatsThisCandidate = NULL;
812 whatsThisTimer->start (100, true /* sshot */);
813 break;
814 }
815 case QEvent::FocusIn:
816 {
817 updateWhatsThis (true /* gotFocus */);
818 tblBootOrder->processFocusIn (widget);
819 break;
820 }
821 default:
822 break;
823 }
824
825 return QDialog::eventFilter (object, event);
826}
827
828void VBoxVMSettingsDlg::showEvent (QShowEvent *e)
829{
830 QDialog::showEvent (e);
831
832 /* one may think that QWidget::polish() is the right place to do things
833 * below, but apparently, by the time when QWidget::polish() is called,
834 * the widget style & layout are not fully done, at least the minimum
835 * size hint is not properly calculated. Since this is sometimes necessary,
836 * we provide our own "polish" implementation. */
837
838 if (polished)
839 return;
840
841 polished = true;
842
843 /* update geometry for the dynamically added usb-page to ensure proper
844 * sizeHint calculation by the Qt layout manager */
845 wstUSBFilters->updateGeometry();
846 /* let our toplevel widget calculate its sizeHint properly */
847 QApplication::sendPostedEvents (0, 0);
848
849 layout()->activate();
850
851 /* resize to the miminum possible size */
852 resize (minimumSize());
853
854 VBoxGlobal::centerWidget (this, parentWidget());
855
856 mIsBootSettingsChanged = false;
857}
858
859void VBoxVMSettingsDlg::updateShortcuts()
860{
861 /* setup necessary combobox item */
862 cbHDA->setCurrentItem (uuidHDA);
863 cbHDB->setCurrentItem (uuidHDB);
864 cbHDD->setCurrentItem (uuidHDD);
865 cbISODVD->setCurrentItem (uuidISODVD);
866 cbISOFloppy->setCurrentItem (uuidISOFloppy);
867 /* check if the enumeration process has been started yet */
868 if (!vboxGlobal().isMediaEnumerationStarted())
869 vboxGlobal().startEnumeratingMedia();
870 else
871 {
872 cbHDA->refresh();
873 cbHDB->refresh();
874 cbHDD->refresh();
875 cbISODVD->refresh();
876 cbISOFloppy->refresh();
877 }
878}
879
880
881void VBoxVMSettingsDlg::updateInterfaces (QWidget *aWidget)
882{
883#if defined Q_WS_WIN
884 /* clear list */
885 mInterfaceList.clear();
886 /* write a QStringList of interface names */
887 CHostNetworkInterfaceEnumerator en =
888 vboxGlobal().virtualBox().GetHost().GetNetworkInterfaces().Enumerate();
889 while (en.HasMore())
890 mInterfaceList += en.GetNext().GetName();
891 if (aWidget)
892 {
893 VBoxVMNetworkSettings *set = static_cast<VBoxVMNetworkSettings*> (aWidget);
894 set->revalidate();
895 }
896#else
897 NOREF (aWidget);
898#endif
899}
900
901void VBoxVMSettingsDlg::networkPageUpdate (QWidget *aWidget)
902{
903 if (!aWidget) return;
904#if defined Q_WS_WIN
905 updateInterfaces (0);
906 VBoxVMNetworkSettings *set = static_cast<VBoxVMNetworkSettings*> (aWidget);
907 set->loadList (mInterfaceList);
908 set->revalidate();
909#endif
910}
911
912
913void VBoxVMSettingsDlg::bootSequenceChanged()
914{
915 mIsBootSettingsChanged = true;
916}
917
918
919void VBoxVMSettingsDlg::hdaMediaChanged()
920{
921 bootSequenceChanged();
922 uuidHDA = grbHDA->isChecked() ? cbHDA->getId() : QUuid();
923 txHDA->setText (getHdInfo (grbHDA, uuidHDA));
924 /* revailidate */
925 wvalHDD->revalidate();
926}
927
928
929void VBoxVMSettingsDlg::hdbMediaChanged()
930{
931 bootSequenceChanged();
932 uuidHDB = grbHDB->isChecked() ? cbHDB->getId() : QUuid();
933 txHDB->setText (getHdInfo (grbHDB, uuidHDB));
934 /* revailidate */
935 wvalHDD->revalidate();
936}
937
938
939void VBoxVMSettingsDlg::hddMediaChanged()
940{
941 bootSequenceChanged();
942 uuidHDD = grbHDD->isChecked() ? cbHDD->getId() : QUuid();
943 txHDD->setText (getHdInfo (grbHDD, uuidHDD));
944 /* revailidate */
945 wvalHDD->revalidate();
946}
947
948
949void VBoxVMSettingsDlg::cdMediaChanged()
950{
951 bootSequenceChanged();
952 uuidISODVD = bgDVD->isChecked() ? cbISODVD->getId() : QUuid();
953 /* revailidate */
954 wvalDVD->revalidate();
955}
956
957
958void VBoxVMSettingsDlg::fdMediaChanged()
959{
960 bootSequenceChanged();
961 uuidISOFloppy = bgFloppy->isChecked() ? cbISOFloppy->getId() : QUuid();
962 /* revailidate */
963 wvalFloppy->revalidate();
964}
965
966
967QString VBoxVMSettingsDlg::getHdInfo (QGroupBox *aGroupBox, QUuid aId)
968{
969 QString notAttached = tr ("<not attached>", "hard disk");
970 if (aId.isNull())
971 return notAttached;
972 return aGroupBox->isChecked() ?
973 vboxGlobal().details (vboxGlobal().virtualBox().GetHardDisk (aId), true) :
974 notAttached;
975}
976
977void VBoxVMSettingsDlg::updateWhatsThis (bool gotFocus /* = false */)
978{
979 QString text;
980
981 QWidget *widget = NULL;
982 if (!gotFocus)
983 {
984 if (whatsThisCandidate != NULL && whatsThisCandidate != this)
985 widget = whatsThisCandidate;
986 }
987 else
988 {
989 widget = focusData()->focusWidget();
990 }
991 /* if the given widget lacks the whats'this text, look at its parent */
992 while (widget && widget != this)
993 {
994 text = QWhatsThis::textFor (widget);
995 if (!text.isEmpty())
996 break;
997 widget = widget->parentWidget();
998 }
999
1000 if (text.isEmpty() && !warningString.isEmpty())
1001 text = warningString;
1002 if (text.isEmpty())
1003 text = QWhatsThis::textFor (this);
1004
1005 whatsThisLabel->setText (text);
1006}
1007
1008void VBoxVMSettingsDlg::setWarning (const QString &warning)
1009{
1010 warningString = warning;
1011 if (!warning.isEmpty())
1012 warningString = QString ("<font color=red>%1</font>").arg (warning);
1013
1014 if (!warningString.isEmpty())
1015 whatsThisLabel->setText (warningString);
1016 else
1017 updateWhatsThis (true);
1018}
1019
1020/**
1021 * Sets up this dialog.
1022 *
1023 * If @a aCategory is non-null, it should be one of values from the hidden
1024 * '[cat]' column of #listView (see VBoxVMSettingsDlg.ui in qdesigner)
1025 * prepended with the '#' sign. In this case, the specified category page
1026 * will be activated when the dialog is open.
1027 *
1028 * If @a aWidget is non-null, it should be a name of one of widgets
1029 * from the given category page. In this case, the specified widget
1030 * will get focus when the dialog is open.
1031 *
1032 * @note Calling this method after the dialog is open has no sense.
1033 *
1034 * @param aCategory Category to select when the dialog is open or null.
1035 * @param aWidget Category to select when the dialog is open or null.
1036 */
1037void VBoxVMSettingsDlg::setup (const QString &aCategory, const QString &aControl)
1038{
1039 if (!aCategory.isNull())
1040 {
1041 /* search for a list view item corresponding to the category */
1042 QListViewItem *item = listView->findItem (aCategory, listView_Link);
1043 if (item)
1044 {
1045 listView->setSelected (item, true);
1046
1047 /* search for a widget with the given name */
1048 if (!aControl.isNull())
1049 {
1050 QObject *obj = widgetStack->visibleWidget()->child (aControl);
1051 if (obj && obj->isWidgetType())
1052 {
1053 QWidget *w = static_cast <QWidget *> (obj);
1054 QWidgetList parents;
1055 QWidget *p = w;
1056 while ((p = p->parentWidget()) != NULL)
1057 {
1058 if (!strcmp (p->className(), "QTabWidget"))
1059 {
1060 /* the tab contents widget is two steps down
1061 * (QTabWidget -> QWidgetStack -> QWidget) */
1062 QWidget *c = parents.last();
1063 if (c)
1064 c = parents.prev();
1065 if (c)
1066 static_cast <QTabWidget *> (p)->showPage (c);
1067 }
1068 parents.append (p);
1069 }
1070
1071 w->setFocus();
1072 }
1073 }
1074 }
1075 }
1076}
1077
1078void VBoxVMSettingsDlg::listView_currentChanged (QListViewItem *item)
1079{
1080 Assert (item);
1081 int id = item->text (1).toInt();
1082 Assert (id >= 0);
1083 titleLabel->setText (::path (item));
1084 widgetStack->raiseWidget (id);
1085}
1086
1087
1088void VBoxVMSettingsDlg::enableOk( const QIWidgetValidator *wval )
1089{
1090 Q_UNUSED (wval);
1091
1092 /* detect the overall validity */
1093 bool newValid = true;
1094 {
1095 QObjectList *l = this->queryList ("QIWidgetValidator");
1096 QObjectListIt it (*l);
1097 QObject *obj;
1098 while ((obj = it.current()) != 0)
1099 {
1100 newValid &= ((QIWidgetValidator *) obj)->isValid();
1101 ++it;
1102 }
1103 delete l;
1104 }
1105
1106 if (valid != newValid)
1107 {
1108 valid = newValid;
1109 buttonOk->setEnabled (valid);
1110 if (valid)
1111 setWarning(0);
1112 warningLabel->setHidden(valid);
1113 warningPixmap->setHidden(valid);
1114 }
1115}
1116
1117
1118void VBoxVMSettingsDlg::revalidate( QIWidgetValidator *wval )
1119{
1120 /* do individual validations for pages */
1121 QWidget *pg = wval->widget();
1122 bool valid = wval->isOtherValid();
1123
1124 if (pg == pageHDD)
1125 {
1126 CVirtualBox vbox = vboxGlobal().virtualBox();
1127 valid = true;
1128
1129 QValueList <QUuid> uuids;
1130
1131 if (valid && grbHDA->isChecked())
1132 {
1133 if (uuidHDA.isNull())
1134 {
1135 valid = false;
1136 setWarning (tr ("Primary Master hard disk is not selected."));
1137 }
1138 else uuids << uuidHDA;
1139 }
1140
1141 if (valid && grbHDB->isChecked())
1142 {
1143 if (uuidHDB.isNull())
1144 {
1145 valid = false;
1146 setWarning (tr ("Primary Slave hard disk is not selected."));
1147 }
1148 else
1149 {
1150 bool found = uuids.findIndex (uuidHDB) >= 0;
1151 if (found)
1152 {
1153 CHardDisk hd = vbox.GetHardDisk (uuidHDB);
1154 valid = hd.GetType() == CEnums::ImmutableHardDisk;
1155 }
1156 if (valid)
1157 uuids << uuidHDB;
1158 else
1159 setWarning (tr ("Primary Slave hard disk is already attached "
1160 "to a different slot."));
1161 }
1162 }
1163
1164 if (valid && grbHDD->isChecked())
1165 {
1166 if (uuidHDD.isNull())
1167 {
1168 valid = false;
1169 setWarning (tr ("Secondary Slave hard disk is not selected."));
1170 }
1171 else
1172 {
1173 bool found = uuids.findIndex (uuidHDD) >= 0;
1174 if (found)
1175 {
1176 CHardDisk hd = vbox.GetHardDisk (uuidHDD);
1177 valid = hd.GetType() == CEnums::ImmutableHardDisk;
1178 }
1179 if (valid)
1180 uuids << uuidHDB;
1181 else
1182 setWarning (tr ("Secondary Slave hard disk is already attached "
1183 "to a different slot."));
1184 }
1185 }
1186
1187 cbHDA->setEnabled (grbHDA->isChecked());
1188 cbHDB->setEnabled (grbHDB->isChecked());
1189 cbHDD->setEnabled (grbHDD->isChecked());
1190 tbHDA->setEnabled (grbHDA->isChecked());
1191 tbHDB->setEnabled (grbHDB->isChecked());
1192 tbHDD->setEnabled (grbHDD->isChecked());
1193 }
1194 else if (pg == pageDVD)
1195 {
1196 if (!bgDVD->isChecked())
1197 rbHostDVD->setChecked(false), rbISODVD->setChecked(false);
1198 else if (!rbHostDVD->isChecked() && !rbISODVD->isChecked())
1199 rbHostDVD->setChecked(true);
1200
1201 valid = !(rbISODVD->isChecked() && uuidISODVD.isNull());
1202
1203 cbHostDVD->setEnabled (rbHostDVD->isChecked());
1204
1205 cbISODVD->setEnabled (rbISODVD->isChecked());
1206 tbISODVD->setEnabled (rbISODVD->isChecked());
1207
1208 if (!valid)
1209 setWarning (tr ("CD/DVD drive image file is not selected."));
1210 }
1211 else if (pg == pageFloppy)
1212 {
1213 if (!bgFloppy->isChecked())
1214 rbHostFloppy->setChecked(false), rbISOFloppy->setChecked(false);
1215 else if (!rbHostFloppy->isChecked() && !rbISOFloppy->isChecked())
1216 rbHostFloppy->setChecked(true);
1217
1218 valid = !(rbISOFloppy->isChecked() && uuidISOFloppy.isNull());
1219
1220 cbHostFloppy->setEnabled (rbHostFloppy->isChecked());
1221
1222 cbISOFloppy->setEnabled (rbISOFloppy->isChecked());
1223 tbISOFloppy->setEnabled (rbISOFloppy->isChecked());
1224
1225 if (!valid)
1226 setWarning (tr ("Floppy drive image file is not selected."));
1227 }
1228 else if (pg == pageNetwork)
1229 {
1230 int index = 0;
1231 for (; index < tbwNetwork->count(); ++index)
1232 {
1233 QWidget *tab = tbwNetwork->page (index);
1234 VBoxVMNetworkSettings *set = static_cast<VBoxVMNetworkSettings*> (tab);
1235 valid = set->isPageValid (mInterfaceList);
1236 if (!valid) break;
1237 }
1238 if (!valid)
1239 setWarning (tr ("Incorrect host network interface is selected "
1240 "for Adapter %1.").arg (index));
1241 }
1242 else if (pg == pageVRDP)
1243 {
1244 if (pageVRDP->isEnabled())
1245 {
1246 valid = !(grbVRDP->isChecked() &&
1247 (leVRDPPort->text().isEmpty() || leVRDPTimeout->text().isEmpty()));
1248 if (!valid && leVRDPPort->text().isEmpty())
1249 setWarning (tr ("VRDP Port is not set."));
1250 if (!valid && leVRDPTimeout->text().isEmpty())
1251 setWarning (tr ("VRDP Timeout is not set."));
1252 }
1253 else
1254 valid = true;
1255 }
1256
1257 wval->setOtherValid (valid);
1258}
1259
1260
1261void VBoxVMSettingsDlg::getFromMachine (const CMachine &machine)
1262{
1263 cmachine = machine;
1264
1265 setCaption (machine.GetName() + tr (" - Settings"));
1266
1267 CVirtualBox vbox = vboxGlobal().virtualBox();
1268 CBIOSSettings biosSettings = cmachine.GetBIOSSettings();
1269
1270 /* name */
1271 leName->setText (machine.GetName());
1272
1273 /* OS type */
1274 QString typeId = machine.GetOSTypeId();
1275 cbOS->setCurrentItem (vboxGlobal().vmGuestOSTypeIndex (typeId));
1276 cbOS_activated (cbOS->currentItem());
1277
1278 /* RAM size */
1279 slRAM->setValue (machine.GetMemorySize());
1280
1281 /* VRAM size */
1282 slVRAM->setValue (machine.GetVRAMSize());
1283
1284 /* Boot-order */
1285 tblBootOrder->getFromMachine (machine);
1286
1287 /* ACPI */
1288 chbEnableACPI->setChecked (biosSettings.GetACPIEnabled());
1289
1290 /* IO APIC */
1291 chbEnableIOAPIC->setChecked (biosSettings.GetIOAPICEnabled());
1292
1293 /* Saved state folder */
1294 leSnapshotFolder->setText (machine.GetSnapshotFolder());
1295
1296 /* Description */
1297 teDescription->setText (machine.GetDescription());
1298
1299 /* Shared clipboard mode */
1300 cbSharedClipboard->setCurrentItem (machine.GetClipboardMode());
1301
1302 /* hard disk images */
1303 {
1304 struct
1305 {
1306 CEnums::DiskControllerType ctl;
1307 LONG dev;
1308 struct {
1309 QGroupBox *grb;
1310 QComboBox *cbb;
1311 QLabel *tx;
1312 QUuid *uuid;
1313 } data;
1314 }
1315 diskSet[] =
1316 {
1317 { CEnums::IDE0Controller, 0, {grbHDA, cbHDA, txHDA, &uuidHDA} },
1318 { CEnums::IDE0Controller, 1, {grbHDB, cbHDB, txHDB, &uuidHDB} },
1319 { CEnums::IDE1Controller, 1, {grbHDD, cbHDD, txHDD, &uuidHDD} },
1320 };
1321
1322 grbHDA->setChecked (false);
1323 grbHDB->setChecked (false);
1324 grbHDD->setChecked (false);
1325
1326 CHardDiskAttachmentEnumerator en =
1327 machine.GetHardDiskAttachments().Enumerate();
1328 while (en.HasMore())
1329 {
1330 CHardDiskAttachment hda = en.GetNext();
1331 for (uint i = 0; i < SIZEOF_ARRAY (diskSet); i++)
1332 {
1333 if (diskSet [i].ctl == hda.GetController() &&
1334 diskSet [i].dev == hda.GetDeviceNumber())
1335 {
1336 CHardDisk hd = hda.GetHardDisk();
1337 CHardDisk root = hd.GetRoot();
1338 QString src = root.GetLocation();
1339 if (hd.GetStorageType() == CEnums::VirtualDiskImage)
1340 {
1341 QFileInfo fi (src);
1342 src = fi.fileName() + " (" +
1343 QDir::convertSeparators (fi.dirPath (true)) + ")";
1344 }
1345 diskSet [i].data.grb->setChecked (true);
1346 diskSet [i].data.tx->setText (vboxGlobal().details (hd));
1347 *(diskSet [i].data.uuid) = QUuid (root.GetId());
1348 }
1349 }
1350 }
1351 }
1352
1353 /* floppy image */
1354 {
1355 /* read out the host floppy drive list and prepare the combobox */
1356 CHostFloppyDriveCollection coll =
1357 vboxGlobal().virtualBox().GetHost().GetFloppyDrives();
1358 hostFloppies.resize (coll.GetCount());
1359 cbHostFloppy->clear();
1360 int id = 0;
1361 CHostFloppyDriveEnumerator en = coll.Enumerate();
1362 while (en.HasMore())
1363 {
1364 CHostFloppyDrive hostFloppy = en.GetNext();
1365 /** @todo set icon? */
1366 cbHostFloppy->insertItem (hostFloppy.GetName(), id);
1367 hostFloppies [id] = hostFloppy;
1368 ++ id;
1369 }
1370
1371 CFloppyDrive floppy = machine.GetFloppyDrive();
1372 switch (floppy.GetState())
1373 {
1374 case CEnums::HostDriveCaptured:
1375 {
1376 CHostFloppyDrive drv = floppy.GetHostDrive();
1377 QString name = drv.GetName();
1378 if (coll.FindByName (name).isNull())
1379 {
1380 /*
1381 * if the floppy drive is not currently available,
1382 * add it to the end of the list with a special mark
1383 */
1384 cbHostFloppy->insertItem ("* " + name);
1385 cbHostFloppy->setCurrentItem (cbHostFloppy->count() - 1);
1386 }
1387 else
1388 {
1389 /* this will select the correct item from the prepared list */
1390 cbHostFloppy->setCurrentText (name);
1391 }
1392 rbHostFloppy->setChecked (true);
1393 break;
1394 }
1395 case CEnums::ImageMounted:
1396 {
1397 CFloppyImage img = floppy.GetImage();
1398 QString src = img.GetFilePath();
1399 AssertMsg (!src.isNull(), ("Image file must not be null"));
1400 QFileInfo fi (src);
1401 rbISOFloppy->setChecked (true);
1402 uuidISOFloppy = QUuid (img.GetId());
1403 break;
1404 }
1405 case CEnums::NotMounted:
1406 {
1407 bgFloppy->setChecked(false);
1408 break;
1409 }
1410 default:
1411 AssertMsgFailed (("invalid floppy state: %d\n", floppy.GetState()));
1412 }
1413 }
1414
1415 /* CD/DVD-ROM image */
1416 {
1417 /* read out the host DVD drive list and prepare the combobox */
1418 CHostDVDDriveCollection coll =
1419 vboxGlobal().virtualBox().GetHost().GetDVDDrives();
1420 hostDVDs.resize (coll.GetCount());
1421 cbHostDVD->clear();
1422 int id = 0;
1423 CHostDVDDriveEnumerator en = coll.Enumerate();
1424 while (en.HasMore())
1425 {
1426 CHostDVDDrive hostDVD = en.GetNext();
1427 /// @todo (r=dmik) set icon?
1428 QString description = hostDVD.GetDescription();
1429 if (description.isEmpty())
1430 {
1431 cbHostDVD->insertItem (hostDVD.GetName(), id);
1432 }
1433 else
1434 {
1435 cbHostDVD->insertItem (description, id);
1436 }
1437 hostDVDs [id] = hostDVD;
1438 ++ id;
1439 }
1440
1441 CDVDDrive dvd = machine.GetDVDDrive();
1442 switch (dvd.GetState())
1443 {
1444 case CEnums::HostDriveCaptured:
1445 {
1446 CHostDVDDrive drv = dvd.GetHostDrive();
1447 QString name = drv.GetName();
1448 QString description = drv.GetDescription();
1449 if (coll.FindByName (name).isNull())
1450 {
1451 /*
1452 * if the DVD drive is not currently available,
1453 * add it to the end of the list with a special mark
1454 */
1455 if (description.isEmpty())
1456 {
1457 cbHostDVD->insertItem ("* " + name);
1458 }
1459 else
1460 {
1461 cbHostDVD->insertItem ("* " + description);
1462 }
1463 cbHostDVD->setCurrentItem (cbHostDVD->count() - 1);
1464 }
1465 else
1466 {
1467 /* this will select the correct item from the prepared list */
1468 if (description.isEmpty())
1469 {
1470 cbHostDVD->setCurrentText (name);
1471 }
1472 else
1473 {
1474 cbHostDVD->setCurrentText (description);
1475 }
1476 }
1477 rbHostDVD->setChecked (true);
1478 break;
1479 }
1480 case CEnums::ImageMounted:
1481 {
1482 CDVDImage img = dvd.GetImage();
1483 QString src = img.GetFilePath();
1484 AssertMsg (!src.isNull(), ("Image file must not be null"));
1485 QFileInfo fi (src);
1486 rbISODVD->setChecked (true);
1487 uuidISODVD = QUuid (img.GetId());
1488 break;
1489 }
1490 case CEnums::NotMounted:
1491 {
1492 bgDVD->setChecked(false);
1493 break;
1494 }
1495 default:
1496 AssertMsgFailed (("invalid DVD state: %d\n", dvd.GetState()));
1497 }
1498 }
1499
1500 /* audio */
1501 {
1502 CAudioAdapter audio = machine.GetAudioAdapter();
1503 grbAudio->setChecked (audio.GetEnabled());
1504 cbAudioDriver->setCurrentText (vboxGlobal().toString (audio.GetAudioDriver()));
1505 }
1506
1507 /* network */
1508 {
1509 ulong count = vbox.GetSystemProperties().GetNetworkAdapterCount();
1510 for (ulong slot = 0; slot < count; ++ slot)
1511 {
1512 CNetworkAdapter adapter = machine.GetNetworkAdapter (slot);
1513 addNetworkAdapter (adapter);
1514 }
1515 }
1516
1517 /* USB */
1518 {
1519 CUSBController ctl = machine.GetUSBController();
1520
1521 if (ctl.isNull())
1522 {
1523 /* disable the USB controller category if the USB controller is
1524 * not available (i.e. in VirtualBox OSE) */
1525
1526 QListViewItem *usbItem = listView->findItem ("#usb", listView_Link);
1527 Assert (usbItem);
1528 if (usbItem)
1529 usbItem->setVisible (false);
1530
1531 /* disable validators if any */
1532 pageUSB->setEnabled (false);
1533
1534 /* Show an error message (if there is any).
1535 * Note that we don't use the generic cannotLoadMachineSettings()
1536 * call here because we want this message to be suppressable. */
1537 vboxProblem().cannotAccessUSB (machine);
1538 }
1539 else
1540 {
1541 cbEnableUSBController->setChecked (ctl.GetEnabled());
1542
1543 CUSBDeviceFilterEnumerator en = ctl.GetDeviceFilters().Enumerate();
1544 while (en.HasMore())
1545 addUSBFilter (en.GetNext(), false /* isNew */);
1546
1547 lvUSBFilters->setCurrentItem (lvUSBFilters->firstChild());
1548 /* silly Qt -- doesn't emit currentChanged after adding the
1549 * first item to an empty list */
1550 lvUSBFilters_currentChanged (lvUSBFilters->firstChild());
1551 }
1552 }
1553
1554 /* vrdp */
1555 {
1556 CVRDPServer vrdp = machine.GetVRDPServer();
1557
1558 if (vrdp.isNull())
1559 {
1560 /* disable the VRDP category if VRDP is
1561 * not available (i.e. in VirtualBox OSE) */
1562
1563 QListViewItem *vrdpItem = listView->findItem ("#vrdp", listView_Link);
1564 Assert (vrdpItem);
1565 if (vrdpItem)
1566 vrdpItem->setVisible (false);
1567
1568 /* disable validators if any */
1569 pageVRDP->setEnabled (false);
1570
1571 /* if machine has something to say, show the message */
1572 vboxProblem().cannotLoadMachineSettings (machine, false /* strict */);
1573 }
1574 else
1575 {
1576 grbVRDP->setChecked (vrdp.GetEnabled());
1577 leVRDPPort->setText (QString::number (vrdp.GetPort()));
1578 cbVRDPAuthType->setCurrentText (vboxGlobal().toString (vrdp.GetAuthType()));
1579 leVRDPTimeout->setText (QString::number (vrdp.GetAuthTimeout()));
1580 }
1581 }
1582
1583 /* shared folders */
1584 {
1585 mSharedFolders->getFromMachine (machine);
1586 }
1587
1588 /* request for media shortcuts update */
1589 cbHDA->setBelongsTo (machine.GetId());
1590 cbHDB->setBelongsTo (machine.GetId());
1591 cbHDD->setBelongsTo (machine.GetId());
1592 updateShortcuts();
1593
1594 /* revalidate pages with custom validation */
1595 wvalHDD->revalidate();
1596 wvalDVD->revalidate();
1597 wvalFloppy->revalidate();
1598 wvalVRDP->revalidate();
1599}
1600
1601
1602COMResult VBoxVMSettingsDlg::putBackToMachine()
1603{
1604 CVirtualBox vbox = vboxGlobal().virtualBox();
1605 CBIOSSettings biosSettings = cmachine.GetBIOSSettings();
1606
1607 /* name */
1608 cmachine.SetName (leName->text());
1609
1610 /* OS type */
1611 CGuestOSType type = vboxGlobal().vmGuestOSType (cbOS->currentItem());
1612 AssertMsg (!type.isNull(), ("vmGuestOSType() must return non-null type"));
1613 cmachine.SetOSTypeId (type.GetId());
1614
1615 /* RAM size */
1616 cmachine.SetMemorySize (slRAM->value());
1617
1618 /* VRAM size */
1619 cmachine.SetVRAMSize (slVRAM->value());
1620
1621 /* boot order */
1622 tblBootOrder->putBackToMachine (cmachine);
1623
1624 /* ACPI */
1625 biosSettings.SetACPIEnabled (chbEnableACPI->isChecked());
1626
1627 /* IO APIC */
1628 biosSettings.SetIOAPICEnabled (chbEnableIOAPIC->isChecked());
1629
1630 /* Saved state folder */
1631 if (leSnapshotFolder->isModified())
1632 cmachine.SetSnapshotFolder (leSnapshotFolder->text());
1633
1634 /* Description */
1635 cmachine.SetDescription (teDescription->text());
1636
1637 /* Shared clipboard mode */
1638 cmachine.SetClipboardMode ((CEnums::ClipboardMode)cbSharedClipboard->currentItem());
1639
1640 /* hard disk images */
1641 {
1642 struct
1643 {
1644 CEnums::DiskControllerType ctl;
1645 LONG dev;
1646 struct {
1647 QGroupBox *grb;
1648 QUuid *uuid;
1649 } data;
1650 }
1651 diskSet[] =
1652 {
1653 { CEnums::IDE0Controller, 0, {grbHDA, &uuidHDA} },
1654 { CEnums::IDE0Controller, 1, {grbHDB, &uuidHDB} },
1655 { CEnums::IDE1Controller, 1, {grbHDD, &uuidHDD} }
1656 };
1657
1658 /*
1659 * first, detach all disks (to ensure we can reattach them to different
1660 * controllers / devices, when appropriate)
1661 */
1662 CHardDiskAttachmentEnumerator en =
1663 cmachine.GetHardDiskAttachments().Enumerate();
1664 while (en.HasMore())
1665 {
1666 CHardDiskAttachment hda = en.GetNext();
1667 for (uint i = 0; i < SIZEOF_ARRAY (diskSet); i++)
1668 {
1669 if (diskSet [i].ctl == hda.GetController() &&
1670 diskSet [i].dev == hda.GetDeviceNumber())
1671 {
1672 cmachine.DetachHardDisk (diskSet [i].ctl, diskSet [i].dev);
1673 if (!cmachine.isOk())
1674 vboxProblem().cannotDetachHardDisk (
1675 this, cmachine, diskSet [i].ctl, diskSet [i].dev);
1676 }
1677 }
1678 }
1679
1680 /* now, attach new disks */
1681 for (uint i = 0; i < SIZEOF_ARRAY (diskSet); i++)
1682 {
1683 QUuid *newId = diskSet [i].data.uuid;
1684 if (diskSet [i].data.grb->isChecked() && !(*newId).isNull())
1685 {
1686 cmachine.AttachHardDisk (*newId, diskSet [i].ctl, diskSet [i].dev);
1687 if (!cmachine.isOk())
1688 vboxProblem().cannotAttachHardDisk (
1689 this, cmachine, *newId, diskSet [i].ctl, diskSet [i].dev);
1690 }
1691 }
1692 }
1693
1694 /* floppy image */
1695 {
1696 CFloppyDrive floppy = cmachine.GetFloppyDrive();
1697 if (!bgFloppy->isChecked())
1698 {
1699 floppy.Unmount();
1700 }
1701 else if (rbHostFloppy->isChecked())
1702 {
1703 int id = cbHostFloppy->currentItem();
1704 Assert (id >= 0);
1705 if (id < (int) hostFloppies.count())
1706 floppy.CaptureHostDrive (hostFloppies [id]);
1707 /*
1708 * otherwise the selected drive is not yet available, leave it
1709 * as is
1710 */
1711 }
1712 else if (rbISOFloppy->isChecked())
1713 {
1714 Assert (!uuidISOFloppy.isNull());
1715 floppy.MountImage (uuidISOFloppy);
1716 }
1717 }
1718
1719 /* CD/DVD-ROM image */
1720 {
1721 CDVDDrive dvd = cmachine.GetDVDDrive();
1722 if (!bgDVD->isChecked())
1723 {
1724 dvd.Unmount();
1725 }
1726 else if (rbHostDVD->isChecked())
1727 {
1728 int id = cbHostDVD->currentItem();
1729 Assert (id >= 0);
1730 if (id < (int) hostDVDs.count())
1731 dvd.CaptureHostDrive (hostDVDs [id]);
1732 /*
1733 * otherwise the selected drive is not yet available, leave it
1734 * as is
1735 */
1736 }
1737 else if (rbISODVD->isChecked())
1738 {
1739 Assert (!uuidISODVD.isNull());
1740 dvd.MountImage (uuidISODVD);
1741 }
1742 }
1743
1744 /* Clear the "GUI_FirstRun" extra data key in case of one of the boot
1745 * settings was changed */
1746 if (mIsBootSettingsChanged)
1747 cmachine.SetExtraData (GUI_FirstRun, QString::null);
1748
1749 /* audio */
1750 {
1751 CAudioAdapter audio = cmachine.GetAudioAdapter();
1752 audio.SetAudioDriver (vboxGlobal().toAudioDriverType (cbAudioDriver->currentText()));
1753 audio.SetEnabled (grbAudio->isChecked());
1754 AssertWrapperOk (audio);
1755 }
1756
1757 /* network */
1758 {
1759 for (int index = 0; index < tbwNetwork->count(); index++)
1760 {
1761 VBoxVMNetworkSettings *page =
1762 (VBoxVMNetworkSettings *) tbwNetwork->page (index);
1763 Assert (page);
1764 page->putBackToAdapter();
1765 }
1766 }
1767
1768 /* usb */
1769 {
1770 CUSBController ctl = cmachine.GetUSBController();
1771
1772 if (!ctl.isNull())
1773 {
1774 /* the USB controller may be unavailable (i.e. in VirtualBox OSE) */
1775
1776 ctl.SetEnabled (cbEnableUSBController->isChecked());
1777
1778 /*
1779 * first, remove all old filters (only if the list is changed,
1780 * not only individual properties of filters)
1781 */
1782 if (mUSBFilterListModified)
1783 for (ulong count = ctl.GetDeviceFilters().GetCount(); count; -- count)
1784 ctl.RemoveDeviceFilter (0);
1785
1786 /* then add all new filters */
1787 for (QListViewItem *item = lvUSBFilters->firstChild(); item;
1788 item = item->nextSibling())
1789 {
1790 USBListItem *uli = static_cast <USBListItem *> (item);
1791 VBoxUSBFilterSettings *settings =
1792 static_cast <VBoxUSBFilterSettings *>
1793 (wstUSBFilters->widget (uli->mId));
1794 Assert (settings);
1795
1796 COMResult res = settings->putBackToFilter();
1797 if (!res.isOk())
1798 return res;
1799
1800 CUSBDeviceFilter filter = settings->filter();
1801 filter.SetActive (uli->isOn());
1802
1803 if (mUSBFilterListModified)
1804 ctl.InsertDeviceFilter (~0, filter);
1805 }
1806 }
1807
1808 mUSBFilterListModified = false;
1809 }
1810
1811 /* vrdp */
1812 {
1813 CVRDPServer vrdp = cmachine.GetVRDPServer();
1814
1815 if (!vrdp.isNull())
1816 {
1817 /* VRDP may be unavailable (i.e. in VirtualBox OSE) */
1818 vrdp.SetEnabled (grbVRDP->isChecked());
1819 vrdp.SetPort (leVRDPPort->text().toULong());
1820 vrdp.SetAuthType (vboxGlobal().toVRDPAuthType (cbVRDPAuthType->currentText()));
1821 vrdp.SetAuthTimeout (leVRDPTimeout->text().toULong());
1822 }
1823 }
1824
1825 /* shared folders */
1826 {
1827 mSharedFolders->putBackToMachine();
1828 }
1829
1830 return COMResult();
1831}
1832
1833
1834void VBoxVMSettingsDlg::showImageManagerHDA() { showVDImageManager (&uuidHDA, cbHDA); }
1835void VBoxVMSettingsDlg::showImageManagerHDB() { showVDImageManager (&uuidHDB, cbHDB); }
1836void VBoxVMSettingsDlg::showImageManagerHDD() { showVDImageManager (&uuidHDD, cbHDD); }
1837void VBoxVMSettingsDlg::showImageManagerISODVD() { showVDImageManager (&uuidISODVD, cbISODVD); }
1838void VBoxVMSettingsDlg::showImageManagerISOFloppy() { showVDImageManager(&uuidISOFloppy, cbISOFloppy); }
1839
1840void VBoxVMSettingsDlg::showVDImageManager (QUuid *id, VBoxMediaComboBox *cbb, QLabel*)
1841{
1842 bootSequenceChanged();
1843
1844 VBoxDefs::DiskType type = VBoxDefs::InvalidType;
1845 if (cbb == cbISODVD)
1846 type = VBoxDefs::CD;
1847 else if (cbb == cbISOFloppy)
1848 type = VBoxDefs::FD;
1849 else
1850 type = VBoxDefs::HD;
1851
1852 VBoxDiskImageManagerDlg dlg (this, "VBoxDiskImageManagerDlg",
1853 WType_Dialog | WShowModal);
1854 QUuid machineId = cmachine.GetId();
1855 dlg.setup (type, true, &machineId, true /* aRefresh */, cmachine);
1856 *id = dlg.exec() == VBoxDiskImageManagerDlg::Accepted ?
1857 dlg.getSelectedUuid() : cbb->getId();
1858 cbb->setCurrentItem (*id);
1859 cbb->setFocus();
1860
1861 /* revalidate pages with custom validation */
1862 wvalHDD->revalidate();
1863 wvalDVD->revalidate();
1864 wvalFloppy->revalidate();
1865}
1866
1867void VBoxVMSettingsDlg::addNetworkAdapter (const CNetworkAdapter &aAdapter)
1868{
1869 VBoxVMNetworkSettings *page = new VBoxVMNetworkSettings();
1870 page->loadList (mInterfaceList);
1871 page->getFromAdapter (aAdapter);
1872 tbwNetwork->addTab (page, QString (tr ("Adapter %1", "network"))
1873 .arg (aAdapter.GetSlot()));
1874
1875 /* fix the tab order so that main dialog's buttons are always the last */
1876 setTabOrder (page->leTAPTerminate, buttonHelp);
1877 setTabOrder (buttonHelp, buttonOk);
1878 setTabOrder (buttonOk, buttonCancel);
1879
1880 /* setup validation */
1881 QIWidgetValidator *wval = new QIWidgetValidator (pageNetwork, this);
1882 connect (page->grbEnabled, SIGNAL (toggled (bool)), wval, SLOT (revalidate()));
1883 connect (page->cbNetworkAttachment, SIGNAL (activated (const QString &)),
1884 wval, SLOT (revalidate()));
1885
1886#if defined Q_WS_WIN
1887 connect (page->lbHostInterface, SIGNAL (highlighted (QListBoxItem*)),
1888 wval, SLOT (revalidate()));
1889 connect (tbwNetwork, SIGNAL (currentChanged (QWidget*)),
1890 this, SLOT (networkPageUpdate (QWidget*)));
1891 connect (page, SIGNAL (listChanged (QWidget*)),
1892 this, SLOT (updateInterfaces (QWidget*)));
1893#endif
1894
1895 connect (wval, SIGNAL (validityChanged (const QIWidgetValidator *)),
1896 this, SLOT (enableOk (const QIWidgetValidator *)));
1897 connect (wval, SIGNAL (isValidRequested (QIWidgetValidator *)),
1898 this, SLOT (revalidate( QIWidgetValidator *)));
1899
1900 page->setValidator (wval);
1901 page->revalidate();
1902}
1903
1904void VBoxVMSettingsDlg::slRAM_valueChanged( int val )
1905{
1906 leRAM->setText( QString().setNum( val ) );
1907}
1908
1909void VBoxVMSettingsDlg::leRAM_textChanged( const QString &text )
1910{
1911 slRAM->setValue( text.toInt() );
1912}
1913
1914void VBoxVMSettingsDlg::slVRAM_valueChanged( int val )
1915{
1916 leVRAM->setText( QString().setNum( val ) );
1917}
1918
1919void VBoxVMSettingsDlg::leVRAM_textChanged( const QString &text )
1920{
1921 slVRAM->setValue( text.toInt() );
1922}
1923
1924void VBoxVMSettingsDlg::cbOS_activated (int item)
1925{
1926 Q_UNUSED (item);
1927/// @todo (dmik) remove?
1928// CGuestOSType type = vboxGlobal().vmGuestOSType (item);
1929// txRAMBest->setText (tr ("<qt>Best&nbsp;%1&nbsp;MB<qt>")
1930// .arg (type.GetRecommendedRAM()));
1931// txVRAMBest->setText (tr ("<qt>Best&nbsp;%1&nbsp;MB</qt>")
1932// .arg (type.GetRecommendedVRAM()));
1933 txRAMBest->setText (QString::null);
1934 txVRAMBest->setText (QString::null);
1935}
1936
1937void VBoxVMSettingsDlg::tbResetSavedStateFolder_clicked()
1938{
1939 /*
1940 * do this instead of le->setText (QString::null) to cause
1941 * isModified() return true
1942 */
1943 leSnapshotFolder->selectAll();
1944 leSnapshotFolder->del();
1945}
1946
1947void VBoxVMSettingsDlg::tbSelectSavedStateFolder_clicked()
1948{
1949 QString settingsFolder = VBoxGlobal::getFirstExistingDir (leSnapshotFolder->text());
1950 if (settingsFolder.isNull())
1951 settingsFolder = QFileInfo (cmachine.GetSettingsFilePath()).dirPath (true);
1952
1953 QString folder = vboxGlobal().getExistingDirectory (settingsFolder, this);
1954 if (folder.isNull())
1955 return;
1956
1957 folder = QDir::convertSeparators (folder);
1958 /* remove trailing slash if any */
1959 folder.remove (QRegExp ("[\\\\/]$"));
1960
1961 /*
1962 * do this instead of le->setText (folder) to cause
1963 * isModified() return true
1964 */
1965 leSnapshotFolder->selectAll();
1966 leSnapshotFolder->insert (folder);
1967}
1968
1969// USB Filter stuff
1970////////////////////////////////////////////////////////////////////////////////
1971
1972void VBoxVMSettingsDlg::addUSBFilter (const CUSBDeviceFilter &aFilter, bool isNew)
1973{
1974 QListViewItem *currentItem = isNew
1975 ? lvUSBFilters->currentItem()
1976 : lvUSBFilters->lastItem();
1977
1978 VBoxUSBFilterSettings *settings = new VBoxUSBFilterSettings (wstUSBFilters);
1979 settings->setup (VBoxUSBFilterSettings::MachineType);
1980 settings->getFromFilter (aFilter);
1981
1982 USBListItem *item = new USBListItem (lvUSBFilters, currentItem);
1983 item->setOn (aFilter.GetActive());
1984 item->setText (lvUSBFilters_Name, aFilter.GetName());
1985
1986 item->mId = wstUSBFilters->addWidget (settings);
1987
1988 /* fix the tab order so that main dialog's buttons are always the last */
1989 setTabOrder (settings->focusProxy(), buttonHelp);
1990 setTabOrder (buttonHelp, buttonOk);
1991 setTabOrder (buttonOk, buttonCancel);
1992
1993 if (isNew)
1994 {
1995 lvUSBFilters->setSelected (item, true);
1996 lvUSBFilters_currentChanged (item);
1997 settings->leUSBFilterName->setFocus();
1998 }
1999
2000 connect (settings->leUSBFilterName, SIGNAL (textChanged (const QString &)),
2001 this, SLOT (lvUSBFilters_setCurrentText (const QString &)));
2002
2003 /* setup validation */
2004
2005 QIWidgetValidator *wval = new QIWidgetValidator (settings, settings);
2006 connect (wval, SIGNAL (validityChanged (const QIWidgetValidator *)),
2007 this, SLOT (enableOk (const QIWidgetValidator *)));
2008
2009 wval->revalidate();
2010}
2011
2012void VBoxVMSettingsDlg::lvUSBFilters_currentChanged (QListViewItem *item)
2013{
2014 if (item && lvUSBFilters->selectedItem() != item)
2015 lvUSBFilters->setSelected (item, true);
2016
2017 tbRemoveUSBFilter->setEnabled (!!item);
2018
2019 tbUSBFilterUp->setEnabled (!!item && item->itemAbove());
2020 tbUSBFilterDown->setEnabled (!!item && item->itemBelow());
2021
2022 if (item)
2023 {
2024 USBListItem *uli = static_cast <USBListItem *> (item);
2025 wstUSBFilters->raiseWidget (uli->mId);
2026 }
2027 else
2028 {
2029 /* raise the disabled widget */
2030 wstUSBFilters->raiseWidget (0);
2031 }
2032}
2033
2034void VBoxVMSettingsDlg::lvUSBFilters_setCurrentText (const QString &aText)
2035{
2036 QListViewItem *item = lvUSBFilters->currentItem();
2037 Assert (item);
2038
2039 item->setText (lvUSBFilters_Name, aText);
2040}
2041
2042void VBoxVMSettingsDlg::tbAddUSBFilter_clicked()
2043{
2044 /* search for the max available filter index */
2045 int maxFilterIndex = 0;
2046 QString usbFilterName = tr ("New Filter %1", "usb");
2047 QRegExp regExp (QString ("^") + usbFilterName.arg ("([0-9]+)") + QString ("$"));
2048 QListViewItemIterator iterator (lvUSBFilters);
2049 while (*iterator)
2050 {
2051 QString filterName = (*iterator)->text (lvUSBFilters_Name);
2052 int pos = regExp.search (filterName);
2053 if (pos != -1)
2054 maxFilterIndex = regExp.cap (1).toInt() > maxFilterIndex ?
2055 regExp.cap (1).toInt() : maxFilterIndex;
2056 ++ iterator;
2057 }
2058
2059 /* creating new usb filter */
2060 CUSBDeviceFilter filter = cmachine.GetUSBController()
2061 .CreateDeviceFilter (usbFilterName.arg (maxFilterIndex + 1));
2062
2063 filter.SetActive (true);
2064 addUSBFilter (filter, true /* isNew */);
2065
2066 mUSBFilterListModified = true;
2067}
2068
2069void VBoxVMSettingsDlg::tbAddUSBFilterFrom_clicked()
2070{
2071 usbDevicesMenu->exec (QCursor::pos());
2072}
2073
2074void VBoxVMSettingsDlg::menuAddUSBFilterFrom_activated (int aIndex)
2075{
2076 CUSBDevice usb = usbDevicesMenu->getUSB (aIndex);
2077 /* if null then some other item but a USB device is selected */
2078 if (usb.isNull())
2079 return;
2080
2081 CUSBDeviceFilter filter = cmachine.GetUSBController()
2082 .CreateDeviceFilter (vboxGlobal().details (usb));
2083
2084 filter.SetVendorId (QString().sprintf ("%04hX", usb.GetVendorId()));
2085 filter.SetProductId (QString().sprintf ("%04hX", usb.GetProductId()));
2086 filter.SetRevision (QString().sprintf ("%04hX", usb.GetRevision()));
2087 filter.SetPort (QString().sprintf ("%04hX", usb.GetPort()));
2088 filter.SetManufacturer (usb.GetManufacturer());
2089 filter.SetProduct (usb.GetProduct());
2090 filter.SetSerialNumber (usb.GetSerialNumber());
2091 filter.SetRemote (usb.GetRemote() ? "yes" : "no");
2092
2093 filter.SetActive (true);
2094 addUSBFilter (filter, true /* isNew */);
2095
2096 mUSBFilterListModified = true;
2097}
2098
2099void VBoxVMSettingsDlg::tbRemoveUSBFilter_clicked()
2100{
2101 QListViewItem *item = lvUSBFilters->currentItem();
2102 Assert (item);
2103
2104 USBListItem *uli = static_cast <USBListItem *> (item);
2105 QWidget *settings = wstUSBFilters->widget (uli->mId);
2106 Assert (settings);
2107 wstUSBFilters->removeWidget (settings);
2108 delete settings;
2109
2110 delete item;
2111
2112 lvUSBFilters->setSelected (lvUSBFilters->currentItem(), true);
2113 mUSBFilterListModified = true;
2114}
2115
2116void VBoxVMSettingsDlg::tbUSBFilterUp_clicked()
2117{
2118 QListViewItem *item = lvUSBFilters->currentItem();
2119 Assert (item);
2120
2121 QListViewItem *itemAbove = item->itemAbove();
2122 Assert (itemAbove);
2123 itemAbove = itemAbove->itemAbove();
2124
2125 if (!itemAbove)
2126 {
2127 /* overcome Qt stupidity */
2128 item->itemAbove()->moveItem (item);
2129 }
2130 else
2131 item->moveItem (itemAbove);
2132
2133 lvUSBFilters_currentChanged (item);
2134 mUSBFilterListModified = true;
2135}
2136
2137void VBoxVMSettingsDlg::tbUSBFilterDown_clicked()
2138{
2139 QListViewItem *item = lvUSBFilters->currentItem();
2140 Assert (item);
2141
2142 QListViewItem *itemBelow = item->itemBelow();
2143 Assert (itemBelow);
2144
2145 item->moveItem (itemBelow);
2146
2147 lvUSBFilters_currentChanged (item);
2148 mUSBFilterListModified = true;
2149}
2150
2151#include "VBoxVMSettingsDlg.ui.moc"
2152
Note: See TracBrowser for help on using the repository browser.

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