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 | /**
|
---|
34 | * Returns the path to the item in the form of 'grandparent > parent > item'
|
---|
35 | * using the text of the first column of every item.
|
---|
36 | */
|
---|
37 | static QString path (QListViewItem *li)
|
---|
38 | {
|
---|
39 | static QString sep = ": ";
|
---|
40 | QString p;
|
---|
41 | QListViewItem *cur = li;
|
---|
42 | while (cur)
|
---|
43 | {
|
---|
44 | if (!p.isNull())
|
---|
45 | p = sep + p;
|
---|
46 | p = cur->text (0).simplifyWhiteSpace() + p;
|
---|
47 | cur = cur->parent();
|
---|
48 | }
|
---|
49 | return p;
|
---|
50 | }
|
---|
51 |
|
---|
52 |
|
---|
53 | enum
|
---|
54 | {
|
---|
55 | // listView column numbers
|
---|
56 | listView_Category = 0,
|
---|
57 | listView_Id = 1,
|
---|
58 | listView_Link = 2,
|
---|
59 | };
|
---|
60 |
|
---|
61 |
|
---|
62 | class USBListItem : public QCheckListItem
|
---|
63 | {
|
---|
64 | public:
|
---|
65 |
|
---|
66 | USBListItem (QListView *aParent, QListViewItem *aAfter)
|
---|
67 | : QCheckListItem (aParent, aAfter, QString::null, CheckBox)
|
---|
68 | , mId (-1) {}
|
---|
69 |
|
---|
70 | int mId;
|
---|
71 | };
|
---|
72 | enum { lvUSBFilters_Name = 0 };
|
---|
73 |
|
---|
74 |
|
---|
75 | void VBoxGlobalSettingsDlg::init()
|
---|
76 | {
|
---|
77 | polished = false;
|
---|
78 |
|
---|
79 | setCaption (tr ("VirtualBox Global Settings"));
|
---|
80 | setIcon (QPixmap::fromMimeSource ("global_settings_16px.png"));
|
---|
81 |
|
---|
82 | /* all pages are initially valid */
|
---|
83 | valid = true;
|
---|
84 | buttonOk->setEnabled (true);
|
---|
85 | warningSpacer->changeSize (0, 0, QSizePolicy::Expanding);
|
---|
86 | warningLabel->setHidden (true);
|
---|
87 | warningPixmap->setHidden (true);
|
---|
88 |
|
---|
89 | /* disable unselecting items by clicking in the unused area of the list */
|
---|
90 | new QIListViewSelectionPreserver (this, listView);
|
---|
91 | /* hide the header and internal columns */
|
---|
92 | listView->header()->hide();
|
---|
93 | listView->setColumnWidthMode (listView_Id, QListView::Manual);
|
---|
94 | listView->setColumnWidthMode (listView_Link, QListView::Manual);
|
---|
95 | listView->hideColumn (listView_Id);
|
---|
96 | listView->hideColumn (listView_Link);
|
---|
97 | /* sort by the id column (to have pages in the desired order) */
|
---|
98 | listView->setSorting (listView_Id);
|
---|
99 | listView->sort();
|
---|
100 | /* disable further sorting (important for network adapters) */
|
---|
101 | listView->setSorting (-1);
|
---|
102 | /* set the first item selected */
|
---|
103 | listView->setSelected (listView->firstChild(), true);
|
---|
104 | listView_currentChanged (listView->firstChild());
|
---|
105 |
|
---|
106 | warningPixmap->setMaximumSize( 16, 16 );
|
---|
107 | warningPixmap->setPixmap( QMessageBox::standardIcon( QMessageBox::Warning ) );
|
---|
108 |
|
---|
109 | /* page title font is derived from the system font */
|
---|
110 | QFont f = font();
|
---|
111 | f.setBold( true );
|
---|
112 | f.setPointSize( f.pointSize() + 2 );
|
---|
113 | titleLabel->setFont( f );
|
---|
114 |
|
---|
115 | /* setup the what's this label */
|
---|
116 | QApplication::setGlobalMouseTracking (true);
|
---|
117 | qApp->installEventFilter (this);
|
---|
118 | whatsThisTimer = new QTimer (this);
|
---|
119 | connect (whatsThisTimer, SIGNAL (timeout()), this, SLOT (updateWhatsThis()));
|
---|
120 | whatsThisCandidate = NULL;
|
---|
121 | whatsThisLabel->setTextFormat (Qt::RichText);
|
---|
122 | whatsThisLabel->setMinimumHeight (whatsThisLabel->frameWidth() * 2 +
|
---|
123 | 6 /* seems that RichText adds some margin */ +
|
---|
124 | whatsThisLabel->fontMetrics().lineSpacing() * 3);
|
---|
125 | whatsThisLabel->setMinimumWidth (whatsThisLabel->frameWidth() * 2 +
|
---|
126 | 6 /* seems that RichText adds some margin */ +
|
---|
127 | whatsThisLabel->fontMetrics().width ('m') * 40);
|
---|
128 |
|
---|
129 | /*
|
---|
130 | * create and layout non-standard widgets
|
---|
131 | * ----------------------------------------------------------------------
|
---|
132 | */
|
---|
133 |
|
---|
134 | hkeHostKey = new QIHotKeyEdit (grbKeyboard, "hkeHostKey");
|
---|
135 | hkeHostKey->setSizePolicy (QSizePolicy (QSizePolicy::Preferred, QSizePolicy::Fixed));
|
---|
136 | QWhatsThis::add (hkeHostKey,
|
---|
137 | tr ("Displays the key used as a Host Key in the VM window. Activate the "
|
---|
138 | "entry field and press a new Host Key. Note that alphanumeric, "
|
---|
139 | "cursor movement and editing keys cannot be used as a Host Key."));
|
---|
140 | layoutHostKey->addWidget (hkeHostKey);
|
---|
141 | txHostKey->setBuddy (hkeHostKey);
|
---|
142 | setTabOrder (listView, hkeHostKey);
|
---|
143 |
|
---|
144 | /*
|
---|
145 | * setup connections and set validation for pages
|
---|
146 | * ----------------------------------------------------------------------
|
---|
147 | */
|
---|
148 |
|
---|
149 | /* General page */
|
---|
150 |
|
---|
151 | /// @todo (dmik) remove
|
---|
152 | // leVDIFolder->setValidator (new QRegExpValidator (QRegExp (".+"), this));
|
---|
153 | // leMachineFolder->setValidator (new QRegExpValidator (QRegExp (".+"), this));
|
---|
154 |
|
---|
155 | wvalGeneral = new QIWidgetValidator (pageGeneral, this);
|
---|
156 | connect (wvalGeneral, SIGNAL (validityChanged (const QIWidgetValidator *)),
|
---|
157 | this, SLOT (enableOk( const QIWidgetValidator *)));
|
---|
158 |
|
---|
159 | /* Keyboard page */
|
---|
160 |
|
---|
161 | wvalKeyboard = new QIWidgetValidator( pageKeyboard, this );
|
---|
162 | connect (wvalKeyboard, SIGNAL (validityChanged (const QIWidgetValidator *)),
|
---|
163 | this, SLOT (enableOk( const QIWidgetValidator *)));
|
---|
164 |
|
---|
165 | /* USB page */
|
---|
166 |
|
---|
167 | lvUSBFilters->header()->hide();
|
---|
168 | /* disable sorting */
|
---|
169 | lvUSBFilters->setSorting (-1);
|
---|
170 | /* disable unselecting items by clicking in the unused area of the list */
|
---|
171 | new QIListViewSelectionPreserver (this, lvUSBFilters);
|
---|
172 | wstUSBFilters = new QWidgetStack (grbUSBFilters, "wstUSBFilters");
|
---|
173 | grbUSBFiltersLayout->addWidget (wstUSBFilters);
|
---|
174 | /* create a default (disabled) filter settings widget at index 0 */
|
---|
175 | VBoxUSBFilterSettings *settings = new VBoxUSBFilterSettings (wstUSBFilters);
|
---|
176 | settings->setup (VBoxUSBFilterSettings::HostType);
|
---|
177 | wstUSBFilters->addWidget (settings, 0);
|
---|
178 | lvUSBFilters_currentChanged (NULL);
|
---|
179 | /* setup toolbutton icons */
|
---|
180 | tbAddUSBFilter->setIconSet (VBoxGlobal::iconSet ("usb_new_16px.png",
|
---|
181 | "usb_new_disabled_16px.png"));
|
---|
182 | tbAddUSBFilterFrom->setIconSet (VBoxGlobal::iconSet ("usb_add_16px.png",
|
---|
183 | "usb_add_disabled_16px.png"));
|
---|
184 | tbRemoveUSBFilter->setIconSet (VBoxGlobal::iconSet ("usb_remove_16px.png",
|
---|
185 | "usb_remove_disabled_16px.png"));
|
---|
186 | tbUSBFilterUp->setIconSet (VBoxGlobal::iconSet ("usb_moveup_16px.png",
|
---|
187 | "usb_moveup_disabled_16px.png"));
|
---|
188 | tbUSBFilterDown->setIconSet (VBoxGlobal::iconSet ("usb_movedown_16px.png",
|
---|
189 | "usb_movedown_disabled_16px.png"));
|
---|
190 | /* create menu of existing usb-devices */
|
---|
191 | usbDevicesMenu = new VBoxUSBMenu (this);
|
---|
192 | connect (usbDevicesMenu, SIGNAL(activated(int)), this, SLOT(menuAddUSBFilterFrom_activated(int)));
|
---|
193 | mLastUSBFilterNum = 0;
|
---|
194 | mUSBFilterListModified = false;
|
---|
195 |
|
---|
196 | /*
|
---|
197 | * set initial values
|
---|
198 | * ----------------------------------------------------------------------
|
---|
199 | */
|
---|
200 |
|
---|
201 | /* General page */
|
---|
202 |
|
---|
203 | /* keyboard page */
|
---|
204 |
|
---|
205 | /*
|
---|
206 | * update the Ok button state for pages with validation
|
---|
207 | * (validityChanged() connected to enableNext() will do the job)
|
---|
208 | */
|
---|
209 | wvalGeneral->revalidate();
|
---|
210 | wvalKeyboard->revalidate();
|
---|
211 | }
|
---|
212 |
|
---|
213 | bool VBoxGlobalSettingsDlg::eventFilter (QObject *object, QEvent *event)
|
---|
214 | {
|
---|
215 | if (!object->isWidgetType())
|
---|
216 | return QDialog::eventFilter (object, event);
|
---|
217 |
|
---|
218 | QWidget *widget = static_cast <QWidget *> (object);
|
---|
219 | if (widget->topLevelWidget() != this)
|
---|
220 | return QDialog::eventFilter (object, event);
|
---|
221 |
|
---|
222 | switch (event->type())
|
---|
223 | {
|
---|
224 | case QEvent::Enter:
|
---|
225 | case QEvent::Leave:
|
---|
226 | {
|
---|
227 | if (event->type() == QEvent::Enter)
|
---|
228 | whatsThisCandidate = widget;
|
---|
229 | else
|
---|
230 | whatsThisCandidate = NULL;
|
---|
231 | whatsThisTimer->start (100, true /* sshot */);
|
---|
232 | break;
|
---|
233 | }
|
---|
234 | case QEvent::FocusIn:
|
---|
235 | {
|
---|
236 | updateWhatsThis (true /* gotFocus */);
|
---|
237 | break;
|
---|
238 | }
|
---|
239 | default:
|
---|
240 | break;
|
---|
241 | }
|
---|
242 |
|
---|
243 | return QDialog::eventFilter (object, event);
|
---|
244 | }
|
---|
245 |
|
---|
246 | void VBoxGlobalSettingsDlg::showEvent (QShowEvent *e)
|
---|
247 | {
|
---|
248 | QDialog::showEvent (e);
|
---|
249 |
|
---|
250 | /* one may think that QWidget::polish() is the right place to do things
|
---|
251 | * below, but apparently, by the time when QWidget::polish() is called,
|
---|
252 | * the widget style & layout are not fully done, at least the minimum
|
---|
253 | * size hint is not properly calculated. Since this is sometimes necessary,
|
---|
254 | * we provide our own "polish" implementation. */
|
---|
255 |
|
---|
256 | if (polished)
|
---|
257 | return;
|
---|
258 |
|
---|
259 | polished = true;
|
---|
260 |
|
---|
261 | /* resize to the miminum possible size */
|
---|
262 | resize (minimumSize());
|
---|
263 |
|
---|
264 | VBoxGlobal::centerWidget (this, parentWidget());
|
---|
265 | }
|
---|
266 |
|
---|
267 | void VBoxGlobalSettingsDlg::listView_currentChanged (QListViewItem *item)
|
---|
268 | {
|
---|
269 | Assert (item);
|
---|
270 | int id = item->text (1).toInt();
|
---|
271 | Assert (id >= 0);
|
---|
272 | titleLabel->setText (::path (item));
|
---|
273 | widgetStack->raiseWidget (id);
|
---|
274 | }
|
---|
275 |
|
---|
276 | void VBoxGlobalSettingsDlg::enableOk (const QIWidgetValidator *wval)
|
---|
277 | {
|
---|
278 | Q_UNUSED (wval);
|
---|
279 |
|
---|
280 | /* detect the overall validity */
|
---|
281 | bool newValid = true;
|
---|
282 | {
|
---|
283 | QObjectList *l = this->queryList ("QIWidgetValidator");
|
---|
284 | QObjectListIt it (*l);
|
---|
285 | QObject *obj;
|
---|
286 | while ((obj = it.current()) != 0)
|
---|
287 | {
|
---|
288 | newValid &= ((QIWidgetValidator *) obj)->isValid();
|
---|
289 | ++it;
|
---|
290 | }
|
---|
291 | delete l;
|
---|
292 | }
|
---|
293 |
|
---|
294 | if (valid != newValid)
|
---|
295 | {
|
---|
296 | valid = newValid;
|
---|
297 | buttonOk->setEnabled (valid);
|
---|
298 | if (valid)
|
---|
299 | warningSpacer->changeSize (0, 0, QSizePolicy::Expanding);
|
---|
300 | else
|
---|
301 | warningSpacer->changeSize (0, 0);
|
---|
302 | warningLabel->setHidden (valid);
|
---|
303 | warningPixmap->setHidden (valid);
|
---|
304 | }
|
---|
305 | }
|
---|
306 |
|
---|
307 | void VBoxGlobalSettingsDlg::revalidate (QIWidgetValidator * /*wval*/)
|
---|
308 | {
|
---|
309 | /* do individual validations for pages */
|
---|
310 |
|
---|
311 | /* currently nothing */
|
---|
312 | }
|
---|
313 |
|
---|
314 | /**
|
---|
315 | * Reads global settings from the given VMGlobalSettings instance
|
---|
316 | * and from the given CSystemProperties object.
|
---|
317 | */
|
---|
318 | void VBoxGlobalSettingsDlg::getFrom (const CSystemProperties &props,
|
---|
319 | const VMGlobalSettings &gs)
|
---|
320 | {
|
---|
321 | /* default folders */
|
---|
322 |
|
---|
323 | leVDIFolder->setText (props.GetDefaultVDIFolder());
|
---|
324 | leMachineFolder->setText (props.GetDefaultMachineFolder());
|
---|
325 |
|
---|
326 | /* proprietary GUI settings */
|
---|
327 |
|
---|
328 | hkeHostKey->setKey (gs.hostKey() );
|
---|
329 | chbAutoCapture->setChecked (gs.autoCapture());
|
---|
330 |
|
---|
331 | /* usb filters page */
|
---|
332 |
|
---|
333 | /// @todo currently, we always disable USB UI on XPCOM-based hosts because
|
---|
334 | /// QueryInterface on CUSBDeviceFilter doesn't return CHostUSBDeviceFilter
|
---|
335 | /// for host filters (most likely, our XPCOM/IPC/DCONNECT bug).
|
---|
336 |
|
---|
337 | #ifdef Q_OS_WIN32
|
---|
338 | CHost host = vboxGlobal().virtualBox().GetHost();
|
---|
339 | CHostUSBDeviceFilterCollection coll = host.GetUSBDeviceFilters();
|
---|
340 | if (coll.isNull())
|
---|
341 | {
|
---|
342 | #endif
|
---|
343 | /* disable the USB host filters category if the USB is
|
---|
344 | * not available (i.e. in VirtualBox OSE) */
|
---|
345 |
|
---|
346 | QListViewItem *usbItem = listView->findItem ("#usb", listView_Link);
|
---|
347 | Assert (usbItem);
|
---|
348 | usbItem->setVisible (false);
|
---|
349 |
|
---|
350 | /* disable validators if any */
|
---|
351 | pageUSB->setEnabled (false);
|
---|
352 |
|
---|
353 | #ifdef Q_OS_WIN32
|
---|
354 | /* Show an error message (if there is any).
|
---|
355 | * This message box may be suppressed if the user wishes so. */
|
---|
356 | vboxProblem().cannotAccessUSB (host);
|
---|
357 | }
|
---|
358 | else
|
---|
359 | {
|
---|
360 | CHostUSBDeviceFilterEnumerator en = coll.Enumerate();
|
---|
361 | while (en.HasMore())
|
---|
362 | {
|
---|
363 | CHostUSBDeviceFilter hostFilter = en.GetNext();
|
---|
364 | CUSBDeviceFilter filter = CUnknown (hostFilter);
|
---|
365 | addUSBFilter (filter, false);
|
---|
366 | }
|
---|
367 | lvUSBFilters->setCurrentItem (lvUSBFilters->firstChild());
|
---|
368 | lvUSBFilters_currentChanged (lvUSBFilters->firstChild());
|
---|
369 | }
|
---|
370 | #endif
|
---|
371 | }
|
---|
372 |
|
---|
373 | /**
|
---|
374 | * Writes global settings to the given VMGlobalSettings instance
|
---|
375 | * and to the given CSystemProperties object.
|
---|
376 | */
|
---|
377 | void VBoxGlobalSettingsDlg::putBackTo (CSystemProperties &props,
|
---|
378 | VMGlobalSettings &gs)
|
---|
379 | {
|
---|
380 | /* default folders */
|
---|
381 |
|
---|
382 | if (leVDIFolder->isModified())
|
---|
383 | props.SetDefaultVDIFolder (leVDIFolder->text());
|
---|
384 | if (props.isOk() && leMachineFolder->isModified())
|
---|
385 | props.SetDefaultMachineFolder (leMachineFolder->text());
|
---|
386 |
|
---|
387 | if (!props.isOk())
|
---|
388 | return;
|
---|
389 |
|
---|
390 | /* proprietary GUI settings */
|
---|
391 |
|
---|
392 | gs.setHostKey (hkeHostKey->key());
|
---|
393 | gs.setAutoCapture (chbAutoCapture->isChecked());
|
---|
394 |
|
---|
395 | /* usb filter page */
|
---|
396 |
|
---|
397 | /*
|
---|
398 | * first, remove all old filters (only if the list is changed,
|
---|
399 | * not only individual properties of filters)
|
---|
400 | */
|
---|
401 | CHost host = vboxGlobal().virtualBox().GetHost();
|
---|
402 | CHostUSBDeviceFilter removedFilter;
|
---|
403 | if (mUSBFilterListModified)
|
---|
404 | for (ulong count = host.GetUSBDeviceFilters().GetCount(); count; -- count)
|
---|
405 | host.RemoveUSBDeviceFilter (0, removedFilter);
|
---|
406 |
|
---|
407 | /* then add all new filters */
|
---|
408 | for (QListViewItem *item = lvUSBFilters->firstChild(); item;
|
---|
409 | item = item->nextSibling())
|
---|
410 | {
|
---|
411 | USBListItem *uli = static_cast <USBListItem *> (item);
|
---|
412 | VBoxUSBFilterSettings *settings =
|
---|
413 | static_cast <VBoxUSBFilterSettings *>
|
---|
414 | (wstUSBFilters->widget (uli->mId));
|
---|
415 | Assert (settings);
|
---|
416 |
|
---|
417 | COMResult res = settings->putBackToFilter();
|
---|
418 | if (!res.isOk())
|
---|
419 | return;
|
---|
420 |
|
---|
421 | CUSBDeviceFilter filter = settings->filter();
|
---|
422 | filter.SetActive (uli->isOn());
|
---|
423 |
|
---|
424 | CHostUSBDeviceFilter insertedFilter = CUnknown (filter);
|
---|
425 | if (mUSBFilterListModified)
|
---|
426 | host.InsertUSBDeviceFilter (host.GetUSBDeviceFilters().GetCount(),
|
---|
427 | insertedFilter);
|
---|
428 | }
|
---|
429 | mUSBFilterListModified = false;
|
---|
430 | }
|
---|
431 |
|
---|
432 | void VBoxGlobalSettingsDlg::updateWhatsThis (bool gotFocus /* = false */)
|
---|
433 | {
|
---|
434 | QString text;
|
---|
435 |
|
---|
436 | QWidget *widget = NULL;
|
---|
437 | if (!gotFocus)
|
---|
438 | {
|
---|
439 | if (whatsThisCandidate != NULL && whatsThisCandidate != this)
|
---|
440 | widget = whatsThisCandidate;
|
---|
441 | }
|
---|
442 | else
|
---|
443 | {
|
---|
444 | widget = focusData()->focusWidget();
|
---|
445 | }
|
---|
446 | /* if the given widget lacks the whats'this text, look at its parent */
|
---|
447 | while (widget && widget != this)
|
---|
448 | {
|
---|
449 | text = QWhatsThis::textFor (widget);
|
---|
450 | if (!text.isEmpty())
|
---|
451 | break;
|
---|
452 | widget = widget->parentWidget();
|
---|
453 | }
|
---|
454 |
|
---|
455 | if (text.isEmpty() && !warningString.isEmpty())
|
---|
456 | text = warningString;
|
---|
457 | if (text.isEmpty())
|
---|
458 | text = QWhatsThis::textFor (this);
|
---|
459 |
|
---|
460 | whatsThisLabel->setText (text);
|
---|
461 | }
|
---|
462 |
|
---|
463 | void VBoxGlobalSettingsDlg::setWarning (const QString &warning)
|
---|
464 | {
|
---|
465 | warningString = warning;
|
---|
466 | if (!warning.isEmpty())
|
---|
467 | warningString = QString ("<font color=red>%1</font>").arg (warning);
|
---|
468 |
|
---|
469 | if (!warningString.isEmpty())
|
---|
470 | whatsThisLabel->setText (warningString);
|
---|
471 | else
|
---|
472 | updateWhatsThis (true);
|
---|
473 | }
|
---|
474 |
|
---|
475 | void VBoxGlobalSettingsDlg::tbResetFolder_clicked()
|
---|
476 | {
|
---|
477 | QToolButton *tb = ::qt_cast <QToolButton *> (sender());
|
---|
478 | Assert (tb);
|
---|
479 |
|
---|
480 | QLineEdit *le = 0;
|
---|
481 | if (tb == tbResetVDIFolder) le = leVDIFolder;
|
---|
482 | else if (tb == tbResetMachineFolder) le = leMachineFolder;
|
---|
483 | Assert (le);
|
---|
484 |
|
---|
485 | /*
|
---|
486 | * do this instead of le->setText (QString::null) to cause
|
---|
487 | * isModified() return true
|
---|
488 | */
|
---|
489 | le->selectAll();
|
---|
490 | le->del();
|
---|
491 | }
|
---|
492 |
|
---|
493 | void VBoxGlobalSettingsDlg::tbSelectFolder_clicked()
|
---|
494 | {
|
---|
495 | QToolButton *tb = ::qt_cast <QToolButton *> (sender());
|
---|
496 | Assert (tb);
|
---|
497 |
|
---|
498 | QLineEdit *le = 0;
|
---|
499 | if (tb == tbSelectVDIFolder) le = leVDIFolder;
|
---|
500 | else if (tb == tbSelectMachineFolder) le = leMachineFolder;
|
---|
501 | Assert (le);
|
---|
502 |
|
---|
503 | QString initDir = VBoxGlobal::getFirstExistingDir (le->text());
|
---|
504 | if (initDir.isNull())
|
---|
505 | initDir = vboxGlobal().virtualBox().GetHomeFolder();
|
---|
506 | QString folder = VBoxGlobal::getExistingDirectory (initDir, this);
|
---|
507 | if (folder.isNull())
|
---|
508 | return;
|
---|
509 |
|
---|
510 | folder = QDir::convertSeparators (folder);
|
---|
511 | /* remove trailing slash if any */
|
---|
512 | folder.remove (QRegExp ("[\\\\/]$"));
|
---|
513 |
|
---|
514 | /*
|
---|
515 | * do this instead of le->setText (folder) to cause
|
---|
516 | * isModified() return true
|
---|
517 | */
|
---|
518 | le->selectAll();
|
---|
519 | le->insert (folder);
|
---|
520 | }
|
---|
521 |
|
---|
522 | // USB Filter stuff
|
---|
523 | ////////////////////////////////////////////////////////////////////////////////
|
---|
524 |
|
---|
525 | void VBoxGlobalSettingsDlg::addUSBFilter (const CUSBDeviceFilter &aFilter,
|
---|
526 | bool aIsNew)
|
---|
527 | {
|
---|
528 | QListViewItem *currentItem = aIsNew
|
---|
529 | ? lvUSBFilters->currentItem()
|
---|
530 | : lvUSBFilters->lastItem();
|
---|
531 |
|
---|
532 | VBoxUSBFilterSettings *settings = new VBoxUSBFilterSettings (wstUSBFilters);
|
---|
533 | settings->setup (VBoxUSBFilterSettings::HostType);
|
---|
534 | settings->getFromFilter (aFilter);
|
---|
535 |
|
---|
536 | USBListItem *item = new USBListItem (lvUSBFilters, currentItem);
|
---|
537 | item->setOn (aFilter.GetActive());
|
---|
538 | item->setText (lvUSBFilters_Name, aFilter.GetName());
|
---|
539 |
|
---|
540 | item->mId = wstUSBFilters->addWidget (settings);
|
---|
541 |
|
---|
542 | /* fix the tab order so that main dialog's buttons are always the last */
|
---|
543 | setTabOrder (settings->focusProxy(), buttonHelp);
|
---|
544 | setTabOrder (buttonHelp, buttonOk);
|
---|
545 | setTabOrder (buttonOk, buttonCancel);
|
---|
546 |
|
---|
547 | if (aIsNew)
|
---|
548 | {
|
---|
549 | lvUSBFilters->setSelected (item, true);
|
---|
550 | lvUSBFilters_currentChanged (item);
|
---|
551 | settings->leUSBFilterName->setFocus();
|
---|
552 | }
|
---|
553 |
|
---|
554 | connect (settings->leUSBFilterName, SIGNAL (textChanged (const QString &)),
|
---|
555 | this, SLOT (lvUSBFilters_setCurrentText (const QString &)));
|
---|
556 |
|
---|
557 | /* setup validation */
|
---|
558 |
|
---|
559 | QIWidgetValidator *wval = new QIWidgetValidator (settings, settings);
|
---|
560 | connect (wval, SIGNAL (validityChanged (const QIWidgetValidator *)),
|
---|
561 | this, SLOT (enableOk (const QIWidgetValidator *)));
|
---|
562 |
|
---|
563 | wval->revalidate();
|
---|
564 | }
|
---|
565 |
|
---|
566 | void VBoxGlobalSettingsDlg::lvUSBFilters_currentChanged (QListViewItem *item)
|
---|
567 | {
|
---|
568 | if (item && lvUSBFilters->selectedItem() != item)
|
---|
569 | lvUSBFilters->setSelected (item, true);
|
---|
570 |
|
---|
571 | tbRemoveUSBFilter->setEnabled (!!item);
|
---|
572 |
|
---|
573 | tbUSBFilterUp->setEnabled (!!item && item->itemAbove());
|
---|
574 | tbUSBFilterDown->setEnabled (!!item && item->itemBelow());
|
---|
575 |
|
---|
576 | if (item)
|
---|
577 | {
|
---|
578 | USBListItem *uli = static_cast <USBListItem *> (item);
|
---|
579 | wstUSBFilters->raiseWidget (uli->mId);
|
---|
580 | }
|
---|
581 | else
|
---|
582 | {
|
---|
583 | /* raise the disabled widget */
|
---|
584 | wstUSBFilters->raiseWidget (0);
|
---|
585 | }
|
---|
586 | }
|
---|
587 |
|
---|
588 | void VBoxGlobalSettingsDlg::lvUSBFilters_setCurrentText (const QString &aText)
|
---|
589 | {
|
---|
590 | QListViewItem *item = lvUSBFilters->currentItem();
|
---|
591 | Assert (item);
|
---|
592 |
|
---|
593 | item->setText (lvUSBFilters_Name, aText);
|
---|
594 | }
|
---|
595 |
|
---|
596 | void VBoxGlobalSettingsDlg::tbAddUSBFilter_clicked()
|
---|
597 | {
|
---|
598 | CHost host = vboxGlobal().virtualBox().GetHost();
|
---|
599 | CHostUSBDeviceFilter hostFilter;
|
---|
600 | host.CreateUSBDeviceFilter (tr ("New Filter %1", "usb")
|
---|
601 | .arg (++ mLastUSBFilterNum), hostFilter);
|
---|
602 | hostFilter.SetAction (CEnums::USBDeviceFilterHold);
|
---|
603 |
|
---|
604 | CUSBDeviceFilter filter = CUnknown (hostFilter);
|
---|
605 | filter.SetActive (true);
|
---|
606 | addUSBFilter (filter, true);
|
---|
607 |
|
---|
608 | mUSBFilterListModified = true;
|
---|
609 | }
|
---|
610 |
|
---|
611 | void VBoxGlobalSettingsDlg::tbAddUSBFilterFrom_clicked()
|
---|
612 | {
|
---|
613 | usbDevicesMenu->exec (QCursor::pos());
|
---|
614 | }
|
---|
615 |
|
---|
616 | void VBoxGlobalSettingsDlg::menuAddUSBFilterFrom_activated (int aIndex)
|
---|
617 | {
|
---|
618 | CUSBDevice usb = usbDevicesMenu->getUSB (aIndex);
|
---|
619 |
|
---|
620 | // if null then some other item but a USB device is selected
|
---|
621 | if (usb.isNull())
|
---|
622 | return;
|
---|
623 |
|
---|
624 | CHost host = vboxGlobal().virtualBox().GetHost();
|
---|
625 | CHostUSBDeviceFilter hostFilter;
|
---|
626 | host.CreateUSBDeviceFilter (vboxGlobal().details (usb), hostFilter);
|
---|
627 | hostFilter.SetAction (CEnums::USBDeviceFilterHold);
|
---|
628 |
|
---|
629 | CUSBDeviceFilter filter = CUnknown (hostFilter);
|
---|
630 | filter.SetVendorId (QString().sprintf ("%04hX", usb.GetVendorId()));
|
---|
631 | filter.SetProductId (QString().sprintf ("%04hX", usb.GetProductId()));
|
---|
632 | filter.SetRevision (QString().sprintf ("%04hX", usb.GetRevision()));
|
---|
633 | filter.SetPort (QString().sprintf ("%04hX", usb.GetPort()));
|
---|
634 | filter.SetManufacturer (usb.GetManufacturer());
|
---|
635 | filter.SetProduct (usb.GetProduct());
|
---|
636 | filter.SetSerialNumber (usb.GetSerialNumber());
|
---|
637 | filter.SetRemote (usb.GetRemote() ? "yes" : "no");
|
---|
638 | filter.SetActive (true);
|
---|
639 | addUSBFilter (filter, true);
|
---|
640 |
|
---|
641 | mUSBFilterListModified = true;
|
---|
642 | }
|
---|
643 |
|
---|
644 | void VBoxGlobalSettingsDlg::tbRemoveUSBFilter_clicked()
|
---|
645 | {
|
---|
646 | QListViewItem *item = lvUSBFilters->currentItem();
|
---|
647 | Assert (item);
|
---|
648 |
|
---|
649 | USBListItem *uli = static_cast <USBListItem *> (item);
|
---|
650 | QWidget *settings = wstUSBFilters->widget (uli->mId);
|
---|
651 | Assert (settings);
|
---|
652 | wstUSBFilters->removeWidget (settings);
|
---|
653 | delete settings;
|
---|
654 |
|
---|
655 | delete item;
|
---|
656 |
|
---|
657 | lvUSBFilters->setSelected (lvUSBFilters->currentItem(), true);
|
---|
658 | mUSBFilterListModified = true;
|
---|
659 | }
|
---|
660 |
|
---|
661 | void VBoxGlobalSettingsDlg::tbUSBFilterUp_clicked()
|
---|
662 | {
|
---|
663 | QListViewItem *item = lvUSBFilters->currentItem();
|
---|
664 | Assert (item);
|
---|
665 |
|
---|
666 | QListViewItem *itemAbove = item->itemAbove();
|
---|
667 | Assert (itemAbove);
|
---|
668 | itemAbove = itemAbove->itemAbove();
|
---|
669 |
|
---|
670 | if (!itemAbove)
|
---|
671 | item->itemAbove()->moveItem (item);
|
---|
672 | else
|
---|
673 | item->moveItem (itemAbove);
|
---|
674 |
|
---|
675 | lvUSBFilters_currentChanged (item);
|
---|
676 | mUSBFilterListModified = true;
|
---|
677 | }
|
---|
678 |
|
---|
679 | void VBoxGlobalSettingsDlg::tbUSBFilterDown_clicked()
|
---|
680 | {
|
---|
681 | QListViewItem *item = lvUSBFilters->currentItem();
|
---|
682 | Assert (item);
|
---|
683 |
|
---|
684 | QListViewItem *itemBelow = item->itemBelow();
|
---|
685 | Assert (itemBelow);
|
---|
686 |
|
---|
687 | item->moveItem (itemBelow);
|
---|
688 |
|
---|
689 | lvUSBFilters_currentChanged (item);
|
---|
690 | mUSBFilterListModified = true;
|
---|
691 | }
|
---|