Switch to clang-format for code formatting, include Mac client

This commit is contained in:
Mike Gelfand
2021-08-15 12:41:48 +03:00
parent 409f59889b
commit db3d40d0ed
349 changed files with 16657 additions and 12081 deletions

View File

@@ -36,24 +36,28 @@
@interface AddWindowController (Private)
- (void) updateFiles;
- (void)updateFiles;
- (void) confirmAdd;
- (void)confirmAdd;
- (void) setDestinationPath: (NSString *) destination determinationType: (TorrentDeterminationType) determinationType;
- (void)setDestinationPath:(NSString*)destination determinationType:(TorrentDeterminationType)determinationType;
- (void) setGroupsMenu;
- (void) changeGroupValue: (id) sender;
- (void)setGroupsMenu;
- (void)changeGroupValue:(id)sender;
@end
@implementation AddWindowController
- (instancetype) initWithTorrent: (Torrent *) torrent destination: (NSString *) path lockDestination: (BOOL) lockDestination
controller: (Controller *) controller torrentFile: (NSString *) torrentFile
deleteTorrentCheckEnableInitially: (BOOL) deleteTorrent canToggleDelete: (BOOL) canToggleDelete
- (instancetype)initWithTorrent:(Torrent*)torrent
destination:(NSString*)path
lockDestination:(BOOL)lockDestination
controller:(Controller*)controller
torrentFile:(NSString*)torrentFile
deleteTorrentCheckEnableInitially:(BOOL)deleteTorrent
canToggleDelete:(BOOL)canToggleDelete
{
if ((self = [super initWithWindowNibName: @"AddWindow"]))
if ((self = [super initWithWindowNibName:@"AddWindow"]))
{
fTorrent = torrent;
fDestination = path.stringByExpandingTildeInPath;
@@ -74,15 +78,16 @@
return self;
}
- (void) awakeFromNib
- (void)awakeFromNib
{
[NSNotificationCenter.defaultCenter addObserver: self selector: @selector(updateCheckButtons:) name: @"TorrentFileCheckChange" object: fTorrent];
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(updateCheckButtons:) name:@"TorrentFileCheckChange"
object:fTorrent];
[NSNotificationCenter.defaultCenter addObserver: self selector: @selector(updateGroupMenu:) name: @"UpdateGroups" object: nil];
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(updateGroupMenu:) name:@"UpdateGroups" object:nil];
[fFileController setTorrent: fTorrent];
[fFileController setTorrent:fTorrent];
NSString * name = fTorrent.name;
NSString* name = fTorrent.name;
self.window.title = name;
fNameField.stringValue = name;
fNameField.toolTip = name;
@@ -96,69 +101,82 @@
fUncheckAllButton.hidden = YES;
NSRect scrollFrame = fFileScrollView.frame;
const CGFloat diff = NSMinY(fFileScrollView.frame) - NSMinY(fFileFilterField.frame);
CGFloat const diff = NSMinY(fFileScrollView.frame) - NSMinY(fFileFilterField.frame);
scrollFrame.origin.y -= diff;
scrollFrame.size.height += diff;
fFileScrollView.frame = scrollFrame;
}
else
[self updateCheckButtons: nil];
{
[self updateCheckButtons:nil];
}
[self setGroupsMenu];
[fGroupPopUp selectItemWithTag: fGroupValue];
[fGroupPopUp selectItemWithTag:fGroupValue];
NSInteger priorityIndex;
switch (fTorrent.priority)
{
case TR_PRI_HIGH: priorityIndex = POPUP_PRIORITY_HIGH; break;
case TR_PRI_NORMAL: priorityIndex = POPUP_PRIORITY_NORMAL; break;
case TR_PRI_LOW: priorityIndex = POPUP_PRIORITY_LOW; break;
default:
NSAssert1(NO, @"Unknown priority for adding torrent: %d", fTorrent.priority);
priorityIndex = POPUP_PRIORITY_NORMAL;
case TR_PRI_HIGH:
priorityIndex = POPUP_PRIORITY_HIGH;
break;
case TR_PRI_NORMAL:
priorityIndex = POPUP_PRIORITY_NORMAL;
break;
case TR_PRI_LOW:
priorityIndex = POPUP_PRIORITY_LOW;
break;
default:
NSAssert1(NO, @"Unknown priority for adding torrent: %d", fTorrent.priority);
priorityIndex = POPUP_PRIORITY_NORMAL;
}
[fPriorityPopUp selectItemAtIndex: priorityIndex];
[fPriorityPopUp selectItemAtIndex:priorityIndex];
fStartCheck.state = [NSUserDefaults.standardUserDefaults boolForKey: @"AutoStartDownload"] ? NSOnState : NSOffState;
fStartCheck.state = [NSUserDefaults.standardUserDefaults boolForKey:@"AutoStartDownload"] ? NSOnState : NSOffState;
fDeleteCheck.state = fDeleteTorrentEnableInitially ? NSOnState : NSOffState;
fDeleteCheck.enabled = fCanToggleDelete;
if (fDestination)
[self setDestinationPath: fDestination determinationType: (fLockDestination ? TorrentDeterminationUserSpecified : TorrentDeterminationAutomatic)];
{
[self setDestinationPath:fDestination
determinationType:(fLockDestination ? TorrentDeterminationUserSpecified : TorrentDeterminationAutomatic)];
}
else
{
fLocationField.stringValue = @"";
fLocationImageView.image = nil;
}
fTimer = [NSTimer scheduledTimerWithTimeInterval: UPDATE_SECONDS target: self
selector: @selector(updateFiles) userInfo: nil repeats: YES];
fTimer = [NSTimer scheduledTimerWithTimeInterval:UPDATE_SECONDS target:self selector:@selector(updateFiles) userInfo:nil
repeats:YES];
[self updateFiles];
}
- (void) windowDidLoad
- (void)windowDidLoad
{
//if there is no destination, prompt for one right away
if (!fDestination)
[self setDestination: nil];
{
[self setDestination:nil];
}
}
- (void) dealloc
- (void)dealloc
{
[NSNotificationCenter.defaultCenter removeObserver: self];
[NSNotificationCenter.defaultCenter removeObserver:self];
[fTimer invalidate];
}
- (Torrent *) torrent
- (Torrent*)torrent
{
return fTorrent;
}
- (void) setDestination: (id) sender
- (void)setDestination:(id)sender
{
NSOpenPanel * panel = [NSOpenPanel openPanel];
NSOpenPanel* panel = [NSOpenPanel openPanel];
panel.prompt = NSLocalizedString(@"Select", "Open torrent -> prompt");
panel.allowsMultipleSelection = NO;
@@ -166,140 +184,160 @@
panel.canChooseDirectories = YES;
panel.canCreateDirectories = YES;
panel.message = [NSString stringWithFormat: NSLocalizedString(@"Select the download folder for \"%@\"",
"Add -> select destination folder"), fTorrent.name];
panel.message = [NSString stringWithFormat:NSLocalizedString(@"Select the download folder for \"%@\"", "Add -> select destination folder"),
fTorrent.name];
[panel beginSheetModalForWindow: self.window completionHandler: ^(NSInteger result) {
[panel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result) {
if (result == NSFileHandlingPanelOKButton)
{
fLockDestination = YES;
[self setDestinationPath: panel.URLs[0].path determinationType: TorrentDeterminationUserSpecified];
[self setDestinationPath:panel.URLs[0].path determinationType:TorrentDeterminationUserSpecified];
}
else
{
if (!fDestination)
[self performSelectorOnMainThread: @selector(cancelAdd:) withObject: nil waitUntilDone: NO];
{
[self performSelectorOnMainThread:@selector(cancelAdd:) withObject:nil waitUntilDone:NO];
}
}
}];
}
- (void) add: (id) sender
- (void)add:(id)sender
{
if ([fDestination.lastPathComponent isEqualToString: fTorrent.name]
&& [NSUserDefaults.standardUserDefaults boolForKey: @"WarningFolderDataSameName"])
if ([fDestination.lastPathComponent isEqualToString:fTorrent.name] &&
[NSUserDefaults.standardUserDefaults boolForKey:@"WarningFolderDataSameName"])
{
NSAlert * alert = [[NSAlert alloc] init];
alert.messageText = NSLocalizedString(@"The destination directory and root data directory have the same name.",
"Add torrent -> same name -> title");
alert.informativeText = NSLocalizedString(@"If you are attempting to use already existing data,"
" the root data directory should be inside the destination directory.", "Add torrent -> same name -> message");
NSAlert* alert = [[NSAlert alloc] init];
alert.messageText = NSLocalizedString(@"The destination directory and root data directory have the same name.", "Add torrent -> same name -> title");
alert.informativeText = NSLocalizedString(
@"If you are attempting to use already existing data,"
" the root data directory should be inside the destination directory.",
"Add torrent -> same name -> message");
alert.alertStyle = NSWarningAlertStyle;
[alert addButtonWithTitle: NSLocalizedString(@"Cancel", "Add torrent -> same name -> button")];
[alert addButtonWithTitle: NSLocalizedString(@"Add", "Add torrent -> same name -> button")];
[alert addButtonWithTitle:NSLocalizedString(@"Cancel", "Add torrent -> same name -> button")];
[alert addButtonWithTitle:NSLocalizedString(@"Add", "Add torrent -> same name -> button")];
alert.showsSuppressionButton = YES;
[alert beginSheetModalForWindow:[self window] completionHandler:^(NSModalResponse returnCode) {
if (alert.suppressionButton.state == NSOnState)
[NSUserDefaults.standardUserDefaults setBool: NO forKey: @"WarningFolderDataSameName"];
{
[NSUserDefaults.standardUserDefaults setBool:NO forKey:@"WarningFolderDataSameName"];
}
if (returnCode == NSAlertSecondButtonReturn)
[self performSelectorOnMainThread: @selector(confirmAdd) withObject: nil waitUntilDone: NO];
{
[self performSelectorOnMainThread:@selector(confirmAdd) withObject:nil waitUntilDone:NO];
}
}];
}
else
{
[self confirmAdd];
}
}
- (void) cancelAdd: (id) sender
- (void)cancelAdd:(id)sender
{
[self.window performClose: sender];
[self.window performClose:sender];
}
//only called on cancel
- (BOOL) windowShouldClose: (id) window
- (BOOL)windowShouldClose:(id)window
{
[fTimer invalidate];
fTimer = nil;
[fFileController setTorrent: nil]; //avoid a crash when window tries to update
[fFileController setTorrent:nil]; //avoid a crash when window tries to update
[fController askOpenConfirmed: self add: NO];
[fController askOpenConfirmed:self add:NO];
return YES;
}
- (void) setFileFilterText: (id) sender
- (void)setFileFilterText:(id)sender
{
[fFileController setFilterText: [sender stringValue]];
[fFileController setFilterText:[sender stringValue]];
}
- (IBAction) checkAll: (id) sender
- (IBAction)checkAll:(id)sender
{
[fFileController checkAll];
}
- (IBAction) uncheckAll: (id) sender
- (IBAction)uncheckAll:(id)sender
{
[fFileController uncheckAll];
}
- (void) verifyLocalData: (id) sender
- (void)verifyLocalData:(id)sender
{
[fTorrent resetCache];
[self updateFiles];
}
- (void) changePriority: (id) sender
- (void)changePriority:(id)sender
{
tr_priority_t priority;
switch ([sender indexOfSelectedItem])
{
case POPUP_PRIORITY_HIGH: priority = TR_PRI_HIGH; break;
case POPUP_PRIORITY_NORMAL: priority = TR_PRI_NORMAL; break;
case POPUP_PRIORITY_LOW: priority = TR_PRI_LOW; break;
default:
NSAssert1(NO, @"Unknown priority tag for adding torrent: %ld", [sender tag]);
priority = TR_PRI_NORMAL;
case POPUP_PRIORITY_HIGH:
priority = TR_PRI_HIGH;
break;
case POPUP_PRIORITY_NORMAL:
priority = TR_PRI_NORMAL;
break;
case POPUP_PRIORITY_LOW:
priority = TR_PRI_LOW;
break;
default:
NSAssert1(NO, @"Unknown priority tag for adding torrent: %ld", [sender tag]);
priority = TR_PRI_NORMAL;
}
fTorrent.priority = priority;
}
- (void) updateCheckButtons: (NSNotification *) notification
- (void)updateCheckButtons:(NSNotification*)notification
{
NSString * statusString = [NSString stringForFileSize: fTorrent.size];
NSString* statusString = [NSString stringForFileSize:fTorrent.size];
if (fTorrent.folder)
{
//check buttons
//keep synced with identical code in InfoFileViewController.m
const NSInteger filesCheckState = [fTorrent checkForFiles: [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, fTorrent.fileCount)]];
NSInteger const filesCheckState = [fTorrent
checkForFiles:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, fTorrent.fileCount)]];
fCheckAllButton.enabled = filesCheckState != NSOnState; //if anything is unchecked
fUncheckAllButton.enabled = !fTorrent.allDownloaded; //if there are any checked files that aren't finished
//status field
NSString * fileString;
NSString* fileString;
NSInteger count = fTorrent.fileCount;
if (count != 1)
fileString = [NSString stringWithFormat: NSLocalizedString(@"%@ files", "Add torrent -> info"),
[NSString formattedUInteger: count]];
{
fileString = [NSString
stringWithFormat:NSLocalizedString(@"%@ files", "Add torrent -> info"), [NSString formattedUInteger:count]];
}
else
{
fileString = NSLocalizedString(@"1 file", "Add torrent -> info");
}
NSString * selectedString = [NSString stringWithFormat: NSLocalizedString(@"%@ selected", "Add torrent -> info"),
[NSString stringForFileSize: fTorrent.totalSizeSelected]];
NSString* selectedString = [NSString stringWithFormat:NSLocalizedString(@"%@ selected", "Add torrent -> info"),
[NSString stringForFileSize:fTorrent.totalSizeSelected]];
statusString = [NSString stringWithFormat: @"%@, %@ (%@)", fileString, statusString, selectedString];
statusString = [NSString stringWithFormat:@"%@, %@ (%@)", fileString, statusString, selectedString];
}
fStatusField.stringValue = statusString;
}
- (void) updateGroupMenu: (NSNotification *) notification
- (void)updateGroupMenu:(NSNotification*)notification
{
[self setGroupsMenu];
if (![fGroupPopUp selectItemWithTag: fGroupValue])
if (![fGroupPopUp selectItemWithTag:fGroupValue])
{
fGroupValue = -1;
fGroupValueDetermination = TorrentDeterminationAutomatic;
[fGroupPopUp selectItemWithTag: fGroupValue];
[fGroupPopUp selectItemWithTag:fGroupValue];
}
}
@@ -307,71 +345,80 @@
@implementation AddWindowController (Private)
- (void) updateFiles
- (void)updateFiles
{
[fTorrent update];
[fFileController refresh];
[self updateCheckButtons: nil]; //call in case button state changed by checking
[self updateCheckButtons:nil]; //call in case button state changed by checking
if (fTorrent.checking)
{
const BOOL waiting = fTorrent.checkingWaiting;
BOOL const waiting = fTorrent.checkingWaiting;
fVerifyIndicator.indeterminate = waiting;
if (waiting)
[fVerifyIndicator startAnimation: self];
{
[fVerifyIndicator startAnimation:self];
}
else
{
fVerifyIndicator.doubleValue = fTorrent.checkingProgress;
}
}
else {
else
{
fVerifyIndicator.indeterminate = YES; //we want to hide when stopped, which only applies when indeterminate
[fVerifyIndicator stopAnimation: self];
[fVerifyIndicator stopAnimation:self];
}
}
- (void) confirmAdd
- (void)confirmAdd
{
[fTimer invalidate];
fTimer = nil;
[fTorrent setGroupValue: fGroupValue determinationType: fGroupValueDetermination];
[fTorrent setGroupValue:fGroupValue determinationType:fGroupValueDetermination];
if (fTorrentFile && fCanToggleDelete && fDeleteCheck.state == NSOnState)
[Torrent trashFile: fTorrentFile error: nil];
{
[Torrent trashFile:fTorrentFile error:nil];
}
if (fStartCheck.state == NSOnState)
{
[fTorrent startTransfer];
}
[fFileController setTorrent: nil]; //avoid a crash when window tries to update
[fFileController setTorrent:nil]; //avoid a crash when window tries to update
[self close];
[fController askOpenConfirmed: self add: YES];
[fController askOpenConfirmed:self add:YES];
}
- (void) setDestinationPath: (NSString *) destination determinationType: (TorrentDeterminationType) determinationType
- (void)setDestinationPath:(NSString*)destination determinationType:(TorrentDeterminationType)determinationType
{
destination = destination.stringByExpandingTildeInPath;
if (!fDestination || ![fDestination isEqualToString: destination])
if (!fDestination || ![fDestination isEqualToString:destination])
{
fDestination = destination;
[fTorrent changeDownloadFolderBeforeUsing: fDestination determinationType: determinationType];
[fTorrent changeDownloadFolderBeforeUsing:fDestination determinationType:determinationType];
}
fLocationField.stringValue = fDestination.stringByAbbreviatingWithTildeInPath;
fLocationField.toolTip = fDestination;
ExpandedPathToIconTransformer * iconTransformer = [[ExpandedPathToIconTransformer alloc] init];
fLocationImageView.image = [iconTransformer transformedValue: fDestination];
ExpandedPathToIconTransformer* iconTransformer = [[ExpandedPathToIconTransformer alloc] init];
fLocationImageView.image = [iconTransformer transformedValue:fDestination];
}
- (void) setGroupsMenu
- (void)setGroupsMenu
{
NSMenu * groupMenu = [GroupsController.groups groupMenuWithTarget: self action: @selector(changeGroupValue:) isSmall: NO];
NSMenu* groupMenu = [GroupsController.groups groupMenuWithTarget:self action:@selector(changeGroupValue:) isSmall:NO];
fGroupPopUp.menu = groupMenu;
}
- (void) changeGroupValue: (id) sender
- (void)changeGroupValue:(id)sender
{
NSInteger previousGroup = fGroupValue;
fGroupValue = [sender tag];
@@ -379,11 +426,16 @@
if (!fLockDestination)
{
if ([GroupsController.groups usesCustomDownloadLocationForIndex: fGroupValue])
[self setDestinationPath: [GroupsController.groups customDownloadLocationForIndex: fGroupValue] determinationType: TorrentDeterminationAutomatic];
else if ([fDestination isEqualToString: [GroupsController.groups customDownloadLocationForIndex: previousGroup]])
[self setDestinationPath: [NSUserDefaults.standardUserDefaults stringForKey: @"DownloadFolder"] determinationType: TorrentDeterminationAutomatic];
else;
if ([GroupsController.groups usesCustomDownloadLocationForIndex:fGroupValue])
{
[self setDestinationPath:[GroupsController.groups customDownloadLocationForIndex:fGroupValue]
determinationType:TorrentDeterminationAutomatic];
}
else if ([fDestination isEqualToString:[GroupsController.groups customDownloadLocationForIndex:previousGroup]])
{
[self setDestinationPath:[NSUserDefaults.standardUserDefaults stringForKey:@"DownloadFolder"]
determinationType:TorrentDeterminationAutomatic];
}
}
}