fix: ui no longer blocks when volumes are unreachable + add support for network and fuse volumes
This commit is contained in:
@@ -7,10 +7,27 @@
|
||||
#include <qpointer.h>
|
||||
#include <qqmlintegration.h>
|
||||
#include <qqmllist.h>
|
||||
#include <qtimer.h>
|
||||
#include <qtypes.h>
|
||||
#include <qvariant.h>
|
||||
#include <qvector.h>
|
||||
|
||||
template <typename T> class QFutureWatcher;
|
||||
|
||||
namespace ZShell::services {
|
||||
|
||||
struct StorageEntry {
|
||||
// Key for the entry: sysfs block device name, or mount point for a mount with
|
||||
// no backing block device (network mount). This is what DiskInfo reports as
|
||||
// its mount, so the UI can show either.
|
||||
QString mount;
|
||||
quint64 usedBytes = 0;
|
||||
quint64 totalBytes = 0;
|
||||
bool hasRoot = false;
|
||||
};
|
||||
|
||||
using StorageScan = QVector<StorageEntry>;
|
||||
|
||||
class Storage : public TickingService {
|
||||
Q_OBJECT
|
||||
QML_ELEMENT
|
||||
@@ -26,6 +43,7 @@ class Storage : public TickingService {
|
||||
Q_PROPERTY(
|
||||
ZShell::services::DiskInfo* primaryDisk READ primaryDisk NOTIFY
|
||||
primaryDiskChanged)
|
||||
Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged)
|
||||
|
||||
public:
|
||||
explicit Storage(QObject* parent = nullptr);
|
||||
@@ -35,12 +53,14 @@ class Storage : public TickingService {
|
||||
[[nodiscard]] DiskInfo* manualPrimaryDisk() const;
|
||||
void setManualPrimaryDisk(DiskInfo* disk);
|
||||
[[nodiscard]] DiskInfo* primaryDisk() const;
|
||||
[[nodiscard]] bool loading() const;
|
||||
|
||||
signals:
|
||||
void disksChanged();
|
||||
void percentageChanged();
|
||||
void manualPrimaryDiskChanged();
|
||||
void primaryDiskChanged();
|
||||
void loadingChanged();
|
||||
|
||||
protected:
|
||||
void tick() override;
|
||||
@@ -55,8 +75,22 @@ class Storage : public TickingService {
|
||||
static qsizetype disksCount(QQmlListProperty<DiskInfo>* prop);
|
||||
static DiskInfo* disksAt(QQmlListProperty<DiskInfo>* prop, qsizetype i);
|
||||
|
||||
// Runs on a worker thread. statvfs on a mount whose backing storage is
|
||||
// unreachable can block for the whole network timeout, so the scan must not
|
||||
// run on the GUI thread. The result is plain data, applied on this object's
|
||||
// thread once it arrives.
|
||||
[[nodiscard]] static StorageScan scanVolumes();
|
||||
|
||||
void beginScan();
|
||||
void onScanFinished();
|
||||
void applyScan(const StorageScan& scan);
|
||||
void setLoading(bool value);
|
||||
|
||||
QList<DiskInfo*> m_disks;
|
||||
QPointer<DiskInfo> m_manualPrimaryDisk;
|
||||
QFutureWatcher<StorageScan>* m_watcher = nullptr;
|
||||
QTimer m_loadingTimer;
|
||||
bool m_loading = false;
|
||||
};
|
||||
|
||||
} // namespace ZShell::services
|
||||
|
||||
Reference in New Issue
Block a user