Changeset 36936 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- May 3, 2011 1:56:14 PM (14 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/settings/machine
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsUSB.cpp
r36519 r36936 36 36 , mMupAction(0), mMdnAction(0) 37 37 , mMenu(0), mUSBDevicesMenu(0) 38 , mUSBFilterListModified(false)39 38 { 40 39 /* Apply UI decorations */ … … 139 138 #ifndef VBOX_WITH_EHCI 140 139 mCbUSB2->setHidden(true); 141 #endif 140 #endif /* VBOX_WITH_EHCI */ 142 141 } 143 142 … … 159 158 case UISettingsPageType_Global: 160 159 { 161 /* Fill internal variables with corresponding values: */ 162 m_cache.m_fUSBEnabled = false; 163 m_cache.m_fEHCIEnabled = false; 160 /* For each USB filter: */ 164 161 const CHostUSBDeviceFilterVector &filters = vboxGlobal().virtualBox().GetHost().GetUSBDeviceFilters(); 165 162 for (int iFilterIndex = 0; iFilterIndex < filters.size(); ++iFilterIndex) 166 163 { 164 /* Prepare USB filter data: */ 165 UIDataSettingsMachineUSBFilter usbFilterData; 166 167 /* Check if filter is valid: */ 167 168 const CHostUSBDeviceFilter &filter = filters[iFilterIndex]; 168 UIUSBFilterData data; 169 data.m_fActive = filter.GetActive(); 170 data.m_strName = filter.GetName(); 171 data.m_strVendorId = filter.GetVendorId(); 172 data.m_strProductId = filter.GetProductId(); 173 data.m_strRevision = filter.GetRevision(); 174 data.m_strManufacturer = filter.GetManufacturer(); 175 data.m_strProduct = filter.GetProduct(); 176 data.m_strSerialNumber = filter.GetSerialNumber(); 177 data.m_strPort = filter.GetPort(); 178 data.m_strRemote = filter.GetRemote(); 179 data.m_action = filter.GetAction(); 180 CHostUSBDevice hostUSBDevice(filter); 181 if (!hostUSBDevice.isNull()) 169 if (!filter.isNull()) 182 170 { 183 data.m_fHostUSBDevice = true; 184 data.m_hostUSBDeviceState = hostUSBDevice.GetState(); 171 usbFilterData.m_fActive = filter.GetActive(); 172 usbFilterData.m_strName = filter.GetName(); 173 usbFilterData.m_strVendorId = filter.GetVendorId(); 174 usbFilterData.m_strProductId = filter.GetProductId(); 175 usbFilterData.m_strRevision = filter.GetRevision(); 176 usbFilterData.m_strManufacturer = filter.GetManufacturer(); 177 usbFilterData.m_strProduct = filter.GetProduct(); 178 usbFilterData.m_strSerialNumber = filter.GetSerialNumber(); 179 usbFilterData.m_strPort = filter.GetPort(); 180 usbFilterData.m_strRemote = filter.GetRemote(); 181 usbFilterData.m_action = filter.GetAction(); 182 CHostUSBDevice hostUSBDevice(filter); 183 if (!hostUSBDevice.isNull()) 184 { 185 usbFilterData.m_fHostUSBDevice = true; 186 usbFilterData.m_hostUSBDeviceState = hostUSBDevice.GetState(); 187 } 188 else 189 { 190 usbFilterData.m_fHostUSBDevice = false; 191 usbFilterData.m_hostUSBDeviceState = KUSBDeviceState_NotSupported; 192 } 185 193 } 186 else 187 { 188 data.m_fHostUSBDevice = false; 189 data.m_hostUSBDeviceState = KUSBDeviceState_NotSupported; 190 } 191 m_cache.m_items << data; 194 195 /* Cache USB filter data: */ 196 m_cache.child(iFilterIndex).cacheInitialData(usbFilterData); 192 197 } 198 193 199 break; 194 200 } 195 201 case UISettingsPageType_Machine: 196 202 { 197 /* Initialize machine COM storage: */ 198 m_machine = data.value<UISettingsDataMachine>().m_machine; 199 /* Fill internal variables with corresponding values: */ 200 const CUSBController &ctl = m_machine.GetUSBController(); 201 bool fIsControllerAvailable = !ctl.isNull(); 202 m_cache.m_fUSBEnabled = fIsControllerAvailable && ctl.GetEnabled(); 203 m_cache.m_fEHCIEnabled = fIsControllerAvailable && ctl.GetEnabledEhci(); 204 if (fIsControllerAvailable) 203 /* Prepare USB data: */ 204 UIDataSettingsMachineUSB usbData; 205 206 /* Check if controller is valid: */ 207 const CUSBController &controller = m_machine.GetUSBController(); 208 if (!controller.isNull()) 205 209 { 206 const CUSBDeviceFilterVector &filters = ctl.GetDeviceFilters(); 210 /* Gather USB values: */ 211 usbData.m_fUSBEnabled = controller.GetEnabled(); 212 usbData.m_fEHCIEnabled = controller.GetEnabledEhci(); 213 214 /* For each USB filter: */ 215 const CUSBDeviceFilterVector &filters = controller.GetDeviceFilters(); 207 216 for (int iFilterIndex = 0; iFilterIndex < filters.size(); ++iFilterIndex) 208 217 { 218 /* Prepare USB filter data: */ 219 UIDataSettingsMachineUSBFilter usbFilterData; 220 221 /* Check if filter is valid: */ 209 222 const CUSBDeviceFilter &filter = filters[iFilterIndex]; 210 UIUSBFilterData data; 211 data.m_fActive = filter.GetActive(); 212 data.m_strName = filter.GetName(); 213 data.m_strVendorId = filter.GetVendorId(); 214 data.m_strProductId = filter.GetProductId(); 215 data.m_strRevision = filter.GetRevision(); 216 data.m_strManufacturer = filter.GetManufacturer(); 217 data.m_strProduct = filter.GetProduct(); 218 data.m_strSerialNumber = filter.GetSerialNumber(); 219 data.m_strPort = filter.GetPort(); 220 data.m_strRemote = filter.GetRemote(); 221 data.m_fHostUSBDevice = false; 222 m_cache.m_items << data; 223 if (!filter.isNull()) 224 { 225 usbFilterData.m_fActive = filter.GetActive(); 226 usbFilterData.m_strName = filter.GetName(); 227 usbFilterData.m_strVendorId = filter.GetVendorId(); 228 usbFilterData.m_strProductId = filter.GetProductId(); 229 usbFilterData.m_strRevision = filter.GetRevision(); 230 usbFilterData.m_strManufacturer = filter.GetManufacturer(); 231 usbFilterData.m_strProduct = filter.GetProduct(); 232 usbFilterData.m_strSerialNumber = filter.GetSerialNumber(); 233 usbFilterData.m_strPort = filter.GetPort(); 234 usbFilterData.m_strRemote = filter.GetRemote(); 235 } 236 237 /* Cache USB filter data: */ 238 m_cache.child(iFilterIndex).cacheInitialData(usbFilterData); 223 239 } 224 240 } 241 242 /* Cache USB data: */ 243 m_cache.cacheInitialData(usbData); 244 225 245 break; 226 246 } … … 242 262 case UISettingsPageType_Global: 243 263 { 244 /* Apply internal variables data to QWidget(s): */264 /* Hide unused widgets: */ 245 265 mGbUSB->setVisible(false); 246 266 mCbUSB2->setVisible(false); … … 249 269 case UISettingsPageType_Machine: 250 270 { 251 /* Apply internal variables data to QWidget(s): */ 252 mGbUSB->setChecked(m_cache.m_fUSBEnabled); 253 mCbUSB2->setChecked(m_cache.m_fEHCIEnabled); 254 usbAdapterToggled(mGbUSB->isChecked()); 271 /* Get USB data from cache: */ 272 const UIDataSettingsMachineUSB &usbData = m_cache.base(); 273 /* Load USB data to page: */ 274 mGbUSB->setChecked(usbData.m_fUSBEnabled); 275 mCbUSB2->setChecked(usbData.m_fEHCIEnabled); 255 276 break; 256 277 } … … 258 279 break; 259 280 } 260 /* Apply internal variables data to QWidget(s): */ 261 for (int iFilterIndex = 0; iFilterIndex < m_cache.m_items.size(); ++iFilterIndex) 262 addUSBFilter(m_cache.m_items[iFilterIndex], false /* its new? */); 281 282 /* For each USB filter => load it to the page: */ 283 for (int iFilterIndex = 0; iFilterIndex < m_cache.childCount(); ++iFilterIndex) 284 addUSBFilter(m_cache.child(iFilterIndex).base(), false /* its new? */); 285 263 286 /* Choose first filter as current: */ 264 287 mTwFilters->setCurrentItem(mTwFilters->topLevelItem(0)); 265 currentChanged(mTwFilters->currentItem()); 266 /* Mark dialog as not edited:*/267 mUSBFilterListModified = false;288 289 /* Update page: */ 290 usbAdapterToggled(mGbUSB->isChecked()); 268 291 269 292 /* Revalidate if possible: */ 270 if (mValidator) mValidator->revalidate(); 293 if (mValidator) 294 mValidator->revalidate(); 271 295 } 272 296 … … 280 304 case UISettingsPageType_Machine: 281 305 { 282 /* Gather internal variables data from QWidget(s): */ 306 /* Prepare USB data: */ 307 UIDataSettingsMachineUSB usbData = m_cache.base(); 308 283 309 /* USB 1.0 (OHCI): */ 284 m_cache.m_fUSBEnabled = mGbUSB->isChecked();310 usbData.m_fUSBEnabled = mGbUSB->isChecked(); 285 311 /* USB 2.0 (EHCI): */ 286 312 QString strExtPackName = "Oracle VM VirtualBox Extension Pack"; 287 313 CExtPack extPack = vboxGlobal().virtualBox().GetExtensionPackManager().Find(strExtPackName); 288 m_cache.m_fEHCIEnabled = extPack.isNull() || !extPack.GetUsable() ? false : mCbUSB2->isChecked(); 314 usbData.m_fEHCIEnabled = extPack.isNull() || !extPack.GetUsable() ? false : mCbUSB2->isChecked(); 315 316 /* Update USB cache: */ 317 m_cache.cacheCurrentData(usbData); 318 289 319 break; 290 320 } … … 292 322 break; 293 323 } 324 325 /* For each USB filter => recache USB filter data: */ 326 for (int iFilterIndex = 0; iFilterIndex < m_filters.size(); ++iFilterIndex) 327 m_cache.child(iFilterIndex).cacheCurrentData(m_filters[iFilterIndex]); 294 328 } 295 329 … … 307 341 case UISettingsPageType_Global: 308 342 { 309 if (isMachineInValidMode()) 343 /* Check if USB data really changed: */ 344 if (m_cache.wasChanged()) 310 345 { 311 /* Gather corresponding values from internal variables: */312 if ( mUSBFilterListModified)346 /* Store USB data: */ 347 if (isMachineInValidMode()) 313 348 { 314 349 /* Get host: */ 315 350 CHost host = vboxGlobal().virtualBox().GetHost(); 316 /* First, remove all old filters: */ 317 for (ulong count = host.GetUSBDeviceFilters().size(); count; --count) 318 host.RemoveUSBDeviceFilter(0); 319 /* Then add all new filters: */ 320 for (int iFilterIndex = 0; iFilterIndex < m_cache.m_items.size(); ++iFilterIndex) 351 /* For each USB filter data set: */ 352 for (int iFilterIndex = 0; iFilterIndex < m_cache.childCount(); ++iFilterIndex) 321 353 { 322 UIUSBFilterData data = m_cache.m_items[iFilterIndex]; 323 CHostUSBDeviceFilter hostFilter = host.CreateUSBDeviceFilter(data.m_strName); 324 hostFilter.SetActive(data.m_fActive); 325 hostFilter.SetVendorId(data.m_strVendorId); 326 hostFilter.SetProductId(data.m_strProductId); 327 hostFilter.SetRevision(data.m_strRevision); 328 hostFilter.SetManufacturer(data.m_strManufacturer); 329 hostFilter.SetProduct(data.m_strProduct); 330 hostFilter.SetSerialNumber(data.m_strSerialNumber); 331 hostFilter.SetPort(data.m_strPort); 332 hostFilter.SetRemote(data.m_strRemote); 333 hostFilter.SetAction(data.m_action); 334 host.InsertUSBDeviceFilter(host.GetUSBDeviceFilters().size(), hostFilter); 354 /* Check if USB filter data really changed: */ 355 const UICacheSettingsMachineUSBFilter &usbFilterCache = m_cache.child(iFilterIndex); 356 if (usbFilterCache.wasChanged()) 357 { 358 /* If filter was removed or updated: */ 359 if (usbFilterCache.wasRemoved() || usbFilterCache.wasUpdated()) 360 host.RemoveUSBDeviceFilter(iFilterIndex); 361 /* If filter was created or updated: */ 362 if (usbFilterCache.wasCreated() || usbFilterCache.wasUpdated()) 363 { 364 /* Get USB filter data from cache: */ 365 const UIDataSettingsMachineUSBFilter &usbFilterData = usbFilterCache.data(); 366 367 /* Store USB filter data: */ 368 CHostUSBDeviceFilter hostFilter = host.CreateUSBDeviceFilter(usbFilterData.m_strName); 369 hostFilter.SetActive(usbFilterData.m_fActive); 370 hostFilter.SetVendorId(usbFilterData.m_strVendorId); 371 hostFilter.SetProductId(usbFilterData.m_strProductId); 372 hostFilter.SetRevision(usbFilterData.m_strRevision); 373 hostFilter.SetManufacturer(usbFilterData.m_strManufacturer); 374 hostFilter.SetProduct(usbFilterData.m_strProduct); 375 hostFilter.SetSerialNumber(usbFilterData.m_strSerialNumber); 376 hostFilter.SetPort(usbFilterData.m_strPort); 377 hostFilter.SetRemote(usbFilterData.m_strRemote); 378 hostFilter.SetAction(usbFilterData.m_action); 379 host.InsertUSBDeviceFilter(iFilterIndex, hostFilter); 380 } 381 } 335 382 } 336 383 } … … 341 388 case UISettingsPageType_Machine: 342 389 { 343 /* Initialize machine COM storage: */ 344 m_machine = data.value<UISettingsDataMachine>().m_machine; 345 /* Get machine USB controller: */ 346 CUSBController ctl = m_machine.GetUSBController(); 347 /* Gather corresponding values from internal variables: */ 348 if (!ctl.isNull()) 390 /* Check if USB data really changed: */ 391 if (m_cache.wasChanged()) 349 392 { 350 if (isMachineOffline()) 393 /* Check if controller is valid: */ 394 CUSBController controller = m_machine.GetUSBController(); 395 if (!controller.isNull()) 351 396 { 352 ctl.SetEnabled(m_cache.m_fUSBEnabled); 353 ctl.SetEnabledEhci(m_cache.m_fEHCIEnabled); 354 } 355 if (isMachineInValidMode()) 356 { 357 if (mUSBFilterListModified) 397 /* Get USB data from cache: */ 398 const UIDataSettingsMachineUSB &usbData = m_cache.data(); 399 /* Store USB data: */ 400 if (isMachineOffline()) 358 401 { 359 /* First, remove all old filters: */ 360 for (ulong count = ctl.GetDeviceFilters().size(); count; --count) 361 ctl.RemoveDeviceFilter(0); 362 /* Then add all new filters: */ 363 for (int iFilterIndex = 0; iFilterIndex < m_cache.m_items.size(); ++iFilterIndex) 402 controller.SetEnabled(usbData.m_fUSBEnabled); 403 controller.SetEnabledEhci(usbData.m_fEHCIEnabled); 404 } 405 /* Store USB filters data: */ 406 if (isMachineInValidMode()) 407 { 408 /* For each USB filter data set: */ 409 int iOperationPosition = 0; 410 for (int iFilterIndex = 0; iFilterIndex < m_cache.childCount(); ++iFilterIndex) 364 411 { 365 const UIUSBFilterData &data = m_cache.m_items[iFilterIndex]; 366 CUSBDeviceFilter filter = ctl.CreateDeviceFilter(data.m_strName); 367 filter.SetActive(data.m_fActive); 368 filter.SetVendorId(data.m_strVendorId); 369 filter.SetProductId(data.m_strProductId); 370 filter.SetRevision(data.m_strRevision); 371 filter.SetManufacturer(data.m_strManufacturer); 372 filter.SetProduct(data.m_strProduct); 373 filter.SetSerialNumber(data.m_strSerialNumber); 374 filter.SetPort(data.m_strPort); 375 filter.SetRemote(data.m_strRemote); 376 ctl.InsertDeviceFilter(~0, filter); 412 /* Check if USB filter data really changed: */ 413 const UICacheSettingsMachineUSBFilter &usbFilterCache = m_cache.child(iFilterIndex); 414 if (usbFilterCache.wasChanged()) 415 { 416 /* If filter was removed or updated: */ 417 if (usbFilterCache.wasRemoved() || usbFilterCache.wasUpdated()) 418 { 419 controller.RemoveDeviceFilter(iOperationPosition); 420 if (usbFilterCache.wasRemoved()) 421 --iOperationPosition; 422 } 423 424 /* If filter was created or updated: */ 425 if (usbFilterCache.wasCreated() || usbFilterCache.wasUpdated()) 426 { 427 /* Get USB filter data from cache: */ 428 const UIDataSettingsMachineUSBFilter &usbFilterData = usbFilterCache.data(); 429 /* Store USB filter data: */ 430 CUSBDeviceFilter filter = controller.CreateDeviceFilter(usbFilterData.m_strName); 431 filter.SetActive(usbFilterData.m_fActive); 432 filter.SetVendorId(usbFilterData.m_strVendorId); 433 filter.SetProductId(usbFilterData.m_strProductId); 434 filter.SetRevision(usbFilterData.m_strRevision); 435 filter.SetManufacturer(usbFilterData.m_strManufacturer); 436 filter.SetProduct(usbFilterData.m_strProduct); 437 filter.SetSerialNumber(usbFilterData.m_strSerialNumber); 438 filter.SetPort(usbFilterData.m_strPort); 439 filter.SetRemote(usbFilterData.m_strRemote); 440 controller.InsertDeviceFilter(iOperationPosition, filter); 441 } 442 } 443 444 /* Advance operation position: */ 445 ++iOperationPosition; 377 446 } 378 447 } … … 462 531 } 463 532 464 void UIMachineSettingsUSB::usbAdapterToggled (bool aOn) 465 { 466 mGbUSBFilters->setEnabled (aOn); 533 void UIMachineSettingsUSB::usbAdapterToggled(bool fEnabled) 534 { 535 /* Enable/disable USB children: */ 536 mUSBChild->setEnabled(fEnabled); 537 if (fEnabled) 538 { 539 /* If there is no chosen item but there is something to choose => choose it: */ 540 if (mTwFilters->currentItem() == 0 && mTwFilters->topLevelItemCount() != 0) 541 mTwFilters->setCurrentItem(mTwFilters->topLevelItem(0)); 542 } 543 /* Update current item: */ 544 currentChanged(mTwFilters->currentItem()); 467 545 } 468 546 469 547 void UIMachineSettingsUSB::currentChanged(QTreeWidgetItem *aItem) 470 548 { 471 if (mTwFilters->isEnabled()) 472 { 473 /* Make sure only the current item selected (if present): */ 474 if (mTwFilters->selectedItems().count() != 1 || mTwFilters->selectedItems()[0] != aItem) 475 { 476 QList<QTreeWidgetItem*> list = mTwFilters->selectedItems(); 477 for (int i = 0; i < list.size(); ++i) 478 list[i]->setSelected(false); 479 if (aItem) 480 aItem->setSelected(true); 481 } 482 } 483 else 484 mTwFilters->setCurrentItem(0); 549 /* Get selected items: */ 550 QList<QTreeWidgetItem*> selectedItems = mTwFilters->selectedItems(); 551 /* Deselect all selected items first: */ 552 for (int iItemIndex = 0; iItemIndex < selectedItems.size(); ++iItemIndex) 553 selectedItems[iItemIndex]->setSelected(false); 554 555 /* If tree-widget is NOT enabled => we should NOT select anything: */ 556 if (!mTwFilters->isEnabled()) 557 return; 558 559 /* Select item if requested: */ 560 if (aItem) 561 aItem->setSelected(true); 485 562 486 563 /* Update corresponding action states: */ … … 493 570 void UIMachineSettingsUSB::newClicked() 494 571 { 495 /* Search for the max available filter index */496 int maxFilterIndex = 0;497 QRegExp regExp (QString ("^") + mUSBFilterName.arg ("([0-9]+)") + QString("$"));498 QTreeWidgetItemIterator iterator 572 /* Search for the max available filter index: */ 573 int iMaxFilterIndex = 0; 574 QRegExp regExp(QString("^") + mUSBFilterName.arg("([0-9]+)") + QString("$")); 575 QTreeWidgetItemIterator iterator(mTwFilters); 499 576 while (*iterator) 500 577 { 501 QString filterName = (*iterator)->text 502 int pos = regExp.indexIn 578 QString filterName = (*iterator)->text(0); 579 int pos = regExp.indexIn(filterName); 503 580 if (pos != -1) 504 maxFilterIndex = regExp.cap (1).toInt() > maxFilterIndex ?505 regExp.cap (1).toInt() : maxFilterIndex;506 ++ 507 } 508 509 /* Add new corresponding list item to the cache: */510 UI USBFilterData data;581 iMaxFilterIndex = regExp.cap(1).toInt() > iMaxFilterIndex ? 582 regExp.cap(1).toInt() : iMaxFilterIndex; 583 ++iterator; 584 } 585 586 /* Prepare new USB filter data: */ 587 UIDataSettingsMachineUSBFilter usbFilterData; 511 588 switch (pageType()) 512 589 { 513 590 case UISettingsPageType_Global: 514 data.m_action = KUSBDeviceFilterAction_Hold;591 usbFilterData.m_action = KUSBDeviceFilterAction_Hold; 515 592 break; 516 593 default: 517 594 break; 518 595 } 519 data.m_fActive = true; 520 data.m_strName = mUSBFilterName.arg(maxFilterIndex + 1); 521 data.m_fHostUSBDevice = false; 522 m_cache.m_items << data; 523 524 /* Add new corresponding tree-widget-item to the tree-widget: */ 525 addUSBFilter(data, true /* its new? */); 526 /* Mark filter's list as edited: */ 527 markSettingsChanged(); 596 usbFilterData.m_fActive = true; 597 usbFilterData.m_strName = mUSBFilterName.arg(iMaxFilterIndex + 1); 598 usbFilterData.m_fHostUSBDevice = false; 599 600 /* Add new USB filter data: */ 601 addUSBFilter(usbFilterData, true /* its new? */); 602 528 603 /* Revalidate if possible: */ 529 604 if (mValidator) … … 533 608 void UIMachineSettingsUSB::addClicked() 534 609 { 535 mUSBDevicesMenu->exec 536 } 537 538 void UIMachineSettingsUSB::addConfirmed (QAction *aAction)610 mUSBDevicesMenu->exec(QCursor::pos()); 611 } 612 613 void UIMachineSettingsUSB::addConfirmed(QAction *pAction) 539 614 { 540 615 /* Get USB device: */ 541 CUSBDevice usb = mUSBDevicesMenu->getUSB (aAction); 542 /* if null then some other item but a USB device is selected */ 616 CUSBDevice usb = mUSBDevicesMenu->getUSB(pAction); 543 617 if (usb.isNull()) 544 618 return; 545 619 546 /* Add new corresponding list item to the cache: */547 UI USBFilterData data;620 /* Prepare new USB filter data: */ 621 UIDataSettingsMachineUSBFilter usbFilterData; 548 622 switch (pageType()) 549 623 { 550 624 case UISettingsPageType_Global: 551 data.m_action = KUSBDeviceFilterAction_Hold; 552 /* Check that under host (global) USB settings if they will be enabled! */ 553 data.m_fHostUSBDevice = false; 554 break; 555 case UISettingsPageType_Machine: 556 data.m_fHostUSBDevice = false; 625 usbFilterData.m_action = KUSBDeviceFilterAction_Hold; 557 626 break; 558 627 default: 559 628 break; 560 629 } 561 data.m_fActive = true; 562 data.m_strName = vboxGlobal().details(usb); 563 data.m_strVendorId = QString().sprintf("%04hX", usb.GetVendorId()); 564 data.m_strProductId = QString().sprintf("%04hX", usb.GetProductId()); 565 data.m_strRevision = QString().sprintf("%04hX", usb.GetRevision()); 630 usbFilterData.m_fActive = true; 631 usbFilterData.m_strName = vboxGlobal().details(usb); 632 usbFilterData.m_fHostUSBDevice = false; 633 usbFilterData.m_strVendorId = QString().sprintf("%04hX", usb.GetVendorId()); 634 usbFilterData.m_strProductId = QString().sprintf("%04hX", usb.GetProductId()); 635 usbFilterData.m_strRevision = QString().sprintf("%04hX", usb.GetRevision()); 566 636 /* The port property depends on the host computer rather than on the USB 567 637 * device itself; for this reason only a few people will want to use it … … 569 639 * will not match the filter in this case. */ 570 640 #if 0 571 data.m_strPort = QString().sprintf("%04hX", usb.GetPort());641 usbFilterData.m_strPort = QString().sprintf("%04hX", usb.GetPort()); 572 642 #endif 573 data.m_strManufacturer = usb.GetManufacturer(); 574 data.m_strProduct = usb.GetProduct(); 575 data.m_strSerialNumber = usb.GetSerialNumber(); 576 data.m_strRemote = QString::number(usb.GetRemote()); 577 m_cache.m_items << data; 578 579 /* Add new corresponding tree-widget-item to the tree-widget: */ 580 addUSBFilter(data, true /* its new? */); 581 /* Mark filter's list as edited: */ 582 markSettingsChanged(); 643 usbFilterData.m_strManufacturer = usb.GetManufacturer(); 644 usbFilterData.m_strProduct = usb.GetProduct(); 645 usbFilterData.m_strSerialNumber = usb.GetSerialNumber(); 646 usbFilterData.m_strRemote = QString::number(usb.GetRemote()); 647 648 /* Add new USB filter data: */ 649 addUSBFilter(usbFilterData, true /* its new? */); 650 583 651 /* Revalidate if possible: */ 584 652 if (mValidator) … … 591 659 QTreeWidgetItem *pItem = mTwFilters->currentItem(); 592 660 Assert(pItem); 593 UI USBFilterData &data = m_cache.m_items[mTwFilters->indexOfTopLevelItem(pItem)];661 UIDataSettingsMachineUSBFilter &usbFilterData = m_filters[mTwFilters->indexOfTopLevelItem(pItem)]; 594 662 595 663 /* Configure USB filter details dialog: */ 596 664 UIMachineSettingsUSBFilterDetails dlgFilterDetails(pageType(), this); 597 dlgFilterDetails.mLeName->setText( data.m_strName);598 dlgFilterDetails.mLeVendorID->setText( data.m_strVendorId);599 dlgFilterDetails.mLeProductID->setText( data.m_strProductId);600 dlgFilterDetails.mLeRevision->setText( data.m_strRevision);601 dlgFilterDetails.mLePort->setText( data.m_strPort);602 dlgFilterDetails.mLeManufacturer->setText( data.m_strManufacturer);603 dlgFilterDetails.mLeProduct->setText( data.m_strProduct);604 dlgFilterDetails.mLeSerialNo->setText( data.m_strSerialNumber);665 dlgFilterDetails.mLeName->setText(usbFilterData.m_strName); 666 dlgFilterDetails.mLeVendorID->setText(usbFilterData.m_strVendorId); 667 dlgFilterDetails.mLeProductID->setText(usbFilterData.m_strProductId); 668 dlgFilterDetails.mLeRevision->setText(usbFilterData.m_strRevision); 669 dlgFilterDetails.mLePort->setText(usbFilterData.m_strPort); 670 dlgFilterDetails.mLeManufacturer->setText(usbFilterData.m_strManufacturer); 671 dlgFilterDetails.mLeProduct->setText(usbFilterData.m_strProduct); 672 dlgFilterDetails.mLeSerialNo->setText(usbFilterData.m_strSerialNumber); 605 673 switch (pageType()) 606 674 { 607 675 case UISettingsPageType_Global: 608 676 { 609 if ( data.m_action == KUSBDeviceFilterAction_Ignore)677 if (usbFilterData.m_action == KUSBDeviceFilterAction_Ignore) 610 678 dlgFilterDetails.mCbAction->setCurrentIndex(0); 611 else if ( data.m_action == KUSBDeviceFilterAction_Hold)679 else if (usbFilterData.m_action == KUSBDeviceFilterAction_Hold) 612 680 dlgFilterDetails.mCbAction->setCurrentIndex(1); 613 681 else … … 617 685 case UISettingsPageType_Machine: 618 686 { 619 QString strRemote = data.m_strRemote.toLower();687 QString strRemote = usbFilterData.m_strRemote.toLower(); 620 688 if (strRemote == "yes" || strRemote == "true" || strRemote == "1") 621 689 dlgFilterDetails.mCbRemote->setCurrentIndex(ModeOn); … … 633 701 if (dlgFilterDetails.exec() == QDialog::Accepted) 634 702 { 635 data.m_strName = dlgFilterDetails.mLeName->text().isEmpty() ? QString::null : dlgFilterDetails.mLeName->text();636 data.m_strVendorId = dlgFilterDetails.mLeVendorID->text().isEmpty() ? QString::null : dlgFilterDetails.mLeVendorID->text();637 data.m_strProductId = dlgFilterDetails.mLeProductID->text().isEmpty() ? QString::null : dlgFilterDetails.mLeProductID->text();638 data.m_strRevision = dlgFilterDetails.mLeRevision->text().isEmpty() ? QString::null : dlgFilterDetails.mLeRevision->text();639 data.m_strManufacturer = dlgFilterDetails.mLeManufacturer->text().isEmpty() ? QString::null : dlgFilterDetails.mLeManufacturer->text();640 data.m_strProduct = dlgFilterDetails.mLeProduct->text().isEmpty() ? QString::null : dlgFilterDetails.mLeProduct->text();641 data.m_strSerialNumber = dlgFilterDetails.mLeSerialNo->text().isEmpty() ? QString::null : dlgFilterDetails.mLeSerialNo->text();642 data.m_strPort = dlgFilterDetails.mLePort->text().isEmpty() ? QString::null : dlgFilterDetails.mLePort->text();703 usbFilterData.m_strName = dlgFilterDetails.mLeName->text().isEmpty() ? QString::null : dlgFilterDetails.mLeName->text(); 704 usbFilterData.m_strVendorId = dlgFilterDetails.mLeVendorID->text().isEmpty() ? QString::null : dlgFilterDetails.mLeVendorID->text(); 705 usbFilterData.m_strProductId = dlgFilterDetails.mLeProductID->text().isEmpty() ? QString::null : dlgFilterDetails.mLeProductID->text(); 706 usbFilterData.m_strRevision = dlgFilterDetails.mLeRevision->text().isEmpty() ? QString::null : dlgFilterDetails.mLeRevision->text(); 707 usbFilterData.m_strManufacturer = dlgFilterDetails.mLeManufacturer->text().isEmpty() ? QString::null : dlgFilterDetails.mLeManufacturer->text(); 708 usbFilterData.m_strProduct = dlgFilterDetails.mLeProduct->text().isEmpty() ? QString::null : dlgFilterDetails.mLeProduct->text(); 709 usbFilterData.m_strSerialNumber = dlgFilterDetails.mLeSerialNo->text().isEmpty() ? QString::null : dlgFilterDetails.mLeSerialNo->text(); 710 usbFilterData.m_strPort = dlgFilterDetails.mLePort->text().isEmpty() ? QString::null : dlgFilterDetails.mLePort->text(); 643 711 switch (pageType()) 644 712 { 645 713 case UISettingsPageType_Global: 646 714 { 647 data.m_action = vboxGlobal().toUSBDevFilterAction(dlgFilterDetails.mCbAction->currentText());715 usbFilterData.m_action = vboxGlobal().toUSBDevFilterAction(dlgFilterDetails.mCbAction->currentText()); 648 716 break; 649 717 } … … 652 720 switch (dlgFilterDetails.mCbRemote->currentIndex()) 653 721 { 654 case ModeAny: data.m_strRemote = QString(); break;655 case ModeOn: data.m_strRemote = QString::number(1); break;656 case ModeOff: data.m_strRemote = QString::number(0); break;722 case ModeAny: usbFilterData.m_strRemote = QString(); break; 723 case ModeOn: usbFilterData.m_strRemote = QString::number(1); break; 724 case ModeOff: usbFilterData.m_strRemote = QString::number(0); break; 657 725 default: AssertMsgFailed(("Invalid combo box index")); 658 726 } … … 662 730 break; 663 731 } 664 pItem->setText(0, data.m_strName); 665 pItem->setToolTip(0, toolTipFor(data)); 666 /* Mark filter's list as edited: */ 667 markSettingsChanged(); 732 pItem->setText(0, usbFilterData.m_strName); 733 pItem->setToolTip(0, toolTipFor(usbFilterData)); 668 734 } 669 735 } … … 676 742 677 743 /* Delete corresponding items: */ 678 m_ cache.m_items.removeAt(mTwFilters->indexOfTopLevelItem(pItem));744 m_filters.removeAt(mTwFilters->indexOfTopLevelItem(pItem)); 679 745 delete pItem; 680 746 681 747 /* Update current item: */ 682 748 currentChanged(mTwFilters->currentItem()); 683 /* Mark filter's list as edited: */684 markSettingsChanged();685 749 /* Revalidate if possible: */ 686 750 if (!mTwFilters->topLevelItemCount()) … … 703 767 Assert (item == takenItem); 704 768 mTwFilters->insertTopLevelItem (index - 1, takenItem); 705 m_ cache.m_items.swap (index, index - 1);769 m_filters.swap (index, index - 1); 706 770 707 771 mTwFilters->setCurrentItem (takenItem); 708 markSettingsChanged();709 772 } 710 773 … … 718 781 Assert (item == takenItem); 719 782 mTwFilters->insertTopLevelItem (index + 1, takenItem); 720 m_ cache.m_items.swap (index, index + 1);783 m_filters.swap (index, index + 1); 721 784 722 785 mTwFilters->setCurrentItem (takenItem); 723 markSettingsChanged();724 786 } 725 787 … … 735 797 736 798 /* Delete corresponding items: */ 737 UI USBFilterData &data = m_cache.m_items[mTwFilters->indexOfTopLevelItem(pChangedItem)];799 UIDataSettingsMachineUSBFilter &data = m_filters[mTwFilters->indexOfTopLevelItem(pChangedItem)]; 738 800 data.m_fActive = pChangedItem->checkState(0) == Qt::Checked; 739 740 markSettingsChanged(); 741 } 742 743 void UIMachineSettingsUSB::markSettingsChanged() 744 { 745 mUSBFilterListModified = true; 746 } 747 748 void UIMachineSettingsUSB::addUSBFilter(const UIUSBFilterData &data, bool fIsNew) 749 { 801 } 802 803 void UIMachineSettingsUSB::addUSBFilter(const UIDataSettingsMachineUSBFilter &usbFilterData, bool fIsNew) 804 { 805 /* Append internal list with data: */ 806 m_filters << usbFilterData; 807 750 808 /* Append tree-widget with item: */ 751 809 QTreeWidgetItem *pItem = new QTreeWidgetItem; 752 pItem->setCheckState(0, data.m_fActive ? Qt::Checked : Qt::Unchecked);753 pItem->setText(0, data.m_strName);754 pItem->setToolTip(0, toolTipFor( data));810 pItem->setCheckState(0, usbFilterData.m_fActive ? Qt::Checked : Qt::Unchecked); 811 pItem->setText(0, usbFilterData.m_strName); 812 pItem->setToolTip(0, toolTipFor(usbFilterData)); 755 813 mTwFilters->addTopLevelItem(pItem); 756 814 … … 802 860 } 803 861 804 /* static */ QString UIMachineSettingsUSB::toolTipFor(const UIUSBFilterData &data) 862 /* static */ 863 QString UIMachineSettingsUSB::toolTipFor(const UIDataSettingsMachineUSBFilter &usbFilterData) 805 864 { 806 865 /* Prepare tool-tip: */ 807 866 QString strToolTip; 808 867 809 QString strVendorId = data.m_strVendorId;868 QString strVendorId = usbFilterData.m_strVendorId; 810 869 if (!strVendorId.isEmpty()) 811 870 strToolTip += tr("<nobr>Vendor ID: %1</nobr>", "USB filter tooltip").arg(strVendorId); 812 871 813 QString strProductId = data.m_strProductId;872 QString strProductId = usbFilterData.m_strProductId; 814 873 if (!strProductId.isEmpty()) 815 874 strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>Product ID: %2</nobr>", "USB filter tooltip").arg(strProductId); 816 875 817 QString strRevision = data.m_strRevision;876 QString strRevision = usbFilterData.m_strRevision; 818 877 if (!strRevision.isEmpty()) 819 878 strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>Revision: %3</nobr>", "USB filter tooltip").arg(strRevision); 820 879 821 QString strProduct = data.m_strProduct;880 QString strProduct = usbFilterData.m_strProduct; 822 881 if (!strProduct.isEmpty()) 823 882 strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>Product: %4</nobr>", "USB filter tooltip").arg(strProduct); 824 883 825 QString strManufacturer = data.m_strManufacturer;884 QString strManufacturer = usbFilterData.m_strManufacturer; 826 885 if (!strManufacturer.isEmpty()) 827 886 strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>Manufacturer: %5</nobr>", "USB filter tooltip").arg(strManufacturer); 828 887 829 QString strSerial = data.m_strSerialNumber;888 QString strSerial = usbFilterData.m_strSerialNumber; 830 889 if (!strSerial.isEmpty()) 831 890 strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>Serial No.: %1</nobr>", "USB filter tooltip").arg(strSerial); 832 891 833 QString strPort = data.m_strPort;892 QString strPort = usbFilterData.m_strPort; 834 893 if (!strPort.isEmpty()) 835 894 strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>Port: %1</nobr>", "USB filter tooltip").arg(strPort); 836 895 837 896 /* Add the state field if it's a host USB device: */ 838 if ( data.m_fHostUSBDevice)897 if (usbFilterData.m_fHostUSBDevice) 839 898 { 840 899 strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>State: %1</nobr>", "USB filter tooltip") 841 .arg(vboxGlobal().toString( data.m_hostUSBDeviceState));900 .arg(vboxGlobal().toString(usbFilterData.m_hostUSBDeviceState)); 842 901 } 843 902 -
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsUSB.h
r36393 r36936 26 26 class VBoxUSBMenu; 27 27 28 /* Common settings / USB page / Filter data: */29 struct UI USBFilterData28 /* Common settings / USB page / USB filter data: */ 29 struct UIDataSettingsMachineUSBFilter 30 30 { 31 /* Common: */ 31 /* Default constructor: */ 32 UIDataSettingsMachineUSBFilter() 33 : m_fActive(false) 34 , m_strName(QString()) 35 , m_strVendorId(QString()) 36 , m_strProductId(QString()) 37 , m_strRevision(QString()) 38 , m_strManufacturer(QString()) 39 , m_strProduct(QString()) 40 , m_strSerialNumber(QString()) 41 , m_strPort(QString()) 42 , m_strRemote(QString()) 43 , m_action(KUSBDeviceFilterAction_Null) 44 , m_hostUSBDeviceState(KUSBDeviceState_NotSupported) {} 45 /* Functions: */ 46 bool equal(const UIDataSettingsMachineUSBFilter &other) const 47 { 48 return (m_fActive == other.m_fActive) && 49 (m_strName == other.m_strName) && 50 (m_strVendorId == other.m_strVendorId) && 51 (m_strProductId == other.m_strProductId) && 52 (m_strRevision == other.m_strRevision) && 53 (m_strManufacturer == other.m_strManufacturer) && 54 (m_strProduct == other.m_strProduct) && 55 (m_strSerialNumber == other.m_strSerialNumber) && 56 (m_strPort == other.m_strPort) && 57 (m_strRemote == other.m_strRemote) && 58 (m_action == other.m_action) && 59 (m_hostUSBDeviceState == other.m_hostUSBDeviceState); 60 } 61 /* Operators: */ 62 bool operator==(const UIDataSettingsMachineUSBFilter &other) const { return equal(other); } 63 bool operator!=(const UIDataSettingsMachineUSBFilter &other) const { return !equal(other); } 64 /* Common variables: */ 32 65 bool m_fActive; 33 66 QString m_strName; … … 40 73 QString m_strPort; 41 74 QString m_strRemote; 42 43 /* Host only: */ 75 /* Host only variables: */ 44 76 KUSBDeviceFilterAction m_action; 45 77 bool m_fHostUSBDevice; 46 78 KUSBDeviceState m_hostUSBDeviceState; 47 79 }; 48 49 /* Common settings / USB page / Cache: */ 50 struct UISettingsCacheCommonUSB 80 typedef UISettingsCache<UIDataSettingsMachineUSBFilter> UICacheSettingsMachineUSBFilter; 81 82 /* Common settings / USB page / USB data: */ 83 struct UIDataSettingsMachineUSB 51 84 { 85 /* Default constructor: */ 86 UIDataSettingsMachineUSB() 87 : m_fUSBEnabled(false) 88 , m_fEHCIEnabled(false) {} 89 /* Functions: */ 90 bool equal(const UIDataSettingsMachineUSB &other) const 91 { 92 return (m_fUSBEnabled == other.m_fUSBEnabled) && 93 (m_fEHCIEnabled == other.m_fEHCIEnabled); 94 } 95 /* Operators: */ 96 bool operator==(const UIDataSettingsMachineUSB &other) const { return equal(other); } 97 bool operator!=(const UIDataSettingsMachineUSB &other) const { return !equal(other); } 98 /* Variables: */ 52 99 bool m_fUSBEnabled; 53 100 bool m_fEHCIEnabled; 54 QList<UIUSBFilterData> m_items;55 101 }; 102 typedef UISettingsCachePool<UIDataSettingsMachineUSB, UICacheSettingsMachineUSBFilter> UICacheSettingsMachineUSB; 56 103 57 104 /* Common settings / USB page: */ … … 99 146 private slots: 100 147 101 void usbAdapterToggled (bool aOn);148 void usbAdapterToggled(bool fEnabled); 102 149 void currentChanged (QTreeWidgetItem *aItem = 0); 103 150 … … 111 158 void showContextMenu (const QPoint &aPos); 112 159 void sltUpdateActivityState(QTreeWidgetItem *pChangedItem); 113 void markSettingsChanged();114 160 115 161 private: 116 162 117 void addUSBFilter(const UI USBFilterData &data, bool fIsNew);163 void addUSBFilter(const UIDataSettingsMachineUSBFilter &usbFilterData, bool fIsNew); 118 164 119 165 /* Fetch data to m_properties, m_settings or m_machine: */ … … 124 170 125 171 /* Returns the multi-line description of the given USB filter: */ 126 static QString toolTipFor(const UI USBFilterData&data);172 static QString toolTipFor(const UIDataSettingsMachineUSBFilter &data); 127 173 128 174 void polishPage(); … … 146 192 QMenu *mMenu; 147 193 VBoxUSBMenu *mUSBDevicesMenu; 148 bool mUSBFilterListModified;149 194 QString mUSBFilterName; 195 QList<UIDataSettingsMachineUSBFilter> m_filters; 150 196 151 197 /* Cache: */ 152 UI SettingsCacheCommonUSB m_cache;198 UICacheSettingsMachineUSB m_cache; 153 199 }; 154 200 -
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsUSB.ui
r34561 r36936 140 140 </customwidgets> 141 141 <resources/> 142 <connections> 143 <connection> 144 <sender>mGbUSB</sender> 145 <signal>toggled(bool)</signal> 146 <receiver>mUSBChild</receiver> 147 <slot>setEnabled(bool)</slot> 148 <hints> 149 <hint type="sourcelabel" > 150 <x>233</x> 151 <y>19</y> 152 </hint> 153 <hint type="destinationlabel" > 154 <x>246</x> 155 <y>177</y> 156 </hint> 157 </hints> 158 </connection> 159 </connections> 142 <connections/> 160 143 </ui>
Note:
See TracChangeset
for help on using the changeset viewer.