VirtualBox

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

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

Main & All Frontends: replaced the IGuestOSType IMachine::OSType property with the wstring IMachine::OSTypeId property (+ converted IGuest and IGuestOSType to VirtualBoxBaseNEXT semantics).

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette