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-17 21:56:16 +02:00
|
|
|
#include "udisks2lister.h"
|
|
|
|
|
|
|
|
#include <QDBusConnection>
|
|
|
|
|
|
|
|
#include "core/logging.h"
|
|
|
|
#include "core/utilities.h"
|
2016-05-30 17:24:02 +02:00
|
|
|
#include "dbus/objectmanager.h"
|
2016-05-17 21:56:16 +02:00
|
|
|
#include "dbus/udisks2block.h"
|
|
|
|
#include "dbus/udisks2drive.h"
|
2016-05-31 17:31:00 +02:00
|
|
|
#include "dbus/udisks2filesystem.h"
|
2016-05-22 22:44:22 +02:00
|
|
|
#include "dbus/udisks2job.h"
|
2016-05-17 21:56:16 +02:00
|
|
|
|
2016-05-31 17:19:46 +02:00
|
|
|
constexpr char Udisks2Lister::udisks2_service_[];
|
2016-05-17 21:56:16 +02:00
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
Udisks2Lister::Udisks2Lister() {}
|
2016-05-17 21:56:16 +02:00
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
Udisks2Lister::~Udisks2Lister() {}
|
2016-05-17 21:56:16 +02:00
|
|
|
|
|
|
|
QStringList Udisks2Lister::DeviceUniqueIDs() {
|
|
|
|
QReadLocker locker(&device_data_lock_);
|
|
|
|
return device_data_.keys();
|
|
|
|
}
|
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
QVariantList Udisks2Lister::DeviceIcons(const QString& id) {
|
2016-05-17 21:56:16 +02:00
|
|
|
return QVariantList();
|
|
|
|
}
|
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
QString Udisks2Lister::DeviceManufacturer(const QString& id) {
|
2016-05-17 21:56:16 +02:00
|
|
|
QReadLocker locker(&device_data_lock_);
|
2016-05-31 17:31:00 +02:00
|
|
|
if (!device_data_.contains(id)) return "";
|
2016-05-17 21:56:16 +02:00
|
|
|
return device_data_[id].vendor;
|
|
|
|
}
|
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
QString Udisks2Lister::DeviceModel(const QString& id) {
|
2016-05-17 21:56:16 +02:00
|
|
|
QReadLocker locker(&device_data_lock_);
|
2016-05-31 17:31:00 +02:00
|
|
|
if (!device_data_.contains(id)) return "";
|
2016-05-17 21:56:16 +02:00
|
|
|
return device_data_[id].model;
|
|
|
|
}
|
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
quint64 Udisks2Lister::DeviceCapacity(const QString& id) {
|
2016-05-17 21:56:16 +02:00
|
|
|
QReadLocker locker(&device_data_lock_);
|
2016-05-31 17:31:00 +02:00
|
|
|
if (!device_data_.contains(id)) return 0;
|
2016-05-17 21:56:16 +02:00
|
|
|
return device_data_[id].capacity;
|
|
|
|
}
|
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
quint64 Udisks2Lister::DeviceFreeSpace(const QString& id) {
|
2016-05-17 21:56:16 +02:00
|
|
|
QReadLocker locker(&device_data_lock_);
|
2016-05-31 17:31:00 +02:00
|
|
|
if (!device_data_.contains(id)) return 0;
|
2016-05-17 21:56:16 +02:00
|
|
|
return device_data_[id].free_space;
|
|
|
|
}
|
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
QVariantMap Udisks2Lister::DeviceHardwareInfo(const QString& id) {
|
2016-05-17 21:56:16 +02:00
|
|
|
QReadLocker locker(&device_data_lock_);
|
2016-05-31 17:31:00 +02:00
|
|
|
if (!device_data_.contains(id)) return QVariantMap();
|
2016-05-17 21:56:16 +02:00
|
|
|
|
|
|
|
QVariantMap result;
|
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
const auto& data = device_data_[id];
|
2017-08-28 23:37:47 +02:00
|
|
|
result[QT_TR_NOOP("D-Bus path")] = data.dbus_path;
|
2016-05-17 21:56:16 +02:00
|
|
|
result[QT_TR_NOOP("Serial number")] = data.serial;
|
|
|
|
result[QT_TR_NOOP("Mount points")] = data.mount_paths.join(", ");
|
2016-06-01 12:46:52 +02:00
|
|
|
result[QT_TR_NOOP("Partition label")] = data.label;
|
2016-05-17 21:56:16 +02:00
|
|
|
result[QT_TR_NOOP("UUID")] = data.uuid;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
QString Udisks2Lister::MakeFriendlyName(const QString& id) {
|
2016-05-17 21:56:16 +02:00
|
|
|
QReadLocker locker(&device_data_lock_);
|
2016-05-31 17:31:00 +02:00
|
|
|
if (!device_data_.contains(id)) return "";
|
2016-05-17 21:56:16 +02:00
|
|
|
return device_data_[id].friendly_name;
|
|
|
|
}
|
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
QList<QUrl> Udisks2Lister::MakeDeviceUrls(const QString& id) {
|
2016-05-17 21:56:16 +02:00
|
|
|
QReadLocker locker(&device_data_lock_);
|
2016-05-31 17:31:00 +02:00
|
|
|
if (!device_data_.contains(id)) return QList<QUrl>();
|
|
|
|
return QList<QUrl>() << QUrl::fromLocalFile(
|
|
|
|
device_data_[id].mount_paths.at(0));
|
2016-05-17 21:56:16 +02:00
|
|
|
}
|
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
void Udisks2Lister::UnmountDevice(const QString& id) {
|
2016-05-17 21:56:16 +02:00
|
|
|
QReadLocker locker(&device_data_lock_);
|
2016-05-31 17:31:00 +02:00
|
|
|
if (!device_data_.contains(id)) return;
|
2016-05-17 21:56:16 +02:00
|
|
|
|
|
|
|
OrgFreedesktopUDisks2FilesystemInterface filesystem(
|
2016-05-31 17:31:00 +02:00
|
|
|
udisks2_service_, device_data_[id].dbus_path,
|
|
|
|
QDBusConnection::systemBus());
|
2016-05-17 21:56:16 +02:00
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
if (filesystem.isValid()) {
|
2016-05-31 19:31:39 +02:00
|
|
|
auto unmount_result = filesystem.Unmount(QVariantMap());
|
|
|
|
unmount_result.waitForFinished();
|
2016-05-30 17:24:02 +02:00
|
|
|
|
2016-05-31 19:31:39 +02:00
|
|
|
if (unmount_result.isError()) {
|
2016-05-31 17:31:00 +02:00
|
|
|
qLog(Warning) << "Failed to unmount " << id << ": "
|
2016-05-31 19:31:39 +02:00
|
|
|
<< unmount_result.error();
|
2016-05-30 17:24:02 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-05-17 21:56:16 +02:00
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
OrgFreedesktopUDisks2DriveInterface drive(udisks2_service_,
|
|
|
|
device_data_[id].dbus_drive_path,
|
|
|
|
QDBusConnection::systemBus());
|
2016-05-17 21:56:16 +02:00
|
|
|
|
2016-05-30 17:24:02 +02:00
|
|
|
if (drive.isValid()) {
|
2016-05-31 19:31:39 +02:00
|
|
|
auto eject_result = drive.Eject(QVariantMap());
|
|
|
|
eject_result.waitForFinished();
|
2016-05-30 17:24:02 +02:00
|
|
|
|
2016-05-31 19:31:39 +02:00
|
|
|
if (eject_result.isError())
|
2016-05-31 17:31:00 +02:00
|
|
|
qLog(Warning) << "Failed to eject " << id << ": "
|
2016-05-31 19:31:39 +02:00
|
|
|
<< eject_result.error();
|
2016-05-17 21:56:16 +02:00
|
|
|
}
|
2016-05-30 17:24:02 +02:00
|
|
|
|
|
|
|
device_data_.remove(id);
|
|
|
|
DeviceRemoved(id);
|
2016-05-17 21:56:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
void Udisks2Lister::UpdateDeviceFreeSpace(const QString& id) {
|
2016-05-17 21:56:16 +02:00
|
|
|
QWriteLocker locker(&device_data_lock_);
|
2016-05-31 17:31:00 +02:00
|
|
|
device_data_[id].free_space =
|
|
|
|
Utilities::FileSystemFreeSpace(device_data_[id].mount_paths.at(0));
|
2016-05-17 21:56:16 +02:00
|
|
|
|
|
|
|
emit DeviceChanged(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Udisks2Lister::Init() {
|
|
|
|
udisks2_interface_.reset(new OrgFreedesktopDBusObjectManagerInterface(
|
2016-05-31 17:31:00 +02:00
|
|
|
udisks2_service_, "/org/freedesktop/UDisks2",
|
|
|
|
QDBusConnection::systemBus()));
|
2016-05-17 21:56:16 +02:00
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
QDBusPendingReply<ManagedObjectList> reply =
|
|
|
|
udisks2_interface_->GetManagedObjects();
|
2016-05-17 21:56:16 +02:00
|
|
|
reply.waitForFinished();
|
|
|
|
|
|
|
|
if (!reply.isValid()) {
|
|
|
|
qLog(Warning) << "Error enumerating udisks2 devices:"
|
|
|
|
<< reply.error().name() << reply.error().message();
|
|
|
|
udisks2_interface_.reset();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
for (const QDBusObjectPath& path : reply.value().keys()) {
|
2016-05-31 19:31:39 +02:00
|
|
|
auto partition_data = ReadPartitionData(path);
|
2016-05-17 21:56:16 +02:00
|
|
|
|
2016-05-31 19:31:39 +02:00
|
|
|
if (!partition_data.dbus_path.isEmpty()) {
|
2016-05-17 21:56:16 +02:00
|
|
|
QWriteLocker locker(&device_data_lock_);
|
2016-05-31 19:31:39 +02:00
|
|
|
device_data_[partition_data.unique_id()] = partition_data;
|
2016-05-17 21:56:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
for (const auto& id : device_data_.keys()) {
|
2016-05-17 21:56:16 +02:00
|
|
|
emit DeviceAdded(id);
|
|
|
|
}
|
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
connect(udisks2_interface_.get(),
|
|
|
|
SIGNAL(InterfacesAdded(QDBusObjectPath, InterfacesAndProperties)),
|
2016-05-17 21:56:16 +02:00
|
|
|
SLOT(DBusInterfaceAdded(QDBusObjectPath, InterfacesAndProperties)));
|
2016-05-31 17:31:00 +02:00
|
|
|
connect(udisks2_interface_.get(),
|
|
|
|
SIGNAL(InterfacesRemoved(QDBusObjectPath, QStringList)),
|
2016-05-17 21:56:16 +02:00
|
|
|
SLOT(DBusInterfaceRemoved(QDBusObjectPath, QStringList)));
|
|
|
|
}
|
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
void Udisks2Lister::DBusInterfaceAdded(
|
|
|
|
const QDBusObjectPath& path, const InterfacesAndProperties& interfaces) {
|
|
|
|
for (auto interface = interfaces.constBegin();
|
|
|
|
interface != interfaces.constEnd(); ++interface) {
|
|
|
|
if (interface.key() != "org.freedesktop.UDisks2.Job") continue;
|
2016-05-21 22:29:18 +02:00
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
std::shared_ptr<OrgFreedesktopUDisks2JobInterface> job =
|
|
|
|
std::make_shared<OrgFreedesktopUDisks2JobInterface>(
|
|
|
|
udisks2_service_, path.path(), QDBusConnection::systemBus());
|
2016-05-22 22:44:22 +02:00
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
if (!job->isValid()) continue;
|
2016-05-22 22:44:22 +02:00
|
|
|
|
2016-05-31 17:19:46 +02:00
|
|
|
bool is_mount_job = false;
|
2016-05-31 19:31:39 +02:00
|
|
|
if (job->operation() == "filesystem-mount") {
|
2016-05-31 17:19:46 +02:00
|
|
|
is_mount_job = true;
|
2016-05-31 19:31:39 +02:00
|
|
|
} else if (job->operation() == "filesystem-unmount") {
|
2016-05-31 17:19:46 +02:00
|
|
|
is_mount_job = false;
|
2016-05-31 19:31:39 +02:00
|
|
|
} else {
|
2016-05-17 21:56:16 +02:00
|
|
|
continue;
|
2016-05-31 19:31:39 +02:00
|
|
|
}
|
2016-05-17 21:56:16 +02:00
|
|
|
|
2016-05-31 19:31:39 +02:00
|
|
|
auto mounted_partitions = job->objects();
|
2016-05-17 21:56:16 +02:00
|
|
|
|
2016-05-31 19:31:39 +02:00
|
|
|
if (mounted_partitions.isEmpty()) {
|
2016-05-21 22:29:18 +02:00
|
|
|
qLog(Warning) << "Empty Udisks2 mount/umount job " << path.path();
|
2016-05-22 22:44:22 +02:00
|
|
|
continue;
|
2016-05-21 22:29:18 +02:00
|
|
|
}
|
|
|
|
|
2016-05-17 21:56:16 +02:00
|
|
|
{
|
|
|
|
QMutexLocker locker(&jobs_lock_);
|
2016-05-22 22:44:22 +02:00
|
|
|
qLog(Debug) << "Adding pending job | DBus Path = " << job->path()
|
2016-05-31 17:19:46 +02:00
|
|
|
<< " | IsMountJob = " << is_mount_job
|
2016-05-31 19:31:39 +02:00
|
|
|
<< " | First partition = " << mounted_partitions.at(0).path();
|
2016-05-22 22:44:22 +02:00
|
|
|
mounting_jobs_[path].dbus_interface = job;
|
2016-05-31 17:19:46 +02:00
|
|
|
mounting_jobs_[path].is_mount = is_mount_job;
|
2016-05-31 19:31:39 +02:00
|
|
|
mounting_jobs_[path].mounted_partitions = mounted_partitions;
|
2016-05-22 22:44:22 +02:00
|
|
|
connect(job.get(), SIGNAL(Completed(bool, const QString&)),
|
|
|
|
SLOT(JobCompleted(bool, const QString&)));
|
2016-05-17 21:56:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
void Udisks2Lister::DBusInterfaceRemoved(const QDBusObjectPath& path,
|
|
|
|
const QStringList& ifaces) {
|
|
|
|
if (!isPendingJob(path)) RemoveDevice(path);
|
2016-05-17 21:56:16 +02:00
|
|
|
}
|
|
|
|
|
2016-05-31 19:31:39 +02:00
|
|
|
bool Udisks2Lister::isPendingJob(const QDBusObjectPath& job_path) {
|
2016-05-17 21:56:16 +02:00
|
|
|
QMutexLocker locker(&jobs_lock_);
|
|
|
|
|
2016-05-31 19:31:39 +02:00
|
|
|
if (!mounting_jobs_.contains(job_path)) return false;
|
2016-05-17 21:56:16 +02:00
|
|
|
|
2016-05-31 19:31:39 +02:00
|
|
|
mounting_jobs_.remove(job_path);
|
2016-05-17 21:56:16 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-31 19:31:39 +02:00
|
|
|
void Udisks2Lister::RemoveDevice(const QDBusObjectPath& device_path) {
|
2016-05-17 21:56:16 +02:00
|
|
|
QWriteLocker locker(&device_data_lock_);
|
|
|
|
QString id;
|
2016-05-31 17:31:00 +02:00
|
|
|
for (const auto& data : device_data_) {
|
2016-05-31 19:31:39 +02:00
|
|
|
if (data.dbus_path == device_path.path()) {
|
2016-05-17 21:56:16 +02:00
|
|
|
id = data.unique_id();
|
2016-05-21 22:29:18 +02:00
|
|
|
break;
|
|
|
|
}
|
2016-05-17 21:56:16 +02:00
|
|
|
}
|
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
if (id.isEmpty()) return;
|
2016-05-17 21:56:16 +02:00
|
|
|
|
2016-05-31 19:31:39 +02:00
|
|
|
qLog(Debug) << "UDisks2 device removed: " << device_path.path();
|
2016-05-17 21:56:16 +02:00
|
|
|
device_data_.remove(id);
|
|
|
|
DeviceRemoved(id);
|
|
|
|
}
|
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
QList<QDBusObjectPath> Udisks2Lister::GetMountedPartitionsFromDBusArgument(
|
|
|
|
const QDBusArgument& input) {
|
2016-05-22 22:44:22 +02:00
|
|
|
QList<QDBusObjectPath> result;
|
|
|
|
|
|
|
|
input.beginArray();
|
|
|
|
while (!input.atEnd()) {
|
|
|
|
QDBusObjectPath extractedPath;
|
|
|
|
input >> extractedPath;
|
|
|
|
result.push_back(extractedPath);
|
|
|
|
}
|
|
|
|
input.endArray();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
void Udisks2Lister::JobCompleted(bool success, const QString& message) {
|
2016-05-22 22:44:22 +02:00
|
|
|
auto job = qobject_cast<OrgFreedesktopUDisks2JobInterface*>(sender());
|
|
|
|
QDBusObjectPath jobPath(job->path());
|
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
if (!job->isValid() || !success || !mounting_jobs_.contains(jobPath)) return;
|
2016-05-22 22:44:22 +02:00
|
|
|
|
|
|
|
qLog(Debug) << "Pending Job Completed | Path = " << job->path()
|
2016-05-31 17:19:46 +02:00
|
|
|
<< " | Mount? = " << mounting_jobs_[jobPath].is_mount
|
2016-05-22 22:44:22 +02:00
|
|
|
<< " | Success = " << success;
|
|
|
|
|
2016-05-31 19:31:39 +02:00
|
|
|
for (const auto& mounted_object :
|
|
|
|
mounting_jobs_[jobPath].mounted_partitions) {
|
|
|
|
auto partition_data = ReadPartitionData(mounted_object);
|
|
|
|
if (partition_data.dbus_path.isEmpty()) continue;
|
2016-05-22 22:44:22 +02:00
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
mounting_jobs_[jobPath].is_mount
|
2016-05-31 19:31:39 +02:00
|
|
|
? HandleFinishedMountJob(partition_data)
|
|
|
|
: HandleFinishedUnmountJob(partition_data, mounted_object);
|
2016-05-30 17:24:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
void Udisks2Lister::HandleFinishedMountJob(
|
2016-05-31 19:31:39 +02:00
|
|
|
const Udisks2Lister::PartitionData& partition_data) {
|
2016-05-31 17:31:00 +02:00
|
|
|
qLog(Debug) << "UDisks2 mount job finished: Drive = "
|
2016-05-31 19:31:39 +02:00
|
|
|
<< partition_data.dbus_drive_path
|
|
|
|
<< " | Partition = " << partition_data.dbus_path;
|
2016-05-30 17:24:02 +02:00
|
|
|
QWriteLocker locker(&device_data_lock_);
|
2016-05-31 19:31:39 +02:00
|
|
|
device_data_[partition_data.unique_id()] = partition_data;
|
|
|
|
DeviceAdded(partition_data.unique_id());
|
2016-05-30 17:24:02 +02:00
|
|
|
}
|
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
void Udisks2Lister::HandleFinishedUnmountJob(
|
2016-05-31 19:31:39 +02:00
|
|
|
const Udisks2Lister::PartitionData& partition_data,
|
|
|
|
const QDBusObjectPath& mounted_object) {
|
2016-05-30 17:24:02 +02:00
|
|
|
QWriteLocker locker(&device_data_lock_);
|
|
|
|
QString id;
|
2016-05-31 17:31:00 +02:00
|
|
|
for (auto& data : device_data_) {
|
2016-05-31 19:31:39 +02:00
|
|
|
if (data.mount_paths.contains(mounted_object.path())) {
|
2016-05-31 17:31:00 +02:00
|
|
|
qLog(Debug)
|
|
|
|
<< "UDisks2 umount job finished, found corresponding device: Drive = "
|
|
|
|
<< data.dbus_drive_path << " | Partition = " << data.dbus_path;
|
2016-05-31 19:31:39 +02:00
|
|
|
data.mount_paths.removeOne(mounted_object.path());
|
2016-05-31 17:31:00 +02:00
|
|
|
if (data.mount_paths.empty()) id = data.unique_id();
|
2016-05-30 17:24:02 +02:00
|
|
|
break;
|
2016-05-22 22:44:22 +02:00
|
|
|
}
|
|
|
|
}
|
2016-05-30 17:24:02 +02:00
|
|
|
|
|
|
|
if (!id.isEmpty()) {
|
2016-05-31 19:31:39 +02:00
|
|
|
qLog(Debug) << "Partition " << partition_data.dbus_path
|
2016-05-31 17:31:00 +02:00
|
|
|
<< " has no more mount points, removing it from device list";
|
2016-05-30 17:24:02 +02:00
|
|
|
device_data_.remove(id);
|
|
|
|
DeviceRemoved(id);
|
|
|
|
}
|
2016-05-22 22:44:22 +02:00
|
|
|
}
|
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
Udisks2Lister::PartitionData Udisks2Lister::ReadPartitionData(
|
|
|
|
const QDBusObjectPath& path) {
|
2016-05-17 21:56:16 +02:00
|
|
|
PartitionData result;
|
|
|
|
OrgFreedesktopUDisks2FilesystemInterface filesystem(
|
2016-05-31 17:31:00 +02:00
|
|
|
udisks2_service_, path.path(), QDBusConnection::systemBus());
|
|
|
|
OrgFreedesktopUDisks2BlockInterface block(udisks2_service_, path.path(),
|
|
|
|
QDBusConnection::systemBus());
|
2016-05-17 21:56:16 +02:00
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
if (filesystem.isValid() && block.isValid() &&
|
|
|
|
!filesystem.mountPoints().empty()) {
|
2016-05-17 21:56:16 +02:00
|
|
|
OrgFreedesktopUDisks2DriveInterface drive(
|
2016-05-31 17:31:00 +02:00
|
|
|
udisks2_service_, block.drive().path(), QDBusConnection::systemBus());
|
2016-05-17 21:56:16 +02:00
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
if (drive.isValid() && drive.mediaRemovable()) {
|
2016-05-17 21:56:16 +02:00
|
|
|
result.dbus_path = path.path();
|
|
|
|
result.dbus_drive_path = block.drive().path();
|
|
|
|
|
|
|
|
result.serial = drive.serial();
|
|
|
|
result.vendor = drive.vendor();
|
|
|
|
result.model = drive.model();
|
|
|
|
|
|
|
|
result.label = block.idLabel();
|
|
|
|
result.uuid = block.idUUID();
|
|
|
|
result.capacity = drive.size();
|
|
|
|
|
|
|
|
if (!result.label.isEmpty())
|
|
|
|
result.friendly_name = result.label;
|
|
|
|
else
|
|
|
|
result.friendly_name = result.model + " " + result.uuid;
|
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
for (const auto& path : filesystem.mountPoints())
|
2016-05-17 21:56:16 +02:00
|
|
|
result.mount_paths.push_back(path);
|
|
|
|
|
2016-05-31 17:31:00 +02:00
|
|
|
result.free_space =
|
|
|
|
Utilities::FileSystemFreeSpace(result.mount_paths.at(0));
|
2016-05-17 21:56:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Udisks2Lister::PartitionData::unique_id() const {
|
|
|
|
return QString("Udisks2/%1/%2/%3/%4/%5")
|
|
|
|
.arg(serial, vendor, model)
|
|
|
|
.arg(capacity)
|
|
|
|
.arg(uuid);
|
|
|
|
}
|
2016-07-06 15:26:45 +02:00
|
|
|
|
|
|
|
Udisks2Lister::Udisks2Job::Udisks2Job() : is_mount(true) {}
|
|
|
|
|
|
|
|
Udisks2Lister::PartitionData::PartitionData() : capacity(0), free_space(0) {}
|