Get free space for DeviceKit devices

This commit is contained in:
David Sansome 2010-07-29 18:14:26 +00:00
parent a95f9aecd8
commit 7c974d66da
2 changed files with 14 additions and 2 deletions

View File

@ -24,6 +24,8 @@
# include "gpoddevice.h"
#endif
#include <sys/vfs.h>
#include <QtDebug>
DeviceKitLister::DeviceKitLister()
@ -110,7 +112,7 @@ quint64 DeviceKitLister::DeviceCapacity(const QString &id) {
}
quint64 DeviceKitLister::DeviceFreeSpace(const QString &id) {
return 0; // TODO
return LockAndGetDeviceInfo(id, &DeviceData::free_space);
}
QVariantMap DeviceKitLister::DeviceHardwareInfo(const QString &id) {
@ -174,6 +176,15 @@ DeviceKitLister::DeviceData DeviceKitLister::ReadDeviceData(
ret.device_presentation_icon_name = device.devicePresentationIconName();
ret.device_size = device.deviceSize();
ret.device_mount_paths = device.deviceMountPaths();
// Get free space info
if (!ret.device_mount_paths.isEmpty()) {
struct statfs fs_info;
if (statfs(ret.device_mount_paths[0].toLocal8Bit().constData(), &fs_info) == 0) {
ret.free_space = fs_info.f_bavail * fs_info.f_bsize;
}
}
return ret;
}

View File

@ -58,7 +58,7 @@ private slots:
private:
struct DeviceData {
DeviceData() : suitable(false), device_size(0) {}
DeviceData() : suitable(false), device_size(0), free_space(0) {}
QString unique_id() const;
@ -72,6 +72,7 @@ private:
QString device_presentation_icon_name;
QStringList device_mount_paths;
quint64 device_size;
quint64 free_space;
};
DeviceData ReadDeviceData(const QDBusObjectPath& path) const;