59 lines
1.4 KiB
C++
59 lines
1.4 KiB
C++
#ifndef VOLUMEMANAGER_H
|
|
#define VOLUMEMANAGER_H
|
|
|
|
#undef slots
|
|
#undef signals
|
|
#undef emit
|
|
|
|
#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
|