diff --git a/macosx/Badger.h b/macosx/Badger.h index f79e4e0c9..d976306b7 100644 --- a/macosx/Badger.h +++ b/macosx/Badger.h @@ -34,12 +34,15 @@ NSImage * fDockIcon, * fBadge, * fUploadBadge, * fDownloadBadge; NSDictionary * fAttributes; - int fCompleted; + int fCompleted, fCompletedBadged; BOOL fSpeedBadge; } - (id) initWithLib: (tr_handle_t *) lib; -- (void) updateBadgeWithCompleted: (int) completed; + +- (void) updateBadge; +- (void) incrementCompleted; +- (void) clearCompleted; - (void) clearBadge; @end diff --git a/macosx/Badger.m b/macosx/Badger.m index ea7f22351..f9a329faa 100644 --- a/macosx/Badger.m +++ b/macosx/Badger.m @@ -58,6 +58,7 @@ [stringShadow release]; fCompleted = 0; + fCompletedBadged = 0; fSpeedBadge = NO; } @@ -71,18 +72,18 @@ [super dealloc]; } -- (void) updateBadgeWithCompleted: (int) completed +- (void) updateBadge { //set completed badge to top right BOOL baseChange; - if (baseChange = (fCompleted != completed)) + if (baseChange = (fCompleted != fCompletedBadged)) { - fCompleted = completed; + fCompletedBadged = fCompleted; [fDockIcon release]; fDockIcon = [[NSImage imageNamed: @"NSApplicationIcon"] copy]; - if (completed > 0) + if (fCompleted > 0) { NSRect badgeRect; NSSize iconSize = [fDockIcon size]; @@ -101,7 +102,7 @@ badgeRect.origin.y += badgeBottomExtra; //place badge text - [self badgeString: [NSString stringWithInt: completed] forRect: badgeRect]; + [self badgeString: [NSString stringWithInt: fCompleted] forRect: badgeRect]; [fDockIcon unlockFocus]; } @@ -182,10 +183,26 @@ } } +- (void) incrementCompleted +{ + fCompleted++; + [self updateBadge]; +} + +- (void) clearCompleted +{ + if (fCompleted != 0) + { + fCompleted = 0; + [self updateBadge]; + } +} + - (void) clearBadge { - [NSApp setApplicationIconImage: [NSImage imageNamed: @"NSApplicationIcon"]]; fCompleted = 0; + fCompletedBadged = 0; + [NSApp setApplicationIconImage: [NSImage imageNamed: @"NSApplicationIcon"]]; } @end diff --git a/macosx/Controller.h b/macosx/Controller.h index 23bbfaa12..b7e60cbdf 100644 --- a/macosx/Controller.h +++ b/macosx/Controller.h @@ -42,7 +42,6 @@ @interface Controller : NSObject { tr_handle_t * fLib; - int fCompleted; NSMutableArray * fTorrents, * fDisplayedTorrents; @@ -200,7 +199,7 @@ - (void) doNothing: (id) sender; //needed for menu items that use bindings with no associated action -- (void) resetDockBadge: (NSNotification *) notification; +- (void) updateDockBadge: (NSNotification *) notification; - (void) setWindowSizeToFit; - (NSRect) sizedWindowFrame; diff --git a/macosx/Controller.m b/macosx/Controller.m index 9d008c2d1..5c11b5d56 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -394,11 +394,10 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy name: @"UpdateQueue" object: nil]; //change that just impacts the dock badge - [nc addObserver: self selector: @selector(resetDockBadge:) + [nc addObserver: self selector: @selector(updateDockBadge:) name: @"DockBadgeChange" object: nil]; //timer to update the interface every second - fCompleted = 0; [self updateUI]; fTimer = [NSTimer scheduledTimerWithTimeInterval: UPDATE_UI_SECONDS target: self selector: @selector(updateUI) userInfo: nil repeats: YES]; @@ -1326,7 +1325,7 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy [fInfoController updateInfoStats]; //badge dock - [fBadger updateBadgeWithCompleted: fCompleted]; + [fBadger updateBadge]; } - (void) updateTorrentsInQueue @@ -1423,7 +1422,7 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy iconData: nil priority: 0 isSticky: NO clickContext: clickContext]; if (![fWindow isKeyWindow]) - fCompleted++; + [fBadger incrementCompleted]; if ([fDefaults boolForKey: @"QueueSeed"]) { @@ -2886,9 +2885,9 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy return fDockMenu; } -- (void) resetDockBadge: (NSNotification *) notification +- (void) updateDockBadge: (NSNotification *) notification { - [fBadger updateBadgeWithCompleted: fCompleted]; + [fBadger updateBadge]; } - (NSRect) windowWillUseStandardFrame: (NSWindow *) window defaultFrame: (NSRect) defaultFrame @@ -2924,12 +2923,7 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy - (void) windowDidBecomeKey: (NSNotification *) notification { - //reset dock badge for completed - if (fCompleted > 0) - { - fCompleted = 0; - [self resetDockBadge: nil]; - } + [fBadger clearCompleted]; } - (NSSize) windowWillResize: (NSWindow *) sender toSize: (NSSize) proposedFrameSize