VirtualBox

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

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

1750: Add CDROM configuration to "Create VM" wizard:

Done as requested:
The "FirstRun" flag is reseted upon every boot-sequence or hd/cd/fd settings related widget changed (comment #17).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 73.1 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 cbHostDVD->insertItem (hostDVD.GetName(), id);
1429 hostDVDs [id] = hostDVD;
1430 ++ id;
1431 }
1432
1433 CDVDDrive dvd = machine.GetDVDDrive();
1434 switch (dvd.GetState())
1435 {
1436 case CEnums::HostDriveCaptured:
1437 {
1438 CHostDVDDrive drv = dvd.GetHostDrive();
1439 QString name = drv.GetName();
1440 if (coll.FindByName (name).isNull())
1441 {
1442 /*
1443 * if the DVD drive is not currently available,
1444 * add it to the end of the list with a special mark
1445 */
1446 cbHostDVD->insertItem ("* " + name);
1447 cbHostDVD->setCurrentItem (cbHostDVD->count() - 1);
1448 }
1449 else
1450 {
1451 /* this will select the correct item from the prepared list */
1452 cbHostDVD->setCurrentText (name);
1453 }
1454 rbHostDVD->setChecked (true);
1455 break;
1456 }
1457 case CEnums::ImageMounted:
1458 {
1459 CDVDImage img = dvd.GetImage();
1460 QString src = img.GetFilePath();
1461 AssertMsg (!src.isNull(), ("Image file must not be null"));
1462 QFileInfo fi (src);
1463 rbISODVD->setChecked (true);
1464 uuidISODVD = QUuid (img.GetId());
1465 break;
1466 }
1467 case CEnums::NotMounted:
1468 {
1469 bgDVD->setChecked(false);
1470 break;
1471 }
1472 default:
1473 AssertMsgFailed (("invalid DVD state: %d\n", dvd.GetState()));
1474 }
1475 }
1476
1477 /* audio */
1478 {
1479 CAudioAdapter audio = machine.GetAudioAdapter();
1480 grbAudio->setChecked (audio.GetEnabled());
1481 cbAudioDriver->setCurrentText (vboxGlobal().toString (audio.GetAudioDriver()));
1482 }
1483
1484 /* network */
1485 {
1486 ulong count = vbox.GetSystemProperties().GetNetworkAdapterCount();
1487 for (ulong slot = 0; slot < count; ++ slot)
1488 {
1489 CNetworkAdapter adapter = machine.GetNetworkAdapter (slot);
1490 addNetworkAdapter (adapter);
1491 }
1492 }
1493
1494 /* USB */
1495 {
1496 CUSBController ctl = machine.GetUSBController();
1497
1498 if (ctl.isNull())
1499 {
1500 /* disable the USB controller category if the USB controller is
1501 * not available (i.e. in VirtualBox OSE) */
1502
1503 QListViewItem *usbItem = listView->findItem ("#usb", listView_Link);
1504 Assert (usbItem);
1505 if (usbItem)
1506 usbItem->setVisible (false);
1507
1508 /* disable validators if any */
1509 pageUSB->setEnabled (false);
1510
1511 /* Show an error message (if there is any).
1512 * Note that we don't use the generic cannotLoadMachineSettings()
1513 * call here because we want this message to be suppressable. */
1514 vboxProblem().cannotAccessUSB (machine);
1515 }
1516 else
1517 {
1518 cbEnableUSBController->setChecked (ctl.GetEnabled());
1519
1520 CUSBDeviceFilterEnumerator en = ctl.GetDeviceFilters().Enumerate();
1521 while (en.HasMore())
1522 addUSBFilter (en.GetNext(), false /* isNew */);
1523
1524 lvUSBFilters->setCurrentItem (lvUSBFilters->firstChild());
1525 /* silly Qt -- doesn't emit currentChanged after adding the
1526 * first item to an empty list */
1527 lvUSBFilters_currentChanged (lvUSBFilters->firstChild());
1528 }
1529 }
1530
1531 /* vrdp */
1532 {
1533 CVRDPServer vrdp = machine.GetVRDPServer();
1534
1535 if (vrdp.isNull())
1536 {
1537 /* disable the VRDP category if VRDP is
1538 * not available (i.e. in VirtualBox OSE) */
1539
1540 QListViewItem *vrdpItem = listView->findItem ("#vrdp", listView_Link);
1541 Assert (vrdpItem);
1542 if (vrdpItem)
1543 vrdpItem->setVisible (false);
1544
1545 /* disable validators if any */
1546 pageVRDP->setEnabled (false);
1547
1548 /* if machine has something to say, show the message */
1549 vboxProblem().cannotLoadMachineSettings (machine, false /* strict */);
1550 }
1551 else
1552 {
1553 grbVRDP->setChecked (vrdp.GetEnabled());
1554 leVRDPPort->setText (QString::number (vrdp.GetPort()));
1555 cbVRDPAuthType->setCurrentText (vboxGlobal().toString (vrdp.GetAuthType()));
1556 leVRDPTimeout->setText (QString::number (vrdp.GetAuthTimeout()));
1557 }
1558 }
1559
1560 /* shared folders */
1561 {
1562 mSharedFolders->getFromMachine (machine);
1563 }
1564
1565 /* request for media shortcuts update */
1566 cbHDA->setBelongsTo (machine.GetId());
1567 cbHDB->setBelongsTo (machine.GetId());
1568 cbHDD->setBelongsTo (machine.GetId());
1569 updateShortcuts();
1570
1571 /* revalidate pages with custom validation */
1572 wvalHDD->revalidate();
1573 wvalDVD->revalidate();
1574 wvalFloppy->revalidate();
1575 wvalVRDP->revalidate();
1576}
1577
1578
1579COMResult VBoxVMSettingsDlg::putBackToMachine()
1580{
1581 CVirtualBox vbox = vboxGlobal().virtualBox();
1582 CBIOSSettings biosSettings = cmachine.GetBIOSSettings();
1583
1584 /* name */
1585 cmachine.SetName (leName->text());
1586
1587 /* OS type */
1588 CGuestOSType type = vboxGlobal().vmGuestOSType (cbOS->currentItem());
1589 AssertMsg (!type.isNull(), ("vmGuestOSType() must return non-null type"));
1590 cmachine.SetOSTypeId (type.GetId());
1591
1592 /* RAM size */
1593 cmachine.SetMemorySize (slRAM->value());
1594
1595 /* VRAM size */
1596 cmachine.SetVRAMSize (slVRAM->value());
1597
1598 /* boot order */
1599 tblBootOrder->putBackToMachine (cmachine);
1600
1601 /* ACPI */
1602 biosSettings.SetACPIEnabled (chbEnableACPI->isChecked());
1603
1604 /* IO APIC */
1605 biosSettings.SetIOAPICEnabled (chbEnableIOAPIC->isChecked());
1606
1607 /* Saved state folder */
1608 if (leSnapshotFolder->isModified())
1609 cmachine.SetSnapshotFolder (leSnapshotFolder->text());
1610
1611 /* Description */
1612 cmachine.SetDescription (teDescription->text());
1613
1614 /* Shared clipboard mode */
1615 cmachine.SetClipboardMode ((CEnums::ClipboardMode)cbSharedClipboard->currentItem());
1616
1617 /* hard disk images */
1618 {
1619 struct
1620 {
1621 CEnums::DiskControllerType ctl;
1622 LONG dev;
1623 struct {
1624 QGroupBox *grb;
1625 QUuid *uuid;
1626 } data;
1627 }
1628 diskSet[] =
1629 {
1630 { CEnums::IDE0Controller, 0, {grbHDA, &uuidHDA} },
1631 { CEnums::IDE0Controller, 1, {grbHDB, &uuidHDB} },
1632 { CEnums::IDE1Controller, 1, {grbHDD, &uuidHDD} }
1633 };
1634
1635 /*
1636 * first, detach all disks (to ensure we can reattach them to different
1637 * controllers / devices, when appropriate)
1638 */
1639 CHardDiskAttachmentEnumerator en =
1640 cmachine.GetHardDiskAttachments().Enumerate();
1641 while (en.HasMore())
1642 {
1643 CHardDiskAttachment hda = en.GetNext();
1644 for (uint i = 0; i < SIZEOF_ARRAY (diskSet); i++)
1645 {
1646 if (diskSet [i].ctl == hda.GetController() &&
1647 diskSet [i].dev == hda.GetDeviceNumber())
1648 {
1649 cmachine.DetachHardDisk (diskSet [i].ctl, diskSet [i].dev);
1650 if (!cmachine.isOk())
1651 vboxProblem().cannotDetachHardDisk (
1652 this, cmachine, diskSet [i].ctl, diskSet [i].dev);
1653 }
1654 }
1655 }
1656
1657 /* now, attach new disks */
1658 for (uint i = 0; i < SIZEOF_ARRAY (diskSet); i++)
1659 {
1660 QUuid *newId = diskSet [i].data.uuid;
1661 if (diskSet [i].data.grb->isChecked() && !(*newId).isNull())
1662 {
1663 cmachine.AttachHardDisk (*newId, diskSet [i].ctl, diskSet [i].dev);
1664 if (!cmachine.isOk())
1665 vboxProblem().cannotAttachHardDisk (
1666 this, cmachine, *newId, diskSet [i].ctl, diskSet [i].dev);
1667 }
1668 }
1669 }
1670
1671 /* floppy image */
1672 {
1673 CFloppyDrive floppy = cmachine.GetFloppyDrive();
1674 if (!bgFloppy->isChecked())
1675 {
1676 floppy.Unmount();
1677 }
1678 else if (rbHostFloppy->isChecked())
1679 {
1680 int id = cbHostFloppy->currentItem();
1681 Assert (id >= 0);
1682 if (id < (int) hostFloppies.count())
1683 floppy.CaptureHostDrive (hostFloppies [id]);
1684 /*
1685 * otherwise the selected drive is not yet available, leave it
1686 * as is
1687 */
1688 }
1689 else if (rbISOFloppy->isChecked())
1690 {
1691 Assert (!uuidISOFloppy.isNull());
1692 floppy.MountImage (uuidISOFloppy);
1693 }
1694 }
1695
1696 /* CD/DVD-ROM image */
1697 {
1698 CDVDDrive dvd = cmachine.GetDVDDrive();
1699 if (!bgDVD->isChecked())
1700 {
1701 dvd.Unmount();
1702 }
1703 else if (rbHostDVD->isChecked())
1704 {
1705 int id = cbHostDVD->currentItem();
1706 Assert (id >= 0);
1707 if (id < (int) hostDVDs.count())
1708 dvd.CaptureHostDrive (hostDVDs [id]);
1709 /*
1710 * otherwise the selected drive is not yet available, leave it
1711 * as is
1712 */
1713 }
1714 else if (rbISODVD->isChecked())
1715 {
1716 Assert (!uuidISODVD.isNull());
1717 dvd.MountImage (uuidISODVD);
1718 }
1719 }
1720
1721 /* Clear the "GUI_FirstRun" extra data key in case of one of the boot
1722 * settings was changed */
1723 if (mIsBootSettingsChanged)
1724 cmachine.SetExtraData (GUI_FirstRun, QString::null);
1725
1726 /* audio */
1727 {
1728 CAudioAdapter audio = cmachine.GetAudioAdapter();
1729 audio.SetAudioDriver (vboxGlobal().toAudioDriverType (cbAudioDriver->currentText()));
1730 audio.SetEnabled (grbAudio->isChecked());
1731 AssertWrapperOk (audio);
1732 }
1733
1734 /* network */
1735 {
1736 for (int index = 0; index < tbwNetwork->count(); index++)
1737 {
1738 VBoxVMNetworkSettings *page =
1739 (VBoxVMNetworkSettings *) tbwNetwork->page (index);
1740 Assert (page);
1741 page->putBackToAdapter();
1742 }
1743 }
1744
1745 /* usb */
1746 {
1747 CUSBController ctl = cmachine.GetUSBController();
1748
1749 if (!ctl.isNull())
1750 {
1751 /* the USB controller may be unavailable (i.e. in VirtualBox OSE) */
1752
1753 ctl.SetEnabled (cbEnableUSBController->isChecked());
1754
1755 /*
1756 * first, remove all old filters (only if the list is changed,
1757 * not only individual properties of filters)
1758 */
1759 if (mUSBFilterListModified)
1760 for (ulong count = ctl.GetDeviceFilters().GetCount(); count; -- count)
1761 ctl.RemoveDeviceFilter (0);
1762
1763 /* then add all new filters */
1764 for (QListViewItem *item = lvUSBFilters->firstChild(); item;
1765 item = item->nextSibling())
1766 {
1767 USBListItem *uli = static_cast <USBListItem *> (item);
1768 VBoxUSBFilterSettings *settings =
1769 static_cast <VBoxUSBFilterSettings *>
1770 (wstUSBFilters->widget (uli->mId));
1771 Assert (settings);
1772
1773 COMResult res = settings->putBackToFilter();
1774 if (!res.isOk())
1775 return res;
1776
1777 CUSBDeviceFilter filter = settings->filter();
1778 filter.SetActive (uli->isOn());
1779
1780 if (mUSBFilterListModified)
1781 ctl.InsertDeviceFilter (~0, filter);
1782 }
1783 }
1784
1785 mUSBFilterListModified = false;
1786 }
1787
1788 /* vrdp */
1789 {
1790 CVRDPServer vrdp = cmachine.GetVRDPServer();
1791
1792 if (!vrdp.isNull())
1793 {
1794 /* VRDP may be unavailable (i.e. in VirtualBox OSE) */
1795 vrdp.SetEnabled (grbVRDP->isChecked());
1796 vrdp.SetPort (leVRDPPort->text().toULong());
1797 vrdp.SetAuthType (vboxGlobal().toVRDPAuthType (cbVRDPAuthType->currentText()));
1798 vrdp.SetAuthTimeout (leVRDPTimeout->text().toULong());
1799 }
1800 }
1801
1802 /* shared folders */
1803 {
1804 mSharedFolders->putBackToMachine();
1805 }
1806
1807 return COMResult();
1808}
1809
1810
1811void VBoxVMSettingsDlg::showImageManagerHDA() { showVDImageManager (&uuidHDA, cbHDA); }
1812void VBoxVMSettingsDlg::showImageManagerHDB() { showVDImageManager (&uuidHDB, cbHDB); }
1813void VBoxVMSettingsDlg::showImageManagerHDD() { showVDImageManager (&uuidHDD, cbHDD); }
1814void VBoxVMSettingsDlg::showImageManagerISODVD() { showVDImageManager (&uuidISODVD, cbISODVD); }
1815void VBoxVMSettingsDlg::showImageManagerISOFloppy() { showVDImageManager(&uuidISOFloppy, cbISOFloppy); }
1816
1817void VBoxVMSettingsDlg::showVDImageManager (QUuid *id, VBoxMediaComboBox *cbb, QLabel*)
1818{
1819 bootSequenceChanged();
1820
1821 VBoxDefs::DiskType type = VBoxDefs::InvalidType;
1822 if (cbb == cbISODVD)
1823 type = VBoxDefs::CD;
1824 else if (cbb == cbISOFloppy)
1825 type = VBoxDefs::FD;
1826 else
1827 type = VBoxDefs::HD;
1828
1829 VBoxDiskImageManagerDlg dlg (this, "VBoxDiskImageManagerDlg",
1830 WType_Dialog | WShowModal);
1831 QUuid machineId = cmachine.GetId();
1832 dlg.setup (type, true, &machineId, true /* aRefresh */, cmachine);
1833 *id = dlg.exec() == VBoxDiskImageManagerDlg::Accepted ?
1834 dlg.getSelectedUuid() : cbb->getId();
1835 cbb->setCurrentItem (*id);
1836 cbb->setFocus();
1837
1838 /* revalidate pages with custom validation */
1839 wvalHDD->revalidate();
1840 wvalDVD->revalidate();
1841 wvalFloppy->revalidate();
1842}
1843
1844void VBoxVMSettingsDlg::addNetworkAdapter (const CNetworkAdapter &aAdapter)
1845{
1846 VBoxVMNetworkSettings *page = new VBoxVMNetworkSettings();
1847 page->loadList (mInterfaceList);
1848 page->getFromAdapter (aAdapter);
1849 tbwNetwork->addTab (page, QString (tr ("Adapter %1", "network"))
1850 .arg (aAdapter.GetSlot()));
1851
1852 /* fix the tab order so that main dialog's buttons are always the last */
1853 setTabOrder (page->leTAPTerminate, buttonHelp);
1854 setTabOrder (buttonHelp, buttonOk);
1855 setTabOrder (buttonOk, buttonCancel);
1856
1857 /* setup validation */
1858 QIWidgetValidator *wval = new QIWidgetValidator (pageNetwork, this);
1859 connect (page->grbEnabled, SIGNAL (toggled (bool)), wval, SLOT (revalidate()));
1860 connect (page->cbNetworkAttachment, SIGNAL (activated (const QString &)),
1861 wval, SLOT (revalidate()));
1862
1863#if defined Q_WS_WIN
1864 connect (page->lbHostInterface, SIGNAL (highlighted (QListBoxItem*)),
1865 wval, SLOT (revalidate()));
1866 connect (tbwNetwork, SIGNAL (currentChanged (QWidget*)),
1867 this, SLOT (networkPageUpdate (QWidget*)));
1868 connect (page, SIGNAL (listChanged (QWidget*)),
1869 this, SLOT (updateInterfaces (QWidget*)));
1870#endif
1871
1872 connect (wval, SIGNAL (validityChanged (const QIWidgetValidator *)),
1873 this, SLOT (enableOk (const QIWidgetValidator *)));
1874 connect (wval, SIGNAL (isValidRequested (QIWidgetValidator *)),
1875 this, SLOT (revalidate( QIWidgetValidator *)));
1876
1877 page->setValidator (wval);
1878 page->revalidate();
1879}
1880
1881void VBoxVMSettingsDlg::slRAM_valueChanged( int val )
1882{
1883 leRAM->setText( QString().setNum( val ) );
1884}
1885
1886void VBoxVMSettingsDlg::leRAM_textChanged( const QString &text )
1887{
1888 slRAM->setValue( text.toInt() );
1889}
1890
1891void VBoxVMSettingsDlg::slVRAM_valueChanged( int val )
1892{
1893 leVRAM->setText( QString().setNum( val ) );
1894}
1895
1896void VBoxVMSettingsDlg::leVRAM_textChanged( const QString &text )
1897{
1898 slVRAM->setValue( text.toInt() );
1899}
1900
1901void VBoxVMSettingsDlg::cbOS_activated (int item)
1902{
1903 Q_UNUSED (item);
1904/// @todo (dmik) remove?
1905// CGuestOSType type = vboxGlobal().vmGuestOSType (item);
1906// txRAMBest->setText (tr ("<qt>Best&nbsp;%1&nbsp;MB<qt>")
1907// .arg (type.GetRecommendedRAM()));
1908// txVRAMBest->setText (tr ("<qt>Best&nbsp;%1&nbsp;MB</qt>")
1909// .arg (type.GetRecommendedVRAM()));
1910 txRAMBest->setText (QString::null);
1911 txVRAMBest->setText (QString::null);
1912}
1913
1914void VBoxVMSettingsDlg::tbResetSavedStateFolder_clicked()
1915{
1916 /*
1917 * do this instead of le->setText (QString::null) to cause
1918 * isModified() return true
1919 */
1920 leSnapshotFolder->selectAll();
1921 leSnapshotFolder->del();
1922}
1923
1924void VBoxVMSettingsDlg::tbSelectSavedStateFolder_clicked()
1925{
1926 QString settingsFolder = VBoxGlobal::getFirstExistingDir (leSnapshotFolder->text());
1927 if (settingsFolder.isNull())
1928 settingsFolder = QFileInfo (cmachine.GetSettingsFilePath()).dirPath (true);
1929
1930 QString folder = vboxGlobal().getExistingDirectory (settingsFolder, this);
1931 if (folder.isNull())
1932 return;
1933
1934 folder = QDir::convertSeparators (folder);
1935 /* remove trailing slash if any */
1936 folder.remove (QRegExp ("[\\\\/]$"));
1937
1938 /*
1939 * do this instead of le->setText (folder) to cause
1940 * isModified() return true
1941 */
1942 leSnapshotFolder->selectAll();
1943 leSnapshotFolder->insert (folder);
1944}
1945
1946// USB Filter stuff
1947////////////////////////////////////////////////////////////////////////////////
1948
1949void VBoxVMSettingsDlg::addUSBFilter (const CUSBDeviceFilter &aFilter, bool isNew)
1950{
1951 QListViewItem *currentItem = isNew
1952 ? lvUSBFilters->currentItem()
1953 : lvUSBFilters->lastItem();
1954
1955 VBoxUSBFilterSettings *settings = new VBoxUSBFilterSettings (wstUSBFilters);
1956 settings->setup (VBoxUSBFilterSettings::MachineType);
1957 settings->getFromFilter (aFilter);
1958
1959 USBListItem *item = new USBListItem (lvUSBFilters, currentItem);
1960 item->setOn (aFilter.GetActive());
1961 item->setText (lvUSBFilters_Name, aFilter.GetName());
1962
1963 item->mId = wstUSBFilters->addWidget (settings);
1964
1965 /* fix the tab order so that main dialog's buttons are always the last */
1966 setTabOrder (settings->focusProxy(), buttonHelp);
1967 setTabOrder (buttonHelp, buttonOk);
1968 setTabOrder (buttonOk, buttonCancel);
1969
1970 if (isNew)
1971 {
1972 lvUSBFilters->setSelected (item, true);
1973 lvUSBFilters_currentChanged (item);
1974 settings->leUSBFilterName->setFocus();
1975 }
1976
1977 connect (settings->leUSBFilterName, SIGNAL (textChanged (const QString &)),
1978 this, SLOT (lvUSBFilters_setCurrentText (const QString &)));
1979
1980 /* setup validation */
1981
1982 QIWidgetValidator *wval = new QIWidgetValidator (settings, settings);
1983 connect (wval, SIGNAL (validityChanged (const QIWidgetValidator *)),
1984 this, SLOT (enableOk (const QIWidgetValidator *)));
1985
1986 wval->revalidate();
1987}
1988
1989void VBoxVMSettingsDlg::lvUSBFilters_currentChanged (QListViewItem *item)
1990{
1991 if (item && lvUSBFilters->selectedItem() != item)
1992 lvUSBFilters->setSelected (item, true);
1993
1994 tbRemoveUSBFilter->setEnabled (!!item);
1995
1996 tbUSBFilterUp->setEnabled (!!item && item->itemAbove());
1997 tbUSBFilterDown->setEnabled (!!item && item->itemBelow());
1998
1999 if (item)
2000 {
2001 USBListItem *uli = static_cast <USBListItem *> (item);
2002 wstUSBFilters->raiseWidget (uli->mId);
2003 }
2004 else
2005 {
2006 /* raise the disabled widget */
2007 wstUSBFilters->raiseWidget (0);
2008 }
2009}
2010
2011void VBoxVMSettingsDlg::lvUSBFilters_setCurrentText (const QString &aText)
2012{
2013 QListViewItem *item = lvUSBFilters->currentItem();
2014 Assert (item);
2015
2016 item->setText (lvUSBFilters_Name, aText);
2017}
2018
2019void VBoxVMSettingsDlg::tbAddUSBFilter_clicked()
2020{
2021 /* search for the max available filter index */
2022 int maxFilterIndex = 0;
2023 QString usbFilterName = tr ("New Filter %1", "usb");
2024 QRegExp regExp (QString ("^") + usbFilterName.arg ("([0-9]+)") + QString ("$"));
2025 QListViewItemIterator iterator (lvUSBFilters);
2026 while (*iterator)
2027 {
2028 QString filterName = (*iterator)->text (lvUSBFilters_Name);
2029 int pos = regExp.search (filterName);
2030 if (pos != -1)
2031 maxFilterIndex = regExp.cap (1).toInt() > maxFilterIndex ?
2032 regExp.cap (1).toInt() : maxFilterIndex;
2033 ++ iterator;
2034 }
2035
2036 /* creating new usb filter */
2037 CUSBDeviceFilter filter = cmachine.GetUSBController()
2038 .CreateDeviceFilter (usbFilterName.arg (maxFilterIndex + 1));
2039
2040 filter.SetActive (true);
2041 addUSBFilter (filter, true /* isNew */);
2042
2043 mUSBFilterListModified = true;
2044}
2045
2046void VBoxVMSettingsDlg::tbAddUSBFilterFrom_clicked()
2047{
2048 usbDevicesMenu->exec (QCursor::pos());
2049}
2050
2051void VBoxVMSettingsDlg::menuAddUSBFilterFrom_activated (int aIndex)
2052{
2053 CUSBDevice usb = usbDevicesMenu->getUSB (aIndex);
2054 /* if null then some other item but a USB device is selected */
2055 if (usb.isNull())
2056 return;
2057
2058 CUSBDeviceFilter filter = cmachine.GetUSBController()
2059 .CreateDeviceFilter (vboxGlobal().details (usb));
2060
2061 filter.SetVendorId (QString().sprintf ("%04hX", usb.GetVendorId()));
2062 filter.SetProductId (QString().sprintf ("%04hX", usb.GetProductId()));
2063 filter.SetRevision (QString().sprintf ("%04hX", usb.GetRevision()));
2064 filter.SetPort (QString().sprintf ("%04hX", usb.GetPort()));
2065 filter.SetManufacturer (usb.GetManufacturer());
2066 filter.SetProduct (usb.GetProduct());
2067 filter.SetSerialNumber (usb.GetSerialNumber());
2068 filter.SetRemote (usb.GetRemote() ? "yes" : "no");
2069
2070 filter.SetActive (true);
2071 addUSBFilter (filter, true /* isNew */);
2072
2073 mUSBFilterListModified = true;
2074}
2075
2076void VBoxVMSettingsDlg::tbRemoveUSBFilter_clicked()
2077{
2078 QListViewItem *item = lvUSBFilters->currentItem();
2079 Assert (item);
2080
2081 USBListItem *uli = static_cast <USBListItem *> (item);
2082 QWidget *settings = wstUSBFilters->widget (uli->mId);
2083 Assert (settings);
2084 wstUSBFilters->removeWidget (settings);
2085 delete settings;
2086
2087 delete item;
2088
2089 lvUSBFilters->setSelected (lvUSBFilters->currentItem(), true);
2090 mUSBFilterListModified = true;
2091}
2092
2093void VBoxVMSettingsDlg::tbUSBFilterUp_clicked()
2094{
2095 QListViewItem *item = lvUSBFilters->currentItem();
2096 Assert (item);
2097
2098 QListViewItem *itemAbove = item->itemAbove();
2099 Assert (itemAbove);
2100 itemAbove = itemAbove->itemAbove();
2101
2102 if (!itemAbove)
2103 {
2104 /* overcome Qt stupidity */
2105 item->itemAbove()->moveItem (item);
2106 }
2107 else
2108 item->moveItem (itemAbove);
2109
2110 lvUSBFilters_currentChanged (item);
2111 mUSBFilterListModified = true;
2112}
2113
2114void VBoxVMSettingsDlg::tbUSBFilterDown_clicked()
2115{
2116 QListViewItem *item = lvUSBFilters->currentItem();
2117 Assert (item);
2118
2119 QListViewItem *itemBelow = item->itemBelow();
2120 Assert (itemBelow);
2121
2122 item->moveItem (itemBelow);
2123
2124 lvUSBFilters_currentChanged (item);
2125 mUSBFilterListModified = true;
2126}
2127
2128#include "VBoxVMSettingsDlg.ui.moc"
2129
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