From e7708ec743e1c504cbae2ab523858589caeae62f Mon Sep 17 00:00:00 2001 From: Golubev Alexander Date: Sat, 27 Jul 2013 06:39:01 +0400 Subject: complete tdehardwaredevices split --- tdecore/tdehw/tdehardwaredevices.cpp | 920 +---------------------------------- 1 file changed, 27 insertions(+), 893 deletions(-) (limited to 'tdecore/tdehw/tdehardwaredevices.cpp') diff --git a/tdecore/tdehw/tdehardwaredevices.cpp b/tdecore/tdehw/tdehardwaredevices.cpp index 3cf62e8af..08646d17d 100644 --- a/tdecore/tdehw/tdehardwaredevices.cpp +++ b/tdecore/tdehw/tdehardwaredevices.cpp @@ -16,60 +16,56 @@ Boston, MA 02110-1301, USA. */ -#include +#include "tdehardwaredevices.h" #include #include -#include +#include #include +#include -#include -#include #include -#include -#include #include +#include +#include + #include #include #include +#include +#include #include -// Backlight devices -#include - -// Input devices -#include - // Network devices #include #include -#include -#include -#include -#include #include -// Network connection manager -#include "tdenetworkconnections.h" +// Backlight devices +#include -// Compile-time configuration -#include "config.h" +// Input devices +#include -#ifdef WITH_NETWORK_MANAGER_BACKEND - #include "networkbackends/network-manager/network-manager.h" -#endif // WITH_NETWORK_MANAGER_BACKEND +#include "kiconloader.h" + +#include "tdegenericdevice.h" +#include "tdestoragedevice.h" +#include "tdecpudevice.h" +#include "tdebatterydevice.h" +#include "tdemainspowerdevice.h" +#include "tdenetworkdevice.h" +#include "tdebacklightdevice.h" +#include "tdemonitordevice.h" +#include "tdesensordevice.h" +#include "tderootsystemdevice.h" +#include "tdeeventdevice.h" +#include "tdeinputdevice.h" -// uPower -#if defined(WITH_UPOWER) || defined(WITH_CONSOLEKIT) - #include - #include - #include - #include - #include -#endif // defined(WITH_UPOWER) +#include "config.h" // BEGIN BLOCK // Copied from include/linux/genhd.h @@ -100,868 +96,6 @@ unsigned int reverse_bits(register unsigned int x) #define BIT_IS_SET(bits, n) (bits[n >> 3] & (1 << (n & 0x7))) -TDESensorCluster::TDESensorCluster() { - label = TQString::null; - current = -1; - minimum = -1; - maximum = -1; - warning = -1; - critical = -1; -} - -TDESensorDevice::TDESensorDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) { -} - -TDESensorDevice::~TDESensorDevice() { -} - -TDESensorClusterMap TDESensorDevice::values() { - return m_sensorValues; -} - -void TDESensorDevice::internalSetValues(TDESensorClusterMap cl) { - m_sensorValues = cl; -} - -TDERootSystemDevice::TDERootSystemDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) { - m_hibernationSpace = -1; -} - -TDERootSystemDevice::~TDERootSystemDevice() { -} - -TDESystemFormFactor::TDESystemFormFactor TDERootSystemDevice::formFactor() { - return m_formFactor; -} - -void TDERootSystemDevice::internalSetFormFactor(TDESystemFormFactor::TDESystemFormFactor ff) { - m_formFactor = ff; -} - -TDESystemPowerStateList TDERootSystemDevice::powerStates() { - return m_powerStates; -} - -void TDERootSystemDevice::internalSetPowerStates(TDESystemPowerStateList ps) { - m_powerStates = ps; -} - -TDESystemHibernationMethodList TDERootSystemDevice::hibernationMethods() { - return m_hibernationMethods; -} - -void TDERootSystemDevice::internalSetHibernationMethods(TDESystemHibernationMethodList hm) { - m_hibernationMethods = hm; -} - -TDESystemHibernationMethod::TDESystemHibernationMethod TDERootSystemDevice::hibernationMethod() { - return m_hibernationMethod; -} - -void TDERootSystemDevice::internalSetHibernationMethod(TDESystemHibernationMethod::TDESystemHibernationMethod hm) { - m_hibernationMethod = hm; -} - -unsigned long TDERootSystemDevice::diskSpaceNeededForHibernation() { - return m_hibernationSpace; -} - -void TDERootSystemDevice::internalSetDiskSpaceNeededForHibernation(unsigned long sz) { - m_hibernationSpace = sz; -} - -bool TDERootSystemDevice::canSetHibernationMethod() { - TQString hibernationnode = "/sys/power/disk"; - int rval = access (hibernationnode.ascii(), W_OK); - if (rval == 0) { - return TRUE; - } - else { - return FALSE; - } -} - -bool TDERootSystemDevice::canStandby() { - TQString statenode = "/sys/power/state"; - int rval = access (statenode.ascii(), W_OK); - if (rval == 0) { - if (powerStates().contains(TDESystemPowerState::Standby)) { - return TRUE; - } - else { - return FALSE; - } - } - else { - return FALSE; - } -} - -bool TDERootSystemDevice::canSuspend() { - TQString statenode = "/sys/power/state"; - int rval = access (statenode.ascii(), W_OK); - if (rval == 0) { - if (powerStates().contains(TDESystemPowerState::Suspend)) { - return TRUE; - } - else { - return FALSE; - } - } - else { -#ifdef WITH_UPOWER - TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus); - if (dbusConn.isConnected()) { - TQT_DBusProxy upowerProperties("org.freedesktop.UPower", "/org/freedesktop/UPower", "org.freedesktop.DBus.Properties", dbusConn); - if (upowerProperties.canSend()) { - // can suspend? - TQValueList params; - params << TQT_DBusData::fromString(upowerProperties.interface()) << TQT_DBusData::fromString("CanSuspend"); - TQT_DBusMessage reply = upowerProperties.sendWithReply("Get", params); - if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) { - return reply[0].toVariant().value.toBool(); - } - else { - return FALSE; - } - } - else { - return FALSE; - } - } - else { - return FALSE; - } -#else // WITH_UPOWER - return FALSE; -#endif// WITH_UPOWER - } -} - -bool TDERootSystemDevice::canHibernate() { - TQString statenode = "/sys/power/state"; - int rval = access (statenode.ascii(), W_OK); - if (rval == 0) { - if (powerStates().contains(TDESystemPowerState::Hibernate)) { - return TRUE; - } - else { - return FALSE; - } - } - else { -#ifdef WITH_UPOWER - TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus); - if (dbusConn.isConnected()) { - TQT_DBusProxy upowerProperties("org.freedesktop.UPower", "/org/freedesktop/UPower", "org.freedesktop.DBus.Properties", dbusConn); - if (upowerProperties.canSend()) { - // can hibernate? - TQValueList params; - params << TQT_DBusData::fromString(upowerProperties.interface()) << TQT_DBusData::fromString("CanHibernate"); - TQT_DBusMessage reply = upowerProperties.sendWithReply("Get", params); - if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) { - return reply[0].toVariant().value.toBool(); - } - else { - return FALSE; - } - } - else { - return FALSE; - } - } - else { - return FALSE; - } -#else // WITH_UPOWER - return FALSE; -#endif// WITH_UPOWER - } -} - -bool TDERootSystemDevice::canPowerOff() { - TDEConfig *config = TDEGlobal::config(); - config->reparseConfiguration(); // config may have changed in the KControl module - - config->setGroup("General" ); - bool maysd = false; -#ifdef WITH_CONSOLEKIT - if (config->readBoolEntry( "offerShutdown", true )) { - TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus); - if (dbusConn.isConnected()) { - TQT_DBusProxy consoleKitManager("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", dbusConn); - if (consoleKitManager.canSend()) { - // can power off? - TQValueList params; - TQT_DBusMessage reply = consoleKitManager.sendWithReply("CanStop", params); - if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) { - maysd = reply[0].toBool(); - } - else { - maysd = false; - } - } - else { - maysd = false; - } - } - else { - maysd = false; - } - } -#else // WITH_CONSOLEKIT - // FIXME - // Can we power down this system? - // This should probably be checked via DCOP and therefore interface with KDM - if (config->readBoolEntry( "offerShutdown", true )/* && DM().canShutdown()*/) { // FIXME - maysd = true; - } -#endif // WITH_CONSOLEKIT - - return maysd; -} - -bool TDERootSystemDevice::canReboot() { - TDEConfig *config = TDEGlobal::config(); - config->reparseConfiguration(); // config may have changed in the KControl module - - config->setGroup("General" ); - bool mayrb = false; -#ifdef WITH_CONSOLEKIT - if (config->readBoolEntry( "offerShutdown", true )) { - TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus); - if (dbusConn.isConnected()) { - TQT_DBusProxy consoleKitManager("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", dbusConn); - if (consoleKitManager.canSend()) { - // can reboot? - TQValueList params; - TQT_DBusMessage reply = consoleKitManager.sendWithReply("CanRestart", params); - if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) { - mayrb = reply[0].toBool(); - } - else { - mayrb = false; - } - } - else { - mayrb = false; - } - } - else { - mayrb = false; - } - } -#else // WITH_CONSOLEKIT - // FIXME - // Can we power down this system? - // This should probably be checked via DCOP and therefore interface with KDM - if (config->readBoolEntry( "offerShutdown", true )/* && DM().canShutdown()*/) { // FIXME - mayrb = true; - } -#endif // WITH_CONSOLEKIT - - return mayrb; -} - -void TDERootSystemDevice::setHibernationMethod(TDESystemHibernationMethod::TDESystemHibernationMethod hm) { - TQString hibernationnode = "/sys/power/disk"; - TQFile file( hibernationnode ); - if ( file.open( IO_WriteOnly ) ) { - TQString hibernationCommand; - if (hm == TDESystemHibernationMethod::Platform) { - hibernationCommand = "platform"; - } - if (hm == TDESystemHibernationMethod::Shutdown) { - hibernationCommand = "shutdown"; - } - if (hm == TDESystemHibernationMethod::Reboot) { - hibernationCommand = "reboot"; - } - if (hm == TDESystemHibernationMethod::TestProc) { - hibernationCommand = "testproc"; - } - if (hm == TDESystemHibernationMethod::Test) { - hibernationCommand = "test"; - } - TQTextStream stream( &file ); - stream << hibernationCommand; - file.close(); - } -} - -bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState ps) { - if ((ps == TDESystemPowerState::Standby) || (ps == TDESystemPowerState::Suspend) || (ps == TDESystemPowerState::Hibernate)) { - TQString statenode = "/sys/power/state"; - TQFile file( statenode ); - if ( file.open( IO_WriteOnly ) ) { - TQString powerCommand; - if (ps == TDESystemPowerState::Standby) { - powerCommand = "standby"; - } - if (ps == TDESystemPowerState::Suspend) { - powerCommand = "mem"; - } - if (ps == TDESystemPowerState::Hibernate) { - powerCommand = "disk"; - } - TQTextStream stream( &file ); - stream << powerCommand; - file.close(); - return true; - } - else { -#ifdef WITH_UPOWER - TQT_DBusConnection dbusConn; - dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus); - if ( dbusConn.isConnected() ) { - if (ps == TDESystemPowerState::Suspend) { - TQT_DBusMessage msg = TQT_DBusMessage::methodCall( - "org.freedesktop.UPower", - "/org/freedesktop/UPower", - "org.freedesktop.UPower", - "Suspend"); - dbusConn.sendWithReply(msg); - return true; - } - else if (ps == TDESystemPowerState::Hibernate) { - TQT_DBusMessage msg = TQT_DBusMessage::methodCall( - "org.freedesktop.UPower", - "/org/freedesktop/UPower", - "org.freedesktop.UPower", - "Hibernate"); - dbusConn.sendWithReply(msg); - return true; - } - else { - return false; - } - } - else { - return false; - } -#else // WITH_UPOWER - return false; -#endif // WITH_UPOWER - } - } - else if (ps == TDESystemPowerState::PowerOff) { -#ifdef WITH_CONSOLEKIT - TDEConfig *config = TDEGlobal::config(); - config->reparseConfiguration(); // config may have changed in the KControl module - config->setGroup("General" ); - if (config->readBoolEntry( "offerShutdown", true )) { - TQT_DBusConnection dbusConn; - dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus); - if ( dbusConn.isConnected() ) { - TQT_DBusMessage msg = TQT_DBusMessage::methodCall( - "org.freedesktop.ConsoleKit", - "/org/freedesktop/ConsoleKit/Manager", - "org.freedesktop.ConsoleKit.Manager", - "Stop"); - dbusConn.sendWithReply(msg); - return true; - } - else { - return false; - } - } - else { - return false; - } -#else // WITH_CONSOLEKIT - // Power down the system using a DCOP command - // Values are explained at http://lists.kde.org/?l=kde-linux&m=115770988603387 - TQByteArray data; - TQDataStream arg(data, IO_WriteOnly); - arg << (int)0 << (int)2 << (int)2; - if ( kapp->dcopClient()->send("ksmserver", "default", "logout(int,int,int)", data) ) { - return true; - } - return false; -#endif // WITH_CONSOLEKIT - } - else if (ps == TDESystemPowerState::Reboot) { -#ifdef WITH_CONSOLEKIT - TDEConfig *config = TDEGlobal::config(); - config->reparseConfiguration(); // config may have changed in the KControl module - config->setGroup("General" ); - if (config->readBoolEntry( "offerShutdown", true )) { - TQT_DBusConnection dbusConn; - dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus); - if ( dbusConn.isConnected() ) { - TQT_DBusMessage msg = TQT_DBusMessage::methodCall( - "org.freedesktop.ConsoleKit", - "/org/freedesktop/ConsoleKit/Manager", - "org.freedesktop.ConsoleKit.Manager", - "Restart"); - dbusConn.sendWithReply(msg); - return true; - } - else { - return false; - } - } - else { - return false; - } -#else // WITH_CONSOLEKIT - // Power down the system using a DCOP command - // Values are explained at http://lists.kde.org/?l=kde-linux&m=115770988603387 - TQByteArray data; - TQDataStream arg(data, IO_WriteOnly); - arg << (int)0 << (int)1 << (int)2; - if ( kapp->dcopClient()->send("ksmserver", "default", "logout(int,int,int)", data) ) { - return true; - } - return false; -#endif // WITH_CONSOLEKIT - } - else if (ps == TDESystemPowerState::Active) { - // Ummm...we're already active... - return true; - } - - return false; -} - -TDENetworkDevice::TDENetworkDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) { - m_rxbytes = -1; - m_txbytes = -1; - m_rxpackets = -1; - m_txpackets = -1; - m_connectionManager = NULL; -} - -TDENetworkDevice::~TDENetworkDevice() { - if (m_connectionManager) { - delete m_connectionManager; - } -} - -TQString TDENetworkDevice::macAddress() { - return m_macAddress; -} - -void TDENetworkDevice::internalSetMacAddress(TQString ma) { - m_macAddress = ma; -} - -TQString TDENetworkDevice::state() { - return m_state; -} - -void TDENetworkDevice::internalSetState(TQString st) { - m_state = st; -} - -bool TDENetworkDevice::carrierPresent() { - return m_carrier; -} - -void TDENetworkDevice::internalSetCarrierPresent(bool cp) { - m_carrier = cp; -} - -bool TDENetworkDevice::dormant() { - return m_dormant; -} - -void TDENetworkDevice::internalSetDormant(bool dm) { - m_dormant = dm; -} - -TQString TDENetworkDevice::ipV4Address() { - return m_ipV4Address; -} - -void TDENetworkDevice::internalSetIpV4Address(TQString ad) { - m_ipV4Address = ad; -} - -TQString TDENetworkDevice::ipV6Address() { - return m_ipV6Address; -} - -void TDENetworkDevice::internalSetIpV6Address(TQString ad) { - m_ipV6Address = ad; -} - -TQString TDENetworkDevice::ipV4Netmask() { - return m_ipV4Netmask; -} - -void TDENetworkDevice::internalSetIpV4Netmask(TQString nm) { - m_ipV4Netmask = nm; -} - -TQString TDENetworkDevice::ipV6Netmask() { - return m_ipV6Netmask; -} - -void TDENetworkDevice::internalSetIpV6Netmask(TQString nm) { - m_ipV6Netmask = nm; -} - -TQString TDENetworkDevice::ipV4Broadcast() { - return m_ipV4Broadcast; -} - -void TDENetworkDevice::internalSetIpV4Broadcast(TQString br) { - m_ipV4Broadcast = br; -} - -TQString TDENetworkDevice::ipV6Broadcast() { - return m_ipV6Broadcast; -} - -void TDENetworkDevice::internalSetIpV6Broadcast(TQString br) { - m_ipV6Broadcast = br; -} - -TQString TDENetworkDevice::ipV4Destination() { - return m_ipV4Destination; -} - -void TDENetworkDevice::internalSetIpV4Destination(TQString ds) { - m_ipV4Destination = ds; -} - -TQString TDENetworkDevice::ipV6Destination() { - return m_ipV6Destination; -} - -void TDENetworkDevice::internalSetIpV6Destination(TQString ds) { - m_ipV6Destination = ds; -} - -double TDENetworkDevice::rxBytes() { - return m_rxbytes; -} - -void TDENetworkDevice::internalSetRxBytes(double rx) { - m_rxbytes = rx; -} - -double TDENetworkDevice::txBytes() { - return m_txbytes; -} - -void TDENetworkDevice::internalSetTxBytes(double tx) { - m_txbytes = tx; -} - -double TDENetworkDevice::rxPackets() { - return m_rxpackets; -} - -void TDENetworkDevice::internalSetRxPackets(double rx) { - m_rxpackets = rx; -} - -double TDENetworkDevice::txPackets() { - return m_txpackets; -} - -void TDENetworkDevice::internalSetTxPackets(double tx) { - m_txpackets = tx; -} - -TDENetworkConnectionManager* TDENetworkDevice::connectionManager() { -#ifdef WITH_NETWORK_MANAGER_BACKEND - if (!m_connectionManager) { - m_connectionManager = new TDENetworkConnectionManager_BackendNM(m_macAddress); - } -#endif // WITH_NETWORK_MANAGER_BACKEND - - return m_connectionManager; -} - -void TDENetworkDevice::internalSetConnectionManager(TDENetworkConnectionManager* mgr) { - m_connectionManager = mgr; -} - -TDEBacklightDevice::TDEBacklightDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) { -} - -TDEBacklightDevice::~TDEBacklightDevice() { -} - -TDEDisplayPowerLevel::TDEDisplayPowerLevel TDEBacklightDevice::powerLevel() { - return m_powerLevel; -} - -void TDEBacklightDevice::internalSetPowerLevel(TDEDisplayPowerLevel::TDEDisplayPowerLevel pl) { - m_powerLevel = pl; -} - -void TDEBacklightDevice::internalSetMaximumRawBrightness(int br) { - m_maximumBrightness = br; -} - -void TDEBacklightDevice::internalSetCurrentRawBrightness(int br) { - m_currentBrightness = br; -} - -int TDEBacklightDevice::brightnessSteps() { - return m_maximumBrightness + 1; -} - -double TDEBacklightDevice::brightnessPercent() { - return (((m_currentBrightness*1.0)/m_maximumBrightness)*100.0); -} - -bool TDEBacklightDevice::canSetBrightness() { - TQString brightnessnode = systemPath() + "/brightness"; - int rval = access (brightnessnode.ascii(), W_OK); - if (rval == 0) { - return TRUE; - } - else { -#ifdef WITH_UPOWER - TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus); - if (dbusConn.isConnected()) { - TQT_DBusProxy hardwareControl("org.trinitydesktop.hardwarecontrol", "/org/trinitydesktop/hardwarecontrol", "org.trinitydesktop.hardwarecontrol.Brightness", dbusConn); - if (hardwareControl.canSend()) { - // can set brightness? - TQValueList params; - params << TQT_DBusData::fromString(brightnessnode); - TQT_DBusMessage reply = hardwareControl.sendWithReply("CanSetBrightness", params); - if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) { - return reply[0].toVariant().value.toBool(); - } - else { - return FALSE; - } - } - else { - return FALSE; - } - } - else { - return FALSE; - } -#else // WITH_UPOWER - return FALSE; -#endif// WITH_UPOWER - } -} - -int TDEBacklightDevice::rawBrightness() { - return m_currentBrightness; -} - -void TDEBacklightDevice::setRawBrightness(int br) { - TQString brightnessnode = systemPath() + "/brightness"; - TQString brightnessCommand = TQString("%1").arg(br); - TQFile file( brightnessnode ); - if ( file.open( IO_WriteOnly ) ) { - TQTextStream stream( &file ); - stream << brightnessCommand; - file.close(); - } -#ifdef WITH_UPOWER - else { - TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus); - if (dbusConn.isConnected()) { - TQT_DBusProxy hardwareControl("org.trinitydesktop.hardwarecontrol", "/org/trinitydesktop/hardwarecontrol", "org.trinitydesktop.hardwarecontrol.Brightness", dbusConn); - if (hardwareControl.canSend()) { - // set brightness - TQValueList params; - params << TQT_DBusData::fromString(brightnessnode) << TQT_DBusData::fromString(brightnessCommand); - hardwareControl.sendWithReply("SetBrightness", params); - } - else { - return; - } - } - else { - return; - } - } -#endif // WITH_UPOWER -} - -TDEMonitorDevice::TDEMonitorDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) { -} - -TDEMonitorDevice::~TDEMonitorDevice() { -} - -bool TDEMonitorDevice::connected() { - return m_connected; -} - -void TDEMonitorDevice::internalSetConnected(bool cn) { - m_connected = cn; -} - -bool TDEMonitorDevice::enabled() { - return m_enabled; -} - -void TDEMonitorDevice::internalSetEnabled(bool en) { - m_enabled = en; -} - -TQByteArray TDEMonitorDevice::edid() { - return m_edid; -} - -void TDEMonitorDevice::internalSetEdid(TQByteArray ed) { - m_edid = ed; -} - -TDEResolutionList TDEMonitorDevice::resolutions() { - return m_resolutions; -} - -void TDEMonitorDevice::internalSetResolutions(TDEResolutionList rs) { - m_resolutions = rs; -} - -TQString TDEMonitorDevice::portType() { - return m_portType; -} - -void TDEMonitorDevice::internalSetPortType(TQString pt) { - m_portType = pt; -} - -TDEDisplayPowerLevel::TDEDisplayPowerLevel TDEMonitorDevice::powerLevel() { - return m_powerLevel; -} - -void TDEMonitorDevice::internalSetPowerLevel(TDEDisplayPowerLevel::TDEDisplayPowerLevel pl) { - m_powerLevel = pl; -} - -TDEEventDevice::TDEEventDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) { - m_fd = -1; - m_fdMonitorActive = false; -} - -TDEEventDevice::~TDEEventDevice() { - if (m_fd >= 0) { - close(m_fd); - } -} - -TDEEventDeviceType::TDEEventDeviceType TDEEventDevice::eventType() { - return m_eventType; -} - -void TDEEventDevice::internalSetEventType(TDEEventDeviceType::TDEEventDeviceType et) { - m_eventType = et; -} - -TDESwitchType::TDESwitchType TDEEventDevice::providedSwitches() { - return m_providedSwitches; -} - -void TDEEventDevice::internalSetProvidedSwitches(TDESwitchType::TDESwitchType sl) { - m_providedSwitches = sl; -} - -TDESwitchType::TDESwitchType TDEEventDevice::activeSwitches() { - return m_switchActive; -} - -void TDEEventDevice::internalSetActiveSwitches(TDESwitchType::TDESwitchType sl) { - m_switchActive = sl; -} - -// Keep this in sync with the TDESwitchType definition in the header -TQStringList TDEEventDevice::friendlySwitchList(TDESwitchType::TDESwitchType switches) { - TQStringList ret; - - if (switches & TDESwitchType::Lid) { - ret.append(i18n("Lid Switch")); - } - if (switches & TDESwitchType::TabletMode) { - ret.append(i18n("Tablet Mode")); - } - if (switches & TDESwitchType::HeadphoneInsert) { - ret.append(i18n("Headphone Inserted")); - } - if (switches & TDESwitchType::RFKill) { - ret.append(i18n("Radio Frequency Device Kill Switch")); - } - if (switches & TDESwitchType::Radio) { - ret.append(i18n("Enable Radio")); - } - if (switches & TDESwitchType::MicrophoneInsert) { - ret.append(i18n("Microphone Inserted")); - } - if (switches & TDESwitchType::Dock) { - ret.append(i18n("Docked")); - } - if (switches & TDESwitchType::LineOutInsert) { - ret.append(i18n("Line Out Inserted")); - } - if (switches & TDESwitchType::JackPhysicalInsert) { - ret.append(i18n("Physical Jack Inserted")); - } - if (switches & TDESwitchType::VideoOutInsert) { - ret.append(i18n("Video Out Inserted")); - } - if (switches & TDESwitchType::CameraLensCover) { - ret.append(i18n("Camera Lens Cover")); - } - if (switches & TDESwitchType::KeypadSlide) { - ret.append(i18n("Keypad Slide")); - } - if (switches & TDESwitchType::FrontProximity) { - ret.append(i18n("Front Proximity")); - } - if (switches & TDESwitchType::RotateLock) { - ret.append(i18n("Rotate Lock")); - } - if (switches & TDESwitchType::LineInInsert) { - ret.append(i18n("Line In Inserted")); - } - - return ret; -} - -void TDEEventDevice::internalStartFdMonitoring(TDEHardwareDevices* hwmanager) { - if (!m_fdMonitorActive) { - // For security and performance reasons, only monitor known ACPI buttons - if (eventType() != TDEEventDeviceType::Unknown) { - if (m_fd >= 0) { - m_eventNotifier = new TQSocketNotifier(m_fd, TQSocketNotifier::Read, this); - connect( m_eventNotifier, TQT_SIGNAL(activated(int)), this, TQT_SLOT(eventReceived()) ); - } - connect( this, TQT_SIGNAL(keyPressed(unsigned int, TDEEventDevice*)), hwmanager, TQT_SLOT(processEventDeviceKeyPressed(unsigned int, TDEEventDevice*)) ); - } - m_fdMonitorActive = true; - } -} - -void TDEEventDevice::eventReceived() { - struct input_event ev; - int r; - r = read(m_fd, &ev, sizeof(struct input_event)); - if (r > 0) { - if (ev.type == EV_KEY) { - emit keyPressed(ev.code, this); - } - } -} - -TDEInputDevice::TDEInputDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) { -} - -TDEInputDevice::~TDEInputDevice() { -} - -TDEInputDeviceType::TDEInputDeviceType TDEInputDevice::inputType() { - return m_inputType; -} - -void TDEInputDevice::internalSetInputType(TDEInputDeviceType::TDEInputDeviceType it) { - m_inputType = it; -} - TDEHardwareDevices::TDEHardwareDevices() { // Initialize members pci_id_map = 0; -- cgit v1.2.1