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