Changeset 452


Ignore:
Timestamp:
Jun 23, 2006, 10:32:01 PM (16 years ago)
Author:
livings124
Message:

Some more work on queueing.

Location:
trunk/macosx
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.h

    r450 r452  
    133133- (void) ratioGlobalChange: (NSNotification *) notification;
    134134
    135 - (void) checkWaitingForFinished: (NSNotification *) notification;
    136 - (void) startSettingChange: (NSNotification *) notification;
     135- (void) checkWaitingForStopped: (NSNotification *) notification;
     136- (void) checkWaitingForFinished: (Torrent *) finishedTorrent;
     137- (void) torrentStartSettingChange: (NSNotification *) notification;
     138- (void) globalStartSettingChange: (NSNotification *) notification;
     139
     140- (void) attemptToStartAuto: (Torrent *) torrent;
    137141
    138142- (void) reloadInspector: (NSNotification *) notification;
  • trunk/macosx/Controller.m

    r450 r452  
    210210                    name: @"RatioGlobalChange" object: nil];
    211211   
    212     [nc addObserver: self selector: @selector(checkWaitingForFinished:)
    213                     name: @"TorrentFinishedDownloading" object: nil];
    214    
    215     [nc addObserver: self selector: @selector(startSettingChange:)
    216                     name: @"StartSettingChange" object: nil];
    217    
     212    //check to start another because of stopped torrent
     213    [nc addObserver: self selector: @selector(checkWaitingForStopped:)
     214                    name: @"StoppedDownloading" object: nil];
     215   
     216    //check all torrents for starting
     217    [nc addObserver: self selector: @selector(globalStartSettingChange:)
     218                    name: @"GlobalStartSettingChange" object: nil];
     219
     220    //check if torrent should now start
     221    [nc addObserver: self selector: @selector(torrentStartSettingChange:)
     222                    name: @"TorrentStartSettingChange" object: nil];
     223   
     224    //change that just impacts the inspector
    218225    [nc addObserver: self selector: @selector(reloadInspector:)
    219226                    name: @"TorrentSettingChange" object: nil];
     
    324331    if (code == NSOKButton)
    325332    {
    326         //setup for autostart
    327         NSString * startSetting = [fDefaults stringForKey: @"StartSetting"];
    328         BOOL waitToStart = [startSetting isEqualToString: @"Wait"];
    329         int desiredActive, active = 0;
    330         if (waitToStart)
    331         {
    332             desiredActive = [fDefaults integerForKey: @"WaitToStartNumber"];
    333             Torrent * tempTorrent;
    334             NSEnumerator * enumerator = [fTorrents objectEnumerator];
    335             while ((tempTorrent = [enumerator nextObject]))
    336                 if ([tempTorrent isActive] && ![tempTorrent isSeeding])
    337                     active++;
    338         }
    339    
    340333        [torrent setDownloadFolder: [[openPanel filenames] objectAtIndex: 0]];
    341         if ((waitToStart && active < desiredActive) || [startSetting isEqualToString: @"Start"])
    342             [torrent startTransfer];
     334        [self attemptToStartAuto: torrent];
    343335        [fTorrents addObject: torrent];
     336        [torrent update];
    344337       
    345338        [self torrentNumberChanged];
     
    352345{
    353346    NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"], * torrentPath;
    354    
    355     //setup for autostart
    356     NSString * startSetting = [fDefaults stringForKey: @"StartSetting"];
    357     BOOL waitToStart = [startSetting isEqualToString: @"Wait"];
    358     int desiredActive, active = 0;
    359     if (waitToStart && ![downloadChoice isEqualToString: @"Ask"])
    360     {
    361         desiredActive = [fDefaults integerForKey: @"WaitToStartNumber"];
    362         Torrent * tempTorrent;
    363         NSEnumerator * enumerator = [fTorrents objectEnumerator];
    364         while ((tempTorrent = [enumerator nextObject]))
    365             if ([tempTorrent isActive] && ![tempTorrent isSeeding])
    366                 active++;
    367     }
    368    
    369347    Torrent * torrent;
    370348    NSEnumerator * enumerator = [filenames objectEnumerator];
     
    403381
    404382            [torrent setDownloadFolder: folder];
    405             #warning should check if transfer was already done
    406             if ((waitToStart && active < desiredActive) || [startSetting isEqualToString: @"Start"])
    407             {
    408                 [torrent startTransfer];
    409                 active++;
    410             }
     383            [self attemptToStartAuto: torrent];
    411384            [fTorrents addObject: torrent];
     385            [torrent update];
    412386        }
    413387       
     
    745719        if ([torrent justFinished])
    746720        {
     721            [self checkWaitingForFinished: torrent];
     722       
    747723            //notifications
    748724            [self notifyGrowl: [torrent name]];
     
    939915}
    940916
    941 - (void) checkWaitingForFinished: (NSNotification *) notification
     917- (void) checkWaitingForStopped: (NSNotification *) notification
     918{
     919    [self checkWaitingForFinished: [notification object]];
     920}
     921
     922- (void) checkWaitingForFinished: (Torrent *) finishedTorrent
    942923{
    943924    //don't try to start a transfer if there should be none waiting
     
    952933    {
    953934        //ignore the torrent just stopped; for some reason it is not marked instantly as not active
    954         if (torrent == [notification object])
     935        if (torrent == finishedTorrent)
    955936            continue;
    956937   
     
    981962}
    982963
    983 - (void) startSettingChange: (NSNotification *) notification
     964- (void) globalStartSettingChange: (NSNotification *) notification
    984965{
    985966    NSString * startSetting = [fDefaults stringForKey: @"StartSetting"];
     
    10491030}
    10501031
     1032- (void) torrentStartSettingChange: (NSNotification *) notification
     1033{
     1034    [self attemptToStartAuto: [notification object]];
     1035
     1036    [self updateUI: nil];
     1037    [self updateTorrentHistory];
     1038}
     1039
     1040//will try to start, taking into consideration the start preference
     1041- (void) attemptToStartAuto: (Torrent *) torrent
     1042{
     1043    #warning should check if transfer was already done
     1044    if (![torrent waitingToStart])
     1045        return;
     1046
     1047    NSString * startSetting = [fDefaults stringForKey: @"StartSetting"];
     1048    if ([startSetting isEqualToString: @"Wait"])
     1049    {
     1050        int desiredActive = [fDefaults integerForKey: @"WaitToStartNumber"];
     1051       
     1052        Torrent * tempTorrent;
     1053        NSEnumerator * enumerator = [fTorrents objectEnumerator];
     1054        while ((tempTorrent = [enumerator nextObject]))
     1055            if ([tempTorrent isActive] && ![tempTorrent isSeeding])
     1056            {
     1057                desiredActive--;
     1058                if (desiredActive <= 0)
     1059                    return;
     1060            }
     1061       
     1062        [torrent startTransfer];
     1063    }
     1064    else if ([startSetting isEqualToString: @"Start"])
     1065        [torrent startTransfer];
     1066    else;
     1067}
     1068
    10511069- (void) reloadInspector: (NSNotification *) notification
    10521070{
  • trunk/macosx/InfoWindowController.m

    r451 r452  
    198198        [fWaitToStartButton setState: [torrent waitingToStart]];
    199199       
    200         [fWaitToStartButton setEnabled: ![torrent isActive] && [torrent progress] < 1.0
    201             && [[[NSUserDefaults standardUserDefaults] stringForKey: @"StartSetting"] isEqualToString: @"Wait"]];
     200        #warning disable if actively downloading or finished
     201        [fWaitToStartButton setEnabled:
     202            [[[NSUserDefaults standardUserDefaults] stringForKey: @"StartSetting"] isEqualToString: @"Wait"]];
    202203    }
    203204    else
     
    471472- (void) setWaitToStart: (id) sender
    472473{
    473     BOOL wait = [sender state];
    474 
    475474    Torrent * torrent;
    476475    NSEnumerator * enumerator = [fTorrents objectEnumerator];
    477476    while ((torrent = [enumerator nextObject]))
    478         [torrent setWaitToStart: wait];
    479    
    480     [[NSNotificationCenter defaultCenter] postNotificationName: @"StartSettingChange" object: self];
     477        [torrent setWaitToStart: [sender state]];
     478   
     479    [[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentStartSettingChange" object: torrent];
    481480}
    482481
  • trunk/macosx/PrefsController.m

    r448 r452  
    453453        [fDefaults setInteger: waitNumber forKey: @"WaitToStartNumber"];
    454454   
    455     [[NSNotificationCenter defaultCenter] postNotificationName: @"StartSettingChange" object: self];
     455    [[NSNotificationCenter defaultCenter] postNotificationName: @"GlobalStartSettingChange" object: self];
    456456}
    457457
  • trunk/macosx/Torrent.m

    r450 r452  
    244244   
    245245        tr_torrentStop(fHandle);
    246        
     246
    247247        if (!wasSeeding)
    248             [[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentFinishedDownloading" object: self];
     248            [[NSNotificationCenter defaultCenter] postNotificationName: @"StoppedDownloading" object: self];
    249249    }
    250250}
     
    453453- (BOOL) justFinished
    454454{
    455     BOOL finished = tr_getFinished(fHandle);
    456     if (finished)
    457         [[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentFinishedDownloading" object: self];
    458    
    459     return finished;
     455    return tr_getFinished(fHandle);
    460456}
    461457
     
    598594   
    599595    fWaitToStart = waitToStart ? [waitToStart boolValue]
    600                     : [[fDefaults stringForKey: @"StartSetting"] isEqualToString: @"Wait"];
     596                    : ![[fDefaults stringForKey: @"StartSetting"] isEqualToString: @"Manual"];
    601597   
    602598    NSString * fileType = fInfo->multifile ? NSFileTypeForHFSTypeCode('fldr') : [[self name] pathExtension];
Note: See TracChangeset for help on using the changeset viewer.