Changeset 145


Ignore:
Timestamp:
Mar 12, 2006, 2:32:04 AM (17 years ago)
Author:
titer
Message:

Fixed warning when quitting with active torrents.
Fixed menu and toolbar items.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/new_api/macosx/Controller.m

    r143 r145  
    100100
    101101    [fTableView setAutosaveTableColumns: YES];
    102     //[fTableView sizeToFit];
    103102
    104103    [fTableView registerForDraggedTypes: [NSArray arrayWithObjects:
     
    200199- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
    201200{
    202     int active = fDownloading + fSeeding;
     201    int active = 0;
     202    Torrent * torrent;
     203    NSEnumerator * enumerator = [fTorrents objectEnumerator];
     204    while( ( torrent = [enumerator nextObject] ) )
     205    {
     206        if( [torrent isActive] )
     207        {
     208            active++;
     209        }
     210    }
     211
    203212    if (active > 0 && [fDefaults boolForKey: @"CheckQuit"])
    204213    {
     
    411420- (void) resumeAllTorrents: (id) sender
    412421{
     422    Torrent * torrent;
    413423    NSEnumerator * enumerator = [fTorrents objectEnumerator];
    414     Torrent * torrent;
    415424    while( ( torrent = [enumerator nextObject] ) )
    416425    {
    417         [torrent stop];
    418     }
    419 }
    420 
    421 - (void) resumeTorrentWithIndex: (int) idx
    422 {
    423     [[fTorrents objectAtIndex: idx] start];
     426        [torrent start];
     427    }
    424428    [self updateUI: nil];
    425429    [self updateTorrentHistory];
    426430}
    427431
     432- (void) resumeTorrentWithIndex: (int) idx
     433{
     434    Torrent * torrent = [fTorrents objectAtIndex: idx];
     435    [torrent start];
     436    [self updateUI: nil];
     437    [self updateTorrentHistory];
     438}
     439
    428440- (void) stopTorrent: (id) sender
    429441{
     
    433445- (void) stopAllTorrents: (id) sender
    434446{
     447    Torrent * torrent;
    435448    NSEnumerator * enumerator = [fTorrents objectEnumerator];
    436     Torrent * torrent;
    437449    while( ( torrent = [enumerator nextObject] ) )
    438450    {
    439         [torrent start];
    440     }
     451        [torrent stop];
     452    }
     453    [self updateUI: nil];
     454    [self updateTorrentHistory];
    441455}
    442456
     
    832846        return [fTableView selectedRow] >= 0;
    833847
     848    Torrent * torrent;
     849    NSEnumerator * enumerator;
    834850
    835851    //enable resume all item
    836852    if (action == @selector(resumeAllTorrents:))
    837         return fCount > fDownloading + fSeeding;
     853    {
     854        enumerator = [fTorrents objectEnumerator];
     855        while( ( torrent = [enumerator nextObject] ) )
     856            if( [torrent isPaused] )
     857                return YES;
     858        return NO;
     859    }
    838860
    839861    //enable pause all item
    840862    if (action == @selector(stopAllTorrents:))
    841         return fDownloading > 0 || fSeeding > 0;
     863    {
     864        enumerator = [fTorrents objectEnumerator];
     865        while( ( torrent = [enumerator nextObject] ) )
     866            if( [torrent isActive] )
     867                return YES;
     868        return NO;
     869    }
    842870
    843871    return YES;
     
    846874- (BOOL)validateMenuItem:(NSMenuItem *)menuItem
    847875{
    848 #if 0
    849876    SEL action = [menuItem action];
    850877
     
    867894    }
    868895
     896    Torrent * torrent;
     897    NSEnumerator * enumerator;
     898
    869899    //enable resume all item
    870900    if (action == @selector(resumeAllTorrents:))
    871         return fCount > fDownloading + fSeeding;
     901    {
     902        enumerator = [fTorrents objectEnumerator];
     903        while( ( torrent = [enumerator nextObject] ) )
     904            if( [torrent isPaused] )
     905                return YES;
     906        return NO;
     907    }
    872908
    873909    //enable pause all item
    874910    if (action == @selector(stopAllTorrents:))
    875         return fDownloading > 0 || fSeeding > 0;
     911    {
     912        enumerator = [fTorrents objectEnumerator];
     913        while( ( torrent = [enumerator nextObject] ) )
     914            if( [torrent isActive] )
     915                return YES;
     916        return NO;
     917    }
    876918
    877919    int row = [fTableView selectedRow];
     920    torrent = ( row < 0 ) ? nil : [fTorrents objectAtIndex: row];
     921
     922    if (action == @selector(revealFromMenu:))
     923    {
     924        return ( torrent != nil );
     925    }
    878926
    879927    //enable remove items
     
    883931        || action == @selector(removeTorrentDeleteBoth:))
    884932    {
     933        if( !torrent )
     934            return NO;
     935
    885936        //append or remove ellipsis when needed
    886         if (row >= 0 && fStat[row].status & ( TR_STATUS_CHECK | TR_STATUS_DOWNLOAD)
    887                     && [[fDefaults stringForKey: @"CheckRemove"] isEqualToString:@"YES"])
     937        if( [torrent isActive] && [fDefaults boolForKey: @"CheckRemove"] )
    888938        {
    889939            if (![[menuItem title] hasSuffix:NS_ELLIPSIS])
     
    895945                [menuItem setTitle:[[menuItem title] substringToIndex:[[menuItem title] length]-[NS_ELLIPSIS length]]];
    896946        }
    897         return row >= 0;
    898     }
    899 
    900     //enable reveal in finder item
    901     if (action == @selector(revealFromMenu:))
    902         return row >= 0;
     947        return YES;
     948    }
    903949
    904950    //enable and change pause / remove item
    905     if (action == @selector(resumeTorrent:) || action == @selector(stopTorrent:))
    906     {
    907         if (row >= 0 && fStat[row].status & TR_STATUS_PAUSE)
     951    if( action == @selector(resumeTorrent:) ||
     952        action == @selector(stopTorrent:) )
     953    {
     954        if( !torrent )
     955            return NO;
     956
     957        if( [torrent isActive] )
     958        {
     959            [menuItem setTitle: @"Pause"];
     960            [menuItem setAction: @selector( stopTorrent: )];
     961        }
     962        else
    908963        {
    909964            [menuItem setTitle: @"Resume"];
    910965            [menuItem setAction: @selector( resumeTorrent: )];
    911966        }
    912         else
    913         {
    914             [menuItem setTitle: @"Pause"];
    915             [menuItem setAction: @selector( stopTorrent: )];
    916         }
    917         return row >= 0;
    918     }
    919 #endif
     967    }
     968
    920969    return YES;
    921970}
Note: See TracChangeset for help on using the changeset viewer.