Changeset 1322


Ignore:
Timestamp:
Jan 9, 2007, 1:09:23 AM (15 years ago)
Author:
livings124
Message:

simplify queueing core a bit...will make things easier later

Location:
trunk/macosx
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.h

    r1283 r1322  
    173173- (void) setQuickRatioGlobal: (id) sender;
    174174
     175#warning simplify?
    175176- (void) checkWaitingForStopped: (NSNotification *) notification;
    176 - (void) checkToStartWaiting: (Torrent *) finishedTorrent;
    177177- (void) torrentStartSettingChange: (NSNotification *) notification;
    178178- (void) globalStartSettingChange: (NSNotification *) notification;
    179179
    180180- (void) torrentStoppedForRatio: (NSNotification *) notification;
    181 
    182 - (void) attemptToStartAuto: (Torrent *) torrent;
    183 - (void) attemptToStartMultipleAuto: (NSArray *) torrents;
     181- (void) updateTorrentsInQueue;
    184182
    185183- (void) changeAutoImport;
  • trunk/macosx/Controller.m

    r1305 r1322  
    598598        [torrent setDownloadFolder: folder];
    599599        [torrent update];
    600         [self attemptToStartAuto: torrent];
    601600       
    602601        [fTorrents addObject: torrent];
     
    604603    }
    605604
    606     [self updateUI: nil];
    607     [self applyFilter: nil];
    608    
    609     [self updateTorrentHistory];
     605    [self updateTorrentsInQueue];
    610606}
    611607
     
    662658        [torrent setDownloadFolder: [[openPanel filenames] objectAtIndex: 0]];
    663659        [torrent update];
    664         [self attemptToStartAuto: torrent];
    665660       
    666661        [fTorrents addObject: torrent];
    667662       
    668         [self updateUI: nil];
    669         [self applyFilter: nil];
     663        [self updateTorrentsInQueue];
    670664    }
    671665   
     
    792786        [torrent setWaitToStart: YES];
    793787   
    794     [self attemptToStartMultipleAuto: torrents];
    795    
    796     [self updateUI: nil];
    797     [self applyFilter: nil];
    798     [self updateTorrentHistory];
     788    [self updateTorrentsInQueue];
    799789}
    800790
     
    11571147    [fInfoController updateInfoStats];
    11581148   
    1159     [self applyFilter: nil];
    1160     [self checkToStartWaiting: torrent];
     1149    [self updateTorrentsInQueue];
    11611150   
    11621151    if ([fDefaults boolForKey: @"PlayDownloadSound"])
     
    15781567- (void) checkWaitingForStopped: (NSNotification *) notification
    15791568{
    1580     [self checkToStartWaiting: [notification object]];
     1569    [self updateTorrentsInQueue];
    15811570   
    15821571    [self updateUI: nil];
     
    15851574}
    15861575
    1587 - (void) checkToStartWaiting: (Torrent *) finishedTorrent
    1588 {
    1589     //don't try to start a transfer if there should be none waiting
    1590     if (![fDefaults boolForKey: @"Queue"])
    1591         return;
    1592 
    1593     int desiredActive = [fDefaults integerForKey: @"QueueDownloadNumber"];
    1594    
    1595     NSEnumerator * enumerator = [fTorrents objectEnumerator];
    1596     Torrent * torrent, * torrentToStart = nil;
    1597     while ((torrent = [enumerator nextObject]))
    1598     {
    1599         //ignore the torrent just stopped
    1600         if (torrent == finishedTorrent)
    1601             continue;
    1602    
    1603         if ([torrent isActive])
    1604         {
    1605             if (![torrent isSeeding] && ![torrent isError])
    1606             {
    1607                 desiredActive--;
    1608                 if (desiredActive <= 0)
    1609                     return;
    1610             }
    1611         }
    1612         else
    1613         {
    1614             //use as next if it is waiting to start and either no previous or order value is lower
    1615             if ([torrent waitingToStart] && (!torrentToStart
    1616                 || [[torrentToStart orderValue] compare: [torrent orderValue]] == NSOrderedDescending))
    1617                 torrentToStart = torrent;
    1618         }
    1619     }
    1620    
    1621     //since it hasn't returned, the queue amount has not been met
    1622     if (torrentToStart)
    1623     {
    1624         [torrentToStart startTransfer];
    1625        
    1626         [self updateUI: nil];
    1627         [self applyFilter: nil];
    1628         [self updateTorrentHistory];
    1629     }
    1630 }
    1631 
    16321576- (void) torrentStartSettingChange: (NSNotification *) notification
    16331577{
    1634     [self attemptToStartMultipleAuto: [notification object]];
    1635 
    1636     [self updateUI: nil];
    1637     [self applyFilter: nil];
    1638     [self updateTorrentHistory];
     1578    [self updateTorrentsInQueue];
    16391579}
    16401580
    16411581- (void) globalStartSettingChange: (NSNotification *) notification
    16421582{
    1643     [self attemptToStartMultipleAuto: fTorrents];
    1644    
    1645     [self updateUI: nil];
    1646     [self applyFilter: nil];
    1647     [self updateTorrentHistory];
     1583    [self updateTorrentsInQueue];
    16481584}
    16491585
     
    16671603- (void) attemptToStartAuto: (Torrent *) torrent
    16681604{
    1669     [self attemptToStartMultipleAuto: [NSArray arrayWithObject: torrent]];
     1605    [self updateTorrentsInQueue];
    16701606}
    16711607
    16721608//will try to start, taking into consideration the start preference
    1673 - (void) attemptToStartMultipleAuto: (NSArray *) torrents
     1609- (void) updateTorrentsInQueue
    16741610{
    16751611    if (![fDefaults boolForKey: @"Queue"])
    16761612    {
    1677         NSEnumerator * enumerator = [torrents objectEnumerator];
     1613        NSEnumerator * enumerator = [fTorrents objectEnumerator];
    16781614        Torrent * torrent;
    16791615        while ((torrent = [enumerator nextObject]))
     
    16981634   
    16991635    //sort torrents by order value
    1700     NSArray * sortedTorrents;
    1701     if ([torrents count] > 1 && desiredActive > 0)
    1702     {
    1703         NSSortDescriptor * orderDescriptor = [[[NSSortDescriptor alloc] initWithKey:
    1704                                                     @"orderValue" ascending: YES] autorelease];
    1705         NSArray * descriptors = [[NSArray alloc] initWithObjects: orderDescriptor, nil];
    1706        
    1707         sortedTorrents = [torrents sortedArrayUsingDescriptors: descriptors];
    1708         [descriptors release];
    1709     }
    1710     else
    1711         sortedTorrents = torrents;
     1636    NSSortDescriptor * orderDescriptor = [[[NSSortDescriptor alloc] initWithKey:
     1637                                                @"orderValue" ascending: YES] autorelease];
     1638    NSArray * descriptors = [[NSArray alloc] initWithObjects: orderDescriptor, nil];
     1639       
     1640    NSArray * sortedTorrents = [fTorrents sortedArrayUsingDescriptors: descriptors];
     1641    [descriptors release];
    17121642
    17131643    enumerator = [sortedTorrents objectEnumerator];
     
    17211651            {
    17221652                [torrent startTransfer];
    1723                 desiredActive--;
     1653                if ([torrent isActive])
     1654                    desiredActive--;
    17241655            }
    17251656            else
     
    17291660        }
    17301661    }
     1662   
     1663    [self updateUI: nil];
     1664    [self applyFilter: nil];
     1665    [self updateTorrentHistory];
    17311666}
    17321667
  • trunk/macosx/Torrent.m

    r1320 r1322  
    259259        }
    260260       
     261        fStat = tr_torrentStat(fHandle);
    261262        [[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentFinishedDownloading" object: self];
    262263    }
     
    447448   
    448449    if (![self isActive] && [self alertForVolumeAvailable] && [self alertForRemainingDiskSpace])
     450    {
    449451        tr_torrentStart(fHandle);
     452        [self update];
     453    }
    450454}
    451455
     
    459463   
    460464        tr_torrentStop(fHandle);
     465        [self update];
    461466
    462467        if (!wasSeeding)
Note: See TracChangeset for help on using the changeset viewer.