Commit b8d96da9 authored by Raine Makelainen's avatar Raine Makelainen

Merge branch 'jb43642' into 'master'

Expose drive's connection bus from partition model

See merge request mer-core/nemo-qml-plugin-systemsettings!86
parents 10096674 00ef929d
...@@ -101,6 +101,11 @@ Partition::StorageType Partition::storageType() const ...@@ -101,6 +101,11 @@ Partition::StorageType Partition::storageType() const
return d ? d->storageType : Invalid; return d ? d->storageType : Invalid;
} }
Partition::ConnectionBus Partition::connectionBus() const
{
return d ? d->connectionBus : UnknownBus;
}
QString Partition::devicePath() const QString Partition::devicePath() const
{ {
return d ? d->devicePath : QString(); return d ? d->devicePath : QString();
......
...@@ -56,6 +56,13 @@ public: ...@@ -56,6 +56,13 @@ public:
Any = System | User | Mass | External Any = System | User | Mass | External
}; };
enum ConnectionBus {
SDIO,
USB,
IEEE1394,
UnknownBus
};
enum Status { enum Status {
Unmounted, Unmounted,
Mounting, Mounting,
...@@ -108,6 +115,7 @@ public: ...@@ -108,6 +115,7 @@ public:
QString cryptoBackingDevicePath() const; QString cryptoBackingDevicePath() const;
StorageType storageType() const; StorageType storageType() const;
ConnectionBus connectionBus() const;
QString devicePath() const; QString devicePath() const;
QString deviceName() const; QString deviceName() const;
......
...@@ -45,6 +45,7 @@ public: ...@@ -45,6 +45,7 @@ public:
, bytesTotal(0) , bytesTotal(0)
, bytesFree(0) , bytesFree(0)
, storageType(Partition::Invalid) , storageType(Partition::Invalid)
, connectionBus(Partition::UnknownBus)
, status(Partition::Unmounted) , status(Partition::Unmounted)
, readOnly(true) , readOnly(true)
, canMount(false) , canMount(false)
...@@ -75,6 +76,7 @@ public: ...@@ -75,6 +76,7 @@ public:
qint64 bytesTotal; qint64 bytesTotal;
qint64 bytesFree; qint64 bytesFree;
Partition::StorageType storageType; Partition::StorageType storageType;
Partition::ConnectionBus connectionBus;
Partition::Status status; Partition::Status status;
bool readOnly; bool readOnly;
bool canMount; bool canMount;
......
...@@ -64,12 +64,14 @@ PartitionManagerPrivate::PartitionManagerPrivate() ...@@ -64,12 +64,14 @@ PartitionManagerPrivate::PartitionManagerPrivate()
QExplicitlySharedDataPointer<PartitionPrivate> root(new PartitionPrivate(this)); QExplicitlySharedDataPointer<PartitionPrivate> root(new PartitionPrivate(this));
root->storageType = Partition::System; root->storageType = Partition::System;
root->connectionBus = Partition::SDIO;
root->mountPath = QStringLiteral("/"); root->mountPath = QStringLiteral("/");
m_partitions.append(root); m_partitions.append(root);
QExplicitlySharedDataPointer<PartitionPrivate> home(new PartitionPrivate(this)); QExplicitlySharedDataPointer<PartitionPrivate> home(new PartitionPrivate(this));
home->storageType = Partition::User; home->storageType = Partition::User;
home->connectionBus = Partition::SDIO;
home->mountPath = QStringLiteral("/home"); home->mountPath = QStringLiteral("/home");
m_partitions.append(home); m_partitions.append(home);
...@@ -146,14 +148,20 @@ QVector<Partition> PartitionManagerPrivate::partitions(const Partition::StorageT ...@@ -146,14 +148,20 @@ QVector<Partition> PartitionManagerPrivate::partitions(const Partition::StorageT
return partitions; return partitions;
} }
void PartitionManagerPrivate::add(Partitions &partitions) void PartitionManagerPrivate::add(QExplicitlySharedDataPointer<PartitionPrivate> partition)
{ {
m_partitions.append(partitions); int insertIndex = 0;
refresh(partitions, partitions); for (const auto existingPartition : m_partitions) {
if (existingPartition->connectionBus <= partition->connectionBus)
for (const auto partition : partitions) { ++insertIndex;
emit partitionAdded(Partition(partition)); else
break;
} }
m_partitions.insert(insertIndex, partition);
Partitions addedPartitions = { partition };
refresh(addedPartitions, addedPartitions);
emit partitionAdded(Partition(partition));
} }
void PartitionManagerPrivate::remove(const Partitions &partitions) void PartitionManagerPrivate::remove(const Partitions &partitions)
......
...@@ -59,7 +59,7 @@ public: ...@@ -59,7 +59,7 @@ public:
Partition root() const; Partition root() const;
QVector<Partition> partitions(Partition::StorageTypes types) const; QVector<Partition> partitions(Partition::StorageTypes types) const;
void add(Partitions &partitions); void add(QExplicitlySharedDataPointer<PartitionPrivate> partition);
void remove(const Partitions &partitions); void remove(const Partitions &partitions);
void refresh(); void refresh();
......
...@@ -261,6 +261,7 @@ QHash<int, QByteArray> PartitionModel::roleNames() const ...@@ -261,6 +261,7 @@ QHash<int, QByteArray> PartitionModel::roleNames() const
{ IsSupportedFileSystemType, "isSupportedFileSystemType"}, { IsSupportedFileSystemType, "isSupportedFileSystemType"},
{ IsEncryptedRoles, "isEncrypted"}, { IsEncryptedRoles, "isEncrypted"},
{ CryptoBackingDevicePath, "cryptoBackingDevicePath"}, { CryptoBackingDevicePath, "cryptoBackingDevicePath"},
{ ConnectionBusRole, "connectionBus"},
}; };
return roleNames; return roleNames;
...@@ -315,6 +316,8 @@ QVariant PartitionModel::data(const QModelIndex &index, int role) const ...@@ -315,6 +316,8 @@ QVariant PartitionModel::data(const QModelIndex &index, int role) const
return partition.isEncrypted(); return partition.isEncrypted();
case CryptoBackingDevicePath: case CryptoBackingDevicePath:
return partition.cryptoBackingDevicePath(); return partition.cryptoBackingDevicePath();
case ConnectionBusRole:
return partition.connectionBus();
default: default:
return QVariant(); return QVariant();
} }
......
...@@ -65,7 +65,8 @@ public: ...@@ -65,7 +65,8 @@ public:
IsCryptoDeviceRoles, IsCryptoDeviceRoles,
IsSupportedFileSystemType, IsSupportedFileSystemType,
IsEncryptedRoles, IsEncryptedRoles,
CryptoBackingDevicePath CryptoBackingDevicePath,
ConnectionBusRole,
}; };
// For Status role // For Status role
...@@ -95,6 +96,14 @@ public: ...@@ -95,6 +96,14 @@ public:
Any = Partition::Any Any = Partition::Any
}; };
enum ConnectionBus {
SDIO = Partition::SDIO,
USB = Partition::USB,
IEEE1394 = Partition::IEEE1394,
UnknownBus = Partition::UnknownBus
};
Q_ENUM(ConnectionBus)
enum Error { enum Error {
ErrorFailed = Partition::ErrorFailed, ErrorFailed = Partition::ErrorFailed,
ErrorCancelled = Partition::ErrorCancelled, ErrorCancelled = Partition::ErrorCancelled,
......
...@@ -20,6 +20,7 @@ UDisks2::Block::Block(const QString &path, const UDisks2::InterfacePropertyMap & ...@@ -20,6 +20,7 @@ UDisks2::Block::Block(const QString &path, const UDisks2::InterfacePropertyMap &
, m_pendingFileSystem(nullptr) , m_pendingFileSystem(nullptr)
, m_pendingBlock(nullptr) , m_pendingBlock(nullptr)
, m_pendingEncrypted(nullptr) , m_pendingEncrypted(nullptr)
, m_pendingDrive(nullptr)
{ {
if (!m_connection.connect( if (!m_connection.connect(
UDISKS2_SERVICE, UDISKS2_SERVICE,
...@@ -50,6 +51,7 @@ UDisks2::Block::Block(const QString &path, const UDisks2::InterfacePropertyMap & ...@@ -50,6 +51,7 @@ UDisks2::Block::Block(const QString &path, const UDisks2::InterfacePropertyMap &
QVariantMap blockProperties = NemoDBus::demarshallArgument<QVariantMap>(message.arguments().at(0)); QVariantMap blockProperties = NemoDBus::demarshallArgument<QVariantMap>(message.arguments().at(0));
qCInfo(lcMemoryCardLog) << "Block properties:" << blockProperties; qCInfo(lcMemoryCardLog) << "Block properties:" << blockProperties;
m_data = blockProperties; m_data = blockProperties;
getDriveProperties();
} else { } else {
QDBusError error = watcher->error(); QDBusError error = watcher->error();
qCWarning(lcMemoryCardLog) << "Error reading block properties:" << error.name() << error.message(); qCWarning(lcMemoryCardLog) << "Error reading block properties:" << error.name() << error.message();
...@@ -63,6 +65,7 @@ UDisks2::Block::Block(const QString &path, const UDisks2::InterfacePropertyMap & ...@@ -63,6 +65,7 @@ UDisks2::Block::Block(const QString &path, const UDisks2::InterfacePropertyMap &
QVariantMap map = interfacePropertyMap.value(UDISKS2_FILESYSTEM_INTERFACE); QVariantMap map = interfacePropertyMap.value(UDISKS2_FILESYSTEM_INTERFACE);
updateMountPoint(map); updateMountPoint(map);
} }
getDriveProperties();
// We have either org.freedesktop.UDisks2.Filesystem or org.freedesktop.UDisks2.Encrypted interface. // We have either org.freedesktop.UDisks2.Filesystem or org.freedesktop.UDisks2.Encrypted interface.
complete(); complete();
...@@ -103,6 +106,7 @@ UDisks2::Block &UDisks2::Block::operator=(const UDisks2::Block &other) ...@@ -103,6 +106,7 @@ UDisks2::Block &UDisks2::Block::operator=(const UDisks2::Block &other)
m_interfacePropertyMap = other.m_interfacePropertyMap; m_interfacePropertyMap = other.m_interfacePropertyMap;
m_data = other.m_data; m_data = other.m_data;
m_drive = other.m_drive;
m_mountable = other.m_mountable; m_mountable = other.m_mountable;
m_mountPath = other.m_mountPath; m_mountPath = other.m_mountPath;
m_encrypted = other.m_encrypted; m_encrypted = other.m_encrypted;
...@@ -138,6 +142,25 @@ QString UDisks2::Block::drive() const ...@@ -138,6 +142,25 @@ QString UDisks2::Block::drive() const
return value(QStringLiteral("Drive")).toString(); return value(QStringLiteral("Drive")).toString();
} }
QString UDisks2::Block::connectionBus() const
{
QString bus = NemoDBus::demarshallDBusArgument(m_drive.value(QStringLiteral("ConnectionBus"))).toString();
// Do a bit of guesswork as we're missing connection between unlocked crypto block to crypto backing block device
// from where we could see the drive where this block belongs to.
if (bus != QLatin1String("/") && hasCryptoBackingDevice()) {
QString cryptoBackingPath = cryptoBackingDevicePath();
if (cryptoBackingPath.contains(QLatin1String("mmcblk"))) {
return QStringLiteral("sdio");
} else if (cryptoBackingPath.startsWith(QLatin1String("/dev/sd"))) {
return QStringLiteral("usb");
}
return QStringLiteral("ieee1394");
}
return bus;
}
qint64 UDisks2::Block::deviceNumber() const qint64 UDisks2::Block::deviceNumber() const
{ {
return value(QStringLiteral("DeviceNumber")).toLongLong(); return value(QStringLiteral("DeviceNumber")).toLongLong();
...@@ -153,6 +176,11 @@ qint64 UDisks2::Block::size() const ...@@ -153,6 +176,11 @@ qint64 UDisks2::Block::size() const
return value(QStringLiteral("Size")).toLongLong(); return value(QStringLiteral("Size")).toLongLong();
} }
bool UDisks2::Block::isCryptoBlock() const
{
return isEncrypted() || hasCryptoBackingDevice();
}
bool UDisks2::Block::hasCryptoBackingDevice() const bool UDisks2::Block::hasCryptoBackingDevice() const
{ {
const QString cryptoBackingDev = cryptoBackingDeviceObjectPath(); const QString cryptoBackingDev = cryptoBackingDeviceObjectPath();
...@@ -274,7 +302,7 @@ bool UDisks2::Block::hasData() const ...@@ -274,7 +302,7 @@ bool UDisks2::Block::hasData() const
void UDisks2::Block::dumpInfo() const void UDisks2::Block::dumpInfo() const
{ {
qCInfo(lcMemoryCardLog) << "Block device:" << device() << "Preferred device:" << preferredDevice(); qCInfo(lcMemoryCardLog) << "Block device:" << device() << "Preferred device:" << preferredDevice();
qCInfo(lcMemoryCardLog) << "- drive:" << drive() << "dNumber:" << deviceNumber(); qCInfo(lcMemoryCardLog) << "- drive:" << drive() << "device number:" << deviceNumber() << "connection bus:" << connectionBus();
qCInfo(lcMemoryCardLog) << "- id:" << id() << "size:" << size(); qCInfo(lcMemoryCardLog) << "- id:" << id() << "size:" << size();
qCInfo(lcMemoryCardLog) << "- isreadonly:" << isReadOnly() << "idtype:" << idType(); qCInfo(lcMemoryCardLog) << "- isreadonly:" << isReadOnly() << "idtype:" << idType();
qCInfo(lcMemoryCardLog) << "- idversion:" << idVersion() << "idlabel:" << idLabel(); qCInfo(lcMemoryCardLog) << "- idversion:" << idVersion() << "idlabel:" << idLabel();
...@@ -313,7 +341,7 @@ void UDisks2::Block::updateProperties(const QDBusMessage &message) ...@@ -313,7 +341,7 @@ void UDisks2::Block::updateProperties(const QDBusMessage &message)
bool UDisks2::Block::isCompleted() const bool UDisks2::Block::isCompleted() const
{ {
return !m_pendingFileSystem && !m_pendingBlock && !m_pendingEncrypted; return !m_pendingFileSystem && !m_pendingBlock && !m_pendingEncrypted && !m_pendingDrive;
} }
void UDisks2::Block::updateMountPoint(const QVariant &mountPoints) void UDisks2::Block::updateMountPoint(const QVariant &mountPoints)
...@@ -403,3 +431,30 @@ void UDisks2::Block::getEncryptedInterface() ...@@ -403,3 +431,30 @@ void UDisks2::Block::getEncryptedInterface()
complete(); complete();
}); });
} }
void UDisks2::Block::getDriveProperties()
{
QDBusInterface drivePropertyInterface(UDISKS2_SERVICE,
drive(),
DBUS_OBJECT_PROPERTIES_INTERFACE,
m_connection);
QDBusPendingCall pendingCall = drivePropertyInterface.asyncCall(DBUS_GET_ALL, UDISKS2_DRIVE_INTERFACE);
m_pendingDrive = new QDBusPendingCallWatcher(pendingCall, this);
connect(m_pendingDrive, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *watcher) {
if (watcher->isValid() && watcher->isFinished()) {
QDBusPendingReply<> reply = *watcher;
QDBusMessage message = reply.reply();
QVariantMap driveProperties = NemoDBus::demarshallArgument<QVariantMap>(message.arguments().at(0));
qCInfo(lcMemoryCardLog) << "Drive properties:" << driveProperties;
m_drive = driveProperties;
} else {
QDBusError error = watcher->error();
qCWarning(lcMemoryCardLog) << "Error reading drive properties:" << error.name() << error.message();
m_drive.clear();
}
m_pendingDrive->deleteLater();
m_pendingDrive = nullptr;
complete();
});
}
...@@ -45,6 +45,7 @@ namespace UDisks2 { ...@@ -45,6 +45,7 @@ namespace UDisks2 {
class Block : public QObject class Block : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString connectionBus READ connectionBus NOTIFY updated)
public: public:
Block(const QString &path, const UDisks2::InterfacePropertyMap &interfacePropertyMap, QObject *parent = nullptr); Block(const QString &path, const UDisks2::InterfacePropertyMap &interfacePropertyMap, QObject *parent = nullptr);
...@@ -57,12 +58,15 @@ public: ...@@ -57,12 +58,15 @@ public:
QString device() const; QString device() const;
QString preferredDevice() const; QString preferredDevice() const;
QString drive() const; QString drive() const;
QString connectionBus() const;
qint64 deviceNumber() const; qint64 deviceNumber() const;
QString id() const; QString id() const;
qint64 size() const; qint64 size() const;
bool isCryptoBlock() const;
bool hasCryptoBackingDevice() const; bool hasCryptoBackingDevice() const;
QString cryptoBackingDevicePath() const; QString cryptoBackingDevicePath() const;
QString cryptoBackingDeviceObjectPath() const; QString cryptoBackingDeviceObjectPath() const;
...@@ -114,10 +118,12 @@ private: ...@@ -114,10 +118,12 @@ private:
void getFileSystemInterface(); void getFileSystemInterface();
void getEncryptedInterface(); void getEncryptedInterface();
void getDriveProperties();
QString m_path; QString m_path;
UDisks2::InterfacePropertyMap m_interfacePropertyMap; UDisks2::InterfacePropertyMap m_interfacePropertyMap;
QVariantMap m_data; QVariantMap m_data;
QVariantMap m_drive;
QDBusConnection m_connection; QDBusConnection m_connection;
QString m_mountPath; QString m_mountPath;
bool m_mountable; bool m_mountable;
...@@ -128,6 +134,7 @@ private: ...@@ -128,6 +134,7 @@ private:
QDBusPendingCallWatcher *m_pendingFileSystem; QDBusPendingCallWatcher *m_pendingFileSystem;
QDBusPendingCallWatcher *m_pendingBlock; QDBusPendingCallWatcher *m_pendingBlock;
QDBusPendingCallWatcher *m_pendingEncrypted; QDBusPendingCallWatcher *m_pendingEncrypted;
QDBusPendingCallWatcher *m_pendingDrive;
}; };
} }
......
...@@ -335,9 +335,20 @@ void UDisks2::Monitor::setPartitionProperties(QExplicitlySharedDataPointer<Parti ...@@ -335,9 +335,20 @@ void UDisks2::Monitor::setPartitionProperties(QExplicitlySharedDataPointer<Parti
} else { } else {
partition->status = Partition::Mounted; partition->status = Partition::Mounted;
} }
partition->isCryptoDevice = blockDevice->isEncrypted() || blockDevice->hasCryptoBackingDevice(); partition->isCryptoDevice = blockDevice->isCryptoBlock();
partition->isEncrypted = blockDevice->isEncrypted(); partition->isEncrypted = blockDevice->isEncrypted();
partition->cryptoBackingDevicePath = blockDevice->cryptoBackingDevicePath(); partition->cryptoBackingDevicePath = blockDevice->cryptoBackingDevicePath();
QString connectionBus = blockDevice->connectionBus();
if (connectionBus == QLatin1String("sdio")) {
partition->connectionBus = Partition::SDIO;
} else if (connectionBus == QLatin1String("usb")) {
partition->connectionBus = Partition::USB;
} else if (connectionBus == QLatin1String("ieee1394")) {
partition->connectionBus = Partition::IEEE1394;
} else {
partition->connectionBus = Partition::UnknownBus;
}
} }
void UDisks2::Monitor::updatePartitionProperties(const UDisks2::Block *blockDevice) void UDisks2::Monitor::updatePartitionProperties(const UDisks2::Block *blockDevice)
...@@ -603,8 +614,7 @@ void UDisks2::Monitor::createPartition(const UDisks2::Block *block) ...@@ -603,8 +614,7 @@ void UDisks2::Monitor::createPartition(const UDisks2::Block *block)
partition->bytesTotal = block->size(); partition->bytesTotal = block->size();
setPartitionProperties(partition, block); setPartitionProperties(partition, block);
partition->valid = true; partition->valid = true;
PartitionManagerPrivate::Partitions addedPartitions = { partition }; m_manager->add(partition);
m_manager->add(addedPartitions);
} }
UDisks2::Block *UDisks2::Monitor::createBlockDevice(const QString &dbusObjectPath, const UDisks2::InterfacePropertyMap &interfacePropertyMap) UDisks2::Block *UDisks2::Monitor::createBlockDevice(const QString &dbusObjectPath, const UDisks2::InterfacePropertyMap &interfacePropertyMap)
...@@ -673,8 +683,7 @@ UDisks2::Block *UDisks2::Monitor::createBlockDevice(const QString &dbusObjectPat ...@@ -673,8 +683,7 @@ UDisks2::Block *UDisks2::Monitor::createBlockDevice(const QString &dbusObjectPat
connect(block, &UDisks2::Block::formatted, this, [this]() { connect(block, &UDisks2::Block::formatted, this, [this]() {
UDisks2::Block *block = qobject_cast<UDisks2::Block *>(sender()); UDisks2::Block *block = qobject_cast<UDisks2::Block *>(sender());
QString blockPath = block->path(); if (m_blockDevices.contains(block->path())) {
if (m_blockDevices.contains(blockPath)) {
for (auto partition : m_manager->m_partitions) { for (auto partition : m_manager->m_partitions) {
if (partition->devicePath == block->device()) { if (partition->devicePath == block->device()) {
partition->status = Partition::Formatted; partition->status = Partition::Formatted;
...@@ -689,8 +698,7 @@ UDisks2::Block *UDisks2::Monitor::createBlockDevice(const QString &dbusObjectPat ...@@ -689,8 +698,7 @@ UDisks2::Block *UDisks2::Monitor::createBlockDevice(const QString &dbusObjectPat
// When block info updated // When block info updated
connect(block, &UDisks2::Block::updated, this, [this]() { connect(block, &UDisks2::Block::updated, this, [this]() {
UDisks2::Block *block = qobject_cast<UDisks2::Block *>(sender()); UDisks2::Block *block = qobject_cast<UDisks2::Block *>(sender());
QString blockPath = block->path(); if (m_blockDevices.contains(block->path())) {
if (m_blockDevices.contains(blockPath)) {
updatePartitionProperties(block); updatePartitionProperties(block);
} }
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment