2016-05-17 21:56:16 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
2016-05-30 17:24:02 +02:00
|
|
|
#include <QReadWriteLock>
|
|
|
|
#include <QMutex>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QDBusArgument>
|
2016-05-17 21:56:16 +02:00
|
|
|
|
2016-05-30 17:24:02 +02:00
|
|
|
#include "devicelister.h"
|
|
|
|
#include "dbus/metatypes.h"
|
2016-05-17 21:56:16 +02:00
|
|
|
|
2016-05-30 17:24:02 +02:00
|
|
|
class OrgFreedesktopDBusObjectManagerInterface;
|
2016-05-22 22:44:22 +02:00
|
|
|
class OrgFreedesktopUDisks2JobInterface;
|
|
|
|
|
2016-05-17 21:56:16 +02:00
|
|
|
class Udisks2Lister : public DeviceLister {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
Udisks2Lister();
|
|
|
|
~Udisks2Lister();
|
|
|
|
|
|
|
|
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:
|
|
|
|
void Init();
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void DBusInterfaceAdded(const QDBusObjectPath &path, const InterfacesAndProperties &ifaces);
|
|
|
|
void DBusInterfaceRemoved(const QDBusObjectPath &path, const QStringList &ifaces);
|
2016-05-22 22:44:22 +02:00
|
|
|
void JobCompleted(bool success, const QString &message);
|
2016-05-17 21:56:16 +02:00
|
|
|
|
|
|
|
private:
|
2016-05-21 22:29:18 +02:00
|
|
|
bool isPendingJob(const QDBusObjectPath &jobPath);
|
|
|
|
void RemoveDevice(const QDBusObjectPath &devicePath);
|
2016-05-22 22:44:22 +02:00
|
|
|
QList<QDBusObjectPath> GetMountedPartitionsFromDBusArgument(const QDBusArgument &input);
|
2016-05-21 22:29:18 +02:00
|
|
|
|
2016-05-30 17:24:02 +02:00
|
|
|
struct Udisks2Job {
|
2016-05-21 22:29:18 +02:00
|
|
|
bool isMount = true;
|
2016-05-22 22:44:22 +02:00
|
|
|
QList<QDBusObjectPath> mounted_partitions;
|
|
|
|
std::shared_ptr<OrgFreedesktopUDisks2JobInterface> dbus_interface;
|
2016-05-21 22:29:18 +02:00
|
|
|
};
|
2016-05-17 21:56:16 +02:00
|
|
|
|
|
|
|
QMutex jobs_lock_;
|
2016-05-22 22:44:22 +02:00
|
|
|
QMap<QDBusObjectPath, Udisks2Job> mounting_jobs_;
|
2016-05-17 21:56:16 +02:00
|
|
|
|
|
|
|
private:
|
2016-05-30 17:24:02 +02:00
|
|
|
struct PartitionData {
|
2016-05-17 21:56:16 +02:00
|
|
|
QString unique_id() const;
|
|
|
|
|
|
|
|
QString dbus_path;
|
|
|
|
QString friendly_name;
|
|
|
|
|
|
|
|
// Device
|
|
|
|
QString serial;
|
|
|
|
QString vendor;
|
|
|
|
QString model;
|
|
|
|
quint64 capacity = 0;
|
|
|
|
QString dbus_drive_path;
|
|
|
|
|
|
|
|
// Paritition
|
|
|
|
QString label;
|
|
|
|
QString uuid;
|
|
|
|
quint64 free_space = 0;
|
|
|
|
QStringList mount_paths;
|
|
|
|
};
|
|
|
|
|
2016-05-30 17:24:02 +02:00
|
|
|
PartitionData ReadPartitionData(const QDBusObjectPath &path);
|
|
|
|
void HandleFinishedMountJob(const Udisks2Lister::PartitionData &partitionData);
|
|
|
|
void HandleFinishedUnmountJob(const Udisks2Lister::PartitionData &partitionData, const QDBusObjectPath &mountedObject);
|
2016-05-17 21:56:16 +02:00
|
|
|
|
|
|
|
QReadWriteLock device_data_lock_;
|
|
|
|
QMap<QString, PartitionData> device_data_;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::unique_ptr<OrgFreedesktopDBusObjectManagerInterface> udisks2_interface_;
|
|
|
|
|
|
|
|
static const QString udisks2service_;
|
|
|
|
};
|