Changeset 448


Ignore:
Timestamp:
Jun 23, 2006, 5:40:56 PM (15 years ago)
Author:
livings124
Message:

If changing preference:

  • from wait to start automatically, start all waiting transfers.
  • to higher number of active torrents, start waiting torrents until amount active is met.
Location:
trunk/macosx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.m

    r447 r448  
    215215    [nc addObserver: self selector: @selector(checkWaitingForFinished:)
    216216                    name: @"TorrentFinishedDownloading" object: nil];
     217   
     218    [nc addObserver: self selector: @selector(startSettingChange:)
     219                    name: @"StartSettingChange" object: nil];
    217220
    218221    //timer to update the interface
     
    984987        [self updateUI: nil];
    985988    }
     989}
     990
     991- (void) startSettingChange: (NSNotification *) notification
     992{
     993    NSString * startSetting = [fDefaults stringForKey: @"StartSetting"];
     994   
     995    if ([startSetting isEqualToString: @"Start"])
     996    {
     997        NSEnumerator * enumerator = [fTorrents objectEnumerator];
     998        Torrent * torrent;
     999        while ((torrent = [enumerator nextObject]))
     1000            if ([torrent waitingToStart])
     1001                [torrent startTransfer];
     1002    }
     1003    else if ([startSetting isEqualToString: @"Wait"])
     1004    {
     1005        NSMutableArray * waitingTorrents = [[NSMutableArray alloc] initWithCapacity: [fTorrents count]];
     1006   
     1007        int amountToStart = [fDefaults integerForKey: @"WaitToStartNumber"];
     1008       
     1009        NSEnumerator * enumerator = [fTorrents objectEnumerator];
     1010        Torrent * torrent;
     1011        while ((torrent = [enumerator nextObject]))
     1012        {
     1013            if ([torrent isActive])
     1014            {
     1015                if (![torrent isSeeding])
     1016                    amountToStart--;
     1017            }
     1018            else if ([torrent waitingToStart])
     1019                [waitingTorrents addObject: torrent];
     1020            else;
     1021        }
     1022       
     1023        int waitingCount = [waitingTorrents count];
     1024        if (amountToStart > waitingCount)
     1025            amountToStart = waitingCount;
     1026       
     1027        //sort torrents by date to start earliest added
     1028        if (amountToStart > 0 && amountToStart < waitingCount)
     1029        {
     1030            NSSortDescriptor * dateDescriptor = [[[NSSortDescriptor alloc] initWithKey:
     1031                                                        @"date" ascending: YES] autorelease];
     1032            NSArray * descriptors = [[NSArray alloc] initWithObjects: dateDescriptor, nil];
     1033           
     1034            [waitingTorrents sortUsingDescriptors: descriptors];
     1035            [descriptors release];
     1036        }
     1037       
     1038        int i;
     1039        for (i = 0; i < amountToStart; i++)
     1040            [[waitingTorrents objectAtIndex: i] startTransfer];
     1041       
     1042        [waitingTorrents release];
     1043    }
     1044    else;
     1045   
     1046    [self updateUI: nil];
     1047    #warning reload inspector
    9861048}
    9871049
  • trunk/macosx/PrefsController.m

    r446 r448  
    453453        [fDefaults setInteger: waitNumber forKey: @"WaitToStartNumber"];
    454454   
    455     #warning notification recheck
     455    [[NSNotificationCenter defaultCenter] postNotificationName: @"StartSettingChange" object: self];
    456456}
    457457
Note: See TracChangeset for help on using the changeset viewer.