diff options
-rw-r--r-- | src/hardware.cpp | 2127 |
1 files changed, 1184 insertions, 943 deletions
diff --git a/src/hardware.cpp b/src/hardware.cpp index 9507ae0..6c29de3 100644 --- a/src/hardware.cpp +++ b/src/hardware.cpp @@ -1,4 +1,4 @@ - /************************************************************************** +/************************************************************************** * Copyright (C) 2006-2007 by Danny Kukawka * * <dkukawka@suse.de>, <danny.kukawka@web.de> * * * @@ -46,65 +46,69 @@ // #define USE_EVENT_DEVICES_DIRECTLY 1 /*! The default constructor of the class HardwareInfo */ -HardwareInfo::HardwareInfo() { - kdDebugFuncIn(trace); +HardwareInfo::HardwareInfo() +{ + kdDebugFuncIn(trace); - // init members - acadapter = true; - lidclose = false; - laptop = false; - brightness = false; - brightness_in_hardware = false; - sessionIsActive = true; // assume as first we are active + // init members + acadapter = true; + lidclose = false; + laptop = false; + brightness = false; + brightness_in_hardware = false; + sessionIsActive = true; // assume as first we are active - // initialize connection to the TDE hardware library - m_hwdevices = TDEGlobal::hardwareDevices(); - connect(m_hwdevices, TQ_SIGNAL(hardwareUpdated(TDEGenericDevice*)), this, TQ_SLOT(processHardwareChangedEvent(TDEGenericDevice*))); + // initialize connection to the TDE hardware library + m_hwdevices = TDEGlobal::hardwareDevices(); + connect(m_hwdevices, TQ_SIGNAL(hardwareUpdated(TDEGenericDevice*)), + this, TQ_SLOT(processHardwareChangedEvent(TDEGenericDevice*))); #ifdef USE_EVENT_DEVICES_DIRECTLY - connect(m_hwdevices, TQ_SIGNAL(eventDeviceKeyPressed(unsigned int, TDEEventDevice*)), this, TQ_SLOT(processKeyPressEvent(unsigned int, TDEEventDevice*))); + connect(m_hwdevices, TQ_SIGNAL(eventDeviceKeyPressed(unsigned int, TDEEventDevice*)), + this, TQ_SLOT(processKeyPressEvent(unsigned int, TDEEventDevice*))); #endif - // update everything the first time - update_info_ac_changed = true; - update_info_cpufreq_policy_changed = true; - update_info_primBattery_changed = true; + // update everything the first time + update_info_ac_changed = true; + update_info_cpufreq_policy_changed = true; + update_info_primBattery_changed = true; - currentCPUFreqPolicy = UNKNOWN_CPUFREQ; - primaryBatteriesWarnLevel = 12; - primaryBatteriesLowLevel = 7; - primaryBatteriesCriticalLevel = 2; + currentCPUFreqPolicy = UNKNOWN_CPUFREQ; + primaryBatteriesWarnLevel = 12; + primaryBatteriesLowLevel = 7; + primaryBatteriesCriticalLevel = 2; - allUDIs = TQStringList(); - unknownUDIs = TQStringList(); - consoleKitSession = TQString(); - BatteryList.setAutoDelete( true ); // the list owns the objects + allUDIs = TQStringList(); + unknownUDIs = TQStringList(); + consoleKitSession = TQString(); + BatteryList.setAutoDelete(true); // the list owns the objects - primaryBatteries = new BatteryCollection(BAT_PRIMARY); - setPrimaryBatteriesWarningLevel(); // force default settings + primaryBatteries = new BatteryCollection(BAT_PRIMARY); + setPrimaryBatteriesWarningLevel(); // force default settings - // connect to D-Bus - dbus_iface = new dbusInterface(); - sessionIsActive = dbus_iface->checkActiveSession(); - connect(dbus_iface, TQ_SIGNAL(activeSessionChanged(bool)), this, TQ_SLOT(handleSessionState(bool))); + // connect to D-Bus + dbus_iface = new dbusInterface(); + sessionIsActive = dbus_iface->checkActiveSession(); + connect(dbus_iface, TQ_SIGNAL(activeSessionChanged(bool)), this, TQ_SLOT(handleSessionState(bool))); - checkPowermanagement(); - checkIsLaptop(); - checkBrightness(); - checkCPUFreq(); - checkSuspend(); - intialiseHWInfo(); + checkPowermanagement(); + checkIsLaptop(); + checkBrightness(); + checkCPUFreq(); + checkSuspend(); + intialiseHWInfo(); - updatePrimaryBatteries(); + updatePrimaryBatteries(); - kdDebugFuncOut(trace); + kdDebugFuncOut(trace); } /*! The default desctuctor of the class HardwareInfo */ -HardwareInfo::~HardwareInfo() { - kdDebugFuncIn(trace); +HardwareInfo::~HardwareInfo() +{ + kdDebugFuncIn(trace); - kdDebugFuncOut(trace); + kdDebugFuncOut(trace); } /*! @@ -113,49 +117,51 @@ HardwareInfo::~HardwareInfo() { * \retval true if reinit HW infos correct * \retval false if not */ -bool HardwareInfo::reinitHardwareInfos () { - kdDebugFuncIn(trace); - - /* first cleanup */ - acadapter = true; - lidclose = false; - laptop = false; - brightness = false; - has_APM = false; - has_ACPI = false; - - update_info_ac_changed = true; - update_info_cpufreq_policy_changed = true; - update_info_primBattery_changed = true; - - allUDIs = TQStringList(); +bool HardwareInfo::reinitHardwareInfos() +{ + kdDebugFuncIn(trace); + + /* first cleanup */ + acadapter = true; + lidclose = false; + laptop = false; + brightness = false; + has_APM = false; + has_ACPI = false; + + update_info_ac_changed = true; + update_info_cpufreq_policy_changed = true; + update_info_primBattery_changed = true; + + allUDIs = TQStringList(); unknownUDIs = TQStringList(); - BatteryList.clear(); - primaryBatteries = new BatteryCollection(BAT_PRIMARY); + BatteryList.clear(); + primaryBatteries = new BatteryCollection(BAT_PRIMARY); - /* reinit hardware data */ - checkPowermanagement(); - checkIsLaptop(); - checkBrightness(); - checkCPUFreq(); - checkSuspend(); - intialiseHWInfo(); - updatePrimaryBatteries(); + /* reinit hardware data */ + checkPowermanagement(); + checkIsLaptop(); + checkBrightness(); + checkCPUFreq(); + checkSuspend(); + intialiseHWInfo(); + updatePrimaryBatteries(); - kdDebugFuncOut(trace); - return true; + kdDebugFuncOut(trace); + return true; } - /*! * \b Slot called if the state of the current session change * \param state boolean represent the state of the session */ -void HardwareInfo::handleSessionState( bool state ) { - if( state != sessionIsActive ) { - sessionIsActive = state; - TQTimer::singleShot(50, this, TQ_SLOT(emitSessionActiveState())); +void HardwareInfo::handleSessionState(bool state) +{ + if (state != sessionIsActive) + { + sessionIsActive = state; + TQTimer::singleShot(50, this, TQ_SLOT(emitSessionActiveState())); } } @@ -163,36 +169,49 @@ void HardwareInfo::handleSessionState( bool state ) { * This function is used to parse changed hardware nofifications from the TDE hardware library * \param device a \ref TDEGenericDevice* which should be processed */ -void HardwareInfo::processHardwareChangedEvent (TDEGenericDevice* device) { - kdDebugFuncIn(trace); - - if (allUDIs.contains( device->uniqueID() )) { - if (device->type() == TDEGenericDeviceType::PowerSupply) { - TQTimer::singleShot(50, this, TQ_SLOT(checkACAdapterState())); - } else if (device->type() == TDEGenericDeviceType::Battery) { - // this is a battery event - updateBatteryValues(device); - } else if (device->type() == TDEGenericDeviceType::Event) { - TDEEventDevice* edevice = dynamic_cast<TDEEventDevice*>(device); - if (edevice) { - if (edevice->eventType() == TDEEventDeviceType::ACPILidSwitch) { - TQTimer::singleShot(50, this, TQ_SLOT(checkLidcloseState())); - } - } - } else if (device->type() == TDEGenericDeviceType::Backlight) { - TQTimer::singleShot(50, this, TQ_SLOT(checkBrightness())); - } - // TODO: add needed code - } else { - TQString duid = device->uniqueID(); - if (!unknownUDIs.contains(duid)) - { - kdDebug() << "unmonitored device changed: " << duid << endl; - unknownUDIs.append(duid); - } - } - - kdDebugFuncOut(trace); +void HardwareInfo::processHardwareChangedEvent(TDEGenericDevice *device) +{ + kdDebugFuncIn(trace); + + if (allUDIs.contains(device->uniqueID())) + { + if (device->type() == TDEGenericDeviceType::PowerSupply) + { + TQTimer::singleShot(50, this, TQ_SLOT(checkACAdapterState())); + } + else if (device->type() == TDEGenericDeviceType::Battery) + { + // this is a battery event + updateBatteryValues(device); + } + else if (device->type() == TDEGenericDeviceType::Event) + { + TDEEventDevice *edevice = dynamic_cast<TDEEventDevice*>(device); + if (edevice) + { + if (edevice->eventType() == TDEEventDeviceType::ACPILidSwitch) + { + TQTimer::singleShot(50, this, TQ_SLOT(checkLidcloseState())); + } + } + } + else if (device->type() == TDEGenericDeviceType::Backlight) + { + TQTimer::singleShot(50, this, TQ_SLOT(checkBrightness())); + } + // TODO: add needed code + } + else + { + TQString duid = device->uniqueID(); + if (!unknownUDIs.contains(duid)) + { + kdDebug() << "unmonitored device changed: " << duid << endl; + unknownUDIs.append(duid); + } + } + + kdDebugFuncOut(trace); } /*! @@ -200,24 +219,27 @@ void HardwareInfo::processHardwareChangedEvent (TDEGenericDevice* device) { * \param keycode a keycode which should be processed * \param edevice the \ref TDEEventDevice* from whence the keypress originated */ -void HardwareInfo::processKeyPressEvent(unsigned int keycode, TDEEventDevice* edevice) { - kdDebugFuncIn(trace); - - // FIXME - // How can I get specific button press/release information (instead of just "something happened to the button") from the TDE hardware library? - kdDebug() << "ButtonPressed event from TDE HW library " << endl; - if (((edevice->eventType() == TDEEventDeviceType::ACPIPowerButton) || (edevice->eventType() == TDEEventDeviceType::ACPIOtherInput)) - && (keycode == KEY_POWER)) { - TQTimer::singleShot(50, this, TQ_SLOT(emitPowerButtonPressed())); - } else if (((edevice->eventType() == TDEEventDeviceType::ACPISuspendButton) || (edevice->eventType() == TDEEventDeviceType::ACPIOtherInput)) - && (keycode == KEY_SLEEP)) { - TQTimer::singleShot(50, this, TQ_SLOT(emitSuspendButtonPressed())); - } else if (((edevice->eventType() == TDEEventDeviceType::ACPISuspendButton) || (edevice->eventType() == TDEEventDeviceType::ACPIOtherInput)) - && (keycode == KEY_SUSPEND)) { - TQTimer::singleShot(50, this, TQ_SLOT(emitS2diskButtonPressed())); - } - - kdDebugFuncOut(trace); +void HardwareInfo::processKeyPressEvent(unsigned int keycode, TDEEventDevice *edevice) +{ + kdDebugFuncIn(trace); + + // FIXME + // How can I get specific button press/release information (instead of just "something happened to the button") from the TDE hardware library? + kdDebug() << "ButtonPressed event from TDE HW library " << endl; + if (((edevice->eventType() == TDEEventDeviceType::ACPIPowerButton) || (edevice->eventType() == TDEEventDeviceType::ACPIOtherInput)) && (keycode == KEY_POWER)) + { + TQTimer::singleShot(50, this, TQ_SLOT(emitPowerButtonPressed())); + } + else if (((edevice->eventType() == TDEEventDeviceType::ACPISuspendButton) || (edevice->eventType() == TDEEventDeviceType::ACPIOtherInput)) && (keycode == KEY_SLEEP)) + { + TQTimer::singleShot(50, this, TQ_SLOT(emitSuspendButtonPressed())); + } + else if (((edevice->eventType() == TDEEventDeviceType::ACPISuspendButton) || (edevice->eventType() == TDEEventDeviceType::ACPIOtherInput)) && (keycode == KEY_SUSPEND)) + { + TQTimer::singleShot(50, this, TQ_SLOT(emitS2diskButtonPressed())); + } + + kdDebugFuncOut(trace); } /*! @@ -225,21 +247,27 @@ void HardwareInfo::processKeyPressEvent(unsigned int keycode, TDEEventDevice* ed * actions after resume, do this here. * \param result integer with the result of the resume/suspend */ -void HardwareInfo::handleResumeSignal (int result) { - if (trace) kdDebug() << funcinfo << "IN: " << "(int result: " << result << ")"<< endl; - - if (result == -1) { - // check if time since suspend is higher than 6 hours, - // the magic D-Bus timeout for pending calls - if (calledSuspend.elapsed() > 21600000) { - emit resumed(INT_MAX); - } - } else { - emit resumed(result); - } - - calledSuspend = TQTime(); - kdDebugFuncOut(trace); +void HardwareInfo::handleResumeSignal(int result) +{ + if (trace) + kdDebug() << funcinfo << "IN: " << "(int result: " << result << ")" << endl; + + if (result == -1) + { + // check if time since suspend is higher than 6 hours, + // the magic D-Bus timeout for pending calls + if (calledSuspend.elapsed() > 21600000) + { + emit resumed(INT_MAX); + } + } + else + { + emit resumed(result); + } + + calledSuspend = TQTime(); + kdDebugFuncOut(trace); } /*! @@ -250,49 +278,73 @@ void HardwareInfo::handleResumeSignal (int result) { * \retval true if we should handle * \retval false if not */ -bool HardwareInfo::checkIfHandleDevice ( TQString _udi, int *type) { - kdDebugFuncIn(trace); - - TQStringList _cap; - bool ret = true; - - TDEGenericDevice* hwdevice = m_hwdevices->findByUniqueID(_udi); - - if (hwdevice) { - TDEGenericDeviceType::TDEGenericDeviceType devtype = hwdevice->type(); - if (devtype == TDEGenericDeviceType::PowerSupply) { - *type = BATTERY; - } else if (devtype == TDEGenericDeviceType::Event) { - TDEEventDevice* edevice = dynamic_cast<TDEEventDevice*>(hwdevice); - if (edevice) { - if (edevice->eventType() == TDEEventDeviceType::ACPILidSwitch) { - *type = LID; - } else if (edevice->eventType() == TDEEventDeviceType::ACPIPowerButton) { - *type = BUTTON_POWER; - } else if (edevice->eventType() == TDEEventDeviceType::ACPISuspendButton) { - *type = BUTTON_SLEEP; - } else { - ret = false; - } - } else { - ret = false; - } - } else if (devtype == TDEGenericDeviceType::Battery) { - *type = BATTERY; - } else if (devtype == TDEGenericDeviceType::Backlight) { - *type = LAPTOP_PANEL; - } else { - ret = false; - kdDebug() << "Device with type " << devtype << " unhandled" << endl; - } - } else { - ret = false; - } - - if (!ret) *type = UNKNOWN_DEVICE; - - kdDebugFuncOut(trace); - return ret; +bool HardwareInfo::checkIfHandleDevice(TQString _udi, int *type) +{ + kdDebugFuncIn(trace); + + TQStringList _cap; + bool ret = true; + + TDEGenericDevice *hwdevice = m_hwdevices->findByUniqueID(_udi); + + if (hwdevice) + { + TDEGenericDeviceType::TDEGenericDeviceType devtype = hwdevice->type(); + if (devtype == TDEGenericDeviceType::PowerSupply) + { + *type = BATTERY; + } + else if (devtype == TDEGenericDeviceType::Event) + { + TDEEventDevice *edevice = dynamic_cast<TDEEventDevice*>(hwdevice); + if (edevice) + { + if (edevice->eventType() == TDEEventDeviceType::ACPILidSwitch) + { + *type = LID; + } + else if (edevice->eventType() == TDEEventDeviceType::ACPIPowerButton) + { + *type = BUTTON_POWER; + } + else if (edevice->eventType() == TDEEventDeviceType::ACPISuspendButton) + { + *type = BUTTON_SLEEP; + } + else + { + ret = false; + } + } + else + { + ret = false; + } + } + else if (devtype == TDEGenericDeviceType::Battery) + { + *type = BATTERY; + } + else if (devtype == TDEGenericDeviceType::Backlight) + { + *type = LAPTOP_PANEL; + } + else + { + ret = false; + kdDebug() << "Device with type " << devtype << " unhandled" << endl; + } + } + else + { + ret = false; + } + + if (!ret) + *type = UNKNOWN_DEVICE; + + kdDebugFuncOut(trace); + return ret; } // --> set some values for devices @@ -304,25 +356,30 @@ bool HardwareInfo::checkIfHandleDevice ( TQString _udi, int *type) { * \param _low value for the state BAT_LOW or -1 * \param _crit value for the state BAT_CRIT or -1 */ -void HardwareInfo::setPrimaryBatteriesWarningLevel (int _warn, int _low, int _crit ) { - if (trace) kdDebug() << funcinfo << "IN: " << "warn: " << _warn << " low: " << _low << " crit: " << _crit << endl; - - if (_warn > -1 && _low > -1 && _crit > -1 ){ - primaryBatteriesWarnLevel = _warn; - primaryBatteriesLowLevel = _low; - primaryBatteriesCriticalLevel = _crit; - } - - if (primaryBatteries) { - primaryBatteries->setWarnLevel( primaryBatteriesWarnLevel ); - primaryBatteries->setLowLevel( primaryBatteriesLowLevel ); - primaryBatteries->setCritLevel( primaryBatteriesCriticalLevel ); - if (!BatteryList.isEmpty()) { - primaryBatteries->refreshInfo( BatteryList, true ); - } - } - - kdDebugFuncOut(trace); +void HardwareInfo::setPrimaryBatteriesWarningLevel(int _warn, int _low, int _crit) +{ + if (trace) + kdDebug() << funcinfo << "IN: " << "warn: " << _warn << " low: " << _low << " crit: " << _crit << endl; + + if (_warn > -1 && _low > -1 && _crit > -1) + { + primaryBatteriesWarnLevel = _warn; + primaryBatteriesLowLevel = _low; + primaryBatteriesCriticalLevel = _crit; + } + + if (primaryBatteries) + { + primaryBatteries->setWarnLevel(primaryBatteriesWarnLevel); + primaryBatteries->setLowLevel(primaryBatteriesLowLevel); + primaryBatteries->setCritLevel(primaryBatteriesCriticalLevel); + if (!BatteryList.isEmpty()) + { + primaryBatteries->refreshInfo(BatteryList, true); + } + } + + kdDebugFuncOut(trace); } // --> init HW information section -- START <--- @@ -330,257 +387,298 @@ void HardwareInfo::setPrimaryBatteriesWarningLevel (int _warn, int _low, int _cr /*! * The function checks if the machine is a laptop. */ -void HardwareInfo::checkIsLaptop () { - kdDebugFuncIn(trace); +void HardwareInfo::checkIsLaptop() +{ + kdDebugFuncIn(trace); - TQString ret; + TQString ret; - TDERootSystemDevice* rdevice = m_hwdevices->rootSystemDevice(); + TDERootSystemDevice *rdevice = m_hwdevices->rootSystemDevice(); - if (rdevice->formFactor() == TDESystemFormFactor::Laptop) { - laptop = true; - } - else { - laptop = false; - } + if (rdevice->formFactor() == TDESystemFormFactor::Laptop) + { + laptop = true; + } + else + { + laptop = false; + } - kdDebugFuncOut(trace); + kdDebugFuncOut(trace); } /*! * The function checks whether the machine support ACPI/APM/PMU or not. */ -void HardwareInfo::checkPowermanagement() { - kdDebugFuncIn(trace); +void HardwareInfo::checkPowermanagement() +{ + kdDebugFuncIn(trace); - TQString ret; + TQString ret; - has_APM = false; - has_ACPI = false; - has_PMU = false; + has_APM = false; + has_ACPI = false; + has_PMU = false; - TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::OtherACPI); - if (hwlist.count() > 0) { - has_ACPI = true; - } + TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::OtherACPI); + if (hwlist.count() > 0) + { + has_ACPI = true; + } - // FIXME - // Do we even need to detect APM and PMU devices in the year 2012?!? + // FIXME + // Do we even need to detect APM and PMU devices in the year 2012?!? - kdDebugFuncOut(trace); + kdDebugFuncOut(trace); } - /*! * The function checks whether the machine can suspend/standby. */ -void HardwareInfo::checkSuspend() { - kdDebugFuncIn(trace); - - suspend_states = SuspendStates(); - - suspend_states.suspend2ram = false; - suspend_states.suspend2ram_can = false; - suspend_states.suspend2ram_allowed = -1; - suspend_states.suspend2disk = false; - suspend_states.suspend2disk_can = false; - suspend_states.suspend2disk_allowed = -1; - suspend_states.freeze = false; - suspend_states.freeze_can = false; - suspend_states.freeze_allowed = -1; - suspend_states.standby = false; - suspend_states.standby_can = false; - suspend_states.standby_allowed = -1; - suspend_states.suspend_hybrid = false; - suspend_states.suspend_hybrid_can = false; - suspend_states.suspend_hybrid_allowed = -1; - - TDERootSystemDevice* rdevice = m_hwdevices->rootSystemDevice(); - TDESystemPowerStateList powerStates = rdevice->powerStates(); - if (powerStates.count() > 0) { - TDESystemPowerStateList::iterator it; - for (it = powerStates.begin(); it != powerStates.end(); ++it) { - if ((*it) == TDESystemPowerState::Active) { - // - } - else if ((*it) == TDESystemPowerState::Standby) { - suspend_states.standby = true; - suspend_states.standby_allowed = rdevice->canStandby(); - suspend_states.standby_can = suspend_states.standby_allowed && suspend_states.standby; - } - else if ((*it) == TDESystemPowerState::Freeze) { - suspend_states.freeze = true; - suspend_states.freeze_allowed = rdevice->canFreeze(); - suspend_states.freeze_can = suspend_states.freeze_allowed && suspend_states.freeze; - } - else if ((*it) == TDESystemPowerState::Suspend) { - suspend_states.suspend2ram = true; - suspend_states.suspend2ram_allowed = rdevice->canSuspend(); - suspend_states.suspend2ram_can = suspend_states.suspend2ram_allowed && suspend_states.suspend2ram; - } - else if ((*it) == TDESystemPowerState::Hibernate) { - suspend_states.suspend2disk = true; - suspend_states.suspend2disk_allowed = rdevice->canHibernate(); - suspend_states.suspend2disk_can = suspend_states.suspend2disk_allowed && suspend_states.suspend2disk; - } - else if ((*it) == TDESystemPowerState::HybridSuspend) { - suspend_states.suspend_hybrid = true; - suspend_states.suspend_hybrid_allowed = rdevice->canHybridSuspend(); - suspend_states.suspend_hybrid_can = suspend_states.suspend_hybrid_allowed && suspend_states.suspend_hybrid; - } - else if ((*it) == TDESystemPowerState::PowerOff) { - // - } - } - } - - kdDebugFuncOut(trace); +void HardwareInfo::checkSuspend() +{ + kdDebugFuncIn(trace); + + suspend_states = SuspendStates(); + + suspend_states.suspend2ram = false; + suspend_states.suspend2ram_can = false; + suspend_states.suspend2ram_allowed = -1; + suspend_states.suspend2disk = false; + suspend_states.suspend2disk_can = false; + suspend_states.suspend2disk_allowed = -1; + suspend_states.freeze = false; + suspend_states.freeze_can = false; + suspend_states.freeze_allowed = -1; + suspend_states.standby = false; + suspend_states.standby_can = false; + suspend_states.standby_allowed = -1; + suspend_states.suspend_hybrid = false; + suspend_states.suspend_hybrid_can = false; + suspend_states.suspend_hybrid_allowed = -1; + + TDERootSystemDevice *rdevice = m_hwdevices->rootSystemDevice(); + TDESystemPowerStateList powerStates = rdevice->powerStates(); + if (powerStates.count() > 0) + { + TDESystemPowerStateList::iterator it; + for (it = powerStates.begin(); it != powerStates.end(); ++it) + { + if ((*it) == TDESystemPowerState::Active) + { + // + } + else if ((*it) == TDESystemPowerState::Standby) + { + suspend_states.standby = true; + suspend_states.standby_allowed = rdevice->canStandby(); + suspend_states.standby_can = suspend_states.standby_allowed && suspend_states.standby; + } + else if ((*it) == TDESystemPowerState::Freeze) + { + suspend_states.freeze = true; + suspend_states.freeze_allowed = rdevice->canFreeze(); + suspend_states.freeze_can = suspend_states.freeze_allowed && suspend_states.freeze; + } + else if ((*it) == TDESystemPowerState::Suspend) + { + suspend_states.suspend2ram = true; + suspend_states.suspend2ram_allowed = rdevice->canSuspend(); + suspend_states.suspend2ram_can = suspend_states.suspend2ram_allowed && suspend_states.suspend2ram; + } + else if ((*it) == TDESystemPowerState::Hibernate) + { + suspend_states.suspend2disk = true; + suspend_states.suspend2disk_allowed = rdevice->canHibernate(); + suspend_states.suspend2disk_can = suspend_states.suspend2disk_allowed && suspend_states.suspend2disk; + } + else if ((*it) == TDESystemPowerState::HybridSuspend) + { + suspend_states.suspend_hybrid = true; + suspend_states.suspend_hybrid_allowed = rdevice->canHybridSuspend(); + suspend_states.suspend_hybrid_can = suspend_states.suspend_hybrid_allowed && suspend_states.suspend_hybrid; + } + else if ((*it) == TDESystemPowerState::PowerOff) + { + // + } + } + } + + kdDebugFuncOut(trace); } /*! * The function checks whether the machine support CPU frequency changes */ -void HardwareInfo::checkCPUFreq() { - kdDebugFuncIn(trace); +void HardwareInfo::checkCPUFreq() +{ + kdDebugFuncIn(trace); - // Use the first CPU in the list; permissions are probably the same across all CPUs - TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::CPU); - TDEGenericDevice *hwdevice; - hwdevice = hwlist.first(); - TDECPUDevice *cpudevice = static_cast<TDECPUDevice*>(hwdevice); + // Use the first CPU in the list; permissions are probably the same across all CPUs + TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::CPU); + TDEGenericDevice *hwdevice; + hwdevice = hwlist.first(); + TDECPUDevice *cpudevice = static_cast<TDECPUDevice*>(hwdevice); - if (!cpudevice->scalingDriver().isNull()) { - cpuFreq = true; - cpuFreqAllowed = cpudevice->canSetGovernor(); + if (!cpudevice->scalingDriver().isNull()) + { + cpuFreq = true; + cpuFreqAllowed = cpudevice->canSetGovernor(); - checkCurrentCPUFreqPolicy(); - } else { - cpuFreq = false; - } + checkCurrentCPUFreqPolicy(); + } + else + { + cpuFreq = false; + } - kdDebugFuncOut(trace); + kdDebugFuncOut(trace); } /*! * The function check the currently selected CPU Frequency policy * \return the current policy */ -cpufreq_type HardwareInfo::checkCurrentCPUFreqPolicy() { - kdDebugFuncIn(trace); - - // Use the first CPU in the list; permissions are probably the same across all CPUs - TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::CPU); - TDEGenericDevice *hwdevice; - hwdevice = hwlist.first(); - TDECPUDevice *cpudevice = static_cast<TDECPUDevice*>(hwdevice); - - TQString gov = cpudevice->governor(); - - cpufreq_type _current = UNKNOWN_CPUFREQ; - - if (cpuFreq) { - if (!gov.isNull()) { - kdDebug() << "got CPU Freq gov: " << gov << endl; - if ((gov == "ondemand") || (gov == "userspace") || (gov == "conservative")) { - _current = DYNAMIC; - } else if (gov == "powersave") { - _current = POWERSAVE; - } else if (gov =="performance") { - _current = PERFORMANCE; - } else { - kdError() << "Got unknown CPUFreq Policy back: " << gov << endl; - } - cpuFreqGovernor = gov; - } else { - kdWarning() << "Could not get information about current governor" << endl; - } - } else { - kdWarning() << "CPU Frequency interface not supported by machine or TDE hardware library" << endl; - } - - if (_current != currentCPUFreqPolicy) { - currentCPUFreqPolicy = _current; - update_info_cpufreq_policy_changed = true; - emit currentCPUFreqPolicyChanged(); - } else { - update_info_cpufreq_policy_changed = false; - } - - kdDebugFuncOut(trace); - return currentCPUFreqPolicy; -} +cpufreq_type HardwareInfo::checkCurrentCPUFreqPolicy() +{ + kdDebugFuncIn(trace); + + // Use the first CPU in the list; permissions are probably the same across all CPUs + TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::CPU); + TDEGenericDevice *hwdevice; + hwdevice = hwlist.first(); + TDECPUDevice *cpudevice = static_cast<TDECPUDevice*>(hwdevice); + + TQString gov = cpudevice->governor(); + + cpufreq_type _current = UNKNOWN_CPUFREQ; + + if (cpuFreq) + { + if (!gov.isNull()) + { + kdDebug() << "got CPU Freq gov: " << gov << endl; + if ((gov == "ondemand") || (gov == "userspace") || (gov == "conservative")) + { + _current = DYNAMIC; + } + else if (gov == "powersave") + { + _current = POWERSAVE; + } + else if (gov == "performance") + { + _current = PERFORMANCE; + } + else + { + kdError() << "Got unknown CPUFreq Policy back: " << gov << endl; + } + cpuFreqGovernor = gov; + } + else + { + kdWarning() << "Could not get information about current governor" << endl; + } + } + else + { + kdWarning() << "CPU Frequency interface not supported by machine or TDE hardware library" << endl; + } + if (_current != currentCPUFreqPolicy) + { + currentCPUFreqPolicy = _current; + update_info_cpufreq_policy_changed = true; + emit currentCPUFreqPolicyChanged(); + } + else + { + update_info_cpufreq_policy_changed = false; + } + + kdDebugFuncOut(trace); + return currentCPUFreqPolicy; +} /*! * The function checks whether the machine provide a brightness interface and init * (if needed) brightness information. */ -void HardwareInfo::checkBrightness() { - kdDebugFuncIn(trace); - - TQStringList devices; - - brightness = false; - currentBrightnessLevel = -1; - availableBrightnessLevels = -1; - - // Use the first backlight in the list - TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::Backlight); - TDEGenericDevice *hwdevice; - hwdevice = hwlist.first(); - TDEBacklightDevice *backlightdevice = static_cast<TDEBacklightDevice*>(hwdevice); - - if (backlightdevice) { - udis.insert("laptop_panel", new TQString( hwdevice->uniqueID() )); - if (!allUDIs.contains( hwdevice->uniqueID() )) { - allUDIs.append( hwdevice->uniqueID() ); - } - - availableBrightnessLevels = backlightdevice->brightnessSteps(); - - if (availableBrightnessLevels > 1) { - brightnessAllowed = backlightdevice->canSetBrightness(); - - brightness = true; - // get the current level via GetBrightness - checkCurrentBrightness(); - } - else { - availableBrightnessLevels = -1; - } - } - else { - udis.remove("laptop_panel"); - kdDebug() << "no device with category laptop_panel found" << endl; - kdDebugFuncOut(trace); - return; - } - - kdDebugFuncOut(trace); -} +void HardwareInfo::checkBrightness() +{ + kdDebugFuncIn(trace); + + TQStringList devices; + + brightness = false; + currentBrightnessLevel = -1; + availableBrightnessLevels = -1; + + // Use the first backlight in the list + TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::Backlight); + TDEGenericDevice *hwdevice; + hwdevice = hwlist.first(); + TDEBacklightDevice *backlightdevice = static_cast<TDEBacklightDevice*>(hwdevice); + + if (backlightdevice) + { + udis.insert("laptop_panel", new TQString(hwdevice->uniqueID())); + if (!allUDIs.contains(hwdevice->uniqueID())) + { + allUDIs.append(hwdevice->uniqueID()); + } + + availableBrightnessLevels = backlightdevice->brightnessSteps(); + + if (availableBrightnessLevels > 1) + { + brightnessAllowed = backlightdevice->canSetBrightness(); + + brightness = true; + // get the current level via GetBrightness + checkCurrentBrightness(); + } + else + { + availableBrightnessLevels = -1; + } + } + else + { + udis.remove("laptop_panel"); + kdDebug() << "no device with category laptop_panel found" << endl; + kdDebugFuncOut(trace); + return; + } + kdDebugFuncOut(trace); +} /*! * The function check the current brigthness */ -void HardwareInfo::checkCurrentBrightness() { - kdDebugFuncIn(trace); - - if (brightness) { - // Use the first backlight in the list - TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::Backlight); - TDEGenericDevice *hwdevice; - hwdevice = hwlist.first(); - TDEBacklightDevice *backlightdevice = static_cast<TDEBacklightDevice*>(hwdevice); - - if (backlightdevice) { - currentBrightnessLevel = backlightdevice->rawBrightness(); - } - } - - kdDebugFuncOut(trace); -} +void HardwareInfo::checkCurrentBrightness() +{ + kdDebugFuncIn(trace); + + if (brightness) + { + // Use the first backlight in the list + TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::Backlight); + TDEGenericDevice *hwdevice; + hwdevice = hwlist.first(); + TDEBacklightDevice *backlightdevice = static_cast<TDEBacklightDevice*>(hwdevice); + + if (backlightdevice) + { + currentBrightnessLevel = backlightdevice->rawBrightness(); + } + } + kdDebugFuncOut(trace); +} /*! * The function initialise the hardware information and collect all @@ -589,105 +687,128 @@ void HardwareInfo::checkCurrentBrightness() { * \retval true if successful * \retval false else, if a error occurs */ -bool HardwareInfo::intialiseHWInfo() { - kdDebugFuncIn(trace); - - TDEGenericDevice *hwdevice; - TDEGenericHardwareList hwlist; - - hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::PowerSupply); - for ( hwdevice = hwlist.first(); hwdevice; hwdevice = hwlist.next() ) { - udis.insert("acadapter", new TQString( hwdevice->uniqueID() )); - if (!allUDIs.contains( hwdevice->uniqueID() )) { - allUDIs.append( hwdevice->uniqueID() ); - } - checkACAdapterState(); - } - - hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::Event); - for ( hwdevice = hwlist.first(); hwdevice; hwdevice = hwlist.next() ) { - TDEEventDevice* edevice = dynamic_cast<TDEEventDevice*>(hwdevice); - if (edevice->eventType() == TDEEventDeviceType::ACPILidSwitch) { - udis.insert("lidclose", new TQString( hwdevice->uniqueID() )); - if (!allUDIs.contains( hwdevice->uniqueID() )) { - allUDIs.append( hwdevice->uniqueID() ); - } - connect(edevice, TQ_SIGNAL(switchChanged()), this, TQ_SLOT(checkLidcloseState())); - checkLidcloseState(); - } - } - - // find batteries and fill battery information - hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::Battery); - for ( hwdevice = hwlist.first(); hwdevice; hwdevice = hwlist.next() ) { - if (!allUDIs.contains( hwdevice->uniqueID() )) { - allUDIs.append( hwdevice->uniqueID() ); - } - BatteryList.append( new Battery( hwdevice->uniqueID() ) ); - } - // connect to signals for primary batteries: - Battery *bat; - for (bat = BatteryList.first(); bat; bat = BatteryList.next() ) { - if (bat->getType() == BAT_PRIMARY) { - connect(bat, TQ_SIGNAL(changedBattery()),this, TQ_SLOT(updatePrimaryBatteries())); - } - } - - kdDebugFuncOut(trace); - return true; +bool HardwareInfo::intialiseHWInfo() +{ + kdDebugFuncIn(trace); + + TDEGenericDevice *hwdevice; + TDEGenericHardwareList hwlist; + + hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::PowerSupply); + for (hwdevice = hwlist.first(); hwdevice; hwdevice = hwlist.next()) + { + udis.insert("acadapter", new TQString(hwdevice->uniqueID())); + if (!allUDIs.contains(hwdevice->uniqueID())) + { + allUDIs.append(hwdevice->uniqueID()); + } + checkACAdapterState(); + } + + hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::Event); + for (hwdevice = hwlist.first(); hwdevice; hwdevice = hwlist.next()) + { + TDEEventDevice *edevice = dynamic_cast<TDEEventDevice*>(hwdevice); + if (edevice->eventType() == TDEEventDeviceType::ACPILidSwitch) + { + udis.insert("lidclose", new TQString(hwdevice->uniqueID())); + if (!allUDIs.contains(hwdevice->uniqueID())) + { + allUDIs.append(hwdevice->uniqueID()); + } + connect(edevice, TQ_SIGNAL(switchChanged()), this, TQ_SLOT(checkLidcloseState())); + checkLidcloseState(); + } + } + + // find batteries and fill battery information + hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::Battery); + for (hwdevice = hwlist.first(); hwdevice; hwdevice = hwlist.next()) + { + if (!allUDIs.contains(hwdevice->uniqueID())) + { + allUDIs.append(hwdevice->uniqueID()); + } + BatteryList.append(new Battery(hwdevice->uniqueID())); + } + // connect to signals for primary batteries: + Battery *bat; + for (bat = BatteryList.first(); bat; bat = BatteryList.next()) + { + if (bat->getType() == BAT_PRIMARY) + { + connect(bat, TQ_SIGNAL(changedBattery()), this, TQ_SLOT(updatePrimaryBatteries())); + } + } + + kdDebugFuncOut(trace); + return true; } /*! * The function/slot checks the state of the AC adapter. */ -void HardwareInfo::checkACAdapterState() { - kdDebugFuncIn(trace); - - if ( udis["acadapter"] ) { - bool _state; - - TDEMainsPowerDevice* mdevice = dynamic_cast<TDEMainsPowerDevice*>(m_hwdevices->findByUniqueID(*udis["acadapter"])); - if (mdevice) { - _state = mdevice->online(); - if (_state != acadapter) { - acadapter = _state; - update_info_ac_changed = true; - emit ACStatus( acadapter ); - } else { - update_info_ac_changed = false; - } - } - else { - // we use true as default e.g. for workstations - acadapter = true; - } - } - - kdDebugFuncOut(trace); +void HardwareInfo::checkACAdapterState() +{ + kdDebugFuncIn(trace); + + if (udis["acadapter"]) + { + bool _state; + + TDEMainsPowerDevice *mdevice = dynamic_cast<TDEMainsPowerDevice*>(m_hwdevices->findByUniqueID(*udis["acadapter"])); + if (mdevice) + { + _state = mdevice->online(); + if (_state != acadapter) + { + acadapter = _state; + update_info_ac_changed = true; + emit ACStatus(acadapter); + } + else + { + update_info_ac_changed = false; + } + } + else + { + // we use true as default e.g. for workstations + acadapter = true; + } + } + + kdDebugFuncOut(trace); } /*! * The function checks the state of the Lidclose button. */ -void HardwareInfo::checkLidcloseState() { - kdDebugFuncIn(trace); - - if ( udis["lidclose"] ) { - bool _state; - - TDEEventDevice* edevice = dynamic_cast<TDEEventDevice*>(m_hwdevices->findByUniqueID(*udis["lidclose"])); - if (edevice) { - _state = (edevice->activeSwitches() & TDESwitchType::Lid); - if (_state != lidclose) { - lidclose = _state; - emit lidclosetStatus( lidclose ); - } - } else { - lidclose = false; - } - } - - kdDebugFuncOut(trace); +void HardwareInfo::checkLidcloseState() +{ + kdDebugFuncIn(trace); + + if (udis["lidclose"]) + { + bool _state; + + TDEEventDevice *edevice = dynamic_cast<TDEEventDevice*>(m_hwdevices->findByUniqueID(*udis["lidclose"])); + if (edevice) + { + _state = (edevice->activeSwitches() & TDESwitchType::Lid); + if (_state != lidclose) + { + lidclose = _state; + emit lidclosetStatus(lidclose); + } + } + else + { + lidclose = false; + } + } + + kdDebugFuncOut(trace); } /*! @@ -696,80 +817,94 @@ void HardwareInfo::checkLidcloseState() { * \param udi TQString with the UDI of the battery * \param property TQString with the changed property */ -void HardwareInfo::updateBatteryValues (TDEGenericDevice* device) { - kdDebugFuncIn(trace); - - if (device && allUDIs.contains( device->uniqueID() )) { - // find effected battery object - Battery *bat; - for (bat = BatteryList.first(); bat; bat = BatteryList.next() ) { - if (device->uniqueID().startsWith( bat->getUdi())) { - TDEBatteryDevice* bdevice = dynamic_cast<TDEBatteryDevice*>(device); - if (bdevice) { - // found a battery with udi - bat->updateProperty(bdevice); - } - } - } - } else { - kdDebug() << "UDI is empty or not in the list of monitored devices " << endl; - } - - kdDebugFuncOut(trace); - return; +void HardwareInfo::updateBatteryValues(TDEGenericDevice *device) +{ + kdDebugFuncIn(trace); + + if (device && allUDIs.contains(device->uniqueID())) + { + // find effected battery object + Battery *bat; + for (bat = BatteryList.first(); bat; bat = BatteryList.next()) + { + if (device->uniqueID().startsWith(bat->getUdi())) + { + TDEBatteryDevice *bdevice = dynamic_cast<TDEBatteryDevice*>(device); + if (bdevice) + { + // found a battery with udi + bat->updateProperty(bdevice); + } + } + } + } + else + { + kdDebug() << "UDI is empty or not in the list of monitored devices " << endl; + } + + kdDebugFuncOut(trace); + return; } /*! * This function refresh the information for the primary battery collection. */ -void HardwareInfo::updatePrimaryBatteries () { - kdDebugFuncIn(trace); - - if (!BatteryList.isEmpty()) { - if (primaryBatteries->getNumBatteries() < 1) { - setPrimaryBatteriesWarningLevel(); - primaryBatteries->refreshInfo( BatteryList ); - connect(primaryBatteries, TQ_SIGNAL(batteryChanged()), this, - TQ_SLOT(setPrimaryBatteriesChanges())); - connect(primaryBatteries, TQ_SIGNAL(batteryWarnState(int,int)), this, - TQ_SLOT(emitBatteryWARNState(int,int))); - } else { - setPrimaryBatteriesWarningLevel(); - primaryBatteries->refreshInfo( BatteryList ); - } - } else { - primaryBatteries = new BatteryCollection(BAT_PRIMARY); - } - - kdDebugFuncOut(trace); +void HardwareInfo::updatePrimaryBatteries() +{ + kdDebugFuncIn(trace); + + if (!BatteryList.isEmpty()) + { + if (primaryBatteries->getNumBatteries() < 1) + { + setPrimaryBatteriesWarningLevel(); + primaryBatteries->refreshInfo(BatteryList); + connect(primaryBatteries, TQ_SIGNAL(batteryChanged()), this, TQ_SLOT(setPrimaryBatteriesChanges())); + connect(primaryBatteries, TQ_SIGNAL(batteryWarnState(int,int)), this, TQ_SLOT(emitBatteryWARNState(int,int))); + } + else + { + setPrimaryBatteriesWarningLevel(); + primaryBatteries->refreshInfo(BatteryList); + } + } + else + { + primaryBatteries = new BatteryCollection(BAT_PRIMARY); + } + + kdDebugFuncOut(trace); } /*! * This function set the change status for the primary battery collection */ -void HardwareInfo::setPrimaryBatteriesChanges () { - kdDebugFuncIn(trace); +void HardwareInfo::setPrimaryBatteriesChanges() +{ + kdDebugFuncIn(trace); - update_info_primBattery_changed = true; - emit primaryBatteryChanged(); + update_info_primBattery_changed = true; + emit primaryBatteryChanged(); - kdDebugFuncOut(trace); + kdDebugFuncOut(trace); } /*! * This slot emit a signal if a warning state of a battery reached */ -void HardwareInfo::emitBatteryWARNState (int type, int state) { - kdDebugFuncIn(trace); +void HardwareInfo::emitBatteryWARNState(int type, int state) +{ + kdDebugFuncIn(trace); - if (type == BAT_PRIMARY) - emit primaryBatteryChanged(); - else - emit generalDataChanged(); + if (type == BAT_PRIMARY) + emit primaryBatteryChanged(); + else + emit generalDataChanged(); - emit batteryWARNState(type, state); + emit batteryWARNState(type, state); - kdDebugFuncOut(trace); + kdDebugFuncOut(trace); } // --> init HW information section -- END <--- @@ -782,122 +917,155 @@ void HardwareInfo::emitBatteryWARNState (int type, int state) { * \retval true if successful * \retval false else, if a error occurs */ -bool HardwareInfo::suspend( suspend_type suspend ) { - kdDebugFuncIn(trace); - - calledSuspend = TQTime(); - - TDERootSystemDevice* rdevice = m_hwdevices->rootSystemDevice(); - - if (rdevice) { - switch (suspend) { - case SUSPEND2DISK: - if (suspend_states.suspend2disk && (suspend_states.suspend2disk_allowed != 0)) { - if (rdevice->setPowerState(TDESystemPowerState::Hibernate)) { - calledSuspend.start(); - handleResumeSignal(0); - return true; - } else { - handleResumeSignal(-1); - return false; - } - } else { - if ( !suspend_states.suspend2disk ) - kdDebug() << "The machine does not support hibernation." << endl; - else - kdWarning() << "Policy forbid user to trigger hibernation" << endl; - - return false; - } - break; - - case SUSPEND_HYBRID: - if (suspend_states.suspend_hybrid && (suspend_states.suspend_hybrid_allowed != 0)) { - if (rdevice->setPowerState(TDESystemPowerState::HybridSuspend)) { - calledSuspend.start(); - handleResumeSignal(0); - return true; - } else { - handleResumeSignal(-1); - return false; - } - } else { - if ( !suspend_states.suspend_hybrid ) - kdDebug() << "The machine does not support hybrid suspension." << endl; - else - kdWarning() << "Policy forbid user to trigger hybrid suspension" << endl; - - return false; - } - break; - - case SUSPEND2RAM: - if (suspend_states.suspend2ram && (suspend_states.suspend2ram_allowed != 0)) { - if (rdevice->setPowerState(TDESystemPowerState::Suspend)) { - calledSuspend.start(); - handleResumeSignal(0); - return true; - } else { - handleResumeSignal(-1); - return false; - } - } else { - if ( !suspend_states.suspend2ram ) - kdDebug() << "The machine does not support Suspend mode." << endl; - else - kdWarning() << "Policy forbid user to trigger Suspend mode" << endl; - - return false; - } - break; - - case FREEZE: - if (suspend_states.freeze && (suspend_states.freeze_allowed != 0)) { - if (rdevice->setPowerState(TDESystemPowerState::Freeze)) { - calledSuspend.start(); - handleResumeSignal(0); - return true; - } else { - handleResumeSignal(-1); - return false; - } - } else { - if ( !suspend_states.freeze ) - kdDebug() << "The machine does not support freeze." << endl; - else - kdWarning() << "Policy forbid user to trigger freeze" << endl; - - return false; - } - break; - - case STANDBY: - if (suspend_states.standby && (suspend_states.standby_allowed != 0)) { - if (rdevice->setPowerState(TDESystemPowerState::Standby)) { - calledSuspend.start(); - handleResumeSignal(0); - return true; - } else { - handleResumeSignal(-1); - return false; - } - } else { - if ( !suspend_states.standby ) - kdDebug() << "The machine does not support standby." << endl; - else - kdWarning() << "Policy forbid user to trigger standby" << endl; - - return false; - } - break; - - default: - return false; - } - } - - kdDebugFuncOut(trace); - return false; +bool HardwareInfo::suspend(suspend_type suspend) +{ + kdDebugFuncIn(trace); + + calledSuspend = TQTime(); + + TDERootSystemDevice *rdevice = m_hwdevices->rootSystemDevice(); + + if (rdevice) + { + switch (suspend) + { + case SUSPEND2DISK: + if (suspend_states.suspend2disk && (suspend_states.suspend2disk_allowed != 0)) + { + if (rdevice->setPowerState(TDESystemPowerState::Hibernate)) + { + calledSuspend.start(); + handleResumeSignal(0); + return true; + } + else + { + handleResumeSignal(-1); + return false; + } + } + else + { + if (!suspend_states.suspend2disk) + kdDebug() << "The machine does not support hibernation." << endl; + else + kdWarning() << "Policy forbid user to trigger hibernation" << endl; + + return false; + } + break; + + case SUSPEND_HYBRID: + if (suspend_states.suspend_hybrid && (suspend_states.suspend_hybrid_allowed != 0)) + { + if (rdevice->setPowerState(TDESystemPowerState::HybridSuspend)) + { + calledSuspend.start(); + handleResumeSignal(0); + return true; + } + else + { + handleResumeSignal(-1); + return false; + } + } + else + { + if (!suspend_states.suspend_hybrid) + kdDebug() << "The machine does not support hybrid suspension." << endl; + else + kdWarning() << "Policy forbid user to trigger hybrid suspension" << endl; + + return false; + } + break; + + case SUSPEND2RAM: + if (suspend_states.suspend2ram && (suspend_states.suspend2ram_allowed != 0)) + { + if (rdevice->setPowerState(TDESystemPowerState::Suspend)) + { + calledSuspend.start(); + handleResumeSignal(0); + return true; + } + else + { + handleResumeSignal(-1); + return false; + } + } + else + { + if (!suspend_states.suspend2ram) + kdDebug() << "The machine does not support Suspend mode." << endl; + else + kdWarning() << "Policy forbid user to trigger Suspend mode" << endl; + + return false; + } + break; + + case FREEZE: + if (suspend_states.freeze && (suspend_states.freeze_allowed != 0)) + { + if (rdevice->setPowerState(TDESystemPowerState::Freeze)) + { + calledSuspend.start(); + handleResumeSignal(0); + return true; + } + else + { + handleResumeSignal(-1); + return false; + } + } + else + { + if (!suspend_states.freeze) + kdDebug() << "The machine does not support freeze." << endl; + else + kdWarning() << "Policy forbid user to trigger freeze" << endl; + + return false; + } + break; + + case STANDBY: + if (suspend_states.standby && (suspend_states.standby_allowed != 0)) + { + if (rdevice->setPowerState(TDESystemPowerState::Standby)) + { + calledSuspend.start(); + handleResumeSignal(0); + return true; + } + else + { + handleResumeSignal(-1); + return false; + } + } + else + { + if (!suspend_states.standby) + kdDebug() << "The machine does not support standby." << endl; + else + kdWarning() << "Policy forbid user to trigger standby" << endl; + + return false; + } + break; + + default: + return false; + } + } + + kdDebugFuncOut(trace); + return false; } /*! @@ -909,47 +1077,58 @@ bool HardwareInfo::suspend( suspend_type suspend ) { */ bool HardwareInfo::setBrightnessLevel(int level) { - if (trace) kdDebug() << funcinfo << "IN: " << "level: " << level << endl; - - bool retval = false; - int maxBrightness = getMaxBrightnessLevel(); - - // Use the first backlight in the list - TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::Backlight); - TDEGenericDevice *hwdevice; - hwdevice = hwlist.first(); - TDEBacklightDevice *backlightdevice = static_cast<TDEBacklightDevice*>(hwdevice); - - if (backlightdevice) { - if (!brightness) { - checkBrightness(); - } - - // Make sure level is within valid range - if (level < 0) { - level = 0; - } - else if (level > maxBrightness) { - level = maxBrightness; - } - - if (!brightness) { - kdError() << "Change brightness not supported " << endl; - } else { - if (currentBrightnessLevel == level) { - kdDebug() << "Brightness level not changed, requested level == current level" << endl; - retval = true; - } else { - backlightdevice->setRawBrightness(level); - retval = true; - } - } - } - - // check for actual brightness level to be sure everything was set correct - checkCurrentBrightness(); - kdDebugFuncOut(trace); - return retval; + if (trace) + kdDebug() << funcinfo << "IN: " << "level: " << level << endl; + + bool retval = false; + int maxBrightness = getMaxBrightnessLevel(); + + // Use the first backlight in the list + TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::Backlight); + TDEGenericDevice *hwdevice; + hwdevice = hwlist.first(); + TDEBacklightDevice *backlightdevice = static_cast<TDEBacklightDevice*>(hwdevice); + + if (backlightdevice) + { + if (!brightness) + { + checkBrightness(); + } + + // Make sure level is within valid range + if (level < 0) + { + level = 0; + } + else if (level > maxBrightness) + { + level = maxBrightness; + } + + if (!brightness) + { + kdError() << "Change brightness not supported " << endl; + } + else + { + if (currentBrightnessLevel == level) + { + kdDebug() << "Brightness level not changed, requested level == current level" << endl; + retval = true; + } + else + { + backlightdevice->setRawBrightness(level); + retval = true; + } + } + } + + // check for actual brightness level to be sure everything was set correct + checkCurrentBrightness(); + kdDebugFuncOut(trace); + return retval; } /*! @@ -961,49 +1140,58 @@ bool HardwareInfo::setBrightnessLevel(int level) */ bool HardwareInfo::setBrightnessPercentage(int percent) { - if (trace) kdDebug() << funcinfo << "IN: " << " percent: " << percent << endl; - - bool retval = false; - - // Use the first backlight in the list - TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::Backlight); - TDEGenericDevice *hwdevice; - hwdevice = hwlist.first(); - TDEBacklightDevice *backlightdevice = static_cast<TDEBacklightDevice*>(hwdevice); - - if (backlightdevice) { - if (!brightness) { - checkBrightness(); - } - - if (!brightness) { - kdError() << "Change brightness not supported " << endl; - } - else { - // Make sure percentage is within valid range - if (percent < 0) { - percent = 0; - } - else if (percent > 100) { - percent = 100; - } - - int level = (int)round(getMaxBrightnessLevel() * percent / 100.0); - if (currentBrightnessLevel == level) { - kdDebug() << "Brightness level not changed, requested level == current level" << endl; - retval = true; - } - else { - backlightdevice->setRawBrightness(level); - retval = true; - } - } - } - - // check for actual brightness level to be sure everything was set correct - checkCurrentBrightness(); - kdDebugFuncOut(trace); - return retval; + if (trace) + kdDebug() << funcinfo << "IN: " << " percent: " << percent << endl; + + bool retval = false; + + // Use the first backlight in the list + TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::Backlight); + TDEGenericDevice *hwdevice; + hwdevice = hwlist.first(); + TDEBacklightDevice *backlightdevice = static_cast<TDEBacklightDevice*>(hwdevice); + + if (backlightdevice) + { + if (!brightness) + { + checkBrightness(); + } + + if (!brightness) + { + kdError() << "Change brightness not supported " << endl; + } + else + { + // Make sure percentage is within valid range + if (percent < 0) + { + percent = 0; + } + else if (percent > 100) + { + percent = 100; + } + + int level = (int) round(getMaxBrightnessLevel() * percent / 100.0); + if (currentBrightnessLevel == level) + { + kdDebug() << "Brightness level not changed, requested level == current level" << endl; + retval = true; + } + else + { + backlightdevice->setRawBrightness(level); + retval = true; + } + } + } + + // check for actual brightness level to be sure everything was set correct + checkCurrentBrightness(); + kdDebugFuncOut(trace); + return retval; } /*! @@ -1014,90 +1202,110 @@ bool HardwareInfo::setBrightnessPercentage(int percent) * \retval true if successful * \retval false else, if a error occurs */ -bool HardwareInfo::setCPUFreq ( cpufreq_type cpufreq, int limit ) { - if (trace) kdDebug() << funcinfo << "IN: " << "cpufreq_type: " << cpufreq << " limit: " << limit << endl; - - if (!cpuFreq) { - kdError() << "This machine does not support change the CPU Freq via TDE hardware library" << endl; - return false; - } - - if (cpuFreqAllowed == 0) { - kdError() << "Could not set CPU Freq - insufficient privileges." << endl; - return false; - } - - TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::CPU); - - if (hwlist.count() > 0) { - TQStringList dynamic; - - if (checkCurrentCPUFreqPolicy() == cpufreq) { - if (cpufreq == DYNAMIC && !cpuFreqGovernor.startsWith("ondemand")) { - kdDebug() << "CPU Freq Policy is already DYNAMIC, but not governor is currently " - << "not 'ondemand'. Try to set ondemand governor." << endl; - } else { - kdDebug() << "Didn't change Policy, was already set." << endl; - return true; - } - } - - switch (cpufreq) { - case PERFORMANCE: - if (!setCPUFreqGovernor("performance")) { - kdError() << "Could not set CPU Freq to performance policy" << endl; - return false; - } - break; - case DYNAMIC: - dynamic << "ondemand" << "userspace" << "conservative"; - - for (TQStringList::Iterator it = dynamic.begin(); it != dynamic.end(); it++){ - kdDebug() << "Try to set dynamic CPUFreq to: " << *it << endl; - - if (setCPUFreqGovernor((*it).latin1())) { - kdDebug() << "Set dynamic successful to: " << *it << endl; - break; - } - } - - // Set performance limits on all CPUs - TDEGenericDevice *hwdevice; - TDECPUDevice *cpudevice; - for ( hwdevice = hwlist.first(); hwdevice; hwdevice = hwlist.next() ) { - cpudevice = static_cast<TDECPUDevice*>(hwdevice); - // set dynamic performance limit - // scale the desired limit so that when limit==0 the minFrequency() is used, and when limit==100 the maxFrequency() is used - double cpuLimit = cpudevice->maxFrequency() - cpudevice->minFrequency(); - cpuLimit = (cpuLimit * limit) / 100.0; - cpuLimit = cpudevice->maxFrequency() + cpuLimit; - cpudevice->setMaximumScalingFrequency(cpuLimit); - - } - - break; - case POWERSAVE: - if (!setCPUFreqGovernor("powersave")) { - kdError() << "Could not set CPU Freq to powersave policy" << endl; - return false; - } - break; - default: - kdWarning() << "Unknown cpufreq_type: " << cpufreq << endl; - return false; - } - - // check if the policy was really set (and emit signal) - if (checkCurrentCPUFreqPolicy() == cpufreq) { +bool HardwareInfo::setCPUFreq(cpufreq_type cpufreq, int limit) +{ + if (trace) + kdDebug() << funcinfo << "IN: " << "cpufreq_type: " << cpufreq << " limit: " << limit << endl; + + if (!cpuFreq) + { + kdError() << "This machine does not support change the CPU Freq via TDE hardware library" << endl; + return false; + } + + if (cpuFreqAllowed == 0) + { + kdError() << "Could not set CPU Freq - insufficient privileges." << endl; + return false; + } + + TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::CPU); + + if (hwlist.count() > 0) + { + TQStringList dynamic; + + if (checkCurrentCPUFreqPolicy() == cpufreq) + { + if (cpufreq == DYNAMIC && !cpuFreqGovernor.startsWith("ondemand")) + { + kdDebug() << "CPU Freq Policy is already DYNAMIC, but not governor is currently " << "not 'ondemand'. Try to set ondemand governor." << endl; + } + else + { + kdDebug() << "Didn't change Policy, was already set." << endl; + return true; + } + } + + switch (cpufreq) + { + case PERFORMANCE: + if (!setCPUFreqGovernor("performance")) + { + kdError() << "Could not set CPU Freq to performance policy" << endl; + return false; + } + break; + case DYNAMIC: + dynamic << "ondemand" << "userspace" << "conservative"; + + for (TQStringList::Iterator it = dynamic.begin(); + it != dynamic.end(); it++) + { + kdDebug() << "Try to set dynamic CPUFreq to: " << *it << endl; + + if (setCPUFreqGovernor((*it).latin1())) + { + kdDebug() << "Set dynamic successful to: " << *it << endl; + break; + } + } + + // Set performance limits on all CPUs + TDEGenericDevice *hwdevice; + TDECPUDevice *cpudevice; + for (hwdevice = hwlist.first(); hwdevice; hwdevice = hwlist.next()) + { + cpudevice = static_cast<TDECPUDevice*>(hwdevice); + // set dynamic performance limit + // scale the desired limit so that when limit==0 the minFrequency() is used, and when limit==100 the maxFrequency() is used + double cpuLimit = cpudevice->maxFrequency() - cpudevice->minFrequency(); + cpuLimit = (cpuLimit * limit) / 100.0; + cpuLimit = cpudevice->maxFrequency() + cpuLimit; + cpudevice->setMaximumScalingFrequency(cpuLimit); + + } + + break; + case POWERSAVE: + if (!setCPUFreqGovernor("powersave")) + { + kdError() << "Could not set CPU Freq to powersave policy" << endl; + return false; + } + break; + default: + kdWarning() << "Unknown cpufreq_type: " << cpufreq << endl; + return false; + } + + // check if the policy was really set (and emit signal) + if (checkCurrentCPUFreqPolicy() == cpufreq) + { // update_info_cpufreq_policy_changed = true; // emit currentCPUFreqPolicyChanged(); - return true; - } else { - return false; - } - } else { - return false; - } + return true; + } + else + { + return false; + } + } + else + { + return false; + } } /*! @@ -1107,28 +1315,29 @@ bool HardwareInfo::setCPUFreq ( cpufreq_type cpufreq, int limit ) { * \retval true if successful * \retval false else, if a error occurs */ -bool HardwareInfo::setCPUFreqGovernor( const char *governor ) { - kdDebugFuncIn(trace); - - bool ret = true; - - TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::CPU); - TDEGenericDevice *hwdevice; - TDECPUDevice *cpudevice; - // Set governor on all CPUs - for ( hwdevice = hwlist.first(); hwdevice; hwdevice = hwlist.next() ) { - cpudevice = static_cast<TDECPUDevice*>(hwdevice); - cpudevice->setGovernor(governor); - if (cpudevice->governor() != governor) { - ret = false; - } - } - - kdDebugFuncOut(trace); - return ret; -} - +bool HardwareInfo::setCPUFreqGovernor(const char *governor) +{ + kdDebugFuncIn(trace); + + bool ret = true; + + TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::CPU); + TDEGenericDevice *hwdevice; + TDECPUDevice *cpudevice; + // Set governor on all CPUs + for (hwdevice = hwlist.first(); hwdevice; hwdevice = hwlist.next()) + { + cpudevice = static_cast<TDECPUDevice*>(hwdevice); + cpudevice->setGovernor(governor); + if (cpudevice->governor() != governor) + { + ret = false; + } + } + kdDebugFuncOut(trace); + return ret; +} // --> TDE hardware library method call (trigger actions) section -- END <--- @@ -1139,41 +1348,54 @@ bool HardwareInfo::setCPUFreqGovernor( const char *governor ) { /*! * Function to emit the signal for the Power button. */ -void HardwareInfo::emitPowerButtonPressed() { - if (sessionIsActive) { - emit powerButtonPressed(); - } else { - kdWarning() << "Session is not active, don't react on power button event!" << endl; - } +void HardwareInfo::emitPowerButtonPressed() +{ + if (sessionIsActive) + { + emit powerButtonPressed(); + } + else + { + kdWarning() << "Session is not active, don't react on power button event!" << endl; + } } /*! * Function to emit the signal for the Suspend button. */ -void HardwareInfo::emitSuspendButtonPressed() { - if (sessionIsActive) { - emit sleepButtonPressed(); - } else { - kdWarning() << "Session is not active, don't react on sleep button event!" << endl; - } +void HardwareInfo::emitSuspendButtonPressed() +{ + if (sessionIsActive) + { + emit sleepButtonPressed(); + } + else + { + kdWarning() << "Session is not active, don't react on sleep button event!" << endl; + } } /*! * Function to emit the signal for the s2disk button. */ -void HardwareInfo::emitS2diskButtonPressed() { - if (sessionIsActive) { - emit s2diskButtonPressed(); - } else { - kdWarning() << "Session is not active, don't react on suspend2disk button event!" << endl; - } +void HardwareInfo::emitS2diskButtonPressed() +{ + if (sessionIsActive) + { + emit s2diskButtonPressed(); + } + else + { + kdWarning() << "Session is not active, don't react on suspend2disk button event!" << endl; + } } /*! * Function to emit the signal about changes in the session state */ -void HardwareInfo::emitSessionActiveState() { - emit desktopSessionIsActive(sessionIsActive); +void HardwareInfo::emitSessionActiveState() +{ + emit desktopSessionIsActive(sessionIsActive); } /*! @@ -1183,21 +1405,22 @@ void HardwareInfo::emitSessionActiveState() { * \retval true if could get set * \retval false else */ -bool HardwareInfo::setBrightnessUp(int percentageStep) { - kdDebugFuncIn(trace); +bool HardwareInfo::setBrightnessUp(int percentageStep) +{ + kdDebugFuncIn(trace); - bool retval = false; + bool retval = false; - checkCurrentBrightness(); + checkCurrentBrightness(); - if (supportBrightness() && percentageStep > 0) - { - int currentPerc = (int)round(100.0 * getCurrentBrightnessLevel() / getMaxBrightnessLevel()); - retval = setBrightnessPercentage(currentPerc + percentageStep); - } + if (supportBrightness() && percentageStep > 0) + { + int currentPerc = (int) round(100.0 * getCurrentBrightnessLevel() / getMaxBrightnessLevel()); + retval = setBrightnessPercentage(currentPerc + percentageStep); + } - kdDebugFuncOut(trace); - return retval; + kdDebugFuncOut(trace); + return retval; } /*! @@ -1207,20 +1430,22 @@ bool HardwareInfo::setBrightnessUp(int percentageStep) { * \retval true if could get set * \retval false else */ -bool HardwareInfo::setBrightnessDown(int percentageStep) { - kdDebugFuncIn(trace); +bool HardwareInfo::setBrightnessDown(int percentageStep) +{ + kdDebugFuncIn(trace); - bool retval = false; + bool retval = false; - checkCurrentBrightness(); + checkCurrentBrightness(); - if (supportBrightness() && percentageStep > 0) { - int currentPerc = (int)round(100.0 * getCurrentBrightnessLevel() / getMaxBrightnessLevel()); - retval = setBrightnessPercentage(currentPerc - percentageStep); - } + if (supportBrightness() && percentageStep > 0) + { + int currentPerc = (int) round(100.0 * getCurrentBrightnessLevel() / getMaxBrightnessLevel()); + retval = setBrightnessPercentage(currentPerc - percentageStep); + } - kdDebugFuncOut(trace); - return retval; + kdDebugFuncOut(trace); + return retval; } // --> private helper slots to forward/handle events -- END <-- @@ -1233,8 +1458,9 @@ bool HardwareInfo::setBrightnessDown(int percentageStep) { * \retval true if adapter is present/connected or unknown * \retval false if not */ -bool HardwareInfo::getAcAdapter() const { - return acadapter; +bool HardwareInfo::getAcAdapter() const +{ + return acadapter; } /*! @@ -1243,38 +1469,42 @@ bool HardwareInfo::getAcAdapter() const { * \retval true if the lid is closed * \retval false if the lid is opend */ -bool HardwareInfo::getLidclose() const { - return lidclose; +bool HardwareInfo::getLidclose() const +{ + return lidclose; } /*! * The function return the maximal available brightness level * \return Integer with max level or -1 if not supported */ -int HardwareInfo::getMaxBrightnessLevel() const { - if (brightness) - return availableBrightnessLevels - 1; - else - return -1; +int HardwareInfo::getMaxBrightnessLevel() const +{ + if (brightness) + return availableBrightnessLevels - 1; + else + return -1; } /*! * The function return the current brightness level * \return Integer with max level or -1 if not supported or unkown */ -int HardwareInfo::getCurrentBrightnessLevel() const { - if (brightness) - return currentBrightnessLevel; - else - return -1; +int HardwareInfo::getCurrentBrightnessLevel() const +{ + if (brightness) + return currentBrightnessLevel; + else + return -1; } /*! * The function return the current set CPU Frequency Policy * \return Integer with currently set Policy or -1 if not supported or unkown */ -int HardwareInfo::getCurrentCPUFreqPolicy() const { - return currentCPUFreqPolicy; +int HardwareInfo::getCurrentCPUFreqPolicy() const +{ + return currentCPUFreqPolicy; } /*! @@ -1283,35 +1513,38 @@ int HardwareInfo::getCurrentCPUFreqPolicy() const { * \return struct with information from \ref suspend_states * TODO: check if we maybe should replace this by more different functions */ -SuspendStates HardwareInfo::getSuspendSupport() const { - return suspend_states; +SuspendStates HardwareInfo::getSuspendSupport() const +{ + return suspend_states; } /*! * The function return a pointer to the battery collection of primary batteries. * \return BatteryCollection with type == PRIMARY */ -BatteryCollection* HardwareInfo::getPrimaryBatteries() const { - return primaryBatteries; +BatteryCollection* HardwareInfo::getPrimaryBatteries() const +{ + return primaryBatteries; } /*! * The function return all batteries * \return TQPtrList<Battery> */ -TQPtrList<Battery> HardwareInfo::getAllBatteries() const { - return BatteryList; +TQPtrList<Battery> HardwareInfo::getAllBatteries() const +{ + return BatteryList; } - /*! * The function return the status of \ref laptop. * \return boolean with info if machine is a laptop * \retval true if a laptop * \retval false else/if not a laptop */ -bool HardwareInfo::isLaptop() const { - return laptop; +bool HardwareInfo::isLaptop() const +{ + return laptop; } /*! @@ -1321,10 +1554,11 @@ bool HardwareInfo::isLaptop() const { * \retval true if connected * \retval false if not connected */ -bool HardwareInfo::isOnline() const { - // FIXME - // Is there ANY case where the TDE hardware library would not function? - return true; +bool HardwareInfo::isOnline() const +{ + // FIXME + // Is there ANY case where the TDE hardware library would not function? + return true; } /*! @@ -1333,8 +1567,9 @@ bool HardwareInfo::isOnline() const { * \retval true if support ACPI * \retval false else */ -bool HardwareInfo::hasACPI() const { - return has_ACPI; +bool HardwareInfo::hasACPI() const +{ + return has_ACPI; } /*! @@ -1343,8 +1578,9 @@ bool HardwareInfo::hasACPI() const { * \retval true if support APM * \retval false else */ -bool HardwareInfo::hasAPM() const { - return has_APM; +bool HardwareInfo::hasAPM() const +{ + return has_APM; } /*! @@ -1353,8 +1589,9 @@ bool HardwareInfo::hasAPM() const { * \retval true if support PMU * \retval false else */ -bool HardwareInfo::hasPMU() const { - return has_PMU; +bool HardwareInfo::hasPMU() const +{ + return has_PMU; } /*! @@ -1363,8 +1600,9 @@ bool HardwareInfo::hasPMU() const { * \retval true if support brightness changes * \retval false else */ -bool HardwareInfo::supportBrightness() const { - return brightness; +bool HardwareInfo::supportBrightness() const +{ + return brightness; } /*! @@ -1373,8 +1611,9 @@ bool HardwareInfo::supportBrightness() const { * \retval true if support brightness changes * \retval false else */ -bool HardwareInfo::supportCPUFreq() const { - return cpuFreq; +bool HardwareInfo::supportCPUFreq() const +{ + return cpuFreq; } /*! @@ -1383,8 +1622,9 @@ bool HardwareInfo::supportCPUFreq() const { * \retval true if the current session is active * \retval false else */ -bool HardwareInfo::currentSessionIsActive() const { - return sessionIsActive; +bool HardwareInfo::currentSessionIsActive() const +{ + return sessionIsActive; } /*! @@ -1395,15 +1635,16 @@ bool HardwareInfo::currentSessionIsActive() const { * \retval 1 not allowed * \retval -1 unknown */ -int HardwareInfo::isCpuFreqAllowed () { - // Use the first CPU in the list; permissions are probably the same across all CPUs - TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::CPU); - TDEGenericDevice *hwdevice; - hwdevice = hwlist.first(); - TDECPUDevice *cpudevice = static_cast<TDECPUDevice*>(hwdevice); - - cpuFreqAllowed = cpudevice->canSetGovernor(); - return cpuFreqAllowed; +int HardwareInfo::isCpuFreqAllowed() +{ + // Use the first CPU in the list; permissions are probably the same across all CPUs + TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::CPU); + TDEGenericDevice *hwdevice; + hwdevice = hwlist.first(); + TDECPUDevice *cpudevice = static_cast<TDECPUDevice*>(hwdevice); + + cpuFreqAllowed = cpudevice->canSetGovernor(); + return cpuFreqAllowed; } // --> get private members section -- END <--- |