mirror of
https://github.com/transmission/transmission
synced 2025-02-07 06:54:40 +00:00
clean dock badging code
This commit is contained in:
parent
b7ae0657ca
commit
8a15058d80
5 changed files with 49 additions and 53 deletions
|
@ -30,8 +30,13 @@
|
|||
tr_handle * fLib;
|
||||
|
||||
NSDictionary * fAttributes;
|
||||
|
||||
BOOL fQuitting;
|
||||
NSProgressIndicator * fQuitIndicator;
|
||||
}
|
||||
|
||||
- (id) initWithFrame: (NSRect) frame lib: (tr_handle *) lib;
|
||||
|
||||
- (void) setQuitting;
|
||||
|
||||
@end
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
@interface BadgeView (Private)
|
||||
|
||||
- (void) badgeString: (NSString *) string forRect: (NSRect) rect;
|
||||
- (void) badge: (NSImage *) badge string: (NSString *) string atHeight: (float) height;
|
||||
|
||||
@end
|
||||
|
||||
|
@ -41,10 +41,16 @@
|
|||
if ((self = [super initWithFrame: frame]))
|
||||
{
|
||||
fLib = lib;
|
||||
fQuitting = NO;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) setQuitting
|
||||
{
|
||||
fQuitting = YES;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[fAttributes release];
|
||||
|
@ -55,6 +61,11 @@
|
|||
{
|
||||
[[NSImage imageNamed: @"NSApplicationIcon"] drawInRect: rect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
|
||||
|
||||
if (fQuitting)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
BOOL checkDownload = [[NSUserDefaults standardUserDefaults] boolForKey: @"BadgeDownloadRate"],
|
||||
checkUpload = [[NSUserDefaults standardUserDefaults] boolForKey: @"BadgeUploadRate"];
|
||||
if (checkDownload || checkUpload)
|
||||
|
@ -72,36 +83,14 @@
|
|||
|
||||
if (uploadRateString || downloadRateString)
|
||||
{
|
||||
NSRect badgeRect = NSZeroRect;
|
||||
badgeRect.size = [[NSImage imageNamed: @"UploadBadge"] size];
|
||||
|
||||
//ignore shadow of badge when placing string
|
||||
NSRect stringRect = badgeRect;
|
||||
stringRect.size.height -= BOTTOM_PADDING;
|
||||
stringRect.origin.y += BOTTOM_PADDING;
|
||||
|
||||
if (uploadRateString)
|
||||
{
|
||||
//place badge and text
|
||||
[[NSImage imageNamed: @"UploadBadge"] drawInRect: badgeRect fromRect: NSZeroRect
|
||||
operation: NSCompositeSourceOver fraction: 1.0];
|
||||
[self badgeString: uploadRateString forRect: stringRect];
|
||||
}
|
||||
if (uploadRateString)
|
||||
[self badge: [NSImage imageNamed: @"UploadBadge"] string: uploadRateString atHeight: 0.0];
|
||||
|
||||
if (downloadRateString)
|
||||
{
|
||||
//download rate above upload rate
|
||||
if (uploadRateString)
|
||||
{
|
||||
float spaceBetween = badgeRect.size.height + BETWEEN_PADDING;
|
||||
badgeRect.origin.y += spaceBetween;
|
||||
stringRect.origin.y += spaceBetween;
|
||||
}
|
||||
|
||||
//place badge and text
|
||||
[[NSImage imageNamed: @"DownloadBadge"] drawInRect: badgeRect fromRect: NSZeroRect
|
||||
operation: NSCompositeSourceOver fraction: 1.0];
|
||||
[self badgeString: downloadRateString forRect: stringRect];
|
||||
float bottom = uploadRateString ? [[NSImage imageNamed: @"UploadBadge"] size].height + BETWEEN_PADDING : 0.0;
|
||||
[self badge: [NSImage imageNamed: @"DownloadBadge"] string: downloadRateString atHeight: bottom];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -112,7 +101,7 @@
|
|||
@implementation BadgeView (Private)
|
||||
|
||||
//dock icon must have locked focus
|
||||
- (void) badgeString: (NSString *) string forRect: (NSRect) rect
|
||||
- (void) badge: (NSImage *) badge string: (NSString *) string atHeight: (float) height
|
||||
{
|
||||
if (!fAttributes)
|
||||
{
|
||||
|
@ -127,14 +116,24 @@
|
|||
[stringShadow release];
|
||||
}
|
||||
|
||||
NSSize stringSize = [string sizeWithAttributes: fAttributes];
|
||||
NSRect badgeRect = NSZeroRect;
|
||||
badgeRect.size = [badge size];
|
||||
badgeRect.origin.y = height;
|
||||
|
||||
[badge drawInRect: badgeRect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
|
||||
|
||||
//string is in center of image
|
||||
rect.origin.x += (rect.size.width - stringSize.width) * 0.5;
|
||||
rect.origin.y += (rect.size.height - stringSize.height) * 0.5;
|
||||
rect.size = stringSize;
|
||||
|
||||
[string drawInRect: rect withAttributes: fAttributes];
|
||||
NSSize stringSize = [string sizeWithAttributes: fAttributes];
|
||||
|
||||
NSRect stringRect = badgeRect;
|
||||
stringRect.origin.x += (badgeRect.size.width - stringSize.width) * 0.5;
|
||||
stringRect.origin.y += (badgeRect.size.height - stringSize.height) * 0.5;
|
||||
stringRect.size = stringSize;
|
||||
|
||||
//adjust for shadow
|
||||
stringRect.origin.y += 1.0;
|
||||
|
||||
[string drawInRect: stringRect withAttributes: fAttributes];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
{
|
||||
tr_handle * fLib;
|
||||
|
||||
NSImage * fDockIcon, * fBadge, * fUploadBadge;
|
||||
NSImage * fDockIcon, * fBadge;
|
||||
|
||||
NSDictionary * fAttributes;
|
||||
int fCompleted, fCompletedBadged;
|
||||
|
@ -41,6 +41,6 @@
|
|||
- (void) updateBadge;
|
||||
- (void) incrementCompleted;
|
||||
- (void) clearCompleted;
|
||||
- (void) clearBadge;
|
||||
- (void) setQuitting;
|
||||
|
||||
@end
|
||||
|
|
|
@ -148,11 +148,8 @@
|
|||
fDockIcon = [[NSImage imageNamed: @"NSApplicationIcon"] copy];
|
||||
dockIcon = [fDockIcon copy];
|
||||
|
||||
if (!fUploadBadge)
|
||||
fUploadBadge = [NSImage imageNamed: @"UploadBadge"];
|
||||
|
||||
NSRect badgeRect;
|
||||
badgeRect.size = [fUploadBadge size];
|
||||
badgeRect.size = [[NSImage imageNamed: @"UploadBadge"] size];
|
||||
badgeRect.origin = NSZeroPoint;
|
||||
|
||||
//ignore shadow of badge when placing string
|
||||
|
@ -165,7 +162,7 @@
|
|||
if (uploadRateString)
|
||||
{
|
||||
//place badge and text
|
||||
[fUploadBadge compositeToPoint: badgeRect.origin operation: NSCompositeSourceOver];
|
||||
[[NSImage imageNamed: @"UploadBadge"] compositeToPoint: badgeRect.origin operation: NSCompositeSourceOver];
|
||||
[self badgeString: uploadRateString forRect: stringRect];
|
||||
}
|
||||
|
||||
|
@ -220,12 +217,13 @@
|
|||
}
|
||||
}
|
||||
|
||||
- (void) clearBadge
|
||||
- (void) setQuitting
|
||||
{
|
||||
if ([NSApp isOnLeopardOrBetter])
|
||||
{
|
||||
[self clearCompleted];
|
||||
[[NSApp dockTile] setContentView: nil];
|
||||
[(BadgeView *)[[NSApp dockTile] contentView] setQuitting];
|
||||
[[NSApp dockTile] display];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
#import "CreatorWindowController.h"
|
||||
#import "StatsWindowController.h"
|
||||
#import "AboutWindowController.h"
|
||||
#import "QuittingWindowController.h"
|
||||
#import "ButtonToolbarItem.h"
|
||||
#import "NSApplicationAdditions.h"
|
||||
#import "NSStringAdditions.h"
|
||||
|
@ -490,6 +489,8 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
|
|||
|
||||
- (void) applicationWillTerminate: (NSNotification *) notification
|
||||
{
|
||||
[fBadger setQuitting];
|
||||
|
||||
//stop timers and notification checking
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
||||
|
||||
|
@ -532,19 +533,12 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
|
|||
[self showStatusBar: NO animate: NO];
|
||||
[self showFilterBar: NO animate: NO];
|
||||
|
||||
//show quit window
|
||||
QuittingWindowController * quitController = [[QuittingWindowController alloc] init];
|
||||
[quitController showWindow: self];
|
||||
|
||||
//save history
|
||||
[self updateTorrentHistory];
|
||||
|
||||
[fDisplayedTorrents removeAllObjects];
|
||||
[fTorrents removeAllObjects];
|
||||
|
||||
//clear badge
|
||||
[fBadger clearBadge];
|
||||
|
||||
//remaining calls the same as dealloc
|
||||
[fInfoController release];
|
||||
[fMessageController release];
|
||||
|
@ -553,7 +547,6 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
|
|||
[fTorrents release];
|
||||
[fDisplayedTorrents release];
|
||||
|
||||
[fBadger release];
|
||||
[fOverlayWindow release];
|
||||
[fIPCController release];
|
||||
|
||||
|
@ -1446,7 +1439,8 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
|
|||
else
|
||||
tr_getSessionStats(fLib, &stats);
|
||||
|
||||
statusString = [NSString stringWithFormat: NSLocalizedString(@"DL: %@ UL: %@", "status bar -> status label"),
|
||||
statusString = [NSString stringWithFormat: NSLocalizedString(@"DL: %@ UL: %@",
|
||||
"status bar -> status label (3 spaces between)"),
|
||||
[NSString stringForFileSize: stats.downloadedBytes], [NSString stringForFileSize: stats.uploadedBytes]];
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue