Changeset 446


Ignore:
Timestamp:
Jun 23, 2006, 3:06:27 PM (16 years ago)
Author:
livings124
Message:

The beginning of queueing. Has some work to go, but the basic infrastructure is set up.

Location:
trunk/macosx
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.h

    r394 r446  
    134134- (void) ratioSingleChange: (NSNotification *) notification;
    135135
     136- (void) checkWaitingForFinished: (NSNotification *) notification;
     137
    136138- (void) sleepCallBack: (natural_t) messageType argument:
    137139                        (void *) messageArgument;
  • trunk/macosx/Controller.m

    r442 r446  
    212212    [nc addObserver: self selector: @selector(ratioGlobalChange:)
    213213                    name: @"RatioGlobalChange" object: nil];
     214   
     215    [nc addObserver: self selector: @selector(checkWaitingForFinished:)
     216                    name: @"TorrentFinishedDownloading" object: nil];
    214217
    215218    //timer to update the interface
     
    318321    if (code == NSOKButton)
    319322    {
     323        //setup for autostart
     324        NSString * startSetting = [fDefaults stringForKey: @"StartSetting"];
     325        BOOL waitToStart = [startSetting isEqualToString: @"Wait"];
     326        int desiredActive, active = 0;
     327        if (waitToStart)
     328        {
     329            desiredActive = [fDefaults integerForKey: @"WaitToStartNumber"];
     330            Torrent * tempTorrent;
     331            NSEnumerator * enumerator = [fTorrents objectEnumerator];
     332            while ((tempTorrent = [enumerator nextObject]))
     333                if ([tempTorrent isActive] && ![tempTorrent isSeeding])
     334                    active++;
     335        }
     336   
    320337        [torrent setDownloadFolder: [[openPanel filenames] objectAtIndex: 0]];
    321         if ([fDefaults boolForKey: @"AutoStartDownload"])
     338        if ((waitToStart && active < desiredActive) || [startSetting isEqualToString: @"Start"])
    322339            [torrent startTransfer];
    323340        [fTorrents addObject: torrent];
     
    329346}
    330347
    331 - (void) application: (NSApplication *) sender
    332          openFiles: (NSArray *) filenames
    333 {
    334     BOOL autoStart = [fDefaults boolForKey: @"AutoStartDownload"];
    335    
     348- (void) application: (NSApplication *) sender openFiles: (NSArray *) filenames
     349{
    336350    NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"], * torrentPath;
     351   
     352    //setup for autostart
     353    NSString * startSetting = [fDefaults stringForKey: @"StartSetting"];
     354    BOOL waitToStart = [startSetting isEqualToString: @"Wait"];
     355    int desiredActive, active = 0;
     356    if (waitToStart && ![downloadChoice isEqualToString: @"Ask"])
     357    {
     358        desiredActive = [fDefaults integerForKey: @"WaitToStartNumber"];
     359        Torrent * tempTorrent;
     360        NSEnumerator * enumerator = [fTorrents objectEnumerator];
     361        while ((tempTorrent = [enumerator nextObject]))
     362            if ([tempTorrent isActive] && ![tempTorrent isSeeding])
     363                active++;
     364    }
     365   
    337366    Torrent * torrent;
    338367    NSEnumerator * enumerator = [filenames objectEnumerator];
     
    342371            continue;
    343372
    344         /* Add it to the "File > Open Recent" menu */
     373        //add it to the "File > Open Recent" menu
    345374        [[NSDocumentController sharedDocumentController]
    346375            noteNewRecentDocumentURL: [NSURL fileURLWithPath: torrentPath]];
     
    371400
    372401            [torrent setDownloadFolder: folder];
    373             if (autoStart)
     402            #warning should check if transfer was already done
     403            if ((waitToStart && active < desiredActive) || [startSetting isEqualToString: @"Start"])
     404            {
    374405                [torrent startTransfer];
     406                active++;
     407            }
    375408            [fTorrents addObject: torrent];
    376409        }
     
    503536            active++;
    504537
    505     if( active > 0 && [fDefaults boolForKey: @"CheckRemove"] )
     538    if (active > 0 && [fDefaults boolForKey: @"CheckRemove"])
    506539    {
    507540        NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys:
     
    911944}
    912945
     946- (void) checkWaitingForFinished: (NSNotification *) notification
     947{
     948    //don't try to start a transfer if there should be none waiting
     949    if (![[fDefaults stringForKey: @"StartSetting"] isEqualToString: @"Wait"])
     950        return;
     951
     952    int desiredActive = [fDefaults integerForKey: @"WaitToStartNumber"], active = 0;
     953   
     954    NSEnumerator * enumerator = [fTorrents objectEnumerator];
     955    Torrent * torrent, * torrentToStart = nil;
     956    while ((torrent = [enumerator nextObject]))
     957    {
     958        //ignore the torrent just stopped; for some reason it is not marked instantly as not active
     959        if (torrent == [notification object])
     960            continue;
     961   
     962        if ([torrent isActive])
     963        {
     964            if (![torrent isSeeding])
     965            {
     966                active++;
     967                if (active >= desiredActive)
     968                    return;
     969            }
     970        }
     971        else
     972        {
     973            if (!torrentToStart && [torrent waitingToStart])
     974                torrentToStart = torrent;
     975        }
     976    }
     977   
     978    //since it hasn't returned, the queue amount has not been met
     979    if (torrentToStart)
     980    {
     981        [torrentToStart startTransfer];
     982        [self updateUI: nil];
     983    }
     984}
     985
    913986- (int) numberOfRowsInTableView: (NSTableView *) t
    914987{
  • trunk/macosx/Defaults.plist

    r425 r446  
    33<plist version="1.0">
    44<dict>
    5         <key>AutoStartDownload</key>
    6         <true/>
    75        <key>BadgeDownloadRate</key>
    86        <false/>
     
    5149        <key>Sort</key>
    5250        <string>Date</string>
     51        <key>StartSetting</key>
     52        <string>Start</string>
    5353        <key>StatusBar</key>
    5454        <true/>
     
    5959        <key>UseAdvancedBar</key>
    6060        <false/>
     61        <key>WaitToStartNumber</key>
     62        <integer>3</integer>
    6163</dict>
    6264</plist>
  • trunk/macosx/English.lproj/PrefsWindow.nib/classes.nib

    r310 r446  
    66            ACTIONS = {
    77                folderSheetShow = id;
    8                 setAutoStart = id;
    98                setBadge = id;
    109                setDownloadLocation = id;
     
    1615                setRatioCheck = id;
    1716                setShowMessage = id;
     17                setStartSetting = id;
    1818                setUpdate = id;
     19                setWaitToStart = id;
    1920            };
    2021            CLASS = PrefsController;
    2122            LANGUAGE = ObjC;
    2223            OUTLETS = {
    23                 fAutoStartCheck = NSButton;
    2424                fBadgeDownloadRateCheck = NSButton;
    2525                fBadgeUploadRateCheck = NSButton;
     
    3636                fRatioField = NSTextField;
    3737                fRemoveCheck = NSButton;
     38                fStartMatrix = NSMatrix;
    3839                fTransfersView = NSView;
    3940                fUpdatePopUp = NSPopUpButton;
     
    4142                fUploadCheck = NSButton;
    4243                fUploadField = NSTextField;
     44                fWaitToStartField = NSTextField;
    4345            };
    4446            SUPERCLASS = NSWindowController;
  • trunk/macosx/English.lproj/PrefsWindow.nib/info.nib

    r319 r446  
    88        <dict>
    99                <key>28</key>
    10                 <string>195 461 462 212 0 0 1152 842 </string>
     10                <string>321 472 535 212 0 0 1152 842 </string>
    1111                <key>41</key>
    12                 <string>345 427 462 306 0 0 1152 842 </string>
     12                <string>286 392 535 345 0 0 1152 842 </string>
    1313                <key>66</key>
    14                 <string>345 526 462 104 0 0 1152 842 </string>
     14                <string>321 526 535 104 0 0 1152 842 </string>
    1515        </dict>
    1616        <key>IBFramework Version</key>
    1717        <string>446.1</string>
    18         <key>IBOpenObjects</key>
    19         <array>
    20                 <integer>41</integer>
    21         </array>
    2218        <key>IBSystem Version</key>
    2319        <string>8I127</string>
  • trunk/macosx/InfoWindowController.m

    r431 r446  
    409409- (void) setRatioCheck: (id) sender
    410410{
    411     NSButtonCell * selected = [fRatioMatrix selectedCell];
    412     int ratioSetting;
    413     if (selected == [fRatioMatrix cellWithTag: RATIO_CHECK_TAG])
     411    int ratioSetting, tag = [[fRatioMatrix selectedCell] tag];
     412    if (tag == RATIO_CHECK_TAG)
    414413        ratioSetting = RATIO_CHECK;
    415     else if (selected == [fRatioMatrix cellWithTag: RATIO_NO_CHECK_TAG])
     414    else if (tag == RATIO_NO_CHECK_TAG)
    416415        ratioSetting = RATIO_NO_CHECK;
    417416    else
     
    424423   
    425424    [self setRatioLimit: fRatioLimitField];
    426     [fRatioLimitField setEnabled: selected == [fRatioMatrix cellWithTag: RATIO_CHECK_TAG]];
     425    [fRatioLimitField setEnabled: tag == RATIO_CHECK_TAG];
    427426}
    428427
  • trunk/macosx/PrefsController.h

    r382 r446  
    3737    IBOutlet NSButton       * fQuitCheck, * fRemoveCheck,
    3838                            * fBadgeDownloadRateCheck, * fBadgeUploadRateCheck,
    39                             * fAutoStartCheck, * fCopyTorrentCheck, * fDeleteOriginalTorrentCheck;
     39                            * fCopyTorrentCheck, * fDeleteOriginalTorrentCheck;
    4040    IBOutlet NSPopUpButton  * fUpdatePopUp;
    4141
     
    4545    IBOutlet NSButton       * fRatioCheck;
    4646    IBOutlet NSTextField    * fRatioField;
     47   
     48    IBOutlet NSMatrix       * fStartMatrix;
     49    IBOutlet NSTextField    * fWaitToStartField;
    4750   
    4851    IBOutlet SUUpdater      * fUpdater;
     
    5861- (void) setUpdate:             (id) sender;
    5962- (void) checkUpdate;
    60 - (void) setAutoStart:          (id) sender;
     63
     64
     65- (void) setStartSetting:   (id) sender;
     66- (void) setWaitToStart:    (id) sender;
     67
    6168- (void) setMoveTorrent:        (id) sender;
    6269- (void) setDownloadLocation:   (id) sender;
  • trunk/macosx/PrefsController.m

    r421 r446  
    3131#define DOWNLOAD_FOLDER     0
    3232#define DOWNLOAD_TORRENT    2
    33 #define DOWNLOAD_ASK        3
     33#define DOWNLOAD_ASK    3
     34
     35#define START_YES_CHECK_TAG     0
     36#define START_WAIT_CHECK_TAG    1
     37#define START_NO_CHECK_TAG      2
    3438
    3539#define UPDATE_DAILY    0
     
    143147    [fBadgeUploadRateCheck setState: [fDefaults boolForKey: @"BadgeUploadRate"]];
    144148   
    145     //set auto start
    146     [fAutoStartCheck setState: [fDefaults boolForKey: @"AutoStartDownload"]];
     149    //set start setting
     150    NSString * startSetting = [fDefaults stringForKey: @"StartSetting"];
     151    int tag;
     152    if ([startSetting isEqualToString: @"Start"])
     153        tag = START_YES_CHECK_TAG;
     154    else if ([startSetting isEqualToString: @"Wait"])
     155        tag = START_WAIT_CHECK_TAG;
     156    else
     157        tag = START_NO_CHECK_TAG;
     158   
     159    [fStartMatrix selectCellWithTag: tag];
     160    [fWaitToStartField setEnabled: tag == START_WAIT_CHECK_TAG];
     161    [fWaitToStartField setIntValue: [fDefaults integerForKey: @"WaitToStartNumber"]];
    147162   
    148163    //set private torrents
     
    408423}
    409424
    410 - (void) setAutoStart: (id) sender
    411 {
    412     [fDefaults setBool: [sender state] forKey: @"AutoStartDownload"];
     425- (void) setStartSetting: (id) sender
     426{
     427    NSString * startSetting;
     428
     429    int tag = [[fStartMatrix selectedCell] tag];
     430    if (tag == START_YES_CHECK_TAG)
     431        startSetting = @"Start";
     432    else if (tag == START_WAIT_CHECK_TAG)
     433        startSetting = @"Wait";
     434    else
     435        startSetting = @"Manual";
     436   
     437    [fDefaults setObject: startSetting forKey: @"StartSetting"];
     438   
     439    [self setWaitToStart: fWaitToStartField];
     440    [fWaitToStartField setEnabled: tag == START_WAIT_CHECK_TAG];
     441}
     442
     443- (void) setWaitToStart: (id) sender
     444{
     445    int waitNumber = [sender intValue];
     446    if (![[sender stringValue] isEqualToString: [NSString stringWithInt: waitNumber]] || waitNumber < 1)
     447    {
     448        NSBeep();
     449        waitNumber = [fDefaults floatForKey: @"WaitToStartNumber"];
     450        [sender setIntValue: waitNumber];
     451    }
     452    else
     453        [fDefaults setInteger: waitNumber forKey: @"WaitToStartNumber"];
     454   
     455    #warning notification recheck
    413456}
    414457
  • trunk/macosx/Torrent.h

    r424 r446  
    5050    int     fStopRatioSetting;
    5151    float   fRatioLimit;
    52     BOOL    fFinishedSeeding;
     52    BOOL    fFinishedSeeding, fWaitToStart;
    5353}
    5454
     
    7474- (float)       ratioLimit;
    7575- (void)        setRatioLimit: (float) limit;
     76
     77- (void) setWaitToStart: (BOOL) wait;
     78- (BOOL) waitingToStart;
    7679
    7780- (void)    revealData;
  • trunk/macosx/Torrent.m

    r424 r446  
    3131        privateTorrent: (NSNumber *) privateTorrent publicTorrent: (NSNumber *) publicTorrent
    3232        date: (NSDate *) date stopRatioSetting: (NSNumber *) stopRatioSetting
    33         ratioLimit: (NSNumber *) ratioLimit;
     33        ratioLimit: (NSNumber *) ratioLimit waitToStart: (NSNumber *) waitToStart;
    3434
    3535- (void) trashFile: (NSString *) path;
     
    4343{
    4444    self = [self initWithHash: nil path: path lib: lib privateTorrent: nil publicTorrent: nil
    45             date: nil stopRatioSetting: nil ratioLimit: nil];
     45            date: nil stopRatioSetting: nil ratioLimit: nil waitToStart: nil];
    4646   
    4747    if (self)
     
    6161                date: [history objectForKey: @"Date"]
    6262                stopRatioSetting: [history objectForKey: @"StopRatioSetting"]
    63                 ratioLimit: [history objectForKey: @"RatioLimit"]];
     63                ratioLimit: [history objectForKey: @"RatioLimit"]
     64                waitToStart: [history objectForKey: @"WaitToStart"]];
    6465   
    6566    if (self)
     
    8687                    [self date], @"Date",
    8788                    [NSNumber numberWithInt: fStopRatioSetting], @"StopRatioSetting",
    88                     [NSNumber numberWithFloat: fRatioLimit], @"RatioLimit", nil];
     89                    [NSNumber numberWithFloat: fRatioLimit], @"RatioLimit",
     90                    [NSNumber numberWithBool: fWaitToStart], @"WaitToStart", nil];
    8991           
    9092    if (fPrivateTorrent)
     
    159161    {
    160162        case TR_STATUS_PAUSE:
    161             [fStatusString setString: fFinishedSeeding ? @"Seeding Complete" : @"Paused"];
     163            if (fFinishedSeeding)
     164                [fStatusString setString: @"Seeding complete"];
     165            else if (fWaitToStart)
     166                [fStatusString setString: [@"Waiting to start" stringByAppendingEllipsis]];
     167            else
     168                [fStatusString setString: @"Paused"];
    162169            break;
    163170
     
    222229    {
    223230        tr_torrentStart(fHandle);
     231
    224232        fFinishedSeeding = NO;
     233        fWaitToStart = NO;
    225234    }
    226235}
     
    229238{
    230239    if ([self isActive])
     240    {
     241        BOOL wasSeeding = [self isSeeding];
     242   
    231243        tr_torrentStop(fHandle);
     244       
     245        if (!wasSeeding)
     246            [[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentFinishedDownloading" object: self];
     247    }
    232248}
    233249
     
    241257{
    242258    if ((fResumeOnWake = [self isActive]))
    243         [self stopTransfer];
     259        tr_torrentStop(fHandle);
    244260}
    245261
     
    247263{
    248264    if (fResumeOnWake)
    249         [self startTransfer];
     265        tr_torrentStart(fHandle);
    250266}
    251267
     
    275291    if (limit >= 0)
    276292        fRatioLimit = limit;
     293}
     294
     295- (void) setWaitToStart: (BOOL) wait
     296{
     297    fWaitToStart = wait;
     298}
     299
     300- (BOOL) waitingToStart
     301{
     302    return fWaitToStart;
    277303}
    278304
     
    425451- (BOOL) justFinished
    426452{
    427     return tr_getFinished(fHandle);
     453    BOOL finished = tr_getFinished(fHandle);
     454    if (finished)
     455        [[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentFinishedDownloading" object: self];
     456   
     457    return finished;
    428458}
    429459
     
    529559        privateTorrent: (NSNumber *) privateTorrent publicTorrent: (NSNumber *) publicTorrent
    530560        date: (NSDate *) date stopRatioSetting: (NSNumber *) stopRatioSetting
    531         ratioLimit: (NSNumber *) ratioLimit
     561        ratioLimit: (NSNumber *) ratioLimit waitToStart: (NSNumber *) waitToStart
    532562{
    533563    if (!(self = [super init]))
     
    564594    fRatioLimit = ratioLimit ? [ratioLimit floatValue] : [fDefaults floatForKey: @"RatioLimit"];
    565595    fFinishedSeeding = NO;
     596   
     597    fWaitToStart = waitToStart ? [waitToStart boolValue]
     598                    : [[fDefaults stringForKey: @"StartSetting"] isEqualToString: @"Wait"];
    566599   
    567600    NSString * fileType = fInfo->multifile ? NSFileTypeForHFSTypeCode('fldr') : [[self name] pathExtension];
Note: See TracChangeset for help on using the changeset viewer.