mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
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 <xakepa10@gmail.com>
This commit is contained in:
parent
02b95a9623
commit
8899a3c369
21 changed files with 705 additions and 1054 deletions
|
@ -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(
|
||||
|
|
222
solid/solid/backends/exports/exportsdevice.cpp
Normal file
222
solid/solid/backends/exports/exportsdevice.cpp
Normal file
|
@ -0,0 +1,222 @@
|
|||
/*
|
||||
Copyright 2022 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "exportsmanager.h"
|
||||
#include "exportsdevice.h"
|
||||
#include "exportsnetworkshare.h"
|
||||
#include "exportsstorageaccess.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
|
||||
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<QByteArray> 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<ExportsDevice*>(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<QByteArray> ExportsDevice::exportParts(const QByteArray &exportline)
|
||||
{
|
||||
QList<QByteArray> 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;
|
||||
}
|
69
solid/solid/backends/exports/exportsdevice.h
Normal file
69
solid/solid/backends/exports/exportsdevice.h
Normal file
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
Copyright 2022 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SOLID_BACKENDS_EXPORTS_EXPORTSDEVICE_H
|
||||
#define SOLID_BACKENDS_EXPORTS_EXPORTSDEVICE_H
|
||||
|
||||
#include <solid/ifaces/device.h>
|
||||
#include <QtCore/QStringList>
|
||||
|
||||
#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<QByteArray> exportParts(const QByteArray &exportline);
|
||||
|
||||
private:
|
||||
QString m_device;
|
||||
QString m_dir;
|
||||
QString m_address;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // SOLID_BACKENDS_EXPORTS_EXPORTSDEVICE_H
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2010 Mario Bensi <mbensi@ipsquad.net>
|
||||
Copyright 2022 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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"
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2011 Mario Bensi <mbensi@ipsquad.net>
|
||||
Copyright 2022 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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 <solid/ifaces/networkshare.h>
|
||||
#include <solid/ifaces/deviceinterface.h>
|
||||
#include "exportsdevice.h"
|
||||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
|
@ -29,34 +30,21 @@ namespace Solid
|
|||
{
|
||||
namespace Backends
|
||||
{
|
||||
namespace Fstab
|
||||
namespace Exports
|
||||
{
|
||||
class FstabDevice;
|
||||
class FstabNetworkShare : public QObject, public Solid::Ifaces::NetworkShare
|
||||
class DeviceInterface : public QObject, virtual public Solid::Ifaces::DeviceInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Solid::Ifaces::NetworkShare)
|
||||
|
||||
Q_INTERFACES(Solid::Ifaces::DeviceInterface)
|
||||
public:
|
||||
explicit FstabNetworkShare(Solid::Backends::Fstab::FstabDevice *device);
|
||||
DeviceInterface(ExportsDevice *device);
|
||||
virtual ~DeviceInterface();
|
||||
|
||||
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;
|
||||
protected:
|
||||
ExportsDevice *m_device;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // SOLID_BACKENDS_FSTAB_NETWORKSHARE_H
|
||||
#endif // SOLID_BACKENDS_EXPORTS_DEVICEINTERFACE_H
|
137
solid/solid/backends/exports/exportsmanager.cpp
Normal file
137
solid/solid/backends/exports/exportsmanager.cpp
Normal file
|
@ -0,0 +1,137 @@
|
|||
/*
|
||||
Copyright 2022 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "exportsmanager.h"
|
||||
#include "exportsdevice.h"
|
||||
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QSet>
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
using namespace Solid::Backends::Exports;
|
||||
|
||||
class ExportsManager::Private
|
||||
{
|
||||
public:
|
||||
Private(ExportsManager *parent);
|
||||
~Private();
|
||||
|
||||
QSet<Solid::DeviceInterface::Type> 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<Solid::DeviceInterface::Type> 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<QByteArray> 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;
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2010 Mario Bensi <mbensi@ipsquad.net>
|
||||
Copyright 2022 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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 <solid/ifaces/devicemanager.h>
|
||||
#include <solid/deviceinterface.h>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QSet>
|
||||
|
||||
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 QSet<Solid::DeviceInterface::Type> 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<Solid::DeviceInterface::Type> m_supportedInterfaces;
|
||||
QStringList m_deviceList;
|
||||
void _k_updateDeviceList();
|
||||
class Private;
|
||||
Private *const d;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif // SOLID_BACKENDS_EXPORTS_EXPORTSMANAGER_H
|
44
solid/solid/backends/exports/exportsnetworkshare.cpp
Normal file
44
solid/solid/backends/exports/exportsnetworkshare.cpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
Copyright 2022 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "exportsnetworkshare.h"
|
||||
#include "exportsdevice.h"
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
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"
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2010 Mario Bensi <mbensi@ipsquad.net>
|
||||
Copyright 2022 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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 <QObject>
|
||||
|
||||
#include <QFileSystemWatcher>
|
||||
#include <QFile>
|
||||
#include <QSocketNotifier>
|
||||
#include <solid/ifaces/networkshare.h>
|
||||
#include "exportsdeviceinterface.h"
|
||||
|
||||
namespace Solid
|
||||
{
|
||||
namespace Backends
|
||||
{
|
||||
namespace Fstab
|
||||
namespace Exports
|
||||
{
|
||||
class ExportsDevice;
|
||||
|
||||
class FstabWatcher : public QObject {
|
||||
class NetworkShare : public DeviceInterface, virtual public Solid::Ifaces::NetworkShare
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Solid::Ifaces::NetworkShare)
|
||||
|
||||
public:
|
||||
FstabWatcher();
|
||||
virtual ~FstabWatcher();
|
||||
NetworkShare(ExportsDevice *device);
|
||||
|
||||
static FstabWatcher *instance();
|
||||
|
||||
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
|
105
solid/solid/backends/exports/exportsstorageaccess.cpp
Normal file
105
solid/solid/backends/exports/exportsstorageaccess.cpp
Normal file
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
Copyright 2022 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "exportsstorageaccess.h"
|
||||
#include "kmountpoint.h"
|
||||
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusReply>
|
||||
#include <QDebug>
|
||||
|
||||
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<int> reply = soliduiserver.call("mountDevice", m_device->udi());
|
||||
|
||||
const Solid::ErrorType replyvalue = static_cast<Solid::ErrorType>(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<int> reply = soliduiserver.call("unmountDevice", m_device->udi());
|
||||
|
||||
const Solid::ErrorType replyvalue = static_cast<Solid::ErrorType>(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);
|
||||
}
|
59
solid/solid/backends/exports/exportsstorageaccess.h
Normal file
59
solid/solid/backends/exports/exportsstorageaccess.h
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
Copyright 2022 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SOLID_BACKENDS_EXPORTS_STORAGEACCESS_H
|
||||
#define SOLID_BACKENDS_EXPORTS_STORAGEACCESS_H
|
||||
|
||||
#include <solid/ifaces/storageaccess.h>
|
||||
#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
|
|
@ -1,128 +0,0 @@
|
|||
/*
|
||||
Copyright 2010 Mario Bensi <mbensi@ipsquad.net>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "fstabdevice.h"
|
||||
#include "fstabhandling.h"
|
||||
#include "fstabnetworkshare.h"
|
||||
#include "fstabstorageaccess.h"
|
||||
#include "fstabservice.h"
|
||||
#include <QtCore/QStringList>
|
||||
|
||||
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<FstabDevice *>(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);
|
||||
}
|
|
@ -1,83 +0,0 @@
|
|||
/*
|
||||
Copyright 2010 Mario Bensi <mbensi@ipsquad.net>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SOLID_BACKENDS_FSTAB_FSTAB_DEVICE_H
|
||||
#define SOLID_BACKENDS_FSTAB_FSTAB_DEVICE_H
|
||||
|
||||
#include <solid/ifaces/device.h>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QPointer>
|
||||
#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<FstabStorageAccess> m_storageAccess;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // SOLID_BACKENDS_FSTAB_FSTAB_DEVICE_H
|
|
@ -1,157 +0,0 @@
|
|||
/*
|
||||
Copyright 2006-2010 Kevin Ottens <ervin@kde.org>
|
||||
Copyright 2010 Mario Bensi <mbensi@ipsquad.net>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "fstabhandling.h"
|
||||
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QProcess>
|
||||
#include <QtCore/QTextStream>
|
||||
#include <kstandarddirs.h>
|
||||
#include <kmountpoint.h>
|
||||
|
||||
#include <solid/soliddefs_p.h>
|
||||
|
||||
#include <config.h>
|
||||
|
||||
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;
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
/*
|
||||
Copyright 2006-2010 Kevin Ottens <ervin@kde.org>
|
||||
Copyright 2010 Mario Bensi <mbensi@ipsquad.net>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SOLID_BACKENDS_FSTAB_FSTABHANDLING_H
|
||||
#define SOLID_BACKENDS_FSTAB_FSTABHANDLING_H
|
||||
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QMultiHash>
|
||||
|
||||
#include <QProcess>
|
||||
#include <QObject>
|
||||
|
||||
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<QString, QString> QStringMultiHash;
|
||||
|
||||
QStringMultiHash m_mtabCache;
|
||||
QStringMultiHash m_fstabCache;
|
||||
bool m_fstabCacheValid;
|
||||
bool m_mtabCacheValid;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -1,148 +0,0 @@
|
|||
/*
|
||||
Copyright 2010 Mario Bensi <mbensi@ipsquad.net>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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<Solid::DeviceInterface::Type> 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<QString> newlist = deviceList.toSet();
|
||||
QSet<QString> 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()
|
||||
{
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
/*
|
||||
Copyright 2011 Mario Bensi <mbensi@ipsquad.net>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "fstabnetworkshare.h"
|
||||
#include <solid/backends/fstab/fstabdevice.h>
|
||||
|
||||
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;
|
||||
}
|
|
@ -1,129 +0,0 @@
|
|||
/*
|
||||
Copyright 2010 Mario Bensi <mbensi@ipsquad.net>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "fstabstorageaccess.h"
|
||||
#include "fstabwatcher.h"
|
||||
#include <solid/backends/fstab/fstabdevice.h>
|
||||
#include <solid/backends/fstab/fstabhandling.h>
|
||||
#include <solid/backends/fstab/fstabservice.h>
|
||||
#include <QtCore/QStringList>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
/*
|
||||
Copyright 2010 Mario Bensi <mbensi@ipsquad.net>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SOLID_BACKENDS_FSTAB_STORAGEACCESS_H
|
||||
#define SOLID_BACKENDS_FSTAB_STORAGEACCESS_H
|
||||
|
||||
#include <solid/ifaces/storageaccess.h>
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QProcess>
|
||||
|
||||
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
|
|
@ -1,88 +0,0 @@
|
|||
/*
|
||||
Copyright 2010 Mario Bensi <mbensi@ipsquad.net>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "fstabwatcher.h"
|
||||
#include "soliddefs_p.h"
|
||||
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <QtCore/QFileSystemWatcher>
|
||||
#include <QtCore/QSocketNotifier>
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QStringList>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
|
||||
#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);
|
||||
|
|
Loading…
Add table
Reference in a new issue