PageRenderTime 99ms CodeModel.GetById 13ms app.highlight 80ms RepoModel.GetById 1ms app.codeStats 0ms

/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsUSB.cpp

https://gitlab.com/ufo/virtualbox-ose-3-1-8
C++ | 577 lines | 457 code | 76 blank | 44 comment | 69 complexity | c80be4d99c7b4b19c6fb65b5717823a2 MD5 | raw file
  1/** @file
  2 *
  3 * VBox frontends: Qt4 GUI ("VirtualBox"):
  4 * VBoxVMSettingsUSB class implementation
  5 */
  6
  7/*
  8 * Copyright (C) 2006-2008 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#include "VBoxVMSettingsUSB.h"
 24#include "VBoxVMSettingsUSBFilterDetails.h"
 25#include "QIWidgetValidator.h"
 26#include "VBoxToolBar.h"
 27#include "VBoxGlobal.h"
 28
 29#include <QHeaderView>
 30
 31inline static QString emptyToNull (const QString &str)
 32{
 33    return str.isEmpty() ? QString::null : str;
 34}
 35
 36VBoxVMSettingsUSB::VBoxVMSettingsUSB (FilterType aType)
 37    : mValidator (0)
 38    , mType (aType)
 39    , mUSBFilterListModified (false)
 40{
 41    /* Apply UI decorations */
 42    Ui::VBoxVMSettingsUSB::setupUi (this);
 43
 44    /* Prepare actions */
 45    mNewAction = new QAction (mTwFilters);
 46    mAddAction = new QAction (mTwFilters);
 47    mEdtAction = new QAction (mTwFilters);
 48    mDelAction = new QAction (mTwFilters);
 49    mMupAction = new QAction (mTwFilters);
 50    mMdnAction = new QAction (mTwFilters);
 51
 52    mNewAction->setShortcut (QKeySequence ("Ins"));
 53    mAddAction->setShortcut (QKeySequence ("Alt+Ins"));
 54    mEdtAction->setShortcut (QKeySequence ("Ctrl+Return"));
 55    mDelAction->setShortcut (QKeySequence ("Del"));
 56    mMupAction->setShortcut (QKeySequence ("Ctrl+Up"));
 57    mMdnAction->setShortcut (QKeySequence ("Ctrl+Down"));
 58
 59    mNewAction->setIcon (VBoxGlobal::iconSet (":/usb_new_16px.png",
 60                                              ":/usb_new_disabled_16px.png"));
 61    mAddAction->setIcon (VBoxGlobal::iconSet (":/usb_add_16px.png",
 62                                              ":/usb_add_disabled_16px.png"));
 63    mEdtAction->setIcon (VBoxGlobal::iconSet (":/usb_filter_edit_16px.png",
 64                                              ":/usb_filter_edit_disabled_16px.png"));
 65    mDelAction->setIcon (VBoxGlobal::iconSet (":/usb_remove_16px.png",
 66                                              ":/usb_remove_disabled_16px.png"));
 67    mMupAction->setIcon (VBoxGlobal::iconSet (":/usb_moveup_16px.png",
 68                                              ":/usb_moveup_disabled_16px.png"));
 69    mMdnAction->setIcon (VBoxGlobal::iconSet (":/usb_movedown_16px.png",
 70                                              ":/usb_movedown_disabled_16px.png"));
 71
 72    /* Prepare menu and toolbar */
 73    mMenu = new QMenu (mTwFilters);
 74    mMenu->addAction (mNewAction);
 75    mMenu->addAction (mAddAction);
 76    mMenu->addSeparator();
 77    mMenu->addAction (mEdtAction);
 78    mMenu->addSeparator();
 79    mMenu->addAction (mDelAction);
 80    mMenu->addSeparator();
 81    mMenu->addAction (mMupAction);
 82    mMenu->addAction (mMdnAction);
 83
 84    /* Prepare toolbar */
 85    VBoxToolBar *toolBar = new VBoxToolBar (mWtFilterHandler);
 86    toolBar->setUsesTextLabel (false);
 87    toolBar->setIconSize (QSize (16, 16));
 88    toolBar->setOrientation (Qt::Vertical);
 89    toolBar->addAction (mNewAction);
 90    toolBar->addAction (mAddAction);
 91    toolBar->addAction (mEdtAction);
 92    toolBar->addAction (mDelAction);
 93    toolBar->addAction (mMupAction);
 94    toolBar->addAction (mMdnAction);
 95    toolBar->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::MinimumExpanding);
 96    toolBar->updateGeometry();
 97    toolBar->setMinimumHeight (toolBar->sizeHint().height());
 98    mWtFilterHandler->layout()->addWidget (toolBar);
 99
100    /* Setup connections */
101    connect (mGbUSB, SIGNAL (toggled (bool)),
102             this, SLOT (usbAdapterToggled (bool)));
103    connect (mTwFilters, SIGNAL (currentItemChanged (QTreeWidgetItem*, QTreeWidgetItem*)),
104             this, SLOT (currentChanged (QTreeWidgetItem*, QTreeWidgetItem*)));
105    connect (mTwFilters, SIGNAL (customContextMenuRequested (const QPoint &)),
106             this, SLOT (showContextMenu (const QPoint &)));
107    connect (mTwFilters, SIGNAL (itemDoubleClicked (QTreeWidgetItem *, int)),
108             this, SLOT (edtClicked()));
109    connect (mTwFilters, SIGNAL (itemChanged (QTreeWidgetItem *, int)),
110             this, SLOT (markSettingsChanged()));
111
112    mUSBDevicesMenu = new VBoxUSBMenu (this);
113    connect (mUSBDevicesMenu, SIGNAL (triggered (QAction*)),
114             this, SLOT (addConfirmed (QAction *)));
115    connect (mNewAction, SIGNAL (triggered (bool)),
116             this, SLOT (newClicked()));
117    connect (mAddAction, SIGNAL (triggered (bool)),
118             this, SLOT (addClicked()));
119    connect (mEdtAction, SIGNAL (triggered (bool)),
120             this, SLOT (edtClicked()));
121    connect (mDelAction, SIGNAL (triggered (bool)),
122             this, SLOT (delClicked()));
123    connect (mMupAction, SIGNAL (triggered (bool)),
124             this, SLOT (mupClicked()));
125    connect (mMdnAction, SIGNAL (triggered (bool)),
126             this, SLOT (mdnClicked()));
127
128    /* Setup dialog */
129    mTwFilters->header()->hide();
130
131    /* Applying language settings */
132    retranslateUi();
133}
134
135void VBoxVMSettingsUSB::getFrom (const CSystemProperties &, const VBoxGlobalSettings &)
136{
137    mGbUSB->setVisible (false);
138
139    CHostUSBDeviceFilterVector filtvec = vboxGlobal().virtualBox().GetHost()
140                                        .GetUSBDeviceFilters();
141    for (int i = 0; i < filtvec.size(); ++i)
142    {
143        CHostUSBDeviceFilter hostFilter = filtvec[i];
144        CUSBDeviceFilter filter (hostFilter);
145        addUSBFilter (filter, false /* isNew */);
146    }
147
148    mTwFilters->setCurrentItem (mTwFilters->topLevelItem (0));
149    currentChanged (mTwFilters->currentItem());
150
151    mUSBFilterListModified = false;
152}
153
154void VBoxVMSettingsUSB::putBackTo (CSystemProperties &, VBoxGlobalSettings &)
155{
156    CHost host = vboxGlobal().virtualBox().GetHost();
157
158    if (mUSBFilterListModified)
159    {
160        /* First, remove all old filters */
161        for (ulong count = host.GetUSBDeviceFilters().size(); count; -- count)
162            host.RemoveUSBDeviceFilter (0);
163
164        /* Then add all new filters */
165        for (int i = 0; i < mFilters.size(); ++ i)
166        {
167            CUSBDeviceFilter filter = mFilters [i];
168            filter.SetActive (mTwFilters->topLevelItem (i)->
169                checkState (0) == Qt::Checked);
170            CHostUSBDeviceFilter insertedFilter (filter);
171            host.InsertUSBDeviceFilter (host.GetUSBDeviceFilters().size(),
172                                        insertedFilter);
173        }
174    }
175
176    mUSBFilterListModified = false;
177}
178
179void VBoxVMSettingsUSB::getFrom (const CMachine &aMachine)
180{
181    mMachine = aMachine;
182
183    CUSBController ctl = aMachine.GetUSBController();
184    mGbUSB->setChecked (!ctl.isNull() && ctl.GetEnabled());
185    mCbUSB2->setChecked (!ctl.isNull() && ctl.GetEnabledEhci());
186    usbAdapterToggled (mGbUSB->isChecked());
187
188    if (!ctl.isNull())
189    {
190        CUSBDeviceFilterVector filtvec = ctl.GetDeviceFilters();
191        for (int i = 0; i < filtvec.size(); ++i)
192            addUSBFilter (filtvec[i], false /* isNew */);
193    }
194
195    mTwFilters->setCurrentItem (mTwFilters->topLevelItem (0));
196    currentChanged (mTwFilters->currentItem());
197
198    mUSBFilterListModified = false;
199}
200
201void VBoxVMSettingsUSB::putBackTo()
202{
203    CUSBController ctl = mMachine.GetUSBController();
204    if (!ctl.isNull())
205    {
206        ctl.SetEnabled (mGbUSB->isChecked());
207        ctl.SetEnabledEhci (mCbUSB2->isChecked());
208
209        if (mUSBFilterListModified)
210        {
211            /* First, remove all old filters */
212            for (ulong count = ctl.GetDeviceFilters().size(); count; -- count)
213                ctl.RemoveDeviceFilter (0);
214
215            /* Then add all new filters */
216            for (int i = 0; i < mFilters.size(); ++ i)
217            {
218                CUSBDeviceFilter filter = mFilters [i];
219                filter.SetActive (mTwFilters->topLevelItem (i)->
220                    checkState (0) == Qt::Checked);
221                ctl.InsertDeviceFilter (~0, filter);
222            }
223        }
224    }
225    mUSBFilterListModified = false;
226}
227
228void VBoxVMSettingsUSB::setValidator (QIWidgetValidator *aVal)
229{
230    mValidator = aVal;
231}
232
233void VBoxVMSettingsUSB::setOrderAfter (QWidget *aWidget)
234{
235    setTabOrder (aWidget, mGbUSB);
236    setTabOrder (mGbUSB, mCbUSB2);
237    setTabOrder (mCbUSB2, mTwFilters);
238}
239
240void VBoxVMSettingsUSB::retranslateUi()
241{
242    /* Translate uic generated strings */
243    Ui::VBoxVMSettingsUSB::retranslateUi (this);
244
245    mNewAction->setText (tr ("&Add Empty Filter"));
246    mAddAction->setText (tr ("A&dd Filter From Device"));
247    mEdtAction->setText (tr ("&Edit Filter"));
248    mDelAction->setText (tr ("&Remove Filter"));
249    mMupAction->setText (tr ("&Move Filter Up"));
250    mMdnAction->setText (tr ("M&ove Filter Down"));
251
252    mNewAction->setToolTip (mNewAction->text().remove ('&') +
253        QString (" (%1)").arg (mNewAction->shortcut().toString()));
254    mAddAction->setToolTip (mAddAction->text().remove ('&') +
255        QString (" (%1)").arg (mAddAction->shortcut().toString()));
256    mEdtAction->setToolTip (mEdtAction->text().remove ('&') +
257        QString (" (%1)").arg (mEdtAction->shortcut().toString()));
258    mDelAction->setToolTip (mDelAction->text().remove ('&') +
259        QString (" (%1)").arg (mDelAction->shortcut().toString()));
260    mMupAction->setToolTip (mMupAction->text().remove ('&') +
261        QString (" (%1)").arg (mMupAction->shortcut().toString()));
262    mMdnAction->setToolTip (mMdnAction->text().remove ('&') +
263        QString (" (%1)").arg (mMdnAction->shortcut().toString()));
264
265    mNewAction->setWhatsThis (tr ("Adds a new USB filter with all fields "
266                                  "initially set to empty strings. Note "
267                                  "that such a filter will match any "
268                                  "attached USB device."));
269    mAddAction->setWhatsThis (tr ("Adds a new USB filter with all fields "
270                                  "set to the values of the selected USB "
271                                  "device attached to the host PC."));
272    mEdtAction->setWhatsThis (tr ("Edits the selected USB filter."));
273    mDelAction->setWhatsThis (tr ("Removes the selected USB filter."));
274    mMupAction->setWhatsThis (tr ("Moves the selected USB filter up."));
275    mMdnAction->setWhatsThis (tr ("Moves the selected USB filter down."));
276
277    mUSBFilterName = tr ("New Filter %1", "usb");
278}
279
280void VBoxVMSettingsUSB::usbAdapterToggled (bool aOn)
281{
282    mGbUSBFilters->setEnabled (aOn);
283}
284
285void VBoxVMSettingsUSB::currentChanged (QTreeWidgetItem *aItem,
286                                        QTreeWidgetItem *)
287{
288    /* Make sure only the current item if present => selected */
289    if (mTwFilters->selectedItems().count() != 1 ||
290        mTwFilters->selectedItems() [0] != aItem)
291    {
292        QList<QTreeWidgetItem*> list = mTwFilters->selectedItems();
293        for (int i = 0; i < list.size(); ++ i)
294            list [i]->setSelected (false);
295        if (aItem)
296            aItem->setSelected (true);
297    }
298
299    /* Enable/disable operational buttons */
300    mEdtAction->setEnabled (aItem);
301    mDelAction->setEnabled (aItem);
302    mMupAction->setEnabled (aItem && mTwFilters->itemAbove (aItem));
303    mMdnAction->setEnabled (aItem && mTwFilters->itemBelow (aItem));
304}
305
306void VBoxVMSettingsUSB::newClicked()
307{
308    /* Search for the max available filter index */
309    int maxFilterIndex = 0;
310    QRegExp regExp (QString ("^") + mUSBFilterName.arg ("([0-9]+)") + QString ("$"));
311    QTreeWidgetItemIterator iterator (mTwFilters);
312    while (*iterator)
313    {
314        QString filterName = (*iterator)->text (0);
315        int pos = regExp.indexIn (filterName);
316        if (pos != -1)
317            maxFilterIndex = regExp.cap (1).toInt() > maxFilterIndex ?
318                             regExp.cap (1).toInt() : maxFilterIndex;
319        ++ iterator;
320    }
321
322    /* Creating new usb filter */
323    CUSBDeviceFilter filter;
324
325    if (mType == HostType)
326    {
327        CHost host = vboxGlobal().virtualBox().GetHost();
328        CHostUSBDeviceFilter hostFilter = host
329            .CreateUSBDeviceFilter (mUSBFilterName.arg (maxFilterIndex + 1));
330        hostFilter.SetAction (KUSBDeviceFilterAction_Hold);
331        filter = hostFilter;
332    }
333    else if (mType == MachineType)
334    {
335        CUSBController ctl = mMachine.GetUSBController();
336        if (ctl.isNull())
337            return;
338        filter = ctl.CreateDeviceFilter (mUSBFilterName.arg (maxFilterIndex + 1));
339    }
340    else
341    {
342        AssertMsgFailed (("Invalid VBoxVMSettingsUSB type"));
343    }
344
345    filter.SetActive (true);
346    addUSBFilter (filter, true /* isNew */);
347
348    mUSBFilterListModified = true;
349}
350
351void VBoxVMSettingsUSB::addClicked()
352{
353    mUSBDevicesMenu->exec (QCursor::pos());
354}
355
356void VBoxVMSettingsUSB::addConfirmed (QAction *aAction)
357{
358    CUSBDevice usb = mUSBDevicesMenu->getUSB (aAction);
359    /* if null then some other item but a USB device is selected */
360    if (usb.isNull())
361        return;
362
363    /* Creating new usb filter */
364    CUSBDeviceFilter filter;
365
366    if (mType == HostType)
367    {
368        CHost host = vboxGlobal().virtualBox().GetHost();
369        CHostUSBDeviceFilter hostFilter = host
370            .CreateUSBDeviceFilter (vboxGlobal().details (usb));
371        hostFilter.SetAction (KUSBDeviceFilterAction_Hold);
372        filter = hostFilter;
373    }
374    else if (mType == MachineType)
375    {
376        CUSBController ctl = mMachine.GetUSBController();
377        if (ctl.isNull())
378            return;
379        filter = ctl.CreateDeviceFilter (vboxGlobal().details (usb));
380    }
381    else
382    {
383        AssertMsgFailed (("Invalid VBoxVMSettingsUSB type"));
384    }
385
386    filter.SetVendorId (QString().sprintf ("%04hX", usb.GetVendorId()));
387    filter.SetProductId (QString().sprintf ("%04hX", usb.GetProductId()));
388    filter.SetRevision (QString().sprintf ("%04hX", usb.GetRevision()));
389    /* The port property depends on the host computer rather than on the USB
390     * device itself; for this reason only a few people will want to use it
391     * in the filter since the same device plugged into a different socket
392     * will not match the filter in this case. */
393#if 0
394    /// @todo set it anyway if Alt is currently pressed
395    filter.SetPort (QString().sprintf ("%04hX", usb.GetPort()));
396#endif
397    filter.SetManufacturer (usb.GetManufacturer());
398    filter.SetProduct (usb.GetProduct());
399    filter.SetSerialNumber (usb.GetSerialNumber());
400    filter.SetRemote (usb.GetRemote() ? "yes" : "no");
401
402    filter.SetActive (true);
403    addUSBFilter (filter, true /* isNew */);
404
405    mUSBFilterListModified = true;
406}
407
408void VBoxVMSettingsUSB::edtClicked()
409{
410    QTreeWidgetItem *item = mTwFilters->currentItem();
411    Assert (item);
412
413    VBoxVMSettingsUSBFilterDetails fd (mType, this);
414
415    CUSBDeviceFilter filter =
416        mFilters [mTwFilters->indexOfTopLevelItem (item)];
417
418    fd.mLeName->setText (filter.isNull() ? QString::null : filter.GetName());
419    fd.mLeVendorID->setText (filter.isNull() ? QString::null : filter.GetVendorId());
420    fd.mLeProductID->setText (filter.isNull() ? QString::null : filter.GetProductId());
421    fd.mLeRevision->setText (filter.isNull() ? QString::null : filter.GetRevision());
422    fd.mLePort->setText (filter.isNull() ? QString::null : filter.GetPort());
423    fd.mLeManufacturer->setText (filter.isNull() ? QString::null : filter.GetManufacturer());
424    fd.mLeProduct->setText (filter.isNull() ? QString::null : filter.GetProduct());
425    fd.mLeSerialNo->setText (filter.isNull() ? QString::null : filter.GetSerialNumber());
426
427    switch (mType)
428    {
429        case MachineType:
430        {
431            QString remote = filter.isNull() ? QString::null : filter.GetRemote().toLower();
432            if (remote == "yes" || remote == "true" || remote == "1")
433                fd.mCbRemote->setCurrentIndex (ModeOn);
434            else if (remote == "no" || remote == "false" || remote == "0")
435                fd.mCbRemote->setCurrentIndex (ModeOff);
436            else
437                fd.mCbRemote->setCurrentIndex (ModeAny);
438            break;
439        }
440        case HostType:
441        {
442            CHostUSBDeviceFilter hostFilter (filter);
443            KUSBDeviceFilterAction action = hostFilter.isNull() ?
444                KUSBDeviceFilterAction_Ignore : hostFilter.GetAction();
445            if (action == KUSBDeviceFilterAction_Ignore)
446                fd.mCbAction->setCurrentIndex (0);
447            else if (action == KUSBDeviceFilterAction_Hold)
448                fd.mCbAction->setCurrentIndex (1);
449            else
450                AssertMsgFailed (("Invalid USBDeviceFilterAction type"));
451            break;
452        }
453        default:
454        {
455            AssertMsgFailed (("Invalid VBoxVMSettingsUSB type"));
456            break;
457        }
458    }
459
460    if (fd.exec() == QDialog::Accepted)
461    {
462        filter.SetName (fd.mLeName->text().isEmpty() ? QString::null : fd.mLeName->text());
463        item->setText (0, fd.mLeName->text());
464        filter.SetVendorId (fd.mLeVendorID->text().isEmpty() ? QString::null : fd.mLeVendorID->text());
465        filter.SetProductId (fd.mLeProductID->text().isEmpty() ? QString::null : fd.mLeProductID->text());
466        filter.SetRevision (fd.mLeRevision->text().isEmpty() ? QString::null : fd.mLeRevision->text());
467        filter.SetManufacturer (fd.mLeManufacturer->text().isEmpty() ? QString::null : fd.mLeManufacturer->text());
468        filter.SetProduct (fd.mLeProduct->text().isEmpty() ? QString::null : fd.mLeProduct->text());
469        filter.SetSerialNumber (fd.mLeSerialNo->text().isEmpty() ? QString::null : fd.mLeSerialNo->text());
470        filter.SetPort (fd.mLePort->text().isEmpty() ? QString::null : fd.mLePort->text());
471        if (mType == MachineType)
472        {
473            switch (fd.mCbRemote->currentIndex())
474             {
475                 case ModeAny: filter.SetRemote (QString::null); break;
476                 case ModeOn:  filter.SetRemote ("yes"); break;
477                 case ModeOff: filter.SetRemote ("no"); break;
478                 default: AssertMsgFailed (("Invalid combo box index"));
479             }
480        }
481        else
482        if (mType == HostType)
483        {
484            CHostUSBDeviceFilter hostFilter (filter);
485            hostFilter.SetAction (vboxGlobal().toUSBDevFilterAction (fd.mCbAction->currentText()));
486        }
487        item->setToolTip (0, vboxGlobal().toolTip (filter));
488    }
489}
490
491void VBoxVMSettingsUSB::delClicked()
492{
493    QTreeWidgetItem *item = mTwFilters->currentItem();
494    Assert (item);
495    int index = mTwFilters->indexOfTopLevelItem (item);
496
497    delete item;
498    mFilters.removeAt (index);
499
500    /* Setup validators */
501    if (!mTwFilters->topLevelItemCount())
502    {
503        if (mValidator)
504        {
505            mValidator->rescan();
506            mValidator->revalidate();
507        }
508    }
509
510    currentChanged (mTwFilters->currentItem());
511    mUSBFilterListModified = true;
512}
513
514void VBoxVMSettingsUSB::mupClicked()
515{
516    QTreeWidgetItem *item = mTwFilters->currentItem();
517    Assert (item);
518
519    int index = mTwFilters->indexOfTopLevelItem (item);
520    QTreeWidgetItem *takenItem = mTwFilters->takeTopLevelItem (index);
521    Assert (item == takenItem);
522    mTwFilters->insertTopLevelItem (index - 1, takenItem);
523    mFilters.swap (index, index - 1);
524
525    mTwFilters->setCurrentItem (takenItem);
526    mUSBFilterListModified = true;
527}
528
529void VBoxVMSettingsUSB::mdnClicked()
530{
531    QTreeWidgetItem *item = mTwFilters->currentItem();
532    Assert (item);
533
534    int index = mTwFilters->indexOfTopLevelItem (item);
535    QTreeWidgetItem *takenItem = mTwFilters->takeTopLevelItem (index);
536    Assert (item == takenItem);
537    mTwFilters->insertTopLevelItem (index + 1, takenItem);
538    mFilters.swap (index, index + 1);
539
540    mTwFilters->setCurrentItem (takenItem);
541    mUSBFilterListModified = true;
542}
543
544void VBoxVMSettingsUSB::showContextMenu (const QPoint &aPos)
545{
546    mMenu->exec (mTwFilters->mapToGlobal (aPos));
547}
548
549void VBoxVMSettingsUSB::markSettingsChanged()
550{
551    mUSBFilterListModified = true;
552}
553
554void VBoxVMSettingsUSB::addUSBFilter (const CUSBDeviceFilter &aFilter,
555                                      bool isNew)
556{
557    QTreeWidgetItem *currentItem = isNew ?
558        mTwFilters->currentItem() :
559        mTwFilters->topLevelItem (mTwFilters->topLevelItemCount() - 1);
560
561    int pos = currentItem ? mTwFilters->indexOfTopLevelItem (currentItem) : -1;
562    mFilters.insert (pos + 1, aFilter);
563
564    QTreeWidgetItem *item = pos >= 0 ?
565        new QTreeWidgetItem (mTwFilters, mTwFilters->topLevelItem (pos)) :
566        new QTreeWidgetItem (mTwFilters);
567    item->setCheckState (0, aFilter.GetActive() ? Qt::Checked : Qt::Unchecked);
568    item->setText (0, aFilter.GetName());
569    item->setToolTip (0, vboxGlobal().toolTip (aFilter));
570
571    if (isNew)
572        mTwFilters->setCurrentItem (item);
573
574    if (mValidator)
575        mValidator->revalidate();
576}
577