Changeset 748


Ignore:
Timestamp:
Aug 9, 2006, 12:09:19 AM (15 years ago)
Author:
livings124
Message:

I hate memory management in objective-c! This should have better behavior when opening multiple files with "always ask" on.

Location:
trunk/macosx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.h

    r740 r748  
    9797- (void) openFiles: (NSArray *) filenames;
    9898- (void) openFiles: (NSArray *) filenames ignoreDownloadFolder: (BOOL) ignore;
     99- (void) openFilesAsk: (NSMutableArray *) files;
    99100- (void) openShowSheet: (id) sender;
    100101
  • trunk/macosx/Controller.m

    r747 r748  
    463463{
    464464    NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"], * torrentPath;
     465   
     466    if (ignore || [downloadChoice isEqualToString: @"Ask"])
     467    {
     468        [self openFilesAsk: [[filenames mutableCopy] retain]];
     469        return;
     470    }
     471   
    465472    Torrent * torrent;
    466473    NSEnumerator * enumerator = [filenames objectEnumerator];
     
    471478
    472479        //add it to the "File > Open Recent" menu
    473         [[NSDocumentController sharedDocumentController]
    474             noteNewRecentDocumentURL: [NSURL fileURLWithPath: torrentPath]];
    475 
    476         if (ignore || [downloadChoice isEqualToString: @"Ask"])
    477         {
    478             NSOpenPanel * panel = [NSOpenPanel openPanel];
    479 
    480             [panel setPrompt: @"Select"];
    481             [panel setAllowsMultipleSelection: NO];
    482             [panel setCanChooseFiles: NO];
    483             [panel setCanChooseDirectories: YES];
    484 
    485             [panel setMessage: [NSString stringWithFormat: @"Select the download folder for \"%@\"", [torrent name]]];
    486 
    487             [panel beginSheetForDirectory: nil file: nil types: nil modalForWindow: fWindow modalDelegate: self
    488                     didEndSelector: @selector(folderChoiceClosed:returnCode:contextInfo:) contextInfo: [torrent retain]];
    489         }
    490         else
    491         {
    492             NSString * folder = [downloadChoice isEqualToString: @"Constant"]
    493                 ? [[fDefaults stringForKey: @"DownloadFolder"] stringByExpandingTildeInPath]
    494                 : [torrentPath stringByDeletingLastPathComponent];
    495 
    496             [torrent setDownloadFolder: folder];
    497             [torrent update];
    498             [self attemptToStartAuto: torrent];
    499            
    500             [fTorrents addObject: torrent];
    501         }
    502        
     480        [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL: [NSURL fileURLWithPath: torrentPath]];
     481
     482        NSString * folder = [downloadChoice isEqualToString: @"Constant"]
     483            ? [[fDefaults stringForKey: @"DownloadFolder"] stringByExpandingTildeInPath]
     484            : [torrentPath stringByDeletingLastPathComponent];
     485       
     486        [torrent setDownloadFolder: folder];
     487        [torrent update];
     488        [self attemptToStartAuto: torrent];
     489       
     490        [fTorrents addObject: torrent];
    503491        [torrent release];
    504492    }
     
    510498}
    511499
     500//called by the main open method to show sheet for choosing download location
     501- (void) openFilesAsk: (NSMutableArray *) files
     502{
     503    NSString * torrentPath;
     504    Torrent * torrent;
     505    do
     506    {
     507        if ([files count] == 0) //recursive base case
     508        {
     509            [files release];
     510            return;
     511        }
     512   
     513        torrentPath = [files objectAtIndex: 0];
     514        torrent = [[Torrent alloc] initWithPath: torrentPath lib: fLib];
     515       
     516        [files removeObjectAtIndex: 0];
     517    } while (!torrent);
     518
     519    //add it to the "File > Open Recent" menu
     520    [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL: [NSURL fileURLWithPath: torrentPath]];
     521
     522    NSOpenPanel * panel = [NSOpenPanel openPanel];
     523
     524    [panel setPrompt: @"Select"];
     525    [panel setAllowsMultipleSelection: NO];
     526    [panel setCanChooseFiles: NO];
     527    [panel setCanChooseDirectories: YES];
     528
     529    [panel setMessage: [NSString stringWithFormat: @"Select the download folder for \"%@\"", [torrent name]]];
     530   
     531    NSDictionary * dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:
     532                                    torrent, @"Torrent", files, @"Files", nil];
     533
     534    [panel beginSheetForDirectory: nil file: nil types: nil modalForWindow: fWindow modalDelegate: self
     535            didEndSelector: @selector(folderChoiceClosed:returnCode:contextInfo:) contextInfo: dictionary];
     536}
     537
    512538- (void) folderChoiceClosed: (NSOpenPanel *) openPanel returnCode: (int) code
    513     contextInfo: (Torrent *) torrent
    514 {
     539    contextInfo: (NSDictionary *) dictionary
     540{
     541    Torrent * torrent = [dictionary objectForKey: @"Torrent"];
     542
    515543    if (code == NSOKButton)
    516544    {
     
    524552        [self applyFilter: nil];
    525553    }
     554   
    526555    [torrent release];
     556   
     557    [self performSelectorOnMainThread: @selector(openFilesAsk:) withObject: [dictionary objectForKey: @"Files"]
     558                        waitUntilDone: NO];
     559   
     560    [dictionary release];
    527561}
    528562
Note: See TracChangeset for help on using the changeset viewer.