7#include "fstabmanager.h"
8#include "../shared/rootdevice.h"
9#include "fstab_debug.h"
10#include "fstabdevice.h"
11#include "fstabhandling.h"
12#include "fstabservice.h"
13#include "fstabwatcher.h"
15using namespace Solid::Backends::Fstab;
16using namespace Solid::Backends::Shared;
18FstabManager::FstabManager(
QObject *parent)
19 : Solid::Ifaces::DeviceManager(parent)
20 , m_deviceList(FstabHandling::deviceList())
22 m_supportedInterfaces << Solid::DeviceInterface::StorageAccess;
23 m_supportedInterfaces << Solid::DeviceInterface::NetworkShare;
25 connect(FstabWatcher::instance(), &FstabWatcher::fstabChanged,
this, &FstabManager::onFstabChanged);
26 connect(FstabWatcher::instance(), &FstabWatcher::mtabChanged,
this, &FstabManager::onMtabChanged);
29QString FstabManager::udiPrefix()
const
31 return QStringLiteral(FSTAB_UDI_PREFIX);
34QSet<Solid::DeviceInterface::Type> FstabManager::supportedInterfaces()
const
36 return m_supportedInterfaces;
39QStringList FstabManager::allDevices()
43 result << udiPrefix();
44 for (
const QString &device : std::as_const(m_deviceList)) {
45 result << udiPrefix() + QStringLiteral(
"/") + device;
53 if ((parentUdi == udiPrefix()) || parentUdi.
isEmpty()) {
55 if (type == Solid::DeviceInterface::StorageAccess) {
56 for (
const QString &device : std::as_const(m_deviceList)) {
57 result << udiPrefix() + QStringLiteral(
"/") + device;
60 }
else if (type == Solid::DeviceInterface::NetworkShare) {
61 for (
const QString &device : std::as_const(m_deviceList)) {
62 result << udiPrefix() + QStringLiteral(
"/") + device;
67 if (type == Solid::DeviceInterface::StorageAccess || type == Solid::DeviceInterface::NetworkShare) {
68 return QStringList{parentUdi};
75QObject *FstabManager::createDevice(
const QString &udi)
77 if (udi == udiPrefix()) {
78 RootDevice *root =
new RootDevice(udi);
80 root->setProduct(
tr(
"Filesystem Volumes"));
81 root->setDescription(
tr(
"Mountable filesystems declared in your system"));
82 root->setIcon(QStringLiteral(
"folder"));
88 QString internalName = udi.
mid(udiPrefix().length() + 1, -1);
89 if (!m_deviceList.contains(internalName)) {
93 FstabDevice *device =
new FstabDevice(udi);
94 connect(
this, &FstabManager::mtabChanged, device, &FstabDevice::onMtabChanged);
99void FstabManager::onFstabChanged()
101 FstabHandling::flushFstabCache();
102 _k_updateDeviceList();
105void FstabManager::_k_updateDeviceList()
107 const QStringList deviceList = FstabHandling::deviceList();
108 const QSet<QString> newlist(deviceList.
begin(), deviceList.
end());
109 const QSet<QString> oldlist(m_deviceList.begin(), m_deviceList.end());
111 m_deviceList = deviceList;
113 qCDebug(FSTAB_LOG) << oldlist <<
"->" << newlist;
115 for (
const QString &device : newlist) {
116 if (!oldlist.contains(device)) {
121 for (
const QString &device : oldlist) {
122 if (!newlist.contains(device)) {
128void FstabManager::onMtabChanged()
130 FstabHandling::flushMtabCache();
132 _k_updateDeviceList();
134 for (
const QString &device : std::as_const(m_deviceList)) {
136 Q_EMIT mtabChanged(device);
140FstabManager::~FstabManager()
144#include "moc_fstabmanager.cpp"
Type
This enum type defines the type of device interface that a Device can have.
void deviceAdded(const QString &udi)
This signal is emitted when a new device appears in the system.
void deviceRemoved(const QString &udi)
This signal is emitted when a device disappears from the system.
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QString tr(const char *sourceText, const char *disambiguation, int n)
bool isEmpty() const const
QString mid(qsizetype position, qsizetype n) const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)