1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-20 14:33:19 +01:00

Fix code review comments from r1530

This commit is contained in:
John Maguire 2010-07-24 19:02:49 +00:00
parent 3cc30db7d4
commit a0fc3e3633

View File

@ -56,14 +56,16 @@ CFTypeRef GetUSBRegistryEntry(io_object_t device, CFStringRef key) {
IOObjectRelease(next); IOObjectRelease(next);
IOObjectRelease(it); IOObjectRelease(it);
return registry_entry; return registry_entry;
} else {
CFTypeRef ret = GetUSBRegistryEntry(next, key);
if (ret) {
IOObjectRelease(next);
IOObjectRelease(it);
return ret;
}
} }
CFTypeRef ret = GetUSBRegistryEntry(next, key);
if (ret) {
IOObjectRelease(next);
IOObjectRelease(it);
return ret;
}
IOObjectRelease(next);
} }
} }
@ -82,7 +84,7 @@ QString GetUSBRegistryEntryString(io_object_t device, CFStringRef key) {
return NULL; return NULL;
} }
quint64 GetUSBRegistryEntryStringInt64(io_object_t device, CFStringRef key) { quint64 GetUSBRegistryEntryInt64(io_object_t device, CFStringRef key) {
CFNumberRef registry_num = (CFNumberRef)GetUSBRegistryEntry(device, key); CFNumberRef registry_num = (CFNumberRef)GetUSBRegistryEntry(device, key);
if (registry_num) { if (registry_num) {
qint64 ret = -1; qint64 ret = -1;
@ -144,6 +146,21 @@ QString GetSerialForDevice(io_object_t device) {
"USB/" + GetUSBRegistryEntryString(device, CFSTR(kUSBSerialNumberString))); "USB/" + GetUSBRegistryEntryString(device, CFSTR(kUSBSerialNumberString)));
} }
QString FindDeviceProperty(const QString& bsd_name, CFStringRef property) {
DASessionRef session = DASessionCreate(kCFAllocatorDefault);
DADiskRef disk = DADiskCreateFromBSDName(
kCFAllocatorDefault, session, bsd_name.toAscii().constData());
io_object_t device = DADiskCopyIOMedia(disk);
QString ret = GetUSBRegistryEntryString(device, property);
IOObjectRelease(device);
CFRelease(disk);
CFRelease(session);
return ret;
}
} }
void MacDeviceLister::DiskAddedCallback(DADiskRef disk, void* context) { void MacDeviceLister::DiskAddedCallback(DADiskRef disk, void* context) {
@ -181,7 +198,7 @@ void MacDeviceLister::DiskRemovedCallback(DADiskRef disk, void* context) {
// the BSD disk name. // the BSD disk name.
for (QMap<QString, QString>::iterator it = me->current_devices_.begin(); for (QMap<QString, QString>::iterator it = me->current_devices_.begin();
it != me->current_devices_.end(); ++it) { it != me->current_devices_.end(); ++it) {
if (it.value() == QString(DADiskGetBSDName(disk))) { if (it.value() == QString::fromLocal8Bit(DADiskGetBSDName(disk))) {
emit me->DeviceRemoved(it.key()); emit me->DeviceRemoved(it.key());
me->current_devices_.erase(it); me->current_devices_.erase(it);
break; break;
@ -203,6 +220,9 @@ QString MacDeviceLister::MakeFriendlyName(const QString& serial) {
CFRelease(disk); CFRelease(disk);
CFRelease(session); CFRelease(session);
if (vendor.isEmpty()) {
return product;
}
return vendor + " " + product; return vendor + " " + product;
} }
@ -217,7 +237,7 @@ QUrl MacDeviceLister::MakeDeviceUrl(const QString& serial) {
[[properties objectForKey:(NSString*)kDADiskDescriptionVolumePathKey] copy]; [[properties objectForKey:(NSString*)kDADiskDescriptionVolumePathKey] copy];
QString path = [[volume_path path] UTF8String]; QString path = [[volume_path path] UTF8String];
QUrl ret = QUrl::fromLocalFile(path); QUrl ret = MakeUrlFromLocalPath(path);
CFRelease(disk); CFRelease(disk);
CFRelease(session); CFRelease(session);
@ -250,35 +270,11 @@ QStringList MacDeviceLister::DeviceIcons(const QString& serial) {
} }
QString MacDeviceLister::DeviceManufacturer(const QString& serial){ QString MacDeviceLister::DeviceManufacturer(const QString& serial){
QString bsd_name = current_devices_[serial]; return FindDeviceProperty(current_devices_[serial], CFSTR(kUSBVendorString));
DASessionRef session = DASessionCreate(kCFAllocatorDefault);
DADiskRef disk = DADiskCreateFromBSDName(
kCFAllocatorDefault, session, bsd_name.toAscii().constData());
io_object_t device = DADiskCopyIOMedia(disk);
QString vendor = GetUSBRegistryEntryString(device, CFSTR(kUSBVendorString));
IOObjectRelease(device);
CFRelease(disk);
CFRelease(session);
return vendor;
} }
QString MacDeviceLister::DeviceModel(const QString& serial){ QString MacDeviceLister::DeviceModel(const QString& serial){
QString bsd_name = current_devices_[serial]; return FindDeviceProperty(current_devices_[serial], CFSTR(kUSBProductString));
DASessionRef session = DASessionCreate(kCFAllocatorDefault);
DADiskRef disk = DADiskCreateFromBSDName(
kCFAllocatorDefault, session, bsd_name.toAscii().constData());
io_object_t device = DADiskCopyIOMedia(disk);
QString product = GetUSBRegistryEntryString(device, CFSTR(kUSBProductString));
IOObjectRelease(device);
CFRelease(disk);
CFRelease(session);
return product;
} }
quint64 MacDeviceLister::DeviceCapacity(const QString& serial){ quint64 MacDeviceLister::DeviceCapacity(const QString& serial){