From 84cd10ab7f4bd0409923d3b2961529a41f4e63e6 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Thu, 5 Apr 2012 14:33:47 -0500 Subject: Add device friendly name generation to TDE hardware library --- tdecore/tdehardwaredevices.cpp | 412 +++++++++++++++++++++++++++++++++++++---- tdecore/tdehardwaredevices.h | 91 ++++++++- 2 files changed, 462 insertions(+), 41 deletions(-) (limited to 'tdecore') diff --git a/tdecore/tdehardwaredevices.cpp b/tdecore/tdehardwaredevices.cpp index 8fc5781f5..eecea7b23 100644 --- a/tdecore/tdehardwaredevices.cpp +++ b/tdecore/tdehardwaredevices.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -45,6 +46,7 @@ TDEGenericDevice::TDEGenericDevice(TDEGenericDeviceType::TDEGenericDeviceType dt m_deviceName = dn; m_parentDevice = 0; + m_friendlyName = TQString::null; m_blacklistedForUpdate = false; } @@ -114,6 +116,7 @@ TQString &TDEGenericDevice::vendorID() { void TDEGenericDevice::setVendorID(TQString id) { m_vendorID = id; + m_vendorID.replace("0x", ""); } TQString &TDEGenericDevice::modelID() { @@ -122,6 +125,41 @@ TQString &TDEGenericDevice::modelID() { void TDEGenericDevice::setModelID(TQString id) { m_modelID = id; + m_modelID.replace("0x", ""); +} + +TQString &TDEGenericDevice::subVendorID() { + return m_subvendorID; +} + +void TDEGenericDevice::setSubVendorID(TQString id) { + m_subvendorID = id; + m_subvendorID.replace("0x", ""); +} + +TQString &TDEGenericDevice::moduleAlias() { + return m_modAlias; +} + +void TDEGenericDevice::setModuleAlias(TQString ma) { + m_modAlias = ma; +} + +TQString &TDEGenericDevice::deviceDriver() { + return m_deviceDriver; +} + +void TDEGenericDevice::setDeviceDriver(TQString dr) { + m_deviceDriver = dr; +} + +TQString &TDEGenericDevice::subModelID() { + return m_submodelID; +} + +void TDEGenericDevice::setSubModelID(TQString id) { + m_submodelID = id; + m_submodelID.replace("0x", ""); } void TDEGenericDevice::setParentDevice(TDEGenericDevice* pd) { @@ -140,6 +178,48 @@ void TDEGenericDevice::setBlacklistedForUpdate(bool bl) { m_blacklistedForUpdate = bl; } +TQString TDEGenericDevice::friendlyName() { + if (m_friendlyName.isNull()) { + if (type() == TDEGenericDeviceType::Root) { + TQString friendlyDriverName = m_systemPath; + friendlyDriverName.remove(0, friendlyDriverName.findRev("/")+1); + m_friendlyName = i18n("Linux Base Device") + " " + friendlyDriverName; + } + else if (m_modAlias.lower().startsWith("pci")) { + m_friendlyName = KGlobal::hardwareDevices()->findPCIDeviceName(m_vendorID, m_modelID, m_subvendorID, m_submodelID); + } + else if (m_modAlias.lower().startsWith("usb")) { + m_friendlyName = KGlobal::hardwareDevices()->findUSBDeviceName(m_vendorID, m_modelID, m_subvendorID, m_submodelID); + } + } + + if (m_friendlyName.isNull()) { + // Could not identify based on model/vendor + // Guess by driver + if (!m_deviceDriver.isNull()) { + TQString friendlyDriverName = m_deviceDriver.lower(); + friendlyDriverName[0] = friendlyDriverName[0].upper(); + m_friendlyName = i18n("Generic %1 Device").arg(friendlyDriverName); + } + else if (m_systemPath.lower().startsWith("/sys/devices/virtual")) { + TQString friendlyDriverName = m_systemPath; + friendlyDriverName.remove(0, friendlyDriverName.findRev("/")+1); + if (!friendlyDriverName.isNull()) { + m_friendlyName = i18n("Virtual Device %1").arg(friendlyDriverName); + } + else { + m_friendlyName = i18n("Unknown Virtual Device"); + } + } + else { + // I really have no idea what this peripheral is; say so! + m_friendlyName = i18n("Unknown Device") + " " + name(); + } + } + + return m_friendlyName; +} + TDEStorageDevice::TDEStorageDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn), m_mediaInserted(true) { m_diskType = TDEDiskDeviceType::Null; m_diskStatus = TDEDiskDeviceStatus::Null; @@ -471,6 +551,10 @@ bool TDEStorageDevice::unmountDevice(TQString* errRet, int* retcode) { } TDEHardwareDevices::TDEHardwareDevices() { + // Initialize members + pci_id_map = 0; + usb_id_map = 0; + // Set up device list m_deviceList.setAutoDelete( TRUE ); // the list owns the objects @@ -517,6 +601,14 @@ TDEHardwareDevices::~TDEHardwareDevices() { // Tear down udev interface udev_unref(m_udevStruct); + + // Delete members + if (pci_id_map) { + delete pci_id_map; + } + if (usb_id_map) { + delete usb_id_map; + } } void TDEHardwareDevices::rescanDeviceInformation(TDEGenericDevice* hwdevice) { @@ -935,6 +1027,9 @@ TDEGenericDeviceType::TDEGenericDeviceType readGenericDeviceTypeFromString(TQStr else if (query == "OtherSensor") { ret = TDEGenericDeviceType::OtherSensor; } + else if (query == "Virtual") { + ret = TDEGenericDeviceType::Virtual; + } else { ret = TDEGenericDeviceType::Other; } @@ -1174,7 +1269,7 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDeviceByExternalRules(udev_ } TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TDEGenericDevice* existingdevice, bool force_full_classification) { - // Classify device and create TDEW device object + // Classify device and create TDEHW device object TQString devicename(udev_device_get_sysname(dev)); TQString devicetype(udev_device_get_devtype(dev)); TQString devicedriver(udev_device_get_driver(dev)); @@ -1183,6 +1278,8 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD TQString systempath(udev_device_get_syspath(dev)); TQString devicevendorid(udev_device_get_property_value(dev, "ID_VENDOR_ID")); TQString devicemodelid(udev_device_get_property_value(dev, "ID_MODEL_ID")); + TQString devicesubvendorid(udev_device_get_property_value(dev, "ID_SUBVENDOR_ID")); + TQString devicesubmodelid(udev_device_get_property_value(dev, "ID_SUBMODEL_ID")); bool removable = false; TDEGenericDevice* device = existingdevice; @@ -1191,48 +1288,60 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD // Figure out the remaining udev logic to classify the rest! // Helpful file: http://www.enlightenment.org/svn/e/trunk/PROTO/enna-explorer/src/bin/udev.c - // Many devices do not provide their vendor/model ID via udev - // Go after it manually... - if (devicevendorid.isNull() || devicemodelid.isNull()) { - bool done = false; - TQString current_path = systempath; - TQString modalias_string = TQString::null; - - while (done == false) { - TQString malnodename = current_path; - malnodename.append("/modalias"); - TQFile malfile(malnodename); - if (malfile.open(IO_ReadOnly)) { - TQTextStream stream( &malfile ); - modalias_string = stream.readLine(); - malfile.close(); - } - if (modalias_string.startsWith("pci") || modalias_string.startsWith("usb")) { + bool done = false; + TQString current_path = systempath; + TQString devicemodalias = TQString::null; + + while (done == false) { + TQString malnodename = current_path; + malnodename.append("/modalias"); + TQFile malfile(malnodename); + if (malfile.open(IO_ReadOnly)) { + TQTextStream stream( &malfile ); + devicemodalias = stream.readLine(); + malfile.close(); + } + if (devicemodalias.startsWith("pci") || devicemodalias.startsWith("usb")) { + done = true; + } + else { + devicemodalias = TQString::null; + current_path.truncate(current_path.findRev("/")); + if (!current_path.startsWith("/sys/devices")) { + // Abort! done = true; } - else { - modalias_string = TQString::null; - current_path.truncate(current_path.findRev("/")); - if (!current_path.startsWith("/sys/devices")) { - // Abort! - done = true; - } - } } + } - if (modalias_string != TQString::null) { - int vloc = modalias_string.find("v"); - int dloc = modalias_string.find("d", vloc); + // Many devices do not provide their vendor/model ID via udev + // Go after it manually... + if (devicevendorid.isNull() || devicemodelid.isNull()) { + if (devicemodalias != TQString::null) { + int vloc = devicemodalias.find("v"); + int dloc = devicemodalias.find("d", vloc); + int svloc = devicemodalias.find("sv"); + int sdloc = devicemodalias.find("sd", vloc); // For added fun the device string lengths differ between pci and usb - if (modalias_string.startsWith("pci")) { - devicevendorid = modalias_string.mid(vloc+1, 8).lower(); - devicemodelid = modalias_string.mid(dloc+1, 8).lower(); + if (devicemodalias.startsWith("pci")) { + devicevendorid = devicemodalias.mid(vloc+1, 8).lower(); + devicemodelid = devicemodalias.mid(dloc+1, 8).lower(); + if (svloc != -1) { + devicesubvendorid = devicemodalias.mid(svloc+1, 8).lower(); + devicesubmodelid = devicemodalias.mid(sdloc+1, 8).lower(); + } devicevendorid.remove(0,4); devicemodelid.remove(0,4); + devicesubvendorid.remove(0,4); + devicesubmodelid.remove(0,4); } - if (modalias_string.startsWith("usb")) { - devicevendorid = modalias_string.mid(vloc+1, 4).lower(); - devicemodelid = modalias_string.mid(dloc+1, 4).lower(); + if (devicemodalias.startsWith("usb")) { + devicevendorid = devicemodalias.mid(vloc+1, 4).lower(); + devicemodelid = devicemodalias.mid(dloc+1, 4).lower(); + if (svloc != -1) { + devicesubvendorid = devicemodalias.mid(svloc+1, 4).lower(); + devicesubmodelid = devicemodalias.mid(sdloc+1, 4).lower(); + } } } } @@ -1288,6 +1397,13 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD } } + // Is this correct? Do we really want to ignore all unclassified virtual devices? + if (device == 0) { + if (systempath.lower().startsWith("/sys/devices/virtual")) { + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::Virtual); + } + } + if (device == 0) { // Unhandled if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::Other); @@ -1300,6 +1416,10 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD device->setSystemPath(systempath); device->setVendorID(devicevendorid); device->setModelID(devicemodelid); + device->setSubVendorID(devicesubvendorid); + device->setSubModelID(devicesubmodelid); + device->setModuleAlias(devicemodalias); + device->setDeviceDriver(devicedriver); updateBlacklists(device, dev); @@ -1557,6 +1677,8 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD device->setSystemPath(systempath); device->setVendorID(devicevendorid); device->setModelID(devicemodelid); + device->setSubVendorID(devicesubvendorid); + device->setSubModelID(devicesubmodelid); return device; } @@ -1690,6 +1812,226 @@ void TDEHardwareDevices::addCoreSystemDevices() { } +TQString TDEHardwareDevices::findPCIDeviceName(TQString vendorid, TQString modelid, TQString subvendorid, TQString submodelid) { + TQString vendorName = TQString::null; + TQString modelName = TQString::null; + TQString friendlyName = TQString::null; + + if (!pci_id_map) { + pci_id_map = new TDEDeviceIDMap; + + TQString database_filename = "/usr/share/pci.ids"; + if (!TQFile::exists(database_filename)) { + database_filename = "/usr/share/misc/pci.ids"; + } + if (!TQFile::exists(database_filename)) { + printf("[tdehardwaredevices] Unable to locate PCI information database pci.ids\n\r"); fflush(stdout); + return i18n("Unknown PCI Device"); + } + + TQFile database(database_filename); + if (database.open(IO_ReadOnly)) { + TQTextStream stream(&database); + TQString line; + TQString vendorID; + TQString modelID; + TQString subvendorID; + TQString submodelID; + TQString deviceMapKey; + TQStringList devinfo; + while (!stream.atEnd()) { + line = stream.readLine(); + if ((!line.upper().startsWith("\t")) && (!line.upper().startsWith("#"))) { + line.replace("\t", ""); + devinfo = TQStringList::split(' ', line, false); + vendorID = *(devinfo.at(0)); + vendorName = line; + vendorName.remove(0, vendorName.find(" ")); + vendorName = vendorName.stripWhiteSpace(); + modelName = TQString::null; + deviceMapKey = vendorID.lower() + ":::"; + } + else { + if ((line.upper().startsWith("\t")) && (!line.upper().startsWith("\t\t"))) { + line.replace("\t", ""); + devinfo = TQStringList::split(' ', line, false); + modelID = *(devinfo.at(0)); + modelName = line; + modelName.remove(0, modelName.find(" ")); + modelName = modelName.stripWhiteSpace(); + deviceMapKey = vendorID.lower() + ":" + modelID.lower() + "::"; + } + else { + if (line.upper().startsWith("\t\t")) { + line.replace("\t", ""); + devinfo = TQStringList::split(' ', line, false); + subvendorID = *(devinfo.at(0)); + submodelID = *(devinfo.at(1)); + modelName = line; + modelName.remove(0, modelName.find(" ")); + modelName = modelName.stripWhiteSpace(); + modelName.remove(0, modelName.find(" ")); + modelName = modelName.stripWhiteSpace(); + deviceMapKey = vendorID.lower() + ":" + modelID.lower() + ":" + subvendorID.lower() + ":" + submodelID.lower(); + } + } + } + if (modelName.isNull()) { + pci_id_map->insert(deviceMapKey, "***UNKNOWN DEVICE*** " + vendorName, true); + } + else { + pci_id_map->insert(deviceMapKey, vendorName + " " + modelName, true); + } + } + database.close(); + } + else { + printf("[tdehardwaredevices] Unable to open PCI information database %s\n\r", database_filename.ascii()); fflush(stdout); + } + } + + if (pci_id_map) { + TQString deviceName; + TQString deviceMapKey = vendorid.lower() + ":" + modelid.lower() + ":" + subvendorid.lower() + ":" + submodelid.lower(); + + deviceName = (*pci_id_map)[deviceMapKey]; + if (deviceName.isNull() || deviceName.startsWith("***UNKNOWN DEVICE*** ")) { + deviceMapKey = vendorid.lower() + ":" + modelid.lower() + ":" + subvendorid.lower() + ":"; + deviceName = (*pci_id_map)[deviceMapKey]; + if (deviceName.isNull() || deviceName.startsWith("***UNKNOWN DEVICE*** ")) { + deviceMapKey = vendorid.lower() + ":" + modelid.lower() + "::"; + deviceName = (*pci_id_map)[deviceMapKey]; + } + } + + if (deviceName.startsWith("***UNKNOWN DEVICE*** ")) { + deviceName.replace("***UNKNOWN DEVICE*** ", ""); + deviceName.prepend(i18n("Unknown PCI Device") + " "); + if (subvendorid.isNull()) { + deviceName.append(TQString(" [%1:%2]").arg(vendorid.lower()).arg(modelid.lower())); + } + else { + deviceName.append(TQString(" [%1:%2] [%3:%4]").arg(vendorid.lower()).arg(modelid.lower()).arg(subvendorid.lower()).arg(submodelid.lower())); + } + } + + return deviceName; + } + else { + return i18n("Unknown PCI Device"); + } +} + +TQString TDEHardwareDevices::findUSBDeviceName(TQString vendorid, TQString modelid, TQString subvendorid, TQString submodelid) { + TQString vendorName = TQString::null; + TQString modelName = TQString::null; + TQString friendlyName = TQString::null; + + if (!usb_id_map) { + usb_id_map = new TDEDeviceIDMap; + + TQString database_filename = "/usr/share/usb.ids"; + if (!TQFile::exists(database_filename)) { + database_filename = "/usr/share/misc/usb.ids"; + } + if (!TQFile::exists(database_filename)) { + printf("[tdehardwaredevices] Unable to locate USB information database usb.ids\n\r"); fflush(stdout); + return i18n("Unknown USB Device"); + } + + TQFile database(database_filename); + if (database.open(IO_ReadOnly)) { + TQTextStream stream(&database); + TQString line; + TQString vendorID; + TQString modelID; + TQString subvendorID; + TQString submodelID; + TQString deviceMapKey; + TQStringList devinfo; + while (!stream.atEnd()) { + line = stream.readLine(); + if ((!line.upper().startsWith("\t")) && (!line.upper().startsWith("#"))) { + line.replace("\t", ""); + devinfo = TQStringList::split(' ', line, false); + vendorID = *(devinfo.at(0)); + vendorName = line; + vendorName.remove(0, vendorName.find(" ")); + vendorName = vendorName.stripWhiteSpace(); + modelName = TQString::null; + deviceMapKey = vendorID.lower() + ":::"; + } + else { + if ((line.upper().startsWith("\t")) && (!line.upper().startsWith("\t\t"))) { + line.replace("\t", ""); + devinfo = TQStringList::split(' ', line, false); + modelID = *(devinfo.at(0)); + modelName = line; + modelName.remove(0, modelName.find(" ")); + modelName = modelName.stripWhiteSpace(); + deviceMapKey = vendorID.lower() + ":" + modelID.lower() + "::"; + } + else { + if (line.upper().startsWith("\t\t")) { + line.replace("\t", ""); + devinfo = TQStringList::split(' ', line, false); + subvendorID = *(devinfo.at(0)); + submodelID = *(devinfo.at(1)); + modelName = line; + modelName.remove(0, modelName.find(" ")); + modelName = modelName.stripWhiteSpace(); + modelName.remove(0, modelName.find(" ")); + modelName = modelName.stripWhiteSpace(); + deviceMapKey = vendorID.lower() + ":" + modelID.lower() + ":" + subvendorID.lower() + ":" + submodelID.lower(); + } + } + } + if (modelName.isNull()) { + usb_id_map->insert(deviceMapKey, "***UNKNOWN DEVICE*** " + vendorName, true); + } + else { + usb_id_map->insert(deviceMapKey, vendorName + " " + modelName, true); + } + } + database.close(); + } + else { + printf("[tdehardwaredevices] Unable to open USB information database %s\n\r", database_filename.ascii()); fflush(stdout); + } + } + + if (usb_id_map) { + TQString deviceName; + TQString deviceMapKey = vendorid.lower() + ":" + modelid.lower() + ":" + subvendorid.lower() + ":" + submodelid.lower(); + + deviceName = (*usb_id_map)[deviceMapKey]; + if (deviceName.isNull() || deviceName.startsWith("***UNKNOWN DEVICE*** ")) { + deviceMapKey = vendorid.lower() + ":" + modelid.lower() + ":" + subvendorid.lower() + ":"; + deviceName = (*usb_id_map)[deviceMapKey]; + if (deviceName.isNull() || deviceName.startsWith("***UNKNOWN DEVICE*** ")) { + deviceMapKey = vendorid.lower() + ":" + modelid.lower() + "::"; + deviceName = (*usb_id_map)[deviceMapKey]; + } + } + + if (deviceName.startsWith("***UNKNOWN DEVICE*** ")) { + deviceName.replace("***UNKNOWN DEVICE*** ", ""); + deviceName.prepend(i18n("Unknown USB Device") + " "); + if (subvendorid.isNull()) { + deviceName.append(TQString(" [%1:%2]").arg(vendorid.lower()).arg(modelid.lower())); + } + else { + deviceName.append(TQString(" [%1:%2] [%3:%4]").arg(vendorid.lower()).arg(modelid.lower()).arg(subvendorid.lower()).arg(submodelid.lower())); + } + } + + return deviceName; + } + else { + return i18n("Unknown USB Device"); + } +} + TQPtrList TDEHardwareDevices::listByDeviceClass(TDEGenericDeviceType::TDEGenericDeviceType cl) { TDEGenericHardwareList ret; ret.setAutoDelete(false); diff --git a/tdecore/tdehardwaredevices.h b/tdecore/tdehardwaredevices.h index bab5bd064..62dff3472 100644 --- a/tdecore/tdehardwaredevices.h +++ b/tdecore/tdehardwaredevices.h @@ -67,7 +67,9 @@ enum TDEGenericDeviceType { OtherUSB, OtherPeripheral, OtherSensor, - Other + Virtual, + Other, + Last = Other }; }; @@ -202,6 +204,14 @@ class TDECORE_EXPORT TDEGenericDevice */ void setVendorModel(TQString vm); + /** + * @return a TQString with a friendly name + * + * While TDE tries very hard to generate and return a friendly name for this device, + * sometimes the best it will be able to do is "Unknown Device [xxxx:yyyy]" + */ + TQString friendlyName(); + /** * @return a TQString with the device bus name, if any */ @@ -270,6 +280,51 @@ class TDECORE_EXPORT TDEGenericDevice */ TQString &modelID(); + /** + * @param a TQString with the model ID, if any + */ + void setModelID(TQString id); + + /** + * @return a TQString with the subvendor ID, if any + */ + TQString &subVendorID(); + + /** + * @param a TQString with the subvendor ID, if any + */ + void setSubVendorID(TQString id); + + /** + * @return a TQString with the submodel ID, if any + */ + TQString &subModelID(); + + /** + * @param a TQString with the submodel ID, if any + */ + void setSubModelID(TQString id); + + /** + * @return a TQString with the module alias string, if any + */ + TQString &moduleAlias(); + + /** + * @param a TQString with the module alias string, if any + */ + void setModuleAlias(TQString ma); + + /** + * @return a TQString with the module alias string, if any + */ + TQString &deviceDriver(); + + /** + * @param a TQString with the module alias string, if any + */ + void setDeviceDriver(TQString dr); + /** * @param a TDEGenericDevice* with the parent device, if any */ @@ -280,11 +335,6 @@ class TDECORE_EXPORT TDEGenericDevice */ TDEGenericDevice* parentDevice(); - /** - * @param a TQString with the model ID, if any - */ - void setModelID(TQString id); - private: TDEGenericDeviceType::TDEGenericDeviceType m_deviceType; TQString m_deviceName; @@ -296,6 +346,11 @@ class TDECORE_EXPORT TDEGenericDevice TQString m_uniqueID; TQString m_vendorID; TQString m_modelID; + TQString m_subvendorID; + TQString m_submodelID; + TQString m_modAlias; + TQString m_deviceDriver; + TQString m_friendlyName; bool m_blacklistedForUpdate; TDEGenericDevice* m_parentDevice; @@ -484,6 +539,7 @@ class TDECORE_EXPORT TDEStorageDevice : public TDEGenericDevice }; typedef TQPtrList TDEGenericHardwareList; +typedef TQMap TDEDeviceIDMap; class TQSocketNotifier; @@ -545,6 +601,26 @@ class TDECORE_EXPORT TDEHardwareDevices : public TQObject */ TDEStorageDevice* findDiskByUID(TQString uid); + /** + * Look up the device in the system PCI database + * @param vendorid a TQString containing the vendor ID in hexadecimal + * @param modelid a TQString containing the model ID in hexadecimal + * @param subvendorid a TQString containing the subvendor ID in hexadecimal + * @param submodelid a TQString containing the submodel ID in hexadecimal + * @return a TQString containing the device name, if found + */ + TQString findPCIDeviceName(TQString vendorid, TQString modelid, TQString subvendorid, TQString submodelid); + + /** + * Look up the device in the system USB database + * @param vendorid a TQString containing the vendor ID in hexadecimal + * @param modelid a TQString containing the model ID in hexadecimal + * @param subvendorid a TQString containing the subvendor ID in hexadecimal + * @param submodelid a TQString containing the submodel ID in hexadecimal + * @return a TQString containing the device name, if found + */ + TQString findUSBDeviceName(TQString vendorid, TQString modelid, TQString subvendorid, TQString submodelid); + signals: void hardwareAdded(TDEGenericDevice*); void hardwareRemoved(TDEGenericDevice*); @@ -578,6 +654,9 @@ class TDECORE_EXPORT TDEHardwareDevices : public TQObject TQStringList m_mountTable; + TDEDeviceIDMap* pci_id_map; + TDEDeviceIDMap* usb_id_map; + friend class TDEGenericDevice; friend class TDEStorageDevice; }; -- cgit v1.2.1 From 4567c04cccf7a994c20f2eb55127f6331ad344f5 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Thu, 5 Apr 2012 18:00:42 -0500 Subject: Update TDE hardware library to classify most devices halfway correctly --- tdecore/tdehardwaredevices.cpp | 413 +++++++++++++++++++++++++++++++++++++++-- tdecore/tdehardwaredevices.h | 52 +++++- 2 files changed, 450 insertions(+), 15 deletions(-) (limited to 'tdecore') diff --git a/tdecore/tdehardwaredevices.cpp b/tdecore/tdehardwaredevices.cpp index eecea7b23..55a5b4817 100644 --- a/tdecore/tdehardwaredevices.cpp +++ b/tdecore/tdehardwaredevices.cpp @@ -153,6 +153,14 @@ void TDEGenericDevice::setDeviceDriver(TQString dr) { m_deviceDriver = dr; } +TQString &TDEGenericDevice::subsystem() { + return m_subsystem; +} + +void TDEGenericDevice::setSubsystem(TQString ss) { + m_subsystem = ss; +} + TQString &TDEGenericDevice::subModelID() { return m_submodelID; } @@ -170,6 +178,10 @@ TDEGenericDevice* TDEGenericDevice::parentDevice() { return m_parentDevice; } +TQPixmap TDEGenericDevice::icon(KIcon::StdSizes size) { + return KGlobal::hardwareDevices()->getDeviceTypeIconFromType(type(), size); +} + bool TDEGenericDevice::blacklistedForUpdate() { return m_blacklistedForUpdate; } @@ -183,7 +195,8 @@ TQString TDEGenericDevice::friendlyName() { if (type() == TDEGenericDeviceType::Root) { TQString friendlyDriverName = m_systemPath; friendlyDriverName.remove(0, friendlyDriverName.findRev("/")+1); - m_friendlyName = i18n("Linux Base Device") + " " + friendlyDriverName; +// m_friendlyName = i18n("Linux Base Device") + " " + friendlyDriverName; + m_friendlyName = friendlyDriverName; } else if (m_modAlias.lower().startsWith("pci")) { m_friendlyName = KGlobal::hardwareDevices()->findPCIDeviceName(m_vendorID, m_modelID, m_subvendorID, m_submodelID); @@ -195,8 +208,12 @@ TQString TDEGenericDevice::friendlyName() { if (m_friendlyName.isNull()) { // Could not identify based on model/vendor + // Guess by type + if (type() == TDEGenericDeviceType::CPU) { + m_friendlyName = name(); + } // Guess by driver - if (!m_deviceDriver.isNull()) { + else if (!m_deviceDriver.isNull()) { TQString friendlyDriverName = m_deviceDriver.lower(); friendlyDriverName[0] = friendlyDriverName[0].upper(); m_friendlyName = i18n("Generic %1 Device").arg(friendlyDriverName); @@ -961,12 +978,24 @@ TDEGenericDeviceType::TDEGenericDeviceType readGenericDeviceTypeFromString(TQStr else if (query == "RAM") { ret = TDEGenericDeviceType::RAM; } + else if (query == "Bus") { + ret = TDEGenericDeviceType::Bus; + } + else if (query == "I2C") { + ret = TDEGenericDeviceType::I2C; + } + else if (query == "MDIO") { + ret = TDEGenericDeviceType::MDIO; + } else if (query == "Mainboard") { ret = TDEGenericDeviceType::Mainboard; } else if (query == "Disk") { ret = TDEGenericDeviceType::Disk; } + else if (query == "SCSI") { + ret = TDEGenericDeviceType::SCSI; + } else if (query == "StorageController") { ret = TDEGenericDeviceType::StorageController; } @@ -991,12 +1020,21 @@ TDEGenericDeviceType::TDEGenericDeviceType readGenericDeviceTypeFromString(TQStr else if (query == "Sound") { ret = TDEGenericDeviceType::Sound; } + else if (query == "VideoCapture") { + ret = TDEGenericDeviceType::VideoCapture; + } else if (query == "IEEE1394") { ret = TDEGenericDeviceType::IEEE1394; } else if (query == "Camera") { ret = TDEGenericDeviceType::Camera; } + else if (query == "Serial") { + ret = TDEGenericDeviceType::Serial; + } + else if (query == "Parallel") { + ret = TDEGenericDeviceType::Parallel; + } else if (query == "TextIO") { ret = TDEGenericDeviceType::TextIO; } @@ -1015,6 +1053,15 @@ TDEGenericDeviceType::TDEGenericDeviceType readGenericDeviceTypeFromString(TQStr else if (query == "ThermalControl") { ret = TDEGenericDeviceType::ThermalControl; } + else if (query == "Bridge") { + ret = TDEGenericDeviceType::Bridge; + } + else if (query == "Platform") { + ret = TDEGenericDeviceType::Platform; + } + else if (query == "PNP") { + ret = TDEGenericDeviceType::PNP; + } else if (query == "OtherACPI") { ret = TDEGenericDeviceType::OtherACPI; } @@ -1027,8 +1074,8 @@ TDEGenericDeviceType::TDEGenericDeviceType readGenericDeviceTypeFromString(TQStr else if (query == "OtherSensor") { ret = TDEGenericDeviceType::OtherSensor; } - else if (query == "Virtual") { - ret = TDEGenericDeviceType::Virtual; + else if (query == "OtherVirtual") { + ret = TDEGenericDeviceType::OtherVirtual; } else { ret = TDEGenericDeviceType::Other; @@ -1280,6 +1327,8 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD TQString devicemodelid(udev_device_get_property_value(dev, "ID_MODEL_ID")); TQString devicesubvendorid(udev_device_get_property_value(dev, "ID_SUBVENDOR_ID")); TQString devicesubmodelid(udev_device_get_property_value(dev, "ID_SUBMODEL_ID")); + TQString devicetypestring(udev_device_get_property_value(dev, "ID_TYPE")); + TQString devicetypestring_alt(udev_device_get_property_value(dev, "DEVTYPE")); bool removable = false; TDEGenericDevice* device = existingdevice; @@ -1350,6 +1399,7 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD if ((devicetype == "disk") || (devicetype == "partition") || (devicedriver == "floppy") + || (devicesubsystem == "scsi_disk") ) { if (!device) device = new TDEStorageDevice(TDEGenericDeviceType::Disk); } @@ -1397,10 +1447,76 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD } } - // Is this correct? Do we really want to ignore all unclassified virtual devices? + // Try to at least generally classify unclassified devices if (device == 0) { if (systempath.lower().startsWith("/sys/devices/virtual")) { - if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::Virtual); + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::OtherVirtual); + } + if ((devicetypestring == "audio") + || (devicesubsystem == "sound")) { + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::Sound); + } + if ((devicesubsystem == "video4linux") + || (devicesubsystem == "dvb")) { + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::VideoCapture); + } + if ((devicetypestring_alt == "scsi_target") + || (devicesubsystem == "scsi_host") + || (devicesubsystem == "scsi_device") + || (devicesubsystem == "scsi_generic") + || (devicesubsystem == "scsi") + || (devicesubsystem == "ata_port") + || (devicesubsystem == "ata_link") + || (devicesubsystem == "ata_device") + || (devicesubsystem == "ata")) { + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::StorageController); + } + if (devicesubsystem == "net") { + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::Network); + } + if (devicesubsystem == "i2c") { + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::I2C); + } + if (devicesubsystem == "mdio_bus") { + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::MDIO); + } + if ((devicesubsystem == "event_source") + || (devicesubsystem == "rtc")) { + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::Mainboard); + } + if (devicesubsystem == "bsg") { + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::SCSI); + } + if (devicesubsystem == "firewire") { + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::IEEE1394); + } + if (devicesubsystem == "serio") { + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::Serial); + } + if (devicesubsystem == "ppdev") { + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::Parallel); + } + if (devicesubsystem == "bridge") { + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::Bridge); + } + if ((devicesubsystem == "pci_bus") + || (devicesubsystem == "pci_express")) { + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::Bus); + } + if (devicesubsystem == "platform") { + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::Platform); + } + if (devicesubsystem == "pnp") { + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::PNP); + } + + // Most general classification possible + if ((devicesubsystem == "usb") + || (devicesubsystem == "usbmon")) { + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::OtherUSB); + } + if (devicesubsystem == "pci") { + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::OtherPeripheral); } } @@ -1420,6 +1536,7 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD device->setSubModelID(devicesubmodelid); device->setModuleAlias(devicemodalias); device->setDeviceDriver(devicedriver); + device->setSubsystem(devicesubsystem); updateBlacklists(device, dev); @@ -1486,7 +1603,6 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD TQString devicebus(udev_device_get_property_value(dev, "ID_BUS")); // Get disk specific info - TQString disktypestring(udev_device_get_property_value(dev, "ID_TYPE")); TQString disklabel(udev_device_get_property_value(dev, "ID_FS_LABEL")); TQString diskuuid(udev_device_get_property_value(dev, "ID_FS_UUID")); TQString filesystemtype(udev_device_get_property_value(dev, "ID_FS_TYPE")); @@ -1502,7 +1618,7 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD TDEDiskDeviceStatus::TDEDiskDeviceStatus diskstatus = sdevice->diskStatus(); if (force_full_classification) { - disktype = classifyDiskType(dev, devicebus, disktypestring, systempath, devicevendor, devicemodel, filesystemtype, devicedriver); + disktype = classifyDiskType(dev, devicebus, devicetypestring, systempath, devicevendor, devicemodel, filesystemtype, devicedriver); sdevice->setDiskType(disktype); device = classifyUnknownDeviceByExternalRules(dev, device, true); // Check external rules for possible subtype overrides disktype = sdevice->diskType(); // The type can be overridden by an external rule @@ -1571,7 +1687,7 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD } } - if (disktypestring.upper() == "CD") { + if (devicetypestring.upper() == "CD") { if (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_STATE")).upper() == "BLANK") { diskstatus = diskstatus | TDEDiskDeviceStatus::Blank; } @@ -1604,7 +1720,7 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD // Set mountable flag if device is likely to be mountable diskstatus = diskstatus | TDEDiskDeviceStatus::Mountable; - if ((!disktypestring.upper().isNull()) && (disktype & TDEDiskDeviceType::HDD)) { + if ((!devicetypestring.upper().isNull()) && (disktype & TDEDiskDeviceType::HDD)) { diskstatus = diskstatus & ~TDEDiskDeviceStatus::Mountable; } if (removable) { @@ -1679,6 +1795,8 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD device->setModelID(devicemodelid); device->setSubVendorID(devicesubvendorid); device->setSubModelID(devicesubmodelid); + device->setDeviceDriver(devicedriver); + device->setSubsystem(devicesubsystem); return device; } @@ -1809,7 +1927,36 @@ void TDEHardwareDevices::addCoreSystemDevices() { ++devicesdirit; } } - + + // Handle CPUs, which are currently handled terribly by udev + // Parse /proc/cpuinfo to extract some information about the CPUs + hwdevice = 0; + TQStringList lines; + TQFile file( "/proc/cpuinfo" ); + if ( file.open( IO_ReadOnly ) ) { + TQTextStream stream( &file ); + TQString line; + int processorNumber = -1; + while ( !stream.atEnd() ) { + line = stream.readLine(); + // WARNING This routine assumes that "processor" is always the first entry in /proc/cpuinfo! + if (line.startsWith("processor")) { + line.remove(0, line.find(":")+1); + line = line.stripWhiteSpace(); + processorNumber = line.toInt(); + hwdevice = new TDEGenericDevice(TDEGenericDeviceType::CPU); + hwdevice->setSystemPath(TQString("/sys/devices/virtual/cpu%1").arg(processorNumber)); // FIXME: A system path is required, but I can't give a real unique path to the hardware manager due to kernel limitations + m_deviceList.append(hwdevice); + } + if (line.startsWith("model name")) { + line.remove(0, line.find(":")+1); + line = line.stripWhiteSpace(); + hwdevice->setName(line); + } + lines += line; + } + file.close(); + } } TQString TDEHardwareDevices::findPCIDeviceName(TQString vendorid, TQString modelid, TQString subvendorid, TQString submodelid) { @@ -2032,6 +2179,250 @@ TQString TDEHardwareDevices::findUSBDeviceName(TQString vendorid, TQString model } } +TQString TDEHardwareDevices::getFriendlyDeviceTypeStringFromType(TDEGenericDeviceType::TDEGenericDeviceType query) { + TQString ret = "Unknown Device"; + + // Keep this in sync with the TDEGenericDeviceType definition in the header + if (query == TDEGenericDeviceType::Root) { + ret = "Root"; + } + else if (query == TDEGenericDeviceType::CPU) { + ret = "CPU"; + } + else if (query == TDEGenericDeviceType::GPU) { + ret = "GPU"; + } + else if (query == TDEGenericDeviceType::RAM) { + ret = "RAM"; + } + else if (query == TDEGenericDeviceType::Bus) { + ret = "Bus"; + } + else if (query == TDEGenericDeviceType::I2C) { + ret = "I2C Bus"; + } + else if (query == TDEGenericDeviceType::MDIO) { + ret = "MDIO Bus"; + } + else if (query == TDEGenericDeviceType::Mainboard) { + ret = "Mainboard"; + } + else if (query == TDEGenericDeviceType::Disk) { + ret = "Disk"; + } + else if (query == TDEGenericDeviceType::SCSI) { + ret = "SCSI"; + } + else if (query == TDEGenericDeviceType::StorageController) { + ret = "Storage Controller"; + } + else if (query == TDEGenericDeviceType::Mouse) { + ret = "Mouse"; + } + else if (query == TDEGenericDeviceType::Keyboard) { + ret = "Keyboard"; + } + else if (query == TDEGenericDeviceType::HID) { + ret = "HID"; + } + else if (query == TDEGenericDeviceType::Network) { + ret = "Network"; + } + else if (query == TDEGenericDeviceType::Printer) { + ret = "Printer"; + } + else if (query == TDEGenericDeviceType::Scanner) { + ret = "Scanner"; + } + else if (query == TDEGenericDeviceType::Sound) { + ret = "Sound"; + } + else if (query == TDEGenericDeviceType::VideoCapture) { + ret = "Video Capture"; + } + else if (query == TDEGenericDeviceType::IEEE1394) { + ret = "IEEE1394"; + } + else if (query == TDEGenericDeviceType::Camera) { + ret = "Camera"; + } + else if (query == TDEGenericDeviceType::TextIO) { + ret = "TextIO"; + } + else if (query == TDEGenericDeviceType::Serial) { + ret = "Serial Port"; + } + else if (query == TDEGenericDeviceType::Parallel) { + ret = "Parallel Port"; + } + else if (query == TDEGenericDeviceType::Peripheral) { + ret = "Peripheral"; + } + else if (query == TDEGenericDeviceType::Battery) { + ret = "Battery"; + } + else if (query == TDEGenericDeviceType::Power) { + ret = "Power Device"; + } + else if (query == TDEGenericDeviceType::ThermalSensor) { + ret = "Thermal Sensor"; + } + else if (query == TDEGenericDeviceType::ThermalControl) { + ret = "Thermal Control"; + } + else if (query == TDEGenericDeviceType::Bridge) { + ret = "Bridge"; + } + else if (query == TDEGenericDeviceType::Platform) { + ret = "Platform"; + } + else if (query == TDEGenericDeviceType::PNP) { + ret = "Plug and Play"; + } + else if (query == TDEGenericDeviceType::OtherACPI) { + ret = "Other ACPI"; + } + else if (query == TDEGenericDeviceType::OtherUSB) { + ret = "Other USB"; + } + else if (query == TDEGenericDeviceType::OtherPeripheral) { + ret = "Other Peripheral"; + } + else if (query == TDEGenericDeviceType::OtherSensor) { + ret = "Other Sensor"; + } + else if (query == TDEGenericDeviceType::OtherVirtual) { + ret = "Other Virtual"; + } + else { + ret = "Unknown Device"; + } + + return ret; +} + +TQPixmap TDEHardwareDevices::getDeviceTypeIconFromType(TDEGenericDeviceType::TDEGenericDeviceType query, KIcon::StdSizes size) { + TQPixmap ret = DesktopIcon("misc", size); + +// // Keep this in sync with the TDEGenericDeviceType definition in the header + if (query == TDEGenericDeviceType::Root) { + ret = DesktopIcon("kcmdevices", size); + } + else if (query == TDEGenericDeviceType::CPU) { + ret = DesktopIcon("kcmprocessor", size); + } + else if (query == TDEGenericDeviceType::GPU) { + ret = DesktopIcon("kcmpci", size); + } + else if (query == TDEGenericDeviceType::RAM) { + ret = DesktopIcon("memory", size); + } + else if (query == TDEGenericDeviceType::Bus) { + ret = DesktopIcon("kcmpci", size); + } + else if (query == TDEGenericDeviceType::I2C) { + ret = DesktopIcon("input_devices_settings", size); + } + else if (query == TDEGenericDeviceType::MDIO) { + ret = DesktopIcon("input_devices_settings", size); + } + else if (query == TDEGenericDeviceType::Mainboard) { + ret = DesktopIcon("kcmpci", size); // FIXME + } + else if (query == TDEGenericDeviceType::Disk) { + ret = DesktopIcon("hdd_unmount", size); + } + else if (query == TDEGenericDeviceType::SCSI) { + ret = DesktopIcon("kcmscsi", size); + } + else if (query == TDEGenericDeviceType::StorageController) { + ret = DesktopIcon("kcmpci", size); + } + else if (query == TDEGenericDeviceType::Mouse) { + ret = DesktopIcon("mouse", size); + } + else if (query == TDEGenericDeviceType::Keyboard) { + ret = DesktopIcon("keyboard", size); + } + else if (query == TDEGenericDeviceType::HID) { + ret = DesktopIcon("kcmdevices", size); // FIXME + } + else if (query == TDEGenericDeviceType::Network) { + ret = DesktopIcon("kcmpci", size); + } + else if (query == TDEGenericDeviceType::Printer) { + ret = DesktopIcon("printer1", size); + } + else if (query == TDEGenericDeviceType::Scanner) { + ret = DesktopIcon("scanner", size); + } + else if (query == TDEGenericDeviceType::Sound) { + ret = DesktopIcon("kcmsound", size); + } + else if (query == TDEGenericDeviceType::VideoCapture) { + ret = DesktopIcon("tv", size); // FIXME + } + else if (query == TDEGenericDeviceType::IEEE1394) { + ret = DesktopIcon("ieee1394", size); + } + else if (query == TDEGenericDeviceType::Camera) { + ret = DesktopIcon("camera", size); + } + else if (query == TDEGenericDeviceType::Serial) { + ret = DesktopIcon("input_devices_settings", size); + } + else if (query == TDEGenericDeviceType::Parallel) { + ret = DesktopIcon("input_devices_settings", size); + } + else if (query == TDEGenericDeviceType::TextIO) { + ret = DesktopIcon("chardevice", size); + } + else if (query == TDEGenericDeviceType::Peripheral) { + ret = DesktopIcon("kcmpci", size); + } + else if (query == TDEGenericDeviceType::Battery) { + ret = DesktopIcon("energy", size); + } + else if (query == TDEGenericDeviceType::Power) { + ret = DesktopIcon("energy", size); + } + else if (query == TDEGenericDeviceType::ThermalSensor) { + ret = DesktopIcon("kcmdevices", size); // FIXME + } + else if (query == TDEGenericDeviceType::ThermalControl) { + ret = DesktopIcon("kcmdevices", size); // FIXME + } + else if (query == TDEGenericDeviceType::Bridge) { + ret = DesktopIcon("kcmpci", size); + } + else if (query == TDEGenericDeviceType::Platform) { + ret = DesktopIcon("kcmsystem", size); + } + else if (query == TDEGenericDeviceType::PNP) { + ret = DesktopIcon("kcmsystem", size); + } + else if (query == TDEGenericDeviceType::OtherACPI) { + ret = DesktopIcon("kcmdevices", size); // FIXME + } + else if (query == TDEGenericDeviceType::OtherUSB) { + ret = DesktopIcon("usb", size); + } + else if (query == TDEGenericDeviceType::OtherPeripheral) { + ret = DesktopIcon("kcmpci", size); + } + else if (query == TDEGenericDeviceType::OtherSensor) { + ret = DesktopIcon("kcmdevices", size); // FIXME + } + else if (query == TDEGenericDeviceType::OtherVirtual) { + ret = DesktopIcon("kcmsystem", size); + } + else { + ret = DesktopIcon("hwinfo", size); + } + + return ret; +} + TQPtrList TDEHardwareDevices::listByDeviceClass(TDEGenericDeviceType::TDEGenericDeviceType cl) { TDEGenericHardwareList ret; ret.setAutoDelete(false); diff --git a/tdecore/tdehardwaredevices.h b/tdecore/tdehardwaredevices.h index 62dff3472..ee47c655a 100644 --- a/tdecore/tdehardwaredevices.h +++ b/tdecore/tdehardwaredevices.h @@ -23,6 +23,7 @@ #include #include #include +#include "kiconloader.h" #include "tdelibs_export.h" // udev includes @@ -38,15 +39,19 @@ * @author Timothy Pearson */ -// Keep readGenericDeviceTypeFromString() in tdehardwaredevices.cpp in sync with this enum +// Keep readGenericDeviceTypeFromString(), getFriendlyDeviceTypeStringFromType(), and getDeviceTypeIconFromType() in tdehardwaredevices.cpp in sync with this enum namespace TDEGenericDeviceType { enum TDEGenericDeviceType { Root, CPU, GPU, RAM, + Bus, + I2C, + MDIO, Mainboard, Disk, + SCSI, StorageController, Mouse, Keyboard, @@ -55,19 +60,25 @@ enum TDEGenericDeviceType { Printer, Scanner, Sound, + VideoCapture, IEEE1394, Camera, TextIO, + Serial, + Parallel, Peripheral, Battery, Power, ThermalSensor, ThermalControl, + Bridge, + Platform, + PNP, OtherACPI, OtherUSB, OtherPeripheral, OtherSensor, - Virtual, + OtherVirtual, Other, Last = Other }; @@ -316,15 +327,25 @@ class TDECORE_EXPORT TDEGenericDevice void setModuleAlias(TQString ma); /** - * @return a TQString with the module alias string, if any + * @return a TQString with the device driver, if any */ TQString &deviceDriver(); /** - * @param a TQString with the module alias string, if any + * @param a TQString with the device driver, if any */ void setDeviceDriver(TQString dr); + /** + * @return a TQString with the subsystem type, if any + */ + TQString &subsystem(); + + /** + * @param a TQString with the subsystem type, if any + */ + void setSubsystem(TQString ss); + /** * @param a TDEGenericDevice* with the parent device, if any */ @@ -335,6 +356,13 @@ class TDECORE_EXPORT TDEGenericDevice */ TDEGenericDevice* parentDevice(); + /** + * Get an icon for this device + * @param size a KIcon::StdSizes structure specifying the desired icon size + * @return a TQPixmap containing the icon for the specified type + */ + virtual TQPixmap icon(KIcon::StdSizes size); + private: TDEGenericDeviceType::TDEGenericDeviceType m_deviceType; TQString m_deviceName; @@ -350,6 +378,7 @@ class TDECORE_EXPORT TDEGenericDevice TQString m_submodelID; TQString m_modAlias; TQString m_deviceDriver; + TQString m_subsystem; TQString m_friendlyName; bool m_blacklistedForUpdate; TDEGenericDevice* m_parentDevice; @@ -621,6 +650,21 @@ class TDECORE_EXPORT TDEHardwareDevices : public TQObject */ TQString findUSBDeviceName(TQString vendorid, TQString modelid, TQString subvendorid, TQString submodelid); + /** + * Get a friendly string describing a device type + * @param query a TDEGenericDeviceType::TDEGenericDeviceType specifying a device type + * @return a TQString containing the friendly type name + */ + TQString getFriendlyDeviceTypeStringFromType(TDEGenericDeviceType::TDEGenericDeviceType query); + + /** + * Get an icon for a device type + * @param query a TDEGenericDeviceType::TDEGenericDeviceType specifying a device type + * @param size a KIcon::StdSizes structure specifying the desired icon size + * @return a TQPixmap containing the icon for the specified type + */ + TQPixmap getDeviceTypeIconFromType(TDEGenericDeviceType::TDEGenericDeviceType query, KIcon::StdSizes size); + signals: void hardwareAdded(TDEGenericDevice*); void hardwareRemoved(TDEGenericDevice*); -- cgit v1.2.1 From beff973e2e273ef576ba848d5b0bb7b575ce342e Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Thu, 5 Apr 2012 18:21:47 -0500 Subject: Reliably detect device driver --- tdecore/tdehardwaredevices.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tdecore') diff --git a/tdecore/tdehardwaredevices.cpp b/tdecore/tdehardwaredevices.cpp index 55a5b4817..c98c21a48 100644 --- a/tdecore/tdehardwaredevices.cpp +++ b/tdecore/tdehardwaredevices.cpp @@ -1395,6 +1395,21 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD } } + // Most of the timeudev doesn't barf up a device driver either, so go after it manually... + if (devicedriver.isNull()) { + TQString driverSymlink = udev_device_get_syspath(dev); + TQString driverSymlinkDir = driverSymlink; + driverSymlink.append("/device/driver"); + driverSymlinkDir.append("/device/"); + TQFileInfo dirfi(driverSymlink); + if (dirfi.isSymLink()) { + char* collapsedPath = realpath((driverSymlinkDir + dirfi.readLink()).ascii(), NULL); + devicedriver = TQString(collapsedPath); + free(collapsedPath); + devicedriver.remove(0, devicedriver.findRev("/")+1); + } + } + // Classify generic device type and create appropriate object if ((devicetype == "disk") || (devicetype == "partition") -- cgit v1.2.1 From 56591939771fdbfc0d4a2c9d79bbed454cc648a0 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Thu, 5 Apr 2012 21:59:04 -0500 Subject: Classify devices based on PCI class if possible Lots of bugfixes --- .../classrules/floppydisk-platform.hwclass | 1 + tdecore/tdehardwaredevices.cpp | 242 +++++++++++++++++---- tdecore/tdehardwaredevices.h | 30 ++- 3 files changed, 226 insertions(+), 47 deletions(-) (limited to 'tdecore') diff --git a/tdecore/hwlibdata/classrules/floppydisk-platform.hwclass b/tdecore/hwlibdata/classrules/floppydisk-platform.hwclass index 8b038b300..b3ccab66c 100644 --- a/tdecore/hwlibdata/classrules/floppydisk-platform.hwclass +++ b/tdecore/hwlibdata/classrules/floppydisk-platform.hwclass @@ -1,4 +1,5 @@ [Conditions] +SUBSYSTEM=block DRIVER=floppy [DeviceType] diff --git a/tdecore/tdehardwaredevices.cpp b/tdecore/tdehardwaredevices.cpp index c98c21a48..8f33e1480 100644 --- a/tdecore/tdehardwaredevices.cpp +++ b/tdecore/tdehardwaredevices.cpp @@ -137,6 +137,15 @@ void TDEGenericDevice::setSubVendorID(TQString id) { m_subvendorID.replace("0x", ""); } +TQString &TDEGenericDevice::PCIClass() { + return m_pciClass; +} + +void TDEGenericDevice::setPCIClass(TQString cl) { + m_pciClass = cl; + m_pciClass.replace("0x", ""); +} + TQString &TDEGenericDevice::moduleAlias() { return m_modAlias; } @@ -195,7 +204,6 @@ TQString TDEGenericDevice::friendlyName() { if (type() == TDEGenericDeviceType::Root) { TQString friendlyDriverName = m_systemPath; friendlyDriverName.remove(0, friendlyDriverName.findRev("/")+1); -// m_friendlyName = i18n("Linux Base Device") + " " + friendlyDriverName; m_friendlyName = friendlyDriverName; } else if (m_modAlias.lower().startsWith("pci")) { @@ -325,6 +333,65 @@ void TDEStorageDevice::setSlaveDevices(TQStringList sd) { m_slaveDevices = sd; } +TQString TDEStorageDevice::friendlyName() { + if (isDiskOfType(TDEDiskDeviceType::Floppy)) { + return i18n("Floppy Drive"); + } + else if (isDiskOfType(TDEDiskDeviceType::Zip)) { + return i18n("Zip Drive"); + } + else if (isDiskOfType(TDEDiskDeviceType::Optical)) { + return i18n("Optical Drive"); + } + else { + return TDEGenericDevice::friendlyName(); + } +} + +TQPixmap TDEStorageDevice::icon(KIcon::StdSizes size) { + TQPixmap ret = DesktopIcon("hdd_unmount", size); + + if (isDiskOfType(TDEDiskDeviceType::Floppy)) { + ret = DesktopIcon("3floppy_unmount", size); + } + if (isDiskOfType(TDEDiskDeviceType::CDROM)) { + ret = DesktopIcon("cdrom_unmount", size); + } + if (isDiskOfType(TDEDiskDeviceType::CDRW)) { + ret = DesktopIcon("cdwriter_unmount", size); + } + if (isDiskOfType(TDEDiskDeviceType::DVDROM)) { + ret = DesktopIcon("dvd_unmount", size); + } + if (isDiskOfType(TDEDiskDeviceType::DVDRW) || isDiskOfType(TDEDiskDeviceType::DVDRAM)) { + ret = DesktopIcon("dvd_unmount", size); + } + if (isDiskOfType(TDEDiskDeviceType::Zip)) { + ret = DesktopIcon("zip_unmount", size); + } + if (isDiskOfType(TDEDiskDeviceType::RAM)) { + ret = DesktopIcon("memory", size); + } + if (isDiskOfType(TDEDiskDeviceType::Loop)) { + ret = DesktopIcon("blockdevice", size); + } + + if (isDiskOfType(TDEDiskDeviceType::HDD)) { + ret = DesktopIcon("hdd_unmount", size); + if (checkDiskStatus(TDEDiskDeviceStatus::Removable)) { + ret = DesktopIcon("usbpendrive_unmount", size); + } + if (isDiskOfType(TDEDiskDeviceType::CompactFlash)) { + ret = DesktopIcon("compact_flash_unmount", size); + } + if (isDiskOfType(TDEDiskDeviceType::MemoryStick)) { + ret = DesktopIcon("memory_stick_unmount", size); + } + } + + return ret; +} + unsigned long TDEStorageDevice::deviceSize() { TQString bsnodename = systemPath(); bsnodename.append("/queue/physical_block_size"); @@ -1047,6 +1114,9 @@ TDEGenericDeviceType::TDEGenericDeviceType readGenericDeviceTypeFromString(TQStr else if (query == "Power") { ret = TDEGenericDeviceType::Power; } + else if (query == "Dock") { + ret = TDEGenericDeviceType::Dock; + } else if (query == "ThermalSensor") { ret = TDEGenericDeviceType::ThermalSensor; } @@ -1267,6 +1337,11 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDeviceByExternalRules(udev_ atleastonematch = true; } } + else if (cndit.key() == "DRIVER") { + if (device->deviceDriver() == (*paramit)) { + atleastonematch = true; + } + } else if (readUdevAttribute(dev, cndit.key()) == (*paramit)) { atleastonematch = true; } @@ -1329,6 +1404,7 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD TQString devicesubmodelid(udev_device_get_property_value(dev, "ID_SUBMODEL_ID")); TQString devicetypestring(udev_device_get_property_value(dev, "ID_TYPE")); TQString devicetypestring_alt(udev_device_get_property_value(dev, "DEVTYPE")); + TQString devicepciclass(udev_device_get_property_value(dev, "PCI_CLASS")); bool removable = false; TDEGenericDevice* device = existingdevice; @@ -1395,7 +1471,7 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD } } - // Most of the timeudev doesn't barf up a device driver either, so go after it manually... + // Most of the time udev doesn't barf up a device driver either, so go after it manually... if (devicedriver.isNull()) { TQString driverSymlink = udev_device_get_syspath(dev); TQString driverSymlinkDir = driverSymlink; @@ -1410,12 +1486,34 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD } } + // udev removes critical leading zeroes in the PCI device class, so go after it manually... + TQString classnodename = systempath; + classnodename.append("/class"); + TQFile classfile( classnodename ); + if ( classfile.open( IO_ReadOnly ) ) { + TQTextStream stream( &classfile ); + devicepciclass = stream.readLine(); + devicepciclass.replace("0x", ""); + devicepciclass = devicepciclass.lower(); + classfile.close(); + } + // Classify generic device type and create appropriate object - if ((devicetype == "disk") + + // Pull out all event special devices and stuff them under Platform + TQString syspath_tail = systempath.lower(); + syspath_tail.remove(0, syspath_tail.findRev("/")+1); + if (syspath_tail.startsWith("event")) { + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::Platform); + } + + // Classify specific known devices + if (((devicetype == "disk") || (devicetype == "partition") || (devicedriver == "floppy") - || (devicesubsystem == "scsi_disk") - ) { + || (devicesubsystem == "scsi_disk")) + && ((devicenode != "") + )) { if (!device) device = new TDEStorageDevice(TDEGenericDeviceType::Disk); } else if (devicetype.isNull()) { @@ -1477,14 +1575,16 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD } if ((devicetypestring_alt == "scsi_target") || (devicesubsystem == "scsi_host") + || (devicesubsystem == "scsi_disk") || (devicesubsystem == "scsi_device") || (devicesubsystem == "scsi_generic") || (devicesubsystem == "scsi") || (devicesubsystem == "ata_port") || (devicesubsystem == "ata_link") + || (devicesubsystem == "ata_disk") || (devicesubsystem == "ata_device") || (devicesubsystem == "ata")) { - if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::StorageController); + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::Platform); } if (devicesubsystem == "net") { if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::Network); @@ -1524,8 +1624,50 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD if (devicesubsystem == "pnp") { if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::PNP); } + if ((devicesubsystem == "hid") + || (devicesubsystem == "hidraw")) { + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::HID); + } + + // Moderate accuracy classification, if PCI device class is available + // See http://www.acm.uiuc.edu/sigops/roll_your_own/7.c.1.html for codes and meanings + if (!devicepciclass.isNull()) { + // Pre PCI 2.0 + if (devicepciclass.startsWith("0001")) { + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::GPU); + } + // Post PCI 2.0 + if (devicepciclass.startsWith("01")) { + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::StorageController); + } + if (devicepciclass.startsWith("02")) { + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::Network); + } + if (devicepciclass.startsWith("03")) { + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::GPU); + } + if (devicepciclass.startsWith("04")) { + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::Sound); // FIXME Technically this code is for "multimedia" + } + if (devicepciclass.startsWith("05")) { + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::RAM); + } + if (devicepciclass.startsWith("06")) { + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::Bridge); + } + if (devicepciclass.startsWith("0a")) { + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::Dock); + } + if (devicepciclass.startsWith("0b")) { + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::CPU); + } + if (devicepciclass.startsWith("0c")) { + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::Serial); + } + } - // Most general classification possible + // Last ditch attempt at classification + // Likely inaccurate and sweeping if ((devicesubsystem == "usb") || (devicesubsystem == "usbmon")) { if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::OtherUSB); @@ -1552,6 +1694,7 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD device->setModuleAlias(devicemodalias); device->setDeviceDriver(devicedriver); device->setSubsystem(devicesubsystem); + device->setPCIClass(devicepciclass); updateBlacklists(device, dev); @@ -1812,6 +1955,7 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD device->setSubModelID(devicesubmodelid); device->setDeviceDriver(devicedriver); device->setSubsystem(devicesubsystem); + device->setPCIClass(devicepciclass); return device; } @@ -1960,7 +2104,7 @@ void TDEHardwareDevices::addCoreSystemDevices() { line = line.stripWhiteSpace(); processorNumber = line.toInt(); hwdevice = new TDEGenericDevice(TDEGenericDeviceType::CPU); - hwdevice->setSystemPath(TQString("/sys/devices/virtual/cpu%1").arg(processorNumber)); // FIXME: A system path is required, but I can't give a real unique path to the hardware manager due to kernel limitations + hwdevice->setSystemPath(TQString("/sys/devices/cpu/cpu%1").arg(processorNumber)); // FIXME: A system path is required, but I can't give a real, extant, unique path to the hardware manager due to kernel limitations m_deviceList.append(hwdevice); } if (line.startsWith("model name")) { @@ -2199,118 +2343,121 @@ TQString TDEHardwareDevices::getFriendlyDeviceTypeStringFromType(TDEGenericDevic // Keep this in sync with the TDEGenericDeviceType definition in the header if (query == TDEGenericDeviceType::Root) { - ret = "Root"; + ret = i18n("Root"); } else if (query == TDEGenericDeviceType::CPU) { - ret = "CPU"; + ret = i18n("CPU"); } else if (query == TDEGenericDeviceType::GPU) { - ret = "GPU"; + ret = i18n("Graphics Processor"); } else if (query == TDEGenericDeviceType::RAM) { - ret = "RAM"; + ret = i18n("RAM"); } else if (query == TDEGenericDeviceType::Bus) { - ret = "Bus"; + ret = i18n("Bus"); } else if (query == TDEGenericDeviceType::I2C) { - ret = "I2C Bus"; + ret = i18n("I2C Bus"); } else if (query == TDEGenericDeviceType::MDIO) { - ret = "MDIO Bus"; + ret = i18n("MDIO Bus"); } else if (query == TDEGenericDeviceType::Mainboard) { - ret = "Mainboard"; + ret = i18n("Mainboard"); } else if (query == TDEGenericDeviceType::Disk) { - ret = "Disk"; + ret = i18n("Disk"); } else if (query == TDEGenericDeviceType::SCSI) { - ret = "SCSI"; + ret = i18n("SCSI"); } else if (query == TDEGenericDeviceType::StorageController) { - ret = "Storage Controller"; + ret = i18n("Storage Controller"); } else if (query == TDEGenericDeviceType::Mouse) { - ret = "Mouse"; + ret = i18n("Mouse"); } else if (query == TDEGenericDeviceType::Keyboard) { - ret = "Keyboard"; + ret = i18n("Keyboard"); } else if (query == TDEGenericDeviceType::HID) { - ret = "HID"; + ret = i18n("HID"); } else if (query == TDEGenericDeviceType::Network) { - ret = "Network"; + ret = i18n("Network"); } else if (query == TDEGenericDeviceType::Printer) { - ret = "Printer"; + ret = i18n("Printer"); } else if (query == TDEGenericDeviceType::Scanner) { - ret = "Scanner"; + ret = i18n("Scanner"); } else if (query == TDEGenericDeviceType::Sound) { - ret = "Sound"; + ret = i18n("Sound"); } else if (query == TDEGenericDeviceType::VideoCapture) { - ret = "Video Capture"; + ret = i18n("Video Capture"); } else if (query == TDEGenericDeviceType::IEEE1394) { - ret = "IEEE1394"; + ret = i18n("IEEE1394"); } else if (query == TDEGenericDeviceType::Camera) { - ret = "Camera"; + ret = i18n("Camera"); } else if (query == TDEGenericDeviceType::TextIO) { - ret = "TextIO"; + ret = i18n("Text I/O"); } else if (query == TDEGenericDeviceType::Serial) { - ret = "Serial Port"; + ret = i18n("Serial Communications Controller"); } else if (query == TDEGenericDeviceType::Parallel) { - ret = "Parallel Port"; + ret = i18n("Parallel Port"); } else if (query == TDEGenericDeviceType::Peripheral) { - ret = "Peripheral"; + ret = i18n("Peripheral"); } else if (query == TDEGenericDeviceType::Battery) { - ret = "Battery"; + ret = i18n("Battery"); } else if (query == TDEGenericDeviceType::Power) { - ret = "Power Device"; + ret = i18n("Power Device"); + } + else if (query == TDEGenericDeviceType::Dock) { + ret = i18n("Docking Station"); } else if (query == TDEGenericDeviceType::ThermalSensor) { - ret = "Thermal Sensor"; + ret = i18n("Thermal Sensor"); } else if (query == TDEGenericDeviceType::ThermalControl) { - ret = "Thermal Control"; + ret = i18n("Thermal Control"); } else if (query == TDEGenericDeviceType::Bridge) { - ret = "Bridge"; + ret = i18n("Bridge"); } else if (query == TDEGenericDeviceType::Platform) { - ret = "Platform"; + ret = i18n("Platform"); } else if (query == TDEGenericDeviceType::PNP) { - ret = "Plug and Play"; + ret = i18n("Plug and Play"); } else if (query == TDEGenericDeviceType::OtherACPI) { - ret = "Other ACPI"; + ret = i18n("Other ACPI"); } else if (query == TDEGenericDeviceType::OtherUSB) { - ret = "Other USB"; + ret = i18n("Other USB"); } else if (query == TDEGenericDeviceType::OtherPeripheral) { - ret = "Other Peripheral"; + ret = i18n("Other Peripheral"); } else if (query == TDEGenericDeviceType::OtherSensor) { - ret = "Other Sensor"; + ret = i18n("Other Sensor"); } else if (query == TDEGenericDeviceType::OtherVirtual) { - ret = "Other Virtual"; + ret = i18n("Other Virtual"); } else { - ret = "Unknown Device"; + ret = i18n("Unknown Device"); } return ret; @@ -2401,6 +2548,9 @@ TQPixmap TDEHardwareDevices::getDeviceTypeIconFromType(TDEGenericDeviceType::TDE else if (query == TDEGenericDeviceType::Power) { ret = DesktopIcon("energy", size); } + else if (query == TDEGenericDeviceType::Dock) { + ret = DesktopIcon("kcmdevices", size); // FIXME + } else if (query == TDEGenericDeviceType::ThermalSensor) { ret = DesktopIcon("kcmdevices", size); // FIXME } diff --git a/tdecore/tdehardwaredevices.h b/tdecore/tdehardwaredevices.h index ee47c655a..96ce7a995 100644 --- a/tdecore/tdehardwaredevices.h +++ b/tdecore/tdehardwaredevices.h @@ -69,6 +69,7 @@ enum TDEGenericDeviceType { Peripheral, Battery, Power, + Dock, ThermalSensor, ThermalControl, Bridge, @@ -221,7 +222,7 @@ class TDECORE_EXPORT TDEGenericDevice * While TDE tries very hard to generate and return a friendly name for this device, * sometimes the best it will be able to do is "Unknown Device [xxxx:yyyy]" */ - TQString friendlyName(); + virtual TQString friendlyName(); /** * @return a TQString with the device bus name, if any @@ -316,6 +317,16 @@ class TDECORE_EXPORT TDEGenericDevice */ void setSubModelID(TQString id); + /** + * @return a TQString with the PCI device class, if any + */ + TQString &PCIClass(); + + /** + * @param a TQString with the PCI device class, if any + */ + void setPCIClass(TQString cl); + /** * @return a TQString with the module alias string, if any */ @@ -376,6 +387,7 @@ class TDECORE_EXPORT TDEGenericDevice TQString m_modelID; TQString m_subvendorID; TQString m_submodelID; + TQString m_pciClass; TQString m_modAlias; TQString m_deviceDriver; TQString m_subsystem; @@ -554,6 +566,22 @@ class TDECORE_EXPORT TDEStorageDevice : public TDEGenericDevice */ TQString deviceFriendlySize(); + /** + * Get an icon for this device + * @param size a KIcon::StdSizes structure specifying the desired icon size + * @return a TQPixmap containing the icon for the specified type + * + * This method overrides TDEGenericDevice::icon(KIcon::StdSizes size) + */ + TQPixmap icon(KIcon::StdSizes size); + + /** + * @return a TQString with a friendly name + * + * This method overrides TDEGenericDevice::friendlyName() + */ + TQString friendlyName(); + private: TDEDiskDeviceType::TDEDiskDeviceType m_diskType; TDEDiskDeviceStatus::TDEDiskDeviceStatus m_diskStatus; -- cgit v1.2.1 From 63c292c62f959fd5e9349e3e9413eae01ec6efef Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Fri, 6 Apr 2012 02:39:07 -0500 Subject: Add a couple of convenience functions to the TDE hw lib --- tdecore/tdehardwaredevices.cpp | 11 +++++++++++ tdecore/tdehardwaredevices.h | 10 ++++++++++ 2 files changed, 21 insertions(+) (limited to 'tdecore') diff --git a/tdecore/tdehardwaredevices.cpp b/tdecore/tdehardwaredevices.cpp index 8f33e1480..e95030983 100644 --- a/tdecore/tdehardwaredevices.cpp +++ b/tdecore/tdehardwaredevices.cpp @@ -199,6 +199,17 @@ void TDEGenericDevice::setBlacklistedForUpdate(bool bl) { m_blacklistedForUpdate = bl; } +TQString TDEGenericDevice::friendlyDeviceType() { + return KGlobal::hardwareDevices()->getFriendlyDeviceTypeStringFromType(type()); +} + +TQString TDEGenericDevice::busID() { + TQString busid = m_systemPath; + busid = busid.remove(0, busid.findRev("/")+1); + busid = busid.remove(0, busid.find(":")+1); + return busid; +} + TQString TDEGenericDevice::friendlyName() { if (m_friendlyName.isNull()) { if (type() == TDEGenericDeviceType::Root) { diff --git a/tdecore/tdehardwaredevices.h b/tdecore/tdehardwaredevices.h index 96ce7a995..bf474da3e 100644 --- a/tdecore/tdehardwaredevices.h +++ b/tdecore/tdehardwaredevices.h @@ -367,6 +367,16 @@ class TDECORE_EXPORT TDEGenericDevice */ TDEGenericDevice* parentDevice(); + /** + * @return a TQString containing the friendly type name + */ + TQString friendlyDeviceType(); + + /** + * @return a TQString containing the device bus ID, if any + */ + TQString busID(); + /** * Get an icon for this device * @param size a KIcon::StdSizes structure specifying the desired icon size -- cgit v1.2.1 From 026722768be80478715b102b56005f04823304b5 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Fri, 6 Apr 2012 19:26:01 -0500 Subject: Fix generic multimedia device listing --- tdecore/tdehardwaredevices.cpp | 17 ++++++++++++++++- tdecore/tdehardwaredevices.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'tdecore') diff --git a/tdecore/tdehardwaredevices.cpp b/tdecore/tdehardwaredevices.cpp index e95030983..cf4ffb1ad 100644 --- a/tdecore/tdehardwaredevices.cpp +++ b/tdecore/tdehardwaredevices.cpp @@ -1149,6 +1149,9 @@ TDEGenericDeviceType::TDEGenericDeviceType readGenericDeviceTypeFromString(TQStr else if (query == "OtherUSB") { ret = TDEGenericDeviceType::OtherUSB; } + else if (query == "OtherMultimedia") { + ret = TDEGenericDeviceType::OtherMultimedia; + } else if (query == "OtherPeripheral") { ret = TDEGenericDeviceType::OtherPeripheral; } @@ -1658,7 +1661,7 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::GPU); } if (devicepciclass.startsWith("04")) { - if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::Sound); // FIXME Technically this code is for "multimedia" + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::OtherMultimedia); } if (devicepciclass.startsWith("05")) { if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::RAM); @@ -1956,6 +1959,12 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD sdevice->setDiskLabel(disklabel); } + if (device->type() == TDEGenericDeviceType::Network) { + // Network devices don't have devices nodes per se, but we can at least return the Linux network name... + devicenode = systempath; + devicenode.remove(0, devicenode.findRev("/")+1); + } + // Set basic device information again, as some information may have changed device->setName(devicename); device->setDeviceNode(devicenode); @@ -2458,6 +2467,9 @@ TQString TDEHardwareDevices::getFriendlyDeviceTypeStringFromType(TDEGenericDevic else if (query == TDEGenericDeviceType::OtherUSB) { ret = i18n("Other USB"); } + else if (query == TDEGenericDeviceType::OtherMultimedia) { + ret = i18n("Other Multimedia"); + } else if (query == TDEGenericDeviceType::OtherPeripheral) { ret = i18n("Other Peripheral"); } @@ -2583,6 +2595,9 @@ TQPixmap TDEHardwareDevices::getDeviceTypeIconFromType(TDEGenericDeviceType::TDE else if (query == TDEGenericDeviceType::OtherUSB) { ret = DesktopIcon("usb", size); } + else if (query == TDEGenericDeviceType::OtherMultimedia) { + ret = DesktopIcon("kcmsound", size); + } else if (query == TDEGenericDeviceType::OtherPeripheral) { ret = DesktopIcon("kcmpci", size); } diff --git a/tdecore/tdehardwaredevices.h b/tdecore/tdehardwaredevices.h index bf474da3e..37889f269 100644 --- a/tdecore/tdehardwaredevices.h +++ b/tdecore/tdehardwaredevices.h @@ -77,6 +77,7 @@ enum TDEGenericDeviceType { PNP, OtherACPI, OtherUSB, + OtherMultimedia, OtherPeripheral, OtherSensor, OtherVirtual, -- cgit v1.2.1 From 61531c281ba5d4792481a75eed2e01619e66f4f8 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Fri, 6 Apr 2012 19:55:37 -0500 Subject: Update disk device labeling --- tdecore/tdehardwaredevices.cpp | 100 ++++++++++++++++++++++++++++++++++------- tdecore/tdehardwaredevices.h | 9 +++- 2 files changed, 93 insertions(+), 16 deletions(-) (limited to 'tdecore') diff --git a/tdecore/tdehardwaredevices.cpp b/tdecore/tdehardwaredevices.cpp index cf4ffb1ad..ba2fc5bfb 100644 --- a/tdecore/tdehardwaredevices.cpp +++ b/tdecore/tdehardwaredevices.cpp @@ -346,17 +346,78 @@ void TDEStorageDevice::setSlaveDevices(TQStringList sd) { TQString TDEStorageDevice::friendlyName() { if (isDiskOfType(TDEDiskDeviceType::Floppy)) { - return i18n("Floppy Drive"); + return friendlyDeviceType(); } - else if (isDiskOfType(TDEDiskDeviceType::Zip)) { - return i18n("Zip Drive"); + + TQString label = diskLabel(); + if (label.isNull()) { + if (deviceSize() > 0) { + if (checkDiskStatus(TDEDiskDeviceStatus::Removable)) { + label = i18n("%1 Removable Device").arg(deviceFriendlySize()); + } + else { + label = i18n("%1 Fixed Storage Device").arg(deviceFriendlySize()); + } + } } - else if (isDiskOfType(TDEDiskDeviceType::Optical)) { - return i18n("Optical Drive"); + + if (!label.isNull()) { + return label; } - else { - return TDEGenericDevice::friendlyName(); + + return friendlyDeviceType(); +} + +TQString TDEStorageDevice::friendlyDeviceType() { + TQString ret = i18n("Hard Disk Drive"); + + // Keep this in sync with TDEStorageDevice::icon(KIcon::StdSizes size) below + if (isDiskOfType(TDEDiskDeviceType::Floppy)) { + ret = i18n("Floppy Drive"); + } + if (isDiskOfType(TDEDiskDeviceType::CDROM)) { + ret = i18n("CDROM Drive"); + } + if (isDiskOfType(TDEDiskDeviceType::CDRW)) { + ret = i18n("CDRW Drive"); + } + if (isDiskOfType(TDEDiskDeviceType::DVDROM)) { + ret = i18n("DVD Drive"); + } + if (isDiskOfType(TDEDiskDeviceType::DVDRW) || isDiskOfType(TDEDiskDeviceType::DVDRAM)) { + ret = i18n("DVDRW Drive"); + } + if (isDiskOfType(TDEDiskDeviceType::DVDRW)) { + ret = i18n("DVDRW Drive"); + } + if (isDiskOfType(TDEDiskDeviceType::DVDRAM)) { + ret = i18n("DVDRAM Drive"); + } + if (isDiskOfType(TDEDiskDeviceType::Zip)) { + ret = i18n("Zip Drive"); + } + + if (isDiskOfType(TDEDiskDeviceType::HDD)) { + ret = i18n("Hard Disk Drive"); + if (checkDiskStatus(TDEDiskDeviceStatus::Removable)) { + ret = i18n("Removable Storage"); + } + if (isDiskOfType(TDEDiskDeviceType::CompactFlash)) { + ret = i18n("Compact Flash"); + } + if (isDiskOfType(TDEDiskDeviceType::MemoryStick)) { + ret = i18n("Memory Stick"); + } + } + + if (isDiskOfType(TDEDiskDeviceType::RAM)) { + ret = i18n("Random Access Memory"); + } + if (isDiskOfType(TDEDiskDeviceType::Loop)) { + ret = i18n("Loop Device"); } + + return ret; } TQPixmap TDEStorageDevice::icon(KIcon::StdSizes size) { @@ -374,18 +435,15 @@ TQPixmap TDEStorageDevice::icon(KIcon::StdSizes size) { if (isDiskOfType(TDEDiskDeviceType::DVDROM)) { ret = DesktopIcon("dvd_unmount", size); } - if (isDiskOfType(TDEDiskDeviceType::DVDRW) || isDiskOfType(TDEDiskDeviceType::DVDRAM)) { + if (isDiskOfType(TDEDiskDeviceType::DVDRW)) { + ret = DesktopIcon("dvd_unmount", size); + } + if (isDiskOfType(TDEDiskDeviceType::DVDRAM)) { ret = DesktopIcon("dvd_unmount", size); } if (isDiskOfType(TDEDiskDeviceType::Zip)) { ret = DesktopIcon("zip_unmount", size); } - if (isDiskOfType(TDEDiskDeviceType::RAM)) { - ret = DesktopIcon("memory", size); - } - if (isDiskOfType(TDEDiskDeviceType::Loop)) { - ret = DesktopIcon("blockdevice", size); - } if (isDiskOfType(TDEDiskDeviceType::HDD)) { ret = DesktopIcon("hdd_unmount", size); @@ -400,6 +458,13 @@ TQPixmap TDEStorageDevice::icon(KIcon::StdSizes size) { } } + if (isDiskOfType(TDEDiskDeviceType::RAM)) { + ret = DesktopIcon("memory", size); + } + if (isDiskOfType(TDEDiskDeviceType::Loop)) { + ret = DesktopIcon("blockdevice", size); + } + return ret; } @@ -1560,7 +1625,12 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD } } else if (devicesubsystem == "tty") { - if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::TextIO); + if (devicenode.contains("/ttyS")) { + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::Serial); + } + else { + if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::TextIO); + } } else if (devicesubsystem == "thermal") { // FIXME diff --git a/tdecore/tdehardwaredevices.h b/tdecore/tdehardwaredevices.h index 37889f269..f284a7d0c 100644 --- a/tdecore/tdehardwaredevices.h +++ b/tdecore/tdehardwaredevices.h @@ -371,7 +371,7 @@ class TDECORE_EXPORT TDEGenericDevice /** * @return a TQString containing the friendly type name */ - TQString friendlyDeviceType(); + virtual TQString friendlyDeviceType(); /** * @return a TQString containing the device bus ID, if any @@ -593,6 +593,13 @@ class TDECORE_EXPORT TDEStorageDevice : public TDEGenericDevice */ TQString friendlyName(); + /** + * @return a TQString containing the friendly type name + * + * This method overrides TDEGenericDevice::friendlyDeviceType() + */ + TQString friendlyDeviceType(); + private: TDEDiskDeviceType::TDEDiskDeviceType m_diskType; TDEDiskDeviceStatus::TDEDiskDeviceStatus m_diskStatus; -- cgit v1.2.1