More const detach fixes
This commit is contained in:
@@ -830,7 +830,7 @@ void DeviceManager::DeviceTaskStarted(const int id) {
|
||||
if (!device) return;
|
||||
|
||||
for (int i = 0; i < devices_.count(); ++i) {
|
||||
DeviceInfo *info = devices_[i];
|
||||
DeviceInfo *info = devices_.value(i);
|
||||
if (info->device_ && &*info->device_ == device) {
|
||||
QModelIndex index = ItemToIndex(info);
|
||||
if (!index.isValid()) continue;
|
||||
@@ -851,7 +851,7 @@ void DeviceManager::TasksChanged() {
|
||||
for (const TaskManager::Task &task : tasks) {
|
||||
if (!active_tasks_.contains(task.id)) continue;
|
||||
|
||||
const QPersistentModelIndex idx = active_tasks_[task.id];
|
||||
const QPersistentModelIndex idx = active_tasks_.value(task.id);
|
||||
if (!idx.isValid()) continue;
|
||||
|
||||
DeviceInfo *info = IndexToItem(idx);
|
||||
|
||||
@@ -144,14 +144,14 @@ QVariantList GioLister::DeviceIcons(const QString &id) {
|
||||
QMutexLocker l(&mutex_);
|
||||
if (!devices_.contains(id)) return ret;
|
||||
|
||||
const DeviceInfo &info = devices_[id];
|
||||
const DeviceInfo device_info = devices_.value(id);
|
||||
|
||||
if (info.mount_ptr) {
|
||||
ret << DeviceLister::GuessIconForPath(info.mount_path);
|
||||
ret << info.mount_icon_names;
|
||||
if (device_info.mount_ptr) {
|
||||
ret << DeviceLister::GuessIconForPath(device_info.mount_path);
|
||||
ret << device_info.mount_icon_names;
|
||||
}
|
||||
|
||||
ret << DeviceLister::GuessIconForModel(QString(), info.mount_name);
|
||||
ret << DeviceLister::GuessIconForModel(QString(), device_info.mount_name);
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -163,9 +163,9 @@ QString GioLister::DeviceModel(const QString &id) {
|
||||
|
||||
QMutexLocker l(&mutex_);
|
||||
if (!devices_.contains(id)) return QString();
|
||||
const DeviceInfo &info = devices_[id];
|
||||
const DeviceInfo device_info = devices_.value(id);
|
||||
|
||||
return info.drive_name.isEmpty() ? info.volume_name : info.drive_name;
|
||||
return device_info.drive_name.isEmpty() ? device_info.volume_name : device_info.drive_name;
|
||||
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ QVariantMap GioLister::DeviceHardwareInfo(const QString &id) {
|
||||
|
||||
QMutexLocker l(&mutex_);
|
||||
if (!devices_.contains(id)) return ret;
|
||||
const DeviceInfo &info = devices_[id];
|
||||
const DeviceInfo info = devices_.value(id);
|
||||
|
||||
ret[QStringLiteral(QT_TR_NOOP("Mount point"))] = info.mount_path;
|
||||
ret[QStringLiteral(QT_TR_NOOP("Device"))] = info.volume_unix_device;
|
||||
@@ -399,7 +399,7 @@ void GioLister::MountChanged(GMount *mount) {
|
||||
new_info.ReadDriveInfo(g_mount_get_drive(mount));
|
||||
|
||||
// Ignore the change if the new info is useless
|
||||
if (new_info.invalid_enclosing_mount || (devices_[id].filesystem_size != 0 && new_info.filesystem_size == 0) || (!devices_[id].filesystem_type.isEmpty() && new_info.filesystem_type.isEmpty())) {
|
||||
if (new_info.invalid_enclosing_mount || (devices_.value(id).filesystem_size != 0 && new_info.filesystem_size == 0) || (!devices_[id].filesystem_type.isEmpty() && new_info.filesystem_type.isEmpty())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -577,11 +577,9 @@ void GioLister::UpdateDeviceFreeSpace(const QString &id) {
|
||||
|
||||
{
|
||||
QMutexLocker l(&mutex_);
|
||||
if (!devices_.contains(id) || !devices_[id].mount_ptr || devices_[id].volume_root_uri.startsWith(QLatin1String("mtp://"))) return;
|
||||
if (!devices_.contains(id) || !devices_[id].mount_ptr || devices_.value(id).volume_root_uri.startsWith(QLatin1String("mtp://"))) return;
|
||||
|
||||
DeviceInfo &device_info = devices_[id];
|
||||
|
||||
GFile *root = g_mount_get_root(device_info.mount_ptr);
|
||||
GFile *root = g_mount_get_root(devices_.value(id).mount_ptr);
|
||||
|
||||
GError *error = nullptr;
|
||||
GFileInfo *info = g_file_query_filesystem_info(root, G_FILE_ATTRIBUTE_FILESYSTEM_FREE, nullptr, &error);
|
||||
@@ -590,7 +588,7 @@ void GioLister::UpdateDeviceFreeSpace(const QString &id) {
|
||||
g_error_free(error);
|
||||
}
|
||||
else {
|
||||
device_info.filesystem_free = g_file_info_get_attribute_uint64(info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
|
||||
devices_[id].filesystem_free = g_file_info_get_attribute_uint64(info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
|
||||
g_object_unref(info);
|
||||
}
|
||||
|
||||
@@ -616,14 +614,14 @@ void GioLister::MountDevice(const QString &id, const int request_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
const DeviceInfo &info = devices_[id];
|
||||
if (info.mount_ptr) {
|
||||
const DeviceInfo device_info = devices_.value(id);
|
||||
if (device_info.mount_ptr) {
|
||||
// Already mounted
|
||||
emit DeviceMounted(id, request_id, true);
|
||||
return;
|
||||
}
|
||||
|
||||
g_volume_mount(info.volume_ptr, G_MOUNT_MOUNT_NONE, nullptr, nullptr, VolumeMountFinished, nullptr);
|
||||
g_volume_mount(device_info.volume_ptr, G_MOUNT_MOUNT_NONE, nullptr, nullptr, VolumeMountFinished, nullptr);
|
||||
emit DeviceMounted(id, request_id, true);
|
||||
|
||||
}
|
||||
@@ -631,25 +629,25 @@ void GioLister::MountDevice(const QString &id, const int request_id) {
|
||||
void GioLister::UnmountDevice(const QString &id) {
|
||||
|
||||
QMutexLocker l(&mutex_);
|
||||
if (!devices_.contains(id) || !devices_[id].mount_ptr || devices_[id].volume_root_uri.startsWith(QLatin1String("mtp://"))) return;
|
||||
if (!devices_.contains(id) || !devices_[id].mount_ptr || devices_.value(id).volume_root_uri.startsWith(QLatin1String("mtp://"))) return;
|
||||
|
||||
const DeviceInfo &info = devices_[id];
|
||||
const DeviceInfo device_info = devices_.value(id);
|
||||
|
||||
if (!info.mount_ptr) return;
|
||||
if (!device_info.mount_ptr) return;
|
||||
|
||||
if (info.volume_ptr) {
|
||||
if (g_volume_can_eject(info.volume_ptr)) {
|
||||
g_volume_eject_with_operation(info.volume_ptr, G_MOUNT_UNMOUNT_NONE, nullptr, nullptr, reinterpret_cast<GAsyncReadyCallback>(VolumeEjectFinished), nullptr);
|
||||
if (device_info.volume_ptr) {
|
||||
if (g_volume_can_eject(device_info.volume_ptr)) {
|
||||
g_volume_eject_with_operation(device_info.volume_ptr, G_MOUNT_UNMOUNT_NONE, nullptr, nullptr, reinterpret_cast<GAsyncReadyCallback>(VolumeEjectFinished), nullptr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else return;
|
||||
|
||||
if (g_mount_can_eject(info.mount_ptr)) {
|
||||
g_mount_eject_with_operation(info.mount_ptr, G_MOUNT_UNMOUNT_NONE, nullptr, nullptr, reinterpret_cast<GAsyncReadyCallback>(MountEjectFinished), nullptr);
|
||||
if (g_mount_can_eject(device_info.mount_ptr)) {
|
||||
g_mount_eject_with_operation(device_info.mount_ptr, G_MOUNT_UNMOUNT_NONE, nullptr, nullptr, reinterpret_cast<GAsyncReadyCallback>(MountEjectFinished), nullptr);
|
||||
}
|
||||
else if (g_mount_can_unmount(info.mount_ptr)) {
|
||||
g_mount_unmount_with_operation(info.mount_ptr, G_MOUNT_UNMOUNT_NONE, nullptr, nullptr, reinterpret_cast<GAsyncReadyCallback>(MountUnmountFinished), nullptr);
|
||||
else if (g_mount_can_unmount(device_info.mount_ptr)) {
|
||||
g_mount_unmount_with_operation(device_info.mount_ptr, G_MOUNT_UNMOUNT_NONE, nullptr, nullptr, reinterpret_cast<GAsyncReadyCallback>(MountUnmountFinished), nullptr);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ T GioLister::LockAndGetDeviceInfo(const QString &id, T DeviceInfo::*field) {
|
||||
QMutexLocker l(&mutex_);
|
||||
if (!devices_.contains(id)) return T();
|
||||
|
||||
return devices_[id].*field;
|
||||
return devices_.value(id).*field;
|
||||
}
|
||||
|
||||
#endif // GIOLISTER_H
|
||||
|
||||
@@ -74,7 +74,7 @@ QVariantList Udisks2Lister::DeviceIcons(const QString &id) {
|
||||
|
||||
QReadLocker locker(&device_data_lock_);
|
||||
if (!device_data_.contains(id)) return QVariantList();
|
||||
QString path = device_data_[id].mount_paths.at(0);
|
||||
const QString path = device_data_.value(id).mount_paths.value(0);
|
||||
|
||||
return QVariantList() << GuessIconForPath(path) << GuessIconForModel(DeviceManufacturer(id), DeviceModel(id));
|
||||
|
||||
@@ -84,7 +84,7 @@ QString Udisks2Lister::DeviceManufacturer(const QString &id) {
|
||||
|
||||
QReadLocker locker(&device_data_lock_);
|
||||
if (!device_data_.contains(id)) return QLatin1String("");
|
||||
return device_data_[id].vendor;
|
||||
return device_data_.value(id).vendor;
|
||||
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ QString Udisks2Lister::DeviceModel(const QString &id) {
|
||||
|
||||
QReadLocker locker(&device_data_lock_);
|
||||
if (!device_data_.contains(id)) return QLatin1String("");
|
||||
return device_data_[id].model;
|
||||
return device_data_.value(id).model;
|
||||
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ quint64 Udisks2Lister::DeviceCapacity(const QString &id) {
|
||||
|
||||
QReadLocker locker(&device_data_lock_);
|
||||
if (!device_data_.contains(id)) return 0;
|
||||
return device_data_[id].capacity;
|
||||
return device_data_.value(id).capacity;
|
||||
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ quint64 Udisks2Lister::DeviceFreeSpace(const QString &id) {
|
||||
|
||||
QReadLocker locker(&device_data_lock_);
|
||||
if (!device_data_.contains(id)) return 0;
|
||||
return device_data_[id].free_space;
|
||||
return device_data_.value(id).free_space;
|
||||
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ QVariantMap Udisks2Lister::DeviceHardwareInfo(const QString &id) {
|
||||
|
||||
QVariantMap result;
|
||||
|
||||
const PartitionData &data = device_data_[id];
|
||||
const PartitionData data = device_data_.value(id);
|
||||
result[QStringLiteral(QT_TR_NOOP("D-Bus path"))] = data.dbus_path;
|
||||
result[QStringLiteral(QT_TR_NOOP("Serial number"))] = data.serial;
|
||||
result[QStringLiteral(QT_TR_NOOP("Mount points"))] = data.mount_paths.join(QLatin1String(", "));
|
||||
@@ -134,7 +134,7 @@ QString Udisks2Lister::MakeFriendlyName(const QString &id) {
|
||||
|
||||
QReadLocker locker(&device_data_lock_);
|
||||
if (!device_data_.contains(id)) return QLatin1String("");
|
||||
return device_data_[id].friendly_name;
|
||||
return device_data_.value(id).friendly_name;
|
||||
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ void Udisks2Lister::UnmountDevice(const QString &id) {
|
||||
QReadLocker locker(&device_data_lock_);
|
||||
if (!device_data_.contains(id)) return;
|
||||
|
||||
OrgFreedesktopUDisks2FilesystemInterface filesystem(QLatin1String(kUDisks2Service), device_data_[id].dbus_path, QDBusConnection::systemBus());
|
||||
OrgFreedesktopUDisks2FilesystemInterface filesystem(QLatin1String(kUDisks2Service), device_data_.value(id).dbus_path, QDBusConnection::systemBus());
|
||||
|
||||
if (filesystem.isValid()) {
|
||||
auto unmount_result = filesystem.Unmount(QVariantMap());
|
||||
@@ -164,7 +164,7 @@ void Udisks2Lister::UnmountDevice(const QString &id) {
|
||||
return;
|
||||
}
|
||||
|
||||
OrgFreedesktopUDisks2DriveInterface drive(QLatin1String(kUDisks2Service), device_data_[id].dbus_drive_path, QDBusConnection::systemBus());
|
||||
OrgFreedesktopUDisks2DriveInterface drive(QLatin1String(kUDisks2Service), device_data_.value(id).dbus_drive_path, QDBusConnection::systemBus());
|
||||
|
||||
if (drive.isValid()) {
|
||||
auto eject_result = drive.Eject(QVariantMap());
|
||||
@@ -183,7 +183,7 @@ void Udisks2Lister::UnmountDevice(const QString &id) {
|
||||
|
||||
void Udisks2Lister::UpdateDeviceFreeSpace(const QString &id) {
|
||||
QWriteLocker locker(&device_data_lock_);
|
||||
device_data_[id].free_space = Utilities::FileSystemFreeSpace(device_data_[id].mount_paths.at(0));
|
||||
device_data_[id].free_space = Utilities::FileSystemFreeSpace(device_data_.value(id).mount_paths.value(0));
|
||||
emit DeviceChanged(id);
|
||||
}
|
||||
|
||||
@@ -326,11 +326,12 @@ void Udisks2Lister::JobCompleted(const bool success, const QString &message) {
|
||||
|
||||
qLog(Debug) << "Pending Job Completed | Path = " << job->path() << " | Mount? = " << mounting_jobs_[jobPath].is_mount << " | Success = " << success;
|
||||
|
||||
for (const auto &mounted_object : std::as_const(mounting_jobs_[jobPath].mounted_partitions)) {
|
||||
const QList<QDBusObjectPath> mounted_partitions = mounting_jobs_.value(jobPath).mounted_partitions;
|
||||
for (const QDBusObjectPath &mounted_object : mounted_partitions) {
|
||||
auto partition_data = ReadPartitionData(mounted_object);
|
||||
if (partition_data.dbus_path.isEmpty()) continue;
|
||||
|
||||
mounting_jobs_[jobPath].is_mount ? HandleFinishedMountJob(partition_data) : HandleFinishedUnmountJob(partition_data, mounted_object);
|
||||
mounting_jobs_.value(jobPath).is_mount ? HandleFinishedMountJob(partition_data) : HandleFinishedUnmountJob(partition_data, mounted_object);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user