- Timestamp:
- May 31, 2007 10:09:04 AM (18 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleWnd.cpp
r2931 r2957 1522 1522 { 1523 1523 case CEnums::HostDriveCaptured: 1524 { 1525 CHostFloppyDrive drv = floppy.GetHostDrive(); 1526 QString drvName = drv.GetName(); 1527 QString description = drv.GetDescription(); 1528 QString fullName = description.isEmpty() ? 1529 drvName : 1530 QString ("<nobr>%1 (%2)</nobr>").arg (description, drvName); 1524 1531 name = tr ("Host Drive ", "Floppy tooltip") + 1525 f loppy.GetHostDrive().GetName();1532 fullName; 1526 1533 break; 1534 } 1527 1535 case CEnums::ImageMounted: 1528 1536 name = floppy.GetImage().GetFilePath(); … … 2157 2165 CHostFloppyDrive hostFloppy = en.GetNext(); 2158 2166 /** @todo set icon */ 2167 QString drvName = hostFloppy.GetName(); 2168 QString description = hostFloppy.GetDescription(); 2169 QString fullName = description.isEmpty() ? 2170 drvName : 2171 QString ("%1 (%2)").arg (description, drvName); 2159 2172 int id = devicesMountFloppyMenu->insertItem ( 2160 tr ("Host Drive ") + hostFloppy.GetName() 2161 ); 2173 tr ("Host Drive ") + fullName); 2162 2174 hostFloppyMap [id] = hostFloppy; 2163 2175 if (machine_state != CEnums::Running) -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxGlobal.cpp
r2930 r2957 1136 1136 { 1137 1137 CHostFloppyDrive drv = floppy.GetHostDrive(); 1138 QString drvName = drv.GetName(); 1139 QString description = drv.GetDescription(); 1140 QString fullName = description.isEmpty() ? 1141 drvName : 1142 QString ("%1 (%2)").arg (description, drvName); 1138 1143 item = item.arg (tr ("Host Drive", "details report (floppy)"), 1139 drv.GetName());1144 fullName); 1140 1145 break; 1141 1146 } -
trunk/src/VBox/Frontends/VirtualBox/ui/VBoxVMSettingsDlg.ui.h
r2936 r2957 1364 1364 CHostFloppyDrive hostFloppy = en.GetNext(); 1365 1365 /** @todo set icon? */ 1366 cbHostFloppy->insertItem (hostFloppy.GetName(), id); 1366 QString name = hostFloppy.GetName(); 1367 QString description = hostFloppy.GetDescription(); 1368 QString fullName = description.isEmpty() ? 1369 name : 1370 QString ("%1 (%2)").arg (description, name); 1371 cbHostFloppy->insertItem (fullName, id); 1367 1372 hostFloppies [id] = hostFloppy; 1368 1373 ++ id; … … 1376 1381 CHostFloppyDrive drv = floppy.GetHostDrive(); 1377 1382 QString name = drv.GetName(); 1383 QString description = drv.GetDescription(); 1384 QString fullName = description.isEmpty() ? 1385 name : 1386 QString ("%1 (%2)").arg (description, name); 1378 1387 if (coll.FindByName (name).isNull()) 1379 1388 { … … 1382 1391 * add it to the end of the list with a special mark 1383 1392 */ 1384 cbHostFloppy->insertItem ("* " + name);1385 cbHostFloppy->setCurrentItem (cbHost Floppy->count() - 1);1393 cbHostFloppy->insertItem ("* " + fullName); 1394 cbHostFloppy->setCurrentItem (cbHostDVD->count() - 1); 1386 1395 } 1387 1396 else 1388 1397 { 1389 1398 /* this will select the correct item from the prepared list */ 1390 cbHostFloppy->setCurrentText ( name);1399 cbHostFloppy->setCurrentText (fullName); 1391 1400 } 1392 1401 rbHostFloppy->setChecked (true); -
trunk/src/VBox/Main/HostDVDDriveImpl.cpp
r2929 r2957 49 49 */ 50 50 HRESULT HostDVDDrive::init (INPTR BSTR aName, 51 INPTR BSTR aUdi /* = NULL */, 51 52 INPTR BSTR aDescription /* = NULL */) 52 53 { … … 58 59 59 60 unconst (mName) = aName; 61 unconst (mUdi) = aUdi; 60 62 unconst (mDescription) = aDescription; 61 63 … … 99 101 } 100 102 103 /** 104 * Returns a human readable description of the host drive 105 * 106 * @returns COM status code 107 * @param driveDescription address of result pointer 108 */ 101 109 STDMETHODIMP HostDVDDrive::COMGETTER(Description) (BSTR *aDescription) 102 110 { … … 113 121 return S_OK; 114 122 } 123 124 /** 125 * Returns the universal device identifier of the host drive 126 * 127 * @returns COM status code 128 * @param driveDescription address of result pointer 129 */ 130 STDMETHODIMP HostDVDDrive::COMGETTER(Udi) (BSTR *aUdi) 131 { 132 if (!aUdi) 133 return E_POINTER; 134 135 AutoCaller autoCaller (this); 136 CheckComRCReturnRC (autoCaller.rc()); 137 138 /* mDescription is constant during life time, no need to lock */ 139 140 mUdi.cloneTo (aUdi); 141 142 return S_OK; 143 } -
trunk/src/VBox/Main/HostFloppyDriveImpl.cpp
r2929 r2957 44 44 * 45 45 * @param aName Name of the drive. 46 * @param aDescription Human-readable drive description (may be NULL). 46 47 * 47 48 * @return COM result indicator. 48 49 */ 49 HRESULT HostFloppyDrive::init (INPTR BSTR aName) 50 HRESULT HostFloppyDrive::init (INPTR BSTR aName, 51 INPTR BSTR aUdi /* = NULL */, 52 INPTR BSTR aDescription /* = NULL */) 50 53 { 51 54 ComAssertRet (aName, E_INVALIDARG); … … 56 59 57 60 unconst (mName) = aName; 61 unconst (mUdi) = aUdi; 62 unconst (mDescription) = aDescription; 58 63 59 64 /* Confirm the successful initialization */ … … 62 67 return S_OK; 63 68 } 69 64 70 65 71 /** … … 94 100 return S_OK; 95 101 } 102 103 /** 104 * Returns a human readable description of the host drive 105 * 106 * @returns COM status code 107 * @param driveDescription address of result pointer 108 */ 109 STDMETHODIMP HostFloppyDrive::COMGETTER(Description) (BSTR *aDescription) 110 { 111 if (!aDescription) 112 return E_POINTER; 113 114 AutoCaller autoCaller (this); 115 CheckComRCReturnRC (autoCaller.rc()); 116 117 /* mDescription is constant during life time, no need to lock */ 118 119 mDescription.cloneTo (aDescription); 120 121 return S_OK; 122 } 123 124 /** 125 * Returns the universal device identifier of the host drive 126 * 127 * @returns COM status code 128 * @param driveDescription address of result pointer 129 */ 130 STDMETHODIMP HostFloppyDrive::COMGETTER(Udi) (BSTR *aUdi) 131 { 132 if (!aUdi) 133 return E_POINTER; 134 135 AutoCaller autoCaller (this); 136 CheckComRCReturnRC (autoCaller.rc()); 137 138 /* mDescription is constant during life time, no need to lock */ 139 140 mUdi.cloneTo (aUdi); 141 142 return S_OK; 143 } -
trunk/src/VBox/Main/HostImpl.cpp
r2939 r2957 304 304 delete[] hostDrives; 305 305 #elif defined(__LINUX__) 306 #ifdef VBOX_USE_LIBHAL 307 if (!getFloppyInfoFromHal(list)) /* Playing with #defines in this way is nasty, I know. */ 308 #endif /* USE_LIBHAL defined */ 306 309 // As with the CDROMs, on Linux we have to take a multi-level approach 307 310 // involving parsing the mount tables. As this is not bulletproof, we'll … … 309 312 // variable and skip the detection. 310 313 311 if (getenv("VBOX_FLOPPY")) 312 { 313 char *floppyEnv = getenv("VBOX_FLOPPY"); 314 char *floppyDrive; 315 floppyDrive = strtok(floppyEnv, ":"); 316 while (floppyDrive) 317 { 318 // check if this is an acceptable device 319 if (validateDevice(floppyDrive, false)) 314 { 315 if (getenv("VBOX_FLOPPY")) 316 { 317 char *floppyEnv = getenv("VBOX_FLOPPY"); 318 char *floppyDrive; 319 floppyDrive = strtok(floppyEnv, ":"); 320 while (floppyDrive) 320 321 { 321 ComObjPtr <HostFloppyDrive> hostFloppyDriveObj; 322 hostFloppyDriveObj.createObject(); 323 hostFloppyDriveObj->init (Bstr (floppyDrive)); 324 list.push_back (hostFloppyDriveObj); 322 // check if this is an acceptable device 323 if (validateDevice(floppyDrive, false)) 324 { 325 ComObjPtr <HostFloppyDrive> hostFloppyDriveObj; 326 hostFloppyDriveObj.createObject(); 327 hostFloppyDriveObj->init (Bstr (floppyDrive)); 328 list.push_back (hostFloppyDriveObj); 329 } 330 floppyDrive = strtok(NULL, ":"); 325 331 } 326 floppyDrive = strtok(NULL, ":"); 327 } 328 } 329 else 330 { 331 // we assume that a floppy is always /dev/fd[x] with x from 0 to 7 332 char devName[10]; 333 for (int i = 0; i <= 7; i++) 334 { 335 sprintf(devName, "/dev/fd%d", i); 336 if (validateDevice(devName, false)) 332 } 333 else 334 { 335 // we assume that a floppy is always /dev/fd[x] with x from 0 to 7 336 char devName[10]; 337 for (int i = 0; i <= 7; i++) 337 338 { 338 ComObjPtr <HostFloppyDrive> hostFloppyDriveObj; 339 hostFloppyDriveObj.createObject(); 340 hostFloppyDriveObj->init (Bstr (devName)); 341 list.push_back (hostFloppyDriveObj); 339 sprintf(devName, "/dev/fd%d", i); 340 if (validateDevice(devName, false)) 341 { 342 ComObjPtr <HostFloppyDrive> hostFloppyDriveObj; 343 hostFloppyDriveObj.createObject(); 344 hostFloppyDriveObj->init (Bstr (devName)); 345 list.push_back (hostFloppyDriveObj); 346 } 342 347 } 343 348 } … … 1411 1416 * system. 1412 1417 * 1413 * @returns true if at least one drive was found, false otherwise1418 * @returns true if information was successfully obtained, false otherwise 1414 1419 * @retval list drives found will be attached to this list 1415 1420 */ … … 1434 1439 if (halDevices != 0) 1435 1440 { 1441 /* Hal is installed and working, so if no devices are reported, assume 1442 that there are none. */ 1443 halSuccess = true; 1436 1444 for (int i = 0; i < numDevices; i++) 1437 1445 { … … 1444 1452 Utf8Str description; 1445 1453 char *vendor, *product; 1446 /* We have at least one hit, so operation successful :) */1447 halSuccess = true;1454 /* We do not check the error here, as this field may 1455 not even exist. */ 1448 1456 vendor = libhal_device_get_property_string(halContext, 1449 halDevices[i], "info.vendor", &dbusError);1457 halDevices[i], "info.vendor", 0); 1450 1458 product = libhal_device_get_property_string(halContext, 1451 1459 halDevices[i], "info.product", &dbusError); 1452 1460 if ((product != 0 && product[0] != 0)) 1453 1461 { 1454 if ( vendor != 0 && vendor[0] != 0)1462 if ((vendor != 0) && (vendor[0] != 0)) 1455 1463 { 1456 1464 description = Utf8StrFmt ("%s %s", … … 1463 1471 ComObjPtr <HostDVDDrive> hostDVDDriveObj; 1464 1472 hostDVDDriveObj.createObject(); 1465 hostDVDDriveObj->init (Bstr (devNode), Bstr (description)); 1473 hostDVDDriveObj->init (Bstr (devNode), 1474 Bstr (halDevices[i]), 1475 Bstr (description)); 1466 1476 list.push_back (hostDVDDriveObj); 1467 1477 } 1468 1478 else 1469 1479 { 1480 if (product == 0) 1481 { 1482 LogRel(("Host::COMGETTER(DVDDrives): failed to get property \"info.product\" for device %s. dbus error: %s (%s)\n", 1483 halDevices[i], dbusError.name, dbusError.message)); 1484 dbus_error_free(&dbusError); 1485 } 1470 1486 ComObjPtr <HostDVDDrive> hostDVDDriveObj; 1471 1487 hostDVDDriveObj.createObject(); 1472 hostDVDDriveObj->init (Bstr (devNode)); 1488 hostDVDDriveObj->init (Bstr (devNode), 1489 Bstr (halDevices[i])); 1473 1490 list.push_back (hostDVDDriveObj); 1491 } 1492 if (vendor != 0) 1493 { 1494 libhal_free_string(vendor); 1495 } 1496 if (product != 0) 1497 { 1498 libhal_free_string(product); 1474 1499 } 1475 1500 } … … 1521 1546 { 1522 1547 LogRel(("Host::COMGETTER(DVDDrives): failed to connect to dbus. dbus error: %s (%s)\n", dbusError.name, dbusError.message)); 1548 dbus_error_free(&dbusError); 1549 } 1550 return halSuccess; 1551 } 1552 1553 1554 /** 1555 * Helper function to query the hal subsystem for information about floppy drives attached to the 1556 * system. 1557 * 1558 * @returns true if information was successfully obtained, false otherwise 1559 * @retval list drives found will be attached to this list 1560 */ 1561 bool Host::getFloppyInfoFromHal(std::list <ComObjPtr <HostFloppyDrive> > &list) 1562 { 1563 bool halSuccess = false; 1564 DBusError dbusError; 1565 dbus_error_init (&dbusError); 1566 DBusConnection *dbusConnection = dbus_bus_get(DBUS_BUS_SYSTEM, &dbusError); 1567 if (dbusConnection != 0) 1568 { 1569 LibHalContext *halContext = libhal_ctx_new(); 1570 if (halContext != 0) 1571 { 1572 if (libhal_ctx_set_dbus_connection (halContext, dbusConnection)) 1573 { 1574 if (libhal_ctx_init(halContext, &dbusError)) 1575 { 1576 int numDevices; 1577 char **halDevices = libhal_find_device_by_capability(halContext, 1578 "storage", &numDevices, &dbusError); 1579 if (halDevices != 0) 1580 { 1581 /* Hal is installed and working, so if no devices are reported, assume 1582 that there are none. */ 1583 halSuccess = true; 1584 for (int i = 0; i < numDevices; i++) 1585 { 1586 char *driveType = libhal_device_get_property_string(halContext, 1587 halDevices[i], "storage.drive_type", 0); 1588 if (driveType != 0) 1589 { 1590 if (strcmp(driveType, "floppy") != 0) 1591 { 1592 libhal_free_string(driveType); 1593 continue; 1594 } 1595 libhal_free_string(driveType); 1596 } 1597 else 1598 { 1599 /* An error occurred. The attribute "storage.drive_type" 1600 probably didn't exist. */ 1601 continue; 1602 } 1603 char *devNode = libhal_device_get_property_string(halContext, 1604 halDevices[i], "block.device", &dbusError); 1605 if (devNode != 0) 1606 { 1607 if (validateDevice(devNode, false)) 1608 { 1609 Utf8Str description; 1610 char *vendor, *product; 1611 /* We do not check the error here, as this field may 1612 not even exist. */ 1613 vendor = libhal_device_get_property_string(halContext, 1614 halDevices[i], "info.vendor", 0); 1615 product = libhal_device_get_property_string(halContext, 1616 halDevices[i], "info.product", &dbusError); 1617 if ((product != 0) && (product[0] != 0)) 1618 { 1619 if ((vendor != 0) && (vendor[0] != 0)) 1620 { 1621 description = Utf8StrFmt ("%s %s", 1622 vendor, product); 1623 } 1624 else 1625 { 1626 description = product; 1627 } 1628 ComObjPtr <HostFloppyDrive> hostFloppyDrive; 1629 hostFloppyDrive.createObject(); 1630 hostFloppyDrive->init (Bstr (devNode), 1631 Bstr (halDevices[i]), 1632 Bstr (description)); 1633 list.push_back (hostFloppyDrive); 1634 } 1635 else 1636 { 1637 if (product == 0) 1638 { 1639 LogRel(("Host::COMGETTER(FloppyDrives): failed to get property \"info.product\" for device %s. dbus error: %s (%s)\n", 1640 halDevices[i], dbusError.name, dbusError.message)); 1641 dbus_error_free(&dbusError); 1642 } 1643 ComObjPtr <HostFloppyDrive> hostFloppyDrive; 1644 hostFloppyDrive.createObject(); 1645 hostFloppyDrive->init (Bstr (devNode), 1646 Bstr (halDevices[i])); 1647 list.push_back (hostFloppyDrive); 1648 } 1649 if (vendor != 0) 1650 { 1651 libhal_free_string(vendor); 1652 } 1653 if (product != 0) 1654 { 1655 libhal_free_string(product); 1656 } 1657 } 1658 else 1659 { 1660 LogRel(("Host::COMGETTER(FloppyDrives): failed to validate the block device %s as a floppy drive\n")); 1661 } 1662 libhal_free_string(devNode); 1663 } 1664 else 1665 { 1666 LogRel(("Host::COMGETTER(FloppyDrives): failed to get property \"block.device\" for device %s. dbus error: %s (%s)\n", 1667 halDevices[i], dbusError.name, dbusError.message)); 1668 dbus_error_free(&dbusError); 1669 } 1670 } 1671 libhal_free_string_array(halDevices); 1672 } 1673 else 1674 { 1675 LogRel(("Host::COMGETTER(FloppyDrives): failed to get devices with capability \"storage.cdrom\". dbus error: %s (%s)\n", dbusError.name, dbusError.message)); 1676 dbus_error_free(&dbusError); 1677 } 1678 if (!libhal_ctx_shutdown(halContext, &dbusError)) /* what now? */ 1679 { 1680 LogRel(("Host::COMGETTER(FloppyDrives): failed to shutdown the libhal context. dbus error: %s (%s)\n", dbusError.name, dbusError.message)); 1681 dbus_error_free(&dbusError); 1682 } 1683 } 1684 else 1685 { 1686 LogRel(("Host::COMGETTER(FloppyDrives): failed to initialise libhal context. dbus error: %s (%s)\n", dbusError.name, dbusError.message)); 1687 dbus_error_free(&dbusError); 1688 } 1689 libhal_ctx_free(halContext); 1690 } 1691 else 1692 { 1693 LogRel(("Host::COMGETTER(FloppyDrives): failed to set libhal connection to dbus.\n")); 1694 } 1695 } 1696 else 1697 { 1698 LogRel(("Host::COMGETTER(FloppyDrives): failed to get a libhal context - out of memory?\n")); 1699 } 1700 dbus_connection_unref(dbusConnection); 1701 } 1702 else 1703 { 1704 LogRel(("Host::COMGETTER(FloppyDrives): failed to connect to dbus. dbus error: %s (%s)\n", dbusError.name, dbusError.message)); 1523 1705 dbus_error_free(&dbusError); 1524 1706 } -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r2917 r2957 3502 3502 <desc>Returns a human readable description for the drive.</desc> 3503 3503 </attribute> 3504 <attribute name="udi" type="wstring" readonly="yes"> 3505 <desc>Returns the unique device identifier for the drive.</desc> 3506 </attribute> 3504 3507 3505 3508 </interface> … … 3540 3543 <attribute name="name" type="wstring" readonly="yes"> 3541 3544 <desc>Returns the platform device identifier.</desc> 3545 </attribute> 3546 <attribute name="description" type="wstring" readonly="yes"> 3547 <desc>Returns a human readable description for the drive.</desc> 3548 </attribute> 3549 <attribute name="udi" type="wstring" readonly="yes"> 3550 <desc>Returns the unique device identifier for the drive.</desc> 3542 3551 </attribute> 3543 3552 </interface> -
trunk/src/VBox/Main/include/HostDVDDriveImpl.h
r2929 r2957 53 53 54 54 // public initializer/uninitializer for internal purposes only 55 HRESULT init (INPTR BSTR aName, INPTR BSTR a Description = NULL);55 HRESULT init (INPTR BSTR aName, INPTR BSTR aUdi = NULL, INPTR BSTR aDescription = NULL); 56 56 void uninit(); 57 57 58 58 // IHostDVDDrive properties 59 59 STDMETHOD(COMGETTER(Name)) (BSTR *aName); 60 STDMETHOD(COMGETTER(Udi)) (BSTR *aUdi); 60 61 STDMETHOD(COMGETTER(Description)) (BSTR *aDescription); 61 62 … … 64 65 /* @note Must be called from under the object read lock. */ 65 66 const Bstr &name() const { return mName; } 67 const Bstr &udi() const { return mUdi; } 68 const Bstr &description() const { return mDescription; } 66 69 67 70 // for VirtualBoxSupportErrorInfoImpl … … 72 75 const Bstr mName; 73 76 const Bstr mDescription; 77 const Bstr mUdi; 74 78 }; 75 79 -
trunk/src/VBox/Main/include/HostFloppyDriveImpl.h
r2929 r2957 53 53 54 54 // public initializer/uninitializer for internal purposes only 55 HRESULT init (INPTR BSTR aName );55 HRESULT init (INPTR BSTR aName, INPTR BSTR aUdi = NULL, INPTR BSTR aDescription = NULL); 56 56 void uninit(); 57 57 58 // IHost DVDDrive properties58 // IHostFloppyDrive properties 59 59 STDMETHOD(COMGETTER(Name)) (BSTR *aName); 60 STDMETHOD(COMGETTER(Description)) (BSTR *aDescription); 61 STDMETHOD(COMGETTER(Udi)) (BSTR *aUdi); 60 62 61 63 // public methods for internal purposes only … … 63 65 /* @note Must be called from under the object read lock. */ 64 66 const Bstr &name() const { return mName; } 67 const Bstr &udi() const { return mUdi; } 68 const Bstr &description() const { return mDescription; } 65 69 66 70 // for VirtualBoxSupportErrorInfoImpl … … 70 74 71 75 const Bstr mName; 76 const Bstr mDescription; 77 const Bstr mUdi; 72 78 }; 73 79 -
trunk/src/VBox/Main/include/HostImpl.h
r2917 r2957 36 36 class SessionMachine; 37 37 class HostDVDDrive; 38 class HostFloppyDrive; 38 39 class Progress; 39 40 … … 133 134 # ifdef VBOX_USE_LIBHAL 134 135 bool getDVDInfoFromHal(std::list <ComObjPtr <HostDVDDrive> > &list); 136 bool getFloppyInfoFromHal(std::list <ComObjPtr <HostFloppyDrive> > &list); 135 137 # endif 136 138 void parseMountTable(char *mountTable, std::list <ComObjPtr <HostDVDDrive> > &list);
Note:
See TracChangeset
for help on using the changeset viewer.