Ignore:
Timestamp:
Aug 2, 2011, 12:43:26 PM (10 years ago)
Author:
livings124
Message:

first go at bringing the libT queue to the Mac client

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.m

    r12598 r12612  
    287287        tr_bencDictAddStr(&settings, TR_PREFS_KEY_DOWNLOAD_DIR, [[[fDefaults stringForKey: @"DownloadFolder"]
    288288                                                                    stringByExpandingTildeInPath] UTF8String]);
     289        tr_bencDictAddBool(&settings, TR_PREFS_KEY_DOWNLOAD_QUEUE_ENABLED, [fDefaults boolForKey: @"Queue"]);
     290        tr_bencDictAddInt(&settings, TR_PREFS_KEY_DOWNLOAD_QUEUE_SIZE, [fDefaults integerForKey: @"QueueDownloadNumber"]);
    289291        tr_bencDictAddInt(&settings, TR_PREFS_KEY_IDLE_LIMIT, [fDefaults integerForKey: @"IdleLimitMinutes"]);
    290292        tr_bencDictAddBool(&settings, TR_PREFS_KEY_IDLE_LIMIT_ENABLED, [fDefaults boolForKey: @"IdleLimitCheck"]);
     
    308310        tr_bencDictAddBool(&settings, TR_PREFS_KEY_PEX_ENABLED, [fDefaults boolForKey: @"PEXGlobal"]);
    309311        tr_bencDictAddBool(&settings, TR_PREFS_KEY_PORT_FORWARDING, [fDefaults boolForKey: @"NatTraversal"]);
     312        tr_bencDictAddInt(&settings, TR_PREFS_KEY_QUEUE_STALLED_MINUTES, [fDefaults integerForKey: @"StalledMinutes"]);
    310313        tr_bencDictAddReal(&settings, TR_PREFS_KEY_RATIO, [fDefaults floatForKey: @"RatioLimit"]);
    311314        tr_bencDictAddBool(&settings, TR_PREFS_KEY_RATIO_ENABLED, [fDefaults boolForKey: @"RatioCheck"]);
     
    316319        tr_bencDictAddStr(&settings, TR_PREFS_KEY_RPC_USERNAME,  [[fDefaults stringForKey: @"RPCUsername"] UTF8String]);
    317320        tr_bencDictAddBool(&settings, TR_PREFS_KEY_RPC_WHITELIST_ENABLED,  [fDefaults boolForKey: @"RPCUseWhitelist"]);
     321        tr_bencDictAddBool(&settings, TR_PREFS_KEY_SEED_QUEUE_ENABLED, [fDefaults boolForKey: @"QueueSeed"]);
     322        tr_bencDictAddInt(&settings, TR_PREFS_KEY_SEED_QUEUE_SIZE, [fDefaults integerForKey: @"QueueSeedNumber"]);
    318323        tr_bencDictAddBool(&settings, TR_PREFS_KEY_START, [fDefaults boolForKey: @"AutoStartDownload"]);
    319324        tr_bencDictAddBool(&settings, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED, [fDefaults boolForKey: @"DoneScriptEnabled"]);
     
    447452    if (history)
    448453    {
     454        NSMutableArray * waitToStartTorrents = [NSMutableArray arrayWithCapacity: (([history count] > 0 && !fPauseOnLaunch) ? [history count]-1 : 0)]; //theoretical max without doing a lot of work
     455       
    449456        for (NSDictionary * historyItem in history)
    450457        {
     
    453460            {
    454461                [fTorrents addObject: torrent];
     462               
     463                NSNumber * waitToStart;
     464                if (!fPauseOnLaunch && (waitToStart = [historyItem objectForKey: @"WaitToStart"]) && [waitToStart boolValue])
     465                    [waitToStartTorrents addObject: torrent];
     466               
    455467                [torrent release];
    456468            }
    457469        }
     470       
     471        //now that all are loaded, let's set those in the queue to waiting
     472        for (Torrent * torrent in waitToStartTorrents)
     473            [torrent startTransfer];
    458474    }
    459475   
     
    491507                    name: @"MakeWindowKey" object: nil];
    492508   
     509#warning look at this
    493510    [nc addObserver: self selector: @selector(updateTorrentsInQueue)
    494511                    name: @"UpdateQueue" object: nil];
     
    882899        else
    883900        {
    884             [torrent setWaitToStart: [fDefaults boolForKey: @"AutoStartDownload"]];
     901            if ([fDefaults boolForKey: @"AutoStartDownload"])
     902                [torrent startTransfer];
    885903           
    886904            [torrent update];
     
    951969    else
    952970    {
    953         [torrent setWaitToStart: [fDefaults boolForKey: @"AutoStartDownload"]];
     971        if ([fDefaults boolForKey: @"AutoStartDownload"])
     972            [torrent startTransfer];
    954973       
    955974        [torrent update];
     
    11761195{
    11771196    for (Torrent * torrent in torrents)
    1178         [torrent setWaitToStart: YES];
     1197        [torrent startTransfer];
    11791198   
    11801199    [self updateTorrentsInQueue];
     
    11911210   
    11921211    for (Torrent * torrent in fTorrents)
    1193         if (![torrent isActive] && [torrent waitingToStart])
     1212        if ([torrent waitingToStart])
    11941213            [torrents addObject: torrent];
    11951214   
     
    12011220    //iterate through instead of all at once to ensure no conflicts
    12021221    for (Torrent * torrent in torrents)
    1203     {
    1204         tr_inf( "restarting a torrent in resumeTorrentsNoWait" );
    1205         [torrent startTransfer];
    1206     }
    1207    
     1222        [torrent startTransferNoQueue];
     1223   
     1224    #warning change to updateTorrentsInQueue?
    12081225    [self updateUI];
    12091226    [self applyFilter];
     
    12241241- (void) stopTorrents: (NSArray *) torrents
    12251242{
     1243#warning look into stopping all without starting any
    12261244    //don't want any of these starting then stopping
    1227     for (Torrent * torrent in torrents)
    1228         [torrent setWaitToStart: NO];
     1245    /*for (Torrent * torrent in torrents)
     1246        [torrent setWaitToStart: NO];*/
    12291247
    12301248    [torrents makeObjectsPerformSelector: @selector(stopTransfer)];
     
    13251343    [selectedValues removeObjectsInArray: torrents];
    13261344   
     1345#warning look into stopping all without starting any
    13271346    //don't want any of these starting then stopping
    1328     for (Torrent * torrent in torrents)
    1329         [torrent setWaitToStart: NO];
     1347    /*for (Torrent * torrent in torrents)
     1348        [torrent setWaitToStart: NO];*/
    13301349   
    13311350    [fTorrents removeObjectsInArray: torrents];
     
    17081727}
    17091728
     1729#warning rename? remove?
    17101730- (void) updateTorrentsInQueue
    17111731{
    1712     NSUInteger desiredDownloadActive = [fDefaults boolForKey: @"Queue"] ? [self numToStartFromQueue: YES] : NSUIntegerMax,
    1713                 desiredSeedActive = [fDefaults boolForKey: @"QueueSeed"] ? [self numToStartFromQueue: NO] : NSUIntegerMax;
    1714    
    1715     for (Torrent * torrent in fTorrents)
    1716     {
    1717         if (desiredDownloadActive == 0 && desiredSeedActive == 0)
    1718             break;
    1719        
    1720         if (![torrent isActive] && ![torrent isChecking] && [torrent waitingToStart])
    1721         {
    1722             if (![torrent allDownloaded])
    1723             {
    1724                 if (desiredDownloadActive > 0)
    1725                 {
    1726                     tr_inf( "restarting download torrent in mac queue" );
    1727                     [torrent startTransfer];
    1728                     if ([torrent isActive])
    1729                         --desiredDownloadActive;
    1730                     [torrent update];
    1731                 }
    1732             }
    1733             else
    1734             {
    1735                 if (desiredSeedActive > 0)
    1736                 {
    1737                     tr_inf( "restarting seed torrent in mac queue" );
    1738                     [torrent startTransfer];
    1739                     if ([torrent isActive])
    1740                         --desiredSeedActive;
    1741                     [torrent update];
    1742                 }
    1743             }
    1744         }
    1745     }
    1746    
    17471732    [self updateUI];
    17481733    [self applyFilter];
    17491734    [[fWindow toolbar] validateVisibleItems];
    17501735    [self updateTorrentHistory];
    1751 }
    1752 
    1753 - (NSUInteger) numToStartFromQueue: (BOOL) downloadQueue
    1754 {
    1755     if (![fDefaults boolForKey: downloadQueue ? @"Queue" : @"QueueSeed"])
    1756         return 0;
    1757    
    1758     NSUInteger desired = [fDefaults integerForKey: downloadQueue ? @"QueueDownloadNumber" : @"QueueSeedNumber"];
    1759        
    1760     for (Torrent * torrent in fTorrents)
    1761     {
    1762         if (desired == 0)
    1763             break;
    1764        
    1765         if ([torrent isChecking])
    1766             --desired;
    1767         else if ([torrent isActive] && ![torrent isStalled] && ![torrent isError])
    1768         {
    1769             if ([torrent allDownloaded] != downloadQueue)
    1770                 --desired;
    1771         }
    1772         else;
    1773     }
    1774    
    1775     return desired;
    17761736}
    17771737
     
    18091769        [[NSDistributedNotificationCenter defaultCenter] postNotificationName: @"com.apple.DownloadFileFinished"
    18101770            object: [torrent dataLocation]];
    1811        
    1812         if ([torrent isActive] && [fDefaults boolForKey: @"QueueSeed"] && [self numToStartFromQueue: NO] == 0)
    1813         {
    1814             [torrent stopTransfer];
    1815             [torrent setWaitToStart: YES];
    1816         }
    18171771    }
    18181772   
     
    18201774}
    18211775
     1776#warning remove?
    18221777- (void) torrentRestartedDownloading: (NSNotification *) notification
    18231778{
    1824     Torrent * torrent = [notification object];
    1825     if ([torrent isActive] && [fDefaults boolForKey: @"Queue"] && [self numToStartFromQueue: YES] == 0)
    1826     {
    1827         [torrent stopTransfer];
    1828         [torrent setWaitToStart: YES];
    1829     }
    1830    
    18311779    [self updateTorrentsInQueue];
    18321780}
     
    27012649            NSUInteger insertIndex = topTorrent ? [fTorrents indexOfObject: topTorrent] + 1 : 0;
    27022650            NSIndexSet * insertIndexes = [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(insertIndex, [movingTorrents count])];
     2651            for (Torrent * torrent in movingTorrents)
     2652                [torrent setQueueIndex: insertIndex++];
    27032653            [fTorrents insertObjects: movingTorrents atIndexes: insertIndexes];
    27042654        }
     
    41654115}
    41664116
     4117#warning handle queue state changes
    41674118- (void) rpcCallback: (tr_rpc_callback_type) type forTorrentStruct: (struct tr_torrent *) torrentStruct
    41684119{
Note: See TracChangeset for help on using the changeset viewer.