Removed HAL dependant code.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/13/head
Michele Calgaro 2 years ago
parent acefd32da2
commit ce3d9531b6
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -49,7 +49,6 @@ option( WITH_MUSICBRAINZ "Enable Musicbrainz support" OFF )
option( WITH_SYSTEM_LIBSAMPLERATE
"Use system libsamplerate instead of bundled one" ON )
option( WITH_TDEHWLIB "Enable TDE hardware library support" ${WITH_ALL_OPTIONS} )
option( WITH_HAL "Enable hal support" OFF )
option( WITH_DEBUG "Enable extra debug" OFF )
# sound output plugins
@ -86,29 +85,25 @@ option( WITH_LAME "Enable support for mp3 encoding via lame" ${WITH_ALL
# WITH_LIBDVDREAD if disabled removes dvd reaping functionality
# requires libdvdread: http://dvdnav.mplayerhq.hu/
# WITH_MUSICBRAINZ if enabled adds support for musicbrainz service for
# query metadata about audio cds
# query metadata about audio cds
# requires media-libs/musicbrainz library: http://musicbrainz.org/doc/libmusicbrainz
# WITH_SYSTEM_LIBSAMPLERATE if disabled the bundled version of libsamplerate
# is used and staticaly linked into the k3b
# requires media-libs/libsamplerate: http://www.mega-nerd.com/SRC/
# WITH_HAL if enabled use of hal daemon instead of libtdehw for
# device management
# depricated
# is used and staticaly linked into the k3b
# requires media-libs/libsamplerate: http://www.mega-nerd.com/SRC/
# WITH_DEBUG if enabled extra debug output is provided
# WITH_ALSA if enabled build the alsa output driver; it's a good
# idea to enable it on a linux othervice sound playback
# may fallback to arts
# idea to enable it on a linux othervice sound playback
# may fallback to arts
# WITH_ARTS if disabled disables fuctionality to play audio (files
# or CDs, not sure exactly)
# or CDs, not sure exactly)
# requires arts (an optional part of TDE)
# WITH_FFMPEG if enabled build an ffmpeg decoding plugin
# requires ffmpeg
# WITH_FFMPEG_ALL_CODECS
# affects ffmpeg plugin
# if enabled makes ffmpeg to decode all formats is
# supports; this is untested and may result in some
# bugs: e.g. display of wrong length
# supports; this is untested and may result in some
# bugs: e.g. display of wrong length
# WITH_FLAC if enabled build flac decoding plugin
# requires media-sound/flac: http://flac.sourceforge.net
# WITH_LAME if enabled build mp3 encoding file via lame

@ -120,27 +120,6 @@ if( WITH_TDEHWLIB )
endif( )
##### hal #######################################
if( WITH_HAL )
pkg_search_module( HAL hal )
if( HAL_FOUND )
set ( HAVE_HAL 1 )
# search for dbus
pkg_search_module( DBUS dbus-1 )
if( NOT DBUS_FOUND )
tde_message_fatal( "dbus-1 is required, but was not found on your system" )
endif( )
# search for dbus-tqt
pkg_search_module( DBUS_TQT dbus-tqt )
if( NOT DBUS_TQT_FOUND )
tde_message_fatal( "dbus-tqt is required, but was not found on your system" )
endif()
else ( )
tde_message_fatal( "hal is required, but was not found on your system" )
endif( )
endif( )
##### arts ######################################
if( WITH_ARTS )

@ -15,7 +15,6 @@
#cmakedefine WITH_ARTS
#cmakedefine HAVE_TDEHWLIB
#cmakedefine HAVE_HAL
#cmakedefine K3B_FFMPEG_ALL_CODECS

@ -10,9 +10,6 @@
*/
#undef FLAC_NEWER_THAN_1_1_1
/* HAL API version 0.4 */
#undef HAL_0_4
/* Define to 1 if you have the <artsc/artsc.h> header file. */
#undef HAVE_ARTSC_ARTSC_H
@ -40,9 +37,6 @@
/* Define to 1 if you have the <FLAC++/decoder.h> header file. */
#undef HAVE_FLAC___DECODER_H
/* compile in HAL support */
#undef HAVE_HAL
/* Define to 1 if you have the <iconv.h> header file. */
#undef HAVE_ICONV_H

@ -19,7 +19,7 @@
#include "k3bjob.h"
#include <k3bdevicemanager.h>
#include <k3bhalconnection.h>
#include <k3bconnection.h>
#include <k3bexternalbinmanager.h>
#include <k3bdefaultexternalprograms.h>
#include <k3bglobals.h>
@ -202,11 +202,11 @@ void K3bCore::init()
externalBinManager()->search();
connect( K3bDevice::HalConnection::instance(), TQT_SIGNAL(deviceAdded(const TQString&)),
connect( K3bDevice::Connection::instance(), TQT_SIGNAL(deviceAdded(const TQString&)),
deviceManager(), TQT_SLOT(addDevice(const TQString&)) );
connect( K3bDevice::HalConnection::instance(), TQT_SIGNAL(deviceRemoved(const TQString&)),
connect( K3bDevice::Connection::instance(), TQT_SIGNAL(deviceRemoved(const TQString&)),
deviceManager(), TQT_SLOT(removeDevice(const TQString&)) );
TQStringList devList = K3bDevice::HalConnection::instance()->devices();
TQStringList devList = K3bDevice::Connection::instance()->devices();
if( devList.isEmpty() )
deviceManager()->scanBus();
else

@ -23,7 +23,7 @@
#include <k3bdeviceglobals.h>
#include <k3bexternalbinmanager.h>
#include <k3bcore.h>
#include <k3bhalconnection.h>
#include <k3bconnection.h>
#include <tdeversion.h>
#include <tdeglobal.h>
@ -580,7 +580,7 @@ bool K3b::unmount( K3bDevice::Device* dev )
return !p.exitStatus();
}
else {
return !K3bDevice::HalConnection::instance()->unmount( dev );
return !K3bDevice::Connection::instance()->unmount( dev );
}
}
@ -598,7 +598,7 @@ bool K3b::mount( K3bDevice::Device* dev )
return true;
#endif
if( !K3bDevice::HalConnection::instance()->mount( dev ) )
if( !K3bDevice::Connection::instance()->mount( dev ) )
return true;
// now try pmount
@ -616,7 +616,7 @@ bool K3b::mount( K3bDevice::Device* dev )
bool K3b::eject( K3bDevice::Device* dev )
{
if( !K3bDevice::HalConnection::instance()->eject( dev ) )
if( !K3bDevice::Connection::instance()->eject( dev ) )
return true;
if( K3b::isMounted( dev ) )

@ -242,14 +242,14 @@ namespace K3b
/**
* Tries to mount the medium. Since K3b does not gather any information
* about mount points the only methods used are pmount and HAL::mount
* about mount points the only methods used are pmount and tdehw lib mount
*/
LIBK3B_EXPORT bool mount( K3bDevice::Device* );
/**
* Ejects the medium in the device or simply opens the tray.
* This method improves over K3bDevice::Device::eject in that it
* unmounts before ejecting and introduces HAL support.
* unmounts before ejecting.
*/
LIBK3B_EXPORT bool eject( K3bDevice::Device* );
}

@ -15,7 +15,6 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${TDE_INCLUDE_DIR}
${TQT_INCLUDE_DIRS}
${HAL_INCLUDE_DIRS}
)
link_directories(
@ -28,10 +27,10 @@ link_directories(
tde_add_library( k3bdevice SHARED AUTOMOC
SOURCES k3bdevice.cpp k3bdevice_mmc.cpp k3bscsicommand.cpp k3btrack.cpp
k3btoc.cpp k3bdevicemanager.cpp k3bmsf.cpp k3bdiskinfo.cpp
k3bdeviceglobals.cpp k3bcrc.cpp k3bcdtext.cpp k3bhalconnection.cpp
k3bdeviceglobals.cpp k3bcrc.cpp k3bcdtext.cpp k3bconnection.cpp
k3bdebug.cpp
VERSION 5.0.0
LINK tdecore-shared ${TDEHW_LIBRARIES} ${HAL_LIBRARIES} ${DBUS_TQT_LIBRARIES}
LINK tdecore-shared ${TDEHW_LIBRARIES}
DESTINATION ${LIB_INSTALL_DIR}
)
@ -40,6 +39,6 @@ tde_add_library( k3bdevice SHARED AUTOMOC
install( FILES k3bdevicemanager.h k3bdevice.h k3btoc.h k3btrack.h
k3bdeviceglobals.h k3bdiskinfo.h k3bcdtext.h k3bmsf.h k3bdevicetypes.h
k3bdevice_export.h k3bhalconnection.h k3bdebug.h
k3bdevice_export.h k3bconnection.h k3bdebug.h
DESTINATION ${INCLUDE_INSTALL_DIR}
)

@ -1,4 +1,4 @@
AM_CPPFLAGS= -I$(srcdir)/libk3bdevice -I$(srcdir) $(all_includes) $(HAL_INCS) $(DBUSQT_CFLAGS)
AM_CPPFLAGS= -I$(srcdir)/libk3bdevice -I$(srcdir) $(all_includes)
KDE_CXXFLAGS = $(ENABLE_PERMISSIVE_FLAG)
@ -6,19 +6,19 @@ METASOURCES = AUTO
lib_LTLIBRARIES = libk3bdevice.la
libk3bdevice_la_LIBADD = $(LIB_TDEIO) $(RESMGR_LIB) $(CAM_LIB) $(HAL_DBUS_LIBS) $(LIB_TQT) $(LIB_TDECORE)
libk3bdevice_la_LIBADD = $(LIB_TDEIO) $(RESMGR_LIB) $(CAM_LIB) $(LIB_TQT) $(LIB_TDECORE)
# lib version 5 for K3b 1.0
libk3bdevice_la_LDFLAGS = $(all_libraries) -version-info 5:0:0 -no-undefined
libk3bdevice_la_SOURCES = k3bdevice.cpp k3bdevice_mmc.cpp k3bscsicommand.cpp \
k3btrack.cpp k3btoc.cpp k3bdevicemanager.cpp k3bmsf.cpp k3bdiskinfo.cpp \
k3bdeviceglobals.cpp k3bcrc.cpp k3bcdtext.cpp k3bhalconnection.cpp \
k3bdeviceglobals.cpp k3bcrc.cpp k3bcdtext.cpp k3bconnection.cpp \
k3bdebug.cpp
include_HEADERS = k3bdevicemanager.h k3bdevice.h k3btoc.h k3btrack.h \
k3bdeviceglobals.h k3bdiskinfo.h k3bcdtext.h k3bmsf.h k3bdevicetypes.h \
k3bdevice_export.h k3bhalconnection.h k3bdebug.h
k3bdevice_export.h k3bconnection.h k3bdebug.h
messages: rc.cpp
$(XGETTEXT) `find -name "*.cpp" -or -name "*.h"` -o $(podir)/libk3bdevice.pot

@ -5,16 +5,3 @@ if test -n "$RESMGR_LIB"; then
else
echo "K3b - Resmgr support: no"
fi
echo ""
if test x$have_hal = xyes; then
echo "K3b - Compile HAL support yes"
else
echo "K3b - Compile HAL support no"
if test "x$ac_cv_use_hal" = "xyes" ; then
echo "K3b - You are missing the HAL >= 0.5 headers and libraries"
echo "K3b - or the DBus Qt bindings."
fi
fi

@ -57,94 +57,3 @@ if test "$ac_cv_use_resmgr" = "yes"; then
AC_SUBST(RESMGR_LIB)
fi
dnl === check for resmgr - end ============
# HAL check from tdebase/tdeioslave/media
AC_ARG_WITH(
hal,
AS_HELP_STRING(
[--without-hal],
[build K3b without HAL support (default=no)]),
[ac_cv_use_hal=$withval],
[ac_cv_use_hal=yes]
)
if test "x$ac_cv_use_hal" = "xyes" ; then
########### Check for the HAL
AC_MSG_CHECKING(for the HAL)
hal_inc=NOTFOUND
hal_lib=NOTFOUND
hal=NOTFOUND
search_incs="$kde_includes /usr/include /usr/include/hal /usr/local/include /usr/local/include/hal"
AC_FIND_FILE(libhal.h libhal-storage.h, $search_incs, hal_incdir)
if [test -r $hal_incdir/libhal.h] ; then
HAL_INCS="-I$hal_incdir"
hal_inc=FOUND
fi
if test -r $hal_incdir/libhal-storage.h ; then
hal_storage_version=4
grep LibHalVolume $hal_incdir/libhal-storage.h \
> /dev/null 2>&1 && hal_storage_version=5
if test $hal_storage_version = 4 ; then
AC_DEFINE(HAL_0_4, , [HAL API version 0.4])
fi
fi
search_libs="$kde_libraries /usr/lib64 /usr/lib /usr/local/lib /lib /lib64"
AC_FIND_FILE(libhal.so, $search_libs, hal_libdir)
if [test -r $hal_libdir/libhal.so] ; then
HAL_LIBS="-L$hal_libdir -lhal"
hal_lib=FOUND
fi
if [test $hal_inc = FOUND] && [test $hal_lib = FOUND] ; then
AC_MSG_RESULT(headers $hal_incdir libraries $hal_libdir)
hal=FOUND
else
AC_MSG_RESULT(searched but not found)
fi
AC_SUBST(HAL_INCS)
AC_SUBST(HAL_LIBS)
########### Check for DBus-TQt bindings
AC_MSG_CHECKING(for DBus with DBus-TQt bindings)
DBUS_REQ=1.0.0
PKG_CHECK_MODULES(DBUSQT, [ dbus-tqt dbus-1 >= $DBUS_REQ ],
dbus=FOUND,dbus=no)
AC_SUBST(DBUSQT_CFLAGS)
AC_SUBST(DBUSTQT_LIBS)
########### Check if media HAL backend sould be compiled
fi
have_hal=no
HAL_DBUS_LIBS=""
AC_MSG_RESULT(Found HAL storage version $hal_storage_version)
if [test "x$hal" = "xFOUND"] && [test "x$dbus" = "xFOUND"] && [ test $hal_storage_version = 5 ] ; then
AC_DEFINE(HAVE_HAL, , [compile in HAL support])
have_hal=yes
HAL_DBUS_LIBS="$HAL_LIBS $DBUSTQT_LIBS"
fi
AM_CONDITIONAL(include_HAL, [test x$have_hal = xyes])
AC_SUBST(HAL_DBUS_LIBS)

@ -0,0 +1,355 @@
/*
*
* $Id: sourceheader,v 1.3 2005/01/19 13:03:46 trueg Exp $
* Copyright (C) 2005-2007 Sebastian Trueg <trueg@k3b.org>
* Copyright (C) 2013 Timothy Pearson <kb9vqf@pearsoncomputing.net>
*
* This file is part of the K3b project.
* Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
* Copyright (C) 2013 Timothy Pearson <kb9vqf@pearsoncomputing.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* See the file "COPYING" for the exact licensing terms.
*/
#include "k3bconnection.h"
#include "k3bdevice.h"
#include <k3bdebug.h>
#include <tdelocale.h>
#include <tqtimer.h>
#include <tqvariant.h>
#ifdef HAVE_TDEHWLIB
#include <tdehardwaredevices.h>
#else
#define TDEHardwareDevices void
#endif
K3bDevice::Connection* K3bDevice::Connection::s_instance = 0;
class K3bDevice::Connection::Private
{
public:
Private()
: bOpen(false),
m_hwdevices(NULL) {
//
}
bool bOpen;
TDEHardwareDevices *m_hwdevices;
TQMap<TQString, TQString> udiDeviceMap;
TQMap<TQString, TQString> deviceUdiMap;
TQMap<TQString, bool> deviceMediumUdiMap;
};
K3bDevice::Connection* K3bDevice::Connection::instance()
{
if (s_instance == 0) {
s_instance = new Connection(0);
}
if ((!s_instance->isConnected()) && (!s_instance->open())) {
k3bDebug() << "(K3bDevice::Connection) failed to initialize the TDE hardware backend." << endl;
}
return s_instance;
}
K3bDevice::Connection::Connection( TQObject* parent, const char* name )
: TQObject( parent, name )
{
d = new Private();
}
K3bDevice::Connection::~Connection()
{
s_instance = 0;
close();
delete d;
}
bool K3bDevice::Connection::isConnected() const
{
return d->bOpen;
}
bool K3bDevice::Connection::open()
{
#ifdef HAVE_TDEHWLIB
// Initialize the TDE device manager
d->m_hwdevices = TDEGlobal::hardwareDevices();
// Connect device monitoring signals/slots
connect(d->m_hwdevices, TQT_SIGNAL(hardwareAdded(TDEGenericDevice*)), this, TQT_SLOT(AddDeviceHandler(TDEGenericDevice*)));
connect(d->m_hwdevices, TQT_SIGNAL(hardwareRemoved(TDEGenericDevice*)), this, TQT_SLOT(RemoveDeviceHandler(TDEGenericDevice*)));
connect(d->m_hwdevices, TQT_SIGNAL(hardwareUpdated(TDEGenericDevice*)), this, TQT_SLOT(ModifyDeviceHandler(TDEGenericDevice*)));
d->bOpen = true;
//
// Report all devices
//
TDEGenericHardwareList hwlist = d->m_hwdevices->listAllPhysicalDevices();
TDEGenericDevice *hwdevice;
for (hwdevice = hwlist.first(); hwdevice; hwdevice = hwlist.next()) {
AddDeviceHandler(hwdevice);
}
return true;
#else
return false;
#endif
}
void K3bDevice::Connection::close()
{
d->bOpen = false;
}
TQStringList K3bDevice::Connection::devices() const
{
return TQStringList(d->udiDeviceMap.values());
}
void K3bDevice::Connection::AddDeviceHandler(TDEGenericDevice* hwdevice)
{
#ifdef HAVE_TDEHWLIB
if (hwdevice->type() != TDEGenericDeviceType::Disk) {
return;
}
TQString udi = hwdevice->uniqueID();
TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice);
if (sdevice->diskType() & TDEDiskDeviceType::Optical) {
TQString blockDevice = sdevice->deviceNode();
if (!blockDevice.isEmpty()) {
k3bDebug() << "Mapping udi " << udi << " to device " << blockDevice << endl;
d->udiDeviceMap[udi] = blockDevice;
d->deviceUdiMap[blockDevice] = udi;
emit deviceAdded(blockDevice);
// Check for medium
if (sdevice->mediaInserted()) {
d->deviceMediumUdiMap[blockDevice] = true;
emit mediumChanged(blockDevice);
}
}
}
#endif
}
void K3bDevice::Connection::RemoveDeviceHandler(TDEGenericDevice* hwdevice)
{
#ifdef HAVE_TDEHWLIB
if (hwdevice->type() != TDEGenericDeviceType::Disk) {
return;
}
TQString udi = hwdevice->uniqueID();
TQString blockDevice = hwdevice->deviceNode();
TQMapIterator<TQString, TQString> it = d->udiDeviceMap.find(udi);
if (it != d->udiDeviceMap.end()) {
k3bDebug() << "Unmapping udi " << udi << " from device " << it.data() << endl;
emit deviceRemoved(it.data());
d->udiDeviceMap.erase(it);
d->deviceUdiMap.erase(it.data());
if (d->deviceMediumUdiMap[blockDevice]) {
d->deviceMediumUdiMap[blockDevice] = false;
emit mediumChanged(blockDevice);
}
}
#endif
}
void K3bDevice::Connection::ModifyDeviceHandler(TDEGenericDevice* hwdevice)
{
#ifdef HAVE_TDEHWLIB
if (hwdevice->type() != TDEGenericDeviceType::Disk) {
return;
}
TQString udi = hwdevice->uniqueID();
TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice);
TQString blockDevice = hwdevice->deviceNode();
if (d->deviceMediumUdiMap[blockDevice] != sdevice->mediaInserted()) {
d->deviceMediumUdiMap[blockDevice] = sdevice->mediaInserted();
emit mediumChanged(blockDevice);
}
#endif
}
int K3bDevice::Connection::lock(Device* dev)
{
#ifdef HAVE_TDEHWLIB
if (!d->deviceUdiMap.contains(dev->blockDeviceName())) {
return ErrorCodes::Device_Volume_NoSuchDevice;
}
TQString udi = d->deviceUdiMap[dev->blockDeviceName()];
TDEGenericDevice *hwdevice = d->m_hwdevices->findByUniqueID(udi);
if (!hwdevice) {
return ErrorCodes::Device_Volume_NoSuchDevice;
}
if (hwdevice->type() != TDEGenericDeviceType::Disk) {
return ErrorCodes::Device_Volume_NoSuchDevice;
}
TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice);
if (sdevice->lockDriveMedia(true)) {
return ErrorCodes::Success;
}
else {
return ErrorCodes::Device_Volume_InvalidEjectOption;
}
#else
return ErrorCodes::Device_Volume_NoSuchDevice;
#endif
}
int K3bDevice::Connection::unlock(Device* dev)
{
#ifdef HAVE_TDEHWLIB
if (!d->deviceUdiMap.contains(dev->blockDeviceName())) {
return ErrorCodes::Device_Volume_NoSuchDevice;
}
TQString udi = d->deviceUdiMap[dev->blockDeviceName()];
TDEGenericDevice *hwdevice = d->m_hwdevices->findByUniqueID(udi);
if (!hwdevice) {
return ErrorCodes::Device_Volume_NoSuchDevice;
}
if (hwdevice->type() != TDEGenericDeviceType::Disk) {
return ErrorCodes::Device_Volume_NoSuchDevice;
}
TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice);
if (sdevice->lockDriveMedia(false)) {
return ErrorCodes::Success;
}
else {
return ErrorCodes::Device_Volume_InvalidEjectOption;
}
#else
return ErrorCodes::Device_Volume_NoSuchDevice;
#endif
}
int K3bDevice::Connection::mount( K3bDevice::Device* dev,
const TQString& mountPoint,
const TQString& fstype,
const TQStringList& options )
{
#ifdef HAVE_TDEHWLIB
if (!d->deviceUdiMap.contains(dev->blockDeviceName())) {
return ErrorCodes::Device_Volume_NoSuchDevice;
}
TQString udi = d->deviceUdiMap[dev->blockDeviceName()];
TDEGenericDevice *hwdevice = d->m_hwdevices->findByUniqueID(udi);
if (!hwdevice) {
return ErrorCodes::Device_Volume_NoSuchDevice;
}
if (hwdevice->type() != TDEGenericDeviceType::Disk) {
return ErrorCodes::Device_Volume_NoSuchDevice;
}
TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice);
// FIXME
// Options from 'options' are not currently loaded into 'mountOptions'
TDEStorageMountOptions mountOptions;
TQStringVariantMap mountResult = sdevice->mountDevice(mountPoint, mountOptions);
TQString mountedPath = mountResult.contains("mountPath") ? mountResult["mountPath"].toString() : TQString::null;
if (mountedPath.isEmpty()) {
return ErrorCodes::CommunicationError;
}
else {
return ErrorCodes::Success;
}
#else
return ErrorCodes::Device_Volume_NoSuchDevice;
#endif
}
int K3bDevice::Connection::unmount(K3bDevice::Device* dev, const TQStringList& options)
{
#ifdef HAVE_TDEHWLIB
if (!d->deviceUdiMap.contains(dev->blockDeviceName())) {
return ErrorCodes::Device_Volume_NoSuchDevice;
}
TQString udi = d->deviceUdiMap[dev->blockDeviceName()];
TDEGenericDevice *hwdevice = d->m_hwdevices->findByUniqueID(udi);
if (!hwdevice) {
return ErrorCodes::Device_Volume_NoSuchDevice;
}
if (hwdevice->type() != TDEGenericDeviceType::Disk) {
return ErrorCodes::Device_Volume_NoSuchDevice;
}
TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice);
// FIXME
// Options from 'options' are not currently loaded into 'mountOptions'
TQString mountOptions;
TQStringVariantMap unmountResult = sdevice->unmountDevice();
if (unmountResult["result"].toBool() == false) {
// Unmount failed!
return ErrorCodes::CommunicationError;
}
else {
return ErrorCodes::Success;
}
#else
return ErrorCodes::Device_Volume_NoSuchDevice;
#endif
}
int K3bDevice::Connection::eject(K3bDevice::Device* dev, const TQStringList& options)
{
#ifdef HAVE_TDEHWLIB
if (!d->deviceUdiMap.contains(dev->blockDeviceName())) {
return ErrorCodes::Device_Volume_NoSuchDevice;
}
TQString udi = d->deviceUdiMap[dev->blockDeviceName()];
TDEGenericDevice *hwdevice = d->m_hwdevices->findByUniqueID(udi);
if (!hwdevice) {
return ErrorCodes::Device_Volume_NoSuchDevice;
}
if (hwdevice->type() != TDEGenericDeviceType::Disk) {
return ErrorCodes::Device_Volume_NoSuchDevice;
}
TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice);
if (sdevice->ejectDriveMedia()) {
return ErrorCodes::Success;
}
else {
return ErrorCodes::Device_Volume_InvalidEjectOption;
}
#else
return ErrorCodes::Device_Volume_NoSuchDevice;
#endif
}
#include "k3bconnection.moc"

@ -13,8 +13,8 @@
* See the file "COPYING" for the exact licensing terms.
*/
#ifndef _K3B_HAL_CONNECTION_H_
#define _K3B_HAL_CONNECTION_H_
#ifndef _K3B_CONNECTION_H_
#define _K3B_CONNECTION_H_
#ifdef HAVE_CONFIG_H
#include <config.h>
@ -27,9 +27,6 @@
#include <tqstringlist.h>
#include <kdemacros.h>
#ifdef HAVE_HAL
class DBusConnection;
#endif
#ifdef HAVE_TDEHWLIB
class TDEGenericDevice;
#else
@ -41,84 +38,72 @@ namespace K3bDevice {
class Device;
/**
* This is a simple HAL/DBUS wrapper which creates QT signals whenever a new optical
* This is a simple wrapper which creates QT signals whenever a new optical
* drive is plugged into the system or one is unplugged.
*
* The HalConnection class also handles media changes. Whenever a new medium is inserted
* The Connection class also handles media changes. Whenever a new medium is inserted
* into a drive or a medium is removed (i.e. ejected) a signal is emitted. This way it
* is easy to keep track of the inserted media.
*
* This class does not deal with K3b devices but with system device names
* such as /dev/cdrom. These device names can be used in DeviceManager::findDevice().
*/
class LIBK3BDEVICE_EXPORT HalConnection : public TQObject
class LIBK3BDEVICE_EXPORT Connection : public TQObject
{
Q_OBJECT
public:
~HalConnection();
~Connection();
/**
* Creates a new singleton HalConnection object or returns the already existing one.
* A newly created HalConnection will emit newDevice signals for all devices in the HAL
* manager. However, since one cannot be sure if this is the first time the HalConnection
* Creates a new singleton Connection object or returns the already existing one.
* A newly created Connection will emit newDevice signals for all devices in the
* manager. However, since one cannot be sure if this is the first time the Connection
* is created it is recommended to connect to the signals and query the list of current
* devices.
*
* \return An instance of the singleton HalConnection object.
* \return An instance of the singleton Connection object.
*/
static HalConnection* instance();
static Connection* instance();
/**
* \return true if a connection to the HAL deamon could be established and
* \return true if a connection to the deamon could be established and
* communication has been set up.
*/
bool isConnected() const;
/**
* \return a list of optical devices as reported by HAL.
* \return a list of optical devices as reported.
*/
TQStringList devices() const;
#ifdef HAVE_HAL
/**
* \internal
*/
void addDevice( const char* udi );
/**
* \internal
*/
void removeDevice( const char* udi );
#endif // HAVE_HAL
/**
* Error codes named as the HAL deamon raises them
* Error codes named as the deamon raises them
*/
enum ErrorCodes {
org_freedesktop_Hal_Success = 0, //*< The operation was successful. This code does not match any in HAL
org_freedesktop_Hal_CommunicationError, //*< DBus communication error. This code does not match any in HAL
org_freedesktop_Hal_NoSuchDevice,
org_freedesktop_Hal_DeviceAlreadyLocked,
org_freedesktop_Hal_PermissionDenied,
org_freedesktop_Hal_Device_Volume_NoSuchDevice,
org_freedesktop_Hal_Device_Volume_PermissionDenied,
org_freedesktop_Hal_Device_Volume_AlreadyMounted,
org_freedesktop_Hal_Device_Volume_InvalidMountOption,
org_freedesktop_Hal_Device_Volume_UnknownFilesystemType,
org_freedesktop_Hal_Device_Volume_InvalidMountpoint,
org_freedesktop_Hal_Device_Volume_MountPointNotAvailable,
org_freedesktop_Hal_Device_Volume_PermissionDeniedByPolicy,
org_freedesktop_Hal_Device_Volume_InvalidUnmountOption,
org_freedesktop_Hal_Device_Volume_InvalidEjectOption
Success = 0, //*< The operation was successful.
CommunicationError,
NoSuchDevice,
DeviceAlreadyLocked,
PermissionDenied,
Device_Volume_NoSuchDevice,
Device_Volume_PermissionDenied,
Device_Volume_AlreadyMounted,
Device_Volume_InvalidMountOption,
Device_Volume_UnknownFilesystemType,
Device_Volume_InvalidMountpoint,
Device_Volume_MountPointNotAvailable,
Device_Volume_PermissionDeniedByPolicy,
Device_Volume_InvalidUnmountOption,
Device_Volume_InvalidEjectOption
};
public slots:
/**
* Lock the device in HAL
* Lock the device
*
* Be aware that once the method returns the HAL deamon has not necessarily
* Be aware that once the method returns the deamon has not necessarily
* finished the procedure yet.
*
* \param dev The device to lock
@ -129,9 +114,9 @@ namespace K3bDevice {
int lock( Device* );
/**
* Unlock a previously locked device in HAL
* Unlock a previously locked device
*
* Be aware that once the method returns the HAL deamon has not necessarily
* Be aware that once the method returns the deamon has not necessarily
* finished the procedure yet.
*
* \param dev The device to lock
@ -142,9 +127,9 @@ namespace K3bDevice {
int unlock( Device* );
/**
* Mounts a device via HAL
* Mounts a device
*
* Be aware that once the method returns the HAL deamon has not necessarily
* Be aware that once the method returns the deamon has not necessarily
* finished the procedure yet.
*
* \param dev The device to lock
@ -158,9 +143,9 @@ namespace K3bDevice {
const TQStringList& options = TQStringList() );
/**
* Unmounts a device via HAL
* Unmounts a device
*
* Be aware that once the method returns the HAL deamon has not necessarily
* Be aware that once the method returns the deamon has not necessarily
* finished the procedure yet.
*
* \param dev The device to lock
@ -172,9 +157,9 @@ namespace K3bDevice {
const TQStringList& options = TQStringList() );
/**
* Unmounts a device via HAL
* Unmounts a device
*
* Be aware that once the method returns the HAL deamon has not necessarily
* Be aware that once the method returns the deamon has not necessarily
* finished the procedure yet.
*
* \param dev The device to lock
@ -203,14 +188,14 @@ namespace K3bDevice {
signals:
/**
* This signal gets emitted whenever HAL finds a new optical drive.
* This signal gets emitted whenever it finds a new optical drive.
*
* \param dev The block device name of the new drive.
*/
void deviceAdded( const TQString& dev );
/**
* This signal gets emitted whenever HAL detects that an optical drive
* This signal gets emitted whenever it detects that an optical drive
* has been unplugged.
*
* \param dev The block device name of the drive.
@ -227,24 +212,20 @@ namespace K3bDevice {
private:
/**
* HalConnection is a signelton class. Use the instance() method to create it.
* Connection is a signelton class. Use the instance() method to create it.
*/
HalConnection( TQObject* parent = 0, const char* name = 0 );
Connection( TQObject* parent = 0, const char* name = 0 );
/**
* Tries to open a connection to HAL.
* Tries to open a connection
*/
bool open();
void close();
static HalConnection* s_instance;
static Connection* s_instance;
class Private;
Private* d;
#ifdef HAVE_HAL
void setupDBusTQtConnection( DBusConnection* dbusConnection );
#endif // HAVE_HAL
};
}

@ -185,9 +185,6 @@ namespace K3bDevice {
/**
* Scan the system for devices. Call this to initialize all devices.
*
* If the system uses the HAL device deamon it is possible to use
* HalConnection instead of calling this method.
*
* \return Number of found devices.
**/
virtual int scanBus();
@ -214,7 +211,7 @@ namespace K3bDevice {
/**
* Remove a device from the device manager. Basicly this method
* only makes sense in combination with the HalConnection. Connect
* only makes sense in combination with the Connection. Connect
* it to the deviceRemoved signal.
*/
virtual void removeDevice( const TQString& dev );

@ -1,962 +0,0 @@
/*
*
* $Id: sourceheader,v 1.3 2005/01/19 13:03:46 trueg Exp $
* Copyright (C) 2005-2007 Sebastian Trueg <trueg@k3b.org>
* Copyright (C) 2013 Timothy Pearson <kb9vqf@pearsoncomputing.net>
*
* This file is part of the K3b project.
* Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
* Copyright (C) 2013 Timothy Pearson <kb9vqf@pearsoncomputing.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* See the file "COPYING" for the exact licensing terms.
*/
#include "k3bhalconnection.h"
#include "k3bdevice.h"
#include <k3bdebug.h>
#include <tdelocale.h>
#include <tqtimer.h>
#include <tqvariant.h>
#ifdef HAVE_HAL
// We acknowledge the the dbus API is unstable
#define DBUS_API_SUBJECT_TO_CHANGE
#include <dbus/connection.h>
#include <dbus/dbus.h>
#include <hal/libhal.h>
#endif
#ifdef HAVE_HAL
static char** qstringListToArray( const TQStringList& s )
{
char** a = new char*[s.count()];
for( unsigned int i = 0; i < s.count(); ++i ) {
a[i] = new char[s[i].length()+1];
::strncpy( a[i], s[i].local8Bit().data(), s[i].length() );
a[s[i].length()] = '\0';
}
return a;
}
static void freeArray( char** a, unsigned int length )
{
for( unsigned int i = 0; i < length; ++i )
delete [] a[i];
delete a;
}
// CALLBACKS
void halDeviceAdded( LibHalContext* ctx, const char* udi )
{
Q_UNUSED( ctx );
k3bDebug() << "adding udi " << udi << endl;
K3bDevice::HalConnection::instance()->addDevice( udi );
}
void halDeviceRemoved( LibHalContext* ctx, const char* udi )
{
Q_UNUSED( ctx );
k3bDebug() << "removing udi " << udi << endl;
K3bDevice::HalConnection::instance()->removeDevice( udi );
}
K3bDevice::HalConnection* K3bDevice::HalConnection::s_instance = 0;
class K3bDevice::HalConnection::Private
{
public:
Private()
: halContext(0),
dBusTQtConnection(0),
bOpen(false) {
}
LibHalContext* halContext;
DBusConnection* connection;
DBusQt::Connection* dBusTQtConnection;
bool bOpen;
TQMap<TQCString, TQString> udiDeviceMap;
TQMap<TQString, TQCString> deviceUdiMap;
TQMap<TQCString, TQCString> deviceMediumUdiMap;
};
K3bDevice::HalConnection* K3bDevice::HalConnection::instance()
{
if( s_instance == 0 )
s_instance = new HalConnection( 0 );
if( !s_instance->isConnected() && !s_instance->open() )
k3bDebug() << "(K3bDevice::HalConnection) failed to open connection to HAL." << endl;
return s_instance;
}
K3bDevice::HalConnection::HalConnection( TQObject* parent, const char* name )
: TQObject( parent, name )
{
d = new Private();
}
K3bDevice::HalConnection::~HalConnection()
{
s_instance = 0;
close();
delete d;
}
bool K3bDevice::HalConnection::isConnected() const
{
return d->bOpen;
}
bool K3bDevice::HalConnection::open()
{
close();
k3bDebug() << "(K3bDevice::HalConnection) initializing HAL >= 0.5" << endl;
d->halContext = libhal_ctx_new();
if( !d->halContext ) {
k3bDebug() << "(K3bDevice::HalConnection) unable to create HAL context." << endl;
return false;
}
DBusError error;
dbus_error_init( &error );
d->connection = dbus_bus_get( DBUS_BUS_SYSTEM, &error );
if( dbus_error_is_set(&error) ) {
k3bDebug() << "(K3bDevice::HalConnection) unable to connect to DBUS: " << error.message << endl;
return false;
}
setupDBusTQtConnection( d->connection );
libhal_ctx_set_dbus_connection( d->halContext, d->connection );
libhal_ctx_set_device_added( d->halContext, halDeviceAdded );
libhal_ctx_set_device_removed( d->halContext, halDeviceRemoved );
libhal_ctx_set_device_new_capability( d->halContext, 0 );
libhal_ctx_set_device_lost_capability( d->halContext, 0 );
libhal_ctx_set_device_property_modified( d->halContext, 0 );
libhal_ctx_set_device_condition( d->halContext, 0 );
if( !libhal_ctx_init( d->halContext, 0 ) ) {
k3bDebug() << "(K3bDevice::HalConnection) Failed to init HAL context!" << endl;
return false;
}
d->bOpen = true;
//
// report all devices
//
int numDevices;
char** halDeviceList = libhal_get_all_devices( d->halContext, &numDevices, 0 );
for( int i = 0; i < numDevices; ++i )
addDevice( halDeviceList[i] );
return true;
}
void K3bDevice::HalConnection::close()
{
if( d->halContext ) {
// clear the context
if( isConnected() )
libhal_ctx_shutdown( d->halContext, 0 );
libhal_ctx_free( d->halContext );
// delete the connection (may be 0 if open() failed)
delete d->dBusTQtConnection;
d->halContext = 0;
d->dBusTQtConnection = 0;
d->bOpen = false;
}
}
TQStringList K3bDevice::HalConnection::devices() const
{
return TQStringList( d->udiDeviceMap.values() );
}
void K3bDevice::HalConnection::addDevice( const char* udi )
{
// ignore devices that have no property "info.capabilities" to suppress error messages
if( !libhal_device_property_exists( d->halContext, udi, "info.capabilities", 0 ) )
return;
if( libhal_device_query_capability( d->halContext, udi, "storage.cdrom", 0 ) ) {
char* dev = libhal_device_get_property_string( d->halContext, udi, "block.device", 0 );
if( dev ) {
TQString s( dev );
libhal_free_string( dev );
if( !s.isEmpty() ) {
k3bDebug() << "Mapping udi " << udi << " to device " << s << endl;
d->udiDeviceMap[udi] = s;
d->deviceUdiMap[s] = udi;
emit deviceAdded( s );
}
}
}
else {
if( libhal_device_property_exists( d->halContext, udi, "block.storage_device", 0 ) ) {
char* deviceUdi = libhal_device_get_property_string( d->halContext, udi, "block.storage_device", 0 );
if( deviceUdi ) {
TQCString du( deviceUdi );
libhal_free_string( deviceUdi );
if( d->udiDeviceMap.contains( du ) ) {
//
// A new medium has been inserted. Save this medium's udi so we can reuse it later
// on for the mount/unmount/eject methods
//
d->deviceMediumUdiMap[du] = TQCString( udi );
emit mediumChanged( d->udiDeviceMap[du] );
}
}
}
}
}
void K3bDevice::HalConnection::removeDevice( const char* udi )
{
TQMapIterator<TQCString, TQString> it = d->udiDeviceMap.find( udi );
if( it != d->udiDeviceMap.end() ) {
k3bDebug() << "Unmapping udi " << udi << " from device " << it.data() << endl;
emit deviceRemoved( it.data() );
d->udiDeviceMap.erase( it );
d->deviceUdiMap.erase( it.data() );
}
else {
if( libhal_device_property_exists( d->halContext, udi, "block.storage_device", 0 ) ) {
char* deviceUdi = libhal_device_get_property_string( d->halContext, udi, "block.storage_device", 0 );
if( deviceUdi ) {
TQCString du( deviceUdi );
libhal_free_string( deviceUdi );
if( d->udiDeviceMap.contains( du ) ) {
//
// A medium has been removed/ejected.
//
d->deviceMediumUdiMap[du] = 0;
emit mediumChanged( d->udiDeviceMap[du] );
}
}
}
}
}
int K3bDevice::HalConnection::lock( Device* dev )
{
//
// The code below is based on the code from tdeioslave/media/mediamanager/halbackend.cpp in the tdebase package
// Copyright (c) 2004-2005 Jérôme Lodewyck <jerome dot lodewyck at normalesup dot org>
//
DBusMessage* dmesg = 0;
DBusMessage* reply = 0;
DBusError error;
if( !d->deviceUdiMap.contains( dev->blockDeviceName() ) ) {
return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
}
TQCString udi = d->deviceUdiMap[dev->blockDeviceName()];
if( !( dmesg = dbus_message_new_method_call( "org.freedesktop.Hal", udi.data(),
"org.freedesktop.Hal.Device",
"Lock" ) ) ) {
k3bDebug() << "(K3bDevice::HalConnection) lock failed for " << udi << ": could not create dbus message\n";
return org_freedesktop_Hal_CommunicationError;
}
const char* lockComment = "Locked by the K3b libraries";
if( !dbus_message_append_args( dmesg,
DBUS_TYPE_STRING, &lockComment,
DBUS_TYPE_INVALID ) ) {
k3bDebug() << "(K3bDevice::HalConnection) lock failed for " << udi << ": could not append args to dbus message\n";
dbus_message_unref( dmesg );
return org_freedesktop_Hal_CommunicationError;
}
int ret = org_freedesktop_Hal_Success;
dbus_error_init( &error );
reply = dbus_connection_send_with_reply_and_block( d->connection, dmesg, -1, &error );
if( dbus_error_is_set( &error ) ) {
kdError() << "(K3bDevice::HalConnection) lock failed for " << udi << ": " << error.name << " - " << error.message << endl;
if( !strcmp(error.name, "org.freedesktop.Hal.NoSuchDevice" ) )
ret = org_freedesktop_Hal_NoSuchDevice;
else if( !strcmp(error.name, "org.freedesktop.Hal.DeviceAlreadyLocked" ) )
ret = org_freedesktop_Hal_DeviceAlreadyLocked;
else if( !strcmp(error.name, "org.freedesktop.Hal.PermissionDenied" ) )
ret = org_freedesktop_Hal_PermissionDenied;
dbus_error_free( &error );
}
else
k3bDebug() << "(K3bDevice::HalConnection) lock queued for " << udi << endl;
dbus_message_unref( dmesg );
if( reply )
dbus_message_unref( reply );
return ret;
}
int K3bDevice::HalConnection::unlock( Device* dev )
{
//
// The code below is based on the code from tdeioslave/media/mediamanager/halbackend.cpp in the tdebase package
// Copyright (c) 2004-2005 Jérôme Lodewyck <jerome dot lodewyck at normalesup dot org>
//
DBusMessage* dmesg = 0;
DBusMessage* reply = 0;
DBusError error;
if( !d->deviceUdiMap.contains( dev->blockDeviceName() ) ) {
return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
}
TQCString udi = d->deviceUdiMap[dev->blockDeviceName()];
if( !( dmesg = dbus_message_new_method_call( "org.freedesktop.Hal", udi.data(),
"org.freedesktop.Hal.Device",
"Unlock" ) ) ) {
k3bDebug() << "(K3bDevice::HalConnection) unlock failed for " << udi << ": could not create dbus message\n";
return org_freedesktop_Hal_CommunicationError;
}
if( !dbus_message_append_args( dmesg,
DBUS_TYPE_INVALID ) ) {
k3bDebug() << "(K3bDevice::HalConnection) unlock failed for " << udi << ": could not append args to dbus message\n";
dbus_message_unref( dmesg );
return org_freedesktop_Hal_CommunicationError;
}
int ret = org_freedesktop_Hal_Success;
dbus_error_init( &error );
reply = dbus_connection_send_with_reply_and_block( d->connection, dmesg, -1, &error );
if( dbus_error_is_set( &error ) ) {
kdError() << "(K3bDevice::HalConnection) unlock failed for " << udi << ": " << error.name << " - " << error.message << endl;
if( !strcmp(error.name, "org.freedesktop.Hal.NoSuchDevice" ) )
ret = org_freedesktop_Hal_NoSuchDevice;
else if( !strcmp(error.name, "org.freedesktop.Hal.DeviceAlreadyLocked" ) )
ret = org_freedesktop_Hal_DeviceAlreadyLocked;
else if( !strcmp(error.name, "org.freedesktop.Hal.PermissionDenied" ) )
ret = org_freedesktop_Hal_PermissionDenied;
dbus_error_free( &error );
}
else
k3bDebug() << "(K3bDevice::HalConnection) unlock queued for " << udi << endl;
dbus_message_unref( dmesg );
if( reply )
dbus_message_unref( reply );
return ret;
}
int K3bDevice::HalConnection::mount( K3bDevice::Device* dev,
const TQString& mountPoint,
const TQString& fstype,
const TQStringList& options )
{
//
// The code below is based on the code from tdeioslave/media/mediamanager/halbackend.cpp in the tdebase package
// Copyright (c) 2004-2005 Jérôme Lodewyck <jerome dot lodewyck at normalesup dot org>
//
DBusMessage* dmesg = 0;
DBusMessage* reply = 0;
DBusError error;
if( !d->deviceUdiMap.contains( dev->blockDeviceName() ) )
return org_freedesktop_Hal_NoSuchDevice;
if( !d->deviceMediumUdiMap.contains( d->deviceUdiMap[dev->blockDeviceName()] ) )
return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
TQCString mediumUdi = d->deviceMediumUdiMap[d->deviceUdiMap[dev->blockDeviceName()]];
if( !( dmesg = dbus_message_new_method_call( "org.freedesktop.Hal", mediumUdi.data(),
"org.freedesktop.Hal.Device.Volume",
"Mount" ) ) ) {
k3bDebug() << "(K3bDevice::HalConnection) mount failed for " << mediumUdi << ": could not create dbus message\n";
return org_freedesktop_Hal_CommunicationError;
}
char** poptions = qstringListToArray( options );
TQByteArray strMountPoint = mountPoint.local8Bit();
TQByteArray strFstype = fstype.local8Bit();
if( !dbus_message_append_args( dmesg,
DBUS_TYPE_STRING, strMountPoint.data(),
DBUS_TYPE_STRING, strFstype.data(),
DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &poptions, options.count(),
DBUS_TYPE_INVALID ) ) {
k3bDebug() << "(K3bDevice::HalConnection) mount failed for " << mediumUdi << ": could not append args to dbus message\n";
dbus_message_unref( dmesg );
freeArray( poptions, options.count() );
return org_freedesktop_Hal_CommunicationError;
}
freeArray( poptions, options.count() );
int ret = org_freedesktop_Hal_Success;
dbus_error_init( &error );
reply = dbus_connection_send_with_reply_and_block( d->connection, dmesg, -1, &error );
if( dbus_error_is_set( &error ) ) {
kdError() << "(K3bDevice::HalConnection) mount failed for " << mediumUdi << ": " << error.name << " - " << error.message << endl;
if( !strcmp(error.name, "org.freedesktop.Hal.Device.Volume.NoSuchDevice" ) )
ret = org_freedesktop_Hal_Device_Volume_NoSuchDevice;
else if( !strcmp(error.name, "org.freedesktop.Hal.Device.Volume.PermissionDenied" ) )
ret = org_freedesktop_Hal_Device_Volume_PermissionDenied;
else if( !strcmp(error.name, "org.freedesktop.Hal.Device.Volume.UnknownFilesystemType" ) )
ret = org_freedesktop_Hal_Device_Volume_UnknownFilesystemType;
else if( !strcmp(error.name, "org.freedesktop.Hal.Device.Volume.MountPointNotAvailable" ) )
ret = org_freedesktop_Hal_Device_Volume_MountPointNotAvailable;
else if( !strcmp(error.name, "org.freedesktop.Hal.Device.Volume.AlreadyMounted" ) )
ret = org_freedesktop_Hal_Device_Volume_AlreadyMounted;
else if( !strcmp(error.name, "org.freedesktop.Hal.Device.Volume.InvalidMountpoint" ) )
ret = org_freedesktop_Hal_Device_Volume_InvalidMountpoint;
else if( !strcmp(error.name, "org.freedesktop.Hal.Device.Volume.InvalidMountOption" ) )
ret = org_freedesktop_Hal_Device_Volume_InvalidMountOption;
else if( !strcmp(error.name, "org.freedesktop.Hal.Device.Volume.PermissionDeniedByPolicy" ) )
ret = org_freedesktop_Hal_Device_Volume_PermissionDeniedByPolicy;
dbus_error_free( &error );
}
else
k3bDebug() << "(K3bDevice::HalConnection) mount queued for " << mediumUdi << endl;
dbus_message_unref( dmesg );
if( reply )
dbus_message_unref( reply );
return ret;
}
int K3bDevice::HalConnection::unmount( K3bDevice::Device* dev,
const TQStringList& options )
{
//
// The code below is based on the code from tdeioslave/media/mediamanager/halbackend.cpp in the tdebase package
// Copyright (c) 2004-2005 Jérôme Lodewyck <jerome dot lodewyck at normalesup dot org>
//
DBusMessage* dmesg = 0;
DBusMessage* reply = 0;
DBusError error;
if( !d->deviceUdiMap.contains( dev->blockDeviceName() ) )
return org_freedesktop_Hal_NoSuchDevice;
if( !d->deviceMediumUdiMap.contains( d->deviceUdiMap[dev->blockDeviceName()] ) )
return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
TQCString mediumUdi = d->deviceMediumUdiMap[d->deviceUdiMap[dev->blockDeviceName()]];
if( !( dmesg = dbus_message_new_method_call( "org.freedesktop.Hal", mediumUdi.data(),
"org.freedesktop.Hal.Device.Volume",
"Unmount" ) ) ) {
k3bDebug() << "(K3bDevice::HalConnection) unmount failed for " << mediumUdi << ": could not create dbus message\n";
return org_freedesktop_Hal_CommunicationError;
}
char** poptions = qstringListToArray( options );
if( !dbus_message_append_args( dmesg,
DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &poptions, options.count(),
DBUS_TYPE_INVALID ) ) {
k3bDebug() << "(K3bDevice::HalConnection) unmount failed for " << mediumUdi << ": could not append args to dbus message\n";
dbus_message_unref( dmesg );
freeArray( poptions, options.count() );
return org_freedesktop_Hal_CommunicationError;
}
freeArray( poptions, options.count() );
int ret = org_freedesktop_Hal_Success;
dbus_error_init( &error );
reply = dbus_connection_send_with_reply_and_block( d->connection, dmesg, -1, &error );
if( dbus_error_is_set( &error ) ) {
kdError() << "(K3bDevice::HalConnection) unmount failed for " << mediumUdi << ": " << error.name << " - " << error.message << endl;
if( !strcmp(error.name, "org.freedesktop.Hal.Device.Volume.NoSuchDevice" ) )
ret = org_freedesktop_Hal_Device_Volume_NoSuchDevice;
else if( !strcmp(error.name, "org.freedesktop.Hal.Device.Volume.PermissionDenied" ) )
ret = org_freedesktop_Hal_Device_Volume_PermissionDenied;
else if( !strcmp(error.name, "org.freedesktop.Hal.Device.Volume.MountPointNotAvailable" ) )
ret = org_freedesktop_Hal_Device_Volume_MountPointNotAvailable;
else if( !strcmp(error.name, "org.freedesktop.Hal.Device.Volume.InvalidUnmountOption" ) )
ret = org_freedesktop_Hal_Device_Volume_InvalidUnmountOption;
else if( !strcmp(error.name, "org.freedesktop.Hal.Device.Volume.InvalidMountpoint" ) )
ret = org_freedesktop_Hal_Device_Volume_InvalidMountpoint;
else if( !strcmp(error.name, "org.freedesktop.Hal.Device.Volume.PermissionDeniedByPolicy" ) )
ret = org_freedesktop_Hal_Device_Volume_PermissionDeniedByPolicy;
dbus_error_free( &error );
}
else
k3bDebug() << "(K3bDevice::HalConnection) unmount queued for " << mediumUdi << endl;
dbus_message_unref( dmesg );
if( reply )
dbus_message_unref( reply );
return ret;
}
int K3bDevice::HalConnection::eject( K3bDevice::Device* dev,
const TQStringList& options )
{
//
// The code below is based on the code from tdeioslave/media/mediamanager/halbackend.cpp in the tdebase package
// Copyright (c) 2004-2005 Jérôme Lodewyck <jerome dot lodewyck at normalesup dot org>
//
DBusMessage* dmesg = 0;
DBusMessage* reply = 0;
DBusError error;
if( !d->deviceUdiMap.contains( dev->blockDeviceName() ) )
return org_freedesktop_Hal_NoSuchDevice;
if( !d->deviceMediumUdiMap.contains( d->deviceUdiMap[dev->blockDeviceName()] ) )
return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
TQCString mediumUdi = d->deviceMediumUdiMap[d->deviceUdiMap[dev->blockDeviceName()]];
if( !( dmesg = dbus_message_new_method_call( "org.freedesktop.Hal", mediumUdi.data(),
"org.freedesktop.Hal.Device.Volume",
"Eject" ) ) ) {
k3bDebug() << "(K3bDevice::HalConnection) eject failed for " << mediumUdi << ": could not create dbus message\n";
return org_freedesktop_Hal_CommunicationError;
}
char** poptions = qstringListToArray( options );
if( !dbus_message_append_args( dmesg,
DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &poptions, options.count(),
DBUS_TYPE_INVALID ) ) {
k3bDebug() << "(K3bDevice::HalConnection) eject failed for " << mediumUdi << ": could not append args to dbus message\n";
dbus_message_unref( dmesg );
freeArray( poptions, options.count() );
return org_freedesktop_Hal_CommunicationError;
}
freeArray( poptions, options.count() );
int ret = org_freedesktop_Hal_Success;
dbus_error_init( &error );
reply = dbus_connection_send_with_reply_and_block( d->connection, dmesg, -1, &error );
if( dbus_error_is_set( &error ) ) {
kdError() << "(K3bDevice::HalConnection) eject failed for " << mediumUdi << ": " << error.name << " - " << error.message << endl;
if( !strcmp(error.name, "org.freedesktop.Hal.Device.Volume.NoSuchDevice" ) )
ret = org_freedesktop_Hal_Device_Volume_NoSuchDevice;
else if( !strcmp(error.name, "org.freedesktop.Hal.Device.Volume.PermissionDenied" ) )
ret = org_freedesktop_Hal_Device_Volume_PermissionDenied;
else if( !strcmp(error.name, "org.freedesktop.Hal.Device.Volume.InvalidEjectOption" ) )
ret = org_freedesktop_Hal_Device_Volume_InvalidEjectOption;
else if( !strcmp(error.name, "org.freedesktop.Hal.Device.Volume.PermissionDeniedByPolicy" ) )
ret = org_freedesktop_Hal_Device_Volume_PermissionDeniedByPolicy;
dbus_error_free( &error );
}
else
k3bDebug() << "(K3bDevice::HalConnection) eject queued for " << mediumUdi << endl;
dbus_message_unref( dmesg );
if( reply )
dbus_message_unref( reply );
return ret;
}
void K3bDevice::HalConnection::setupDBusTQtConnection( DBusConnection* dbusConnection )
{
d->dBusTQtConnection = new DBusQt::Connection( this );
d->dBusTQtConnection->dbus_connection_setup_with_qt_main( dbusConnection );
}
void K3bDevice::HalConnection::AddDeviceHandler(TDEGenericDevice* hwdevice)
{
// Empty body, only to avoid linking errors
}
void K3bDevice::HalConnection::RemoveDeviceHandler(TDEGenericDevice* hwdevice)
{
// Empty body, only to avoid linking errors
}
void K3bDevice::HalConnection::ModifyDeviceHandler(TDEGenericDevice* hwdevice)
{
// Empty body, only to avoid linking errors
}
#else // HAVE_HAL
#ifdef HAVE_TDEHWLIB
#include <tdehardwaredevices.h>
#else
#define TDEHardwareDevices void
#endif
K3bDevice::HalConnection* K3bDevice::HalConnection::s_instance = 0;
class K3bDevice::HalConnection::Private
{
public:
Private()
: bOpen(false),
m_hwdevices(NULL) {
//
}
bool bOpen;
TDEHardwareDevices *m_hwdevices;
TQMap<TQString, TQString> udiDeviceMap;
TQMap<TQString, TQString> deviceUdiMap;
TQMap<TQString, bool> deviceMediumUdiMap;
};
K3bDevice::HalConnection* K3bDevice::HalConnection::instance()
{
if (s_instance == 0) {
s_instance = new HalConnection(0);
}
if ((!s_instance->isConnected()) && (!s_instance->open())) {
k3bDebug() << "(K3bDevice::HalConnection) failed to initialize the TDE hardware backend." << endl;
}
return s_instance;
}
K3bDevice::HalConnection::HalConnection( TQObject* parent, const char* name )
: TQObject( parent, name )
{
d = new Private();
}
K3bDevice::HalConnection::~HalConnection()
{
s_instance = 0;
close();
delete d;
}
bool K3bDevice::HalConnection::isConnected() const
{
return d->bOpen;
}
bool K3bDevice::HalConnection::open()
{
#ifdef HAVE_TDEHWLIB
// Initialize the TDE device manager
d->m_hwdevices = TDEGlobal::hardwareDevices();
// Connect device monitoring signals/slots
connect(d->m_hwdevices, TQT_SIGNAL(hardwareAdded(TDEGenericDevice*)), this, TQT_SLOT(AddDeviceHandler(TDEGenericDevice*)));
connect(d->m_hwdevices, TQT_SIGNAL(hardwareRemoved(TDEGenericDevice*)), this, TQT_SLOT(RemoveDeviceHandler(TDEGenericDevice*)));
connect(d->m_hwdevices, TQT_SIGNAL(hardwareUpdated(TDEGenericDevice*)), this, TQT_SLOT(ModifyDeviceHandler(TDEGenericDevice*)));
d->bOpen = true;
//
// Report all devices
//
TDEGenericHardwareList hwlist = d->m_hwdevices->listAllPhysicalDevices();
TDEGenericDevice *hwdevice;
for (hwdevice = hwlist.first(); hwdevice; hwdevice = hwlist.next()) {
AddDeviceHandler(hwdevice);
}
return true;
#else
return false;
#endif
}
void K3bDevice::HalConnection::close()
{
d->bOpen = false;
}
TQStringList K3bDevice::HalConnection::devices() const
{
return TQStringList(d->udiDeviceMap.values());
}
void K3bDevice::HalConnection::AddDeviceHandler(TDEGenericDevice* hwdevice)
{
#ifdef HAVE_TDEHWLIB
if (hwdevice->type() != TDEGenericDeviceType::Disk) {
return;
}
TQString udi = hwdevice->uniqueID();
TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice);
if (sdevice->diskType() & TDEDiskDeviceType::Optical) {
TQString blockDevice = sdevice->deviceNode();
if (!blockDevice.isEmpty()) {
k3bDebug() << "Mapping udi " << udi << " to device " << blockDevice << endl;
d->udiDeviceMap[udi] = blockDevice;
d->deviceUdiMap[blockDevice] = udi;
emit deviceAdded(blockDevice);
// Check for medium
if (sdevice->mediaInserted()) {
d->deviceMediumUdiMap[blockDevice] = true;
emit mediumChanged(blockDevice);
}
}
}
#endif
}
void K3bDevice::HalConnection::RemoveDeviceHandler(TDEGenericDevice* hwdevice)
{
#ifdef HAVE_TDEHWLIB
if (hwdevice->type() != TDEGenericDeviceType::Disk) {
return;
}
TQString udi = hwdevice->uniqueID();
TQString blockDevice = hwdevice->deviceNode();
TQMapIterator<TQString, TQString> it = d->udiDeviceMap.find(udi);
if (it != d->udiDeviceMap.end()) {
k3bDebug() << "Unmapping udi " << udi << " from device " << it.data() << endl;
emit deviceRemoved(it.data());
d->udiDeviceMap.erase(it);
d->deviceUdiMap.erase(it.data());
if (d->deviceMediumUdiMap[blockDevice]) {
d->deviceMediumUdiMap[blockDevice] = false;
emit mediumChanged(blockDevice);
}
}
#endif
}
void K3bDevice::HalConnection::ModifyDeviceHandler(TDEGenericDevice* hwdevice)
{
#ifdef HAVE_TDEHWLIB
if (hwdevice->type() != TDEGenericDeviceType::Disk) {
return;
}
TQString udi = hwdevice->uniqueID();
TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice);
TQString blockDevice = hwdevice->deviceNode();
if (d->deviceMediumUdiMap[blockDevice] != sdevice->mediaInserted()) {
d->deviceMediumUdiMap[blockDevice] = sdevice->mediaInserted();
emit mediumChanged(blockDevice);
}
#endif
}
int K3bDevice::HalConnection::lock(Device* dev)
{
#ifdef HAVE_TDEHWLIB
if (!d->deviceUdiMap.contains(dev->blockDeviceName())) {
return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
}
TQString udi = d->deviceUdiMap[dev->blockDeviceName()];
TDEGenericDevice *hwdevice = d->m_hwdevices->findByUniqueID(udi);
if (!hwdevice) {
return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
}
if (hwdevice->type() != TDEGenericDeviceType::Disk) {
return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
}
TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice);
if (sdevice->lockDriveMedia(true)) {
return org_freedesktop_Hal_Success;
}
else {
return org_freedesktop_Hal_Device_Volume_InvalidEjectOption;
}
#else
return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
#endif
}
int K3bDevice::HalConnection::unlock(Device* dev)
{
#ifdef HAVE_TDEHWLIB
if (!d->deviceUdiMap.contains(dev->blockDeviceName())) {
return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
}
TQString udi = d->deviceUdiMap[dev->blockDeviceName()];
TDEGenericDevice *hwdevice = d->m_hwdevices->findByUniqueID(udi);
if (!hwdevice) {
return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
}
if (hwdevice->type() != TDEGenericDeviceType::Disk) {
return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
}
TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice);
if (sdevice->lockDriveMedia(false)) {
return org_freedesktop_Hal_Success;
}
else {
return org_freedesktop_Hal_Device_Volume_InvalidEjectOption;
}
#else
return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
#endif
}
int K3bDevice::HalConnection::mount( K3bDevice::Device* dev,
const TQString& mountPoint,
const TQString& fstype,
const TQStringList& options )
{
#ifdef HAVE_TDEHWLIB
if (!d->deviceUdiMap.contains(dev->blockDeviceName())) {
return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
}
TQString udi = d->deviceUdiMap[dev->blockDeviceName()];
TDEGenericDevice *hwdevice = d->m_hwdevices->findByUniqueID(udi);
if (!hwdevice) {
return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
}
if (hwdevice->type() != TDEGenericDeviceType::Disk) {
return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
}
TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice);
// FIXME
// Options from 'options' are not currently loaded into 'mountOptions'
TDEStorageMountOptions mountOptions;
TQStringVariantMap mountResult = sdevice->mountDevice(mountPoint, mountOptions);
TQString mountedPath = mountResult.contains("mountPath") ? mountResult["mountPath"].toString() : TQString::null;
if (mountedPath.isEmpty()) {
return org_freedesktop_Hal_CommunicationError;
}
else {
return org_freedesktop_Hal_Success;
}
#else
return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
#endif
}
int K3bDevice::HalConnection::unmount(K3bDevice::Device* dev, const TQStringList& options)
{
#ifdef HAVE_TDEHWLIB
if (!d->deviceUdiMap.contains(dev->blockDeviceName())) {
return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
}
TQString udi = d->deviceUdiMap[dev->blockDeviceName()];
TDEGenericDevice *hwdevice = d->m_hwdevices->findByUniqueID(udi);
if (!hwdevice) {
return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
}
if (hwdevice->type() != TDEGenericDeviceType::Disk) {
return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
}
TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice);
// FIXME
// Options from 'options' are not currently loaded into 'mountOptions'
TQString mountOptions;
TQStringVariantMap unmountResult = sdevice->unmountDevice();
if (unmountResult["result"].toBool() == false) {
// Unmount failed!
return org_freedesktop_Hal_CommunicationError;
}
else {
return org_freedesktop_Hal_Success;
}
#else
return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
#endif
}
int K3bDevice::HalConnection::eject(K3bDevice::Device* dev, const TQStringList& options)
{
#ifdef HAVE_TDEHWLIB
if (!d->deviceUdiMap.contains(dev->blockDeviceName())) {
return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
}
TQString udi = d->deviceUdiMap[dev->blockDeviceName()];
TDEGenericDevice *hwdevice = d->m_hwdevices->findByUniqueID(udi);
if (!hwdevice) {
return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
}
if (hwdevice->type() != TDEGenericDeviceType::Disk) {
return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
}
TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice);
if (sdevice->ejectDriveMedia()) {
return org_freedesktop_Hal_Success;
}
else {
return org_freedesktop_Hal_Device_Volume_InvalidEjectOption;
}
#else
return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
#endif
}
#endif // HAVE_HAL
#include "k3bhalconnection.moc"

@ -29,7 +29,7 @@
#include <k3bcore.h>
#include <k3bdevicemanager.h>
#include <k3bhalconnection.h>
#include <k3bconnection.h>
#include <k3bexternalbinmanager.h>
#include <k3bdefaultexternalprograms.h>
#include <k3bglobals.h>
@ -416,8 +416,8 @@ bool K3bApplication::Core::internalBlockDevice( K3bDevice::Device* dev )
m_deviceBlockMap[dev] = mediaCache()->blockDevice( dev );
}
if( K3bDevice::HalConnection::instance()->lock( dev ) != K3bDevice::HalConnection::org_freedesktop_Hal_Success )
kdDebug() << "(K3bInterferingSystemsHandler) HAL lock failed." << endl;
if( K3bDevice::Connection::instance()->lock( dev ) != K3bDevice::Connection::ErrorCodes::Success )
kdDebug() << "(K3bInterferingSystemsHandler) lock failed." << endl;
//
// Check if the device is in use
@ -439,7 +439,7 @@ void K3bApplication::Core::internalUnblockDevice( K3bDevice::Device* dev )
m_deviceBlockMap.erase( dev );
}
K3bDevice::HalConnection::instance()->unlock( dev );
K3bDevice::Connection::instance()->unlock( dev );
K3bCore::internalUnblockDevice( dev );
}

Loading…
Cancel
Save