VirtualBox

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

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

FE/Qt: Corrected the fix for #1989.

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