VirtualBox

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

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

FE/Qt4: Made it build on win.x86.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 34.7 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//#warning port me
743 /*
744 VBoxUSBFilterSettings *settings =
745 static_cast <VBoxUSBFilterSettings *>
746 (wstUSBFilters->widget (uli->mId));
747 Assert (settings);
748
749 COMResult res = settings->putBackToFilter();
750 if (!res.isOk())
751 return;
752
753 CUSBDeviceFilter filter = settings->filter();
754 filter.SetActive (uli->isOn());
755
756 CHostUSBDeviceFilter insertedFilter = CUnknown (filter);
757 if (mUSBFilterListModified)
758 host.InsertUSBDeviceFilter (host.GetUSBDeviceFilters().GetCount(),
759 insertedFilter);
760 */
761 }
762 mUSBFilterListModified = false;
763
764 /* language properties */
765
766 Q3ListViewItem *selItem = lvLanguages->selectedItem();
767 Assert (selItem);
768 if (mLanguageChanged && selItem)
769 {
770 gs.setLanguageId (selItem->text (1));
771//#warning "port me: check if this is longer necessary (See the ChangeGUILanguageEvent)"
772 VBoxGlobal::loadLanguage (selItem->text (1));
773 }
774}
775
776void VBoxGlobalSettingsDlg::updateWhatsThis (bool gotFocus /* = false */)
777{
778 QString text;
779
780 QWidget *widget = NULL;
781 if (!gotFocus)
782 {
783 if (whatsThisCandidate != NULL && whatsThisCandidate != this)
784 widget = whatsThisCandidate;
785 }
786 else
787 {
788//#warning port me
789// widget = focusData()->focusWidget();
790 }
791 /* if the given widget lacks the whats'this text, look at its parent */
792 while (widget && widget != this)
793 {
794//#warning port me
795// text = Q3WhatsThis::textFor (widget);
796 if (!text.isEmpty())
797 break;
798 widget = widget->parentWidget();
799 }
800
801 if (text.isEmpty() && !warningString.isEmpty())
802 text = warningString;
803//#warning port me
804// if (text.isEmpty())
805// text = Q3WhatsThis::textFor (this);
806
807 whatsThisLabel->setText (text);
808}
809
810void VBoxGlobalSettingsDlg::setWarning (const QString &warning)
811{
812 warningString = warning;
813 if (!warning.isEmpty())
814 warningString = QString ("<font color=red>%1</font>").arg (warning);
815
816 if (!warningString.isEmpty())
817 whatsThisLabel->setText (warningString);
818 else
819 updateWhatsThis (true);
820}
821
822void VBoxGlobalSettingsDlg::tbResetFolder_clicked()
823{
824 QToolButton *tb = qobject_cast <QToolButton *> (sender());
825 Assert (tb);
826
827 QLineEdit *le = 0;
828 if (tb == tbResetVDIFolder) le = leVDIFolder;
829 else if (tb == tbResetMachineFolder) le = leMachineFolder;
830 else if (tb == tbResetVRDPLib) le = leVRDPLib;
831 Assert (le);
832
833 /*
834 * do this instead of le->setText (QString::null) to cause
835 * isModified() return true
836 */
837 le->selectAll();
838 le->del();
839}
840
841void VBoxGlobalSettingsDlg::tbSelectFolder_clicked()
842{
843 QToolButton *tb = qobject_cast <QToolButton *> (sender());
844 Assert (tb);
845
846 QLineEdit *le = 0;
847 if (tb == tbSelectVDIFolder) le = leVDIFolder;
848 else if (tb == tbSelectMachineFolder) le = leMachineFolder;
849 else if (tb == tbSelectVRDPLib) le = leVRDPLib;
850 Assert (le);
851
852 QString initDir = VBoxGlobal::getFirstExistingDir (le->text());
853 if (initDir.isNull())
854 initDir = vboxGlobal().virtualBox().GetHomeFolder();
855
856 QString path = le == leVRDPLib ?
857 VBoxGlobal::getOpenFileName (initDir, QString::null, this, QString::null) :
858 VBoxGlobal::getExistingDirectory (initDir, this);
859 if (path.isNull())
860 return;
861
862 path = QDir::convertSeparators (path);
863 /* remove trailing slash if any */
864 path.remove (QRegExp ("[\\\\/]$"));
865
866 /*
867 * do this instead of le->setText (path) to cause
868 * isModified() return true
869 */
870 le->selectAll();
871 le->insert (path);
872}
873
874// USB Filter stuff
875////////////////////////////////////////////////////////////////////////////////
876
877void VBoxGlobalSettingsDlg::addUSBFilter (const CUSBDeviceFilter &aFilter,
878 bool aIsNew)
879{
880 /*
881 Q3ListViewItem *currentItem = aIsNew
882 ? lvUSBFilters->currentItem()
883 : lvUSBFilters->lastItem();
884
885 VBoxUSBFilterSettings *settings = new VBoxUSBFilterSettings (wstUSBFilters);
886 settings->setup (VBoxUSBFilterSettings::HostType);
887 settings->getFromFilter (aFilter);
888
889 USBListItem *item = new USBListItem (lvUSBFilters, currentItem);
890 item->setOn (aFilter.GetActive());
891 item->setText (lvUSBFilters_Name, aFilter.GetName());
892
893 item->mId = wstUSBFilters->addWidget (settings);
894
895 // fix the tab order so that main dialog's buttons are always the last
896 setTabOrder (settings->focusProxy(), buttonHelp);
897 setTabOrder (buttonHelp, buttonOk);
898 setTabOrder (buttonOk, buttonCancel);
899
900 if (aIsNew)
901 {
902 lvUSBFilters->setSelected (item, true);
903 lvUSBFilters_currentChanged (item);
904 settings->leUSBFilterName->setFocus();
905 }
906
907 connect (settings->leUSBFilterName, SIGNAL (textChanged (const QString &)),
908 this, SLOT (lvUSBFilters_setCurrentText (const QString &)));
909
910 // setup validation
911
912 QIWidgetValidator *wval =
913 new QIWidgetValidator (pagePath (pageUSB), settings, settings);
914 connect (wval, SIGNAL (validityChanged (const QIWidgetValidator *)),
915 this, SLOT (enableOk (const QIWidgetValidator *)));
916
917 wval->revalidate();
918 */
919}
920
921void VBoxGlobalSettingsDlg::lvUSBFilters_currentChanged (Q3ListViewItem *item)
922{
923 if (item && lvUSBFilters->selectedItem() != item)
924 lvUSBFilters->setSelected (item, true);
925
926 tbRemoveUSBFilter->setEnabled (!!item);
927
928 tbUSBFilterUp->setEnabled (!!item && item->itemAbove());
929 tbUSBFilterDown->setEnabled (!!item && item->itemBelow());
930
931 if (item)
932 {
933 USBListItem *uli = static_cast <USBListItem *> (item);
934 wstUSBFilters->raiseWidget (uli->mId);
935 }
936 else
937 {
938 /* raise the disabled widget */
939 wstUSBFilters->raiseWidget (0);
940 }
941}
942
943void VBoxGlobalSettingsDlg::lvUSBFilters_setCurrentText (const QString &aText)
944{
945 Q3ListViewItem *item = lvUSBFilters->currentItem();
946 Assert (item);
947
948 item->setText (lvUSBFilters_Name, aText);
949}
950
951void VBoxGlobalSettingsDlg::tbAddUSBFilter_clicked()
952{
953 /* search for the max available filter index */
954 int maxFilterIndex = 0;
955 QString usbFilterName = tr ("New Filter %1", "usb");
956 QRegExp regExp (QString ("^") + usbFilterName.arg ("([0-9]+)") + QString ("$"));
957 Q3ListViewItemIterator iterator (lvUSBFilters);
958 while (*iterator)
959 {
960 QString filterName = (*iterator)->text (lvUSBFilters_Name);
961 int pos = regExp.search (filterName);
962 if (pos != -1)
963 maxFilterIndex = regExp.cap (1).toInt() > maxFilterIndex ?
964 regExp.cap (1).toInt() : maxFilterIndex;
965 ++ iterator;
966 }
967
968 /* create a new usb filter */
969 CHost host = vboxGlobal().virtualBox().GetHost();
970 CHostUSBDeviceFilter hostFilter = host
971 .CreateUSBDeviceFilter (usbFilterName.arg (maxFilterIndex + 1));
972 hostFilter.SetAction (KUSBDeviceFilterAction_Hold);
973
974 CUSBDeviceFilter filter = CUnknown (hostFilter);
975 filter.SetActive (true);
976 addUSBFilter (filter, true);
977
978 mUSBFilterListModified = true;
979}
980
981void VBoxGlobalSettingsDlg::tbAddUSBFilterFrom_clicked()
982{
983 usbDevicesMenu->exec (QCursor::pos());
984}
985
986void VBoxGlobalSettingsDlg::menuAddUSBFilterFrom_activated (QAction *aAction)
987{
988 CUSBDevice usb = usbDevicesMenu->getUSB (aAction);
989
990 // if null then some other item but a USB device is selected
991 if (usb.isNull())
992 return;
993
994 CHost host = vboxGlobal().virtualBox().GetHost();
995 CHostUSBDeviceFilter hostFilter = host
996 .CreateUSBDeviceFilter (vboxGlobal().details (usb));
997 hostFilter.SetAction (KUSBDeviceFilterAction_Hold);
998
999 CUSBDeviceFilter filter = CUnknown (hostFilter);
1000 filter.SetVendorId (QString().sprintf ("%04hX", usb.GetVendorId()));
1001 filter.SetProductId (QString().sprintf ("%04hX", usb.GetProductId()));
1002 filter.SetRevision (QString().sprintf ("%04hX", usb.GetRevision()));
1003 /* The port property depends on the host computer rather than on the USB
1004 * device itself; for this reason only a few people will want to use it in
1005 * the filter since the same device plugged into a different socket will
1006 * not match the filter in this case. */
1007#if 0
1008 /// @todo set it anyway if Alt is currently pressed
1009 filter.SetPort (QString().sprintf ("%04hX", usb.GetPort()));
1010#endif
1011 filter.SetManufacturer (usb.GetManufacturer());
1012 filter.SetProduct (usb.GetProduct());
1013 filter.SetSerialNumber (usb.GetSerialNumber());
1014 filter.SetRemote (usb.GetRemote() ? "yes" : "no");
1015
1016 filter.SetActive (true);
1017 addUSBFilter (filter, true);
1018
1019 mUSBFilterListModified = true;
1020}
1021
1022void VBoxGlobalSettingsDlg::tbRemoveUSBFilter_clicked()
1023{
1024 Q3ListViewItem *item = lvUSBFilters->currentItem();
1025 Assert (item);
1026
1027 USBListItem *uli = static_cast <USBListItem *> (item);
1028 QWidget *settings = wstUSBFilters->widget (uli->mId);
1029 Assert (settings);
1030 wstUSBFilters->removeWidget (settings);
1031 delete settings;
1032
1033 delete item;
1034
1035 lvUSBFilters->setSelected (lvUSBFilters->currentItem(), true);
1036 mUSBFilterListModified = true;
1037}
1038
1039void VBoxGlobalSettingsDlg::tbUSBFilterUp_clicked()
1040{
1041 Q3ListViewItem *item = lvUSBFilters->currentItem();
1042 Assert (item);
1043
1044 Q3ListViewItem *itemAbove = item->itemAbove();
1045 Assert (itemAbove);
1046 itemAbove = itemAbove->itemAbove();
1047
1048 if (!itemAbove)
1049 item->itemAbove()->moveItem (item);
1050 else
1051 item->moveItem (itemAbove);
1052
1053 lvUSBFilters_currentChanged (item);
1054 mUSBFilterListModified = true;
1055}
1056
1057void VBoxGlobalSettingsDlg::tbUSBFilterDown_clicked()
1058{
1059 Q3ListViewItem *item = lvUSBFilters->currentItem();
1060 Assert (item);
1061
1062 Q3ListViewItem *itemBelow = item->itemBelow();
1063 Assert (itemBelow);
1064
1065 item->moveItem (itemBelow);
1066
1067 lvUSBFilters_currentChanged (item);
1068 mUSBFilterListModified = true;
1069}
1070
1071void VBoxGlobalSettingsDlg::lvLanguages_currentChanged (Q3ListViewItem *aItem)
1072{
1073 Assert (aItem);
1074 if (!aItem) return;
1075
1076 /* disable labels for the Default language item */
1077 bool enabled = !aItem->text (1).isNull();
1078
1079 tlLangName->setEnabled (enabled);
1080 tlAuthorName->setEnabled (enabled);
1081 tlLangData->setText (aItem->text (2));
1082 tlAuthorData->setText (aItem->text (3));
1083
1084 mLanguageChanged = true;
1085}
1086
1087void VBoxGlobalSettingsDlg::fixLanguageChange()
1088{
1089 /* fix for usb page */
1090
1091#ifdef DEBUG_dmik
1092 CHost host = vboxGlobal().virtualBox().GetHost();
1093 CHostUSBDeviceFilterCollection coll = host.GetUSBDeviceFilters();
1094 if (coll.isNull())
1095 {
1096#endif
1097 /* disable the USB host filters category if the USB is
1098 * not available (i.e. in VirtualBox OSE) */
1099
1100 Q3ListViewItem *usbItem = listView->findItem ("#usb", listView_Link);
1101 Assert (usbItem);
1102 usbItem->setVisible (false);
1103
1104 /* disable validators if any */
1105 pageUSB->setEnabled (false);
1106
1107#ifdef DEBUG_dmik
1108 }
1109#endif
1110}
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