Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[macOS] Apply ObjC modernizations once again. #3358

Merged
merged 1 commit into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion macosx/AddMagnetWindowController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ - (void)awakeFromNib
self.fNameField.toolTip = name;

//disable fullscreen support
[self.window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenNone];
self.window.collectionBehavior = NSWindowCollectionBehaviorFullScreenNone;

[self setGroupsMenu];
[self.fGroupPopUp selectItemWithTag:self.fGroupValue];
Expand Down
4 changes: 2 additions & 2 deletions macosx/AddWindowController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ - (void)awakeFromNib
self.fNameField.toolTip = name;

//disable fullscreen support
[self.window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenNone];
self.window.collectionBehavior = NSWindowCollectionBehaviorFullScreenNone;

self.fIconView.image = self.torrent.icon;

Expand Down Expand Up @@ -233,7 +233,7 @@ - (void)add:(id)sender
[alert addButtonWithTitle:NSLocalizedString(@"Add", "Add torrent -> same name -> button")];
alert.showsSuppressionButton = YES;

[alert beginSheetModalForWindow:[self window] completionHandler:^(NSModalResponse returnCode) {
[alert beginSheetModalForWindow:self.window completionHandler:^(NSModalResponse returnCode) {
if (alert.suppressionButton.state == NSControlStateValueOn)
{
[NSUserDefaults.standardUserDefaults setBool:NO forKey:@"WarningFolderDataSameName"];
Expand Down
8 changes: 4 additions & 4 deletions macosx/BlocklistDownloader.mm
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ - (BOOL)untarFrom:(NSURL*)file to:(NSURL*)destination
return NO;
}

NSURL* destinationDir = [destination URLByDeletingLastPathComponent];
NSURL* destinationDir = destination.URLByDeletingLastPathComponent;

NSTask* untar = [[NSTask alloc] init];
untar.launchPath = @"/usr/bin/tar";
Expand Down Expand Up @@ -279,7 +279,7 @@ - (BOOL)untarFrom:(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];
gunzip.launchPath = @"/usr/bin/gunzip";
Expand All @@ -301,7 +301,7 @@ - (BOOL)gunzipFrom:(NSURL*)file to:(NSURL*)destination
return NO;
}

NSURL* result = [file URLByDeletingPathExtension];
NSURL* result = file.URLByDeletingPathExtension;

[NSFileManager.defaultManager moveItemAtURL:result toURL:destination error:nil];
return YES;
Expand Down Expand Up @@ -348,7 +348,7 @@ - (BOOL)unzipFrom:(NSURL*)file to:(NSURL*)destination
return NO;
}

NSURL* destinationDir = [destination URLByDeletingLastPathComponent];
NSURL* destinationDir = destination.URLByDeletingLastPathComponent;

NSTask* unzip = [[NSTask alloc] init];
unzip.launchPath = @"/usr/bin/unzip";
Expand Down
2 changes: 1 addition & 1 deletion macosx/BlocklistDownloaderViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ - (void)startDownload
[NSBundle.mainBundle loadNibNamed:@"BlocklistStatusWindow" owner:self topLevelObjects:NULL];

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];
}
Expand Down
2 changes: 1 addition & 1 deletion macosx/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ typedef NS_ENUM(unsigned int, addType) { //
@property(nonatomic, readonly) CGFloat toolbarHeight;
@property(nonatomic, readonly) CGFloat mainWindowComponentHeight;
@property(nonatomic, readonly) CGFloat scrollViewHeight;
- (BOOL)isFullScreen;
@property(nonatomic, getter=isFullScreen, readonly) BOOL fullScreen;

- (void)updateForExpandCollapse;

Expand Down
21 changes: 11 additions & 10 deletions macosx/Controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ typedef NS_ENUM(unsigned int, sortOrderTag) { //

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)};
ckerr marked this conversation as resolved.
Show resolved Hide resolved
[(__bridge Controller*)controller performSelectorOnMainThread:@selector(altSpeedToggledCallbackIsLimited:) withObject:dict
waitUntilDone:NO];
}
Expand Down Expand Up @@ -512,7 +512,7 @@ - (instancetype)init
_fLib = tr_sessionInit(configDir, YES, &settings);
tr_variantFree(&settings);

_fConfigDirectory = [[NSString alloc] initWithUTF8String:configDir];
_fConfigDirectory = @(configDir);

NSApp.delegate = self;

Expand Down Expand Up @@ -569,7 +569,7 @@ - (void)awakeFromNib
self.fWindow.excludedFromWindowsMenu = YES;

//make window primary view in fullscreen
[self.fWindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
self.fWindow.collectionBehavior = NSWindowCollectionBehaviorFullScreenPrimary;

//set table size
BOOL const small = [self.fDefaults boolForKey:@"SmallView"];
Expand Down Expand Up @@ -1021,7 +1021,7 @@ - (void)download:(NSURLDownload*)download decideDestinationWithSuggestedFilename
NSString* message = [NSString
stringWithFormat:NSLocalizedString(@"It appears that the file \"%@\" from %@ is not a torrent file.", "Download not a torrent -> message"),
suggestedName,
[download.request.URL.absoluteString stringByRemovingPercentEncoding]];
download.request.URL.absoluteString.stringByRemovingPercentEncoding];

NSAlert* alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:NSLocalizedString(@"OK", "Download not a torrent -> button")];
Expand All @@ -1046,7 +1046,7 @@ - (void)download:(NSURLDownload*)download didFailWithError:(NSError*)error
{
NSString* message = [NSString
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];

NSAlert* alert = [[NSAlert alloc] init];
Expand Down Expand Up @@ -1351,7 +1351,7 @@ - (void)openFilesWithDict:(NSDictionary*)dictionary
//called on by applescript
- (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];
}

Expand All @@ -1374,9 +1374,10 @@ - (void)openShowSheet:(id)sender
[filenames addObject:url.path];
}

NSDictionary* dictionary = [[NSDictionary alloc]
initWithObjects:@[ filenames, sender == self.fOpenIgnoreDownloadFolder ? @(ADD_SHOW_OPTIONS) : @(ADD_MANUAL) ]
forKeys:@[ @"Filenames", @"AddType" ]];
NSDictionary* dictionary = @{
@"Filenames" : filenames,
@"AddType" : sender == self.fOpenIgnoreDownloadFolder ? @(ADD_SHOW_OPTIONS) : @(ADD_MANUAL)
};
[self performSelectorOnMainThread:@selector(openFilesWithDict:) withObject:dictionary waitUntilDone:NO];
}
}];
Expand Down Expand Up @@ -1552,7 +1553,7 @@ - (void)openURLShowSheet:(id)sender
[self.fWindow beginSheet:self.fUrlSheetController.window completionHandler:^(NSModalResponse returnCode) {
if (returnCode == 1)
{
NSString* urlString = [self.fUrlSheetController urlString];
NSString* urlString = self.fUrlSheetController.urlString;
urlString = [urlString stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
dispatch_async(dispatch_get_main_queue(), ^{
[self openURL:urlString];
Expand Down
10 changes: 5 additions & 5 deletions macosx/CreatorWindowController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ - (instancetype)initWithHandle:(tr_session*)handle path:(NSURL*)path
//remove potentially invalid addresses
for (NSInteger i = _fTrackers.count - 1; i >= 0; i--)
{
if (!tr_urlIsValidTracker([_fTrackers[i] UTF8String]))
if (!tr_urlIsValidTracker(_fTrackers[i].UTF8String))
{
[_fTrackers removeObjectAtIndex:i];
}
Expand All @@ -161,7 +161,7 @@ - (void)awakeFromNib
self.window.title = name;

//disable fullscreen support
[self.window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenNone];
self.window.collectionBehavior = NSWindowCollectionBehaviorFullScreenNone;

self.fNameField.stringValue = name;
self.fNameField.toolTip = self.fPath.path;
Expand Down Expand Up @@ -191,7 +191,7 @@ - (void)awakeFromNib
self.fStatusField.stringValue = statusString;

[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"]
URLByAppendingPathComponent:[name stringByAppendingPathExtension:@"torrent"]];
Expand Down Expand Up @@ -601,14 +601,14 @@ - (void)createReal

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;
}

//store values
[self.fDefaults setObject:self.fTrackers forKey:@"CreatorTrackers"];
[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.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
Expand Down
2 changes: 1 addition & 1 deletion macosx/MessageWindowController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ - (void)awakeFromNib
self.window.title = NSLocalizedString(@"Message Log", "Message window -> title");

//disable fullscreen support
[window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenNone];
window.collectionBehavior = NSWindowCollectionBehaviorFullScreenNone;

//set images and text for popup button items
[self.fLevelButton itemAtIndex:LEVEL_ERROR].title = NSLocalizedString(@"Error", "Message window -> level string");
Expand Down
2 changes: 1 addition & 1 deletion macosx/NSImageAdditions.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ + (NSImage*)discIconWithColor:(NSColor*)color insetFactor:(CGFloat)insetFactor
bp.lineWidth = BORDER_WIDTH;

//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];
[borderColor setStroke];
[bp stroke];
Expand Down
2 changes: 1 addition & 1 deletion macosx/NSStringAdditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@interface NSString (NSStringAdditions)

@property(nonatomic, class, readonly) NSString* ellipsis;
- (NSString*)stringByAppendingEllipsis;
@property(nonatomic, readonly, copy) NSString* stringByAppendingEllipsis;

+ (NSString*)formattedUInteger:(NSUInteger)value;

Expand Down
4 changes: 2 additions & 2 deletions macosx/PiecesView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ - (void)awakeFromNib

- (void)viewDidChangeEffectiveAppearance
{
[self setTorrent:_torrent];
self.torrent = _torrent;
[self updateView];
}

Expand Down Expand Up @@ -122,7 +122,7 @@ - (void)updateView
NSRect fillRects[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;

Expand Down
4 changes: 2 additions & 2 deletions macosx/PrefsController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ - (void)awakeFromNib
self.window.restorationClass = [self class];

//disable fullscreen support
[self.window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenNone];
self.window.collectionBehavior = NSWindowCollectionBehaviorFullScreenNone;

NSToolbar* toolbar = [[NSToolbar alloc] initWithIdentifier:@"Preferences Toolbar"];
toolbar.delegate = self;
Expand Down Expand Up @@ -1119,7 +1119,7 @@ - (void)updateRPCPassword

tr_sessionSetRPCPassword(self.fHandle, fullPassword);

self.fRPCPassword = [[NSString alloc] initWithUTF8String:fullPassword];
self.fRPCPassword = @(fullPassword);
self.fRPCPasswordField.stringValue = self.fRPCPassword;
}
else
Expand Down
20 changes: 10 additions & 10 deletions macosx/ProgressGradients.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ @implementation ProgressGradients

+ (NSGradient*)progressWhiteGradient
{
if ([NSApp isDarkMode])
if (NSApp.darkMode)
{
return [[self class] progressGradientForRed:0.1 green:0.1 blue:0.1];
}
Expand All @@ -21,7 +21,7 @@ + (NSGradient*)progressWhiteGradient

+ (NSGradient*)progressGrayGradient
{
if ([NSApp isDarkMode])
if (NSApp.darkMode)
{
return [[self class] progressGradientForRed:0.35 green:0.35 blue:0.35];
}
Expand All @@ -33,7 +33,7 @@ + (NSGradient*)progressGrayGradient

+ (NSGradient*)progressLightGrayGradient
{
if ([NSApp isDarkMode])
if (NSApp.darkMode)
{
return [[self class] progressGradientForRed:0.2 green:0.2 blue:0.2];
}
Expand All @@ -45,7 +45,7 @@ + (NSGradient*)progressLightGrayGradient

+ (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];
}
Expand All @@ -57,7 +57,7 @@ + (NSGradient*)progressBlueGradient

+ (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];
}
Expand All @@ -69,7 +69,7 @@ + (NSGradient*)progressDarkBlueGradient

+ (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];
}
Expand All @@ -81,7 +81,7 @@ + (NSGradient*)progressGreenGradient

+ (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];
}
Expand All @@ -93,7 +93,7 @@ + (NSGradient*)progressLightGreenGradient

+ (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];
}
Expand All @@ -105,7 +105,7 @@ + (NSGradient*)progressDarkGreenGradient

+ (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];
}
Expand All @@ -117,7 +117,7 @@ + (NSGradient*)progressRedGradient

+ (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];
}
Expand Down