Update a device's free space after copying or removing files from it
This commit is contained in:
parent
a1332a2c05
commit
2e646494aa
@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
#include "connecteddevice.h"
|
||||
#include "devicelister.h"
|
||||
#include "devicemanager.h"
|
||||
#include "core/database.h"
|
||||
#include "library/library.h"
|
||||
@ -84,3 +85,11 @@ void ConnectedDevice::InitBackendDirectory(
|
||||
void ConnectedDevice::Eject() {
|
||||
manager_->UnmountAsync(manager_->FindDeviceById(unique_id_));
|
||||
}
|
||||
|
||||
void ConnectedDevice::FinishCopy(bool) {
|
||||
lister_->UpdateDeviceFreeSpace(unique_id_);
|
||||
}
|
||||
|
||||
void ConnectedDevice::FinishDelete(bool) {
|
||||
lister_->UpdateDeviceFreeSpace(unique_id_);
|
||||
}
|
||||
|
@ -48,6 +48,9 @@ public:
|
||||
LibraryModel* model() const { return model_; }
|
||||
QUrl url() const { return url_; }
|
||||
|
||||
virtual void FinishCopy(bool success);
|
||||
virtual void FinishDelete(bool success);
|
||||
|
||||
void Eject();
|
||||
|
||||
signals:
|
||||
|
@ -278,3 +278,17 @@ void DeviceKitLister::UnmountDevice(const QString& id) {
|
||||
drive.DriveEject(QStringList());
|
||||
// Don't bother waiting for the eject to finish
|
||||
}
|
||||
|
||||
void DeviceKitLister::UpdateDeviceFreeSpace(const QString& id) {
|
||||
{
|
||||
QMutexLocker l(&mutex_);
|
||||
if (!device_data_.contains(id))
|
||||
return;
|
||||
|
||||
DeviceData& data = device_data_[id];
|
||||
if (!data.device_mount_paths.isEmpty())
|
||||
data.free_space = Utilities::FileSystemFreeSpace(data.device_mount_paths[0]);
|
||||
}
|
||||
|
||||
emit DeviceChanged(id);
|
||||
}
|
||||
|
@ -48,6 +48,9 @@ public:
|
||||
|
||||
void UnmountDevice(const QString &id);
|
||||
|
||||
public slots:
|
||||
void UpdateDeviceFreeSpace(const QString& id);
|
||||
|
||||
protected:
|
||||
void Init();
|
||||
|
||||
|
@ -55,6 +55,9 @@ public:
|
||||
// Do whatever needs to be done to safely remove the device.
|
||||
virtual void UnmountDevice(const QString& id) = 0;
|
||||
|
||||
public slots:
|
||||
virtual void UpdateDeviceFreeSpace(const QString& id) = 0;
|
||||
|
||||
signals:
|
||||
void DeviceAdded(const QString& id);
|
||||
void DeviceRemoved(const QString& id);
|
||||
|
@ -323,3 +323,31 @@ void GioLister::UnmountDevice(const QString &id) {
|
||||
(GAsyncReadyCallback) MountUnmountFinished, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void GioLister::UpdateDeviceFreeSpace(const QString& id) {
|
||||
{
|
||||
QMutexLocker l(&mutex_);
|
||||
if (!mounts_.contains(id))
|
||||
return;
|
||||
|
||||
MountInfo& mount_info = mounts_[id];
|
||||
|
||||
GFile* root = g_mount_get_root(mount_info.mount);
|
||||
|
||||
GError* error = NULL;
|
||||
GFileInfo* info = g_file_query_filesystem_info(
|
||||
root, G_FILE_ATTRIBUTE_FILESYSTEM_FREE, NULL, &error);
|
||||
if (error) {
|
||||
qWarning() << error->message;
|
||||
g_error_free(error);
|
||||
} else {
|
||||
mount_info.filesystem_free = g_file_info_get_attribute_uint64(
|
||||
info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
|
||||
g_object_unref(info);
|
||||
}
|
||||
|
||||
g_object_unref(root);
|
||||
}
|
||||
|
||||
emit DeviceChanged(id);
|
||||
}
|
||||
|
@ -46,6 +46,9 @@ public:
|
||||
|
||||
void UnmountDevice(const QString &id);
|
||||
|
||||
public slots:
|
||||
void UpdateDeviceFreeSpace(const QString& id);
|
||||
|
||||
protected:
|
||||
void Init();
|
||||
|
||||
|
@ -129,7 +129,7 @@ bool GPodDevice::CopyToStorage(
|
||||
return true;
|
||||
}
|
||||
|
||||
void GPodDevice::FinishCopy(bool success) {
|
||||
void GPodDevice::WriteDatabase(bool success) {
|
||||
if (success) {
|
||||
// Write the itunes database
|
||||
GError* error = NULL;
|
||||
@ -154,6 +154,11 @@ void GPodDevice::FinishCopy(bool success) {
|
||||
db_busy_.unlock();
|
||||
}
|
||||
|
||||
void GPodDevice::FinishCopy(bool success) {
|
||||
WriteDatabase(success);
|
||||
ConnectedDevice::FinishCopy(success);
|
||||
}
|
||||
|
||||
void GPodDevice::StartDelete() {
|
||||
StartCopy();
|
||||
}
|
||||
@ -200,6 +205,7 @@ bool GPodDevice::DeleteFromStorage(const Song& metadata) {
|
||||
}
|
||||
|
||||
void GPodDevice::FinishDelete(bool success) {
|
||||
FinishCopy(success);
|
||||
WriteDatabase(success);
|
||||
ConnectedDevice::FinishDelete(success);
|
||||
}
|
||||
|
||||
|
@ -56,9 +56,11 @@ protected slots:
|
||||
protected:
|
||||
Itdb_Track* AddTrackToITunesDb(const Song& metadata);
|
||||
void AddTrackToModel(Itdb_Track* track, const QString& prefix);
|
||||
|
||||
virtual void FinaliseDatabase() {}
|
||||
|
||||
private:
|
||||
void WriteDatabase(bool success);
|
||||
|
||||
protected:
|
||||
QThread* loader_thread_;
|
||||
GPodLoader* loader_;
|
||||
|
@ -163,3 +163,18 @@ iLister::DeviceInfo iLister::ReadDeviceInfo(const char* uuid) {
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void iLister::UpdateDeviceFreeSpace(const QString& id) {
|
||||
{
|
||||
QMutexLocker l(&mutex_);
|
||||
if (!devices_.contains(id))
|
||||
return;
|
||||
|
||||
DeviceInfo& info = devices_[id];
|
||||
iMobileDeviceConnection conn(info.uuid);
|
||||
|
||||
info.free_bytes = conn.GetProperty("AmountDataAvailable", "com.apple.disk_usage").toULongLong();
|
||||
}
|
||||
|
||||
emit DeviceChanged(id);
|
||||
}
|
||||
|
@ -26,6 +26,9 @@ class iLister : public DeviceLister {
|
||||
virtual QList<QUrl> MakeDeviceUrls(const QString& id);
|
||||
virtual void UnmountDevice(const QString& id);
|
||||
|
||||
public slots:
|
||||
virtual void UpdateDeviceFreeSpace(const QString& id);
|
||||
|
||||
private:
|
||||
struct DeviceInfo {
|
||||
DeviceInfo() : free_bytes(0), total_bytes(0) {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user