1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-04 18:48:06 +00:00

#4241 Update dock badge count after removing download through web interface

This commit is contained in:
Mitchell Livingston 2011-06-19 03:52:54 +00:00
parent 62f594267a
commit 4d5ab8a4c5
4 changed files with 33 additions and 11 deletions

View file

@ -25,17 +25,20 @@
#import <Cocoa/Cocoa.h>
#import <transmission.h>
@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;

View file

@ -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: @""];
}
}

View file

@ -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"

View file

@ -342,7 +342,7 @@ typedef enum
[self setTab: nil];
}
- (void) swipeWithEvent:(NSEvent *) event
- (void) swipeWithEvent: (NSEvent *) event
{
if ([event deltaX] < 0.0)
[self setNextTab];