diff options
Diffstat (limited to 'tdecore')
-rw-r--r-- | tdecore/tdehardwaredevices.cpp | 64 | ||||
-rw-r--r-- | tdecore/tdehardwaredevices.h | 48 |
2 files changed, 102 insertions, 10 deletions
diff --git a/tdecore/tdehardwaredevices.cpp b/tdecore/tdehardwaredevices.cpp index 3c1afe44a..424c7533c 100644 --- a/tdecore/tdehardwaredevices.cpp +++ b/tdecore/tdehardwaredevices.cpp @@ -930,6 +930,33 @@ void TDECPUDevice::setGovernor(TQString gv) { stream << gv.lower(); file.close(); } + + // Force update of the device information object + KGlobal::hardwareDevices()->processModifiedCPUs(); +} + +bool TDECPUDevice::canSetMaximumScalingFrequency() { + TQString freqnode = systemPath() + "/cpufreq/scaling_max_freq"; + int rval = access (freqnode.ascii(), W_OK); + if (rval == 0) { + return TRUE; + } + else { + return FALSE; + } +} + +void TDECPUDevice::setMaximumScalingFrequency(double fr) { + TQString freqnode = systemPath() + "/cpufreq/scaling_max_freq"; + TQFile file( freqnode ); + if ( file.open( IO_WriteOnly ) ) { + TQTextStream stream( &file ); + stream << TQString("%1").arg(fr*1000000.0, 0, 'f', 0); + file.close(); + } + + // Force update of the device information object + KGlobal::hardwareDevices()->processModifiedCPUs(); } TDESensorDevice::TDESensorDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) { @@ -1213,6 +1240,14 @@ void TDEBatteryDevice::internalSetDischargeRate(double vt) { m_dischargeRate = vt; } +double TDEBatteryDevice::timeRemaining() { + return m_timeRemaining; +} + +void TDEBatteryDevice::internalSetTimeRemaining(double tr) { + m_timeRemaining = tr; +} + TQString TDEBatteryDevice::technology() { return m_technology; } @@ -1221,12 +1256,25 @@ void TDEBatteryDevice::internalSetTechnology(TQString tc) { m_technology = tc; } -TQString TDEBatteryDevice::status() { +TDEBatteryStatus::TDEBatteryStatus TDEBatteryDevice::status() { return m_status; } void TDEBatteryDevice::internalSetStatus(TQString tc) { - m_status = tc; + tc = tc.lower(); + + if (tc == "charging") { + m_status = TDEBatteryStatus::Charging; + } + else if (tc == "discharging") { + m_status = TDEBatteryStatus::Discharging; + } + else if (tc == "full") { + m_status = TDEBatteryStatus::Full; + } + else { + m_status = TDEBatteryStatus::Unknown; + } } bool TDEBatteryDevice::installed() { @@ -1788,7 +1836,7 @@ void TDEHardwareDevices::processHotPluggedHardware() { TQString actionevent(udev_device_get_action(dev)); if (actionevent == "add") { TDEGenericDevice* device = classifyUnknownDevice(dev); - + // Make sure this device is not a duplicate TDEGenericDevice *hwdevice; for (hwdevice = m_deviceList.first(); hwdevice; hwdevice = m_deviceList.next()) { @@ -1808,6 +1856,7 @@ void TDEHardwareDevices::processHotPluggedHardware() { else if (actionevent == "remove") { // Delete device from hardware listing TQString systempath(udev_device_get_syspath(dev)); + systempath += "/"; TDEGenericDevice *hwdevice; for (hwdevice = m_deviceList.first(); hwdevice; hwdevice = m_deviceList.next()) { if (hwdevice->systemPath() == systempath) { @@ -1837,6 +1886,7 @@ void TDEHardwareDevices::processHotPluggedHardware() { else if (actionevent == "change") { // Update device and emit change event TQString systempath(udev_device_get_syspath(dev)); + systempath += "/"; TDEGenericDevice *hwdevice; for (hwdevice = m_deviceList.first(); hwdevice; hwdevice = m_deviceList.next()) { if (hwdevice->systemPath() == systempath) { @@ -1938,7 +1988,7 @@ void TDEHardwareDevices::processModifiedCPUs() { scalingdriverfile.close(); } nodename = cpufreq_dir.path(); - nodename.append("/scaling_min_freq"); + nodename.append("/cpuinfo_min_freq"); TQFile minfrequencyfile(nodename); if (minfrequencyfile.open(IO_ReadOnly)) { TQTextStream stream( &minfrequencyfile ); @@ -1946,7 +1996,7 @@ void TDEHardwareDevices::processModifiedCPUs() { minfrequencyfile.close(); } nodename = cpufreq_dir.path(); - nodename.append("/scaling_max_freq"); + nodename.append("/cpuinfo_max_freq"); TQFile maxfrequencyfile(nodename); if (maxfrequencyfile.open(IO_ReadOnly)) { TQTextStream stream( &maxfrequencyfile ); @@ -2680,6 +2730,7 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD devicesubsystem = (udev_device_get_subsystem(dev)); devicenode = (udev_device_get_devnode(dev)); systempath = (udev_device_get_syspath(dev)); + systempath += "/"; devicevendorid = (udev_device_get_property_value(dev, "ID_VENDOR_ID")); devicemodelid = (udev_device_get_property_value(dev, "ID_MODEL_ID")); devicevendoridenc = (udev_device_get_property_value(dev, "ID_VENDOR_ENC")); @@ -3660,6 +3711,9 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD ++valuesdirit; } } + + // Calculate time remaining + bdevice->internalSetTimeRemaining(bdevice->energy()*bdevice->dischargeRate()*60); } if (device->type() == TDEGenericDeviceType::PowerSupply) { diff --git a/tdecore/tdehardwaredevices.h b/tdecore/tdehardwaredevices.h index f3c11126f..9061ad7fc 100644 --- a/tdecore/tdehardwaredevices.h +++ b/tdecore/tdehardwaredevices.h @@ -773,6 +773,16 @@ class TDECORE_EXPORT TDECPUDevice : public TDEGenericDevice */ void setGovernor(TQString gv); + /** + * @return TRUE if permissions allow the CPU maximum frequency to be set, FALSE if not + */ + bool canSetMaximumScalingFrequency(); + + /** + * @param gv a double with the new CPU maximum frequency in MHz + */ + void setMaximumScalingFrequency(double fr); + protected: /** * @param fr a double with the current CPU frequency in MHz, if available @@ -842,6 +852,15 @@ class TDECORE_EXPORT TDECPUDevice : public TDEGenericDevice friend class TDEHardwareDevices; }; +namespace TDEBatteryStatus { +enum TDEBatteryStatus { + Charging, + Discharging, + Full, + Unknown = 0x80000000 +}; +}; + class TDECORE_EXPORT TDEBatteryDevice : public TDEGenericDevice { public: @@ -902,14 +921,19 @@ class TDECORE_EXPORT TDEBatteryDevice : public TDEGenericDevice double dischargeRate(); /** + * @return a double with the current battery discharge time remaining in seconds, if available + */ + double timeRemaining(); + + /** * @return a TQString with the battery technology, if available */ TQString technology(); /** - * @return a TQString with the battery status, if available + * @return a TDEBatteryStatus::TDEBatteryStatus with the current battery status */ - TQString status(); + TDEBatteryStatus::TDEBatteryStatus status(); /** * @return TRUE if the battery is installed @@ -977,6 +1001,12 @@ class TDECORE_EXPORT TDEBatteryDevice : public TDEGenericDevice void internalSetDischargeRate(double vt); /** + * @param a double with the current battery discharge time remaining in seconds, if available + * @internal + */ + void internalSetTimeRemaining(double tr); + + /** * @param a TQString with the battery technology, if available * @internal */ @@ -1004,8 +1034,9 @@ class TDECORE_EXPORT TDEBatteryDevice : public TDEGenericDevice double m_maximumEnergy; double m_maximumDesignEnergy; double m_dischargeRate; + double m_timeRemaining; TQString m_technology; - TQString m_status; + TDEBatteryStatus::TDEBatteryStatus m_status; bool m_installed; friend class TDEHardwareDevices; @@ -1569,7 +1600,7 @@ class TDECORE_EXPORT TDERootSystemDevice : public TDEGenericDevice void setHibernationMethod(TDESystemHibernationMethod::TDESystemHibernationMethod hm); /** - * @param ps a TDESystemPowerState::TDESystemPowerState with the desired hibernation method + * @param ps a TDESystemPowerState::TDESystemPowerState with the desired power state * @return TRUE if power state was set */ bool setPowerState(TDESystemPowerState::TDESystemPowerState ps); @@ -1894,6 +1925,13 @@ class TDECORE_EXPORT TDEHardwareDevices : public TQObject TDERootSystemDevice* rootSystemDevice(); /** + * Rescan a hardware device to look for changes + * WARNING: This method can be very expensive. Use with caution! + * @param hwdevice TDEGenericDevice* with the device to rescan + */ + void rescanDeviceInformation(TDEGenericDevice* hwdevice); + + /** * Convert a byte count to human readable form * @param bytes a double containing the number of bytes * @return a TQString containing the human readable byte count @@ -1913,7 +1951,6 @@ class TDECORE_EXPORT TDEHardwareDevices : public TQObject void processStatelessDevices(); private: - void rescanDeviceInformation(TDEGenericDevice* hwdevice); void updateBlacklists(TDEGenericDevice* hwdevice, udev_device* dev); private: @@ -1958,6 +1995,7 @@ class TDECORE_EXPORT TDEHardwareDevices : public TQObject friend class TDEGenericDevice; friend class TDEStorageDevice; + friend class TDECPUDevice; }; #endif
\ No newline at end of file |