Commit 5f315b19 authored by Raine Makelainen's avatar Raine Makelainen

[nemo-storage] Expose drive map from the partition model. Contributes to JB#42943

This can be used e.g. when showing unsupported partitions.
parent bc99cc0b
......@@ -101,9 +101,9 @@ Partition::StorageType Partition::storageType() const
return d ? d->storageType : Invalid;
}
Partition::ConnectionBus Partition::connectionBus() const
QVariantMap Partition::drive() const
{
return d ? d->connectionBus : UnknownBus;
return d ? d->drive : QVariantMap();
}
QString Partition::devicePath() const
......
......@@ -115,7 +115,7 @@ public:
QString cryptoBackingDevicePath() const;
StorageType storageType() const;
ConnectionBus connectionBus() const;
QVariantMap drive() const;
QString devicePath() const;
QString deviceName() const;
......
......@@ -34,6 +34,8 @@
#include "partition.h"
#include <QVariantMap>
class PartitionManagerPrivate;
class PartitionPrivate : public QSharedData
......@@ -45,7 +47,6 @@ public:
, bytesTotal(0)
, bytesFree(0)
, storageType(Partition::Invalid)
, connectionBus(Partition::UnknownBus)
, status(Partition::Unmounted)
, readOnly(true)
, canMount(false)
......@@ -76,8 +77,8 @@ public:
qint64 bytesTotal;
qint64 bytesFree;
Partition::StorageType storageType;
Partition::ConnectionBus connectionBus;
Partition::Status status;
QVariantMap drive;
bool readOnly;
bool canMount;
bool isEncrypted;
......
......@@ -63,17 +63,22 @@ PartitionManagerPrivate::PartitionManagerPrivate()
connect(m_udisksMonitor.data(), &UDisks2::Monitor::unmountError, this, &PartitionManagerPrivate::unmountError);
connect(m_udisksMonitor.data(), &UDisks2::Monitor::formatError, this, &PartitionManagerPrivate::formatError);
QVariantMap defaultDrive;
defaultDrive.insert(QLatin1String("model"), QString());
defaultDrive.insert(QLatin1String("vendor"), QString());
defaultDrive.insert(QLatin1String("connectionBus"), Partition::SDIO);
QExplicitlySharedDataPointer<PartitionPrivate> root(new PartitionPrivate(this));
root->storageType = Partition::System;
root->connectionBus = Partition::SDIO;
root->mountPath = QStringLiteral("/");
root->drive = defaultDrive;
m_partitions.append(root);
QExplicitlySharedDataPointer<PartitionPrivate> home(new PartitionPrivate(this));
home->storageType = Partition::User;
home->connectionBus = Partition::SDIO;
home->mountPath = QStringLiteral("/home");
home->drive = defaultDrive;
m_partitions.append(home);
refresh(m_partitions, m_partitions);
......@@ -153,7 +158,8 @@ void PartitionManagerPrivate::add(QExplicitlySharedDataPointer<PartitionPrivate>
{
int insertIndex = 0;
for (const auto existingPartition : m_partitions) {
if (existingPartition->connectionBus <= partition->connectionBus)
if (existingPartition->drive.value(QLatin1String("connectionBus")).toInt()
<= partition->drive.value(QLatin1String("connectionBus")).toInt())
++insertIndex;
else
break;
......
......@@ -261,7 +261,7 @@ QHash<int, QByteArray> PartitionModel::roleNames() const
{ IsSupportedFileSystemType, "isSupportedFileSystemType"},
{ IsEncryptedRoles, "isEncrypted"},
{ CryptoBackingDevicePath, "cryptoBackingDevicePath"},
{ ConnectionBusRole, "connectionBus"},
{ DriveRole, "drive"},
};
return roleNames;
......@@ -316,8 +316,8 @@ QVariant PartitionModel::data(const QModelIndex &index, int role) const
return partition.isEncrypted();
case CryptoBackingDevicePath:
return partition.cryptoBackingDevicePath();
case ConnectionBusRole:
return partition.connectionBus();
case DriveRole:
return partition.drive();
default:
return QVariant();
}
......
......@@ -66,7 +66,7 @@ public:
IsSupportedFileSystemType,
IsEncryptedRoles,
CryptoBackingDevicePath,
ConnectionBusRole,
DriveRole,
};
// For Status role
......
......@@ -129,6 +129,16 @@ QString UDisks2::Block::drive() const
return value(QStringLiteral("Drive")).toString();
}
QString UDisks2::Block::driveModel() const
{
return NemoDBus::demarshallDBusArgument(m_drive.value(QStringLiteral("Model"))).toString();
}
QString UDisks2::Block::driveVendor() const
{
return NemoDBus::demarshallDBusArgument(m_drive.value(QStringLiteral("Vendor"))).toString();
}
QString UDisks2::Block::connectionBus() const
{
QString bus = NemoDBus::demarshallDBusArgument(m_drive.value(QStringLiteral("ConnectionBus"))).toString();
......
......@@ -57,9 +57,11 @@ public:
QString device() const;
QString preferredDevice() const;
QString drive() const;
QString driveModel() const;
QString driveVendor() const;
QString connectionBus() const;
QString partitionTable() const;
QString partitionTable() const;
bool isPartition() const;
bool isPartitionTable() const;
......
......@@ -331,16 +331,21 @@ void UDisks2::Monitor::setPartitionProperties(QExplicitlySharedDataPointer<Parti
partition->isEncrypted = blockDevice->isEncrypted();
partition->cryptoBackingDevicePath = blockDevice->cryptoBackingDevicePath();
QVariantMap drive;
QString connectionBus = blockDevice->connectionBus();
if (connectionBus == QLatin1String("sdio")) {
partition->connectionBus = Partition::SDIO;
drive.insert(QLatin1String("connectionBus"), Partition::SDIO);
} else if (connectionBus == QLatin1String("usb")) {
partition->connectionBus = Partition::USB;
drive.insert(QLatin1String("connectionBus"), Partition::USB);
} else if (connectionBus == QLatin1String("ieee1394")) {
partition->connectionBus = Partition::IEEE1394;
drive.insert(QLatin1String("connectionBus"), Partition::IEEE1394);
} else {
partition->connectionBus = Partition::UnknownBus;
drive.insert(QLatin1String("connectionBus"), Partition::UnknownBus);
}
drive.insert(QLatin1String("model"), blockDevice->driveModel());
drive.insert(QLatin1String("vendor"), blockDevice->driveVendor());
partition->drive = drive;
}
void UDisks2::Monitor::updatePartitionProperties(const UDisks2::Block *blockDevice)
......
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