Changeset 107


Ignore:
Timestamp:
Feb 8, 2006, 7:05:42 PM (15 years ago)
Author:
titer
Message:

Update the torrent history as the app runs, so it won't be lost if it
doesn't exit properly

Location:
trunk/macosx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.h

    r94 r107  
    114114
    115115- (void) updateUI:        (NSTimer *) timer;
     116- (void) updateTorrentHistory;
    116117- (void) sleepCallBack:   (natural_t) messageType argument:
    117118                        (void *) messageArgument;
  • trunk/macosx/Controller.m

    r106 r107  
    224224    [fBadger release];                                                         
    225225
    226     // Save history and stop running torrents
    227     NSMutableArray * history = [NSMutableArray arrayWithCapacity: fCount];
    228     BOOL active;
     226    // Save history
     227    [self updateTorrentHistory];
     228   
     229    // Stop running torrents
    229230    for( i = 0; i < fCount; i++ )
    230     {
    231         active = fStat[i].status &
    232             ( TR_STATUS_CHECK | TR_STATUS_DOWNLOAD | TR_STATUS_SEED );
    233 
    234         [history addObject: [NSDictionary dictionaryWithObjectsAndKeys:
    235             [NSString stringWithUTF8String: fStat[i].info.torrent],
    236             @"TorrentPath",
    237             [NSString stringWithUTF8String: tr_torrentGetFolder( fHandle, i )],
    238             @"DownloadFolder",
    239             active ? @"NO" : @"YES",
    240             @"Paused",
    241             NULL]];
    242 
    243         if( active )
    244         {
     231        if( fStat[i].status & ( TR_STATUS_CHECK | TR_STATUS_DOWNLOAD |
     232                    TR_STATUS_SEED ) )
    245233            tr_torrentStop( fHandle, i );
    246         }
    247     }
    248     [fDefaults setObject: history forKey: @"History"];
    249234
    250235    // Wait for torrents to stop (5 seconds timeout)
     
    352337
    353338    [self updateUI: NULL];
     339    [self updateTorrentHistory];
    354340}
    355341
     
    431417    tr_torrentStart( fHandle, idx );
    432418    [self updateUI: NULL];
     419    [self updateTorrentHistory];
    433420}
    434421
     
    455442    tr_torrentStop( fHandle, idx );
    456443    [self updateUI: NULL];
     444    [self updateTorrentHistory];
    457445}
    458446
     
    528516    tr_torrentClose( fHandle, idx );
    529517    [self updateUI: NULL];
     518    [self updateTorrentHistory];
    530519}
    531520
     
    617606        downloadRate: dl >= 0.1 && [defaults boolForKey: @"BadgeDownloadRate"]
    618607          ? [NSString stringForSpeedAbbrev: dl] : nil];
     608}
     609
     610- (void) updateTorrentHistory
     611{
     612    if( !fStat )
     613        return;
     614
     615    NSMutableArray * history = [NSMutableArray arrayWithCapacity: fCount];
     616
     617    int i;
     618    for (i = 0; i < fCount; i++)
     619        [history addObject: [NSDictionary dictionaryWithObjectsAndKeys:
     620            [NSString stringWithUTF8String: fStat[i].info.torrent],
     621            @"TorrentPath",
     622            [NSString stringWithUTF8String: tr_torrentGetFolder( fHandle, i )],
     623            @"DownloadFolder",
     624            fStat[i].status & (TR_STATUS_CHECK | TR_STATUS_DOWNLOAD |
     625              TR_STATUS_SEED) ? @"NO" : @"YES",
     626            @"Paused",
     627            nil]];
     628
     629    [fDefaults setObject: history forKey: @"History"];
    619630}
    620631
Note: See TracChangeset for help on using the changeset viewer.