19 #include <tdehardwaredevices.h>
23 #include <tqstringlist.h>
24 #include <tqsocketnotifier.h>
26 #include <tdeglobal.h>
28 #include <tdeconfig.h>
29 #include <tdetempfile.h>
30 #include <ksimpledirwatch.h>
31 #include <kstandarddirs.h>
33 #include <tdeapplication.h>
34 #include <dcopclient.h>
41 #include <sys/ioctl.h>
43 #include <linux/cdrom.h>
49 #include <linux/input.h>
52 #include <sys/types.h>
54 #include <netinet/in.h>
55 #include <arpa/inet.h>
56 #include <arpa/inet.h>
57 #include <sys/socket.h>
61 #include "tdenetworkconnections.h"
66 #ifdef WITH_NETWORK_MANAGER_BACKEND
67 #include "networkbackends/network-manager/network-manager.h"
68 #endif // WITH_NETWORK_MANAGER_BACKEND
71 #if defined(WITH_UPOWER) || defined(WITH_UDISKS) || defined(WITH_UDISKS2)
72 #include <tqdbusdata.h>
73 #include <tqdbusmessage.h>
74 #include <tqdbusproxy.h>
75 #include <tqdbusvariant.h>
76 #include <tqdbusconnection.h>
77 #endif // defined(WITH_UPOWER) || defined(WITH_UDISKS) || defined(WITH_UDISKS2)
78 #if defined(WITH_UDISKS) || defined(WITH_UDISKS2)
79 #include <tqdbuserror.h>
80 #include <tqdbusdatamap.h>
81 #include <tqdbusobjectpath.h>
82 #endif // defined(WITH_UDISKS) || defined(WITH_UDISKS2)
83 #if defined(WITH_UDISKS)
84 #include "tqdbusdatalist.h"
85 #endif // ddefined(WITH_UDISKS)
89 #define GENHD_FL_REMOVABLE 1
90 #define GENHD_FL_MEDIA_CHANGE_NOTIFY 4
92 #define GENHD_FL_UP 16
93 #define GENHD_FL_SUPPRESS_PARTITION_INFO 32
94 #define GENHD_FL_EXT_DEVT 64
95 #define GENHD_FL_NATIVE_CAPACITY 128
96 #define GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE 256
105 unsigned int reverse_bits(
register unsigned int x)
107 x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1));
108 x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2));
109 x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4));
110 x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8));
111 return((x >> 16) | (x << 16));
114 #define BIT_IS_SET(bits, n) (bits[n >> 3] & (1 << (n & 0x7)))
116 TDESensorCluster::TDESensorCluster() {
117 label = TQString::null;
125 TDEGenericDevice::TDEGenericDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TQObject() {
130 m_friendlyName = TQString::null;
131 m_blacklistedForUpdate =
false;
134 TDEGenericDevice::~TDEGenericDevice() {
137 TDEGenericDeviceType::TDEGenericDeviceType TDEGenericDevice::type() {
141 TQString TDEGenericDevice::name() {
145 void TDEGenericDevice::internalSetName(TQString dn) {
149 TQString TDEGenericDevice::vendorName() {
153 void TDEGenericDevice::internalSetVendorName(TQString vn) {
157 TQString TDEGenericDevice::vendorModel() {
158 return m_vendorModel;
161 void TDEGenericDevice::internalSetVendorModel(TQString vm) {
165 TQString TDEGenericDevice::serialNumber() {
166 return m_serialNumber;
169 void TDEGenericDevice::internalSetSerialNumber(TQString sn) {
173 TQString TDEGenericDevice::systemPath() {
174 if (!m_systemPath.endsWith(
"/")) {
180 void TDEGenericDevice::internalSetSystemPath(TQString sp) {
184 TQString TDEGenericDevice::deviceNode() {
188 void TDEGenericDevice::internalSetDeviceNode(TQString sn) {
192 TQString TDEGenericDevice::deviceBus() {
196 void TDEGenericDevice::internalSetDeviceBus(TQString db) {
200 TQString TDEGenericDevice::uniqueID() {
201 m_uniqueID = m_systemPath+m_deviceNode;
205 TQString TDEGenericDevice::vendorID() {
209 void TDEGenericDevice::internalSetVendorID(TQString
id) {
211 m_vendorID.replace(
"0x",
"");
214 TQString TDEGenericDevice::modelID() {
218 void TDEGenericDevice::internalSetModelID(TQString
id) {
220 m_modelID.replace(
"0x",
"");
223 TQString TDEGenericDevice::vendorEncoded() {
227 void TDEGenericDevice::internalSetVendorEncoded(TQString
id) {
231 TQString TDEGenericDevice::modelEncoded() {
235 void TDEGenericDevice::internalSetModelEncoded(TQString
id) {
239 TQString TDEGenericDevice::subVendorID() {
240 return m_subvendorID;
243 void TDEGenericDevice::internalSetSubVendorID(TQString
id) {
245 m_subvendorID.replace(
"0x",
"");
248 TQString TDEGenericDevice::PCIClass() {
252 void TDEGenericDevice::internalSetPCIClass(TQString cl) {
254 m_pciClass.replace(
"0x",
"");
257 TQString TDEGenericDevice::moduleAlias() {
261 void TDEGenericDevice::internalSetModuleAlias(TQString ma) {
265 TQString TDEGenericDevice::deviceDriver() {
266 return m_deviceDriver;
269 void TDEGenericDevice::internalSetDeviceDriver(TQString dr) {
273 TQString TDEGenericDevice::subsystem() {
277 void TDEGenericDevice::internalSetSubsystem(TQString ss) {
281 TQString TDEGenericDevice::subModelID() {
285 void TDEGenericDevice::internalSetSubModelID(TQString
id) {
287 m_submodelID.replace(
"0x",
"");
290 void TDEGenericDevice::internalSetParentDevice(TDEGenericDevice* pd) {
294 TDEGenericDevice* TDEGenericDevice::parentDevice() {
295 return m_parentDevice;
302 bool TDEGenericDevice::blacklistedForUpdate() {
303 return m_blacklistedForUpdate;
306 void TDEGenericDevice::internalSetBlacklistedForUpdate(
bool bl) {
307 m_blacklistedForUpdate = bl;
310 TQString TDEGenericDevice::friendlyDeviceType() {
314 TQString TDEGenericDevice::busID() {
315 TQString busid = m_systemPath;
316 busid = busid.remove(0, busid.findRev(
"/")+1);
317 busid = busid.remove(0, busid.find(
":")+1);
321 TQString TDEGenericDevice::friendlyName() {
322 if (m_friendlyName.isNull()) {
323 if (type() == TDEGenericDeviceType::RootSystem) {
324 m_friendlyName =
"Linux System";
326 else if (type() == TDEGenericDeviceType::Root) {
327 TQString friendlyDriverName = systemPath();
328 friendlyDriverName.truncate(friendlyDriverName.length()-1);
329 friendlyDriverName.remove(0, friendlyDriverName.findRev(
"/")+1);
330 m_friendlyName = friendlyDriverName;
332 else if (m_modAlias.lower().startsWith(
"pci")) {
335 else if (m_modAlias.lower().startsWith(
"usb")) {
339 TQString acpigentype = systemPath();
340 acpigentype.truncate(acpigentype.length()-1);
341 acpigentype.remove(0, acpigentype.findRev(
"/")+1);
342 TQString pnpgentype = acpigentype;
343 pnpgentype.truncate(pnpgentype.find(
":"));
344 if (pnpgentype.startsWith(
"PNP")) {
347 else if (acpigentype.startsWith(
"device:")) {
348 acpigentype.remove(0, acpigentype.findRev(
":")+1);
349 acpigentype.prepend(
"0x");
350 m_friendlyName =
i18n(
"ACPI Node %1").arg(acpigentype.toUInt(0,0));
355 if (m_friendlyName.isNull()) {
358 if (!m_vendorName.isNull() && !m_vendorModel.isNull()) {
359 m_friendlyName = m_vendorName +
" " + m_vendorModel;
363 if (m_friendlyName.isNull()) {
366 if (type() == TDEGenericDeviceType::CPU) {
367 m_friendlyName =
name();
369 else if (type() == TDEGenericDeviceType::Event) {
371 if (m_parentDevice) {
372 return m_parentDevice->friendlyName();
375 m_friendlyName =
i18n(
"Generic Event Device");
378 else if (type() == TDEGenericDeviceType::Input) {
380 if (m_parentDevice) {
381 return m_parentDevice->friendlyName();
384 m_friendlyName =
i18n(
"Generic Input Device");
388 else if (!m_deviceDriver.isNull()) {
389 TQString friendlyDriverName = m_deviceDriver.lower();
390 friendlyDriverName[0] = friendlyDriverName[0].upper();
391 m_friendlyName =
i18n(
"Generic %1 Device").arg(friendlyDriverName);
393 else if (m_systemPath.lower().startsWith(
"/sys/devices/virtual")) {
394 TQString friendlyDriverName = systemPath();
395 friendlyDriverName.truncate(friendlyDriverName.length()-1);
396 friendlyDriverName.remove(0, friendlyDriverName.findRev(
"/")+1);
397 if (!friendlyDriverName.isNull()) {
398 m_friendlyName =
i18n(
"Virtual Device %1").arg(friendlyDriverName);
401 m_friendlyName =
i18n(
"Unknown Virtual Device");
406 m_friendlyName =
i18n(
"Unknown Device") +
" " +
name();
410 return m_friendlyName;
413 TDEStorageDevice::TDEStorageDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn), m_mediaInserted(true) {
414 m_diskType = TDEDiskDeviceType::Null;
415 m_diskStatus = TDEDiskDeviceStatus::Null;
418 TDEStorageDevice::~TDEStorageDevice() {
421 TDEDiskDeviceType::TDEDiskDeviceType TDEStorageDevice::diskType() {
425 void TDEStorageDevice::internalSetDiskType(TDEDiskDeviceType::TDEDiskDeviceType dt) {
429 bool TDEStorageDevice::isDiskOfType(TDEDiskDeviceType::TDEDiskDeviceType tf) {
430 return ((m_diskType&tf)!=TDEDiskDeviceType::Null);
433 TDEDiskDeviceStatus::TDEDiskDeviceStatus TDEStorageDevice::diskStatus() {
437 void TDEStorageDevice::internalSetDiskStatus(TDEDiskDeviceStatus::TDEDiskDeviceStatus st) {
441 bool TDEStorageDevice::checkDiskStatus(TDEDiskDeviceStatus::TDEDiskDeviceStatus sf) {
442 return ((m_diskStatus&sf)!=(TDEDiskDeviceStatus::TDEDiskDeviceStatus)0);
445 bool TDEStorageDevice::lockDriveMedia(
bool lock) {
446 int fd =
open(deviceNode().ascii(), O_RDWR | O_NONBLOCK);
450 if (ioctl(fd, CDROM_LOCKDOOR, (lock)?1:0) != 0) {
460 bool ejectDriveUDisks(TDEStorageDevice* sdevice) {
462 TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
463 if (dbusConn.isConnected()) {
464 TQString blockDeviceString = sdevice->deviceNode();
465 blockDeviceString.replace(
"/dev/",
"");
466 blockDeviceString =
"/org/freedesktop/UDisks/devices/" + blockDeviceString;
470 TQT_DBusProxy driveControl(
"org.freedesktop.UDisks", blockDeviceString,
"org.freedesktop.UDisks.Device", dbusConn);
471 if (driveControl.canSend()) {
472 TQValueList<TQT_DBusData> params;
473 TQT_DBusDataList options;
474 params << TQT_DBusData::fromList(options);
475 TQT_DBusMessage reply = driveControl.sendWithReply(
"DriveEject", params, &error);
476 if (error.isValid()) {
478 printf(
"[ERROR] %s\n", error.name().ascii()); fflush(stdout);
494 #endif // WITH_UDISKS
497 bool ejectDriveUDisks2(TDEStorageDevice* sdevice) {
499 TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
500 if (dbusConn.isConnected()) {
501 TQString blockDeviceString = sdevice->deviceNode();
502 blockDeviceString.replace(
"/dev/",
"");
503 blockDeviceString =
"/org/freedesktop/UDisks2/block_devices/" + blockDeviceString;
504 TQT_DBusProxy hardwareControl(
"org.freedesktop.UDisks2", blockDeviceString,
"org.freedesktop.DBus.Properties", dbusConn);
505 if (hardwareControl.canSend()) {
508 TQValueList<TQT_DBusData> params;
509 params << TQT_DBusData::fromString(
"org.freedesktop.UDisks2.Block") << TQT_DBusData::fromString(
"Drive");
510 TQT_DBusMessage reply = hardwareControl.sendWithReply(
"Get", params, &error);
511 if (error.isValid()) {
513 printf(
"[ERROR] %s\n", error.name().ascii()); fflush(stdout);
517 if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
518 TQT_DBusObjectPath driveObjectPath = reply[0].toVariant().value.toObjectPath();
519 if (!driveObjectPath.isValid()) {
523 error = TQT_DBusError();
524 TQT_DBusProxy driveInformation(
"org.freedesktop.UDisks2", driveObjectPath,
"org.freedesktop.DBus.Properties", dbusConn);
526 TQValueList<TQT_DBusData> params;
527 params << TQT_DBusData::fromString(
"org.freedesktop.UDisks2.Drive") << TQT_DBusData::fromString(
"Ejectable");
528 TQT_DBusMessage reply = driveInformation.sendWithReply(
"Get", params, &error);
529 if (error.isValid()) {
531 printf(
"[ERROR] %s\n", error.name().ascii()); fflush(stdout);
534 if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
535 bool ejectable = reply[0].toVariant().value.toBool();
541 TQT_DBusProxy driveControl(
"org.freedesktop.UDisks2", driveObjectPath,
"org.freedesktop.UDisks2.Drive", dbusConn);
542 TQValueList<TQT_DBusData> params;
543 TQT_DBusDataMap<TQString> options(TQT_DBusData::Variant);
544 params << TQT_DBusData::fromStringKeyMap(options);
545 TQT_DBusMessage reply = driveControl.sendWithReply(
"Eject", params, &error);
546 if (error.isValid()) {
548 printf(
"[ERROR] %s\n", error.name().ascii()); fflush(stdout);
571 #else // WITH_UDISKS2
573 #endif // WITH_UDISKS2
576 bool TDEStorageDevice::ejectDrive() {
577 if (ejectDriveUDisks2(
this)) {
582 printf(
"[tdehwlib] Failed to eject drive '%s' via udisks2, falling back to alternate mechanism\n", deviceNode().ascii());
583 #endif // WITH_UDISKS2
584 if (ejectDriveUDisks(
this)) {
589 printf(
"[tdehwlib] Failed to eject drive '%s' via udisks, falling back to alternate mechanism\n", deviceNode().ascii());
590 #endif // WITH_UDISKS
591 TQString command = TQString(
"eject -v '%1' 2>&1").arg(deviceNode());
593 FILE *exepipe = popen(command.ascii(),
"r");
595 TQString pmount_output;
597 pmount_output = fgets(buffer,
sizeof(buffer), exepipe);
598 int retcode = pclose(exepipe);
603 printf(
"[tdehwlib] Failed to eject drive '%s' via 'eject' command\n", deviceNode().ascii());
608 printf(
"[tdehwlib] Failed to eject drive '%s' via 'eject' command\n", deviceNode().ascii());
615 bool TDEStorageDevice::ejectDriveMedia() {
616 int fd =
open(deviceNode().ascii(), O_RDWR | O_NONBLOCK);
620 if (ioctl(fd, CDROMEJECT) != 0) {
630 TQString TDEStorageDevice::diskLabel() {
634 void TDEStorageDevice::internalSetDiskLabel(TQString dn) {
638 bool TDEStorageDevice::mediaInserted() {
639 return m_mediaInserted;
642 void TDEStorageDevice::internalSetMediaInserted(
bool inserted) {
643 m_mediaInserted = inserted;
646 TQString TDEStorageDevice::fileSystemName() {
647 return m_fileSystemName;
650 void TDEStorageDevice::internalSetFileSystemName(TQString fn) {
651 m_fileSystemName = fn;
654 TQString TDEStorageDevice::fileSystemUsage() {
655 return m_fileSystemUsage;
658 void TDEStorageDevice::internalSetFileSystemUsage(TQString fu) {
659 m_fileSystemUsage = fu;
662 TQString TDEStorageDevice::diskUUID() {
666 void TDEStorageDevice::internalSetDiskUUID(TQString
id) {
670 TQStringList TDEStorageDevice::holdingDevices() {
671 return m_holdingDevices;
674 void TDEStorageDevice::internalSetHoldingDevices(TQStringList hd) {
675 m_holdingDevices = hd;
678 TQStringList TDEStorageDevice::slaveDevices() {
679 return m_slaveDevices;
682 void TDEStorageDevice::internalSetSlaveDevices(TQStringList sd) {
686 TQString TDEStorageDevice::friendlyName() {
688 TQString devicevendorid = vendorEncoded();
689 TQString devicemodelid = modelEncoded();
691 devicevendorid.replace(
"\\x20",
" ");
692 devicemodelid.replace(
"\\x20",
" ");
694 devicevendorid = devicevendorid.stripWhiteSpace();
695 devicemodelid = devicemodelid.stripWhiteSpace();
696 devicevendorid = devicevendorid.simplifyWhiteSpace();
697 devicemodelid = devicemodelid.simplifyWhiteSpace();
699 TQString devicename = devicevendorid +
" " + devicemodelid;
701 devicename = devicename.stripWhiteSpace();
702 devicename = devicename.simplifyWhiteSpace();
704 if (devicename !=
"") {
708 if (isDiskOfType(TDEDiskDeviceType::Camera)) {
709 return TDEGenericDevice::friendlyName();
712 if (isDiskOfType(TDEDiskDeviceType::Floppy)) {
713 return friendlyDeviceType();
716 TQString
label = diskLabel();
717 if (label.isNull()) {
718 if (deviceSize() > 0) {
719 if (checkDiskStatus(TDEDiskDeviceStatus::Hotpluggable)) {
720 label =
i18n(
"%1 Removable Device").arg(deviceFriendlySize());
723 label =
i18n(
"%1 Fixed Storage Device").arg(deviceFriendlySize());
728 if (!label.isNull()) {
732 return friendlyDeviceType();
735 TQString TDEStorageDevice::friendlyDeviceType() {
736 TQString ret =
i18n(
"Hard Disk Drive");
739 if (isDiskOfType(TDEDiskDeviceType::Floppy)) {
740 ret =
i18n(
"Floppy Drive");
742 if (isDiskOfType(TDEDiskDeviceType::Optical)) {
743 ret =
i18n(
"Optical Drive");
745 if (isDiskOfType(TDEDiskDeviceType::CDROM)) {
746 ret =
i18n(
"CDROM Drive");
748 if (isDiskOfType(TDEDiskDeviceType::CDRW)) {
749 ret =
i18n(
"CDRW Drive");
751 if (isDiskOfType(TDEDiskDeviceType::DVDROM)) {
752 ret =
i18n(
"DVD Drive");
754 if (isDiskOfType(TDEDiskDeviceType::DVDRW)) {
755 ret =
i18n(
"DVDRW Drive");
757 if (isDiskOfType(TDEDiskDeviceType::DVDRAM)) {
758 ret =
i18n(
"DVDRAM Drive");
760 if (isDiskOfType(TDEDiskDeviceType::Zip)) {
761 ret =
i18n(
"Zip Drive");
763 if (isDiskOfType(TDEDiskDeviceType::Tape)) {
764 ret =
i18n(
"Tape Drive");
766 if (isDiskOfType(TDEDiskDeviceType::Camera)) {
767 ret =
i18n(
"Digital Camera");
770 if (isDiskOfType(TDEDiskDeviceType::HDD)) {
771 ret =
i18n(
"Hard Disk Drive");
772 if (checkDiskStatus(TDEDiskDeviceStatus::Hotpluggable)) {
773 ret =
i18n(
"Removable Storage");
775 if (isDiskOfType(TDEDiskDeviceType::CompactFlash)) {
776 ret =
i18n(
"Compact Flash");
778 if (isDiskOfType(TDEDiskDeviceType::MemoryStick)) {
779 ret =
i18n(
"Memory Stick");
781 if (isDiskOfType(TDEDiskDeviceType::SmartMedia)) {
782 ret =
i18n(
"Smart Media");
784 if (isDiskOfType(TDEDiskDeviceType::SDMMC)) {
785 ret =
i18n(
"Secure Digital");
789 if (isDiskOfType(TDEDiskDeviceType::RAM)) {
790 ret =
i18n(
"Random Access Memory");
792 if (isDiskOfType(TDEDiskDeviceType::Loop)) {
793 ret =
i18n(
"Loop Device");
802 if (isDiskOfType(TDEDiskDeviceType::Floppy)) {
805 if (isDiskOfType(TDEDiskDeviceType::Optical)) {
808 if (isDiskOfType(TDEDiskDeviceType::CDROM)) {
811 if (isDiskOfType(TDEDiskDeviceType::CDRW)) {
814 if (isDiskOfType(TDEDiskDeviceType::DVDROM)) {
817 if (isDiskOfType(TDEDiskDeviceType::DVDRW)) {
820 if (isDiskOfType(TDEDiskDeviceType::DVDRAM)) {
823 if (isDiskOfType(TDEDiskDeviceType::Zip)) {
826 if (isDiskOfType(TDEDiskDeviceType::Tape)) {
829 if (isDiskOfType(TDEDiskDeviceType::Camera)) {
833 if (isDiskOfType(TDEDiskDeviceType::HDD)) {
835 if (checkDiskStatus(TDEDiskDeviceStatus::Hotpluggable)) {
838 if (isDiskOfType(TDEDiskDeviceType::CompactFlash)) {
841 if (isDiskOfType(TDEDiskDeviceType::MemoryStick)) {
844 if (isDiskOfType(TDEDiskDeviceType::SmartMedia)) {
847 if (isDiskOfType(TDEDiskDeviceType::SDMMC)) {
852 if (isDiskOfType(TDEDiskDeviceType::RAM)) {
855 if (isDiskOfType(TDEDiskDeviceType::Loop)) {
862 unsigned long long TDEStorageDevice::deviceSize() {
863 TQString bsnodename = systemPath();
864 bsnodename.append(
"/queue/physical_block_size");
865 TQFile bsfile( bsnodename );
867 if ( bsfile.open( IO_ReadOnly ) ) {
868 TQTextStream stream( &bsfile );
869 blocksize = stream.readLine();
877 TQString dsnodename = systemPath();
878 dsnodename.append(
"/size");
879 TQFile dsfile( dsnodename );
881 if ( dsfile.open( IO_ReadOnly ) ) {
882 TQTextStream stream( &dsfile );
883 devicesize = stream.readLine();
887 return ((
unsigned long long)blocksize.toULong()*(
unsigned long long)devicesize.toULong());
890 TQString TDEStorageDevice::deviceFriendlySize() {
891 return TDEHardwareDevices::bytesToFriendlySizeString(deviceSize());
894 TQString TDEStorageDevice::mountPath() {
905 TQString dmnodename = systemPath();
906 dmnodename.append(
"/dm/name");
907 TQFile namefile( dmnodename );
909 if ( namefile.open( IO_ReadOnly ) ) {
910 TQTextStream stream( &namefile );
911 dmaltname = stream.readLine();
914 if (!dmaltname.isNull()) {
915 dmaltname.prepend(
"/dev/mapper/");
919 TQFile file(
"/proc/mounts" );
920 if ( file.open( IO_ReadOnly ) ) {
921 TQTextStream stream( &file );
923 while ( !stream.atEnd() ) {
924 line = stream.readLine();
925 TQStringList mountInfo = TQStringList::split(
" ", line,
true);
926 TQString testNode = *mountInfo.at(0);
928 if ((testNode == deviceNode()) || (testNode == dmaltname) || (testNode == (
"/dev/disk/by-uuid/" + diskUUID()))) {
929 TQString ret = *mountInfo.at(1);
930 ret.replace(
"\\040",
" ");
940 TQStringList slaveDeviceList = holdingDevices();
941 for ( TQStringList::Iterator slavedevit = slaveDeviceList.begin(); slavedevit != slaveDeviceList.end(); ++slavedevit ) {
944 TDEGenericDevice *hwdevice = hwdevices->findBySystemPath(*slavedevit);
945 if ((hwdevice) && (hwdevice->type() == TDEGenericDeviceType::Disk)) {
946 TDEStorageDevice* sdevice =
static_cast<TDEStorageDevice*
>(hwdevice);
947 return sdevice->mountPath();
951 return TQString::null;
954 TQString TDEStorageDevice::mountDevice(TQString mediaName, TQString mountOptions, TQString* errRet,
int* retcode) {
955 int internal_retcode;
957 retcode = &internal_retcode;
960 TQString ret = mountPath();
967 KTempFile passwordFile(TQString::null,
"tmp", 0600);
968 passwordFile.setAutoDelete(
true);
970 TQString passFileName = passwordFile.name();
971 TQString devNode = deviceNode();
972 passFileName.replace(
"'",
"'\\''");
973 devNode.replace(
"'",
"'\\''");
974 mediaName.replace(
"'",
"'\\''");
975 TQString command = TQString(
"pmount -p '%1' %2 '%3' '%4' 2>&1").arg(passFileName).arg(mountOptions).arg(devNode).arg(mediaName);
977 FILE *exepipe = popen(command.ascii(),
"r");
979 TQString pmount_output;
981 pmount_output = fgets(buffer,
sizeof(buffer), exepipe);
982 *retcode = pclose(exepipe);
984 *errRet = pmount_output;
996 TQString TDEStorageDevice::mountEncryptedDevice(TQString passphrase, TQString mediaName, TQString mountOptions, TQString* errRet,
int* retcode) {
997 int internal_retcode;
999 retcode = &internal_retcode;
1002 TQString ret = mountPath();
1004 if (!ret.isNull()) {
1009 KTempFile passwordFile(TQString::null,
"tmp", 0600);
1010 passwordFile.setAutoDelete(
true);
1011 TQFile* pwFile = passwordFile.file();
1013 return TQString::null;
1016 pwFile->writeBlock(passphrase.ascii(), passphrase.length());
1019 TQString passFileName = passwordFile.name();
1020 TQString devNode = deviceNode();
1021 passFileName.replace(
"'",
"'\\''");
1022 devNode.replace(
"'",
"'\\''");
1023 mediaName.replace(
"'",
"'\\''");
1024 TQString command = TQString(
"pmount -p '%1' %2 '%3' '%4' 2>&1").arg(passFileName).arg(mountOptions).arg(devNode).arg(mediaName);
1026 FILE *exepipe = popen(command.ascii(),
"r");
1028 TQString pmount_output;
1030 pmount_output = fgets(buffer,
sizeof(buffer), exepipe);
1031 *retcode = pclose(exepipe);
1033 *errRet = pmount_output;
1045 bool TDEStorageDevice::unmountDevice(TQString* errRet,
int* retcode) {
1046 int internal_retcode;
1048 retcode = &internal_retcode;
1051 TQString mountpoint = mountPath();
1053 if (mountpoint.isNull()) {
1057 mountpoint.replace(
"'",
"'\\''");
1058 TQString command = TQString(
"pumount '%1' 2>&1").arg(mountpoint);
1059 FILE *exepipe = popen(command.ascii(),
"r");
1061 TQString pmount_output;
1063 pmount_output = fgets(buffer,
sizeof(buffer), exepipe);
1064 *retcode = pclose(exepipe);
1065 if (*retcode == 0) {
1070 *errRet = pmount_output;
1081 TDECPUDevice::TDECPUDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) {
1083 m_minfrequency = -1;
1084 m_maxfrequency = -1;
1086 m_transitionlatency = -1;
1089 TDECPUDevice::~TDECPUDevice() {
1092 double TDECPUDevice::frequency() {
1096 void TDECPUDevice::internalSetFrequency(
double fr) {
1100 double TDECPUDevice::minFrequency() {
1101 return m_minfrequency;
1104 void TDECPUDevice::internalSetMinFrequency(
double fr) {
1105 m_minfrequency = fr;
1108 double TDECPUDevice::maxFrequency() {
1109 return m_maxfrequency;
1112 void TDECPUDevice::internalSetMaxFrequency(
double fr) {
1113 m_maxfrequency = fr;
1116 double TDECPUDevice::transitionLatency() {
1117 return m_transitionlatency;
1120 void TDECPUDevice::internalSetTransitionLatency(
double tl) {
1121 m_transitionlatency = tl;
1124 TQString TDECPUDevice::governor() {
1128 void TDECPUDevice::internalSetGovernor(TQString gr) {
1132 TQString TDECPUDevice::scalingDriver() {
1133 return m_scalingdriver;
1136 void TDECPUDevice::internalSetScalingDriver(TQString dr) {
1137 m_scalingdriver = dr;
1140 TQStringList TDECPUDevice::dependentProcessors() {
1144 void TDECPUDevice::internalSetDependentProcessors(TQStringList dp) {
1148 TQStringList TDECPUDevice::availableFrequencies() {
1149 return m_frequencies;
1152 void TDECPUDevice::internalSetAvailableFrequencies(TQStringList af) {
1156 TQStringList TDECPUDevice::availableGovernors() {
1160 void TDECPUDevice::internalSetAvailableGovernors(TQStringList gp) {
1164 void TDECPUDevice::internalSetCoreNumber(
int cn) {
1168 bool TDECPUDevice::canSetGovernor() {
1169 TQString governornode = systemPath() +
"/cpufreq/scaling_governor";
1170 int rval = access (governornode.ascii(), W_OK);
1176 TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
1177 if (dbusConn.isConnected()) {
1178 TQT_DBusProxy hardwareControl(
"org.trinitydesktop.hardwarecontrol",
"/org/trinitydesktop/hardwarecontrol",
"org.trinitydesktop.hardwarecontrol.CPUGovernor", dbusConn);
1179 if (hardwareControl.canSend()) {
1181 TQValueList<TQT_DBusData> params;
1182 params << TQT_DBusData::fromInt32(coreNumber());
1183 TQT_DBusMessage reply = hardwareControl.sendWithReply(
"CanSetCPUGovernor", params);
1184 if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
1185 return reply[0].toVariant().value.toBool();
1198 #else // WITH_UPOWER
1200 #endif// WITH_UPOWER
1204 void TDECPUDevice::setGovernor(TQString gv) {
1205 TQString governornode = systemPath() +
"/cpufreq/scaling_governor";
1206 TQFile file( governornode );
1207 if ( file.open( IO_WriteOnly ) ) {
1208 TQTextStream stream( &file );
1209 stream << gv.lower();
1214 TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
1215 if (dbusConn.isConnected()) {
1216 TQT_DBusProxy hardwareControl(
"org.trinitydesktop.hardwarecontrol",
"/org/trinitydesktop/hardwarecontrol",
"org.trinitydesktop.hardwarecontrol.CPUGovernor", dbusConn);
1217 if (hardwareControl.canSend()) {
1219 TQValueList<TQT_DBusData> params;
1220 params << TQT_DBusData::fromInt32(coreNumber()) << TQT_DBusData::fromString(gv.lower());
1221 hardwareControl.sendWithReply(
"SetCPUGovernor", params);
1231 #endif // WITH_UPOWER
1237 bool TDECPUDevice::canSetMaximumScalingFrequency() {
1238 TQString freqnode = systemPath() +
"/cpufreq/scaling_max_freq";
1239 int rval = access (freqnode.ascii(), W_OK);
1248 void TDECPUDevice::setMaximumScalingFrequency(
double fr) {
1249 TQString freqnode = systemPath() +
"/cpufreq/scaling_max_freq";
1250 TQFile file( freqnode );
1251 if ( file.open( IO_WriteOnly ) ) {
1252 TQTextStream stream( &file );
1253 stream << TQString(
"%1").arg(fr*1000000.0, 0,
'f', 0);
1261 int TDECPUDevice::coreNumber() {
1262 return m_corenumber;
1265 TDESensorDevice::TDESensorDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) {
1268 TDESensorDevice::~TDESensorDevice() {
1271 TDESensorClusterMap TDESensorDevice::values() {
1272 return m_sensorValues;
1275 void TDESensorDevice::internalSetValues(TDESensorClusterMap cl) {
1276 m_sensorValues = cl;
1279 TDERootSystemDevice::TDERootSystemDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) {
1280 m_hibernationSpace = -1;
1283 TDERootSystemDevice::~TDERootSystemDevice() {
1286 TDESystemFormFactor::TDESystemFormFactor TDERootSystemDevice::formFactor() {
1287 return m_formFactor;
1290 void TDERootSystemDevice::internalSetFormFactor(TDESystemFormFactor::TDESystemFormFactor ff) {
1294 TDESystemPowerStateList TDERootSystemDevice::powerStates() {
1295 return m_powerStates;
1298 void TDERootSystemDevice::internalSetPowerStates(TDESystemPowerStateList ps) {
1302 TDESystemHibernationMethodList TDERootSystemDevice::hibernationMethods() {
1303 return m_hibernationMethods;
1306 void TDERootSystemDevice::internalSetHibernationMethods(TDESystemHibernationMethodList hm) {
1307 m_hibernationMethods = hm;
1310 TDESystemHibernationMethod::TDESystemHibernationMethod TDERootSystemDevice::hibernationMethod() {
1311 return m_hibernationMethod;
1314 void TDERootSystemDevice::internalSetHibernationMethod(TDESystemHibernationMethod::TDESystemHibernationMethod hm) {
1315 m_hibernationMethod = hm;
1318 unsigned long TDERootSystemDevice::diskSpaceNeededForHibernation() {
1319 return m_hibernationSpace;
1322 void TDERootSystemDevice::internalSetDiskSpaceNeededForHibernation(
unsigned long sz) {
1323 m_hibernationSpace = sz;
1326 bool TDERootSystemDevice::canSetHibernationMethod() {
1327 TQString hibernationnode =
"/sys/power/disk";
1328 int rval = access (hibernationnode.ascii(), W_OK);
1337 bool TDERootSystemDevice::canStandby() {
1338 TQString statenode =
"/sys/power/state";
1339 int rval = access (statenode.ascii(), W_OK);
1341 if (powerStates().contains(TDESystemPowerState::Standby)) {
1353 bool TDERootSystemDevice::canSuspend() {
1354 TQString statenode =
"/sys/power/state";
1355 int rval = access (statenode.ascii(), W_OK);
1357 if (powerStates().contains(TDESystemPowerState::Suspend)) {
1366 TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
1367 if (dbusConn.isConnected()) {
1368 TQT_DBusProxy upowerProperties(
"org.freedesktop.UPower",
"/org/freedesktop/UPower",
"org.freedesktop.DBus.Properties", dbusConn);
1369 if (upowerProperties.canSend()) {
1371 TQValueList<TQT_DBusData> params;
1372 params << TQT_DBusData::fromString(upowerProperties.interface()) << TQT_DBusData::fromString(
"CanSuspend");
1373 TQT_DBusMessage reply = upowerProperties.sendWithReply(
"Get", params);
1374 if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
1375 return reply[0].toVariant().value.toBool();
1388 #else // WITH_UPOWER
1390 #endif// WITH_UPOWER
1394 bool TDERootSystemDevice::canHibernate() {
1395 TQString statenode =
"/sys/power/state";
1396 int rval = access (statenode.ascii(), W_OK);
1398 if (powerStates().contains(TDESystemPowerState::Hibernate)) {
1407 TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
1408 if (dbusConn.isConnected()) {
1409 TQT_DBusProxy upowerProperties(
"org.freedesktop.UPower",
"/org/freedesktop/UPower",
"org.freedesktop.DBus.Properties", dbusConn);
1410 if (upowerProperties.canSend()) {
1412 TQValueList<TQT_DBusData> params;
1413 params << TQT_DBusData::fromString(upowerProperties.interface()) << TQT_DBusData::fromString(
"CanHibernate");
1414 TQT_DBusMessage reply = upowerProperties.sendWithReply(
"Get", params);
1415 if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
1416 return reply[0].toVariant().value.toBool();
1429 #else // WITH_UPOWER
1431 #endif// WITH_UPOWER
1435 bool TDERootSystemDevice::canPowerOff() {
1441 #ifdef WITH_CONSOLEKIT
1443 TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
1444 if (dbusConn.isConnected()) {
1445 TQT_DBusProxy consoleKitManager(
"org.freedesktop.ConsoleKit",
"/org/freedesktop/ConsoleKit/Manager",
"org.freedesktop.ConsoleKit.Manager", dbusConn);
1446 if (consoleKitManager.canSend()) {
1448 TQValueList<TQT_DBusData> params;
1449 TQT_DBusMessage reply = consoleKitManager.sendWithReply(
"CanStop", params);
1450 if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
1451 maysd = reply[0].toBool();
1465 #else // WITH_CONSOLEKIT
1472 #endif // WITH_CONSOLEKIT
1477 bool TDERootSystemDevice::canReboot() {
1483 #ifdef WITH_CONSOLEKIT
1485 TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
1486 if (dbusConn.isConnected()) {
1487 TQT_DBusProxy consoleKitManager(
"org.freedesktop.ConsoleKit",
"/org/freedesktop/ConsoleKit/Manager",
"org.freedesktop.ConsoleKit.Manager", dbusConn);
1488 if (consoleKitManager.canSend()) {
1490 TQValueList<TQT_DBusData> params;
1491 TQT_DBusMessage reply = consoleKitManager.sendWithReply(
"CanRestart", params);
1492 if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
1493 mayrb = reply[0].toBool();
1507 #else // WITH_CONSOLEKIT
1514 #endif // WITH_CONSOLEKIT
1519 void TDERootSystemDevice::setHibernationMethod(TDESystemHibernationMethod::TDESystemHibernationMethod hm) {
1520 TQString hibernationnode =
"/sys/power/disk";
1521 TQFile file( hibernationnode );
1522 if ( file.open( IO_WriteOnly ) ) {
1523 TQString hibernationCommand;
1524 if (hm == TDESystemHibernationMethod::Platform) {
1525 hibernationCommand =
"platform";
1527 if (hm == TDESystemHibernationMethod::Shutdown) {
1528 hibernationCommand =
"shutdown";
1530 if (hm == TDESystemHibernationMethod::Reboot) {
1531 hibernationCommand =
"reboot";
1533 if (hm == TDESystemHibernationMethod::TestProc) {
1534 hibernationCommand =
"testproc";
1536 if (hm == TDESystemHibernationMethod::Test) {
1537 hibernationCommand =
"test";
1539 TQTextStream stream( &file );
1540 stream << hibernationCommand;
1545 bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState ps) {
1546 if ((ps == TDESystemPowerState::Standby) || (ps == TDESystemPowerState::Suspend) || (ps == TDESystemPowerState::Hibernate)) {
1547 TQString statenode =
"/sys/power/state";
1548 TQFile file( statenode );
1549 if ( file.open( IO_WriteOnly ) ) {
1550 TQString powerCommand;
1551 if (ps == TDESystemPowerState::Standby) {
1552 powerCommand =
"standby";
1554 if (ps == TDESystemPowerState::Suspend) {
1555 powerCommand =
"mem";
1557 if (ps == TDESystemPowerState::Hibernate) {
1558 powerCommand =
"disk";
1560 TQTextStream stream( &file );
1561 stream << powerCommand;
1567 TQT_DBusConnection dbusConn;
1568 dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
1569 if ( dbusConn.isConnected() ) {
1570 if (ps == TDESystemPowerState::Suspend) {
1571 TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
1572 "org.freedesktop.UPower",
1573 "/org/freedesktop/UPower",
1574 "org.freedesktop.UPower",
1576 dbusConn.sendWithReply(msg);
1579 else if (ps == TDESystemPowerState::Hibernate) {
1580 TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
1581 "org.freedesktop.UPower",
1582 "/org/freedesktop/UPower",
1583 "org.freedesktop.UPower",
1585 dbusConn.sendWithReply(msg);
1595 #else // WITH_UPOWER
1597 #endif // WITH_UPOWER
1600 else if (ps == TDESystemPowerState::PowerOff) {
1601 #ifdef WITH_CONSOLEKIT
1606 TQT_DBusConnection dbusConn;
1607 dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
1608 if ( dbusConn.isConnected() ) {
1609 TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
1610 "org.freedesktop.ConsoleKit",
1611 "/org/freedesktop/ConsoleKit/Manager",
1612 "org.freedesktop.ConsoleKit.Manager",
1614 dbusConn.sendWithReply(msg);
1624 #else // WITH_CONSOLEKIT
1628 TQDataStream arg(data, IO_WriteOnly);
1629 arg << (int)0 << (
int)2 << (int)2;
1630 if ( kapp->dcopClient()->send(
"ksmserver",
"default",
"logout(int,int,int)", data) ) {
1634 #endif // WITH_CONSOLEKIT
1636 else if (ps == TDESystemPowerState::Reboot) {
1637 #ifdef WITH_CONSOLEKIT
1642 TQT_DBusConnection dbusConn;
1643 dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
1644 if ( dbusConn.isConnected() ) {
1645 TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
1646 "org.freedesktop.ConsoleKit",
1647 "/org/freedesktop/ConsoleKit/Manager",
1648 "org.freedesktop.ConsoleKit.Manager",
1650 dbusConn.sendWithReply(msg);
1660 #else // WITH_CONSOLEKIT
1664 TQDataStream arg(data, IO_WriteOnly);
1665 arg << (int)0 << (
int)1 << (int)2;
1666 if ( kapp->dcopClient()->send(
"ksmserver",
"default",
"logout(int,int,int)", data) ) {
1670 #endif // WITH_CONSOLEKIT
1672 else if (ps == TDESystemPowerState::Active) {
1680 TDEBatteryDevice::TDEBatteryDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) {
1683 TDEBatteryDevice::~TDEBatteryDevice() {
1686 double TDEBatteryDevice::voltage() {
1687 return m_currentVoltage;
1690 void TDEBatteryDevice::internalSetVoltage(
double vt) {
1691 m_currentVoltage = vt;
1694 double TDEBatteryDevice::maximumVoltage() {
1695 return m_maximumVoltage;
1698 void TDEBatteryDevice::internalSetMaximumVoltage(
double vt) {
1699 m_maximumVoltage = vt;
1702 double TDEBatteryDevice::minimumVoltage() {
1703 return m_minimumVoltage;
1706 void TDEBatteryDevice::internalSetMinimumVoltage(
double vt) {
1707 m_minimumVoltage = vt;
1710 double TDEBatteryDevice::maximumDesignVoltage() {
1711 return m_maximumDesignVoltage;
1714 void TDEBatteryDevice::internalSetMaximumDesignVoltage(
double vt) {
1715 m_maximumDesignVoltage = vt;
1718 double TDEBatteryDevice::energy() {
1719 return m_currentEnergy;
1722 void TDEBatteryDevice::internalSetEnergy(
double vt) {
1723 m_currentEnergy = vt;
1726 double TDEBatteryDevice::alarmEnergy() {
1727 return m_alarmEnergy;
1730 void TDEBatteryDevice::internalSetAlarmEnergy(
double vt) {
1734 double TDEBatteryDevice::maximumEnergy() {
1735 return m_maximumEnergy;
1738 void TDEBatteryDevice::internalSetMaximumEnergy(
double vt) {
1739 m_maximumEnergy = vt;
1742 double TDEBatteryDevice::maximumDesignEnergy() {
1743 return m_maximumDesignEnergy;
1746 void TDEBatteryDevice::internalSetMaximumDesignEnergy(
double vt) {
1747 m_maximumDesignEnergy = vt;
1750 double TDEBatteryDevice::dischargeRate() {
1751 return m_dischargeRate;
1754 void TDEBatteryDevice::internalSetDischargeRate(
double vt) {
1755 m_dischargeRate = vt;
1758 double TDEBatteryDevice::timeRemaining() {
1759 return m_timeRemaining;
1762 void TDEBatteryDevice::internalSetTimeRemaining(
double tr) {
1763 m_timeRemaining = tr;
1766 TQString TDEBatteryDevice::technology() {
1767 return m_technology;
1770 void TDEBatteryDevice::internalSetTechnology(TQString tc) {
1774 TDEBatteryStatus::TDEBatteryStatus TDEBatteryDevice::status() {
1778 void TDEBatteryDevice::internalSetStatus(TQString tc) {
1781 if (tc ==
"charging") {
1782 m_status = TDEBatteryStatus::Charging;
1784 else if (tc ==
"discharging") {
1785 m_status = TDEBatteryStatus::Discharging;
1787 else if (tc ==
"full") {
1788 m_status = TDEBatteryStatus::Full;
1791 m_status = TDEBatteryStatus::Unknown;
1795 bool TDEBatteryDevice::installed() {
1799 void TDEBatteryDevice::internalSetInstalled(
bool tc) {
1803 double TDEBatteryDevice::chargePercent() {
1804 return (m_currentEnergy/m_maximumEnergy)*100.0;
1807 TDEMainsPowerDevice::TDEMainsPowerDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) {
1810 TDEMainsPowerDevice::~TDEMainsPowerDevice() {
1813 bool TDEMainsPowerDevice::online() {
1817 void TDEMainsPowerDevice::internalSetOnline(
bool tc) {
1821 TDENetworkDevice::TDENetworkDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) {
1826 m_connectionManager = NULL;
1829 TDENetworkDevice::~TDENetworkDevice() {
1830 if (m_connectionManager) {
1831 delete m_connectionManager;
1835 TQString TDENetworkDevice::macAddress() {
1836 return m_macAddress;
1839 void TDENetworkDevice::internalSetMacAddress(TQString ma) {
1843 TQString TDENetworkDevice::state() {
1847 void TDENetworkDevice::internalSetState(TQString st) {
1851 bool TDENetworkDevice::carrierPresent() {
1855 void TDENetworkDevice::internalSetCarrierPresent(
bool cp) {
1859 bool TDENetworkDevice::dormant() {
1863 void TDENetworkDevice::internalSetDormant(
bool dm) {
1867 TQString TDENetworkDevice::ipV4Address() {
1868 return m_ipV4Address;
1871 void TDENetworkDevice::internalSetIpV4Address(TQString ad) {
1875 TQString TDENetworkDevice::ipV6Address() {
1876 return m_ipV6Address;
1879 void TDENetworkDevice::internalSetIpV6Address(TQString ad) {
1883 TQString TDENetworkDevice::ipV4Netmask() {
1884 return m_ipV4Netmask;
1887 void TDENetworkDevice::internalSetIpV4Netmask(TQString nm) {
1891 TQString TDENetworkDevice::ipV6Netmask() {
1892 return m_ipV6Netmask;
1895 void TDENetworkDevice::internalSetIpV6Netmask(TQString nm) {
1899 TQString TDENetworkDevice::ipV4Broadcast() {
1900 return m_ipV4Broadcast;
1903 void TDENetworkDevice::internalSetIpV4Broadcast(TQString br) {
1904 m_ipV4Broadcast = br;
1907 TQString TDENetworkDevice::ipV6Broadcast() {
1908 return m_ipV6Broadcast;
1911 void TDENetworkDevice::internalSetIpV6Broadcast(TQString br) {
1912 m_ipV6Broadcast = br;
1915 TQString TDENetworkDevice::ipV4Destination() {
1916 return m_ipV4Destination;
1919 void TDENetworkDevice::internalSetIpV4Destination(TQString ds) {
1920 m_ipV4Destination = ds;
1923 TQString TDENetworkDevice::ipV6Destination() {
1924 return m_ipV6Destination;
1927 void TDENetworkDevice::internalSetIpV6Destination(TQString ds) {
1928 m_ipV6Destination = ds;
1931 double TDENetworkDevice::rxBytes() {
1935 void TDENetworkDevice::internalSetRxBytes(
double rx) {
1939 double TDENetworkDevice::txBytes() {
1943 void TDENetworkDevice::internalSetTxBytes(
double tx) {
1947 double TDENetworkDevice::rxPackets() {
1951 void TDENetworkDevice::internalSetRxPackets(
double rx) {
1955 double TDENetworkDevice::txPackets() {
1959 void TDENetworkDevice::internalSetTxPackets(
double tx) {
1963 TDENetworkConnectionManager* TDENetworkDevice::connectionManager() {
1964 #ifdef WITH_NETWORK_MANAGER_BACKEND
1965 if (!m_connectionManager) {
1966 m_connectionManager =
new TDENetworkConnectionManager_BackendNM(m_macAddress);
1968 #endif // WITH_NETWORK_MANAGER_BACKEND
1970 return m_connectionManager;
1973 void TDENetworkDevice::internalSetConnectionManager(TDENetworkConnectionManager* mgr) {
1974 m_connectionManager = mgr;
1977 TDEBacklightDevice::TDEBacklightDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) {
1980 TDEBacklightDevice::~TDEBacklightDevice() {
1983 TDEDisplayPowerLevel::TDEDisplayPowerLevel TDEBacklightDevice::powerLevel() {
1984 return m_powerLevel;
1987 void TDEBacklightDevice::internalSetPowerLevel(TDEDisplayPowerLevel::TDEDisplayPowerLevel pl) {
1991 void TDEBacklightDevice::internalSetMaximumRawBrightness(
int br) {
1992 m_maximumBrightness = br;
1995 void TDEBacklightDevice::internalSetCurrentRawBrightness(
int br) {
1996 m_currentBrightness = br;
1999 int TDEBacklightDevice::brightnessSteps() {
2000 return m_maximumBrightness + 1;
2003 double TDEBacklightDevice::brightnessPercent() {
2004 return (((m_currentBrightness*1.0)/m_maximumBrightness)*100.0);
2007 bool TDEBacklightDevice::canSetBrightness() {
2008 TQString brightnessnode = systemPath() +
"/brightness";
2009 int rval = access (brightnessnode.ascii(), W_OK);
2015 TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
2016 if (dbusConn.isConnected()) {
2017 TQT_DBusProxy hardwareControl(
"org.trinitydesktop.hardwarecontrol",
"/org/trinitydesktop/hardwarecontrol",
"org.trinitydesktop.hardwarecontrol.Brightness", dbusConn);
2018 if (hardwareControl.canSend()) {
2020 TQValueList<TQT_DBusData> params;
2021 params << TQT_DBusData::fromString(brightnessnode);
2022 TQT_DBusMessage reply = hardwareControl.sendWithReply(
"CanSetBrightness", params);
2023 if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
2024 return reply[0].toVariant().value.toBool();
2037 #else // WITH_UPOWER
2039 #endif// WITH_UPOWER
2043 int TDEBacklightDevice::rawBrightness() {
2044 return m_currentBrightness;
2047 void TDEBacklightDevice::setRawBrightness(
int br) {
2048 TQString brightnessnode = systemPath() +
"/brightness";
2049 TQString brightnessCommand = TQString(
"%1").arg(br);
2050 TQFile file( brightnessnode );
2051 if ( file.open( IO_WriteOnly ) ) {
2052 TQTextStream stream( &file );
2053 stream << brightnessCommand;
2058 TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
2059 if (dbusConn.isConnected()) {
2060 TQT_DBusProxy hardwareControl(
"org.trinitydesktop.hardwarecontrol",
"/org/trinitydesktop/hardwarecontrol",
"org.trinitydesktop.hardwarecontrol.Brightness", dbusConn);
2061 if (hardwareControl.canSend()) {
2063 TQValueList<TQT_DBusData> params;
2064 params << TQT_DBusData::fromString(brightnessnode) << TQT_DBusData::fromString(brightnessCommand);
2065 hardwareControl.sendWithReply(
"SetBrightness", params);
2075 #endif // WITH_UPOWER
2078 TDEMonitorDevice::TDEMonitorDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) {
2081 TDEMonitorDevice::~TDEMonitorDevice() {
2084 bool TDEMonitorDevice::connected() {
2088 void TDEMonitorDevice::internalSetConnected(
bool cn) {
2092 bool TDEMonitorDevice::enabled() {
2096 void TDEMonitorDevice::internalSetEnabled(
bool en) {
2100 TQByteArray TDEMonitorDevice::edid() {
2104 void TDEMonitorDevice::internalSetEdid(TQByteArray ed) {
2108 TDEResolutionList TDEMonitorDevice::resolutions() {
2109 return m_resolutions;
2112 void TDEMonitorDevice::internalSetResolutions(TDEResolutionList rs) {
2116 TQString TDEMonitorDevice::portType() {
2120 void TDEMonitorDevice::internalSetPortType(TQString pt) {
2124 TDEDisplayPowerLevel::TDEDisplayPowerLevel TDEMonitorDevice::powerLevel() {
2125 return m_powerLevel;
2128 void TDEMonitorDevice::internalSetPowerLevel(TDEDisplayPowerLevel::TDEDisplayPowerLevel pl) {
2132 TDEEventDevice::TDEEventDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) {
2134 m_fdMonitorActive =
false;
2137 TDEEventDevice::~TDEEventDevice() {
2143 TDEEventDeviceType::TDEEventDeviceType TDEEventDevice::eventType() {
2147 void TDEEventDevice::internalSetEventType(TDEEventDeviceType::TDEEventDeviceType et) {
2151 TDESwitchType::TDESwitchType TDEEventDevice::providedSwitches() {
2152 return m_providedSwitches;
2155 void TDEEventDevice::internalSetProvidedSwitches(TDESwitchType::TDESwitchType sl) {
2156 m_providedSwitches = sl;
2159 TDESwitchType::TDESwitchType TDEEventDevice::activeSwitches() {
2160 return m_switchActive;
2163 void TDEEventDevice::internalSetActiveSwitches(TDESwitchType::TDESwitchType sl) {
2164 m_switchActive = sl;
2168 TQStringList TDEEventDevice::friendlySwitchList(TDESwitchType::TDESwitchType switches) {
2171 if (switches & TDESwitchType::Lid) {
2172 ret.append(
i18n(
"Lid Switch"));
2174 if (switches & TDESwitchType::TabletMode) {
2175 ret.append(
i18n(
"Tablet Mode"));
2177 if (switches & TDESwitchType::HeadphoneInsert) {
2178 ret.append(
i18n(
"Headphone Inserted"));
2180 if (switches & TDESwitchType::RFKill) {
2181 ret.append(
i18n(
"Radio Frequency Device Kill Switch"));
2183 if (switches & TDESwitchType::Radio) {
2184 ret.append(
i18n(
"Enable Radio"));
2186 if (switches & TDESwitchType::MicrophoneInsert) {
2187 ret.append(
i18n(
"Microphone Inserted"));
2189 if (switches & TDESwitchType::Dock) {
2190 ret.append(
i18n(
"Docked"));
2192 if (switches & TDESwitchType::LineOutInsert) {
2193 ret.append(
i18n(
"Line Out Inserted"));
2195 if (switches & TDESwitchType::JackPhysicalInsert) {
2196 ret.append(
i18n(
"Physical Jack Inserted"));
2198 if (switches & TDESwitchType::VideoOutInsert) {
2199 ret.append(
i18n(
"Video Out Inserted"));
2201 if (switches & TDESwitchType::CameraLensCover) {
2202 ret.append(
i18n(
"Camera Lens Cover"));
2204 if (switches & TDESwitchType::KeypadSlide) {
2205 ret.append(
i18n(
"Keypad Slide"));
2207 if (switches & TDESwitchType::FrontProximity) {
2208 ret.append(
i18n(
"Front Proximity"));
2210 if (switches & TDESwitchType::RotateLock) {
2211 ret.append(
i18n(
"Rotate Lock"));
2213 if (switches & TDESwitchType::LineInInsert) {
2214 ret.append(
i18n(
"Line In Inserted"));
2220 void TDEEventDevice::internalStartFdMonitoring(TDEHardwareDevices* hwmanager) {
2221 if (!m_fdMonitorActive) {
2223 if (eventType() != TDEEventDeviceType::Unknown) {
2225 m_eventNotifier =
new TQSocketNotifier(m_fd, TQSocketNotifier::Read,
this);
2226 connect( m_eventNotifier, TQT_SIGNAL(activated(
int)),
this, TQT_SLOT(eventReceived()) );
2228 connect(
this, TQT_SIGNAL(keyPressed(
unsigned int, TDEEventDevice*)), hwmanager, TQT_SLOT(processEventDeviceKeyPressed(
unsigned int, TDEEventDevice*)) );
2230 m_fdMonitorActive =
true;
2234 void TDEEventDevice::eventReceived() {
2235 struct input_event ev;
2237 r = read(m_fd, &ev,
sizeof(
struct input_event));
2239 if (ev.type == EV_KEY) {
2240 emit keyPressed(ev.code,
this);
2245 TDEInputDevice::TDEInputDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) {
2248 TDEInputDevice::~TDEInputDevice() {
2251 TDEInputDeviceType::TDEInputDeviceType TDEInputDevice::inputType() {
2255 void TDEInputDevice::internalSetInputType(TDEInputDeviceType::TDEInputDeviceType it) {
2259 TDEHardwareDevices::TDEHardwareDevices() {
2267 m_deviceList.setAutoDelete( TRUE );
2270 m_udevStruct = udev_new();
2271 if (!m_udevStruct) {
2272 printf(
"Unable to create udev interface\n");
2277 m_udevMonitorStruct = udev_monitor_new_from_netlink(m_udevStruct,
"udev");
2278 udev_monitor_filter_add_match_subsystem_devtype(m_udevMonitorStruct, NULL, NULL);
2279 udev_monitor_enable_receiving(m_udevMonitorStruct);
2281 int udevmonitorfd = udev_monitor_get_fd(m_udevMonitorStruct);
2282 if (udevmonitorfd >= 0) {
2283 m_devScanNotifier =
new TQSocketNotifier(udevmonitorfd, TQSocketNotifier::Read,
this);
2284 connect( m_devScanNotifier, TQT_SIGNAL(activated(
int)),
this, TQT_SLOT(processHotPluggedHardware()) );
2289 m_mountTable.clear();
2290 TQFile file(
"/proc/mounts" );
2291 if ( file.open( IO_ReadOnly ) ) {
2292 TQTextStream stream( &file );
2293 while ( !stream.atEnd() ) {
2294 m_mountTable.append(stream.readLine());
2300 m_procMountsFd =
open(
"/proc/mounts", O_RDONLY, 0);
2301 if (m_procMountsFd >= 0) {
2302 m_mountScanNotifier =
new TQSocketNotifier(m_procMountsFd, TQSocketNotifier::Exception,
this);
2303 connect( m_mountScanNotifier, TQT_SIGNAL(activated(
int)),
this, TQT_SLOT(processModifiedMounts()) );
2309 TQFile cpufile(
"/proc/cpuinfo" );
2310 if ( cpufile.open( IO_ReadOnly ) ) {
2311 TQTextStream stream( &cpufile );
2312 while ( !stream.atEnd() ) {
2313 m_cpuInfo.append(stream.readLine());
2325 connect( m_cpuWatch, TQT_SIGNAL(dirty(
const TQString &)),
this, TQT_SLOT(processModifiedCPUs()) );
2327 m_cpuWatchTimer =
new TQTimer(
this);
2328 connect( m_cpuWatchTimer, SIGNAL(timeout()),
this, SLOT(processModifiedCPUs()) );
2329 TQDir nodezerocpufreq(
"/sys/devices/system/cpu/cpu0/cpufreq");
2330 if (nodezerocpufreq.exists()) {
2331 m_cpuWatchTimer->start( 500, FALSE );
2337 m_deviceWatchTimer =
new TQTimer(
this);
2338 connect( m_deviceWatchTimer, SIGNAL(timeout()),
this, SLOT(processStatelessDevices()) );
2339 m_deviceWatchTimer->start( 1000, FALSE );
2342 queryHardwareInformation();
2346 TDEHardwareDevices::~TDEHardwareDevices() {
2348 m_deviceWatchTimer->stop();
2353 m_cpuWatch->stopScan();
2355 m_cpuWatchTimer->stop();
2359 close(m_procMountsFd);
2362 udev_unref(m_udevStruct);
2379 void TDEHardwareDevices::rescanDeviceInformation(TDEGenericDevice* hwdevice) {
2380 struct udev_device *dev;
2381 dev = udev_device_new_from_syspath(m_udevStruct, hwdevice->systemPath().ascii());
2382 classifyUnknownDevice(dev, hwdevice,
false);
2383 updateParentDeviceInformation(hwdevice);
2384 udev_device_unref(dev);
2387 TDEGenericDevice* TDEHardwareDevices::findBySystemPath(TQString syspath) {
2388 if (!syspath.endsWith(
"/")) {
2391 TDEGenericDevice *hwdevice;
2393 TDEGenericHardwareList devList = listAllPhysicalDevices();
2394 for ( hwdevice = devList.first(); hwdevice; hwdevice = devList.next() ) {
2395 if (hwdevice->systemPath() == syspath) {
2403 TDEGenericDevice* TDEHardwareDevices::findByUniqueID(TQString uid) {
2404 TDEGenericDevice *hwdevice;
2406 TDEGenericHardwareList devList = listAllPhysicalDevices();
2407 for ( hwdevice = devList.first(); hwdevice; hwdevice = devList.next() ) {
2408 if (hwdevice->uniqueID() == uid) {
2416 TDEGenericDevice* TDEHardwareDevices::findByDeviceNode(TQString devnode) {
2417 TDEGenericDevice *hwdevice;
2418 for ( hwdevice = m_deviceList.first(); hwdevice; hwdevice = m_deviceList.next() ) {
2419 if (hwdevice->deviceNode() == devnode) {
2427 TDEStorageDevice* TDEHardwareDevices::findDiskByUID(TQString uid) {
2428 TDEGenericDevice *hwdevice;
2429 for ( hwdevice = m_deviceList.first(); hwdevice; hwdevice = m_deviceList.next() ) {
2430 if (hwdevice->type() == TDEGenericDeviceType::Disk) {
2431 TDEStorageDevice* sdevice =
static_cast<TDEStorageDevice*
>(hwdevice);
2432 if (sdevice->uniqueID() == uid) {
2441 void TDEHardwareDevices::processHotPluggedHardware() {
2442 udev_device* dev = udev_monitor_receive_device(m_udevMonitorStruct);
2444 TQString actionevent(udev_device_get_action(dev));
2445 if (actionevent ==
"add") {
2446 TDEGenericDevice* device = classifyUnknownDevice(dev);
2449 TDEGenericDevice *hwdevice;
2450 for (hwdevice = m_deviceList.first(); hwdevice; hwdevice = m_deviceList.next()) {
2451 if (hwdevice->systemPath() == device->systemPath()) {
2459 m_deviceList.append(device);
2460 updateParentDeviceInformation(device);
2461 emit hardwareAdded(device);
2462 emit hardwareEvent(TDEHardwareEvent::HardwareAdded, device->uniqueID());
2465 else if (actionevent ==
"remove") {
2467 TQString systempath(udev_device_get_syspath(dev));
2469 TDEGenericDevice *hwdevice;
2470 for (hwdevice = m_deviceList.first(); hwdevice; hwdevice = m_deviceList.next()) {
2471 if (hwdevice->systemPath() == systempath) {
2472 emit hardwareRemoved(hwdevice);
2473 emit hardwareEvent(TDEHardwareEvent::HardwareRemoved, hwdevice->uniqueID());
2476 if (hwdevice->type() == TDEGenericDeviceType::Disk) {
2477 TDEStorageDevice* sdevice =
static_cast<TDEStorageDevice*
>(hwdevice);
2478 TQStringList slavedevices = sdevice->slaveDevices();
2479 m_deviceList.remove(hwdevice);
2480 for ( TQStringList::Iterator slaveit = slavedevices.begin(); slaveit != slavedevices.end(); ++slaveit ) {
2481 TDEGenericDevice* slavedevice = findBySystemPath(*slaveit);
2483 rescanDeviceInformation(slavedevice);
2484 emit hardwareUpdated(slavedevice);
2485 emit hardwareEvent(TDEHardwareEvent::HardwareUpdated, slavedevice->uniqueID());
2490 m_deviceList.remove(hwdevice);
2497 else if (actionevent ==
"change") {
2499 TQString systempath(udev_device_get_syspath(dev));
2501 TDEGenericDevice *hwdevice;
2502 for (hwdevice = m_deviceList.first(); hwdevice; hwdevice = m_deviceList.next()) {
2503 if (hwdevice->systemPath() == systempath) {
2504 if (!hwdevice->blacklistedForUpdate()) {
2505 classifyUnknownDevice(dev, hwdevice,
false);
2506 updateParentDeviceInformation(hwdevice);
2507 emit hardwareUpdated(hwdevice);
2508 emit hardwareEvent(TDEHardwareEvent::HardwareUpdated, hwdevice->uniqueID());
2511 else if ((hwdevice->type() == TDEGenericDeviceType::Monitor)
2512 && (hwdevice->systemPath().contains(systempath))) {
2513 if (!hwdevice->blacklistedForUpdate()) {
2514 struct udev_device *slavedev;
2515 slavedev = udev_device_new_from_syspath(m_udevStruct, hwdevice->systemPath().ascii());
2516 classifyUnknownDevice(slavedev, hwdevice,
false);
2517 udev_device_unref(slavedev);
2518 updateParentDeviceInformation(hwdevice);
2519 emit hardwareUpdated(hwdevice);
2520 emit hardwareEvent(TDEHardwareEvent::HardwareUpdated, hwdevice->uniqueID());
2528 void TDEHardwareDevices::processModifiedCPUs() {
2534 TQFile cpufile(
"/proc/cpuinfo" );
2535 if ( cpufile.open( IO_ReadOnly ) ) {
2536 TQTextStream stream( &cpufile );
2537 while ( !stream.atEnd() ) {
2538 m_cpuInfo.append(stream.readLine());
2544 bool cpuinfo_format_x86 =
true;
2545 bool cpuinfo_format_arm =
false;
2549 int blockNumber = 0;
2550 TQStringList::Iterator blockBegin = m_cpuInfo.begin();
2551 for (TQStringList::Iterator cpuit1 = m_cpuInfo.begin(); cpuit1 != m_cpuInfo.end(); ++cpuit1) {
2553 curline1 = curline1.stripWhiteSpace();
2554 if (!(*blockBegin).startsWith(
"processor")) {
2556 TQStringList::Iterator cpuit2;
2557 for (cpuit2 = blockBegin; cpuit2 != m_cpuInfo.end(); ++cpuit2) {
2559 curline2 = curline2.stripWhiteSpace();
2560 if (curline2.startsWith(
"processor")) {
2564 else if (curline2 ==
"") {
2569 m_cpuInfo.insert(blockBegin, (*cpuit2));
2572 m_cpuInfo.insert(blockBegin,
"processor : 0");
2575 if (curline1 ==
"") {
2577 blockBegin = cpuit1;
2580 if (curline1.startsWith(
"Processor")) {
2581 cpuinfo_format_x86 =
false;
2582 cpuinfo_format_arm =
true;
2587 TDECPUDevice *cdevice;
2589 bool modified =
false;
2590 bool have_frequency =
false;
2593 int processorNumber = 0;
2594 int processorCount = 0;
2596 if (cpuinfo_format_x86) {
2600 TQStringList::Iterator cpuit;
2601 for (cpuit = m_cpuInfo.begin(); cpuit != m_cpuInfo.end(); ++cpuit) {
2603 if (curline.startsWith(
"processor")) {
2604 curline.remove(0, curline.find(
":")+1);
2605 curline = curline.stripWhiteSpace();
2606 processorNumber = curline.toInt();
2607 if (!cdevice) cdevice =
dynamic_cast<TDECPUDevice*
>(findBySystemPath(TQString(
"/sys/devices/system/cpu/cpu%1").arg(processorNumber)));
2609 if (cdevice->coreNumber() != processorNumber) modified =
true;
2610 cdevice->internalSetCoreNumber(processorNumber);
2613 if (curline.startsWith(
"model name")) {
2614 curline.remove(0, curline.find(
":")+1);
2615 curline = curline.stripWhiteSpace();
2617 if (cdevice->name() != curline) modified =
true;
2618 cdevice->internalSetName(curline);
2621 if (curline.startsWith(
"cpu MHz")) {
2622 curline.remove(0, curline.find(
":")+1);
2623 curline = curline.stripWhiteSpace();
2625 if (cdevice->frequency() != curline.toDouble()) modified =
true;
2626 cdevice->internalSetFrequency(curline.toDouble());
2627 have_frequency =
true;
2630 if (curline.startsWith(
"vendor_id")) {
2631 curline.remove(0, curline.find(
":")+1);
2632 curline = curline.stripWhiteSpace();
2634 if (cdevice->vendorName() != curline) modified =
true;
2635 cdevice->internalSetVendorName(curline);
2636 if (cdevice->vendorEncoded() != curline) modified =
true;
2637 cdevice->internalSetVendorEncoded(curline);
2640 curline = curline.stripWhiteSpace();
2641 if (curline ==
"") {
2646 else if (cpuinfo_format_arm) {
2650 TQStringList::Iterator cpuit;
2652 TQString vendorName;
2653 TQString serialNumber;
2654 for (cpuit = m_cpuInfo.begin(); cpuit != m_cpuInfo.end(); ++cpuit) {
2656 if (curline.startsWith(
"Processor")) {
2657 curline.remove(0, curline.find(
":")+1);
2658 curline = curline.stripWhiteSpace();
2659 modelName = curline;
2661 if (curline.startsWith(
"Hardware")) {
2662 curline.remove(0, curline.find(
":")+1);
2663 curline = curline.stripWhiteSpace();
2664 vendorName = curline;
2666 if (curline.startsWith(
"Serial")) {
2667 curline.remove(0, curline.find(
":")+1);
2668 curline = curline.stripWhiteSpace();
2669 serialNumber = curline;
2672 for (TQStringList::Iterator cpuit = m_cpuInfo.begin(); cpuit != m_cpuInfo.end(); ++cpuit) {
2674 if (curline.startsWith(
"processor")) {
2675 curline.remove(0, curline.find(
":")+1);
2676 curline = curline.stripWhiteSpace();
2677 processorNumber = curline.toInt();
2679 cdevice =
dynamic_cast<TDECPUDevice*
>(findBySystemPath(TQString(
"/sys/devices/system/cpu/cpu%1").arg(processorNumber)));
2682 if (cdevice->coreNumber() != processorNumber) modified =
true;
2683 cdevice->internalSetCoreNumber(processorNumber);
2684 if (cdevice->name() != modelName) modified =
true;
2685 cdevice->internalSetName(modelName);
2686 if (cdevice->vendorName() != vendorName) modified =
true;
2687 cdevice->internalSetVendorName(vendorName);
2688 if (cdevice->vendorEncoded() != vendorName) modified =
true;
2689 cdevice->internalSetVendorEncoded(vendorName);
2690 if (cdevice->serialNumber() != serialNumber) modified =
true;
2691 cdevice->internalSetSerialNumber(serialNumber);
2695 curline = curline.stripWhiteSpace();
2696 if (curline ==
"") {
2702 processorCount = processorNumber+1;
2705 for (processorNumber=0; processorNumber<processorCount; processorNumber++) {
2706 cdevice =
dynamic_cast<TDECPUDevice*
>(findBySystemPath(TQString(
"/sys/devices/system/cpu/cpu%1").arg(processorNumber)));
2707 TQDir cpufreq_dir(TQString(
"/sys/devices/system/cpu/cpu%1/cpufreq").arg(processorNumber));
2708 TQString scalinggovernor;
2709 TQString scalingdriver;
2710 double minfrequency = -1;
2711 double maxfrequency = -1;
2712 double trlatency = -1;
2713 TQStringList affectedcpulist;
2714 TQStringList frequencylist;
2715 TQStringList governorlist;
2716 if (cpufreq_dir.exists()) {
2717 TQString nodename = cpufreq_dir.path();
2718 nodename.append(
"/scaling_governor");
2719 TQFile scalinggovernorfile(nodename);
2720 if (scalinggovernorfile.open(IO_ReadOnly)) {
2721 TQTextStream stream( &scalinggovernorfile );
2722 scalinggovernor = stream.readLine();
2723 scalinggovernorfile.close();
2725 nodename = cpufreq_dir.path();
2726 nodename.append(
"/scaling_driver");
2727 TQFile scalingdriverfile(nodename);
2728 if (scalingdriverfile.open(IO_ReadOnly)) {
2729 TQTextStream stream( &scalingdriverfile );
2730 scalingdriver = stream.readLine();
2731 scalingdriverfile.close();
2733 nodename = cpufreq_dir.path();
2734 nodename.append(
"/cpuinfo_min_freq");
2735 TQFile minfrequencyfile(nodename);
2736 if (minfrequencyfile.open(IO_ReadOnly)) {
2737 TQTextStream stream( &minfrequencyfile );
2738 minfrequency = stream.readLine().toDouble()/1000.0;
2739 minfrequencyfile.close();
2741 nodename = cpufreq_dir.path();
2742 nodename.append(
"/cpuinfo_max_freq");
2743 TQFile maxfrequencyfile(nodename);
2744 if (maxfrequencyfile.open(IO_ReadOnly)) {
2745 TQTextStream stream( &maxfrequencyfile );
2746 maxfrequency = stream.readLine().toDouble()/1000.0;
2747 maxfrequencyfile.close();
2749 nodename = cpufreq_dir.path();
2750 nodename.append(
"/cpuinfo_transition_latency");
2751 TQFile trlatencyfile(nodename);
2752 if (trlatencyfile.open(IO_ReadOnly)) {
2753 TQTextStream stream( &trlatencyfile );
2754 trlatency = stream.readLine().toDouble()/1000.0;
2755 trlatencyfile.close();
2757 nodename = cpufreq_dir.path();
2758 nodename.append(
"/affected_cpus");
2759 TQFile tiedcpusfile(nodename);
2760 if (tiedcpusfile.open(IO_ReadOnly)) {
2761 TQTextStream stream( &tiedcpusfile );
2762 affectedcpulist = TQStringList::split(
" ", stream.readLine());
2763 tiedcpusfile.close();
2765 nodename = cpufreq_dir.path();
2766 nodename.append(
"/scaling_available_frequencies");
2767 TQFile availfreqsfile(nodename);
2768 if (availfreqsfile.open(IO_ReadOnly)) {
2769 TQTextStream stream( &availfreqsfile );
2770 frequencylist = TQStringList::split(
" ", stream.readLine());
2771 availfreqsfile.close();
2773 nodename = cpufreq_dir.path();
2774 nodename.append(
"/scaling_available_governors");
2775 TQFile availgvrnsfile(nodename);
2776 if (availgvrnsfile.open(IO_ReadOnly)) {
2777 TQTextStream stream( &availgvrnsfile );
2778 governorlist = TQStringList::split(
" ", stream.readLine());
2779 availgvrnsfile.close();
2782 if (!have_frequency) {
2783 nodename = cpufreq_dir.path();
2784 nodename.append(
"/cpuinfo_cur_freq");
2785 TQFile cpufreqfile(nodename);
2786 if (cpufreqfile.open(IO_ReadOnly)) {
2787 TQTextStream stream( &cpufreqfile );
2788 if (cdevice) cdevice->internalSetFrequency(stream.readLine().toDouble()/1000.0);
2789 cpufreqfile.close();
2790 have_frequency =
true;
2794 bool frequencyFound;
2795 TQStringList::Iterator freqit;
2796 frequencyFound =
false;
2797 for ( freqit = frequencylist.begin(); freqit != frequencylist.end(); ++freqit ) {
2798 double thisfrequency = (*freqit).toDouble()/1000.0;
2799 if (thisfrequency == minfrequency) {
2800 frequencyFound =
true;
2803 if (!frequencyFound) {
2804 int minFrequencyInt = (minfrequency*1000.0);
2805 frequencylist.prepend(TQString(
"%1").arg(minFrequencyInt));
2807 frequencyFound =
false;
2808 for ( freqit = frequencylist.begin(); freqit != frequencylist.end(); ++freqit ) {
2809 double thisfrequency = (*freqit).toDouble()/1000.0;
2810 if (thisfrequency == maxfrequency) {
2811 frequencyFound =
true;
2814 if (!frequencyFound) {
2815 int maxfrequencyInt = (maxfrequency*1000.0);
2816 frequencylist.append(TQString(
"%1").arg(maxfrequencyInt));
2820 if (have_frequency) {
2822 minfrequency = cdevice->frequency();
2823 maxfrequency = cdevice->frequency();
2830 if (cdevice->governor() != scalinggovernor) modified =
true;
2831 cdevice->internalSetGovernor(scalinggovernor);
2832 if (cdevice->scalingDriver() != scalingdriver) modified =
true;
2833 cdevice->internalSetScalingDriver(scalingdriver);
2834 if (cdevice->minFrequency() != minfrequency) modified =
true;
2835 cdevice->internalSetMinFrequency(minfrequency);
2836 if (cdevice->maxFrequency() != maxfrequency) modified =
true;
2837 cdevice->internalSetMaxFrequency(maxfrequency);
2838 if (cdevice->transitionLatency() != trlatency) modified =
true;
2839 cdevice->internalSetTransitionLatency(trlatency);
2840 if (cdevice->dependentProcessors().join(
" ") != affectedcpulist.join(
" ")) modified =
true;
2841 cdevice->internalSetDependentProcessors(affectedcpulist);
2842 if (cdevice->availableFrequencies().join(
" ") != frequencylist.join(
" ")) modified =
true;
2843 cdevice->internalSetAvailableFrequencies(frequencylist);
2844 if (cdevice->availableGovernors().join(
" ") != governorlist.join(
" ")) modified =
true;
2845 cdevice->internalSetAvailableGovernors(governorlist);
2850 for (processorNumber=0; processorNumber<processorCount; processorNumber++) {
2851 TDEGenericDevice* hwdevice = findBySystemPath(TQString(
"/sys/devices/system/cpu/cpu%1").arg(processorNumber));
2853 emit hardwareUpdated(hwdevice);
2854 emit hardwareEvent(TDEHardwareEvent::HardwareUpdated, hwdevice->uniqueID());
2859 void TDEHardwareDevices::processStatelessDevices() {
2862 TDEGenericDevice *hwdevice;
2865 TDEGenericHardwareList devList = listAllPhysicalDevices();
2866 for ( hwdevice = devList.first(); hwdevice; hwdevice = devList.next() ) {
2867 if ((hwdevice->type() == TDEGenericDeviceType::RootSystem) || (hwdevice->type() == TDEGenericDeviceType::Network) || (hwdevice->type() == TDEGenericDeviceType::OtherSensor) || (hwdevice->type() == TDEGenericDeviceType::Event) || (hwdevice->type() == TDEGenericDeviceType::Battery) || (hwdevice->type() == TDEGenericDeviceType::PowerSupply)) {
2868 rescanDeviceInformation(hwdevice);
2869 emit hardwareUpdated(hwdevice);
2870 emit hardwareEvent(TDEHardwareEvent::HardwareUpdated, hwdevice->uniqueID());
2875 void TDEHardwareDevices::processEventDeviceKeyPressed(
unsigned int keycode, TDEEventDevice* edevice) {
2876 emit eventDeviceKeyPressed(keycode, edevice);
2879 void TDEHardwareDevices::processModifiedMounts() {
2883 TQStringList deletedEntries = m_mountTable;
2886 m_mountTable.clear();
2887 TQFile file(
"/proc/mounts" );
2888 if ( file.open( IO_ReadOnly ) ) {
2889 TQTextStream stream( &file );
2890 while ( !stream.atEnd() ) {
2891 m_mountTable.append(stream.readLine());
2896 TQStringList addedEntries = m_mountTable;
2899 processModifiedMounts_removeagain:
2900 for ( TQStringList::Iterator delit = deletedEntries.begin(); delit != deletedEntries.end(); ++delit ) {
2901 for ( TQStringList::Iterator addit = addedEntries.begin(); addit != addedEntries.end(); ++addit ) {
2902 if ((*delit) == (*addit)) {
2903 deletedEntries.remove(delit);
2904 addedEntries.remove(addit);
2908 goto processModifiedMounts_removeagain;
2913 TQStringList::Iterator it;
2914 for ( it = addedEntries.begin(); it != addedEntries.end(); ++it ) {
2915 TQStringList mountInfo = TQStringList::split(
" ", (*it),
true);
2917 TDEGenericDevice* hwdevice = findByDeviceNode(*mountInfo.at(0));
2919 emit hardwareUpdated(hwdevice);
2920 emit hardwareEvent(TDEHardwareEvent::HardwareUpdated, hwdevice->uniqueID());
2922 if (hwdevice->type() == TDEGenericDeviceType::Disk) {
2923 TDEStorageDevice* sdevice =
static_cast<TDEStorageDevice*
>(hwdevice);
2924 TQStringList slavedevices = sdevice->slaveDevices();
2925 for ( TQStringList::Iterator slaveit = slavedevices.begin(); slaveit != slavedevices.end(); ++slaveit ) {
2926 TDEGenericDevice* slavedevice = findBySystemPath(*slaveit);
2928 emit hardwareUpdated(slavedevice);
2929 emit hardwareEvent(TDEHardwareEvent::HardwareUpdated, slavedevice->uniqueID());
2935 for ( it = deletedEntries.begin(); it != deletedEntries.end(); ++it ) {
2936 TQStringList mountInfo = TQStringList::split(
" ", (*it),
true);
2938 TDEGenericDevice* hwdevice = findByDeviceNode(*mountInfo.at(0));
2940 emit hardwareUpdated(hwdevice);
2941 emit hardwareEvent(TDEHardwareEvent::HardwareUpdated, hwdevice->uniqueID());
2943 if (hwdevice->type() == TDEGenericDeviceType::Disk) {
2944 TDEStorageDevice* sdevice =
static_cast<TDEStorageDevice*
>(hwdevice);
2945 TQStringList slavedevices = sdevice->slaveDevices();
2946 for ( TQStringList::Iterator slaveit = slavedevices.begin(); slaveit != slavedevices.end(); ++slaveit ) {
2947 TDEGenericDevice* slavedevice = findBySystemPath(*slaveit);
2949 emit hardwareUpdated(slavedevice);
2950 emit hardwareEvent(TDEHardwareEvent::HardwareUpdated, slavedevice->uniqueID());
2957 emit mountTableModified();
2958 emit hardwareEvent(TDEHardwareEvent::MountTableModified, TQString());
2961 TDEDiskDeviceType::TDEDiskDeviceType classifyDiskType(udev_device* dev,
const TQString devicebus,
const TQString disktypestring,
const TQString systempath,
const TQString devicevendor,
const TQString devicemodel,
const TQString filesystemtype,
const TQString devicedriver) {
2963 TDEDiskDeviceType::TDEDiskDeviceType disktype = TDEDiskDeviceType::Null;
2965 if (devicebus.upper() ==
"USB") {
2966 disktype = disktype | TDEDiskDeviceType::USB;
2969 if (disktypestring.upper() ==
"ZIP") {
2970 disktype = disktype | TDEDiskDeviceType::Zip;
2972 if ((devicevendor.upper() ==
"IOMEGA") && (devicemodel.upper().contains(
"ZIP"))) {
2973 disktype = disktype | TDEDiskDeviceType::Zip;
2976 if ((devicevendor.upper() ==
"APPLE") && (devicemodel.upper().contains(
"IPOD"))) {
2977 disktype = disktype | TDEDiskDeviceType::MediaDevice;
2979 if ((devicevendor.upper() ==
"SANDISK") && (devicemodel.upper().contains(
"SANSA"))) {
2980 disktype = disktype | TDEDiskDeviceType::MediaDevice;
2983 if (disktypestring.upper() ==
"TAPE") {
2984 disktype = disktype | TDEDiskDeviceType::Tape;
2987 if ((disktypestring.upper() ==
"COMPACT_FLASH")
2988 || (TQString(udev_device_get_property_value(dev,
"ID_DRIVE_FLASH_CF")) ==
"1")) {
2989 disktype = disktype | TDEDiskDeviceType::CompactFlash;
2992 if ((disktypestring.upper() ==
"MEMORY_STICK")
2993 || (TQString(udev_device_get_property_value(dev,
"ID_DRIVE_FLASH_MS")) ==
"1")) {
2994 disktype = disktype | TDEDiskDeviceType::MemoryStick;
2997 if ((disktypestring.upper() ==
"SMART_MEDIA")
2998 || (TQString(udev_device_get_property_value(dev,
"ID_DRIVE_FLASH_SM")) ==
"1")) {
2999 disktype = disktype | TDEDiskDeviceType::SmartMedia;
3002 if ((disktypestring.upper() ==
"SD_MMC")
3003 || (TQString(udev_device_get_property_value(dev,
"ID_DRIVE_FLASH_SD")) ==
"1")
3004 || (TQString(udev_device_get_property_value(dev,
"ID_DRIVE_FLASH_SDHC")) ==
"1")
3005 || (TQString(udev_device_get_property_value(dev,
"ID_DRIVE_FLASH_MMC")) ==
"1")) {
3006 disktype = disktype | TDEDiskDeviceType::SDMMC;
3009 if ((disktypestring.upper() ==
"FLASHKEY")
3010 || (TQString(udev_device_get_property_value(dev,
" ID_DRIVE_FLASH")) ==
"1")) {
3011 disktype = disktype | TDEDiskDeviceType::Flash;
3014 if (disktypestring.upper() ==
"OPTICAL") {
3015 disktype = disktype | TDEDiskDeviceType::Optical;
3018 if (disktypestring.upper() ==
"JAZ") {
3019 disktype = disktype | TDEDiskDeviceType::Jaz;
3022 if (disktypestring.upper() ==
"DISK") {
3023 disktype = disktype | TDEDiskDeviceType::HDD;
3025 if (disktypestring.isNull()) {
3028 disktype = disktype | TDEDiskDeviceType::HDD;
3033 if ((disktype & TDEDiskDeviceType::Zip) || (disktype & TDEDiskDeviceType::Floppy) || (disktype & TDEDiskDeviceType::Jaz) || (disktype & TDEDiskDeviceType::Tape)) {
3034 disktype = disktype & ~TDEDiskDeviceType::HDD;
3037 if (disktypestring.upper() ==
"CD") {
3038 disktype = disktype & ~TDEDiskDeviceType::HDD;
3039 disktype = disktype | TDEDiskDeviceType::Optical;
3041 if (TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA")) ==
"1") {
3042 disktype = disktype | TDEDiskDeviceType::CDROM;
3044 if (TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA_CD_RW")) ==
"1") {
3045 disktype = disktype | TDEDiskDeviceType::CDRW;
3046 disktype = disktype & ~TDEDiskDeviceType::CDROM;
3048 if (TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA_DVD")) ==
"1") {
3049 disktype = disktype | TDEDiskDeviceType::DVDROM;
3050 disktype = disktype & ~TDEDiskDeviceType::CDROM;
3052 if (TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA_DVD_RAM")) ==
"1") {
3053 disktype = disktype | TDEDiskDeviceType::DVDRAM;
3054 disktype = disktype & ~TDEDiskDeviceType::DVDROM;
3056 if ((TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA_DVD_R")) ==
"1")
3057 || (TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA_DVD_R_DL")) ==
"1")
3058 || (TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA_DVD_PLUS_R")) ==
"1")
3059 || (TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA_DVD_MINUS_R")) ==
"1")
3060 || (TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA_DVD_PLUS_R_DL")) ==
"1")
3061 || (TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA_DVD_MINUS_R_DL")) ==
"1")
3063 disktype = disktype | TDEDiskDeviceType::DVDRW;
3064 disktype = disktype & ~TDEDiskDeviceType::DVDROM;
3066 if ((TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA_DVD_RW")) ==
"1")
3067 || (TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA_DVD_RW_DL")) ==
"1")
3068 || (TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA_DVD_PLUS_RW")) ==
"1")
3069 || (TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA_DVD_MINUS_RW")) ==
"1")
3070 || (TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA_DVD_PLUS_RW_DL")) ==
"1")
3071 || (TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA_DVD_MINUS_RW_DL")) ==
"1")
3073 disktype = disktype | TDEDiskDeviceType::DVDRW;
3074 disktype = disktype & ~TDEDiskDeviceType::DVDROM;
3076 if (TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA_BD")) ==
"1") {
3077 disktype = disktype | TDEDiskDeviceType::BDROM;
3078 disktype = disktype & ~TDEDiskDeviceType::CDROM;
3080 if ((TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA_BD_R")) ==
"1")
3081 || (TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA_BD_R_DL")) ==
"1")
3082 || (TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA_BD_PLUS_R")) ==
"1")
3083 || (TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA_BD_MINUS_R")) ==
"1")
3084 || (TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA_DVD_PLUS_R_DL")) ==
"1")
3085 || (TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA_DVD_MINUS_R_DL")) ==
"1")
3087 disktype = disktype | TDEDiskDeviceType::BDRW;
3088 disktype = disktype & ~TDEDiskDeviceType::BDROM;
3090 if ((TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA_BD_RW")) ==
"1")
3091 || (TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA_BD_RW_DL")) ==
"1")
3092 || (TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA_BD_PLUS_RW")) ==
"1")
3093 || (TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA_BD_MINUS_RW")) ==
"1")
3094 || (TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA_DVD_PLUS_RW_DL")) ==
"1")
3095 || (TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA_DVD_MINUS_RW_DL")) ==
"1")
3097 disktype = disktype | TDEDiskDeviceType::BDRW;
3098 disktype = disktype & ~TDEDiskDeviceType::BDROM;
3100 if (!TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA_TRACK_COUNT_AUDIO")).isNull()) {
3101 disktype = disktype | TDEDiskDeviceType::CDAudio;
3103 if ((TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA_VCD")) ==
"1") || (TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA_SDVD")) ==
"1")) {
3104 disktype = disktype | TDEDiskDeviceType::CDVideo;
3109 if (systempath.startsWith(
"/sys/devices/virtual/block/ram")) {
3110 disktype = disktype | TDEDiskDeviceType::RAM;
3112 if (systempath.startsWith(
"/sys/devices/virtual/block/loop")) {
3113 disktype = disktype | TDEDiskDeviceType::Loop;
3116 if (filesystemtype.upper() ==
"CRYPTO_LUKS") {
3117 disktype = disktype | TDEDiskDeviceType::LUKS;
3119 else if (filesystemtype.upper() ==
"CRYPTO") {
3120 disktype = disktype | TDEDiskDeviceType::OtherCrypted;
3128 typedef TQMap<TQString, TQString> TDEConfigMap;
3130 TQString readUdevAttribute(udev_device* dev, TQString attr) {
3131 return TQString(udev_device_get_property_value(dev, attr.ascii()));
3134 TDEGenericDeviceType::TDEGenericDeviceType readGenericDeviceTypeFromString(TQString query) {
3135 TDEGenericDeviceType::TDEGenericDeviceType ret = TDEGenericDeviceType::Other;
3138 if (query ==
"Root") {
3139 ret = TDEGenericDeviceType::Root;
3141 else if (query ==
"RootSystem") {
3142 ret = TDEGenericDeviceType::RootSystem;
3144 else if (query ==
"CPU") {
3145 ret = TDEGenericDeviceType::CPU;
3147 else if (query ==
"GPU") {
3148 ret = TDEGenericDeviceType::GPU;
3150 else if (query ==
"RAM") {
3151 ret = TDEGenericDeviceType::RAM;
3153 else if (query ==
"Bus") {
3154 ret = TDEGenericDeviceType::Bus;
3156 else if (query ==
"I2C") {
3157 ret = TDEGenericDeviceType::I2C;
3159 else if (query ==
"MDIO") {
3160 ret = TDEGenericDeviceType::MDIO;
3162 else if (query ==
"Mainboard") {
3163 ret = TDEGenericDeviceType::Mainboard;
3165 else if (query ==
"Disk") {
3166 ret = TDEGenericDeviceType::Disk;
3168 else if (query ==
"SCSI") {
3169 ret = TDEGenericDeviceType::SCSI;
3171 else if (query ==
"StorageController") {
3172 ret = TDEGenericDeviceType::StorageController;
3174 else if (query ==
"Mouse") {
3175 ret = TDEGenericDeviceType::Mouse;
3177 else if (query ==
"Keyboard") {
3178 ret = TDEGenericDeviceType::Keyboard;
3180 else if (query ==
"HID") {
3181 ret = TDEGenericDeviceType::HID;
3183 else if (query ==
"Modem") {
3184 ret = TDEGenericDeviceType::Modem;
3186 else if (query ==
"Monitor") {
3187 ret = TDEGenericDeviceType::Monitor;
3189 else if (query ==
"Network") {
3190 ret = TDEGenericDeviceType::Network;
3192 else if (query ==
"Printer") {
3193 ret = TDEGenericDeviceType::Printer;
3195 else if (query ==
"Scanner") {
3196 ret = TDEGenericDeviceType::Scanner;
3198 else if (query ==
"Sound") {
3199 ret = TDEGenericDeviceType::Sound;
3201 else if (query ==
"VideoCapture") {
3202 ret = TDEGenericDeviceType::VideoCapture;
3204 else if (query ==
"IEEE1394") {
3205 ret = TDEGenericDeviceType::IEEE1394;
3207 else if (query ==
"PCMCIA") {
3208 ret = TDEGenericDeviceType::PCMCIA;
3210 else if (query ==
"Camera") {
3211 ret = TDEGenericDeviceType::Camera;
3213 else if (query ==
"Serial") {
3214 ret = TDEGenericDeviceType::Serial;
3216 else if (query ==
"Parallel") {
3217 ret = TDEGenericDeviceType::Parallel;
3219 else if (query ==
"TextIO") {
3220 ret = TDEGenericDeviceType::TextIO;
3222 else if (query ==
"Peripheral") {
3223 ret = TDEGenericDeviceType::Peripheral;
3225 else if (query ==
"Backlight") {
3226 ret = TDEGenericDeviceType::Backlight;
3228 else if (query ==
"Battery") {
3229 ret = TDEGenericDeviceType::Battery;
3231 else if (query ==
"Power") {
3232 ret = TDEGenericDeviceType::PowerSupply;
3234 else if (query ==
"Dock") {
3235 ret = TDEGenericDeviceType::Dock;
3237 else if (query ==
"ThermalSensor") {
3238 ret = TDEGenericDeviceType::ThermalSensor;
3240 else if (query ==
"ThermalControl") {
3241 ret = TDEGenericDeviceType::ThermalControl;
3243 else if (query ==
"Bluetooth") {
3244 ret = TDEGenericDeviceType::BlueTooth;
3246 else if (query ==
"Bridge") {
3247 ret = TDEGenericDeviceType::Bridge;
3249 else if (query ==
"Platform") {
3250 ret = TDEGenericDeviceType::Platform;
3252 else if (query ==
"Cryptography") {
3253 ret = TDEGenericDeviceType::Cryptography;
3255 else if (query ==
"Event") {
3256 ret = TDEGenericDeviceType::Event;
3258 else if (query ==
"Input") {
3259 ret = TDEGenericDeviceType::Input;
3261 else if (query ==
"PNP") {
3262 ret = TDEGenericDeviceType::PNP;
3264 else if (query ==
"OtherACPI") {
3265 ret = TDEGenericDeviceType::OtherACPI;
3267 else if (query ==
"OtherUSB") {
3268 ret = TDEGenericDeviceType::OtherUSB;
3270 else if (query ==
"OtherMultimedia") {
3271 ret = TDEGenericDeviceType::OtherMultimedia;
3273 else if (query ==
"OtherPeripheral") {
3274 ret = TDEGenericDeviceType::OtherPeripheral;
3276 else if (query ==
"OtherSensor") {
3277 ret = TDEGenericDeviceType::OtherSensor;
3279 else if (query ==
"OtherVirtual") {
3280 ret = TDEGenericDeviceType::OtherVirtual;
3283 ret = TDEGenericDeviceType::Other;
3289 TDEDiskDeviceType::TDEDiskDeviceType readDiskDeviceSubtypeFromString(TQString query, TDEDiskDeviceType::TDEDiskDeviceType flagsIn=TDEDiskDeviceType::Null) {
3290 TDEDiskDeviceType::TDEDiskDeviceType ret = flagsIn;
3293 if (query ==
"MediaDevice") {
3294 ret = ret | TDEDiskDeviceType::MediaDevice;
3296 if (query ==
"Floppy") {
3297 ret = ret | TDEDiskDeviceType::Floppy;
3299 if (query ==
"CDROM") {
3300 ret = ret | TDEDiskDeviceType::CDROM;
3302 if (query ==
"CDRW") {
3303 ret = ret | TDEDiskDeviceType::CDRW;
3305 if (query ==
"DVDROM") {
3306 ret = ret | TDEDiskDeviceType::DVDROM;
3308 if (query ==
"DVDRAM") {
3309 ret = ret | TDEDiskDeviceType::DVDRAM;
3311 if (query ==
"DVDRW") {
3312 ret = ret | TDEDiskDeviceType::DVDRW;
3314 if (query ==
"BDROM") {
3315 ret = ret | TDEDiskDeviceType::BDROM;
3317 if (query ==
"BDRW") {
3318 ret = ret | TDEDiskDeviceType::BDRW;
3320 if (query ==
"Zip") {
3321 ret = ret | TDEDiskDeviceType::Zip;
3323 if (query ==
"Jaz") {
3324 ret = ret | TDEDiskDeviceType::Jaz;
3326 if (query ==
"Camera") {
3327 ret = ret | TDEDiskDeviceType::Camera;
3329 if (query ==
"LUKS") {
3330 ret = ret | TDEDiskDeviceType::LUKS;
3332 if (query ==
"OtherCrypted") {
3333 ret = ret | TDEDiskDeviceType::OtherCrypted;
3335 if (query ==
"CDAudio") {
3336 ret = ret | TDEDiskDeviceType::CDAudio;
3338 if (query ==
"CDVideo") {
3339 ret = ret | TDEDiskDeviceType::CDVideo;
3341 if (query ==
"DVDVideo") {
3342 ret = ret | TDEDiskDeviceType::DVDVideo;
3344 if (query ==
"BDVideo") {
3345 ret = ret | TDEDiskDeviceType::BDVideo;
3347 if (query ==
"Flash") {
3348 ret = ret | TDEDiskDeviceType::Flash;
3350 if (query ==
"USB") {
3351 ret = ret | TDEDiskDeviceType::USB;
3353 if (query ==
"Tape") {
3354 ret = ret | TDEDiskDeviceType::Tape;
3356 if (query ==
"HDD") {
3357 ret = ret | TDEDiskDeviceType::HDD;
3359 if (query ==
"Optical") {
3360 ret = ret | TDEDiskDeviceType::Optical;
3362 if (query ==
"RAM") {
3363 ret = ret | TDEDiskDeviceType::RAM;
3365 if (query ==
"Loop") {
3366 ret = ret | TDEDiskDeviceType::Loop;
3368 if (query ==
"CompactFlash") {
3369 ret = ret | TDEDiskDeviceType::CompactFlash;
3371 if (query ==
"MemoryStick") {
3372 ret = ret | TDEDiskDeviceType::MemoryStick;
3374 if (query ==
"SmartMedia") {
3375 ret = ret | TDEDiskDeviceType::SmartMedia;
3377 if (query ==
"SDMMC") {
3378 ret = ret | TDEDiskDeviceType::SDMMC;
3380 if (query ==
"UnlockedCrypt") {
3381 ret = ret | TDEDiskDeviceType::UnlockedCrypt;
3387 TDEGenericDevice* createDeviceObjectForType(TDEGenericDeviceType::TDEGenericDeviceType type) {
3388 TDEGenericDevice* ret = 0;
3390 if (type == TDEGenericDeviceType::Disk) {
3391 ret =
new TDEStorageDevice(type);
3394 ret =
new TDEGenericDevice(type);
3400 TDEGenericDevice* TDEHardwareDevices::classifyUnknownDeviceByExternalRules(udev_device* dev, TDEGenericDevice* existingdevice,
bool classifySubDevices) {
3402 TDEGenericDevice* device = existingdevice;
3403 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Other);
3407 if (classifySubDevices) {
3408 if (!device->m_externalRulesFile.isNull()) {
3409 if (device->type() == TDEGenericDeviceType::Disk) {
3411 TDEStorageDevice* sdevice =
static_cast<TDEStorageDevice*
>(device);
3412 TQStringList subtype = device->m_externalSubtype;
3413 TDEDiskDeviceType::TDEDiskDeviceType desiredSubdeviceType = TDEDiskDeviceType::Null;
3414 if (subtype.count()>0) {
3415 for ( TQStringList::Iterator paramit = subtype.begin(); paramit != subtype.end(); ++paramit ) {
3416 desiredSubdeviceType = readDiskDeviceSubtypeFromString(*paramit, desiredSubdeviceType);
3418 if (desiredSubdeviceType != sdevice->diskType()) {
3419 printf(
"[tdehardwaredevices] Rules file %s used to set device subtype for device at path %s\n", device->m_externalRulesFile.ascii(), device->systemPath().ascii()); fflush(stdout);
3420 sdevice->internalSetDiskType(desiredSubdeviceType);
3427 TQStringList hardware_info_directories(
TDEGlobal::dirs()->resourceDirs(
"data"));
3428 TQString hardware_info_directory_suffix(
"tdehwlib/deviceclasses/");
3429 TQString hardware_info_directory;
3436 device->m_externalRulesFile = TQString::null;
3437 for ( TQStringList::Iterator it = hardware_info_directories.begin(); it != hardware_info_directories.end(); ++it ) {
3438 hardware_info_directory = (*it);
3439 hardware_info_directory += hardware_info_directory_suffix;
3442 TQDir d(hardware_info_directory);
3443 d.setFilter( TQDir::Files | TQDir::Hidden );
3445 const TQFileInfoList *list = d.entryInfoList();
3446 TQFileInfoListIterator it( *list );
3449 while ((fi = it.current()) != 0) {
3450 if (fi->extension(
false) ==
"hwclass") {
3454 TDEConfig rulesFile(fi->absFilePath(),
true,
false);
3456 TDEConfigMap conditionmap = rulesFile.entryMap(
"Conditions");
3457 TDEConfigMap::Iterator cndit;
3458 for (cndit = conditionmap.begin(); cndit != conditionmap.end(); ++cndit) {
3459 TQStringList conditionList = TQStringList::split(
',', cndit.data(),
false);
3460 bool atleastonematch =
false;
3461 for ( TQStringList::Iterator paramit = conditionList.begin(); paramit != conditionList.end(); ++paramit ) {
3462 if (cndit.key() ==
"VENDOR_ID") {
3463 if (device->vendorID() == (*paramit)) {
3464 atleastonematch =
true;
3467 else if (cndit.key() ==
"MODEL_ID") {
3468 if (device->modelID() == (*paramit)) {
3469 atleastonematch =
true;
3472 else if (cndit.key() ==
"DRIVER") {
3473 if (device->deviceDriver() == (*paramit)) {
3474 atleastonematch =
true;
3477 else if (readUdevAttribute(dev, cndit.key()) == (*paramit)) {
3478 atleastonematch =
true;
3481 if (!atleastonematch) {
3487 rulesFile.setGroup(
"DeviceType");
3488 TQString gentype = rulesFile.readEntry(
"GENTYPE");
3489 TDEGenericDeviceType::TDEGenericDeviceType desiredDeviceType = device->type();
3490 if (!gentype.isNull()) {
3491 desiredDeviceType = readGenericDeviceTypeFromString(gentype);
3495 if (desiredDeviceType != device->type()) {
3496 printf(
"[tdehardwaredevices] Rules file %s used to set device type for device at path %s\n", fi->absFilePath().ascii(), device->systemPath().ascii()); fflush(stdout);
3497 if (m_deviceList.contains(device)) {
3498 m_deviceList.remove(device);
3503 device = createDeviceObjectForType(desiredDeviceType);
3508 device->m_externalSubtype = rulesFile.readListEntry(
"SUBTYPE",
',');
3509 device->m_externalRulesFile = fi->absFilePath();
3512 rulesFile.setGroup(
"DeviceSettings");
3513 device->internalSetBlacklistedForUpdate(rulesFile.readBoolEntry(
"UPDATE_BLACKLISTED", device->blacklistedForUpdate()));
3525 TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TDEGenericDevice* existingdevice,
bool force_full_classification) {
3527 TQString devicename;
3528 TQString devicetype;
3529 TQString devicedriver;
3530 TQString devicesubsystem;
3531 TQString devicenode;
3532 TQString systempath;
3533 TQString devicevendorid;
3534 TQString devicemodelid;
3535 TQString devicevendoridenc;
3536 TQString devicemodelidenc;
3537 TQString devicesubvendorid;
3538 TQString devicesubmodelid;
3539 TQString devicetypestring;
3540 TQString devicetypestring_alt;
3541 TQString devicepciclass;
3542 TDEGenericDevice* device = existingdevice;
3543 bool temp_udev_device = !dev;
3545 devicename = (udev_device_get_sysname(dev));
3546 devicetype = (udev_device_get_devtype(dev));
3547 devicedriver = (udev_device_get_driver(dev));
3548 devicesubsystem = (udev_device_get_subsystem(dev));
3549 devicenode = (udev_device_get_devnode(dev));
3550 systempath = (udev_device_get_syspath(dev));
3552 devicevendorid = (udev_device_get_property_value(dev,
"ID_VENDOR_ID"));
3553 devicemodelid = (udev_device_get_property_value(dev,
"ID_MODEL_ID"));
3554 devicevendoridenc = (udev_device_get_property_value(dev,
"ID_VENDOR_ENC"));
3555 devicemodelidenc = (udev_device_get_property_value(dev,
"ID_MODEL_ENC"));
3556 devicesubvendorid = (udev_device_get_property_value(dev,
"ID_SUBVENDOR_ID"));
3557 devicesubmodelid = (udev_device_get_property_value(dev,
"ID_SUBMODEL_ID"));
3558 devicetypestring = (udev_device_get_property_value(dev,
"ID_TYPE"));
3559 devicetypestring_alt = (udev_device_get_property_value(dev,
"DEVTYPE"));
3560 devicepciclass = (udev_device_get_property_value(dev,
"PCI_CLASS"));
3564 devicename = device->name();
3565 devicetype = device->m_udevtype;
3566 devicedriver = device->deviceDriver();
3567 devicesubsystem = device->subsystem();
3568 devicenode = device->deviceNode();
3569 systempath = device->systemPath();
3570 devicevendorid = device->vendorID();
3571 devicemodelid = device->modelID();
3572 devicevendoridenc = device->vendorEncoded();
3573 devicemodelidenc = device->modelEncoded();
3574 devicesubvendorid = device->subVendorID();
3575 devicesubmodelid = device->subModelID();
3576 devicetypestring = device->m_udevdevicetypestring;
3577 devicetypestring_alt = device->udevdevicetypestring_alt;
3578 devicepciclass = device->PCIClass();
3580 TQString syspathudev = systempath;
3581 syspathudev.truncate(syspathudev.length()-1);
3582 dev = udev_device_new_from_syspath(m_udevStruct, syspathudev.ascii());
3591 TQString current_path = systempath;
3592 TQString devicemodalias = TQString::null;
3594 while (done ==
false) {
3595 TQString malnodename = current_path;
3596 malnodename.append(
"/modalias");
3597 TQFile malfile(malnodename);
3598 if (malfile.open(IO_ReadOnly)) {
3599 TQTextStream stream( &malfile );
3600 devicemodalias = stream.readLine();
3603 if (devicemodalias.startsWith(
"pci") || devicemodalias.startsWith(
"usb")) {
3607 devicemodalias = TQString::null;
3608 current_path.truncate(current_path.findRev(
"/"));
3609 if (!current_path.startsWith(
"/sys/devices")) {
3619 if (devicevendorid.isNull() || devicemodelid.isNull() || devicemodelid.contains(
"/")) {
3620 if (devicemodalias != TQString::null) {
3622 if (devicemodalias.startsWith(
"pci")) {
3623 int vloc = devicemodalias.find(
"v");
3624 int dloc = devicemodalias.find(
"d", vloc);
3625 int svloc = devicemodalias.find(
"sv");
3626 int sdloc = devicemodalias.find(
"sd", vloc);
3628 devicevendorid = devicemodalias.mid(vloc+1, 8).lower();
3629 devicemodelid = devicemodalias.mid(dloc+1, 8).lower();
3631 devicesubvendorid = devicemodalias.mid(svloc+1, 8).lower();
3632 devicesubmodelid = devicemodalias.mid(sdloc+1, 8).lower();
3634 devicevendorid.remove(0,4);
3635 devicemodelid.remove(0,4);
3636 devicesubvendorid.remove(0,4);
3637 devicesubmodelid.remove(0,4);
3639 if (devicemodalias.startsWith(
"usb")) {
3640 int vloc = devicemodalias.find(
"v");
3641 int dloc = devicemodalias.find(
"p", vloc);
3642 int svloc = devicemodalias.find(
"sv");
3643 int sdloc = devicemodalias.find(
"sp", vloc);
3645 devicevendorid = devicemodalias.mid(vloc+1, 4).lower();
3646 devicemodelid = devicemodalias.mid(dloc+1, 4).lower();
3648 devicesubvendorid = devicemodalias.mid(svloc+1, 4).lower();
3649 devicesubmodelid = devicemodalias.mid(sdloc+1, 4).lower();
3656 if (devicedriver.isNull()) {
3657 TQString driverSymlink = udev_device_get_syspath(dev);
3658 TQString driverSymlinkDir = driverSymlink;
3659 driverSymlink.append(
"/device/driver");
3660 driverSymlinkDir.append(
"/device/");
3661 TQFileInfo dirfi(driverSymlink);
3662 if (dirfi.isSymLink()) {
3663 char* collapsedPath = realpath((driverSymlinkDir + dirfi.readLink()).ascii(), NULL);
3664 devicedriver = TQString(collapsedPath);
3665 free(collapsedPath);
3666 devicedriver.remove(0, devicedriver.findRev(
"/")+1);
3671 TQString classnodename = systempath;
3672 classnodename.append(
"/class");
3673 TQFile classfile( classnodename );
3674 if ( classfile.open( IO_ReadOnly ) ) {
3675 TQTextStream stream( &classfile );
3676 devicepciclass = stream.readLine();
3677 devicepciclass.replace(
"0x",
"");
3678 devicepciclass = devicepciclass.lower();
3685 TQString syspath_tail = systempath.lower();
3686 syspath_tail.truncate(syspath_tail.length()-1);
3687 syspath_tail.remove(0, syspath_tail.findRev(
"/")+1);
3688 if (syspath_tail.startsWith(
"event")) {
3689 if (!device) device =
new TDEEventDevice(TDEGenericDeviceType::Event);
3692 if (syspath_tail.startsWith(
"input")) {
3693 if (!device) device =
new TDEInputDevice(TDEGenericDeviceType::Input);
3699 bool is_keyboard =
false;
3700 TQString inputtopdirname = udev_device_get_syspath(dev);
3701 inputtopdirname.append(
"/input/");
3702 TQDir inputdir(inputtopdirname);
3703 inputdir.setFilter(TQDir::All);
3704 const TQFileInfoList *dirlist = inputdir.entryInfoList();
3706 TQFileInfoListIterator inputdirsit(*dirlist);
3708 while ( (dirfi = inputdirsit.current()) != 0 ) {
3709 if ((dirfi->fileName() !=
".") && (dirfi->fileName() !=
"..")) {
3710 struct udev_device *slavedev;
3711 slavedev = udev_device_new_from_syspath(m_udevStruct, (inputtopdirname + dirfi->fileName()).ascii());
3712 if (udev_device_get_property_value(slavedev,
"ID_INPUT_KEYBOARD") != 0) {
3715 udev_device_unref(slavedev);
3721 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Keyboard);
3725 if (((devicetype ==
"disk")
3726 || (devicetype ==
"partition")
3727 || (devicedriver ==
"floppy")
3728 || (devicesubsystem ==
"scsi_disk")
3729 || (devicesubsystem ==
"scsi_tape"))
3730 && ((devicenode !=
"")
3732 if (!device) device =
new TDEStorageDevice(TDEGenericDeviceType::Disk);
3734 else if (devicetype ==
"host") {
3735 if (devicesubsystem ==
"bluetooth") {
3736 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::BlueTooth);
3739 else if (devicetype.isNull()) {
3740 if (devicesubsystem ==
"acpi") {
3743 TQString pnpgentype = systempath;
3744 pnpgentype.remove(0, pnpgentype.findRev(
"/")+1);
3745 pnpgentype.truncate(pnpgentype.find(
":"));
3746 if (pnpgentype.startsWith(
"PNP")) {
3750 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::OtherACPI);
3753 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::OtherACPI);
3756 else if (devicesubsystem ==
"input") {
3760 if (systempath.contains(
"/mouse")) {
3761 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Mouse);
3766 if (udev_device_get_property_value(dev,
"ID_INPUT_MOUSE") != 0) {
3767 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Mouse);
3773 if (udev_device_get_property_value(dev,
"ID_INPUT_KEYBOARD") != 0) {
3774 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Keyboard);
3778 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::HID);
3781 else if (devicesubsystem ==
"tty") {
3782 if (devicenode.contains(
"/ttyS")) {
3783 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Serial);
3786 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::TextIO);
3789 else if (devicesubsystem ==
"usb-serial") {
3790 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Serial);
3792 else if ((devicesubsystem ==
"spi_master")
3793 || (devicesubsystem ==
"spidev")) {
3794 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Serial);
3796 else if (devicesubsystem ==
"spi") {
3797 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Platform);
3799 else if (devicesubsystem ==
"thermal") {
3802 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::ThermalControl);
3804 else if (devicesubsystem ==
"hwmon") {
3807 if (!device) device =
new TDESensorDevice(TDEGenericDeviceType::OtherSensor);
3813 if (devicesubsystem ==
"backlight") {
3814 if (!device) device =
new TDEBacklightDevice(TDEGenericDeviceType::Backlight);
3816 if (systempath.lower().startsWith(
"/sys/devices/virtual")) {
3817 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::OtherVirtual);
3819 if (systempath.lower().startsWith(
"/sys/module/")
3820 || (systempath.lower().startsWith(
"/sys/kernel/"))) {
3821 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Platform);
3823 if ((devicetypestring ==
"audio")
3824 || (devicesubsystem ==
"sound")
3825 || (devicesubsystem ==
"ac97")) {
3826 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Sound);
3828 if ((devicesubsystem ==
"video4linux")
3829 || (devicesubsystem ==
"dvb")) {
3830 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::VideoCapture);
3832 if ((devicetypestring_alt ==
"scsi_target")
3833 || (devicesubsystem ==
"scsi_host")
3834 || (devicesubsystem ==
"scsi_disk")
3835 || (devicesubsystem ==
"scsi_device")
3836 || (devicesubsystem ==
"scsi_generic")
3837 || (devicesubsystem ==
"scsi")
3838 || (devicetypestring_alt ==
"sas_target")
3839 || (devicesubsystem ==
"sas_host")
3840 || (devicesubsystem ==
"sas_port")
3841 || (devicesubsystem ==
"sas_device")
3842 || (devicesubsystem ==
"sas_generic")
3843 || (devicesubsystem ==
"sas_phy")
3844 || (devicesubsystem ==
"sas_end_device")
3845 || (devicesubsystem ==
"spi_transport")
3846 || (devicesubsystem ==
"spi_host")
3847 || (devicesubsystem ==
"ata_port")
3848 || (devicesubsystem ==
"ata_link")
3849 || (devicesubsystem ==
"ata_disk")
3850 || (devicesubsystem ==
"ata_device")
3851 || (devicesubsystem ==
"ata")) {
3852 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Platform);
3854 if (devicesubsystem ==
"infiniband") {
3855 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Peripheral);
3857 if ((devicesubsystem ==
"infiniband_cm")
3858 || (devicesubsystem ==
"infiniband_mad")) {
3859 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Platform);
3861 if ((devicesubsystem ==
"enclosure")
3862 || (devicesubsystem ==
"clocksource")
3863 || (devicesubsystem ==
"amba")) {
3864 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Platform);
3866 if (devicesubsystem ==
"ipmi_si") {
3867 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Mainboard);
3869 if (devicesubsystem ==
"misc") {
3870 if (devicedriver.startsWith(
"tpm_")) {
3871 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Cryptography);
3874 if (devicesubsystem ==
"leds") {
3875 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::OtherACPI);
3877 if (devicesubsystem ==
"net") {
3878 if (!device) device =
new TDENetworkDevice(TDEGenericDeviceType::Network);
3880 if ((devicesubsystem ==
"i2c")
3881 || (devicesubsystem ==
"i2c-dev")) {
3882 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::I2C);
3884 if (devicesubsystem ==
"mdio_bus") {
3885 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::MDIO);
3887 if (devicesubsystem ==
"graphics") {
3888 if (devicenode.isNull()) {
3889 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::GPU);
3892 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Platform);
3895 if (devicesubsystem ==
"mmc_host") {
3896 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::StorageController);
3898 if (devicesubsystem ==
"mmc") {
3899 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Platform);
3901 if ((devicesubsystem ==
"event_source")
3902 || (devicesubsystem ==
"rtc")) {
3903 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Mainboard);
3905 if (devicesubsystem ==
"bsg") {
3906 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::SCSI);
3908 if (devicesubsystem ==
"firewire") {
3909 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::IEEE1394);
3911 if (devicesubsystem ==
"drm") {
3912 if (devicenode.isNull()) {
3913 if (!device) device =
new TDEMonitorDevice(TDEGenericDeviceType::Monitor);
3916 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Platform);
3919 if (devicesubsystem ==
"serio") {
3920 if (devicedriver.contains(
"atkbd")) {
3921 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Keyboard);
3923 else if (devicedriver.contains(
"mouse")) {
3924 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Mouse);
3927 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Serial);
3930 if (devicesubsystem ==
"ppdev") {
3931 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Parallel);
3933 if (devicesubsystem ==
"printer") {
3934 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Printer);
3936 if (devicesubsystem ==
"bridge") {
3937 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Bridge);
3939 if ((devicesubsystem ==
"pci_bus")
3940 || (devicesubsystem ==
"pci_express")) {
3941 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Bus);
3943 if (devicesubsystem ==
"pcmcia_socket") {
3944 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::PCMCIA);
3946 if (devicesubsystem ==
"platform") {
3947 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Platform);
3949 if (devicesubsystem ==
"ieee80211") {
3950 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Platform);
3952 if (devicesubsystem ==
"rfkill") {
3953 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Platform);
3955 if (devicesubsystem ==
"machinecheck") {
3956 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Platform);
3958 if (devicesubsystem ==
"pnp") {
3959 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::PNP);
3961 if ((devicesubsystem ==
"hid")
3962 || (devicesubsystem ==
"hidraw")
3963 || (devicesubsystem ==
"usbhid")) {
3964 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::HID);
3966 if (devicesubsystem ==
"power_supply") {
3967 TQString powersupplyname(udev_device_get_property_value(dev,
"POWER_SUPPLY_NAME"));
3968 if (powersupplyname.upper().startsWith(
"AC")) {
3969 if (!device) device =
new TDEMainsPowerDevice(TDEGenericDeviceType::PowerSupply);
3972 if (!device) device =
new TDEBatteryDevice(TDEGenericDeviceType::Battery);
3978 if (!devicepciclass.isNull()) {
3980 if (devicepciclass.startsWith(
"0001")) {
3981 if (devicenode.isNull()) {
3982 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::GPU);
3985 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Platform);
3989 TQString devicepcisubclass = devicepciclass;
3990 devicepcisubclass = devicepcisubclass.remove(0,2);
3991 if (devicepciclass.startsWith(
"01")) {
3992 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::StorageController);
3994 if (devicepciclass.startsWith(
"02")) {
3995 if (!device) device =
new TDENetworkDevice(TDEGenericDeviceType::Network);
3997 if (devicepciclass.startsWith(
"03")) {
3998 if (devicenode.isNull()) {
3999 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::GPU);
4002 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Platform);
4005 if (devicepciclass.startsWith(
"04")) {
4006 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::OtherMultimedia);
4008 if (devicepciclass.startsWith(
"05")) {
4009 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::RAM);
4011 if (devicepciclass.startsWith(
"06")) {
4012 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Bridge);
4014 if (devicepciclass.startsWith(
"07")) {
4015 if (devicepcisubclass.startsWith(
"03")) {
4016 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Modem);
4019 if (devicepciclass.startsWith(
"0a")) {
4020 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Dock);
4022 if (devicepciclass.startsWith(
"0b")) {
4023 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::CPU);
4025 if (devicepciclass.startsWith(
"0c")) {
4026 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Serial);
4032 if ((devicesubsystem ==
"usb")
4033 || (devicesubsystem ==
"usb_device")
4034 || (devicesubsystem ==
"usbmon")) {
4036 int usbInterfaceClass = -1;
4038 TQFile ifaceprotofile(current_path +
"/bInterfaceClass");
4039 if (ifaceprotofile.open(IO_ReadOnly)) {
4040 TQTextStream stream( &ifaceprotofile );
4041 usbInterfaceClass = stream.readLine().toUInt();
4042 ifaceprotofile.close();
4046 int usbInterfaceSubClass = -1;
4048 TQFile ifaceprotofile(current_path +
"/bInterfaceSubClass");
4049 if (ifaceprotofile.open(IO_ReadOnly)) {
4050 TQTextStream stream( &ifaceprotofile );
4051 usbInterfaceSubClass = stream.readLine().toUInt();
4052 ifaceprotofile.close();
4056 int usbInterfaceProtocol = -1;
4058 TQFile ifaceprotofile(current_path +
"/bInterfaceProtocol");
4059 if (ifaceprotofile.open(IO_ReadOnly)) {
4060 TQTextStream stream( &ifaceprotofile );
4061 usbInterfaceProtocol = stream.readLine().toUInt();
4062 ifaceprotofile.close();
4065 if ((usbInterfaceClass == 6) && (usbInterfaceSubClass == 1) && (usbInterfaceProtocol == 1)) {
4068 device =
new TDEStorageDevice(TDEGenericDeviceType::Disk);
4069 TDEStorageDevice* sdevice =
static_cast<TDEStorageDevice*
>(device);
4070 sdevice->internalSetDiskType(TDEDiskDeviceType::Camera);
4071 TQString parentsyspathudev = systempath;
4072 parentsyspathudev.truncate(parentsyspathudev.length()-1);
4073 parentsyspathudev.truncate(parentsyspathudev.findRev(
"/"));
4074 struct udev_device *parentdev;
4075 parentdev = udev_device_new_from_syspath(m_udevStruct, parentsyspathudev.ascii());
4076 devicenode = (udev_device_get_devnode(parentdev));
4080 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::OtherUSB);
4083 if (devicesubsystem ==
"pci") {
4084 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::OtherPeripheral);
4086 if (devicesubsystem ==
"cpu") {
4087 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Platform);
4093 if (!device) device =
new TDEGenericDevice(TDEGenericDeviceType::Other);
4094 printf(
"[FIXME] UNCLASSIFIED DEVICE name: %s type: %s subsystem: %s driver: %s [Node Path: %s] [Syspath: %s] [%s:%s]\n", devicename.ascii(), devicetype.ascii(), devicesubsystem.ascii(), devicedriver.ascii(), devicenode.ascii(), udev_device_get_syspath(dev), devicevendorid.ascii(), devicemodelid.ascii()); fflush(stdout);
4098 if ((device->type() == TDEGenericDeviceType::Root) || (device->type() == TDEGenericDeviceType::RootSystem)) {
4099 systempath = device->systemPath();
4103 device->internalSetName(devicename);
4104 device->internalSetDeviceNode(devicenode);
4105 device->internalSetSystemPath(systempath);
4106 device->internalSetVendorID(devicevendorid);
4107 device->internalSetModelID(devicemodelid);
4108 device->internalSetVendorEncoded(devicevendoridenc);
4109 device->internalSetModelEncoded(devicemodelidenc);
4110 device->internalSetSubVendorID(devicesubvendorid);
4111 device->internalSetSubModelID(devicesubmodelid);
4112 device->internalSetModuleAlias(devicemodalias);
4113 device->internalSetDeviceDriver(devicedriver);
4114 device->internalSetSubsystem(devicesubsystem);
4115 device->internalSetPCIClass(devicepciclass);
4117 updateBlacklists(device, dev);
4119 if (force_full_classification) {
4121 device = classifyUnknownDeviceByExternalRules(dev, device,
false);
4124 if (device->type() == TDEGenericDeviceType::Disk) {
4125 TDEStorageDevice* sdevice =
static_cast<TDEStorageDevice*
>(device);
4126 if (sdevice->diskType() & TDEDiskDeviceType::Camera) {
4128 sdevice->internalSetDiskStatus(TDEDiskDeviceStatus::Removable);
4129 sdevice->internalSetFileSystemName(
"pictbridge");
4132 bool removable =
false;
4133 bool hotpluggable =
false;
4142 TQString capabilitynodename = systempath;
4143 capabilitynodename.append(
"/capability");
4144 TQFile capabilityfile( capabilitynodename );
4145 unsigned int capabilities = 0;
4146 if ( capabilityfile.open( IO_ReadOnly ) ) {
4147 TQTextStream stream( &capabilityfile );
4148 TQString capabilitystring;
4149 capabilitystring = stream.readLine();
4150 capabilities = capabilitystring.toUInt();
4151 capabilityfile.close();
4153 if (capabilities & GENHD_FL_REMOVABLE) {
4156 hotpluggable =
true;
4158 if (capabilities & GENHD_FL_MEDIA_CHANGE_NOTIFY) {
4163 TQStringList holdingDeviceNodes;
4164 TQString holdersnodename = udev_device_get_syspath(dev);
4165 holdersnodename.append(
"/holders/");
4166 TQDir holdersdir(holdersnodename);
4167 holdersdir.setFilter(TQDir::All);
4168 const TQFileInfoList *dirlist = holdersdir.entryInfoList();
4170 TQFileInfoListIterator holdersdirit(*dirlist);
4172 while ( (dirfi = holdersdirit.current()) != 0 ) {
4173 if (dirfi->isSymLink()) {
4174 char* collapsedPath = realpath((holdersnodename + dirfi->readLink()).ascii(), NULL);
4175 holdingDeviceNodes.append(TQString(collapsedPath));
4176 free(collapsedPath);
4183 TQStringList slaveDeviceNodes;
4184 TQString slavesnodename = udev_device_get_syspath(dev);
4185 slavesnodename.append(
"/slaves/");
4186 TQDir slavedir(slavesnodename);
4187 slavedir.setFilter(TQDir::All);
4188 dirlist = slavedir.entryInfoList();
4190 TQFileInfoListIterator slavedirit(*dirlist);
4192 while ( (dirfi = slavedirit.current()) != 0 ) {
4193 if (dirfi->isSymLink()) {
4194 char* collapsedPath = realpath((slavesnodename + dirfi->readLink()).ascii(), NULL);
4195 slaveDeviceNodes.append(TQString(collapsedPath));
4196 free(collapsedPath);
4203 TQString devicevendor(udev_device_get_property_value(dev,
"ID_VENDOR"));
4204 TQString devicemodel(udev_device_get_property_value(dev,
"ID_MODEL"));
4205 TQString devicebus(udev_device_get_property_value(dev,
"ID_BUS"));
4208 TQString disklabel(udev_device_get_property_value(dev,
"ID_FS_LABEL"));
4209 TQString diskuuid(udev_device_get_property_value(dev,
"ID_FS_UUID"));
4210 TQString filesystemtype(udev_device_get_property_value(dev,
"ID_FS_TYPE"));
4211 TQString filesystemusage(udev_device_get_property_value(dev,
"ID_FS_USAGE"));
4213 device->internalSetVendorName(devicevendor);
4214 device->internalSetVendorModel(devicemodel);
4215 device->internalSetDeviceBus(devicebus);
4217 TDEDiskDeviceType::TDEDiskDeviceType disktype = sdevice->diskType();
4218 TDEDiskDeviceStatus::TDEDiskDeviceStatus diskstatus = TDEDiskDeviceStatus::Null;
4220 disktype = classifyDiskType(dev, devicebus, devicetypestring, systempath, devicevendor, devicemodel, filesystemtype, devicedriver);
4221 sdevice->internalSetDiskType(disktype);
4222 device = classifyUnknownDeviceByExternalRules(dev, device,
true);
4223 disktype = sdevice->diskType();
4225 if ((disktype & TDEDiskDeviceType::CDROM)
4226 || (disktype & TDEDiskDeviceType::CDRW)
4227 || (disktype & TDEDiskDeviceType::DVDROM)
4228 || (disktype & TDEDiskDeviceType::DVDRAM)
4229 || (disktype & TDEDiskDeviceType::DVDRW)
4230 || (disktype & TDEDiskDeviceType::BDROM)
4231 || (disktype & TDEDiskDeviceType::BDRW)
4232 || (disktype & TDEDiskDeviceType::CDAudio)
4233 || (disktype & TDEDiskDeviceType::CDVideo)
4234 || (disktype & TDEDiskDeviceType::DVDVideo)
4235 || (disktype & TDEDiskDeviceType::BDVideo)
4238 disktype = disktype | TDEDiskDeviceType::Optical;
4241 if (disktype & TDEDiskDeviceType::Floppy) {
4244 TQString floppyblknodename = systempath;
4245 floppyblknodename.append(
"/block");
4246 TQDir floppyblkdir(floppyblknodename);
4247 floppyblkdir.setFilter(TQDir::All);
4248 const TQFileInfoList *floppyblkdirlist = floppyblkdir.entryInfoList();
4249 if (floppyblkdirlist) {
4250 TQFileInfoListIterator floppyblkdirit(*floppyblkdirlist);
4252 while ( (dirfi = floppyblkdirit.current()) != 0 ) {
4253 if ((dirfi->fileName() !=
".") && (dirfi->fileName() !=
"..")) {
4255 devicenode = TQString(
"/dev/").append(dirfi->fileName());
4270 TQString floppycmsnodename = systempath;
4271 floppycmsnodename.append(
"/cmos");
4272 TQFile floppycmsfile( floppycmsnodename );
4273 TQString cmosstring;
4274 if ( floppycmsfile.open( IO_ReadOnly ) ) {
4275 TQTextStream stream( &floppycmsfile );
4276 cmosstring = stream.readLine();
4277 floppycmsfile.close();
4282 if (devicenode.isNull()) {
4284 disktype = disktype & ~TDEDiskDeviceType::Floppy;
4288 if (devicetypestring.upper() ==
"CD") {
4289 if (TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA_STATE")).upper() ==
"BLANK") {
4290 diskstatus = diskstatus | TDEDiskDeviceStatus::Blank;
4292 sdevice->internalSetMediaInserted((TQString(udev_device_get_property_value(dev,
"ID_CDROM_MEDIA")) !=
""));
4295 if (disktype & TDEDiskDeviceType::Zip) {
4297 TQString zipnodename = systempath;
4298 zipnodename.append(
"/size");
4299 TQFile namefile( zipnodename );
4301 if ( namefile.open( IO_ReadOnly ) ) {
4302 TQTextStream stream( &namefile );
4303 zipsize = stream.readLine();
4306 if (!zipsize.isNull()) {
4307 sdevice->internalSetMediaInserted((zipsize.toInt() != 0));
4312 diskstatus = diskstatus | TDEDiskDeviceStatus::Removable;
4315 diskstatus = diskstatus | TDEDiskDeviceStatus::Hotpluggable;
4318 if ((filesystemtype.upper() !=
"CRYPTO_LUKS") && (filesystemtype.upper() !=
"CRYPTO") && (filesystemtype.upper() !=
"SWAP") && (!filesystemtype.isNull())) {
4319 diskstatus = diskstatus | TDEDiskDeviceStatus::ContainsFilesystem;
4323 diskstatus = diskstatus | TDEDiskDeviceStatus::Mountable;
4324 if ((devicetypestring.upper().isNull()) && (disktype & TDEDiskDeviceType::HDD)) {
4325 diskstatus = diskstatus & ~TDEDiskDeviceStatus::Mountable;
4328 if (sdevice->mediaInserted()) {
4329 diskstatus = diskstatus | TDEDiskDeviceStatus::Inserted;
4332 diskstatus = diskstatus & ~TDEDiskDeviceStatus::Mountable;
4336 if (filesystemtype.upper() ==
"SWAP") {
4337 diskstatus = diskstatus & ~TDEDiskDeviceStatus::Mountable;
4340 if ((disktype & TDEDiskDeviceType::HDD) || (disktype & TDEDiskDeviceType::Optical)) {
4341 if (!(diskstatus & TDEDiskDeviceStatus::ContainsFilesystem)) {
4342 diskstatus = diskstatus & ~TDEDiskDeviceStatus::Mountable;
4346 if (holdingDeviceNodes.count() > 0) {
4347 diskstatus = diskstatus | TDEDiskDeviceStatus::UsedByDevice;
4350 if (slaveDeviceNodes.count() > 0) {
4351 diskstatus = diskstatus | TDEDiskDeviceStatus::UsesDevice;
4355 for ( TQStringList::Iterator slaveit = slaveDeviceNodes.begin(); slaveit != slaveDeviceNodes.end(); ++slaveit ) {
4356 struct udev_device *slavedev;
4357 slavedev = udev_device_new_from_syspath(m_udevStruct, (*slaveit).ascii());
4358 TQString slavediskfstype(udev_device_get_property_value(slavedev,
"ID_FS_TYPE"));
4359 if ((slavediskfstype.upper() ==
"CRYPTO_LUKS") || (slavediskfstype.upper() ==
"CRYPTO")) {
4360 disktype = disktype | TDEDiskDeviceType::UnlockedCrypt;
4362 disktype = disktype | classifyDiskType(slavedev, TQString(udev_device_get_property_value(dev,
"ID_BUS")), TQString(udev_device_get_property_value(dev,
"ID_TYPE")), (*slaveit), TQString(udev_device_get_property_value(dev,
"ID_VENDOR")), TQString(udev_device_get_property_value(dev,
"ID_MODEL")), TQString(udev_device_get_property_value(dev,
"ID_FS_TYPE")), TQString(udev_device_get_driver(dev)));
4364 udev_device_unref(slavedev);
4367 sdevice->internalSetDiskType(disktype);
4368 sdevice->internalSetDiskUUID(diskuuid);
4369 sdevice->internalSetDiskStatus(diskstatus);
4370 sdevice->internalSetFileSystemName(filesystemtype);
4371 sdevice->internalSetFileSystemUsage(filesystemusage);
4372 sdevice->internalSetSlaveDevices(slaveDeviceNodes);
4373 sdevice->internalSetHoldingDevices(holdingDeviceNodes);
4376 if ((sdevice->isDiskOfType(TDEDiskDeviceType::CDROM))
4377 || (sdevice->isDiskOfType(TDEDiskDeviceType::CDRW))
4378 || (sdevice->isDiskOfType(TDEDiskDeviceType::DVDROM))
4379 || (sdevice->isDiskOfType(TDEDiskDeviceType::DVDRW))
4380 || (sdevice->isDiskOfType(TDEDiskDeviceType::BDROM))
4381 || (sdevice->isDiskOfType(TDEDiskDeviceType::BDRW))
4382 || (sdevice->isDiskOfType(TDEDiskDeviceType::CDAudio))
4383 || (sdevice->isDiskOfType(TDEDiskDeviceType::CDVideo))
4384 || (sdevice->isDiskOfType(TDEDiskDeviceType::DVDVideo))
4385 || (sdevice->isDiskOfType(TDEDiskDeviceType::BDVideo))
4387 if (disklabel ==
"" && sdevice->diskLabel().isNull()) {
4389 FILE *exepipe = popen(((TQString(
"volname %1").arg(devicenode).ascii())),
"r");
4392 disklabel = fgets(buffer,
sizeof(buffer), exepipe);
4398 sdevice->internalSetDiskLabel(disklabel);
4402 if (device->type() == TDEGenericDeviceType::Network) {
4404 TQString potentialdevicenode = systempath;
4405 if (potentialdevicenode.endsWith(
"/")) potentialdevicenode.truncate(potentialdevicenode.length()-1);
4406 potentialdevicenode.remove(0, potentialdevicenode.findRev(
"/")+1);
4407 TQString potentialparentnode = systempath;
4408 if (potentialparentnode.endsWith(
"/")) potentialparentnode.truncate(potentialparentnode.length()-1);
4409 potentialparentnode.remove(0, potentialparentnode.findRev(
"/", potentialparentnode.findRev(
"/")-1)+1);
4410 if (potentialparentnode.startsWith(
"net/")) {
4411 devicenode = potentialdevicenode;
4414 if (devicenode.isNull()) {
4418 device->m_deviceType = TDEGenericDeviceType::Platform;
4422 TDENetworkDevice* ndevice =
dynamic_cast<TDENetworkDevice*
>(device);
4423 TQString valuesnodename = systempath +
"/";
4424 TQDir valuesdir(valuesnodename);
4425 valuesdir.setFilter(TQDir::All);
4427 const TQFileInfoList *dirlist = valuesdir.entryInfoList();
4429 TQFileInfoListIterator valuesdirit(*dirlist);
4431 while ( (dirfi = valuesdirit.current()) != 0 ) {
4432 nodename = dirfi->fileName();
4433 TQFile file( valuesnodename + nodename );
4434 if ( file.open( IO_ReadOnly ) ) {
4435 TQTextStream stream( &file );
4437 line = stream.readLine();
4438 if (nodename ==
"address") {
4439 ndevice->internalSetMacAddress(line);
4441 if (nodename ==
"carrier") {
4442 ndevice->internalSetCarrierPresent(line.toInt());
4444 if (nodename ==
"dormant") {
4445 ndevice->internalSetDormant(line.toInt());
4447 if (nodename ==
"operstate") {
4448 TQString friendlyState = line.lower();
4449 friendlyState[0] = friendlyState[0].upper();
4450 ndevice->internalSetState(friendlyState);
4458 if (ndevice->state().upper() ==
"UP") {
4459 struct ifaddrs *ifaddr, *ifa;
4461 char host[NI_MAXHOST];
4463 if (getifaddrs(&ifaddr) != -1) {
4464 for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
4465 if (ifa->ifa_addr == NULL) {
4469 family = ifa->ifa_addr->sa_family;
4471 if (TQString(ifa->ifa_name) == devicenode) {
4472 if ((family == AF_INET) || (family == AF_INET6)) {
4473 s = getnameinfo(ifa->ifa_addr, (family == AF_INET) ?
sizeof(
struct sockaddr_in) :
sizeof(
struct sockaddr_in6), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
4475 TQString address(host);
4476 if (family == AF_INET) {
4477 ndevice->internalSetIpV4Address(address);
4479 if (family == AF_INET6) {
4480 address.truncate(address.findRev(
"%"));
4481 ndevice->internalSetIpV6Address(address);
4484 s = getnameinfo(ifa->ifa_netmask, (family == AF_INET) ?
sizeof(
struct sockaddr_in) :
sizeof(
struct sockaddr_in6), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
4486 TQString address(host);
4487 if (family == AF_INET) {
4488 ndevice->internalSetIpV4Netmask(address);
4490 if (family == AF_INET6) {
4491 address.truncate(address.findRev(
"%"));
4492 ndevice->internalSetIpV6Netmask(address);
4495 s = getnameinfo(ifa->ifa_ifu.ifu_broadaddr, (family == AF_INET) ?
sizeof(
struct sockaddr_in) :
sizeof(
struct sockaddr_in6), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
4497 TQString address(host);
4498 if (family == AF_INET) {
4499 ndevice->internalSetIpV4Broadcast(address);
4501 if (family == AF_INET6) {
4502 address.truncate(address.findRev(
"%"));
4503 ndevice->internalSetIpV6Broadcast(address);
4506 s = getnameinfo(ifa->ifa_ifu.ifu_dstaddr, (family == AF_INET) ?
sizeof(
struct sockaddr_in) :
sizeof(
struct sockaddr_in6), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
4508 TQString address(host);
4509 if (family == AF_INET) {
4510 ndevice->internalSetIpV4Destination(address);
4512 if (family == AF_INET6) {
4513 address.truncate(address.findRev(
"%"));
4514 ndevice->internalSetIpV6Destination(address);
4522 freeifaddrs(ifaddr);
4525 TQString valuesnodename = systempath +
"/statistics/";
4526 TQDir valuesdir(valuesnodename);
4527 valuesdir.setFilter(TQDir::All);
4529 const TQFileInfoList *dirlist = valuesdir.entryInfoList();
4531 TQFileInfoListIterator valuesdirit(*dirlist);
4533 while ( (dirfi = valuesdirit.current()) != 0 ) {
4534 nodename = dirfi->fileName();
4535 TQFile file( valuesnodename + nodename );
4536 if ( file.open( IO_ReadOnly ) ) {
4537 TQTextStream stream( &file );
4539 line = stream.readLine();
4540 if (nodename ==
"rx_bytes") {
4541 ndevice->internalSetRxBytes(line.toDouble());
4543 if (nodename ==
"tx_bytes") {
4544 ndevice->internalSetTxBytes(line.toDouble());
4546 if (nodename ==
"rx_packets") {
4547 ndevice->internalSetRxPackets(line.toDouble());
4549 if (nodename ==
"tx_packets") {
4550 ndevice->internalSetTxPackets(line.toDouble());
4561 if ((device->type() == TDEGenericDeviceType::OtherSensor) || (device->type() == TDEGenericDeviceType::ThermalSensor)) {
4563 TDESensorClusterMap sensors;
4564 TQString valuesnodename = systempath +
"/";
4565 TQDir valuesdir(valuesnodename);
4566 valuesdir.setFilter(TQDir::All);
4568 const TQFileInfoList *dirlist = valuesdir.entryInfoList();
4570 TQFileInfoListIterator valuesdirit(*dirlist);
4572 while ( (dirfi = valuesdirit.current()) != 0 ) {
4573 nodename = dirfi->fileName();
4574 if (nodename.contains(
"_")) {
4575 TQFile file( valuesnodename + nodename );
4576 if ( file.open( IO_ReadOnly ) ) {
4577 TQTextStream stream( &file );
4579 line = stream.readLine();
4580 TQStringList sensornodelist = TQStringList::split(
"_", nodename);
4581 TQString sensornodename = *(sensornodelist.at(0));
4582 TQString sensornodetype = *(sensornodelist.at(1));
4583 double lineValue = line.toDouble();
4584 if (!sensornodename.contains(
"fan")) {
4585 lineValue = lineValue / 1000.0;
4587 if (sensornodetype ==
"label") {
4588 sensors[sensornodename].label = line;
4590 if (sensornodetype ==
"input") {
4591 sensors[sensornodename].current = lineValue;
4593 if (sensornodetype ==
"min") {
4594 sensors[sensornodename].minimum = lineValue;
4596 if (sensornodetype ==
"max") {
4597 sensors[sensornodename].maximum = lineValue;
4599 if (sensornodetype ==
"warn") {
4600 sensors[sensornodename].warning = lineValue;
4602 if (sensornodetype ==
"crit") {
4603 sensors[sensornodename].critical = lineValue;
4612 TDESensorDevice* sdevice =
dynamic_cast<TDESensorDevice*
>(device);
4613 sdevice->internalSetValues(sensors);
4616 if (device->type() == TDEGenericDeviceType::Battery) {
4618 TDEBatteryDevice* bdevice =
dynamic_cast<TDEBatteryDevice*
>(device);
4619 TQString valuesnodename = systempath +
"/";
4620 TQDir valuesdir(valuesnodename);
4621 valuesdir.setFilter(TQDir::All);
4623 const TQFileInfoList *dirlist = valuesdir.entryInfoList();
4625 TQFileInfoListIterator valuesdirit(*dirlist);
4627 while ( (dirfi = valuesdirit.current()) != 0 ) {
4628 nodename = dirfi->fileName();
4629 TQFile file( valuesnodename + nodename );
4630 if ( file.open( IO_ReadOnly ) ) {
4631 TQTextStream stream( &file );
4633 line = stream.readLine();
4634 if (nodename ==
"alarm") {
4635 bdevice->internalSetAlarmEnergy(line.toDouble()/1000000.0);
4637 if (nodename ==
"energy_full") {
4638 bdevice->internalSetMaximumEnergy(line.toDouble()/1000000.0);
4640 if (nodename ==
"energy_full_design") {
4641 bdevice->internalSetMaximumDesignEnergy(line.toDouble()/1000000.0);
4643 if (nodename ==
"energy_now") {
4644 bdevice->internalSetEnergy(line.toDouble()/1000000.0);
4646 if (nodename ==
"manufacturer") {
4647 bdevice->internalSetVendorName(line.stripWhiteSpace());
4649 if (nodename ==
"model_name") {
4650 bdevice->internalSetVendorModel(line.stripWhiteSpace());
4652 if (nodename ==
"power_now") {
4653 bdevice->internalSetDischargeRate(line.toDouble()/1000000.0);
4655 if (nodename ==
"present") {
4656 bdevice->internalSetInstalled(line.toInt());
4658 if (nodename ==
"serial_number") {
4659 bdevice->internalSetSerialNumber(line.stripWhiteSpace());
4661 if (nodename ==
"status") {
4662 bdevice->internalSetStatus(line);
4664 if (nodename ==
"technology") {
4665 bdevice->internalSetTechnology(line);
4667 if (nodename ==
"voltage_min_design") {
4668 bdevice->internalSetMinimumVoltage(line.toDouble()/1000000.0);
4670 if (nodename ==
"voltage_now") {
4671 bdevice->internalSetVoltage(line.toDouble()/1000000.0);
4684 bdevice->internalSetTimeRemaining((bdevice->energy()/bdevice->dischargeRate())*60*60);
4687 if (device->type() == TDEGenericDeviceType::PowerSupply) {
4689 TDEMainsPowerDevice* pdevice =
dynamic_cast<TDEMainsPowerDevice*
>(device);
4690 TQString valuesnodename = systempath +
"/";
4691 TQDir valuesdir(valuesnodename);
4692 valuesdir.setFilter(TQDir::All);
4694 const TQFileInfoList *dirlist = valuesdir.entryInfoList();
4696 TQFileInfoListIterator valuesdirit(*dirlist);
4698 while ( (dirfi = valuesdirit.current()) != 0 ) {
4699 nodename = dirfi->fileName();
4700 TQFile file( valuesnodename + nodename );
4701 if ( file.open( IO_ReadOnly ) ) {
4702 TQTextStream stream( &file );
4704 line = stream.readLine();
4705 if (nodename ==
"manufacturer") {
4706 pdevice->internalSetVendorName(line.stripWhiteSpace());
4708 if (nodename ==
"model_name") {
4709 pdevice->internalSetVendorModel(line.stripWhiteSpace());
4711 if (nodename ==
"online") {
4712 pdevice->internalSetOnline(line.toInt());
4714 if (nodename ==
"serial_number") {
4715 pdevice->internalSetSerialNumber(line.stripWhiteSpace());
4724 if (device->type() == TDEGenericDeviceType::Backlight) {
4726 TDEBacklightDevice* bdevice =
dynamic_cast<TDEBacklightDevice*
>(device);
4727 TQString valuesnodename = systempath +
"/";
4728 TQDir valuesdir(valuesnodename);
4729 valuesdir.setFilter(TQDir::All);
4731 const TQFileInfoList *dirlist = valuesdir.entryInfoList();
4733 TQFileInfoListIterator valuesdirit(*dirlist);
4735 while ( (dirfi = valuesdirit.current()) != 0 ) {
4736 nodename = dirfi->fileName();
4737 TQFile file( valuesnodename + nodename );
4738 if ( file.open( IO_ReadOnly ) ) {
4739 TQTextStream stream( &file );
4741 line = stream.readLine();
4742 if (nodename ==
"bl_power") {
4743 TDEDisplayPowerLevel::TDEDisplayPowerLevel pl = TDEDisplayPowerLevel::On;
4744 int rpl = line.toInt();
4745 if (rpl == FB_BLANK_UNBLANK) {
4746 pl = TDEDisplayPowerLevel::On;
4748 else if (rpl == FB_BLANK_POWERDOWN) {
4749 pl = TDEDisplayPowerLevel::Off;
4751 bdevice->internalSetPowerLevel(pl);
4753 if (nodename ==
"max_brightness") {
4754 bdevice->internalSetMaximumRawBrightness(line.toInt());
4756 if (nodename ==
"actual_brightness") {
4757 bdevice->internalSetCurrentRawBrightness(line.toInt());
4766 if (device->type() == TDEGenericDeviceType::Monitor) {
4767 TDEMonitorDevice* mdevice =
dynamic_cast<TDEMonitorDevice*
>(device);
4768 TQString valuesnodename = systempath +
"/";
4769 TQDir valuesdir(valuesnodename);
4770 valuesdir.setFilter(TQDir::All);
4772 const TQFileInfoList *dirlist = valuesdir.entryInfoList();
4774 TQFileInfoListIterator valuesdirit(*dirlist);
4776 while ( (dirfi = valuesdirit.current()) != 0 ) {
4777 nodename = dirfi->fileName();
4778 TQFile file( valuesnodename + nodename );
4779 if ( file.open( IO_ReadOnly ) ) {
4780 TQTextStream stream( &file );
4782 line = stream.readLine();
4783 if (nodename ==
"status") {
4784 mdevice->internalSetConnected(line.lower() ==
"connected");
4786 if (nodename ==
"enabled") {
4787 mdevice->internalSetEnabled(line.lower() ==
"enabled");
4789 if (nodename ==
"modes") {
4790 TQStringList resinfo;
4791 TQStringList resolutionsStringList = line.upper();
4792 while ((!stream.atEnd()) && (!line.isNull())) {
4793 line = stream.readLine();
4794 if (!line.isNull()) {
4795 resolutionsStringList.append(line.upper());
4798 TDEResolutionList resolutions;
4799 resolutions.clear();
4800 for (TQStringList::Iterator it = resolutionsStringList.begin(); it != resolutionsStringList.end(); ++it) {
4801 resinfo = TQStringList::split(
'X', *it,
true);
4802 resolutions.append(TDEResolutionPair((*(resinfo.at(0))).toUInt(), (*(resinfo.at(1))).toUInt()));
4804 mdevice->internalSetResolutions(resolutions);
4806 if (nodename ==
"dpms") {
4807 TDEDisplayPowerLevel::TDEDisplayPowerLevel pl = TDEDisplayPowerLevel::On;
4809 pl = TDEDisplayPowerLevel::On;
4811 else if (line ==
"Standby") {
4812 pl = TDEDisplayPowerLevel::Standby;
4814 else if (line ==
"Suspend") {
4815 pl = TDEDisplayPowerLevel::Suspend;
4817 else if (line ==
"Off") {
4818 pl = TDEDisplayPowerLevel::Off;
4820 mdevice->internalSetPowerLevel(pl);
4828 TQString genericPortName = mdevice->systemPath();
4829 genericPortName.remove(0, genericPortName.find(
"-")+1);
4830 genericPortName.truncate(genericPortName.findRev(
"-"));
4831 mdevice->internalSetPortType(genericPortName);
4833 if (mdevice->connected()) {
4834 TQPair<TQString,TQString> monitor_info = getEDIDMonitorName(device->systemPath());
4835 if (!monitor_info.first.isNull()) {
4836 mdevice->internalSetVendorName(monitor_info.first);
4837 mdevice->internalSetVendorModel(monitor_info.second);
4838 mdevice->m_friendlyName = monitor_info.first +
" " + monitor_info.second;
4841 mdevice->m_friendlyName =
i18n(
"Generic %1 Device").arg(genericPortName);
4843 mdevice->internalSetEdid(getEDID(mdevice->systemPath()));
4846 mdevice->m_friendlyName =
i18n(
"Disconnected %1 Port").arg(genericPortName);
4847 mdevice->internalSetEdid(TQByteArray());
4848 mdevice->internalSetResolutions(TDEResolutionList());
4855 if (device->type() == TDEGenericDeviceType::RootSystem) {
4857 TDERootSystemDevice* rdevice =
dynamic_cast<TDERootSystemDevice*
>(device);
4861 TDESystemFormFactor::TDESystemFormFactor formfactor = TDESystemFormFactor::Desktop;
4862 if (listByDeviceClass(TDEGenericDeviceType::Backlight).count() > 0) {
4863 formfactor = TDESystemFormFactor::Laptop;
4865 rdevice->internalSetFormFactor(formfactor);
4867 TQString valuesnodename =
"/sys/power/";
4868 TQDir valuesdir(valuesnodename);
4869 valuesdir.setFilter(TQDir::All);
4871 const TQFileInfoList *dirlist = valuesdir.entryInfoList();
4873 TQFileInfoListIterator valuesdirit(*dirlist);
4875 while ( (dirfi = valuesdirit.current()) != 0 ) {
4876 nodename = dirfi->fileName();
4877 TQFile file( valuesnodename + nodename );
4878 if ( file.open( IO_ReadOnly ) ) {
4879 TQTextStream stream( &file );
4881 line = stream.readLine();
4882 if (nodename ==
"state") {
4883 TDESystemPowerStateList powerstates;
4885 powerstates.append(TDESystemPowerState::Active);
4886 powerstates.append(TDESystemPowerState::PowerOff);
4887 if (line.contains(
"standby")) {
4888 powerstates.append(TDESystemPowerState::Standby);
4890 if (line.contains(
"mem")) {
4891 powerstates.append(TDESystemPowerState::Suspend);
4893 if (line.contains(
"disk")) {
4894 powerstates.append(TDESystemPowerState::Hibernate);
4896 rdevice->internalSetPowerStates(powerstates);
4898 if (nodename ==
"disk") {
4900 TDESystemHibernationMethodList hibernationmethods;
4901 if (line.contains(
"platform")) {
4902 hibernationmethods.append(TDESystemHibernationMethod::Platform);
4904 if (line.contains(
"shutdown")) {
4905 hibernationmethods.append(TDESystemHibernationMethod::Shutdown);
4907 if (line.contains(
"reboot")) {
4908 hibernationmethods.append(TDESystemHibernationMethod::Reboot);
4910 if (line.contains(
"testproc")) {
4911 hibernationmethods.append(TDESystemHibernationMethod::TestProc);
4913 if (line.contains(
"test")) {
4914 hibernationmethods.append(TDESystemHibernationMethod::Test);
4916 rdevice->internalSetHibernationMethods(hibernationmethods);
4919 line.truncate(line.findRev(
"]"));
4920 line.remove(0, line.findRev(
"[")+1);
4921 TDESystemHibernationMethod::TDESystemHibernationMethod hibernationmethod = TDESystemHibernationMethod::Unsupported;
4922 if (line.contains(
"platform")) {
4923 hibernationmethod = TDESystemHibernationMethod::Platform;
4925 if (line.contains(
"shutdown")) {
4926 hibernationmethod = TDESystemHibernationMethod::Shutdown;
4928 if (line.contains(
"reboot")) {
4929 hibernationmethod = TDESystemHibernationMethod::Reboot;
4931 if (line.contains(
"testproc")) {
4932 hibernationmethod = TDESystemHibernationMethod::TestProc;
4934 if (line.contains(
"test")) {
4935 hibernationmethod = TDESystemHibernationMethod::Test;
4937 rdevice->internalSetHibernationMethod(hibernationmethod);
4939 if (nodename ==
"image_size") {
4940 rdevice->internalSetDiskSpaceNeededForHibernation(line.toULong());
4952 if (device->type() == TDEGenericDeviceType::Event) {
4954 TDEEventDevice* edevice =
dynamic_cast<TDEEventDevice*
>(device);
4955 if (edevice->systemPath().contains(
"PNP0C0D")) {
4956 edevice->internalSetEventType(TDEEventDeviceType::ACPILidSwitch);
4958 else if (edevice->systemPath().contains(
"PNP0C0E") || edevice->systemPath().contains(
"/LNXSLPBN")) {
4959 edevice->internalSetEventType(TDEEventDeviceType::ACPISleepButton);
4961 else if (edevice->systemPath().contains(
"PNP0C0C") || edevice->systemPath().contains(
"/LNXPWRBN")) {
4962 edevice->internalSetEventType(TDEEventDeviceType::ACPIPowerButton);
4965 edevice->internalSetEventType(TDEEventDeviceType::Unknown);
4969 if (device->type() == TDEGenericDeviceType::Input) {
4971 TDEInputDevice* idevice =
dynamic_cast<TDEInputDevice*
>(device);
4972 if (idevice->systemPath().contains(
"PNP0C0D")) {
4973 idevice->internalSetInputType(TDEInputDeviceType::ACPILidSwitch);
4975 else if (idevice->systemPath().contains(
"PNP0C0E") || idevice->systemPath().contains(
"/LNXSLPBN")) {
4976 idevice->internalSetInputType(TDEInputDeviceType::ACPISleepButton);
4978 else if (idevice->systemPath().contains(
"PNP0C0C") || idevice->systemPath().contains(
"/LNXPWRBN")) {
4979 idevice->internalSetInputType(TDEInputDeviceType::ACPIPowerButton);
4982 idevice->internalSetInputType(TDEInputDeviceType::Unknown);
4986 if (device->type() == TDEGenericDeviceType::Event) {
4988 TDEEventDevice* edevice =
dynamic_cast<TDEEventDevice*
>(device);
4990 char switches[SW_CNT];
4993 TDESwitchType::TDESwitchType supportedSwitches = TDESwitchType::Null;
4994 if (edevice->m_fd < 0) {
4995 edevice->m_fd =
open(edevice->deviceNode().ascii(), O_RDONLY);
4997 r = ioctl(edevice->m_fd, EVIOCGBIT(EV_SW,
sizeof(switches)), switches);
4999 if (BIT_IS_SET(switches, SW_LID)) {
5000 supportedSwitches = supportedSwitches | TDESwitchType::Lid;
5002 if (BIT_IS_SET(switches, SW_TABLET_MODE)) {
5003 supportedSwitches = supportedSwitches | TDESwitchType::TabletMode;
5005 if (BIT_IS_SET(switches, SW_RFKILL_ALL)) {
5006 supportedSwitches = supportedSwitches | TDESwitchType::RFKill;
5008 if (BIT_IS_SET(switches, SW_RADIO)) {
5009 supportedSwitches = supportedSwitches | TDESwitchType::Radio;
5011 if (BIT_IS_SET(switches, SW_MICROPHONE_INSERT)) {
5012 supportedSwitches = supportedSwitches | TDESwitchType::MicrophoneInsert;
5014 if (BIT_IS_SET(switches, SW_DOCK)) {
5015 supportedSwitches = supportedSwitches | TDESwitchType::Dock;
5017 if (BIT_IS_SET(switches, SW_LINEOUT_INSERT)) {
5018 supportedSwitches = supportedSwitches | TDESwitchType::LineOutInsert;
5020 if (BIT_IS_SET(switches, SW_JACK_PHYSICAL_INSERT)) {
5021 supportedSwitches = supportedSwitches | TDESwitchType::JackPhysicalInsert;
5023 if (BIT_IS_SET(switches, SW_VIDEOOUT_INSERT)) {
5024 supportedSwitches = supportedSwitches | TDESwitchType::VideoOutInsert;
5026 #if 0 // Some old kernels don't provide these defines... [FIXME]
5027 if (BIT_IS_SET(switches, SW_CAMERA_LENS_COVER)) {
5028 supportedSwitches = supportedSwitches | TDESwitchType::CameraLensCover;
5030 if (BIT_IS_SET(switches, SW_KEYPAD_SLIDE)) {
5031 supportedSwitches = supportedSwitches | TDESwitchType::KeypadSlide;
5033 if (BIT_IS_SET(switches, SW_FRONT_PROXIMITY)) {
5034 supportedSwitches = supportedSwitches | TDESwitchType::FrontProximity;
5036 if (BIT_IS_SET(switches, SW_ROTATE_LOCK)) {
5037 supportedSwitches = supportedSwitches | TDESwitchType::RotateLock;
5039 if (BIT_IS_SET(switches, SW_LINEIN_INSERT)) {
5040 supportedSwitches = supportedSwitches | TDESwitchType::LineInInsert;
5044 edevice->internalSetProvidedSwitches(supportedSwitches);
5047 TDESwitchType::TDESwitchType activeSwitches = TDESwitchType::Null;
5048 r = ioctl(edevice->m_fd, EVIOCGSW(
sizeof(switches)), switches);
5050 if (BIT_IS_SET(switches, SW_LID)) {
5051 activeSwitches = activeSwitches | TDESwitchType::Lid;
5053 if (BIT_IS_SET(switches, SW_TABLET_MODE)) {
5054 activeSwitches = activeSwitches | TDESwitchType::TabletMode;
5056 if (BIT_IS_SET(switches, SW_RFKILL_ALL)) {
5057 activeSwitches = activeSwitches | TDESwitchType::RFKill;
5059 if (BIT_IS_SET(switches, SW_RADIO)) {
5060 activeSwitches = activeSwitches | TDESwitchType::Radio;
5062 if (BIT_IS_SET(switches, SW_MICROPHONE_INSERT)) {
5063 activeSwitches = activeSwitches | TDESwitchType::MicrophoneInsert;
5065 if (BIT_IS_SET(switches, SW_DOCK)) {
5066 activeSwitches = activeSwitches | TDESwitchType::Dock;
5068 if (BIT_IS_SET(switches, SW_LINEOUT_INSERT)) {
5069 activeSwitches = activeSwitches | TDESwitchType::LineOutInsert;
5071 if (BIT_IS_SET(switches, SW_JACK_PHYSICAL_INSERT)) {
5072 activeSwitches = activeSwitches | TDESwitchType::JackPhysicalInsert;
5074 if (BIT_IS_SET(switches, SW_VIDEOOUT_INSERT)) {
5075 activeSwitches = activeSwitches | TDESwitchType::VideoOutInsert;
5077 #if 0 // Some old kernels don't provide these defines... [FIXME]
5078 if (BIT_IS_SET(switches, SW_CAMERA_LENS_COVER)) {
5079 activeSwitches = activeSwitches | TDESwitchType::CameraLensCover;
5081 if (BIT_IS_SET(switches, SW_KEYPAD_SLIDE)) {
5082 activeSwitches = activeSwitches | TDESwitchType::KeypadSlide;
5084 if (BIT_IS_SET(switches, SW_FRONT_PROXIMITY)) {
5085 activeSwitches = activeSwitches | TDESwitchType::FrontProximity;
5087 if (BIT_IS_SET(switches, SW_ROTATE_LOCK)) {
5088 activeSwitches = activeSwitches | TDESwitchType::RotateLock;
5090 if (BIT_IS_SET(switches, SW_LINEIN_INSERT)) {
5091 activeSwitches = activeSwitches | TDESwitchType::LineInInsert;
5095 edevice->internalSetActiveSwitches(activeSwitches);
5097 edevice->internalStartFdMonitoring(
this);
5101 if ((device->type() == TDEGenericDeviceType::Root) || (device->type() == TDEGenericDeviceType::RootSystem)) {
5102 systempath = device->systemPath();
5106 device->internalSetName(devicename);
5107 device->internalSetDeviceNode(devicenode);
5108 device->internalSetSystemPath(systempath);
5109 device->internalSetVendorID(devicevendorid);
5110 device->internalSetModelID(devicemodelid);
5111 device->internalSetVendorEncoded(devicevendoridenc);
5112 device->internalSetModelEncoded(devicemodelidenc);
5113 device->internalSetSubVendorID(devicesubvendorid);
5114 device->internalSetSubModelID(devicesubmodelid);
5115 device->internalSetDeviceDriver(devicedriver);
5116 device->internalSetSubsystem(devicesubsystem);
5117 device->internalSetPCIClass(devicepciclass);
5120 device->m_udevtype = devicetype;
5121 device->m_udevdevicetypestring = devicetypestring;
5122 device->udevdevicetypestring_alt = devicetypestring_alt;
5124 if (temp_udev_device) {
5125 udev_device_unref(dev);
5131 void TDEHardwareDevices::updateBlacklists(TDEGenericDevice* hwdevice, udev_device* dev) {
5137 if ((hwdevice->vendorID() ==
"08ec") && (hwdevice->modelID() ==
"0020") && (TQString(udev_device_get_property_value(dev,
"ID_TYPE")) ==
"cd")) {
5138 hwdevice->internalSetBlacklistedForUpdate(
true);
5142 bool TDEHardwareDevices::queryHardwareInformation() {
5143 if (!m_udevStruct) {
5148 m_deviceList.clear();
5149 addCoreSystemDevices();
5151 struct udev_enumerate *enumerate;
5152 struct udev_list_entry *devices, *dev_list_entry;
5153 struct udev_device *dev;
5156 enumerate = udev_enumerate_new(m_udevStruct);
5157 udev_enumerate_add_match_subsystem(enumerate, NULL);
5158 udev_enumerate_scan_devices(enumerate);
5159 devices = udev_enumerate_get_list_entry(enumerate);
5161 udev_list_entry_foreach(dev_list_entry, devices) {
5165 path = udev_list_entry_get_name(dev_list_entry);
5166 dev = udev_device_new_from_syspath(m_udevStruct, path);
5168 TDEGenericDevice* device = classifyUnknownDevice(dev);
5171 TDEGenericDevice *hwdevice;
5172 for (hwdevice = m_deviceList.first(); hwdevice; hwdevice = m_deviceList.next()) {
5173 if (hwdevice->systemPath() == device->systemPath()) {
5181 m_deviceList.append(device);
5184 udev_device_unref(dev);
5188 udev_enumerate_unref(enumerate);
5191 updateParentDeviceInformation();
5193 emit hardwareEvent(TDEHardwareEvent::HardwareListModified, TQString());
5198 void TDEHardwareDevices::updateParentDeviceInformation(TDEGenericDevice* hwdevice) {
5201 TQString current_path = hwdevice->systemPath();
5202 TDEGenericDevice* parentdevice = 0;
5204 if (current_path.endsWith(
"/")) {
5205 current_path.truncate(current_path.findRev(
"/"));
5207 while (done ==
false) {
5208 current_path.truncate(current_path.findRev(
"/"));
5209 if (current_path.startsWith(
"/sys/devices")) {
5210 if (current_path.endsWith(
"/")) {
5211 current_path.truncate(current_path.findRev(
"/"));
5213 parentdevice = findBySystemPath(current_path);
5224 hwdevice->internalSetParentDevice(parentdevice);
5227 void TDEHardwareDevices::updateParentDeviceInformation() {
5228 TDEGenericDevice *hwdevice;
5231 TDEGenericHardwareList devList = listAllPhysicalDevices();
5232 for ( hwdevice = devList.first(); hwdevice; hwdevice = devList.next() ) {
5233 updateParentDeviceInformation(hwdevice);
5237 void TDEHardwareDevices::addCoreSystemDevices() {
5238 TDEGenericDevice *hwdevice;
5241 hwdevice =
new TDERootSystemDevice(TDEGenericDeviceType::RootSystem);
5242 hwdevice->internalSetSystemPath(
"/sys/devices");
5243 m_deviceList.append(hwdevice);
5244 rescanDeviceInformation(hwdevice);
5247 TQStringList holdingDeviceNodes;
5248 TQString devicesnodename =
"/sys/devices";
5249 TQDir devicesdir(devicesnodename);
5250 devicesdir.setFilter(TQDir::All);
5252 const TQFileInfoList *dirlist = devicesdir.entryInfoList();
5254 TQFileInfoListIterator devicesdirit(*dirlist);
5256 while ( (dirfi = devicesdirit.current()) != 0 ) {
5257 nodename = dirfi->fileName();
5258 if (nodename !=
"." && nodename !=
"..") {
5259 hwdevice =
new TDEGenericDevice(TDEGenericDeviceType::Root);
5260 hwdevice->internalSetSystemPath(dirfi->absFilePath());
5261 m_deviceList.append(hwdevice);
5270 TQDir d(
"/sys/devices/system/cpu/");
5271 d.setFilter( TQDir::Dirs );
5272 const TQFileInfoList *list = d.entryInfoList();
5273 TQFileInfoListIterator it( *list );
5275 while ((fi = it.current()) != 0) {
5276 TQString directoryName = fi->fileName();
5277 if (directoryName.startsWith(
"cpu")) {
5278 directoryName = directoryName.remove(0,3);
5280 int processorNumber = directoryName.toUInt(&isInt, 10);
5282 hwdevice =
new TDECPUDevice(TDEGenericDeviceType::CPU);
5283 hwdevice->internalSetSystemPath(TQString(
"/sys/devices/system/cpu/cpu%1").arg(processorNumber));
5284 m_deviceList.append(hwdevice);
5291 processModifiedCPUs();
5294 TQString TDEHardwareDevices::findPCIDeviceName(TQString vendorid, TQString modelid, TQString subvendorid, TQString submodelid) {
5295 TQString vendorName = TQString::null;
5296 TQString modelName = TQString::null;
5297 TQString friendlyName = TQString::null;
5300 pci_id_map =
new TDEDeviceIDMap;
5302 TQString database_filename =
"/usr/share/pci.ids";
5303 if (!TQFile::exists(database_filename)) {
5304 database_filename =
"/usr/share/misc/pci.ids";
5306 if (!TQFile::exists(database_filename)) {
5307 printf(
"[tdehardwaredevices] Unable to locate PCI information database pci.ids\n"); fflush(stdout);
5308 return i18n(
"Unknown PCI Device");
5311 TQFile database(database_filename);
5312 if (database.open(IO_ReadOnly)) {
5313 TQTextStream stream(&database);
5317 TQString subvendorID;
5318 TQString submodelID;
5319 TQString deviceMapKey;
5320 TQStringList devinfo;
5321 while (!stream.atEnd()) {
5322 line = stream.readLine();
5323 if ((!line.upper().startsWith(
"\t")) && (!line.upper().startsWith(
"#"))) {
5324 line.replace(
"\t",
"");
5325 devinfo = TQStringList::split(
' ', line,
false);
5326 vendorID = *(devinfo.at(0));
5328 vendorName.remove(0, vendorName.find(
" "));
5329 vendorName = vendorName.stripWhiteSpace();
5330 modelName = TQString::null;
5331 deviceMapKey = vendorID.lower() +
":::";
5334 if ((line.upper().startsWith(
"\t")) && (!line.upper().startsWith(
"\t\t"))) {
5335 line.replace(
"\t",
"");
5336 devinfo = TQStringList::split(
' ', line,
false);
5337 modelID = *(devinfo.at(0));
5339 modelName.remove(0, modelName.find(
" "));
5340 modelName = modelName.stripWhiteSpace();
5341 deviceMapKey = vendorID.lower() +
":" + modelID.lower() +
"::";
5344 if (line.upper().startsWith(
"\t\t")) {
5345 line.replace(
"\t",
"");
5346 devinfo = TQStringList::split(
' ', line,
false);
5347 subvendorID = *(devinfo.at(0));
5348 submodelID = *(devinfo.at(1));
5350 modelName.remove(0, modelName.find(
" "));
5351 modelName = modelName.stripWhiteSpace();
5352 modelName.remove(0, modelName.find(
" "));
5353 modelName = modelName.stripWhiteSpace();
5354 deviceMapKey = vendorID.lower() +
":" + modelID.lower() +
":" + subvendorID.lower() +
":" + submodelID.lower();
5358 if (modelName.isNull()) {
5359 pci_id_map->insert(deviceMapKey,
"***UNKNOWN DEVICE*** " + vendorName,
true);
5362 pci_id_map->insert(deviceMapKey, vendorName +
" " + modelName,
true);
5368 printf(
"[tdehardwaredevices] Unable to open PCI information database %s\n", database_filename.ascii()); fflush(stdout);
5373 TQString deviceName;
5374 TQString deviceMapKey = vendorid.lower() +
":" + modelid.lower() +
":" + subvendorid.lower() +
":" + submodelid.lower();
5376 deviceName = (*pci_id_map)[deviceMapKey];
5377 if (deviceName.isNull() || deviceName.startsWith(
"***UNKNOWN DEVICE*** ")) {
5378 deviceMapKey = vendorid.lower() +
":" + modelid.lower() +
":" + subvendorid.lower() +
":";
5379 deviceName = (*pci_id_map)[deviceMapKey];
5380 if (deviceName.isNull() || deviceName.startsWith(
"***UNKNOWN DEVICE*** ")) {
5381 deviceMapKey = vendorid.lower() +
":" + modelid.lower() +
"::";
5382 deviceName = (*pci_id_map)[deviceMapKey];
5386 if (deviceName.startsWith(
"***UNKNOWN DEVICE*** ")) {
5387 deviceName.replace(
"***UNKNOWN DEVICE*** ",
"");
5388 deviceName.prepend(
i18n(
"Unknown PCI Device") +
" ");
5389 if (subvendorid.isNull()) {
5390 deviceName.append(TQString(
" [%1:%2]").arg(vendorid.lower()).arg(modelid.lower()));
5393 deviceName.append(TQString(
" [%1:%2] [%3:%4]").arg(vendorid.lower()).arg(modelid.lower()).arg(subvendorid.lower()).arg(submodelid.lower()));
5400 return i18n(
"Unknown PCI Device");
5404 TQString TDEHardwareDevices::findUSBDeviceName(TQString vendorid, TQString modelid, TQString subvendorid, TQString submodelid) {
5405 TQString vendorName = TQString::null;
5406 TQString modelName = TQString::null;
5407 TQString friendlyName = TQString::null;
5410 usb_id_map =
new TDEDeviceIDMap;
5412 TQString database_filename =
"/usr/share/usb.ids";
5413 if (!TQFile::exists(database_filename)) {
5414 database_filename =
"/usr/share/misc/usb.ids";
5416 if (!TQFile::exists(database_filename)) {
5417 printf(
"[tdehardwaredevices] Unable to locate USB information database usb.ids\n"); fflush(stdout);
5418 return i18n(
"Unknown USB Device");
5421 TQFile database(database_filename);
5422 if (database.open(IO_ReadOnly)) {
5423 TQTextStream stream(&database);
5427 TQString subvendorID;
5428 TQString submodelID;
5429 TQString deviceMapKey;
5430 TQStringList devinfo;
5431 while (!stream.atEnd()) {
5432 line = stream.readLine();
5433 if ((!line.upper().startsWith(
"\t")) && (!line.upper().startsWith(
"#"))) {
5434 line.replace(
"\t",
"");
5435 devinfo = TQStringList::split(
' ', line,
false);
5436 vendorID = *(devinfo.at(0));
5438 vendorName.remove(0, vendorName.find(
" "));
5439 vendorName = vendorName.stripWhiteSpace();
5440 modelName = TQString::null;
5441 deviceMapKey = vendorID.lower() +
":::";
5444 if ((line.upper().startsWith(
"\t")) && (!line.upper().startsWith(
"\t\t"))) {
5445 line.replace(
"\t",
"");
5446 devinfo = TQStringList::split(
' ', line,
false);
5447 modelID = *(devinfo.at(0));
5449 modelName.remove(0, modelName.find(
" "));
5450 modelName = modelName.stripWhiteSpace();
5451 deviceMapKey = vendorID.lower() +
":" + modelID.lower() +
"::";
5454 if (line.upper().startsWith(
"\t\t")) {
5455 line.replace(
"\t",
"");
5456 devinfo = TQStringList::split(
' ', line,
false);
5457 subvendorID = *(devinfo.at(0));
5458 submodelID = *(devinfo.at(1));
5460 modelName.remove(0, modelName.find(
" "));
5461 modelName = modelName.stripWhiteSpace();
5462 modelName.remove(0, modelName.find(
" "));
5463 modelName = modelName.stripWhiteSpace();
5464 deviceMapKey = vendorID.lower() +
":" + modelID.lower() +
":" + subvendorID.lower() +
":" + submodelID.lower();
5468 if (modelName.isNull()) {
5469 usb_id_map->insert(deviceMapKey,
"***UNKNOWN DEVICE*** " + vendorName,
true);
5472 usb_id_map->insert(deviceMapKey, vendorName +
" " + modelName,
true);
5478 printf(
"[tdehardwaredevices] Unable to open USB information database %s\n", database_filename.ascii()); fflush(stdout);
5483 TQString deviceName;
5484 TQString deviceMapKey = vendorid.lower() +
":" + modelid.lower() +
":" + subvendorid.lower() +
":" + submodelid.lower();
5486 deviceName = (*usb_id_map)[deviceMapKey];
5487 if (deviceName.isNull() || deviceName.startsWith(
"***UNKNOWN DEVICE*** ")) {
5488 deviceMapKey = vendorid.lower() +
":" + modelid.lower() +
":" + subvendorid.lower() +
":";
5489 deviceName = (*usb_id_map)[deviceMapKey];
5490 if (deviceName.isNull() || deviceName.startsWith(
"***UNKNOWN DEVICE*** ")) {
5491 deviceMapKey = vendorid.lower() +
":" + modelid.lower() +
"::";
5492 deviceName = (*usb_id_map)[deviceMapKey];
5496 if (deviceName.startsWith(
"***UNKNOWN DEVICE*** ")) {
5497 deviceName.replace(
"***UNKNOWN DEVICE*** ",
"");
5498 deviceName.prepend(
i18n(
"Unknown USB Device") +
" ");
5499 if (subvendorid.isNull()) {
5500 deviceName.append(TQString(
" [%1:%2]").arg(vendorid.lower()).arg(modelid.lower()));
5503 deviceName.append(TQString(
" [%1:%2] [%3:%4]").arg(vendorid.lower()).arg(modelid.lower()).arg(subvendorid.lower()).arg(submodelid.lower()));
5510 return i18n(
"Unknown USB Device");
5514 TQString TDEHardwareDevices::findPNPDeviceName(TQString pnpid) {
5515 TQString friendlyName = TQString::null;
5518 pnp_id_map =
new TDEDeviceIDMap;
5520 TQStringList hardware_info_directories(
TDEGlobal::dirs()->resourceDirs(
"data"));
5521 TQString hardware_info_directory_suffix(
"tdehwlib/pnpdev/");
5522 TQString hardware_info_directory;
5523 TQString database_filename;
5525 for ( TQStringList::Iterator it = hardware_info_directories.begin(); it != hardware_info_directories.end(); ++it ) {
5526 hardware_info_directory = (*it);
5527 hardware_info_directory += hardware_info_directory_suffix;
5530 database_filename = hardware_info_directory +
"pnp.ids";
5531 if (TQFile::exists(database_filename)) {
5537 if (!TQFile::exists(database_filename)) {
5538 printf(
"[tdehardwaredevices] Unable to locate PNP information database pnp.ids\n"); fflush(stdout);
5539 return i18n(
"Unknown PNP Device");
5542 TQFile database(database_filename);
5543 if (database.open(IO_ReadOnly)) {
5544 TQTextStream stream(&database);
5547 TQString vendorName;
5548 TQString deviceMapKey;
5549 TQStringList devinfo;
5550 while (!stream.atEnd()) {
5551 line = stream.readLine();
5552 if ((!line.upper().startsWith(
"\t")) && (!line.upper().startsWith(
"#"))) {
5553 devinfo = TQStringList::split(
'\t', line,
false);
5554 if (devinfo.count() > 1) {
5555 pnpID = *(devinfo.at(0));
5556 vendorName = *(devinfo.at(1));;
5557 vendorName = vendorName.stripWhiteSpace();
5558 deviceMapKey = pnpID.upper().stripWhiteSpace();
5559 if (!deviceMapKey.isNull()) {
5560 pnp_id_map->insert(deviceMapKey, vendorName,
true);
5568 printf(
"[tdehardwaredevices] Unable to open PNP information database %s\n", database_filename.ascii()); fflush(stdout);
5573 TQString deviceName;
5575 deviceName = (*pnp_id_map)[pnpid];
5580 return i18n(
"Unknown PNP Device");
5584 TQString TDEHardwareDevices::findMonitorManufacturerName(TQString dpyid) {
5585 TQString friendlyName = TQString::null;
5588 dpy_id_map =
new TDEDeviceIDMap;
5590 TQStringList hardware_info_directories(
TDEGlobal::dirs()->resourceDirs(
"data"));
5591 TQString hardware_info_directory_suffix(
"tdehwlib/pnpdev/");
5592 TQString hardware_info_directory;
5593 TQString database_filename;
5595 for ( TQStringList::Iterator it = hardware_info_directories.begin(); it != hardware_info_directories.end(); ++it ) {
5596 hardware_info_directory = (*it);
5597 hardware_info_directory += hardware_info_directory_suffix;
5600 database_filename = hardware_info_directory +
"dpy.ids";
5601 if (TQFile::exists(database_filename)) {
5607 if (!TQFile::exists(database_filename)) {
5608 printf(
"[tdehardwaredevices] Unable to locate monitor information database dpy.ids\n"); fflush(stdout);
5609 return i18n(
"Unknown Monitor Device");
5612 TQFile database(database_filename);
5613 if (database.open(IO_ReadOnly)) {
5614 TQTextStream stream(&database);
5617 TQString vendorName;
5618 TQString deviceMapKey;
5619 TQStringList devinfo;
5620 while (!stream.atEnd()) {
5621 line = stream.readLine();
5622 if ((!line.upper().startsWith(
"\t")) && (!line.upper().startsWith(
"#"))) {
5623 devinfo = TQStringList::split(
'\t', line,
false);
5624 if (devinfo.count() > 1) {
5625 dpyID = *(devinfo.at(0));
5626 vendorName = *(devinfo.at(1));;
5627 vendorName = vendorName.stripWhiteSpace();
5628 deviceMapKey = dpyID.upper().stripWhiteSpace();
5629 if (!deviceMapKey.isNull()) {
5630 dpy_id_map->insert(deviceMapKey, vendorName,
true);
5638 printf(
"[tdehardwaredevices] Unable to open monitor information database %s\n", database_filename.ascii()); fflush(stdout);
5643 TQString deviceName;
5645 deviceName = (*dpy_id_map)[dpyid];
5650 return i18n(
"Unknown Monitor Device");
5654 TQPair<TQString,TQString> TDEHardwareDevices::getEDIDMonitorName(TQString path) {
5655 TQPair<TQString,TQString> edid;
5656 TQByteArray binaryedid = getEDID(path);
5657 if (binaryedid.isNull()) {
5658 return TQPair<TQString,TQString>(TQString::null, TQString::null);
5662 unsigned char letter_1 = ((binaryedid[8]>>2) & 0x1F) + 0x40;
5663 unsigned char letter_2 = (((binaryedid[8] & 0x03) << 3) | ((binaryedid[9]>>5) & 0x07)) + 0x40;
5664 unsigned char letter_3 = (binaryedid[9] & 0x1F) + 0x40;
5665 TQChar qletter_1 = TQChar(letter_1);
5666 TQChar qletter_2 = TQChar(letter_2);
5667 TQChar qletter_3 = TQChar(letter_3);
5668 TQString manufacturer_id = TQString(
"%1%2%3").arg(qletter_1).arg(qletter_2).arg(qletter_3);
5671 unsigned int raw_model_id = (((binaryedid[10] << 8) | binaryedid[11]) << 16) & 0xFFFF0000;
5673 unsigned int model_id = reverse_bits(raw_model_id);
5676 bool has_friendly_name =
false;
5677 unsigned char descriptor_block[18];
5679 for (i=72;i<90;i++) {
5680 descriptor_block[i-72] = binaryedid[i] & 0xFF;
5682 if ((descriptor_block[0] != 0) || (descriptor_block[1] != 0) || (descriptor_block[3] != 0xFC)) {
5683 for (i=90;i<108;i++) {
5684 descriptor_block[i-90] = binaryedid[i] & 0xFF;
5686 if ((descriptor_block[0] != 0) || (descriptor_block[1] != 0) || (descriptor_block[3] != 0xFC)) {
5687 for (i=108;i<126;i++) {
5688 descriptor_block[i-108] = binaryedid[i] & 0xFF;
5693 TQString monitor_name;
5694 if ((descriptor_block[0] == 0) && (descriptor_block[1] == 0) && (descriptor_block[3] == 0xFC)) {
5695 char* pos = strchr((
char *)(descriptor_block+5),
'\n');
5698 has_friendly_name =
true;
5699 monitor_name = TQString((
char *)(descriptor_block+5));
5702 has_friendly_name =
false;
5707 TQString manufacturer_name = findMonitorManufacturerName(manufacturer_id);
5708 if (manufacturer_name.isNull()) {
5709 manufacturer_name = manufacturer_id;
5712 if (has_friendly_name) {
5713 edid.first = TQString(
"%1").arg(manufacturer_name);
5714 edid.second = TQString(
"%2").arg(monitor_name);
5717 edid.first = TQString(
"%1").arg(manufacturer_name);
5718 edid.second = TQString(
"0x%2").arg(model_id, 0, 16);
5724 TQByteArray TDEHardwareDevices::getEDID(TQString path) {
5725 TQFile file(TQString(
"%1/edid").arg(path));
5726 if (!file.open (IO_ReadOnly)) {
5727 return TQByteArray();
5729 TQByteArray binaryedid = file.readAll();
5734 TQString TDEHardwareDevices::getFriendlyDeviceTypeStringFromType(TDEGenericDeviceType::TDEGenericDeviceType query) {
5735 TQString ret =
"Unknown Device";
5738 if (query == TDEGenericDeviceType::Root) {
5741 else if (query == TDEGenericDeviceType::RootSystem) {
5742 ret =
i18n(
"System Root");
5744 else if (query == TDEGenericDeviceType::CPU) {
5747 else if (query == TDEGenericDeviceType::GPU) {
5748 ret =
i18n(
"Graphics Processor");
5750 else if (query == TDEGenericDeviceType::RAM) {
5753 else if (query == TDEGenericDeviceType::Bus) {
5756 else if (query == TDEGenericDeviceType::I2C) {
5757 ret =
i18n(
"I2C Bus");
5759 else if (query == TDEGenericDeviceType::MDIO) {
5760 ret =
i18n(
"MDIO Bus");
5762 else if (query == TDEGenericDeviceType::Mainboard) {
5763 ret =
i18n(
"Mainboard");
5765 else if (query == TDEGenericDeviceType::Disk) {
5768 else if (query == TDEGenericDeviceType::SCSI) {
5771 else if (query == TDEGenericDeviceType::StorageController) {
5772 ret =
i18n(
"Storage Controller");
5774 else if (query == TDEGenericDeviceType::Mouse) {
5775 ret =
i18n(
"Mouse");
5777 else if (query == TDEGenericDeviceType::Keyboard) {
5778 ret =
i18n(
"Keyboard");
5780 else if (query == TDEGenericDeviceType::HID) {
5783 else if (query == TDEGenericDeviceType::Modem) {
5784 ret =
i18n(
"Modem");
5786 else if (query == TDEGenericDeviceType::Monitor) {
5787 ret =
i18n(
"Monitor and Display");
5789 else if (query == TDEGenericDeviceType::Network) {
5790 ret =
i18n(
"Network");
5792 else if (query == TDEGenericDeviceType::Printer) {
5793 ret =
i18n(
"Printer");
5795 else if (query == TDEGenericDeviceType::Scanner) {
5796 ret =
i18n(
"Scanner");
5798 else if (query == TDEGenericDeviceType::Sound) {
5799 ret =
i18n(
"Sound");
5801 else if (query == TDEGenericDeviceType::VideoCapture) {
5802 ret =
i18n(
"Video Capture");
5804 else if (query == TDEGenericDeviceType::IEEE1394) {
5805 ret =
i18n(
"IEEE1394");
5807 else if (query == TDEGenericDeviceType::PCMCIA) {
5808 ret =
i18n(
"PCMCIA");
5810 else if (query == TDEGenericDeviceType::Camera) {
5811 ret =
i18n(
"Camera");
5813 else if (query == TDEGenericDeviceType::TextIO) {
5814 ret =
i18n(
"Text I/O");
5816 else if (query == TDEGenericDeviceType::Serial) {
5817 ret =
i18n(
"Serial Communications Controller");
5819 else if (query == TDEGenericDeviceType::Parallel) {
5820 ret =
i18n(
"Parallel Port");
5822 else if (query == TDEGenericDeviceType::Peripheral) {
5823 ret =
i18n(
"Peripheral");
5825 else if (query == TDEGenericDeviceType::Backlight) {
5826 ret =
i18n(
"Backlight");
5828 else if (query == TDEGenericDeviceType::Battery) {
5829 ret =
i18n(
"Battery");
5831 else if (query == TDEGenericDeviceType::PowerSupply) {
5832 ret =
i18n(
"Power Supply");
5834 else if (query == TDEGenericDeviceType::Dock) {
5835 ret =
i18n(
"Docking Station");
5837 else if (query == TDEGenericDeviceType::ThermalSensor) {
5838 ret =
i18n(
"Thermal Sensor");
5840 else if (query == TDEGenericDeviceType::ThermalControl) {
5841 ret =
i18n(
"Thermal Control");
5843 else if (query == TDEGenericDeviceType::BlueTooth) {
5844 ret =
i18n(
"Bluetooth");
5846 else if (query == TDEGenericDeviceType::Bridge) {
5847 ret =
i18n(
"Bridge");
5849 else if (query == TDEGenericDeviceType::Platform) {
5850 ret =
i18n(
"Platform");
5852 else if (query == TDEGenericDeviceType::Cryptography) {
5853 ret =
i18n(
"Cryptography");
5855 else if (query == TDEGenericDeviceType::Event) {
5856 ret =
i18n(
"Platform Event");
5858 else if (query == TDEGenericDeviceType::Input) {
5859 ret =
i18n(
"Platform Input");
5861 else if (query == TDEGenericDeviceType::PNP) {
5862 ret =
i18n(
"Plug and Play");
5864 else if (query == TDEGenericDeviceType::OtherACPI) {
5865 ret =
i18n(
"Other ACPI");
5867 else if (query == TDEGenericDeviceType::OtherUSB) {
5868 ret =
i18n(
"Other USB");
5870 else if (query == TDEGenericDeviceType::OtherMultimedia) {
5871 ret =
i18n(
"Other Multimedia");
5873 else if (query == TDEGenericDeviceType::OtherPeripheral) {
5874 ret =
i18n(
"Other Peripheral");
5876 else if (query == TDEGenericDeviceType::OtherSensor) {
5877 ret =
i18n(
"Other Sensor");
5879 else if (query == TDEGenericDeviceType::OtherVirtual) {
5880 ret =
i18n(
"Other Virtual");
5883 ret =
i18n(
"Unknown Device");
5889 TQPixmap TDEHardwareDevices::getDeviceTypeIconFromType(TDEGenericDeviceType::TDEGenericDeviceType query,
TDEIcon::StdSizes size) {
5893 if (query == TDEGenericDeviceType::Root) {
5896 else if (query == TDEGenericDeviceType::RootSystem) {
5899 else if (query == TDEGenericDeviceType::CPU) {
5902 else if (query == TDEGenericDeviceType::GPU) {
5905 else if (query == TDEGenericDeviceType::RAM) {
5908 else if (query == TDEGenericDeviceType::Bus) {
5911 else if (query == TDEGenericDeviceType::I2C) {
5912 ret =
DesktopIcon(
"input_devices_settings", size);
5914 else if (query == TDEGenericDeviceType::MDIO) {
5915 ret =
DesktopIcon(
"input_devices_settings", size);
5917 else if (query == TDEGenericDeviceType::Mainboard) {
5920 else if (query == TDEGenericDeviceType::Disk) {
5923 else if (query == TDEGenericDeviceType::SCSI) {
5926 else if (query == TDEGenericDeviceType::StorageController) {
5929 else if (query == TDEGenericDeviceType::Mouse) {
5932 else if (query == TDEGenericDeviceType::Keyboard) {
5935 else if (query == TDEGenericDeviceType::HID) {
5938 else if (query == TDEGenericDeviceType::Modem) {
5941 else if (query == TDEGenericDeviceType::Monitor) {
5944 else if (query == TDEGenericDeviceType::Network) {
5947 else if (query == TDEGenericDeviceType::Printer) {
5950 else if (query == TDEGenericDeviceType::Scanner) {
5953 else if (query == TDEGenericDeviceType::Sound) {
5956 else if (query == TDEGenericDeviceType::VideoCapture) {
5959 else if (query == TDEGenericDeviceType::IEEE1394) {
5962 else if (query == TDEGenericDeviceType::PCMCIA) {
5965 else if (query == TDEGenericDeviceType::Camera) {
5968 else if (query == TDEGenericDeviceType::Serial) {
5969 ret =
DesktopIcon(
"input_devices_settings", size);
5971 else if (query == TDEGenericDeviceType::Parallel) {
5972 ret =
DesktopIcon(
"input_devices_settings", size);
5974 else if (query == TDEGenericDeviceType::TextIO) {
5977 else if (query == TDEGenericDeviceType::Peripheral) {
5980 else if (query == TDEGenericDeviceType::Backlight) {
5983 else if (query == TDEGenericDeviceType::Battery) {
5986 else if (query == TDEGenericDeviceType::PowerSupply) {
5989 else if (query == TDEGenericDeviceType::Dock) {
5992 else if (query == TDEGenericDeviceType::ThermalSensor) {
5995 else if (query == TDEGenericDeviceType::ThermalControl) {
5998 else if (query == TDEGenericDeviceType::BlueTooth) {
6001 else if (query == TDEGenericDeviceType::Bridge) {
6004 else if (query == TDEGenericDeviceType::Platform) {
6007 else if (query == TDEGenericDeviceType::Cryptography) {
6010 else if (query == TDEGenericDeviceType::Event) {
6013 else if (query == TDEGenericDeviceType::Input) {
6016 else if (query == TDEGenericDeviceType::PNP) {
6019 else if (query == TDEGenericDeviceType::OtherACPI) {
6022 else if (query == TDEGenericDeviceType::OtherUSB) {
6025 else if (query == TDEGenericDeviceType::OtherMultimedia) {
6028 else if (query == TDEGenericDeviceType::OtherPeripheral) {
6031 else if (query == TDEGenericDeviceType::OtherSensor) {
6034 else if (query == TDEGenericDeviceType::OtherVirtual) {
6044 TDERootSystemDevice* TDEHardwareDevices::rootSystemDevice() {
6045 TDEGenericDevice *hwdevice;
6046 for ( hwdevice = m_deviceList.first(); hwdevice; hwdevice = m_deviceList.next() ) {
6047 if (hwdevice->type() == TDEGenericDeviceType::RootSystem) {
6048 return dynamic_cast<TDERootSystemDevice*
>(hwdevice);
6055 TQString TDEHardwareDevices::bytesToFriendlySizeString(
double bytes) {
6056 TQString prettystring;
6058 prettystring = TQString(
"%1B").arg(bytes);
6061 bytes = bytes / 1024;
6062 prettystring = TQString(
"%1KB").arg(bytes, 0,
'f', 1);
6066 bytes = bytes / 1024;
6067 prettystring = TQString(
"%1MB").arg(bytes, 0,
'f', 1);
6071 bytes = bytes / 1024;
6072 prettystring = TQString(
"%1GB").arg(bytes, 0,
'f', 1);
6076 bytes = bytes / 1024;
6077 prettystring = TQString(
"%1TB").arg(bytes, 0,
'f', 1);
6081 bytes = bytes / 1024;
6082 prettystring = TQString(
"%1PB").arg(bytes, 0,
'f', 1);
6086 bytes = bytes / 1024;
6087 prettystring = TQString(
"%1EB").arg(bytes, 0,
'f', 1);
6091 bytes = bytes / 1024;
6092 prettystring = TQString(
"%1ZB").arg(bytes, 0,
'f', 1);
6096 bytes = bytes / 1024;
6097 prettystring = TQString(
"%1YB").arg(bytes, 0,
'f', 1);
6100 return prettystring;
6103 TDEGenericHardwareList TDEHardwareDevices::listByDeviceClass(TDEGenericDeviceType::TDEGenericDeviceType cl) {
6104 TDEGenericHardwareList ret;
6105 ret.setAutoDelete(
false);
6107 TDEGenericDevice *hwdevice;
6108 for ( hwdevice = m_deviceList.first(); hwdevice; hwdevice = m_deviceList.next() ) {
6109 if (hwdevice->type() == cl) {
6110 ret.append(hwdevice);
6117 TDEGenericHardwareList TDEHardwareDevices::listAllPhysicalDevices() {
6118 TDEGenericHardwareList ret = m_deviceList;
6119 ret.setAutoDelete(
false);
6124 #include "tdehardwaredevices.moc"