VirtualBox

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

Last change on this file since 2586 was 2496, checked in by vboxsync, 18 years ago

Fixing a problem at Global Settings Startup with incorrect language list size (horizontal scroll-bar appearing) due to vertical scroll-bar appearing.

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