[26714] | 1 | /* $Id: UIMachineSettingsUSB.cpp 37051 2011-05-12 13:48:15Z vboxsync $ */
|
---|
[25177] | 2 | /** @file
|
---|
| 3 | *
|
---|
| 4 | * VBox frontends: Qt4 GUI ("VirtualBox"):
|
---|
[33882] | 5 | * UIMachineSettingsUSB class implementation
|
---|
[25177] | 6 | */
|
---|
| 7 |
|
---|
| 8 | /*
|
---|
[36324] | 9 | * Copyright (C) 2006-2011 Oracle Corporation
|
---|
[25177] | 10 | *
|
---|
| 11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
| 12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
| 13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
| 14 | * General Public License (GPL) as published by the Free Software
|
---|
| 15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
| 16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
| 17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
| 18 | */
|
---|
| 19 |
|
---|
[30192] | 20 | /* Local includes */
|
---|
| 21 | #include "QIWidgetValidator.h"
|
---|
| 22 | #include "UIIconPool.h"
|
---|
| 23 | #include "VBoxGlobal.h"
|
---|
[36393] | 24 | #include "VBoxProblemReporter.h"
|
---|
[32760] | 25 | #include "UIToolBar.h"
|
---|
[33882] | 26 | #include "UIMachineSettingsUSB.h"
|
---|
| 27 | #include "UIMachineSettingsUSBFilterDetails.h"
|
---|
[25177] | 28 |
|
---|
[30192] | 29 | /* Global includes */
|
---|
[25177] | 30 | #include <QHeaderView>
|
---|
| 31 |
|
---|
[33882] | 32 | UIMachineSettingsUSB::UIMachineSettingsUSB(UISettingsPageType type)
|
---|
[33631] | 33 | : UISettingsPage(type)
|
---|
[33686] | 34 | , mValidator(0)
|
---|
| 35 | , mNewAction(0), mAddAction(0), mEdtAction(0), mDelAction(0)
|
---|
| 36 | , mMupAction(0), mMdnAction(0)
|
---|
| 37 | , mMenu(0), mUSBDevicesMenu(0)
|
---|
[25177] | 38 | {
|
---|
| 39 | /* Apply UI decorations */
|
---|
[33882] | 40 | Ui::UIMachineSettingsUSB::setupUi (this);
|
---|
[25177] | 41 |
|
---|
| 42 | /* Prepare actions */
|
---|
| 43 | mNewAction = new QAction (mTwFilters);
|
---|
| 44 | mAddAction = new QAction (mTwFilters);
|
---|
| 45 | mEdtAction = new QAction (mTwFilters);
|
---|
| 46 | mDelAction = new QAction (mTwFilters);
|
---|
| 47 | mMupAction = new QAction (mTwFilters);
|
---|
| 48 | mMdnAction = new QAction (mTwFilters);
|
---|
| 49 |
|
---|
| 50 | mNewAction->setShortcut (QKeySequence ("Ins"));
|
---|
| 51 | mAddAction->setShortcut (QKeySequence ("Alt+Ins"));
|
---|
| 52 | mEdtAction->setShortcut (QKeySequence ("Ctrl+Return"));
|
---|
| 53 | mDelAction->setShortcut (QKeySequence ("Del"));
|
---|
| 54 | mMupAction->setShortcut (QKeySequence ("Ctrl+Up"));
|
---|
| 55 | mMdnAction->setShortcut (QKeySequence ("Ctrl+Down"));
|
---|
| 56 |
|
---|
[30192] | 57 | mNewAction->setIcon(UIIconPool::iconSet(":/usb_new_16px.png",
|
---|
| 58 | ":/usb_new_disabled_16px.png"));
|
---|
| 59 | mAddAction->setIcon(UIIconPool::iconSet(":/usb_add_16px.png",
|
---|
| 60 | ":/usb_add_disabled_16px.png"));
|
---|
| 61 | mEdtAction->setIcon(UIIconPool::iconSet(":/usb_filter_edit_16px.png",
|
---|
| 62 | ":/usb_filter_edit_disabled_16px.png"));
|
---|
| 63 | mDelAction->setIcon(UIIconPool::iconSet(":/usb_remove_16px.png",
|
---|
| 64 | ":/usb_remove_disabled_16px.png"));
|
---|
| 65 | mMupAction->setIcon(UIIconPool::iconSet(":/usb_moveup_16px.png",
|
---|
| 66 | ":/usb_moveup_disabled_16px.png"));
|
---|
| 67 | mMdnAction->setIcon(UIIconPool::iconSet(":/usb_movedown_16px.png",
|
---|
| 68 | ":/usb_movedown_disabled_16px.png"));
|
---|
[25177] | 69 |
|
---|
| 70 | /* Prepare menu and toolbar */
|
---|
| 71 | mMenu = new QMenu (mTwFilters);
|
---|
| 72 | mMenu->addAction (mNewAction);
|
---|
| 73 | mMenu->addAction (mAddAction);
|
---|
| 74 | mMenu->addSeparator();
|
---|
| 75 | mMenu->addAction (mEdtAction);
|
---|
| 76 | mMenu->addSeparator();
|
---|
| 77 | mMenu->addAction (mDelAction);
|
---|
| 78 | mMenu->addSeparator();
|
---|
| 79 | mMenu->addAction (mMupAction);
|
---|
| 80 | mMenu->addAction (mMdnAction);
|
---|
| 81 |
|
---|
| 82 | /* Prepare toolbar */
|
---|
[32760] | 83 | UIToolBar *toolBar = new UIToolBar (mWtFilterHandler);
|
---|
[25177] | 84 | toolBar->setUsesTextLabel (false);
|
---|
| 85 | toolBar->setIconSize (QSize (16, 16));
|
---|
| 86 | toolBar->setOrientation (Qt::Vertical);
|
---|
| 87 | toolBar->addAction (mNewAction);
|
---|
| 88 | toolBar->addAction (mAddAction);
|
---|
| 89 | toolBar->addAction (mEdtAction);
|
---|
| 90 | toolBar->addAction (mDelAction);
|
---|
| 91 | toolBar->addAction (mMupAction);
|
---|
| 92 | toolBar->addAction (mMdnAction);
|
---|
| 93 | toolBar->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::MinimumExpanding);
|
---|
| 94 | toolBar->updateGeometry();
|
---|
[33912] | 95 | #ifdef Q_WS_MAC
|
---|
| 96 | /* On the Mac this has to be slightly higher, than what sizeHint returned.
|
---|
| 97 | * No idea why. */
|
---|
| 98 | toolBar->setMinimumHeight(toolBar->sizeHint().height() + 4);
|
---|
| 99 | #else
|
---|
| 100 | toolBar->setMinimumHeight(toolBar->sizeHint().height());
|
---|
| 101 | #endif /* Q_WS_MAC */
|
---|
[25177] | 102 | mWtFilterHandler->layout()->addWidget (toolBar);
|
---|
| 103 |
|
---|
| 104 | /* Setup connections */
|
---|
| 105 | connect (mGbUSB, SIGNAL (toggled (bool)),
|
---|
| 106 | this, SLOT (usbAdapterToggled (bool)));
|
---|
| 107 | connect (mTwFilters, SIGNAL (currentItemChanged (QTreeWidgetItem*, QTreeWidgetItem*)),
|
---|
[36357] | 108 | this, SLOT (currentChanged (QTreeWidgetItem*)));
|
---|
[25177] | 109 | connect (mTwFilters, SIGNAL (customContextMenuRequested (const QPoint &)),
|
---|
| 110 | this, SLOT (showContextMenu (const QPoint &)));
|
---|
| 111 | connect (mTwFilters, SIGNAL (itemDoubleClicked (QTreeWidgetItem *, int)),
|
---|
| 112 | this, SLOT (edtClicked()));
|
---|
| 113 | connect (mTwFilters, SIGNAL (itemChanged (QTreeWidgetItem *, int)),
|
---|
[33631] | 114 | this, SLOT (sltUpdateActivityState(QTreeWidgetItem *)));
|
---|
[25177] | 115 |
|
---|
| 116 | mUSBDevicesMenu = new VBoxUSBMenu (this);
|
---|
| 117 | connect (mUSBDevicesMenu, SIGNAL (triggered (QAction*)),
|
---|
| 118 | this, SLOT (addConfirmed (QAction *)));
|
---|
| 119 | connect (mNewAction, SIGNAL (triggered (bool)),
|
---|
| 120 | this, SLOT (newClicked()));
|
---|
| 121 | connect (mAddAction, SIGNAL (triggered (bool)),
|
---|
| 122 | this, SLOT (addClicked()));
|
---|
| 123 | connect (mEdtAction, SIGNAL (triggered (bool)),
|
---|
| 124 | this, SLOT (edtClicked()));
|
---|
| 125 | connect (mDelAction, SIGNAL (triggered (bool)),
|
---|
| 126 | this, SLOT (delClicked()));
|
---|
| 127 | connect (mMupAction, SIGNAL (triggered (bool)),
|
---|
| 128 | this, SLOT (mupClicked()));
|
---|
| 129 | connect (mMdnAction, SIGNAL (triggered (bool)),
|
---|
| 130 | this, SLOT (mdnClicked()));
|
---|
| 131 |
|
---|
| 132 | /* Setup dialog */
|
---|
| 133 | mTwFilters->header()->hide();
|
---|
| 134 |
|
---|
| 135 | /* Applying language settings */
|
---|
| 136 | retranslateUi();
|
---|
[31946] | 137 |
|
---|
| 138 | #ifndef VBOX_WITH_EHCI
|
---|
| 139 | mCbUSB2->setHidden(true);
|
---|
[36936] | 140 | #endif /* VBOX_WITH_EHCI */
|
---|
[25177] | 141 | }
|
---|
| 142 |
|
---|
[33882] | 143 | bool UIMachineSettingsUSB::isOHCIEnabled() const
|
---|
[28939] | 144 | {
|
---|
| 145 | return mGbUSB->isChecked();
|
---|
| 146 | }
|
---|
| 147 |
|
---|
[33631] | 148 | /* Load data to cashe from corresponding external object(s),
|
---|
| 149 | * this task COULD be performed in other than GUI thread: */
|
---|
[33882] | 150 | void UIMachineSettingsUSB::loadToCacheFrom(QVariant &data)
|
---|
[25177] | 151 | {
|
---|
[33631] | 152 | /* Fetch data to properties & settings or machine: */
|
---|
| 153 | fetchData(data);
|
---|
[25177] | 154 |
|
---|
[37051] | 155 | /* Clear cache initially: */
|
---|
| 156 | m_cache.clear();
|
---|
| 157 |
|
---|
[33631] | 158 | /* Depending on page type: */
|
---|
[36324] | 159 | switch (pageType())
|
---|
[25177] | 160 | {
|
---|
[33631] | 161 | case UISettingsPageType_Global:
|
---|
| 162 | {
|
---|
[36936] | 163 | /* For each USB filter: */
|
---|
[33631] | 164 | const CHostUSBDeviceFilterVector &filters = vboxGlobal().virtualBox().GetHost().GetUSBDeviceFilters();
|
---|
| 165 | for (int iFilterIndex = 0; iFilterIndex < filters.size(); ++iFilterIndex)
|
---|
| 166 | {
|
---|
[36936] | 167 | /* Prepare USB filter data: */
|
---|
| 168 | UIDataSettingsMachineUSBFilter usbFilterData;
|
---|
| 169 |
|
---|
| 170 | /* Check if filter is valid: */
|
---|
[33631] | 171 | const CHostUSBDeviceFilter &filter = filters[iFilterIndex];
|
---|
[36936] | 172 | if (!filter.isNull())
|
---|
[33631] | 173 | {
|
---|
[36936] | 174 | usbFilterData.m_fActive = filter.GetActive();
|
---|
| 175 | usbFilterData.m_strName = filter.GetName();
|
---|
| 176 | usbFilterData.m_strVendorId = filter.GetVendorId();
|
---|
| 177 | usbFilterData.m_strProductId = filter.GetProductId();
|
---|
| 178 | usbFilterData.m_strRevision = filter.GetRevision();
|
---|
| 179 | usbFilterData.m_strManufacturer = filter.GetManufacturer();
|
---|
| 180 | usbFilterData.m_strProduct = filter.GetProduct();
|
---|
| 181 | usbFilterData.m_strSerialNumber = filter.GetSerialNumber();
|
---|
| 182 | usbFilterData.m_strPort = filter.GetPort();
|
---|
| 183 | usbFilterData.m_strRemote = filter.GetRemote();
|
---|
| 184 | usbFilterData.m_action = filter.GetAction();
|
---|
| 185 | CHostUSBDevice hostUSBDevice(filter);
|
---|
| 186 | if (!hostUSBDevice.isNull())
|
---|
| 187 | {
|
---|
| 188 | usbFilterData.m_fHostUSBDevice = true;
|
---|
| 189 | usbFilterData.m_hostUSBDeviceState = hostUSBDevice.GetState();
|
---|
| 190 | }
|
---|
| 191 | else
|
---|
| 192 | {
|
---|
| 193 | usbFilterData.m_fHostUSBDevice = false;
|
---|
| 194 | usbFilterData.m_hostUSBDeviceState = KUSBDeviceState_NotSupported;
|
---|
| 195 | }
|
---|
[33631] | 196 | }
|
---|
[36936] | 197 |
|
---|
| 198 | /* Cache USB filter data: */
|
---|
| 199 | m_cache.child(iFilterIndex).cacheInitialData(usbFilterData);
|
---|
[33631] | 200 | }
|
---|
[36936] | 201 |
|
---|
[33631] | 202 | break;
|
---|
| 203 | }
|
---|
| 204 | case UISettingsPageType_Machine:
|
---|
| 205 | {
|
---|
[36936] | 206 | /* Prepare USB data: */
|
---|
| 207 | UIDataSettingsMachineUSB usbData;
|
---|
| 208 |
|
---|
| 209 | /* Check if controller is valid: */
|
---|
| 210 | const CUSBController &controller = m_machine.GetUSBController();
|
---|
| 211 | if (!controller.isNull())
|
---|
[33631] | 212 | {
|
---|
[36936] | 213 | /* Gather USB values: */
|
---|
| 214 | usbData.m_fUSBEnabled = controller.GetEnabled();
|
---|
| 215 | usbData.m_fEHCIEnabled = controller.GetEnabledEhci();
|
---|
| 216 |
|
---|
| 217 | /* For each USB filter: */
|
---|
| 218 | const CUSBDeviceFilterVector &filters = controller.GetDeviceFilters();
|
---|
[33631] | 219 | for (int iFilterIndex = 0; iFilterIndex < filters.size(); ++iFilterIndex)
|
---|
| 220 | {
|
---|
[36936] | 221 | /* Prepare USB filter data: */
|
---|
| 222 | UIDataSettingsMachineUSBFilter usbFilterData;
|
---|
| 223 |
|
---|
| 224 | /* Check if filter is valid: */
|
---|
[33631] | 225 | const CUSBDeviceFilter &filter = filters[iFilterIndex];
|
---|
[36936] | 226 | if (!filter.isNull())
|
---|
| 227 | {
|
---|
| 228 | usbFilterData.m_fActive = filter.GetActive();
|
---|
| 229 | usbFilterData.m_strName = filter.GetName();
|
---|
| 230 | usbFilterData.m_strVendorId = filter.GetVendorId();
|
---|
| 231 | usbFilterData.m_strProductId = filter.GetProductId();
|
---|
| 232 | usbFilterData.m_strRevision = filter.GetRevision();
|
---|
| 233 | usbFilterData.m_strManufacturer = filter.GetManufacturer();
|
---|
| 234 | usbFilterData.m_strProduct = filter.GetProduct();
|
---|
| 235 | usbFilterData.m_strSerialNumber = filter.GetSerialNumber();
|
---|
| 236 | usbFilterData.m_strPort = filter.GetPort();
|
---|
| 237 | usbFilterData.m_strRemote = filter.GetRemote();
|
---|
| 238 | }
|
---|
| 239 |
|
---|
| 240 | /* Cache USB filter data: */
|
---|
| 241 | m_cache.child(iFilterIndex).cacheInitialData(usbFilterData);
|
---|
[33631] | 242 | }
|
---|
| 243 | }
|
---|
[36936] | 244 |
|
---|
| 245 | /* Cache USB data: */
|
---|
| 246 | m_cache.cacheInitialData(usbData);
|
---|
| 247 |
|
---|
[33631] | 248 | break;
|
---|
| 249 | }
|
---|
| 250 | default:
|
---|
| 251 | break;
|
---|
[25177] | 252 | }
|
---|
| 253 |
|
---|
[33631] | 254 | /* Upload properties & settings or machine to data: */
|
---|
| 255 | uploadData(data);
|
---|
[25177] | 256 | }
|
---|
| 257 |
|
---|
[33631] | 258 | /* Load data to corresponding widgets from cache,
|
---|
| 259 | * this task SHOULD be performed in GUI thread only: */
|
---|
[33882] | 260 | void UIMachineSettingsUSB::getFromCache()
|
---|
[25177] | 261 | {
|
---|
[37051] | 262 | /* Clear list initially: */
|
---|
| 263 | mTwFilters->clear();
|
---|
| 264 | m_filters.clear();
|
---|
| 265 |
|
---|
[33631] | 266 | /* Depending on page type: */
|
---|
[36324] | 267 | switch (pageType())
|
---|
[25177] | 268 | {
|
---|
[33631] | 269 | case UISettingsPageType_Global:
|
---|
[25177] | 270 | {
|
---|
[36936] | 271 | /* Hide unused widgets: */
|
---|
[33631] | 272 | mGbUSB->setVisible(false);
|
---|
| 273 | mCbUSB2->setVisible(false);
|
---|
| 274 | break;
|
---|
[25177] | 275 | }
|
---|
[33631] | 276 | case UISettingsPageType_Machine:
|
---|
| 277 | {
|
---|
[36936] | 278 | /* Get USB data from cache: */
|
---|
| 279 | const UIDataSettingsMachineUSB &usbData = m_cache.base();
|
---|
| 280 | /* Load USB data to page: */
|
---|
| 281 | mGbUSB->setChecked(usbData.m_fUSBEnabled);
|
---|
| 282 | mCbUSB2->setChecked(usbData.m_fEHCIEnabled);
|
---|
[33631] | 283 | break;
|
---|
| 284 | }
|
---|
| 285 | default:
|
---|
| 286 | break;
|
---|
[25177] | 287 | }
|
---|
[36936] | 288 |
|
---|
| 289 | /* For each USB filter => load it to the page: */
|
---|
| 290 | for (int iFilterIndex = 0; iFilterIndex < m_cache.childCount(); ++iFilterIndex)
|
---|
| 291 | addUSBFilter(m_cache.child(iFilterIndex).base(), false /* its new? */);
|
---|
| 292 |
|
---|
[33631] | 293 | /* Choose first filter as current: */
|
---|
| 294 | mTwFilters->setCurrentItem(mTwFilters->topLevelItem(0));
|
---|
[25177] | 295 |
|
---|
[36936] | 296 | /* Update page: */
|
---|
| 297 | usbAdapterToggled(mGbUSB->isChecked());
|
---|
| 298 |
|
---|
[33631] | 299 | /* Revalidate if possible: */
|
---|
[36936] | 300 | if (mValidator)
|
---|
| 301 | mValidator->revalidate();
|
---|
[25177] | 302 | }
|
---|
| 303 |
|
---|
[33631] | 304 | /* Save data from corresponding widgets to cache,
|
---|
| 305 | * this task SHOULD be performed in GUI thread only: */
|
---|
[33882] | 306 | void UIMachineSettingsUSB::putToCache()
|
---|
[25177] | 307 | {
|
---|
[33631] | 308 | /* Depending on page type: */
|
---|
[36324] | 309 | switch (pageType())
|
---|
[25177] | 310 | {
|
---|
[33631] | 311 | case UISettingsPageType_Machine:
|
---|
| 312 | {
|
---|
[36936] | 313 | /* Prepare USB data: */
|
---|
| 314 | UIDataSettingsMachineUSB usbData = m_cache.base();
|
---|
| 315 |
|
---|
[36393] | 316 | /* USB 1.0 (OHCI): */
|
---|
[36936] | 317 | usbData.m_fUSBEnabled = mGbUSB->isChecked();
|
---|
[36393] | 318 | /* USB 2.0 (EHCI): */
|
---|
| 319 | QString strExtPackName = "Oracle VM VirtualBox Extension Pack";
|
---|
| 320 | CExtPack extPack = vboxGlobal().virtualBox().GetExtensionPackManager().Find(strExtPackName);
|
---|
[36936] | 321 | usbData.m_fEHCIEnabled = extPack.isNull() || !extPack.GetUsable() ? false : mCbUSB2->isChecked();
|
---|
| 322 |
|
---|
| 323 | /* Update USB cache: */
|
---|
| 324 | m_cache.cacheCurrentData(usbData);
|
---|
| 325 |
|
---|
[33631] | 326 | break;
|
---|
| 327 | }
|
---|
| 328 | default:
|
---|
| 329 | break;
|
---|
[25177] | 330 | }
|
---|
[36936] | 331 |
|
---|
| 332 | /* For each USB filter => recache USB filter data: */
|
---|
| 333 | for (int iFilterIndex = 0; iFilterIndex < m_filters.size(); ++iFilterIndex)
|
---|
| 334 | m_cache.child(iFilterIndex).cacheCurrentData(m_filters[iFilterIndex]);
|
---|
[25177] | 335 | }
|
---|
| 336 |
|
---|
[33631] | 337 | /* Save data from cache to corresponding external object(s),
|
---|
| 338 | * this task COULD be performed in other than GUI thread: */
|
---|
[33882] | 339 | void UIMachineSettingsUSB::saveFromCacheTo(QVariant &data)
|
---|
[25177] | 340 | {
|
---|
[33631] | 341 | /* Fetch data to properties & settings or machine: */
|
---|
| 342 | fetchData(data);
|
---|
| 343 |
|
---|
[36357] | 344 | /* Save settings depending on page type: */
|
---|
[36324] | 345 | switch (pageType())
|
---|
[25177] | 346 | {
|
---|
[36357] | 347 | /* Here come the global USB properties: */
|
---|
[33631] | 348 | case UISettingsPageType_Global:
|
---|
[25177] | 349 | {
|
---|
[36936] | 350 | /* Check if USB data really changed: */
|
---|
| 351 | if (m_cache.wasChanged())
|
---|
[25177] | 352 | {
|
---|
[36936] | 353 | /* Store USB data: */
|
---|
| 354 | if (isMachineInValidMode())
|
---|
[33631] | 355 | {
|
---|
[36519] | 356 | /* Get host: */
|
---|
| 357 | CHost host = vboxGlobal().virtualBox().GetHost();
|
---|
[36936] | 358 | /* For each USB filter data set: */
|
---|
| 359 | for (int iFilterIndex = 0; iFilterIndex < m_cache.childCount(); ++iFilterIndex)
|
---|
[36357] | 360 | {
|
---|
[36936] | 361 | /* Check if USB filter data really changed: */
|
---|
| 362 | const UICacheSettingsMachineUSBFilter &usbFilterCache = m_cache.child(iFilterIndex);
|
---|
| 363 | if (usbFilterCache.wasChanged())
|
---|
| 364 | {
|
---|
| 365 | /* If filter was removed or updated: */
|
---|
| 366 | if (usbFilterCache.wasRemoved() || usbFilterCache.wasUpdated())
|
---|
| 367 | host.RemoveUSBDeviceFilter(iFilterIndex);
|
---|
| 368 | /* If filter was created or updated: */
|
---|
| 369 | if (usbFilterCache.wasCreated() || usbFilterCache.wasUpdated())
|
---|
| 370 | {
|
---|
| 371 | /* Get USB filter data from cache: */
|
---|
| 372 | const UIDataSettingsMachineUSBFilter &usbFilterData = usbFilterCache.data();
|
---|
| 373 |
|
---|
| 374 | /* Store USB filter data: */
|
---|
| 375 | CHostUSBDeviceFilter hostFilter = host.CreateUSBDeviceFilter(usbFilterData.m_strName);
|
---|
| 376 | hostFilter.SetActive(usbFilterData.m_fActive);
|
---|
| 377 | hostFilter.SetVendorId(usbFilterData.m_strVendorId);
|
---|
| 378 | hostFilter.SetProductId(usbFilterData.m_strProductId);
|
---|
| 379 | hostFilter.SetRevision(usbFilterData.m_strRevision);
|
---|
| 380 | hostFilter.SetManufacturer(usbFilterData.m_strManufacturer);
|
---|
| 381 | hostFilter.SetProduct(usbFilterData.m_strProduct);
|
---|
| 382 | hostFilter.SetSerialNumber(usbFilterData.m_strSerialNumber);
|
---|
| 383 | hostFilter.SetPort(usbFilterData.m_strPort);
|
---|
| 384 | hostFilter.SetRemote(usbFilterData.m_strRemote);
|
---|
| 385 | hostFilter.SetAction(usbFilterData.m_action);
|
---|
| 386 | host.InsertUSBDeviceFilter(iFilterIndex, hostFilter);
|
---|
| 387 | }
|
---|
| 388 | }
|
---|
[36357] | 389 | }
|
---|
[33631] | 390 | }
|
---|
[25177] | 391 | }
|
---|
[33631] | 392 | break;
|
---|
[25177] | 393 | }
|
---|
[36357] | 394 | /* Here come VM USB properties: */
|
---|
[33631] | 395 | case UISettingsPageType_Machine:
|
---|
| 396 | {
|
---|
[36936] | 397 | /* Check if USB data really changed: */
|
---|
| 398 | if (m_cache.wasChanged())
|
---|
[33631] | 399 | {
|
---|
[36936] | 400 | /* Check if controller is valid: */
|
---|
| 401 | CUSBController controller = m_machine.GetUSBController();
|
---|
| 402 | if (!controller.isNull())
|
---|
[33631] | 403 | {
|
---|
[36936] | 404 | /* Get USB data from cache: */
|
---|
| 405 | const UIDataSettingsMachineUSB &usbData = m_cache.data();
|
---|
| 406 | /* Store USB data: */
|
---|
| 407 | if (isMachineOffline())
|
---|
[33631] | 408 | {
|
---|
[36936] | 409 | controller.SetEnabled(usbData.m_fUSBEnabled);
|
---|
| 410 | controller.SetEnabledEhci(usbData.m_fEHCIEnabled);
|
---|
| 411 | }
|
---|
| 412 | /* Store USB filters data: */
|
---|
| 413 | if (isMachineInValidMode())
|
---|
| 414 | {
|
---|
| 415 | /* For each USB filter data set: */
|
---|
| 416 | int iOperationPosition = 0;
|
---|
| 417 | for (int iFilterIndex = 0; iFilterIndex < m_cache.childCount(); ++iFilterIndex)
|
---|
[36357] | 418 | {
|
---|
[36936] | 419 | /* Check if USB filter data really changed: */
|
---|
| 420 | const UICacheSettingsMachineUSBFilter &usbFilterCache = m_cache.child(iFilterIndex);
|
---|
| 421 | if (usbFilterCache.wasChanged())
|
---|
| 422 | {
|
---|
| 423 | /* If filter was removed or updated: */
|
---|
| 424 | if (usbFilterCache.wasRemoved() || usbFilterCache.wasUpdated())
|
---|
| 425 | {
|
---|
| 426 | controller.RemoveDeviceFilter(iOperationPosition);
|
---|
| 427 | if (usbFilterCache.wasRemoved())
|
---|
| 428 | --iOperationPosition;
|
---|
| 429 | }
|
---|
| 430 |
|
---|
| 431 | /* If filter was created or updated: */
|
---|
| 432 | if (usbFilterCache.wasCreated() || usbFilterCache.wasUpdated())
|
---|
| 433 | {
|
---|
| 434 | /* Get USB filter data from cache: */
|
---|
| 435 | const UIDataSettingsMachineUSBFilter &usbFilterData = usbFilterCache.data();
|
---|
| 436 | /* Store USB filter data: */
|
---|
| 437 | CUSBDeviceFilter filter = controller.CreateDeviceFilter(usbFilterData.m_strName);
|
---|
| 438 | filter.SetActive(usbFilterData.m_fActive);
|
---|
| 439 | filter.SetVendorId(usbFilterData.m_strVendorId);
|
---|
| 440 | filter.SetProductId(usbFilterData.m_strProductId);
|
---|
| 441 | filter.SetRevision(usbFilterData.m_strRevision);
|
---|
| 442 | filter.SetManufacturer(usbFilterData.m_strManufacturer);
|
---|
| 443 | filter.SetProduct(usbFilterData.m_strProduct);
|
---|
| 444 | filter.SetSerialNumber(usbFilterData.m_strSerialNumber);
|
---|
| 445 | filter.SetPort(usbFilterData.m_strPort);
|
---|
| 446 | filter.SetRemote(usbFilterData.m_strRemote);
|
---|
| 447 | controller.InsertDeviceFilter(iOperationPosition, filter);
|
---|
| 448 | }
|
---|
| 449 | }
|
---|
| 450 |
|
---|
| 451 | /* Advance operation position: */
|
---|
| 452 | ++iOperationPosition;
|
---|
[36357] | 453 | }
|
---|
| 454 | }
|
---|
[33631] | 455 | }
|
---|
| 456 | }
|
---|
| 457 | break;
|
---|
| 458 | }
|
---|
| 459 | default:
|
---|
| 460 | break;
|
---|
[25177] | 461 | }
|
---|
[33631] | 462 |
|
---|
| 463 | /* Upload properties & settings or machine to data: */
|
---|
| 464 | uploadData(data);
|
---|
[25177] | 465 | }
|
---|
| 466 |
|
---|
[33882] | 467 | void UIMachineSettingsUSB::setValidator (QIWidgetValidator *aVal)
|
---|
[25177] | 468 | {
|
---|
| 469 | mValidator = aVal;
|
---|
[28939] | 470 | connect (mGbUSB, SIGNAL (stateChanged (int)), mValidator, SLOT (revalidate()));
|
---|
[36393] | 471 | connect(mCbUSB2, SIGNAL(stateChanged(int)), mValidator, SLOT(revalidate()));
|
---|
[25177] | 472 | }
|
---|
| 473 |
|
---|
[36393] | 474 | bool UIMachineSettingsUSB::revalidate(QString &strWarningText, QString& /* strTitle */)
|
---|
| 475 | {
|
---|
| 476 | /* USB 2.0 Extension Pack presence test: */
|
---|
| 477 | QString strExtPackName = "Oracle VM VirtualBox Extension Pack";
|
---|
| 478 | CExtPack extPack = vboxGlobal().virtualBox().GetExtensionPackManager().Find(strExtPackName);
|
---|
[36394] | 479 | if (mCbUSB2->isChecked() && (extPack.isNull() || !extPack.GetUsable()))
|
---|
[36393] | 480 | {
|
---|
| 481 | strWarningText = tr("USB 2.0 is currently enabled for this virtual machine. "
|
---|
| 482 | "However this requires the <b>%1</b> to be installed. "
|
---|
| 483 | "Please install the Extension Pack from the VirtualBox download site. "
|
---|
| 484 | "After this you will be able to re-enable USB 2.0. "
|
---|
| 485 | "It will be disabled in the meantime unless you cancel the current settings changes.")
|
---|
| 486 | .arg(strExtPackName);
|
---|
| 487 | vboxProblem().remindAboutUnsupportedUSB2(strExtPackName, this);
|
---|
| 488 | return true;
|
---|
| 489 | }
|
---|
| 490 | return true;
|
---|
| 491 | }
|
---|
| 492 |
|
---|
[33882] | 493 | void UIMachineSettingsUSB::setOrderAfter (QWidget *aWidget)
|
---|
[25177] | 494 | {
|
---|
| 495 | setTabOrder (aWidget, mGbUSB);
|
---|
| 496 | setTabOrder (mGbUSB, mCbUSB2);
|
---|
| 497 | setTabOrder (mCbUSB2, mTwFilters);
|
---|
| 498 | }
|
---|
| 499 |
|
---|
[33882] | 500 | void UIMachineSettingsUSB::retranslateUi()
|
---|
[25177] | 501 | {
|
---|
| 502 | /* Translate uic generated strings */
|
---|
[33882] | 503 | Ui::UIMachineSettingsUSB::retranslateUi (this);
|
---|
[25177] | 504 |
|
---|
| 505 | mNewAction->setText (tr ("&Add Empty Filter"));
|
---|
| 506 | mAddAction->setText (tr ("A&dd Filter From Device"));
|
---|
| 507 | mEdtAction->setText (tr ("&Edit Filter"));
|
---|
| 508 | mDelAction->setText (tr ("&Remove Filter"));
|
---|
| 509 | mMupAction->setText (tr ("&Move Filter Up"));
|
---|
| 510 | mMdnAction->setText (tr ("M&ove Filter Down"));
|
---|
| 511 |
|
---|
| 512 | mNewAction->setToolTip (mNewAction->text().remove ('&') +
|
---|
| 513 | QString (" (%1)").arg (mNewAction->shortcut().toString()));
|
---|
| 514 | mAddAction->setToolTip (mAddAction->text().remove ('&') +
|
---|
| 515 | QString (" (%1)").arg (mAddAction->shortcut().toString()));
|
---|
| 516 | mEdtAction->setToolTip (mEdtAction->text().remove ('&') +
|
---|
| 517 | QString (" (%1)").arg (mEdtAction->shortcut().toString()));
|
---|
| 518 | mDelAction->setToolTip (mDelAction->text().remove ('&') +
|
---|
| 519 | QString (" (%1)").arg (mDelAction->shortcut().toString()));
|
---|
| 520 | mMupAction->setToolTip (mMupAction->text().remove ('&') +
|
---|
| 521 | QString (" (%1)").arg (mMupAction->shortcut().toString()));
|
---|
| 522 | mMdnAction->setToolTip (mMdnAction->text().remove ('&') +
|
---|
| 523 | QString (" (%1)").arg (mMdnAction->shortcut().toString()));
|
---|
| 524 |
|
---|
| 525 | mNewAction->setWhatsThis (tr ("Adds a new USB filter with all fields "
|
---|
| 526 | "initially set to empty strings. Note "
|
---|
| 527 | "that such a filter will match any "
|
---|
| 528 | "attached USB device."));
|
---|
| 529 | mAddAction->setWhatsThis (tr ("Adds a new USB filter with all fields "
|
---|
| 530 | "set to the values of the selected USB "
|
---|
| 531 | "device attached to the host PC."));
|
---|
| 532 | mEdtAction->setWhatsThis (tr ("Edits the selected USB filter."));
|
---|
| 533 | mDelAction->setWhatsThis (tr ("Removes the selected USB filter."));
|
---|
| 534 | mMupAction->setWhatsThis (tr ("Moves the selected USB filter up."));
|
---|
| 535 | mMdnAction->setWhatsThis (tr ("Moves the selected USB filter down."));
|
---|
| 536 |
|
---|
| 537 | mUSBFilterName = tr ("New Filter %1", "usb");
|
---|
| 538 | }
|
---|
| 539 |
|
---|
[36936] | 540 | void UIMachineSettingsUSB::usbAdapterToggled(bool fEnabled)
|
---|
[25177] | 541 | {
|
---|
[36936] | 542 | /* Enable/disable USB children: */
|
---|
| 543 | mUSBChild->setEnabled(fEnabled);
|
---|
| 544 | if (fEnabled)
|
---|
| 545 | {
|
---|
| 546 | /* If there is no chosen item but there is something to choose => choose it: */
|
---|
| 547 | if (mTwFilters->currentItem() == 0 && mTwFilters->topLevelItemCount() != 0)
|
---|
| 548 | mTwFilters->setCurrentItem(mTwFilters->topLevelItem(0));
|
---|
| 549 | }
|
---|
| 550 | /* Update current item: */
|
---|
| 551 | currentChanged(mTwFilters->currentItem());
|
---|
[25177] | 552 | }
|
---|
| 553 |
|
---|
[36357] | 554 | void UIMachineSettingsUSB::currentChanged(QTreeWidgetItem *aItem)
|
---|
[25177] | 555 | {
|
---|
[36936] | 556 | /* Get selected items: */
|
---|
| 557 | QList<QTreeWidgetItem*> selectedItems = mTwFilters->selectedItems();
|
---|
| 558 | /* Deselect all selected items first: */
|
---|
| 559 | for (int iItemIndex = 0; iItemIndex < selectedItems.size(); ++iItemIndex)
|
---|
| 560 | selectedItems[iItemIndex]->setSelected(false);
|
---|
[25177] | 561 |
|
---|
[36936] | 562 | /* If tree-widget is NOT enabled => we should NOT select anything: */
|
---|
| 563 | if (!mTwFilters->isEnabled())
|
---|
| 564 | return;
|
---|
| 565 |
|
---|
| 566 | /* Select item if requested: */
|
---|
| 567 | if (aItem)
|
---|
| 568 | aItem->setSelected(true);
|
---|
| 569 |
|
---|
[36357] | 570 | /* Update corresponding action states: */
|
---|
| 571 | mEdtAction->setEnabled(aItem);
|
---|
| 572 | mDelAction->setEnabled(aItem);
|
---|
| 573 | mMupAction->setEnabled(aItem && mTwFilters->itemAbove(aItem));
|
---|
| 574 | mMdnAction->setEnabled(aItem && mTwFilters->itemBelow(aItem));
|
---|
[25177] | 575 | }
|
---|
| 576 |
|
---|
[33882] | 577 | void UIMachineSettingsUSB::newClicked()
|
---|
[25177] | 578 | {
|
---|
[36936] | 579 | /* Search for the max available filter index: */
|
---|
| 580 | int iMaxFilterIndex = 0;
|
---|
| 581 | QRegExp regExp(QString("^") + mUSBFilterName.arg("([0-9]+)") + QString("$"));
|
---|
| 582 | QTreeWidgetItemIterator iterator(mTwFilters);
|
---|
[25177] | 583 | while (*iterator)
|
---|
| 584 | {
|
---|
[36936] | 585 | QString filterName = (*iterator)->text(0);
|
---|
| 586 | int pos = regExp.indexIn(filterName);
|
---|
[25177] | 587 | if (pos != -1)
|
---|
[36936] | 588 | iMaxFilterIndex = regExp.cap(1).toInt() > iMaxFilterIndex ?
|
---|
| 589 | regExp.cap(1).toInt() : iMaxFilterIndex;
|
---|
| 590 | ++iterator;
|
---|
[25177] | 591 | }
|
---|
| 592 |
|
---|
[36936] | 593 | /* Prepare new USB filter data: */
|
---|
| 594 | UIDataSettingsMachineUSBFilter usbFilterData;
|
---|
[36324] | 595 | switch (pageType())
|
---|
[25177] | 596 | {
|
---|
[33631] | 597 | case UISettingsPageType_Global:
|
---|
[36936] | 598 | usbFilterData.m_action = KUSBDeviceFilterAction_Hold;
|
---|
[33631] | 599 | break;
|
---|
| 600 | default:
|
---|
| 601 | break;
|
---|
[25177] | 602 | }
|
---|
[36936] | 603 | usbFilterData.m_fActive = true;
|
---|
| 604 | usbFilterData.m_strName = mUSBFilterName.arg(iMaxFilterIndex + 1);
|
---|
| 605 | usbFilterData.m_fHostUSBDevice = false;
|
---|
[25177] | 606 |
|
---|
[36936] | 607 | /* Add new USB filter data: */
|
---|
| 608 | addUSBFilter(usbFilterData, true /* its new? */);
|
---|
| 609 |
|
---|
[33631] | 610 | /* Revalidate if possible: */
|
---|
| 611 | if (mValidator)
|
---|
| 612 | mValidator->revalidate();
|
---|
[25177] | 613 | }
|
---|
| 614 |
|
---|
[33882] | 615 | void UIMachineSettingsUSB::addClicked()
|
---|
[25177] | 616 | {
|
---|
[36936] | 617 | mUSBDevicesMenu->exec(QCursor::pos());
|
---|
[25177] | 618 | }
|
---|
| 619 |
|
---|
[36936] | 620 | void UIMachineSettingsUSB::addConfirmed(QAction *pAction)
|
---|
[25177] | 621 | {
|
---|
[33631] | 622 | /* Get USB device: */
|
---|
[36936] | 623 | CUSBDevice usb = mUSBDevicesMenu->getUSB(pAction);
|
---|
[25177] | 624 | if (usb.isNull())
|
---|
| 625 | return;
|
---|
| 626 |
|
---|
[36936] | 627 | /* Prepare new USB filter data: */
|
---|
| 628 | UIDataSettingsMachineUSBFilter usbFilterData;
|
---|
[36324] | 629 | switch (pageType())
|
---|
[25177] | 630 | {
|
---|
[33631] | 631 | case UISettingsPageType_Global:
|
---|
[36936] | 632 | usbFilterData.m_action = KUSBDeviceFilterAction_Hold;
|
---|
[33631] | 633 | break;
|
---|
| 634 | default:
|
---|
| 635 | break;
|
---|
[25177] | 636 | }
|
---|
[36936] | 637 | usbFilterData.m_fActive = true;
|
---|
| 638 | usbFilterData.m_strName = vboxGlobal().details(usb);
|
---|
| 639 | usbFilterData.m_fHostUSBDevice = false;
|
---|
| 640 | usbFilterData.m_strVendorId = QString().sprintf("%04hX", usb.GetVendorId());
|
---|
| 641 | usbFilterData.m_strProductId = QString().sprintf("%04hX", usb.GetProductId());
|
---|
| 642 | usbFilterData.m_strRevision = QString().sprintf("%04hX", usb.GetRevision());
|
---|
[25177] | 643 | /* The port property depends on the host computer rather than on the USB
|
---|
| 644 | * device itself; for this reason only a few people will want to use it
|
---|
| 645 | * in the filter since the same device plugged into a different socket
|
---|
| 646 | * will not match the filter in this case. */
|
---|
| 647 | #if 0
|
---|
[36936] | 648 | usbFilterData.m_strPort = QString().sprintf("%04hX", usb.GetPort());
|
---|
[25177] | 649 | #endif
|
---|
[36936] | 650 | usbFilterData.m_strManufacturer = usb.GetManufacturer();
|
---|
| 651 | usbFilterData.m_strProduct = usb.GetProduct();
|
---|
| 652 | usbFilterData.m_strSerialNumber = usb.GetSerialNumber();
|
---|
| 653 | usbFilterData.m_strRemote = QString::number(usb.GetRemote());
|
---|
[25177] | 654 |
|
---|
[36936] | 655 | /* Add new USB filter data: */
|
---|
| 656 | addUSBFilter(usbFilterData, true /* its new? */);
|
---|
| 657 |
|
---|
[33631] | 658 | /* Revalidate if possible: */
|
---|
| 659 | if (mValidator)
|
---|
| 660 | mValidator->revalidate();
|
---|
[25177] | 661 | }
|
---|
| 662 |
|
---|
[33882] | 663 | void UIMachineSettingsUSB::edtClicked()
|
---|
[25177] | 664 | {
|
---|
[33631] | 665 | /* Get current USB filter item: */
|
---|
| 666 | QTreeWidgetItem *pItem = mTwFilters->currentItem();
|
---|
| 667 | Assert(pItem);
|
---|
[36936] | 668 | UIDataSettingsMachineUSBFilter &usbFilterData = m_filters[mTwFilters->indexOfTopLevelItem(pItem)];
|
---|
[25177] | 669 |
|
---|
[33631] | 670 | /* Configure USB filter details dialog: */
|
---|
[36324] | 671 | UIMachineSettingsUSBFilterDetails dlgFilterDetails(pageType(), this);
|
---|
[36936] | 672 | dlgFilterDetails.mLeName->setText(usbFilterData.m_strName);
|
---|
| 673 | dlgFilterDetails.mLeVendorID->setText(usbFilterData.m_strVendorId);
|
---|
| 674 | dlgFilterDetails.mLeProductID->setText(usbFilterData.m_strProductId);
|
---|
| 675 | dlgFilterDetails.mLeRevision->setText(usbFilterData.m_strRevision);
|
---|
| 676 | dlgFilterDetails.mLePort->setText(usbFilterData.m_strPort);
|
---|
| 677 | dlgFilterDetails.mLeManufacturer->setText(usbFilterData.m_strManufacturer);
|
---|
| 678 | dlgFilterDetails.mLeProduct->setText(usbFilterData.m_strProduct);
|
---|
| 679 | dlgFilterDetails.mLeSerialNo->setText(usbFilterData.m_strSerialNumber);
|
---|
[36324] | 680 | switch (pageType())
|
---|
[25177] | 681 | {
|
---|
[33631] | 682 | case UISettingsPageType_Global:
|
---|
[25177] | 683 | {
|
---|
[36936] | 684 | if (usbFilterData.m_action == KUSBDeviceFilterAction_Ignore)
|
---|
[33631] | 685 | dlgFilterDetails.mCbAction->setCurrentIndex(0);
|
---|
[36936] | 686 | else if (usbFilterData.m_action == KUSBDeviceFilterAction_Hold)
|
---|
[33631] | 687 | dlgFilterDetails.mCbAction->setCurrentIndex(1);
|
---|
[25177] | 688 | else
|
---|
[33631] | 689 | AssertMsgFailed(("Invalid USBDeviceFilterAction type"));
|
---|
[25177] | 690 | break;
|
---|
| 691 | }
|
---|
[33631] | 692 | case UISettingsPageType_Machine:
|
---|
[25177] | 693 | {
|
---|
[36936] | 694 | QString strRemote = usbFilterData.m_strRemote.toLower();
|
---|
[33631] | 695 | if (strRemote == "yes" || strRemote == "true" || strRemote == "1")
|
---|
| 696 | dlgFilterDetails.mCbRemote->setCurrentIndex(ModeOn);
|
---|
| 697 | else if (strRemote == "no" || strRemote == "false" || strRemote == "0")
|
---|
| 698 | dlgFilterDetails.mCbRemote->setCurrentIndex(ModeOff);
|
---|
[25177] | 699 | else
|
---|
[33631] | 700 | dlgFilterDetails.mCbRemote->setCurrentIndex(ModeAny);
|
---|
[25177] | 701 | break;
|
---|
| 702 | }
|
---|
| 703 | default:
|
---|
| 704 | break;
|
---|
| 705 | }
|
---|
| 706 |
|
---|
[33631] | 707 | /* Run USB filter details dialog: */
|
---|
| 708 | if (dlgFilterDetails.exec() == QDialog::Accepted)
|
---|
[25177] | 709 | {
|
---|
[36936] | 710 | usbFilterData.m_strName = dlgFilterDetails.mLeName->text().isEmpty() ? QString::null : dlgFilterDetails.mLeName->text();
|
---|
| 711 | usbFilterData.m_strVendorId = dlgFilterDetails.mLeVendorID->text().isEmpty() ? QString::null : dlgFilterDetails.mLeVendorID->text();
|
---|
| 712 | usbFilterData.m_strProductId = dlgFilterDetails.mLeProductID->text().isEmpty() ? QString::null : dlgFilterDetails.mLeProductID->text();
|
---|
| 713 | usbFilterData.m_strRevision = dlgFilterDetails.mLeRevision->text().isEmpty() ? QString::null : dlgFilterDetails.mLeRevision->text();
|
---|
| 714 | usbFilterData.m_strManufacturer = dlgFilterDetails.mLeManufacturer->text().isEmpty() ? QString::null : dlgFilterDetails.mLeManufacturer->text();
|
---|
| 715 | usbFilterData.m_strProduct = dlgFilterDetails.mLeProduct->text().isEmpty() ? QString::null : dlgFilterDetails.mLeProduct->text();
|
---|
| 716 | usbFilterData.m_strSerialNumber = dlgFilterDetails.mLeSerialNo->text().isEmpty() ? QString::null : dlgFilterDetails.mLeSerialNo->text();
|
---|
| 717 | usbFilterData.m_strPort = dlgFilterDetails.mLePort->text().isEmpty() ? QString::null : dlgFilterDetails.mLePort->text();
|
---|
[36324] | 718 | switch (pageType())
|
---|
[25177] | 719 | {
|
---|
[33631] | 720 | case UISettingsPageType_Global:
|
---|
| 721 | {
|
---|
[36936] | 722 | usbFilterData.m_action = vboxGlobal().toUSBDevFilterAction(dlgFilterDetails.mCbAction->currentText());
|
---|
[33631] | 723 | break;
|
---|
| 724 | }
|
---|
| 725 | case UISettingsPageType_Machine:
|
---|
| 726 | {
|
---|
| 727 | switch (dlgFilterDetails.mCbRemote->currentIndex())
|
---|
| 728 | {
|
---|
[36936] | 729 | case ModeAny: usbFilterData.m_strRemote = QString(); break;
|
---|
| 730 | case ModeOn: usbFilterData.m_strRemote = QString::number(1); break;
|
---|
| 731 | case ModeOff: usbFilterData.m_strRemote = QString::number(0); break;
|
---|
[33631] | 732 | default: AssertMsgFailed(("Invalid combo box index"));
|
---|
| 733 | }
|
---|
| 734 | break;
|
---|
| 735 | }
|
---|
| 736 | default:
|
---|
| 737 | break;
|
---|
[25177] | 738 | }
|
---|
[36936] | 739 | pItem->setText(0, usbFilterData.m_strName);
|
---|
| 740 | pItem->setToolTip(0, toolTipFor(usbFilterData));
|
---|
[25177] | 741 | }
|
---|
| 742 | }
|
---|
| 743 |
|
---|
[33882] | 744 | void UIMachineSettingsUSB::delClicked()
|
---|
[25177] | 745 | {
|
---|
[33631] | 746 | /* Get current USB filter item: */
|
---|
| 747 | QTreeWidgetItem *pItem = mTwFilters->currentItem();
|
---|
| 748 | Assert(pItem);
|
---|
[25177] | 749 |
|
---|
[33631] | 750 | /* Delete corresponding items: */
|
---|
[36936] | 751 | m_filters.removeAt(mTwFilters->indexOfTopLevelItem(pItem));
|
---|
[33631] | 752 | delete pItem;
|
---|
[25177] | 753 |
|
---|
[33631] | 754 | /* Update current item: */
|
---|
| 755 | currentChanged(mTwFilters->currentItem());
|
---|
| 756 | /* Revalidate if possible: */
|
---|
[25177] | 757 | if (!mTwFilters->topLevelItemCount())
|
---|
| 758 | {
|
---|
| 759 | if (mValidator)
|
---|
| 760 | {
|
---|
| 761 | mValidator->rescan();
|
---|
| 762 | mValidator->revalidate();
|
---|
| 763 | }
|
---|
| 764 | }
|
---|
| 765 | }
|
---|
| 766 |
|
---|
[33882] | 767 | void UIMachineSettingsUSB::mupClicked()
|
---|
[25177] | 768 | {
|
---|
| 769 | QTreeWidgetItem *item = mTwFilters->currentItem();
|
---|
| 770 | Assert (item);
|
---|
| 771 |
|
---|
| 772 | int index = mTwFilters->indexOfTopLevelItem (item);
|
---|
| 773 | QTreeWidgetItem *takenItem = mTwFilters->takeTopLevelItem (index);
|
---|
| 774 | Assert (item == takenItem);
|
---|
| 775 | mTwFilters->insertTopLevelItem (index - 1, takenItem);
|
---|
[36936] | 776 | m_filters.swap (index, index - 1);
|
---|
[25177] | 777 |
|
---|
| 778 | mTwFilters->setCurrentItem (takenItem);
|
---|
| 779 | }
|
---|
| 780 |
|
---|
[33882] | 781 | void UIMachineSettingsUSB::mdnClicked()
|
---|
[25177] | 782 | {
|
---|
| 783 | QTreeWidgetItem *item = mTwFilters->currentItem();
|
---|
| 784 | Assert (item);
|
---|
| 785 |
|
---|
| 786 | int index = mTwFilters->indexOfTopLevelItem (item);
|
---|
| 787 | QTreeWidgetItem *takenItem = mTwFilters->takeTopLevelItem (index);
|
---|
| 788 | Assert (item == takenItem);
|
---|
| 789 | mTwFilters->insertTopLevelItem (index + 1, takenItem);
|
---|
[36936] | 790 | m_filters.swap (index, index + 1);
|
---|
[25177] | 791 |
|
---|
| 792 | mTwFilters->setCurrentItem (takenItem);
|
---|
| 793 | }
|
---|
| 794 |
|
---|
[33882] | 795 | void UIMachineSettingsUSB::showContextMenu (const QPoint &aPos)
|
---|
[25177] | 796 | {
|
---|
| 797 | mMenu->exec (mTwFilters->mapToGlobal (aPos));
|
---|
| 798 | }
|
---|
| 799 |
|
---|
[33882] | 800 | void UIMachineSettingsUSB::sltUpdateActivityState(QTreeWidgetItem *pChangedItem)
|
---|
[33631] | 801 | {
|
---|
| 802 | /* Check changed USB filter item: */
|
---|
| 803 | Assert(pChangedItem);
|
---|
| 804 |
|
---|
| 805 | /* Delete corresponding items: */
|
---|
[36936] | 806 | UIDataSettingsMachineUSBFilter &data = m_filters[mTwFilters->indexOfTopLevelItem(pChangedItem)];
|
---|
[33631] | 807 | data.m_fActive = pChangedItem->checkState(0) == Qt::Checked;
|
---|
| 808 | }
|
---|
| 809 |
|
---|
[36936] | 810 | void UIMachineSettingsUSB::addUSBFilter(const UIDataSettingsMachineUSBFilter &usbFilterData, bool fIsNew)
|
---|
[25177] | 811 | {
|
---|
[36936] | 812 | /* Append internal list with data: */
|
---|
| 813 | m_filters << usbFilterData;
|
---|
[25177] | 814 |
|
---|
[33631] | 815 | /* Append tree-widget with item: */
|
---|
| 816 | QTreeWidgetItem *pItem = new QTreeWidgetItem;
|
---|
[36936] | 817 | pItem->setCheckState(0, usbFilterData.m_fActive ? Qt::Checked : Qt::Unchecked);
|
---|
| 818 | pItem->setText(0, usbFilterData.m_strName);
|
---|
| 819 | pItem->setToolTip(0, toolTipFor(usbFilterData));
|
---|
[33631] | 820 | mTwFilters->addTopLevelItem(pItem);
|
---|
[25177] | 821 |
|
---|
[33631] | 822 | /* Select this item if its new: */
|
---|
| 823 | if (fIsNew)
|
---|
| 824 | mTwFilters->setCurrentItem(pItem);
|
---|
| 825 | }
|
---|
[25177] | 826 |
|
---|
[36357] | 827 | /* Fetch data to m_properties & m_settings or m_machine & m_console: */
|
---|
[33882] | 828 | void UIMachineSettingsUSB::fetchData(const QVariant &data)
|
---|
[33631] | 829 | {
|
---|
[36324] | 830 | switch (pageType())
|
---|
[33631] | 831 | {
|
---|
| 832 | case UISettingsPageType_Global:
|
---|
| 833 | {
|
---|
| 834 | m_properties = data.value<UISettingsDataGlobal>().m_properties;
|
---|
| 835 | m_settings = data.value<UISettingsDataGlobal>().m_settings;
|
---|
| 836 | break;
|
---|
| 837 | }
|
---|
| 838 | case UISettingsPageType_Machine:
|
---|
| 839 | {
|
---|
| 840 | m_machine = data.value<UISettingsDataMachine>().m_machine;
|
---|
[36357] | 841 | m_console = data.value<UISettingsDataMachine>().m_console;
|
---|
[33631] | 842 | break;
|
---|
| 843 | }
|
---|
| 844 | default:
|
---|
| 845 | break;
|
---|
| 846 | }
|
---|
| 847 | }
|
---|
[25177] | 848 |
|
---|
[36357] | 849 | /* Upload m_properties & m_settings or m_machine & m_console to data: */
|
---|
[33882] | 850 | void UIMachineSettingsUSB::uploadData(QVariant &data) const
|
---|
[33631] | 851 | {
|
---|
[36324] | 852 | switch (pageType())
|
---|
[33631] | 853 | {
|
---|
| 854 | case UISettingsPageType_Global:
|
---|
| 855 | {
|
---|
| 856 | data = QVariant::fromValue(UISettingsDataGlobal(m_properties, m_settings));
|
---|
| 857 | break;
|
---|
| 858 | }
|
---|
| 859 | case UISettingsPageType_Machine:
|
---|
| 860 | {
|
---|
[36357] | 861 | data = QVariant::fromValue(UISettingsDataMachine(m_machine, m_console));
|
---|
[33631] | 862 | break;
|
---|
| 863 | }
|
---|
| 864 | default:
|
---|
| 865 | break;
|
---|
| 866 | }
|
---|
| 867 | }
|
---|
[25177] | 868 |
|
---|
[36936] | 869 | /* static */
|
---|
| 870 | QString UIMachineSettingsUSB::toolTipFor(const UIDataSettingsMachineUSBFilter &usbFilterData)
|
---|
[33631] | 871 | {
|
---|
| 872 | /* Prepare tool-tip: */
|
---|
| 873 | QString strToolTip;
|
---|
| 874 |
|
---|
[36936] | 875 | QString strVendorId = usbFilterData.m_strVendorId;
|
---|
[33631] | 876 | if (!strVendorId.isEmpty())
|
---|
| 877 | strToolTip += tr("<nobr>Vendor ID: %1</nobr>", "USB filter tooltip").arg(strVendorId);
|
---|
| 878 |
|
---|
[36936] | 879 | QString strProductId = usbFilterData.m_strProductId;
|
---|
[33631] | 880 | if (!strProductId.isEmpty())
|
---|
| 881 | strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>Product ID: %2</nobr>", "USB filter tooltip").arg(strProductId);
|
---|
| 882 |
|
---|
[36936] | 883 | QString strRevision = usbFilterData.m_strRevision;
|
---|
[33631] | 884 | if (!strRevision.isEmpty())
|
---|
| 885 | strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>Revision: %3</nobr>", "USB filter tooltip").arg(strRevision);
|
---|
| 886 |
|
---|
[36936] | 887 | QString strProduct = usbFilterData.m_strProduct;
|
---|
[33631] | 888 | if (!strProduct.isEmpty())
|
---|
| 889 | strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>Product: %4</nobr>", "USB filter tooltip").arg(strProduct);
|
---|
| 890 |
|
---|
[36936] | 891 | QString strManufacturer = usbFilterData.m_strManufacturer;
|
---|
[33631] | 892 | if (!strManufacturer.isEmpty())
|
---|
| 893 | strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>Manufacturer: %5</nobr>", "USB filter tooltip").arg(strManufacturer);
|
---|
| 894 |
|
---|
[36936] | 895 | QString strSerial = usbFilterData.m_strSerialNumber;
|
---|
[33631] | 896 | if (!strSerial.isEmpty())
|
---|
| 897 | strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>Serial No.: %1</nobr>", "USB filter tooltip").arg(strSerial);
|
---|
| 898 |
|
---|
[36936] | 899 | QString strPort = usbFilterData.m_strPort;
|
---|
[33631] | 900 | if (!strPort.isEmpty())
|
---|
| 901 | strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>Port: %1</nobr>", "USB filter tooltip").arg(strPort);
|
---|
| 902 |
|
---|
| 903 | /* Add the state field if it's a host USB device: */
|
---|
[36936] | 904 | if (usbFilterData.m_fHostUSBDevice)
|
---|
[33631] | 905 | {
|
---|
| 906 | strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>State: %1</nobr>", "USB filter tooltip")
|
---|
[36936] | 907 | .arg(vboxGlobal().toString(usbFilterData.m_hostUSBDeviceState));
|
---|
[33631] | 908 | }
|
---|
| 909 |
|
---|
| 910 | return strToolTip;
|
---|
[25177] | 911 | }
|
---|
| 912 |
|
---|
[36357] | 913 | void UIMachineSettingsUSB::polishPage()
|
---|
| 914 | {
|
---|
[36519] | 915 | mGbUSB->setEnabled(isMachineOffline());
|
---|
| 916 | mCbUSB2->setEnabled(isMachineOffline());
|
---|
| 917 | mGbUSBFilters->setEnabled(isMachineInValidMode());
|
---|
| 918 | mTwFilters->setEnabled(isMachineInValidMode());
|
---|
[36357] | 919 | }
|
---|
| 920 |
|
---|