diff --git a/src/solid/devices/backends/fstab/fstabdevice.h b/src/solid/devices/backends/fstab/fstabdevice.h index bf0a81b..6493c90 100644 --- a/src/solid/devices/backends/fstab/fstabdevice.h +++ b/src/solid/devices/backends/fstab/fstabdevice.h @@ -1,76 +1,76 @@ /* SPDX-FileCopyrightText: 2010 Mario Bensi SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef SOLID_BACKENDS_FSTAB_FSTAB_DEVICE_H #define SOLID_BACKENDS_FSTAB_FSTAB_DEVICE_H #include #include #include #include "fstabstorageaccess.h" namespace Solid { namespace Backends { namespace Fstab { class FstabDevice : public Solid::Ifaces::Device { Q_OBJECT public: FstabDevice(QString uid); virtual ~FstabDevice(); QString udi() const override; QString parentUdi() const override; QString vendor() const override; QString product() const override; QString icon() const override; QStringList emblems() const override; QString description() const override; bool queryDeviceInterface(const Solid::DeviceInterface::Type &type) const override; QObject *createDeviceInterface(const Solid::DeviceInterface::Type &type) override; QString device() const; Q_SIGNALS: void mtabChanged(const QString &device); -private Q_SLOTS: +public Q_SLOTS: void onMtabChanged(const QString &device); private: QString m_uid; QString m_device; QString m_product; QString m_vendor; QString m_description; QString m_iconName; QPointer m_storageAccess; enum class StorageType : uint8_t { Other = 0, NetworkShare, Encrypted, }; StorageType m_storageType = StorageType::Other; }; } } } #endif // SOLID_BACKENDS_FSTAB_FSTAB_DEVICE_H diff --git a/src/solid/devices/backends/fstab/fstabmanager.cpp b/src/solid/devices/backends/fstab/fstabmanager.cpp index 645c6c8..47ccb38 100644 --- a/src/solid/devices/backends/fstab/fstabmanager.cpp +++ b/src/solid/devices/backends/fstab/fstabmanager.cpp @@ -1,154 +1,154 @@ /* SPDX-FileCopyrightText: 2010 Mario Bensi SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "fstabmanager.h" #include "fstabdevice.h" #include "fstabhandling.h" #include "../shared/rootdevice.h" #include "fstabservice.h" #include "fstabwatcher.h" using namespace Solid::Backends::Fstab; using namespace Solid::Backends::Shared; FstabManager::FstabManager(QObject *parent) : Solid::Ifaces::DeviceManager(parent) { m_supportedInterfaces << Solid::DeviceInterface::StorageAccess; m_supportedInterfaces << Solid::DeviceInterface::NetworkShare; m_deviceList = FstabHandling::deviceList(); - connect(FstabWatcher::instance(), SIGNAL(fstabChanged()), this, SLOT(onFstabChanged())); - connect(FstabWatcher::instance(), SIGNAL(mtabChanged()), this, SLOT(onMtabChanged())); + connect(FstabWatcher::instance(), &FstabWatcher::fstabChanged, this, &FstabManager::onFstabChanged); + connect(FstabWatcher::instance(), &FstabWatcher::mtabChanged, this, &FstabManager::onMtabChanged); } QString FstabManager::udiPrefix() const { return QString::fromLatin1(FSTAB_UDI_PREFIX); } QSet FstabManager::supportedInterfaces() const { return m_supportedInterfaces; } QStringList FstabManager::allDevices() { QStringList result; result << udiPrefix(); Q_FOREACH (const QString &device, m_deviceList) { result << udiPrefix() + "/" + device; } return result; } QStringList FstabManager::devicesFromQuery(const QString &parentUdi, Solid::DeviceInterface::Type type) { if ((parentUdi == udiPrefix()) || parentUdi.isEmpty()) { QStringList result; if (type == Solid::DeviceInterface::StorageAccess) { for (const QString &device : qAsConst(m_deviceList)) { result << udiPrefix() + "/" + device; } return result; } else if (type == Solid::DeviceInterface::NetworkShare) { for (const QString &device : qAsConst(m_deviceList)) { result << udiPrefix() + "/" + device; } return result; } } else { if (type == Solid::DeviceInterface::StorageAccess || type == Solid::DeviceInterface::NetworkShare) { return QStringList{parentUdi}; } } return QStringList(); } QObject *FstabManager::createDevice(const QString &udi) { if (udi == udiPrefix()) { RootDevice *root = new RootDevice(FSTAB_UDI_PREFIX); root->setProduct(tr("Filesystem Volumes")); root->setDescription(tr("Mountable filesystems declared in your system")); root->setIcon("folder"); return root; } else { // global device manager makes sure udi starts with udi prefix + '/' QString internalName = udi.mid(udiPrefix().length() + 1, -1); if (!m_deviceList.contains(internalName)) { return nullptr; } - QObject *device = new FstabDevice(udi); - connect(this, SIGNAL(mtabChanged(QString)), device, SLOT(onMtabChanged(QString))); + FstabDevice *device = new FstabDevice(udi); + connect(this, &FstabManager::mtabChanged, device, &FstabDevice::onMtabChanged); return device; } } void FstabManager::onFstabChanged() { FstabHandling::flushFstabCache(); _k_updateDeviceList(); } void FstabManager::_k_updateDeviceList() { QStringList deviceList = FstabHandling::deviceList(); #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) QSet newlist = deviceList.toSet(); QSet oldlist = m_deviceList.toSet(); #else QSet newlist(deviceList.begin(), deviceList.end()); QSet oldlist(m_deviceList.begin(), m_deviceList.end()); #endif Q_FOREACH (const QString &device, newlist) { if (!oldlist.contains(device)) { emit deviceAdded(udiPrefix() + "/" + device); } } Q_FOREACH (const QString &device, oldlist) { if (!newlist.contains(device)) { emit deviceRemoved(udiPrefix() + "/" + device); } } m_deviceList = deviceList; Q_FOREACH (const QString &device, newlist) { if (!oldlist.contains(device)) { emit deviceAdded(udiPrefix() + "/" + device); } } } void FstabManager::onMtabChanged() { FstabHandling::flushMtabCache(); _k_updateDeviceList(); // devicelist is union of mtab and fstab Q_FOREACH (const QString &device, m_deviceList) { // notify storageaccess objects via device ... emit mtabChanged(device); } } FstabManager::~FstabManager() { } diff --git a/src/solid/devices/backends/fstab/fstabwatcher.cpp b/src/solid/devices/backends/fstab/fstabwatcher.cpp index ef487fb..91e110d 100644 --- a/src/solid/devices/backends/fstab/fstabwatcher.cpp +++ b/src/solid/devices/backends/fstab/fstabwatcher.cpp @@ -1,103 +1,104 @@ /* SPDX-FileCopyrightText: 2010 Mario Bensi SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "fstabwatcher.h" #include "soliddefs_p.h" #include #include #include #include namespace Solid { namespace Backends { namespace Fstab { Q_GLOBAL_STATIC(FstabWatcher, globalFstabWatcher) static const QString s_mtabFile = QStringLiteral("/etc/mtab"); #ifdef Q_OS_SOLARIS static const QString s_fstabFile = QStringLiteral("/etc/vfstab"); #else static const QString s_fstabFile = QStringLiteral("/etc/fstab"); #endif FstabWatcher::FstabWatcher() : m_isRoutineInstalled(false) , m_fileSystemWatcher(new QFileSystemWatcher(this)) { if (qApp) { - connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(orphanFileSystemWatcher())); + connect(qApp, &QCoreApplication::aboutToQuit, this, &FstabWatcher::orphanFileSystemWatcher); } m_mtabFile = new QFile(s_mtabFile, this); if (m_mtabFile && m_mtabFile->symLinkTarget().startsWith("/proc/") && m_mtabFile->open(QIODevice::ReadOnly)) { m_mtabSocketNotifier = new QSocketNotifier(m_mtabFile->handle(), QSocketNotifier::Exception, this); - connect(m_mtabSocketNotifier, - SIGNAL(activated(int)), this, SIGNAL(mtabChanged())); + connect(m_mtabSocketNotifier, &QSocketNotifier::activated, + this, &FstabWatcher::mtabChanged); } else { m_fileSystemWatcher->addPath(s_mtabFile); } m_fileSystemWatcher->addPath(s_fstabFile); - connect(m_fileSystemWatcher, SIGNAL(fileChanged(QString)), this, SLOT(onFileChanged(QString))); + connect(m_fileSystemWatcher, &QFileSystemWatcher::fileChanged, + this, &FstabWatcher::onFileChanged); } FstabWatcher::~FstabWatcher() { // The QFileSystemWatcher doesn't work correctly in a singleton // The solution so far was to destroy the QFileSystemWatcher when the application quits // But we have some crash with this solution. // For the moment to workaround the problem, we detach the QFileSystemWatcher from the parent // effectively leaking it on purpose. #if 0 //qRemovePostRoutine(globalFstabWatcher.destroy); #else m_fileSystemWatcher->setParent(nullptr); #endif } void FstabWatcher::orphanFileSystemWatcher() { m_fileSystemWatcher->setParent(nullptr); } FstabWatcher *FstabWatcher::instance() { #if 0 FstabWatcher *fstabWatcher = globalFstabWatcher; if (fstabWatcher && !fstabWatcher->m_isRoutineInstalled) { qAddPostRoutine(globalFstabWatcher.destroy); fstabWatcher->m_isRoutineInstalled = true; } return fstabWatcher; #else return globalFstabWatcher; #endif } void FstabWatcher::onFileChanged(const QString &path) { if (path == s_mtabFile) { emit mtabChanged(); if (!m_fileSystemWatcher->files().contains(s_mtabFile)) { m_fileSystemWatcher->addPath(s_mtabFile); } } if (path == s_fstabFile) { emit fstabChanged(); if (!m_fileSystemWatcher->files().contains(s_fstabFile)) { m_fileSystemWatcher->addPath(s_fstabFile); } } } }}} // namespace Solid:Backends::Fstab