1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 09:13:06 +00:00

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

doesn't exit properly
This commit is contained in:
Eric Petit 2006-02-08 19:05:42 +00:00
parent 604f0b2b35
commit da6b5deb96
2 changed files with 33 additions and 21 deletions

View file

@ -113,6 +113,7 @@
- (void) showInfo: (id) sender;
- (void) updateUI: (NSTimer *) timer;
- (void) updateTorrentHistory;
- (void) sleepCallBack: (natural_t) messageType argument:
(void *) messageArgument;

View file

@ -223,29 +223,14 @@ static void sleepCallBack( void * controller, io_service_t y,
[fBadger clearBadge];
[fBadger release];
// Save history and stop running torrents
NSMutableArray * history = [NSMutableArray arrayWithCapacity: fCount];
BOOL active;
// Save history
[self updateTorrentHistory];
// Stop running torrents
for( i = 0; i < fCount; i++ )
{
active = fStat[i].status &
( TR_STATUS_CHECK | TR_STATUS_DOWNLOAD | TR_STATUS_SEED );
[history addObject: [NSDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithUTF8String: fStat[i].info.torrent],
@"TorrentPath",
[NSString stringWithUTF8String: tr_torrentGetFolder( fHandle, i )],
@"DownloadFolder",
active ? @"NO" : @"YES",
@"Paused",
NULL]];
if( active )
{
if( fStat[i].status & ( TR_STATUS_CHECK | TR_STATUS_DOWNLOAD |
TR_STATUS_SEED ) )
tr_torrentStop( fHandle, i );
}
}
[fDefaults setObject: history forKey: @"History"];
// Wait for torrents to stop (5 seconds timeout)
NSDate * start = [NSDate date];
@ -351,6 +336,7 @@ static void sleepCallBack( void * controller, io_service_t y,
}
[self updateUI: NULL];
[self updateTorrentHistory];
}
- (void) advancedChanged: (id) sender
@ -430,6 +416,7 @@ static void sleepCallBack( void * controller, io_service_t y,
{
tr_torrentStart( fHandle, idx );
[self updateUI: NULL];
[self updateTorrentHistory];
}
- (void) stopTorrent: (id) sender
@ -454,6 +441,7 @@ static void sleepCallBack( void * controller, io_service_t y,
{
tr_torrentStop( fHandle, idx );
[self updateUI: NULL];
[self updateTorrentHistory];
}
- (void) removeTorrentWithIndex: (int) idx
@ -527,6 +515,7 @@ static void sleepCallBack( void * controller, io_service_t y,
tr_torrentClose( fHandle, idx );
[self updateUI: NULL];
[self updateTorrentHistory];
}
- (void) removeTorrent: (id) sender
@ -618,6 +607,28 @@ static void sleepCallBack( void * controller, io_service_t y,
? [NSString stringForSpeedAbbrev: dl] : nil];
}
- (void) updateTorrentHistory
{
if( !fStat )
return;
NSMutableArray * history = [NSMutableArray arrayWithCapacity: fCount];
int i;
for (i = 0; i < fCount; i++)
[history addObject: [NSDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithUTF8String: fStat[i].info.torrent],
@"TorrentPath",
[NSString stringWithUTF8String: tr_torrentGetFolder( fHandle, i )],
@"DownloadFolder",
fStat[i].status & (TR_STATUS_CHECK | TR_STATUS_DOWNLOAD |
TR_STATUS_SEED) ? @"NO" : @"YES",
@"Paused",
nil]];
[fDefaults setObject: history forKey: @"History"];
}
- (int) numberOfRowsInTableView: (NSTableView *) t
{
return fCount;