2023-04-11 10:19:35 +08:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Copyright (C) 2023, KylinSoft Co., Ltd.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Authors: iaom <zhangpengfei@kylinos.cn>
|
|
|
|
*/
|
2023-04-04 14:49:50 +08:00
|
|
|
#ifndef VOLUMEMANAGER_H
|
|
|
|
#define VOLUMEMANAGER_H
|
2023-04-08 16:54:01 +08:00
|
|
|
|
|
|
|
#undef slots
|
|
|
|
#undef signals
|
|
|
|
#undef emit
|
|
|
|
|
2023-04-04 14:49:50 +08:00
|
|
|
#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();
|
2024-04-24 17:48:36 +08:00
|
|
|
void refresh();
|
2023-04-04 14:49:50 +08:00
|
|
|
Q_SIGNALS:
|
|
|
|
void VolumeDataUpdated();
|
|
|
|
|
|
|
|
private:
|
|
|
|
explicit VolumeManager(QObject *parent = nullptr);
|
|
|
|
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
|