2016-05-31 17:31:00 +02:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2016, Valeriy Malov <jazzvoid@gmail.com>
|
|
|
|
|
|
|
|
Clementine 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.
|
|
|
|
|
|
|
|
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-05-31 17:19:46 +02:00
|
|
|
#ifndef UDISKS2LISTER_H
|
|
|
|
#define UDISKS2LISTER_H
|
2016-05-17 21:56:16 +02:00
|
|
|
|
2016-05-31 17:19:46 +02:00
|
|
|
#include <QDBusArgument>
|
2016-05-30 17:24:02 +02:00
|
|
|
#include <QMutex>
|
2016-05-31 17:19:46 +02:00
|
|
|
#include <QReadWriteLock>
|
2016-05-30 17:24:02 +02:00
|
|
|
#include <QStringList>
|
2020-09-18 16:15:19 +02:00
|
|
|
#include <memory>
|
2016-05-17 21:56:16 +02:00
|
|
|
|
2016-05-30 17:24:02 +02:00
|
|
|
#include "dbus/metatypes.h"
|
2016-07-06 15:26:45 +02:00
|
|
|
#include "devicelister.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
|
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
public:
|
2016-05-17 21:56:16 +02:00
|
|
|
Udisks2Lister();
|
|
|
|
~Udisks2Lister();
|
|
|
|
|
2016-05-31 17:19:46 +02:00
|
|
|
QStringList DeviceUniqueIDs() override;
|
2016-05-31 17:31:00 +02:00
|
|
|
QVariantList DeviceIcons(const QString& id) override;
|
|
|
|
QString DeviceManufacturer(const QString& id) override;
|
|
|
|
QString DeviceModel(const QString& id) override;
|
|
|
|
quint64 DeviceCapacity(const QString& id) override;
|
|
|
|
quint64 DeviceFreeSpace(const QString& id) override;
|
|
|
|
QVariantMap DeviceHardwareInfo(const QString& id) override;
|
2016-05-17 21:56:16 +02:00
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
QString MakeFriendlyName(const QString& id) override;
|
|
|
|
QList<QUrl> MakeDeviceUrls(const QString& id) override;
|
2016-05-17 21:56:16 +02:00
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
void UnmountDevice(const QString& id) override;
|
2016-05-17 21:56:16 +02:00
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
public slots:
|
|
|
|
void UpdateDeviceFreeSpace(const QString& id) override;
|
2016-05-17 21:56:16 +02:00
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
protected:
|
2016-05-31 17:19:46 +02:00
|
|
|
void Init() override;
|
2016-05-17 21:56:16 +02:00
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
private slots:
|
|
|
|
void DBusInterfaceAdded(const QDBusObjectPath& path,
|
|
|
|
const InterfacesAndProperties& ifaces);
|
|
|
|
void DBusInterfaceRemoved(const QDBusObjectPath& path,
|
|
|
|
const QStringList& ifaces);
|
|
|
|
void JobCompleted(bool success, const QString& message);
|
2016-05-17 21:56:16 +02:00
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
private:
|
2016-05-31 19:31:39 +02:00
|
|
|
bool isPendingJob(const QDBusObjectPath& job_path);
|
|
|
|
void RemoveDevice(const QDBusObjectPath& device_path);
|
2016-05-31 17:31:00 +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-07-06 15:26:45 +02:00
|
|
|
Udisks2Job();
|
|
|
|
bool is_mount;
|
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
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
private:
|
2016-05-30 17:24:02 +02:00
|
|
|
struct PartitionData {
|
2016-07-06 15:26:45 +02:00
|
|
|
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;
|
2016-07-06 15:26:45 +02:00
|
|
|
quint64 capacity;
|
2016-05-17 21:56:16 +02:00
|
|
|
QString dbus_drive_path;
|
|
|
|
|
2019-08-22 05:43:16 +02:00
|
|
|
// Partition
|
2016-05-17 21:56:16 +02:00
|
|
|
QString label;
|
|
|
|
QString uuid;
|
2016-07-06 15:26:45 +02:00
|
|
|
quint64 free_space;
|
2016-05-17 21:56:16 +02:00
|
|
|
QStringList mount_paths;
|
|
|
|
};
|
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
PartitionData ReadPartitionData(const QDBusObjectPath& path);
|
|
|
|
void HandleFinishedMountJob(
|
2016-05-31 19:31:39 +02:00
|
|
|
const Udisks2Lister::PartitionData& partition_data);
|
2016-05-31 17:31:00 +02:00
|
|
|
void HandleFinishedUnmountJob(
|
2016-05-31 19:31:39 +02:00
|
|
|
const Udisks2Lister::PartitionData& partition_data,
|
|
|
|
const QDBusObjectPath& mounted_object);
|
2016-05-17 21:56:16 +02:00
|
|
|
|
|
|
|
QReadWriteLock device_data_lock_;
|
|
|
|
QMap<QString, PartitionData> device_data_;
|
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
private:
|
2016-05-17 21:56:16 +02:00
|
|
|
std::unique_ptr<OrgFreedesktopDBusObjectManagerInterface> udisks2_interface_;
|
|
|
|
|
2016-05-31 17:19:46 +02:00
|
|
|
static constexpr char udisks2_service_[] = "org.freedesktop.UDisks2";
|
2016-05-17 21:56:16 +02:00
|
|
|
};
|
2016-05-31 17:19:46 +02:00
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
#endif // UDISKS2LISTER_H
|