diff options
author | Timothy Pearson <[email protected]> | 2013-03-31 02:45:14 -0500 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2013-03-31 02:45:14 -0500 |
commit | bc8c073fb46ceeea6ab93a66f231563581871af3 (patch) | |
tree | a1df480082798094fd3fc7a4e31fca9a027e8cbf /src/sources | |
parent | c2c9050abab88daaf3cfd32a9125e72e0bfaefaf (diff) | |
download | kima-bc8c073fb46ceeea6ab93a66f231563581871af3.tar.gz kima-bc8c073fb46ceeea6ab93a66f231563581871af3.zip |
Use TDE hardware library instead of HAL
Remove spurious build files
Diffstat (limited to 'src/sources')
-rw-r--r-- | src/sources/Makefile.am | 4 | ||||
-rw-r--r-- | src/sources/batterysrc.cpp | 115 | ||||
-rw-r--r-- | src/sources/batterysrc.h | 19 | ||||
-rw-r--r-- | src/sources/ibmacpithermalsrc.cpp | 2 |
4 files changed, 32 insertions, 108 deletions
diff --git a/src/sources/Makefile.am b/src/sources/Makefile.am index 2e8a3c0..ed4262e 100644 --- a/src/sources/Makefile.am +++ b/src/sources/Makefile.am @@ -16,5 +16,5 @@ noinst_HEADERS = acpithermalsrc.h batterysrc.h cpuinfofreqsrc.h hddtempsrc.h \ omnibookthermalsrc.h source.h sysfreqsrc.h \ threadedtrigger.h triggeredsource.h updateevent.h uptimesrc.h -AM_CXXFLAGS = @libhal_CFLAGS@ @nvcontrol_CFLAGS@ -LIBS += @libhal_LIBS@ @nvcontrol_LIBS@ +AM_CXXFLAGS = @nvcontrol_CFLAGS@ +LIBS += @nvcontrol_LIBS@ diff --git a/src/sources/batterysrc.cpp b/src/sources/batterysrc.cpp index 8c5989d..f4d4bd5 100644 --- a/src/sources/batterysrc.cpp +++ b/src/sources/batterysrc.cpp @@ -22,120 +22,51 @@ #include <tdelocale.h> #include <kdebug.h> -#define DBUS_DEBUG_MESSAGE(func, _dbus_err_) \ - kdDebug() << "error in " << func << ": " << _dbus_err_.name << ", " << _dbus_err_.message << endl - -#define FREE_DBUS_ERROR(func, _dbus_err_) \ - do { \ - if(dbus_error_is_set(&_dbus_err_)) { \ - DBUS_DEBUG_MESSAGE(func, _dbus_err_); \ - dbus_error_free(&_dbus_err_); \ - } \ - } while(0) - BatterySrc::BatterySrc(TQWidget* inParent, TQString inUDI): LabelSource(inParent), mTrigger(this, 5000), mUDI(inUDI), - mLibHalContext(NULL){ - mID = mUDI.section('/', -1); - mName = mID; - mDescription = i18n("This source displays the current state of charge of your battery."); + mHardwareDevices(NULL){ - dbus_error_init(&mDBusError); - if((mLibHalContext = libhal_ctx_new()) == NULL){ - kdDebug() << "error: libmLibHalContext_new" << endl; - return; - } - if(!libhal_ctx_set_dbus_connection(mLibHalContext, dbus_bus_get (DBUS_BUS_SYSTEM, &mDBusError))){ - FREE_DBUS_ERROR("libhal_ctx_set_dbus_connection", mDBusError); - libhal_ctx_free(mLibHalContext); - mLibHalContext = NULL; - return; - } - if(!libhal_ctx_init(mLibHalContext, &mDBusError)){ - FREE_DBUS_ERROR("libhal_ctx_init", mDBusError); - libhal_ctx_free(mLibHalContext); - mLibHalContext = NULL; - return; + mHardwareDevices = TDEGlobal::hardwareDevices(); + TDEGenericDevice* hwdevice = mHardwareDevices->findByUniqueID(inUDI); + + if (hwdevice->type() == TDEGenericDeviceType::Battery) { + TDEBatteryDevice* bdevice = static_cast<TDEBatteryDevice*>(hwdevice); + mID = bdevice->friendlyName(); } + mName = mID; + mDescription = i18n("This source displays the current state of charge of your battery."); } BatterySrc::~BatterySrc(){ - if(mLibHalContext != NULL){ - if(!libhal_ctx_shutdown(mLibHalContext, &mDBusError)){ - FREE_DBUS_ERROR("libhal_ctx_shutdown", mDBusError); - } - libhal_ctx_free(mLibHalContext); - } + // } std::list<Source*>BatterySrc::createInstances(TQWidget* inParent){ std::list<Source*> list; - - LibHalContext* libHalContext; - DBusError dBusError; - dbus_error_init(&dBusError); - if((libHalContext = libhal_ctx_new()) == NULL){ - kdDebug() << "error: libmLibHalContext_new" << endl; - return list; - } - if(!libhal_ctx_set_dbus_connection(libHalContext, dbus_bus_get (DBUS_BUS_SYSTEM, &dBusError))){ - FREE_DBUS_ERROR("libhal_ctx_set_dbus_connection", dBusError); - libhal_ctx_free(libHalContext); - return list; - } - if(!libhal_ctx_init(libHalContext, &dBusError)){ - FREE_DBUS_ERROR("libhal_ctx_init", dBusError); - libhal_ctx_free(libHalContext); - return list; - } - int num = 0; - char** udis = libhal_manager_find_device_string_match(libHalContext, "info.category", "battery", &num, &dBusError); - if(!dbus_error_is_set(&dBusError)){ - for(int i = 0; i < num; ++i){ - if(libhal_device_get_property_type(libHalContext, udis[i], "battery.charge_level.last_full", &dBusError) == LIBHAL_PROPERTY_TYPE_INT32 && libhal_device_get_property_type(libHalContext, udis[i], "battery.charge_level.current", &dBusError) == LIBHAL_PROPERTY_TYPE_INT32){ - if(!dbus_error_is_set(&dBusError)) // todo: check whether this check is redundant - list.push_back(new BatterySrc(inParent, udis[i])); - } - if(dbus_error_is_set(&dBusError)) { - DBUS_DEBUG_MESSAGE("libhal_device_get_property_type", dBusError); - dbus_error_free(&dBusError); - } + TDEHardwareDevices* hardwareDevices = TDEGlobal::hardwareDevices(); + TDEGenericHardwareList hwlist = hardwareDevices->listAllPhysicalDevices(); + TDEGenericDevice *hwdevice; + for (hwdevice = hwlist.first(); hwdevice; hwdevice = hwlist.next()) { + if (hwdevice->type() == TDEGenericDeviceType::Battery) { + list.push_back(new BatterySrc(inParent, hwdevice->uniqueID())); } - } else { - DBUS_DEBUG_MESSAGE("libhal_manager_find_device_string_match", dBusError); - dbus_error_free(&dBusError); - } - if(!libhal_ctx_shutdown(libHalContext, &dBusError)){ - FREE_DBUS_ERROR("libhal_ctx_shutdown", dBusError); } - // clean up - libhal_ctx_free(libHalContext); - libhal_free_string_array(udis); + return list; } TQString BatterySrc::fetchValue() { TQString s = "n/a"; - if(mLibHalContext != NULL){ - int last_full = 0; - int current = 0; - - last_full = libhal_device_get_property_int(mLibHalContext, mUDI.ascii(), "battery.charge_level.last_full", &mDBusError); - if(dbus_error_is_set(&mDBusError)){ - DBUS_DEBUG_MESSAGE("libhal_device_get_property_int", mDBusError); - dbus_error_free(&mDBusError); - return s; - } - current = libhal_device_get_property_int(mLibHalContext, mUDI.ascii(), "battery.charge_level.current", &mDBusError); - if(dbus_error_is_set(&mDBusError)){ - DBUS_DEBUG_MESSAGE("libhal_device_get_property_int", mDBusError); - dbus_error_free(&mDBusError); - return s; + if (mHardwareDevices != NULL) { + TDEGenericDevice* hwdevice = mHardwareDevices->findByUniqueID(mUDI); + if (hwdevice->type() != TDEGenericDeviceType::Battery) { + return i18n("unknown"); } - s = TQString::number(tqRound((current * 100.0) / last_full)) + " %"; + TDEBatteryDevice* bdevice = static_cast<TDEBatteryDevice*>(hwdevice); + s = TQString::number(bdevice->chargePercent()) + " %"; } return s; } diff --git a/src/sources/batterysrc.h b/src/sources/batterysrc.h index ac64f2d..62c6828 100644 --- a/src/sources/batterysrc.h +++ b/src/sources/batterysrc.h @@ -25,7 +25,8 @@ #include <tqfile.h> #include <tqstring.h> #include <list> -#include <hal/libhal.h> + +#include <tdehardwaredevices.h> /** * BatterySrc fetches the state of charge of the battery from HAL @@ -40,7 +41,7 @@ public: */ BatterySrc(TQWidget* inParent, TQString inUDI); virtual ~BatterySrc(); - + /** * Creates instances of that Source (and returns pointers to them) */ @@ -60,18 +61,12 @@ private: /** * The hal udi of that battery source - */ + */ TQString mUDI; /** - * The local hal context - */ - LibHalContext* mLibHalContext; - - /** - * The local dbus error object - */ - DBusError mDBusError; - + * The internal hardware library object + */ + TDEHardwareDevices* mHardwareDevices; }; #endif //BATTERYSRC_H diff --git a/src/sources/ibmacpithermalsrc.cpp b/src/sources/ibmacpithermalsrc.cpp index 918770b..8ff2c1b 100644 --- a/src/sources/ibmacpithermalsrc.cpp +++ b/src/sources/ibmacpithermalsrc.cpp @@ -22,8 +22,6 @@ #include <tqtextstream.h> #include <tqfile.h> #include <tdelocale.h> -//#include "hal/libhal.h" -// hal-get-property --udi /org/freedesktop/Hal/devices/computer --key system.product IBMACPIThermalSrc::IBMACPIThermalSrc(TQWidget* inParent, const TQFile& inSourceFile, unsigned int inIndex): LabelSource(inParent), |