ukui-search/ukui-search-service-dir-man.../dirwatcher/volume-manager.h

54 lines
1.4 KiB
C
Raw Normal View History

#ifndef VOLUMEMANAGER_H
#define VOLUMEMANAGER_H
#include <gio/gio.h>
#include <gio/gunixmounts.h>
#include <QObject>
#include <QStorageInfo>
#include <QMultiMap>
#include <QMutex>
#include <QVector>
class Volume
{
public:
Volume();
Volume(const QString& device);
QString device();
QStringList duplicatesMountPoints() const;
QMap<QString, QString> subVolumes() const;
QStringList mountPoints() const;
void setDevice(const QString& device);
void addMountPoint(const QString& mountPoint, const QString& subVolume = QString());
private:
QString m_device;
QMap<QString, QString> m_mountPoints; //挂载点->子卷路径
};
class VolumeManager : public QObject
{
Q_OBJECT
public:
static VolumeManager *self();
~VolumeManager();
QVector<QStringList> getDuplicates();
QVector<Volume> volumesHaveSubVolumes();
QVector<Volume> volumes();
Q_SIGNALS:
void VolumeDataUpdated();
private:
explicit VolumeManager(QObject *parent = nullptr);
void refresh();
static void mountAddCallback(GVolumeMonitor *monitor, GMount *gmount, VolumeManager *pThis);
static void mountRemoveCallback(GVolumeMonitor *monitor, GMount *gmount, VolumeManager *pThis);
GVolumeMonitor* m_volumeMonitor = nullptr;
quint64 m_mountAddHandle;
quint64 m_mountRemoveHandle;
QMap<QString, Volume> m_volumes; //device -> Volume
QMutex m_mutex;
};
#endif // VOLUMEMANAGER_H