7#include "fstabdevice.h"
8#include "fstab_debug.h"
9#include "fstabhandling.h"
10#include "fstabnetworkshare.h"
11#include "fstabservice.h"
12#include <QCoreApplication>
16using namespace Solid::Backends::Fstab;
18FstabDevice::FstabDevice(
QString uid)
22 m_device = m_uid.mid(parentUdi().length() + 1);
24 const QString &fstype = FstabHandling::fstype(m_device);
25 qCDebug(FSTAB_LOG) <<
"Adding " << m_device <<
"type:" << fstype;
28 m_vendor = m_device.mid(2, m_device.indexOf(
QLatin1String(
"/"), 2) - 2);
29 m_product = m_device.mid(m_device.indexOf(
QLatin1String(
"/"), 2) + 1);
30 m_storageType = StorageType::NetworkShare;
32 m_vendor = m_device.left(m_device.indexOf(
QLatin1String(
":/")));
33 m_product = m_device.mid(m_device.indexOf(
QLatin1String(
":/")) + 1);
34 m_storageType = StorageType::NetworkShare;
37 m_product = m_device.
mid(m_device.indexOf(fstype) + fstype.
length());
39 if (m_product.startsWith(home)) {
40 m_product = QStringLiteral(
"~") + m_product.mid(
home.length());
43 m_storageType = StorageType::Encrypted;
45 m_storageType = StorageType::NetworkShare;
49 const auto &options = FstabHandling::options(m_device);
51 const auto gvfsName = options.value(
QLatin1String(
"x-gvfs-name"));
52 if (!gvfsName.isEmpty()) {
55 const auto gvfsIcon = options.value(
QLatin1String(
"x-gvfs-icon"));
56 if (!gvfsIcon.isEmpty()) {
60 if (m_storageType == StorageType::NetworkShare) {
66 if (m_displayName.isEmpty()) {
67 const QStringList currentMountPoints = FstabHandling::currentMountPoints(m_device);
68 if (currentMountPoints.
isEmpty()) {
69 const QStringList mountPoints = FstabHandling::mountPoints(m_device);
70 m_displayName = mountPoints.
isEmpty() ? m_description : mountPoints.
first();
72 m_displayName = currentMountPoints.
first();
76 if (m_iconName.isEmpty()) {
77 if (m_storageType == StorageType::NetworkShare) {
78 m_iconName = QStringLiteral(
"network-server");
79 }
else if (m_storageType == StorageType::Encrypted) {
80 m_iconName = QStringLiteral(
"folder-decrypted");
82 const QStringList &mountPoints = FstabHandling::mountPoints(m_device);
85 m_iconName = QStringLiteral(
"drive-harddisk-root");
86 }
else if (mountPoints.
contains(home)) {
87 m_iconName = QStringLiteral(
"user-home");
89 m_iconName = QStringLiteral(
"folder");
95FstabDevice::~FstabDevice()
104QString FstabDevice::parentUdi()
const
109QString FstabDevice::vendor()
const
114QString FstabDevice::product()
const
119QString FstabDevice::icon()
const
126 if (!m_storageAccess) {
127 FstabDevice *d =
const_cast<FstabDevice *
>(
this);
128 d->m_storageAccess =
new FstabStorageAccess(d);
130 if (m_storageAccess->isAccessible()) {
131 return {QStringLiteral(
"emblem-mounted")};
133 return {QStringLiteral(
"emblem-unmounted")};
137QString FstabDevice::displayName()
const
139 return m_displayName;
142QString FstabDevice::description()
const
144 return m_description;
147bool FstabDevice::isEncrypted()
const
149 return m_storageType == FstabDevice::StorageType::Encrypted;
154 if (interfaceType == Solid::DeviceInterface::StorageAccess) {
157 if ((m_storageType == StorageType::NetworkShare) && (interfaceType == Solid::DeviceInterface::NetworkShare)) {
165 if (interfaceType == Solid::DeviceInterface::StorageAccess) {
166 if (!m_storageAccess) {
167 m_storageAccess =
new FstabStorageAccess(
this);
169 return m_storageAccess;
170 }
else if ((m_storageType == StorageType::NetworkShare) && (interfaceType == Solid::DeviceInterface::NetworkShare)) {
171 return new FstabNetworkShare(
this);
176QString FstabDevice::device()
const
181void FstabDevice::onMtabChanged(
const QString &device)
183 if (m_device == device) {
184 Q_EMIT mtabChanged(device);
188#include "moc_fstabdevice.cpp"
Type
This enum type defines the type of device interface that a Device can have.
This class allows applications to deal with devices available in the underlying system.
QAction * home(const QObject *recvr, const char *slot, QObject *parent)
QString translate(const char *context, const char *sourceText, const char *disambiguation, int n)
bool isEmpty() const const
QString arg(Args &&... args) const const
QString fromLatin1(QByteArrayView str)
qsizetype length() const const
QString mid(qsizetype position, qsizetype n) const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
QString fromPercentEncoding(const QByteArray &input)