mirror of
https://github.com/clementine-player/Clementine
synced 2025-02-07 06:35:15 +01:00
Fix free space & capacity counts for MTP devices on Mac.
This commit is contained in:
parent
24ad106750
commit
ab363a54ea
@ -40,8 +40,8 @@ class MacDeviceLister : public DeviceLister {
|
||||
int bus;
|
||||
int address;
|
||||
|
||||
int capacity;
|
||||
int free_space;
|
||||
quint64 capacity;
|
||||
quint64 free_space;
|
||||
};
|
||||
|
||||
public slots:
|
||||
@ -61,8 +61,8 @@ class MacDeviceLister : public DeviceLister {
|
||||
void FoundMTPDevice(const MTPDevice& device, const QString& serial);
|
||||
void RemovedMTPDevice(const QString& serial);
|
||||
|
||||
int GetFreeSpace(const QUrl& url);
|
||||
int GetCapacity(const QUrl& url);
|
||||
quint64 GetFreeSpace(const QUrl& url);
|
||||
quint64 GetCapacity(const QUrl& url);
|
||||
|
||||
DASessionRef loop_session_;
|
||||
CFRunLoopRef run_loop_;
|
||||
|
@ -299,24 +299,37 @@ QString FindDeviceProperty(const QString& bsd_name, CFStringRef property) {
|
||||
|
||||
}
|
||||
|
||||
int MacDeviceLister::GetFreeSpace(const QUrl& url) {
|
||||
quint64 MacDeviceLister::GetFreeSpace(const QUrl& url) {
|
||||
QMutexLocker l(&libmtp_mutex_);
|
||||
MtpConnection connection(url);
|
||||
if (!connection.is_valid()) {
|
||||
qWarning() << "Error connecting to MTP device, couldn't get device free space";
|
||||
return -1;
|
||||
}
|
||||
return connection.device()->storage->FreeSpaceInBytes;
|
||||
LIBMTP_devicestorage_t* storage = connection.device()->storage;
|
||||
quint64 free_bytes = 0;
|
||||
while (storage) {
|
||||
free_bytes += storage->FreeSpaceInBytes;
|
||||
qDebug() << "Storage so far:" << free_bytes;
|
||||
storage = storage->next;
|
||||
}
|
||||
return free_bytes;
|
||||
}
|
||||
|
||||
int MacDeviceLister::GetCapacity(const QUrl& url) {
|
||||
quint64 MacDeviceLister::GetCapacity(const QUrl& url) {
|
||||
QMutexLocker l(&libmtp_mutex_);
|
||||
MtpConnection connection(url);
|
||||
if (!connection.is_valid()) {
|
||||
qWarning() << "Error connecting to MTP device, couldn't get device capacity";
|
||||
return -1;
|
||||
}
|
||||
return connection.device()->storage->MaxCapacity;
|
||||
LIBMTP_devicestorage_t* storage = connection.device()->storage;
|
||||
quint64 capacity_bytes = 0;
|
||||
while (storage) {
|
||||
capacity_bytes += storage->MaxCapacity;
|
||||
storage = storage->next;
|
||||
}
|
||||
return capacity_bytes;
|
||||
}
|
||||
|
||||
void MacDeviceLister::DiskAddedCallback(DADiskRef disk, void* context) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user