-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrivemanager.cpp
More file actions
57 lines (49 loc) · 1.72 KB
/
drivemanager.cpp
File metadata and controls
57 lines (49 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "drivemanager.h"
#include <QDebug>
DriveManager::DriveManager(QObject *parent)
: QObject(parent), m_timer(new QTimer(this)) {
// Initial check
m_currentDrives = getFilteredDrives();
// Poll for changes every 2 seconds
connect(m_timer, &QTimer::timeout, this, &DriveManager::checkForChanges);
m_timer->start(2000);
}
QList<QStorageInfo> DriveManager::getDrives() const { return m_currentDrives; }
QList<QStorageInfo> DriveManager::getFilteredDrives() const {
QList<QStorageInfo> allDrives = QStorageInfo::mountedVolumes();
QList<QStorageInfo> filteredDrives;
for (const QStorageInfo &drive : allDrives) {
// Filter out loop devices and system filesystems
if (drive.device().startsWith("/dev/loop") ||
drive.fileSystemType() == "squashfs" ||
drive.fileSystemType() == "tmpfs" ||
drive.fileSystemType() == "overlay" ||
drive.fileSystemType() == "proc" || drive.fileSystemType() == "sysfs" ||
drive.fileSystemType() == "devtmpfs" ||
drive.fileSystemType() == "devpts") {
continue;
}
filteredDrives.append(drive);
}
return filteredDrives;
}
void DriveManager::checkForChanges() {
QList<QStorageInfo> newDrives = getFilteredDrives();
// Simple check if the number of drives changed or if paths are different
bool changed = false;
if (newDrives.size() != m_currentDrives.size()) {
changed = true;
} else {
for (int i = 0; i < newDrives.size(); ++i) {
if (newDrives[i].rootPath() != m_currentDrives[i].rootPath() ||
newDrives[i].name() != m_currentDrives[i].name()) {
changed = true;
break;
}
}
}
if (changed) {
m_currentDrives = newDrives;
emit drivesUpdated(m_currentDrives);
}
}