1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-27 01:57:52 +00:00

make sleep code match quit code for waiting for transfers to stop

This commit is contained in:
Mitchell Livingston 2006-07-07 01:41:32 +00:00
parent 82a793171c
commit 5fc3a462c8
2 changed files with 19 additions and 20 deletions

View file

@ -161,7 +161,7 @@
- (void) linkHomepage: (id) sender; - (void) linkHomepage: (id) sender;
- (void) linkForums: (id) sender; - (void) linkForums: (id) sender;
- (void) notifyGrowl: (NSString * ) title message: (NSString *) message notification: (NSString *) notification; - (void) notifyGrowl: (NSString *) title message: (NSString *) message identifier: (NSString *) ident;
- (void) growlRegister; - (void) growlRegister;
- (void) checkUpdate: (id) sender; - (void) checkUpdate: (id) sender;

View file

@ -785,7 +785,7 @@ static void sleepCallBack(void * controller, io_service_t y,
[self checkWaitingForFinished: torrent]; [self checkWaitingForFinished: torrent];
//notifications //notifications
[self notifyGrowl: @"Download Complete" message: [torrent name] notification: @"Download Complete"]; [self notifyGrowl: @"Download Complete" message: [torrent name] identifier: @"Download Complete"];
if (![fWindow isKeyWindow]) if (![fWindow isKeyWindow])
fCompleted++; fCompleted++;
} }
@ -1173,7 +1173,7 @@ static void sleepCallBack(void * controller, io_service_t y,
//import only actually happened if the torrent array is larger //import only actually happened if the torrent array is larger
if (oldCount < [fTorrents count]) if (oldCount < [fTorrents count])
[self notifyGrowl: [file stringByAppendingString: @" Auto Added"] message: @"Torrent file added" [self notifyGrowl: [file stringByAppendingString: @" Auto Added"] message: @"Torrent file added"
notification: @"Automatically Add Torrent"]; identifier: @"Automatically Add Torrent"];
} }
} }
@ -1675,27 +1675,26 @@ static void sleepCallBack(void * controller, io_service_t y,
Torrent * torrent; Torrent * torrent;
BOOL active; BOOL active;
switch( messageType ) switch (messageType)
{ {
case kIOMessageSystemWillSleep: case kIOMessageSystemWillSleep:
/* Close all connections before going to sleep and remember //close all connections before going to sleep and remember we should resume when we wake up
we should resume when we wake up */
[fTorrents makeObjectsPerformSelector: @selector(sleep)]; [fTorrents makeObjectsPerformSelector: @selector(sleep)];
/* Wait for torrents to stop (5 seconds timeout) */ //wait for running transfers to stop (5 second timeout)
NSDate * start = [NSDate date]; NSDate * start = [NSDate date];
enumerator = [fTorrents objectEnumerator]; BOOL timeUp = NO;
while( ( torrent = [enumerator nextObject] ) )
NSEnumerator * enumerator = [fTorrents objectEnumerator];
Torrent * torrent;
while (!timeUp && (torrent = [enumerator nextObject]))
while (![torrent isPaused] && !(timeUp = [start timeIntervalSinceNow] < -5.0))
{ {
while( [[NSDate date] timeIntervalSinceDate: start] < 5 && usleep(100000);
![torrent isPaused] )
{
usleep( 100000 );
[torrent update]; [torrent update];
} }
}
IOAllowPowerChange( fRootPort, (long) messageArgument ); IOAllowPowerChange(fRootPort, (long) messageArgument);
break; break;
case kIOMessageCanSystemSleep: case kIOMessageCanSystemSleep:
@ -1710,13 +1709,13 @@ static void sleepCallBack(void * controller, io_service_t y,
} }
if (active) if (active)
IOCancelPowerChange( fRootPort, (long) messageArgument ); IOCancelPowerChange(fRootPort, (long) messageArgument);
else else
IOAllowPowerChange( fRootPort, (long) messageArgument ); IOAllowPowerChange(fRootPort, (long) messageArgument);
break; break;
case kIOMessageSystemHasPoweredOn: case kIOMessageSystemHasPoweredOn:
/* Resume download after we wake up */ //resume sleeping transfers after we wake up
[fTorrents makeObjectsPerformSelector: @selector(wakeUp)]; [fTorrents makeObjectsPerformSelector: @selector(wakeUp)];
break; break;
} }
@ -1758,7 +1757,7 @@ static void sleepCallBack(void * controller, io_service_t y,
[[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: FORUM_URL]]; [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: FORUM_URL]];
} }
- (void) notifyGrowl: (NSString * ) title message: (NSString *) message notification: (NSString *) notification - (void) notifyGrowl: (NSString *) title message: (NSString *) message identifier: (NSString *) ident
{ {
if (!fHasGrowl) if (!fHasGrowl)
return; return;
@ -1773,7 +1772,7 @@ static void sleepCallBack(void * controller, io_service_t y,
" application name \"Transmission\"\n" " application name \"Transmission\"\n"
" end tell\n" " end tell\n"
" end if\n" " end if\n"
"end tell", notification, title, message]; "end tell", ident, title, message];
NSAppleScript * appleScript = [[NSAppleScript alloc] initWithSource: growlScript]; NSAppleScript * appleScript = [[NSAppleScript alloc] initWithSource: growlScript];
NSDictionary * error; NSDictionary * error;