VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox4/ui/VBoxGlobalSettingsDlg.ui.h@ 9382

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

FE/Qt4: Initial version of the ported QIRichLabel class.

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