VirtualBox

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

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

1934: Never decrease size in the layout:

Fixing minimum height of the VM & Global Settings Dialog whatsThisLabel so, that its height will never shrinks.

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