Changeset 325


Ignore:
Timestamp:
Jun 11, 2006, 12:16:31 AM (16 years ago)
Author:
livings124
Message:

Make Copy Torrent dialog a sheet.

Location:
trunk/macosx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.h

    r323 r325  
    106106
    107107- (void) copyTorrentFile: (id) sender;
     108- (void) copyTorrentFileForTorrents: (NSMutableArray *) torrents;
     109- (void) saveTorrentCopySheetClosed: (NSSavePanel *) panel returnCode: (int) code
     110    contextInfo: (NSMutableArray *) torrents;
    108111
    109112- (void) revealFile: (id) sender;
  • trunk/macosx/Controller.m

    r324 r325  
    633633- (void) copyTorrentFile: (id) sender
    634634{
    635     Torrent * torrent;
    636     NSEnumerator * enumerator = [[self torrentsAtIndexes:
    637             [fTableView selectedRowIndexes]] objectEnumerator];
    638    
    639     while ((torrent = [enumerator nextObject]))
    640     {
    641         //warn user if torrent file can't be found
    642         if (![[NSFileManager defaultManager] fileExistsAtPath: [torrent torrentLocation]])
    643         {
    644             NSAlert * alert = [[NSAlert alloc] init];
    645             [alert addButtonWithTitle: @"OK"];
    646             [alert setMessageText: [NSString stringWithFormat:
    647                     @"Copy of \"%@\" Cannot Be Created", [torrent name]]];
    648             [alert setInformativeText: [NSString stringWithFormat:
    649                     @"The torrent file (%@) cannot be found.", [torrent torrentLocation]]];
    650             [alert setAlertStyle: NSWarningAlertStyle];
    651            
    652             [alert runModal];
    653            
    654             continue;
    655         }
     635    [self copyTorrentFileForTorrents: [[NSMutableArray alloc] initWithArray:
     636            [self torrentsAtIndexes: [fTableView selectedRowIndexes]]]];
     637}
     638
     639- (void) copyTorrentFileForTorrents: (NSMutableArray *) torrents
     640{
     641    if ([torrents count] == 0)
     642    {
     643        [torrents release];
     644        return;
     645    }
     646
     647    Torrent * torrent = [torrents objectAtIndex: 0];
     648
     649    //warn user if torrent file can't be found
     650    if (![[NSFileManager defaultManager] fileExistsAtPath: [torrent torrentLocation]])
     651    {
     652        NSAlert * alert = [[NSAlert alloc] init];
     653        [alert addButtonWithTitle: @"OK"];
     654        [alert setMessageText: [NSString stringWithFormat:
     655                @"Copy of \"%@\" Cannot Be Created", [torrent name]]];
     656        [alert setInformativeText: [NSString stringWithFormat:
     657                @"The torrent file (%@) cannot be found.", [torrent torrentLocation]]];
     658        [alert setAlertStyle: NSWarningAlertStyle];
    656659       
    657         //save with extension
    658         NSSavePanel * savePanel = [NSSavePanel savePanel];
    659         [savePanel setRequiredFileType: @"torrent"];
    660         [savePanel setCanSelectHiddenExtension: YES];
     660        [alert runModal];
    661661       
    662         //if save successful, copy torrent to new location with name of data file
    663         if ([savePanel runModalForDirectory: nil file: [torrent name]] == NSOKButton)
    664             [[NSFileManager defaultManager] copyPath: [torrent torrentLocation]
    665                 toPath: [savePanel filename] handler: nil];
    666     }
     662        [torrents removeObjectAtIndex: 0];
     663        [self copyTorrentFileForTorrents: torrents];
     664    }
     665    else
     666    {
     667        NSSavePanel * panel = [NSSavePanel savePanel];
     668        [panel setRequiredFileType: @"torrent"];
     669        [panel setExtensionHidden: NO];
     670        [panel setCanSelectHiddenExtension: NO];
     671       
     672        [panel beginSheetForDirectory: nil file: [torrent name]
     673            modalForWindow: fWindow modalDelegate: self didEndSelector:
     674            @selector( saveTorrentCopySheetClosed:returnCode:contextInfo: )
     675            contextInfo: torrents];
     676    }
     677}
     678
     679- (void) saveTorrentCopySheetClosed: (NSSavePanel *) panel returnCode: (int) code
     680    contextInfo: (NSMutableArray *) torrents
     681{
     682    //if save successful, copy torrent to new location with name of data file
     683    if (code == NSOKButton)
     684        [[NSFileManager defaultManager] copyPath: [[torrents objectAtIndex: 0] torrentLocation]
     685                toPath: [panel filename] handler: nil];
     686   
     687    [torrents removeObjectAtIndex: 0];
     688    [self performSelectorOnMainThread: @selector(copyTorrentFileForTorrents:)
     689                withObject: torrents waitUntilDone: NO];
    667690}
    668691
Note: See TracChangeset for help on using the changeset viewer.