mirror of
https://github.com/transmission/transmission
synced 2024-12-27 01:57:52 +00:00
I hate memory management in objective-c! This should have better behavior when opening multiple files with "always ask" on.
This commit is contained in:
parent
0e334e4d2f
commit
57ecfe7ee6
2 changed files with 65 additions and 30 deletions
|
@ -96,6 +96,7 @@
|
||||||
|
|
||||||
- (void) openFiles: (NSArray *) filenames;
|
- (void) openFiles: (NSArray *) filenames;
|
||||||
- (void) openFiles: (NSArray *) filenames ignoreDownloadFolder: (BOOL) ignore;
|
- (void) openFiles: (NSArray *) filenames ignoreDownloadFolder: (BOOL) ignore;
|
||||||
|
- (void) openFilesAsk: (NSMutableArray *) files;
|
||||||
- (void) openShowSheet: (id) sender;
|
- (void) openShowSheet: (id) sender;
|
||||||
|
|
||||||
- (void) quitSheetDidEnd: (NSWindow *) sheet returnCode: (int) returnCode contextInfo: (void *) contextInfo;
|
- (void) quitSheetDidEnd: (NSWindow *) sheet returnCode: (int) returnCode contextInfo: (void *) contextInfo;
|
||||||
|
|
|
@ -462,6 +462,13 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
|
||||||
- (void) openFiles: (NSArray *) filenames ignoreDownloadFolder: (BOOL) ignore
|
- (void) openFiles: (NSArray *) filenames ignoreDownloadFolder: (BOOL) ignore
|
||||||
{
|
{
|
||||||
NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"], * torrentPath;
|
NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"], * torrentPath;
|
||||||
|
|
||||||
|
if (ignore || [downloadChoice isEqualToString: @"Ask"])
|
||||||
|
{
|
||||||
|
[self openFilesAsk: [[filenames mutableCopy] retain]];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Torrent * torrent;
|
Torrent * torrent;
|
||||||
NSEnumerator * enumerator = [filenames objectEnumerator];
|
NSEnumerator * enumerator = [filenames objectEnumerator];
|
||||||
while ((torrentPath = [enumerator nextObject]))
|
while ((torrentPath = [enumerator nextObject]))
|
||||||
|
@ -470,25 +477,8 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
//add it to the "File > Open Recent" menu
|
//add it to the "File > Open Recent" menu
|
||||||
[[NSDocumentController sharedDocumentController]
|
[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL: [NSURL fileURLWithPath: torrentPath]];
|
||||||
noteNewRecentDocumentURL: [NSURL fileURLWithPath: torrentPath]];
|
|
||||||
|
|
||||||
if (ignore || [downloadChoice isEqualToString: @"Ask"])
|
|
||||||
{
|
|
||||||
NSOpenPanel * panel = [NSOpenPanel openPanel];
|
|
||||||
|
|
||||||
[panel setPrompt: @"Select"];
|
|
||||||
[panel setAllowsMultipleSelection: NO];
|
|
||||||
[panel setCanChooseFiles: NO];
|
|
||||||
[panel setCanChooseDirectories: YES];
|
|
||||||
|
|
||||||
[panel setMessage: [NSString stringWithFormat: @"Select the download folder for \"%@\"", [torrent name]]];
|
|
||||||
|
|
||||||
[panel beginSheetForDirectory: nil file: nil types: nil modalForWindow: fWindow modalDelegate: self
|
|
||||||
didEndSelector: @selector(folderChoiceClosed:returnCode:contextInfo:) contextInfo: [torrent retain]];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
NSString * folder = [downloadChoice isEqualToString: @"Constant"]
|
NSString * folder = [downloadChoice isEqualToString: @"Constant"]
|
||||||
? [[fDefaults stringForKey: @"DownloadFolder"] stringByExpandingTildeInPath]
|
? [[fDefaults stringForKey: @"DownloadFolder"] stringByExpandingTildeInPath]
|
||||||
: [torrentPath stringByDeletingLastPathComponent];
|
: [torrentPath stringByDeletingLastPathComponent];
|
||||||
|
@ -498,8 +488,6 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
|
||||||
[self attemptToStartAuto: torrent];
|
[self attemptToStartAuto: torrent];
|
||||||
|
|
||||||
[fTorrents addObject: torrent];
|
[fTorrents addObject: torrent];
|
||||||
}
|
|
||||||
|
|
||||||
[torrent release];
|
[torrent release];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -509,9 +497,49 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
|
||||||
[self updateTorrentHistory];
|
[self updateTorrentHistory];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) folderChoiceClosed: (NSOpenPanel *) openPanel returnCode: (int) code
|
//called by the main open method to show sheet for choosing download location
|
||||||
contextInfo: (Torrent *) torrent
|
- (void) openFilesAsk: (NSMutableArray *) files
|
||||||
{
|
{
|
||||||
|
NSString * torrentPath;
|
||||||
|
Torrent * torrent;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if ([files count] == 0) //recursive base case
|
||||||
|
{
|
||||||
|
[files release];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
torrentPath = [files objectAtIndex: 0];
|
||||||
|
torrent = [[Torrent alloc] initWithPath: torrentPath lib: fLib];
|
||||||
|
|
||||||
|
[files removeObjectAtIndex: 0];
|
||||||
|
} while (!torrent);
|
||||||
|
|
||||||
|
//add it to the "File > Open Recent" menu
|
||||||
|
[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL: [NSURL fileURLWithPath: torrentPath]];
|
||||||
|
|
||||||
|
NSOpenPanel * panel = [NSOpenPanel openPanel];
|
||||||
|
|
||||||
|
[panel setPrompt: @"Select"];
|
||||||
|
[panel setAllowsMultipleSelection: NO];
|
||||||
|
[panel setCanChooseFiles: NO];
|
||||||
|
[panel setCanChooseDirectories: YES];
|
||||||
|
|
||||||
|
[panel setMessage: [NSString stringWithFormat: @"Select the download folder for \"%@\"", [torrent name]]];
|
||||||
|
|
||||||
|
NSDictionary * dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:
|
||||||
|
torrent, @"Torrent", files, @"Files", nil];
|
||||||
|
|
||||||
|
[panel beginSheetForDirectory: nil file: nil types: nil modalForWindow: fWindow modalDelegate: self
|
||||||
|
didEndSelector: @selector(folderChoiceClosed:returnCode:contextInfo:) contextInfo: dictionary];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) folderChoiceClosed: (NSOpenPanel *) openPanel returnCode: (int) code
|
||||||
|
contextInfo: (NSDictionary *) dictionary
|
||||||
|
{
|
||||||
|
Torrent * torrent = [dictionary objectForKey: @"Torrent"];
|
||||||
|
|
||||||
if (code == NSOKButton)
|
if (code == NSOKButton)
|
||||||
{
|
{
|
||||||
[torrent setDownloadFolder: [[openPanel filenames] objectAtIndex: 0]];
|
[torrent setDownloadFolder: [[openPanel filenames] objectAtIndex: 0]];
|
||||||
|
@ -523,7 +551,13 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
|
||||||
[self updateUI: nil];
|
[self updateUI: nil];
|
||||||
[self applyFilter: nil];
|
[self applyFilter: nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
[torrent release];
|
[torrent release];
|
||||||
|
|
||||||
|
[self performSelectorOnMainThread: @selector(openFilesAsk:) withObject: [dictionary objectForKey: @"Files"]
|
||||||
|
waitUntilDone: NO];
|
||||||
|
|
||||||
|
[dictionary release];
|
||||||
}
|
}
|
||||||
|
|
||||||
//called on by applescript
|
//called on by applescript
|
||||||
|
|
Loading…
Reference in a new issue