diff --git a/src/solid/devices/backends/fstab/fstabdevice.h b/src/solid/devices/backends/fstab/fstabdevice.h --- a/src/solid/devices/backends/fstab/fstabdevice.h +++ b/src/solid/devices/backends/fstab/fstabdevice.h @@ -80,6 +80,7 @@ Other = 0, NetworkShare, Encrypted, + Iso, }; StorageType m_storageType = StorageType::Other; }; diff --git a/src/solid/devices/backends/fstab/fstabdevice.cpp b/src/solid/devices/backends/fstab/fstabdevice.cpp --- a/src/solid/devices/backends/fstab/fstabdevice.cpp +++ b/src/solid/devices/backends/fstab/fstabdevice.cpp @@ -31,6 +31,51 @@ using namespace Solid::Backends::Fstab; +namespace { + +QString UnescapeMtabEntry(const QString& mtabEntry) +{ + QString ret = mtabEntry; + // The following characters are encoded in the mtab file according to the Glibc documentation + ret.replace(QLatin1Literal("\\011"), QLatin1Literal("\t")); + ret.replace(QLatin1Literal("\\012"), QLatin1Literal("\n")); + ret.replace(QLatin1Literal("\\040"), QLatin1Literal(" ")); + ret.replace(QLatin1Literal("\\\\"), QLatin1Literal("\\")); + return ret; +} + +QString ShortenPath(const QString& path) +{ + QString home = QDir::homePath(); + if (path.startsWith(home)) { + return QLatin1Literal("~") + path.mid(home.length()); + } + return path; +} + +QString GetFilePathFromFuseIsoMtabFile(const QString& mountPath) +{ + QFile f(QDir::homePath() + QLatin1Literal("/.mtab.fuseiso")); + if (f.open(QIODevice::ReadOnly)) { + QTextStream ts(&f); + while (!ts.atEnd()) { + QString line = ts.readLine(); + QStringList fields = line.split(QChar(' ')); + if (fields.size() < 2) { + continue; + } + QString isoFilePath = UnescapeMtabEntry(fields.at(0).toLocal8Bit()); + QString mntPath = UnescapeMtabEntry(fields.at(1).toLocal8Bit()); + if (mntPath == mountPath) { + return isoFilePath; + } + } + } + return QString(); +} + +} + FstabDevice::FstabDevice(QString uid) : Solid::Ifaces::Device(), m_uid(uid) @@ -55,14 +100,17 @@ } else if (fstype.startsWith("fuse.") || fstype == QLatin1String("overlay")) { m_vendor = fstype; - m_product = m_device.mid(m_device.indexOf(fstype) + fstype.length()); - QString home = QDir::homePath(); - if (m_product.startsWith(home)) { - m_product = "~" + m_product.mid(home.length()); - } + const QString mountPath = m_device.mid(m_device.indexOf(fstype) + fstype.length()); + m_product = ShortenPath(mountPath); if ((fstype == QLatin1String("fuse.encfs")) || (fstype == QLatin1String("fuse.cryfs"))) { m_storageType = StorageType::Encrypted; + } else if (fstype == QLatin1String("fuse.fuseiso")) { + const QString isoFilePath = GetFilePathFromFuseIsoMtabFile(mountPath); + if (!isoFilePath.isEmpty()) { + m_description = ShortenPath(isoFilePath) + QLatin1String(" on ") + m_product; + } + m_storageType = StorageType::Iso; } } @@ -93,6 +141,8 @@ m_iconName = QLatin1String("network-server"); } else if (m_storageType == StorageType::Encrypted) { m_iconName = QLatin1String("folder-decrypted"); + } else if (m_storageType == StorageType::Iso) { + m_iconName = QLatin1String("media-optical-data"); } else { const QStringList& mountPoints = FstabHandling::mountPoints(m_device); const QString home = QDir::homePath(); diff --git a/src/solid/devices/backends/fstab/fstabhandling.cpp b/src/solid/devices/backends/fstab/fstabhandling.cpp --- a/src/solid/devices/backends/fstab/fstabhandling.cpp +++ b/src/solid/devices/backends/fstab/fstabhandling.cpp @@ -125,7 +125,8 @@ { if (fstype == "fuse.encfs" || fstype == "fuse.cryfs" || - fstype == "overlay") { + fstype == "overlay" || + fstype == "fuse.fuseiso") { return true; } return false;