From f4e5b830396046c590ac401bba283e555d01362f Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Fri, 10 Jun 2022 02:30:39 +0200 Subject: [PATCH] Replace use of C-style casts --- src/core/mac_startup.mm | 15 ++-- src/device/macosdevicelister.mm | 78 +++++++++---------- .../globalshortcutsbackend-macos.mm | 8 +- 3 files changed, 51 insertions(+), 50 deletions(-) diff --git a/src/core/mac_startup.mm b/src/core/mac_startup.mm index 99d13d7a5..1d211da2b 100644 --- a/src/core/mac_startup.mm +++ b/src/core/mac_startup.mm @@ -67,7 +67,7 @@ QDebug operator<<(QDebug dbg, NSObject *object) { - QString ns_format = [ [NSString stringWithFormat:@"%@", object] UTF8String]; + QString ns_format = [[NSString stringWithFormat:@"%@", object] UTF8String]; dbg.nospace() << ns_format; return dbg.space(); @@ -149,11 +149,12 @@ QDebug operator<<(QDebug dbg, NSObject *object) { [[NSAppleEventManager sharedAppleEventManager] setEventHandler:self andSelector:@selector(handleURLEvent:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL]; - key_tap_ = [ [SPMediaKeyTap alloc] initWithDelegate:self]; + key_tap_ = [[SPMediaKeyTap alloc] initWithDelegate:self]; if ([SPMediaKeyTap usesGlobalMediaKeyTap]) { if ([key_tap_ startWatchingMediaKeys]) { qLog(Debug) << "Media key monitoring started"; - } else { + } + else { qLog(Warning) << "Failed to start media key monitoring"; } } @@ -181,7 +182,7 @@ QDebug operator<<(QDebug dbg, NSObject *object) { qLog(Debug) << "Wants to open:" << filenames; [filenames enumerateObjectsUsingBlock:^(id object, NSUInteger, BOOL*) { - [self application:app openFile:(NSString*)object]; + [self application:app openFile:reinterpret_cast(object)]; }]; } @@ -254,7 +255,7 @@ QDebug operator<<(QDebug dbg, NSObject *object) { - (void)SetApplicationHandler:(PlatformInterface*)handler { - delegate_ = [ [AppDelegate alloc] initWithHandler:handler]; + delegate_ = [[AppDelegate alloc] initWithHandler:handler]; // App-shortcut-handler set before delegate is set. // this makes sure the delegate's shortcut_handler is set [delegate_ setShortcutHandler:shortcut_handler_]; @@ -263,7 +264,7 @@ QDebug operator<<(QDebug dbg, NSObject *object) { // FIXME #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" - [ [NSUserNotificationCenter defaultUserNotificationCenter]setDelegate:delegate_]; + [[NSUserNotificationCenter defaultUserNotificationCenter]setDelegate:delegate_]; #pragma GCC diagnostic pop } @@ -402,7 +403,7 @@ QKeySequence KeySequenceFromNSEvent(NSEvent *event) { void DumpDictionary(CFDictionaryRef dict) { - NSDictionary *d = (NSDictionary*)dict; + NSDictionary *d = reinterpret_cast(dict); NSLog(@"%@", d); } diff --git a/src/device/macosdevicelister.mm b/src/device/macosdevicelister.mm index fbfb5201f..4744bbb4b 100644 --- a/src/device/macosdevicelister.mm +++ b/src/device/macosdevicelister.mm @@ -212,7 +212,7 @@ CFTypeRef GetUSBRegistryEntry(io_object_t device, CFStringRef key) { if (IORegistryEntryGetParentIterator(device, kIOServicePlane, &it) == KERN_SUCCESS) { io_object_t next; while ((next = IOIteratorNext(it))) { - CFTypeRef registry_entry = (CFStringRef)IORegistryEntryCreateCFProperty(next, key, kCFAllocatorDefault, 0); + CFTypeRef registry_entry = reinterpret_cast(IORegistryEntryCreateCFProperty(next, key, kCFAllocatorDefault, 0)); if (registry_entry) { IOObjectRelease(next); IOObjectRelease(it); @@ -235,9 +235,9 @@ CFTypeRef GetUSBRegistryEntry(io_object_t device, CFStringRef key) { } QString GetUSBRegistryEntryString(io_object_t device, CFStringRef key) { - ScopedCFTypeRef registry_string((CFStringRef)GetUSBRegistryEntry(device, key)); + ScopedCFTypeRef registry_string(reinterpret_cast(GetUSBRegistryEntry(device, key))); if (registry_string) { - return QString::fromUtf8([(NSString*)registry_string.get() UTF8String]); + return QString::fromUtf8([reinterpret_cast(registry_string.get()) UTF8String]); } return QString(); @@ -252,8 +252,8 @@ NSObject *GetPropertyForDevice(io_object_t device, CFStringRef key) { return nil; } - scoped_nsobject dict((NSDictionary*)properties); // Takes ownership. - NSObject *prop = [dict objectForKey:(NSString*)key]; + scoped_nsobject dict(reinterpret_cast(properties)); // Takes ownership. + NSObject *prop = [dict objectForKey:reinterpret_cast(key)]; if (prop) { // The dictionary goes out of scope so we should retain this object. [prop retain]; @@ -278,7 +278,7 @@ int GetUSBDeviceClass(io_object_t device) { CFSTR(kUSBInterfaceClass), kCFAllocatorDefault, kIORegistryIterateRecursively)); - NSNumber *number = (NSNumber*)interface_class.get(); + NSNumber *number = reinterpret_cast(interface_class.get()); if (number) { int ret = [number unsignedShortValue]; return ret; @@ -289,14 +289,14 @@ int GetUSBDeviceClass(io_object_t device) { QString GetIconForDevice(io_object_t device) { - scoped_nsobject media_icon((NSDictionary*)GetPropertyForDevice(device, CFSTR("IOMediaIcon"))); + scoped_nsobject media_icon(reinterpret_cast(GetPropertyForDevice(device, CFSTR("IOMediaIcon")))); if (media_icon) { - NSString *bundle = (NSString*)[media_icon objectForKey:@"CFBundleIdentifier"]; - NSString *file = (NSString*)[media_icon objectForKey:@"IOBundleResourceFile"]; + NSString *bundle = reinterpret_cast([media_icon objectForKey:@"CFBundleIdentifier"]); + NSString *file = reinterpret_cast([media_icon objectForKey:@"IOBundleResourceFile"]); - scoped_nsobject bundle_url((NSURL*)KextManagerCreateURLForBundleIdentifier(kCFAllocatorDefault, (CFStringRef)bundle)); + scoped_nsobject bundle_url(reinterpret_cast(KextManagerCreateURLForBundleIdentifier(kCFAllocatorDefault, reinterpret_cast(bundle)))); - QString path = QString::fromUtf8([ [bundle_url path] UTF8String]); + QString path = QString::fromUtf8([[bundle_url path] UTF8String]); path += "/Contents/Resources/"; path += QString::fromUtf8([file UTF8String]); return path; @@ -318,7 +318,7 @@ QString GetSerialForDevice(io_object_t device) { QString GetSerialForMTPDevice(io_object_t device) { - scoped_nsobject serial((NSString*) GetPropertyForDevice(device, CFSTR(kUSBSerialNumberString))); + scoped_nsobject serial(reinterpret_cast(GetPropertyForDevice(device, CFSTR(kUSBSerialNumberString)))); return QString(QString("MTP/") + QString::fromUtf8([serial UTF8String])); } @@ -376,9 +376,9 @@ void MacOsDeviceLister::DiskAddedCallback(DADiskRef disk, void *context) { MacOsDeviceLister *me = reinterpret_cast(context); - scoped_nsobject properties((NSDictionary*)DADiskCopyDescription(disk)); + scoped_nsobject properties(reinterpret_cast(DADiskCopyDescription(disk))); - NSString *kind = [properties objectForKey:(NSString*)kDADiskDescriptionMediaKindKey]; + NSString *kind = [properties objectForKey:reinterpret_cast(kDADiskDescriptionMediaKindKey)]; #ifdef HAVE_AUDIOCD if (kind && strcmp([kind UTF8String], kIOCDMediaClass) == 0) { // CD inserted. @@ -389,7 +389,7 @@ void MacOsDeviceLister::DiskAddedCallback(DADiskRef disk, void *context) { } #endif - NSURL *volume_path = [ [properties objectForKey:(NSString*)kDADiskDescriptionVolumePathKey] copy]; + NSURL *volume_path = [[properties objectForKey:reinterpret_cast(kDADiskDescriptionVolumePathKey)] copy]; if (volume_path) { ScopedIOObject device(DADiskCopyIOMedia(disk)); @@ -402,8 +402,8 @@ void MacOsDeviceLister::DiskAddedCallback(DADiskRef disk, void *context) { kern_return_t ret = IORegistryEntryCreateCFProperties(device.get(), &cf_properties, kCFAllocatorDefault, 0); if (ret == KERN_SUCCESS) { - scoped_nsobject dict((NSDictionary*)cf_properties); // Takes ownership. - if ([ [dict objectForKey:@"Removable"] intValue] == 1) { + scoped_nsobject dict(reinterpret_cast(cf_properties)); // Takes ownership. + if ([[dict objectForKey:@"Removable"] intValue] == 1) { QString serial = GetSerialForDevice(device.get()); if (!serial.isEmpty()) { me->current_devices_[serial] = QString(DADiskGetBSDName(disk)); @@ -475,7 +475,7 @@ int GetBusNumber(io_object_t o) { while ((o = IOIteratorNext(it))) { NSObject *bus = GetPropertyForDevice(o, CFSTR("USBBusNumber")); if (bus) { - NSNumber *bus_num = (NSNumber*)bus; + NSNumber *bus_num = reinterpret_cast(bus); return [bus_num intValue]; } } @@ -497,10 +497,10 @@ void MacOsDeviceLister::USBDeviceAddedCallback(void *refcon, io_iterator_t it) { BOOST_SCOPE_EXIT_END if (CFStringCompare(class_name.get(), CFSTR(kIOUSBDeviceClassName), 0) == kCFCompareEqualTo) { - NSString *vendor = (NSString*)GetPropertyForDevice(object, CFSTR(kUSBVendorString)); - NSString *product = (NSString*)GetPropertyForDevice(object, CFSTR(kUSBProductString)); - NSNumber *vendor_id = (NSNumber*)GetPropertyForDevice(object, CFSTR(kUSBVendorID)); - NSNumber *product_id = (NSNumber*)GetPropertyForDevice(object, CFSTR(kUSBProductID)); + NSString *vendor = reinterpret_cast(GetPropertyForDevice(object, CFSTR(kUSBVendorString))); + NSString *product = reinterpret_cast(GetPropertyForDevice(object, CFSTR(kUSBProductString))); + NSNumber *vendor_id = reinterpret_cast(GetPropertyForDevice(object, CFSTR(kUSBVendorID))); + NSNumber *product_id = reinterpret_cast(GetPropertyForDevice(object, CFSTR(kUSBProductID))); int interface_class = GetUSBDeviceClass(object); qLog(Debug) << "Interface class:" << interface_class; @@ -528,7 +528,7 @@ void MacOsDeviceLister::USBDeviceAddedCallback(void *refcon, io_iterator_t it) { continue; } - NSNumber *addr = (NSNumber*)GetPropertyForDevice(object, CFSTR("USB Address")); + NSNumber *addr = reinterpret_cast(GetPropertyForDevice(object, CFSTR("USB Address"))); int bus = GetBusNumber(object); if (!addr || bus == -1) { // Failed to get bus or address number. @@ -559,7 +559,7 @@ void MacOsDeviceLister::USBDeviceAddedCallback(void *refcon, io_iterator_t it) { } IOUSBDeviceInterface **dev = nullptr; - HRESULT result = (*plugin_interface)->QueryInterface(plugin_interface, CFUUIDGetUUIDBytes(kIOUSBDeviceInterfaceID), (LPVOID*)&dev); + HRESULT result = (*plugin_interface)->QueryInterface(plugin_interface, CFUUIDGetUUIDBytes(kIOUSBDeviceInterfaceID), reinterpret_cast(&dev)); (*plugin_interface)->Release(plugin_interface); @@ -633,10 +633,10 @@ void MacOsDeviceLister::USBDeviceRemovedCallback(void *refcon, io_iterator_t it) BOOST_SCOPE_EXIT_END if (CFStringCompare(class_name.get(), CFSTR(kIOUSBDeviceClassName), 0) == kCFCompareEqualTo) { - NSString *vendor = (NSString*)GetPropertyForDevice(object, CFSTR(kUSBVendorString)); - NSString *product = (NSString*)GetPropertyForDevice(object, CFSTR(kUSBProductString)); - NSNumber *vendor_id = (NSNumber*)GetPropertyForDevice(object, CFSTR(kUSBVendorID)); - NSNumber *product_id = (NSNumber*)GetPropertyForDevice(object, CFSTR(kUSBProductID)); + NSString *vendor = reinterpret_cast(GetPropertyForDevice(object, CFSTR(kUSBVendorString))); + NSString *product = reinterpret_cast(GetPropertyForDevice(object, CFSTR(kUSBProductString))); + NSNumber *vendor_id = reinterpret_cast(GetPropertyForDevice(object, CFSTR(kUSBVendorID))); + NSNumber *product_id = reinterpret_cast(GetPropertyForDevice(object, CFSTR(kUSBProductID))); QString serial = GetSerialForMTPDevice(object); MTPDevice device; @@ -696,8 +696,8 @@ QString MacOsDeviceLister::MakeFriendlyName(const QString &serial) { ScopedCFTypeRef disk(DADiskCreateFromBSDName(kCFAllocatorDefault, session.get(), bsd_name.toLatin1().constData())); if (IsCDDevice(serial)) { - scoped_nsobject properties((NSDictionary*)DADiskCopyDescription(disk.get())); - NSString *device_name = (NSString*)[properties.get() objectForKey:(NSString*)kDADiskDescriptionMediaNameKey]; + scoped_nsobject properties(reinterpret_cast(DADiskCopyDescription(disk.get()))); + NSString *device_name = reinterpret_cast([properties.get() objectForKey:reinterpret_cast(kDADiskDescriptionMediaNameKey)]); return QString::fromUtf8([device_name UTF8String]); } @@ -738,10 +738,10 @@ QList MacOsDeviceLister::MakeDeviceUrls(const QString &serial) { ScopedCFTypeRef session(DASessionCreate(kCFAllocatorDefault)); ScopedCFTypeRef disk(DADiskCreateFromBSDName(kCFAllocatorDefault, session.get(), bsd_name.toLatin1().constData())); - scoped_nsobject properties((NSDictionary*)DADiskCopyDescription(disk.get())); - scoped_nsobject volume_path([ [properties objectForKey:(NSString*)kDADiskDescriptionVolumePathKey] copy]); + scoped_nsobject properties(reinterpret_cast(DADiskCopyDescription(disk.get()))); + scoped_nsobject volume_path([[properties objectForKey:reinterpret_cast(kDADiskDescriptionVolumePathKey)] copy]); - QString path = QString::fromUtf8([ [volume_path path] UTF8String]); + QString path = QString::fromUtf8([[volume_path path] UTF8String]); QUrl ret = MakeUrlFromLocalPath(path); return QList() << ret; @@ -769,10 +769,10 @@ QVariantList MacOsDeviceLister::DeviceIcons(const QString &serial) { ScopedIOObject device(DADiskCopyIOMedia(disk.get())); QString icon = GetIconForDevice(device.get()); - scoped_nsobject properties((NSDictionary*)DADiskCopyDescription(disk)); - scoped_nsobject volume_path([ [properties objectForKey:(NSString*)kDADiskDescriptionVolumePathKey] copy]); + scoped_nsobject properties(reinterpret_cast(DADiskCopyDescription(disk))); + scoped_nsobject volume_path([[properties objectForKey:reinterpret_cast(kDADiskDescriptionVolumePathKey)] copy]); - QString path = QString::fromUtf8([ [volume_path path] UTF8String]); + QString path = QString::fromUtf8([[volume_path path] UTF8String]); QVariantList ret; ret << GuessIconForPath(path); @@ -810,7 +810,7 @@ quint64 MacOsDeviceLister::DeviceCapacity(const QString &serial) { io_object_t device = DADiskCopyIOMedia(disk); - NSNumber *capacity = (NSNumber*)GetPropertyForDevice(device, CFSTR("Size")); + NSNumber *capacity = reinterpret_cast(GetPropertyForDevice(device, CFSTR("Size"))); quint64 ret = [capacity unsignedLongLongValue]; @@ -830,8 +830,8 @@ quint64 MacOsDeviceLister::DeviceFreeSpace(const QString &serial) { ScopedCFTypeRef session(DASessionCreate(kCFAllocatorDefault)); ScopedCFTypeRef disk(DADiskCreateFromBSDName(kCFAllocatorDefault, session.get(), bsd_name.toLatin1().constData())); - scoped_nsobject properties((NSDictionary*)DADiskCopyDescription(disk)); - scoped_nsobject volume_path([ [properties objectForKey:(NSString*)kDADiskDescriptionVolumePathKey] copy]); + scoped_nsobject properties(reinterpret_cast(DADiskCopyDescription(disk))); + scoped_nsobject volume_path([[properties objectForKey:reinterpret_cast(kDADiskDescriptionVolumePathKey)] copy]); NSNumber *value = nil; NSError *error = nil; diff --git a/src/globalshortcuts/globalshortcutsbackend-macos.mm b/src/globalshortcuts/globalshortcutsbackend-macos.mm index b40753daf..9c9d23f02 100644 --- a/src/globalshortcuts/globalshortcutsbackend-macos.mm +++ b/src/globalshortcuts/globalshortcutsbackend-macos.mm @@ -137,8 +137,8 @@ bool GlobalShortcutsBackendMacOS::KeyPressed(const QKeySequence &sequence) { bool GlobalShortcutsBackendMacOS::IsAccessibilityEnabled() { - NSDictionary *options = @{(id)kAXTrustedCheckOptionPrompt: @YES}; - return AXIsProcessTrustedWithOptions((CFDictionaryRef)options); + NSDictionary *options = @{reinterpret_cast(kAXTrustedCheckOptionPrompt): @YES}; + return AXIsProcessTrustedWithOptions(reinterpret_cast(options)); } @@ -152,7 +152,7 @@ void GlobalShortcutsBackendMacOS::ShowAccessibilityDialog() { SBElementArray *panes = [system_prefs panes]; SBSystemPreferencesPane *security_pane = nil; for (SBSystemPreferencesPane *pane : panes) { - if ([ [pane id] isEqualToString:@"com.apple.preference.security"]) { + if ([[pane id] isEqualToString:@"com.apple.preference.security"]) { security_pane = pane; break; } @@ -161,7 +161,7 @@ void GlobalShortcutsBackendMacOS::ShowAccessibilityDialog() { SBElementArray *anchors = [security_pane anchors]; for (SBSystemPreferencesAnchor *anchor : anchors) { - if ([ [anchor name] isEqualToString:@"Privacy_Accessibility"]) { + if ([[anchor name] isEqualToString:@"Privacy_Accessibility"]) { [anchor reveal]; } }