Hi! I have some questions.
1. Should backend/hal/acadapter.cpp be changed as the following? My current `lshal` (0.5.7) shows "ac_adaptEr.present" instead of "ac_adaptOr.present"...um... the hal spec said the otherwise though. Index: backends/hal/acadapter.cpp =================================================================== --- backends/hal/acadapter.cpp (revision 580530) +++ backends/hal/acadapter.cpp (working copy) @@ -33,7 +33,7 @@ bool AcAdapter::isPlugged() const { - return m_device->property( "ac_adaptor.present" ).toBool(); + return m_device->property( "ac_adapter.present" ).toBool(); } 2. In the attached code (halpowermanager.cpp), how can I delete the HalDevice object? In particular, what should I do in the 'HalPowerManager::~HalPowerManager()'? I guess I probably should not write things in this way? or some other parents should own it? Many Thanks!! I am still learning :) --Martin
HalPowerManager::HalPowerManager( QObject *parent, const QStringList &args ) { m_halmanager = new HalManager(parent, args); if( !m_halmanager ) { kDebug() << "Cannot init HalManager" << endl; m_acadapter = NULL; return; } QStringList dev_list = m_halmanager->devicesFromQuery("/org/freedesktop/Hal/devices/computer", Capability::Battery); for( int i = 0; i < dev_list.size(); i++ ) { kDebug() << "Battery #" << i << ": " << dev_list[i] << endl; if( m_batteries.find(dev_list[i]) != m_batteries.end() ) { kDebug() << "Battery with udi " << dev_list[i] << " has already been found" << endl; continue; } HalDevice *device = new HalDevice(dev_list[i]); if( !device ) { kDebug() << "Cannot create HalDevice for " << dev_list[i] << endl; continue; } Battery *battery = new Battery(device); if( !battery ) { kDebug() << "Cannot create Battery Device for " << dev_list[i] << endl; delete device; continue; } if( battery->type() != Battery::PrimaryBattery ) { kDebug() << "udi " << dev_list[i] << " is not a primary battery" << endl; delete battery; delete device; continue; } m_batteries.insert(device->udi(), battery); connect( battery, SIGNAL( chargePercentChanged( int ) ), this, SLOT( slotChargePercentageChanged( int ) ) ); } recalcBatteryLevel(); recalcBatteryState(); m_acadapter = NULL; dev_list = m_halmanager->devicesFromQuery("/org/freedesktop/Hal/devices/computer", Capability::AcAdapter); for( int i = 0; i < dev_list.size(); i++ ) { HalDevice *device = new HalDevice(dev_list[i]); if( !device ) { kDebug() << "Cannot create HalDevice for " << dev_list[i] << endl; continue; } m_acadapter = new AcAdapter(device); if( !m_acadapter ) { kDebug() << "Cannot create AcAdapter Device for " << dev_list[i] << endl; continue; } connect( m_acadapter, SIGNAL( plugStateChanged( bool ) ), this, SLOT( slotPlugStateChanged( bool ) ) ); break; } connect( m_halmanager, SIGNAL( deviceRemoved( const QString & ) ), this, SLOT( slotDeviceRemoved( const QString & ) ) ); } HalPowerManager::~HalPowerManager() { BatteryHash::const_iterator i; for(i = m_batteries.begin(); i != m_batteries.end(); i++) { Battery *battery = i.value(); //FIXME: who owns the corresponding HalDevice? delete battery; } //FIXME: who owns the corresponding HalDevice? delete m_acadapter; delete m_halmanager; }
_______________________________________________ Kde-hardware-devel mailing list Kde-hardware-devel@kde.org https://mail.kde.org/mailman/listinfo/kde-hardware-devel