Commit b9ad8ee9 authored by Raine Makelainen's avatar Raine Makelainen

Merge branch 'jb39820' into 'master'

Adapt to udisks2

See merge request !42
parents 437aa724 e2e35877
......@@ -189,6 +189,11 @@ QString Partition::devicePath() const
return d ? d->devicePath : QString();
}
QString Partition::deviceName() const
{
return d ? d->deviceName : QString();
}
QString Partition::mountPath() const
{
return d ? d->mountPath : QString();
......
......@@ -82,6 +82,7 @@ public:
StorageType storageType() const;
QString devicePath() const;
QString deviceName() const;
QString mountPath() const;
QString filesystemType() const;
......
......@@ -43,7 +43,10 @@
static const auto systemdService = QStringLiteral("org.freedesktop.systemd1");
static const auto systemdPath = QStringLiteral("/org/freedesktop/systemd1");
static const auto managerInterface = QStringLiteral("org.freedesktop.systemd1.Manager");
static const auto sdcardMountPath = QStringLiteral("/media/sdcard/");
static const auto userName = QString(qgetenv("USER"));
static const auto externalMountPath = QString("/run/media/%1/").arg(userName);
static const auto mountServiceName = QString("run-media-%1").arg(userName);
PartitionManagerPrivate *PartitionManagerPrivate::sharedInstance = nullptr;
......@@ -186,7 +189,7 @@ void PartitionManagerPrivate::refresh()
partitionFile.readLine();
static const QRegularExpression whitespace(QStringLiteral("\\s+"));
static const QRegularExpression externalMedia(QStringLiteral("^mmcblk(?!0)\\d+(?:p\\d+$)?"));
static const QRegularExpression externalMedia(QStringLiteral("^mmcblk(?!0)\\d+(?:p\\d+$)?|^sd[a-z](\\d+)$"));
static const QRegularExpression deviceRoot(QStringLiteral("^mmcblk\\d+$"));
while (!partitionFile.atEnd()) {
......@@ -291,7 +294,7 @@ void PartitionManagerPrivate::refresh(const Partitions &partitions, Partitions &
for (auto partition : partitions) {
if ((partition->status == Partition::Mounted || partition->status == Partition::Mounting)
&& (partition->storageType != Partition::External || partition->mountPath.startsWith(sdcardMountPath))) {
&& (partition->storageType != Partition::External || partition->mountPath.startsWith(externalMountPath))) {
continue;
}
......@@ -360,7 +363,7 @@ void PartitionManagerPrivate::refresh(const Partitions &partitions, Partitions &
// Directly probing the device would be better but requires root permissions.
if (char * const uuid = blkid_get_tag_value(
cache, "UUID", partition->devicePath.toUtf8().constData())) {
partition->mountPath = sdcardMountPath + QString::fromUtf8(uuid);
partition->mountPath = externalMountPath + QString::fromUtf8(uuid);
::free(uuid);
}
......@@ -378,7 +381,8 @@ void PartitionManagerPrivate::refresh(const Partitions &partitions, Partitions &
static const QString mountPathFromSystemdService(const QString &serviceName)
{
// Format is like media-sdcard-3630\\x2d3563.mount
// Format is like run-media-<user>-0403\\x2d02011.mount
// run-media-<user>-KINGSTON.mount
QString mountPath = serviceName;
mountPath.replace("-", "/");
......@@ -389,9 +393,11 @@ static const QString mountPathFromSystemdService(const QString &serviceName)
return mountPath.mid(0, mountPath.length() - 6);
}
void PartitionManagerPrivate::newUnit(const QString &serviceName, const QDBusObjectPath &)
void PartitionManagerPrivate::newUnit(const QString &serviceName, const QDBusObjectPath &objectPath)
{
if (!serviceName.startsWith(QStringLiteral("media-sdcard"))) {
Q_UNUSED(objectPath)
if (!serviceName.startsWith(mountServiceName)) {
return;
}
......@@ -399,9 +405,11 @@ void PartitionManagerPrivate::newUnit(const QString &serviceName, const QDBusObj
refresh();
}
void PartitionManagerPrivate::removedUnit(const QString &serviceName, const QDBusObjectPath &)
void PartitionManagerPrivate::removedUnit(const QString &serviceName, const QDBusObjectPath &objectPath)
{
if (!serviceName.startsWith(QStringLiteral("media-sdcard"))) {
Q_UNUSED(objectPath)
if (!serviceName.startsWith(mountServiceName)) {
return;
}
......
......@@ -61,8 +61,8 @@ signals:
void partitionRemoved(const Partition &partition);
private slots:
void newUnit(const QString &serviceName, const QDBusObjectPath &path);
void removedUnit(const QString &serviceName, const QDBusObjectPath &path);
void newUnit(const QString &serviceName, const QDBusObjectPath &objectPath);
void removedUnit(const QString &serviceName, const QDBusObjectPath &objectPath);
private:
static PartitionManagerPrivate *sharedInstance;
......
......@@ -128,6 +128,7 @@ QHash<int, QByteArray> PartitionModel::roleNames() const
{ StorageTypeRole, "storageType" },
{ FilesystemTypeRole, "filesystemType" },
{ DevicePathRole, "devicePath" },
{ DeviceNameRole, "deviceName" },
{ MountPathRole, "mountPath" },
{ BytesAvailableRole, "bytesAvailable" },
{ BytesTotalRole, "bytesTotal" },
......@@ -165,6 +166,8 @@ QVariant PartitionModel::data(const QModelIndex &index, int role) const
return partition.filesystemType();
case DevicePathRole:
return partition.devicePath();
case DeviceNameRole:
return partition.deviceName();
case MountPathRole:
return partition.mountPath();
case BytesAvailableRole:
......@@ -185,7 +188,8 @@ void PartitionModel::partitionChanged(const Partition &partition)
{
for (int i = 0; i < m_partitions.count(); ++i) {
if (m_partitions.at(i) == partition) {
emit dataChanged(createIndex(i, 0), createIndex(i, 0));
QModelIndex index = createIndex(i, 0);
emit dataChanged(index, index);
return;
}
}
......
......@@ -53,6 +53,7 @@ public:
StorageTypeRole,
FilesystemTypeRole,
DevicePathRole,
DeviceNameRole,
MountPathRole,
BytesAvailableRole,
BytesTotalRole,
......
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