Remove old devicekit udisks backend
This commit is contained in:
@@ -306,10 +306,6 @@ optional_component(AUDIOCD ON "Devices: Audio CD support"
|
|||||||
DEPENDS "libcdio" CDIO_FOUND
|
DEPENDS "libcdio" CDIO_FOUND
|
||||||
)
|
)
|
||||||
|
|
||||||
optional_component(DEVICEKIT ON "Devices: DeviceKit backend"
|
|
||||||
DEPENDS "D-Bus support" DBUS_FOUND
|
|
||||||
)
|
|
||||||
|
|
||||||
optional_component(UDISKS2 ON "Devices: UDisks2 backend"
|
optional_component(UDISKS2 ON "Devices: UDisks2 backend"
|
||||||
DEPENDS "D-Bus support" DBUS_FOUND
|
DEPENDS "D-Bus support" DBUS_FOUND
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -604,10 +604,6 @@ if(UNIX AND HAVE_DBUS)
|
|||||||
SOURCES core/mpris.cpp core/mpris2.cpp core/dbusscreensaver.cpp
|
SOURCES core/mpris.cpp core/mpris2.cpp core/dbusscreensaver.cpp
|
||||||
HEADERS core/mpris.h core/mpris2.h
|
HEADERS core/mpris.h core/mpris2.h
|
||||||
)
|
)
|
||||||
optional_source(HAVE_DEVICEKIT
|
|
||||||
SOURCES device/devicekitlister.cpp
|
|
||||||
HEADERS device/devicekitlister.h
|
|
||||||
)
|
|
||||||
optional_source(HAVE_UDISKS2
|
optional_source(HAVE_UDISKS2
|
||||||
SOURCES device/udisks2lister.cpp
|
SOURCES device/udisks2lister.cpp
|
||||||
HEADERS device/udisks2lister.h
|
HEADERS device/udisks2lister.h
|
||||||
@@ -667,20 +663,6 @@ if(UNIX AND HAVE_DBUS)
|
|||||||
list(APPEND HEADERS ${CMAKE_CURRENT_BINARY_DIR}/dbus/avahientrygroup.h)
|
list(APPEND HEADERS ${CMAKE_CURRENT_BINARY_DIR}/dbus/avahientrygroup.h)
|
||||||
list(APPEND SOURCES ${CMAKE_CURRENT_BINARY_DIR}/dbus/avahientrygroup.cpp)
|
list(APPEND SOURCES ${CMAKE_CURRENT_BINARY_DIR}/dbus/avahientrygroup.cpp)
|
||||||
|
|
||||||
# DeviceKit DBUS interfaces
|
|
||||||
if(HAVE_DEVICEKIT)
|
|
||||||
set_source_files_properties(dbus/org.freedesktop.UDisks.xml
|
|
||||||
PROPERTIES NO_NAMESPACE dbus/udisks)
|
|
||||||
set_source_files_properties(dbus/org.freedesktop.UDisks.Device.xml
|
|
||||||
PROPERTIES NO_NAMESPACE dbus/udisksdevice)
|
|
||||||
qt5_add_dbus_interface(SOURCES
|
|
||||||
dbus/org.freedesktop.UDisks.xml
|
|
||||||
dbus/udisks)
|
|
||||||
qt5_add_dbus_interface(SOURCES
|
|
||||||
dbus/org.freedesktop.UDisks.Device.xml
|
|
||||||
dbus/udisksdevice)
|
|
||||||
endif(HAVE_DEVICEKIT)
|
|
||||||
|
|
||||||
if(HAVE_UDISKS2)
|
if(HAVE_UDISKS2)
|
||||||
set_source_files_properties(dbus/org.freedesktop.DBus.ObjectManager.xml
|
set_source_files_properties(dbus/org.freedesktop.DBus.ObjectManager.xml
|
||||||
PROPERTIES NO_NAMESPACE dbus/objectmanager INCLUDE dbus/metatypes.h)
|
PROPERTIES NO_NAMESPACE dbus/objectmanager INCLUDE dbus/metatypes.h)
|
||||||
|
|||||||
@@ -30,7 +30,6 @@
|
|||||||
#cmakedefine HAVE_X11
|
#cmakedefine HAVE_X11
|
||||||
#cmakedefine HAVE_UDISKS2
|
#cmakedefine HAVE_UDISKS2
|
||||||
#cmakedefine HAVE_ALSA
|
#cmakedefine HAVE_ALSA
|
||||||
#cmakedefine HAVE_DEVICEKIT
|
|
||||||
#cmakedefine HAVE_IMOBILEDEVICE
|
#cmakedefine HAVE_IMOBILEDEVICE
|
||||||
#cmakedefine HAVE_AUDIOCD
|
#cmakedefine HAVE_AUDIOCD
|
||||||
#cmakedefine HAVE_LIBGPOD
|
#cmakedefine HAVE_LIBGPOD
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -78,7 +78,7 @@ class DeviceInfo : public SimpleTreeItem<DeviceInfo> {
|
|||||||
transcode_format_(Song::FileType_Unknown),
|
transcode_format_(Song::FileType_Unknown),
|
||||||
task_percentage_(-1) {}
|
task_percentage_(-1) {}
|
||||||
|
|
||||||
// A device can be discovered in different ways (devicekit, gio, etc.)
|
// A device can be discovered in different ways (udisks2, gio, etc.)
|
||||||
// Sometimes the same device is discovered more than once. In this case the device will have multiple "backends".
|
// Sometimes the same device is discovered more than once. In this case the device will have multiple "backends".
|
||||||
struct Backend {
|
struct Backend {
|
||||||
Backend(DeviceLister *lister = nullptr, const QString &id = QString())
|
Backend(DeviceLister *lister = nullptr, const QString &id = QString())
|
||||||
|
|||||||
@@ -1,297 +0,0 @@
|
|||||||
/*
|
|
||||||
* Strawberry Music Player
|
|
||||||
* This file was part of Clementine.
|
|
||||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
|
||||||
*
|
|
||||||
* Strawberry 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 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Strawberry 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 General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include <dbus/udisks.h>
|
|
||||||
#include <dbus/udisksdevice.h>
|
|
||||||
|
|
||||||
#include <QMutex>
|
|
||||||
#include <QList>
|
|
||||||
#include <QVariant>
|
|
||||||
#include <QString>
|
|
||||||
#include <QStringBuilder>
|
|
||||||
#include <QUrl>
|
|
||||||
#include <QDBusConnection>
|
|
||||||
#include <QDBusPendingReply>
|
|
||||||
#include <QDBusObjectPath>
|
|
||||||
#include <QDBusError>
|
|
||||||
#include <QJsonArray>
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QtDebug>
|
|
||||||
|
|
||||||
#include "core/logging.h"
|
|
||||||
#include "core/utilities.h"
|
|
||||||
#include "devicekitlister.h"
|
|
||||||
|
|
||||||
DeviceKitLister::DeviceKitLister() {}
|
|
||||||
DeviceKitLister::~DeviceKitLister() {}
|
|
||||||
|
|
||||||
QString DeviceKitLister::DeviceData::unique_id() const {
|
|
||||||
return QString("DeviceKit/%1/%2/%3/%4").arg(drive_serial, drive_vendor, drive_model).arg(device_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DeviceKitLister::Init() {
|
|
||||||
|
|
||||||
interface_.reset(new OrgFreedesktopUDisksInterface(OrgFreedesktopUDisksInterface::staticInterfaceName(), "/org/freedesktop/UDisks", QDBusConnection::systemBus()));
|
|
||||||
|
|
||||||
// Get all the devices currently attached
|
|
||||||
QDBusPendingReply<QList<QDBusObjectPath> > reply = interface_->EnumerateDevices();
|
|
||||||
reply.waitForFinished();
|
|
||||||
|
|
||||||
if (!reply.isValid()) {
|
|
||||||
qLog(Warning) << "Error enumerating DeviceKit-disks devices:" << reply.error().name() << reply.error().message();
|
|
||||||
interface_.reset();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Listen for changes
|
|
||||||
connect(interface_.get(), SIGNAL(DeviceAdded(QDBusObjectPath)), SLOT(DBusDeviceAdded(QDBusObjectPath)));
|
|
||||||
connect(interface_.get(), SIGNAL(DeviceRemoved(QDBusObjectPath)), SLOT(DBusDeviceRemoved(QDBusObjectPath)));
|
|
||||||
connect(interface_.get(), SIGNAL(DeviceChanged(QDBusObjectPath)), SLOT(DBusDeviceChanged(QDBusObjectPath)));
|
|
||||||
|
|
||||||
// Get information about each one
|
|
||||||
QMap<QString, DeviceData> device_data;
|
|
||||||
for (const QDBusObjectPath &path : reply.value()) {
|
|
||||||
DeviceData data = ReadDeviceData(path);
|
|
||||||
if (data.suitable) device_data[data.unique_id()] = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the internal cache
|
|
||||||
{
|
|
||||||
QMutexLocker l(&mutex_);
|
|
||||||
device_data_ = device_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Notify about the changes
|
|
||||||
for (const QString &id : device_data.keys()) {
|
|
||||||
emit DeviceAdded(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList DeviceKitLister::DeviceUniqueIDs() {
|
|
||||||
QMutexLocker l(&mutex_);
|
|
||||||
return device_data_.keys();
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariantList DeviceKitLister::DeviceIcons(const QString &id) {
|
|
||||||
|
|
||||||
QString path = LockAndGetDeviceInfo(id, &DeviceData::device_mount_paths)[0];
|
|
||||||
return QVariantList()
|
|
||||||
<< GuessIconForPath(path)
|
|
||||||
<< GuessIconForModel(DeviceManufacturer(id), DeviceModel(id))
|
|
||||||
<< LockAndGetDeviceInfo(id, &DeviceData::device_presentation_icon_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString DeviceKitLister::DeviceManufacturer(const QString &id) {
|
|
||||||
return LockAndGetDeviceInfo(id, &DeviceData::drive_vendor);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString DeviceKitLister::DeviceModel(const QString &id) {
|
|
||||||
return LockAndGetDeviceInfo(id, &DeviceData::drive_model);
|
|
||||||
}
|
|
||||||
|
|
||||||
quint64 DeviceKitLister::DeviceCapacity(const QString &id) {
|
|
||||||
return LockAndGetDeviceInfo(id, &DeviceData::device_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
quint64 DeviceKitLister::DeviceFreeSpace(const QString &id) {
|
|
||||||
return LockAndGetDeviceInfo(id, &DeviceData::free_space);
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariantMap DeviceKitLister::DeviceHardwareInfo(const QString &id) {
|
|
||||||
|
|
||||||
QVariantMap ret;
|
|
||||||
|
|
||||||
QMutexLocker l(&mutex_);
|
|
||||||
if (!device_data_.contains(id)) return ret;
|
|
||||||
const DeviceData &data = device_data_[id];
|
|
||||||
|
|
||||||
ret[QT_TR_NOOP("D-Bus path")] = data.dbus_path;
|
|
||||||
ret[QT_TR_NOOP("Serial number")] = data.drive_serial;
|
|
||||||
ret[QT_TR_NOOP("Mount points")] = data.device_mount_paths.join(", ");
|
|
||||||
ret[QT_TR_NOOP("Device")] = data.device_file;
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
QString DeviceKitLister::MakeFriendlyName(const QString &id) {
|
|
||||||
|
|
||||||
QMutexLocker l(&mutex_);
|
|
||||||
if (!device_data_.contains(id)) return QString();
|
|
||||||
const DeviceData &data = device_data_[id];
|
|
||||||
|
|
||||||
if (!data.device_presentation_name.isEmpty())
|
|
||||||
return data.device_presentation_name;
|
|
||||||
if (!data.drive_model.isEmpty() && !data.drive_vendor.isEmpty())
|
|
||||||
return data.drive_vendor + " " + data.drive_model;
|
|
||||||
if (!data.drive_model.isEmpty()) return data.drive_model;
|
|
||||||
return data.drive_serial;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
DeviceKitLister::DeviceData DeviceKitLister::ReadDeviceData(const QDBusObjectPath &path) const {
|
|
||||||
|
|
||||||
DeviceData ret;
|
|
||||||
|
|
||||||
OrgFreedesktopUDisksDeviceInterface device(OrgFreedesktopUDisksInterface::staticInterfaceName(), path.path(), QDBusConnection::systemBus());
|
|
||||||
if (!device.isValid()) {
|
|
||||||
qLog(Warning) << "Error connecting to the device interface on" << path.path();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't do anything with internal drives, hidden drives, or partition tables
|
|
||||||
if (device.deviceIsSystemInternal() || device.devicePresentationHide() || device.deviceMountPaths().isEmpty() || device.deviceIsPartitionTable()) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret.suitable = true;
|
|
||||||
ret.dbus_path = path.path();
|
|
||||||
ret.drive_serial = device.driveSerial();
|
|
||||||
ret.drive_model = device.driveModel();
|
|
||||||
ret.drive_vendor = device.driveVendor();
|
|
||||||
ret.device_file = device.deviceFile();
|
|
||||||
ret.device_presentation_name = device.devicePresentationName();
|
|
||||||
ret.device_presentation_icon_name = device.devicePresentationIconName();
|
|
||||||
ret.device_size = device.deviceSize();
|
|
||||||
ret.device_mount_paths = device.deviceMountPaths();
|
|
||||||
|
|
||||||
// Get free space info
|
|
||||||
if (!ret.device_mount_paths.isEmpty())
|
|
||||||
ret.free_space = Utilities::FileSystemFreeSpace(ret.device_mount_paths[0]);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceKitLister::DBusDeviceAdded(const QDBusObjectPath &path) {
|
|
||||||
|
|
||||||
DeviceData data = ReadDeviceData(path);
|
|
||||||
if (!data.suitable) return;
|
|
||||||
|
|
||||||
{
|
|
||||||
QMutexLocker l(&mutex_);
|
|
||||||
device_data_[data.unique_id()] = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
emit DeviceAdded(data.unique_id());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceKitLister::DBusDeviceRemoved(const QDBusObjectPath &path) {
|
|
||||||
|
|
||||||
QString id;
|
|
||||||
{
|
|
||||||
QMutexLocker l(&mutex_);
|
|
||||||
id = FindUniqueIdByPath(path);
|
|
||||||
if (id.isNull()) return;
|
|
||||||
|
|
||||||
device_data_.remove(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
emit DeviceRemoved(id);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceKitLister::DBusDeviceChanged(const QDBusObjectPath &path) {
|
|
||||||
|
|
||||||
bool already_known = false;
|
|
||||||
{
|
|
||||||
QMutexLocker l(&mutex_);
|
|
||||||
already_known = !FindUniqueIdByPath(path).isNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
DeviceData data = ReadDeviceData(path);
|
|
||||||
|
|
||||||
if (already_known && !data.suitable)
|
|
||||||
DBusDeviceRemoved(path);
|
|
||||||
else if (!already_known && data.suitable)
|
|
||||||
DBusDeviceAdded(path);
|
|
||||||
else if (already_known && data.suitable) {
|
|
||||||
{
|
|
||||||
QMutexLocker l(&mutex_);
|
|
||||||
device_data_[data.unique_id()] = data;
|
|
||||||
}
|
|
||||||
emit DeviceChanged(data.unique_id());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
QString DeviceKitLister::FindUniqueIdByPath(const QDBusObjectPath &path) const {
|
|
||||||
|
|
||||||
for (const DeviceData &data : device_data_) {
|
|
||||||
if (data.dbus_path == path.path()) return data.unique_id();
|
|
||||||
}
|
|
||||||
return QString();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<QUrl> DeviceKitLister::MakeDeviceUrls(const QString &id) {
|
|
||||||
|
|
||||||
QString mount_point = LockAndGetDeviceInfo(id, &DeviceData::device_mount_paths)[0];
|
|
||||||
|
|
||||||
return QList<QUrl>() << MakeUrlFromLocalPath(mount_point);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceKitLister::UnmountDevice(const QString &id) {
|
|
||||||
|
|
||||||
QString path = LockAndGetDeviceInfo(id, &DeviceData::dbus_path);
|
|
||||||
|
|
||||||
OrgFreedesktopUDisksDeviceInterface device(OrgFreedesktopUDisksInterface::staticInterfaceName(), path, QDBusConnection::systemBus());
|
|
||||||
if (!device.isValid()) {
|
|
||||||
qLog(Warning) << "Error connecting to the device interface on" << path;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the device's parent drive
|
|
||||||
QString drive_path = device.partitionSlave().path();
|
|
||||||
OrgFreedesktopUDisksDeviceInterface drive(OrgFreedesktopUDisksInterface::staticInterfaceName(), drive_path, QDBusConnection::systemBus());
|
|
||||||
if (!drive.isValid()) {
|
|
||||||
qLog(Warning) << "Error connecting to the drive interface on" << drive_path;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unmount the filesystem
|
|
||||||
QDBusPendingReply<> reply = device.FilesystemUnmount(QStringList());
|
|
||||||
reply.waitForFinished();
|
|
||||||
|
|
||||||
// Eject the drive
|
|
||||||
drive.DriveEject(QStringList());
|
|
||||||
// Don't bother waiting for the eject to finish
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceKitLister::UpdateDeviceFreeSpace(const QString &id) {
|
|
||||||
|
|
||||||
{
|
|
||||||
QMutexLocker l(&mutex_);
|
|
||||||
if (!device_data_.contains(id)) return;
|
|
||||||
|
|
||||||
DeviceData &data = device_data_[id];
|
|
||||||
if (!data.device_mount_paths.isEmpty())
|
|
||||||
data.free_space = Utilities::FileSystemFreeSpace(data.device_mount_paths[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
emit DeviceChanged(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
/*
|
|
||||||
* Strawberry Music Player
|
|
||||||
* This file was part of Clementine.
|
|
||||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
|
||||||
*
|
|
||||||
* Strawberry 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 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Strawberry 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 General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef DEVICEKITLISTER_H
|
|
||||||
#define DEVICEKITLISTER_H
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#include <QtGlobal>
|
|
||||||
#include <QObject>
|
|
||||||
#include <QMutex>
|
|
||||||
#include <QList>
|
|
||||||
#include <QMap>
|
|
||||||
#include <QString>
|
|
||||||
#include <QStringList>
|
|
||||||
#include <QUrl>
|
|
||||||
#ifdef HAVE_DBUS
|
|
||||||
# include <QDBusObjectPath>
|
|
||||||
#endif
|
|
||||||
#include <QJsonArray>
|
|
||||||
#include <QJsonObject>
|
|
||||||
|
|
||||||
#include "devicelister.h"
|
|
||||||
|
|
||||||
class OrgFreedesktopUDisksInterface;
|
|
||||||
class QDBusObjectPath;
|
|
||||||
|
|
||||||
class DeviceKitLister : public DeviceLister {
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
DeviceKitLister();
|
|
||||||
~DeviceKitLister();
|
|
||||||
|
|
||||||
QStringList DeviceUniqueIDs();
|
|
||||||
QVariantList DeviceIcons(const QString &id);
|
|
||||||
QString DeviceManufacturer(const QString &id);
|
|
||||||
QString DeviceModel(const QString &id);
|
|
||||||
quint64 DeviceCapacity(const QString &id);
|
|
||||||
quint64 DeviceFreeSpace(const QString &id);
|
|
||||||
QVariantMap DeviceHardwareInfo(const QString &id);
|
|
||||||
|
|
||||||
QString MakeFriendlyName(const QString &id);
|
|
||||||
QList<QUrl> MakeDeviceUrls(const QString &id);
|
|
||||||
|
|
||||||
void UnmountDevice(const QString &id);
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void UpdateDeviceFreeSpace(const QString &id);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
bool Init();
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void DBusDeviceAdded(const QDBusObjectPath &path);
|
|
||||||
void DBusDeviceRemoved(const QDBusObjectPath &path);
|
|
||||||
void DBusDeviceChanged(const QDBusObjectPath &path);
|
|
||||||
|
|
||||||
private:
|
|
||||||
struct DeviceData {
|
|
||||||
DeviceData() : suitable(false), device_size(0), free_space(0) {}
|
|
||||||
|
|
||||||
QString unique_id() const;
|
|
||||||
|
|
||||||
bool suitable;
|
|
||||||
QString dbus_path;
|
|
||||||
QString drive_serial;
|
|
||||||
QString drive_model;
|
|
||||||
QString drive_vendor;
|
|
||||||
QString device_file;
|
|
||||||
QString device_presentation_name;
|
|
||||||
QString device_presentation_icon_name;
|
|
||||||
QStringList device_mount_paths;
|
|
||||||
quint64 device_size;
|
|
||||||
quint64 free_space;
|
|
||||||
};
|
|
||||||
|
|
||||||
DeviceData ReadDeviceData(const QDBusObjectPath &path) const;
|
|
||||||
|
|
||||||
// You MUST hold the mutex while calling this function
|
|
||||||
QString FindUniqueIdByPath(const QDBusObjectPath &path) const;
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
T LockAndGetDeviceInfo(const QString &id, T DeviceData::*field);
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::unique_ptr<OrgFreedesktopUDisksInterface> interface_;
|
|
||||||
|
|
||||||
QMutex mutex_;
|
|
||||||
QMap<QString, DeviceData> device_data_;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
T DeviceKitLister::LockAndGetDeviceInfo(const QString &id, T DeviceData::*field) {
|
|
||||||
QMutexLocker l(&mutex_);
|
|
||||||
if (!device_data_.contains(id)) return T();
|
|
||||||
|
|
||||||
return device_data_[id].*field;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // DEVICEKITLISTER_H
|
|
||||||
@@ -66,9 +66,6 @@
|
|||||||
# include "cddadevice.h"
|
# include "cddadevice.h"
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_DBUS
|
#ifdef HAVE_DBUS
|
||||||
# ifdef HAVE_DEVICEKIT
|
|
||||||
# include "devicekitlister.h"
|
|
||||||
# endif
|
|
||||||
# ifdef HAVE_UDISKS2
|
# ifdef HAVE_UDISKS2
|
||||||
# include "udisks2lister.h"
|
# include "udisks2lister.h"
|
||||||
# endif
|
# endif
|
||||||
@@ -121,9 +118,6 @@ DeviceManager::DeviceManager(Application *app, QObject *parent)
|
|||||||
#if defined(HAVE_AUDIOCD) && defined(HAVE_GSTREAMER) && !defined(Q_OS_MACOS)
|
#if defined(HAVE_AUDIOCD) && defined(HAVE_GSTREAMER) && !defined(Q_OS_MACOS)
|
||||||
AddLister(new CddaLister);
|
AddLister(new CddaLister);
|
||||||
#endif
|
#endif
|
||||||
#if defined(HAVE_DBUS) && defined(HAVE_DEVICEKIT)
|
|
||||||
AddLister(new DeviceKitLister);
|
|
||||||
#endif
|
|
||||||
#if defined(HAVE_DBUS) && defined(HAVE_UDISKS2)
|
#if defined(HAVE_DBUS) && defined(HAVE_UDISKS2)
|
||||||
AddLister(new Udisks2Lister);
|
AddLister(new Udisks2Lister);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user