VirtualBox

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

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

Fixed a typo

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 74.4 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 mResetFirstRunFlag = false;
403
404 setIcon (QPixmap::fromMimeSource ("settings_16px.png"));
405
406 /* all pages are initially valid */
407 valid = true;
408 buttonOk->setEnabled( true );
409
410 /* disable unselecting items by clicking in the unused area of the list */
411 new QIListViewSelectionPreserver (this, listView);
412 /* hide the header and internal columns */
413 listView->header()->hide();
414 listView->setColumnWidthMode (listView_Id, QListView::Manual);
415 listView->setColumnWidthMode (listView_Link, QListView::Manual);
416 listView->hideColumn (listView_Id);
417 listView->hideColumn (listView_Link);
418 /* sort by the id column (to have pages in the desired order) */
419 listView->setSorting (listView_Id);
420 listView->sort();
421 /* disable further sorting (important for network adapters) */
422 listView->setSorting (-1);
423 /* set the first item selected */
424 listView->setSelected (listView->firstChild(), true);
425 listView_currentChanged (listView->firstChild());
426 /* setup status bar icon */
427 warningPixmap->setMaximumSize( 16, 16 );
428 warningPixmap->setPixmap( QMessageBox::standardIcon( QMessageBox::Warning ) );
429
430 /* page title font is derived from the system font */
431 QFont f = font();
432 f.setBold (true);
433 f.setPointSize (f.pointSize() + 2);
434 titleLabel->setFont (f);
435
436 /* setup the what's this label */
437 QApplication::setGlobalMouseTracking (true);
438 qApp->installEventFilter (this);
439 whatsThisTimer = new QTimer (this);
440 connect (whatsThisTimer, SIGNAL (timeout()), this, SLOT (updateWhatsThis()));
441 whatsThisCandidate = NULL;
442
443 whatsThisLabel = new QIRichLabel (this, "whatsThisLabel");
444 VBoxVMSettingsDlgLayout->addWidget (whatsThisLabel, 2, 1);
445
446#ifndef DEBUG
447 /* Enforce rich text format to avoid jumping margins (margins of plain
448 * text labels seem to be smaller). We don't do it in the DEBUG builds to
449 * be able to immediately catch badly formatted text (i.e. text that
450 * contains HTML tags but doesn't start with <qt> so that Qt isn't able to
451 * recognize it as rich text and draws all tags as is instead of doing
452 * formatting). We want to catch this text because this is how it will look
453 * in the whatsthis balloon where we cannot enforce rich text. */
454 whatsThisLabel->setTextFormat (Qt::RichText);
455#endif
456
457 whatsThisLabel->setMaxHeightMode (true);
458 whatsThisLabel->setFocusPolicy (QWidget::NoFocus);
459 whatsThisLabel->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Fixed);
460 whatsThisLabel->setBackgroundMode (QLabel::PaletteMidlight);
461 whatsThisLabel->setFrameShape (QLabel::Box);
462 whatsThisLabel->setFrameShadow (QLabel::Sunken);
463 whatsThisLabel->setMargin (7);
464 whatsThisLabel->setScaledContents (FALSE);
465 whatsThisLabel->setAlignment (int (QLabel::WordBreak |
466 QLabel::AlignJustify |
467 QLabel::AlignTop));
468
469 whatsThisLabel->setFixedHeight (whatsThisLabel->frameWidth() * 2 +
470 6 /* seems that RichText adds some margin */ +
471 whatsThisLabel->fontMetrics().lineSpacing() * 3);
472 whatsThisLabel->setMinimumWidth (whatsThisLabel->frameWidth() * 2 +
473 6 /* seems that RichText adds some margin */ +
474 whatsThisLabel->fontMetrics().width ('m') * 40);
475
476 /*
477 * setup connections and set validation for pages
478 * ----------------------------------------------------------------------
479 */
480
481 /* General page */
482
483 CSystemProperties sysProps = vboxGlobal().virtualBox().GetSystemProperties();
484
485 const uint MinRAM = sysProps.GetMinGuestRAM();
486 const uint MaxRAM = sysProps.GetMaxGuestRAM();
487 const uint MinVRAM = sysProps.GetMinGuestVRAM();
488 const uint MaxVRAM = sysProps.GetMaxGuestVRAM();
489
490 leName->setValidator( new QRegExpValidator( QRegExp( ".+" ), this ) );
491
492 leRAM->setValidator (new QIntValidator (MinRAM, MaxRAM, this));
493 leVRAM->setValidator (new QIntValidator (MinVRAM, MaxVRAM, this));
494
495 wvalGeneral = new QIWidgetValidator( pageGeneral, this );
496 connect (wvalGeneral, SIGNAL (validityChanged (const QIWidgetValidator *)),
497 this, SLOT(enableOk (const QIWidgetValidator *)));
498
499 tbSelectSavedStateFolder->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
500 "select_file_dis_16px.png"));
501 tbResetSavedStateFolder->setIconSet (VBoxGlobal::iconSet ("eraser_16px.png",
502 "eraser_disabled_16px.png"));
503
504 teDescription->setTextFormat (Qt::PlainText);
505
506 /* HDD Images page */
507
508 QWhatsThis::add (static_cast <QWidget *> (grbHDA->child ("qt_groupbox_checkbox")),
509 tr ("When checked, attaches the specified virtual hard disk to the "
510 "Master slot of the Primary IDE controller."));
511 QWhatsThis::add (static_cast <QWidget *> (grbHDB->child ("qt_groupbox_checkbox")),
512 tr ("When checked, attaches the specified virtual hard disk to the "
513 "Slave slot of the Primary IDE controller."));
514 QWhatsThis::add (static_cast <QWidget *> (grbHDD->child ("qt_groupbox_checkbox")),
515 tr ("When checked, attaches the specified virtual hard disk to the "
516 "Slave slot of the Secondary IDE controller."));
517 cbHDA = new VBoxMediaComboBox (grbHDA, "cbHDA", VBoxDefs::HD);
518 cbHDB = new VBoxMediaComboBox (grbHDB, "cbHDB", VBoxDefs::HD);
519 cbHDD = new VBoxMediaComboBox (grbHDD, "cbHDD", VBoxDefs::HD);
520 hdaLayout->insertWidget (0, cbHDA);
521 hdbLayout->insertWidget (0, cbHDB);
522 hddLayout->insertWidget (0, cbHDD);
523 /* sometimes the weirdness of Qt just kills... */
524 setTabOrder (static_cast <QWidget *> (grbHDA->child ("qt_groupbox_checkbox")),
525 cbHDA);
526 setTabOrder (static_cast <QWidget *> (grbHDB->child ("qt_groupbox_checkbox")),
527 cbHDB);
528 setTabOrder (static_cast <QWidget *> (grbHDD->child ("qt_groupbox_checkbox")),
529 cbHDD);
530
531 QWhatsThis::add (cbHDB, 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 (cbHDD, 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 (cbHDA, 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 (cbHDB, tr ("Displays the virtual hard disk to attach to this IDE slot "
538 "and allows to quickly select a different hard disk."));
539 QWhatsThis::add (cbHDD, tr ("Displays the virtual hard disk to attach to this IDE slot "
540 "and allows to quickly select a different hard disk."));
541
542 wvalHDD = new QIWidgetValidator( pageHDD, this );
543 connect (wvalHDD, SIGNAL (validityChanged (const QIWidgetValidator *)),
544 this, SLOT (enableOk (const QIWidgetValidator *)));
545 connect (wvalHDD, SIGNAL (isValidRequested (QIWidgetValidator *)),
546 this, SLOT (revalidate (QIWidgetValidator *)));
547
548 connect (grbHDA, SIGNAL (toggled (bool)), this, SLOT (hdaMediaChanged()));
549 connect (grbHDB, SIGNAL (toggled (bool)), this, SLOT (hdbMediaChanged()));
550 connect (grbHDD, SIGNAL (toggled (bool)), this, SLOT (hddMediaChanged()));
551 connect (cbHDA, SIGNAL (activated (int)), this, SLOT (hdaMediaChanged()));
552 connect (cbHDB, SIGNAL (activated (int)), this, SLOT (hdbMediaChanged()));
553 connect (cbHDD, SIGNAL (activated (int)), this, SLOT (hddMediaChanged()));
554 connect (tbHDA, SIGNAL (clicked()), this, SLOT (showImageManagerHDA()));
555 connect (tbHDB, SIGNAL (clicked()), this, SLOT (showImageManagerHDB()));
556 connect (tbHDD, SIGNAL (clicked()), this, SLOT (showImageManagerHDD()));
557
558 /* setup iconsets -- qdesigner is not capable... */
559 tbHDA->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
560 "select_file_dis_16px.png"));
561 tbHDB->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
562 "select_file_dis_16px.png"));
563 tbHDD->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
564 "select_file_dis_16px.png"));
565
566 /* CD/DVD-ROM Drive Page */
567
568 QWhatsThis::add (static_cast <QWidget *> (bgDVD->child ("qt_groupbox_checkbox")),
569 tr ("When checked, mounts the specified media to the CD/DVD drive of the "
570 "virtual machine. Note that the CD/DVD drive is always connected to the "
571 "Secondary Master IDE controller of the machine."));
572 cbISODVD = new VBoxMediaComboBox (bgDVD, "cbISODVD", VBoxDefs::CD);
573 cdLayout->insertWidget(0, cbISODVD);
574 QWhatsThis::add (cbISODVD, tr ("Displays the image file to mount to the virtual CD/DVD "
575 "drive and allows to quickly select a different image."));
576
577 wvalDVD = new QIWidgetValidator (pageDVD, this);
578 connect (wvalDVD, SIGNAL (validityChanged (const QIWidgetValidator *)),
579 this, SLOT (enableOk (const QIWidgetValidator *)));
580 connect (wvalDVD, SIGNAL (isValidRequested (QIWidgetValidator *)),
581 this, SLOT (revalidate( QIWidgetValidator *)));
582
583 connect (bgDVD, SIGNAL (toggled (bool)), this, SLOT (cdMediaChanged()));
584 connect (rbHostDVD, SIGNAL (stateChanged (int)), wvalDVD, SLOT (revalidate()));
585 connect (rbISODVD, SIGNAL (stateChanged (int)), wvalDVD, SLOT (revalidate()));
586 connect (cbISODVD, SIGNAL (activated (int)), this, SLOT (cdMediaChanged()));
587 connect (tbISODVD, SIGNAL (clicked()), this, SLOT (showImageManagerISODVD()));
588
589 /* setup iconsets -- qdesigner is not capable... */
590 tbISODVD->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
591 "select_file_dis_16px.png"));
592
593 /* Floppy Drive Page */
594
595 QWhatsThis::add (static_cast <QWidget *> (bgFloppy->child ("qt_groupbox_checkbox")),
596 tr ("When checked, mounts the specified media to the Floppy drive of the "
597 "virtual machine."));
598 cbISOFloppy = new VBoxMediaComboBox (bgFloppy, "cbISOFloppy", VBoxDefs::FD);
599 fdLayout->insertWidget(0, cbISOFloppy);
600 QWhatsThis::add (cbISOFloppy, tr ("Displays the image file to mount to the virtual Floppy "
601 "drive and allows to quickly select a different image."));
602
603 wvalFloppy = new QIWidgetValidator (pageFloppy, this);
604 connect (wvalFloppy, SIGNAL (validityChanged (const QIWidgetValidator *)),
605 this, SLOT (enableOk (const QIWidgetValidator *)));
606 connect (wvalFloppy, SIGNAL (isValidRequested (QIWidgetValidator *)),
607 this, SLOT (revalidate( QIWidgetValidator *)));
608
609 connect (bgFloppy, SIGNAL (toggled (bool)), this, SLOT (fdMediaChanged()));
610 connect (rbHostFloppy, SIGNAL (stateChanged (int)), wvalFloppy, SLOT (revalidate()));
611 connect (rbISOFloppy, SIGNAL (stateChanged (int)), wvalFloppy, SLOT (revalidate()));
612 connect (cbISOFloppy, SIGNAL (activated (int)), this, SLOT (fdMediaChanged()));
613 connect (tbISOFloppy, SIGNAL (clicked()), this, SLOT (showImageManagerISOFloppy()));
614
615 /* setup iconsets -- qdesigner is not capable... */
616 tbISOFloppy->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
617 "select_file_dis_16px.png"));
618
619 /* Audio Page */
620
621 QWhatsThis::add (static_cast <QWidget *> (grbAudio->child ("qt_groupbox_checkbox")),
622 tr ("When checked, the virtual PCI audio card is plugged into the "
623 "virtual machine that uses the specified driver to communicate "
624 "to the host audio card."));
625
626 /* Network Page */
627
628 QVBoxLayout* pageNetworkLayout = new QVBoxLayout (pageNetwork, 0, 10, "pageNetworkLayout");
629 tbwNetwork = new QTabWidget (pageNetwork, "tbwNetwork");
630 pageNetworkLayout->addWidget (tbwNetwork);
631
632 /* USB Page */
633
634 lvUSBFilters->header()->hide();
635 /* disable sorting */
636 lvUSBFilters->setSorting (-1);
637 /* disable unselecting items by clicking in the unused area of the list */
638 new QIListViewSelectionPreserver (this, lvUSBFilters);
639 /* create the widget stack for filter settings */
640 /// @todo (r=dmik) having a separate settings widget for every USB filter
641 // is not that smart if there are lots of USB filters. The reason for
642 // stacking here is that the stacked widget is used to temporarily store
643 // data of the associated USB filter until the dialog window is accepted.
644 // If we remove stacking, we will have to create a structure to store
645 // editable data of all USB filters while the dialog is open.
646 wstUSBFilters = new QWidgetStack (grbUSBFilters, "wstUSBFilters");
647 grbUSBFiltersLayout->addWidget (wstUSBFilters);
648 /* create a default (disabled) filter settings widget at index 0 */
649 VBoxUSBFilterSettings *settings = new VBoxUSBFilterSettings (wstUSBFilters);
650 settings->setup (VBoxUSBFilterSettings::MachineType);
651 wstUSBFilters->addWidget (settings, 0);
652 lvUSBFilters_currentChanged (NULL);
653
654 /* setup iconsets -- qdesigner is not capable... */
655 tbAddUSBFilter->setIconSet (VBoxGlobal::iconSet ("usb_new_16px.png",
656 "usb_new_disabled_16px.png"));
657 tbAddUSBFilterFrom->setIconSet (VBoxGlobal::iconSet ("usb_add_16px.png",
658 "usb_add_disabled_16px.png"));
659 tbRemoveUSBFilter->setIconSet (VBoxGlobal::iconSet ("usb_remove_16px.png",
660 "usb_remove_disabled_16px.png"));
661 tbUSBFilterUp->setIconSet (VBoxGlobal::iconSet ("usb_moveup_16px.png",
662 "usb_moveup_disabled_16px.png"));
663 tbUSBFilterDown->setIconSet (VBoxGlobal::iconSet ("usb_movedown_16px.png",
664 "usb_movedown_disabled_16px.png"));
665 usbDevicesMenu = new VBoxUSBMenu (this);
666 connect (usbDevicesMenu, SIGNAL(activated(int)), this, SLOT(menuAddUSBFilterFrom_activated(int)));
667 mUSBFilterListModified = false;
668
669 /* VRDP Page */
670
671 QWhatsThis::add (static_cast <QWidget *> (grbVRDP->child ("qt_groupbox_checkbox")),
672 tr ("When checked, the VM will act as a Remote Desktop "
673 "Protocol (RDP) server, allowing remote clients to connect "
674 "and operate the VM (when it is running) "
675 "using a standard RDP client."));
676
677 ULONG maxPort = 65535;
678 leVRDPPort->setValidator (new QIntValidator (0, maxPort, this));
679 leVRDPTimeout->setValidator (new QIntValidator (0, maxPort, this));
680 wvalVRDP = new QIWidgetValidator (pageVRDP, this);
681 connect (wvalVRDP, SIGNAL (validityChanged (const QIWidgetValidator *)),
682 this, SLOT (enableOk (const QIWidgetValidator *)));
683 connect (wvalVRDP, SIGNAL (isValidRequested (QIWidgetValidator *)),
684 this, SLOT (revalidate( QIWidgetValidator *)));
685
686 connect (grbVRDP, SIGNAL (toggled (bool)), wvalFloppy, SLOT (revalidate()));
687 connect (leVRDPPort, SIGNAL (textChanged (const QString&)), wvalFloppy, SLOT (revalidate()));
688 connect (leVRDPTimeout, SIGNAL (textChanged (const QString&)), wvalFloppy, SLOT (revalidate()));
689
690 /* Shared Folders Page */
691
692 QVBoxLayout* pageFoldersLayout = new QVBoxLayout (pageFolders, 0, 10, "pageFoldersLayout");
693 mSharedFolders = new VBoxSharedFoldersSettings (pageFolders, "sharedFolders");
694 mSharedFolders->setDialogType (VBoxSharedFoldersSettings::MachineType);
695 pageFoldersLayout->addWidget (mSharedFolders);
696
697 /*
698 * set initial values
699 * ----------------------------------------------------------------------
700 */
701
702 /* General page */
703
704 cbOS->insertStringList (vboxGlobal().vmGuestOSTypeDescriptions());
705
706 slRAM->setPageStep (calcPageStep (MaxRAM));
707 slRAM->setLineStep (slRAM->pageStep() / 4);
708 slRAM->setTickInterval (slRAM->pageStep());
709 /* setup the scale so that ticks are at page step boundaries */
710 slRAM->setMinValue ((MinRAM / slRAM->pageStep()) * slRAM->pageStep());
711 slRAM->setMaxValue (MaxRAM);
712 txRAMMin->setText (tr ("<qt>%1&nbsp;MB</qt>").arg (MinRAM));
713 txRAMMax->setText (tr ("<qt>%1&nbsp;MB</qt>").arg (MaxRAM));
714 /* limit min/max. size of QLineEdit */
715 leRAM->setMaximumSize (leRAM->fontMetrics().width ("99999")
716 + leRAM->frameWidth() * 2,
717 leRAM->minimumSizeHint().height());
718 leRAM->setMinimumSize (leRAM->maximumSize());
719 /* ensure leRAM value and validation is updated */
720 slRAM_valueChanged (slRAM->value());
721
722 slVRAM->setPageStep (calcPageStep (MaxVRAM));
723 slVRAM->setLineStep (slVRAM->pageStep() / 4);
724 slVRAM->setTickInterval (slVRAM->pageStep());
725 /* setup the scale so that ticks are at page step boundaries */
726 slVRAM->setMinValue ((MinVRAM / slVRAM->pageStep()) * slVRAM->pageStep());
727 slVRAM->setMaxValue (MaxVRAM);
728 txVRAMMin->setText (tr ("<qt>%1&nbsp;MB</qt>").arg (MinVRAM));
729 txVRAMMax->setText (tr ("<qt>%1&nbsp;MB</qt>").arg (MaxVRAM));
730 /* limit min/max. size of QLineEdit */
731 leVRAM->setMaximumSize (leVRAM->fontMetrics().width ("99999")
732 + leVRAM->frameWidth() * 2,
733 leVRAM->minimumSizeHint().height());
734 leVRAM->setMinimumSize (leVRAM->maximumSize());
735 /* ensure leVRAM value and validation is updated */
736 slVRAM_valueChanged (slVRAM->value());
737
738 /* Boot-order table */
739 tblBootOrder = new BootItemsList (groupBox12, "tblBootOrder");
740 connect (tblBootOrder, SIGNAL (bootSequenceChanged()),
741 this, SLOT (resetFirstRunFlag()));
742 /* Fixing focus order for BootItemsList */
743 setTabOrder (tbwGeneral, tblBootOrder);
744 setTabOrder (tblBootOrder->focusProxy(), chbEnableACPI);
745 groupBox12Layout->addWidget (tblBootOrder);
746 tblBootOrder->fixTabStops();
747 /* Shared Clipboard mode */
748 cbSharedClipboard->insertItem (vboxGlobal().toString (CEnums::ClipDisabled));
749 cbSharedClipboard->insertItem (vboxGlobal().toString (CEnums::ClipHostToGuest));
750 cbSharedClipboard->insertItem (vboxGlobal().toString (CEnums::ClipGuestToHost));
751 cbSharedClipboard->insertItem (vboxGlobal().toString (CEnums::ClipBidirectional));
752
753 /* HDD Images page */
754
755 /* CD-ROM Drive Page */
756
757 /* Audio Page */
758
759 cbAudioDriver->insertItem (vboxGlobal().toString (CEnums::NullAudioDriver));
760#if defined Q_WS_WIN32
761 cbAudioDriver->insertItem (vboxGlobal().toString (CEnums::DSOUNDAudioDriver));
762#ifdef VBOX_WITH_WINMM
763 cbAudioDriver->insertItem (vboxGlobal().toString (CEnums::WINMMAudioDriver));
764#endif
765#elif defined Q_OS_LINUX
766 cbAudioDriver->insertItem (vboxGlobal().toString (CEnums::OSSAudioDriver));
767#ifdef VBOX_WITH_ALSA
768 cbAudioDriver->insertItem (vboxGlobal().toString (CEnums::ALSAAudioDriver));
769#endif
770#elif defined Q_OS_MACX
771 cbAudioDriver->insertItem (vboxGlobal().toString (CEnums::CoreAudioDriver));
772#endif
773
774 /* Network Page */
775
776 updateInterfaces (0);
777
778 /*
779 * update the Ok button state for pages with validation
780 * (validityChanged() connected to enableNext() will do the job)
781 */
782 wvalGeneral->revalidate();
783 wvalHDD->revalidate();
784 wvalDVD->revalidate();
785 wvalFloppy->revalidate();
786
787 /* VRDP Page */
788
789 leVRDPPort->setAlignment (Qt::AlignRight);
790 cbVRDPAuthType->insertItem (vboxGlobal().toString (CEnums::VRDPAuthNull));
791 cbVRDPAuthType->insertItem (vboxGlobal().toString (CEnums::VRDPAuthExternal));
792 cbVRDPAuthType->insertItem (vboxGlobal().toString (CEnums::VRDPAuthGuest));
793 leVRDPTimeout->setAlignment (Qt::AlignRight);
794}
795
796bool VBoxVMSettingsDlg::eventFilter (QObject *object, QEvent *event)
797{
798 if (!object->isWidgetType())
799 return QDialog::eventFilter (object, event);
800
801 QWidget *widget = static_cast <QWidget *> (object);
802 if (widget->topLevelWidget() != this)
803 return QDialog::eventFilter (object, event);
804
805 switch (event->type())
806 {
807 case QEvent::Enter:
808 case QEvent::Leave:
809 {
810 if (event->type() == QEvent::Enter)
811 whatsThisCandidate = widget;
812 else
813 whatsThisCandidate = NULL;
814 whatsThisTimer->start (100, true /* sshot */);
815 break;
816 }
817 case QEvent::FocusIn:
818 {
819 updateWhatsThis (true /* gotFocus */);
820 tblBootOrder->processFocusIn (widget);
821 break;
822 }
823 default:
824 break;
825 }
826
827 return QDialog::eventFilter (object, event);
828}
829
830void VBoxVMSettingsDlg::showEvent (QShowEvent *e)
831{
832 QDialog::showEvent (e);
833
834 /* one may think that QWidget::polish() is the right place to do things
835 * below, but apparently, by the time when QWidget::polish() is called,
836 * the widget style & layout are not fully done, at least the minimum
837 * size hint is not properly calculated. Since this is sometimes necessary,
838 * we provide our own "polish" implementation. */
839
840 if (polished)
841 return;
842
843 polished = true;
844
845 /* update geometry for the dynamically added usb-page to ensure proper
846 * sizeHint calculation by the Qt layout manager */
847 wstUSBFilters->updateGeometry();
848 /* let our toplevel widget calculate its sizeHint properly */
849 QApplication::sendPostedEvents (0, 0);
850
851 layout()->activate();
852
853 /* resize to the miminum possible size */
854 resize (minimumSize());
855
856 VBoxGlobal::centerWidget (this, parentWidget());
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::resetFirstRunFlag()
914{
915 mResetFirstRunFlag = true;
916}
917
918
919void VBoxVMSettingsDlg::hdaMediaChanged()
920{
921 resetFirstRunFlag();
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 resetFirstRunFlag();
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 resetFirstRunFlag();
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 resetFirstRunFlag();
952 uuidISODVD = bgDVD->isChecked() ? cbISODVD->getId() : QUuid();
953 /* revailidate */
954 wvalDVD->revalidate();
955}
956
957
958void VBoxVMSettingsDlg::fdMediaChanged()
959{
960 resetFirstRunFlag();
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 QString name = hostFloppy.GetName();
1367 QString description = hostFloppy.GetDescription();
1368 QString fullName = description.isEmpty() ?
1369 name :
1370 QString ("%1 (%2)").arg (description, name);
1371 cbHostFloppy->insertItem (fullName, id);
1372 hostFloppies [id] = hostFloppy;
1373 ++ id;
1374 }
1375
1376 CFloppyDrive floppy = machine.GetFloppyDrive();
1377 switch (floppy.GetState())
1378 {
1379 case CEnums::HostDriveCaptured:
1380 {
1381 CHostFloppyDrive drv = floppy.GetHostDrive();
1382 QString name = drv.GetName();
1383 QString description = drv.GetDescription();
1384 QString fullName = description.isEmpty() ?
1385 name :
1386 QString ("%1 (%2)").arg (description, name);
1387 if (coll.FindByName (name).isNull())
1388 {
1389 /*
1390 * if the floppy drive is not currently available,
1391 * add it to the end of the list with a special mark
1392 */
1393 cbHostFloppy->insertItem ("* " + fullName);
1394 cbHostFloppy->setCurrentItem (cbHostFloppy->count() - 1);
1395 }
1396 else
1397 {
1398 /* this will select the correct item from the prepared list */
1399 cbHostFloppy->setCurrentText (fullName);
1400 }
1401 rbHostFloppy->setChecked (true);
1402 break;
1403 }
1404 case CEnums::ImageMounted:
1405 {
1406 CFloppyImage img = floppy.GetImage();
1407 QString src = img.GetFilePath();
1408 AssertMsg (!src.isNull(), ("Image file must not be null"));
1409 QFileInfo fi (src);
1410 rbISOFloppy->setChecked (true);
1411 uuidISOFloppy = QUuid (img.GetId());
1412 break;
1413 }
1414 case CEnums::NotMounted:
1415 {
1416 bgFloppy->setChecked(false);
1417 break;
1418 }
1419 default:
1420 AssertMsgFailed (("invalid floppy state: %d\n", floppy.GetState()));
1421 }
1422 }
1423
1424 /* CD/DVD-ROM image */
1425 {
1426 /* read out the host DVD drive list and prepare the combobox */
1427 CHostDVDDriveCollection coll =
1428 vboxGlobal().virtualBox().GetHost().GetDVDDrives();
1429 hostDVDs.resize (coll.GetCount());
1430 cbHostDVD->clear();
1431 int id = 0;
1432 CHostDVDDriveEnumerator en = coll.Enumerate();
1433 while (en.HasMore())
1434 {
1435 CHostDVDDrive hostDVD = en.GetNext();
1436 /// @todo (r=dmik) set icon?
1437 QString name = hostDVD.GetName();
1438 QString description = hostDVD.GetDescription();
1439 QString fullName = description.isEmpty() ?
1440 name :
1441 QString ("%1 (%2)").arg (description, name);
1442 cbHostDVD->insertItem (fullName, id);
1443 hostDVDs [id] = hostDVD;
1444 ++ id;
1445 }
1446
1447 CDVDDrive dvd = machine.GetDVDDrive();
1448 switch (dvd.GetState())
1449 {
1450 case CEnums::HostDriveCaptured:
1451 {
1452 CHostDVDDrive drv = dvd.GetHostDrive();
1453 QString name = drv.GetName();
1454 QString description = drv.GetDescription();
1455 QString fullName = description.isEmpty() ?
1456 name :
1457 QString ("%1 (%2)").arg (description, name);
1458 if (coll.FindByName (name).isNull())
1459 {
1460 /*
1461 * if the DVD drive is not currently available,
1462 * add it to the end of the list with a special mark
1463 */
1464 cbHostDVD->insertItem ("* " + fullName);
1465 cbHostDVD->setCurrentItem (cbHostDVD->count() - 1);
1466 }
1467 else
1468 {
1469 /* this will select the correct item from the prepared list */
1470 cbHostDVD->setCurrentText (fullName);
1471 }
1472 rbHostDVD->setChecked (true);
1473 break;
1474 }
1475 case CEnums::ImageMounted:
1476 {
1477 CDVDImage img = dvd.GetImage();
1478 QString src = img.GetFilePath();
1479 AssertMsg (!src.isNull(), ("Image file must not be null"));
1480 QFileInfo fi (src);
1481 rbISODVD->setChecked (true);
1482 uuidISODVD = QUuid (img.GetId());
1483 break;
1484 }
1485 case CEnums::NotMounted:
1486 {
1487 bgDVD->setChecked(false);
1488 break;
1489 }
1490 default:
1491 AssertMsgFailed (("invalid DVD state: %d\n", dvd.GetState()));
1492 }
1493 }
1494
1495 /* audio */
1496 {
1497 CAudioAdapter audio = machine.GetAudioAdapter();
1498 grbAudio->setChecked (audio.GetEnabled());
1499 cbAudioDriver->setCurrentText (vboxGlobal().toString (audio.GetAudioDriver()));
1500 }
1501
1502 /* network */
1503 {
1504 ulong count = vbox.GetSystemProperties().GetNetworkAdapterCount();
1505 for (ulong slot = 0; slot < count; ++ slot)
1506 {
1507 CNetworkAdapter adapter = machine.GetNetworkAdapter (slot);
1508 addNetworkAdapter (adapter);
1509 }
1510 }
1511
1512 /* USB */
1513 {
1514 CUSBController ctl = machine.GetUSBController();
1515
1516 if (ctl.isNull())
1517 {
1518 /* disable the USB controller category if the USB controller is
1519 * not available (i.e. in VirtualBox OSE) */
1520
1521 QListViewItem *usbItem = listView->findItem ("#usb", listView_Link);
1522 Assert (usbItem);
1523 if (usbItem)
1524 usbItem->setVisible (false);
1525
1526 /* disable validators if any */
1527 pageUSB->setEnabled (false);
1528
1529 /* Show an error message (if there is any).
1530 * Note that we don't use the generic cannotLoadMachineSettings()
1531 * call here because we want this message to be suppressable. */
1532 vboxProblem().cannotAccessUSB (machine);
1533 }
1534 else
1535 {
1536 cbEnableUSBController->setChecked (ctl.GetEnabled());
1537
1538 CUSBDeviceFilterEnumerator en = ctl.GetDeviceFilters().Enumerate();
1539 while (en.HasMore())
1540 addUSBFilter (en.GetNext(), false /* isNew */);
1541
1542 lvUSBFilters->setCurrentItem (lvUSBFilters->firstChild());
1543 /* silly Qt -- doesn't emit currentChanged after adding the
1544 * first item to an empty list */
1545 lvUSBFilters_currentChanged (lvUSBFilters->firstChild());
1546 }
1547 }
1548
1549 /* vrdp */
1550 {
1551 CVRDPServer vrdp = machine.GetVRDPServer();
1552
1553 if (vrdp.isNull())
1554 {
1555 /* disable the VRDP category if VRDP is
1556 * not available (i.e. in VirtualBox OSE) */
1557
1558 QListViewItem *vrdpItem = listView->findItem ("#vrdp", listView_Link);
1559 Assert (vrdpItem);
1560 if (vrdpItem)
1561 vrdpItem->setVisible (false);
1562
1563 /* disable validators if any */
1564 pageVRDP->setEnabled (false);
1565
1566 /* if machine has something to say, show the message */
1567 vboxProblem().cannotLoadMachineSettings (machine, false /* strict */);
1568 }
1569 else
1570 {
1571 grbVRDP->setChecked (vrdp.GetEnabled());
1572 leVRDPPort->setText (QString::number (vrdp.GetPort()));
1573 cbVRDPAuthType->setCurrentText (vboxGlobal().toString (vrdp.GetAuthType()));
1574 leVRDPTimeout->setText (QString::number (vrdp.GetAuthTimeout()));
1575 }
1576 }
1577
1578 /* shared folders */
1579 {
1580 mSharedFolders->getFromMachine (machine);
1581 }
1582
1583 /* request for media shortcuts update */
1584 cbHDA->setBelongsTo (machine.GetId());
1585 cbHDB->setBelongsTo (machine.GetId());
1586 cbHDD->setBelongsTo (machine.GetId());
1587 updateShortcuts();
1588
1589 /* revalidate pages with custom validation */
1590 wvalHDD->revalidate();
1591 wvalDVD->revalidate();
1592 wvalFloppy->revalidate();
1593 wvalVRDP->revalidate();
1594}
1595
1596
1597COMResult VBoxVMSettingsDlg::putBackToMachine()
1598{
1599 CVirtualBox vbox = vboxGlobal().virtualBox();
1600 CBIOSSettings biosSettings = cmachine.GetBIOSSettings();
1601
1602 /* name */
1603 cmachine.SetName (leName->text());
1604
1605 /* OS type */
1606 CGuestOSType type = vboxGlobal().vmGuestOSType (cbOS->currentItem());
1607 AssertMsg (!type.isNull(), ("vmGuestOSType() must return non-null type"));
1608 cmachine.SetOSTypeId (type.GetId());
1609
1610 /* RAM size */
1611 cmachine.SetMemorySize (slRAM->value());
1612
1613 /* VRAM size */
1614 cmachine.SetVRAMSize (slVRAM->value());
1615
1616 /* boot order */
1617 tblBootOrder->putBackToMachine (cmachine);
1618
1619 /* ACPI */
1620 biosSettings.SetACPIEnabled (chbEnableACPI->isChecked());
1621
1622 /* IO APIC */
1623 biosSettings.SetIOAPICEnabled (chbEnableIOAPIC->isChecked());
1624
1625 /* Saved state folder */
1626 if (leSnapshotFolder->isModified())
1627 cmachine.SetSnapshotFolder (leSnapshotFolder->text());
1628
1629 /* Description */
1630 cmachine.SetDescription (teDescription->text());
1631
1632 /* Shared clipboard mode */
1633 cmachine.SetClipboardMode ((CEnums::ClipboardMode)cbSharedClipboard->currentItem());
1634
1635 /* hard disk images */
1636 {
1637 struct
1638 {
1639 CEnums::DiskControllerType ctl;
1640 LONG dev;
1641 struct {
1642 QGroupBox *grb;
1643 QUuid *uuid;
1644 } data;
1645 }
1646 diskSet[] =
1647 {
1648 { CEnums::IDE0Controller, 0, {grbHDA, &uuidHDA} },
1649 { CEnums::IDE0Controller, 1, {grbHDB, &uuidHDB} },
1650 { CEnums::IDE1Controller, 1, {grbHDD, &uuidHDD} }
1651 };
1652
1653 /*
1654 * first, detach all disks (to ensure we can reattach them to different
1655 * controllers / devices, when appropriate)
1656 */
1657 CHardDiskAttachmentEnumerator en =
1658 cmachine.GetHardDiskAttachments().Enumerate();
1659 while (en.HasMore())
1660 {
1661 CHardDiskAttachment hda = en.GetNext();
1662 for (uint i = 0; i < SIZEOF_ARRAY (diskSet); i++)
1663 {
1664 if (diskSet [i].ctl == hda.GetController() &&
1665 diskSet [i].dev == hda.GetDeviceNumber())
1666 {
1667 cmachine.DetachHardDisk (diskSet [i].ctl, diskSet [i].dev);
1668 if (!cmachine.isOk())
1669 vboxProblem().cannotDetachHardDisk (
1670 this, cmachine, diskSet [i].ctl, diskSet [i].dev);
1671 }
1672 }
1673 }
1674
1675 /* now, attach new disks */
1676 for (uint i = 0; i < SIZEOF_ARRAY (diskSet); i++)
1677 {
1678 QUuid *newId = diskSet [i].data.uuid;
1679 if (diskSet [i].data.grb->isChecked() && !(*newId).isNull())
1680 {
1681 cmachine.AttachHardDisk (*newId, diskSet [i].ctl, diskSet [i].dev);
1682 if (!cmachine.isOk())
1683 vboxProblem().cannotAttachHardDisk (
1684 this, cmachine, *newId, diskSet [i].ctl, diskSet [i].dev);
1685 }
1686 }
1687 }
1688
1689 /* floppy image */
1690 {
1691 CFloppyDrive floppy = cmachine.GetFloppyDrive();
1692 if (!bgFloppy->isChecked())
1693 {
1694 floppy.Unmount();
1695 }
1696 else if (rbHostFloppy->isChecked())
1697 {
1698 int id = cbHostFloppy->currentItem();
1699 Assert (id >= 0);
1700 if (id < (int) hostFloppies.count())
1701 floppy.CaptureHostDrive (hostFloppies [id]);
1702 /*
1703 * otherwise the selected drive is not yet available, leave it
1704 * as is
1705 */
1706 }
1707 else if (rbISOFloppy->isChecked())
1708 {
1709 Assert (!uuidISOFloppy.isNull());
1710 floppy.MountImage (uuidISOFloppy);
1711 }
1712 }
1713
1714 /* CD/DVD-ROM image */
1715 {
1716 CDVDDrive dvd = cmachine.GetDVDDrive();
1717 if (!bgDVD->isChecked())
1718 {
1719 dvd.Unmount();
1720 }
1721 else if (rbHostDVD->isChecked())
1722 {
1723 int id = cbHostDVD->currentItem();
1724 Assert (id >= 0);
1725 if (id < (int) hostDVDs.count())
1726 dvd.CaptureHostDrive (hostDVDs [id]);
1727 /*
1728 * otherwise the selected drive is not yet available, leave it
1729 * as is
1730 */
1731 }
1732 else if (rbISODVD->isChecked())
1733 {
1734 Assert (!uuidISODVD.isNull());
1735 dvd.MountImage (uuidISODVD);
1736 }
1737 }
1738
1739 /* Clear the "GUI_FirstRun" extra data key in case if the boot order
1740 * and/or disk configuration were changed */
1741 if (mResetFirstRunFlag)
1742 cmachine.SetExtraData (GUI_FirstRun, QString::null);
1743
1744 /* audio */
1745 {
1746 CAudioAdapter audio = cmachine.GetAudioAdapter();
1747 audio.SetAudioDriver (vboxGlobal().toAudioDriverType (cbAudioDriver->currentText()));
1748 audio.SetEnabled (grbAudio->isChecked());
1749 AssertWrapperOk (audio);
1750 }
1751
1752 /* network */
1753 {
1754 for (int index = 0; index < tbwNetwork->count(); index++)
1755 {
1756 VBoxVMNetworkSettings *page =
1757 (VBoxVMNetworkSettings *) tbwNetwork->page (index);
1758 Assert (page);
1759 page->putBackToAdapter();
1760 }
1761 }
1762
1763 /* usb */
1764 {
1765 CUSBController ctl = cmachine.GetUSBController();
1766
1767 if (!ctl.isNull())
1768 {
1769 /* the USB controller may be unavailable (i.e. in VirtualBox OSE) */
1770
1771 ctl.SetEnabled (cbEnableUSBController->isChecked());
1772
1773 /*
1774 * first, remove all old filters (only if the list is changed,
1775 * not only individual properties of filters)
1776 */
1777 if (mUSBFilterListModified)
1778 for (ulong count = ctl.GetDeviceFilters().GetCount(); count; -- count)
1779 ctl.RemoveDeviceFilter (0);
1780
1781 /* then add all new filters */
1782 for (QListViewItem *item = lvUSBFilters->firstChild(); item;
1783 item = item->nextSibling())
1784 {
1785 USBListItem *uli = static_cast <USBListItem *> (item);
1786 VBoxUSBFilterSettings *settings =
1787 static_cast <VBoxUSBFilterSettings *>
1788 (wstUSBFilters->widget (uli->mId));
1789 Assert (settings);
1790
1791 COMResult res = settings->putBackToFilter();
1792 if (!res.isOk())
1793 return res;
1794
1795 CUSBDeviceFilter filter = settings->filter();
1796 filter.SetActive (uli->isOn());
1797
1798 if (mUSBFilterListModified)
1799 ctl.InsertDeviceFilter (~0, filter);
1800 }
1801 }
1802
1803 mUSBFilterListModified = false;
1804 }
1805
1806 /* vrdp */
1807 {
1808 CVRDPServer vrdp = cmachine.GetVRDPServer();
1809
1810 if (!vrdp.isNull())
1811 {
1812 /* VRDP may be unavailable (i.e. in VirtualBox OSE) */
1813 vrdp.SetEnabled (grbVRDP->isChecked());
1814 vrdp.SetPort (leVRDPPort->text().toULong());
1815 vrdp.SetAuthType (vboxGlobal().toVRDPAuthType (cbVRDPAuthType->currentText()));
1816 vrdp.SetAuthTimeout (leVRDPTimeout->text().toULong());
1817 }
1818 }
1819
1820 /* shared folders */
1821 {
1822 mSharedFolders->putBackToMachine();
1823 }
1824
1825 return COMResult();
1826}
1827
1828
1829void VBoxVMSettingsDlg::showImageManagerHDA() { showVDImageManager (&uuidHDA, cbHDA); }
1830void VBoxVMSettingsDlg::showImageManagerHDB() { showVDImageManager (&uuidHDB, cbHDB); }
1831void VBoxVMSettingsDlg::showImageManagerHDD() { showVDImageManager (&uuidHDD, cbHDD); }
1832void VBoxVMSettingsDlg::showImageManagerISODVD() { showVDImageManager (&uuidISODVD, cbISODVD); }
1833void VBoxVMSettingsDlg::showImageManagerISOFloppy() { showVDImageManager(&uuidISOFloppy, cbISOFloppy); }
1834
1835void VBoxVMSettingsDlg::showVDImageManager (QUuid *id, VBoxMediaComboBox *cbb, QLabel*)
1836{
1837 VBoxDefs::DiskType type = VBoxDefs::InvalidType;
1838 if (cbb == cbISODVD)
1839 type = VBoxDefs::CD;
1840 else if (cbb == cbISOFloppy)
1841 type = VBoxDefs::FD;
1842 else
1843 type = VBoxDefs::HD;
1844
1845 VBoxDiskImageManagerDlg dlg (this, "VBoxDiskImageManagerDlg",
1846 WType_Dialog | WShowModal);
1847 QUuid machineId = cmachine.GetId();
1848 dlg.setup (type, true, &machineId, true /* aRefresh */, cmachine);
1849 if (dlg.exec() == VBoxDiskImageManagerDlg::Accepted)
1850 {
1851 *id = dlg.getSelectedUuid();
1852 resetFirstRunFlag();
1853 }
1854 else
1855 {
1856 *id = cbb->getId();
1857 }
1858
1859 cbb->setCurrentItem (*id);
1860 cbb->setFocus();
1861
1862 /* revalidate pages with custom validation */
1863 wvalHDD->revalidate();
1864 wvalDVD->revalidate();
1865 wvalFloppy->revalidate();
1866}
1867
1868void VBoxVMSettingsDlg::addNetworkAdapter (const CNetworkAdapter &aAdapter)
1869{
1870 VBoxVMNetworkSettings *page = new VBoxVMNetworkSettings();
1871 page->loadList (mInterfaceList);
1872 page->getFromAdapter (aAdapter);
1873 tbwNetwork->addTab (page, QString (tr ("Adapter %1", "network"))
1874 .arg (aAdapter.GetSlot()));
1875
1876 /* fix the tab order so that main dialog's buttons are always the last */
1877 setTabOrder (page->leTAPTerminate, buttonHelp);
1878 setTabOrder (buttonHelp, buttonOk);
1879 setTabOrder (buttonOk, buttonCancel);
1880
1881 /* setup validation */
1882 QIWidgetValidator *wval = new QIWidgetValidator (pageNetwork, this);
1883 connect (page->grbEnabled, SIGNAL (toggled (bool)), wval, SLOT (revalidate()));
1884 connect (page->cbNetworkAttachment, SIGNAL (activated (const QString &)),
1885 wval, SLOT (revalidate()));
1886
1887#if defined Q_WS_WIN
1888 connect (page->lbHostInterface, SIGNAL (highlighted (QListBoxItem*)),
1889 wval, SLOT (revalidate()));
1890 connect (tbwNetwork, SIGNAL (currentChanged (QWidget*)),
1891 this, SLOT (networkPageUpdate (QWidget*)));
1892 connect (page, SIGNAL (listChanged (QWidget*)),
1893 this, SLOT (updateInterfaces (QWidget*)));
1894#endif
1895
1896 connect (wval, SIGNAL (validityChanged (const QIWidgetValidator *)),
1897 this, SLOT (enableOk (const QIWidgetValidator *)));
1898 connect (wval, SIGNAL (isValidRequested (QIWidgetValidator *)),
1899 this, SLOT (revalidate( QIWidgetValidator *)));
1900
1901 page->setValidator (wval);
1902 page->revalidate();
1903}
1904
1905void VBoxVMSettingsDlg::slRAM_valueChanged( int val )
1906{
1907 leRAM->setText( QString().setNum( val ) );
1908}
1909
1910void VBoxVMSettingsDlg::leRAM_textChanged( const QString &text )
1911{
1912 slRAM->setValue( text.toInt() );
1913}
1914
1915void VBoxVMSettingsDlg::slVRAM_valueChanged( int val )
1916{
1917 leVRAM->setText( QString().setNum( val ) );
1918}
1919
1920void VBoxVMSettingsDlg::leVRAM_textChanged( const QString &text )
1921{
1922 slVRAM->setValue( text.toInt() );
1923}
1924
1925void VBoxVMSettingsDlg::cbOS_activated (int item)
1926{
1927 Q_UNUSED (item);
1928/// @todo (dmik) remove?
1929// CGuestOSType type = vboxGlobal().vmGuestOSType (item);
1930// txRAMBest->setText (tr ("<qt>Best&nbsp;%1&nbsp;MB<qt>")
1931// .arg (type.GetRecommendedRAM()));
1932// txVRAMBest->setText (tr ("<qt>Best&nbsp;%1&nbsp;MB</qt>")
1933// .arg (type.GetRecommendedVRAM()));
1934 txRAMBest->setText (QString::null);
1935 txVRAMBest->setText (QString::null);
1936}
1937
1938void VBoxVMSettingsDlg::tbResetSavedStateFolder_clicked()
1939{
1940 /*
1941 * do this instead of le->setText (QString::null) to cause
1942 * isModified() return true
1943 */
1944 leSnapshotFolder->selectAll();
1945 leSnapshotFolder->del();
1946}
1947
1948void VBoxVMSettingsDlg::tbSelectSavedStateFolder_clicked()
1949{
1950 QString settingsFolder = VBoxGlobal::getFirstExistingDir (leSnapshotFolder->text());
1951 if (settingsFolder.isNull())
1952 settingsFolder = QFileInfo (cmachine.GetSettingsFilePath()).dirPath (true);
1953
1954 QString folder = vboxGlobal().getExistingDirectory (settingsFolder, this);
1955 if (folder.isNull())
1956 return;
1957
1958 folder = QDir::convertSeparators (folder);
1959 /* remove trailing slash if any */
1960 folder.remove (QRegExp ("[\\\\/]$"));
1961
1962 /*
1963 * do this instead of le->setText (folder) to cause
1964 * isModified() return true
1965 */
1966 leSnapshotFolder->selectAll();
1967 leSnapshotFolder->insert (folder);
1968}
1969
1970// USB Filter stuff
1971////////////////////////////////////////////////////////////////////////////////
1972
1973void VBoxVMSettingsDlg::addUSBFilter (const CUSBDeviceFilter &aFilter, bool isNew)
1974{
1975 QListViewItem *currentItem = isNew
1976 ? lvUSBFilters->currentItem()
1977 : lvUSBFilters->lastItem();
1978
1979 VBoxUSBFilterSettings *settings = new VBoxUSBFilterSettings (wstUSBFilters);
1980 settings->setup (VBoxUSBFilterSettings::MachineType);
1981 settings->getFromFilter (aFilter);
1982
1983 USBListItem *item = new USBListItem (lvUSBFilters, currentItem);
1984 item->setOn (aFilter.GetActive());
1985 item->setText (lvUSBFilters_Name, aFilter.GetName());
1986
1987 item->mId = wstUSBFilters->addWidget (settings);
1988
1989 /* fix the tab order so that main dialog's buttons are always the last */
1990 setTabOrder (settings->focusProxy(), buttonHelp);
1991 setTabOrder (buttonHelp, buttonOk);
1992 setTabOrder (buttonOk, buttonCancel);
1993
1994 if (isNew)
1995 {
1996 lvUSBFilters->setSelected (item, true);
1997 lvUSBFilters_currentChanged (item);
1998 settings->leUSBFilterName->setFocus();
1999 }
2000
2001 connect (settings->leUSBFilterName, SIGNAL (textChanged (const QString &)),
2002 this, SLOT (lvUSBFilters_setCurrentText (const QString &)));
2003
2004 /* setup validation */
2005
2006 QIWidgetValidator *wval = new QIWidgetValidator (settings, settings);
2007 connect (wval, SIGNAL (validityChanged (const QIWidgetValidator *)),
2008 this, SLOT (enableOk (const QIWidgetValidator *)));
2009
2010 wval->revalidate();
2011}
2012
2013void VBoxVMSettingsDlg::lvUSBFilters_currentChanged (QListViewItem *item)
2014{
2015 if (item && lvUSBFilters->selectedItem() != item)
2016 lvUSBFilters->setSelected (item, true);
2017
2018 tbRemoveUSBFilter->setEnabled (!!item);
2019
2020 tbUSBFilterUp->setEnabled (!!item && item->itemAbove());
2021 tbUSBFilterDown->setEnabled (!!item && item->itemBelow());
2022
2023 if (item)
2024 {
2025 USBListItem *uli = static_cast <USBListItem *> (item);
2026 wstUSBFilters->raiseWidget (uli->mId);
2027 }
2028 else
2029 {
2030 /* raise the disabled widget */
2031 wstUSBFilters->raiseWidget (0);
2032 }
2033}
2034
2035void VBoxVMSettingsDlg::lvUSBFilters_setCurrentText (const QString &aText)
2036{
2037 QListViewItem *item = lvUSBFilters->currentItem();
2038 Assert (item);
2039
2040 item->setText (lvUSBFilters_Name, aText);
2041}
2042
2043void VBoxVMSettingsDlg::tbAddUSBFilter_clicked()
2044{
2045 /* search for the max available filter index */
2046 int maxFilterIndex = 0;
2047 QString usbFilterName = tr ("New Filter %1", "usb");
2048 QRegExp regExp (QString ("^") + usbFilterName.arg ("([0-9]+)") + QString ("$"));
2049 QListViewItemIterator iterator (lvUSBFilters);
2050 while (*iterator)
2051 {
2052 QString filterName = (*iterator)->text (lvUSBFilters_Name);
2053 int pos = regExp.search (filterName);
2054 if (pos != -1)
2055 maxFilterIndex = regExp.cap (1).toInt() > maxFilterIndex ?
2056 regExp.cap (1).toInt() : maxFilterIndex;
2057 ++ iterator;
2058 }
2059
2060 /* creating new usb filter */
2061 CUSBDeviceFilter filter = cmachine.GetUSBController()
2062 .CreateDeviceFilter (usbFilterName.arg (maxFilterIndex + 1));
2063
2064 filter.SetActive (true);
2065 addUSBFilter (filter, true /* isNew */);
2066
2067 mUSBFilterListModified = true;
2068}
2069
2070void VBoxVMSettingsDlg::tbAddUSBFilterFrom_clicked()
2071{
2072 usbDevicesMenu->exec (QCursor::pos());
2073}
2074
2075void VBoxVMSettingsDlg::menuAddUSBFilterFrom_activated (int aIndex)
2076{
2077 CUSBDevice usb = usbDevicesMenu->getUSB (aIndex);
2078 /* if null then some other item but a USB device is selected */
2079 if (usb.isNull())
2080 return;
2081
2082 CUSBDeviceFilter filter = cmachine.GetUSBController()
2083 .CreateDeviceFilter (vboxGlobal().details (usb));
2084
2085 filter.SetVendorId (QString().sprintf ("%04hX", usb.GetVendorId()));
2086 filter.SetProductId (QString().sprintf ("%04hX", usb.GetProductId()));
2087 filter.SetRevision (QString().sprintf ("%04hX", usb.GetRevision()));
2088 /* The port property depends on the host computer rather than on the USB
2089 * device itself; for this reason only a few people will want to use it in
2090 * the filter since the same device plugged into a different socket will
2091 * not match the filter in this case. */
2092#if 0
2093 /// @todo set it anyway if Alt is currently pressed
2094 filter.SetPort (QString().sprintf ("%04hX", usb.GetPort()));
2095#endif
2096 filter.SetManufacturer (usb.GetManufacturer());
2097 filter.SetProduct (usb.GetProduct());
2098 filter.SetSerialNumber (usb.GetSerialNumber());
2099 filter.SetRemote (usb.GetRemote() ? "yes" : "no");
2100
2101 filter.SetActive (true);
2102 addUSBFilter (filter, true /* isNew */);
2103
2104 mUSBFilterListModified = true;
2105}
2106
2107void VBoxVMSettingsDlg::tbRemoveUSBFilter_clicked()
2108{
2109 QListViewItem *item = lvUSBFilters->currentItem();
2110 Assert (item);
2111
2112 USBListItem *uli = static_cast <USBListItem *> (item);
2113 QWidget *settings = wstUSBFilters->widget (uli->mId);
2114 Assert (settings);
2115 wstUSBFilters->removeWidget (settings);
2116 delete settings;
2117
2118 delete item;
2119
2120 lvUSBFilters->setSelected (lvUSBFilters->currentItem(), true);
2121 mUSBFilterListModified = true;
2122}
2123
2124void VBoxVMSettingsDlg::tbUSBFilterUp_clicked()
2125{
2126 QListViewItem *item = lvUSBFilters->currentItem();
2127 Assert (item);
2128
2129 QListViewItem *itemAbove = item->itemAbove();
2130 Assert (itemAbove);
2131 itemAbove = itemAbove->itemAbove();
2132
2133 if (!itemAbove)
2134 {
2135 /* overcome Qt stupidity */
2136 item->itemAbove()->moveItem (item);
2137 }
2138 else
2139 item->moveItem (itemAbove);
2140
2141 lvUSBFilters_currentChanged (item);
2142 mUSBFilterListModified = true;
2143}
2144
2145void VBoxVMSettingsDlg::tbUSBFilterDown_clicked()
2146{
2147 QListViewItem *item = lvUSBFilters->currentItem();
2148 Assert (item);
2149
2150 QListViewItem *itemBelow = item->itemBelow();
2151 Assert (itemBelow);
2152
2153 item->moveItem (itemBelow);
2154
2155 lvUSBFilters_currentChanged (item);
2156 mUSBFilterListModified = true;
2157}
2158
2159#include "VBoxVMSettingsDlg.ui.moc"
2160
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