VirtualBox

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

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

FE/Qt4: Renamed QIRichLabel to QILabel. From now QAbstractWizard uses the new global QILabel.

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