From 4d5ab8a4c5f8e36d15a038e223ebf145a1eff953 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Sun, 19 Jun 2011 03:52:54 +0000 Subject: [PATCH] #4241 Update dock badge count after removing download through web interface --- macosx/Badger.h | 7 +++++-- macosx/Badger.m | 30 +++++++++++++++++++++++------- macosx/Controller.m | 5 ++++- macosx/InfoWindowController.m | 2 +- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/macosx/Badger.h b/macosx/Badger.h index f7f35fba8..c5aa017a4 100644 --- a/macosx/Badger.h +++ b/macosx/Badger.h @@ -25,17 +25,20 @@ #import #import +@class Torrent; + @interface Badger : NSObject { tr_session * fLib; - NSUInteger fCompleted; + NSMutableSet * fHashes; } - (id) initWithLib: (tr_session *) lib; - (void) updateBadgeWithDownload: (CGFloat) downloadRate upload: (CGFloat) uploadRate; -- (void) incrementCompleted; +- (void) addCompletedTorrent: (Torrent *) torrent; +- (void) removeTorrent: (Torrent *) torrent; - (void) clearCompleted; - (void) setQuitting; diff --git a/macosx/Badger.m b/macosx/Badger.m index d1ff66072..c63b0ea11 100644 --- a/macosx/Badger.m +++ b/macosx/Badger.m @@ -24,6 +24,8 @@ #import "Badger.h" #import "BadgeView.h" +#import "NSStringAdditions.h" +#import "Torrent.h" @implementation Badger @@ -33,11 +35,11 @@ { fLib = lib; - fCompleted = 0; - BadgeView * view = [[BadgeView alloc] initWithLib: lib]; [[NSApp dockTile] setContentView: view]; [view release]; + + fHashes = [[NSMutableSet alloc] init]; } return self; @@ -47,6 +49,8 @@ { [[NSNotificationCenter defaultCenter] removeObserver: self]; + [fHashes release]; + [super dealloc]; } @@ -62,17 +66,29 @@ [[NSApp dockTile] display]; } -- (void) incrementCompleted +- (void) addCompletedTorrent: (Torrent *) torrent { - fCompleted++; - [[NSApp dockTile] setBadgeLabel: [NSString stringWithFormat: @"%d", fCompleted]]; + [fHashes addObject: [torrent hashString]]; + [[NSApp dockTile] setBadgeLabel: [NSString formattedUInteger: [fHashes count]]]; +} + +- (void) removeTorrent: (Torrent *) torrent +{ + if ([fHashes count] > 0) + { + [fHashes removeObject: [torrent hashString]]; + if ([fHashes count] > 0) + [[NSApp dockTile] setBadgeLabel: [NSString formattedUInteger: [fHashes count]]]; + else + [[NSApp dockTile] setBadgeLabel: @""]; + } } - (void) clearCompleted { - if (fCompleted != 0) + if ([fHashes count] > 0) { - fCompleted = 0; + [fHashes removeAllObjects]; [[NSApp dockTile] setBadgeLabel: @""]; } } diff --git a/macosx/Controller.m b/macosx/Controller.m index c57b314ae..eed1bd7e9 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -1341,6 +1341,9 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy //let's expand all groups that have removed items - they either don't exist anymore, are already expanded, or are collapsed (rpc) [fTableView removeCollapsedGroup: [torrent groupValue]]; + //we can't assume the window is active - RPC removal, for example + [fBadger removeTorrent: torrent]; + [torrent closeRemoveTorrent: deleteData]; } @@ -1794,7 +1797,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy iconData: nil priority: 0 isSticky: NO clickContext: clickContext]; if (![fWindow isMainWindow]) - [fBadger incrementCompleted]; + [fBadger addCompletedTorrent: torrent]; //bounce download stack [[NSDistributedNotificationCenter defaultCenter] postNotificationName: @"com.apple.DownloadFileFinished" diff --git a/macosx/InfoWindowController.m b/macosx/InfoWindowController.m index 2ce3e0e82..c4697d194 100644 --- a/macosx/InfoWindowController.m +++ b/macosx/InfoWindowController.m @@ -342,7 +342,7 @@ typedef enum [self setTab: nil]; } -- (void) swipeWithEvent:(NSEvent *) event +- (void) swipeWithEvent: (NSEvent *) event { if ([event deltaX] < 0.0) [self setNextTab];