VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/ui/VBoxGlobalSettingsDlg.ui.h@ 8192

Last change on this file since 8192 was 8192, checked in by vboxsync, 17 years ago

missing rebrands

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 35.6 KB
Line 
1/**
2 *
3 * VBox frontends: Qt GUI ("VirtualBox"):
4 * "Global settings" dialog UI include (Qt Designer)
5 */
6
7/*
8 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
19 * Clara, CA 95054 USA or visit http://www.sun.com if you need
20 * additional information or have any questions.
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#include <iprt/err.h>
33#include <iprt/param.h>
34#include <iprt/path.h>
35
36/* defined in VBoxGlobal.cpp */
37extern const char *gVBoxLangSubDir;
38extern const char *gVBoxLangFileBase;
39extern const char *gVBoxLangFileExt;
40extern const char *gVBoxLangIDRegExp;
41extern const char *gVBoxBuiltInLangName;
42
43/**
44 * Returns the path to the item in the form of 'grandparent > parent > item'
45 * using the text of the first column of every item.
46 */
47static QString path (QListViewItem *li)
48{
49 static QString sep = ": ";
50 QString p;
51 QListViewItem *cur = li;
52 while (cur)
53 {
54 if (!p.isNull())
55 p = sep + p;
56 p = cur->text (0).simplifyWhiteSpace() + p;
57 cur = cur->parent();
58 }
59 return p;
60}
61
62
63enum
64{
65 // listView column numbers
66 listView_Category = 0,
67 listView_Id = 1,
68 listView_Link = 2,
69};
70
71
72class USBListItem : public QCheckListItem
73{
74public:
75
76 USBListItem (QListView *aParent, QListViewItem *aAfter)
77 : QCheckListItem (aParent, aAfter, QString::null, CheckBox)
78 , mId (-1) {}
79
80 int mId;
81};
82enum { lvUSBFilters_Name = 0 };
83
84
85class LanguageItem : public QListViewItem
86{
87public:
88
89 enum { TypeId = 1001 };
90
91 LanguageItem (QListView *aParent, const QTranslator &aTranslator,
92 const QString &aId, bool aBuiltIn = false)
93 : QListViewItem (aParent), mBuiltIn (aBuiltIn), mInvalid (false)
94 {
95 Assert (!aId.isEmpty());
96
97 QTranslatorMessage transMes;
98
99 /* Note: context/source/comment arguments below must match strings
100 * used in VBoxGlobal::languageName() and friends (the latter are the
101 * source of information for the lupdate tool that generates
102 * translation files) */
103
104 QString nativeLanguage = tratra (aTranslator,
105 "@@@", "English", "Native language name");
106 QString nativeCountry = tratra (aTranslator,
107 "@@@", "--", "Native language country name "
108 "(empty if this language is for all countries)");
109
110 QString englishLanguage = tratra (aTranslator,
111 "@@@", "English", "Language name, in English");
112 QString englishCountry = tratra (aTranslator,
113 "@@@", "--", "Language country name, in English "
114 "(empty if native country name is empty)");
115
116 QString translatorsName = tratra (aTranslator,
117 "@@@", "Sun Microsystems, Inc.", "Comma-separated list of translators");
118
119 QString itemName = nativeLanguage;
120 QString langName = englishLanguage;
121
122 if (!aBuiltIn)
123 {
124 if (nativeCountry != "--")
125 itemName += " (" + nativeCountry + ")";
126
127 if (englishCountry != "--")
128 langName += " (" + englishCountry + ")";
129
130 if (itemName != langName)
131 langName = itemName + " / " + langName;
132 }
133 else
134 {
135 itemName += VBoxGlobalSettingsDlg::tr (" (built-in)", "Language");
136 langName += VBoxGlobalSettingsDlg::tr (" (built-in)", "Language");
137 }
138
139 setText (0, itemName);
140 setText (1, aId);
141 setText (2, langName);
142 setText (3, translatorsName);
143 }
144
145 /* Constructs an item for an invalid language ID (i.e. when a language
146 * file is missing or corrupt). */
147 LanguageItem (QListView *aParent, const QString &aId)
148 : QListViewItem (aParent), mBuiltIn (false), mInvalid (true)
149 {
150 Assert (!aId.isEmpty());
151
152 setText (0, QString ("<%1>").arg (aId));
153 setText (1, aId);
154 setText (2, VBoxGlobalSettingsDlg::tr ("<unavailable>", "Language"));
155 setText (3, VBoxGlobalSettingsDlg::tr ("<unknown>", "Author(s)"));
156 }
157
158 /* Constructs an item for the default language ID (column 1 will be set
159 * to QString::null) */
160 LanguageItem (QListView *aParent)
161 : QListViewItem (aParent), mBuiltIn (false), mInvalid (false)
162 {
163 setText (0, VBoxGlobalSettingsDlg::tr ("Default", "Language"));
164 setText (1, QString::null);
165 /* empty strings of some reasonable length to prevent the info part
166 * from being shrinked too much when the list wants to be wider */
167 setText (2, " ");
168 setText (3, " ");
169 }
170
171 int rtti() const { return TypeId; }
172
173 int compare (QListViewItem *aItem, int aColumn, bool aAscending) const
174 {
175 QString thisId = text (1);
176 QString thatId = aItem->text (1);
177 if (thisId.isNull())
178 return -1;
179 if (thatId.isNull())
180 return 1;
181 if (mBuiltIn)
182 return -1;
183 if (aItem->rtti() == TypeId && ((LanguageItem *) aItem)->mBuiltIn)
184 return 1;
185 return QListViewItem::compare (aItem, aColumn, aAscending);
186 }
187
188 void paintCell (QPainter *aPainter, const QColorGroup &aGroup,
189 int aColumn, int aWidth, int aAlign)
190 {
191 QFont font = aPainter->font();
192
193 if (mInvalid)
194 font.setItalic (true);
195 /* mark the effectively active language */
196 if (text (1) == VBoxGlobal::languageId())
197 font.setBold (true);
198
199 if (aPainter->font() != font)
200 aPainter->setFont (font);
201
202 QListViewItem::paintCell (aPainter, aGroup, aColumn, aWidth, aAlign);
203
204 if (mBuiltIn)
205 {
206 int y = height() - 1;
207 aPainter->setPen (aGroup.mid());
208 aPainter->drawLine (0, y, aWidth - 1, y);
209 }
210 }
211
212 int width (const QFontMetrics &aFM, const QListView *aLV, int aC) const
213 {
214 QFont font = aLV->font();
215
216 if (mInvalid)
217 font.setItalic (true);
218 /* mark the effectively active language */
219 if (text (1) == VBoxGlobal::languageId())
220 font.setBold (true);
221
222 QFontMetrics fm = aFM;
223 if (aLV->font() != font)
224 fm = QFontMetrics (font);
225
226 return QListViewItem::width (fm, aLV, aC);
227 }
228
229 void setup ()
230 {
231 QListViewItem::setup();
232 if (mBuiltIn)
233 setHeight (height() + 1);
234 }
235
236private:
237
238 QString tratra (const QTranslator &aTranslator, const char *aCtxt,
239 const char *aSrc, const char *aCmnt)
240 {
241 QString msg = aTranslator.findMessage (aCtxt, aSrc, aCmnt).translation();
242 /* return the source text if no translation is found */
243 if (msg.isEmpty())
244 msg = QString (aSrc);
245 return msg;
246 }
247
248 bool mBuiltIn : 1;
249 bool mInvalid : 1;
250};
251
252
253void VBoxGlobalSettingsDlg::init()
254{
255 polished = false;
256
257 setIcon (QPixmap::fromMimeSource ("global_settings_16px.png"));
258
259 /* all pages are initially valid */
260 valid = true;
261 buttonOk->setEnabled (true);
262 warningSpacer->changeSize (0, 0, QSizePolicy::Expanding);
263 warningLabel->setHidden (true);
264 warningPixmap->setHidden (true);
265
266 /* disable unselecting items by clicking in the unused area of the list */
267 new QIListViewSelectionPreserver (this, listView);
268 /* hide the header and internal columns */
269 listView->header()->hide();
270 listView->setColumnWidthMode (listView_Id, QListView::Manual);
271 listView->setColumnWidthMode (listView_Link, QListView::Manual);
272 listView->hideColumn (listView_Id);
273 listView->hideColumn (listView_Link);
274 /* sort by the id column (to have pages in the desired order) */
275 listView->setSorting (listView_Id);
276 listView->sort();
277
278 warningPixmap->setMaximumSize( 16, 16 );
279 warningPixmap->setPixmap( QMessageBox::standardIcon( QMessageBox::Warning ) );
280
281 /* page title font is derived from the system font */
282 QFont f = font();
283 f.setBold( true );
284 f.setPointSize( f.pointSize() + 2 );
285 titleLabel->setFont( f );
286
287 /* setup the what's this label */
288 QApplication::setGlobalMouseTracking (true);
289 qApp->installEventFilter (this);
290 whatsThisTimer = new QTimer (this);
291 connect (whatsThisTimer, SIGNAL (timeout()), this, SLOT (updateWhatsThis()));
292 whatsThisCandidate = NULL;
293
294 whatsThisLabel = new QIRichLabel (this, "whatsThisLabel");
295 VBoxGlobalSettingsDlgLayout->addWidget (whatsThisLabel, 2, 1);
296
297#ifndef DEBUG
298 /* Enforce rich text format to avoid jumping margins (margins of plain
299 * text labels seem to be smaller). We don't do it in the DEBUG builds to
300 * be able to immediately catch badly formatted text (i.e. text that
301 * contains HTML tags but doesn't start with <qt> so that Qt isn't able to
302 * recognize it as rich text and draws all tags as is instead of doing
303 * formatting). We want to catch this text because this is how it will look
304 * in the whatsthis balloon where we cannot enforce rich text. */
305 whatsThisLabel->setTextFormat (Qt::RichText);
306#endif
307
308 whatsThisLabel->setMaxHeightMode (true);
309 whatsThisLabel->setFocusPolicy (QWidget::NoFocus);
310 whatsThisLabel->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Fixed);
311 whatsThisLabel->setBackgroundMode (QLabel::PaletteMidlight);
312 whatsThisLabel->setFrameShape (QLabel::Box);
313 whatsThisLabel->setFrameShadow (QLabel::Sunken);
314 whatsThisLabel->setMargin (7);
315 whatsThisLabel->setScaledContents (FALSE);
316 whatsThisLabel->setAlignment (int (QLabel::WordBreak |
317 QLabel::AlignJustify |
318 QLabel::AlignTop));
319
320 whatsThisLabel->setFixedHeight (whatsThisLabel->frameWidth() * 2 +
321 6 /* seems that RichText adds some margin */ +
322 whatsThisLabel->fontMetrics().lineSpacing() * 4);
323 whatsThisLabel->setMinimumWidth (whatsThisLabel->frameWidth() * 2 +
324 6 /* seems that RichText adds some margin */ +
325 whatsThisLabel->fontMetrics().width ('m') * 40);
326
327 /*
328 * create and layout non-standard widgets
329 * ----------------------------------------------------------------------
330 */
331
332 hkeHostKey = new QIHotKeyEdit (grbKeyboard, "hkeHostKey");
333 hkeHostKey->setSizePolicy (QSizePolicy (QSizePolicy::Preferred, QSizePolicy::Fixed));
334 QWhatsThis::add (hkeHostKey,
335 tr ("Displays the key used as a Host Key in the VM window. Activate the "
336 "entry field and press a new Host Key. Note that alphanumeric, "
337 "cursor movement and editing keys cannot be used as a Host Key."));
338 layoutHostKey->addWidget (hkeHostKey);
339 txHostKey->setBuddy (hkeHostKey);
340 setTabOrder (listView, hkeHostKey);
341
342 /*
343 * setup connections and set validation for pages
344 * ----------------------------------------------------------------------
345 */
346
347 /* General page */
348
349 wvalGeneral = new QIWidgetValidator (pagePath (pageGeneral), pageGeneral, this);
350 connect (wvalGeneral, SIGNAL (validityChanged (const QIWidgetValidator *)),
351 this, SLOT (enableOk( const QIWidgetValidator *)));
352
353 /* Keyboard page */
354
355 wvalKeyboard = new QIWidgetValidator (pagePath (pageKeyboard), pageKeyboard, this);
356 connect (wvalKeyboard, SIGNAL (validityChanged (const QIWidgetValidator *)),
357 this, SLOT (enableOk( const QIWidgetValidator *)));
358
359 /* USB page */
360
361 lvUSBFilters->header()->hide();
362 /* disable sorting */
363 lvUSBFilters->setSorting (-1);
364 /* disable unselecting items by clicking in the unused area of the list */
365 new QIListViewSelectionPreserver (this, lvUSBFilters);
366 wstUSBFilters = new QWidgetStack (grbUSBFilters, "wstUSBFilters");
367 grbUSBFiltersLayout->addWidget (wstUSBFilters);
368 /* create a default (disabled) filter settings widget at index 0 */
369 VBoxUSBFilterSettings *settings = new VBoxUSBFilterSettings (wstUSBFilters);
370 settings->setup (VBoxUSBFilterSettings::HostType);
371 wstUSBFilters->addWidget (settings, 0);
372 lvUSBFilters_currentChanged (NULL);
373
374 /* toolbar */
375 {
376 VBoxToolBar *toolBar = new VBoxToolBar (0, grbUSBFilters, "USBToolBar");
377
378 mAddUSBFilterAct->addTo (toolBar);
379 mAddUSBFilterFromAct->addTo (toolBar);
380 mRemoveUSBFilterAct->addTo (toolBar);
381 mUSBFilterUpAct->addTo (toolBar);
382 mUSBFilterDownAct->addTo (toolBar);
383
384 toolBar->setUsesTextLabel (false);
385 toolBar->setUsesBigPixmaps (false);
386 toolBar->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
387 toolBar->setOrientation (Qt::Vertical);
388 #ifdef Q_WS_MAC
389 toolBar->setMacStyle();
390 #endif
391 mUSBToolBarLayout->insertWidget (0, toolBar);
392 }
393
394 /* context menu */
395 mUSBContextMenu = new QPopupMenu (this);
396 mAddUSBFilterAct->addTo (mUSBContextMenu);
397 mAddUSBFilterFromAct->addTo (mUSBContextMenu);
398 mRemoveUSBFilterAct->addTo (mUSBContextMenu);
399 mUSBFilterUpAct->addTo (mUSBContextMenu);
400 mUSBFilterDownAct->addTo (mUSBContextMenu);
401
402 /* icons */
403 mAddUSBFilterAct->setIconSet (VBoxGlobal::iconSet ("usb_new_16px.png",
404 "usb_new_disabled_16px.png"));
405 mAddUSBFilterFromAct->setIconSet (VBoxGlobal::iconSet ("usb_add_16px.png",
406 "usb_add_disabled_16px.png"));
407 mRemoveUSBFilterAct->setIconSet (VBoxGlobal::iconSet ("usb_remove_16px.png",
408 "usb_remove_disabled_16px.png"));
409 mUSBFilterUpAct->setIconSet (VBoxGlobal::iconSet ("usb_moveup_16px.png",
410 "usb_moveup_disabled_16px.png"));
411 mUSBFilterDownAct->setIconSet (VBoxGlobal::iconSet ("usb_movedown_16px.png",
412 "usb_movedown_disabled_16px.png"));
413
414 /* create menu of existing usb-devices */
415 usbDevicesMenu = new VBoxUSBMenu (this);
416 connect (usbDevicesMenu, SIGNAL(activated(int)), this, SLOT(menuAddUSBFilterFrom_activated(int)));
417 mUSBFilterListModified = false;
418
419 /*
420 * set initial values
421 * ----------------------------------------------------------------------
422 */
423
424 /* General page */
425
426 /* keyboard page */
427
428 /* Language page */
429
430 lvLanguages->header()->hide();
431 lvLanguages->setSorting (0);
432
433 char szNlsPath[RTPATH_MAX];
434 int rc = RTPathAppPrivateNoArch (szNlsPath, sizeof(szNlsPath));
435 AssertRC (rc);
436 QString nlsPath = QString (szNlsPath) + gVBoxLangSubDir;
437 QDir nlsDir (nlsPath);
438 QStringList files = nlsDir.entryList (QString ("%1*%2")
439 .arg (gVBoxLangFileBase, gVBoxLangFileExt),
440 QDir::Files);
441 QTranslator translator;
442 /* add the default language */
443 new LanguageItem (lvLanguages);
444 /* add the built-in language */
445 new LanguageItem (lvLanguages, translator, gVBoxBuiltInLangName, true /* built-in */);
446 /* add all existing languages */
447 for (QStringList::Iterator it = files.begin(); it != files.end(); ++ it)
448 {
449 QString fileName = *it;
450 QRegExp regExp (QString (gVBoxLangFileBase) + gVBoxLangIDRegExp);
451 int pos = regExp.search (fileName);
452 if (pos == -1)
453 continue;
454
455 bool loadOk = translator.load (fileName, nlsPath);
456 if (!loadOk)
457 continue;
458
459 new LanguageItem (lvLanguages, translator, regExp.cap (1));
460 }
461 lvLanguages->adjustColumn (0);
462
463 /*
464 * update the Ok button state for pages with validation
465 * (validityChanged() connected to enableNext() will do the job)
466 */
467 wvalGeneral->revalidate();
468 wvalKeyboard->revalidate();
469}
470
471/**
472 * Returns a path to the given page of this settings dialog. See ::path() for
473 * details.
474 */
475QString VBoxGlobalSettingsDlg::pagePath (QWidget *aPage)
476{
477 QListViewItem *li = listView->
478 findItem (QString::number (widgetStack->id (aPage)), 1);
479 return ::path (li);
480}
481
482bool VBoxGlobalSettingsDlg::event (QEvent *aEvent)
483{
484 bool result = QWidget::event (aEvent);
485 if (aEvent->type() == QEvent::LanguageChange)
486 {
487 /* set the first item selected */
488 listView->setSelected (listView->firstChild(), true);
489 listView_currentChanged (listView->firstChild());
490 lvLanguages_currentChanged (lvLanguages->currentItem());
491 mLanguageChanged = false;
492 fixLanguageChange();
493 }
494 return result;
495}
496
497bool VBoxGlobalSettingsDlg::eventFilter (QObject *object, QEvent *event)
498{
499 if (!object->isWidgetType())
500 return QDialog::eventFilter (object, event);
501
502 QWidget *widget = static_cast <QWidget *> (object);
503 if (widget->topLevelWidget() != this)
504 return QDialog::eventFilter (object, event);
505
506 switch (event->type())
507 {
508 case QEvent::Enter:
509 case QEvent::Leave:
510 {
511 if (event->type() == QEvent::Enter)
512 whatsThisCandidate = widget;
513 else
514 whatsThisCandidate = NULL;
515 whatsThisTimer->start (100, true /* sshot */);
516 break;
517 }
518 case QEvent::FocusIn:
519 {
520 updateWhatsThis (true /* gotFocus */);
521 break;
522 }
523 case QEvent::Show:
524 {
525 if (widget == pageLanguage)
526 lvLanguages->updateGeometry();
527 break;
528 }
529 default:
530 break;
531 }
532
533 return QDialog::eventFilter (object, event);
534}
535
536void VBoxGlobalSettingsDlg::showEvent (QShowEvent *e)
537{
538 QDialog::showEvent (e);
539
540 /* one may think that QWidget::polish() is the right place to do things
541 * below, but apparently, by the time when QWidget::polish() is called,
542 * the widget style & layout are not fully done, at least the minimum
543 * size hint is not properly calculated. Since this is sometimes necessary,
544 * we provide our own "polish" implementation. */
545
546 if (polished)
547 return;
548
549 polished = true;
550
551 /* update geometry for the dynamically added usb-page to ensure proper
552 * sizeHint calculation by the Qt layout manager */
553 wstUSBFilters->updateGeometry();
554 /* let our toplevel widget calculate its sizeHint properly */
555 QApplication::sendPostedEvents (0, 0);
556
557 /* resize to the miminum possible size */
558 resize (minimumSize());
559
560 VBoxGlobal::centerWidget (this, parentWidget());
561}
562
563void VBoxGlobalSettingsDlg::listView_currentChanged (QListViewItem *item)
564{
565 Assert (item);
566 int id = item->text (1).toInt();
567 Assert (id >= 0);
568 titleLabel->setText (::path (item));
569 widgetStack->raiseWidget (id);
570}
571
572void VBoxGlobalSettingsDlg::enableOk (const QIWidgetValidator *wval)
573{
574 Q_UNUSED (wval);
575
576 /* reset the warning text; interested parties will set it during
577 * validation */
578 setWarning (QString::null);
579
580 QString wvalWarning;
581
582 /* detect the overall validity */
583 bool newValid = true;
584 {
585 QObjectList *l = this->queryList ("QIWidgetValidator");
586 QObjectListIt it (*l);
587 QObject *obj;
588 while ((obj = it.current()) != 0)
589 {
590 QIWidgetValidator *wval = (QIWidgetValidator *) obj;
591 newValid = wval->isValid();
592 if (!newValid)
593 {
594 wvalWarning = wval->warningText();
595 break;
596 }
597 ++ it;
598 }
599 delete l;
600 }
601
602 if (warningString.isNull() && !wvalWarning.isNull())
603 {
604 /* try to set the generic error message when invalid but no specific
605 * message is provided */
606 setWarning (wvalWarning);
607 }
608
609 if (valid != newValid)
610 {
611 valid = newValid;
612 buttonOk->setEnabled (valid);
613 /// @todo in VBoxVMSettingsDlg.ui.h, this is absent at all. Is it
614 /// really what we want?
615#if 0
616 if (valid)
617 warningSpacer->changeSize (0, 0, QSizePolicy::Expanding);
618 else
619 warningSpacer->changeSize (0, 0);
620#endif
621 warningLabel->setHidden (valid);
622 warningPixmap->setHidden (valid);
623 }
624}
625
626void VBoxGlobalSettingsDlg::revalidate (QIWidgetValidator * /*wval*/)
627{
628 /* do individual validations for pages */
629
630 /* currently nothing */
631}
632
633/**
634 * Reads global settings from the given VBoxGlobalSettings instance
635 * and from the given CSystemProperties object.
636 */
637void VBoxGlobalSettingsDlg::getFrom (const CSystemProperties &props,
638 const VBoxGlobalSettings &gs)
639{
640 /* default folders */
641
642 leVDIFolder->setText (props.GetDefaultVDIFolder());
643 leMachineFolder->setText (props.GetDefaultMachineFolder());
644
645 /* vrdp lib path */
646 leVRDPLib->setText (props.GetRemoteDisplayAuthLibrary());
647
648 /* VT-x/AMD-V */
649 chbVTX->setChecked (props.GetHWVirtExEnabled());
650
651 /* proprietary GUI settings */
652
653 hkeHostKey->setKey (gs.hostKey() );
654 chbAutoCapture->setChecked (gs.autoCapture());
655
656 /* usb filters page */
657
658#ifdef DEBUG_dmik
659 CHost host = vboxGlobal().virtualBox().GetHost();
660 CHostUSBDeviceFilterCollection coll = host.GetUSBDeviceFilters();
661
662 /* Show an error message (if there is any).
663 * This message box may be suppressed if the user wishes so. */
664 if (!host.isReallyOk())
665 vboxProblem().cannotAccessUSB (host);
666
667 if (coll.isNull())
668 {
669#endif
670 /* disable the USB host filters category if the USB is
671 * not available (i.e. in VirtualBox OSE) */
672
673 QListViewItem *usbItem = listView->findItem ("#usb", listView_Link);
674 Assert (usbItem);
675 usbItem->setVisible (false);
676
677 /* disable validators if any */
678 pageUSB->setEnabled (false);
679
680#ifdef DEBUG_dmik
681 }
682 else
683 {
684 CHostUSBDeviceFilterEnumerator en = coll.Enumerate();
685 while (en.HasMore())
686 {
687 CHostUSBDeviceFilter hostFilter = en.GetNext();
688 CUSBDeviceFilter filter = CUnknown (hostFilter);
689 addUSBFilter (filter, false);
690 }
691 lvUSBFilters->setCurrentItem (lvUSBFilters->firstChild());
692 lvUSBFilters_currentChanged (lvUSBFilters->firstChild());
693 }
694#endif
695
696 /* language properties */
697
698 QString langId = gs.languageId();
699 QListViewItem *item = lvLanguages->findItem (langId, 1);
700 if (!item)
701 {
702 /* add an item for an invalid language to represent it in the list */
703 item = new LanguageItem (lvLanguages, langId);
704 lvLanguages->adjustColumn (0);
705 }
706 Assert (item);
707 if (item)
708 {
709 lvLanguages->setCurrentItem (item);
710 lvLanguages->setSelected (item, true);
711 }
712}
713
714/**
715 * Writes global settings to the given VBoxGlobalSettings instance
716 * and to the given CSystemProperties object.
717 */
718void VBoxGlobalSettingsDlg::putBackTo (CSystemProperties &props,
719 VBoxGlobalSettings &gs)
720{
721 /* default folders */
722
723 if (leVDIFolder->isModified())
724 props.SetDefaultVDIFolder (leVDIFolder->text());
725 if (props.isOk() && leMachineFolder->isModified())
726 props.SetDefaultMachineFolder (leMachineFolder->text());
727
728 /* vrdp lib path */
729 if (leVRDPLib->isModified())
730 props.SetRemoteDisplayAuthLibrary (leVRDPLib->text());
731
732 /* VT-x/AMD-V */
733 props.SetHWVirtExEnabled (chbVTX->isChecked());
734
735 if (!props.isOk())
736 return;
737
738 /* proprietary GUI settings */
739
740 gs.setHostKey (hkeHostKey->key());
741 gs.setAutoCapture (chbAutoCapture->isChecked());
742
743 /* usb filter page */
744
745 /*
746 * first, remove all old filters (only if the list is changed,
747 * not only individual properties of filters)
748 */
749 CHost host = vboxGlobal().virtualBox().GetHost();
750 if (mUSBFilterListModified)
751 for (ulong cnt = host.GetUSBDeviceFilters().GetCount(); cnt; -- cnt)
752 host.RemoveUSBDeviceFilter (0);
753
754 /* then add all new filters */
755 for (QListViewItem *item = lvUSBFilters->firstChild(); item;
756 item = item->nextSibling())
757 {
758 USBListItem *uli = static_cast <USBListItem *> (item);
759 VBoxUSBFilterSettings *settings =
760 static_cast <VBoxUSBFilterSettings *>
761 (wstUSBFilters->widget (uli->mId));
762 Assert (settings);
763
764 COMResult res = settings->putBackToFilter();
765 if (!res.isOk())
766 return;
767
768 CUSBDeviceFilter filter = settings->filter();
769 filter.SetActive (uli->isOn());
770
771 CHostUSBDeviceFilter insertedFilter = CUnknown (filter);
772 if (mUSBFilterListModified)
773 host.InsertUSBDeviceFilter (host.GetUSBDeviceFilters().GetCount(),
774 insertedFilter);
775 }
776 mUSBFilterListModified = false;
777
778 /* language properties */
779
780 QListViewItem *selItem = lvLanguages->selectedItem();
781 Assert (selItem);
782 if (mLanguageChanged && selItem)
783 {
784 gs.setLanguageId (selItem->text (1));
785 VBoxGlobal::loadLanguage (selItem->text (1));
786 }
787}
788
789void VBoxGlobalSettingsDlg::updateWhatsThis (bool gotFocus /* = false */)
790{
791 QString text;
792
793 QWidget *widget = NULL;
794 if (!gotFocus)
795 {
796 if (whatsThisCandidate != NULL && whatsThisCandidate != this)
797 widget = whatsThisCandidate;
798 }
799 else
800 {
801 widget = focusData()->focusWidget();
802 }
803 /* if the given widget lacks the whats'this text, look at its parent */
804 while (widget && widget != this)
805 {
806 text = QWhatsThis::textFor (widget);
807 if (!text.isEmpty())
808 break;
809 widget = widget->parentWidget();
810 }
811
812 if (text.isEmpty() && !warningString.isEmpty())
813 text = warningString;
814 if (text.isEmpty())
815 text = QWhatsThis::textFor (this);
816
817 whatsThisLabel->setText (text);
818}
819
820void VBoxGlobalSettingsDlg::setWarning (const QString &warning)
821{
822 warningString = warning;
823 if (!warning.isEmpty())
824 warningString = QString ("<font color=red>%1</font>").arg (warning);
825
826 if (!warningString.isEmpty())
827 whatsThisLabel->setText (warningString);
828 else
829 updateWhatsThis (true);
830}
831
832void VBoxGlobalSettingsDlg::tbResetFolder_clicked()
833{
834 QToolButton *tb = ::qt_cast <QToolButton *> (sender());
835 Assert (tb);
836
837 QLineEdit *le = 0;
838 if (tb == tbResetVDIFolder) le = leVDIFolder;
839 else if (tb == tbResetMachineFolder) le = leMachineFolder;
840 else if (tb == tbResetVRDPLib) le = leVRDPLib;
841 Assert (le);
842
843 /*
844 * do this instead of le->setText (QString::null) to cause
845 * isModified() return true
846 */
847 le->selectAll();
848 le->del();
849}
850
851void VBoxGlobalSettingsDlg::tbSelectFolder_clicked()
852{
853 QToolButton *tb = ::qt_cast <QToolButton *> (sender());
854 Assert (tb);
855
856 QLineEdit *le = 0;
857 if (tb == tbSelectVDIFolder) le = leVDIFolder;
858 else if (tb == tbSelectMachineFolder) le = leMachineFolder;
859 else if (tb == tbSelectVRDPLib) le = leVRDPLib;
860 Assert (le);
861
862 QString initDir = VBoxGlobal::getFirstExistingDir (le->text());
863 if (initDir.isNull())
864 initDir = vboxGlobal().virtualBox().GetHomeFolder();
865
866 QString path = le == leVRDPLib ?
867 VBoxGlobal::getOpenFileName (initDir, QString::null, this,
868 "getFile", QString::null) :
869 VBoxGlobal::getExistingDirectory (initDir, this);
870 if (path.isNull())
871 return;
872
873 path = QDir::convertSeparators (path);
874 /* remove trailing slash if any */
875 path.remove (QRegExp ("[\\\\/]$"));
876
877 /*
878 * do this instead of le->setText (path) to cause
879 * isModified() return true
880 */
881 le->selectAll();
882 le->insert (path);
883}
884
885// USB Filter stuff
886////////////////////////////////////////////////////////////////////////////////
887
888void VBoxGlobalSettingsDlg::addUSBFilter (const CUSBDeviceFilter &aFilter,
889 bool aIsNew)
890{
891 QListViewItem *currentItem = aIsNew
892 ? lvUSBFilters->currentItem()
893 : lvUSBFilters->lastItem();
894
895 VBoxUSBFilterSettings *settings = new VBoxUSBFilterSettings (wstUSBFilters);
896 settings->setup (VBoxUSBFilterSettings::HostType);
897 settings->getFromFilter (aFilter);
898
899 USBListItem *item = new USBListItem (lvUSBFilters, currentItem);
900 item->setOn (aFilter.GetActive());
901 item->setText (lvUSBFilters_Name, aFilter.GetName());
902
903 item->mId = wstUSBFilters->addWidget (settings);
904
905 /* fix the tab order so that main dialog's buttons are always the last */
906 setTabOrder (settings->focusProxy(), buttonHelp);
907 setTabOrder (buttonHelp, buttonOk);
908 setTabOrder (buttonOk, buttonCancel);
909
910 if (aIsNew)
911 {
912 lvUSBFilters->setSelected (item, true);
913 lvUSBFilters_currentChanged (item);
914 settings->leUSBFilterName->setFocus();
915 }
916
917 connect (settings->leUSBFilterName, SIGNAL (textChanged (const QString &)),
918 this, SLOT (lvUSBFilters_setCurrentText (const QString &)));
919
920 /* setup validation */
921
922 QIWidgetValidator *wval =
923 new QIWidgetValidator (pagePath (pageUSB), settings, settings);
924 connect (wval, SIGNAL (validityChanged (const QIWidgetValidator *)),
925 this, SLOT (enableOk (const QIWidgetValidator *)));
926
927 wval->revalidate();
928}
929
930void VBoxGlobalSettingsDlg::lvUSBFilters_currentChanged (QListViewItem *item)
931{
932 if (item && lvUSBFilters->selectedItem() != item)
933 lvUSBFilters->setSelected (item, true);
934
935 mRemoveUSBFilterAct->setEnabled (!!item);
936
937 mUSBFilterUpAct->setEnabled (!!item && item->itemAbove());
938 mUSBFilterDownAct->setEnabled (!!item && item->itemBelow());
939
940 if (item)
941 {
942 USBListItem *uli = static_cast <USBListItem *> (item);
943 wstUSBFilters->raiseWidget (uli->mId);
944 }
945 else
946 {
947 /* raise the disabled widget */
948 wstUSBFilters->raiseWidget (0);
949 }
950}
951
952void VBoxGlobalSettingsDlg::lvUSBFilters_contextMenuRequested (QListViewItem *,
953 const QPoint &aPoint, int)
954{
955 mUSBContextMenu->exec (aPoint);
956}
957
958void VBoxGlobalSettingsDlg::lvUSBFilters_setCurrentText (const QString &aText)
959{
960 QListViewItem *item = lvUSBFilters->currentItem();
961 Assert (item);
962
963 item->setText (lvUSBFilters_Name, aText);
964}
965
966void VBoxGlobalSettingsDlg::addUSBFilterAct_activated()
967{
968 /* search for the max available filter index */
969 int maxFilterIndex = 0;
970 QString usbFilterName = tr ("New Filter %1", "usb");
971 QRegExp regExp (QString ("^") + usbFilterName.arg ("([0-9]+)") + QString ("$"));
972 QListViewItemIterator iterator (lvUSBFilters);
973 while (*iterator)
974 {
975 QString filterName = (*iterator)->text (lvUSBFilters_Name);
976 int pos = regExp.search (filterName);
977 if (pos != -1)
978 maxFilterIndex = regExp.cap (1).toInt() > maxFilterIndex ?
979 regExp.cap (1).toInt() : maxFilterIndex;
980 ++ iterator;
981 }
982
983 /* create a new usb filter */
984 CHost host = vboxGlobal().virtualBox().GetHost();
985 CHostUSBDeviceFilter hostFilter = host
986 .CreateUSBDeviceFilter (usbFilterName.arg (maxFilterIndex + 1));
987 hostFilter.SetAction (KUSBDeviceFilterAction_Hold);
988
989 CUSBDeviceFilter filter = CUnknown (hostFilter);
990 filter.SetActive (true);
991 addUSBFilter (filter, true);
992
993 mUSBFilterListModified = true;
994}
995
996void VBoxGlobalSettingsDlg::addUSBFilterFromAct_activated()
997{
998 QPoint pos = QCursor::pos();
999 QRect rect = frameGeometry();
1000 if (!rect.contains (pos))
1001 {
1002 pos = lvUSBFilters->parentWidget()->mapToGlobal (lvUSBFilters->pos());
1003 pos += QPoint (5, 5);
1004 }
1005
1006 usbDevicesMenu->exec (pos);
1007}
1008
1009void VBoxGlobalSettingsDlg::menuAddUSBFilterFrom_activated (int aIndex)
1010{
1011 CUSBDevice usb = usbDevicesMenu->getUSB (aIndex);
1012
1013 // if null then some other item but a USB device is selected
1014 if (usb.isNull())
1015 return;
1016
1017 CHost host = vboxGlobal().virtualBox().GetHost();
1018 CHostUSBDeviceFilter hostFilter = host
1019 .CreateUSBDeviceFilter (vboxGlobal().details (usb));
1020 hostFilter.SetAction (KUSBDeviceFilterAction_Hold);
1021
1022 CUSBDeviceFilter filter = CUnknown (hostFilter);
1023 filter.SetVendorId (QString().sprintf ("%04hX", usb.GetVendorId()));
1024 filter.SetProductId (QString().sprintf ("%04hX", usb.GetProductId()));
1025 filter.SetRevision (QString().sprintf ("%04hX", usb.GetRevision()));
1026 /* The port property depends on the host computer rather than on the USB
1027 * device itself; for this reason only a few people will want to use it in
1028 * the filter since the same device plugged into a different socket will
1029 * not match the filter in this case. */
1030#if 0
1031 /// @todo set it anyway if Alt is currently pressed
1032 filter.SetPort (QString().sprintf ("%04hX", usb.GetPort()));
1033#endif
1034 filter.SetManufacturer (usb.GetManufacturer());
1035 filter.SetProduct (usb.GetProduct());
1036 filter.SetSerialNumber (usb.GetSerialNumber());
1037 filter.SetRemote (usb.GetRemote() ? "yes" : "no");
1038
1039 filter.SetActive (true);
1040 addUSBFilter (filter, true);
1041
1042 mUSBFilterListModified = true;
1043}
1044
1045void VBoxGlobalSettingsDlg::removeUSBFilterAct_activated()
1046{
1047 QListViewItem *item = lvUSBFilters->currentItem();
1048 Assert (item);
1049
1050 USBListItem *uli = static_cast <USBListItem *> (item);
1051 QWidget *settings = wstUSBFilters->widget (uli->mId);
1052 Assert (settings);
1053 wstUSBFilters->removeWidget (settings);
1054 delete settings;
1055
1056 delete item;
1057
1058 lvUSBFilters->setSelected (lvUSBFilters->currentItem(), true);
1059 mUSBFilterListModified = true;
1060}
1061
1062void VBoxGlobalSettingsDlg::USBFilterUpAct_activated()
1063{
1064 QListViewItem *item = lvUSBFilters->currentItem();
1065 Assert (item);
1066
1067 QListViewItem *itemAbove = item->itemAbove();
1068 Assert (itemAbove);
1069 itemAbove = itemAbove->itemAbove();
1070
1071 if (!itemAbove)
1072 item->itemAbove()->moveItem (item);
1073 else
1074 item->moveItem (itemAbove);
1075
1076 lvUSBFilters_currentChanged (item);
1077 mUSBFilterListModified = true;
1078}
1079
1080void VBoxGlobalSettingsDlg::USBFilterDownAct_activated()
1081{
1082 QListViewItem *item = lvUSBFilters->currentItem();
1083 Assert (item);
1084
1085 QListViewItem *itemBelow = item->itemBelow();
1086 Assert (itemBelow);
1087
1088 item->moveItem (itemBelow);
1089
1090 lvUSBFilters_currentChanged (item);
1091 mUSBFilterListModified = true;
1092}
1093
1094void VBoxGlobalSettingsDlg::lvLanguages_currentChanged (QListViewItem *aItem)
1095{
1096 Assert (aItem);
1097 if (!aItem) return;
1098
1099 /* disable labels for the Default language item */
1100 bool enabled = !aItem->text (1).isNull();
1101
1102 tlLangName->setEnabled (enabled);
1103 tlAuthorName->setEnabled (enabled);
1104 tlLangData->setText (aItem->text (2));
1105 tlAuthorData->setText (aItem->text (3));
1106
1107 mLanguageChanged = true;
1108}
1109
1110void VBoxGlobalSettingsDlg::fixLanguageChange()
1111{
1112 /* fix for usb page */
1113
1114#ifdef DEBUG_dmik
1115 CHost host = vboxGlobal().virtualBox().GetHost();
1116 CHostUSBDeviceFilterCollection coll = host.GetUSBDeviceFilters();
1117 if (coll.isNull())
1118 {
1119#endif
1120 /* disable the USB host filters category if the USB is
1121 * not available (i.e. in VirtualBox OSE) */
1122
1123 QListViewItem *usbItem = listView->findItem ("#usb", listView_Link);
1124 Assert (usbItem);
1125 usbItem->setVisible (false);
1126
1127 /* disable validators if any */
1128 pageUSB->setEnabled (false);
1129
1130#ifdef DEBUG_dmik
1131 }
1132#endif
1133}
Note: See TracBrowser for help on using the repository browser.

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