From c251a5c5df17c3a308c052599045ae9fcf2bd947 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Sun, 30 Jul 2006 18:37:29 +0000 Subject: [PATCH] Check for completed download in Torrent class. --- macosx/Controller.h | 1 + macosx/Controller.m | 47 +++++++++++++++++++++------------------------ macosx/Torrent.m | 4 ++++ 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/macosx/Controller.h b/macosx/Controller.h index e8aecc936..7f0e47b44 100644 --- a/macosx/Controller.h +++ b/macosx/Controller.h @@ -131,6 +131,7 @@ - (void) updateControlTint: (NSNotification *) notification; - (void) updateUI: (NSTimer *) timer; +- (void) torrentFinishedDownloading: (NSNotification *) notification; - (void) updateTorrentHistory; - (void) sortTorrents; diff --git a/macosx/Controller.m b/macosx/Controller.m index 932fa7c0a..3f7f91662 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -285,6 +285,9 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy //observe notifications NSNotificationCenter * nc = [NSNotificationCenter defaultCenter]; + [nc addObserver: self selector: @selector(torrentFinishedDownloading:) + name: @"TorrentFinishedDownloading" object: nil]; + [nc addObserver: self selector: @selector(updateControlTint:) name: NSControlTintDidChangeNotification object: nil]; @@ -839,25 +842,7 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy - (void) updateUI: (NSTimer *) t { - NSEnumerator * enumerator = [fTorrents objectEnumerator]; - Torrent * torrent; - while ((torrent = [enumerator nextObject])) - { - [torrent update]; - - if ([torrent justFinished]) - { - [self applyFilter: nil]; - [self checkToStartWaiting: torrent]; - - [GrowlApplicationBridge notifyWithTitle: @"Download Complete" - description: [torrent name] notificationName: GROWL_DOWNLOAD_COMPLETE iconData: nil - priority: 0 isSticky: NO clickContext: nil]; - - if (![fWindow isKeyWindow]) - fCompleted++; - } - } + [fTorrents makeObjectsPerformSelector: @selector(update)]; if ([fSortType isEqualToString: @"Progress"] || [fSortType isEqualToString: @"State"]) [self sortTorrents]; @@ -880,6 +865,20 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy [fBadger updateBadgeWithCompleted: fCompleted uploadRate: uploadRate downloadRate: downloadRate]; } +- (void) torrentFinishedDownloading: (NSNotification *) notification +{ + Torrent * torrent = [notification object]; + + [self applyFilter: nil]; + [self checkToStartWaiting: torrent]; + + [GrowlApplicationBridge notifyWithTitle: @"Download Complete" description: [torrent name] + notificationName: GROWL_DOWNLOAD_COMPLETE iconData: nil priority: 0 isSticky: NO clickContext: nil]; + + if (![fWindow isKeyWindow]) + fCompleted++; +} + - (void) updateTorrentHistory { NSMutableArray * history = [NSMutableArray arrayWithCapacity: [fTorrents count]]; @@ -1311,9 +1310,8 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy [self applyFilter: nil]; [fInfoController updateInfoStatsAndSettings]; - [GrowlApplicationBridge notifyWithTitle: @"Seeding Complete" - description: [[notification object] name] notificationName: GROWL_SEEDING_COMPLETE - iconData: nil priority: 0 isSticky: NO clickContext: nil]; + [GrowlApplicationBridge notifyWithTitle: @"Seeding Complete" description: [[notification object] name] + notificationName: GROWL_SEEDING_COMPLETE iconData: nil priority: 0 isSticky: NO clickContext: nil]; } - (void) attemptToStartAuto: (Torrent *) torrent @@ -1420,9 +1418,8 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy //import only actually happened if the torrent array is larger if (oldCount < [fTorrents count]) - [GrowlApplicationBridge notifyWithTitle: @"Torrent File Auto Added" - description: file notificationName: GROWL_AUTO_ADD iconData: nil - priority: 0 isSticky: NO clickContext: nil]; + [GrowlApplicationBridge notifyWithTitle: @"Torrent File Auto Added" description: file + notificationName: GROWL_AUTO_ADD iconData: nil priority: 0 isSticky: NO clickContext: nil]; } } diff --git a/macosx/Torrent.m b/macosx/Torrent.m index 919c17e80..0f2c2b458 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -143,6 +143,10 @@ { fStat = tr_torrentStat(fHandle); + //notification when downloading finished + if ([self justFinished]) + [[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentFinishedDownloading" object: self]; + //check to stop for ratio if ([self isSeeding] && ((fStopRatioSetting == RATIO_CHECK && [self ratio] >= fRatioLimit) || (fStopRatioSetting == RATIO_GLOBAL && [fDefaults boolForKey: @"RatioCheck"]