parent
4b775b444d
commit
e7708ec743
@ -0,0 +1,138 @@
|
||||
/* This file is part of the TDE libraries
|
||||
Copyright (C) 2012 Timothy Pearson <kb9vqf@pearsoncomputing.net>
|
||||
(C) 2013 Golubev Alexander <fatzer2@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2 as published by the Free Software Foundation.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "tdebacklightdevice.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <tqfile.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
// uPower
|
||||
#if defined(WITH_UPOWER)
|
||||
#include <tqdbusdata.h>
|
||||
#include <tqdbusmessage.h>
|
||||
#include <tqdbusproxy.h>
|
||||
#include <tqdbusvariant.h>
|
||||
#include <tqdbusconnection.h>
|
||||
#endif // defined(WITH_UPOWER)
|
||||
|
||||
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<TQT_DBusData> 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<TQT_DBusData> params;
|
||||
params << TQT_DBusData::fromString(brightnessnode) << TQT_DBusData::fromString(brightnessCommand);
|
||||
hardwareControl.sendWithReply("SetBrightness", params);
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif // WITH_UPOWER
|
||||
}
|
||||
|
||||
#include "tdebacklightdevice.moc"
|
@ -0,0 +1,97 @@
|
||||
/* This file is part of the TDE libraries
|
||||
Copyright (C) 2012 Timothy Pearson <kb9vqf@pearsoncomputing.net>
|
||||
(C) 2013 Golubev Alexander <fatzer2@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2 as published by the Free Software Foundation.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef _TDEBACKLIGHTDEVICE_H
|
||||
#define _TDEBACKLIGHTDEVICE_H
|
||||
|
||||
#include "tdegenericdevice.h"
|
||||
#include "tdehwcommontypes.h"
|
||||
|
||||
class TDECORE_EXPORT TDEBacklightDevice : public TDEGenericDevice
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
* @param Device type
|
||||
*/
|
||||
TDEBacklightDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn=TQString::null);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~TDEBacklightDevice();
|
||||
|
||||
/**
|
||||
* @return a TDEDisplayPowerLevel::TDEDisplayPowerLevel with the current power level
|
||||
*/
|
||||
TDEDisplayPowerLevel::TDEDisplayPowerLevel powerLevel();
|
||||
|
||||
/**
|
||||
* @return an integer with the number of discrete control steps available
|
||||
*/
|
||||
int brightnessSteps();
|
||||
|
||||
/**
|
||||
* @return a double with the current brightness percentage
|
||||
*/
|
||||
double brightnessPercent();
|
||||
|
||||
/**
|
||||
* @return TRUE if permissions allow brightness can be set, FALSE if not
|
||||
*/
|
||||
bool canSetBrightness();
|
||||
|
||||
/**
|
||||
* @return an int with the current raw brightness
|
||||
*/
|
||||
int rawBrightness();
|
||||
|
||||
/**
|
||||
* @param br an integer with the new raw brightness value
|
||||
*/
|
||||
void setRawBrightness(int br);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @param pl a TDEDisplayPowerLevel::TDEDisplayPowerLevel with the current power level
|
||||
* @internal
|
||||
*/
|
||||
void internalSetPowerLevel(TDEDisplayPowerLevel::TDEDisplayPowerLevel pl);
|
||||
|
||||
/**
|
||||
* @param br an integer with the maximum raw brightness value
|
||||
* @internal
|
||||
*/
|
||||
void internalSetMaximumRawBrightness(int br);
|
||||
|
||||
/**
|
||||
* @param br an integer with the current raw brightness value
|
||||
* @internal
|
||||
*/
|
||||
void internalSetCurrentRawBrightness(int br);
|
||||
|
||||
private:
|
||||
TDEDisplayPowerLevel::TDEDisplayPowerLevel m_powerLevel;
|
||||
int m_currentBrightness;
|
||||
int m_maximumBrightness;
|
||||
|
||||
friend class TDEHardwareDevices;
|
||||
};
|
||||
|
||||
#endif // _TDEBACKLIGHTDEVICE_H
|
@ -0,0 +1,146 @@
|
||||
/* This file is part of the TDE libraries
|
||||
Copyright (C) 2012 Timothy Pearson <kb9vqf@pearsoncomputing.net>
|
||||
(C) 2013 Golubev Alexander <fatzer2@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2 as published by the Free Software Foundation.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "tdeeventdevice.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <linux/input.h>
|
||||
|
||||
#include <tqsocketnotifier.h>
|
||||
|
||||
#include "tdelocale.h"
|
||||
|
||||
#include "tdehardwaredevices.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "tdeeventdevice.moc"
|
@ -0,0 +1,161 @@
|
||||
/* This file is part of the TDE libraries
|
||||
Copyright (C) 2012 Timothy Pearson <kb9vqf@pearsoncomputing.net>
|
||||
(C) 2013 Golubev Alexander <fatzer2@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2 as published by the Free Software Foundation.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef _TDEEVENTDEVICE_H
|
||||
#define _TDEEVENTDEVICE_H
|
||||
|
||||
#include "tdegenericdevice.h"
|
||||
|
||||
class TDEHardwareDevices;
|
||||
|
||||
namespace TDEEventDeviceType {
|
||||
enum TDEEventDeviceType {
|
||||
Unknown,
|
||||
ACPILidSwitch,
|
||||
ACPISleepButton,
|
||||
ACPIPowerButton,
|
||||
Other = 0x80000000
|
||||
};
|
||||
};
|
||||
|
||||
// Keep friendlySwitchList() in tdehardwaredevices.cpp in sync with this enum
|
||||
namespace TDESwitchType {
|
||||
enum TDESwitchType {
|
||||
Null = 0x00000000,
|
||||
Lid = 0x00000001,
|
||||
TabletMode = 0x00000002,
|
||||
HeadphoneInsert = 0x00000004,
|
||||
RFKill = 0x00000008,
|
||||
Radio = 0x00000010,
|
||||
MicrophoneInsert = 0x00000020,
|
||||
Dock = 0x00000040,
|
||||
LineOutInsert = 0x00000080,
|
||||
JackPhysicalInsert = 0x00000100,
|
||||
VideoOutInsert = 0x00000200,
|
||||
CameraLensCover = 0x00000400,
|
||||
KeypadSlide = 0x00000800,
|
||||
FrontProximity = 0x00001000,
|
||||
RotateLock = 0x00002000,
|
||||
LineInInsert = 0x00004000
|
||||
};
|
||||
|
||||
inline TDESwitchType operator|(TDESwitchType a, TDESwitchType b)
|
||||
{
|
||||
return static_cast<TDESwitchType>(static_cast<int>(a) | static_cast<int>(b));
|
||||
}
|
||||
|
||||
inline TDESwitchType operator&(TDESwitchType a, TDESwitchType b)
|
||||
{
|
||||
return static_cast<TDESwitchType>(static_cast<int>(a) & static_cast<int>(b));
|
||||
}
|
||||
|
||||
inline TDESwitchType operator~(TDESwitchType a)
|
||||
{
|
||||
return static_cast<TDESwitchType>(~static_cast<int>(a));
|
||||
}
|
||||
};
|
||||
|
||||
class TQSocketNotifier;
|
||||
|
||||
class TDECORE_EXPORT TDEEventDevice : public TDEGenericDevice
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
* @param Device type
|
||||
*/
|
||||
TDEEventDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn=TQString::null);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~TDEEventDevice();
|
||||
|
||||
/**
|
||||
* @return a TDEEventDeviceType::TDEEventDeviceType with the event device type, if known
|
||||
*/
|
||||
TDEEventDeviceType::TDEEventDeviceType eventType();
|
||||
|
||||
/**
|
||||
* @return a TDESwitchType::TDESwitchType with all switches provided by this device
|
||||
*/
|
||||
TDESwitchType::TDESwitchType providedSwitches();
|
||||
|
||||
/**
|
||||
* @return a TDESwitchType::TDESwitchType with all active switches provided by this device
|
||||
*/
|
||||
TDESwitchType::TDESwitchType activeSwitches();
|
||||
|
||||
/**
|
||||
* @param switches a TDESwitchType::TDESwitchType with any switch flags set
|
||||
* @return a TQStringList with friendly names for all set switch flags
|
||||
*/
|
||||
static TQStringList friendlySwitchList(TDESwitchType::TDESwitchType switches);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @param et a TDEEventDeviceType::TDEEventDeviceType with the event device type, if known
|
||||
* @internal
|
||||
*/
|
||||
void internalSetEventType(TDEEventDeviceType::TDEEventDeviceType et);
|
||||
|
||||
/**
|
||||
* @param sl a TDESwitchType::TDESwitchType with all switches provided by this device
|
||||
* @internal
|
||||
*/
|
||||
void internalSetProvidedSwitches(TDESwitchType::TDESwitchType sl);
|
||||
|
||||
/**
|
||||
* @param sl a TDESwitchType::TDESwitchType with all active switches provided by this device
|
||||
* @internal
|
||||
*/
|
||||
void internalSetActiveSwitches(TDESwitchType::TDESwitchType sl);
|
||||
|
||||
/**
|
||||
* @param hwmanager the master hardware manager
|
||||
* @internal
|
||||
*/
|
||||
void internalStartFdMonitoring(TDEHardwareDevices* hwmanager);
|
||||
|
||||
protected slots:
|
||||
void eventReceived();
|
||||
|
||||
signals:
|
||||
/**
|
||||
* @param keycode the code of the key that was pressed/released
|
||||
* See include/linux/input.h for a complete list of keycodes
|
||||
* @param device a TDEEventDevice* with the device that received the event
|
||||
*/
|
||||
void keyPressed(unsigned int keycode, TDEEventDevice* device);
|
||||
|
||||
private:
|
||||
TDEEventDeviceType::TDEEventDeviceType m_eventType;
|
||||
TDESwitchType::TDESwitchType m_providedSwitches;
|
||||
TDESwitchType::TDESwitchType m_switchActive;
|
||||
|
||||
int m_fd;
|
||||
bool m_fdMonitorActive;
|
||||
TQSocketNotifier* m_eventNotifier;
|
||||
|
||||
friend class TDEHardwareDevices;
|
||||
};
|
||||
|
||||
#endif // _TDEEVENTDEVICE_H
|
@ -0,0 +1,100 @@
|
||||
/* This file is part of the TDE libraries
|
||||
Copyright (C) 2012 Timothy Pearson <kb9vqf@pearsoncomputing.net>
|
||||
(C) 2013 Golubev Alexander <fatzer2@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2 as published by the Free Software Foundation.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef _TDEHWCOMMON_H
|
||||
#define _TDEHWCOMMON_H
|
||||
|
||||
// Keep readGenericDeviceTypeFromString(), getFriendlyDeviceTypeStringFromType(), and getDeviceTypeIconFromType() in tdehardwaredevices.cpp in sync with this enum
|
||||
namespace TDEGenericDeviceType {
|
||||
enum TDEGenericDeviceType {
|
||||
Root,
|
||||
RootSystem,
|
||||
CPU,
|
||||
GPU,
|
||||
RAM,
|
||||
Bus,
|
||||
I2C,
|
||||
MDIO,
|
||||
Mainboard,
|
||||
Disk,
|
||||
SCSI,
|
||||
StorageController,
|
||||
Mouse,
|
||||
Keyboard,
|
||||
HID,
|
||||
Modem,
|
||||
Monitor,
|
||||
Network,
|
||||
Printer,
|
||||
Scanner,
|
||||
Sound,
|
||||
VideoCapture,
|
||||
IEEE1394,
|
||||
PCMCIA,
|
||||
Camera,
|
||||
TextIO,
|
||||
Serial,
|
||||
Parallel,
|
||||
Peripheral,
|
||||
Backlight,
|
||||
Battery,
|
||||
PowerSupply,
|
||||
Dock,
|
||||
ThermalSensor,
|
||||
ThermalControl,
|
||||
BlueTooth,
|
||||
Bridge,
|
||||
Platform,
|
||||
Cryptography,
|
||||
Event,
|
||||
Input,
|
||||
PNP,
|
||||
OtherACPI,
|
||||
OtherUSB,
|
||||
OtherMultimedia,
|
||||
OtherPeripheral,
|
||||
OtherSensor,
|
||||
OtherVirtual,
|
||||
Other,
|
||||
Last = Other
|
||||
};
|
||||
};
|
||||
|
||||
namespace TDEDisplayPowerLevel {
|
||||
enum TDEDisplayPowerLevel {
|
||||
On,
|
||||
Standby,
|
||||
Suspend,
|
||||
Off
|
||||
};
|
||||
};
|
||||
|
||||
namespace TDEHardwareEvent {
|
||||
enum TDEHardwareEvent {
|
||||
HardwareListModified,
|
||||
MountTableModified,
|
||||
HardwareAdded,
|
||||
HardwareRemoved,
|
||||
HardwareUpdated,
|
||||
Other,
|
||||
Last = Other
|
||||
};
|
||||
};
|
||||
|
||||
#endif // _TDEHWCOMMON_H
|
@ -0,0 +1,38 @@
|
||||
/* This file is part of the TDE libraries
|
||||
Copyright (C) 2012 Timothy Pearson <kb9vqf@pearsoncomputing.net>
|
||||
(C) 2013 Golubev Alexander <fatzer2@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2 as published by the Free Software Foundation.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "tdeinputdevice.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
#include "tdeinputdevice.moc"
|
@ -0,0 +1,67 @@
|
||||
/* This file is part of the TDE libraries
|
||||
Copyright (C) 2012 Timothy Pearson <kb9vqf@pearsoncomputing.net>
|
||||
(C) 2013 Golubev Alexander <fatzer2@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2 as published by the Free Software Foundation.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef _TDEINPUTDEVICE_H
|
||||
#define _TDEINPUTDEVICE_H
|
||||
|
||||
#include "tdegenericdevice.h"
|
||||
|
||||
namespace TDEInputDeviceType {
|
||||
enum TDEInputDeviceType {
|
||||
Unknown,
|
||||
ACPILidSwitch,
|
||||
ACPISleepButton,
|
||||
ACPIPowerButton,
|
||||
Other = 0x80000000
|
||||
};
|
||||
};
|
||||
|
||||
class TDECORE_EXPORT TDEInputDevice : public TDEGenericDevice
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
* @param Device type
|
||||
*/
|
||||
TDEInputDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn=TQString::null);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~TDEInputDevice();
|
||||
|
||||
/**
|
||||
* @return a TDEInputDeviceType::TDEInputDeviceType with the input device type, if known
|
||||
*/
|
||||
TDEInputDeviceType::TDEInputDeviceType inputType();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @param it a TDEInputDeviceType::TDEInputDeviceType with the input device type, if known
|
||||
* @internal
|
||||
*/
|
||||
void internalSetInputType(TDEInputDeviceType::TDEInputDeviceType it);
|
||||
|
||||
private:
|
||||
TDEInputDeviceType::TDEInputDeviceType m_inputType;
|
||||
|
||||
friend class TDEHardwareDevices;
|
||||
};
|
||||
|
||||
#endif // _TDEINPUTDEVICE_H
|
@ -0,0 +1,78 @@
|
||||
/* This file is part of the TDE libraries
|
||||
Copyright (C) 2012 Timothy Pearson <kb9vqf@pearsoncomputing.net>
|
||||
(C) 2013 Golubev Alexander <fatzer2@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2 as published by the Free Software Foundation.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "tdemonitordevice.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
#include "tdemonitordevice.moc"
|
@ -0,0 +1,122 @@
|
||||
/* This file is part of the TDE libraries
|
||||
Copyright (C) 2012 Timothy Pearson <kb9vqf@pearsoncomputing.net>
|
||||
(C) 2013 Golubev Alexander <fatzer2@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2 as published by the Free Software Foundation.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef _TDEMONITORDEVICE_H
|
||||
#define _TDEMONITORDEVICE_H
|
||||
|
||||
#include "tdegenericdevice.h"
|
||||
#include "tdehwcommontypes.h"
|
||||
|
||||
typedef TQPair<unsigned int, unsigned int> TDEResolutionPair;
|
||||
typedef TQValueList< TDEResolutionPair > TDEResolutionList;
|
||||
|
||||
class TDECORE_EXPORT TDEMonitorDevice : public TDEGenericDevice
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
* @param Device type
|
||||
*/
|
||||
TDEMonitorDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn=TQString::null);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~TDEMonitorDevice();
|
||||
|
||||
/**
|
||||
* @return TRUE if a monitor is connected, FALSE if not
|
||||
*/
|
||||
bool connected();
|
||||
|
||||
/**
|
||||
* @return TRUE if this port is enabled, FALSE if not
|
||||
*/
|
||||
bool enabled();
|
||||
|
||||
/**
|
||||
* @return a TQByteArray containing this monitor's EDID information
|
||||
*/
|
||||
TQByteArray edid();
|
||||
|
||||
/**
|
||||
* @return a TDEResolutionList containing this monitor's supported resolutions
|
||||
*/
|
||||
TDEResolutionList resolutions();
|
||||
|
||||
/**
|
||||
* @return a TQString containing the display port type
|
||||
*/
|
||||
TQString portType();
|
||||
|
||||
/**
|
||||
* @return a TDEDisplayPowerLevel::TDEDisplayPowerLevel with the current power level
|
||||
*/
|
||||
TDEDisplayPowerLevel::TDEDisplayPowerLevel powerLevel();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @param TRUE if a monitor is connected, FALSE if not
|
||||
* @internal
|
||||
*/
|
||||
void internalSetConnected(bool cn);
|
||||
|
||||
/**
|
||||
* @param TRUE if this port is enabled, FALSE if not
|
||||
* @internal
|
||||
*/
|
||||
void internalSetEnabled(bool en);
|
||||
|
||||
/**
|
||||
* @param ed a TQByteArray containing this monitor's EDID information
|
||||
* @internal
|
||||
*/
|
||||
void internalSetEdid(TQByteArray ed);
|
||||
|
||||
/**
|
||||
* @param rs a TDEResolutionList containing this monitor's supported resolutions
|
||||
* @internal
|
||||
*/
|
||||
void internalSetResolutions(TDEResolutionList rs);
|
||||
|
||||
/**
|
||||
* @param pt a TQString containing the display port type
|
||||
* @internal
|
||||
*/
|
||||
void internalSetPortType(TQString pt);
|
||||
|
||||
/**
|
||||
* @param pl a TDEDisplayPowerLevel::TDEDisplayPowerLevel with the current power level
|
||||
* @internal
|
||||
*/
|
||||
void internalSetPowerLevel(TDEDisplayPowerLevel::TDEDisplayPowerLevel pl);
|
||||
|
||||
private:
|
||||
bool m_connected;
|
||||
bool m_enabled;
|
||||
TQByteArray m_edid;
|
||||
TDEResolutionList m_resolutions;
|
||||
TQString m_portType;
|
||||
TDEDisplayPowerLevel::TDEDisplayPowerLevel m_powerLevel;
|
||||
|
||||
friend class TDEHardwareDevices;
|
||||
};
|
||||
|
||||
|
||||
#endif // _TDEMONITORDEVICE_H
|
@ -0,0 +1,188 @@
|
||||
/* This file is part of the TDE libraries
|
||||
Copyright (C) 2012 Timothy Pearson <kb9vqf@pearsoncomputing.net>
|
||||
(C) 2013 Golubev Alexander <fatzer2@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2 as published by the Free Software Foundation.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "tdenetworkdevice.h"
|
||||
|
||||
// Network connection manager
|
||||
#include "tdenetworkconnections.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifdef WITH_NETWORK_MANAGER_BACKEND
|
||||
#include "network-manager.h"
|
||||
#endif // WITH_NETWORK_MANAGER_BACKEND
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
#include "tdenetworkdevice.moc"
|
@ -0,0 +1,252 @@
|
||||
/* This file is part of the TDE libraries
|
||||
Copyright (C) 2012 Timothy Pearson <kb9vqf@pearsoncomputing.net>
|
||||
(C) 2013 Golubev Alexander <fatzer2@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2 as published by the Free Software Foundation.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef _TDENETWORKDEVICE_H
|
||||
#define _TDENETWORKDEVICE_H
|
||||
|
||||
#include "tdegenericdevice.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
class TDENetworkConnectionManager;
|
||||
|
||||
class TDECORE_EXPORT TDENetworkDevice : public TDEGenericDevice
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
* @param Device type
|
||||
*/
|
||||
TDENetworkDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn=TQString::null);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~TDENetworkDevice();
|
||||
|
||||
/**
|
||||
* @return a TQString containing the network device's MAC address
|
||||
*/
|
||||
TQString macAddress();
|
||||
|
||||
/**
|
||||
* @return a TQString containing the network device's operational state
|
||||
*/
|
||||
TQString state();
|
||||
|
||||
/**
|
||||
* @return TRUE if carrier is present, FALSE if not
|
||||
*/
|
||||
bool carrierPresent();
|
||||
|
||||
/**
|
||||
* @return TRUE if device is dormant, FALSE if not
|
||||
*/
|
||||
bool dormant();
|
||||
|
||||
/**
|
||||
* @return a TQString containing the network device's IPv4 address
|
||||
*/
|
||||
TQString ipV4Address();
|
||||
|
||||
/**
|
||||
* @return a TQString containing the network device's IPv6 address
|
||||
*/
|
||||
TQString ipV6Address();
|
||||
|
||||
/**
|
||||
* @return a TQString containing the network device's IPv4 netmask
|
||||
*/
|
||||
TQString ipV4Netmask();
|
||||
|
||||
/**
|
||||
* @return a TQString containing the network device's IPv6 netmask
|
||||
*/
|
||||
TQString ipV6Netmask();
|
||||
|
||||
/**
|
||||
* @return a TQString containing the network device's IPv4 broadcast
|
||||
*/
|
||||
TQString ipV4Broadcast();
|
||||
|
||||
/**
|
||||
* @return a TQString containing the network device's IPv6 broadcast
|
||||
*/
|
||||
TQString ipV6Broadcast();
|
||||
|
||||
/**
|
||||
* @return a TQString containing the network device's IPv4 destination
|
||||
*/
|
||||
TQString ipV4Destination();
|
||||
|
||||
/**
|
||||
* @return a TQString containing the network device's IPv6 destination
|
||||
*/
|
||||
TQString ipV6Destination();
|
||||
|
||||
/**
|
||||
* @return a double with the number of received bytes, if available
|
||||
*/
|
||||
double rxBytes();
|
||||
|
||||
/**
|
||||
* @return a double with the number of transmitted bytes, if available
|
||||
*/
|
||||
double txBytes();
|
||||
|
||||
/**
|
||||
* @return a double with the number of received packets, if available
|
||||
*/
|
||||
double rxPackets();
|
||||
|
||||
/**
|
||||
* @return a double with the number of transmitted packets, if available
|
||||
*/
|
||||
double txPackets();
|
||||
|
||||
/**
|
||||
* @return a pointer to a TDENetworkConnectionManager object, if available
|
||||
*/
|
||||
TDENetworkConnectionManager* connectionManager();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @param ma a TQString containing the network device's MAC address
|
||||
* @internal
|
||||
*/
|
||||
void internalSetMacAddress(TQString ma);
|
||||
|
||||
/**
|
||||
* @param st a TQString containing the network device's operational state
|
||||
* @internal
|
||||
*/
|
||||
void internalSetState(TQString st);
|
||||
|
||||
/**
|
||||
* @param TRUE if carrier is present, FALSE if not
|
||||
* @internal
|
||||
*/
|
||||
void internalSetCarrierPresent(bool cp);
|
||||
|
||||
/**
|
||||
* @param TRUE if device is dormant, FALSE if not
|
||||
* @internal
|
||||
*/
|
||||
void internalSetDormant(bool dm);
|
||||
|
||||
/**
|
||||
* @param ad a TQString containing the network device's IPv4 address
|
||||
* @internal
|
||||
*/
|
||||
void internalSetIpV4Address(TQString ad);
|
||||
|
||||
/**
|
||||
* @param ad a TQString containing the network device's IPv6 address
|
||||
* @internal
|
||||
*/
|
||||
void internalSetIpV6Address(TQString ad);
|
||||
|
||||
/**
|
||||
* @param nm a TQString containing the network device's IPv4 netmask
|
||||
* @internal
|
||||
*/
|
||||
void internalSetIpV4Netmask(TQString nm);
|
||||
|
||||
/**
|
||||
* @param nm a TQString containing the network device's IPv6 netmask
|
||||
* @internal
|
||||
*/
|
||||
void internalSetIpV6Netmask(TQString nm);
|
||||
|
||||
/**
|
||||
* @param br a TQString containing the network device's IPv4 broadcast
|
||||
* @internal
|
||||
*/
|
||||
void internalSetIpV4Broadcast(TQString br);
|
||||
|
||||
/**
|
||||
* @param br a TQString containing the network device's IPv6 broadcast
|
||||
* @internal
|
||||
*/
|
||||
void internalSetIpV6Broadcast(TQString br);
|
||||
|
||||
/**
|
||||
* @param ds a TQString containing the network device's IPv4 destination
|
||||
* @internal
|
||||
*/
|
||||
void internalSetIpV4Destination(TQString ds);
|
||||
|
||||
/**
|
||||
* @param ds a TQString containing the network device's IPv6 destination
|
||||
* @internal
|
||||
*/
|
||||
void internalSetIpV6Destination(TQString ds);
|
||||
|
||||
/**
|
||||
* @param rx a double with the number of received bytes, if available
|
||||
* @internal
|
||||
*/
|
||||
void internalSetRxBytes(double rx);
|
||||
|
||||
/**
|
||||
* @param tx a double with the number of transmitted bytes, if available
|
||||
* @internal
|
||||
*/
|
||||
void internalSetTxBytes(double tx);
|
||||
|
||||
/**
|
||||
* @param rx a double with the number of received packets, if available
|
||||
* @internal
|
||||
*/
|
||||
void internalSetRxPackets(double rx);
|
||||
|
||||
/**
|
||||
* @param tx a double with the number of transmitted packets, if available
|
||||
* @internal
|
||||
*/
|
||||
void internalSetTxPackets(double tx);
|
||||
|
||||
/**
|
||||
* @param mgr a pointer to a TDENetworkConnectionManager object, if available
|
||||
*/
|
||||
void internalSetConnectionManager(TDENetworkConnectionManager* mgr);
|
||||
|
||||
private:
|
||||
TQString m_macAddress;
|
||||
TQString m_state;
|
||||
bool m_carrier;
|
||||
bool m_dormant;
|
||||
TQString m_ipV4Address;
|
||||
TQString m_ipV6Address;
|
||||
TQString m_ipV4Netmask;
|
||||
TQString m_ipV6Netmask;
|
||||
TQString m_ipV4Broadcast;
|
||||
TQString m_ipV6Broadcast;
|
||||
TQString m_ipV4Destination;
|
||||
TQString m_ipV6Destination;
|
||||
double m_rxbytes;
|
||||
double m_txbytes;
|
||||
double m_rxpackets;
|
||||
double m_txpackets;
|
||||
TDENetworkConnectionManager* m_connectionManager;
|
||||
|
||||
friend class TDEHardwareDevices;
|
||||
};
|
||||
|
||||
#endif // _TDENETWORKDEVICE_H
|
@ -0,0 +1,440 @@
|
||||
/* This file is part of the TDE libraries
|
||||
Copyright (C) 2012 Timothy Pearson <kb9vqf@pearsoncomputing.net>
|
||||
(C) 2013 Golubev Alexander <fatzer2@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2 as published by the Free Software Foundation.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "tderootsystemdevice.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <tqfile.h>
|
||||
|
||||
#include "tdeglobal.h"
|
||||
#include "tdeconfig.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#if defined(WITH_UPOWER) || defined(WITH_CONSOLEKIT)
|
||||
#include <tqdbusdata.h>
|
||||
#include <tqdbusmessage.h>
|
||||
#include <tqdbusproxy.h>
|
||||
#include <tqdbusvariant.h>
|
||||
#include <tqdbusconnection.h>
|
||||
#endif // defined(WITH_UPOWER) || defined(WITH_CONSOLEKIT)
|
||||
|
||||
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<TQT_DBusData> 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<TQT_DBusData> 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<TQT_DBusData> 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<TQT_DBusData> 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;
|
||||
}
|
||||
|
||||
#include "tderootsystemdevice.moc"
|
@ -0,0 +1,182 @@
|
||||
/* This file is part of the TDE libraries
|
||||
Copyright (C) 2012 Timothy Pearson <kb9vqf@pearsoncomputing.net>
|
||||
(C) 2013 Golubev Alexander <fatzer2@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2 as published by the Free Software Foundation.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef _TDEROOTSYSTEMDEVICE_H
|
||||
#define _TDEROOTSYSTEMDEVICE_H
|
||||
|
||||
#include "tdegenericdevice.h"
|
||||
#include "tdehwcommontypes.h"
|
||||
|
||||
namespace TDESystemFormFactor {
|
||||
enum TDESystemFormFactor {
|
||||
Unclassified,
|
||||
Desktop,
|
||||
Laptop,
|
||||
Server,
|
||||
Other = 0x80000000
|
||||
};
|
||||
};
|
||||
|
||||
namespace TDESystemPowerState {
|
||||
enum TDESystemPowerState {
|
||||
Active,
|
||||
Standby,
|
||||
Suspend,
|
||||
Hibernate,
|
||||
PowerOff,
|
||||
Reboot
|
||||
};
|
||||
};
|
||||
|
||||
namespace TDESystemHibernationMethod {
|
||||
enum TDESystemHibernationMethod {
|
||||
Unsupported,
|
||||
Platform,
|
||||
Shutdown,
|
||||
Reboot,
|
||||
TestProc,
|
||||
Test
|
||||
};
|
||||
};
|
||||
|
||||
typedef TQValueList<TDESystemPowerState::TDESystemPowerState> TDESystemPowerStateList;
|
||||
typedef TQValueList<TDESystemHibernationMethod::TDESystemHibernationMethod> TDESystemHibernationMethodList;
|
||||
|
||||
class TDECORE_EXPORT TDERootSystemDevice : public TDEGenericDevice
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
* @param Device type
|
||||
*/
|
||||
TDERootSystemDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn=TQString::null);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~TDERootSystemDevice();
|
||||
|
||||
/**
|
||||
* @return a TDESystemFormFactor::TDESystemFormFactor with the system's form factor
|
||||
*/
|
||||
TDESystemFormFactor::TDESystemFormFactor formFactor();
|
||||
|
||||
/**
|
||||
* @return a TDESystemPowerStateList with all available power states
|
||||
*/
|
||||
TDESystemPowerStateList powerStates();
|
||||
|
||||
/**
|
||||
* @return a TDESystemHibernationMethodList with all available hibernation methods
|
||||
*/
|
||||
TDESystemHibernationMethodList hibernationMethods();
|
||||
|
||||
/**
|
||||
* @return a TDESystemHibernationMethod::TDESystemHibernationMethod with the current hibernation method
|
||||
*/
|
||||
TDESystemHibernationMethod::TDESystemHibernationMethod hibernationMethod();
|
||||
|
||||
/**
|
||||
* @return an unsigned long with the number of bytes required to hibernate
|
||||
*/
|
||||
unsigned long diskSpaceNeededForHibernation();
|
||||
|
||||
/**
|
||||
* @return TRUE if permissions allow the hibernation method to be set, FALSE if not
|
||||
*/
|
||||
bool canSetHibernationMethod();
|
||||
|
||||
/**
|
||||
* @return TRUE if hardware and permissions allow the system to enter standby, FALSE if not
|
||||
*/
|
||||
bool canStandby();
|
||||
|
||||
/**
|
||||
* @return TRUE if hardware and permissions allow the system to be suspended, FALSE if not
|
||||
*/
|
||||
bool canSuspend();
|
||||
|
||||
/**
|
||||
* @return TRUE if hardware and permissions allow the system to be hibernated, FALSE if not
|
||||
*/
|
||||
bool canHibernate();
|
||||
|
||||
/**
|
||||
* @return TRUE if permissions allow the system to be powered down, FALSE if not
|
||||
*/
|
||||
bool canPowerOff();
|
||||
|
||||
/**
|
||||
* @return TRUE if permissions allow the system to be rebooted, FALSE if not
|
||||
*/
|
||||
bool canReboot();
|
||||
|
||||
/**
|
||||
* @param hm a TDESystemHibernationMethod::TDESystemHibernationMethod with the desired hibernation method
|
||||
*/
|
||||
void setHibernationMethod(TDESystemHibernationMethod::TDESystemHibernationMethod hm);
|
||||
|
||||
/**
|
||||
* @param ps a TDESystemPowerState::TDESystemPowerState with the desired power state
|
||||
* @return TRUE if power state was set
|
||||
*/
|
||||
bool setPowerState(TDESystemPowerState::TDESystemPowerState ps);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @param ff a TDESystemFormFactor::TDESystemFormFactor with the system's form factor
|
||||
* @internal
|
||||
*/
|
||||
void internalSetFormFactor(TDESystemFormFactor::TDESystemFormFactor ff);
|
||||
|
||||
/**
|
||||
* @param ps a TDESystemPowerStateList with all available power states
|
||||
* @internal
|
||||
*/
|
||||
void internalSetPowerStates(TDESystemPowerStateList ps);
|
||||
|
||||
/**
|
||||
* @param hm a TDESystemHibernationMethodList with all available hibernation methods
|
||||
* @internal
|
||||
*/
|
||||
void internalSetHibernationMethods(TDESystemHibernationMethodList hm);
|
||||
|
||||
/**
|
||||
* @param hm a TDESystemHibernationMethod::TDESystemHibernationMethod with the current hibernation method
|
||||
* @internal
|
||||
*/
|
||||
void internalSetHibernationMethod(TDESystemHibernationMethod::TDESystemHibernationMethod hm);
|
||||
|
||||
/**
|
||||
* @param sz an unsigned long with the number of bytes required to hibernate
|
||||
* @internal
|
||||
*/
|
||||
void internalSetDiskSpaceNeededForHibernation(unsigned long sz);
|
||||
|
||||
private:
|
||||
TDESystemFormFactor::TDESystemFormFactor m_formFactor;
|
||||
TDESystemPowerStateList m_powerStates;
|
||||
TDESystemHibernationMethodList m_hibernationMethods;
|
||||
TDESystemHibernationMethod::TDESystemHibernationMethod m_hibernationMethod;
|
||||
unsigned long m_hibernationSpace;
|
||||
|
||||
friend class TDEHardwareDevices;
|
||||
};
|
||||
|
||||
#endif // _TDEROOTSYSTEMDEVICE_H
|
@ -0,0 +1,47 @@
|
||||
/* This file is part of the TDE libraries
|
||||
Copyright (C) 2012 Timothy Pearson <kb9vqf@pearsoncomputing.net>
|
||||
(C) 2013 Golubev Alexander <fatzer2@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2 as published by the Free Software Foundation.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "tdesensordevice.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
#include "tdesensordevice.moc"
|
@ -0,0 +1,75 @@
|
||||
/* This file is part of the TDE libraries
|
||||
Copyright (C) 2012 Timothy Pearson <kb9vqf@pearsoncomputing.net>
|
||||
(C) 2013 Golubev Alexander <fatzer2@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2 as published by the Free Software Foundation.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef _TDESENSORDEVICE_H
|
||||
#define _TDESENSORDEVICE_H
|
||||
|
||||
#include "tdegenericdevice.h"
|
||||
|
||||
class TDECORE_EXPORT TDESensorCluster
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
TDESensorCluster();
|
||||
|
||||
TQString label;
|
||||
double current;
|
||||
double minimum;
|
||||
double maximum;
|
||||
double warning;
|
||||
double critical;
|
||||
};
|
||||
|
||||
typedef TQMap<TQString, TDESensorCluster> TDESensorClusterMap;
|
||||
|
||||
class TDECORE_EXPORT TDESensorDevice : public TDEGenericDevice
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
* @param Device type
|
||||
*/
|
||||
TDESensorDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn=TQString::null);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~TDESensorDevice();
|
||||
|
||||
/**
|
||||
* @return a TDESensorClusterMap with the current sensor values
|
||||
*/
|
||||
TDESensorClusterMap values();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @param a TDESensorClusterMap with the current sensor values
|
||||
* @internal
|
||||
*/
|
||||
void internalSetValues(TDESensorClusterMap cl);
|
||||
|
||||
private:
|
||||
TDESensorClusterMap m_sensorValues;
|
||||
|
||||
friend class TDEHardwareDevices;
|
||||
};
|
||||
|
||||
#endif // _TDESENSORDEVICE_H
|
Loading…
Reference in new issue