VirtualBox

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

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

1934: Never decrease size in the layout:

QIConstrainKeeper used for the vertical size of the whatsThisLabel of VMSettings dialog, to have it's minimum size fixed at it's maximum value.

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