Changeset 3224


Ignore:
Timestamp:
Sep 28, 2007, 3:36:46 PM (14 years ago)
Author:
livings124
Message:

work with new callback for completeness change

Location:
trunk/macosx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Defaults.plist

    r3213 r3224  
    3535        <key>DeleteOriginalTorrent</key>
    3636        <false/>
     37        <key>DisplayPeerProgressBarNumber</key>
     38        <false/>
     39        <key>DisplayProgressBarAvailable</key>
     40        <false/>
    3741        <key>DisplaySmallStatusRegular</key>
    3842        <true/>
    3943        <key>DisplayStatusProgressSelected</key>
    40         <false/>
    41     <key>DisplayPeerProgressBarNumber</key>
    42         <false/>
    43     <key>DisplayProgressBarAvailable</key>
    4444        <false/>
    4545        <key>DownloadChoice</key>
  • trunk/macosx/Torrent.m

    r3219 r3224  
    4747            previousPath: (NSString *) previousPath fileSize: (uint64_t) size index: (int) index;
    4848
     49- (void) completenessChange: (NSNumber *) status;
     50
    4951- (void) quickPause;
    5052- (void) endQuickPause;
     
    5355
    5456@end
     57
     58void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void * torrentData)
     59{
     60    [(Torrent *)torrentData performSelectorOnMainThread: @selector(completenessChange:)
     61                withObject: [[NSNumber alloc] initWithInt: status] waitUntilDone: NO];
     62}
    5563
    5664@implementation Torrent
     
    168176- (void) closeTorrent
    169177{
     178    tr_torrentClearStatusCallback(fHandle);
    170179    tr_torrentClose(fHandle);
    171180}
     
    214223    fStat = tr_torrentStat(fHandle);
    215224   
    216     //notification when downloading finished
    217     if (tr_getComplete(fHandle) || tr_getDone(fHandle))
    218     {
    219         BOOL canMove = YES;
    220        
    221         //move file from incomplete folder to download folder
    222         if (fUseIncompleteFolder && ![[self downloadFolder] isEqualToString: fDownloadFolder]
    223             && (canMove = [self alertForMoveFolderAvailable]))
    224         {
    225             [self quickPause];
    226            
    227             if ([[NSFileManager defaultManager] movePath: [[self downloadFolder] stringByAppendingPathComponent: [self name]]
    228                                     toPath: [fDownloadFolder stringByAppendingPathComponent: [self name]] handler: nil])
    229                 [self updateDownloadFolder];
    230             else
    231                 canMove = NO;
    232            
    233             [self endQuickPause];
    234         }
    235        
    236         if (!canMove)
    237         {
    238             fUseIncompleteFolder = NO;
    239            
    240             [fDownloadFolder release];
    241             fDownloadFolder = fIncompleteFolder;
    242             fIncompleteFolder = nil;
    243         }
    244                
    245                 [fDateCompleted release];
    246                 fDateCompleted = [[NSDate alloc] init];
    247        
    248         fStat = tr_torrentStat(fHandle);
    249         [[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentFinishedDownloading" object: self];
    250     }
    251     else if (tr_getIncomplete(fHandle))
    252         [[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentRestartedDownloading" object: self];
    253     else;
    254    
    255225    //check to stop for ratio
     226    #warning fix this!
    256227    float stopRatio;
    257228    if ([self isSeeding] && (stopRatio = [self actualStopRatio]) != INVALID && [self ratio] >= stopRatio)
     
    15121483    }
    15131484   
     1485    tr_torrentSetStatusCallback(fHandle, completenessChangeCallback, self);
     1486   
    15141487    fInfo = tr_torrentInfo(fHandle);
    15151488
     
    16351608}
    16361609
     1610//status will be retained
     1611- (void) completenessChange: (NSNumber *) status
     1612{
     1613    BOOL canMove;
     1614    switch ([status intValue])
     1615    {
     1616        case TR_CP_DONE:
     1617        case TR_CP_COMPLETE:
     1618            canMove = YES;
     1619       
     1620            //move file from incomplete folder to download folder
     1621            if (fUseIncompleteFolder && ![[self downloadFolder] isEqualToString: fDownloadFolder]
     1622                && (canMove = [self alertForMoveFolderAvailable]))
     1623            {
     1624                [self quickPause];
     1625               
     1626                if ([[NSFileManager defaultManager] movePath: [[self downloadFolder] stringByAppendingPathComponent: [self name]]
     1627                                        toPath: [fDownloadFolder stringByAppendingPathComponent: [self name]] handler: nil])
     1628                    [self updateDownloadFolder];
     1629                else
     1630                    canMove = NO;
     1631               
     1632                [self endQuickPause];
     1633            }
     1634           
     1635            if (!canMove)
     1636            {
     1637                fUseIncompleteFolder = NO;
     1638               
     1639                [fDownloadFolder release];
     1640                fDownloadFolder = fIncompleteFolder;
     1641                fIncompleteFolder = nil;
     1642            }
     1643           
     1644            [fDateCompleted release];
     1645            fDateCompleted = [[NSDate alloc] init];
     1646           
     1647            fStat = tr_torrentStat(fHandle);
     1648            [[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentFinishedDownloading" object: self];
     1649            break;
     1650       
     1651        case TR_CP_INCOMPLETE:
     1652            [[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentRestartedDownloading" object: self];
     1653            break;
     1654    }
     1655    [status release];
     1656   
     1657    [self update];
     1658}
     1659
    16371660- (void) quickPause
    16381661{
Note: See TracChangeset for help on using the changeset viewer.