VirtualBox

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

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

FE/Qt: Corrected a major problem with whatsthis balloons containing HTML markup and line-feeds -- Qt couldn't detect the rich-text and therefore would display the text as is (showing HTML tags and breaking lines). All language files have been synchronized.

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