parent
9f2311f262
commit
da10cdaf05
@ -1,10 +1,8 @@
|
||||
INCLUDES = -I/usr/include/dvdread -I$(top_srcdir)/libk9copy $(DBUS_INCS) \
|
||||
$(HAL_INCS) $(K3B_INCS) -I$(includedir) $(all_includes)
|
||||
INCLUDES = -I/usr/include/dvdread -I$(top_srcdir)/libk9copy $(K3B_INCS) -I$(includedir) $(all_includes)
|
||||
METASOURCES = AUTO
|
||||
libk9devices_la_LDFLAGS = $(all_libraries)
|
||||
noinst_LTLIBRARIES = libk9devices.la
|
||||
noinst_HEADERS = k9halconnection.h k9haldevice.h k9cddrive.h k9dbusdispatch.h
|
||||
libk9devices_la_SOURCES = k9halconnection.cpp k9haldevice.cpp k9cddrive.cpp \
|
||||
k9dbusdispatch.cpp
|
||||
noinst_HEADERS = k9cddrive.h
|
||||
libk9devices_la_SOURCES = k9cddrive.cpp
|
||||
|
||||
libk9devices_la_LIBADD = $(K3B_LIBS) $(HAL_DBUS_LIBS)
|
||||
libk9devices_la_LIBADD = $(K3B_LIBS)
|
||||
|
@ -1,231 +0,0 @@
|
||||
//
|
||||
// C++ Implementation: k9dbusdispatch
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// Author: Jean-Michel PETIT <k9copy@free.fr>, (C) 2007
|
||||
//
|
||||
// Copyright: See COPYING file that comes with this distribution
|
||||
//
|
||||
//
|
||||
#include "k9dbusdispatch.h"
|
||||
#ifdef HAVE_HAL
|
||||
#include <dbus/dbus.h>
|
||||
|
||||
//==============================callbacks ========================================
|
||||
|
||||
|
||||
static dbus_bool_t qDBusAddWatch(DBusWatch *watch, void *data)
|
||||
{
|
||||
|
||||
int flags = dbus_watch_get_flags(watch);
|
||||
int fd = dbus_watch_get_fd(watch);
|
||||
|
||||
K9DBusDispatch *d=(K9DBusDispatch*)data;
|
||||
|
||||
k9Watcher watcher;
|
||||
if (flags & DBUS_WATCH_READABLE) {
|
||||
bool enabled = dbus_watch_get_enabled(watch);
|
||||
//tqDebug("addReadWatch %d %s", fd, (enabled ? "enabled" : "disabled"));
|
||||
watcher.watch = watch;
|
||||
watcher.read = new TQSocketNotifier(fd, TQSocketNotifier::Read, d);
|
||||
if (!enabled) watcher.read->setEnabled(false);
|
||||
d->connect(watcher.read, TQT_SIGNAL(activated(int)), TQT_SLOT(socketRead(int)));
|
||||
}
|
||||
if (flags & DBUS_WATCH_WRITABLE) {
|
||||
bool enabled = dbus_watch_get_enabled(watch);
|
||||
//tqDebug("addWriteWatch %d %s", fd, (enabled ? "enabled" : "disabled"));
|
||||
watcher.watch = watch;
|
||||
watcher.write = new TQSocketNotifier(fd, TQSocketNotifier::Write, d);
|
||||
if (!enabled) watcher.write->setEnabled(false);
|
||||
d->connect(watcher.write, TQT_SIGNAL(activated(int)), TQT_SLOT(socketWrite(int)));
|
||||
}
|
||||
// FIXME-QT4 d->watchers.insertMulti(fd, watcher);
|
||||
K9DBusDispatch::WatcherHash::iterator it = d->watchers.find(fd);
|
||||
if (it == d->watchers.end())
|
||||
{
|
||||
it = d->watchers.insert(fd, K9DBusDispatch::WatcherList());
|
||||
}
|
||||
it.data().append(watcher);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void qDBusRemoveWatch(DBusWatch *watch, void *data)
|
||||
{
|
||||
K9DBusDispatch *d = (K9DBusDispatch*)data;
|
||||
|
||||
int fd = dbus_watch_get_fd(watch);
|
||||
|
||||
K9DBusDispatch::WatcherHash::iterator it = d->watchers.find(fd);
|
||||
if (it != d->watchers.end())
|
||||
{
|
||||
K9DBusDispatch::WatcherList& list = *it;
|
||||
for (K9DBusDispatch::WatcherList::iterator wit = list.begin();
|
||||
wit != list.end(); ++wit)
|
||||
{
|
||||
if ((*wit).watch == watch)
|
||||
{
|
||||
// migth be called from a function triggered by a socket listener
|
||||
// so just disconnect them and schedule their delayed deletion.
|
||||
|
||||
d->removedWatches.append(*wit);
|
||||
if ((*wit).read)
|
||||
{
|
||||
(*wit).read->disconnect(d);
|
||||
(*wit).read = 0;
|
||||
}
|
||||
if ((*wit).write)
|
||||
{
|
||||
(*wit).write->disconnect(d);
|
||||
(*wit).write = 0;
|
||||
}
|
||||
(*wit).watch = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (d->removedWatches.count() > 0)
|
||||
TQTimer::singleShot(0, d, TQT_SLOT(purgeRemovedWatches()));
|
||||
|
||||
}
|
||||
|
||||
static void qDBusToggleWatch(DBusWatch *watch, void *data)
|
||||
{
|
||||
K9DBusDispatch *d=(K9DBusDispatch*)data;
|
||||
int fd = dbus_watch_get_fd(watch);
|
||||
|
||||
K9DBusDispatch::WatcherHash::iterator it = d->watchers.find(fd);
|
||||
if (it != d->watchers.end()) {
|
||||
K9DBusDispatch::WatcherList& list = *it;
|
||||
for (K9DBusDispatch::WatcherList::iterator wit = list.begin(); wit != list.end();
|
||||
++wit)
|
||||
{
|
||||
if ((*wit).watch == watch) {
|
||||
bool enabled = dbus_watch_get_enabled(watch);
|
||||
int flags = dbus_watch_get_flags(watch);
|
||||
|
||||
// tqDebug("toggle watch %d to %d (write: %d, read: %d)",
|
||||
// dbus_watch_get_fd(watch), enabled,
|
||||
// flags & DBUS_WATCH_WRITABLE, flags & DBUS_WATCH_READABLE);
|
||||
|
||||
if (flags & DBUS_WATCH_READABLE && (*wit).read)
|
||||
(*wit).read->setEnabled(enabled);
|
||||
if (flags & DBUS_WATCH_WRITABLE && (*wit).write)
|
||||
(*wit).write->setEnabled(enabled);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void K9DBusDispatch::purgeRemovedWatches()
|
||||
{
|
||||
if (removedWatches.isEmpty()) return;
|
||||
|
||||
WatcherList::iterator listIt = removedWatches.begin();
|
||||
for (; listIt != removedWatches.end(); ++listIt)
|
||||
{
|
||||
delete (*listIt).read;
|
||||
delete (*listIt).write;
|
||||
}
|
||||
removedWatches.clear();
|
||||
|
||||
uint count = 0;
|
||||
WatcherHash::iterator it = watchers.begin();
|
||||
while (it != watchers.end())
|
||||
{
|
||||
WatcherList& list = *it;
|
||||
listIt = list.begin();
|
||||
while (listIt != list.end())
|
||||
{
|
||||
if (!((*listIt).read) && !((*listIt).write))
|
||||
{
|
||||
listIt = list.erase(listIt);
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
||||
if (list.isEmpty())
|
||||
{
|
||||
WatcherHash::iterator copyIt = it;
|
||||
++it;
|
||||
watchers.erase(copyIt);
|
||||
}
|
||||
else
|
||||
++it;
|
||||
}
|
||||
}
|
||||
//==============================================================================
|
||||
|
||||
void K9DBusDispatch::socketRead(int fd)
|
||||
{
|
||||
// FIXME-QT4 TQHashIterator<int, TQDBusConnectionPrivate::Watcher> it(watchers);
|
||||
WatcherHash::const_iterator it = watchers.find(fd);
|
||||
if (it != watchers.end()) {
|
||||
const WatcherList& list = *it;
|
||||
for (WatcherList::const_iterator wit = list.begin(); wit != list.end(); ++wit) {
|
||||
if ((*wit).read && (*wit).read->isEnabled()) {
|
||||
if (!dbus_watch_handle((*wit).watch, DBUS_WATCH_READABLE))
|
||||
tqDebug("OUT OF MEM");
|
||||
}
|
||||
}
|
||||
}
|
||||
scheduleDispatch();
|
||||
}
|
||||
|
||||
void K9DBusDispatch::socketWrite(int fd)
|
||||
{
|
||||
// FIXME-QT4 TQHashIterator<int, TQDBusConnectionPrivate::Watcher> it(watchers);
|
||||
WatcherHash::const_iterator it = watchers.find(fd);
|
||||
if (it != watchers.end()) {
|
||||
const WatcherList& list = *it;
|
||||
for (WatcherList::const_iterator wit = list.begin(); wit != list.end(); ++wit) {
|
||||
if ((*wit).write && (*wit).write->isEnabled()) {
|
||||
if (!dbus_watch_handle((*wit).watch, DBUS_WATCH_WRITABLE))
|
||||
tqDebug("OUT OF MEM");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void K9DBusDispatch::scheduleDispatch()
|
||||
{
|
||||
m_dispatcher->start(0);
|
||||
}
|
||||
|
||||
void K9DBusDispatch::dispatch()
|
||||
{
|
||||
if (dbus_connection_dispatch(m_connection) != DBUS_DISPATCH_DATA_REMAINS)
|
||||
{
|
||||
// stop dispatch timer
|
||||
m_dispatcher->stop();
|
||||
}
|
||||
}
|
||||
|
||||
K9DBusDispatch::K9DBusDispatch(TQObject *parent, const char *name)
|
||||
: TQObject(parent, name)
|
||||
{
|
||||
m_dispatcher = new TQTimer(this);
|
||||
TQObject::connect(m_dispatcher, TQT_SIGNAL(timeout()), this, TQT_SLOT(dispatch()));
|
||||
}
|
||||
|
||||
|
||||
K9DBusDispatch::~K9DBusDispatch()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void K9DBusDispatch::setConnection(DBusConnection* _value) {
|
||||
m_connection = _value;
|
||||
|
||||
dbus_connection_set_exit_on_disconnect(m_connection, false);
|
||||
dbus_connection_set_watch_functions(m_connection, qDBusAddWatch, qDBusRemoveWatch,
|
||||
qDBusToggleWatch, this, 0);
|
||||
}
|
||||
|
||||
#include "k9dbusdispatch.moc"
|
||||
#endif
|
||||
|
@ -1,71 +0,0 @@
|
||||
//
|
||||
// C++ Interface: k9dbusdispatch
|
||||
//
|
||||
// Description: the main goal of this class is to dispatch dbus messages so that libhal can
|
||||
// detect changes on devices.
|
||||
// This code is based on TQDBusConnectionPrivate from the new TQt DBus bindings
|
||||
//
|
||||
//
|
||||
// Author: Jean-Michel PETIT <k9copy@free.fr>, (C) 2007
|
||||
//
|
||||
// Copyright: See COPYING file that comes with this distribution
|
||||
//
|
||||
//
|
||||
#ifndef K9DBUSDISPATCH_H
|
||||
#define K9DBUSDISPATCH_H
|
||||
#include "k9common.h"
|
||||
|
||||
#ifdef Q_MOC_RUN
|
||||
#define HAVE_HAL
|
||||
#endif // Q_MOC_RUN
|
||||
|
||||
#ifdef HAVE_HAL
|
||||
|
||||
#include <tqobject.h>
|
||||
#include <tqtimer.h>
|
||||
#define DBUS_API_SUBJECT_TO_CHANGE
|
||||
#include <dbus/dbus.h>
|
||||
#include <tqsocketnotifier.h>
|
||||
#include <tqvaluelist.h>
|
||||
#include <tqmap.h>
|
||||
|
||||
/**
|
||||
@author Jean-Michel PETIT <k9copy@free.fr>
|
||||
*/
|
||||
|
||||
class k9Watcher {
|
||||
public:
|
||||
k9Watcher() { read=write=0; watch=0;};
|
||||
DBusWatch *watch;
|
||||
TQSocketNotifier *read,*write;
|
||||
};
|
||||
|
||||
class K9DBusDispatch : public TQObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
K9DBusDispatch(TQObject *parent = 0, const char *name = 0);
|
||||
|
||||
~K9DBusDispatch();
|
||||
void setConnection(DBusConnection* _value);
|
||||
typedef TQValueList<k9Watcher> WatcherList;
|
||||
WatcherList removedWatches;
|
||||
typedef TQMap<int, WatcherList> WatcherHash;
|
||||
WatcherHash watchers;
|
||||
|
||||
private:
|
||||
TQTimer *m_dispatcher;
|
||||
DBusConnection *m_connection;
|
||||
|
||||
void purgeRemovedWatches();
|
||||
void scheduleDispatch();
|
||||
private slots:
|
||||
void socketRead(int fd);
|
||||
void socketWrite(int fd);
|
||||
void dispatch();
|
||||
|
||||
|
||||
};
|
||||
#endif
|
||||
#endif
|
@ -1,159 +0,0 @@
|
||||
//
|
||||
// C++ Implementation: k9halconnection
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// Author: Jean-Michel PETIT <k9copy@free.fr>, (C) 2007
|
||||
//
|
||||
// Copyright: See COPYING file that comes with this distribution
|
||||
//
|
||||
//
|
||||
#include "k9common.h"
|
||||
#ifdef HAVE_HAL
|
||||
|
||||
#include "k9halconnection.h"
|
||||
#define DBUS_API_SUBJECT_TO_CHANGE
|
||||
#include "k9haldevice.h"
|
||||
#include <dbus/dbus.h>
|
||||
#include <hal/libhal.h>
|
||||
k9HalConnection *Hinstance=NULL;
|
||||
|
||||
void halDeviceAdded (LibHalContext *ctx, const char *udi) {
|
||||
Hinstance->addDevice(udi);
|
||||
Hinstance->testVolumeChanged( udi);
|
||||
|
||||
}
|
||||
|
||||
void halDeviceRemoved (LibHalContext *ctx, const char *udi) {
|
||||
Hinstance->removeDevice( udi);
|
||||
Hinstance->testVolumeChanged( udi);
|
||||
}
|
||||
|
||||
|
||||
k9HalConnection::k9HalConnection(TQObject *parent, const char *name)
|
||||
: TQObject(parent, name)
|
||||
{
|
||||
m_devices.setAutoDelete(true);
|
||||
m_context =(void*) libhal_ctx_new();
|
||||
|
||||
DBusError error;
|
||||
dbus_error_init( &error );
|
||||
m_dbusConnect = dbus_bus_get( DBUS_BUS_SYSTEM, &error );
|
||||
if( dbus_error_is_set(&error) ) {
|
||||
tqDebug("%s", (TQString("Error connecting to DBUS : %1").arg(error.message)).ascii());
|
||||
return;
|
||||
}
|
||||
|
||||
m_dbusDispatch=new K9DBusDispatch(this,0);
|
||||
m_dbusDispatch->setConnection(m_dbusConnect);
|
||||
|
||||
libhal_ctx_set_dbus_connection((LibHalContext*) m_context,m_dbusConnect );
|
||||
|
||||
libhal_ctx_set_device_added( (LibHalContext*)m_context, halDeviceAdded );
|
||||
libhal_ctx_set_device_removed( (LibHalContext*)m_context, halDeviceRemoved );
|
||||
|
||||
if( !libhal_ctx_init((LibHalContext*) m_context, 0 ) ) {
|
||||
tqDebug("HAL init failed");
|
||||
return;
|
||||
}
|
||||
|
||||
int numDevices;
|
||||
char** halDeviceList = libhal_get_all_devices((LibHalContext*) m_context, &numDevices, 0 );
|
||||
for( int i = 0; i < numDevices; ++i )
|
||||
//tqDebug(halDeviceList[i]);
|
||||
addDevice( halDeviceList[i] );
|
||||
}
|
||||
|
||||
void k9HalConnection::removeDevice( const char* udi ) {
|
||||
k9HalDevice *device=findDevice( udi);
|
||||
if (device !=NULL) {
|
||||
emit deviceRemoved( device);
|
||||
m_devices.remove(device);
|
||||
}
|
||||
}
|
||||
|
||||
void k9HalConnection::addDevice( const char* udi )
|
||||
{
|
||||
// ignore devices that have no property "info.capabilities" to suppress error messages
|
||||
if( !libhal_device_property_exists( (LibHalContext*) m_context, udi, "info.capabilities", 0 ) )
|
||||
return;
|
||||
|
||||
if( libhal_device_query_capability( (LibHalContext*) m_context, udi, "storage.cdrom", 0 ) ) {
|
||||
char* dev = libhal_device_get_property_string( (LibHalContext*) m_context, udi, "block.device", 0 );
|
||||
if( dev ) {
|
||||
TQString s( dev );
|
||||
libhal_free_string( dev );
|
||||
|
||||
if( !s.isEmpty() ) {
|
||||
k9HalDevice *device=new k9HalDevice(this,udi);
|
||||
m_devices.append( device);
|
||||
emit deviceAdded( device);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void k9HalConnection::testVolumeChanged( const char * udi) {
|
||||
// ignore devices that have no property "info.capabilities" to suppress error messages
|
||||
if( !libhal_device_property_exists( (LibHalContext*) m_context, udi, "info.capabilities", 0 ) ){
|
||||
k9HalDevice *device=findDeviceByVolume( udi);
|
||||
if (device != NULL)
|
||||
device->updateVolumeName();
|
||||
}
|
||||
else
|
||||
if( libhal_device_query_capability( (LibHalContext*) m_context, udi, "volume", 0 ) ) {
|
||||
char* udiParent = libhal_device_get_property_string( (LibHalContext*) m_context, udi, "info.parent", 0 );
|
||||
if( udiParent ) {
|
||||
k9HalDevice *device=findDevice( udiParent);
|
||||
libhal_free_string( udiParent );
|
||||
if (device)
|
||||
device->updateVolumeName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
k9HalConnection::~k9HalConnection()
|
||||
{
|
||||
libhal_ctx_shutdown((LibHalContext*)m_context, 0 );
|
||||
libhal_ctx_free ((LibHalContext*)m_context);
|
||||
#ifdef DBUS_QT3
|
||||
//TQDBusConnection::closeConnection("sbus");
|
||||
#else
|
||||
//delete m_dBusTQtConnect;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
k9HalConnection * k9HalConnection::getInstance() {
|
||||
if (Hinstance==NULL)
|
||||
Hinstance=new k9HalConnection(NULL,NULL);
|
||||
return Hinstance;
|
||||
}
|
||||
|
||||
k9HalDevice *k9HalConnection::findDevice( const char *udi) {
|
||||
for (k9HalDevice *dev= m_devices.first();dev;dev=m_devices.next()) {
|
||||
if (dev->name()==TQString(udi))
|
||||
return dev;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
k9HalDevice *k9HalConnection::findDeviceByVolume( const char *udi) {
|
||||
for (k9HalDevice *dev= m_devices.first();dev;dev=m_devices.next()) {
|
||||
if (dev->getVolumeUdi()==TQString(udi))
|
||||
return dev;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void k9HalConnection::end() {
|
||||
if (Hinstance !=NULL){
|
||||
delete Hinstance;
|
||||
}
|
||||
Hinstance=NULL;
|
||||
}
|
||||
#include "k9halconnection.moc"
|
||||
#endif
|
@ -1,72 +0,0 @@
|
||||
//
|
||||
// C++ Interface: k9halconnection
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// Author: Jean-Michel PETIT <k9copy@free.fr>, (C) 2007
|
||||
//
|
||||
// Copyright: See COPYING file that comes with this distribution
|
||||
//
|
||||
//
|
||||
#include "k9common.h"
|
||||
|
||||
#ifdef Q_MOC_RUN
|
||||
#define HAVE_HAL
|
||||
#endif // Q_MOC_RUN
|
||||
|
||||
#ifdef HAVE_HAL
|
||||
#ifndef K9HALCONNECTION_H
|
||||
#define K9HALCONNECTION_H
|
||||
|
||||
#include <tqobject.h>
|
||||
#include <tqptrlist.h>
|
||||
#include "k9dbusdispatch.h"
|
||||
/**
|
||||
@author Jean-Michel PETIT <k9copy@free.fr>
|
||||
*/
|
||||
|
||||
class k9HalDevice;
|
||||
class DBusConnection;
|
||||
#ifdef DBUS_QT3
|
||||
class TQDBusConnection;
|
||||
#else
|
||||
namespace DBusTQt {
|
||||
class Connection;
|
||||
};
|
||||
#endif
|
||||
|
||||
class k9HalConnection : public TQObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
friend class k9HalDevice;
|
||||
public:
|
||||
static k9HalConnection* getInstance();
|
||||
static void end();
|
||||
|
||||
TQPtrList< k9HalDevice > getDevices() const { return m_devices;}
|
||||
void addDevice( const char* udi );
|
||||
void removeDevice( const char* udi );
|
||||
void testVolumeChanged( const char * udi);
|
||||
k9HalDevice *findDevice (const char* udi);
|
||||
k9HalDevice *findDeviceByVolume (const char* udi);
|
||||
signals:
|
||||
void deviceAdded(k9HalDevice *);
|
||||
void deviceRemoved(k9HalDevice*);
|
||||
private:
|
||||
TQPtrList <k9HalDevice> m_devices;
|
||||
void *m_context;
|
||||
DBusConnection * m_dbusConnect;
|
||||
K9DBusDispatch *m_dbusDispatch;
|
||||
private:
|
||||
|
||||
k9HalConnection(TQObject *parent = 0, const char *name = 0);
|
||||
|
||||
~k9HalConnection();
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
@ -1,112 +0,0 @@
|
||||
//
|
||||
// C++ Implementation: k9haldevice
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// Author: Jean-Michel PETIT <k9copy@free.fr>, (C) 2007
|
||||
//
|
||||
// Copyright: See COPYING file that comes with this distribution
|
||||
//
|
||||
//
|
||||
#include "k9haldevice.h"
|
||||
#ifdef HAVE_HAL
|
||||
#include "k9halconnection.h"
|
||||
#define DBUS_API_SUBJECT_TO_CHANGE
|
||||
#include <dbus/dbus.h>
|
||||
#include <hal/libhal.h>
|
||||
#include <hal/libhal-storage.h>
|
||||
|
||||
k9HalDevice::k9HalDevice(TQObject *parent, const char *udi)
|
||||
: TQObject(parent, udi) {
|
||||
|
||||
m_connection=(k9HalConnection*)parent;
|
||||
getDriveProperties();
|
||||
}
|
||||
|
||||
k9HalDevice::~k9HalDevice() {}
|
||||
|
||||
TQString k9HalDevice::volumeName() {
|
||||
TQString sVol("");
|
||||
LibHalDrive *drive= libhal_drive_from_udi ((LibHalContext *)m_connection->m_context, name());
|
||||
int num_volumes;
|
||||
if (drive !=NULL) {
|
||||
char** volumes = libhal_drive_find_all_volumes ((LibHalContext *)m_connection->m_context, drive, &num_volumes);
|
||||
if (volumes != NULL) {
|
||||
for (int i = 0; i < num_volumes; i++) {
|
||||
char *volume_udi;
|
||||
LibHalVolume *volume;
|
||||
volume_udi = volumes[i];
|
||||
TQString s(volume_udi);
|
||||
m_volumeUdi=s;
|
||||
volume = libhal_volume_from_udi ((LibHalContext *)m_connection->m_context, volume_udi);
|
||||
if (volume != NULL) {
|
||||
sVol=TQString(libhal_volume_get_label (volume));
|
||||
libhal_volume_free (volume);
|
||||
}
|
||||
}
|
||||
if (num_volumes >0)
|
||||
libhal_free_string_array (volumes);
|
||||
}
|
||||
libhal_drive_free(drive);
|
||||
}
|
||||
return sVol;
|
||||
}
|
||||
|
||||
TQString k9HalDevice::mountPoint() {
|
||||
TQString sMountPoint("");
|
||||
LibHalDrive *drive= libhal_drive_from_udi ((LibHalContext *)m_connection->m_context, name());
|
||||
if (drive !=NULL) {
|
||||
int num_volumes;
|
||||
char** volumes = libhal_drive_find_all_volumes ((LibHalContext *)m_connection->m_context, drive, &num_volumes);
|
||||
if (volumes != NULL) {
|
||||
for (int i = 0; i < num_volumes; i++) {
|
||||
char *volume_udi;
|
||||
LibHalVolume *volume;
|
||||
volume_udi = volumes[i];
|
||||
volume = libhal_volume_from_udi ((LibHalContext *)m_connection->m_context, volume_udi);
|
||||
if (volume != NULL) {
|
||||
sMountPoint=TQString(libhal_volume_get_mount_point (volume));
|
||||
libhal_volume_free (volume);
|
||||
}
|
||||
}
|
||||
if (num_volumes >0)
|
||||
libhal_free_string_array (volumes);
|
||||
}
|
||||
libhal_drive_free(drive);
|
||||
}
|
||||
return sMountPoint;
|
||||
}
|
||||
|
||||
|
||||
void k9HalDevice::updateVolumeName() {
|
||||
m_volumeName=volumeName();
|
||||
emit volumeChanged(this->getDeviceName(),m_volumeName);
|
||||
}
|
||||
|
||||
void k9HalDevice::getDriveProperties() {
|
||||
LibHalContext *context=(LibHalContext *)m_connection->m_context;
|
||||
LibHalDrive *drive= libhal_drive_from_udi (context, name());
|
||||
LibHalDriveCdromCaps caps;
|
||||
caps= libhal_drive_get_cdrom_caps (drive);
|
||||
m_canReadCd=m_canReadDvd=m_canBurnCd=m_canBurnDvd=false;
|
||||
m_canReadCd= (caps & LIBHAL_DRIVE_CDROM_CAPS_CDROM)==LIBHAL_DRIVE_CDROM_CAPS_CDROM;
|
||||
m_canBurnCd= (caps & LIBHAL_DRIVE_CDROM_CAPS_CDR)==LIBHAL_DRIVE_CDROM_CAPS_CDR;
|
||||
m_canReadDvd=(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDROM)==LIBHAL_DRIVE_CDROM_CAPS_DVDROM;
|
||||
m_canBurnDvd=(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDR)==LIBHAL_DRIVE_CDROM_CAPS_DVDR;
|
||||
m_model=TQString(libhal_drive_get_model(drive));
|
||||
// tqDebug("%s", (TQString("canReadDvd:%1 canBurnDvd:%2 model:%3").arg(m_canReadDvd).arg(m_canBurnDvd).arg(m_model)).ascii());
|
||||
|
||||
|
||||
libhal_drive_free(drive);
|
||||
if (libhal_device_property_exists( (LibHalContext*) m_connection->m_context, name(), "storage.cdrom.write_speed", 0 )) {
|
||||
m_maxWriteSpeed= libhal_device_get_property_int( (LibHalContext*)m_connection->m_context, name(), "storage.cdrom.write_speed", 0 );
|
||||
}
|
||||
char* dev = libhal_device_get_property_string( (LibHalContext*) m_connection->m_context, name(), "block.device", 0 );
|
||||
m_deviceName=TQString ( dev );
|
||||
libhal_free_string( dev );
|
||||
|
||||
m_volumeName=volumeName();
|
||||
}
|
||||
#include "k9haldevice.moc"
|
||||
#endif
|
@ -1,92 +0,0 @@
|
||||
//
|
||||
// C++ Interface: k9haldevice
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// Author: Jean-Michel PETIT <k9copy@free.fr>, (C) 2007
|
||||
//
|
||||
// Copyright: See COPYING file that comes with this distribution
|
||||
//
|
||||
//
|
||||
|
||||
#ifndef K9HALDEVICE_H
|
||||
#define K9HALDEVICE_H
|
||||
#include "k9common.h"
|
||||
|
||||
#ifdef Q_MOC_RUN
|
||||
#define HAVE_HAL
|
||||
#endif // Q_MOC_RUN
|
||||
|
||||
#ifdef HAVE_HAL
|
||||
|
||||
#include <tqobject.h>
|
||||
/**
|
||||
@author Jean-Michel PETIT <k9copy@free.fr>
|
||||
*/
|
||||
class k9HalConnection;
|
||||
class k9HalDevice : public TQObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
k9HalDevice(TQObject *parent = 0, const char *name = 0);
|
||||
|
||||
~k9HalDevice();
|
||||
|
||||
bool getCanReadCd() const {
|
||||
return m_canReadCd;
|
||||
}
|
||||
|
||||
bool getCanReadDvd() const {
|
||||
return m_canReadDvd;
|
||||
}
|
||||
|
||||
bool getCanBurnCd() const {
|
||||
return m_canBurnCd;
|
||||
}
|
||||
|
||||
bool getCanBurnDvd() const {
|
||||
return m_canBurnDvd;
|
||||
}
|
||||
|
||||
TQString getModel() const {
|
||||
return m_model;
|
||||
}
|
||||
|
||||
int getMaxWriteSpeed() const {
|
||||
return m_maxWriteSpeed;
|
||||
}
|
||||
|
||||
TQString getDeviceName() const {
|
||||
return m_deviceName;
|
||||
}
|
||||
void updateVolumeName();
|
||||
|
||||
TQString getVolumeUdi() const {
|
||||
return m_volumeUdi;
|
||||
}
|
||||
|
||||
TQString getVolumeName() const {
|
||||
return m_volumeName;
|
||||
}
|
||||
|
||||
TQString mountPoint();
|
||||
signals:
|
||||
void volumeChanged(const TQString &device,const TQString &volumeName);
|
||||
|
||||
private:
|
||||
TQString m_volumeName;
|
||||
TQString m_volumeUdi;
|
||||
k9HalConnection *m_connection;
|
||||
bool m_canReadCd,m_canReadDvd,m_canBurnCd,m_canBurnDvd;
|
||||
TQString m_model;
|
||||
TQString m_deviceName;
|
||||
int m_maxWriteSpeed;
|
||||
void getDriveProperties();
|
||||
TQString volumeName();
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
Loading…
Reference in new issue