solid: remove UDisks backend

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2021-01-22 16:26:58 +02:00
parent 1f081d5014
commit 7bde1955a0
24 changed files with 16 additions and 3177 deletions

View file

@ -201,12 +201,6 @@ set_package_properties(UDisks2 PROPERTIES
TYPE OPTIONAL
)
if(UDISKS2_FOUND )
set(WITH_SOLID_UDISKS2 ON)
else()
set(WITH_SOLID_UDISKS2 OFF)
endif()
configure_file(
config-solid.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/config-solid.h
@ -280,9 +274,8 @@ set(solid_LIB_SRCS ${solid_LIB_SRCS}
)
# FIXME: this should work on more Unix systems
if(WITH_SOLID_UDISKS2)
if(UDISKS2_FOUND)
message(STATUS "Building Solid UDisks2 backend." )
add_definitions(-DWITH_SOLID_UDISKS2)
set(solid_LIB_SRCS
${solid_LIB_SRCS}
backends/udisks2/udisksmanager.cpp
@ -300,22 +293,7 @@ if(WITH_SOLID_UDISKS2)
)
# for the localizations
set(solid_OPTIONAL_LIBS ${solid_OPTIONAL_LIBS} ${KDE4_KDECORE_LIBS})
else(WITH_SOLID_UDISKS2)
message(STATUS "Building Solid UDisks backend." )
set(solid_LIB_SRCS
${solid_LIB_SRCS}
backends/udisks/udisksmanager.cpp
backends/udisks/udisksdevice.cpp
backends/udisks/udisksblock.cpp
backends/udisks/udisksstoragevolume.cpp
backends/udisks/udisksdeviceinterface.cpp
backends/udisks/udisksopticaldisc.cpp
backends/udisks/udisksopticaldrive.cpp
backends/udisks/udisksstoragedrive.cpp
backends/udisks/udisksstorageaccess.cpp
backends/udisks/udisksgenericinterface.cpp
)
endif(WITH_SOLID_UDISKS2)
endif(UDISKS2_FOUND)
message(STATUS "Building Solid fstab backend." )
set(solid_LIB_SRCS

View file

@ -1,39 +0,0 @@
/*
Copyright 2009 Pino Toscano <pino@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_BACKENDS_UDISKS_H
#define SOLID_BACKENDS_UDISKS_H
/* UDisks */
#define UD_DBUS_SERVICE "org.freedesktop.UDisks"
#define UD_DBUS_PATH "/org/freedesktop/UDisks"
#define UD_DBUS_INTERFACE_DISKS "org.freedesktop.UDisks"
#define UD_DBUS_INTERFACE_DISKS_DEVICE "org.freedesktop.UDisks.Device"
#define UD_UDI_DISKS_PREFIX "/org/freedesktop/UDisks"
/* errors */
#define UD_ERROR_UNAUTHORIZED "org.freedesktop.PolicyKit.Error.NotAuthorized"
#define UD_ERROR_BUSY "org.freedesktop.UDisks.Error.Busy"
#define UD_ERROR_FAILED "org.freedesktop.UDisks.Error.Failed"
#define UD_ERROR_CANCELED "org.freedesktop.UDisks.Error.Cancelled"
#define UD_ERROR_INVALID_OPTION "org.freedesktop.UDisks.Error.InvalidOption"
#define UD_ERROR_MISSING_DRIVER "org.freedesktop.UDisks.Error.FilesystemDriverMissing"
#endif // SOLID_BACKENDS_UDISKS_H

View file

@ -1,50 +0,0 @@
/*
Copyright 2010 Michael Zanetti <mzanetti@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "udisksblock.h"
using namespace Solid::Backends::UDisks;
Block::Block(UDisksDevice *device)
: DeviceInterface(device)
{
}
Block::~Block()
{
}
QString Block::device() const
{
return m_device->prop("DeviceFile").toString();
}
int Block::deviceMinor() const
{
return m_device->prop("DeviceMinor").toInt();
}
int Block::deviceMajor() const
{
return m_device->prop("DeviceMajor").toInt();
}

View file

@ -1,53 +0,0 @@
/*
Copyright 2010 Michael Zanetti <mzanetti@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UDISKSBLOCK_H
#define UDISKSBLOCK_H
#include <solid/ifaces/block.h>
#include "udisksdeviceinterface.h"
namespace Solid
{
namespace Backends
{
namespace UDisks
{
class Block: public DeviceInterface, virtual public Solid::Ifaces::Block
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::Block)
public:
Block(UDisksDevice *device);
virtual ~Block();
virtual QString device() const;
virtual int deviceMinor() const;
virtual int deviceMajor() const;
};
}
}
}
#endif // UDISKSBLOCK_H

View file

@ -1,773 +0,0 @@
/*
Copyright 2010 Michael Zanetti <mzanetti@kde.org>
Copyright 2010-2011 Lukas Tinkl <ltinkl@redhat.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "udisks.h"
#include "udisksdevice.h"
#include "udisksdeviceinterface.h"
#include "udisksstoragevolume.h"
#include "udisksopticaldisc.h"
#include "udisksopticaldrive.h"
#include "udisksstorageaccess.h"
#include "udisksgenericinterface.h"
#include <solid/genericinterface.h>
#include <solid/deviceinterface.h>
#include <solid/device.h>
#include <QtCore/QStringList>
#include <QtCore/QDebug>
#include <QtDBus/QDBusMessage>
#include <QtDBus/QDBusMetaType>
#include <QtDBus/QDBusPendingReply>
using namespace Solid::Backends::UDisks;
// Adapted from KLocale as Solid needs to be Qt-only
static QString formatByteSize(double size)
{
// Per IEC 60027-2
// Binary prefixes
//Tebi-byte TiB 2^40 1,099,511,627,776 bytes
//Gibi-byte GiB 2^30 1,073,741,824 bytes
//Mebi-byte MiB 2^20 1,048,576 bytes
//Kibi-byte KiB 2^10 1,024 bytes
QString s;
// Gibi-byte
if ( size >= 1073741824.0 )
{
size /= 1073741824.0;
if ( size > 1024 ) // Tebi-byte
s = QObject::tr("%1 TiB").arg(QLocale().toString(size / 1024.0, 'f', 1));
else
s = QObject::tr("%1 GiB").arg(QLocale().toString(size, 'f', 1));
}
// Mebi-byte
else if ( size >= 1048576.0 )
{
size /= 1048576.0;
s = QObject::tr("%1 MiB").arg(QLocale().toString(size, 'f', 1));
}
// Kibi-byte
else if ( size >= 1024.0 )
{
size /= 1024.0;
s = QObject::tr("%1 KiB").arg(QLocale().toString(size, 'f', 1));
}
// Just byte
else if ( size > 0 )
{
s = QObject::tr("%1 B").arg(QLocale().toString(size, 'f', 1));
}
// Nothing
else
{
s = QObject::tr("0 B");
}
return s;
}
UDisksDevice::UDisksDevice(const QString &udi)
: Solid::Ifaces::Device()
, m_udi(udi)
{
QString realUdi = m_udi;
if (realUdi.endsWith(":media")) {
realUdi.chop(6);
}
m_device = new QDBusInterface(UD_DBUS_SERVICE, realUdi,
UD_DBUS_INTERFACE_DISKS_DEVICE,
QDBusConnection::systemBus());
if (m_device->isValid())
connect(m_device, SIGNAL(Changed()), this, SLOT(slotChanged()));
}
UDisksDevice::~UDisksDevice()
{
delete m_device;
}
QObject* UDisksDevice::createDeviceInterface(const Solid::DeviceInterface::Type& type)
{
if (!queryDeviceInterface(type)) {
return 0;
}
DeviceInterface *iface = 0;
switch (type)
{
case Solid::DeviceInterface::GenericInterface:
iface = new GenericInterface(this);
break;
case Solid::DeviceInterface::Block:
iface = new Block(this);
break;
case Solid::DeviceInterface::StorageAccess:
iface = new UDisksStorageAccess(this);
break;
case Solid::DeviceInterface::StorageDrive:
iface = new UDisksStorageDrive(this);
break;
case Solid::DeviceInterface::OpticalDrive:
iface = new UDisksOpticalDrive(this);
break;
case Solid::DeviceInterface::StorageVolume:
iface = new UDisksStorageVolume(this);
break;
case Solid::DeviceInterface::OpticalDisc:
iface = new OpticalDisc(this);
break;
default:
break;
}
return iface;
}
bool UDisksDevice::queryDeviceInterface(const Solid::DeviceInterface::Type& type) const
{
switch (type) {
case Solid::DeviceInterface::GenericInterface:
return true;
case Solid::DeviceInterface::Block:
return prop("DeviceMajor").toInt() != -1;
case Solid::DeviceInterface::StorageVolume:
if (prop("DeviceIsOpticalDisc").toBool()) {
return m_udi.endsWith(":media");
} else {
return prop("DeviceIsPartition").toBool()
|| prop("IdUsage").toString()=="filesystem"
|| prop("IdUsage").toString()=="crypto";
}
case Solid::DeviceInterface::StorageAccess:
if (prop("DeviceIsOpticalDisc").toBool()) {
return prop("IdUsage").toString()=="filesystem"
&& m_udi.endsWith(":media");
} else {
return prop("IdUsage").toString()=="filesystem"
|| prop("IdUsage").toString()=="crypto";
}
case Solid::DeviceInterface::StorageDrive:
return !m_udi.endsWith(":media") && prop("DeviceIsDrive").toBool();
case Solid::DeviceInterface::OpticalDrive:
return !m_udi.endsWith(":media")
&& prop( "DeviceIsDrive" ).toBool()
&& !prop( "DriveMediaCompatibility" ).toStringList().filter( "optical_" ).isEmpty();
case Solid::DeviceInterface::OpticalDisc:
return m_udi.endsWith(":media") && prop("DeviceIsOpticalDisc").toBool();
default:
return false;
}
}
QStringList UDisksDevice::emblems() const
{
QStringList res;
if (queryDeviceInterface(Solid::DeviceInterface::StorageAccess))
{
bool isEncrypted = false;
if (queryDeviceInterface(Solid::DeviceInterface::StorageVolume))
{
const UDisks::UDisksStorageVolume volIface(const_cast<UDisksDevice *>(this));
isEncrypted = (volIface.usage() == Solid::StorageVolume::Encrypted);
}
const UDisks::UDisksStorageAccess accessIface(const_cast<UDisksDevice *>(this));
if (accessIface.isAccessible())
{
if (isEncrypted)
res << "emblem-encrypted-unlocked";
else
res << "emblem-mounted";
}
else
{
if (isEncrypted)
res << "emblem-encrypted-locked";
else
res << "emblem-unmounted";
}
}
return res;
}
QString UDisksDevice::description() const
{
if (queryDeviceInterface(Solid::DeviceInterface::StorageDrive))
return storageDescription();
else if (queryDeviceInterface(Solid::DeviceInterface::StorageVolume))
return volumeDescription();
else
return product();
}
QString UDisksDevice::storageDescription() const
{
QString description;
const UDisks::UDisksStorageDrive storageDrive(const_cast<UDisksDevice*>(this));
Solid::StorageDrive::DriveType drive_type = storageDrive.driveType();
bool drive_is_hotpluggable = storageDrive.isHotpluggable();
const UDisks::UDisksStorageVolume storageVolume(const_cast<UDisksDevice*>(this));
if (drive_type == Solid::StorageDrive::CdromDrive)
{
const UDisks::UDisksOpticalDrive opticalDrive(const_cast<UDisksDevice*>(this));
Solid::OpticalDrive::MediumTypes mediumTypes = opticalDrive.supportedMedia();
QString first;
QString second;
first = QObject::tr("CD-ROM");
if (mediumTypes & Solid::OpticalDrive::Cdr)
first = QObject::tr("CD-R");
if (mediumTypes & Solid::OpticalDrive::Cdrw)
first = QObject::tr("CD-RW");
if (mediumTypes & Solid::OpticalDrive::Dvd)
second = QObject::tr("/DVD-ROM");
if (mediumTypes & Solid::OpticalDrive::Dvdplusr)
second = QObject::tr("/DVD+R");
if (mediumTypes & Solid::OpticalDrive::Dvdplusrw)
second = QObject::tr("/DVD+RW");
if (mediumTypes & Solid::OpticalDrive::Dvdr)
second = QObject::tr("/DVD-R");
if (mediumTypes & Solid::OpticalDrive::Dvdrw)
second = QObject::tr("/DVD-RW");
if (mediumTypes & Solid::OpticalDrive::Dvdram)
second = QObject::tr("/DVD-RAM");
if ((mediumTypes & Solid::OpticalDrive::Dvdr) && (mediumTypes & Solid::OpticalDrive::Dvdplusr))
{
if(mediumTypes & Solid::OpticalDrive::Dvdplusdl)
second = QObject::tr("/DVD±R DL");
else
second = QObject::tr("/DVD±R");
}
if ((mediumTypes & Solid::OpticalDrive::Dvdrw) && (mediumTypes & Solid::OpticalDrive::Dvdplusrw))
{
if((mediumTypes & Solid::OpticalDrive::Dvdplusdl) || (mediumTypes & Solid::OpticalDrive::Dvdplusdlrw))
second = QObject::tr("/DVD±RW DL");
else
second = QObject::tr("/DVD±RW");
}
if (mediumTypes & Solid::OpticalDrive::Bd)
second = QObject::tr("/BD-ROM");
if (mediumTypes & Solid::OpticalDrive::Bdr)
second = QObject::tr("/BD-R");
if (mediumTypes & Solid::OpticalDrive::Bdre)
second = QObject::tr("/BD-RE");
if (mediumTypes & Solid::OpticalDrive::HdDvd)
second = QObject::tr("/HD DVD-ROM");
if (mediumTypes & Solid::OpticalDrive::HdDvdr)
second = QObject::tr("/HD DVD-R");
if (mediumTypes & Solid::OpticalDrive::HdDvdrw)
second = QObject::tr("/HD DVD-RW");
if (drive_is_hotpluggable)
description = QObject::tr("External %1%2 Drive").arg(first).arg(second);
else
description = QObject::tr("%1%2 Drive").arg(first).arg(second);
return description;
}
if (drive_type == Solid::StorageDrive::Floppy)
{
if (drive_is_hotpluggable)
description = QObject::tr("External Floppy Drive");
else
description = QObject::tr("Floppy Drive");
return description;
}
bool drive_is_removable = storageDrive.isRemovable();
if (drive_type == Solid::StorageDrive::HardDisk && !drive_is_removable)
{
QString size_str = formatByteSize(storageVolume.size());
if (!size_str.isEmpty())
{
if (drive_is_hotpluggable)
description = QObject::tr("%1 External Hard Drive").arg(size_str);
else
description = QObject::tr("%1 Hard Drive").arg(size_str);
} else {
if (drive_is_hotpluggable)
description = QObject::tr("External Hard Drive");
else
description = QObject::tr("Hard Drive");
}
return description;
}
QString vendormodel_str;
QString model = product();
QString vendor_str = vendor();
if (vendor_str.isEmpty())
{
if (!model.isEmpty())
vendormodel_str = model;
}
else
{
if (model.isEmpty())
vendormodel_str = vendor_str;
else
{
if (model.startsWith(vendor_str))
{
// e.g. vendor is "Nokia" and model is "Nokia N950" we do not want "Nokia Nokia N950" as description
vendormodel_str = model;
}
else
{
vendormodel_str = QObject::tr("%1 %2").arg(vendor_str).arg(model);
}
}
}
if (vendormodel_str.isEmpty())
description = QObject::tr("Drive");
else
description = vendormodel_str;
return description;
}
QString UDisksDevice::volumeDescription() const
{
QString description;
const UDisks::UDisksStorageVolume storageVolume(const_cast<UDisksDevice*>(this));
QString volume_label = prop("IdLabel").toString();
if (volume_label.isEmpty())
volume_label = prop("PartitionLabel").toString();
if (!volume_label.isEmpty())
return volume_label;
const UDisks::UDisksStorageDrive storageDrive(const_cast<UDisksDevice*>(this));
Solid::StorageDrive::DriveType drive_type = storageDrive.driveType();
// Handle media in optical drives
if (drive_type == Solid::StorageDrive::CdromDrive)
{
const UDisks::OpticalDisc disc(const_cast<UDisksDevice*>(this));
switch (disc.discType())
{
case Solid::OpticalDisc::UnknownDiscType:
case Solid::OpticalDisc::CdRom:
description = QObject::tr("CD-ROM");
break;
case Solid::OpticalDisc::CdRecordable:
if (disc.isBlank())
description = QObject::tr("Blank CD-R");
else
description = QObject::tr("CD-R");
break;
case Solid::OpticalDisc::CdRewritable:
if (disc.isBlank())
description = QObject::tr("Blank CD-RW");
else
description = QObject::tr("CD-RW");
break;
case Solid::OpticalDisc::DvdRom:
description = QObject::tr("DVD-ROM");
break;
case Solid::OpticalDisc::DvdRam:
if (disc.isBlank())
description = QObject::tr("Blank DVD-RAM");
else
description = QObject::tr("DVD-RAM");
break;
case Solid::OpticalDisc::DvdRecordable:
if (disc.isBlank())
description = QObject::tr("Blank DVD-R");
else
description = QObject::tr("DVD-R");
break;
case Solid::OpticalDisc::DvdPlusRecordableDuallayer:
if (disc.isBlank())
description = QObject::tr("Blank DVD+R Dual-Layer");
else
description = QObject::tr("DVD+R Dual-Layer");
break;
case Solid::OpticalDisc::DvdRewritable:
if (disc.isBlank())
description = QObject::tr("Blank DVD-RW");
else
description = QObject::tr("DVD-RW");
break;
case Solid::OpticalDisc::DvdPlusRecordable:
if (disc.isBlank())
description = QObject::tr("Blank DVD+R");
else
description = QObject::tr("DVD+R");
break;
case Solid::OpticalDisc::DvdPlusRewritable:
if (disc.isBlank())
description = QObject::tr("Blank DVD+RW");
else
description = QObject::tr("DVD+RW");
break;
case Solid::OpticalDisc::DvdPlusRewritableDuallayer:
if (disc.isBlank())
description = QObject::tr("Blank DVD+RW Dual-Layer");
else
description = QObject::tr("DVD+RW Dual-Layer");
break;
case Solid::OpticalDisc::BluRayRom:
description = QObject::tr("BD-ROM");
break;
case Solid::OpticalDisc::BluRayRecordable:
if (disc.isBlank())
description = QObject::tr("Blank BD-R");
else
description = QObject::tr("BD-R");
break;
case Solid::OpticalDisc::BluRayRewritable:
if (disc.isBlank())
description = QObject::tr("Blank BD-RE");
else
description = QObject::tr("BD-RE");
break;
case Solid::OpticalDisc::HdDvdRom:
description = QObject::tr("HD DVD-ROM");
break;
case Solid::OpticalDisc::HdDvdRecordable:
if (disc.isBlank())
description = QObject::tr("Blank HD DVD-R");
else
description = QObject::tr("HD DVD-R");
break;
case Solid::OpticalDisc::HdDvdRewritable:
if (disc.isBlank())
description = QObject::tr("Blank HD DVD-RW");
else
description = QObject::tr("HD DVD-RW");
break;
}
// Special case for pure audio disc
if (disc.availableContent() == Solid::OpticalDisc::Audio)
description = QObject::tr("Audio CD");
return description;
}
bool drive_is_removable = storageDrive.isRemovable();
bool drive_is_hotpluggable = storageDrive.isHotpluggable();
bool drive_is_encrypted_container = (storageVolume.usage() == Solid::StorageVolume::Encrypted);
QString size_str = formatByteSize(storageVolume.size());
if (drive_is_encrypted_container)
{
if (!size_str.isEmpty())
description = QObject::tr("%1 Encrypted Container").arg(size_str);
else
description = QObject::tr("Encrypted Container");
}
else if (drive_type == Solid::StorageDrive::HardDisk && !drive_is_removable)
{
if (!size_str.isEmpty())
{
if (drive_is_hotpluggable)
description = QObject::tr("%1 External Hard Drive").arg(size_str);
else
description = QObject::tr("%1 Hard Drive").arg(size_str);
}
else
{
if (drive_is_hotpluggable)
description = QObject::tr("External Hard Drive");
else
description = QObject::tr("Hard Drive");
}
}
else
{
if (drive_is_removable)
description = QObject::tr("%1 Removable Media").arg(size_str);
else
description = QObject::tr("%1 Media").arg(size_str);
}
return description;
}
QString UDisksDevice::icon() const
{
QString iconName = prop( "DevicePresentationIconName" ).toString();
if ( !iconName.isEmpty() )
{
return iconName;
}
else
{
bool isPartition = prop( "DeviceIsPartition" ).toBool();
if ( isPartition ) // this is a slave device, we need to return its parent's icon
{
if ( !m_parentDevice && !parentUdi().isEmpty() )
m_parentDevice = new UDisksDevice( parentUdi() );
if ( m_parentDevice )
iconName = m_parentDevice->icon();
if ( !iconName.isEmpty() )
return iconName;
}
// handle mounted ISOs
bool isLoop = prop( "DeviceIsLinuxLoop" ).toBool();
QString fstype = prop("IdType").toString();
if( isLoop && ( fstype == "iso9660" || fstype == "udf" ) )
{
return "media-optical";
}
// handle media
const QString media = prop( "DriveMedia" ).toString();
bool isOptical = prop( "DeviceIsOpticalDisc" ).toBool();
if ( !media.isEmpty() )
{
if ( isOptical ) // optical stuff
{
bool isWritable = prop( "OpticalDiscIsBlank" ).toBool() || prop("OpticalDiscIsAppendable").toBool();
const UDisks::OpticalDisc disc(const_cast<UDisksDevice*>(this));
Solid::OpticalDisc::ContentTypes availContent = disc.availableContent();
if (availContent & Solid::OpticalDisc::VideoDvd) // Video DVD
return "media-optical-dvd-video";
else if ((availContent & Solid::OpticalDisc::VideoCd) || (availContent & Solid::OpticalDisc::SuperVideoCd)) // Video CD
return "media-optical-video";
else if ((availContent & Solid::OpticalDisc::Data) && (availContent & Solid::OpticalDisc::Audio)) // Mixed CD
return "media-optical-mixed-cd";
else if (availContent & Solid::OpticalDisc::Audio) // Audio CD
return "media-optical-audio";
else if (availContent & Solid::OpticalDisc::Data) // Data CD
return "media-optical-data";
else if ( isWritable )
return "media-optical-recordable";
else
{
if ( media.startsWith( "optical_dvd" ) || media.startsWith( "optical_hddvd" ) ) // DVD
return "media-optical-dvd";
else if ( media.startsWith( "optical_bd" ) ) // BluRay
return "media-optical-blu-ray";
}
// fallback for every other optical disc
return "media-optical";
}
if ( media == "flash_ms" ) // Flash & Co.
return "media-flash-memory-stick";
else if ( media == "flash_sd" || media == "flash_sdhc" || media == "flash_mmc" )
return "media-flash-sd-mmc";
else if ( media == "flash_sm" )
return "media-flash-smart-media";
else if ( media.startsWith( "flash" ) )
return "media-flash";
else if ( media == "floppy" ) // the good ol' floppy
return "media-floppy";
}
// handle drives
bool isRemovable = prop( "DeviceIsRemovable" ).toBool();
const QString conn = prop( "DriveConnectionInterface" ).toString();
if ( queryDeviceInterface(Solid::DeviceInterface::OpticalDrive) )
return "drive-optical";
else if ( isRemovable && !isOptical )
{
if ( conn == "usb" )
return "drive-removable-media-usb";
else
return "drive-removable-media";
}
}
return "drive-harddisk"; // general fallback
}
QString UDisksDevice::product() const
{
QString product = prop("DriveModel").toString();
const bool isDrive = prop( "DeviceIsDrive" ).toBool() && !m_udi.endsWith(":media");
if (!isDrive) {
QString label = prop("IdLabel").toString();
if (!label.isEmpty()) {
product = label;
}
}
return product;
}
QString UDisksDevice::vendor() const
{
return prop("DriveVendor").toString();
}
QString UDisksDevice::udi() const
{
return m_udi;
}
QString UDisksDevice::parentUdi() const
{
if (m_udi.endsWith(QLatin1String(":media"))) {
QString result = m_udi;
return result.remove(":media");
}
else if ( prop( "DeviceIsLuksCleartext" ).toBool() )
return prop( "LuksCleartextSlave" ).value<QDBusObjectPath>().path();
else {
QString parent = prop("PartitionSlave").value<QDBusObjectPath>().path();
if (parent.isEmpty() || parent=="/") {
parent = UD_UDI_DISKS_PREFIX;
}
return parent;
}
}
void UDisksDevice::checkCache(const QString &key) const
{
if (m_cache.isEmpty()) // recreate the cache
allProperties();
if (m_cache.contains(key))
return;
QVariant reply = m_device->property(key.toUtf8());
if (reply.isValid()) {
m_cache[key] = reply;
} else {
m_cache[key] = QVariant();
}
}
QVariant UDisksDevice::prop(const QString &key) const
{
checkCache(key);
return m_cache.value(key);
}
bool UDisksDevice::propertyExists(const QString &key) const
{
checkCache(key);
return m_cache.contains(key);
}
QMap<QString, QVariant> UDisksDevice::allProperties() const
{
QDBusMessage call = QDBusMessage::createMethodCall(m_device->service(), m_device->path(),
"org.freedesktop.DBus.Properties", "GetAll");
call << m_device->interface();
QDBusPendingReply< QVariantMap > reply = QDBusConnection::systemBus().asyncCall(call);
reply.waitForFinished();
if (reply.isValid())
m_cache = reply.value();
else
m_cache.clear();
return m_cache;
}
void UDisksDevice::slotChanged()
{
// given we cannot know which property/ies changed, clear the cache
m_cache.clear();
emit changed();
}
bool UDisksDevice::isDeviceBlacklisted() const
{
return prop("DevicePresentationHide").toBool() ||
prop("DeviceMountPaths").toStringList().contains("/boot") ||
prop("IdLabel").toString() == "System Reserved" ||
( prop("IdUsage").toString().isEmpty() && !(prop("OpticalDiscIsBlank").toBool() || (prop("OpticalDiscNumAudioTracks").toInt() > 0) ));
}
QString UDisksDevice::errorToString(const QString & error) const
{
if (error == UD_ERROR_UNAUTHORIZED)
return QObject::tr("You are not authorized to perform this operation.");
else if (error == UD_ERROR_BUSY)
return QObject::tr("The device is currently busy.");
else if (error == UD_ERROR_FAILED)
return QObject::tr("The requested operation has failed.");
else if (error == UD_ERROR_CANCELED)
return QObject::tr("The requested operation has been canceled.");
else if (error == UD_ERROR_INVALID_OPTION)
return QObject::tr("An invalid or malformed option has been given.");
else if (error == UD_ERROR_MISSING_DRIVER)
return QObject::tr("The kernel driver for this filesystem type is not available.");
else
return QObject::tr("An unspecified error has occurred.");
}
Solid::ErrorType UDisksDevice::errorToSolidError(const QString & error) const
{
if (error == UD_ERROR_BUSY)
return Solid::DeviceBusy;
else if (error == UD_ERROR_FAILED)
return Solid::OperationFailed;
else if (error == UD_ERROR_CANCELED)
return Solid::UserCanceled;
else if (error == UD_ERROR_INVALID_OPTION)
return Solid::InvalidOption;
else if (error == UD_ERROR_MISSING_DRIVER)
return Solid::MissingDriver;
else
return Solid::UnauthorizedOperation;
}

View file

@ -1,88 +0,0 @@
/*
Copyright 2010 Michael Zanetti <mzanetti@kde.org>
Copyright 2010-2011 Lukas Tinkl <ltinkl@redhat.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UDISKSDEVICE_H
#define UDISKSDEVICE_H
#include <ifaces/device.h>
#include <solid/deviceinterface.h>
#include <solid/solidnamespace.h>
#include <QtDBus/QDBusInterface>
#include <QtCore/QSet>
#include <QtCore/QPointer>
namespace Solid
{
namespace Backends
{
namespace UDisks
{
class UDisksDevice : public Solid::Ifaces::Device
{
Q_OBJECT
public:
UDisksDevice(const QString &udi);
virtual ~UDisksDevice();
virtual QObject* createDeviceInterface(const Solid::DeviceInterface::Type& type);
virtual bool queryDeviceInterface(const Solid::DeviceInterface::Type& type) const;
virtual QString description() const;
virtual QStringList emblems() const;
virtual QString icon() const;
virtual QString product() const;
virtual QString vendor() const;
virtual QString udi() const;
virtual QString parentUdi() const;
QVariant prop(const QString &key) const;
bool propertyExists(const QString &key) const;
QMap<QString, QVariant> allProperties() const;
bool isDeviceBlacklisted() const;
QString errorToString(const QString & error) const;
Solid::ErrorType errorToSolidError(const QString & error) const;
Q_SIGNALS:
void changed();
private Q_SLOTS:
void slotChanged();
private:
QString storageDescription() const;
QString volumeDescription() const;
mutable QDBusInterface *m_device;
QString m_udi;
mutable QVariantMap m_cache;
mutable QPointer<UDisksDevice> m_parentDevice;
void checkCache(const QString &key) const;
};
}
}
}
#endif // UDISKSDEVICE_H

View file

@ -1,33 +0,0 @@
/*
Copyright 2010 Michael Zanetti <mzanetti@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "udisksdeviceinterface.h"
using namespace Solid::Backends::UDisks;
DeviceInterface::DeviceInterface(UDisksDevice *device)
: QObject(device), m_device(device)
{
}
DeviceInterface::~DeviceInterface()
{
}

View file

@ -1,174 +0,0 @@
/*
Copyright 2010 Michael Zanetti <mzanetti@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UDISKSDEVICEINTERFACE_H
#define UDISKSDEVICEINTERFACE_H
#include <ifaces/deviceinterface.h>
#include "udisksdevice.h"
#include <QtCore/QObject>
#include <QtCore/QStringList>
namespace Solid
{
namespace Backends
{
namespace UDisks
{
class DeviceInterface : public QObject, virtual public Solid::Ifaces::DeviceInterface
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::DeviceInterface)
public:
DeviceInterface(UDisksDevice *device);
virtual ~DeviceInterface();
protected:
UDisksDevice *m_device;
public:
inline static QStringList toStringList(Solid::DeviceInterface::Type type)
{
QStringList list;
switch(type)
{
case Solid::DeviceInterface::GenericInterface:
list << "generic";
break;
case Solid::DeviceInterface::Processor:
// Doesn't exist with UDisks
break;
case Solid::DeviceInterface::Block:
list << "block";
break;
case Solid::DeviceInterface::StorageAccess:
list << "volume";
break;
case Solid::DeviceInterface::StorageDrive:
list << "storage";
break;
case Solid::DeviceInterface::OpticalDrive:
list << "storage.cdrom";
break;
case Solid::DeviceInterface::StorageVolume:
list << "volume";
break;
case Solid::DeviceInterface::OpticalDisc:
list << "volume.disc";
break;
case Solid::DeviceInterface::Camera:
// Doesn't exist with UDisks
break;
case Solid::DeviceInterface::PortableMediaPlayer:
// Doesn't exist with UDisks
break;
case Solid::DeviceInterface::NetworkInterface:
// Doesn't exist with UDisks
break;
case Solid::DeviceInterface::AcAdapter:
// Doesn't exist with UDisks
break;
case Solid::DeviceInterface::Battery:
// Doesn't exist with UDisks
break;
case Solid::DeviceInterface::Button:
// Doesn't exist with UDisks
break;
case Solid::DeviceInterface::AudioInterface:
// Doesn't exist with UDisks
break;
case Solid::DeviceInterface::DvbInterface:
// Doesn't exist with UDisks
break;
case Solid::DeviceInterface::Video:
// Doesn't exist with UDisks
break;
case Solid::DeviceInterface::SerialInterface:
// Doesn't exist with UDisks
break;
case Solid::DeviceInterface::InternetGateway:
break;
case Solid::DeviceInterface::SmartCardReader:
// Doesn't exist with UDisks
case Solid::DeviceInterface::NetworkShare:
// Doesn't exist with UDisks
break;
case Solid::DeviceInterface::Unknown:
break;
case Solid::DeviceInterface::Last:
break;
}
return list;
}
inline static Solid::DeviceInterface::Type fromString(const QString &capability)
{
if (capability == "generic")
return Solid::DeviceInterface::GenericInterface;
else if (capability == "processor")
return Solid::DeviceInterface::Processor;
else if (capability == "block")
return Solid::DeviceInterface::Block;
else if (capability == "storage")
return Solid::DeviceInterface::StorageDrive;
else if (capability == "storage.cdrom")
return Solid::DeviceInterface::OpticalDrive;
else if (capability == "volume")
return Solid::DeviceInterface::StorageVolume;
else if (capability == "volume.disc")
return Solid::DeviceInterface::OpticalDisc;
else if (capability == "camera")
return Solid::DeviceInterface::Camera;
else if (capability == "portable_audio_player")
return Solid::DeviceInterface::PortableMediaPlayer;
else if (capability == "net")
return Solid::DeviceInterface::NetworkInterface;
else if (capability == "ac_adapter")
return Solid::DeviceInterface::AcAdapter;
else if (capability == "battery")
return Solid::DeviceInterface::Battery;
else if (capability == "button")
return Solid::DeviceInterface::Button;
else if (capability == "alsa" || capability == "oss")
return Solid::DeviceInterface::AudioInterface;
else if (capability == "dvb")
return Solid::DeviceInterface::DvbInterface;
else if (capability == "video4linux")
return Solid::DeviceInterface::Video;
else if (capability == "serial")
return Solid::DeviceInterface::SerialInterface;
else if (capability == "smart_card_reader")
return Solid::DeviceInterface::SmartCardReader;
else if (capability == "networkshare")
return Solid::DeviceInterface::NetworkShare;
else
return Solid::DeviceInterface::Unknown;
}
};
}
}
}
#endif // UDISKSDEVICEINTERFACE_H

View file

@ -1,57 +0,0 @@
/*
Copyright 2009 Pino Toscano <pino@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "udisksgenericinterface.h"
#include "udisksdevice.h"
using namespace Solid::Backends::UDisks;
GenericInterface::GenericInterface(UDisksDevice *device)
: DeviceInterface(device)
{
/* TODO
connect(device, SIGNAL(propertyChanged(QMap<QString,int>)),
this, SIGNAL(propertyChanged(QMap<QString,int>)));
connect(device, SIGNAL(conditionRaised(QString,QString)),
this, SIGNAL(conditionRaised(QString,QString)));
*/
}
GenericInterface::~GenericInterface()
{
}
QVariant GenericInterface::property(const QString &key) const
{
return m_device->prop(key);
}
QMap<QString, QVariant> GenericInterface::allProperties() const
{
return m_device->allProperties();
}
bool GenericInterface::propertyExists(const QString &key) const
{
return m_device->propertyExists(key);
}
#include "backends/udisks/moc_udisksgenericinterface.cpp"

View file

@ -1,57 +0,0 @@
/*
Copyright 2009 Pino Toscano <pino@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_BACKENDS_UDISKS_GENERICINTERFACE_H
#define SOLID_BACKENDS_UDISKS_GENERICINTERFACE_H
#include <solid/ifaces/genericinterface.h>
#include <solid/genericinterface.h>
#include "udisksdeviceinterface.h"
namespace Solid
{
namespace Backends
{
namespace UDisks
{
class UDisksDevice;
class GenericInterface : public DeviceInterface, virtual public Solid::Ifaces::GenericInterface
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::GenericInterface)
public:
GenericInterface(UDisksDevice *device);
virtual ~GenericInterface();
virtual QVariant property(const QString &key) const;
virtual QMap<QString, QVariant> allProperties() const;
virtual bool propertyExists(const QString &key) const;
Q_SIGNALS:
void propertyChanged(const QMap<QString, int> &changes);
void conditionRaised(const QString &condition, const QString &reason);
};
}
}
}
#endif // SOLID_BACKENDS_UDISKS_GENERICINTERFACE_H

View file

@ -1,270 +0,0 @@
/*
Copyright 2010 Michael Zanetti <mzanetti@kde.org>
Copyright 2010 Lukas Tinkl <ltinkl@redhat.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "udisksmanager.h"
#include "udisks.h"
#include <QtDBus/QDBusReply>
#include <QtCore/QDebug>
#include <QtDBus/QDBusMetaType>
#include <QtDBus/QDBusConnectionInterface>
#include "../shared/rootdevice.h"
using namespace Solid::Backends::UDisks;
using namespace Solid::Backends::Shared;
UDisksManager::UDisksManager(QObject *parent)
: Solid::Ifaces::DeviceManager(parent),
m_manager(UD_DBUS_SERVICE,
UD_DBUS_PATH,
UD_DBUS_INTERFACE_DISKS,
QDBusConnection::systemBus())
{
m_supportedInterfaces
<< Solid::DeviceInterface::GenericInterface
<< Solid::DeviceInterface::Block
<< Solid::DeviceInterface::StorageAccess
<< Solid::DeviceInterface::StorageDrive
<< Solid::DeviceInterface::OpticalDrive
<< Solid::DeviceInterface::OpticalDisc
<< Solid::DeviceInterface::StorageVolume;
qDBusRegisterMetaType<QList<QDBusObjectPath> >();
qDBusRegisterMetaType<QVariantMap>();
bool serviceFound = m_manager.isValid();
if (!serviceFound) {
// find out whether it will be activated automatically
QDBusMessage message = QDBusMessage::createMethodCall("org.freedesktop.DBus",
"/org/freedesktop/DBus",
"org.freedesktop.DBus",
"ListActivatableNames");
QDBusReply<QStringList> reply = QDBusConnection::systemBus().call(message);
if (reply.isValid() && reply.value().contains(UD_DBUS_SERVICE)) {
QDBusConnection::systemBus().interface()->startService(UD_DBUS_SERVICE);
serviceFound = true;
}
}
if (serviceFound) {
connect(&m_manager, SIGNAL(DeviceAdded(QDBusObjectPath)),
this, SLOT(slotDeviceAdded(QDBusObjectPath)));
connect(&m_manager, SIGNAL(DeviceRemoved(QDBusObjectPath)),
this, SLOT(slotDeviceRemoved(QDBusObjectPath)));
connect(&m_manager, SIGNAL(DeviceChanged(QDBusObjectPath)),
this, SLOT(slotDeviceChanged(QDBusObjectPath)));
}
}
UDisksManager::~UDisksManager()
{
}
QObject* UDisksManager::createDevice(const QString& udi)
{
if (udi==udiPrefix()) {
RootDevice *root = new RootDevice(udi);
root->setProduct(tr("Storage"));
root->setDescription(tr("Storage devices"));
root->setIcon("server-database"); // Obviously wasn't meant for that, but maps nicely in oxygen icon set :-p
return root;
} else if (deviceCache().contains(udi)) {
return new UDisksDevice(udi);
} else {
return 0;
}
}
QStringList UDisksManager::devicesFromQuery(const QString& parentUdi, Solid::DeviceInterface::Type type)
{
QStringList result;
if (!parentUdi.isEmpty())
{
foreach (const QString &udi, deviceCache())
{
if (udi==udiPrefix())
continue;
UDisksDevice device(udi);
if (device.queryDeviceInterface(type) && device.parentUdi() == parentUdi)
result << udi;
}
return result;
}
else if (type != Solid::DeviceInterface::Unknown)
{
foreach (const QString &udi, deviceCache())
{
if (udi==udiPrefix())
continue;
UDisksDevice device(udi);
if (device.queryDeviceInterface(type))
result << udi;
}
return result;
}
return deviceCache();
}
QStringList UDisksManager::allDevices()
{
m_knownDrivesWithMedia.clear();
m_deviceCache.clear();
m_deviceCache << udiPrefix();
foreach(const QString &udi, allDevicesInternal())
{
m_deviceCache.append(udi);
UDisksDevice device(udi);
if (device.queryDeviceInterface(Solid::DeviceInterface::OpticalDrive)) // forge a special (separate) device for optical discs
{
if (device.prop("DeviceIsOpticalDisc").toBool())
{
if (!m_knownDrivesWithMedia.contains(udi))
m_knownDrivesWithMedia.append(udi);
m_deviceCache.append(udi + ":media");
}
}
}
return m_deviceCache;
}
QStringList UDisksManager::allDevicesInternal()
{
QDBusReply<QList<QDBusObjectPath> > reply = m_manager.call("EnumerateDevices");
if (!reply.isValid()) {
qWarning() << Q_FUNC_INFO << " error: " << reply.error().name();
return QStringList();
}
QStringList retList;
foreach(const QDBusObjectPath &path, reply.value()) {
retList << path.path();
}
return retList;
}
QSet< Solid::DeviceInterface::Type > UDisksManager::supportedInterfaces() const
{
return m_supportedInterfaces;
}
QString UDisksManager::udiPrefix() const
{
return UD_UDI_DISKS_PREFIX;
}
void UDisksManager::slotDeviceAdded(const QDBusObjectPath &opath)
{
const QString udi = opath.path();
if (!m_deviceCache.contains(udi)) {
m_deviceCache.append(udi);
}
UDisksDevice device(udi);
if (device.queryDeviceInterface(Solid::DeviceInterface::StorageDrive)
&& !device.prop("DeviceIsMediaAvailable").toBool()
&& !m_dirtyDevices.contains(udi))
m_dirtyDevices.append(udi);
emit deviceAdded(udi);
slotDeviceChanged(opath); // case: hotswap event (optical drive with media inside)
}
void UDisksManager::slotDeviceRemoved(const QDBusObjectPath &opath)
{
const QString udi = opath.path();
// case: hotswap event (optical drive with media inside)
if (m_knownDrivesWithMedia.contains(udi)) {
m_knownDrivesWithMedia.removeAll(udi);
m_deviceCache.removeAll(udi + ":media");
emit deviceRemoved(udi + ":media");
}
if (m_dirtyDevices.contains(udi))
m_dirtyDevices.removeAll(udi);
emit deviceRemoved(udi);
m_deviceCache.removeAll(opath.path());
}
void UDisksManager::slotDeviceChanged(const QDBusObjectPath &opath)
{
const QString udi = opath.path();
UDisksDevice device(udi);
if (device.queryDeviceInterface(Solid::DeviceInterface::OpticalDrive))
{
if (!m_knownDrivesWithMedia.contains(udi) && device.prop("DeviceIsOpticalDisc").toBool())
{
m_knownDrivesWithMedia.append(udi);
if (!m_deviceCache.isEmpty()) {
m_deviceCache.append(udi + ":media");
}
emit deviceAdded(udi + ":media");
}
if (m_knownDrivesWithMedia.contains(udi) && !device.prop("DeviceIsOpticalDisc").toBool())
{
m_knownDrivesWithMedia.removeAll(udi);
m_deviceCache.removeAll(udi + ":media");
emit deviceRemoved(udi + ":media");
}
}
if (device.queryDeviceInterface(Solid::DeviceInterface::StorageDrive)
&& device.prop("DeviceIsMediaAvailable").toBool()
&& m_dirtyDevices.contains(udi))
{
//qDebug() << "dirty device added:" << udi;
emit deviceAdded(udi);
m_dirtyDevices.removeAll(udi);
}
}
const QStringList &UDisksManager::deviceCache()
{
if (m_deviceCache.isEmpty())
allDevices();
return m_deviceCache;
}
#include "backends/udisks/moc_udisksmanager.cpp"

View file

@ -1,70 +0,0 @@
/*
Copyright 2010 Michael Zanetti <mzanetti@kde.org>
Copyright 2010 Lukas Tinkl <ltinkl@redhat.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UDISKSMANAGER_H
#define UDISKSMANAGER_H
#include "udisksdevice.h"
#include "solid/ifaces/devicemanager.h"
#include <QtDBus/QDBusInterface>
#include <QtCore/QSet>
namespace Solid
{
namespace Backends
{
namespace UDisks
{
class UDisksManager : public Solid::Ifaces::DeviceManager
{
Q_OBJECT
public:
UDisksManager(QObject *parent);
virtual QObject* createDevice(const QString& udi);
virtual QStringList devicesFromQuery(const QString& parentUdi, Solid::DeviceInterface::Type type);
virtual QStringList allDevices();
virtual QSet< Solid::DeviceInterface::Type > supportedInterfaces() const;
virtual QString udiPrefix() const;
virtual ~UDisksManager();
private Q_SLOTS:
void slotDeviceAdded(const QDBusObjectPath &opath);
void slotDeviceRemoved(const QDBusObjectPath &opath);
void slotDeviceChanged(const QDBusObjectPath &opath);
private:
const QStringList &deviceCache();
QStringList allDevicesInternal();
QStringList m_knownDrivesWithMedia; // list of known optical drives which contain a media
QSet<Solid::DeviceInterface::Type> m_supportedInterfaces;
QDBusInterface m_manager;
QStringList m_deviceCache;
QStringList m_dirtyDevices; // special 2-stage storage like Nokia N900
};
}
}
}
#endif // UDISKSMANAGER_H

View file

@ -1,280 +0,0 @@
/*
Copyright 2010 Michael Zanetti <mzanetti@kde.org>
Copyright 2010, 2011 Lukas Tinkl <ltinkl@redhat.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <QtCore/QFile>
#include <QtCore/QMap>
#include <QtCore/qmutex.h>
#include "udisksopticaldisc.h"
#include "soliddefs_p.h"
typedef QMap<QString, Solid::OpticalDisc::ContentTypes> ContentTypesCache;
Q_GLOBAL_STATIC(ContentTypesCache, cache)
Q_GLOBAL_STATIC(QMutex, cacheLock)
// inspired by http://cgit.freedesktop.org/hal/tree/hald/linux/probing/probe-volume.c
static Solid::OpticalDisc::ContentType advancedDiscDetect(const QString & device_file)
{
/* the discs block size */
unsigned short bs;
/* the path table size */
unsigned short ts;
/* the path table location (in blocks) */
unsigned int tl;
/* length of the directory name in current path table entry */
unsigned char len_di = 0;
/* the number of the parent directory's path table entry */
unsigned int parent = 0;
/* filename for the current path table entry */
char dirname[256];
/* our position into the path table */
int pos = 0;
/* the path table record we're on */
int curr_record = 1;
Solid::OpticalDisc::ContentType result = Solid::OpticalDisc::NoContent;
int fd = open (QFile::encodeName(device_file), O_RDONLY);
/* read the block size */
lseek (fd, 0x8080, SEEK_CUR);
if (read (fd, &bs, 2) != 2)
{
qDebug("Advanced probing on %s failed while reading block size", qPrintable(device_file));
goto out;
}
/* read in size of path table */
lseek (fd, 2, SEEK_CUR);
if (read (fd, &ts, 2) != 2)
{
qDebug("Advanced probing on %s failed while reading path table size", qPrintable(device_file));
goto out;
}
/* read in which block path table is in */
lseek (fd, 6, SEEK_CUR);
if (read (fd, &tl, 4) != 4)
{
qDebug("Advanced probing on %s failed while reading path table block", qPrintable(device_file));
goto out;
}
/* seek to the path table */
lseek (fd, bs * tl, SEEK_SET);
/* loop through the path table entries */
while (pos < ts)
{
/* get the length of the filename of the current entry */
if (read (fd, &len_di, 1) != 1)
{
qDebug("Advanced probing on %s failed, cannot read more entries", qPrintable(device_file));
break;
}
/* get the record number of this entry's parent
i'm pretty sure that the 1st entry is always the top directory */
lseek (fd, 5, SEEK_CUR);
if (read (fd, &parent, 2) != 2)
{
qDebug("Advanced probing on %s failed, couldn't read parent entry", qPrintable(device_file));
break;
}
/* read the name */
if (read (fd, dirname, len_di) != len_di)
{
qDebug("Advanced probing on %s failed, couldn't read the entry name", qPrintable(device_file));
break;
}
dirname[len_di] = 0;
/* if we found a folder that has the root as a parent, and the directory name matches
one of the special directories then set the properties accordingly */
if (parent == 1)
{
if (!strcasecmp (dirname, "VIDEO_TS"))
{
qDebug("Disc in %s is a Video DVD", qPrintable(device_file));
result = Solid::OpticalDisc::VideoDvd;
break;
}
else if (!strcasecmp (dirname, "BDMV"))
{
qDebug("Disc in %s is a Blu-ray video disc", qPrintable(device_file));
result = Solid::OpticalDisc::VideoBluRay;
break;
}
else if (!strcasecmp (dirname, "VCD"))
{
qDebug("Disc in %s is a Video CD", qPrintable(device_file));
result = Solid::OpticalDisc::VideoCd;
break;
}
else if (!strcasecmp (dirname, "SVCD"))
{
qDebug("Disc in %s is a Super Video CD", qPrintable(device_file));
result = Solid::OpticalDisc::SuperVideoCd;
break;
}
}
/* all path table entries are padded to be even,
so if this is an odd-length table, seek a byte to fix it */
if (len_di%2 == 1)
{
lseek (fd, 1, SEEK_CUR);
pos++;
}
/* update our position */
pos += 8 + len_di;
curr_record++;
}
close(fd);
return result;
out:
/* go back to the start of the file */
lseek (fd, 0, SEEK_SET);
close(fd);
return result;
}
using namespace Solid::Backends::UDisks;
OpticalDisc::OpticalDisc(UDisksDevice *device)
: UDisksStorageVolume(device), m_needsReprobe(true), m_cachedContent(Solid::OpticalDisc::NoContent)
{
connect(device, SIGNAL(changed()), this, SLOT(slotChanged()));
}
OpticalDisc::~OpticalDisc()
{
}
qulonglong OpticalDisc::capacity() const
{
return m_device->prop("DeviceSize").toULongLong();
}
bool OpticalDisc::isRewritable() const
{
// the hard way, udisks has no notion of a disc "rewritability"
const QString mediaType = m_device->prop("DriveMedia").toString();
return mediaType == "optical_cd_rw" || mediaType == "optical_dvd_rw" || mediaType == "optical_dvd_ram" ||
mediaType == "optical_dvd_plus_rw" || mediaType == "optical_dvd_plus_rw_dl" ||
mediaType == "optical_bd_re" || mediaType == "optical_hddvd_rw"; // TODO check completeness
}
bool OpticalDisc::isBlank() const
{
return m_device->prop("OpticalDiscIsBlank").toBool();
}
bool OpticalDisc::isAppendable() const
{
return m_device->prop("OpticalDiscIsAppendable").toBool();
}
Solid::OpticalDisc::DiscType OpticalDisc::discType() const
{
const QString discType = m_device->prop("DriveMedia").toString();
QMap<Solid::OpticalDisc::DiscType, QString> map;
map[Solid::OpticalDisc::CdRom] = "optical_cd";
map[Solid::OpticalDisc::CdRecordable] = "optical_cd_r";
map[Solid::OpticalDisc::CdRewritable] = "optical_cd_rw";
map[Solid::OpticalDisc::DvdRom] = "optical_dvd";
map[Solid::OpticalDisc::DvdRecordable] = "optical_dvd_r";
map[Solid::OpticalDisc::DvdRewritable] ="optical_dvd_rw";
map[Solid::OpticalDisc::DvdRam] ="optical_dvd_ram";
map[Solid::OpticalDisc::DvdPlusRecordable] ="optical_dvd_plus_r";
map[Solid::OpticalDisc::DvdPlusRewritable] ="optical_dvd_plus_rw";
map[Solid::OpticalDisc::DvdPlusRecordableDuallayer] ="optical_dvd_plus_r_dl";
map[Solid::OpticalDisc::DvdPlusRewritableDuallayer] ="optical_dvd_plus_rw_dl";
map[Solid::OpticalDisc::BluRayRom] ="optical_bd";
map[Solid::OpticalDisc::BluRayRecordable] ="optical_bd_r";
map[Solid::OpticalDisc::BluRayRewritable] ="optical_bd_re";
map[Solid::OpticalDisc::HdDvdRom] ="optical_hddvd";
map[Solid::OpticalDisc::HdDvdRecordable] ="optical_hddvd_r";
map[Solid::OpticalDisc::HdDvdRewritable] ="optical_hddvd_rw";
// TODO add these to Solid
//map[Solid::OpticalDisc::MagnetoOptical] ="optical_mo";
//map[Solid::OpticalDisc::MountRainer] ="optical_mrw";
//map[Solid::OpticalDisc::MountRainerWritable] ="optical_mrw_w";
return map.key( discType, Solid::OpticalDisc::UnknownDiscType );
}
Solid::OpticalDisc::ContentTypes OpticalDisc::availableContent() const
{
if (isBlank()) {
m_needsReprobe = false;
return Solid::OpticalDisc::NoContent;
}
if (m_needsReprobe) {
QMutexLocker lock(cacheLock());
QString deviceFile = m_device->prop("DeviceFile").toString();
if (cache()->contains(deviceFile)) {
m_cachedContent = cache()->value(deviceFile);
m_needsReprobe = false;
return m_cachedContent;
}
m_cachedContent = Solid::OpticalDisc::NoContent;
bool hasData = m_device->prop("OpticalDiscNumTracks").toInt() > 0 &&
m_device->prop("OpticalDiscNumTracks").toInt() > m_device->prop("OpticalDiscNumAudioTracks").toInt();
bool hasAudio = m_device->prop("OpticalDiscNumAudioTracks").toInt() > 0;
if ( hasData ) {
m_cachedContent |= Solid::OpticalDisc::Data;
m_cachedContent |= advancedDiscDetect(deviceFile);
}
if ( hasAudio )
m_cachedContent |= Solid::OpticalDisc::Audio;
m_needsReprobe = false;
cache()->insert(deviceFile, m_cachedContent);
}
return m_cachedContent;
}
void OpticalDisc::slotChanged()
{
QMutexLocker lock(cacheLock());
m_needsReprobe = true;
m_cachedContent = Solid::OpticalDisc::NoContent;
cache()->remove(m_device->prop("DeviceFile").toString());
}

View file

@ -1,63 +0,0 @@
/*
Copyright 2010 Michael Zanetti <mzanetti@kde.org>
Copyright 2010, 2011 Lukas Tinkl <ltinkl@redhat.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPTICALDISC_H
#define OPTICALDISC_H
#include <solid/ifaces/opticaldisc.h>
#include "udisksstoragevolume.h"
namespace Solid
{
namespace Backends
{
namespace UDisks
{
class OpticalDisc : public UDisksStorageVolume, virtual public Solid::Ifaces::OpticalDisc
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::OpticalDisc)
public:
OpticalDisc(UDisksDevice *device);
virtual ~OpticalDisc();
virtual qulonglong capacity() const;
virtual bool isRewritable() const;
virtual bool isBlank() const;
virtual bool isAppendable() const;
virtual Solid::OpticalDisc::DiscType discType() const;
virtual Solid::OpticalDisc::ContentTypes availableContent() const;
private slots:
void slotChanged();
private:
mutable bool m_needsReprobe;
mutable Solid::OpticalDisc::ContentTypes m_cachedContent;
};
}
}
}
#endif // OPTICALDISC_H

View file

@ -1,189 +0,0 @@
/*
Copyright 2010 Michael Zanetti <mzanetti@kde.org>
Copyright 2010-2011 Lukas Tinkl <ltinkl@redhat.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <QtCore/QFile>
#include <QtCore/QDebug>
#include "udisksopticaldrive.h"
#include "udisks.h"
#include "udisksdevice.h"
using namespace Solid::Backends::UDisks;
UDisksOpticalDrive::UDisksOpticalDrive(UDisksDevice *device)
: UDisksStorageDrive(device), m_ejectInProgress(false), m_readSpeed(0), m_writeSpeed(0), m_speedsInit(false)
{
m_device->registerAction("eject", this,
SLOT(slotEjectRequested()),
SLOT(slotEjectDone(int,QString)));
connect(m_device, SIGNAL(changed()), this, SLOT(slotChanged()));
}
UDisksOpticalDrive::~UDisksOpticalDrive()
{
}
bool UDisksOpticalDrive::eject()
{
if (m_ejectInProgress)
return false;
m_ejectInProgress = true;
m_device->broadcastActionRequested("eject");
QDBusConnection c = QDBusConnection::systemBus();
QString path = m_device->udi();
QDBusMessage msg = QDBusMessage::createMethodCall(UD_DBUS_SERVICE, path, UD_DBUS_INTERFACE_DISKS_DEVICE, "DriveEject");
msg << (QStringList() << "unmount"); // unmount parameter
return c.callWithCallback(msg, this, SLOT(slotDBusReply(QDBusMessage)), SLOT(slotDBusError(QDBusError)));
}
void UDisksOpticalDrive::slotDBusReply(const QDBusMessage &/*reply*/)
{
m_ejectInProgress = false;
m_device->broadcastActionDone("eject");
}
void UDisksOpticalDrive::slotDBusError(const QDBusError &error)
{
m_ejectInProgress = false;
m_device->broadcastActionDone("eject", m_device->errorToSolidError(error.name()),
m_device->errorToString(error.name()) + ": " +error.message());
}
void UDisksOpticalDrive::slotEjectRequested()
{
m_ejectInProgress = true;
emit ejectRequested(m_device->udi());
}
void UDisksOpticalDrive::slotEjectDone(int error, const QString &errorString)
{
m_ejectInProgress = false;
emit ejectDone(static_cast<Solid::ErrorType>(error), errorString, m_device->udi());
}
void UDisksOpticalDrive::initReadWriteSpeeds() const
{
#if 0
int read_speed, write_speed;
char *write_speeds = 0;
QByteArray device_file = QFile::encodeName(m_device->property("DeviceFile").toString());
//qDebug("Doing open (\"%s\", O_RDONLY | O_NONBLOCK)", device_file.constData());
int fd = open(device_file, O_RDONLY | O_NONBLOCK);
if (fd < 0) {
qWarning("Cannot open %s: %s", device_file.constData(), strerror (errno));
return;
}
if (get_read_write_speed(fd, &read_speed, &write_speed, &write_speeds) >= 0) {
m_readSpeed = read_speed;
m_writeSpeed = write_speed;
QStringList list = QString::fromLatin1(write_speeds).split(',', QString::SkipEmptyParts);
foreach (const QString & speed, list)
m_writeSpeeds.append(speed.toInt());
free(write_speeds);
m_speedsInit = true;
}
close(fd);
#endif
}
QList<int> UDisksOpticalDrive::writeSpeeds() const
{
if (!m_speedsInit)
initReadWriteSpeeds();
//qDebug() << "solid write speeds:" << m_writeSpeeds;
return m_writeSpeeds;
}
int UDisksOpticalDrive::writeSpeed() const
{
if (!m_speedsInit)
initReadWriteSpeeds();
return m_writeSpeed;
}
int UDisksOpticalDrive::readSpeed() const
{
if (!m_speedsInit)
initReadWriteSpeeds();
return m_readSpeed;
}
Solid::OpticalDrive::MediumTypes UDisksOpticalDrive::supportedMedia() const
{
const QStringList mediaTypes = m_device->prop("DriveMediaCompatibility").toStringList();
Solid::OpticalDrive::MediumTypes supported;
QMap<Solid::OpticalDrive::MediumType, QString> map;
map[Solid::OpticalDrive::Cdr] = "optical_cd_r";
map[Solid::OpticalDrive::Cdrw] = "optical_cd_rw";
map[Solid::OpticalDrive::Dvd] = "optical_dvd";
map[Solid::OpticalDrive::Dvdr] = "optical_dvd_r";
map[Solid::OpticalDrive::Dvdrw] ="optical_dvd_rw";
map[Solid::OpticalDrive::Dvdram] ="optical_dvd_ram";
map[Solid::OpticalDrive::Dvdplusr] ="optical_dvd_plus_r";
map[Solid::OpticalDrive::Dvdplusrw] ="optical_dvd_plus_rw";
map[Solid::OpticalDrive::Dvdplusdl] ="optical_dvd_plus_r_dl";
map[Solid::OpticalDrive::Dvdplusdlrw] ="optical_dvd_plus_rw_dl";
map[Solid::OpticalDrive::Bd] ="optical_bd";
map[Solid::OpticalDrive::Bdr] ="optical_bd_r";
map[Solid::OpticalDrive::Bdre] ="optical_bd_re";
map[Solid::OpticalDrive::HdDvd] ="optical_hddvd";
map[Solid::OpticalDrive::HdDvdr] ="optical_hddvd_r";
map[Solid::OpticalDrive::HdDvdrw] ="optical_hddvd_rw";
// TODO add these to Solid
//map[Solid::OpticalDrive::Mo] ="optical_mo";
//map[Solid::OpticalDrive::Mr] ="optical_mrw";
//map[Solid::OpticalDrive::Mrw] ="optical_mrw_w";
foreach ( const Solid::OpticalDrive::MediumType & type, map.keys() )
{
if ( mediaTypes.contains( map[type] ) )
{
supported |= type;
}
}
return supported;
}
void UDisksOpticalDrive::slotChanged()
{
m_speedsInit = false; // reset the read/write speeds, changes eg. with an inserted media
}

View file

@ -1,81 +0,0 @@
/*
Copyright 2010 Michael Zanetti <mzanetti@kde.org>
Copyright 2010 Lukas Tinkl <ltinkl@redhat.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UDISKSOPTICALDRIVE_H
#define UDISKSOPTICALDRIVE_H
#include <solid/ifaces/opticaldrive.h>
#include "udisksstoragedrive.h"
namespace Solid
{
namespace Backends
{
namespace UDisks
{
class UDisksOpticalDrive: public UDisksStorageDrive, virtual public Solid::Ifaces::OpticalDrive
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::OpticalDrive)
public:
UDisksOpticalDrive(UDisksDevice *device);
virtual ~UDisksOpticalDrive();
Q_SIGNALS:
void ejectPressed(const QString &udi);
void ejectDone(Solid::ErrorType error, QVariant errorData, const QString &udi);
void ejectRequested(const QString &udi);
public:
virtual bool eject();
virtual QList<int> writeSpeeds() const;
virtual int writeSpeed() const;
virtual int readSpeed() const;
virtual Solid::OpticalDrive::MediumTypes supportedMedia() const;
private Q_SLOTS:
void slotDBusReply(const QDBusMessage &reply);
void slotDBusError(const QDBusError &error);
void slotEjectRequested();
void slotEjectDone(int error, const QString &errorString);
void slotChanged();
private:
void initReadWriteSpeeds() const;
bool m_ejectInProgress;
// read/write speeds
mutable int m_readSpeed;
mutable int m_writeSpeed;
mutable QList<int> m_writeSpeeds;
mutable bool m_speedsInit;
};
}
}
}
#endif // UDISKSOPTICALDRIVE_H

View file

@ -1,392 +0,0 @@
/*
Copyright 2009 Pino Toscano <pino@kde.org>
Copyright 2009, 2011 Lukas Tinkl <ltinkl@redhat.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "udisksstorageaccess.h"
#include "udisks.h"
#include <QtCore/QDebug>
#include <QtCore/QTimer>
#include <QtCore/QProcess>
#include <QtDBus/QtDBus>
#include <QtGui/QApplication>
#include <QtGui/QWidget>
using namespace Solid::Backends::UDisks;
UDisksStorageAccess::UDisksStorageAccess(UDisksDevice *device)
: DeviceInterface(device), m_setupInProgress(false), m_teardownInProgress(false), m_passphraseRequested(false)
{
connect(device, SIGNAL(changed()), this, SLOT(slotChanged()));
updateCache();
// Delay connecting to DBus signals to avoid the related time penalty
// in hot paths such as predicate matching
QTimer::singleShot(0, this, SLOT(connectDBusSignals()));
}
UDisksStorageAccess::~UDisksStorageAccess()
{
}
void UDisksStorageAccess::connectDBusSignals()
{
m_device->registerAction("setup", this,
SLOT(slotSetupRequested()),
SLOT(slotSetupDone(int,QString)));
m_device->registerAction("teardown", this,
SLOT(slotTeardownRequested()),
SLOT(slotTeardownDone(int,QString)));
}
bool UDisksStorageAccess::isLuksDevice() const
{
return m_device->prop("DeviceIsLuks").toBool();
}
bool UDisksStorageAccess::isAccessible() const
{
if (isLuksDevice()) { // check if the cleartext slave is mounted
UDisksDevice holderDevice(m_device->prop("LuksHolder").value<QDBusObjectPath>().path());
return holderDevice.prop("DeviceIsMounted").toBool();
}
return m_device->prop("DeviceIsMounted").toBool();
}
QString UDisksStorageAccess::filePath() const
{
if (!isAccessible())
return QString();
QStringList mntPoints;
if (isLuksDevice()) { // encrypted (and unlocked) device
QString path = m_device->prop("LuksHolder").value<QDBusObjectPath>().path();
if (path.isEmpty() || path == "/")
return QString();
UDisksDevice holderDevice(path);
mntPoints = holderDevice.prop("DeviceMountPaths").toStringList();
if (!mntPoints.isEmpty())
return mntPoints.first(); // FIXME Solid doesn't support multiple mount points
else
return QString();
}
mntPoints = m_device->prop("DeviceMountPaths").toStringList();
if (!mntPoints.isEmpty())
return mntPoints.first(); // FIXME Solid doesn't support multiple mount points
else
return QString();
}
bool UDisksStorageAccess::isIgnored() const
{
return m_device->isDeviceBlacklisted();
}
bool UDisksStorageAccess::setup()
{
if ( m_teardownInProgress || m_setupInProgress )
return false;
m_setupInProgress = true;
m_device->broadcastActionRequested("setup");
if (m_device->prop("IdUsage").toString() == "crypto")
return requestPassphrase();
else
return mount();
}
bool UDisksStorageAccess::teardown()
{
if ( m_teardownInProgress || m_setupInProgress )
return false;
m_teardownInProgress = true;
m_device->broadcastActionRequested("teardown");
return unmount();
}
void UDisksStorageAccess::slotChanged()
{
const bool old_isAccessible = m_isAccessible;
updateCache();
if (old_isAccessible != m_isAccessible)
{
emit accessibilityChanged(m_isAccessible, m_device->udi());
}
}
void UDisksStorageAccess::updateCache()
{
m_isAccessible = isAccessible();
}
void UDisksStorageAccess::slotDBusReply( const QDBusMessage & reply )
{
Q_UNUSED(reply);
if (m_setupInProgress)
{
if (isLuksDevice() && !isAccessible()) // unlocked device, now mount it
mount();
else // Don't broadcast setupDone unless the setup is really done. (Fix kde#271156)
{
m_setupInProgress = false;
m_device->broadcastActionDone("setup");
}
}
else if (m_teardownInProgress)
{
QString clearTextPath = m_device->prop("LuksHolder").value<QDBusObjectPath>().path();
if (isLuksDevice() && clearTextPath != "/") // unlocked device, lock it
{
callCryptoTeardown();
}
else if (m_device->prop("DeviceIsLuksCleartext").toBool()) {
callCryptoTeardown(true); // Lock crypted parent
}
else
{
if (m_device->prop("DriveIsMediaEjectable").toBool() &&
m_device->prop("DeviceIsMediaAvailable").toBool() &&
!m_device->prop("DeviceIsOpticalDisc").toBool()) // optical drives have their Eject method
{
QString devnode = m_device->prop("DeviceFile").toString();
#if defined(Q_OS_OPENBSD)
QString program = "cdio";
QStringList args;
args << "-f" << devnode << "eject";
#elif defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD) || defined(Q_OS_DRAGONFLY)
devnode.remove("/dev/").replace("([0-9]).", "\\1");
QString program = "cdcontrol";
QStringList args;
args << "-f" << devnode << "eject";
#else
QString program = "eject";
QStringList args;
args << devnode;
#endif
QProcess::startDetached( program, args );
}
// try to eject the (parent) drive, e.g. SD card from a reader
QString drivePath = m_device->prop("PartitionSlave").value<QDBusObjectPath>().path();
if (!drivePath.isEmpty() || drivePath != "/")
{
QDBusConnection c = QDBusConnection::systemBus();
QDBusMessage msg = QDBusMessage::createMethodCall(UD_DBUS_SERVICE, drivePath, UD_DBUS_INTERFACE_DISKS_DEVICE, "DriveEject");
msg << QStringList(); // options, unused now
c.call(msg, QDBus::NoBlock);
// power down removable USB hard drives, rhbz#852196
UDisksDevice drive(drivePath);
if (drive.prop("DriveCanDetach").toBool()) {
QDBusMessage msg2 = QDBusMessage::createMethodCall(UD_DBUS_SERVICE, drivePath, UD_DBUS_INTERFACE_DISKS_DEVICE, "DriveDetach");
msg2 << QStringList(); // options, unused now
c.call(msg2, QDBus::NoBlock);
}
}
m_teardownInProgress = false;
m_device->broadcastActionDone("teardown");
}
}
}
void UDisksStorageAccess::slotDBusError( const QDBusError & error )
{
if (m_setupInProgress)
{
m_setupInProgress = false;
m_device->broadcastActionDone("setup", m_device->errorToSolidError(error.name()),
m_device->errorToString(error.name()) + ": " +error.message());
}
else if (m_teardownInProgress)
{
m_teardownInProgress = false;
m_device->broadcastActionDone("teardown", m_device->errorToSolidError(error.name()),
m_device->errorToString(error.name()) + ": " + error.message());
}
}
void UDisksStorageAccess::slotSetupRequested()
{
m_setupInProgress = true;
emit setupRequested(m_device->udi());
}
void UDisksStorageAccess::slotSetupDone(int error, const QString &errorString)
{
m_setupInProgress = false;
emit setupDone(static_cast<Solid::ErrorType>(error), errorString, m_device->udi());
slotChanged();
}
void UDisksStorageAccess::slotTeardownRequested()
{
m_teardownInProgress = true;
emit teardownRequested(m_device->udi());
}
void UDisksStorageAccess::slotTeardownDone(int error, const QString &errorString)
{
m_teardownInProgress = false;
emit teardownDone(static_cast<Solid::ErrorType>(error), errorString, m_device->udi());
slotChanged();
}
bool UDisksStorageAccess::mount()
{
QString path = m_device->udi();
if (path.endsWith(":media")) {
path.chop(6);
}
QString fstype;
QStringList options;
if (isLuksDevice()) { // mount options for the cleartext volume
path = m_device->prop("LuksHolder").value<QDBusObjectPath>().path();
UDisksDevice holderDevice(path);
fstype = holderDevice.prop("IdType").toString();
}
QDBusConnection c = QDBusConnection::systemBus();
QDBusMessage msg = QDBusMessage::createMethodCall(UD_DBUS_SERVICE, path, UD_DBUS_INTERFACE_DISKS_DEVICE, "FilesystemMount");
if (m_device->prop("IdUsage").toString() == "filesystem")
fstype = m_device->prop("IdType").toString();
if (fstype == "vfat") {
options << "flush";
}
msg << fstype;
msg << options;
return c.callWithCallback(msg, this,
SLOT(slotDBusReply(QDBusMessage)),
SLOT(slotDBusError(QDBusError)));
}
bool UDisksStorageAccess::unmount()
{
QString path = m_device->udi();
if (path.endsWith(":media")) {
path.chop(6);
}
if (isLuksDevice()) { // unmount options for the cleartext volume
path = m_device->prop("LuksHolder").value<QDBusObjectPath>().path();
}
QDBusConnection c = QDBusConnection::systemBus();
QDBusMessage msg = QDBusMessage::createMethodCall(UD_DBUS_SERVICE, path, UD_DBUS_INTERFACE_DISKS_DEVICE, "FilesystemUnmount");
msg << QStringList(); // options, unused now
return c.callWithCallback(msg, this,
SLOT(slotDBusReply(QDBusMessage)),
SLOT(slotDBusError(QDBusError)),
s_unmountTimeout);
}
QString UDisksStorageAccess::generateReturnObjectPath()
{
static int number = 1;
return "/org/kde/solid/UDisksStorageAccess_"+QString::number(number++);
}
bool UDisksStorageAccess::requestPassphrase()
{
QString udi = m_device->udi();
QString returnService = QDBusConnection::sessionBus().baseService();
m_lastReturnObject = generateReturnObjectPath();
QDBusConnection::sessionBus().registerObject(m_lastReturnObject, this, QDBusConnection::ExportScriptableSlots);
QWidget *activeWindow = QApplication::activeWindow();
uint wId = 0;
if (activeWindow!=0)
wId = (uint)activeWindow->winId();
QString appId = QCoreApplication::applicationName();
QDBusInterface soliduiserver("org.kde.kded", "/modules/soliduiserver", "org.kde.SolidUiServer");
QDBusReply<void> reply = soliduiserver.call("showPassphraseDialog", udi, returnService,
m_lastReturnObject, wId, appId);
m_passphraseRequested = reply.isValid();
if (!m_passphraseRequested)
qWarning() << "Failed to call the SolidUiServer, D-Bus said:" << reply.error();
return m_passphraseRequested;
}
void UDisksStorageAccess::passphraseReply( const QString & passphrase )
{
if (m_passphraseRequested)
{
QDBusConnection::sessionBus().unregisterObject(m_lastReturnObject);
m_passphraseRequested = false;
if (!passphrase.isEmpty())
callCryptoSetup(passphrase);
else
{
m_setupInProgress = false;
m_device->broadcastActionDone("setup");
}
}
}
void UDisksStorageAccess::callCryptoSetup( const QString & passphrase )
{
QDBusConnection c = QDBusConnection::systemBus();
QDBusMessage msg = QDBusMessage::createMethodCall(UD_DBUS_SERVICE, m_device->udi(), UD_DBUS_INTERFACE_DISKS_DEVICE, "LuksUnlock");
msg << passphrase;
msg << QStringList(); // options, unused now
c.callWithCallback(msg, this,
SLOT(slotDBusReply(QDBusMessage)),
SLOT(slotDBusError(QDBusError)));
}
bool UDisksStorageAccess::callCryptoTeardown(bool actOnParent)
{
QDBusConnection c = QDBusConnection::systemBus();
QDBusMessage msg = QDBusMessage::createMethodCall(UD_DBUS_SERVICE,
actOnParent?(m_device->prop("LuksCleartextSlave").value<QDBusObjectPath>().path()):m_device->udi(),
UD_DBUS_INTERFACE_DISKS_DEVICE, "LuksLock");
msg << QStringList(); // options, unused now
return c.callWithCallback(msg, this,
SLOT(slotDBusReply(QDBusMessage)),
SLOT(slotDBusError(QDBusError)));
}
#include "backends/udisks/moc_udisksstorageaccess.cpp"

View file

@ -1,102 +0,0 @@
/*
Copyright 2009 Pino Toscano <pino@kde.org>
Copyright 2009 Lukas Tinkl <ltinkl@redhat.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UDISKSSTORAGEACCESS_H
#define UDISKSSTORAGEACCESS_H
#include <solid/ifaces/storageaccess.h>
#include "udisksdeviceinterface.h"
#include <QtDBus/QDBusMessage>
#include <QtDBus/QDBusError>
namespace Solid
{
namespace Backends
{
namespace UDisks
{
class UDisksStorageAccess : public DeviceInterface, virtual public Solid::Ifaces::StorageAccess
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::StorageAccess)
public:
UDisksStorageAccess(UDisksDevice *device);
virtual ~UDisksStorageAccess();
virtual bool isAccessible() const;
virtual QString filePath() const;
virtual bool isIgnored() const;
virtual bool setup();
virtual bool teardown();
Q_SIGNALS:
void accessibilityChanged(bool accessible, const QString &udi);
void setupDone(Solid::ErrorType error, QVariant errorData, const QString &udi);
void teardownDone(Solid::ErrorType error, QVariant errorData, const QString &udi);
void setupRequested(const QString &udi);
void teardownRequested(const QString &udi);
public Q_SLOTS:
Q_SCRIPTABLE void passphraseReply( const QString & passphrase );
private Q_SLOTS:
void slotChanged();
void slotDBusReply( const QDBusMessage & reply );
void slotDBusError( const QDBusError & error );
void connectDBusSignals();
void slotSetupRequested();
void slotSetupDone(int error, const QString &errorString);
void slotTeardownRequested();
void slotTeardownDone(int error, const QString &errorString);
private:
/// @return true if this device is luks and unlocked
bool isLuksDevice() const;
void updateCache();
bool mount();
bool unmount();
bool requestPassphrase();
void callCryptoSetup( const QString & passphrase );
bool callCryptoTeardown( bool actOnParent=false );
QString generateReturnObjectPath();
private:
bool m_isAccessible;
bool m_setupInProgress;
bool m_teardownInProgress;
bool m_passphraseRequested;
QString m_lastReturnObject;
static const int s_unmountTimeout = 0x7fffffff;
};
}
}
}
#endif // UDISKSSTORAGEACCESS_H

View file

@ -1,154 +0,0 @@
/*
Copyright 2010 Michael Zanetti <mzanetti@kde.org>
Copyright 2010 Lukas Tinkl <ltinkl@redhat.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "udisksstoragedrive.h"
#include <QtCore/QDebug>
using namespace Solid::Backends::UDisks;
UDisksStorageDrive::UDisksStorageDrive(UDisksDevice* device)
: Block(device)
{
}
UDisksStorageDrive::~UDisksStorageDrive()
{
}
qulonglong UDisksStorageDrive::size() const
{
return m_device->prop("DeviceSize").toULongLong();
}
bool UDisksStorageDrive::isHotpluggable() const
{
return m_device->prop("DriveCanDetach").toBool();
}
bool UDisksStorageDrive::isRemovable() const
{
return m_device->prop("DeviceIsRemovable").toBool() ||
!m_device->prop( "DeviceIsSystemInternal" ).toBool();
}
Solid::StorageDrive::DriveType UDisksStorageDrive::driveType() const
{
const QStringList mediaTypes = m_device->prop("DriveMediaCompatibility").toStringList();
bool isHardDisk = m_device->prop( "DeviceIsSystemInternal" ).toBool();
if ( isHardDisk )
{
return Solid::StorageDrive::HardDisk;
}
else if ( !mediaTypes.filter( "optical" ).isEmpty() ) // optical disks
{
return Solid::StorageDrive::CdromDrive;
}
else if ( mediaTypes.contains( "floppy" ) )
{
return Solid::StorageDrive::Floppy;
}
#if 0 // TODO add to Solid
else if ( mediaTypes.contains( "floppy_jaz" ) )
{
return Solid::StorageDrive::Jaz;
}
else if ( mediaTypes.contains( "floppy_zip" ) )
{
return Solid::StorageDrive::Zip;
}
#endif
/*
else if (type=="tape") // FIXME: DK doesn't know about tapes
{
return Solid::StorageDrive::Tape;
}
*/
#if 0 // TODO add to Solid
else if ( mediaTypes.contains( "flash" ) )
{
return Solid::StorageDrive::Flash;
}
#endif
else if ( mediaTypes.contains( "flash_cf" ) )
{
return Solid::StorageDrive::CompactFlash;
}
else if ( mediaTypes.contains( "flash_ms" ) )
{
return Solid::StorageDrive::MemoryStick;
}
else if ( mediaTypes.contains( "flash_sm" ) )
{
return Solid::StorageDrive::SmartMedia;
}
else if ( mediaTypes.contains( "flash_sd" ) || mediaTypes.contains( "flash_sdhc" ) || mediaTypes.contains( "flash_mmc" ) )
{
return Solid::StorageDrive::SdMmc;
}
// FIXME: DK doesn't know about xD cards either
else
{
return Solid::StorageDrive::HardDisk;
}
}
Solid::StorageDrive::Bus UDisksStorageDrive::bus() const
{
const QString bus = m_device->prop( "DriveConnectionInterface" ).toString();
if ( bus == "ata" || bus == "ata_parallel" ) // parallel (classical) ATA
{
return Solid::StorageDrive::Ide;
}
else if ( bus == "usb" )
{
return Solid::StorageDrive::Usb;
}
else if ( bus == "firewire" )
{
return Solid::StorageDrive::Ieee1394;
}
else if ( bus == "scsi" )
{
return Solid::StorageDrive::Scsi;
}
else if ( bus == "ata_serial" || bus == "ata_serial_esata" ) // serial ATA
{
return Solid::StorageDrive::Sata;
}
#if 0 // TODO add these to Solid
else if ( bus == "sdio" )
{
return Solid::StorageDrive::SDIO;
}
else if ( bus == "virtual" )
{
return Solid::StorageDrive::Virtual;
}
#endif
else
return Solid::StorageDrive::Platform;
}

View file

@ -1,55 +0,0 @@
/*
Copyright 2010 Michael Zanetti <mzanetti@kde.org>
Copyright 2010 Lukas Tinkl <ltinkl@redhat.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UDISKSSTORAGEDRIVE_H
#define UDISKSSTORAGEDRIVE_H
#include <ifaces/storagedrive.h>
#include "udisksblock.h"
namespace Solid
{
namespace Backends
{
namespace UDisks
{
class UDisksStorageDrive: public Block, virtual public Solid::Ifaces::StorageDrive
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::StorageDrive)
public:
UDisksStorageDrive(UDisksDevice *device);
virtual ~UDisksStorageDrive();
virtual qulonglong size() const;
virtual bool isHotpluggable() const;
virtual bool isRemovable() const;
virtual Solid::StorageDrive::DriveType driveType() const;
virtual Solid::StorageDrive::Bus bus() const;
};
}
}
}
#endif // UDISKSSTORAGEDRIVE_H

View file

@ -1,99 +0,0 @@
/*
Copyright 2010 Michael Zanetti <mzanetti@kde.org>
Copyright 2010 Lukas Tinkl <ltinkl@redhat.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "udisksstoragevolume.h"
using namespace Solid::Backends::UDisks;
UDisksStorageVolume::UDisksStorageVolume(UDisksDevice *device)
: Block(device)
{
}
UDisksStorageVolume::~UDisksStorageVolume()
{
}
QString UDisksStorageVolume::encryptedContainerUdi() const
{
if ( m_device->prop( "DeviceIsLuksCleartext" ).toBool() )
return m_device->prop( "LuksCleartextSlave" ).value<QDBusObjectPath>().path();
return QString();
}
qulonglong UDisksStorageVolume::size() const
{
return m_device->prop("PartitionSize").toULongLong();
}
QString UDisksStorageVolume::uuid() const
{
return m_device->prop("IdUuid").toString();
}
QString UDisksStorageVolume::label() const
{
QString label = m_device->prop("IdLabel").toString();
if (label.isEmpty())
label = m_device->prop("PartitionLabel").toString();
return label;
}
QString UDisksStorageVolume::fsType() const
{
return m_device->prop("IdType").toString();
}
Solid::StorageVolume::UsageType UDisksStorageVolume::usage() const
{
QString usage = m_device->prop("IdUsage").toString();
if (usage == "filesystem")
{
return Solid::StorageVolume::FileSystem;
}
else if (usage == "partitiontable")
{
return Solid::StorageVolume::PartitionTable;
}
else if (usage == "raid")
{
return Solid::StorageVolume::Raid;
}
else if (usage == "crypto")
{
return Solid::StorageVolume::Encrypted;
}
else if (usage == "unused")
{
return Solid::StorageVolume::Unused;
}
else
{
return Solid::StorageVolume::Other;
}
}
bool UDisksStorageVolume::isIgnored() const
{
return m_device->isDeviceBlacklisted();
}

View file

@ -1,57 +0,0 @@
/*
Copyright 2010 Michael Zanetti <mzanetti@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UDISKSSTORAGEVOLUME_H
#define UDISKSSTORAGEVOLUME_H
#include <ifaces/storagevolume.h>
#include "udisksblock.h"
namespace Solid
{
namespace Backends
{
namespace UDisks
{
class UDisksStorageVolume: public Block, virtual public Solid::Ifaces::StorageVolume
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::StorageVolume)
public:
UDisksStorageVolume(UDisksDevice *device);
virtual ~UDisksStorageVolume();
virtual QString encryptedContainerUdi() const;
virtual qulonglong size() const;
virtual QString uuid() const;
virtual QString label() const;
virtual QString fsType() const;
virtual Solid::StorageVolume::UsageType usage() const;
virtual bool isIgnored() const;
};
}
}
}
#endif // UDISKSSTORAGEVOLUME_H

View file

@ -21,3 +21,4 @@
#cmakedefine UDEV_FOUND
#cmakedefine01 UDEV_HAVE_GET_SYSATTR_LIST_ENTRY
#cmakedefine HUPNP_FOUND
#cmakedefine UDISKS2_FOUND

View file

@ -24,24 +24,20 @@
#include <config-solid.h>
#include "backends/fakehw/fakemanager.h"
#if defined (WITH_SOLID_UDISKS2)
#include "backends/udisks2/udisksmanager.h"
#else
#include "backends/udisks/udisksmanager.h"
#endif
#include "backends/fstab/fstabmanager.h"
#include "backends/upower/upowermanager.h"
#if defined (HUPNP_FOUND)
#include "backends/upnp/upnpdevicemanager.h"
#endif
#if defined (UDEV_FOUND) && defined(Q_OS_LINUX)
#include "backends/udev/udevmanager.h"
#endif
#include "backends/fstab/fstabmanager.h"
#if defined (UDISKS2_FOUND)
#include "backends/udisks2/udisksmanager.h"
#endif
#if defined (HUPNP_FOUND)
#include "backends/upnp/upnpdevicemanager.h"
#endif
Solid::ManagerBasePrivate::ManagerBasePrivate()
{
@ -59,16 +55,16 @@ void Solid::ManagerBasePrivate::loadBackends()
if (!solidFakeXml.isEmpty()) {
m_backends << new Solid::Backends::Fake::FakeManager(0, solidFakeXml);
} else {
m_backends << new Solid::Backends::Fstab::FstabManager(0);
m_backends << new Solid::Backends::UPower::UPowerManager(0);
# if defined(UDEV_FOUND) && defined(Q_OS_LINUX)
m_backends << new Solid::Backends::UDev::UDevManager(0);
# endif
# if defined(WITH_SOLID_UDISKS2)
m_backends << new Solid::Backends::UDisks2::Manager(0)
# else
m_backends << new Solid::Backends::UDisks::UDisksManager(0)
# if defined(UDISKS2_FOUND)
m_backends << new Solid::Backends::UDisks2::Manager(0);
# endif
<< new Solid::Backends::UPower::UPowerManager(0)
<< new Solid::Backends::Fstab::FstabManager(0);
# if defined (HUPNP_FOUND)
m_backends << new Solid::Backends::UPnP::UPnPDeviceManager(0);