VirtualBox

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

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

1942: Improve automatic naming for "Add New..." Uis

Feature implemented as designed:
Search algorithm will find the last created default named interface (filter) and will use its index+1 as a starting index for the newly created ones.

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