From 8899a3c36970d5b399cb819dc2b4e9d270aa8975 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Tue, 17 May 2022 21:40:19 +0300 Subject: [PATCH] solid: replace fstab with exports backend to NFS or not to NFS: https://ibb.co/Tt8kLGJ side note: fstab backend mount point detection was broken for NFS shares, probably for SMB shares too Signed-off-by: Ivailo Monev --- solid/solid/CMakeLists.txt | 11 +- .../solid/backends/exports/exportsdevice.cpp | 222 ++++++++++++++++++ solid/solid/backends/exports/exportsdevice.h | 69 ++++++ .../exportsdeviceinterface.cpp} | 18 +- .../exportsdeviceinterface.h} | 46 ++-- .../solid/backends/exports/exportsmanager.cpp | 137 +++++++++++ .../exportsmanager.h} | 42 ++-- .../backends/exports/exportsnetworkshare.cpp | 44 ++++ .../exportsnetworkshare.h} | 45 ++-- .../backends/exports/exportsstorageaccess.cpp | 105 +++++++++ .../backends/exports/exportsstorageaccess.h | 59 +++++ solid/solid/backends/fstab/fstabdevice.cpp | 128 ---------- solid/solid/backends/fstab/fstabdevice.h | 83 ------- solid/solid/backends/fstab/fstabhandling.cpp | 157 ------------- solid/solid/backends/fstab/fstabhandling.h | 74 ------ solid/solid/backends/fstab/fstabmanager.cpp | 148 ------------ .../backends/fstab/fstabnetworkshare.cpp | 64 ----- .../backends/fstab/fstabstorageaccess.cpp | 129 ---------- .../solid/backends/fstab/fstabstorageaccess.h | 86 ------- solid/solid/backends/fstab/fstabwatcher.cpp | 88 ------- solid/solid/managerbase.cpp | 4 +- 21 files changed, 705 insertions(+), 1054 deletions(-) create mode 100644 solid/solid/backends/exports/exportsdevice.cpp create mode 100644 solid/solid/backends/exports/exportsdevice.h rename solid/solid/backends/{fstab/fstabservice.h => exports/exportsdeviceinterface.cpp} (72%) rename solid/solid/backends/{fstab/fstabnetworkshare.h => exports/exportsdeviceinterface.h} (50%) create mode 100644 solid/solid/backends/exports/exportsmanager.cpp rename solid/solid/backends/{fstab/fstabmanager.h => exports/exportsmanager.h} (62%) create mode 100644 solid/solid/backends/exports/exportsnetworkshare.cpp rename solid/solid/backends/{fstab/fstabwatcher.h => exports/exportsnetworkshare.h} (55%) create mode 100644 solid/solid/backends/exports/exportsstorageaccess.cpp create mode 100644 solid/solid/backends/exports/exportsstorageaccess.h delete mode 100644 solid/solid/backends/fstab/fstabdevice.cpp delete mode 100644 solid/solid/backends/fstab/fstabdevice.h delete mode 100644 solid/solid/backends/fstab/fstabhandling.cpp delete mode 100644 solid/solid/backends/fstab/fstabhandling.h delete mode 100644 solid/solid/backends/fstab/fstabmanager.cpp delete mode 100644 solid/solid/backends/fstab/fstabnetworkshare.cpp delete mode 100644 solid/solid/backends/fstab/fstabstorageaccess.cpp delete mode 100644 solid/solid/backends/fstab/fstabstorageaccess.h delete mode 100644 solid/solid/backends/fstab/fstabwatcher.cpp diff --git a/solid/solid/CMakeLists.txt b/solid/solid/CMakeLists.txt index cb77ce54..10a70c19 100644 --- a/solid/solid/CMakeLists.txt +++ b/solid/solid/CMakeLists.txt @@ -67,12 +67,11 @@ set(solid_LIB_SRCS ifaces/graphic.cpp backends/shared/rootdevice.cpp - backends/fstab/fstabmanager.cpp - backends/fstab/fstabdevice.cpp - backends/fstab/fstabnetworkshare.cpp - backends/fstab/fstabstorageaccess.cpp - backends/fstab/fstabhandling.cpp - backends/fstab/fstabwatcher.cpp + backends/exports/exportsdevice.cpp + backends/exports/exportsdeviceinterface.cpp + backends/exports/exportsmanager.cpp + backends/exports/exportsnetworkshare.cpp + backends/exports/exportsstorageaccess.cpp ) configure_file( diff --git a/solid/solid/backends/exports/exportsdevice.cpp b/solid/solid/backends/exports/exportsdevice.cpp new file mode 100644 index 00000000..01c840aa --- /dev/null +++ b/solid/solid/backends/exports/exportsdevice.cpp @@ -0,0 +1,222 @@ +/* + Copyright 2022 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#include "exportsmanager.h" +#include "exportsdevice.h" +#include "exportsnetworkshare.h" +#include "exportsstorageaccess.h" + +#include +#include +#include + +using namespace Solid::Backends::Exports; + +static inline QString dehex(const QString &hexstring) +{ + const QByteArray devicehex = hexstring.toLatin1(); + if (devicehex.size() < 17) { + return QString(); + } + return QString::fromLocal8Bit(QByteArray::fromHex(devicehex.constData() + 17)); +} + +static inline QString normalizedAddress(const QByteArray &exportaddress) +{ + QByteArray normalized = exportaddress; + const int bracketindex = normalized.indexOf('('); + if (bracketindex > 0) { + normalized = normalized.left(bracketindex); + } + const int slashindex = normalized.indexOf('/'); + if (slashindex > 0) { + normalized = normalized.left(slashindex); + } + return QString::fromLatin1(normalized.constData(), normalized.size()); +} + +ExportsDevice::ExportsDevice(const QString &device) + : Solid::Ifaces::Device() + , m_device(device) + , m_dir(dehex(m_device)) +{ + // qDebug() << Q_FUNC_INFO << m_device; + foreach (const QString &exportsfilepath, ExportsDevice::exportsFiles()) { + QFile exportsfile(exportsfilepath); + if (!exportsfile.open(QFile::ReadOnly)) { + continue; + } + while (!exportsfile.atEnd()) { + const QByteArray exportsline = exportsfile.readLine().trimmed(); + const QList exportparts = ExportsDevice::exportParts(exportsline); + if (exportparts.size() < 2) { + continue; + } + const QByteArray exportdir = exportparts.at(0); + // qDebug() << Q_FUNC_INFO << m_device << m_dir; + if (exportdir == m_dir) { + m_address = normalizedAddress(exportparts.at(1)); + } + } + } +} + +ExportsDevice::~ExportsDevice() +{ +} + +QString ExportsDevice::udi() const +{ + return m_device; +} + +QString ExportsDevice::parentUdi() const +{ + if (m_device == EXPORTS_ROOT_UDI) { + // root0 + return QString(); + } + return QString(EXPORTS_ROOT_UDI); +} + +QString ExportsDevice::vendor() const +{ + return m_dir; +} + +QString ExportsDevice::product() const +{ + if (m_device == EXPORTS_ROOT_UDI) { + return QString::fromLatin1("Devices"); + } else if(queryDeviceInterface(Solid::DeviceInterface::NetworkShare)) { + return m_address; + } + + return QString(); +} + +QString ExportsDevice::icon() const +{ + if (m_device == EXPORTS_ROOT_UDI) { + return QString::fromLatin1("computer"); + } else if (queryDeviceInterface(Solid::DeviceInterface::NetworkShare)) { + return QString::fromLatin1("network-server"); + } + return QString(); +} + +QStringList ExportsDevice::emblems() const +{ + QStringList result; + if (queryDeviceInterface(Solid::DeviceInterface::StorageAccess)) { + const StorageAccess accessIface(const_cast(this)); + if (accessIface.isAccessible()) { + result << QString::fromLatin1("emblem-mounted"); + } else { + result << QString::fromLatin1("emblem-unmounted"); + } + } + return result; +} + +QString ExportsDevice::description() const +{ + if (m_device == EXPORTS_ROOT_UDI || parentUdi().isEmpty()) { + return QObject::tr("Computer"); + } else if (queryDeviceInterface(Solid::DeviceInterface::NetworkShare)) { + return QString::fromLatin1("%1 on %2").arg(QDir(m_dir).dirName()).arg(m_address); + } + return QString(); +} + +bool ExportsDevice::queryDeviceInterface(const Solid::DeviceInterface::Type &type) const +{ + switch (type) { + case Solid::DeviceInterface::NetworkShare: + case Solid::DeviceInterface::StorageAccess: { + return true; + } + default: { + return false; + } + } + Q_UNREACHABLE(); +} + +QObject *ExportsDevice::createDeviceInterface(const Solid::DeviceInterface::Type &type) +{ + if (!queryDeviceInterface(type)) { + return nullptr; + } + switch (type) { + case Solid::DeviceInterface::NetworkShare: { + return new NetworkShare(this); + } + case Solid::DeviceInterface::StorageAccess: { + return new StorageAccess(this); + } + default: { + Q_ASSERT(false); + return nullptr; + } + } + Q_UNREACHABLE(); +} + +// for reference: +// https://linux.die.net/man/8/exportfs +QStringList ExportsDevice::exportsFiles() +{ + QStringList result; + result.append(QString::fromLatin1("/etc/exports")); + QDir exportsdir(QString::fromLatin1("/etc/exports.d")); + foreach (const QFileInfo &exportsinfo, exportsdir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot)) { + if (!exportsinfo.isFile()) { + continue; + } + const QString exportsfilepath = exportsinfo.filePath(); + if (!exportsfilepath.endsWith(QLatin1String(".exports"))) { + continue; + } + result.append(exportsfilepath); + } + return result; +} + +QList ExportsDevice::exportParts(const QByteArray &exportline) +{ + QList result; + if (exportline.isEmpty() || exportline.startsWith('#')) { + return result; + } + int partstart = 0; + for (int i = 0; i < exportline.size(); i++) { + if (exportline.at(i) == ' ' || exportline.at(i) == '\t') { + // qDebug() << Q_FUNC_INFO << i << partstart; + result.append(exportline.mid(partstart, i - partstart)); + partstart = i + 1; + } + if (partstart && i == (exportline.size() - 1)) { + result.append(exportline.mid(partstart, i - partstart + 1)); + } + } + // qDebug() << Q_FUNC_INFO << result; + return result; +} \ No newline at end of file diff --git a/solid/solid/backends/exports/exportsdevice.h b/solid/solid/backends/exports/exportsdevice.h new file mode 100644 index 00000000..55c63456 --- /dev/null +++ b/solid/solid/backends/exports/exportsdevice.h @@ -0,0 +1,69 @@ +/* + Copyright 2022 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#ifndef SOLID_BACKENDS_EXPORTS_EXPORTSDEVICE_H +#define SOLID_BACKENDS_EXPORTS_EXPORTSDEVICE_H + +#include +#include + +#include "kdevicedatabase.h" + +namespace Solid +{ +namespace Backends +{ +namespace Exports +{ + +class ExportsDevice : public Solid::Ifaces::Device +{ + Q_OBJECT + +public: + ExportsDevice(const QString &device); + virtual ~ExportsDevice(); + + virtual QString udi() const; + virtual QString parentUdi() const; + virtual QString vendor() const; + virtual QString product() const; + virtual QString icon() const; + virtual QStringList emblems() const; + virtual QString description() const; + virtual bool queryDeviceInterface(const Solid::DeviceInterface::Type &type) const; + virtual QObject *createDeviceInterface(const Solid::DeviceInterface::Type &type); + + QString exportDir() const { return m_dir; } + QString exportAddress() const { return m_address; } + + static QStringList exportsFiles(); + static QList exportParts(const QByteArray &exportline); + +private: + QString m_device; + QString m_dir; + QString m_address; +}; + +} +} +} +#endif // SOLID_BACKENDS_EXPORTS_EXPORTSDEVICE_H diff --git a/solid/solid/backends/fstab/fstabservice.h b/solid/solid/backends/exports/exportsdeviceinterface.cpp similarity index 72% rename from solid/solid/backends/fstab/fstabservice.h rename to solid/solid/backends/exports/exportsdeviceinterface.cpp index 5be03e8b..33aed6b0 100644 --- a/solid/solid/backends/fstab/fstabservice.h +++ b/solid/solid/backends/exports/exportsdeviceinterface.cpp @@ -1,5 +1,5 @@ /* - Copyright 2010 Mario Bensi + Copyright 2022 Ivailo Monev This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -18,11 +18,17 @@ License along with this library. If not, see . */ -#ifndef SOLID_BACKENDS_FSTAB_SERVICE_H -#define SOLID_BACKENDS_FSTAB_SERVICE_H +#include "exportsdeviceinterface.h" -/* FStab */ -#define FSTAB_UDI_PREFIX "/org/kde/fstab" +using namespace Solid::Backends::Exports; -#endif // SOLID_BACKENDS_FSTAB_H +DeviceInterface::DeviceInterface(ExportsDevice *device) + : QObject(device), m_device(device) +{ +} +DeviceInterface::~DeviceInterface() +{ +} + +#include "backends/exports/moc_exportsdeviceinterface.cpp" diff --git a/solid/solid/backends/fstab/fstabnetworkshare.h b/solid/solid/backends/exports/exportsdeviceinterface.h similarity index 50% rename from solid/solid/backends/fstab/fstabnetworkshare.h rename to solid/solid/backends/exports/exportsdeviceinterface.h index 20193948..c86260d5 100644 --- a/solid/solid/backends/fstab/fstabnetworkshare.h +++ b/solid/solid/backends/exports/exportsdeviceinterface.h @@ -1,5 +1,5 @@ /* - Copyright 2011 Mario Bensi + Copyright 2022 Ivailo Monev This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -18,10 +18,11 @@ License along with this library. If not, see . */ -#ifndef SOLID_BACKENDS_FSTAB_NETWORKSHARE_H -#define SOLID_BACKENDS_FSTAB_NETWORKSHARE_H +#ifndef SOLID_BACKENDS_EXPORTS_DEVICEINTERFACE_H +#define SOLID_BACKENDS_EXPORTS_DEVICEINTERFACE_H -#include +#include +#include "exportsdevice.h" #include @@ -29,34 +30,21 @@ namespace Solid { namespace Backends { -namespace Fstab +namespace Exports { - class FstabDevice; - class FstabNetworkShare : public QObject, public Solid::Ifaces::NetworkShare - { - Q_OBJECT - Q_INTERFACES(Solid::Ifaces::NetworkShare) - - public: - explicit FstabNetworkShare(Solid::Backends::Fstab::FstabDevice *device); - - virtual ~FstabNetworkShare(); - - virtual Solid::NetworkShare::ShareType type() const; - - virtual QUrl url() const; - - public: - const Solid::Backends::Fstab::FstabDevice* fstabDevice() const; - - private: - Solid::Backends::Fstab::FstabDevice *m_fstabDevice; - Solid::NetworkShare::ShareType m_type; - QUrl m_url; - }; +class DeviceInterface : public QObject, virtual public Solid::Ifaces::DeviceInterface +{ + Q_OBJECT + Q_INTERFACES(Solid::Ifaces::DeviceInterface) +public: + DeviceInterface(ExportsDevice *device); + virtual ~DeviceInterface(); +protected: + ExportsDevice *m_device; +}; } } } -#endif // SOLID_BACKENDS_FSTAB_NETWORKSHARE_H +#endif // SOLID_BACKENDS_EXPORTS_DEVICEINTERFACE_H diff --git a/solid/solid/backends/exports/exportsmanager.cpp b/solid/solid/backends/exports/exportsmanager.cpp new file mode 100644 index 00000000..98382141 --- /dev/null +++ b/solid/solid/backends/exports/exportsmanager.cpp @@ -0,0 +1,137 @@ +/* + Copyright 2022 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#include "exportsmanager.h" +#include "exportsdevice.h" + +#include +#include +#include + +using namespace Solid::Backends::Exports; + +class ExportsManager::Private +{ +public: + Private(ExportsManager *parent); + ~Private(); + + QSet m_supportedInterfaces; +}; + +ExportsManager::Private::Private(ExportsManager *parent) +{ +} + +ExportsManager::Private::~Private() +{ +} + +ExportsManager::ExportsManager(QObject *parent) + : Solid::Ifaces::DeviceManager(parent), + d(new Private(this)) +{ + // TODO: monitor /etc/exports and /etc/exports.d to emit: + // deviceAdded(udi) + // deviceRemoved(udi); + // deviceChanged() does not apply for network share devices + + d->m_supportedInterfaces + << Solid::DeviceInterface::NetworkShare + << Solid::DeviceInterface::StorageAccess; +} + +ExportsManager::~ExportsManager() +{ + delete d; +} + +QString ExportsManager::udiPrefix() const +{ + return QString(EXPORTS_UDI_PREFIX); +} + +QSet ExportsManager::supportedInterfaces() const +{ + return d->m_supportedInterfaces; +} + +QStringList ExportsManager::allDevices() +{ + QStringList result; + foreach (const QString &exportsfilepath, ExportsDevice::exportsFiles()) { + QFile exportsfile(exportsfilepath); + if (!exportsfile.open(QFile::ReadOnly)) { + continue; + } + while (!exportsfile.atEnd()) { + const QByteArray exportsline = exportsfile.readLine().trimmed(); + const QList exportparts = ExportsDevice::exportParts(exportsline); + if (exportparts.size() < 1) { + continue; + } + const QByteArray devudihex = exportparts.at(0).toHex(); + const QString devudi = QString::fromLatin1("%1/%2").arg(EXPORTS_UDI_PREFIX, devudihex.constData()); + result.append(devudi); + } + } + return result; +} + +QStringList ExportsManager::devicesFromQuery(const QString &parentUdi, + Solid::DeviceInterface::Type type) +{ + QStringList allDev = allDevices(); + QStringList result; + + if (!parentUdi.isEmpty()) { + foreach (const QString &udi, allDev) { + ExportsDevice device(udi); + if (device.queryDeviceInterface(type) && device.parentUdi() == parentUdi) { + result << udi; + } + } + return result; + } else if (type != Solid::DeviceInterface::Unknown) { + foreach (const QString &udi, allDev) { + ExportsDevice device(udi); + if (device.queryDeviceInterface(type)) { + result << udi; + } + } + return result; + } else { + return allDev; + } +} + +QObject *ExportsManager::createDevice(const QString &udi) +{ + if (udi == udiPrefix()) { + return new ExportsDevice(EXPORTS_ROOT_UDI); + } + + if (!udi.isEmpty()) { + return new ExportsDevice(udi); + } + + qWarning() << "cannot create device for UDI" << udi; + return 0; +} diff --git a/solid/solid/backends/fstab/fstabmanager.h b/solid/solid/backends/exports/exportsmanager.h similarity index 62% rename from solid/solid/backends/fstab/fstabmanager.h rename to solid/solid/backends/exports/exportsmanager.h index 81e176b9..118dc19a 100644 --- a/solid/solid/backends/fstab/fstabmanager.h +++ b/solid/solid/backends/exports/exportsmanager.h @@ -1,5 +1,5 @@ /* - Copyright 2010 Mario Bensi + Copyright 2022 Ivailo Monev This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -18,51 +18,41 @@ License along with this library. If not, see . */ -#ifndef SOLID_BACKENDS_FSTAB_FSTABMANAGER_H -#define SOLID_BACKENDS_FSTAB_FSTABMANAGER_H +#ifndef SOLID_BACKENDS_EXPORTS_EXPORTSMANAGER_H +#define SOLID_BACKENDS_EXPORTS_EXPORTSMANAGER_H + +#define EXPORTS_ROOT_UDI "/org/kde/exports/root0" +#define EXPORTS_UDI_PREFIX "/org/kde/exports" #include -#include -#include -#include namespace Solid { namespace Backends { -namespace Fstab +namespace Exports { -class AbstractDeviceFactory; - -class FstabManager : public Solid::Ifaces::DeviceManager +class ExportsManager : public Solid::Ifaces::DeviceManager { Q_OBJECT public: - explicit FstabManager(QObject *parent); - virtual ~FstabManager(); + ExportsManager(QObject *parent); + virtual ~ExportsManager(); - virtual QString udiPrefix() const ; + virtual QString udiPrefix() const; virtual QSet supportedInterfaces() const; virtual QStringList allDevices(); - virtual QStringList devicesFromQuery(const QString &parentUdi, Solid::DeviceInterface::Type type); + virtual QStringList devicesFromQuery(const QString &parentUdi, + Solid::DeviceInterface::Type type); virtual QObject *createDevice(const QString &udi); -Q_SIGNALS: - void mtabChanged(const QString& device); - -private Q_SLOTS: - void onFstabChanged(); - void onMtabChanged(); - private: - QSet m_supportedInterfaces; - QStringList m_deviceList; - void _k_updateDeviceList(); + class Private; + Private *const d; }; - } } } -#endif +#endif // SOLID_BACKENDS_EXPORTS_EXPORTSMANAGER_H diff --git a/solid/solid/backends/exports/exportsnetworkshare.cpp b/solid/solid/backends/exports/exportsnetworkshare.cpp new file mode 100644 index 00000000..9579b8c5 --- /dev/null +++ b/solid/solid/backends/exports/exportsnetworkshare.cpp @@ -0,0 +1,44 @@ +/* + Copyright 2022 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#include "exportsnetworkshare.h" +#include "exportsdevice.h" + +#include + +using namespace Solid::Backends::Exports; + +NetworkShare::NetworkShare(ExportsDevice *device) + : DeviceInterface(device) +{ +} + +Solid::NetworkShare::ShareType NetworkShare::type() const +{ + // the only type this backend supports + return Solid::NetworkShare::Nfs; +} + +QUrl NetworkShare::url() const +{ + return QUrl(m_device->exportAddress()); +} + +#include "backends/exports/moc_exportsnetworkshare.cpp" diff --git a/solid/solid/backends/fstab/fstabwatcher.h b/solid/solid/backends/exports/exportsnetworkshare.h similarity index 55% rename from solid/solid/backends/fstab/fstabwatcher.h rename to solid/solid/backends/exports/exportsnetworkshare.h index 7d03d1ea..1dd1c90e 100644 --- a/solid/solid/backends/fstab/fstabwatcher.h +++ b/solid/solid/backends/exports/exportsnetworkshare.h @@ -1,5 +1,5 @@ /* - Copyright 2010 Mario Bensi + Copyright 2022 Ivailo Monev This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -18,44 +18,33 @@ License along with this library. If not, see . */ -#ifndef SOLID_BACKENDS_FSTAB_WATCHER_H -#define SOLID_BACKENDS_FSTAB_WATCHER_H +#ifndef SOLID_BACKENDS_EXPORTS_NETWORKSHARE_H +#define SOLID_BACKENDS_EXPORTS_NETWORKSHARE_H -#include - -#include -#include -#include +#include +#include "exportsdeviceinterface.h" namespace Solid { namespace Backends { -namespace Fstab +namespace Exports { +class ExportsDevice; - class FstabWatcher : public QObject { - Q_OBJECT - public: - FstabWatcher(); - virtual ~FstabWatcher(); +class NetworkShare : public DeviceInterface, virtual public Solid::Ifaces::NetworkShare +{ + Q_OBJECT + Q_INTERFACES(Solid::Ifaces::NetworkShare) - static FstabWatcher *instance(); +public: + NetworkShare(ExportsDevice *device); - Q_SIGNALS: - void mtabChanged(); - void fstabChanged(); - - private Q_SLOTS: - void onFileChanged(const QString &path); - - private: - QFileSystemWatcher *m_fileSystemWatcher; - QSocketNotifier *m_mtabSocketNotifier; - QFile *m_mtabFile; - }; + virtual Solid::NetworkShare::ShareType type() const; + virtual QUrl url() const; +}; } } } -#endif // SOLID_BACKENDS_FSTAB_WATCHER_H +#endif // SOLID_BACKENDS_EXPORTS_NETWORKSHARE_H diff --git a/solid/solid/backends/exports/exportsstorageaccess.cpp b/solid/solid/backends/exports/exportsstorageaccess.cpp new file mode 100644 index 00000000..ed3bcf70 --- /dev/null +++ b/solid/solid/backends/exports/exportsstorageaccess.cpp @@ -0,0 +1,105 @@ +/* + Copyright 2022 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#include "exportsstorageaccess.h" +#include "kmountpoint.h" + +#include +#include +#include + +using namespace Solid::Backends::Exports; + +StorageAccess::StorageAccess(ExportsDevice *device) + : DeviceInterface(device) +{ +} + +StorageAccess::~StorageAccess() +{ +} + +bool StorageAccess::isAccessible() const +{ + return !filePath().isEmpty(); +} + +QString StorageAccess::filePath() const +{ + const KMountPoint::List mountpoints = KMountPoint::currentMountPoints(); + + const QString exportdir(m_device->exportDir()); + const QString exportdirandaddress = QString::fromLatin1("%1:%2").arg(m_device->exportAddress()).arg(m_device->exportDir()); + foreach (const KMountPoint::Ptr mountpoint, mountpoints) { + // qDebug() << Q_FUNC_INFO << mountpoint->mountedFrom() << mountpoint->realDeviceName() << mountpoint->mountPoint() << exportdir; + if (mountpoint->mountedFrom() == exportdir || mountpoint->mountedFrom() == exportdirandaddress) { + return mountpoint->mountPoint(); + } + } + + return QString(); +} + +bool StorageAccess::isIgnored() const +{ + return false; +} + +bool StorageAccess::setup() +{ + const QString mountpoint = filePath(); + if (!mountpoint.isEmpty()) { + return true; + } + + emit setupRequested(m_device->udi()); + + QDBusInterface soliduiserver("org.kde.kded", "/modules/soliduiserver", "org.kde.SolidUiServer"); + QDBusReply reply = soliduiserver.call("mountDevice", m_device->udi()); + + const Solid::ErrorType replyvalue = static_cast(reply.value()); + if (replyvalue == Solid::NoError) { + emit accessibilityChanged(true, m_device->udi()); + } + + emit setupDone(replyvalue, Solid::errorString(replyvalue), m_device->udi()); + return (replyvalue == Solid::NoError); +} + +bool StorageAccess::teardown() +{ + const QString mountpoint = filePath(); + if (mountpoint.isEmpty()) { + return false; + } + + emit teardownRequested(m_device->udi()); + + QDBusInterface soliduiserver("org.kde.kded", "/modules/soliduiserver", "org.kde.SolidUiServer"); + QDBusReply reply = soliduiserver.call("unmountDevice", m_device->udi()); + + const Solid::ErrorType replyvalue = static_cast(reply.value()); + if (replyvalue == Solid::NoError) { + emit accessibilityChanged(false, m_device->udi()); + } + + emit teardownDone(replyvalue, Solid::errorString(replyvalue), m_device->udi()); + return (replyvalue == Solid::NoError); +} diff --git a/solid/solid/backends/exports/exportsstorageaccess.h b/solid/solid/backends/exports/exportsstorageaccess.h new file mode 100644 index 00000000..2a47f1bf --- /dev/null +++ b/solid/solid/backends/exports/exportsstorageaccess.h @@ -0,0 +1,59 @@ +/* + Copyright 2022 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#ifndef SOLID_BACKENDS_EXPORTS_STORAGEACCESS_H +#define SOLID_BACKENDS_EXPORTS_STORAGEACCESS_H + +#include +#include "exportsdeviceinterface.h" + +namespace Solid +{ +namespace Backends +{ +namespace Exports +{ +class StorageAccess : public DeviceInterface, virtual public Solid::Ifaces::StorageAccess +{ + Q_OBJECT + Q_INTERFACES(Solid::Ifaces::StorageAccess) + +public: + explicit StorageAccess(ExportsDevice *device); + virtual ~StorageAccess(); + + virtual bool isAccessible() const; + virtual QString filePath() const; + virtual bool isIgnored() const; + virtual bool setup(); + virtual bool teardown(); + +Q_SIGNALS: + void accessibilityChanged(bool accessible, const QString &udi); + void setupDone(Solid::ErrorType error, QVariant data, const QString &udi); + void teardownDone(Solid::ErrorType error, QVariant data, const QString &udi); + void setupRequested(const QString &udi); + void teardownRequested(const QString &udi); +}; +} +} +} + +#endif // SOLID_BACKENDS_EXPORTS_STORAGEACCESS_H diff --git a/solid/solid/backends/fstab/fstabdevice.cpp b/solid/solid/backends/fstab/fstabdevice.cpp deleted file mode 100644 index 0c91c6ac..00000000 --- a/solid/solid/backends/fstab/fstabdevice.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - Copyright 2010 Mario Bensi - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) version 3, or any - later version accepted by the membership of KDE e.V. (or its - successor approved by the membership of KDE e.V.), which shall - act as a proxy defined in Section 6 of version 3 of the license. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library. If not, see . -*/ - -#include "fstabdevice.h" -#include "fstabhandling.h" -#include "fstabnetworkshare.h" -#include "fstabstorageaccess.h" -#include "fstabservice.h" -#include - -using namespace Solid::Backends::Fstab; - -FstabDevice::FstabDevice(QString uid) : - Solid::Ifaces::Device(), - m_uid(uid) -{ - m_device = m_uid; - m_device.remove(parentUdi() + "/"); - - if (m_device.startsWith("//")) { - m_product = m_device.mid(2, m_device.indexOf("/", 2) - 2); - m_vendor = m_device.mid(m_device.indexOf("/", 2) + 1); - } else { - m_product = m_device.left(m_device.indexOf(":/")); - m_vendor = m_device.mid(m_device.indexOf(":/") + 1); - } - - m_description = m_vendor + " on " + m_product; -} - -FstabDevice::~FstabDevice() -{ -} - -QString FstabDevice::udi() const -{ - return m_uid; -} - -QString FstabDevice::parentUdi() const -{ - return QString::fromLatin1(FSTAB_UDI_PREFIX); -} - -QString FstabDevice::vendor() const -{ - return m_vendor; -} - -QString FstabDevice::product() const -{ - return m_product; -} - -QString FstabDevice::icon() const -{ - return QString::fromLatin1("network-server"); -} - -QStringList FstabDevice::emblems() const -{ - QStringList res; - if (!m_storageAccess) { - FstabDevice* d = const_cast(this); - d->m_storageAccess = new FstabStorageAccess(d); - } - if (m_storageAccess->isAccessible()) { - res << "emblem-mounted"; - } else { - res << "emblem-unmounted"; - } - - return res; -} - -QString FstabDevice::description() const -{ - return m_description; -} - -bool FstabDevice::queryDeviceInterface(const Solid::DeviceInterface::Type &type) const -{ - if (type == Solid::DeviceInterface::StorageAccess - || type == Solid::DeviceInterface::NetworkShare) { - return true; - } - return false; -} - -QObject* FstabDevice::createDeviceInterface(const Solid::DeviceInterface::Type &type) -{ - if (type == Solid::DeviceInterface::StorageAccess) { - if (!m_storageAccess) - m_storageAccess = new FstabStorageAccess(this); - return m_storageAccess; - } else if (type == Solid::DeviceInterface::NetworkShare) { - return new FstabNetworkShare(this); - } - return 0; -} - -QString FstabDevice::device() const -{ - return m_device; -} - -void FstabDevice::onMtabChanged(const QString& device) -{ - if (m_device == device) - emit mtabChanged(device); -} diff --git a/solid/solid/backends/fstab/fstabdevice.h b/solid/solid/backends/fstab/fstabdevice.h deleted file mode 100644 index 846fd766..00000000 --- a/solid/solid/backends/fstab/fstabdevice.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - Copyright 2010 Mario Bensi - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) version 3, or any - later version accepted by the membership of KDE e.V. (or its - successor approved by the membership of KDE e.V.), which shall - act as a proxy defined in Section 6 of version 3 of the license. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library. If not, see . -*/ - -#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(); - - virtual QString udi() const; - - virtual QString parentUdi() const; - - virtual QString vendor() const; - - virtual QString product() const; - - virtual QString icon() const; - - virtual QStringList emblems() const; - - virtual QString description() const; - - virtual bool queryDeviceInterface(const Solid::DeviceInterface::Type &type) const; - - virtual QObject *createDeviceInterface(const Solid::DeviceInterface::Type &type); - - QString device() const; - - Q_SIGNALS: - void mtabChanged(const QString& device); - - private Q_SLOTS: - void onMtabChanged(const QString& device); - - private: - QString m_uid; - QString m_device; - QString m_product; - QString m_vendor; - QString m_description; - QPointer m_storageAccess; - }; - -} -} -} -#endif // SOLID_BACKENDS_FSTAB_FSTAB_DEVICE_H diff --git a/solid/solid/backends/fstab/fstabhandling.cpp b/solid/solid/backends/fstab/fstabhandling.cpp deleted file mode 100644 index f868ca7d..00000000 --- a/solid/solid/backends/fstab/fstabhandling.cpp +++ /dev/null @@ -1,157 +0,0 @@ -/* - Copyright 2006-2010 Kevin Ottens - Copyright 2010 Mario Bensi - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) version 3, or any - later version accepted by the membership of KDE e.V. (or its - successor approved by the membership of KDE e.V.), which shall - act as a proxy defined in Section 6 of version 3 of the license. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library. If not, see . -*/ - -#include "fstabhandling.h" - -#include -#include -#include -#include -#include -#include - -#include - -#include - -Q_GLOBAL_STATIC(Solid::Backends::Fstab::FstabHandling, globalFstabCache) - -Solid::Backends::Fstab::FstabHandling::FstabHandling() - : m_fstabCacheValid(false), - m_mtabCacheValid(false) -{ } - -bool _k_isFstabNetworkFileSystem(const QString &fstype, const QString &devName) -{ - if (fstype == "nfs" - || fstype == "nfs4" - || fstype == "smbfs" - || fstype == "cifs" - || devName.startsWith(QLatin1String("//"))) { - return true; - } - return false; -} - -void Solid::Backends::Fstab::FstabHandling::_k_updateFstabMountPointsCache() -{ - if (globalFstabCache()->m_fstabCacheValid) - return; - - globalFstabCache()->m_fstabCache.clear(); - - const KMountPoint::List mountpoints = KMountPoint::possibleMountPoints(); - foreach (const KMountPoint::Ptr mountpoint, mountpoints) { - const QString device = mountpoint->mountedFrom(); - if (_k_isFstabNetworkFileSystem(mountpoint->mountType(), device)) { - globalFstabCache()->m_fstabCache.insert(device, mountpoint->mountPoint()); - } - } - - globalFstabCache()->m_fstabCacheValid = true; -} - -QStringList Solid::Backends::Fstab::FstabHandling::deviceList() -{ - _k_updateFstabMountPointsCache(); - _k_updateMtabMountPointsCache(); - - QStringList devices = globalFstabCache()->m_fstabCache.keys(); - devices += globalFstabCache()->m_mtabCache.keys(); - devices.removeDuplicates(); - return devices; -} - -QStringList Solid::Backends::Fstab::FstabHandling::mountPoints(const QString &device) -{ - _k_updateFstabMountPointsCache(); - _k_updateMtabMountPointsCache(); - - QStringList mountpoints = globalFstabCache()->m_fstabCache.values(device); - mountpoints += globalFstabCache()->m_mtabCache.values(device); - mountpoints.removeDuplicates(); - return mountpoints; -} - -QProcess *Solid::Backends::Fstab::FstabHandling::callSystemCommand(const QString &commandName, - const QStringList &args, - QObject *obj, const char *slot) -{ - QString commandExe = KStandardDirs::findRootExe(commandName); - if (commandExe.isEmpty()) { - return 0; - } - - QProcess *process = new QProcess(obj); - - QObject::connect(process, SIGNAL(finished(int,QProcess::ExitStatus)), - obj, slot); - - process->start(commandExe, args); - - if (process->waitForStarted()) { - return process; - } else { - delete process; - return 0; - } -} - -QProcess *Solid::Backends::Fstab::FstabHandling::callSystemCommand(const QString &commandName, - const QString &device, - QObject *obj, const char *slot) -{ - return callSystemCommand(commandName, QStringList() << device, obj, slot); -} - -void Solid::Backends::Fstab::FstabHandling::_k_updateMtabMountPointsCache() -{ - if (globalFstabCache()->m_mtabCacheValid) - return; - - globalFstabCache()->m_mtabCache.clear(); - - const KMountPoint::List mountpoints = KMountPoint::currentMountPoints(); - foreach (const KMountPoint::Ptr mountpoint, mountpoints) { - const QString device = mountpoint->mountedFrom(); - if (_k_isFstabNetworkFileSystem(mountpoint->mountType(), QString())) { - globalFstabCache()->m_fstabCache.insert(device, mountpoint->mountPoint()); - } - } - - globalFstabCache()->m_mtabCacheValid = true; -} - -QStringList Solid::Backends::Fstab::FstabHandling::currentMountPoints(const QString &device) -{ - _k_updateMtabMountPointsCache(); - return globalFstabCache()->m_mtabCache.values(device); -} - -void Solid::Backends::Fstab::FstabHandling::flushMtabCache() -{ - globalFstabCache()->m_mtabCacheValid = false; -} - -void Solid::Backends::Fstab::FstabHandling::flushFstabCache() -{ - globalFstabCache()->m_fstabCacheValid = false; -} diff --git a/solid/solid/backends/fstab/fstabhandling.h b/solid/solid/backends/fstab/fstabhandling.h deleted file mode 100644 index 22304a66..00000000 --- a/solid/solid/backends/fstab/fstabhandling.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - Copyright 2006-2010 Kevin Ottens - Copyright 2010 Mario Bensi - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) version 3, or any - later version accepted by the membership of KDE e.V. (or its - successor approved by the membership of KDE e.V.), which shall - act as a proxy defined in Section 6 of version 3 of the license. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library. If not, see . -*/ - -#ifndef SOLID_BACKENDS_FSTAB_FSTABHANDLING_H -#define SOLID_BACKENDS_FSTAB_FSTABHANDLING_H - -#include -#include - -#include -#include - -namespace Solid -{ -namespace Backends -{ -namespace Fstab -{ - -class FstabHandling -{ -public: - FstabHandling(); - - static QStringList deviceList(); - static QStringList currentMountPoints(const QString &device); - static QStringList mountPoints(const QString &device); - static QProcess *callSystemCommand(const QString &commandName, - const QStringList &args, - QObject *obj, const char *slot); - static QProcess *callSystemCommand(const QString &commandName, - const QString &device, - QObject *obj, const char *slot); - static void flushMtabCache(); - static void flushFstabCache(); - -private: - static void _k_updateMtabMountPointsCache(); - static void _k_updateFstabMountPointsCache(); - - typedef QMultiHash QStringMultiHash; - - QStringMultiHash m_mtabCache; - QStringMultiHash m_fstabCache; - bool m_fstabCacheValid; - bool m_mtabCacheValid; - -}; - -} -} -} - -#endif - - diff --git a/solid/solid/backends/fstab/fstabmanager.cpp b/solid/solid/backends/fstab/fstabmanager.cpp deleted file mode 100644 index 6b29fa4d..00000000 --- a/solid/solid/backends/fstab/fstabmanager.cpp +++ /dev/null @@ -1,148 +0,0 @@ -/* - Copyright 2010 Mario Bensi - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) version 3, or any - later version accepted by the membership of KDE e.V. (or its - successor approved by the membership of KDE e.V.), which shall - act as a proxy defined in Section 6 of version 3 of the license. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library. If not, see . -*/ - -#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())); -} - -QString FstabManager::udiPrefix() const -{ - return QString::fromLatin1(FSTAB_UDI_PREFIX); -} - -QSet FstabManager::supportedInterfaces() const -{ - return m_supportedInterfaces; -} - -QStringList FstabManager::allDevices() -{ - QStringList result; - - result << udiPrefix(); - foreach (const QString &device, m_deviceList) { - result << udiPrefix() + "/" + device; - } - - return result; -} - -QStringList FstabManager::devicesFromQuery( const QString &parentUdi, - Solid::DeviceInterface::Type type) -{ - if (type == Solid::DeviceInterface::StorageAccess - || type == Solid::DeviceInterface::NetworkShare) { - if (parentUdi.isEmpty() || parentUdi == udiPrefix()) { - QStringList list = allDevices(); - list.removeFirst(); - return list; - } else { - QStringList list; - list << parentUdi; - return list; - } - } - return QStringList(); -} - -QObject *FstabManager::createDevice(const QString &udi) -{ - if (udi == udiPrefix()) { - RootDevice *root = new RootDevice(FSTAB_UDI_PREFIX); - - root->setProduct(tr("Network Shares")); - root->setDescription(tr("NFS and SMB shares declared in your system")); - root->setIcon("folder-remote"); - - 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 0; - - QObject* device = new FstabDevice(udi); - connect (this, SIGNAL(mtabChanged(QString)), device, SLOT(onMtabChanged(QString))); - return device; - - } -} - -void FstabManager::onFstabChanged() -{ - FstabHandling::flushFstabCache(); - _k_updateDeviceList(); -} - -void FstabManager::_k_updateDeviceList() -{ - QStringList deviceList = FstabHandling::deviceList(); - QSet newlist = deviceList.toSet(); - QSet oldlist = m_deviceList.toSet(); - - foreach(const QString &device, oldlist) { - if ( !newlist.contains(device) ) { - emit deviceRemoved(udiPrefix() + "/" + device); - } - } - - m_deviceList = deviceList; - - 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 - - foreach(const QString &device, m_deviceList) { - // notify storageaccess objects via device ... - emit mtabChanged(device); - } -} - -FstabManager::~FstabManager() -{ -} diff --git a/solid/solid/backends/fstab/fstabnetworkshare.cpp b/solid/solid/backends/fstab/fstabnetworkshare.cpp deleted file mode 100644 index 4bdd0599..00000000 --- a/solid/solid/backends/fstab/fstabnetworkshare.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - Copyright 2011 Mario Bensi - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) version 3, or any - later version accepted by the membership of KDE e.V. (or its - successor approved by the membership of KDE e.V.), which shall - act as a proxy defined in Section 6 of version 3 of the license. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library. If not, see . -*/ - -#include "fstabnetworkshare.h" -#include - -using namespace Solid::Backends::Fstab; - -FstabNetworkShare::FstabNetworkShare(Solid::Backends::Fstab::FstabDevice *device) : - QObject(device), - m_fstabDevice(device) -{ - QString url; - if (m_fstabDevice->device().startsWith("//")) { - m_type = Solid::NetworkShare::Cifs; - url = "smb:"; - url += m_fstabDevice->device(); - } else if (m_fstabDevice->device().contains(":/")) { - m_type = Solid::NetworkShare::Nfs; - url = "nfs://"; - url += m_fstabDevice->product(); - url += m_fstabDevice->vendor(); - } else { - m_type = Solid::NetworkShare::Unknown; - } - m_url = QUrl(url); -} - -FstabNetworkShare::~FstabNetworkShare() -{ -} - -Solid::NetworkShare::ShareType FstabNetworkShare::type() const -{ - return m_type; -} - -QUrl FstabNetworkShare::url() const -{ - return m_url; -} - - -const Solid::Backends::Fstab::FstabDevice *FstabNetworkShare::fstabDevice() const -{ - return m_fstabDevice; -} diff --git a/solid/solid/backends/fstab/fstabstorageaccess.cpp b/solid/solid/backends/fstab/fstabstorageaccess.cpp deleted file mode 100644 index 14eab7c1..00000000 --- a/solid/solid/backends/fstab/fstabstorageaccess.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* - Copyright 2010 Mario Bensi - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) version 3, or any - later version accepted by the membership of KDE e.V. (or its - successor approved by the membership of KDE e.V.), which shall - act as a proxy defined in Section 6 of version 3 of the license. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library. If not, see . -*/ - -#include "fstabstorageaccess.h" -#include "fstabwatcher.h" -#include -#include -#include -#include - -using namespace Solid::Backends::Fstab; - -FstabStorageAccess::FstabStorageAccess(Solid::Backends::Fstab::FstabDevice *device) : - QObject(device), - m_fstabDevice(device) -{ - QStringList currentMountPoints = FstabHandling::currentMountPoints(device->device()); - if (currentMountPoints.isEmpty()) { - QStringList mountPoints = FstabHandling::mountPoints(device->device()); - m_filePath = mountPoints.isEmpty() ? QString() : mountPoints.first(); - m_isAccessible = false; - } else { - m_filePath = currentMountPoints.first(); - m_isAccessible = true; - } - - connect(device, SIGNAL(mtabChanged(QString)), this, SLOT(onMtabChanged(QString))); -} - -FstabStorageAccess::~FstabStorageAccess() -{ -} - -const Solid::Backends::Fstab::FstabDevice *FstabStorageAccess::fstabDevice() const -{ - return m_fstabDevice; -} - -bool FstabStorageAccess::isAccessible() const -{ - return m_isAccessible; -} - -QString FstabStorageAccess::filePath() const -{ - return m_filePath; -} - -bool FstabStorageAccess::isIgnored() const -{ - return false; -} - -bool FstabStorageAccess::setup() -{ - if (filePath().isEmpty()) { - return false; - } - emit setupRequested(m_fstabDevice->udi()); - m_process = FstabHandling::callSystemCommand("mount", filePath(), - this, SLOT(slotSetupFinished(int,QProcess::ExitStatus))); - - return m_process!=0; -} - -bool FstabStorageAccess::teardown() -{ - if (filePath().isEmpty()) { - return false; - } - emit teardownRequested(m_fstabDevice->udi()); - m_process = FstabHandling::callSystemCommand("umount", filePath(), - this, SLOT(slotTeardownFinished(int,QProcess::ExitStatus))); - - return m_process!=0; -} - -void FstabStorageAccess::slotSetupFinished(int exitCode, QProcess::ExitStatus /*exitStatus*/) -{ - if (exitCode==0) { - emit setupDone(Solid::NoError, QString(), m_fstabDevice->udi()); - } else { - emit setupDone(Solid::UnauthorizedOperation, m_process->readAllStandardError(), m_fstabDevice->udi()); - } - delete m_process; -} - -void FstabStorageAccess::slotTeardownFinished(int exitCode, QProcess::ExitStatus /*exitStatus*/) -{ - if (exitCode==0) { - emit teardownDone(Solid::NoError, QString(), m_fstabDevice->udi()); - } else { - emit teardownDone(Solid::UnauthorizedOperation, m_process->readAllStandardError(), m_fstabDevice->udi()); - } - delete m_process; -} - -void FstabStorageAccess::onMtabChanged(const QString& device) -{ - QStringList currentMountPoints = FstabHandling::currentMountPoints(device); - if (currentMountPoints.isEmpty()) { - // device umounted - m_filePath = FstabHandling::mountPoints(device).first(); - m_isAccessible = false; - emit accessibilityChanged(false, QString(FSTAB_UDI_PREFIX) + "/" + device); - } else { - // device added - m_filePath = currentMountPoints.first(); - m_isAccessible = true; - emit accessibilityChanged(true, QString(FSTAB_UDI_PREFIX) + "/" + device); - } -} diff --git a/solid/solid/backends/fstab/fstabstorageaccess.h b/solid/solid/backends/fstab/fstabstorageaccess.h deleted file mode 100644 index c3f681f4..00000000 --- a/solid/solid/backends/fstab/fstabstorageaccess.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - Copyright 2010 Mario Bensi - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) version 3, or any - later version accepted by the membership of KDE e.V. (or its - successor approved by the membership of KDE e.V.), which shall - act as a proxy defined in Section 6 of version 3 of the license. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library. If not, see . -*/ - -#ifndef SOLID_BACKENDS_FSTAB_STORAGEACCESS_H -#define SOLID_BACKENDS_FSTAB_STORAGEACCESS_H - -#include - -#include -#include - -namespace Solid -{ -namespace Backends -{ -namespace Fstab -{ - class FstabDevice; - class FstabStorageAccess : public QObject, public Solid::Ifaces::StorageAccess - { - Q_OBJECT - Q_INTERFACES(Solid::Ifaces::StorageAccess) - - public: - explicit FstabStorageAccess(Solid::Backends::Fstab::FstabDevice *device); - - virtual ~FstabStorageAccess(); - - virtual bool isAccessible() const; - - virtual QString filePath() const; - - virtual bool isIgnored() const; - - virtual bool setup(); - - virtual bool teardown(); - - public: - const Solid::Backends::Fstab::FstabDevice* fstabDevice() const; - - Q_SIGNALS: - void accessibilityChanged(bool accessible, const QString &udi); - - void setupDone(Solid::ErrorType error, QVariant data, const QString &udi); - - void teardownDone(Solid::ErrorType error, QVariant data, const QString &udi); - - void setupRequested(const QString &udi); - - void teardownRequested(const QString &udi); - - private Q_SLOTS: - void slotSetupFinished(int exitCode, QProcess::ExitStatus exitStatus); - void slotTeardownFinished(int exitCode, QProcess::ExitStatus exitStatus); - void onMtabChanged(const QString& device); - - private: - Solid::Backends::Fstab::FstabDevice *m_fstabDevice; - QProcess *m_process; - QString m_filePath; - bool m_isAccessible; - }; - -} -} -} - -#endif // SOLID_BACKENDS_FSTAB_DEVICE_INTERFACE_H diff --git a/solid/solid/backends/fstab/fstabwatcher.cpp b/solid/solid/backends/fstab/fstabwatcher.cpp deleted file mode 100644 index 8132b20c..00000000 --- a/solid/solid/backends/fstab/fstabwatcher.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* - Copyright 2010 Mario Bensi - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) version 3, or any - later version accepted by the membership of KDE e.V. (or its - successor approved by the membership of KDE e.V.), which shall - act as a proxy defined in Section 6 of version 3 of the license. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library. If not, see . -*/ - -#include "fstabwatcher.h" -#include "soliddefs_p.h" - -#include -#include -#include -#include -#include - -using namespace Solid::Backends::Fstab; - -Q_GLOBAL_STATIC(FstabWatcher, globalFstabWatcher) - -#ifdef Q_OS_SOLARIS -#define FSTAB "/etc/vfstab" -#define MTAB "/etc/mnttab" -#else -#define FSTAB "/etc/fstab" -#define MTAB "/etc/mtab" -#endif - -FstabWatcher::FstabWatcher() - : m_fileSystemWatcher(new QFileSystemWatcher(this)) -{ - m_mtabFile = new QFile(MTAB, this); - if (m_mtabFile && m_mtabFile->readLink().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()) ); - } else { - m_fileSystemWatcher->addPath(MTAB); - } - - m_fileSystemWatcher->addPath(FSTAB); - connect(m_fileSystemWatcher, SIGNAL(fileChanged(QString)), this, SLOT(onFileChanged(QString))); -} - -FstabWatcher::~FstabWatcher() -{ - m_fileSystemWatcher->deleteLater(); -} - -FstabWatcher *FstabWatcher::instance() -{ - return globalFstabWatcher(); -} - - -void FstabWatcher::onFileChanged(const QString &path) -{ - if (path == MTAB) { - emit mtabChanged(); - if (!m_fileSystemWatcher->files().contains(MTAB)) { - m_fileSystemWatcher->addPath(MTAB); - } - } - if (path == FSTAB) { - emit fstabChanged(); - if (!m_fileSystemWatcher->files().contains(FSTAB)) { - m_fileSystemWatcher->addPath(FSTAB); - } - } -} - - diff --git a/solid/solid/managerbase.cpp b/solid/solid/managerbase.cpp index 577396aa..b2f60fa1 100644 --- a/solid/solid/managerbase.cpp +++ b/solid/solid/managerbase.cpp @@ -24,7 +24,7 @@ #include -#include "backends/fstab/fstabmanager.h" +#include "backends/exports/exportsmanager.h" #if defined(ENABLE_TESTING) #include "backends/fakehw/fakemanager.h" @@ -57,7 +57,7 @@ void Solid::ManagerBasePrivate::loadBackends() } #endif - m_backends << new Solid::Backends::Fstab::FstabManager(0); + m_backends << new Solid::Backends::Exports::ExportsManager(0); #if defined(UDEV_FOUND) m_backends << new Solid::Backends::UDev::UDevManager(0);