Merge branch 'tdehardwaredevices-splited' of git://github.com/Fat-Zer/tdelibs

pull/16/head
Timothy Pearson 11 years ago
commit 06fa48d8eb

@ -8,11 +8,11 @@
#
#################################################
configure_file( ${CMAKE_SOURCE_DIR}/kdoctools/update-entities.sh ${CMAKE_SOURCE_DIR}/kdoctools/update-entities IMMEDIATE @ONLY )
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/update-entities.sh ${CMAKE_CURRENT_BINARY_DIR}/update-entities IMMEDIATE @ONLY )
set( UPDATE_SCRIPT "${CMAKE_SOURCE_DIR}/kdoctools/update-entities" )
set( UPDATE_SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/update-entities" )
set( TDEVERSION_FILE "${CMAKE_SOURCE_DIR}/tdecore/tdeversion.h" )
set( ENTITIES_FILE "${CMAKE_SOURCE_DIR}/kdoctools/customization/entities/general.entities" )
set( ENTITIES_FILE "${CMAKE_CURRENT_SOURCE_DIR}/customization/entities/general.entities" )
if( NOT EXISTS ${UPDATE_SCRIPT} )
tde_message_fatal( "${UPDATE_SCRIPT} not found!\n Check your sources." )

@ -12,60 +12,20 @@
add_subdirectory( malloc )
add_subdirectory( network )
add_subdirectory( tdeconfig_compiler )
add_subdirectory( hwlibdata )
add_subdirectory( hwlibdaemons )
if( NOT DBUS_SYSTEM_BUS )
set( DBUS_SYSTEM_BUS "unix:path=/var/run/dbus/system_bus_socket" CACHE INTERNAL "" FORCE )
endif()
if( WITH_UPOWER OR WITH_UDISKS OR WITH_UDISKS2 OR
WITH_NETWORK_MANAGER_BACKEND OR WITH_CONSOLEKIT )
list( APPEND TDEHW_CUSTOM_INCLUDE_DIRS ${DBUS_TQT_INCLUDE_DIRS} )
list( APPEND TDEHW_CUSTOM_LIBRARY_DIRS ${DBUS_TQT_LIBRARY_DIRS} )
list( APPEND TDEHW_CUSTOM_LIBRARIES ${DBUS_TQT_LIBRARIES} )
endif( )
if( WITH_UPOWER )
add_definitions( -DWITH_UPOWER )
endif( )
if( WITH_UDISKS )
add_definitions( -DWITH_UDISKS )
endif( )
if( WITH_UDISKS2 )
add_definitions( -DWITH_UDISKS2 )
endif( )
if( WITH_CONSOLEKIT )
add_definitions( -DWITH_CONSOLEKIT )
endif( )
add_subdirectory( tdehw )
if( WITH_LIBART )
add_subdirectory( svgicons )
set( KDESVGICONS kdesvgicons-static )
endif( WITH_LIBART )
if( WITH_NETWORK_MANAGER_BACKEND )
add_subdirectory( networkbackends/network-manager/dbus )
list( APPEND TDEHW_CUSTOM_INCLUDE_DIRS
${NM_UTIL_INCLUDE_DIRS}
"${CMAKE_CURRENT_BINARY_DIR}/networkbackends/network-manager/dbus"
)
list( APPEND TDEHW_CUSTOM_LIBRARIES
tdenm_dbus-static
)
set ( TDENM_BACKEND_SOURCES networkbackends/network-manager/network-manager.cpp )
endif( WITH_NETWORK_MANAGER_BACKEND )
include_directories(
${TQT_INCLUDE_DIRS}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/network
${CMAKE_CURRENT_SOURCE_DIR}/tdehw
${CMAKE_SOURCE_DIR}/dcop
${CMAKE_SOURCE_DIR}/libltdl
${CMAKE_SOURCE_DIR}/tdefx
@ -74,7 +34,6 @@ include_directories(
${LIBART_INCLUDE_DIRS}
${LIBIDN_INCLUDE_DIRS}
${GAMIN_INCLUDEDIR}
${TDEHW_CUSTOM_INCLUDE_DIRS}
)
link_directories(
@ -82,7 +41,6 @@ link_directories(
${LIBIDN_LIBRARY_DIRS}
${GAMIN_LIBDIR}
${LIBART_LIBRARY_DIRS}
${TDEHW_CUSTOM_LIBRARY_DIRS}
)
##### headers ###################################
@ -111,8 +69,7 @@ install( FILES
kcalendarsystem.h kcalendarsystemfactory.h kmacroexpander.h
kmanagerselection.h kmountpoint.h kuser.h klockfile.h
kidna.h ktempdir.h kshell.h fixx11h.h kxerrorhandler.h
tdelibs_export.h kde_file.h ktimezones.h tdehardwaredevices.h
tdenetworkconnections.h
tdelibs_export.h kde_file.h ktimezones.h
${CMAKE_CURRENT_BINARY_DIR}/kdemacros.h
DESTINATION ${INCLUDE_INSTALL_DIR} )
@ -168,16 +125,15 @@ set( ${target}_SRCS
ktempdir.cpp kshell.cpp kmountpoint.cpp kcalendarsystemjalali.cpp
kprotocolinfo_tdecore.cpp kprotocolinfofactory.cpp kxerrorhandler.cpp
kuser.cpp tdeconfigskeleton.cpp tdeconfigdialogmanager.cpp klockfile.cpp
kqiodevicegzip_p.cpp ktimezones.cpp tdehardwaredevices.cpp tdenetworkconnections.cpp
ksimpledirwatch.cpp
${TDENM_BACKEND_SOURCES}
kqiodevicegzip_p.cpp ktimezones.cpp ksimpledirwatch.cpp
)
tde_add_library( ${target} SHARED AUTOMOC
SOURCES ${${target}_SRCS}
VERSION 4.2.0
EMBED tdecorenetwork-static
LINK ltdlc-static ${KDESVGICONS} DCOP-shared tdefx-shared ${ZLIB_LIBRARIES} ${LIBIDN_LIBRARIES} ${XCOMPOSITE_LIBRARIES} ICE SM udev ${GAMIN_LIBRARIES} ${TDEHW_CUSTOM_LIBRARIES}
EMBED tdecorenetwork-static tdehw-static
LINK ltdlc-static ${KDESVGICONS} DCOP-shared tdefx-shared ${ZLIB_LIBRARIES}
${LIBIDN_LIBRARIES} ${XCOMPOSITE_LIBRARIES} ICE SM ${GAMIN_LIBRARIES}
DEPENDENCIES dcopidl dcopidl2cpp
DESTINATION ${LIB_INSTALL_DIR}
)

File diff suppressed because it is too large Load Diff

@ -0,0 +1,90 @@
#################################################
#
# (C) 2013 Golubev Alexander
# fatzer2 (AT) gmail.com
#
# Improvements and feedback are welcome
#
# This file is released under GPL >= 2
#
#################################################
add_subdirectory( hwlibdata )
add_subdirectory( hwlibdaemons )
add_subdirectory( networkbackends )
if( NOT DBUS_SYSTEM_BUS )
set( DBUS_SYSTEM_BUS "unix:path=/var/run/dbus/system_bus_socket" CACHE INTERNAL "" FORCE )
endif()
if( WITH_UPOWER OR WITH_UDISKS OR WITH_UDISKS2 OR
WITH_NETWORK_MANAGER_BACKEND OR WITH_CONSOLEKIT )
list( APPEND TDEHW_CUSTOM_INCLUDE_DIRS ${DBUS_TQT_INCLUDE_DIRS} )
list( APPEND TDEHW_CUSTOM_LIBRARY_DIRS ${DBUS_TQT_LIBRARY_DIRS} )
list( APPEND TDEHW_CUSTOM_LIBRARIES ${DBUS_TQT_LIBRARIES} )
endif( )
if( WITH_UPOWER )
add_definitions( -DWITH_UPOWER )
endif( )
if( WITH_UDISKS )
add_definitions( -DWITH_UDISKS )
endif( )
if( WITH_UDISKS2 )
add_definitions( -DWITH_UDISKS2 )
endif( )
if( WITH_CONSOLEKIT )
add_definitions( -DWITH_CONSOLEKIT )
endif( )
if( WITH_NETWORK_MANAGER_BACKEND )
list( APPEND TDEHW_CUSTOM_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/networkbackends/network-manager )
list( APPEND TDEHW_CUSTOM_LIBRARIES network_manager_backend-static )
endif( WITH_NETWORK_MANAGER_BACKEND )
include_directories(
${TQT_INCLUDE_DIRS}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_BINARY_DIR}/tdecore
${CMAKE_SOURCE_DIR}/tdecore
${CMAKE_SOURCE_DIR}/dcop
${TDEHW_CUSTOM_INCLUDE_DIRS}
)
link_directories(
${TQT_LIBRARY_DIRS}
${TDEHW_CUSTOM_LIBRARY_DIRS}
)
##### headers ###################################
install( FILES tdehardwaredevices.h tdenetworkconnections.h tdegenericdevice.h
tdestoragedevice.h tdecpudevice.h tdebatterydevice.h tdemainspowerdevice.h
tdenetworkdevice.h tdebacklightdevice.h tdemonitordevice.h
tdesensordevice.h tderootsystemdevice.h tdeeventdevice.h tdeinputdevice.h
tdehwcommontypes.h
DESTINATION ${INCLUDE_INSTALL_DIR} )
##### libtdecore ################################
set( target tdehw )
set( ${target}_SRCS
tdehardwaredevices.cpp tdenetworkconnections.cpp tdegenericdevice.cpp
tdestoragedevice.cpp tdecpudevice.cpp tdebatterydevice.cpp
tdemainspowerdevice.cpp tdenetworkdevice.cpp tdebacklightdevice.cpp
tdemonitordevice.cpp tdesensordevice.cpp tderootsystemdevice.cpp
tdeeventdevice.cpp tdeinputdevice.cpp
)
tde_add_library( ${target} STATIC_PIC AUTOMOC
SOURCES ${${target}_SRCS}
LINK udev ${TDENM_LIBRARIES} ${TDEUPOWER_LIBRARIES}
${TDEHW_CUSTOM_LIBRARIES}
)

@ -0,0 +1,12 @@
#################################################
#
# (C) 2013 Golubev Alexander
# fatzer2 (AT) gmail.com
#
# Improvements and feedback are welcome
#
# This file is released under GPL >= 2
#
#################################################
tde_conditional_add_subdirectory( WITH_NETWORK_MANAGER_BACKEND network-manager )

@ -0,0 +1,36 @@
#################################################
#
# (C) 2013 Golubev Alexander
# fatzer2 (AT) gmail.com
#
# Improvements and feedback are welcome
#
# This file is released under GPL >= 2
#
#################################################
add_subdirectory( dbus-introspection )
include_directories (
${TQT_INCLUDE_DIRS}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${DBUS_TQT_INCLUDE_DIRS}
${NM_UTIL_INCLUDE_DIRS}
${CMAKE_BINARY_DIR}/tdecore
${CMAKE_SOURCE_DIR}/tdecore
${CMAKE_SOURCE_DIR}/tdecore/tdehw
${CMAKE_CURRENT_BINARY_DIR}/dbus-introspection
)
link_directories(
${TQT_LIBRARY_DIRS}
${DBUS_TQT_LIBRARY_DIRS}
)
tde_add_library( network_manager_backend STATIC_PIC AUTOMOC
SOURCES network-manager.cpp
EMBED tdenm_dbus-static
LINK tdenm_dbus-static ${DBUS_TQT_LIBRARIES}
)

@ -18,7 +18,7 @@ include_directories(
##### tdenm_dbus (static) #########################
set( INTROSPECTIONPATH "${CMAKE_SOURCE_DIR}/tdecore/networkbackends/network-manager/introspection" )
set( INTROSPECTIONPATH ${CMAKE_CURRENT_SOURCE_DIR} )
# options:
# p - generate proxy files
@ -59,19 +59,9 @@ set( MOCHEADERS accesspointproxy.h deviceproxy.h networkmanagerproxy.h networkma
networkmanagersettings.h connectionsettings.h )
foreach( _header_file ${MOCHEADERS} )
get_filename_component( _basename "${_header_file}" NAME_WE )
set( _moc_file ${_basename}.moc )
list( APPEND _moc_files ${_moc_file} )
add_custom_command( OUTPUT ${_moc_file}
COMMAND ${TMOC_EXECUTABLE} ${_header_file} -o ${_moc_file}
DEPENDS ${_header_file} )
tde_moc( MOCSOURCES ${CMAKE_CURRENT_BINARY_DIR}/${_header_file} )
endforeach( )
add_custom_command( OUTPUT mocfiles.cpp
COMMAND cat ${_moc_files} > mocfiles.cpp
DEPENDS ${_moc_files} )
# build the library
tde_add_library( tdenm_dbus STATIC_PIC
@ -80,6 +70,6 @@ tde_add_library( tdenm_dbus STATIC_PIC
deviceproxy.cpp bluetoothproxy.cpp olpcmeshproxy.cpp ethernetproxy.cpp
infinibandproxy.cpp wifiproxy.cpp wimaxproxy.cpp accesspointproxy.cpp
networkmanagersettings.cpp connectionsettings.cpp
mocfiles.cpp activeconnectionproxy.cpp vpnconnectionproxy.cpp
vpnpluginproxy.cpp modemproxy.cpp
activeconnectionproxy.cpp vpnconnectionproxy.cpp
vpnpluginproxy.cpp modemproxy.cpp ${MOCSOURCES}
)

@ -22,6 +22,7 @@
#include "tdeconfig.h"
#include "tdehardwaredevices.h"
#include "tdenetworkdevice.h"
#include "network-manager.h"
#include "network-manager_p.h"

@ -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,151 @@
/* 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 "tdebatterydevice.h"
#include "config.h"
TDEBatteryDevice::TDEBatteryDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) {
}
TDEBatteryDevice::~TDEBatteryDevice() {
}
double TDEBatteryDevice::voltage() {
return m_currentVoltage;
}
void TDEBatteryDevice::internalSetVoltage(double vt) {
m_currentVoltage = vt;
}
double TDEBatteryDevice::maximumVoltage() {
return m_maximumVoltage;
}
void TDEBatteryDevice::internalSetMaximumVoltage(double vt) {
m_maximumVoltage = vt;
}
double TDEBatteryDevice::minimumVoltage() {
return m_minimumVoltage;
}
void TDEBatteryDevice::internalSetMinimumVoltage(double vt) {
m_minimumVoltage = vt;
}
double TDEBatteryDevice::maximumDesignVoltage() {
return m_maximumDesignVoltage;
}
void TDEBatteryDevice::internalSetMaximumDesignVoltage(double vt) {
m_maximumDesignVoltage = vt;
}
double TDEBatteryDevice::energy() {
return m_currentEnergy;
}
void TDEBatteryDevice::internalSetEnergy(double vt) {
m_currentEnergy = vt;
}
double TDEBatteryDevice::alarmEnergy() {
return m_alarmEnergy;
}
void TDEBatteryDevice::internalSetAlarmEnergy(double vt) {
m_alarmEnergy = vt;
}
double TDEBatteryDevice::maximumEnergy() {
return m_maximumEnergy;
}
void TDEBatteryDevice::internalSetMaximumEnergy(double vt) {
m_maximumEnergy = vt;
}
double TDEBatteryDevice::maximumDesignEnergy() {
return m_maximumDesignEnergy;
}
void TDEBatteryDevice::internalSetMaximumDesignEnergy(double vt) {
m_maximumDesignEnergy = vt;
}
double TDEBatteryDevice::dischargeRate() {
return m_dischargeRate;
}
void TDEBatteryDevice::internalSetDischargeRate(double vt) {
m_dischargeRate = vt;
}
double TDEBatteryDevice::timeRemaining() {
return m_timeRemaining;
}
void TDEBatteryDevice::internalSetTimeRemaining(double tr) {
m_timeRemaining = tr;
}
TQString TDEBatteryDevice::technology() {
return m_technology;
}
void TDEBatteryDevice::internalSetTechnology(TQString tc) {
m_technology = tc;
}
TDEBatteryStatus::TDEBatteryStatus TDEBatteryDevice::status() {
return m_status;
}
void TDEBatteryDevice::internalSetStatus(TQString tc) {
tc = tc.lower();
if (tc == "charging") {
m_status = TDEBatteryStatus::Charging;
}
else if (tc == "discharging") {
m_status = TDEBatteryStatus::Discharging;
}
else if (tc == "full") {
m_status = TDEBatteryStatus::Full;
}
else {
m_status = TDEBatteryStatus::Unknown;
}
}
bool TDEBatteryDevice::installed() {
return m_installed;
}
void TDEBatteryDevice::internalSetInstalled(bool tc) {
m_installed = tc;
}
double TDEBatteryDevice::chargePercent() {
return (m_currentEnergy/m_maximumEnergy)*100.0;
}
#include "tdebatterydevice.moc"

@ -0,0 +1,215 @@
/* 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 _TDEBATTERYDEVICE_H
#define _TDEBATTERYDEVICE_H
#include "tdegenericdevice.h"
namespace TDEBatteryStatus {
enum TDEBatteryStatus {
Charging,
Discharging,
Full,
Unknown = 0x80000000
};
};
class TDECORE_EXPORT TDEBatteryDevice : public TDEGenericDevice
{
public:
/**
* Constructor.
* @param Device type
*/
TDEBatteryDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn=TQString::null);
/**
* Destructor.
*/
~TDEBatteryDevice();
/**
* @return a double with the current battery voltage, if available
*/
double voltage();
/**
* @return a double with the minimum battery voltage, if available
*/
double minimumVoltage();
/**
* @return a double with the maximum battery voltage, if available
*/
double maximumVoltage();
/**
* @return a double with the designed maximum battery voltage, if available
*/
double maximumDesignVoltage();
/**
* @return a double with the current battery energy in watt-hours, if available
*/
double energy();
/**
* @return a double with the current battery alarm energy in watt-hours, if available
*/
double alarmEnergy();
/**
* @return a double with the maximum battery energy in watt-hours, if available
*/
double maximumEnergy();
/**
* @return a double with the designed maximum battery energy in watt-hours, if available
*/
double maximumDesignEnergy();
/**
* @return a double with the current battery discharge rate in watt-hours, if available
*/
double dischargeRate();
/**
* @return a double with the current battery discharge time remaining in seconds, if available
*/
double timeRemaining();
/**
* @return a TQString with the battery technology, if available
*/
TQString technology();
/**
* @return a TDEBatteryStatus::TDEBatteryStatus with the current battery status
*/
TDEBatteryStatus::TDEBatteryStatus status();
/**
* @return TRUE if the battery is installed
*/
bool installed();
/**
* @return a double with the current battery charge in percent, if available
*/
double chargePercent();
protected:
/**
* @param a double with the current battery voltage, if available
* @internal
*/
void internalSetVoltage(double vt);
/**
* @param a double with the minimum battery voltage, if available
* @internal
*/
void internalSetMinimumVoltage(double vt);
/**
* @param a double with the maximum battery voltage, if available
* @internal
*/
void internalSetMaximumVoltage(double vt);
/**
* @param a double with the designed maximum battery voltage, if available
* @internal
*/
void internalSetMaximumDesignVoltage(double vt);
/**
* @param a double with the current battery energy in watt-hours, if available
* @internal
*/
void internalSetEnergy(double vt);
/**
* @param a double with the current battery alarm energy in watt-hours, if available
* @internal
*/
void internalSetAlarmEnergy(double vt);
/**
* @param a double with the maximum battery energy in watt-hours, if available
* @internal
*/
void internalSetMaximumEnergy(double vt);
/**
* @param a double with the designed maximum battery energy in watt-hours, if available
* @internal
*/
void internalSetMaximumDesignEnergy(double vt);
/**
* @param a double with the current battery discharge rate in volt-hours, if available
* @internal
*/
void internalSetDischargeRate(double vt);
/**
* @param a double with the current battery discharge time remaining in seconds, if available
* @internal
*/
void internalSetTimeRemaining(double tr);
/**
* @param a TQString with the battery technology, if available
* @internal
*/
void internalSetTechnology(TQString tc);
/**
* @param a TQString with the battery status, if available
* @internal
*/
void internalSetStatus(TQString tc);
/**
* @param TRUE if the battery is installed
* @internal
*/
void internalSetInstalled(bool tc);
private:
double m_currentVoltage;
double m_minimumVoltage;
double m_maximumVoltage;
double m_maximumDesignVoltage;
double m_alarmEnergy;
double m_currentEnergy;
double m_maximumEnergy;
double m_maximumDesignEnergy;
double m_dischargeRate;
double m_timeRemaining;
TQString m_technology;
TDEBatteryStatus::TDEBatteryStatus m_status;
bool m_installed;
friend class TDEHardwareDevices;
};
#endif // _TDEBATTERYDEVICE_H

@ -0,0 +1,226 @@
/* 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 "tdecpudevice.h"
#include <unistd.h>
#include <tqfile.h>
#include "tdeglobal.h"
#include "tdehardwaredevices.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)
TDECPUDevice::TDECPUDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) {
m_frequency = -1;
m_minfrequency = -1;
m_maxfrequency = -1;
m_corenumber = -1;
m_transitionlatency = -1;
}
TDECPUDevice::~TDECPUDevice() {
}
double TDECPUDevice::frequency() {
return m_frequency;
}
void TDECPUDevice::internalSetFrequency(double fr) {
m_frequency = fr;
}
double TDECPUDevice::minFrequency() {
return m_minfrequency;
}
void TDECPUDevice::internalSetMinFrequency(double fr) {
m_minfrequency = fr;
}
double TDECPUDevice::maxFrequency() {
return m_maxfrequency;
}
void TDECPUDevice::internalSetMaxFrequency(double fr) {
m_maxfrequency = fr;
}
double TDECPUDevice::transitionLatency() {
return m_transitionlatency;
}
void TDECPUDevice::internalSetTransitionLatency(double tl) {
m_transitionlatency = tl;
}
TQString TDECPUDevice::governor() {
return m_governor;
}
void TDECPUDevice::internalSetGovernor(TQString gr) {
m_governor = gr;
}
TQString TDECPUDevice::scalingDriver() {
return m_scalingdriver;
}
void TDECPUDevice::internalSetScalingDriver(TQString dr) {
m_scalingdriver = dr;
}
TQStringList TDECPUDevice::dependentProcessors() {
return m_tiedprocs;
}
void TDECPUDevice::internalSetDependentProcessors(TQStringList dp) {
m_tiedprocs = dp;
}
TQStringList TDECPUDevice::availableFrequencies() {
return m_frequencies;
}
void TDECPUDevice::internalSetAvailableFrequencies(TQStringList af) {
m_frequencies = af;
}
TQStringList TDECPUDevice::availableGovernors() {
return m_governers;
}
void TDECPUDevice::internalSetAvailableGovernors(TQStringList gp) {
m_governers = gp;
}
void TDECPUDevice::internalSetCoreNumber(int cn) {
m_corenumber = cn;
}
bool TDECPUDevice::canSetGovernor() {
TQString governornode = systemPath() + "/cpufreq/scaling_governor";
int rval = access (governornode.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.CPUGovernor", dbusConn);
if (hardwareControl.canSend()) {
// can set CPU governor?
TQValueList<TQT_DBusData> params;
params << TQT_DBusData::fromInt32(coreNumber());
TQT_DBusMessage reply = hardwareControl.sendWithReply("CanSetCPUGovernor", 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
}
}
void TDECPUDevice::setGovernor(TQString gv) {
TQString governornode = systemPath() + "/cpufreq/scaling_governor";
TQFile file( governornode );
if ( file.open( IO_WriteOnly ) ) {
TQTextStream stream( &file );
stream << gv.lower();
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.CPUGovernor", dbusConn);
if (hardwareControl.canSend()) {
// set CPU governor
TQValueList<TQT_DBusData> params;
params << TQT_DBusData::fromInt32(coreNumber()) << TQT_DBusData::fromString(gv.lower());
hardwareControl.sendWithReply("SetCPUGovernor", params);
}
else {
return;
}
}
else {
return;
}
}
#endif // WITH_UPOWER
// Force update of the device information object
TDEGlobal::hardwareDevices()->processModifiedCPUs();
}
bool TDECPUDevice::canSetMaximumScalingFrequency() {
TQString freqnode = systemPath() + "/cpufreq/scaling_max_freq";
int rval = access (freqnode.ascii(), W_OK);
if (rval == 0) {
return TRUE;
}
else {
return FALSE;
}
}
void TDECPUDevice::setMaximumScalingFrequency(double fr) {
TQString freqnode = systemPath() + "/cpufreq/scaling_max_freq";
TQFile file( freqnode );
if ( file.open( IO_WriteOnly ) ) {
TQTextStream stream( &file );
stream << TQString("%1").arg(fr*1000000.0, 0, 'f', 0);
file.close();
}
// Force update of the device information object
TDEGlobal::hardwareDevices()->processModifiedCPUs();
}
int TDECPUDevice::coreNumber() {
return m_corenumber;
}
#include "tdecpudevice.moc"

@ -0,0 +1,186 @@
/* 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 _TDECPUDEVICE_H
#define _TDECPUDEVICE_H
#include "tdegenericdevice.h"
class TDECORE_EXPORT TDECPUDevice : public TDEGenericDevice
{
public:
/**
* Constructor.
* @param Device type
*/
TDECPUDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn=TQString::null);
/**
* Destructor.
*/
~TDECPUDevice();
/**
* @return a double with the current CPU frequency in MHz, if available
*/
double frequency();
/**
* @return a double with the minimum CPU frequency in MHz, if available
*/
double minFrequency();
/**
* @return a double with the maximum CPU frequency in MHz, if available
*/
double maxFrequency();
/**
* @return a double with the transition latency in ns, if available
*/
double transitionLatency();
/**
* @return a TQString with the current CPU governor policy, if available
*/
TQString governor();
/**
* @return a TQString with the current CPU scaling driver, if available
*/
TQString scalingDriver();
/**
* @return a TQStringList with the IDs of all processors that are dependent on the frequency/power settings of this one, if available
*/
TQStringList dependentProcessors();
/**
* @return a TQStringList with all valid scaling frequencies in Hz, if available
*/
TQStringList availableFrequencies();
/**
* @return a TQStringList with all available governor policies, if available
*/
TQStringList availableGovernors();
/**
* @return TRUE if permissions allow the CPU governor to be set, FALSE if not
*/
bool canSetGovernor();
/**
* @param gv a TQString with the new CPU governor policy name
*/
void setGovernor(TQString gv);
/**
* @return TRUE if permissions allow the CPU maximum frequency to be set, FALSE if not
*/
bool canSetMaximumScalingFrequency();
/**
* @param gv a double with the new CPU maximum frequency in MHz
*/
void setMaximumScalingFrequency(double fr);
/**
* @return an integer with the core number, starting at 0
*/
int coreNumber();
protected:
/**
* @param fr a double with the current CPU frequency in MHz, if available
* @internal
*/
void internalSetFrequency(double fr);
/**
* @param fr a double with the minimum CPU frequency in MHz, if available
* @internal
*/
void internalSetMinFrequency(double fr);
/**
* @param fr a double with the maximum CPU frequency in MHz, if available
* @internal
*/
void internalSetMaxFrequency(double fr);
/**
* @param tl a double with the transition latency in ns, if available
* @internal
*/
void internalSetTransitionLatency(double tl);
/**
* @param gr a TQString with the current CPU governor policy, if available
* @internal
*/
void internalSetGovernor(TQString gr);
/**
* @param dr a TQString with the current CPU scaling driver, if available
* @internal
*/
void internalSetScalingDriver(TQString dr);
/**
* @param dp a TQStringList with the IDs of all processors that are dependent on the frequency/power settings of this one, if available
* @internal
*/
void internalSetDependentProcessors(TQStringList dp);
/**
* @param af a TQStringList with all valid scaling frequencies in Hz, if available
* @internal
*/
void internalSetAvailableFrequencies(TQStringList af);
/**
* @param gp a TQStringList with all available governor policies, if available
* @internal
*/
void internalSetAvailableGovernors(TQStringList gp);
/**
* @param cn an integer with the core number, starting at 0
* @internal
*/
void internalSetCoreNumber(int cn);
private:
double m_frequency;
double m_minfrequency;
double m_maxfrequency;
double m_transitionlatency;
TQString m_governor;
TQString m_scalingdriver;
TQStringList m_tiedprocs;
TQStringList m_frequencies;
TQStringList m_governers;
int m_corenumber;
friend class TDEHardwareDevices;
};
#endif // _TDECPUDEVICE_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,319 @@
/* 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 "tdegenericdevice.h"
#include <tqpixmap.h>
#include "tdeglobal.h"
#include "tdelocale.h"
#include "tdehardwaredevices.h"
#include "config.h"
TDEGenericDevice::TDEGenericDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TQObject() {
m_deviceType = dt;
m_deviceName = dn;
m_parentDevice = 0;
m_friendlyName = TQString::null;
m_blacklistedForUpdate = false;
}
TDEGenericDevice::~TDEGenericDevice() {
}
TDEGenericDeviceType::TDEGenericDeviceType TDEGenericDevice::type() {
return m_deviceType;
}
TQString TDEGenericDevice::name() {
return m_deviceName;
}
void TDEGenericDevice::internalSetName(TQString dn) {
m_deviceName = dn;
}
TQString TDEGenericDevice::vendorName() {
return m_vendorName;
}
void TDEGenericDevice::internalSetVendorName(TQString vn) {
m_vendorName = vn;
}
TQString TDEGenericDevice::vendorModel() {
return m_vendorModel;
}
void TDEGenericDevice::internalSetVendorModel(TQString vm) {
m_vendorModel = vm;
}
TQString TDEGenericDevice::serialNumber() {
return m_serialNumber;
}
void TDEGenericDevice::internalSetSerialNumber(TQString sn) {
m_serialNumber = sn;
}
TQString TDEGenericDevice::systemPath() {
if (!m_systemPath.endsWith("/")) {
m_systemPath += "/";
}
return m_systemPath;
}
void TDEGenericDevice::internalSetSystemPath(TQString sp) {
m_systemPath = sp;
}
TQString TDEGenericDevice::deviceNode() {
return m_deviceNode;
}
void TDEGenericDevice::internalSetDeviceNode(TQString sn) {
m_deviceNode = sn;
}
TQString TDEGenericDevice::deviceBus() {
return m_deviceBus;
}
void TDEGenericDevice::internalSetDeviceBus(TQString db) {
m_deviceBus = db;
}
TQString TDEGenericDevice::uniqueID() {
m_uniqueID = m_systemPath+m_deviceNode;
return m_uniqueID;
}
TQString TDEGenericDevice::vendorID() {
return m_vendorID;
}
void TDEGenericDevice::internalSetVendorID(TQString id) {
m_vendorID = id;
m_vendorID.replace("0x", "");
}
TQString TDEGenericDevice::modelID() {
return m_modelID;
}
void TDEGenericDevice::internalSetModelID(TQString id) {
m_modelID = id;
m_modelID.replace("0x", "");
}
TQString TDEGenericDevice::vendorEncoded() {
return m_vendorenc;
}
void TDEGenericDevice::internalSetVendorEncoded(TQString id) {
m_vendorenc = id;
}
TQString TDEGenericDevice::modelEncoded() {
return m_modelenc;
}
void TDEGenericDevice::internalSetModelEncoded(TQString id) {
m_modelenc = id;
}
TQString TDEGenericDevice::subVendorID() {
return m_subvendorID;
}
void TDEGenericDevice::internalSetSubVendorID(TQString id) {
m_subvendorID = id;
m_subvendorID.replace("0x", "");
}
TQString TDEGenericDevice::PCIClass() {
return m_pciClass;
}
void TDEGenericDevice::internalSetPCIClass(TQString cl) {
m_pciClass = cl;
m_pciClass.replace("0x", "");
}
TQString TDEGenericDevice::moduleAlias() {
return m_modAlias;
}
void TDEGenericDevice::internalSetModuleAlias(TQString ma) {
m_modAlias = ma;
}
TQString TDEGenericDevice::deviceDriver() {
return m_deviceDriver;
}
void TDEGenericDevice::internalSetDeviceDriver(TQString dr) {
m_deviceDriver = dr;
}
TQString TDEGenericDevice::subsystem() {
return m_subsystem;
}
void TDEGenericDevice::internalSetSubsystem(TQString ss) {
m_subsystem = ss;
}
TQString TDEGenericDevice::subModelID() {
return m_submodelID;
}
void TDEGenericDevice::internalSetSubModelID(TQString id) {
m_submodelID = id;
m_submodelID.replace("0x", "");
}
void TDEGenericDevice::internalSetParentDevice(TDEGenericDevice* pd) {
m_parentDevice = pd;
}
TDEGenericDevice* TDEGenericDevice::parentDevice() {
return m_parentDevice;
}
TQPixmap TDEGenericDevice::icon(TDEIcon::StdSizes size) {
return TDEGlobal::hardwareDevices()->getDeviceTypeIconFromType(type(), size);
}
bool TDEGenericDevice::blacklistedForUpdate() {
return m_blacklistedForUpdate;
}
void TDEGenericDevice::internalSetBlacklistedForUpdate(bool bl) {
m_blacklistedForUpdate = bl;
}
TQString TDEGenericDevice::friendlyDeviceType() {
return TDEGlobal::hardwareDevices()->getFriendlyDeviceTypeStringFromType(type());
}
TQString TDEGenericDevice::busID() {
TQString busid = m_systemPath;
busid = busid.remove(0, busid.findRev("/")+1);
busid = busid.remove(0, busid.find(":")+1);
return busid;
}
TQString TDEGenericDevice::friendlyName() {
if (m_friendlyName.isNull()) {
if (type() == TDEGenericDeviceType::RootSystem) {
m_friendlyName = "Linux System";
}
else if (type() == TDEGenericDeviceType::Root) {
TQString friendlyDriverName = systemPath();
friendlyDriverName.truncate(friendlyDriverName.length()-1);
friendlyDriverName.remove(0, friendlyDriverName.findRev("/")+1);
m_friendlyName = friendlyDriverName;
}
else if (m_modAlias.lower().startsWith("pci")) {
m_friendlyName = TDEGlobal::hardwareDevices()->findPCIDeviceName(m_vendorID, m_modelID, m_subvendorID, m_submodelID);
}
else if (m_modAlias.lower().startsWith("usb")) {
m_friendlyName = TDEGlobal::hardwareDevices()->findUSBDeviceName(m_vendorID, m_modelID, m_subvendorID, m_submodelID);
}
else {
TQString acpigentype = systemPath();
acpigentype.truncate(acpigentype.length()-1);
acpigentype.remove(0, acpigentype.findRev("/")+1);
TQString pnpgentype = acpigentype;
pnpgentype.truncate(pnpgentype.find(":"));
if (pnpgentype.startsWith("PNP")) {
m_friendlyName = TDEGlobal::hardwareDevices()->findPNPDeviceName(pnpgentype);
}
else if (acpigentype.startsWith("device:")) {
acpigentype.remove(0, acpigentype.findRev(":")+1);
acpigentype.prepend("0x");
m_friendlyName = i18n("ACPI Node %1").arg(acpigentype.toUInt(0,0));
}
}
}
if (m_friendlyName.isNull()) {
// Could not identify based on model/vendor codes
// Try to construct something from the model/vendor strings if they are available
if (!m_vendorName.isNull() && !m_vendorModel.isNull()) {
m_friendlyName = m_vendorName + " " + m_vendorModel;
}
}
if (m_friendlyName.isNull()) {
// Could not identify based on model/vendor
// Guess by type
if (type() == TDEGenericDeviceType::CPU) {
m_friendlyName = name();
}
else if (type() == TDEGenericDeviceType::Event) {
// Use parent node name
if (m_parentDevice) {
return m_parentDevice->friendlyName();
}
else {
m_friendlyName = i18n("Generic Event Device");
}
}
else if (type() == TDEGenericDeviceType::Input) {
// Use parent node name
if (m_parentDevice) {
return m_parentDevice->friendlyName();
}
else {
m_friendlyName = i18n("Generic Input Device");
}
}
// Guess by driver
else if (!m_deviceDriver.isNull()) {
TQString friendlyDriverName = m_deviceDriver.lower();
friendlyDriverName[0] = friendlyDriverName[0].upper();
m_friendlyName = i18n("Generic %1 Device").arg(friendlyDriverName);
}
else if (m_systemPath.lower().startsWith("/sys/devices/virtual")) {
TQString friendlyDriverName = systemPath();
friendlyDriverName.truncate(friendlyDriverName.length()-1);
friendlyDriverName.remove(0, friendlyDriverName.findRev("/")+1);
if (!friendlyDriverName.isNull()) {
m_friendlyName = i18n("Virtual Device %1").arg(friendlyDriverName);
}
else {
m_friendlyName = i18n("Unknown Virtual Device");
}
}
else {
// I really have no idea what this peripheral is; say so!
m_friendlyName = i18n("Unknown Device") + " " + name();
}
}
return m_friendlyName;
}
#include "tdegenericdevice.moc"

@ -0,0 +1,334 @@
/* 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 _TDEGENERICDEVICE_H
#define _TDEGENERICDEVICE_H
#include <tqobject.h>
#include <tqstring.h>
#include "tdelibs_export.h"
#include "kicontheme.h"
#include "tdehwcommontypes.h"
class TDECORE_EXPORT TDEGenericDevice : public TQObject
{
Q_OBJECT
public:
/**
* Constructor.
* @param Device type
*/
TDEGenericDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn=TQString::null);
/**
* Destructor.
*/
~TDEGenericDevice();
/**
* @return a TDEGenericDeviceType::TDEGenericDeviceType specifying the device type
*/
TDEGenericDeviceType::TDEGenericDeviceType type();
/**
* @return a TQString with the device name, if any
*/
TQString name();
/**
* @return a TQString with the vendor name, if any
*/
TQString vendorName();
/**
* @return a TQString with the vendor model, if any
*/
TQString vendorModel();
/**
* @return a TQString with the serial number, if any
*/
TQString serialNumber();
/**
* @return a TQString with a friendly name
*
* While TDE tries very hard to generate and return a friendly name for this device,
* sometimes the best it will be able to do is "Unknown Device [xxxx:yyyy]"
*/
virtual TQString friendlyName();
/**
* @return a TQString with the device bus name, if any
*/
TQString deviceBus();
/**
* @return a TQString with the system path, if any
*
* This method is non-portable, so be careful!
*/
TQString systemPath();
/**
* @return a TQString with the system device node, if any
*
* This method is non-portable, so be careful!
*/
TQString deviceNode();
/**
* @return true if this device has been blacklisted for update actions
*/
bool blacklistedForUpdate();
/**
* @return a TQString containing a unique identifier for this device
*/
TQString uniqueID();
/**
* @return a TQString with the vendor ID, if any
*/
TQString vendorID();
/**
* @return a TQString with the model ID, if any
*/
TQString modelID();
/**
* @return a TQString with the encoded vendor, if any
*/
TQString vendorEncoded();
/**
* @return a TQString with the encoded model, if any
*/
TQString modelEncoded();
/**
* @return a TQString with the subvendor ID, if any
*/
TQString subVendorID();
/**
* @return a TQString with the submodel ID, if any
*/
TQString subModelID();
/**
* @return a TQString with the PCI device class, if any
*/
TQString PCIClass();
/**
* @return a TQString with the module alias string, if any
*/
TQString moduleAlias();
/**
* @return a TQString with the device driver, if any
*/
TQString deviceDriver();
/**
* @return a TQString with the subsystem type, if any
*/
TQString subsystem();
/**
* @return a TDEGenericDevice* with the parent device, if any
*/
TDEGenericDevice* parentDevice();
/**
* @return a TQString containing the friendly type name
*/
virtual TQString friendlyDeviceType();
/**
* @return a TQString containing the device bus ID, if any
*/
TQString busID();
/**
* Get an icon for this device
* @param size a TDEIcon::StdSizes structure specifying the desired icon size
* @return a TQPixmap containing the icon for the specified type
*/
virtual TQPixmap icon(TDEIcon::StdSizes size);
protected:
/**
* @param a TQString with the device name, if any
* @internal
*/
void internalSetName(TQString dn);
/**
* @param a TQString with the vendor name, if any
* @internal
*/
void internalSetVendorName(TQString vn);
/**
* @param a TQString with the vendor model, if any
* @internal
*/
void internalSetVendorModel(TQString vm);
/**
* @param a TQString with the serial number, if any
* @internal
*/
void internalSetSerialNumber(TQString sn);
/**
* @param a TQString with the device bus name, if any
* @internal
*/
void internalSetDeviceBus(TQString db);
/**
* @param a TQString with the system path, if any
* @internal
*
* This method is non-portable, so be careful!
*/
void internalSetSystemPath(TQString sp);
/**
* @param a TQString with the system device node, if any
* @internal
*
* This method is non-portable, so be careful!
*/
void internalSetDeviceNode(TQString sn);
/**
* @param bl true if this device has been blacklisted for update actions
* @internal
*/
void internalSetBlacklistedForUpdate(bool bl);
/**
* @param a TQString with the vendor ID, if any
* @internal
*/
void internalSetVendorID(TQString id);
/**
* @param a TQString with the model ID, if any
* @internal
*/
void internalSetModelID(TQString id);
/**
* @param a TQString with the encoded vendor, if any
* @internal
*/
void internalSetVendorEncoded(TQString id);
/**
* @param a TQString with the encoded model, if any
* @internal
*/
void internalSetModelEncoded(TQString id);
/**
* @param a TQString with the subvendor ID, if any
* @internal
*/
void internalSetSubVendorID(TQString id);
/**
* @param a TQString with the submodel ID, if any
* @internal
*/
void internalSetSubModelID(TQString id);
/**
* @param a TQString with the PCI device class, if any
* @internal
*/
void internalSetPCIClass(TQString cl);
/**
* @param a TQString with the module alias string, if any
* @internal
*/
void internalSetModuleAlias(TQString ma);
/**
* @param a TQString with the device driver, if any
* @internal
*/
void internalSetDeviceDriver(TQString dr);
/**
* @param a TQString with the subsystem type, if any
* @internal
*/
void internalSetSubsystem(TQString ss);
/**
* @param a TDEGenericDevice* with the parent device, if any
* @internal
*/
void internalSetParentDevice(TDEGenericDevice* pd);
private:
TDEGenericDeviceType::TDEGenericDeviceType m_deviceType;
TQString m_deviceName;
TQString m_systemPath;
TQString m_deviceNode;
TQString m_vendorName;
TQString m_vendorModel;
TQString m_serialNumber;
TQString m_deviceBus;
TQString m_uniqueID;
TQString m_vendorID;
TQString m_modelID;
TQString m_vendorenc;
TQString m_modelenc;
TQString m_subvendorID;
TQString m_submodelID;
TQString m_pciClass;
TQString m_modAlias;
TQString m_deviceDriver;
TQString m_subsystem;
TQString m_friendlyName;
bool m_blacklistedForUpdate;
TDEGenericDevice* m_parentDevice;
// Internal use only!
TQStringList m_externalSubtype;
TQString m_externalRulesFile;
TQString m_udevtype;
TQString m_udevdevicetypestring;
TQString udevdevicetypestring_alt;
friend class TDEHardwareDevices;
};
#endif // _TDEGENERICDEVICE_H

@ -0,0 +1,299 @@
/* This file is part of the TDE libraries
Copyright (C) 2012 Timothy Pearson <kb9vqf@pearsoncomputing.net>
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 _TDEHARDWAREDEVICES_H
#define _TDEHARDWAREDEVICES_H
// TDE includes
#include <tqobject.h>
#include <tqptrlist.h>
#include <tqmap.h>
#include <tqstring.h>
#include <tqstringlist.h>
#include "tdelibs_export.h"
#include "kicontheme.h"
#include "tdehwcommontypes.h"
// FIXME delete those headers after complete fixing everything in over modules
#include "tdegenericdevice.h"
#include "kiconloader.h"
#include <libudev.h>
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <unistd.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"
/**
* Hardware Device Access and Monitoring Library
*
* @author Timothy Pearson
*/
struct udev_device;
class KSimpleDirWatch;
class TDEGenericDevice;
class TDEStorageDevice;
class TDENetworkDevice;
class TDEBacklightDevice;
class TDEMonitorDevice;
class TDESensorDevice;
class TDERootSystemDevice;
class TDEEventDevice;
class TDEInputDevice;
class TQSocketNotifier;
typedef TQPtrList<TDEGenericDevice> TDEGenericHardwareList;
typedef TQMap<TQString, TQString> TDEDeviceIDMap;
class TDECORE_EXPORT TDEHardwareDevices : public TQObject
{
Q_OBJECT
public:
/**
* Constructor.
*/
TDEHardwareDevices();
/**
* Destructor.
*/
~TDEHardwareDevices();
/**
* Query all hardware capabilities on all devices
* This does not normally need to be called by an application, as
* device detection is handled internally and automatically
*
* A call to this method immediately invalidates any TDEGenericHardwareList
* structures returned by listAllPhysicalDevices()
*
* @return TRUE if successful
*/
bool queryHardwareInformation();
/**
* List all hardware capabilities on all devices
* @return TDEGenericHardwareList containing all known hardware devices
*/
TDEGenericHardwareList listAllPhysicalDevices();
/**
* List all hardware capabilities on all devices
* @param a TDEGenericDeviceType::TDEGenericDeviceType specifying the device class
* @return TDEGenericHardwareList containing all known hardware devices
*/
TDEGenericHardwareList listByDeviceClass(TDEGenericDeviceType::TDEGenericDeviceType cl);
/**
* Return the device with system path @arg syspath, or 0 if no device exists for that path
* @return TDEGenericDevice
*/
TDEGenericDevice* findBySystemPath(TQString syspath);
/**
* Return the device with unique ID @arg uid, or 0 if no device exists for that uid
* @return TDEGenericDevice
*/
TDEGenericDevice* findByUniqueID(TQString uid);
/**
* Return the device with device node @arg devnode, or 0 if no device exists at that node
* @return TDEGenericDevice
*/
TDEGenericDevice* findByDeviceNode(TQString devnode);
/**
* Return the storage device with unique ID @arg uid, or 0 if no device exists for that uid
* @return TDEGenericDevice
*/
TDEStorageDevice* findDiskByUID(TQString uid);
/**
* Look up the device in the system PCI database
* @param vendorid a TQString containing the vendor ID in hexadecimal
* @param modelid a TQString containing the model ID in hexadecimal
* @param subvendorid a TQString containing the subvendor ID in hexadecimal
* @param submodelid a TQString containing the submodel ID in hexadecimal
* @return a TQString containing the device name, if found
*/
TQString findPCIDeviceName(TQString vendorid, TQString modelid, TQString subvendorid, TQString submodelid);
/**
* Look up the device in the system USB database
* @param vendorid a TQString containing the vendor ID in hexadecimal
* @param modelid a TQString containing the model ID in hexadecimal
* @param subvendorid a TQString containing the subvendor ID in hexadecimal
* @param submodelid a TQString containing the submodel ID in hexadecimal
* @return a TQString containing the device name, if found
*/
TQString findUSBDeviceName(TQString vendorid, TQString modelid, TQString subvendorid, TQString submodelid);
/**
* Look up the device in the system PNP database
* @param pnpid a TQString containing the PNP ID
* @return a TQString containing the device name, if found
*/
TQString findPNPDeviceName(TQString pnpid);
/**
* Look up the monitor manufacturer in the system display database
* @param pnpid a TQString containing the display manufacturer ID
* @return a TQString containing the manufacturer name, if found
*/
TQString findMonitorManufacturerName(TQString dpyid);
/**
* Get a friendly string describing a device type
* @param query a TDEGenericDeviceType::TDEGenericDeviceType specifying a device type
* @return a TQString containing the friendly type name
*/
TQString getFriendlyDeviceTypeStringFromType(TDEGenericDeviceType::TDEGenericDeviceType query);
/**
* Get an icon for a device type
* @param query a TDEGenericDeviceType::TDEGenericDeviceType specifying a device type
* @param size a TDEIcon::StdSizes structure specifying the desired icon size
* @return a TQPixmap containing the icon for the specified type
*/
TQPixmap getDeviceTypeIconFromType(TDEGenericDeviceType::TDEGenericDeviceType query, TDEIcon::StdSizes size);
/**
* Convenience function to obtain the root system device
* @return a pointer to a TDERootSystemDevice object
*/
TDERootSystemDevice* rootSystemDevice();
/**
* Rescan a hardware device to look for changes
* WARNING: This method can be very expensive. Use with caution!
* @param hwdevice TDEGenericDevice* with the device to rescan
*/
void rescanDeviceInformation(TDEGenericDevice* hwdevice);
/**
* Rescan a hardware device to look for changes
* WARNING: This method can be very expensive. Use with caution!
* The computational expense can be reduced somewhat if the device tree structure
* has not changed by calling this method with regenerateDeviceTree = FALSE.
* @param hwdevice TDEGenericDevice* with the device to rescan
* @param regenerateDeviceTree TRUE to update parent/child links in device tree
*/
void rescanDeviceInformation(TDEGenericDevice* hwdevice, bool regenerateDeviceTree);
/**
* Enable or disable automatic state updates of triggerless hardware devices
* such as CPUs and network cards. When enabled, your application will use
* additional CPU resources to continually poll triggerless hardware devices.
* Automatic updates are disabled by default.
* @param enable a bool specifiying whether or not automatic updates should be enabled
*/
void setTriggerlessHardwareUpdatesEnabled(bool enable);
/**
* Convert a byte count to human readable form
* @param bytes a double containing the number of bytes
* @return a TQString containing the human readable byte count
*/
static TQString bytesToFriendlySizeString(double bytes);
signals:
void hardwareAdded(TDEGenericDevice*);
void hardwareRemoved(TDEGenericDevice*);
void hardwareUpdated(TDEGenericDevice*);
void mountTableModified();
void hardwareEvent(TDEHardwareEvent::TDEHardwareEvent, TQString uuid);
/**
* @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 eventDeviceKeyPressed(unsigned int keycode, TDEEventDevice* device);
private slots:
void processHotPluggedHardware();
void processModifiedMounts();
void processModifiedCPUs();
void processStatelessDevices();
void processEventDeviceKeyPressed(unsigned int keycode, TDEEventDevice* edevice);
private:
void updateBlacklists(TDEGenericDevice* hwdevice, udev_device* dev);
private:
TDEGenericDevice *classifyUnknownDevice(udev_device* dev, TDEGenericDevice* existingdevice=0, bool force_full_classification=true);
TDEGenericDevice *classifyUnknownDeviceByExternalRules(udev_device* dev, TDEGenericDevice* existingdevice=0, bool classifySubDevices=false);
void updateExistingDeviceInformation(TDEGenericDevice* existingdevice, udev_device* dev=NULL);
void updateParentDeviceInformation();
void updateParentDeviceInformation(TDEGenericDevice* hwdevice);
void addCoreSystemDevices();
/**
* Get the binary monitor EDID for the specified sysfs path
* @return a TQByteArray containing the EDID
*/
TQByteArray getEDID(TQString path);
/**
* Get the monitor EDID name for the specified sysfs path
* @return a TQPair<TQString,TQString> containing the monitor vendor and model, if available
*/
TQPair<TQString,TQString> getEDIDMonitorName(TQString path);
struct udev *m_udevStruct;
struct udev_monitor *m_udevMonitorStruct;
TDEGenericHardwareList m_deviceList;
int m_procMountsFd;
KSimpleDirWatch* m_cpuWatch;
TQTimer* m_cpuWatchTimer;
TQTimer* m_deviceWatchTimer;
TQSocketNotifier* m_devScanNotifier;
TQSocketNotifier* m_mountScanNotifier;
TQStringList m_mountTable;
TQStringList m_cpuInfo;
TDEDeviceIDMap* pci_id_map;
TDEDeviceIDMap* usb_id_map;
TDEDeviceIDMap* pnp_id_map;
TDEDeviceIDMap* dpy_id_map;
friend class TDEGenericDevice;
friend class TDEStorageDevice;
friend class TDECPUDevice;
};
#endif // _TDEHARDWAREDEVICES_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,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 "tdemainspowerdevice.h"
#include "config.h"
TDEMainsPowerDevice::TDEMainsPowerDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) {
}
TDEMainsPowerDevice::~TDEMainsPowerDevice() {
}
bool TDEMainsPowerDevice::online() {
return m_online;
}
void TDEMainsPowerDevice::internalSetOnline(bool tc) {
m_online = tc;
}
#include "tdemainspowerdevice.moc"

@ -0,0 +1,57 @@
/* 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 _TDEMAINSPOWERDEVICE_H
#define _TDEMAINSPOWERDEVICE_H
#include "tdegenericdevice.h"
class TDECORE_EXPORT TDEMainsPowerDevice : public TDEGenericDevice
{
public:
/**
* Constructor.
* @param Device type
*/
TDEMainsPowerDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn=TQString::null);
/**
* Destructor.
*/
~TDEMainsPowerDevice();
/**
* @return TRUE if power supply is online via mains power, FALSE if not
*/
bool online();
protected:
/**
* @param TRUE if power supply is online via mains power, FALSE if not
* @internal
*/
void internalSetOnline(bool vt);
private:
bool m_online;
friend class TDEHardwareDevices;
};
#endif // _TDEMAINSPOWERDEVICE_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

@ -19,21 +19,23 @@
#include "tdehardwaredevices.h"
#include "tdenetworkconnections.h"
#include "config.h"
#include <tqtimer.h>
#include <tdelocale.h>
#include "tdenetworkdevice.h"
// #define DEBUG_SIGNAL_QUEUE 1
#include "config.h"
#ifdef WITH_NETWORK_MANAGER_BACKEND
#include "networkbackends/network-manager/network-manager.h"
#include "network-manager.h"
#endif // WITH_NETWORK_MANAGER_BACKEND
#define SET_BIT(x, y) (x |= 1 << y)
#define TEST_BIT(x, y) ((x & (1 << y)) >> y)
/*================================================================================================*/
/* TDENetworkSearchDomain */
/*================================================================================================*/

@ -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,250 @@
/* 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"
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,442 @@
/* 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 <dcopclient.h>
#include "tdeglobal.h"
#include "tdeconfig.h"
#include "tdeapplication.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

@ -0,0 +1,772 @@
/* 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 "tdestoragedevice.h"
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/cdrom.h>
#include <tqpixmap.h>
#include <tqfile.h>
#include "tdelocale.h"
#include "tdeglobal.h"
#include "kiconloader.h"
#include "tdetempfile.h"
#include "tdehardwaredevices.h"
#include "config.h"
// uDisks2 integration
#if defined(WITH_UDISKS) || defined(WITH_UDISKS2)
#include <tqdbusdata.h>
#include <tqdbusmessage.h>
#include <tqdbusproxy.h>
#include <tqdbusvariant.h>
#include <tqdbusconnection.h>
#include <tqdbuserror.h>
#include <tqdbusdatamap.h>
#include <tqdbusobjectpath.h>
#endif // defined(WITH_UDISKS) || defined(WITH_UDISKS2)
#if defined(WITH_UDISKS)
#include "tqdbusdatalist.h"
#endif // ddefined(WITH_UDISKS)
TDEStorageDevice::TDEStorageDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn), m_mediaInserted(true) {
m_diskType = TDEDiskDeviceType::Null;
m_diskStatus = TDEDiskDeviceStatus::Null;
}
TDEStorageDevice::~TDEStorageDevice() {
}
TDEDiskDeviceType::TDEDiskDeviceType TDEStorageDevice::diskType() {
return m_diskType;
}
void TDEStorageDevice::internalSetDiskType(TDEDiskDeviceType::TDEDiskDeviceType dt) {
m_diskType = dt;
}
bool TDEStorageDevice::isDiskOfType(TDEDiskDeviceType::TDEDiskDeviceType tf) {
return ((m_diskType&tf)!=TDEDiskDeviceType::Null);
}
TDEDiskDeviceStatus::TDEDiskDeviceStatus TDEStorageDevice::diskStatus() {
return m_diskStatus;
}
void TDEStorageDevice::internalSetDiskStatus(TDEDiskDeviceStatus::TDEDiskDeviceStatus st) {
m_diskStatus = st;
}
bool TDEStorageDevice::checkDiskStatus(TDEDiskDeviceStatus::TDEDiskDeviceStatus sf) {
return ((m_diskStatus&sf)!=(TDEDiskDeviceStatus::TDEDiskDeviceStatus)0);
}
bool TDEStorageDevice::lockDriveMedia(bool lock) {
int fd = open(deviceNode().ascii(), O_RDWR | O_NONBLOCK);
if (fd < 0) {
return false;
}
if (ioctl(fd, CDROM_LOCKDOOR, (lock)?1:0) != 0) {
close(fd);
return false;
}
else {
close(fd);
return true;
}
}
bool ejectDriveUDisks(TDEStorageDevice* sdevice) {
#ifdef WITH_UDISKS
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if (dbusConn.isConnected()) {
TQString blockDeviceString = sdevice->deviceNode();
blockDeviceString.replace("/dev/", "");
blockDeviceString = "/org/freedesktop/UDisks/devices/" + blockDeviceString;
// Eject the drive!
TQT_DBusError error;
TQT_DBusProxy driveControl("org.freedesktop.UDisks", blockDeviceString, "org.freedesktop.UDisks.Device", dbusConn);
if (driveControl.canSend()) {
TQValueList<TQT_DBusData> params;
TQT_DBusDataList options;
params << TQT_DBusData::fromList(options);
TQT_DBusMessage reply = driveControl.sendWithReply("DriveEject", params, &error);
if (error.isValid()) {
// Error!
printf("[ERROR] %s\n", error.name().ascii()); fflush(stdout);
return FALSE;
}
else {
return TRUE;
}
}
else {
return FALSE;
}
}
else {
return FALSE;
}
#else // WITH_UDISKS
return FALSE;
#endif // WITH_UDISKS
}
bool ejectDriveUDisks2(TDEStorageDevice* sdevice) {
#ifdef WITH_UDISKS2
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if (dbusConn.isConnected()) {
TQString blockDeviceString = sdevice->deviceNode();
blockDeviceString.replace("/dev/", "");
blockDeviceString = "/org/freedesktop/UDisks2/block_devices/" + blockDeviceString;
TQT_DBusProxy hardwareControl("org.freedesktop.UDisks2", blockDeviceString, "org.freedesktop.DBus.Properties", dbusConn);
if (hardwareControl.canSend()) {
// get associated udisks2 drive path
TQT_DBusError error;
TQValueList<TQT_DBusData> params;
params << TQT_DBusData::fromString("org.freedesktop.UDisks2.Block") << TQT_DBusData::fromString("Drive");
TQT_DBusMessage reply = hardwareControl.sendWithReply("Get", params, &error);
if (error.isValid()) {
// Error!
printf("[ERROR] %s\n", error.name().ascii()); fflush(stdout);
return FALSE;
}
else {
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
TQT_DBusObjectPath driveObjectPath = reply[0].toVariant().value.toObjectPath();
if (!driveObjectPath.isValid()) {
return FALSE;
}
error = TQT_DBusError();
TQT_DBusProxy driveInformation("org.freedesktop.UDisks2", driveObjectPath, "org.freedesktop.DBus.Properties", dbusConn);
// can eject?
TQValueList<TQT_DBusData> params;
params << TQT_DBusData::fromString("org.freedesktop.UDisks2.Drive") << TQT_DBusData::fromString("Ejectable");
TQT_DBusMessage reply = driveInformation.sendWithReply("Get", params, &error);
if (error.isValid()) {
// Error!
printf("[ERROR] %s\n", error.name().ascii()); fflush(stdout);
return FALSE;
}
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
bool ejectable = reply[0].toVariant().value.toBool();
if (!ejectable) {
return FALSE;
}
// Eject the drive!
TQT_DBusProxy driveControl("org.freedesktop.UDisks2", driveObjectPath, "org.freedesktop.UDisks2.Drive", dbusConn);
TQValueList<TQT_DBusData> params;
TQT_DBusDataMap<TQString> options(TQT_DBusData::Variant);
params << TQT_DBusData::fromStringKeyMap(options);
TQT_DBusMessage reply = driveControl.sendWithReply("Eject", params, &error);
if (error.isValid()) {
// Error!
printf("[ERROR] %s\n", error.name().ascii()); fflush(stdout);
return FALSE;
}
else {
return TRUE;
}
}
else {
return FALSE;
}
}
else {
return FALSE;
}
}
}
else {
return FALSE;
}
}
else {
return FALSE;
}
#else // WITH_UDISKS2
return FALSE;
#endif // WITH_UDISKS2
}
bool TDEStorageDevice::ejectDrive() {
if (ejectDriveUDisks2(this)) {
return TRUE;
}
else {
#ifdef WITH_UDISKS2
printf("[tdehwlib] Failed to eject drive '%s' via udisks2, falling back to alternate mechanism\n", deviceNode().ascii());
#endif // WITH_UDISKS2
if (ejectDriveUDisks(this)) {
return TRUE;
}
else {
#ifdef WITH_UDISKS
printf("[tdehwlib] Failed to eject drive '%s' via udisks, falling back to alternate mechanism\n", deviceNode().ascii());
#endif // WITH_UDISKS
TQString command = TQString("eject -v '%1' 2>&1").arg(deviceNode());
FILE *exepipe = popen(command.ascii(), "r");
if (exepipe) {
TQString pmount_output;
char buffer[8092];
pmount_output = fgets(buffer, sizeof(buffer), exepipe);
int retcode = pclose(exepipe);
if (retcode == 0) {
return TRUE;
}
else {
printf("[tdehwlib] Failed to eject drive '%s' via 'eject' command\n", deviceNode().ascii());
return FALSE;
}
}
else {
printf("[tdehwlib] Failed to eject drive '%s' via 'eject' command\n", deviceNode().ascii());
return FALSE;
}
}
}
}
bool TDEStorageDevice::ejectDriveMedia() {
int fd = open(deviceNode().ascii(), O_RDWR | O_NONBLOCK);
if (fd < 0) {
return false;
}
if (ioctl(fd, CDROMEJECT) != 0) {
close(fd);
return false;
}
else {
close(fd);
return true;
}
}
TQString TDEStorageDevice::diskLabel() {
return m_diskName;
}
void TDEStorageDevice::internalSetDiskLabel(TQString dn) {
m_diskName = dn;
}
bool TDEStorageDevice::mediaInserted() {
return m_mediaInserted;
}
void TDEStorageDevice::internalSetMediaInserted(bool inserted) {
m_mediaInserted = inserted;
}
TQString TDEStorageDevice::fileSystemName() {
return m_fileSystemName;
}
void TDEStorageDevice::internalSetFileSystemName(TQString fn) {
m_fileSystemName = fn;
}
TQString TDEStorageDevice::fileSystemUsage() {
return m_fileSystemUsage;
}
void TDEStorageDevice::internalSetFileSystemUsage(TQString fu) {
m_fileSystemUsage = fu;
}
TQString TDEStorageDevice::diskUUID() {
return m_diskUUID;
}
void TDEStorageDevice::internalSetDiskUUID(TQString id) {
m_diskUUID = id;
}
TQStringList TDEStorageDevice::holdingDevices() {
return m_holdingDevices;
}
void TDEStorageDevice::internalSetHoldingDevices(TQStringList hd) {
m_holdingDevices = hd;
}
TQStringList TDEStorageDevice::slaveDevices() {
return m_slaveDevices;
}
void TDEStorageDevice::internalSetSlaveDevices(TQStringList sd) {
m_slaveDevices = sd;
}
TQString TDEStorageDevice::friendlyName() {
// Return the actual storage device name
TQString devicevendorid = vendorEncoded();
TQString devicemodelid = modelEncoded();
devicevendorid.replace("\\x20", " ");
devicemodelid.replace("\\x20", " ");
devicevendorid = devicevendorid.stripWhiteSpace();
devicemodelid = devicemodelid.stripWhiteSpace();
devicevendorid = devicevendorid.simplifyWhiteSpace();
devicemodelid = devicemodelid.simplifyWhiteSpace();
TQString devicename = devicevendorid + " " + devicemodelid;
devicename = devicename.stripWhiteSpace();
devicename = devicename.simplifyWhiteSpace();
if (devicename != "") {
return devicename;
}
if (isDiskOfType(TDEDiskDeviceType::Camera)) {
return TDEGenericDevice::friendlyName();
}
if (isDiskOfType(TDEDiskDeviceType::Floppy)) {
return friendlyDeviceType();
}
TQString label = diskLabel();
if (label.isNull()) {
if (deviceSize() > 0) {
if (checkDiskStatus(TDEDiskDeviceStatus::Hotpluggable)) {
label = i18n("%1 Removable Device").arg(deviceFriendlySize());
}
else {
label = i18n("%1 Fixed Storage Device").arg(deviceFriendlySize());
}
}
}
if (!label.isNull()) {
return label;
}
return friendlyDeviceType();
}
TQString TDEStorageDevice::friendlyDeviceType() {
TQString ret = i18n("Hard Disk Drive");
// Keep this in sync with TDEStorageDevice::icon(TDEIcon::StdSizes size) below
if (isDiskOfType(TDEDiskDeviceType::Floppy)) {
ret = i18n("Floppy Drive");
}
if (isDiskOfType(TDEDiskDeviceType::Optical)) {
ret = i18n("Optical Drive");
}
if (isDiskOfType(TDEDiskDeviceType::CDROM)) {
ret = i18n("CDROM Drive");
}
if (isDiskOfType(TDEDiskDeviceType::CDRW)) {
ret = i18n("CDRW Drive");
}
if (isDiskOfType(TDEDiskDeviceType::DVDROM)) {
ret = i18n("DVD Drive");
}
if (isDiskOfType(TDEDiskDeviceType::DVDRW)) {
ret = i18n("DVDRW Drive");
}
if (isDiskOfType(TDEDiskDeviceType::DVDRAM)) {
ret = i18n("DVDRAM Drive");
}
if (isDiskOfType(TDEDiskDeviceType::Zip)) {
ret = i18n("Zip Drive");
}
if (isDiskOfType(TDEDiskDeviceType::Tape)) {
ret = i18n("Tape Drive");
}
if (isDiskOfType(TDEDiskDeviceType::Camera)) {
ret = i18n("Digital Camera");
}
if (isDiskOfType(TDEDiskDeviceType::HDD)) {
ret = i18n("Hard Disk Drive");
if (checkDiskStatus(TDEDiskDeviceStatus::Hotpluggable)) {
ret = i18n("Removable Storage");
}
if (isDiskOfType(TDEDiskDeviceType::CompactFlash)) {
ret = i18n("Compact Flash");
}
if (isDiskOfType(TDEDiskDeviceType::MemoryStick)) {
ret = i18n("Memory Stick");
}
if (isDiskOfType(TDEDiskDeviceType::SmartMedia)) {
ret = i18n("Smart Media");
}
if (isDiskOfType(TDEDiskDeviceType::SDMMC)) {
ret = i18n("Secure Digital");
}
}
if (isDiskOfType(TDEDiskDeviceType::RAM)) {
ret = i18n("Random Access Memory");
}
if (isDiskOfType(TDEDiskDeviceType::Loop)) {
ret = i18n("Loop Device");
}
return ret;
}
TQPixmap TDEStorageDevice::icon(TDEIcon::StdSizes size) {
TQPixmap ret = DesktopIcon("hdd_unmount", size);
if (isDiskOfType(TDEDiskDeviceType::Floppy)) {
ret = DesktopIcon("3floppy_unmount", size);
}
if (isDiskOfType(TDEDiskDeviceType::Optical)) {
ret = DesktopIcon("cdrom_unmount", size);
}
if (isDiskOfType(TDEDiskDeviceType::CDROM)) {
ret = DesktopIcon("cdrom_unmount", size);
}
if (isDiskOfType(TDEDiskDeviceType::CDRW)) {
ret = DesktopIcon("cdwriter_unmount", size);
}
if (isDiskOfType(TDEDiskDeviceType::DVDROM)) {
ret = DesktopIcon("dvd_unmount", size);
}
if (isDiskOfType(TDEDiskDeviceType::DVDRW)) {
ret = DesktopIcon("dvd_unmount", size);
}
if (isDiskOfType(TDEDiskDeviceType::DVDRAM)) {
ret = DesktopIcon("dvd_unmount", size);
}
if (isDiskOfType(TDEDiskDeviceType::Zip)) {
ret = DesktopIcon("zip_unmount", size);
}
if (isDiskOfType(TDEDiskDeviceType::Tape)) {
ret = DesktopIcon("tape_unmount", size);
}
if (isDiskOfType(TDEDiskDeviceType::Camera)) {
ret = DesktopIcon("camera_unmount");
}
if (isDiskOfType(TDEDiskDeviceType::HDD)) {
ret = DesktopIcon("hdd_unmount", size);
if (checkDiskStatus(TDEDiskDeviceStatus::Hotpluggable)) {
ret = DesktopIcon("usbpendrive_unmount", size);
}
if (isDiskOfType(TDEDiskDeviceType::CompactFlash)) {
ret = DesktopIcon("compact_flash_unmount", size);
}
if (isDiskOfType(TDEDiskDeviceType::MemoryStick)) {
ret = DesktopIcon("memory_stick_unmount", size);
}
if (isDiskOfType(TDEDiskDeviceType::SmartMedia)) {
ret = DesktopIcon("smart_media_unmount", size);
}
if (isDiskOfType(TDEDiskDeviceType::SDMMC)) {
ret = DesktopIcon("sd_mmc_unmount", size);
}
}
if (isDiskOfType(TDEDiskDeviceType::RAM)) {
ret = DesktopIcon("memory", size);
}
if (isDiskOfType(TDEDiskDeviceType::Loop)) {
ret = DesktopIcon("blockdevice", size);
}
return ret;
}
unsigned long long TDEStorageDevice::deviceSize() {
TQString bsnodename = systemPath();
bsnodename.append("/queue/physical_block_size");
TQFile bsfile( bsnodename );
TQString blocksize;
if ( bsfile.open( IO_ReadOnly ) ) {
TQTextStream stream( &bsfile );
blocksize = stream.readLine();
bsfile.close();
}
else {
// Drat, I can't get a guaranteed block size. Assume a block size of 512, as everything I have read indicates that /sys/block/<dev>/size is given in terms of a 512 byte block...
blocksize = "512";
}
TQString dsnodename = systemPath();
dsnodename.append("/size");
TQFile dsfile( dsnodename );
TQString devicesize;
if ( dsfile.open( IO_ReadOnly ) ) {
TQTextStream stream( &dsfile );
devicesize = stream.readLine();
dsfile.close();
}
return ((unsigned long long)blocksize.toULong()*(unsigned long long)devicesize.toULong());
}
TQString TDEStorageDevice::deviceFriendlySize() {
return TDEHardwareDevices::bytesToFriendlySizeString(deviceSize());
}
TQString TDEStorageDevice::mountPath() {
// See if this device node is mounted
// This requires parsing /proc/mounts, looking for deviceNode()
// The Device Mapper throws a monkey wrench into this
// It likes to advertise mounts as /dev/mapper/<something>,
// where <something> is listed in <system path>/dm/name
// First, ensure that all device information (mainly holders/slaves) is accurate
TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);
TQString dmnodename = systemPath();
dmnodename.append("/dm/name");
TQFile namefile( dmnodename );
TQString dmaltname;
if ( namefile.open( IO_ReadOnly ) ) {
TQTextStream stream( &namefile );
dmaltname = stream.readLine();
namefile.close();
}
if (!dmaltname.isNull()) {
dmaltname.prepend("/dev/mapper/");
}
TQStringList lines;
TQFile file( "/proc/mounts" );
if ( file.open( IO_ReadOnly ) ) {
TQTextStream stream( &file );
TQString line;
while ( !stream.atEnd() ) {
line = stream.readLine();
TQStringList mountInfo = TQStringList::split(" ", line, true);
TQString testNode = *mountInfo.at(0);
// Check for match
if ((testNode == deviceNode()) || (testNode == dmaltname) || (testNode == ("/dev/disk/by-uuid/" + diskUUID()))) {
TQString ret = *mountInfo.at(1);
ret.replace("\\040", " ");
return ret;
}
lines += line;
}
file.close();
}
// While this device is not directly mounted, it could concievably be mounted via the Device Mapper
// If so, try to retrieve the mount path...
TQStringList slaveDeviceList = holdingDevices();
for ( TQStringList::Iterator slavedevit = slaveDeviceList.begin(); slavedevit != slaveDeviceList.end(); ++slavedevit ) {
// Try to locate this device path in the TDE device tree
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
TDEGenericDevice *hwdevice = hwdevices->findBySystemPath(*slavedevit);
if ((hwdevice) && (hwdevice->type() == TDEGenericDeviceType::Disk)) {
TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice);
return sdevice->mountPath();
}
}
return TQString::null;
}
TQString TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageMountOptions mountOptions, TQString* errRet, int* retcode) {
int internal_retcode;
if (!retcode) {
retcode = &internal_retcode;
}
TQString ret = mountPath();
if (!ret.isNull()) {
return ret;
}
// Create dummy password file
KTempFile passwordFile(TQString::null, "tmp", 0600);
passwordFile.setAutoDelete(true);
TQString optionString;
if (mountOptions["ro"] == "true") {
optionString.append(" -r");
}
if (mountOptions["atime"] != "true") {
optionString.append(" -A");
}
if (mountOptions["utf8"] == "true") {
optionString.append(" -c utf8");
}
if (mountOptions["sync"] == "true") {
optionString.append(" -s");
}
if (mountOptions.contains("filesystem")) {
optionString.append(TQString(" -t %1").arg(mountOptions["filesystem"]));
}
if (mountOptions.contains("locale")) {
optionString.append(TQString(" -c %1").arg(mountOptions["locale"]));
}
TQString passFileName = passwordFile.name();
TQString devNode = deviceNode();
passFileName.replace("'", "'\\''");
devNode.replace("'", "'\\''");
mediaName.replace("'", "'\\''");
TQString command = TQString("pmount -p '%1' %2 '%3' '%4' 2>&1").arg(passFileName).arg(optionString).arg(devNode).arg(mediaName);
FILE *exepipe = popen(command.ascii(), "r");
if (exepipe) {
TQString pmount_output;
char buffer[8092];
pmount_output = fgets(buffer, sizeof(buffer), exepipe);
*retcode = pclose(exepipe);
if (errRet) {
*errRet = pmount_output;
}
}
// Update internal mount data
TDEGlobal::hardwareDevices()->processModifiedMounts();
ret = mountPath();
return ret;
}
TQString TDEStorageDevice::mountEncryptedDevice(TQString passphrase, TQString mediaName, TDEStorageMountOptions mountOptions, TQString* errRet, int* retcode) {
int internal_retcode;
if (!retcode) {
retcode = &internal_retcode;
}
TQString ret = mountPath();
if (!ret.isNull()) {
return ret;
}
// Create dummy password file
KTempFile passwordFile(TQString::null, "tmp", 0600);
passwordFile.setAutoDelete(true);
TQFile* pwFile = passwordFile.file();
if (!pwFile) {
return TQString::null;
}
pwFile->writeBlock(passphrase.ascii(), passphrase.length());
pwFile->flush();
TQString optionString;
if (mountOptions["ro"] == "true") {
optionString.append(" -r");
}
if (mountOptions["atime"] != "true") {
optionString.append(" -A");
}
if (mountOptions["utf8"] == "true") {
optionString.append(" -c utf8");
}
if (mountOptions["sync"] == "true") {
optionString.append(" -s");
}
if (mountOptions.contains("filesystem")) {
optionString.append(TQString(" -t %1").arg(mountOptions["filesystem"]));
}
if (mountOptions.contains("locale")) {
optionString.append(TQString(" -c %1").arg(mountOptions["locale"]));
}
TQString passFileName = passwordFile.name();
TQString devNode = deviceNode();
passFileName.replace("'", "'\\''");
devNode.replace("'", "'\\''");
mediaName.replace("'", "'\\''");
TQString command = TQString("pmount -p '%1' %2 '%3' '%4' 2>&1").arg(passFileName).arg(optionString).arg(devNode).arg(mediaName);
FILE *exepipe = popen(command.ascii(), "r");
if (exepipe) {
TQString pmount_output;
char buffer[8092];
pmount_output = fgets(buffer, sizeof(buffer), exepipe);
*retcode = pclose(exepipe);
if (errRet) {
*errRet = pmount_output;
}
}
// Update internal mount data
TDEGlobal::hardwareDevices()->processModifiedMounts();
ret = mountPath();
return ret;
}
bool TDEStorageDevice::unmountDevice(TQString* errRet, int* retcode) {
int internal_retcode;
if (!retcode) {
retcode = &internal_retcode;
}
TQString mountpoint = mountPath();
if (mountpoint.isNull()) {
return true;
}
mountpoint.replace("'", "'\\''");
TQString command = TQString("pumount '%1' 2>&1").arg(mountpoint);
FILE *exepipe = popen(command.ascii(), "r");
if (exepipe) {
TQString pmount_output;
char buffer[8092];
pmount_output = fgets(buffer, sizeof(buffer), exepipe);
*retcode = pclose(exepipe);
if (*retcode == 0) {
return true;
}
else {
if (errRet) {
*errRet = pmount_output;
}
}
}
// Update internal mount data
TDEGlobal::hardwareDevices()->processModifiedMounts();
return false;
}
#include "tdestoragedevice.moc"

@ -0,0 +1,344 @@
/* 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 _TDESTORAGEDEVICE_H
#define _TDESTORAGEDEVICE_H
#include "tdegenericdevice.h"
// Keep readDiskDeviceSubtypeFromString() in tdehardwaredevices.cpp in sync with this enum
namespace TDEDiskDeviceType {
enum TDEDiskDeviceType {
Null = 0x00000000,
MediaDevice = 0x00000001,
Floppy = 0x00000002,
CDROM = 0x00000004,
CDRW = 0x00000008,
DVDROM = 0x00000010,
DVDRAM = 0x00000020,
DVDRW = 0x00000040,
BDROM = 0x00000080,
BDRW = 0x00000100,
Zip = 0x00000200,
Jaz = 0x00000400,
Camera = 0x00000800,
LUKS = 0x00001000,
OtherCrypted = 0x00002000,
CDAudio = 0x00004000,
CDVideo = 0x00008000,
DVDVideo = 0x00010000,
BDVideo = 0x00020000,
Flash = 0x00040000,
USB = 0x00080000,
Tape = 0x00100000,
HDD = 0x00200000,
Optical = 0x00400000,
RAM = 0x00800000,
Loop = 0x01000000,
CompactFlash = 0x02000000,
MemoryStick = 0x04000000,
SmartMedia = 0x08000000,
SDMMC = 0x10000000,
UnlockedCrypt = 0x20000000,
Other = 0x80000000
};
inline TDEDiskDeviceType operator|(TDEDiskDeviceType a, TDEDiskDeviceType b)
{
return static_cast<TDEDiskDeviceType>(static_cast<int>(a) | static_cast<int>(b));
}
inline TDEDiskDeviceType operator&(TDEDiskDeviceType a, TDEDiskDeviceType b)
{
return static_cast<TDEDiskDeviceType>(static_cast<int>(a) & static_cast<int>(b));
}
inline TDEDiskDeviceType operator~(TDEDiskDeviceType a)
{
return static_cast<TDEDiskDeviceType>(~static_cast<int>(a));
}
};
namespace TDEDiskDeviceStatus {
enum TDEDiskDeviceStatus {
Null = 0x00000000,
Mountable = 0x00000001,
Removable = 0x00000002,
Inserted = 0x00000004,
Blank = 0x00000008,
UsedByDevice = 0x00000010,
UsesDevice = 0x00000020,
ContainsFilesystem = 0x00000040,
Hotpluggable = 0x00000080,
Other = 0x80000000
};
inline TDEDiskDeviceStatus operator|(TDEDiskDeviceStatus a, TDEDiskDeviceStatus b)
{
return static_cast<TDEDiskDeviceStatus>(static_cast<int>(a) | static_cast<int>(b));
}
inline TDEDiskDeviceStatus operator&(TDEDiskDeviceStatus a, TDEDiskDeviceStatus b)
{
return static_cast<TDEDiskDeviceStatus>(static_cast<int>(a) & static_cast<int>(b));
}
inline TDEDiskDeviceStatus operator~(TDEDiskDeviceStatus a)
{
return static_cast<TDEDiskDeviceStatus>(~static_cast<int>(a));
}
};
typedef TQMap<TQString,TQString> TDEStorageMountOptions;
class TDECORE_EXPORT TDEStorageDevice : public TDEGenericDevice
{
public:
/**
* Constructor.
* @param Device type
*/
TDEStorageDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn=TQString::null);
/**
* Destructor.
*/
~TDEStorageDevice();
/**
* @return a TQString with the disk or partition label, if any
*/
TQString diskLabel();
/**
* @return a TQString with the disk UUID, if any
*/
TQString diskUUID();
/**
* @return an OR-ed combination of TDEDiskDeviceType::TDEDiskDeviceType type flags
*/
TDEDiskDeviceType::TDEDiskDeviceType diskType();
/**
* @return an OR-ed combination of TDEDiskDeviceStatus::TDEDiskDeviceStatus type flags
*/
TDEDiskDeviceStatus::TDEDiskDeviceStatus diskStatus();
/**
* @return true if media inserted, false if no media available
*/
bool mediaInserted();
/**
* @return a TQString with the filesystem name, if any
*/
TQString fileSystemName();
/**
* @return a TQString with the filesystem usage string, if any
*/
TQString fileSystemUsage();
/**
* @return a TQStringList containing system paths to all devices with a lock on this device, if any
*/
TQStringList holdingDevices();
/**
* @return a TQStringList containing system paths to all devices locked by this device, if any
*/
TQStringList slaveDevices();
/**
* Mounts the device if not encrypted
*
* @param a TQString containing a requested mount name under /media, if desired
* @param a TQString containing any mount options for pmount, if desired
* @param a pointer to a TQString which will be populated with any error messages from pmount, if desired
* @param a pointer to an integer which will be populated with the return code from pmount, if desired
*
* @return a TQString with the mount path, if successful
*/
TQString mountDevice(TQString mediaName=TQString::null, TDEStorageMountOptions mountOptions=TDEStorageMountOptions(), TQString* errRet=0, int* retcode=0);
/**
* Mounts the encrypted device if the correct passphrase is given
*
* @param a TQString containing the passphrase
* @param a TQString containing a requested mount name under /media, if desired
* @param a TQString containing any mount options for pmount, if desired
* @param a pointer to a TQString which will be populated with any error messages from pmount, if desired
* @param a pointer to an integer which will be populated with the return code from pmount, if desired
*
* @return a TQString with the mount path, if successful
*/
TQString mountEncryptedDevice(TQString passphrase, TQString mediaName=TQString::null, TDEStorageMountOptions mountOptions=TDEStorageMountOptions(), TQString* errRet=0, int* retcode=0);
/**
* Unmounts the device
*
* @param a pointer to a TQString which will be populated with any error messages from pmount, if desired
* @param a pointer to an integer which will be populated with the return code from pmount, if desired
*
* @return TRUE if unmount was successful
*/
bool unmountDevice(TQString* errRet, int* retcode=0);
/**
* @return a TQString with the mount path, if mounted
*/
TQString mountPath();
/**
* @return an unsigned long with the device size in bytes
*/
unsigned long long deviceSize();
/**
* @return a TQString with the device size in human readable form
*/
TQString deviceFriendlySize();
/**
* Get an icon for this device
* @param size a TDEIcon::StdSizes structure specifying the desired icon size
* @return a TQPixmap containing the icon for the specified type
*
* This method overrides TDEGenericDevice::icon(TDEIcon::StdSizes size)
*/
TQPixmap icon(TDEIcon::StdSizes size);
/**
* @return a TQString with a friendly name
*
* This method overrides TDEGenericDevice::friendlyName()
*/
TQString friendlyName();
/**
* @return a TQString containing the friendly type name
*
* This method overrides TDEGenericDevice::friendlyDeviceType()
*/
TQString friendlyDeviceType();
/**
* @param an OR-ed combination of TDEDiskDeviceType::TDEDiskDeviceType type flags
*/
bool isDiskOfType(TDEDiskDeviceType::TDEDiskDeviceType tf);
/**
* @param an OR-ed combination of TDEDiskDeviceStatus::TDEDiskDeviceStatus type flags
*/
bool checkDiskStatus(TDEDiskDeviceStatus::TDEDiskDeviceStatus sf);
/**
* @param TRUE to engage media lock, FALSE to disable it
* @return TRUE on success, FALSE on failure
*
* This method currently works on CD-ROM drives and similar devices
*/
bool lockDriveMedia(bool lock);
/**
* @return TRUE on success, FALSE on failure
*
* This method currently works on CD-ROM drives and similar devices
*/
bool ejectDriveMedia();
/**
* @return TRUE on success, FALSE on failure
*
* This method currently works on all removable storage devices
*/
bool ejectDrive();
protected:
/**
* @param a TQString with the disk or partition label, if any
* @internal
*/
void internalSetDiskLabel(TQString dn);
/**
* @param a TQString with the disk UUID, if any
* @internal
*/
void internalSetDiskUUID(TQString id);
/**
* @param an OR-ed combination of TDEDiskDeviceType::TDEDiskDeviceType type flags
* @internal
*/
void internalSetDiskType(TDEDiskDeviceType::TDEDiskDeviceType tf);
/**
* @param an OR-ed combination of TDEDiskDeviceStatus::TDEDiskDeviceStatus type flags
* @internal
*/
void internalSetDiskStatus(TDEDiskDeviceStatus::TDEDiskDeviceStatus st);
/**
* @param a bool with the media status
* @internal
*/
void internalSetMediaInserted(bool inserted);
/**
* @param a TQString with the filesystem name, if any
* @internal
*/
void internalSetFileSystemName(TQString fn);
/**
* @param a TQString with the filesystem usage string, if any
* @internal
*/
void internalSetFileSystemUsage(TQString fu);
/**
* @param a TQStringList containing system paths to all devices with a lock on this device, if any
* @internal
*/
void internalSetHoldingDevices(TQStringList hd);
/**
* @param a TQStringList containing system paths to all devices locked by this device, if any
* @internal
*/
void internalSetSlaveDevices(TQStringList sd);
private:
TDEDiskDeviceType::TDEDiskDeviceType m_diskType;
TDEDiskDeviceStatus::TDEDiskDeviceStatus m_diskStatus;
TQString m_diskName;
TQString m_diskUUID;
TQString m_fileSystemName;
TQString m_fileSystemUsage;
bool m_mediaInserted;
TQString m_mountPath;
TQStringList m_holdingDevices;
TQStringList m_slaveDevices;
friend class TDEHardwareDevices;
};
#endif // _TDESTORAGEDEVICE_H
Loading…
Cancel
Save