VirtualBox

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

最後變更 在這個檔案從8155是 8155,由 vboxsync 提交於 17 年 前

The Big Sun Rebranding Header Change

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 34.2 KB
 
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.alldomusa.eu.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 "@@@", "innotek", "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 /* setup toolbutton icons */
374 tbAddUSBFilter->setIconSet (VBoxGlobal::iconSet ("usb_new_16px.png",
375 "usb_new_disabled_16px.png"));
376 tbAddUSBFilterFrom->setIconSet (VBoxGlobal::iconSet ("usb_add_16px.png",
377 "usb_add_disabled_16px.png"));
378 tbRemoveUSBFilter->setIconSet (VBoxGlobal::iconSet ("usb_remove_16px.png",
379 "usb_remove_disabled_16px.png"));
380 tbUSBFilterUp->setIconSet (VBoxGlobal::iconSet ("usb_moveup_16px.png",
381 "usb_moveup_disabled_16px.png"));
382 tbUSBFilterDown->setIconSet (VBoxGlobal::iconSet ("usb_movedown_16px.png",
383 "usb_movedown_disabled_16px.png"));
384 /* create menu of existing usb-devices */
385 usbDevicesMenu = new VBoxUSBMenu (this);
386 connect (usbDevicesMenu, SIGNAL(activated(int)), this, SLOT(menuAddUSBFilterFrom_activated(int)));
387 mUSBFilterListModified = false;
388
389 /*
390 * set initial values
391 * ----------------------------------------------------------------------
392 */
393
394 /* General page */
395
396 /* keyboard page */
397
398 /* Language page */
399
400 lvLanguages->header()->hide();
401 lvLanguages->setSorting (0);
402
403 char szNlsPath[RTPATH_MAX];
404 int rc = RTPathAppPrivateNoArch (szNlsPath, sizeof(szNlsPath));
405 AssertRC (rc);
406 QString nlsPath = QString (szNlsPath) + gVBoxLangSubDir;
407 QDir nlsDir (nlsPath);
408 QStringList files = nlsDir.entryList (QString ("%1*%2")
409 .arg (gVBoxLangFileBase, gVBoxLangFileExt),
410 QDir::Files);
411 QTranslator translator;
412 /* add the default language */
413 new LanguageItem (lvLanguages);
414 /* add the built-in language */
415 new LanguageItem (lvLanguages, translator, gVBoxBuiltInLangName, true /* built-in */);
416 /* add all existing languages */
417 for (QStringList::Iterator it = files.begin(); it != files.end(); ++ it)
418 {
419 QString fileName = *it;
420 QRegExp regExp (QString (gVBoxLangFileBase) + gVBoxLangIDRegExp);
421 int pos = regExp.search (fileName);
422 if (pos == -1)
423 continue;
424
425 bool loadOk = translator.load (fileName, nlsPath);
426 if (!loadOk)
427 continue;
428
429 new LanguageItem (lvLanguages, translator, regExp.cap (1));
430 }
431 lvLanguages->adjustColumn (0);
432
433 /*
434 * update the Ok button state for pages with validation
435 * (validityChanged() connected to enableNext() will do the job)
436 */
437 wvalGeneral->revalidate();
438 wvalKeyboard->revalidate();
439}
440
441/**
442 * Returns a path to the given page of this settings dialog. See ::path() for
443 * details.
444 */
445QString VBoxGlobalSettingsDlg::pagePath (QWidget *aPage)
446{
447 QListViewItem *li = listView->
448 findItem (QString::number (widgetStack->id (aPage)), 1);
449 return ::path (li);
450}
451
452bool VBoxGlobalSettingsDlg::event (QEvent *aEvent)
453{
454 bool result = QWidget::event (aEvent);
455 if (aEvent->type() == QEvent::LanguageChange)
456 {
457 /* set the first item selected */
458 listView->setSelected (listView->firstChild(), true);
459 listView_currentChanged (listView->firstChild());
460 lvLanguages_currentChanged (lvLanguages->currentItem());
461 mLanguageChanged = false;
462 fixLanguageChange();
463 }
464 return result;
465}
466
467bool VBoxGlobalSettingsDlg::eventFilter (QObject *object, QEvent *event)
468{
469 if (!object->isWidgetType())
470 return QDialog::eventFilter (object, event);
471
472 QWidget *widget = static_cast <QWidget *> (object);
473 if (widget->topLevelWidget() != this)
474 return QDialog::eventFilter (object, event);
475
476 switch (event->type())
477 {
478 case QEvent::Enter:
479 case QEvent::Leave:
480 {
481 if (event->type() == QEvent::Enter)
482 whatsThisCandidate = widget;
483 else
484 whatsThisCandidate = NULL;
485 whatsThisTimer->start (100, true /* sshot */);
486 break;
487 }
488 case QEvent::FocusIn:
489 {
490 updateWhatsThis (true /* gotFocus */);
491 break;
492 }
493 case QEvent::Show:
494 {
495 if (widget == pageLanguage)
496 lvLanguages->updateGeometry();
497 break;
498 }
499 default:
500 break;
501 }
502
503 return QDialog::eventFilter (object, event);
504}
505
506void VBoxGlobalSettingsDlg::showEvent (QShowEvent *e)
507{
508 QDialog::showEvent (e);
509
510 /* one may think that QWidget::polish() is the right place to do things
511 * below, but apparently, by the time when QWidget::polish() is called,
512 * the widget style & layout are not fully done, at least the minimum
513 * size hint is not properly calculated. Since this is sometimes necessary,
514 * we provide our own "polish" implementation. */
515
516 if (polished)
517 return;
518
519 polished = true;
520
521 /* update geometry for the dynamically added usb-page to ensure proper
522 * sizeHint calculation by the Qt layout manager */
523 wstUSBFilters->updateGeometry();
524 /* let our toplevel widget calculate its sizeHint properly */
525 QApplication::sendPostedEvents (0, 0);
526
527 /* resize to the miminum possible size */
528 resize (minimumSize());
529
530 VBoxGlobal::centerWidget (this, parentWidget());
531}
532
533void VBoxGlobalSettingsDlg::listView_currentChanged (QListViewItem *item)
534{
535 Assert (item);
536 int id = item->text (1).toInt();
537 Assert (id >= 0);
538 titleLabel->setText (::path (item));
539 widgetStack->raiseWidget (id);
540}
541
542void VBoxGlobalSettingsDlg::enableOk (const QIWidgetValidator *wval)
543{
544 Q_UNUSED (wval);
545
546 /* reset the warning text; interested parties will set it during
547 * validation */
548 setWarning (QString::null);
549
550 QString wvalWarning;
551
552 /* detect the overall validity */
553 bool newValid = true;
554 {
555 QObjectList *l = this->queryList ("QIWidgetValidator");
556 QObjectListIt it (*l);
557 QObject *obj;
558 while ((obj = it.current()) != 0)
559 {
560 QIWidgetValidator *wval = (QIWidgetValidator *) obj;
561 newValid = wval->isValid();
562 if (!newValid)
563 {
564 wvalWarning = wval->warningText();
565 break;
566 }
567 ++ it;
568 }
569 delete l;
570 }
571
572 if (warningString.isNull() && !wvalWarning.isNull())
573 {
574 /* try to set the generic error message when invalid but no specific
575 * message is provided */
576 setWarning (wvalWarning);
577 }
578
579 if (valid != newValid)
580 {
581 valid = newValid;
582 buttonOk->setEnabled (valid);
583 /// @todo in VBoxVMSettingsDlg.ui.h, this is absent at all. Is it
584 /// really what we want?
585#if 0
586 if (valid)
587 warningSpacer->changeSize (0, 0, QSizePolicy::Expanding);
588 else
589 warningSpacer->changeSize (0, 0);
590#endif
591 warningLabel->setHidden (valid);
592 warningPixmap->setHidden (valid);
593 }
594}
595
596void VBoxGlobalSettingsDlg::revalidate (QIWidgetValidator * /*wval*/)
597{
598 /* do individual validations for pages */
599
600 /* currently nothing */
601}
602
603/**
604 * Reads global settings from the given VBoxGlobalSettings instance
605 * and from the given CSystemProperties object.
606 */
607void VBoxGlobalSettingsDlg::getFrom (const CSystemProperties &props,
608 const VBoxGlobalSettings &gs)
609{
610 /* default folders */
611
612 leVDIFolder->setText (props.GetDefaultVDIFolder());
613 leMachineFolder->setText (props.GetDefaultMachineFolder());
614
615 /* vrdp lib path */
616 leVRDPLib->setText (props.GetRemoteDisplayAuthLibrary());
617
618 /* VT-x/AMD-V */
619 chbVTX->setChecked (props.GetHWVirtExEnabled());
620
621 /* proprietary GUI settings */
622
623 hkeHostKey->setKey (gs.hostKey() );
624 chbAutoCapture->setChecked (gs.autoCapture());
625
626 /* usb filters page */
627
628#ifdef DEBUG_dmik
629 CHost host = vboxGlobal().virtualBox().GetHost();
630 CHostUSBDeviceFilterCollection coll = host.GetUSBDeviceFilters();
631
632 /* Show an error message (if there is any).
633 * This message box may be suppressed if the user wishes so. */
634 if (!host.isReallyOk())
635 vboxProblem().cannotAccessUSB (host);
636
637 if (coll.isNull())
638 {
639#endif
640 /* disable the USB host filters category if the USB is
641 * not available (i.e. in VirtualBox OSE) */
642
643 QListViewItem *usbItem = listView->findItem ("#usb", listView_Link);
644 Assert (usbItem);
645 usbItem->setVisible (false);
646
647 /* disable validators if any */
648 pageUSB->setEnabled (false);
649
650#ifdef DEBUG_dmik
651 }
652 else
653 {
654 CHostUSBDeviceFilterEnumerator en = coll.Enumerate();
655 while (en.HasMore())
656 {
657 CHostUSBDeviceFilter hostFilter = en.GetNext();
658 CUSBDeviceFilter filter = CUnknown (hostFilter);
659 addUSBFilter (filter, false);
660 }
661 lvUSBFilters->setCurrentItem (lvUSBFilters->firstChild());
662 lvUSBFilters_currentChanged (lvUSBFilters->firstChild());
663 }
664#endif
665
666 /* language properties */
667
668 QString langId = gs.languageId();
669 QListViewItem *item = lvLanguages->findItem (langId, 1);
670 if (!item)
671 {
672 /* add an item for an invalid language to represent it in the list */
673 item = new LanguageItem (lvLanguages, langId);
674 lvLanguages->adjustColumn (0);
675 }
676 Assert (item);
677 if (item)
678 {
679 lvLanguages->setCurrentItem (item);
680 lvLanguages->setSelected (item, true);
681 }
682}
683
684/**
685 * Writes global settings to the given VBoxGlobalSettings instance
686 * and to the given CSystemProperties object.
687 */
688void VBoxGlobalSettingsDlg::putBackTo (CSystemProperties &props,
689 VBoxGlobalSettings &gs)
690{
691 /* default folders */
692
693 if (leVDIFolder->isModified())
694 props.SetDefaultVDIFolder (leVDIFolder->text());
695 if (props.isOk() && leMachineFolder->isModified())
696 props.SetDefaultMachineFolder (leMachineFolder->text());
697
698 /* vrdp lib path */
699 if (leVRDPLib->isModified())
700 props.SetRemoteDisplayAuthLibrary (leVRDPLib->text());
701
702 /* VT-x/AMD-V */
703 props.SetHWVirtExEnabled (chbVTX->isChecked());
704
705 if (!props.isOk())
706 return;
707
708 /* proprietary GUI settings */
709
710 gs.setHostKey (hkeHostKey->key());
711 gs.setAutoCapture (chbAutoCapture->isChecked());
712
713 /* usb filter page */
714
715 /*
716 * first, remove all old filters (only if the list is changed,
717 * not only individual properties of filters)
718 */
719 CHost host = vboxGlobal().virtualBox().GetHost();
720 if (mUSBFilterListModified)
721 for (ulong cnt = host.GetUSBDeviceFilters().GetCount(); cnt; -- cnt)
722 host.RemoveUSBDeviceFilter (0);
723
724 /* then add all new filters */
725 for (QListViewItem *item = lvUSBFilters->firstChild(); item;
726 item = item->nextSibling())
727 {
728 USBListItem *uli = static_cast <USBListItem *> (item);
729 VBoxUSBFilterSettings *settings =
730 static_cast <VBoxUSBFilterSettings *>
731 (wstUSBFilters->widget (uli->mId));
732 Assert (settings);
733
734 COMResult res = settings->putBackToFilter();
735 if (!res.isOk())
736 return;
737
738 CUSBDeviceFilter filter = settings->filter();
739 filter.SetActive (uli->isOn());
740
741 CHostUSBDeviceFilter insertedFilter = CUnknown (filter);
742 if (mUSBFilterListModified)
743 host.InsertUSBDeviceFilter (host.GetUSBDeviceFilters().GetCount(),
744 insertedFilter);
745 }
746 mUSBFilterListModified = false;
747
748 /* language properties */
749
750 QListViewItem *selItem = lvLanguages->selectedItem();
751 Assert (selItem);
752 if (mLanguageChanged && selItem)
753 {
754 gs.setLanguageId (selItem->text (1));
755 VBoxGlobal::loadLanguage (selItem->text (1));
756 }
757}
758
759void VBoxGlobalSettingsDlg::updateWhatsThis (bool gotFocus /* = false */)
760{
761 QString text;
762
763 QWidget *widget = NULL;
764 if (!gotFocus)
765 {
766 if (whatsThisCandidate != NULL && whatsThisCandidate != this)
767 widget = whatsThisCandidate;
768 }
769 else
770 {
771 widget = focusData()->focusWidget();
772 }
773 /* if the given widget lacks the whats'this text, look at its parent */
774 while (widget && widget != this)
775 {
776 text = QWhatsThis::textFor (widget);
777 if (!text.isEmpty())
778 break;
779 widget = widget->parentWidget();
780 }
781
782 if (text.isEmpty() && !warningString.isEmpty())
783 text = warningString;
784 if (text.isEmpty())
785 text = QWhatsThis::textFor (this);
786
787 whatsThisLabel->setText (text);
788}
789
790void VBoxGlobalSettingsDlg::setWarning (const QString &warning)
791{
792 warningString = warning;
793 if (!warning.isEmpty())
794 warningString = QString ("<font color=red>%1</font>").arg (warning);
795
796 if (!warningString.isEmpty())
797 whatsThisLabel->setText (warningString);
798 else
799 updateWhatsThis (true);
800}
801
802void VBoxGlobalSettingsDlg::tbResetFolder_clicked()
803{
804 QToolButton *tb = ::qt_cast <QToolButton *> (sender());
805 Assert (tb);
806
807 QLineEdit *le = 0;
808 if (tb == tbResetVDIFolder) le = leVDIFolder;
809 else if (tb == tbResetMachineFolder) le = leMachineFolder;
810 else if (tb == tbResetVRDPLib) le = leVRDPLib;
811 Assert (le);
812
813 /*
814 * do this instead of le->setText (QString::null) to cause
815 * isModified() return true
816 */
817 le->selectAll();
818 le->del();
819}
820
821void VBoxGlobalSettingsDlg::tbSelectFolder_clicked()
822{
823 QToolButton *tb = ::qt_cast <QToolButton *> (sender());
824 Assert (tb);
825
826 QLineEdit *le = 0;
827 if (tb == tbSelectVDIFolder) le = leVDIFolder;
828 else if (tb == tbSelectMachineFolder) le = leMachineFolder;
829 else if (tb == tbSelectVRDPLib) le = leVRDPLib;
830 Assert (le);
831
832 QString initDir = VBoxGlobal::getFirstExistingDir (le->text());
833 if (initDir.isNull())
834 initDir = vboxGlobal().virtualBox().GetHomeFolder();
835
836 QString path = le == leVRDPLib ?
837 VBoxGlobal::getOpenFileName (initDir, QString::null, this,
838 "getFile", QString::null) :
839 VBoxGlobal::getExistingDirectory (initDir, this);
840 if (path.isNull())
841 return;
842
843 path = QDir::convertSeparators (path);
844 /* remove trailing slash if any */
845 path.remove (QRegExp ("[\\\\/]$"));
846
847 /*
848 * do this instead of le->setText (path) to cause
849 * isModified() return true
850 */
851 le->selectAll();
852 le->insert (path);
853}
854
855// USB Filter stuff
856////////////////////////////////////////////////////////////////////////////////
857
858void VBoxGlobalSettingsDlg::addUSBFilter (const CUSBDeviceFilter &aFilter,
859 bool aIsNew)
860{
861 QListViewItem *currentItem = aIsNew
862 ? lvUSBFilters->currentItem()
863 : lvUSBFilters->lastItem();
864
865 VBoxUSBFilterSettings *settings = new VBoxUSBFilterSettings (wstUSBFilters);
866 settings->setup (VBoxUSBFilterSettings::HostType);
867 settings->getFromFilter (aFilter);
868
869 USBListItem *item = new USBListItem (lvUSBFilters, currentItem);
870 item->setOn (aFilter.GetActive());
871 item->setText (lvUSBFilters_Name, aFilter.GetName());
872
873 item->mId = wstUSBFilters->addWidget (settings);
874
875 /* fix the tab order so that main dialog's buttons are always the last */
876 setTabOrder (settings->focusProxy(), buttonHelp);
877 setTabOrder (buttonHelp, buttonOk);
878 setTabOrder (buttonOk, buttonCancel);
879
880 if (aIsNew)
881 {
882 lvUSBFilters->setSelected (item, true);
883 lvUSBFilters_currentChanged (item);
884 settings->leUSBFilterName->setFocus();
885 }
886
887 connect (settings->leUSBFilterName, SIGNAL (textChanged (const QString &)),
888 this, SLOT (lvUSBFilters_setCurrentText (const QString &)));
889
890 /* setup validation */
891
892 QIWidgetValidator *wval =
893 new QIWidgetValidator (pagePath (pageUSB), settings, settings);
894 connect (wval, SIGNAL (validityChanged (const QIWidgetValidator *)),
895 this, SLOT (enableOk (const QIWidgetValidator *)));
896
897 wval->revalidate();
898}
899
900void VBoxGlobalSettingsDlg::lvUSBFilters_currentChanged (QListViewItem *item)
901{
902 if (item && lvUSBFilters->selectedItem() != item)
903 lvUSBFilters->setSelected (item, true);
904
905 tbRemoveUSBFilter->setEnabled (!!item);
906
907 tbUSBFilterUp->setEnabled (!!item && item->itemAbove());
908 tbUSBFilterDown->setEnabled (!!item && item->itemBelow());
909
910 if (item)
911 {
912 USBListItem *uli = static_cast <USBListItem *> (item);
913 wstUSBFilters->raiseWidget (uli->mId);
914 }
915 else
916 {
917 /* raise the disabled widget */
918 wstUSBFilters->raiseWidget (0);
919 }
920}
921
922void VBoxGlobalSettingsDlg::lvUSBFilters_setCurrentText (const QString &aText)
923{
924 QListViewItem *item = lvUSBFilters->currentItem();
925 Assert (item);
926
927 item->setText (lvUSBFilters_Name, aText);
928}
929
930void VBoxGlobalSettingsDlg::tbAddUSBFilter_clicked()
931{
932 /* search for the max available filter index */
933 int maxFilterIndex = 0;
934 QString usbFilterName = tr ("New Filter %1", "usb");
935 QRegExp regExp (QString ("^") + usbFilterName.arg ("([0-9]+)") + QString ("$"));
936 QListViewItemIterator iterator (lvUSBFilters);
937 while (*iterator)
938 {
939 QString filterName = (*iterator)->text (lvUSBFilters_Name);
940 int pos = regExp.search (filterName);
941 if (pos != -1)
942 maxFilterIndex = regExp.cap (1).toInt() > maxFilterIndex ?
943 regExp.cap (1).toInt() : maxFilterIndex;
944 ++ iterator;
945 }
946
947 /* create a new usb filter */
948 CHost host = vboxGlobal().virtualBox().GetHost();
949 CHostUSBDeviceFilter hostFilter = host
950 .CreateUSBDeviceFilter (usbFilterName.arg (maxFilterIndex + 1));
951 hostFilter.SetAction (KUSBDeviceFilterAction_Hold);
952
953 CUSBDeviceFilter filter = CUnknown (hostFilter);
954 filter.SetActive (true);
955 addUSBFilter (filter, true);
956
957 mUSBFilterListModified = true;
958}
959
960void VBoxGlobalSettingsDlg::tbAddUSBFilterFrom_clicked()
961{
962 usbDevicesMenu->exec (QCursor::pos());
963}
964
965void VBoxGlobalSettingsDlg::menuAddUSBFilterFrom_activated (int aIndex)
966{
967 CUSBDevice usb = usbDevicesMenu->getUSB (aIndex);
968
969 // if null then some other item but a USB device is selected
970 if (usb.isNull())
971 return;
972
973 CHost host = vboxGlobal().virtualBox().GetHost();
974 CHostUSBDeviceFilter hostFilter = host
975 .CreateUSBDeviceFilter (vboxGlobal().details (usb));
976 hostFilter.SetAction (KUSBDeviceFilterAction_Hold);
977
978 CUSBDeviceFilter filter = CUnknown (hostFilter);
979 filter.SetVendorId (QString().sprintf ("%04hX", usb.GetVendorId()));
980 filter.SetProductId (QString().sprintf ("%04hX", usb.GetProductId()));
981 filter.SetRevision (QString().sprintf ("%04hX", usb.GetRevision()));
982 /* The port property depends on the host computer rather than on the USB
983 * device itself; for this reason only a few people will want to use it in
984 * the filter since the same device plugged into a different socket will
985 * not match the filter in this case. */
986#if 0
987 /// @todo set it anyway if Alt is currently pressed
988 filter.SetPort (QString().sprintf ("%04hX", usb.GetPort()));
989#endif
990 filter.SetManufacturer (usb.GetManufacturer());
991 filter.SetProduct (usb.GetProduct());
992 filter.SetSerialNumber (usb.GetSerialNumber());
993 filter.SetRemote (usb.GetRemote() ? "yes" : "no");
994
995 filter.SetActive (true);
996 addUSBFilter (filter, true);
997
998 mUSBFilterListModified = true;
999}
1000
1001void VBoxGlobalSettingsDlg::tbRemoveUSBFilter_clicked()
1002{
1003 QListViewItem *item = lvUSBFilters->currentItem();
1004 Assert (item);
1005
1006 USBListItem *uli = static_cast <USBListItem *> (item);
1007 QWidget *settings = wstUSBFilters->widget (uli->mId);
1008 Assert (settings);
1009 wstUSBFilters->removeWidget (settings);
1010 delete settings;
1011
1012 delete item;
1013
1014 lvUSBFilters->setSelected (lvUSBFilters->currentItem(), true);
1015 mUSBFilterListModified = true;
1016}
1017
1018void VBoxGlobalSettingsDlg::tbUSBFilterUp_clicked()
1019{
1020 QListViewItem *item = lvUSBFilters->currentItem();
1021 Assert (item);
1022
1023 QListViewItem *itemAbove = item->itemAbove();
1024 Assert (itemAbove);
1025 itemAbove = itemAbove->itemAbove();
1026
1027 if (!itemAbove)
1028 item->itemAbove()->moveItem (item);
1029 else
1030 item->moveItem (itemAbove);
1031
1032 lvUSBFilters_currentChanged (item);
1033 mUSBFilterListModified = true;
1034}
1035
1036void VBoxGlobalSettingsDlg::tbUSBFilterDown_clicked()
1037{
1038 QListViewItem *item = lvUSBFilters->currentItem();
1039 Assert (item);
1040
1041 QListViewItem *itemBelow = item->itemBelow();
1042 Assert (itemBelow);
1043
1044 item->moveItem (itemBelow);
1045
1046 lvUSBFilters_currentChanged (item);
1047 mUSBFilterListModified = true;
1048}
1049
1050void VBoxGlobalSettingsDlg::lvLanguages_currentChanged (QListViewItem *aItem)
1051{
1052 Assert (aItem);
1053 if (!aItem) return;
1054
1055 /* disable labels for the Default language item */
1056 bool enabled = !aItem->text (1).isNull();
1057
1058 tlLangName->setEnabled (enabled);
1059 tlAuthorName->setEnabled (enabled);
1060 tlLangData->setText (aItem->text (2));
1061 tlAuthorData->setText (aItem->text (3));
1062
1063 mLanguageChanged = true;
1064}
1065
1066void VBoxGlobalSettingsDlg::fixLanguageChange()
1067{
1068 /* fix for usb page */
1069
1070#ifdef DEBUG_dmik
1071 CHost host = vboxGlobal().virtualBox().GetHost();
1072 CHostUSBDeviceFilterCollection coll = host.GetUSBDeviceFilters();
1073 if (coll.isNull())
1074 {
1075#endif
1076 /* disable the USB host filters category if the USB is
1077 * not available (i.e. in VirtualBox OSE) */
1078
1079 QListViewItem *usbItem = listView->findItem ("#usb", listView_Link);
1080 Assert (usbItem);
1081 usbItem->setVisible (false);
1082
1083 /* disable validators if any */
1084 pageUSB->setEnabled (false);
1085
1086#ifdef DEBUG_dmik
1087 }
1088#endif
1089}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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