[macOS] Apply ObjC modernizations once again. (#3358)

This doesn't include designated initializers refactoring.
This commit is contained in:
Dzmitry Neviadomski 2022-06-29 07:20:42 +03:00 committed by GitHub
parent 88a3149ce4
commit 37f7f83d4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 59 additions and 58 deletions

View File

@ -75,7 +75,7 @@
self.fNameField.toolTip = name; self.fNameField.toolTip = name;
//disable fullscreen support //disable fullscreen support
[self.window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenNone]; self.window.collectionBehavior = NSWindowCollectionBehaviorFullScreenNone;
[self setGroupsMenu]; [self setGroupsMenu];
[self.fGroupPopUp selectItemWithTag:self.fGroupValue]; [self.fGroupPopUp selectItemWithTag:self.fGroupValue];

View File

@ -107,7 +107,7 @@
self.fNameField.toolTip = name; self.fNameField.toolTip = name;
//disable fullscreen support //disable fullscreen support
[self.window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenNone]; self.window.collectionBehavior = NSWindowCollectionBehaviorFullScreenNone;
self.fIconView.image = self.torrent.icon; self.fIconView.image = self.torrent.icon;
@ -233,7 +233,7 @@
[alert addButtonWithTitle:NSLocalizedString(@"Add", "Add torrent -> same name -> button")]; [alert addButtonWithTitle:NSLocalizedString(@"Add", "Add torrent -> same name -> button")];
alert.showsSuppressionButton = YES; alert.showsSuppressionButton = YES;
[alert beginSheetModalForWindow:[self window] completionHandler:^(NSModalResponse returnCode) { [alert beginSheetModalForWindow:self.window completionHandler:^(NSModalResponse returnCode) {
if (alert.suppressionButton.state == NSControlStateValueOn) if (alert.suppressionButton.state == NSControlStateValueOn)
{ {
[NSUserDefaults.standardUserDefaults setBool:NO forKey:@"WarningFolderDataSameName"]; [NSUserDefaults.standardUserDefaults setBool:NO forKey:@"WarningFolderDataSameName"];

View File

@ -249,7 +249,7 @@ BlocklistDownloader* fBLDownloader = nil;
return NO; return NO;
} }
NSURL* destinationDir = [destination URLByDeletingLastPathComponent]; NSURL* destinationDir = destination.URLByDeletingLastPathComponent;
NSTask* untar = [[NSTask alloc] init]; NSTask* untar = [[NSTask alloc] init];
untar.launchPath = @"/usr/bin/tar"; untar.launchPath = @"/usr/bin/tar";
@ -279,7 +279,7 @@ BlocklistDownloader* fBLDownloader = nil;
- (BOOL)gunzipFrom:(NSURL*)file to:(NSURL*)destination - (BOOL)gunzipFrom:(NSURL*)file to:(NSURL*)destination
{ {
NSURL* destinationDir = [destination URLByDeletingLastPathComponent]; NSURL* destinationDir = destination.URLByDeletingLastPathComponent;
NSTask* gunzip = [[NSTask alloc] init]; NSTask* gunzip = [[NSTask alloc] init];
gunzip.launchPath = @"/usr/bin/gunzip"; gunzip.launchPath = @"/usr/bin/gunzip";
@ -301,7 +301,7 @@ BlocklistDownloader* fBLDownloader = nil;
return NO; return NO;
} }
NSURL* result = [file URLByDeletingPathExtension]; NSURL* result = file.URLByDeletingPathExtension;
[NSFileManager.defaultManager moveItemAtURL:result toURL:destination error:nil]; [NSFileManager.defaultManager moveItemAtURL:result toURL:destination error:nil];
return YES; return YES;
@ -348,7 +348,7 @@ BlocklistDownloader* fBLDownloader = nil;
return NO; return NO;
} }
NSURL* destinationDir = [destination URLByDeletingLastPathComponent]; NSURL* destinationDir = destination.URLByDeletingLastPathComponent;
NSTask* unzip = [[NSTask alloc] init]; NSTask* unzip = [[NSTask alloc] init];
unzip.launchPath = @"/usr/bin/unzip"; unzip.launchPath = @"/usr/bin/unzip";

View File

@ -133,7 +133,7 @@ BlocklistDownloaderViewController* fBLViewController = nil;
[NSBundle.mainBundle loadNibNamed:@"BlocklistStatusWindow" owner:self topLevelObjects:NULL]; [NSBundle.mainBundle loadNibNamed:@"BlocklistStatusWindow" owner:self topLevelObjects:NULL];
BlocklistDownloader* downloader = [BlocklistDownloader downloader]; BlocklistDownloader* downloader = [BlocklistDownloader downloader];
[downloader setViewController:self]; //do before showing the sheet to ensure it doesn't slide out with placeholder text downloader.viewController = self; //do before showing the sheet to ensure it doesn't slide out with placeholder text
[self.fPrefsController.window beginSheet:self.fStatusWindow completionHandler:nil]; [self.fPrefsController.window beginSheet:self.fStatusWindow completionHandler:nil];
} }

View File

@ -168,7 +168,7 @@ typedef NS_ENUM(unsigned int, addType) { //
@property(nonatomic, readonly) CGFloat toolbarHeight; @property(nonatomic, readonly) CGFloat toolbarHeight;
@property(nonatomic, readonly) CGFloat mainWindowComponentHeight; @property(nonatomic, readonly) CGFloat mainWindowComponentHeight;
@property(nonatomic, readonly) CGFloat scrollViewHeight; @property(nonatomic, readonly) CGFloat scrollViewHeight;
- (BOOL)isFullScreen; @property(nonatomic, getter=isFullScreen, readonly) BOOL fullScreen;
- (void)updateForExpandCollapse; - (void)updateForExpandCollapse;

View File

@ -122,7 +122,7 @@ typedef NS_ENUM(unsigned int, sortOrderTag) { //
static void altSpeedToggledCallback([[maybe_unused]] tr_session* handle, bool active, bool byUser, void* controller) static void altSpeedToggledCallback([[maybe_unused]] tr_session* handle, bool active, bool byUser, void* controller)
{ {
NSDictionary* dict = [[NSDictionary alloc] initWithObjects:@[ @(active), @(byUser) ] forKeys:@[ @"Active", @"ByUser" ]]; NSDictionary* dict = @{@"Active" : @(active), @"ByUser" : @(byUser)};
[(__bridge Controller*)controller performSelectorOnMainThread:@selector(altSpeedToggledCallbackIsLimited:) withObject:dict [(__bridge Controller*)controller performSelectorOnMainThread:@selector(altSpeedToggledCallbackIsLimited:) withObject:dict
waitUntilDone:NO]; waitUntilDone:NO];
} }
@ -512,7 +512,7 @@ static void removeKeRangerRansomware()
_fLib = tr_sessionInit(configDir, YES, &settings); _fLib = tr_sessionInit(configDir, YES, &settings);
tr_variantFree(&settings); tr_variantFree(&settings);
_fConfigDirectory = [[NSString alloc] initWithUTF8String:configDir]; _fConfigDirectory = @(configDir);
NSApp.delegate = self; NSApp.delegate = self;
@ -569,7 +569,7 @@ static void removeKeRangerRansomware()
self.fWindow.excludedFromWindowsMenu = YES; self.fWindow.excludedFromWindowsMenu = YES;
//make window primary view in fullscreen //make window primary view in fullscreen
[self.fWindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary]; self.fWindow.collectionBehavior = NSWindowCollectionBehaviorFullScreenPrimary;
//set table size //set table size
BOOL const small = [self.fDefaults boolForKey:@"SmallView"]; BOOL const small = [self.fDefaults boolForKey:@"SmallView"];
@ -1021,7 +1021,7 @@ static void removeKeRangerRansomware()
NSString* message = [NSString NSString* message = [NSString
stringWithFormat:NSLocalizedString(@"It appears that the file \"%@\" from %@ is not a torrent file.", "Download not a torrent -> message"), stringWithFormat:NSLocalizedString(@"It appears that the file \"%@\" from %@ is not a torrent file.", "Download not a torrent -> message"),
suggestedName, suggestedName,
[download.request.URL.absoluteString stringByRemovingPercentEncoding]]; download.request.URL.absoluteString.stringByRemovingPercentEncoding];
NSAlert* alert = [[NSAlert alloc] init]; NSAlert* alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:NSLocalizedString(@"OK", "Download not a torrent -> button")]; [alert addButtonWithTitle:NSLocalizedString(@"OK", "Download not a torrent -> button")];
@ -1046,7 +1046,7 @@ static void removeKeRangerRansomware()
{ {
NSString* message = [NSString NSString* message = [NSString
stringWithFormat:NSLocalizedString(@"The torrent could not be downloaded from %@: %@.", "Torrent download failed -> message"), stringWithFormat:NSLocalizedString(@"The torrent could not be downloaded from %@: %@.", "Torrent download failed -> message"),
[download.request.URL.absoluteString stringByRemovingPercentEncoding], download.request.URL.absoluteString.stringByRemovingPercentEncoding,
error.localizedDescription]; error.localizedDescription];
NSAlert* alert = [[NSAlert alloc] init]; NSAlert* alert = [[NSAlert alloc] init];
@ -1351,7 +1351,7 @@ static void removeKeRangerRansomware()
//called on by applescript //called on by applescript
- (void)open:(NSArray*)files - (void)open:(NSArray*)files
{ {
NSDictionary* dict = [[NSDictionary alloc] initWithObjects:@[ files, @(ADD_MANUAL) ] forKeys:@[ @"Filenames", @"AddType" ]]; NSDictionary* dict = @{ @"Filenames" : files, @"AddType" : @(ADD_MANUAL) };
[self performSelectorOnMainThread:@selector(openFilesWithDict:) withObject:dict waitUntilDone:NO]; [self performSelectorOnMainThread:@selector(openFilesWithDict:) withObject:dict waitUntilDone:NO];
} }
@ -1374,9 +1374,10 @@ static void removeKeRangerRansomware()
[filenames addObject:url.path]; [filenames addObject:url.path];
} }
NSDictionary* dictionary = [[NSDictionary alloc] NSDictionary* dictionary = @{
initWithObjects:@[ filenames, sender == self.fOpenIgnoreDownloadFolder ? @(ADD_SHOW_OPTIONS) : @(ADD_MANUAL) ] @"Filenames" : filenames,
forKeys:@[ @"Filenames", @"AddType" ]]; @"AddType" : sender == self.fOpenIgnoreDownloadFolder ? @(ADD_SHOW_OPTIONS) : @(ADD_MANUAL)
};
[self performSelectorOnMainThread:@selector(openFilesWithDict:) withObject:dictionary waitUntilDone:NO]; [self performSelectorOnMainThread:@selector(openFilesWithDict:) withObject:dictionary waitUntilDone:NO];
} }
}]; }];
@ -1552,7 +1553,7 @@ static void removeKeRangerRansomware()
[self.fWindow beginSheet:self.fUrlSheetController.window completionHandler:^(NSModalResponse returnCode) { [self.fWindow beginSheet:self.fUrlSheetController.window completionHandler:^(NSModalResponse returnCode) {
if (returnCode == 1) if (returnCode == 1)
{ {
NSString* urlString = [self.fUrlSheetController urlString]; NSString* urlString = self.fUrlSheetController.urlString;
urlString = [urlString stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet]; urlString = [urlString stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[self openURL:urlString]; [self openURL:urlString];

View File

@ -141,7 +141,7 @@ NSMutableSet* creatorWindowControllerSet = nil;
//remove potentially invalid addresses //remove potentially invalid addresses
for (NSInteger i = _fTrackers.count - 1; i >= 0; i--) for (NSInteger i = _fTrackers.count - 1; i >= 0; i--)
{ {
if (!tr_urlIsValidTracker([_fTrackers[i] UTF8String])) if (!tr_urlIsValidTracker(_fTrackers[i].UTF8String))
{ {
[_fTrackers removeObjectAtIndex:i]; [_fTrackers removeObjectAtIndex:i];
} }
@ -161,7 +161,7 @@ NSMutableSet* creatorWindowControllerSet = nil;
self.window.title = name; self.window.title = name;
//disable fullscreen support //disable fullscreen support
[self.window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenNone]; self.window.collectionBehavior = NSWindowCollectionBehaviorFullScreenNone;
self.fNameField.stringValue = name; self.fNameField.stringValue = name;
self.fNameField.toolTip = self.fPath.path; self.fNameField.toolTip = self.fPath.path;
@ -191,7 +191,7 @@ NSMutableSet* creatorWindowControllerSet = nil;
self.fStatusField.stringValue = statusString; self.fStatusField.stringValue = statusString;
[self updatePiecesField]; [self updatePiecesField];
[self.fPieceSizeStepper setIntValue:(int)log2((double)self.fInfo->pieceSize)]; self.fPieceSizeStepper.intValue = (int)log2((double)self.fInfo->pieceSize);
self.fLocation = [[self.fDefaults URLForKey:@"CreatorLocationURL"] self.fLocation = [[self.fDefaults URLForKey:@"CreatorLocationURL"]
URLByAppendingPathComponent:[name stringByAppendingPathExtension:@"torrent"]]; URLByAppendingPathComponent:[name stringByAppendingPathExtension:@"torrent"]];
@ -601,14 +601,14 @@ NSMutableSet* creatorWindowControllerSet = nil;
for (NSUInteger i = 0; i < self.fTrackers.count; i++) for (NSUInteger i = 0; i < self.fTrackers.count; i++)
{ {
trackerInfo[i].announce = (char*)[self.fTrackers[i] UTF8String]; trackerInfo[i].announce = (char*)(self.fTrackers[i]).UTF8String;
trackerInfo[i].tier = i; trackerInfo[i].tier = i;
} }
//store values //store values
[self.fDefaults setObject:self.fTrackers forKey:@"CreatorTrackers"]; [self.fDefaults setObject:self.fTrackers forKey:@"CreatorTrackers"];
[self.fDefaults setBool:self.fPrivateCheck.state == NSControlStateValueOn forKey:@"CreatorPrivate"]; [self.fDefaults setBool:self.fPrivateCheck.state == NSControlStateValueOn forKey:@"CreatorPrivate"];
[self.fDefaults setObject:[self.fSource stringValue] forKey:@"CreatorSource"]; [self.fDefaults setObject:self.fSource.stringValue forKey:@"CreatorSource"];
[self.fDefaults setBool:self.fOpenCheck.state == NSControlStateValueOn forKey:@"CreatorOpen"]; [self.fDefaults setBool:self.fOpenCheck.state == NSControlStateValueOn forKey:@"CreatorOpen"];
self.fOpenWhenCreated = self.fOpenCheck.state == self.fOpenWhenCreated = self.fOpenCheck.state ==
NSControlStateValueOn; //need this since the check box might not exist, and value in prefs might have changed from another creator window NSControlStateValueOn; //need this since the check box might not exist, and value in prefs might have changed from another creator window

View File

@ -67,7 +67,7 @@
self.window.title = NSLocalizedString(@"Message Log", "Message window -> title"); self.window.title = NSLocalizedString(@"Message Log", "Message window -> title");
//disable fullscreen support //disable fullscreen support
[window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenNone]; window.collectionBehavior = NSWindowCollectionBehaviorFullScreenNone;
//set images and text for popup button items //set images and text for popup button items
[self.fLevelButton itemAtIndex:LEVEL_ERROR].title = NSLocalizedString(@"Error", "Message window -> level string"); [self.fLevelButton itemAtIndex:LEVEL_ERROR].title = NSLocalizedString(@"Error", "Message window -> level string");

View File

@ -21,7 +21,7 @@
bp.lineWidth = BORDER_WIDTH; bp.lineWidth = BORDER_WIDTH;
//border //border
CGFloat fractionOfBlendedColor = [NSApp isDarkMode] ? 0.15 : 0.3; CGFloat fractionOfBlendedColor = NSApp.darkMode ? 0.15 : 0.3;
NSColor* borderColor = [color blendedColorWithFraction:fractionOfBlendedColor ofColor:NSColor.controlTextColor]; NSColor* borderColor = [color blendedColorWithFraction:fractionOfBlendedColor ofColor:NSColor.controlTextColor];
[borderColor setStroke]; [borderColor setStroke];
[bp stroke]; [bp stroke];

View File

@ -7,7 +7,7 @@
@interface NSString (NSStringAdditions) @interface NSString (NSStringAdditions)
@property(nonatomic, class, readonly) NSString* ellipsis; @property(nonatomic, class, readonly) NSString* ellipsis;
- (NSString*)stringByAppendingEllipsis; @property(nonatomic, readonly, copy) NSString* stringByAppendingEllipsis;
+ (NSString*)formattedUInteger:(NSUInteger)value; + (NSString*)formattedUInteger:(NSUInteger)value;

View File

@ -51,7 +51,7 @@ enum
- (void)viewDidChangeEffectiveAppearance - (void)viewDidChangeEffectiveAppearance
{ {
[self setTorrent:_torrent]; self.torrent = _torrent;
[self updateView]; [self updateView];
} }
@ -122,7 +122,7 @@ enum
NSRect fillRects[self.fNumPieces]; NSRect fillRects[self.fNumPieces];
NSColor* fillColors[self.fNumPieces]; NSColor* fillColors[self.fNumPieces];
NSColor* defaultColor = [NSApp isDarkMode] ? NSColor.blackColor : NSColor.whiteColor; NSColor* defaultColor = NSApp.darkMode ? NSColor.blackColor : NSColor.whiteColor;
NSInteger usedCount = 0; NSInteger usedCount = 0;

View File

@ -199,7 +199,7 @@
self.window.restorationClass = [self class]; self.window.restorationClass = [self class];
//disable fullscreen support //disable fullscreen support
[self.window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenNone]; self.window.collectionBehavior = NSWindowCollectionBehaviorFullScreenNone;
NSToolbar* toolbar = [[NSToolbar alloc] initWithIdentifier:@"Preferences Toolbar"]; NSToolbar* toolbar = [[NSToolbar alloc] initWithIdentifier:@"Preferences Toolbar"];
toolbar.delegate = self; toolbar.delegate = self;
@ -1119,7 +1119,7 @@
tr_sessionSetRPCPassword(self.fHandle, fullPassword); tr_sessionSetRPCPassword(self.fHandle, fullPassword);
self.fRPCPassword = [[NSString alloc] initWithUTF8String:fullPassword]; self.fRPCPassword = @(fullPassword);
self.fRPCPasswordField.stringValue = self.fRPCPassword; self.fRPCPasswordField.stringValue = self.fRPCPassword;
} }
else else

View File

@ -9,7 +9,7 @@
+ (NSGradient*)progressWhiteGradient + (NSGradient*)progressWhiteGradient
{ {
if ([NSApp isDarkMode]) if (NSApp.darkMode)
{ {
return [[self class] progressGradientForRed:0.1 green:0.1 blue:0.1]; return [[self class] progressGradientForRed:0.1 green:0.1 blue:0.1];
} }
@ -21,7 +21,7 @@
+ (NSGradient*)progressGrayGradient + (NSGradient*)progressGrayGradient
{ {
if ([NSApp isDarkMode]) if (NSApp.darkMode)
{ {
return [[self class] progressGradientForRed:0.35 green:0.35 blue:0.35]; return [[self class] progressGradientForRed:0.35 green:0.35 blue:0.35];
} }
@ -33,7 +33,7 @@
+ (NSGradient*)progressLightGrayGradient + (NSGradient*)progressLightGrayGradient
{ {
if ([NSApp isDarkMode]) if (NSApp.darkMode)
{ {
return [[self class] progressGradientForRed:0.2 green:0.2 blue:0.2]; return [[self class] progressGradientForRed:0.2 green:0.2 blue:0.2];
} }
@ -45,7 +45,7 @@
+ (NSGradient*)progressBlueGradient + (NSGradient*)progressBlueGradient
{ {
if ([NSApp isDarkMode]) if (NSApp.darkMode)
{ {
return [[self class] progressGradientForRed:0.35 * 2.0 / 3.0 green:0.67 * 2.0 / 3.0 blue:0.98 * 2.0 / 3.0]; return [[self class] progressGradientForRed:0.35 * 2.0 / 3.0 green:0.67 * 2.0 / 3.0 blue:0.98 * 2.0 / 3.0];
} }
@ -57,7 +57,7 @@
+ (NSGradient*)progressDarkBlueGradient + (NSGradient*)progressDarkBlueGradient
{ {
if ([NSApp isDarkMode]) if (NSApp.darkMode)
{ {
return [[self class] progressGradientForRed:0.616 * 2.0 / 3.0 green:0.722 * 2.0 / 3.0 blue:0.776 * 2.0 / 3.0]; return [[self class] progressGradientForRed:0.616 * 2.0 / 3.0 green:0.722 * 2.0 / 3.0 blue:0.776 * 2.0 / 3.0];
} }
@ -69,7 +69,7 @@
+ (NSGradient*)progressGreenGradient + (NSGradient*)progressGreenGradient
{ {
if ([NSApp isDarkMode]) if (NSApp.darkMode)
{ {
return [[self class] progressGradientForRed:0.44 * 2.0 / 3.0 green:0.89 * 2.0 / 3.0 blue:0.40 * 2.0 / 3.0]; return [[self class] progressGradientForRed:0.44 * 2.0 / 3.0 green:0.89 * 2.0 / 3.0 blue:0.40 * 2.0 / 3.0];
} }
@ -81,7 +81,7 @@
+ (NSGradient*)progressLightGreenGradient + (NSGradient*)progressLightGreenGradient
{ {
if ([NSApp isDarkMode]) if (NSApp.darkMode)
{ {
return [[self class] progressGradientForRed:0.62 * 3.0 / 4.0 green:0.99 * 3.0 / 4.0 blue:0.58 * 3.0 / 4.0]; return [[self class] progressGradientForRed:0.62 * 3.0 / 4.0 green:0.99 * 3.0 / 4.0 blue:0.58 * 3.0 / 4.0];
} }
@ -93,7 +93,7 @@
+ (NSGradient*)progressDarkGreenGradient + (NSGradient*)progressDarkGreenGradient
{ {
if ([NSApp isDarkMode]) if (NSApp.darkMode)
{ {
return [[self class] progressGradientForRed:0.627 * 2.0 / 3.0 green:0.714 * 2.0 / 3.0 blue:0.639 * 2.0 / 3.0]; return [[self class] progressGradientForRed:0.627 * 2.0 / 3.0 green:0.714 * 2.0 / 3.0 blue:0.639 * 2.0 / 3.0];
} }
@ -105,7 +105,7 @@
+ (NSGradient*)progressRedGradient + (NSGradient*)progressRedGradient
{ {
if ([NSApp isDarkMode]) if (NSApp.darkMode)
{ {
return [[self class] progressGradientForRed:0.902 * 2.0 / 3.0 green:0.439 * 2.0 / 3.0 blue:0.451 * 2.0 / 3.0]; return [[self class] progressGradientForRed:0.902 * 2.0 / 3.0 green:0.439 * 2.0 / 3.0 blue:0.451 * 2.0 / 3.0];
} }
@ -117,7 +117,7 @@
+ (NSGradient*)progressYellowGradient + (NSGradient*)progressYellowGradient
{ {
if ([NSApp isDarkMode]) if (NSApp.darkMode)
{ {
return [[self class] progressGradientForRed:0.933 * 0.8 green:0.890 * 0.8 blue:0.243 * 0.8]; return [[self class] progressGradientForRed:0.933 * 0.8 green:0.890 * 0.8 blue:0.243 * 0.8];
} }

View File

@ -19,7 +19,7 @@ NSString* generateIconData(NSString* fileExtension, NSUInteger width, NSMutableD
// we need to do this once per file extension, per size // we need to do this once per file extension, per size
NSString* iconFileName = [NSString stringWithFormat:@"%ldx%@.tiff", width, rawFilename]; NSString* iconFileName = [NSString stringWithFormat:@"%ldx%@.tiff", width, rawFilename];
if (![allImgProps objectForKey:iconFileName]) if (!allImgProps[iconFileName])
{ {
NSImage* icon = [[NSWorkspace sharedWorkspace] iconForFileType:fileExtension]; NSImage* icon = [[NSWorkspace sharedWorkspace] iconForFileType:fileExtension];
@ -29,13 +29,13 @@ NSString* generateIconData(NSString* fileExtension, NSUInteger width, NSMutableD
[icon drawInRect:iconFrame fromRect:NSZeroRect operation:NSCompositingOperationCopy fraction:1.0]; [icon drawInRect:iconFrame fromRect:NSZeroRect operation:NSCompositingOperationCopy fraction:1.0];
[renderedIcon unlockFocus]; [renderedIcon unlockFocus];
NSData* iconData = [renderedIcon TIFFRepresentation]; NSData* iconData = renderedIcon.TIFFRepresentation;
NSDictionary* imgProps = @{ NSDictionary* imgProps = @{
(NSString*)kQLPreviewPropertyMIMETypeKey : @"image/png", (NSString*)kQLPreviewPropertyMIMETypeKey : @"image/png",
(NSString*)kQLPreviewPropertyAttachmentDataKey : iconData (NSString*)kQLPreviewPropertyAttachmentDataKey : iconData
}; };
[allImgProps setObject:imgProps forKey:iconFileName]; allImgProps[iconFileName] = imgProps;
} }
return [@"cid:" stringByAppendingString:iconFileName]; return [@"cid:" stringByAppendingString:iconFileName];
@ -54,7 +54,7 @@ OSStatus GeneratePreviewForURL(void* thisInterface, QLPreviewRequestRef preview,
//try to parse the torrent file //try to parse the torrent file
auto metainfo = tr_torrent_metainfo{}; auto metainfo = tr_torrent_metainfo{};
if (!metainfo.parseTorrentFile([[(__bridge NSURL*)url path] UTF8String])) if (!metainfo.parseTorrentFile(((__bridge NSURL*)url).path.UTF8String))
{ {
return noErr; return noErr;
} }
@ -69,11 +69,11 @@ OSStatus GeneratePreviewForURL(void* thisInterface, QLPreviewRequestRef preview,
NSMutableDictionary* allImgProps = [NSMutableDictionary dictionary]; NSMutableDictionary* allImgProps = [NSMutableDictionary dictionary];
NSString* name = [NSString stringWithUTF8String:metainfo.name().c_str()]; NSString* name = @(metainfo.name().c_str());
auto const n_files = metainfo.fileCount(); auto const n_files = metainfo.fileCount();
auto const is_multifile = n_files > 1; auto const is_multifile = n_files > 1;
NSString* fileTypeString = is_multifile ? NSFileTypeForHFSTypeCode(kGenericFolderIcon) : [name pathExtension]; NSString* fileTypeString = is_multifile ? NSFileTypeForHFSTypeCode(kGenericFolderIcon) : name.pathExtension;
NSUInteger const width = 32; NSUInteger const width = 32;
[htmlString appendFormat:@"<h2><img class=\"icon\" src=\"%@\" width=\"%ld\" height=\"%ld\" />%@</h2>", [htmlString appendFormat:@"<h2><img class=\"icon\" src=\"%@\" width=\"%ld\" height=\"%ld\" />%@</h2>",
@ -97,7 +97,7 @@ OSStatus GeneratePreviewForURL(void* thisInterface, QLPreviewRequestRef preview,
timeStyle:NSDateFormatterShortStyle] : timeStyle:NSDateFormatterShortStyle] :
nil; nil;
auto const& creator = metainfo.creator(); auto const& creator = metainfo.creator();
NSString* creatorString = !std::empty(creator) ? [NSString stringWithUTF8String:creator.c_str()] : nil; NSString* creatorString = !std::empty(creator) ? @(creator.c_str()) : nil;
if ([creatorString isEqualToString:@""]) if ([creatorString isEqualToString:@""])
{ {
creatorString = nil; creatorString = nil;
@ -128,7 +128,7 @@ OSStatus GeneratePreviewForURL(void* thisInterface, QLPreviewRequestRef preview,
auto const& commentStr = metainfo.comment(); auto const& commentStr = metainfo.comment();
if (!std::empty(commentStr)) if (!std::empty(commentStr))
{ {
NSString* comment = [NSString stringWithUTF8String:commentStr.c_str()]; NSString* comment = @(commentStr.c_str());
if (![comment isEqualToString:@""]) if (![comment isEqualToString:@""])
[htmlString appendFormat:@"<p>%@</p>", comment]; [htmlString appendFormat:@"<p>%@</p>", comment];
} }
@ -191,16 +191,16 @@ OSStatus GeneratePreviewForURL(void* thisInterface, QLPreviewRequestRef preview,
#warning display folders? #warning display folders?
for (auto const& [path, size] : metainfo.files().sortedByPath()) for (auto const& [path, size] : metainfo.files().sortedByPath())
{ {
NSString* fullFilePath = [NSString stringWithUTF8String:path.c_str()]; NSString* fullFilePath = @(path.c_str());
NSCAssert([fullFilePath hasPrefix:[name stringByAppendingString:@"/"]], @"Expected file path %@ to begin with %@/", fullFilePath, name); NSCAssert([fullFilePath hasPrefix:[name stringByAppendingString:@"/"]], @"Expected file path %@ to begin with %@/", fullFilePath, name);
NSString* shortenedFilePath = [fullFilePath substringFromIndex:[name length] + 1]; NSString* shortenedFilePath = [fullFilePath substringFromIndex:name.length + 1];
NSString* shortenedFilePathAndSize = [NSString NSString* shortenedFilePathAndSize = [NSString
stringWithFormat:@"%@ - %@", shortenedFilePath, [NSString stringForFileSize:size]]; stringWithFormat:@"%@ - %@", shortenedFilePath, [NSString stringForFileSize:size]];
NSUInteger const width = 16; NSUInteger const width = 16;
[listSection appendFormat:@"<tr><td><img class=\"icon\" src=\"%@\" width=\"%ld\" height=\"%ld\" />%@<td></tr>", [listSection appendFormat:@"<tr><td><img class=\"icon\" src=\"%@\" width=\"%ld\" height=\"%ld\" />%@<td></tr>",
generateIconData([shortenedFilePath pathExtension], width, allImgProps), generateIconData(shortenedFilePath.pathExtension, width, allImgProps),
width, width,
width, width,
shortenedFilePathAndSize]; shortenedFilePathAndSize];
@ -211,7 +211,7 @@ OSStatus GeneratePreviewForURL(void* thisInterface, QLPreviewRequestRef preview,
[lists addObject:listSection]; [lists addObject:listSection];
} }
if ([lists count] > 0) if (lists.count > 0)
{ {
[htmlString appendFormat:@"<hr/><br>%@", [lists componentsJoinedByString:@"<br>"]]; [htmlString appendFormat:@"<hr/><br>%@", [lists componentsJoinedByString:@"<br>"]];
} }

View File

@ -70,7 +70,7 @@ tr_session* fLib = NULL;
self.window.title = NSLocalizedString(@"Statistics", "Stats window -> title"); self.window.title = NSLocalizedString(@"Statistics", "Stats window -> title");
//disable fullscreen support //disable fullscreen support
[self.window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenNone]; self.window.collectionBehavior = NSWindowCollectionBehaviorFullScreenNone;
//set label text //set label text
self.fUploadedLabelField.stringValue = [NSLocalizedString(@"Uploaded", "Stats window -> label") stringByAppendingString:@":"]; self.fUploadedLabelField.stringValue = [NSLocalizedString(@"Uploaded", "Stats window -> label") stringByAppendingString:@":"];

View File

@ -12,7 +12,7 @@
//otherwise we get strange drawing issues, leading to a potential crash //otherwise we get strange drawing issues, leading to a potential crash
[NSNotificationCenter.defaultCenter postNotificationName:@"ToolbarDidChange" object:nil]; [NSNotificationCenter.defaultCenter postNotificationName:@"ToolbarDidChange" object:nil];
[super setVisible:visible]; super.visible = visible;
} }
@end @end

View File

@ -83,7 +83,7 @@ typedef NS_ENUM(unsigned int, TorrentDeterminationType) {
- (void)moveTorrentDataFileTo:(NSString*)folder; - (void)moveTorrentDataFileTo:(NSString*)folder;
- (void)copyTorrentFileTo:(NSString*)path; - (void)copyTorrentFileTo:(NSString*)path;
- (BOOL)alertForRemainingDiskSpace; @property(nonatomic, readonly) BOOL alertForRemainingDiskSpace;
@property(nonatomic, readonly) NSImage* icon; @property(nonatomic, readonly) NSImage* icon;

View File

@ -199,7 +199,7 @@ NSMutableSet* fTrackerIconLoading;
NSImage* result = [NSImage imageWithSystemSymbolName:@"globe" accessibilityDescription:nil]; NSImage* result = [NSImage imageWithSystemSymbolName:@"globe" accessibilityDescription:nil];
[result lockFocus]; [result lockFocus];
[NSColor.textColor set]; [NSColor.textColor set];
NSRect imageRect = { NSZeroPoint, [result size] }; NSRect imageRect = { NSZeroPoint, result.size };
NSRectFillUsingOperation(imageRect, NSCompositingOperationSourceIn); NSRectFillUsingOperation(imageRect, NSCompositingOperationSourceIn);
[result unlockFocus]; [result unlockFocus];
return result; return result;
@ -235,7 +235,7 @@ NSMutableSet* fTrackerIconLoading;
{ {
[fTrackerIconCache setObject:icon forKey:baseAddress]; [fTrackerIconCache setObject:icon forKey:baseAddress];
[[self controlView] setNeedsDisplay:YES]; [self.controlView setNeedsDisplay:YES];
} }
else else
{ {