VirtualBox

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

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

FE/Qt: Don't set the Port property when creating a USB filter from the existing device, since it will make problems for most users.

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

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